Thanks to visit codestin.com
Credit goes to github.com

Skip to content
This repository was archived by the owner on Sep 27, 2023. It is now read-only.

Commit fb048ca

Browse files
authored
Add unit tests for explicit dynamic routing header feature. (#337)
1 parent 309521b commit fb048ca

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

src/test/java/com/google/api/pathtemplate/PathTemplateTest.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -178,6 +178,36 @@ public void matchWithUnboundInMiddle() {
178178
assertPositionalMatch(template.match("bar/foo/foo/foo/bar"), "foo/foo", "bar");
179179
}
180180

181+
@Test
182+
public void matchWithNamedBindings() {
183+
PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**");
184+
Map<String, String> actual =
185+
template.match("projects/proj_foo/instances/instance_bar/table/table_baz");
186+
Truth.assertThat(actual).containsEntry("instance_id", "instances/instance_bar");
187+
}
188+
189+
@Test
190+
public void matchFailWithNamedBindingsWhenPathMismatches() {
191+
PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**");
192+
Map<String, String> actual =
193+
template.match("projects/proj_foo/instances_fail/instance_bar/table/table_baz");
194+
Truth.assertThat(actual).isNull();
195+
}
196+
197+
@Test
198+
public void matchWithNamedBindingsThatHasOnlyWildcard() {
199+
PathTemplate template = PathTemplate.create("profiles/{routing_id=*}");
200+
Map<String, String> actual = template.match("profiles/prof_qux");
201+
Truth.assertThat(actual).containsEntry("routing_id", "prof_qux");
202+
}
203+
204+
@Test
205+
public void matchFailWithNamedBindingsThatHasOnlyWildcardWhenPathMismatches() {
206+
PathTemplate template = PathTemplate.create("profiles/{routing_id=*}");
207+
Map<String, String> actual = template.match("profiles/prof_qux/fail");
208+
Truth.assertThat(actual).isNull();
209+
}
210+
181211
@Test
182212
public void matchWithCustomVerbs() {
183213
PathTemplate template = PathTemplate.create("**:foo");

0 commit comments

Comments
 (0)