Search in sources :

Example 46 with InjectionManager

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());
    }
}
Also used : ServiceLocator(org.glassfish.hk2.api.ServiceLocator) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) HK2InjectionManager(org.glassfish.jersey.hk2.HK2InjectionManager) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 47 with InjectionManager

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);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 48 with InjectionManager

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);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 49 with InjectionManager

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());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 50 with InjectionManager

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);
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) ResourceConfig(org.glassfish.jersey.server.ResourceConfig) 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