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());
}
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromDescriptionsWithTypes.
@Test
public void testBuildWadlGeneratorFromDescriptionsWithTypes() {
WadlGeneratorConfig config = WadlGeneratorConfig.generator(MyWadlGenerator3.class).prop("foo", "string").prop("bar", new Bar()).build();
final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator3.class, wadlGenerator.getClass());
MyWadlGenerator3 g = (MyWadlGenerator3) wadlGenerator;
Assert.assertNotNull(g.foo);
Assert.assertEquals(g.foo.s, "string");
Assert.assertNotNull(g.bar);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class WadlGeneratorConfigTest method testCustomWadlGeneratorConfig.
@Test
public void testCustomWadlGeneratorConfig() {
final String propValue = "someValue";
final String propValue2 = "baz";
class MyWadlGeneratorConfig extends WadlGeneratorConfig {
@Override
public List<WadlGeneratorDescription> configure() {
return generator(MyWadlGenerator.class).prop("foo", propValue).generator(MyWadlGenerator2.class).prop("bar", propValue2).descriptions();
}
}
final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
WadlGeneratorConfig config = new MyWadlGeneratorConfig();
WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
final MyWadlGenerator2 wadlGenerator2 = (MyWadlGenerator2) wadlGenerator;
Assert.assertEquals(wadlGenerator2.getBar(), propValue2);
Assert.assertEquals(MyWadlGenerator.class, wadlGenerator2.getDelegate().getClass());
Assert.assertEquals(((MyWadlGenerator) wadlGenerator2.getDelegate()).getFoo(), propValue);
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromGenerators.
@Test
public void testBuildWadlGeneratorFromGenerators() {
final Class<MyWadlGenerator> generator = MyWadlGenerator.class;
final Class<MyWadlGenerator2> generator2 = MyWadlGenerator2.class;
WadlGeneratorConfig config = WadlGeneratorConfig.generator(generator).generator(generator2).build();
final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
Assert.assertEquals(MyWadlGenerator.class, ((MyWadlGenerator2) wadlGenerator).getDelegate().getClass());
}
use of org.glassfish.jersey.internal.inject.InjectionManager in project jersey by jersey.
the class WadlGeneratorConfigurationLoaderTest method testLoadConfigInstance.
@Test
public void testLoadConfigInstance() {
final WadlGeneratorConfig config = WadlGeneratorConfig.generator(MyWadlGenerator.class).build();
final ResourceConfig resourceConfig = new ResourceConfig();
resourceConfig.property(ServerProperties.WADL_GENERATOR_CONFIG, config);
final InjectionManager locator = InjectionManagerFactory.createInjectionManager(resourceConfig.getProperties());
final WadlGenerator wadlGenerator = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(resourceConfig.getProperties()).createWadlGenerator(locator);
Assert.assertTrue(wadlGenerator instanceof MyWadlGenerator);
}
Aggregations