ApplicationPublisher { public void publish(Application application) { Set<Class<?>> classes = new LinkedHashSet<>(); Set<Class<?>> appClasses = application.getClasses(); if (appClasses != null) { classes.addAll(appClasses); } if (application instanceof EverrestApplication) { EverrestApplication everrest = (EverrestApplication)application; for (Map.Entry<String, Class<?>> e : everrest.getResourceClasses().entrySet()) { Class<?> clazz = e.getValue(); addResource(e.getKey(), clazz); classes.remove(clazz); } for (Map.Entry<String, Object> e : everrest.getResourceSingletons().entrySet()) { addResource(e.getKey(), e.getValue()); } for (ObjectFactory<? extends ObjectModel> factory : everrest.getFactories()) { addFactory(factory); classes.remove(factory.getObjectModel().getObjectClass()); } } for (Class<?> clazz : classes) { addPerRequest(clazz); } Set<Object> singletons = application.getSingletons(); if (singletons != null) { for (Object instance : singletons) { addSingleton(instance); } } } ApplicationPublisher(ResourceBinder resources, ProviderBinder providers);   ApplicationPublisher(ResourceBinder resources, RestComponentResolver componentResolver); void publish(Application application);  }
@Test public void publishesPerRequestExceptionMapper() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(RuntimeExceptionMapper.class)); publisher.publish(application); verify(providers).addExceptionMapper(RuntimeExceptionMapper.class); }
@Test public void publishesSingletonExceptionMapper() { ExceptionMapper exceptionMapper = new RuntimeExceptionMapper(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(exceptionMapper)); publisher.publish(application); verify(providers).addExceptionMapper(exceptionMapper); }
@Test public void publishesPerRequestContextResolver() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(ContextResolverText.class)); publisher.publish(application); verify(providers).addContextResolver(ContextResolverText.class); }
@Test public void publishesSingletonContextResolver() { ContextResolver contextResolver = new ContextResolverText(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(contextResolver)); publisher.publish(application); verify(providers).addContextResolver(contextResolver); }
@Test public void publishesPerRequestMessageBodyReader() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(StringEntityProvider.class)); publisher.publish(application); verify(providers).addMessageBodyReader(StringEntityProvider.class); }
@Test public void publishesSingletonMessageBodyReader() { MessageBodyReader<String> messageBodyReader = new StringEntityProvider(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(messageBodyReader)); publisher.publish(application); verify(providers).addMessageBodyReader(messageBodyReader); }
@Test public void publishesPerRequestMessageBodyWriter() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(StringEntityProvider.class)); publisher.publish(application); verify(providers).addMessageBodyWriter(StringEntityProvider.class); }
@Test public void publishesSingletonMessageBodyWriter() { MessageBodyWriter<String> messageBodyWriter = new StringEntityProvider(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(messageBodyWriter)); publisher.publish(application); verify(providers).addMessageBodyWriter(messageBodyWriter); }
@Test public void publishesPerRequestMethodInvokerFilter() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesMethodInvokerFilter.class)); publisher.publish(application); verify(providers).addMethodInvokerFilter(AllMatchesMethodInvokerFilter.class); }
@Test public void publishesSingletonMethodInvokerFilter() { MethodInvokerFilter methodInvokerFilter = new AllMatchesMethodInvokerFilter(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(methodInvokerFilter)); publisher.publish(application); verify(providers).addMethodInvokerFilter(methodInvokerFilter); }
@Test public void publishesPerRequestRequestFilter() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesRequestFilter.class)); publisher.publish(application); verify(providers).addRequestFilter(AllMatchesRequestFilter.class); }
@Test public void publishesSingletonRequestFilter() { RequestFilter requestFilter = new AllMatchesRequestFilter(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(requestFilter)); publisher.publish(application); verify(providers).addRequestFilter(requestFilter); }
@Test public void publishesPerResponseResponseFilter() { Application application = mock(Application.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesResponseFilter.class)); publisher.publish(application); verify(providers).addResponseFilter(AllMatchesResponseFilter.class); }
@Test public void publishesSingletonResponseFilter() { ResponseFilter responseFilter = new AllMatchesResponseFilter(); Application application = mock(Application.class); when(application.getSingletons()).thenReturn(newHashSet(responseFilter)); publisher.publish(application); verify(providers).addResponseFilter(responseFilter); }
@Test public void publishesExceptionMapperWithFactoryAndOverridesPerRequestExceptionMapperThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory exceptionMapperFactory = mockObjectFactory(RuntimeExceptionMapper.class); when(application.getClasses()).thenReturn(newHashSet(RuntimeExceptionMapper.class)); when(application.getFactories()).thenReturn(newHashSet(exceptionMapperFactory)); publisher.publish(application); verify(providers, never()).addExceptionMapper(RuntimeExceptionMapper.class); verify(providers).addExceptionMapper(exceptionMapperFactory); }
@Test public void publishesContextResolverWithFactoryAndOverridesPerRequestContextResolverThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory contextResolverFactory = mockObjectFactory(ContextResolverText.class); when(application.getClasses()).thenReturn(newHashSet(ContextResolverText.class)); when(application.getFactories()).thenReturn(newHashSet(contextResolverFactory)); publisher.publish(application); verify(providers, never()).addContextResolver(ContextResolverText.class); verify(providers).addContextResolver(contextResolverFactory); }
@Test public void publishesMessageBodyReaderWithFactoryAndOverridesPerRequestMessageBodyReaderThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory messageBodyReaderFactory = mockObjectFactory(StringEntityProvider.class); when(application.getClasses()).thenReturn(newHashSet(StringEntityProvider.class)); when(application.getFactories()).thenReturn(newHashSet(messageBodyReaderFactory)); publisher.publish(application); verify(providers, never()).addMessageBodyReader(StringEntityProvider.class); verify(providers).addMessageBodyReader(messageBodyReaderFactory); }
@Test public void publishesMessageBodyWriterWithFactoryAndOverridesPerRequestMessageBodyWriterThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory messageBodyWriterFactory = mockObjectFactory(StringEntityProvider.class); when(application.getClasses()).thenReturn(newHashSet(StringEntityProvider.class)); when(application.getFactories()).thenReturn(newHashSet(messageBodyWriterFactory)); publisher.publish(application); verify(providers, never()).addMessageBodyWriter(StringEntityProvider.class); verify(providers).addMessageBodyWriter(messageBodyWriterFactory); }
@Test public void publishesMethodInvokerFilterWithFactoryAndOverridesPerRequestMethodInvokerFilterThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory methodInvokerFilterFactory = mockObjectFactory(AllMatchesMethodInvokerFilter.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesMethodInvokerFilter.class)); when(application.getFactories()).thenReturn(newHashSet(methodInvokerFilterFactory)); publisher.publish(application); verify(providers, never()).addMethodInvokerFilter(AllMatchesMethodInvokerFilter.class); verify(providers).addMethodInvokerFilter(methodInvokerFilterFactory); }
@Test public void publishesRequestFilterWithFactoryAndOverridesPerRequestRequestFilterThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory requestFilterFactory = mockObjectFactory(AllMatchesRequestFilter.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesRequestFilter.class)); when(application.getFactories()).thenReturn(newHashSet(requestFilterFactory)); publisher.publish(application); verify(providers, never()).addRequestFilter(AllMatchesRequestFilter.class); verify(providers).addRequestFilter(requestFilterFactory); }
@Test public void publishesResponseFilterWithFactoryAndOverridesPerRequestResponseFilterThroughEverrestApplication() { EverrestApplication application = mock(EverrestApplication.class); ObjectFactory responseFilterFactory = mockObjectFactory(AllMatchesResponseFilter.class); when(application.getClasses()).thenReturn(newHashSet(AllMatchesResponseFilter.class)); when(application.getFactories()).thenReturn(newHashSet(responseFilterFactory)); publisher.publish(application); verify(providers, never()).addResponseFilter(AllMatchesResponseFilter.class); verify(providers).addResponseFilter(responseFilterFactory); }