use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testProviderOrderSemiAutomatic.
@Test
public void testProviderOrderSemiAutomatic() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager();
config.register(MidPriorityProvider.class, 50);
config.register(LowPriorityProvider.class, 2000);
config.register(HighPriorityProvider.class);
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> allProviders = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<>());
final Iterator<WriterInterceptor> iterator = allProviders.iterator();
assertEquals(MidPriorityProvider.class, iterator.next().getClass());
assertEquals(HighPriorityProvider.class, iterator.next().getClass());
assertEquals(LowPriorityProvider.class, iterator.next().getClass());
assertFalse(iterator.hasNext());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testProviderOrderAutomatic.
@Test
public void testProviderOrderAutomatic() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager();
config.register(MidPriorityProvider.class);
config.register(LowPriorityProvider.class);
config.register(HighPriorityProvider.class);
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> allProviders = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<WriterInterceptor>());
final Iterator<WriterInterceptor> iterator = allProviders.iterator();
assertEquals(HighPriorityProvider.class, iterator.next().getClass());
assertEquals(MidPriorityProvider.class, iterator.next().getClass());
assertEquals(LowPriorityProvider.class, iterator.next().getClass());
assertFalse(iterator.hasNext());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testBinderConfiguringFeature.
@Test
public void testBinderConfiguringFeature() throws Exception {
config.register(ContractBinderFeature.class);
final InjectionManager injectionManager = Injections.createInjectionManager();
config.configureMetaProviders(injectionManager);
assertTrue(config.isEnabled(ContractBinderFeature.class));
assertEquals(1, config.getInstances().size());
assertSame(ContractBinder.class, config.getInstances().iterator().next().getClass());
final Contract service = injectionManager.getInstance(Contract.class);
assertNotNull(service);
assertSame(Service.class, service.getClass());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testProviderOrderDifForContracts.
@Test
@SuppressWarnings("unchecked")
public void testProviderOrderDifForContracts() throws Exception {
final Map<Class<?>, Integer> contracts = new IdentityHashMap<Class<?>, Integer>();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 2000);
config.register(MidPriorityProvider.class, contracts);
contracts.clear();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 1000);
config.register(LowPriorityProvider.class, contracts);
contracts.clear();
contracts.put(WriterInterceptor.class, ContractProvider.NO_PRIORITY);
contracts.put(ReaderInterceptor.class, 3000);
config.register(HighPriorityProvider.class, contracts);
contracts.clear();
final InjectionManager injectionManager = Injections.createInjectionManager();
ProviderBinder.bindProviders(config.getComponentBag(), injectionManager);
final Iterable<WriterInterceptor> writerInterceptors = Providers.getAllProviders(injectionManager, WriterInterceptor.class, new RankedComparator<WriterInterceptor>());
final Iterator<WriterInterceptor> writerIterator = writerInterceptors.iterator();
assertEquals(HighPriorityProvider.class, writerIterator.next().getClass());
assertEquals(MidPriorityProvider.class, writerIterator.next().getClass());
assertEquals(LowPriorityProvider.class, writerIterator.next().getClass());
assertFalse(writerIterator.hasNext());
final Iterable<ReaderInterceptor> readerInterceptors = Providers.getAllProviders(injectionManager, ReaderInterceptor.class, new RankedComparator<ReaderInterceptor>());
final Iterator<ReaderInterceptor> readerIterator = readerInterceptors.iterator();
assertEquals(LowPriorityProvider.class, readerIterator.next().getClass());
assertEquals(MidPriorityProvider.class, readerIterator.next().getClass());
assertEquals(HighPriorityProvider.class, readerIterator.next().getClass());
assertFalse(readerIterator.hasNext());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class BeanParamMemoryLeakTest method testBeanParam.
@Test
public void testBeanParam() throws Exception {
initiateWebApplication(BeanParamInjectionResource.class);
final InjectionManager injectionManager = app().getInjectionManager();
if (!(injectionManager instanceof HK2InjectionManager)) {
throw new RuntimeException("Bean Manager is not an injection manager");
}
HK2InjectionManager hk2BeanManager = (HK2InjectionManager) injectionManager;
ServiceLocator serviceLocator = hk2BeanManager.getServiceLocator();
// we do not expect any descriptor registered yet
assertEquals(0, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// now make one registered via this call
assertEquals("one", resource("/jaxrs?q=one").getEntity());
// make sure it got registered
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// make another call
assertEquals("two", resource("/jaxrs?q=two").getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
// and some more
for (int i = 0; i < 20; i++) {
assertEquals(Integer.toString(i), resource("/jaxrs?q=" + i).getEntity());
assertEquals(1, serviceLocator.getDescriptors(new ParameterBeanFilter()).size());
}
}
Aggregations