From fb048ca4037dac220169ba27dc149b36a73ee919 Mon Sep 17 00:00:00 2001 From: Blake Li Date: Fri, 4 Feb 2022 21:47:22 -0500 Subject: [PATCH] Add unit tests for explicit dynamic routing header feature. (#337) --- .../api/pathtemplate/PathTemplateTest.java | 30 +++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java b/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java index 6e4f02557..ae829c5ad 100644 --- a/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java +++ b/src/test/java/com/google/api/pathtemplate/PathTemplateTest.java @@ -178,6 +178,36 @@ public void matchWithUnboundInMiddle() { assertPositionalMatch(template.match("bar/foo/foo/foo/bar"), "foo/foo", "bar"); } + @Test + public void matchWithNamedBindings() { + PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**"); + Map actual = + template.match("projects/proj_foo/instances/instance_bar/table/table_baz"); + Truth.assertThat(actual).containsEntry("instance_id", "instances/instance_bar"); + } + + @Test + public void matchFailWithNamedBindingsWhenPathMismatches() { + PathTemplate template = PathTemplate.create("projects/*/{instance_id=instances/*}/**"); + Map actual = + template.match("projects/proj_foo/instances_fail/instance_bar/table/table_baz"); + Truth.assertThat(actual).isNull(); + } + + @Test + public void matchWithNamedBindingsThatHasOnlyWildcard() { + PathTemplate template = PathTemplate.create("profiles/{routing_id=*}"); + Map actual = template.match("profiles/prof_qux"); + Truth.assertThat(actual).containsEntry("routing_id", "prof_qux"); + } + + @Test + public void matchFailWithNamedBindingsThatHasOnlyWildcardWhenPathMismatches() { + PathTemplate template = PathTemplate.create("profiles/{routing_id=*}"); + Map actual = template.match("profiles/prof_qux/fail"); + Truth.assertThat(actual).isNull(); + } + @Test public void matchWithCustomVerbs() { PathTemplate template = PathTemplate.create("**:foo");