@@ -114,6 +114,7 @@ public void pathWildcards_matchZeroOrMoreSegments() {
114
114
PathTemplate start = PathTemplate .create ("{glob=**}/b" );
115
115
PathTemplate middle = PathTemplate .create ("a/{glob=**}/b" );
116
116
PathTemplate end = PathTemplate .create ("a/{glob=**}" );
117
+ PathTemplate endWithCustomVerb = PathTemplate .create ("a/{glob=**}:foo" );
117
118
118
119
Truth .assertThat (start .match ("b" ).get ("glob" )).isEmpty ();
119
120
Truth .assertThat (start .match ("/b" ).get ("glob" )).isEmpty ();
@@ -129,6 +130,10 @@ public void pathWildcards_matchZeroOrMoreSegments() {
129
130
Truth .assertThat (end .match ("a/" ).get ("glob" )).isEmpty ();
130
131
Truth .assertThat (end .match ("a/b" ).get ("glob" )).isEqualTo ("b" );
131
132
Truth .assertThat (end .match ("a/b/b/b" ).get ("glob" )).isEqualTo ("b/b/b" );
133
+
134
+ Truth .assertThat (endWithCustomVerb .match ("a/:foo" ).get ("glob" )).isEmpty ();
135
+ Truth .assertThat (endWithCustomVerb .match ("a/b:foo" ).get ("glob" )).isEqualTo ("b" );
136
+ Truth .assertThat (endWithCustomVerb .match ("a/b/b:foo" ).get ("glob" )).isEqualTo ("b/b" );
132
137
}
133
138
134
139
@ Test
@@ -173,6 +178,12 @@ public void matchWithUnboundInMiddle() {
173
178
assertPositionalMatch (template .match ("bar/foo/foo/foo/bar" ), "foo/foo" , "bar" );
174
179
}
175
180
181
+ @ Test
182
+ public void matchWithCustomVerbs () {
183
+ PathTemplate template = PathTemplate .create ("**:foo" );
184
+ assertPositionalMatch (template .match ("a/b/c:foo" ), "a/b/c" );
185
+ }
186
+
176
187
// Complex Resource ID Segments.
177
188
// ========
178
189
@@ -215,6 +226,45 @@ public void complexResourceIdBasicCases() {
215
226
Truth .assertThat (match .get ("zone_b" )).isEqualTo ("us-east3-a" );
216
227
}
217
228
229
+ @ Test
230
+ public void complexResourceIdCustomVerb () {
231
+ // Separate by "~".
232
+ PathTemplate template = PathTemplate .create ("projects/{project}/zones/{zone_a}~{zone_b}:hello" );
233
+ Map <String , String > match =
234
+ template .match (
235
+ "https://www.googleapis.com/compute/v1/projects/project-123/zones/europe-west3-c~us-east3-a:hello" );
236
+ Truth .assertThat (match ).isNotNull ();
237
+ Truth .assertThat (match .get (PathTemplate .HOSTNAME_VAR )).isEqualTo ("https://www.googleapis.com" );
238
+ Truth .assertThat (match .get ("project" )).isEqualTo ("project-123" );
239
+ Truth .assertThat (match .get ("zone_a}~{zone_b" )).isNull ();
240
+ Truth .assertThat (match .get ("zone_a" )).isEqualTo ("europe-west3-c" );
241
+ Truth .assertThat (match .get ("zone_b" )).isEqualTo ("us-east3-a" );
242
+
243
+ // Separate by "-".
244
+ template = PathTemplate .create ("projects/{project}/zones/{zone_a}-{zone_b}:hello" );
245
+ match = template .match ("projects/project-123/zones/europe-west3-c~us-east3-a:hello" );
246
+ Truth .assertThat (match ).isNotNull ();
247
+ Truth .assertThat (match .get ("project" )).isEqualTo ("project-123" );
248
+ Truth .assertThat (match .get ("zone_a" )).isEqualTo ("europe" );
249
+ Truth .assertThat (match .get ("zone_b" )).isEqualTo ("west3-c~us-east3-a" );
250
+
251
+ // Separate by ".".
252
+ template = PathTemplate .create ("projects/{project}/zones/{zone_a}.{zone_b}:hello" );
253
+ match = template .match ("projects/project-123/zones/europe-west3-c.us-east3-a:hello" );
254
+ Truth .assertThat (match ).isNotNull ();
255
+ Truth .assertThat (match .get ("project" )).isEqualTo ("project-123" );
256
+ Truth .assertThat (match .get ("zone_a" )).isEqualTo ("europe-west3-c" );
257
+ Truth .assertThat (match .get ("zone_b" )).isEqualTo ("us-east3-a" );
258
+
259
+ // Separate by "_".
260
+ template = PathTemplate .create ("projects/{project}/zones/{zone_a}_{zone_b}:hello" );
261
+ match = template .match ("projects/project-123/zones/europe-west3-c_us-east3-a:hello" );
262
+ Truth .assertThat (match ).isNotNull ();
263
+ Truth .assertThat (match .get ("project" )).isEqualTo ("project-123" );
264
+ Truth .assertThat (match .get ("zone_a" )).isEqualTo ("europe-west3-c" );
265
+ Truth .assertThat (match .get ("zone_b" )).isEqualTo ("us-east3-a" );
266
+ }
267
+
218
268
@ Test
219
269
public void complexResourceIdEqualsWildcard () {
220
270
PathTemplate template = PathTemplate .create ("projects/{project=*}/zones/{zone_a=*}~{zone_b=*}" );
@@ -604,6 +654,18 @@ public void instantiateWithComplexResourceId_basic() {
604
654
Truth .assertThat (instance ).isEqualTo ("projects/a%2Fb%2Fc/zones/apple~baseball" );
605
655
}
606
656
657
+ @ Test
658
+ public void instantiateWithComplexResourceId_customVerb () {
659
+ PathTemplate template = PathTemplate .create ("projects/{project}/zones/{zone_a}~{zone_b}:hello" );
660
+ String instance =
661
+ template .instantiate ("project" , "a/b/c" , "zone_a" , "apple" , "zone_b" , "baseball" );
662
+ Truth .assertThat (instance ).isEqualTo ("projects/a%2Fb%2Fc/zones/apple~baseball:hello" );
663
+
664
+ template = PathTemplate .create ("projects/{project}/zones/{zone_a}~{zone_b}/stuff:hello" );
665
+ instance = template .instantiate ("project" , "a/b/c" , "zone_a" , "apple" , "zone_b" , "baseball" );
666
+ Truth .assertThat (instance ).isEqualTo ("projects/a%2Fb%2Fc/zones/apple~baseball/stuff:hello" );
667
+ }
668
+
607
669
@ Test
608
670
public void instantiateWithComplexResourceId_mixedSeparators () {
609
671
PathTemplate template =
@@ -647,6 +709,14 @@ public void instantiateWithComplexResourceId_mixedSeparatorsInParent() {
647
709
Truth .assertThat (instance ).isEqualTo ("projects/a%2Fb%2Fc~foo.bar/zones/apple~baseball" );
648
710
}
649
711
712
+ @ Test
713
+ public void instantiateWithCustomVerbs () {
714
+ PathTemplate template = PathTemplate .create ("/v1/{name=operations/**}:cancel" );
715
+ String templateInstance = template .instantiate ("name" , "operations/3373707" );
716
+ Truth .assertThat (templateInstance ).isEqualTo ("v1/operations/3373707:cancel" );
717
+ Truth .assertThat (template .matches (templateInstance ));
718
+ }
719
+
650
720
// Other
651
721
// =====
652
722
0 commit comments