5050import java .util .Arrays ;
5151import java .util .Collections ;
5252import java .util .concurrent .TimeUnit ;
53- import javax .annotation .Nullable ;
5453import org .junit .Test ;
5554import org .junit .runner .RunWith ;
5655import org .junit .runners .JUnit4 ;
@@ -211,7 +210,7 @@ public void convertRoute() {
211210 assertThat (struct1 .getStruct ())
212211 .isEqualTo (
213212 new Route (
214- new RouteMatch (new PathMatcher ("/service/method" , null , null ),
213+ new RouteMatch (PathMatcher . fromPath ("/service/method" , false ),
215214 Collections .<HeaderMatcher >emptyList (), null ),
216215 new RouteAction (TimeUnit .SECONDS .toNanos (15L ), "cluster-foo" , null )));
217216
@@ -259,38 +258,6 @@ public void convertRoute_skipWithUnsupportedAction() {
259258 assertThat (Route .fromEnvoyProtoRoute (proto )).isNull ();
260259 }
261260
262- @ Test
263- public void isDefaultRoute () {
264- StructOrError <Route > struct1 = Route .fromEnvoyProtoRoute (buildSimpleRouteProto ("" , null ));
265- StructOrError <Route > struct2 = Route .fromEnvoyProtoRoute (buildSimpleRouteProto ("/" , null ));
266- StructOrError <Route > struct3 =
267- Route .fromEnvoyProtoRoute (buildSimpleRouteProto ("/service/" , null ));
268- StructOrError <Route > struct4 =
269- Route .fromEnvoyProtoRoute (buildSimpleRouteProto (null , "/service/method" ));
270-
271- assertThat (struct1 .getStruct ().isDefaultRoute ()).isTrue ();
272- assertThat (struct2 .getStruct ().isDefaultRoute ()).isTrue ();
273- assertThat (struct3 .getStruct ().isDefaultRoute ()).isFalse ();
274- assertThat (struct4 .getStruct ().isDefaultRoute ()).isFalse ();
275- }
276-
277- private static io .envoyproxy .envoy .config .route .v3 .Route buildSimpleRouteProto (
278- @ Nullable String pathPrefix , @ Nullable String path ) {
279- io .envoyproxy .envoy .config .route .v3 .Route .Builder routeBuilder =
280- io .envoyproxy .envoy .config .route .v3 .Route .newBuilder ()
281- .setName ("simple-route" )
282- .setRoute (io .envoyproxy .envoy .config .route .v3 .RouteAction .newBuilder ()
283- .setCluster ("simple-cluster" ));
284- if (pathPrefix != null ) {
285- routeBuilder .setMatch (io .envoyproxy .envoy .config .route .v3 .RouteMatch .newBuilder ()
286- .setPrefix (pathPrefix ));
287- } else if (path != null ) {
288- routeBuilder .setMatch (io .envoyproxy .envoy .config .route .v3 .RouteMatch .newBuilder ()
289- .setPath (path ));
290- }
291- return routeBuilder .build ();
292- }
293-
294261 @ Test
295262 public void convertRouteMatch_pathMatching () {
296263 // path_specifier = prefix
@@ -300,7 +267,13 @@ public void convertRouteMatch_pathMatching() {
300267 assertThat (struct1 .getErrorDetail ()).isNull ();
301268 assertThat (struct1 .getStruct ()).isEqualTo (
302269 new RouteMatch (
303- new PathMatcher (null , "/" , null ), Collections .<HeaderMatcher >emptyList (), null ));
270+ PathMatcher .fromPrefix ("/" , false ), Collections .<HeaderMatcher >emptyList (), null ));
271+
272+ proto1 = proto1 .toBuilder ().setCaseSensitive (BoolValue .newBuilder ().setValue (true )).build ();
273+ struct1 = Route .convertEnvoyProtoRouteMatch (proto1 );
274+ assertThat (struct1 .getStruct ()).isEqualTo (
275+ new RouteMatch (
276+ PathMatcher .fromPrefix ("/" , true ), Collections .<HeaderMatcher >emptyList (), null ));
304277
305278 // path_specifier = path
306279 io .envoyproxy .envoy .config .route .v3 .RouteMatch proto2 =
@@ -311,7 +284,14 @@ public void convertRouteMatch_pathMatching() {
311284 assertThat (struct2 .getErrorDetail ()).isNull ();
312285 assertThat (struct2 .getStruct ()).isEqualTo (
313286 new RouteMatch (
314- new PathMatcher ("/service/method" , null , null ),
287+ PathMatcher .fromPath ("/service/method" , false ),
288+ Collections .<HeaderMatcher >emptyList (), null ));
289+
290+ proto2 = proto2 .toBuilder ().setCaseSensitive (BoolValue .newBuilder ().setValue (true )).build ();
291+ struct2 = Route .convertEnvoyProtoRouteMatch (proto2 );
292+ assertThat (struct2 .getStruct ()).isEqualTo (
293+ new RouteMatch (
294+ PathMatcher .fromPath ("/service/method" , true ),
315295 Collections .<HeaderMatcher >emptyList (), null ));
316296
317297 // path_specifier = safe_regex
@@ -323,18 +303,9 @@ public void convertRouteMatch_pathMatching() {
323303 assertThat (struct4 .getErrorDetail ()).isNull ();
324304 assertThat (struct4 .getStruct ()).isEqualTo (
325305 new RouteMatch (
326- new PathMatcher ( null , null , Pattern .compile ("." )),
306+ PathMatcher . fromRegEx ( Pattern .compile ("." )),
327307 Collections .<HeaderMatcher >emptyList (), null ));
328308
329- // case_sensitive = false
330- io .envoyproxy .envoy .config .route .v3 .RouteMatch proto5 =
331- io .envoyproxy .envoy .config .route .v3 .RouteMatch .newBuilder ()
332- .setCaseSensitive (BoolValue .newBuilder ().setValue (false ))
333- .build ();
334- StructOrError <RouteMatch > struct5 = Route .convertEnvoyProtoRouteMatch (proto5 );
335- assertThat (struct5 .getErrorDetail ()).isNotNull ();
336- assertThat (struct5 .getStruct ()).isNull ();
337-
338309 // query_parameters is set
339310 io .envoyproxy .envoy .config .route .v3 .RouteMatch proto6 =
340311 io .envoyproxy .envoy .config .route .v3 .RouteMatch .newBuilder ()
@@ -370,7 +341,7 @@ public void convertRouteMatch_withHeaderMatching() {
370341 assertThat (struct .getStruct ())
371342 .isEqualTo (
372343 new RouteMatch (
373- new PathMatcher ( null , "" , null ),
344+ PathMatcher . fromPrefix ( "" , false ),
374345 Arrays .asList (
375346 new HeaderMatcher (":scheme" , null , null , null , null , "http" , null , false ),
376347 new HeaderMatcher (":method" , "PUT" , null , null , null , null , null , false )),
@@ -394,7 +365,7 @@ public void convertRouteMatch_withRuntimeFraction() {
394365 assertThat (struct .getStruct ())
395366 .isEqualTo (
396367 new RouteMatch (
397- new PathMatcher ( null , "" , null ), Collections .<HeaderMatcher >emptyList (),
368+ PathMatcher . fromPrefix ( "" , false ), Collections .<HeaderMatcher >emptyList (),
398369 new FractionMatcher (30 , 100 )));
399370 }
400371
0 commit comments