Search in sources :

Example 1 with InjectionManager

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

the class WadlGeneratorConfigTest method testBuildWadlGeneratorFromDescriptions.

@Test
public void testBuildWadlGeneratorFromDescriptions() {
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager();
    final String propValue = "bar";
    WadlGeneratorConfig config = WadlGeneratorConfig.generator(MyWadlGenerator.class).prop("foo", propValue).build();
    WadlGenerator wadlGenerator = config.createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
    Assert.assertEquals(((MyWadlGenerator) wadlGenerator).getFoo(), propValue);
    final String propValue2 = "baz";
    config = WadlGeneratorConfig.generator(MyWadlGenerator.class).prop("foo", propValue).generator(MyWadlGenerator2.class).prop("bar", propValue2).build();
    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 2 with InjectionManager

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

the class WadlGeneratorConfigurationLoaderTest method testLoadConfigClass.

@Test
public void testLoadConfigClass() throws URISyntaxException {
    final ResourceConfig resourceConfig = new ResourceConfig();
    resourceConfig.property(ServerProperties.WADL_GENERATOR_CONFIG, MyWadlGeneratorConfig.class.getName());
    final InjectionManager locator = InjectionManagerFactory.createInjectionManager(resourceConfig.getProperties());
    final WadlGenerator wadlGenerator = WadlGeneratorConfigLoader.loadWadlGeneratorsFromConfig(resourceConfig.getProperties()).createWadlGenerator(locator);
    Assert.assertEquals(MyWadlGenerator.class, wadlGenerator.getClass());
}
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)

Example 3 with InjectionManager

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

the class WadlGeneratorLoaderTest method testLoadFileFromClasspathRelative.

@Test
public void testLoadFileFromClasspathRelative() throws Exception {
    final InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
    final Properties props = new Properties();
    props.put("testFile", "classpath:testfile.xml");
    final WadlGeneratorDescription description = new WadlGeneratorDescription(MyWadlGenerator2.class, props);
    final WadlGenerator wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, description);
    Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
    final URL resource = getClass().getResource("testfile.xml");
    Assert.assertEquals(new File(resource.toURI()).getAbsolutePath(), ((MyWadlGenerator2) wadlGenerator).getTestFile().getAbsolutePath());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 4 with InjectionManager

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

the class WadlGeneratorLoaderTest method testLoadFileFromClasspathAbsolute.

@Test
public void testLoadFileFromClasspathAbsolute() throws Exception {
    final InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
    final Properties props = new Properties();
    final String path = "classpath:/" + getClass().getPackage().getName().replaceAll("\\.", "/") + "/testfile.xml";
    props.put("testFile", path);
    final WadlGeneratorDescription description = new WadlGeneratorDescription(MyWadlGenerator2.class, props);
    final WadlGenerator wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, description);
    Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
    final URL resource = getClass().getResource("testfile.xml");
    Assert.assertEquals(new File(resource.toURI()).getAbsolutePath(), ((MyWadlGenerator2) wadlGenerator).getTestFile().getAbsolutePath());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) InjectionManager(org.glassfish.jersey.internal.inject.InjectionManager) Test(org.junit.Test)

Example 5 with InjectionManager

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

the class WadlGeneratorLoaderTest method testLoadFileFromAbsolutePath.

@Test
public void testLoadFileFromAbsolutePath() throws Exception {
    final InjectionManager injectionManager = InjectionManagerFactory.createInjectionManager();
    final URL resource = getClass().getResource("testfile.xml");
    final Properties props = new Properties();
    final String path = new File(resource.toURI()).getAbsolutePath();
    props.put("testFile", path);
    final WadlGeneratorDescription description = new WadlGeneratorDescription(MyWadlGenerator2.class, props);
    final WadlGenerator wadlGenerator = WadlGeneratorLoader.loadWadlGeneratorDescriptions(injectionManager, description);
    Assert.assertEquals(MyWadlGenerator2.class, wadlGenerator.getClass());
    Assert.assertEquals(new File(resource.toURI()).getAbsolutePath(), ((MyWadlGenerator2) wadlGenerator).getTestFile().getAbsolutePath());
}
Also used : WadlGenerator(org.glassfish.jersey.server.wadl.WadlGenerator) Properties(java.util.Properties) File(java.io.File) URL(java.net.URL) 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