use of org.apache.camel.CamelContext 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();
}
use of org.apache.camel.CamelContext 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);
}
use of org.apache.camel.CamelContext 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();
}
use of org.apache.camel.CamelContext in project camel by apache.
the class RestSwaggerEndpoint method createProducer.
@Override
public Producer createProducer() throws Exception {
final CamelContext camelContext = getCamelContext();
final Swagger swagger = loadSpecificationFrom(camelContext, specificationUri);
final Map<String, Path> paths = swagger.getPaths();
for (final Entry<String, Path> pathEntry : paths.entrySet()) {
final Path path = pathEntry.getValue();
final Optional<Entry<HttpMethod, Operation>> maybeOperationEntry = path.getOperationMap().entrySet().stream().filter(operationEntry -> operationId.equals(operationEntry.getValue().getOperationId())).findAny();
if (maybeOperationEntry.isPresent()) {
final Entry<HttpMethod, Operation> operationEntry = maybeOperationEntry.get();
final String uriTemplate = pathEntry.getKey();
final HttpMethod httpMethod = operationEntry.getKey();
final String method = httpMethod.name();
final Operation operation = operationEntry.getValue();
return createProducerFor(swagger, operation, method, uriTemplate);
}
}
final String supportedOperations = paths.values().stream().flatMap(p -> p.getOperations().stream()).map(Operation::getOperationId).collect(Collectors.joining(", "));
throw new IllegalArgumentException("The specified operation with ID: `" + operationId + "` cannot be found in the Swagger specification loaded from `" + specificationUri + "`. Operations defined in the specification are: " + supportedOperations);
}
use of org.apache.camel.CamelContext in project camel by apache.
the class RestSwaggerEndpoint method determineBasePath.
String determineBasePath(final Swagger swagger) {
if (isNotEmpty(basePath)) {
return basePath;
}
final String componentBasePath = component().getBasePath();
if (isNotEmpty(componentBasePath)) {
return componentBasePath;
}
final String specificationBasePath = swagger.getBasePath();
if (isNotEmpty(specificationBasePath)) {
return specificationBasePath;
}
final CamelContext camelContext = getCamelContext();
final RestConfiguration specificConfiguration = camelContext.getRestConfiguration(assignedComponentName, false);
if (specificConfiguration != null && isNotEmpty(specificConfiguration.getContextPath())) {
return specificConfiguration.getContextPath();
}
final RestConfiguration restConfiguration = camelContext.getRestConfiguration("rest-swagger", true);
final String restConfigurationBasePath = restConfiguration.getContextPath();
if (isNotEmpty(restConfigurationBasePath)) {
return restConfigurationBasePath;
}
return RestSwaggerComponent.DEFAULT_BASE_PATH;
}
Aggregations