GsRoutingStrategy implements RoutingStrategy { @Override public Router create(Method serviceMethod) { return createRoutingStrategy(serviceMethod); }  @Override Router create(Method serviceMethod); static Router lookForRoutingAnnotationInMethodSignature(Method m); static Router createRoutingStrategy(Method serviceMethod, int routingArgumentIndex, Routing routingAnnotation);  }
@Test public void astrixRoutingTakesPrecedence() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing String routingArg, @AstrixRouting String anotherArg) { } } Router router = new GsRoutingStrategy().create(Service.class.getMethod("hello", String.class, String.class)); RoutingKey routingKey = router.getRoutingKey(new Object[]{"ignored-arg", "second-arg"}); assertEquals(RoutingKey.create("second-arg"), routingKey); }
@Test public void routesOnRoutingAnnotatedArgument() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing String routingArg, String anotherArg) { } } Router router = new GsRoutingStrategy().create(Service.class.getMethod("hello", String.class, String.class)); RoutingKey routingKey = router.getRoutingKey(new Object[]{"routing-arg", "another-arg"}); assertEquals(RoutingKey.create("routing-arg"), routingKey); }
@Test public void routesOnRoutingAnnotatedArgumentPropertyIfDefined() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing("getRouting") ProperRoutingMethod routingArg) { } } Router router = new GsRoutingStrategy().create(Service.class.getMethod("hello", ProperRoutingMethod.class)); RoutingKey routingKey = router.getRoutingKey(new Object[]{new ProperRoutingMethod()}); assertEquals(RoutingKey.create("routing-arg"), routingKey); }
@Test(expected = IllegalArgumentException.class) public void missingPropertyMethod_throwsIllegalArgumentException() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing("getRouting") MissingRoutingMethod routingArg) { } } new GsRoutingStrategy().create(Service.class.getMethod("hello", MissingRoutingMethod.class)); }
@Test(expected = IllegalArgumentException.class) public void invalidPropertyMethod_throwsIllegalArgumentException() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing("getRouting") IllegalRoutingMethod routingArg) { } } new GsRoutingStrategy().create(Service.class.getMethod("hello", IllegalRoutingMethod.class)); }
@Test(expected = AmbiguousRoutingException.class) public void multipleRoutingAnnotations_throwsAmbiguousRoutingException() throws Exception { class Service { @SuppressWarnings("unused") public void hello(@Routing String routingArg, @Routing String routingArg2) { } } new GsRoutingStrategy().create(Service.class.getMethod("hello", String.class, String.class)); }
@Test(expected = AmbiguousRoutingException.class) public void noRoutingArgument_throwsAmbiguousRoutingException() throws Exception { class Service { @SuppressWarnings("unused") public void hello(String routingArg, String routingArg2) { } } new GsRoutingStrategy().create(Service.class.getMethod("hello", String.class, String.class)); }