You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2019/06/06 07:10:32 UTC

[camel] 02/04: CAMEL-13316: Olingo components handle value/property results

This is an automated email from the ASF dual-hosted git repository.

acosentino pushed a commit to branch camel-2.x
in repository https://gitbox.apache.org/repos/asf/camel.git

commit d673e97c101e0d06301932a147d6e762832112c1
Author: phantomjinx <p....@phantomjinx.co.uk>
AuthorDate: Mon Mar 18 15:30:17 2019 +0000

    CAMEL-13316: Olingo components handle value/property results
    
    * When split, both olingo components handle results which are values or
      properties rather than entities.
    
    * Provides tests confirming the fix.
---
 .../camel/component/olingo2/Olingo2Consumer.java   |  4 +-
 .../component/olingo2/Olingo2ComponentTest.java    | 51 +++++++++++++++++++---
 .../camel/component/olingo4/Olingo4Consumer.java   |  9 +++-
 .../component/olingo4/Olingo4ComponentTest.java    | 35 ++++++++++++++-
 4 files changed, 89 insertions(+), 10 deletions(-)

diff --git a/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Consumer.java b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Consumer.java
index e92d96d..d069318 100644
--- a/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Consumer.java
+++ b/components/camel-olingo2/camel-olingo2-component/src/main/java/org/apache/camel/component/olingo2/Olingo2Consumer.java
@@ -144,7 +144,9 @@ public class Olingo2Consumer extends AbstractApiConsumer<Olingo2ApiName, Olingo2
             for (ODataEntry entry : odataFeed.getEntries()) {
                 splitResult.add(entry);
             }
-        } else if (result instanceof ODataEntry) {
+        } else if (result instanceof List) {
+            return result;
+        } else {
             splitResult.add(result);
         }
 
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 c60a3d9..cdaa7e6 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
@@ -121,6 +121,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport {
         LOG.info("Manufacturer: {}", properties);
     }
 
+    @SuppressWarnings( "unchecked" )
     @Test
     public void testCreateUpdateDelete() throws Exception {
         final Map<String, Object> data = getEntityData();
@@ -163,6 +164,7 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport {
         return data;
     }
 
+    @SuppressWarnings( "unchecked" )
     @Test
     public void testBatch() throws Exception {
         final List<Olingo2BatchRequest> batchParts = new ArrayList<>();
@@ -296,10 +298,42 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport {
     }
 
     /**
-     *
-     * Read entity set of the People object
-     * and with no filter already seen, all items
-     * should be present in each message
+     * Read value of the People object and split the results
+     * into individual messages
+     */
+    @SuppressWarnings( "unchecked" )
+    @Test
+    public void testConsumerReadClientValuesSplitResults() throws Exception {
+        final Map<String, Object> headers = new HashMap<>();
+        String endpoint = "olingo2://read/Manufacturers('1')/Address?consumer.splitResult=true";
+
+        this.context.setTracing(true);
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:consumer-value");
+        mockEndpoint.expectedMinimumMessageCount(1);
+        mockEndpoint.setResultWaitTime(60000);
+
+        final Map<String, Object> resultValue = requestBodyAndHeaders(endpoint, null, headers);
+        assertNotNull(resultValue);
+
+        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 People object and with no filter already seen, all
+     * items should be present in each message
      *
      * @throws Exception
      */
@@ -473,9 +507,14 @@ public class Olingo2ComponentTest extends AbstractOlingo2TestSupport {
                 //
                 // Consumer endpoint
                 //
-                from("olingo2://read/Manufacturers?filterAlreadySeen=true&consumer.delay=2&consumer.sendEmptyMessageWhenIdle=true&consumer.splitResult=false").to("mock:consumer-alreadyseen");
+                from("olingo2://read/Manufacturers?filterAlreadySeen=true&consumer.delay=2&consumer.sendEmptyMessageWhenIdle=true&consumer.splitResult=false")
+                    .to("mock:consumer-alreadyseen");
+
+                from("olingo2://read/Manufacturers?consumer.splitResult=true")
+                    .to("mock:consumer-splitresult");
 
-                from("olingo2://read/Manufacturers?consumer.splitResult=true").to("mock:consumer-splitresult");
+                from("olingo2://read/Manufacturers('1')/Address?consumer.splitResult=true")
+                    .to("mock:consumer-value");
             }
         };
     }
diff --git a/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Consumer.java b/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Consumer.java
index 4cee0a5..8c72db4 100644
--- a/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Consumer.java
+++ b/components/camel-olingo4/camel-olingo4-component/src/main/java/org/apache/camel/component/olingo4/Olingo4Consumer.java
@@ -29,6 +29,7 @@ import org.apache.camel.component.olingo4.internal.Olingo4ApiName;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.component.AbstractApiConsumer;
 import org.apache.camel.util.component.ApiConsumerHelper;
+import org.apache.olingo.client.api.domain.ClientCollectionValue;
 import org.apache.olingo.client.api.domain.ClientEntity;
 import org.apache.olingo.client.api.domain.ClientEntitySet;
 import org.apache.olingo.client.api.domain.ClientValue;
@@ -156,7 +157,13 @@ public class Olingo4Consumer extends AbstractApiConsumer<Olingo4ApiName, Olingo4
                 }
                 splitResult.add(entity);
             }
