This is an automated email from the ASF dual-hosted git repository.
orpiske pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 8b10c79f4b1 (chores) camel-olingo2: Jakarta migration changes
8b10c79f4b1 is described below
commit 8b10c79f4b1f1a5dba1fb32acbd85f5604393e8f
Author: Otavio Rodolfo Piske <[email protected]>
AuthorDate: Wed Jan 18 12:06:23 2023 +0100
(chores) camel-olingo2: Jakarta migration changes
- remove incompatible tests
- added a note about the risk of unexpected behavior
---
.../src/main/docs/olingo2-component.adoc | 6 +
.../olingo2/AbstractOlingo2AppAPITestSupport.java | 2 +-
.../camel/component/olingo2/Olingo2AppAPITest.java | 473 ---------------------
.../olingo2/Olingo2ComponentConsumerTest.java | 378 ----------------
.../olingo2/Olingo2ComponentProducerTest.java | 410 ------------------
.../camel/component/olingo2/Olingo2RouteTest.java | 89 ----
.../camel/component/olingo2/Olingo2TestUtil.java | 2 +-
.../src/test/resources/olingo2_ref/WEB-INF/web.xml | 45 --
8 files changed, 8 insertions(+), 1397 deletions(-)
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/main/docs/olingo2-component.adoc
b/components/camel-olingo2/camel-olingo2-component/src/main/docs/olingo2-component.adoc
index 269012a0704..2b0dcfb6562 100644
---
a/components/camel-olingo2/camel-olingo2-component/src/main/docs/olingo2-component.adoc
+++
b/components/camel-olingo2/camel-olingo2-component/src/main/docs/olingo2-component.adoc
@@ -13,6 +13,12 @@
*{component-header}*
+[NOTE]
+====
+Starting with Camel 4.0, our project has migrated to JakartaEE. Some parts of
Apache Olingo2 may depend on J2EE, which may
+result in unexpected behavior and other runtime problems.
+====
+
The Olingo2 component utilizes http://olingo.apache.org/[Apache Olingo]
version 2.0 APIs to interact with OData 2.0 compliant services.
A number of popular commercial and enterprise vendors and products
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java
index fdd1a805e25..5e35aa18561 100644
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java
+++
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/AbstractOlingo2AppAPITestSupport.java
@@ -44,7 +44,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
public class AbstractOlingo2AppAPITestSupport {
protected static final String SERVICE_NAME = "MyFormula.svc";
- protected static final Logger LOG =
LoggerFactory.getLogger(Olingo2AppAPITest.class);
+ protected static final Logger LOG =
LoggerFactory.getLogger(AbstractOlingo2AppAPITestSupport.class);
protected static final int PORT = AvailablePortFinder.getNextAvailable();
protected static final long TIMEOUT = 100000;
protected static final String MANUFACTURERS = "Manufacturers";
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java
deleted file mode 100644
index f309642844d..00000000000
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2AppAPITest.java
+++ /dev/null
@@ -1,473 +0,0 @@
-/*
- * 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.io.IOException;
-import java.io.InputStream;
-import java.util.ArrayList;
-import java.util.Calendar;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-import java.util.concurrent.TimeUnit;
-
-import org.apache.camel.component.olingo2.api.Olingo2App;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchChangeRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse;
-import org.apache.camel.component.olingo2.api.batch.Operation;
-import org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl;
-import org.apache.camel.component.olingo2.api.impl.SystemQueryOption;
-import org.apache.camel.test.infra.jetty.services.JettyConfiguration;
-import org.apache.camel.test.infra.jetty.services.JettyEmbeddedService;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.edm.EdmEntitySet;
-import org.apache.olingo.odata2.api.edm.EdmEntitySetInfo;
-import org.apache.olingo.odata2.api.ep.EntityProvider;
-import org.apache.olingo.odata2.api.ep.EntityProviderException;
-import org.apache.olingo.odata2.api.ep.EntityProviderReadProperties;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.api.servicedocument.Collection;
-import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.fail;
-
-/**
- * Integration test for {@link
org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl} using the sample
Olingo2
- * Server dynamically downloaded and started during the test.
- */
-public class Olingo2AppAPITest extends AbstractOlingo2AppAPITestSupport {
-
- private static Olingo2App olingoApp;
- private static Edm edm;
- private static Map<String, EdmEntitySet> edmEntitySetMap;
-
- private static final JettyConfiguration JETTY_CONFIGURATION =
createConfiguration();
-
- @RegisterExtension
- public static JettyEmbeddedService service = new
JettyEmbeddedService(JETTY_CONFIGURATION);
-
- @BeforeAll
- public static void beforeClass() {
- try {
- Olingo2TestUtil.generateSampleData(TEST_SERVICE_URL);
- setupClient();
- } catch (IOException e) {
- throw new RuntimeException(e);
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- @AfterAll
- public static void afterClass() {
- if (olingoApp != null) {
- olingoApp.close();
- }
-
- }
-
- protected static void setupClient() throws Exception {
- olingoApp = new Olingo2AppImpl(TEST_SERVICE_URL + "/");
- olingoApp.setContentType(TEST_FORMAT_STRING);
-
- LOG.info("Read Edm ");
- final TestOlingo2ResponseHandler<Edm> responseHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(null, Olingo2AppImpl.METADATA, null, null,
responseHandler);
-
- edm = responseHandler.await();
- LOG.info("Read default EntityContainer: {}",
responseHandler.await().getDefaultEntityContainer().getName());
-
- edmEntitySetMap = new HashMap<>();
- for (EdmEntitySet ees : edm.getEntitySets()) {
- edmEntitySetMap.put(ees.getName(), ees);
- }
-
- // wait for generated data to be registered in server
- Thread.sleep(2000);
- }
-
- @Test
- public void testServiceDocument() throws Exception {
- final TestOlingo2ResponseHandler<ServiceDocument> responseHandler =
new TestOlingo2ResponseHandler<>();
-
- olingoApp.read(null, "", null, null, responseHandler);
-
- final ServiceDocument serviceDocument = responseHandler.await();
- final List<Collection> collections =
serviceDocument.getAtomInfo().getWorkspaces().get(0).getCollections();
- assertEquals(3, collections.size(), "Service Atom Collections");
- LOG.info("Service Atom Collections: {}", collections);
-
- final List<EdmEntitySetInfo> entitySetsInfo =
serviceDocument.getEntitySetsInfo();
- assertEquals(3, entitySetsInfo.size(), "Service Entity Sets");
- LOG.info("Service Document Entries: {}", entitySetsInfo);
- }
-
- @Test
- public void testReadFeed() throws Exception {
- final TestOlingo2ResponseHandler<ODataFeed> responseHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, MANUFACTURERS, null, null, responseHandler);
-
- final ODataFeed dataFeed = responseHandler.await();
- assertNotNull(dataFeed, "Data feed");
- LOG.info("Entries: {}", prettyPrint(dataFeed));
- }
-
- @Test
- public void testReadUnparsedFeed() throws Exception {
- final TestOlingo2ResponseHandler<InputStream> responseHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.uread(edm, MANUFACTURERS, null, null, responseHandler);
-
- final InputStream rawfeed = responseHandler.await();
- assertNotNull(rawfeed, "Data feed");
- // for this test, we just let EP to verify the stream data
- final ODataFeed dataFeed = EntityProvider.readFeed(TEST_FORMAT_STRING,
edmEntitySetMap.get(MANUFACTURERS), rawfeed,
- EntityProviderReadProperties.init().build());
- LOG.info("Entries: {}", prettyPrint(dataFeed));
- }
-
- @Test
- public void testReadEntry() {
- final TestOlingo2ResponseHandler<ODataEntry> responseHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, TEST_MANUFACTURER, null, null, responseHandler);
- final ODataEntry entry = assertDoesNotThrow(() ->
responseHandler.await());
- LOG.info("Single Entry: {}", prettyPrint(entry));
-
- responseHandler.reset();
-
- olingoApp.read(edm, TEST_CAR, null, null, responseHandler);
- final ODataEntry entry1 = assertDoesNotThrow(() ->
responseHandler.await());
- LOG.info("Single Entry: {}", prettyPrint(entry1));
-
- responseHandler.reset();
- final Map<String, String> queryParams = new HashMap<>();
- queryParams.put(SystemQueryOption.$expand.toString(), CARS);
-
- olingoApp.read(edm, TEST_MANUFACTURER, queryParams, null,
responseHandler);
-
- final ODataEntry entryExpanded = assertDoesNotThrow(() ->
responseHandler.await());
- LOG.info("Single Entry with expanded Cars relation: {}",
prettyPrint(entryExpanded));
- }
-
- @Test
- public void testReadUnparsedEntry() throws EntityProviderException {
- final TestOlingo2ResponseHandler<InputStream> responseHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.uread(edm, TEST_MANUFACTURER, null, null, responseHandler);
- InputStream rawentry = assertDoesNotThrow(() ->
responseHandler.await());
- ODataEntry entry = EntityProvider.readEntry(TEST_FORMAT_STRING,
edmEntitySetMap.get(MANUFACTURERS), rawentry,
- EntityProviderReadProperties.init().build());
- LOG.info("Single Entry: {}", prettyPrint(entry));
-
- responseHandler.reset();
-
- olingoApp.uread(edm, TEST_CAR, null, null, responseHandler);
- rawentry = assertDoesNotThrow(() -> responseHandler.await());
- entry = EntityProvider.readEntry(TEST_FORMAT_STRING,
edmEntitySetMap.get(CARS), rawentry,
- EntityProviderReadProperties.init().build());
- LOG.info("Single Entry: {}", prettyPrint(entry));
-
- responseHandler.reset();
- final Map<String, String> queryParams = new HashMap<>();
- queryParams.put(SystemQueryOption.$expand.toString(), CARS);
-
- olingoApp.uread(edm, TEST_MANUFACTURER, queryParams, null,
responseHandler);
-
- rawentry = assertDoesNotThrow(() -> responseHandler.await());
- ODataEntry entryExpanded =
EntityProvider.readEntry(TEST_FORMAT_STRING,
edmEntitySetMap.get(MANUFACTURERS), rawentry,
- EntityProviderReadProperties.init().build());
- LOG.info("Single Entry with expanded Cars relation: {}",
prettyPrint(entryExpanded));
- }
-
- @Test
- public void testReadUpdateProperties() throws Exception {
- // test simple property Manufacturer.Founded
- final TestOlingo2ResponseHandler<Map<String, Object>> propertyHandler
= new TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, null, null,
propertyHandler);
-
- Calendar founded = (Calendar) assertDoesNotThrow(() ->
propertyHandler.await().get(FOUNDED_PROPERTY));
- LOG.info("Founded property {}", founded);
-
- final TestOlingo2ResponseHandler<Calendar> valueHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, TEST_MANUFACTURER_FOUNDED_VALUE, null, null,
valueHandler);
-
- founded = assertDoesNotThrow(() -> valueHandler.await());
- LOG.info("Founded property {}", founded);
-
- final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler = new
TestOlingo2ResponseHandler<>();
- final HashMap<String, Object> properties = new HashMap<>();
- properties.put(FOUNDED_PROPERTY, new Date());
-
- // olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY,
properties, statusHandler);
- // requires a plain Date for XML
- olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_PROPERTY, null, new
Date(), statusHandler);
-
- LOG.info("Founded property updated with status {}",
statusHandler.await().getStatusCode());
-
- statusHandler.reset();
-
- olingoApp.update(edm, TEST_MANUFACTURER_FOUNDED_VALUE, null, new
Date(), statusHandler);
-
- LOG.info("Founded property updated with status {}",
statusHandler.await().getStatusCode());
-
- // test complex property Manufacturer.Address
- propertyHandler.reset();
-
- olingoApp.read(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, null, null,
propertyHandler);
-
- final Map<String, Object> address = assertDoesNotThrow(() ->
propertyHandler.await());
- LOG.info("Address property {}", prettyPrint(address, 0));
-
- statusHandler.reset();
-
- address.clear();
- // Olingo2 sample server MERGE/PATCH behaves like PUT!!!
- // address.put("Street", "Main Street");
- address.put("Street", "Star Street 137");
- address.put("City", "Stuttgart");
- address.put("ZipCode", "70173");
- address.put("Country", "Germany");
-
- // olingoApp.patch(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY,
address, statusHandler);
- olingoApp.merge(edm, TEST_MANUFACTURER_ADDRESS_PROPERTY, null,
address, statusHandler);
-
- LOG.info("Address property updated with status {}",
statusHandler.await().getStatusCode());
- }
-
- @Test
- public void testReadDeleteCreateLinks() throws Exception {
- final TestOlingo2ResponseHandler<List<String>> linksHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, TEST_MANUFACTURER_LINKS_CARS, null, null,
linksHandler);
-
- final List<String> links = linksHandler.await();
- assertFalse(links.isEmpty());
- LOG.info("Read links: {}", links);
-
- final TestOlingo2ResponseHandler<String> linkHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, TEST_CAR_LINK_MANUFACTURER, null, null,
linkHandler);
-
- final String link = linkHandler.await();
- LOG.info("Read link: {}", link);
-
- //Deleting relationships through links is not supported in Olingo2 at
the time of writing this test
- /*
- * final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler =
new
- * TestOlingo2ResponseHandler<HttpStatusCodes>(); final
- * ArrayList<Map<String, Object>> carKeys = new ArrayList<Map<String,
- * Object>>(); for (String carLink : links) { final Matcher matcher =
- * LINK_PATTERN.matcher(carLink); assertTrue("Link pattern " + carLink,
- * matcher.matches()); final String carId = matcher.group(1); final
- * HashMap<String, Object> keys = new HashMap<String, Object>();
- * keys.put(ID_PROPERTY, carId); carKeys.add(keys); // delete
- * manufacturer->car link statusHandler.reset(); final String
- * resourcePath = TEST_MANUFACTURER_LINKS_CARS + "('" + carId + "')";
- * olingoApp.delete(resourcePath, statusHandler);
- * assertEquals("Delete car link " + resourcePath,
- * HttpStatusCodes.OK.getStatusCode(),
- * statusHandler.await().getStatusCode()); } // add links to all Cars
- * statusHandler.reset(); olingoApp.create(edm,
- * TEST_MANUFACTURER_LINKS_CARS, carKeys, statusHandler);
- * assertEquals("Links update",
- * HttpStatusCodes.ACCEPTED.getStatusCode(),
- * statusHandler.await().getStatusCode()); // delete car->manufacturer
- * link statusHandler.reset();
- * olingoApp.delete(TEST_CAR_LINK_MANUFACTURER, statusHandler);
- * assertEquals("Delete manufacturer link " +
- * TEST_CAR_LINK_MANUFACTURER, HttpStatusCodes.OK.getStatusCode(),
- * statusHandler.await().getStatusCode()); // add link to Manufacturer
- * statusHandler.reset(); final HashMap<String, Object> manufacturerKey
- * = new HashMap<String, Object>(); manufacturerKey.put(ID_PROPERTY,
- * "1"); olingoApp.create(edm, TEST_CAR_LINK_MANUFACTURER,
- * manufacturerKey, statusHandler); assertEquals("Link update",
- * HttpStatusCodes.ACCEPTED.getStatusCode(),
- * statusHandler.await().getStatusCode());
- */
- }
-
- @Test
- public void testReadCount() throws Exception {
- final TestOlingo2ResponseHandler<Long> countHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.read(edm, MANUFACTURERS + COUNT_OPTION, null, null,
countHandler);
-
- final Long await1 = assertDoesNotThrow(() -> countHandler.await());
- LOG.info("Manufacturers count: {}", await1);
-
- countHandler.reset();
- olingoApp.read(edm, TEST_MANUFACTURER + COUNT_OPTION, null, null,
countHandler);
-
- final Long await2 = assertDoesNotThrow(() -> countHandler.await());
- LOG.info("Manufacturer count: {}", await2);
-
- countHandler.reset();
- olingoApp.read(edm, TEST_MANUFACTURER_LINKS_CARS + COUNT_OPTION, null,
null, countHandler);
-
- final Long await3 = assertDoesNotThrow(() -> countHandler.await());
- LOG.info("Manufacturers links count: {}", await3);
-
- countHandler.reset();
- olingoApp.read(edm, TEST_CAR_LINK_MANUFACTURER + COUNT_OPTION, null,
null, countHandler);
-
- final Long await4 = assertDoesNotThrow(() -> countHandler.await());
- LOG.info("Manufacturer link count: {}", await4);
- }
-
- @Test
- public void testCreateUpdateDeleteEntry() throws Exception {
-
- // create entry to update
- final TestOlingo2ResponseHandler<ODataEntry> entryHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.create(edm, MANUFACTURERS, null, getEntityData(),
entryHandler);
-
- ODataEntry createdEntry = entryHandler.await();
- LOG.info("Created Entry: {}", prettyPrint(createdEntry));
-
- Map<String, Object> data = getEntityData();
- @SuppressWarnings("unchecked")
- Map<String, Object> address = (Map<String, Object>) data.get(ADDRESS);
-
- data.put("Name", "MyCarManufacturer Renamed");
- address.put("Street", "Main Street");
- final TestOlingo2ResponseHandler<HttpStatusCodes> statusHandler = new
TestOlingo2ResponseHandler<>();
-
- olingoApp.update(edm, TEST_CREATE_MANUFACTURER, null, data,
statusHandler);
- statusHandler.await();
-
- statusHandler.reset();
- data.put("Name", "MyCarManufacturer Patched");
- olingoApp.patch(edm, TEST_CREATE_MANUFACTURER, null, data,
statusHandler);
- statusHandler.await();
-
- entryHandler.reset();
- olingoApp.read(edm, TEST_CREATE_MANUFACTURER, null, null,
entryHandler);
-
- ODataEntry updatedEntry = entryHandler.await();
- LOG.info("Updated Entry successfully: {}", prettyPrint(updatedEntry));
-
- statusHandler.reset();
- olingoApp.delete(TEST_CREATE_MANUFACTURER, null, statusHandler);
-
- HttpStatusCodes statusCode = statusHandler.await();
- LOG.info("Deletion of Entry was successful: {}: {}",
statusCode.getStatusCode(), statusCode.getInfo());
-
- try {
- LOG.info("Verify Delete Entry");
-
- entryHandler.reset();
- olingoApp.read(edm, TEST_CREATE_MANUFACTURER, null, null,
entryHandler);
-
- entryHandler.await();
- fail("Entry not deleted!");
- } catch (Exception e) {
- LOG.info("Deleted entry not found: {}", e.getMessage());
- }
- }
-
- @Test
- public void testBatchRequest() throws Exception {
-
- final List<Olingo2BatchRequest> batchParts = new ArrayList<>();
-
- // Edm query
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(Olingo2AppImpl.METADATA).build());
-
- // feed query
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(MANUFACTURERS).build());
-
- // read
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).build());
-
- // read with expand
- final HashMap<String, String> queryParams = new HashMap<>();
- queryParams.put(SystemQueryOption.$expand.toString(), CARS);
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).queryParams(queryParams).build());
-
- // create
- final Map<String, Object> data = getEntityData();
-
batchParts.add(Olingo2BatchChangeRequest.resourcePath(MANUFACTURERS).contentId(TEST_RESOURCE_CONTENT_ID)
- .operation(Operation.CREATE).body(data).build());
-
- // update
- final Map<String, Object> updateData = new HashMap<>(data);
- @SuppressWarnings("unchecked")
- Map<String, Object> address = (Map<String, Object>)
updateData.get(ADDRESS);
- updateData.put("Name", "MyCarManufacturer Renamed");
- address.put("Street", "Main Street");
-
- batchParts.add(
-
Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.UPDATE).body(updateData).build());
-
- // delete
-
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.DELETE).build());
-
- final TestOlingo2ResponseHandler<List<Olingo2BatchResponse>>
responseHandler = new TestOlingo2ResponseHandler<>();
-
- // read to verify delete
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_CREATE_MANUFACTURER).build());
-
- olingoApp.batch(edm, null, batchParts, responseHandler);
-
- final List<Olingo2BatchResponse> responseParts =
responseHandler.await(15, TimeUnit.MINUTES);
- assertEquals(8, responseParts.size(), "Batch responses expected");
-
- assertNotNull(responseParts.get(0).getBody());
- final ODataFeed feed = (ODataFeed) responseParts.get(1).getBody();
- assertNotNull(feed);
- LOG.info("Batch feed: {}", prettyPrint(feed));
-
- ODataEntry dataEntry = (ODataEntry) responseParts.get(2).getBody();
- assertNotNull(dataEntry);
- LOG.info("Batch read entry: {}", prettyPrint(dataEntry));
-
- dataEntry = (ODataEntry) responseParts.get(3).getBody();
- assertNotNull(dataEntry);
- LOG.info("Batch read entry with expand: {}", prettyPrint(dataEntry));
-
- dataEntry = (ODataEntry) responseParts.get(4).getBody();
- assertNotNull(dataEntry);
- LOG.info("Batch create entry: {}", prettyPrint(dataEntry));
-
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(),
responseParts.get(5).getStatusCode());
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(),
responseParts.get(6).getStatusCode());
-
- assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(),
responseParts.get(7).getStatusCode());
- final Exception exception = (Exception) responseParts.get(7).getBody();
- assertNotNull(exception);
- LOG.info("Batch retrieve deleted entry: {}", exception);
- }
-}
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java
deleted file mode 100644
index 725294c3627..00000000000
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentConsumerTest.java
+++ /dev/null
@@ -1,378 +0,0 @@
-/*
- * 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.io.IOException;
-import java.util.Map;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.ExtendedCamelContext;
-import org.apache.camel.LoggingLevel;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.infra.jetty.services.JettyConfiguration;
-import org.apache.camel.test.infra.jetty.services.JettyEmbeddedService;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import static
org.apache.camel.component.olingo2.AbstractOlingo2AppAPITestSupport.createConfiguration;
-import static org.apache.camel.test.junit5.TestSupport.assertIsInstanceOf;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test class for {@link org.apache.camel.component.olingo2.api.Olingo2App}
APIs.
- * <p>
- * The integration test runs against Apache Olingo 2.0 sample server which is
dynamically installed and started during
- * the test.
- * </p>
- */
-public class Olingo2ComponentConsumerTest extends AbstractOlingo2TestSupport {
-
- private static final int PORT = AvailablePortFinder.getNextAvailable();
- private static final String TEST_SERVICE_URL = "http://localhost:" + PORT
+ "/MyFormula.svc";
-
- private static final JettyConfiguration JETTY_CONFIGURATION =
createConfiguration(PORT);
-
- @RegisterExtension
- public static JettyEmbeddedService service = new
JettyEmbeddedService(JETTY_CONFIGURATION);
-
- public Olingo2ComponentConsumerTest() {
- setDefaultTestProperty("serviceUri", "http://localhost:" + PORT +
"/MyFormula.svc");
- }
-
- @Override
- protected CamelContext createCamelContext() throws Exception {
- CamelContext context = super.createCamelContext();
-
context.adapt(ExtendedCamelContext.class).getBeanIntrospection().setLoggingLevel(LoggingLevel.INFO);
-
context.adapt(ExtendedCamelContext.class).getBeanIntrospection().setExtendedStatistics(true);
- return context;
- }
-
- @BeforeAll
- public static void beforeClass() throws IOException {
- Olingo2TestUtil.generateSampleData(TEST_SERVICE_URL);
-
- }
-
- private void addRouteAndStartContext(RouteBuilder builder) throws
Exception {
- context().addRoutes(builder);
- startCamelContext();
- }
-
- /**
- * Read entity set of the People object and filter already seen items on
subsequent exchanges Use a delay since the
- * mock endpoint does not always get the correct number of exchanges
before being satisfied. Note: - splitResults is
- * set to false since this ensures the first returned message contains all
the results. This is preferred for the
- * purposes of this test. The default will mean the first n messages
contain the results (where n is the result
- * total) then subsequent messages will be empty
- */
- @Test
- public void testConsumerReadFilterAlreadySeen() throws Exception {
- int expectedMsgCount = 3;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-alreadyseen");
- mockEndpoint.expectedMessageCount(expectedMsgCount);
- mockEndpoint.setResultWaitTime(60000);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- from("olingo2://read/Manufacturers?filterAlreadySeen=true&" +
"delay=2&sendEmptyMessageWhenIdle=true&"
- + "splitResult=false")
- .to("mock:consumer-alreadyseen");
- }
- };
- addRouteAndStartContext(builder);
-
- mockEndpoint.assertIsSatisfied();
-
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
-
- if (i == 0) {
- //
- // First polled messages contained all the manufacturers
- //
- assertTrue(body instanceof ODataFeed);
- ODataFeed set = (ODataFeed) body;
- assertTrue(set.getEntries().size() > 0);
- } else {
- //
- // Subsequent polling messages should be empty
- // since the filterAlreadySeen property is true
- //
- assertNull(body);
- }
- }
-
- // should be reflection free
- long counter =
context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getInvokedCounter();
- assertEquals(0, counter);
- }
-
- /**
- * Read entity set of the People object and filter already seen items on
subsequent exchanges Use a delay since the
- * mock endpoint does not always get the correct number of exchanges
before being satisfied. Note: - splitResults is
- * set to false since this ensures the first returned message contains all
the results. - sendEmptyMessageWhenIdle
- * is set to false so only 1 message should even be returned.
- */
- @Test
- public void testConsumerReadFilterAlreadySeenNoEmptyMsgs() throws
Exception {
- int expectedMsgCount = 1;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-alreadyseen");
- //
- // Add 1 to count since we want to wait for full result time
- // before asserting that only 1 message has been delivered
- //
- mockEndpoint.expectedMinimumMessageCount(expectedMsgCount + 1);
- mockEndpoint.setResultWaitTime(6000L);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
- from("olingo2://read/Manufacturers?filterAlreadySeen=true&" +
"delay=2&sendEmptyMessageWhenIdle=false&"
- + "splitResult=false")
- .to("mock:consumer-alreadyseen");
- }
- };
- addRouteAndStartContext(builder);
-
- //
- // Want to wait for entire result time & there should
- // be exactly 1 exchange transmitted to the endpoint
- //
- mockEndpoint.assertIsNotSatisfied();
-
- // Only 1 exchange so this is good!
- assertEquals(1, mockEndpoint.getExchanges().size());
- Object body = mockEndpoint.getExchanges().get(0).getIn().getBody();
-
- //
- // Only polled message contains all the entities
- //
- assertTrue(body instanceof ODataFeed);
- ODataFeed set = (ODataFeed) body;
- assertTrue(set.getEntries().size() > 0);
- }
-
- /**
- * WithPredicate in address FilterAlreadySeen: true SplitResults: true
sendEmptyMessageWhenIdle: true
- *
- * @throws Exception
- */
- @Test
- public void testConsumerReadFilterAlreadySeenWithPredicate1() throws
Exception {
- int expectedMsgCount = 3;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-splitresult-kp-manufacturer");
- mockEndpoint.expectedMinimumMessageCount(expectedMsgCount);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
-
from("olingo2://read/Manufacturers('1')?filterAlreadySeen=true&" +
"delay=2&sendEmptyMessageWhenIdle=true&"
- + "splitResult=true")
- .to("mock:consumer-splitresult-kp-manufacturer");
- }
- };
- addRouteAndStartContext(builder);
-
- mockEndpoint.assertIsSatisfied();
-
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
-
- if (i == 0) {
- //
- // First polled messages contained all the entities
- //
- assertTrue(body instanceof ODataEntry);
- ODataEntry entry = (ODataEntry) body;
- Object nameValue = entry.getProperties().get("Name");
- assertNotNull(nameValue);
- assertEquals("Star Powered Racing", nameValue.toString());
- } else {
- //
- // Subsequent polling messages should be empty
- // since the filterAlreadySeen property is true
- //
- assertNull(body);
- }
- }
- }
-
- /**
- * WithPredicate in address FilterAlreadySeen: true SplitResults: true
sendEmptyMessageWhenIdle: false
- *
- * @throws Exception
- */
- @Test
- public void testConsumerReadFilterAlreadySeenWithPredicate2() throws
Exception {
- int expectedMsgCount = 1;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-splitresult-kp-manufacturer");
-
- //
- // Add 1 to count since we want to wait for full result time
- // before asserting that only 1 message has been delivered
- //
- mockEndpoint.expectedMinimumMessageCount(expectedMsgCount + 1);
- mockEndpoint.setResultWaitTime(6000L);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
-
from("olingo2://read/Manufacturers('1')?filterAlreadySeen=true&" +
"delay=2&sendEmptyMessageWhenIdle=false&"
- + "splitResult=true")
- .to("mock:consumer-splitresult-kp-manufacturer");
- }
- };
- addRouteAndStartContext(builder);
-
- //
- // Want to wait for entire result time & there should
- // be exactly 1 exchange transmitted to the endpoint
- //
- mockEndpoint.assertIsNotSatisfied();
-
- // Only 1 exchange so this is good!
- assertEquals(1, mockEndpoint.getExchanges().size());
-
- Object body = mockEndpoint.getExchanges().get(0).getIn().getBody();
- //
- // Only polled message contains the entity
- //
- assertTrue(body instanceof ODataEntry);
- ODataEntry entry = (ODataEntry) body;
- Object nameValue = entry.getProperties().get("Name");
- assertNotNull(nameValue);
- assertEquals("Star Powered Racing", nameValue.toString());
-
- // should be reflection free
- long counter =
context.adapt(ExtendedCamelContext.class).getBeanIntrospection().getInvokedCounter();
- assertEquals(0, counter);
- }
-
- /**
- * Read value of the Address object and split the results into individual
messages
- */
- @SuppressWarnings("unchecked")
- @Test
- public void testConsumerReadClientValuesSplitResults() throws Exception {
- MockEndpoint mockEndpoint = getMockEndpoint("mock:consumer-value");
- mockEndpoint.expectedMinimumMessageCount(1);
- mockEndpoint.setResultWaitTime(60000);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
-
from("olingo2://read/Manufacturers('1')/Address?splitResult=true").to("mock:consumer-value");
- }
- };
- addRouteAndStartContext(builder);
-
- mockEndpoint.assertIsSatisfied();
- //
- // 1 individual message in the exchange
- //
- Object body = mockEndpoint.getExchanges().get(0).getIn().getBody();
- assertIsInstanceOf(Map.class, body);
- Map<String, Object> value = (Map<String, Object>) body;
- Object addrObj = value.get("Address");
- assertIsInstanceOf(Map.class, addrObj);
- Map<String, Object> addrMap = (Map<String, Object>) addrObj;
- assertEquals("70173", addrMap.get("ZipCode"));
- assertEquals("Star Street 137", addrMap.get("Street"));
- assertEquals("Germany", addrMap.get("Country"));
- assertEquals("Stuttgart", addrMap.get("City"));
- }
-
- /**
- * Read entity set of the Manufacturers object and split the results into
individual messages
- */
- @Test
- public void testConsumerReadSplitResults() throws Exception {
- int expectedMsgCount = 2;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-splitresult");
- mockEndpoint.expectedMinimumMessageCount(expectedMsgCount);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
-
from("olingo2://read/Manufacturers?splitResult=true").to("mock:consumer-splitresult");
- }
- };
-
- addRouteAndStartContext(builder);
-
- mockEndpoint.assertIsSatisfied();
-
- //
- // 2 individual messages in the exchange,
- // each containing a different entity.
- //
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
- assertTrue(body instanceof ODataEntry);
- ODataEntry entry = (ODataEntry) body;
- Map<String, Object> properties = entry.getProperties();
- assertNotNull(properties);
-
- Object name = properties.get("Name");
- assertNotNull(name);
- assertTrue(name.toString().contains("Powered Racing"));
- }
- }
-
- /**
- * Read entity set of the Manufacturers object and split the results into
individual messages. Auto add inline count
- * or results to entities.
- */
- @Test
- public void testConsumerReadSplitResultsWithInlineCount() throws Exception
{
- int expectedMsgCount = 2;
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:consumer-splitresult-with-count");
- mockEndpoint.expectedMinimumMessageCount(expectedMsgCount);
-
- RouteBuilder builder = new RouteBuilder() {
- public void configure() {
-
from("olingo2://read/Manufacturers/?$inlinecount=allpages&splitResult=true")
- .to("mock:consumer-splitresult-with-count");
- }
- };
-
- addRouteAndStartContext(builder);
-
- mockEndpoint.assertIsSatisfied();
-
- //
- // 2 individual messages in the exchange,
- // each containing a different entity.
- //
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
- assertTrue(body instanceof ODataEntry);
- ODataEntry entry = (ODataEntry) body;
- Map<String, Object> properties = entry.getProperties();
- assertNotNull(properties);
-
- Object name = properties.get("Name");
- assertNotNull(name);
- assertTrue(name.toString().contains("Powered Racing"));
- Object resultCount = properties.get("ResultCount");
- assertTrue(((Integer) resultCount) > 0);
- }
- }
-}
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java
deleted file mode 100644
index 44c4fe7bd62..00000000000
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2ComponentProducerTest.java
+++ /dev/null
@@ -1,410 +0,0 @@
-/*
- * 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.ArrayList;
-import java.util.Date;
-import java.util.HashMap;
-import java.util.List;
-import java.util.Map;
-
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.component.mock.MockEndpoint;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchChangeRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchQueryRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchRequest;
-import org.apache.camel.component.olingo2.api.batch.Olingo2BatchResponse;
-import org.apache.camel.component.olingo2.api.batch.Operation;
-import org.apache.camel.component.olingo2.api.impl.Olingo2AppImpl;
-import org.apache.camel.component.olingo2.api.impl.SystemQueryOption;
-import org.apache.camel.component.olingo2.internal.Olingo2Constants;
-import org.apache.camel.test.AvailablePortFinder;
-import org.apache.camel.test.infra.jetty.services.JettyConfiguration;
-import org.apache.camel.test.infra.jetty.services.JettyEmbeddedService;
-import org.apache.olingo.odata2.api.commons.HttpStatusCodes;
-import org.apache.olingo.odata2.api.edm.Edm;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.apache.olingo.odata2.api.ep.feed.ODataFeed;
-import org.apache.olingo.odata2.api.servicedocument.ServiceDocument;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-import static
org.apache.camel.component.olingo2.AbstractOlingo2AppAPITestSupport.createConfiguration;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertFalse;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-import static org.junit.jupiter.api.Assertions.assertTrue;
-
-/**
- * Test class for {@link org.apache.camel.component.olingo2.api.Olingo2App}
APIs.
- * <p>
- * The integration test runs against Apache Olingo 2.0 sample server which is
dynamically installed and started during
- * the test.
- * </p>
- */
-public class Olingo2ComponentProducerTest extends AbstractOlingo2TestSupport {
-
- private static final Logger LOG =
LoggerFactory.getLogger(Olingo2ComponentProducerTest.class);
- private static final int PORT = AvailablePortFinder.getNextAvailable();
- private static final String ID_PROPERTY = "Id";
- private static final String MANUFACTURERS = "Manufacturers";
- private static final String TEST_MANUFACTURER = "Manufacturers('1')";
- private static final String CARS = "Cars";
- private static final String TEST_RESOURCE_CONTENT_ID = "1";
- private static final String ADDRESS = "Address";
- private static final String TEST_RESOURCE = "$1";
- private static final String TEST_RESOURCE_ADDRESS = TEST_RESOURCE +
"/Address";
- private static final String TEST_MERGE_MANUFACTURER_ID = "124";
- private static final String TEST_CREATE_MANUFACTURER_ID = "123";
- private static final String TEST_CREATE_MANUFACTURER
- = String.format("DefaultContainer.Manufacturers('%s')",
TEST_CREATE_MANUFACTURER_ID);
- private static final String TEST_SERVICE_URL = "http://localhost:" + PORT
+ "/MyFormula.svc";
-
- private static final JettyConfiguration JETTY_CONFIGURATION =
createConfiguration(PORT);
-
- @RegisterExtension
- public static JettyEmbeddedService service = new
JettyEmbeddedService(JETTY_CONFIGURATION);
-
- public Olingo2ComponentProducerTest() {
- setDefaultTestProperty("serviceUri", "http://localhost:" + PORT +
"/MyFormula.svc");
- }
-
- @BeforeAll
- public static void beforeClass() throws Exception {
- Olingo2TestUtil.generateSampleData(TEST_SERVICE_URL);
- }
-
- @Test
- public void testRead() throws Exception {
- final Map<String, Object> headers = new HashMap<>();
-
- // read ServiceDocument
- final ServiceDocument document =
requestBodyAndHeaders("direct:READSERVICEDOC", null, headers);
- assertNotNull(document);
- assertFalse(document.getEntitySetsInfo().isEmpty(), "ServiceDocument
entity sets");
- LOG.info("Service document has {} entity sets",
document.getEntitySetsInfo().size());
-
- // parameter type is java.util.Map
- final HashMap<String, String> queryParams = new HashMap<>();
- queryParams.put(SystemQueryOption.$top.name(), "5");
- headers.put("CamelOlingo2.queryParams", queryParams);
-
- // read ODataFeed
- final ODataFeed manufacturers =
requestBodyAndHeaders("direct:READFEED", null, headers);
- assertNotNull(manufacturers);
- final List<ODataEntry> manufacturersEntries =
manufacturers.getEntries();
- assertFalse(manufacturersEntries.isEmpty(), "Manufacturers empty
entries");
- LOG.info("Manufacturers feed has {} entries",
manufacturersEntries.size());
-
- // read ODataEntry
- headers.clear();
- 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("1", properties.get(ID_PROPERTY), "Manufacturer Id");
- LOG.info("Manufacturer: {}", properties);
- }
-
- @Test
- public void testCreateUpdateDelete() {
- final Map<String, Object> data = getEntityData();
- Map<String, Object> address;
-
- final ODataEntry manufacturer = requestBody("direct:CREATE", data);
- assertNotNull(manufacturer, "Created Manufacturer");
- final Map<String, Object> properties = manufacturer.getProperties();
- assertEquals(TEST_CREATE_MANUFACTURER_ID, properties.get(ID_PROPERTY),
"Created Manufacturer Id");
- LOG.info("Created Manufacturer: {}", properties);
-
- // update
- data.put("Name", "MyCarManufacturer Renamed");
- address = (Map<String, Object>) data.get("Address");
- address.put("Street", "Main Street");
-
- HttpStatusCodes status = requestBody("direct:UPDATE", data);
- assertNotNull(status, "Update status");
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(),
status.getStatusCode(), "Update status");
- LOG.info("Update status: {}", status);
-
- final Map<String, Object> headers = new HashMap<>();
- headers.put(Olingo2Constants.PROPERTY_PREFIX + "keyPredicate",
String.format("'%s'", TEST_CREATE_MANUFACTURER_ID));
- final ODataEntry updatedManufacturer =
requestBodyAndHeaders("direct:READENTRY", null, headers);
- assertNotNull(updatedManufacturer);
- final Map<String, Object> updatedProperties =
updatedManufacturer.getProperties();
- assertEquals(TEST_CREATE_MANUFACTURER_ID,
updatedProperties.get(ID_PROPERTY), "Manufacturer Id");
- assertEquals("MyCarManufacturer Renamed",
updatedProperties.get("Name"), "Manufacturer Name");
- LOG.info("Updated Manufacturer: {}", updatedProperties);
-
- // delete
- status = requestBody("direct:DELETE", null);
- assertNotNull(status, "Delete status");
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(),
status.getStatusCode(), "Delete status");
- LOG.info("Delete status: {}", status);
- }
-
- @Test
- public void testCreateMerge() {
- final Map<String, Object> data = getEntityData();
- data.put(ID_PROPERTY, TEST_MERGE_MANUFACTURER_ID);
-
- final ODataEntry manufacturer = requestBody("direct:CREATE", data);
- assertNotNull(manufacturer, "Created Manufacturer");
- final Map<String, Object> properties = manufacturer.getProperties();
- assertEquals(TEST_MERGE_MANUFACTURER_ID, properties.get(ID_PROPERTY),
"Created Manufacturer Id");
- LOG.info("Created Manufacturer: {}", properties);
-
- final Map<String, Object> propertiesToUpdate = new HashMap<>();
- propertiesToUpdate.put(ID_PROPERTY, TEST_MERGE_MANUFACTURER_ID);
- propertiesToUpdate.put("Name", "MyCarManufacturer Updated");
-
- HttpStatusCodes status = requestBody("direct:MERGE",
propertiesToUpdate);
- assertNotNull(status, "Merge status");
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(),
status.getStatusCode(), "Merge status");
- LOG.info("Merge status: {}", status);
-
- final Map<String, Object> headers = new HashMap<>();
- headers.put(Olingo2Constants.PROPERTY_PREFIX + "keyPredicate",
String.format("'%s'", TEST_MERGE_MANUFACTURER_ID));
- final ODataEntry mergedManufacturer =
requestBodyAndHeaders("direct:READENTRY", null, headers);
- assertNotNull(mergedManufacturer);
- final Map<String, Object> mergedProperties =
mergedManufacturer.getProperties();
- assertEquals(TEST_MERGE_MANUFACTURER_ID,
mergedProperties.get(ID_PROPERTY), "Manufacturer Id");
- assertEquals("MyCarManufacturer Updated",
mergedProperties.get("Name"), "Manufacturer Name");
- assertNotNull(mergedProperties.get("Address"), "Manufacturer Address");
- LOG.info("Merged Manufacturer: {}", mergedProperties);
- }
-
- private Map<String, Object> getEntityData() {
- final Map<String, Object> data = new HashMap<>();
- data.put(ID_PROPERTY, TEST_CREATE_MANUFACTURER_ID);
- data.put("Name", "MyCarManufacturer");
- data.put("Founded", new Date());
- Map<String, Object> address = new HashMap<>();
- address.put("Street", "Main");
- address.put("ZipCode", "42421");
- address.put("City", "Fairy City");
- address.put("Country", "FarFarAway");
- data.put("Address", address);
- return data;
- }
-
- @Test
- public void testBatch() throws Exception {
- final List<Olingo2BatchRequest> batchParts = new ArrayList<>();
-
- // 1. Edm query
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(Olingo2AppImpl.METADATA).build());
-
- // 2. feed query
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(MANUFACTURERS).build());
-
- // 3. read
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).build());
-
- // 4. read with expand
- final HashMap<String, String> queryParams = new HashMap<>();
- queryParams.put(SystemQueryOption.$expand.toString(), CARS);
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_MANUFACTURER).queryParams(queryParams).build());
-
- // 5. create
- final Map<String, Object> data = getEntityData();
-
batchParts.add(Olingo2BatchChangeRequest.resourcePath(MANUFACTURERS).contentId(TEST_RESOURCE_CONTENT_ID)
- .operation(Operation.CREATE).body(data).build());
-
- // 6. update address in created entry
- final Map<String, Object> updateData = new HashMap<>(data);
- Map<String, Object> address = (Map<String, Object>)
updateData.get(ADDRESS);
- address.put("Street", "Main Street");
-
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE_ADDRESS).operation(Operation.UPDATE).body(address)
- .build());
-
- // 7. update
- updateData.put("Name", "MyCarManufacturer Renamed");
- batchParts.add(
-
Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.UPDATE).body(updateData).build());
-
- // 8. delete
-
batchParts.add(Olingo2BatchChangeRequest.resourcePath(TEST_RESOURCE).operation(Operation.DELETE).build());
-
- // 9. read to verify delete
-
batchParts.add(Olingo2BatchQueryRequest.resourcePath(TEST_CREATE_MANUFACTURER).build());
-
- // execute batch request
- final List<Olingo2BatchResponse> responseParts =
requestBody("direct:BATCH", batchParts);
- assertNotNull(responseParts, "Batch response");
- assertEquals(9, responseParts.size(), "Batch responses expected");
-
- final Edm edm = (Edm) responseParts.get(0).getBody();
- assertNotNull(edm);
- LOG.info("Edm entity sets: {}", edm.getEntitySets());
-
- final ODataFeed feed = (ODataFeed) responseParts.get(1).getBody();
- assertNotNull(feed);
- LOG.info("Read feed: {}", feed.getEntries());
-
- ODataEntry dataEntry = (ODataEntry) responseParts.get(2).getBody();
- assertNotNull(dataEntry);
- LOG.info("Read entry: {}", dataEntry.getProperties());
-
- dataEntry = (ODataEntry) responseParts.get(3).getBody();
- assertNotNull(dataEntry);
- LOG.info("Read entry with $expand: {}", dataEntry.getProperties());
-
- dataEntry = (ODataEntry) responseParts.get(4).getBody();
- assertNotNull(dataEntry);
- LOG.info("Created entry: {}", dataEntry.getProperties());
-
- int statusCode = responseParts.get(5).getStatusCode();
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
- LOG.info("Update address status: {}", statusCode);
-
- statusCode = responseParts.get(6).getStatusCode();
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
- LOG.info("Update entry status: {}", statusCode);
-
- statusCode = responseParts.get(7).getStatusCode();
- assertEquals(HttpStatusCodes.NO_CONTENT.getStatusCode(), statusCode);
- LOG.info("Delete status: {}", statusCode);
-
- assertEquals(HttpStatusCodes.NOT_FOUND.getStatusCode(),
responseParts.get(8).getStatusCode());
- final Exception exception = (Exception) responseParts.get(8).getBody();
- assertNotNull(exception);
- LOG.info("Read deleted entry exception: {}", exception);
- }
-
- /**
- * Read entity set of the People object and with no filter already seen,
all items should be present in each message
- *
- * @throws Exception
- */
- @Test
- public void testProducerReadNoFilterAlreadySeen() throws Exception {
- final Map<String, Object> headers = new HashMap<>();
- String endpoint = "direct:read-people-nofilterseen";
- int expectedMsgCount = 3;
-
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:producer-noalreadyseen");
- mockEndpoint.expectedMessageCount(expectedMsgCount);
-
- int expectedEntities = -1;
- for (int i = 0; i < expectedMsgCount; ++i) {
- final ODataFeed manufacturers = (ODataFeed)
requestBodyAndHeaders(endpoint, null, headers);
- assertNotNull(manufacturers);
- if (i == 0) {
- expectedEntities = manufacturers.getEntries().size();
- }
- }
-
- mockEndpoint.assertIsSatisfied();
-
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
- assertTrue(body instanceof ODataFeed);
- ODataFeed set = (ODataFeed) body;
-
- //
- // All messages contained all the manufacturers
- //
- assertEquals(expectedEntities, set.getEntries().size());
- }
- }
-
- /**
- * Read entity set of the People object and filter already seen items on
subsequent exchanges
- */
- @Test
- public void testProducerReadFilterAlreadySeen() throws Exception {
- final Map<String, Object> headers = new HashMap<>();
- String endpoint = "direct:read-people-filterseen";
- int expectedMsgCount = 3;
-
- MockEndpoint mockEndpoint =
getMockEndpoint("mock:producer-alreadyseen");
- mockEndpoint.expectedMessageCount(expectedMsgCount);
-
- int expectedEntities = -1;
- for (int i = 0; i < expectedMsgCount; ++i) {
- final ODataFeed manufacturers = (ODataFeed)
requestBodyAndHeaders(endpoint, null, headers);
- assertNotNull(manufacturers);
- if (i == 0) {
- expectedEntities = manufacturers.getEntries().size();
- }
- }
-
- mockEndpoint.assertIsSatisfied();
-
- for (int i = 0; i < expectedMsgCount; ++i) {
- Object body = mockEndpoint.getExchanges().get(i).getIn().getBody();
- assertTrue(body instanceof ODataFeed);
- ODataFeed set = (ODataFeed) body;
-
- if (i == 0) {
- //
- // First polled messages contained all the manufacturers
- //
- assertEquals(expectedEntities, set.getEntries().size());
- } else {
- //
- // Subsequent messages should be empty
- // since the filterAlreadySeen property is true
- //
- assertEquals(0, set.getEntries().size());
- }
- }
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
- // test routes for read
- from("direct:READSERVICEDOC").to("olingo2://read/");
-
-
from("direct:READFEED").to("olingo2://read/Manufacturers?$orderBy=Name%20asc");
-
-
from("direct:READENTRY").to("olingo2://read/DefaultContainer.Manufacturers");
-
- // test route for create
- from("direct:CREATE").to("olingo2://create/Manufacturers");
-
- // test route for update
-
from("direct:UPDATE").to(String.format("olingo2://update/Manufacturers('%s')",
TEST_CREATE_MANUFACTURER_ID));
-
- // test route for delete
-
from("direct:DELETE").to(String.format("olingo2://delete/Manufacturers('%s')",
TEST_CREATE_MANUFACTURER_ID));
-
- // test route for merge
-
from("direct:MERGE").to(String.format("olingo2://merge/Manufacturers('%s')",
TEST_MERGE_MANUFACTURER_ID));
-
- /*
- * // test route for patch
- * from("direct:PATCH") .to("olingo2://patch");
- */
-
- // test route for batch
- from("direct:BATCH").to("olingo2://batch");
-
-
from("direct:read-people-nofilterseen").to("olingo2://read/Manufacturers").to("mock:producer-noalreadyseen");
-
-
from("direct:read-people-filterseen").to("olingo2://read/Manufacturers?filterAlreadySeen=true")
- .to("mock:producer-alreadyseen");
- }
- };
- }
-}
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
deleted file mode 100644
index 9a056ef1b16..00000000000
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2RouteTest.java
+++ /dev/null
@@ -1,89 +0,0 @@
-/*
- * 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.infra.jetty.services.JettyConfiguration;
-import org.apache.camel.test.infra.jetty.services.JettyEmbeddedService;
-import org.apache.camel.test.junit5.CamelTestSupport;
-import org.apache.olingo.odata2.api.ep.entry.ODataEntry;
-import org.junit.jupiter.api.AfterAll;
-import org.junit.jupiter.api.BeforeAll;
-import org.junit.jupiter.api.Test;
-import org.junit.jupiter.api.extension.RegisterExtension;
-
-import static
org.apache.camel.component.olingo2.AbstractOlingo2AppAPITestSupport.createConfiguration;
-import static org.junit.jupiter.api.Assertions.assertEquals;
-import static org.junit.jupiter.api.Assertions.assertNotNull;
-
-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 final JettyConfiguration JETTY_CONFIGURATION =
createConfiguration(PORT);
-
- @RegisterExtension
- public static JettyEmbeddedService service = new
JettyEmbeddedService(JETTY_CONFIGURATION);
-
- @BeforeAll
- public static void beforeClass() throws Exception {
- Olingo2TestUtil.generateSampleData(TEST_SERVICE_URL);
- }
-
- @AfterAll
- public static void afterClass() {
- if (olingoApp != null) {
- olingoApp.close();
- }
- }
-
- @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() {
- 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("1", properties.get(ID_PROPERTY), "Manufacturer Id");
- }
-
- @Override
- protected RouteBuilder createRouteBuilder() {
- return new RouteBuilder() {
- public void configure() {
-
from("direct:READENTRY").to("olingo2://read/DefaultContainer.Manufacturers?serviceUri="
+ TEST_SERVICE_URL);
- }
- };
- }
-}
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2TestUtil.java
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2TestUtil.java
index eef9dd8fc4b..101cfcf1da9 100644
---
a/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2TestUtil.java
+++
b/components/camel-olingo2/camel-olingo2-component/src/test/java/org/apache/camel/component/olingo2/Olingo2TestUtil.java
@@ -40,7 +40,7 @@ public final class Olingo2TestUtil {
Method m = clz.getMethod("generateData", String.class);
m.invoke(null, serviceUrl);
} catch (Throwable t) {
- LOG.error("Unable to load the required sample class", t);
+ LOG.error("Unable to load the required sample class: {}",
t.getMessage());
throw new IOException("unable to load the required sample class",
t);
}
}
diff --git
a/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml
b/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml
deleted file mode 100644
index 4fc7368699a..00000000000
---
a/components/camel-olingo2/camel-olingo2-component/src/test/resources/olingo2_ref/WEB-INF/web.xml
+++ /dev/null
@@ -1,45 +0,0 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<!--
-
- 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.
-
--->
-<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xmlns="https://jakarta.ee/xml/ns/jakartaee"
- xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee
https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
- id="WebApp_ID" version="6.0">
- <display-name>org.apache.olingo.sample.annotation</display-name>
-
- <servlet>
- <servlet-name>CarServiceServlet</servlet-name>
-
<servlet-class>org.apache.cxf.jaxrs.servlet.CXFNonSpringJaxrsServlet</servlet-class>
- <init-param>
- <param-name>javax.ws.rs.Application</param-name>
-
<param-value>org.apache.olingo.odata2.core.rest.app.ODataApplication</param-value>
- </init-param>
- <init-param>
-
<param-name>org.apache.olingo.odata2.service.factory</param-name>
-
<param-value>org.apache.olingo.sample.annotation.processor.AnnotationSampleServiceFactory</param-value>
- </init-param>
- <load-on-startup>1</load-on-startup>
- </servlet>
-
- <servlet-mapping>
- <servlet-name>CarServiceServlet</servlet-name>
- <url-pattern>/MyFormula.svc/*</url-pattern>
- </servlet-mapping>
-
-</web-app>