Search in sources :

Example 16 with InjectionManager

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

the class CommonConfigTest method testConfigureFeatureInstanceRecursive.

@Test
public void testConfigureFeatureInstanceRecursive() throws Exception {
    config.register(new RecursiveInstanceFeature());
    InjectionManager injectionManager = Injections.createInjectionManager();
    config.configureMetaProviders(injectionManager);
    assertEquals(0, config.getClasses().size());
    assertEquals(2, config.getInstances().size());
    final Set<Object> pureProviders = config.getComponentBag().getInstances(ComponentBag.excludeMetaProviders(injectionManager));
    assertEquals(1, pureProviders.size());
    assertSame(CustomReaderA.class, pureProviders.iterator().next().getClass());
}
Also used : InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 17 with InjectionManager

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

the class CommonConfigTest method testProviderOrderManual.

@Test
public void testProviderOrderManual() throws Exception {
    final InjectionManager injectionManager = Injections.createInjectionManager();
    config.register(MidPriorityProvider.class, 500);
    config.register(LowPriorityProvider.class, 20);
    config.register(HighPriorityProvider.class, 150);
    ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
    final Iterable<WriterInterceptor> allProviders = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<>());
    final Iterator<WriterInterceptor> iterator = allProviders.iterator();
    assertEquals(LowPriorityProvider.class, iterator.next().getClass());
    assertEquals(HighPriorityProvider.class, iterator.next().getClass());
    assertEquals(MidPriorityProvider.class, iterator.next().getClass());
    assertFalse(iterator.hasNext());
}
Also used : WriterInterceptor(javax.ws.rs.ext.WriterInterceptor) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 18 with InjectionManager

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

the class ProviderBinderTest method testProvidersMbwInstance.

@Test
public void testProvidersMbwInstance() {
    InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
    ProviderBinder providerBinder = new ProviderBinder(injectionManager);
    providerBinder.bindInstances(Collections.singleton(new MyProvider()));
    Set<MessageBodyWriter> providers = Providers.getCustomProviders(injectionManager, MessageBodyWriter.class);
    assertEquals(instancesOfType(MyProvider.class, providers).size(), 1);
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 19 with InjectionManager

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

the class ProviderBinderTest method testServicesMbr.

@Test
public void testServicesMbr() {
    InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
    Set<MessageBodyReader> providers = Providers.getProviders(injectionManager, MessageBodyReader.class);
    assertTrue(providers.size() > 0);
}
Also used : MessageBodyReader(javax.ws.rs.ext.MessageBodyReader) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 20 with InjectionManager

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

the class ProviderBinderTest method testProvidersMbw.

@Test
public void testProvidersMbw() {
    InjectionManager injectionManager = Injections.createInjectionManager(initBinders());
    ProviderBinder providerBinder = new ProviderBinder(injectionManager);
    providerBinder.bindClasses(Collections.singleton(MyProvider.class));
    Set<MessageBodyWriter> providers = Providers.getCustomProviders(injectionManager, MessageBodyWriter.class);
    final Collection<MyProvider> myProviders = instancesOfType(MyProvider.class, providers);
    assertEquals(1, myProviders.size());
}
Also used : ProviderBinder(org.glassfish.jersey.internal.inject.ProviderBinder) MessageBodyWriter(javax.ws.rs.ext.MessageBodyWriter) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Aggregations

InjectionManager (org.glassfish.jersey.internal.inject.InjectionManager)50 Test (org.junit.Test)41 WadlGenerator (org.glassfish.jersey.server.wadl.WadlGenerator)10 AbstractBinder (org.glassfish.jersey.internal.inject.AbstractBinder)8 ProviderBinder (org.glassfish.jersey.internal.inject.ProviderBinder)7 MessageBodyReader (javax.ws.rs.ext.MessageBodyReader)5 File (java.io.File)4 URL (java.net.URL)4 Properties (java.util.Properties)4 WriterInterceptor (javax.ws.rs.ext.WriterInterceptor)4 ServiceLocator (org.glassfish.hk2.api.ServiceLocator)4 MessageBodyWriter (javax.ws.rs.ext.MessageBodyWriter)3 JerseyTest (org.glassfish.jersey.test.JerseyTest)3 ArrayList (java.util.ArrayList)2 Collection (java.util.Collection)2 Collections (java.util.Collections)2 IdentityHashMap (java.util.IdentityHashMap)2 Iterator (java.util.Iterator)2 List (java.util.List)2 Function (java.util.function.Function)2