-        } else if (result instanceof ClientEntity) {
+        } else if (result instanceof ClientValue && ((ClientValue) result).isCollection()) {
+            ClientValue value = (ClientValue) result;
+            ClientCollectionValue<ClientValue> collection = value.asCollection();
+            collection.forEach(v -> {
+                splitResult.add(v);
+            });
+        } else {
             splitResult.add(result);
         }
 
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 dfafcbe..c7d0125 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
@@ -34,6 +34,7 @@ import org.apache.olingo.client.api.domain.ClientEntitySet;
 import org.apache.olingo.client.api.domain.ClientPrimitiveValue;
 import org.apache.olingo.client.api.domain.ClientProperty;
 import org.apache.olingo.client.api.domain.ClientServiceDocument;
+import org.apache.olingo.client.api.domain.ClientValue;
 import org.apache.olingo.commons.api.Constants;
 import org.apache.olingo.commons.api.edm.Edm;
 import org.apache.olingo.commons.api.ex.ODataError;
@@ -466,6 +467,30 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport {
             }
         }
     }
+    /**
+     * Read value of the People object and split the results
+     * into individual messages
+     */
+    @Test
+    public void testConsumerReadClientValuesSplitResults() throws Exception {
+        final Map<String, Object> headers = new HashMap<>();
+        String endpoint = "olingo4://read/People('russellwhyte')/FavoriteFeature?consumer.splitResult=true";
+
+        MockEndpoint mockEndpoint = getMockEndpoint("mock:consumer-splitresult-value");
+        mockEndpoint.expectedMinimumMessageCount(1);
+
+        final ClientValue resultValue = requestBodyAndHeaders(endpoint, null, headers);
+        assertIsInstanceOf(ClientValue.class, resultValue);
+
+        mockEndpoint.assertIsSatisfied();
+        //
+        // 1 individual message in the exchange
+        //
+        Object body = mockEndpoint.getExchanges().get(0).getIn().getBody();
+        assertIsInstanceOf(ClientPrimitiveValue.class, body);
+        ClientPrimitiveValue value = (ClientPrimitiveValue) body;
+        assertEquals("Feature1", value.toString());
+    }
 
     @Override
     protected RouteBuilder createRouteBuilder() throws Exception {
@@ -522,9 +547,15 @@ public class Olingo4ComponentTest extends AbstractOlingo4TestSupport {
                 //
                 // Consumer endpoint
                 //
-                from("olingo4://read/People?filterAlreadySeen=true&consumer.delay=2&consumer.sendEmptyMessageWhenIdle=true&consumer.splitResult=false").to("mock:consumer-alreadyseen");
+                from("olingo4://read/People?filterAlreadySeen=true&consumer.delay=2&consumer.sendEmptyMessageWhenIdle=true&consumer.splitResult=false")
+                    .to("mock:consumer-alreadyseen");
+
+                from("olingo4://read/People?consumer.splitResult=true")
+                    .to("mock:consumer-splitresult");
+
+                from("olingo4://read/People('russellwhyte')/FavoriteFeature?consumer.splitResult=true")
+                    .to("mock:consumer-splitresult-value");
 
-                from("olingo4://read/People?consumer.splitResult=true").to("mock:consumer-splitresult");
             }
         };
     }