This is an automated email from the ASF dual-hosted git repository. dmvolod pushed a commit to branch camel-2.23.x in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/camel-2.23.x by this push: new 534d4b2 CAMEL-13005: olingo4 component serviceUri not set 534d4b2 is described below commit 534d4b2cb87ac16d9def40577af4fa0756581e26 Author: Dmitry Volodin <dmvo...@gmail.com> AuthorDate: Fri Dec 14 20:21:06 2018 +0300 CAMEL-13005: olingo4 component serviceUri not set --- .../component/olingo4/api/impl/Olingo4AppImpl.java | 2 +- .../camel/component/olingo4/Olingo4Endpoint.java | 2 + .../olingo4/AbstractOlingo4TestSupport.java | 2 +- .../component/olingo4/Olingo4ComponentTest.java | 78 +++++++++++----------- .../camel/component/olingo4/Olingo4RouteTest.java | 49 ++++++++++++++ 5 files changed, 92 insertions(+), 41 deletions(-) diff --git a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java index 79f26b6..62bc8ab 100644 --- a/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java +++ b/components/camel-olingo4/camel-olingo4-api/src/main/java/org/apache/camel/component/olingo4/api/impl/Olingo4AppImpl.java @@ -194,7 +194,7 @@ public final class Olingo4AppImpl implements Olingo4App { @Override public void setServiceUri(String serviceUri) { if (serviceUri == null || serviceUri.isEmpty()) { - throw new IllegalArgumentException("serviceUri"); + throw new IllegalArgumentException("serviceUri is not set"); } this.serviceUri = serviceUri.endsWith(SEPARATOR) ? serviceUri.substring(0, serviceUri.length() - 1) : serviceUri; } diff --git a/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Endpoint.java b/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Endpoint.java index 94517ea..109bfba 100644 --- a/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Endpoint.java +++ b/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Endpoint.java @@ -43,6 +43,7 @@ public class Olingo4Endpoint extends AbstractApiEndpoint<Olingo4ApiName, Olingo4 protected static final String RESOURCE_PATH_PROPERTY = "resourcePath"; protected static final String RESPONSE_HANDLER_PROPERTY = "responseHandler"; + protected static final String SERVICE_URI_PROPERTY = "serviceUri"; private static final String KEY_PREDICATE_PROPERTY = "keyPredicate"; private static final String QUERY_PARAMS_PROPERTY = "queryParams"; @@ -73,6 +74,7 @@ public class Olingo4Endpoint extends AbstractApiEndpoint<Olingo4ApiName, Olingo4 // avoid adding edm as queryParam endpointPropertyNames.add(EDM_PROPERTY); endpointPropertyNames.add(ENDPOINT_HTTP_HEADERS_PROPERTY); + endpointPropertyNames.add(SERVICE_URI_PROPERTY); } public Producer createProducer() throws Exception { diff --git a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/AbstractOlingo4TestSupport.java b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/AbstractOlingo4TestSupport.java index c514af0..1f81c24 100644 --- a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/AbstractOlingo4TestSupport.java +++ b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/AbstractOlingo4TestSupport.java @@ -38,7 +38,7 @@ import org.apache.olingo.client.api.domain.ClientObjectFactory; import org.apache.olingo.client.core.ODataClientFactory; /** - * Abstract base class for Olingo Integration tests generated by Camel API + * Abstract base class for Olingo 4.0 Integration tests generated by Camel API * component maven plugin. */ public class AbstractOlingo4TestSupport extends CamelTestSupport { diff --git a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentTest.java b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentTest.java index 61a071d..4300553 100644 --- a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentTest.java +++ b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4ComponentTest.java @@ -78,50 +78,50 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { final Map<String, Object> headers = new HashMap<>(); // Read metadata ($metadata) object - final Edm metadata = (Edm)requestBodyAndHeaders("direct://readmetadata", null, headers); + final Edm metadata = (Edm)requestBodyAndHeaders("direct:readmetadata", null, headers); assertNotNull(metadata); assertEquals(1, metadata.getSchemas().size()); // Read service document object - final ClientServiceDocument document = (ClientServiceDocument)requestBodyAndHeaders("direct://readdocument", null, headers); + final ClientServiceDocument document = (ClientServiceDocument)requestBodyAndHeaders("direct:readdocument", null, headers); assertNotNull(document); assertTrue(document.getEntitySets().size() > 1); LOG.info("Service document has {} entity sets", document.getEntitySets().size()); // Read entity set of the People object - final ClientEntitySet entities = (ClientEntitySet)requestBodyAndHeaders("direct://readentities", null, headers); + final ClientEntitySet entities = (ClientEntitySet)requestBodyAndHeaders("direct:readentities", null, headers); assertNotNull(entities); assertEquals(5, entities.getEntities().size()); // Read object count with query options passed through header - final Long count = (Long)requestBodyAndHeaders("direct://readcount", null, headers); + final Long count = (Long)requestBodyAndHeaders("direct:readcount", null, headers); assertEquals(20, count.intValue()); - final ClientPrimitiveValue value = (ClientPrimitiveValue)requestBodyAndHeaders("direct://readvalue", null, headers); + final ClientPrimitiveValue value = (ClientPrimitiveValue)requestBodyAndHeaders("direct:readvalue", null, headers); LOG.info("Client value \"{}\" has type {}", value, value.getTypeName()); assertEquals("Male", value.asPrimitive().toString()); - final ClientPrimitiveValue singleProperty = (ClientPrimitiveValue)requestBodyAndHeaders("direct://readsingleprop", null, headers); + final ClientPrimitiveValue singleProperty = (ClientPrimitiveValue)requestBodyAndHeaders("direct:readsingleprop", null, headers); assertTrue(singleProperty.isPrimitive()); assertEquals("San Francisco International Airport", singleProperty.toString()); - final ClientComplexValue complexProperty = (ClientComplexValue)requestBodyAndHeaders("direct://readcomplexprop", null, headers); + final ClientComplexValue complexProperty = (ClientComplexValue)requestBodyAndHeaders("direct:readcomplexprop", null, headers); assertTrue(complexProperty.isComplex()); assertEquals("San Francisco", complexProperty.get("City").getComplexValue().get("Name").getValue().toString()); - final ClientEntity entity = (ClientEntity)requestBodyAndHeaders("direct://readentitybyid", null, headers); + final ClientEntity entity = (ClientEntity)requestBodyAndHeaders("direct:readentitybyid", null, headers); assertNotNull(entity); assertEquals("Russell", entity.getProperty("FirstName").getValue().toString()); - final ClientEntity unbFuncReturn = (ClientEntity)requestBodyAndHeaders("direct://callunboundfunction", null, headers); + final ClientEntity unbFuncReturn = (ClientEntity)requestBodyAndHeaders("direct:callunboundfunction", null, headers); assertNotNull(unbFuncReturn); } @Test public void testReadWithFilter() { // Read entity set with filter of the Airports object - final ClientEntitySet entities = (ClientEntitySet)requestBody("direct://readwithfilter", null); + final ClientEntitySet entities = (ClientEntitySet)requestBody("direct:readwithfilter", null); assertNotNull(entities); assertEquals(1, entities.getEntities().size()); @@ -131,7 +131,7 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { public void testCreateUpdateDelete() throws Exception { final ClientEntity clientEntity = createEntity(); - ClientEntity entity = requestBody("direct://create-entity", clientEntity); + ClientEntity entity = requestBody("direct:create-entity", clientEntity); assertNotNull(entity); assertEquals("Lewis", entity.getProperty("FirstName").getValue().toString()); assertEquals("", entity.getProperty("MiddleName").getValue().toString()); @@ -139,20 +139,20 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { // update clientEntity.getProperties().add(objFactory.newPrimitiveProperty("MiddleName", objFactory.newPrimitiveValueBuilder().buildString("Lewis"))); - HttpStatusCode status = requestBody("direct://update-entity", clientEntity); + HttpStatusCode status = requestBody("direct:update-entity", clientEntity); assertNotNull("Update status", status); assertEquals("Update status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Update entity status: {}", status); // delete - status = requestBody("direct://delete-entity", null); + status = requestBody("direct:delete-entity", null); assertNotNull("Delete status", status); assertEquals("Delete status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Delete status: {}", status); // check for delete try { - requestBody("direct://read-deleted-entity", null); + requestBody("direct:read-deleted-entity", null); } catch (CamelExecutionException e) { assertEquals("Resource Not Found [HTTP/1.1 404 Not Found]", e.getCause().getMessage()); } @@ -160,7 +160,7 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { @Test public void testCreateUpdateDeleteFromJson() throws Exception { - ClientEntity entity = requestBody("direct://create-entity", TEST_CREATE_JSON); + ClientEntity entity = requestBody("direct:create-entity", TEST_CREATE_JSON); assertNotNull(entity); assertEquals("Lewis", entity.getProperty("FirstName").getValue().toString()); assertEquals("Black", entity.getProperty("LastName").getValue().toString()); @@ -168,20 +168,20 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { assertEquals("", entity.getProperty("MiddleName").getValue().toString()); // update - HttpStatusCode status = requestBody("direct://update-entity", TEST_UPDATE_JSON); + HttpStatusCode status = requestBody("direct:update-entity", TEST_UPDATE_JSON); assertNotNull("Update status", status); assertEquals("Update status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Update entity status: {}", status); // delete - status = requestBody("direct://delete-entity", null); + status = requestBody("direct:delete-entity", null); assertNotNull("Delete status", status); assertEquals("Delete status", HttpStatusCode.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Delete status: {}", status); // check for delete try { - requestBody("direct://read-deleted-entity", null); + requestBody("direct:read-deleted-entity", null); } catch (CamelExecutionException e) { assertEquals("Resource Not Found [HTTP/1.1 404 Not Found]", e.getCause().getMessage()); } @@ -232,7 +232,7 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { batchParts.add(Olingo4BatchQueryRequest.resourcePath(TEST_CREATE_PEOPLE).resourceUri(TEST_SERVICE_BASE_URL).build()); // execute batch request - final List<Olingo4BatchResponse> responseParts = requestBody("direct://batch", batchParts); + final List<Olingo4BatchResponse> responseParts = requestBody("direct:batch", batchParts); assertNotNull("Batch response", responseParts); assertEquals("Batch responses expected", 8, responseParts.size()); @@ -275,7 +275,7 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { @Test public void testEndpointHttpHeaders() throws Exception { final Map<String, Object> headers = new HashMap<>(); - final ClientEntity entity = (ClientEntity)requestBodyAndHeaders("direct://read-etag", null, headers); + final ClientEntity entity = (ClientEntity)requestBodyAndHeaders("direct:read-etag", null, headers); MockEndpoint mockEndpoint = getMockEndpoint("mock:check-etag-header"); mockEndpoint.expectedMessageCount(1); @@ -287,11 +287,11 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { Map<String, String> endpointHttpHeaders = new HashMap<>(); endpointHttpHeaders.put("If-Match", entity.getETag()); headers.put("CamelOlingo4.endpointHttpHeaders", endpointHttpHeaders); - requestBodyAndHeaders("direct://delete-with-etag", null, headers); + requestBodyAndHeaders("direct:delete-with-etag", null, headers); // check for deleted entity with ETag try { - requestBody("direct://read-etag", null); + requestBody("direct:read-etag", null); } catch (CamelExecutionException e) { assertStringContains(e.getCause().getMessage(), "The request resource is not found."); } @@ -302,44 +302,44 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport { return new RouteBuilder() { public void configure() { // test routes for read - from("direct://readmetadata").to("olingo4://read/$metadata"); + from("direct:readmetadata").to("olingo4://read/$metadata"); - from("direct://readdocument").to("olingo4://read/"); + from("direct:readdocument").to("olingo4://read/"); - from("direct://readentities").to("olingo4://read/People?$top=5&$orderby=FirstName asc"); + from("direct:readentities").to("olingo4://read/People?$top=5&$orderby=FirstName asc"); - from("direct://readcount").to("olingo4://read/People/$count"); + from("direct:readcount").to("olingo4://read/People/$count"); - from("direct://readvalue").to("olingo4://read/People('russellwhyte')/Gender/$value"); + from("direct:readvalue").to("olingo4://read/People('russellwhyte')/Gender/$value"); - from("direct://readsingleprop").to("olingo4://read/Airports('KSFO')/Name"); + from("direct:readsingleprop").to("olingo4://read/Airports('KSFO')/Name"); - from("direct://readcomplexprop").to("olingo4://read/Airports('KSFO')/Location"); + from("direct:readcomplexprop").to("olingo4://read/Airports('KSFO')/Location"); - from("direct://readentitybyid").to("olingo4://read/People('russellwhyte')"); + from("direct:readentitybyid").to("olingo4://read/People('russellwhyte')"); - from("direct://readwithfilter").to("olingo4://read/Airports?$filter=Name eq 'San Francisco International Airport'"); + from("direct:readwithfilter").to("olingo4://read/Airports?$filter=Name eq 'San Francisco International Airport'"); - from("direct://callunboundfunction").to("olingo4://read/GetNearestAirport(lat=33,lon=-118)"); + from("direct:callunboundfunction").to("olingo4://read/GetNearestAirport(lat=33,lon=-118)"); // test route for create individual entity - from("direct://create-entity").to("olingo4://create/People"); + from("direct:create-entity").to("olingo4://create/People"); // test route for update - from("direct://update-entity").to("olingo4://update/People('lewisblack')"); + from("direct:update-entity").to("olingo4://update/People('lewisblack')"); // test route for delete - from("direct://delete-entity").to("olingo4://delete/People('lewisblack')"); + from("direct:delete-entity").to("olingo4://delete/People('lewisblack')"); // test route for delete - from("direct://read-deleted-entity").to("olingo4://delete/People('lewisblack')"); + from("direct:read-deleted-entity").to("olingo4://delete/People('lewisblack')"); // test route for batch - from("direct://batch").to("olingo4://batch"); + from("direct:batch").to("olingo4://batch"); - from("direct://read-etag").to("olingo4://read/Airlines('AA')").to("mock:check-etag-header"); + from("direct:read-etag").to("olingo4://read/Airlines('AA')").to("mock:check-etag-header"); - from("direct://delete-with-etag").to("olingo4://delete/Airlines('AA')"); + from("direct:delete-with-etag").to("olingo4://delete/Airlines('AA')"); } }; } diff --git a/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4RouteTest.java b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4RouteTest.java new file mode 100644 index 0000000..b616f2d --- /dev/null +++ b/components/camel-olingo4/camel-olingo4-component/src/test/java/org/apache/camel/component/olingo4/Olingo4RouteTest.java @@ -0,0 +1,49 @@ +/** + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.component.olingo4; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.olingo.client.api.domain.ClientEntitySet; +import org.junit.Test; + +public class Olingo4RouteTest extends CamelTestSupport { + protected static final String TEST_SERVICE_BASE_URL = "http://services.odata.org/TripPinRESTierService"; + + @SuppressWarnings("unchecked") + protected <T> T requestBody(String endpoint, Object body) throws CamelExecutionException { + return (T)template().requestBody(endpoint, body); + } + + @Test + public void testRead() throws Exception { + // Read entity set of the People object + final ClientEntitySet entities = (ClientEntitySet)requestBody("direct:readentities", null); + assertNotNull(entities); + assertEquals(20, entities.getEntities().size()); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("direct:readentities").to("olingo4://read/People?serviceUri=" + TEST_SERVICE_BASE_URL); + } + }; + } +}