Search in sources :

Example 1 with DefaultClassResolver

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

the class NettySharedHttpServerTest method createRegistry.

@Override
protected JndiRegistry createRegistry() throws Exception {
    nettySharedHttpServer = new DefaultNettySharedHttpServer();
    nettySharedHttpServer.setClassResolver(new DefaultClassResolver(context));
    NettySharedHttpServerBootstrapConfiguration configuration = new NettySharedHttpServerBootstrapConfiguration();
    configuration.setPort(getPort());
    configuration.setHost("localhost");
    configuration.setBacklog(20);
    configuration.setKeepAlive(true);
    configuration.setCompression(true);
    nettySharedHttpServer.setNettyServerBootstrapConfiguration(configuration);
    nettySharedHttpServer.start();
    JndiRegistry jndi = super.createRegistry();
    jndi.bind("myNettyServer", nettySharedHttpServer);
    return jndi;
}
Also used : JndiRegistry(org.apache.camel.impl.JndiRegistry) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver)

Example 2 with DefaultClassResolver

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

the class RestSwaggerEndpointTest method shouldComplainForUnknownOperations.

@Test(expected = IllegalArgumentException.class)
public void shouldComplainForUnknownOperations() throws Exception {
    final CamelContext camelContext = mock(CamelContext.class);
    when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver());
    final RestSwaggerComponent component = new RestSwaggerComponent(camelContext);
    final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:unknown", "unknown", component);
    endpoint.createProducer();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Test(org.junit.Test)

Example 3 with DefaultClassResolver

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

the class RestSwaggerEndpointTest method shouldCreateProducers.

@Test
public void shouldCreateProducers() throws Exception {
    final CamelContext camelContext = mock(CamelContext.class);
    when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver());
    final Endpoint endpointDelegate = mock(Endpoint.class);
    when(camelContext.getEndpoint("rest:GET:/v2:/pet/{petId}")).thenReturn(endpointDelegate);
    final Producer delegateProducer = mock(Producer.class);
    when(endpointDelegate.createProducer()).thenReturn(delegateProducer);
    final RestSwaggerComponent component = new RestSwaggerComponent(camelContext);
    component.setHost("http://petstore.swagger.io");
    final RestSwaggerEndpoint endpoint = new RestSwaggerEndpoint("rest-swagger:getPetById", "getPetById", component);
    final Producer producer = endpoint.createProducer();
    assertThat(producer).isSameAs(delegateProducer);
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Endpoint(org.apache.camel.Endpoint) Producer(org.apache.camel.Producer) Test(org.junit.Test)

Example 4 with DefaultClassResolver

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

the class RestSwaggerEndpointTest method shouldLoadSwaggerSpecifications.

@Test
public void shouldLoadSwaggerSpecifications() throws IOException {
    final CamelContext camelContext = mock(CamelContext.class);
    when(camelContext.getClassResolver()).thenReturn(new DefaultClassResolver());
    assertThat(RestSwaggerEndpoint.loadSpecificationFrom(camelContext, RestSwaggerComponent.DEFAULT_SPECIFICATION_URI)).isNotNull();
}
Also used : CamelContext(org.apache.camel.CamelContext) DefaultClassResolver(org.apache.camel.impl.DefaultClassResolver) Test(org.junit.Test)

Example 5 with DefaultClassResolver

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

the class RestSwaggerReaderApiDocsOverrideTest 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);
    assertFalse(json.contains("\"/hello/bye\""));
    assertFalse(json.contains("\"summary\" : \"To update the greeting message\""));
    assertTrue(json.contains("\"/hello/bye/{name}\""));
    assertFalse(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)

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