Search in sources :

Example 1 with RoutingContext

use of com.spotify.apollo.environment.EnvironmentFactory.RoutingContext in project apollo by spotify.

the class EnvironmentFactoryTest method shouldThrowIfUsedAfterInit.

@Test
public void shouldThrowIfUsedAfterInit() throws Exception {
    final EnvironmentFactory factory = sut.build();
    final RoutingContext routingContext = factory.createRoutingContext();
    final Environment environment = factory.create(SERVICE_NAME, routingContext);
    final Route<AsyncHandler<Response<ByteString>>> route = Route.sync("GET", "/f1", handler());
    environment.routingEngine().registerRoute(route);
    final Iterable<Object> objects = routingContext.endpointObjects();
    assertTrue(Iterables.contains(objects, route));
    try {
        environment.routingEngine().registerRoute(route);
        fail("should throw");
    } catch (Exception e) {
        assertThat(e.getMessage(), containsString("already been initialized"));
    }
}
Also used : RoutingContext(com.spotify.apollo.environment.EnvironmentFactory.RoutingContext) AsyncHandler(com.spotify.apollo.route.AsyncHandler) ByteString(okio.ByteString) Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Example 2 with RoutingContext

use of com.spotify.apollo.environment.EnvironmentFactory.RoutingContext in project apollo by spotify.

the class EnvironmentFactoryTest method shouldCollectRegisteredRoutes.

@Test
public void shouldCollectRegisteredRoutes() throws Exception {
    final EnvironmentFactory factory = sut.build();
    final RoutingContext routingContext = factory.createRoutingContext();
    final Environment environment = factory.create(SERVICE_NAME, routingContext);
    final Route<AsyncHandler<Response<ByteString>>> route1 = Route.sync("GET", "/f1", handler());
    final Route<AsyncHandler<Response<ByteString>>> route2 = Route.sync("GET", "/2", handler());
    final Route<AsyncHandler<Response<ByteString>>> route3 = Route.sync("GET", "/3", handler());
    environment.routingEngine().registerRoute(route1).registerRoute(route2);
    environment.routingEngine().registerRoute(route3);
    final Iterable<Object> objects = routingContext.endpointObjects();
    assertTrue(Iterables.contains(objects, route1));
    assertTrue(Iterables.contains(objects, route2));
    assertTrue(Iterables.contains(objects, route3));
}
Also used : RoutingContext(com.spotify.apollo.environment.EnvironmentFactory.RoutingContext) AsyncHandler(com.spotify.apollo.route.AsyncHandler) ByteString(okio.ByteString) Environment(com.spotify.apollo.Environment) Test(org.junit.Test)

Aggregations

Environment (com.spotify.apollo.Environment)2 RoutingContext (com.spotify.apollo.environment.EnvironmentFactory.RoutingContext)2 AsyncHandler (com.spotify.apollo.route.AsyncHandler)2 ByteString (okio.ByteString)2 Test (org.junit.Test)2