use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class InjectionManagerTest method testServiceLocatorParent.
@Test
public void testServiceLocatorParent() {
AbstractBinder binder = new AbstractBinder() {
@Override
protected void configure() {
bindAsContract(EnglishGreeting.class);
}
};
ServiceLocator parentLocator = ServiceLocatorUtilities.bind(binder);
InjectionManager injectionManager = new HK2InjectionManager();
injectionManager.initialize(parentLocator);
assertNotNull(injectionManager.getInstance(EnglishGreeting.class));
}
use of org.glassfish.jersey.internal.inject.InjectionManager 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);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class JaxrsProvidersTest method testProviders.
@Test
public void testProviders() throws Exception {
final InjectionManager injectionManager = Injections.createInjectionManager(new MessagingBinders.MessageBodyProviders(null, RuntimeType.SERVER), new Binder());
injectionManager.register(new TestBinder(injectionManager));
TestBinder.initProviders(injectionManager);
RequestScope scope = injectionManager.getInstance(RequestScope.class);
scope.runInScope(new Callable<Object>() {
@Override
public Object call() throws Exception {
Providers instance = injectionManager.getInstance(Providers.class);
assertNotNull(instance);
assertSame(JaxrsProviders.class, instance.getClass());
assertNotNull(instance.getExceptionMapper(Throwable.class));
assertNotNull(instance.getMessageBodyReader(String.class, String.class, new Annotation[0], MediaType.TEXT_PLAIN_TYPE));
assertNotNull(instance.getMessageBodyWriter(String.class, String.class, new Annotation[0], MediaType.TEXT_PLAIN_TYPE));
assertNotNull(instance.getContextResolver(String.class, MediaType.TEXT_PLAIN_TYPE));
return null;
}
});
}
use of org.glassfish.jersey.internal.inject.InjectionManager 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);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class CommonConfigTest method testFeatureInjections.
@Test
public void testFeatureInjections() throws Exception {
config.register(InjectIntoFeatureClass.class).register(new InjectIntoFeatureInstance()).register(new AbstractBinder() {
@Override
protected void configure() {
bind(new InjectMe());
}
});
final InjectionManager injectionManager = Injections.createInjectionManager();
config.configureMetaProviders(injectionManager);
assertThat("Feature instance not injected", config.getProperty("instance-injected").toString(), is("true"));
assertThat("Feature class not injected", config.getProperty("class-injected").toString(), is("true"));
}
Aggregations