Search in sources :

Example 6 with ProviderBinder

use of org.glassfish.jersey.internal.inject.ProviderBinder in project jersey by jersey.

the class ContextResolverFactoryTest method setUp.

@Before
public void setUp() {
    final InjectionManager locator = Injections.createInjectionManager(new ContextResolverFactory.Binder(), new Binder());
    final ProviderBinder providerBinder = new ProviderBinder(locator);
    providerBinder.bindClasses(Collections.singleton(CustomIntegerResolverC.class));
    crf = locator.getInstance(ContextResolverFactory.class);
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) AbstractBinder(org.glassfish.jersey.internal.inject.AbstractBinder) ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Before(org.junit.Before)

Example 7 with ProviderBinder

use of org.glassfish.jersey.internal.inject.ProviderBinder in project jersey by jersey.

the class ProviderBinderTest method testCustomRegistration.

@Test
public void testCustomRegistration() {
    InjectionManager injectionManager = Injections.createInjectionManager();
    ProviderBinder providerBinder = new ProviderBinder(injectionManager);
    providerBinder.bindClasses(Child.class);
    providerBinder.bindClasses(NotFilterChild.class);
    ContainerRequestFilter requestFilter = getRequestFilter(injectionManager);
    ContainerRequestFilter requestFilter2 = getRequestFilter(injectionManager);
    assertEquals(requestFilter, requestFilter2);
    ContainerResponseFilter responseFilter = getResponseFilter(injectionManager);
    ContainerResponseFilter responseFilter2 = getResponseFilter(injectionManager);
    assertTrue(responseFilter == responseFilter2);
    assertTrue(responseFilter == requestFilter);
    // only one filter should be registered
    Collection<ContainerResponseFilter> filters = Providers.getCustomProviders(injectionManager, ContainerResponseFilter.class);
    assertEquals(1, filters.size());
    Child child = injectionManager.getInstance(Child.class);
    Child child2 = injectionManager.getInstance(Child.class);
    assertTrue(child != responseFilter);
    assertTrue(child == child2);
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) ContainerResponseFilter(javax.ws.rs.container.ContainerResponseFilter) ContainerRequestFilter(javax.ws.rs.container.ContainerRequestFilter) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

ProviderBinder (org.glassfish.jersey.internal.inject.ProviderBinder)7 InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)6 Test (org.junit.Test)5 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)2 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)2 ContainerRequestFilter (javax.ws.rs.container.ContainerRequestFilter)1 ContainerResponseFilter (javax.ws.rs.container.ContainerResponseFilter)1 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)1 Before (org.junit.Before)1