This is an automated email from the ASF dual-hosted git repository. dmvolod pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push: new 4ac1882 CAMEL-13062: olingo2 component serviceUri not set 4ac1882 is described below commit 4ac1882ad7982da2632accd6ca2661a686e899bd Author: Dmitry Volodin <dmvo...@gmail.com> AuthorDate: Tue Jan 15 18:38:06 2019 +0300 CAMEL-13062: olingo2 component serviceUri not set --- .../component/olingo2/api/impl/Olingo2AppImpl.java | 2 +- .../camel/component/olingo2/Olingo2Endpoint.java | 2 + .../olingo2/AbstractOlingo2TestSupport.java | 2 +- .../component/olingo2/Olingo2ComponentTest.java | 32 ++++---- .../camel/component/olingo2/Olingo2RouteTest.java | 88 ++++++++++++++++++++++ 5 files changed, 108 insertions(+), 18 deletions(-) diff --git a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java index adf7d99..43a18fa 100644 --- a/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java +++ b/components/camel-olingo2/camel-olingo2-api/src/main/java/org/apache/camel/component/olingo2/api/impl/Olingo2AppImpl.java @@ -174,7 +174,7 @@ public final class Olingo2AppImpl implements Olingo2App { @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-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java index e980b89..753acd7 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java +++ b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Endpoint.java @@ -43,6 +43,7 @@ public class Olingo2Endpoint extends AbstractApiEndpoint<Olingo2ApiName, Olingo2 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"; @@ -74,6 +75,7 @@ public class Olingo2Endpoint extends AbstractApiEndpoint<Olingo2ApiName, Olingo2 // 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-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java index 876db96..48c49db 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2TestSupport.java @@ -23,8 +23,8 @@ import java.util.Properties; import org.apache.camel.CamelContext; import org.apache.camel.CamelExecutionException; -import org.apache.camel.test.junit4.CamelTestSupport; import org.apache.camel.support.IntrospectionSupport; +import org.apache.camel.test.junit4.CamelTestSupport; /** * Abstract base class for Olingo Integration tests generated by Camel API component maven plugin. diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentTest.java index beb12c1..a1b27fa 100644 --- a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentTest.java +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentTest.java @@ -94,7 +94,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { final Map<String, Object> headers = new HashMap<>(); // read ServiceDocument - final ServiceDocument document = requestBodyAndHeaders("direct://READSERVICEDOC", null, headers); + final ServiceDocument document = requestBodyAndHeaders("direct:READSERVICEDOC", null, headers); assertNotNull(document); assertFalse("ServiceDocument entity sets", document.getEntitySetsInfo().isEmpty()); LOG.info("Service document has {} entity sets", document.getEntitySetsInfo().size()); @@ -105,7 +105,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { headers.put("CamelOlingo2.queryParams", queryParams); // read ODataFeed - final ODataFeed manufacturers = requestBodyAndHeaders("direct://READFEED", null, headers); + final ODataFeed manufacturers = requestBodyAndHeaders("direct:READFEED", null, headers); assertNotNull(manufacturers); final List<ODataEntry> manufacturersEntries = manufacturers.getEntries(); assertFalse("Manufacturers empty entries", manufacturersEntries.isEmpty()); @@ -114,7 +114,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { // read ODataEntry headers.clear(); headers.put(Olingo2Constants.PROPERTY_PREFIX + "keyPredicate", "'1'"); - final ODataEntry manufacturer = requestBodyAndHeaders("direct://READENTRY", null, headers); + final ODataEntry manufacturer = requestBodyAndHeaders("direct:READENTRY", null, headers); assertNotNull(manufacturer); final Map<String, Object> properties = manufacturer.getProperties(); assertEquals("Manufacturer Id", "1", properties.get(ID_PROPERTY)); @@ -126,7 +126,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { final Map<String, Object> data = getEntityData(); Map<String, Object> address; - final ODataEntry manufacturer = requestBody("direct://CREATE", data); + final ODataEntry manufacturer = requestBody("direct:CREATE", data); assertNotNull("Created Manufacturer", manufacturer); final Map<String, Object> properties = manufacturer.getProperties(); assertEquals("Created Manufacturer Id", "123", properties.get(ID_PROPERTY)); @@ -137,13 +137,13 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { address = (Map<String, Object>)data.get("Address"); address.put("Street", "Main Street"); - HttpStatusCodes status = requestBody("direct://UPDATE", data); + HttpStatusCodes status = requestBody("direct:UPDATE", data); assertNotNull("Update status", status); assertEquals("Update status", HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Update status: {}", status); // delete - status = requestBody("direct://DELETE", null); + status = requestBody("direct:DELETE", null); assertNotNull("Delete status", status); assertEquals("Delete status", HttpStatusCodes.NO_CONTENT.getStatusCode(), status.getStatusCode()); LOG.info("Delete status: {}", status); @@ -205,7 +205,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_CREATE_MANUFACTURER).build()); // execute batch request - final List<Olingo2BatchResponse> responseParts = requestBody("direct://BATCH", batchParts); + final List<Olingo2BatchResponse> responseParts = requestBody("direct:BATCH", batchParts); assertNotNull("Batch response", responseParts); assertEquals("Batch responses expected", 9, responseParts.size()); @@ -252,39 +252,39 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport { return new RouteBuilder() { public void configure() { // test routes for read - from("direct://READSERVICEDOC") + from("direct:READSERVICEDOC") .to("olingo2://read/"); - from("direct://READFEED") + from("direct:READFEED") .to("olingo2://read/Manufacturers?$orderBy=Name%20asc"); - from("direct://READENTRY") + from("direct:READENTRY") .to("olingo2://read/DefaultContainer.Manufacturers"); // test route for create - from("direct://CREATE") + from("direct:CREATE") .to("olingo2://create/Manufacturers"); // test route for update - from("direct://UPDATE") + from("direct:UPDATE") .to("olingo2://update/Manufacturers('123')"); // test route for delete - from("direct://DELETE") + from("direct:DELETE") .to("olingo2://delete/Manufacturers('123')"); /* // test route for merge - from("direct://MERGE") + from("direct:MERGE") .to("olingo2://merge"); // test route for patch - from("direct://PATCH") + from("direct:PATCH") .to("olingo2://patch"); */ // test route for batch - from("direct://BATCH") + from("direct:BATCH") .to("olingo2://batch"); } diff --git a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java new file mode 100644 index 0000000..5af29fa --- /dev/null +++ b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java @@ -0,0 +1,88 @@ +/** + * 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.olingo2; + +import java.util.HashMap; +import java.util.Map; + +import org.apache.camel.CamelExecutionException; +import org.apache.camel.builder.RouteBuilder; +import org.apache.camel.component.olingo2.api.Olingo2App; +import org.apache.camel.component.olingo2.internal.Olingo2Constants; +import org.apache.camel.test.AvailablePortFinder; +import org.apache.camel.test.junit4.CamelTestSupport; +import org.apache.olingo.odata2.api.ep.entry.ODataEntry; +import org.junit.AfterClass; +import org.junit.BeforeClass; +import org.junit.Test; + +public class Olingo2RouteTest extends CamelTestSupport { + private static final int PORT = AvailablePortFinder.getNextAvailable(); + private static final String TEST_SERVICE_URL = "http://localhost:" + PORT + "/MyFormula.svc"; + private static final String ID_PROPERTY = "Id"; + + private static Olingo2App olingoApp; + private static Olingo2SampleServer server; + + @BeforeClass + public static void beforeClass() throws Exception { + startServers(PORT); + Olingo2SampleServer.generateSampleData(TEST_SERVICE_URL); + } + + @AfterClass + public static void afterClass() throws Exception { + if (olingoApp != null) { + olingoApp.close(); + } + if (server != null) { + server.stop(); + server.destroy(); + } + } + + protected static void startServers(int port) throws Exception { + server = new Olingo2SampleServer(port, "/olingo2_ref"); + server.start(); + } + + @SuppressWarnings("unchecked") + protected <T> T requestBodyAndHeaders(String endpointUri, Object body, Map<String, Object> headers) + throws CamelExecutionException { + return (T) template().requestBodyAndHeaders(endpointUri, body, headers); + } + + @Test + public void testRead() throws Exception { + final Map<String, Object> headers = new HashMap<>(); + + headers.put(Olingo2Constants.PROPERTY_PREFIX + "keyPredicate", "'1'"); + final ODataEntry manufacturer = requestBodyAndHeaders("direct:READENTRY", null, headers); + assertNotNull(manufacturer); + final Map<String, Object> properties = manufacturer.getProperties(); + assertEquals("Manufacturer Id", "1", properties.get(ID_PROPERTY)); + } + + @Override + protected RouteBuilder createRouteBuilder() throws Exception { + return new RouteBuilder() { + public void configure() { + from("direct:READENTRY").to("olingo2://read/DefaultContainer.Manufacturers?serviceUri=" + TEST_SERVICE_URL); + } + }; + } +}