@@ -51,42 +51,61 @@ public void setUp() {
51
51
52
52
@ Test
53
53
public void add_happyPath () {
54
- String headerKey = "table_location" ;
55
54
Map <String , String > actual =
56
55
getRoutingHeaders (
57
- headerKey ,
58
56
"projects/**/{table_location=instances/*}" ,
59
57
"projects/my_cozy_home/instances/living_room" );
60
- assertThat (actual ).containsExactly (headerKey , "instances/living_room" );
58
+ assertThat (actual ).containsExactly ("table_location" , "instances/living_room" );
59
+ }
60
+
61
+ @ Test
62
+ public void build_shouldKeepLastEntryIfMultipleEntriesHaveTheSameKeyRatherThanErrorOut () {
63
+ requestParamsBuilder .add (
64
+ "projects/my_cozy_home/instances/living_room" ,
65
+ "table_location" ,
66
+ PathTemplate .create ("projects/**/{table_location=instances/*}" ));
67
+ requestParamsBuilder .add (
68
+ "projects/my_cozy_home/instances/living_room" ,
69
+ "table_location" ,
70
+ PathTemplate .create ("{table_location=**}" ));
71
+ requestParamsBuilder .add (
72
+ "projects/my_cozy_home/instances/living_room" ,
73
+ "routing_id" ,
74
+ PathTemplate .create ("{routing_id=**}" ));
75
+ Map <String , String > actual = requestParamsBuilder .build ();
76
+
77
+ // Should contain two entries instead of three, also should only keep the last entry if there
78
+ // are multiple entries with the same key
79
+ assertThat (actual )
80
+ .containsExactly (
81
+ "table_location" ,
82
+ "projects/my_cozy_home/instances/living_room" ,
83
+ "routing_id" ,
84
+ "projects/my_cozy_home/instances/living_room" );
61
85
}
62
86
63
87
@ Test
64
88
public void add_matchedValuesWithNoRoutingHeaderKey () {
65
- Map <String , String > actual =
66
- getRoutingHeaders ("table_location" , "projects/**" , "projects/my_cozy_home/" );
89
+ Map <String , String > actual = getRoutingHeaders ("projects/**" , "projects/my_cozy_home/" );
67
90
assertThat (actual ).isEmpty ();
68
91
}
69
92
70
93
@ Test
71
94
public void add_emptyMatchedValues () {
72
95
Map <String , String > actual =
73
- getRoutingHeaders (
74
- "table_location" ,
75
- "projects/**/{table_location=instances/*}" ,
76
- "projects/does_not_matter" );
96
+ getRoutingHeaders ("projects/**/{table_location=instances/*}" , "projects/does_not_matter" );
77
97
assertThat (actual ).isEmpty ();
78
98
}
79
99
80
100
@ Test
81
101
public void add_nullFieldValue () {
82
- Map <String , String > actual = getRoutingHeaders ("table_location" , " projects/**" , null );
102
+ Map <String , String > actual = getRoutingHeaders ("projects/**" , null );
83
103
assertThat (actual ).isEmpty ();
84
104
}
85
105
86
- private Map <String , String > getRoutingHeaders (
87
- String headerKey , String patternString , String fieldValue ) {
106
+ private Map <String , String > getRoutingHeaders (String patternString , String fieldValue ) {
88
107
PathTemplate pathTemplate = PathTemplate .create (patternString );
89
- requestParamsBuilder .add (fieldValue , headerKey , pathTemplate );
108
+ requestParamsBuilder .add (fieldValue , "table_location" , pathTemplate );
90
109
return requestParamsBuilder .build ();
91
110
}
92
111
}
0 commit comments