@@ -51,42 +51,61 @@ public void setUp() {
5151
5252 @ Test
5353 public void add_happyPath () {
54- String headerKey = "table_location" ;
5554 Map <String , String > actual =
5655 getRoutingHeaders (
57- headerKey ,
5856 "projects/**/{table_location=instances/*}" ,
5957 "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" );
6185 }
6286
6387 @ Test
6488 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/" );
6790 assertThat (actual ).isEmpty ();
6891 }
6992
7093 @ Test
7194 public void add_emptyMatchedValues () {
7295 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" );
7797 assertThat (actual ).isEmpty ();
7898 }
7999
80100 @ Test
81101 public void add_nullFieldValue () {
82- Map <String , String > actual = getRoutingHeaders ("table_location" , " projects/**" , null );
102+ Map <String , String > actual = getRoutingHeaders ("projects/**" , null );
83103 assertThat (actual ).isEmpty ();
84104 }
85105
86- private Map <String , String > getRoutingHeaders (
87- String headerKey , String patternString , String fieldValue ) {
106+ private Map <String , String > getRoutingHeaders (String patternString , String fieldValue ) {
88107 PathTemplate pathTemplate = PathTemplate .create (patternString );
89- requestParamsBuilder .add (fieldValue , headerKey , pathTemplate );
108+ requestParamsBuilder .add (fieldValue , "table_location" , pathTemplate );
90109 return requestParamsBuilder .build ();
91110 }
92111}
0 commit comments