@Test public void makesSureDecoratedServiceIsAdded() { final Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator = spy(new DecoratingFunction()); final AnnotatedServiceRegistrationBean bean = new AnnotatedServiceRegistrationBean() .setServiceName("test") .setService(new SimpleService()) .setDecorators(decorator); final ServerBuilder sb = new ServerBuilder(); configureAnnotatedHttpServices(sb, ImmutableList.of(bean), null); verify(decorator).apply(any()); assertThat(service(sb).as(SimpleDecorator.class)).isPresent(); }
@Test public void makesSureDecoratorsAreConfigured() { final Function<Service<HttpRequest, HttpResponse>, ? extends Service<HttpRequest, HttpResponse>> decorator = spy(new IdentityFunction()); final AnnotatedServiceRegistrationBean bean = new AnnotatedServiceRegistrationBean() .setServiceName("test") .setService(new SimpleService()) .setDecorators(decorator); final ServerBuilder sb1 = new ServerBuilder(); configureAnnotatedHttpServices(sb1, ImmutableList.of(bean), MeterIdPrefixFunctionFactory.DEFAULT); verify(decorator).apply(any()); assertThat(service(sb1).as(MetricCollectingService.class)).isPresent(); reset(decorator); final ServerBuilder sb2 = new ServerBuilder(); configureAnnotatedHttpServices(sb2, ImmutableList.of(bean), null); verify(decorator).apply(any()); assertThat(service(sb2)).isInstanceOf(AnnotatedHttpService.class); }
@Bean public AnnotatedServiceRegistrationBean annotatedService() { return new AnnotatedServiceRegistrationBean() .setServiceName("annotatedService") .setService(new AnnotatedService()) .setPathPrefix("/annotated") .setDecorators(LoggingService.newDecorator()) .setExceptionHandlers(ImmutableList.of(new IllegalArgumentExceptionHandler())) .setRequestConverters(ImmutableList.of(new StringRequestConverterFunction())) .setResponseConverters(ImmutableList.of(new StringResponseConverter())); }