Search in sources :

Example 6 with DefaultClassResolver

use of org.apache.camel.impl.DefaultClassResolver in project camel by apache.

the class RestSwaggerReaderModelTest method testReaderRead.

@Test
public void testReaderRead() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    config.setTitle("Camel User store");
    config.setLicense("Apache 2.0");
    config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    RestSwaggerReader reader = new RestSwaggerReader();
    Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
    assertNotNull(swagger);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(swagger);
    log.info(json);
    assertTrue(json.contains("\"host\" : \"localhost:8080\""));
    assertTrue(json.contains("\"description\" : \"The user returned\""));
    assertTrue(json.contains("\"$ref\" : \"#/definitions/User\""));
    assertTrue(json.contains("\"x-className\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.User\""));
    assertFalse(json.contains("\"enum\""));
    context.stop();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 7 with DefaultClassResolver

use of org.apache.camel.impl.DefaultClassResolver in project camel by apache.

the class RestSwaggerReaderTest method testReaderRead.

@Test
public void testReaderRead() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    RestSwaggerReader reader = new RestSwaggerReader();
    Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
    assertNotNull(swagger);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(swagger);
    log.info(json);
    assertTrue(json.contains("\"host\" : \"localhost:8080\""));
    assertTrue(json.contains("\"basePath\" : \"/api\""));
    assertTrue(json.contains("\"/hello/bye\""));
    assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
    assertTrue(json.contains("\"/hello/bye/{name}\""));
    assertTrue(json.contains("\"/hello/hi/{name}\""));
    context.stop();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 8 with DefaultClassResolver

use of org.apache.camel.impl.DefaultClassResolver in project camel by apache.

the class OsgiFactoryFinderTest method testFindClass.

@Test
public void testFindClass() throws Exception {
    OsgiFactoryFinder finder = new OsgiFactoryFinder(getBundleContext(), new DefaultClassResolver(), "META-INF/services/org/apache/camel/component/");
    Class<?> clazz = finder.findClass("file_test", "strategy.factory.");
    assertNotNull("We should get the file strategy factory here", clazz);
    try {
        clazz = finder.findClass("nofile", "strategy.factory.");
        fail("We should get exception here");
    } catch (Exception ex) {
        assertTrue("Should get NoFactoryAvailableException", ex instanceof NoFactoryAvailableException);
    }
    try {
        clazz = finder.findClass("file_test", "nostrategy.factory.");
        fail("We should get exception here");
    } catch (Exception ex) {
        assertTrue("Should get IOException", ex instanceof IOException);
    }
}
Also used : DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) IOException(java.io.IOException) NoFactoryAvailableException(org.apache.camel.NoFactoryAvailableException) IOException(java.io.IOException) Test(org.junit.Test)

Example 9 with DefaultClassResolver

use of org.apache.camel.impl.DefaultClassResolver in project camel by apache.

the class RestSwaggerReaderApiDocsTest method testReaderRead.

@Test
public void testReaderRead() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    RestSwaggerReader reader = new RestSwaggerReader();
    Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
    assertNotNull(swagger);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(swagger);
    log.info(json);
    assertTrue(json.contains("\"host\" : \"localhost:8080\""));
    assertTrue(json.contains("\"basePath\" : \"/api\""));
    assertFalse(json.contains("\"/hello/bye\""));
    assertFalse(json.contains("\"summary\" : \"To update the greeting message\""));
    assertFalse(json.contains("\"/hello/bye/{name}\""));
    assertTrue(json.contains("\"/hello/hi/{name}\""));
    context.stop();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Example 10 with DefaultClassResolver

use of org.apache.camel.impl.DefaultClassResolver in project camel by apache.

the class RestSwaggerReaderDayOfWeekTest method testReaderRead.

@Test
public void testReaderRead() throws Exception {
    BeanConfig config = new BeanConfig();
    config.setHost("localhost:8080");
    config.setSchemes(new String[] { "http" });
    config.setBasePath("/api");
    config.setTitle("Day");
    config.setLicense("Apache 2.0");
    config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html");
    RestSwaggerReader reader = new RestSwaggerReader();
    Swagger swagger = reader.read(context.getRestDefinitions(), null, config, context.getName(), new DefaultClassResolver());
    assertNotNull(swagger);
    ObjectMapper mapper = new ObjectMapper();
    mapper.enable(SerializationFeature.INDENT_OUTPUT);
    mapper.setSerializationInclusion(JsonInclude.Include.NON_NULL);
    String json = mapper.writeValueAsString(swagger);
    log.info(json);
    assertTrue(json.contains("\"host\" : \"localhost:8080\""));
    assertTrue(json.contains("\"default\" : \"friday\""));
    assertTrue(json.contains("\"enum\" : [ \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\" ]"));
    assertTrue(json.contains("\"$ref\" : \"#/definitions/DayResponse\""));
    assertTrue(json.contains("\"format\" : \"org.apache.camel.swagger.DayResponse\""));
    assertTrue(json.contains("\"X-Rate-Limit-Limit\" : {"));
    assertTrue(json.contains("\"description\" : \"The number of allowed requests in the current period\""));
    context.stop();
}
Also used : BeanConfig(io.swagger.jaxrs.config.BeanConfig) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Swagger(io.swagger.models.Swagger) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

DefaultClassResolver (org.apache.camel.impl.DefaultClassResolver)15 Test (org.junit.Test)12 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)7 BeanConfig (io.swagger.jaxrs.config.BeanConfig)7 Swagger (io.swagger.models.Swagger)7 CamelContext (org.apache.camel.CamelContext)4 JndiRegistry (org.apache.camel.impl.JndiRegistry)2 IOException (java.io.IOException)1 Endpoint (org.apache.camel.Endpoint)1 NoFactoryAvailableException (org.apache.camel.NoFactoryAvailableException)1 Producer (org.apache.camel.Producer)1 DefaultFactoryFinderResolver (org.apache.camel.impl.DefaultFactoryFinderResolver)1 DefaultPackageScanClassResolver (org.apache.camel.impl.DefaultPackageScanClassResolver)1 DefaultTypeConverter (org.apache.camel.impl.converter.DefaultTypeConverter)1 RestDefinition (org.apache.camel.model.rest.RestDefinition)1 ReflectionInjector (org.apache.camel.util.ReflectionInjector)1 Before (org.junit.Before)1