[OLINGO-832] Changed integration in TecSvc and added more IT tests

Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/2d4772dc
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/2d4772dc
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/2d4772dc

Branch: refs/heads/OLINGO-856_ODataHandlerInAPI
Commit: 2d4772dc1b3c39d60124689d0218dcabc49aaeba
Parents: feb94ed
Author: Michael Bolz <[email protected]>
Authored: Thu Feb 25 21:18:34 2016 +0100
Committer: Michael Bolz <[email protected]>
Committed: Thu Feb 25 21:18:34 2016 +0100

----------------------------------------------------------------------
 .../fit/tecsvc/http/BasicStreamITCase.java      | 34 ++++++++++++---
 .../olingo/server/tecsvc/data/DataCreator.java  | 43 +++++++++++++++++++
 .../processor/TechnicalEntityProcessor.java     | 44 +++++++++++++++++---
 .../tecsvc/provider/ContainerProvider.java      | 17 +++++++-
 .../json/ODataJsonSerializerTest.java           |  2 +
 5 files changed, 126 insertions(+), 14 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d4772dc/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
----------------------------------------------------------------------
diff --git 
a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java 
b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
index 1903d13..0c2ddb5 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/BasicStreamITCase.java
@@ -39,12 +39,11 @@ public class BasicStreamITCase extends 
AbstractBaseTestITCase {
   private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
 
   @Test
-  public void streamAllPrim() throws Exception {
-    URL url = new URL(SERVICE_URI + "ESAllPrim?$format=json");
+  public void streamESStreamJson() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESStream?$format=json");
 
     HttpURLConnection connection = (HttpURLConnection) url.openConnection();
     connection.setRequestMethod(HttpMethod.GET.name());
-    connection.setRequestProperty("odata.streaming", "true");
     connection.connect();
 
     assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
@@ -52,9 +51,32 @@ public class BasicStreamITCase extends 
AbstractBaseTestITCase {
 
     final String content = IOUtils.toString(connection.getInputStream());
 
-    assertTrue(content.contains("\"PropertyString\":\"First Resource - 
positive values->streamed\""));
-    assertTrue(content.contains("\"PropertyString\":\"Second Resource - 
negative values->streamed\""));
-    assertTrue(content.contains("\"PropertyString\":\"->streamed\""));
+    assertTrue(content.contains("[email protected]\"," +
+            "\"[email protected]\"," +
+            "\"[email protected]\""));
+    assertTrue(content.contains("\"PropertyString\":\"TEST 1->streamed\""));
+    assertTrue(content.contains("\"PropertyString\":\"TEST 2->streamed\""));
+  }
+
+  @Test
+  public void streamESStreamXml() throws Exception {
+    URL url = new URL(SERVICE_URI + "ESStream?$format=xml");
+
+    HttpURLConnection connection = (HttpURLConnection) url.openConnection();
+    connection.setRequestMethod(HttpMethod.GET.name());
+    connection.connect();
+
+    assertEquals(HttpStatusCode.OK.getStatusCode(), 
connection.getResponseCode());
+    assertEquals(ContentType.APPLICATION_XML, 
ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE)));
+
+    final String content = IOUtils.toString(connection.getInputStream());
+    System.out.println(content);
+
+    
assertTrue(content.contains("<m:element>[email protected]</m:element>"
 +
+            "<m:element>[email protected]</m:element>" +
+            "<m:element>[email protected]</m:element>"));
+    assertTrue(content.contains("<d:PropertyString>TEST 
1</d:PropertyString>"));
+    assertTrue(content.contains("<d:PropertyString>TEST 
2</d:PropertyString>"));
   }
 
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d4772dc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index d946664..376d916 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -75,6 +75,7 @@ public class DataCreator {
     data.put("ESBase", createESBase(edm, odata));
     data.put("ESCompMixPrimCollComp", createESCompMixPrimCollComp(edm, odata));
     data.put("ESMixEnumDefCollComp", createESMixEnumDefCollComp(edm, odata));
+    data.put("ESStream", createESStream(edm, odata));
 
     linkESTwoPrim(data);
     linkESAllPrim(data);
@@ -937,6 +938,48 @@ public class DataCreator {
     return entityCollection;
   }
 
+  private EntityCollection createESStream(final Edm edm, final OData odata) {
+    EntityCollection entityCollection = new EntityCollection();
+
+    entityCollection.getEntities().add(new Entity()
+            .addProperty(createPrimitive("PropertyInt16", Short.MAX_VALUE))
+            .addProperty(createPrimitiveCollection("CollPropertyString",
+                    "[email protected]",
+                    "[email protected]",
+                    "[email protected]"))
+            .addProperty(createComplex("PropertyComp",
+                    createPrimitive("PropertyInt16", (short) 111),
+                    createPrimitive("PropertyString", "TEST A")))
+            .addProperty(createColPropertyComp()));
+
+    entityCollection.getEntities().add(new Entity()
+            .addProperty(createPrimitive("PropertyInt16", (short) 7))
+            .addProperty(createPrimitiveCollection("CollPropertyString",
+                    "[email protected]",
+                    "[email protected]",
+                    "[email protected]"))
+            .addProperty(createComplex("PropertyComp",
+                    createPrimitive("PropertyInt16", (short) 222),
+                    createPrimitive("PropertyString", "TEST B")))
+            .addProperty(createColPropertyComp()));
+
+    entityCollection.getEntities().add(new Entity()
+            .addProperty(createPrimitive("PropertyInt16", (short) 0))
+            .addProperty(createPrimitiveCollection("CollPropertyString",
+                    "[email protected]",
+                    "[email protected]",
+                    "[email protected]"))
+            .addProperty(createComplex("PropertyComp",
+                    createPrimitive("PropertyInt16", (short) 333),
+                    createPrimitive("PropertyString", "TEST C")))
+            .addProperty(createColPropertyComp()));
+
+    setEntityType(entityCollection, 
edm.getEntityType(EntityTypeProvider.nameETMixPrimCollComp));
+    createEntityId(edm, odata, "ESStream", entityCollection);
+
+    return entityCollection;
+  }
+
   @SuppressWarnings("unchecked")
   private Property createColPropertyComp() {
     return createComplexCollection("CollPropertyComp",

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d4772dc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
index 850867e..5b48095 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalEntityProcessor.java
@@ -18,10 +18,12 @@
  */
 package org.apache.olingo.server.tecsvc.processor;
 
+import java.util.Collections;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 
+import org.apache.olingo.commons.api.data.ComplexValue;
 import org.apache.olingo.commons.api.data.ContextURL;
 import org.apache.olingo.commons.api.data.ContextURL.Builder;
 import org.apache.olingo.commons.api.data.ContextURL.Suffix;
@@ -77,6 +79,7 @@ import 
org.apache.olingo.server.tecsvc.processor.queryoptions.options.SearchHand
 import 
org.apache.olingo.server.tecsvc.processor.queryoptions.options.ServerSidePagingHandler;
 import 
org.apache.olingo.server.tecsvc.processor.queryoptions.options.SkipHandler;
 import 
org.apache.olingo.server.tecsvc.processor.queryoptions.options.TopHandler;
+import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
 
 /**
  * Technical Processor for entity-related functionality.
@@ -529,7 +532,7 @@ public class TechnicalEntityProcessor extends 
TechnicalProcessor
       final SerializerResult serializerResult =
           serializeReferenceCollection(entitySetSerialization, edmEntitySet, 
requestedContentType, countOption);
       response.setContent(serializerResult.getContent());
-    } else if(isOdataStreaming(request)) {
+    } else if(isStreaming(edmEntitySet, requestedContentType)) {
       final SerializerStreamResult serializerResult =
           serializeEntityCollectionStreamed(request,
               entitySetSerialization, edmEntitySet, edmEntityType, 
requestedContentType,
@@ -553,9 +556,19 @@ public class TechnicalEntityProcessor extends 
TechnicalProcessor
     }
   }
 
-  private boolean isOdataStreaming(ODataRequest request) {
-    String odataStreaming = request.getHeader("odata.streaming");
-    return Boolean.parseBoolean(odataStreaming);
+  /**
+   * Check is streaming is enabled for this entity set in combination with the 
given content type.
+   * <code>TRUE</code> if the technical scenario supports streaming for this 
combination,
+   * otherwise <code>FALSE</code>.
+   *
+   * @param edmEntitySet entity set of the request
+   * @param contentType requested content type of the request
+   * @return <code>TRUE</code> if the technical scenario supports streaming 
for this combination,
+   *          otherwise <code>FALSE</code>.
+   */
+  private boolean isStreaming(EdmEntitySet edmEntitySet, ContentType 
contentType) {
+    return contentType.isCompatible(ContentType.APPLICATION_JSON)
+            && 
ContainerProvider.ES_STREAM.equalsIgnoreCase(edmEntitySet.getName());
   }
 
   private SerializerResult serializeEntityCollection(final ODataRequest 
request, final EntityCollection
@@ -598,18 +611,37 @@ public class TechnicalEntityProcessor extends 
TechnicalProcessor
 
       private Entity addToPrimitiveProperty(Entity entity, String name, Object 
data) {
         List<Property> properties = entity.getProperties();
+        addTo(name, data, properties);
+        return entity;
+      }
+
+      private void addTo(String name, Object data, List<Property> properties) {
         int pos = 0;
         for (Property property : properties) {
+          if(property.isComplex()) {
+            final List<ComplexValue> cvs;
+            if(property.isCollection()) {
+              cvs = (List<ComplexValue>) property.asCollection();
+            } else {
+              cvs = Collections.singletonList(property.asComplex());
+            }
+            for (ComplexValue cv : cvs) {
+              final List<Property> value = cv.getValue();
+              if(value != null) {
+                addTo(name, data, value);
+              }
+            }
+          }
+
           if(name.equals(property.getName())) {
             properties.remove(pos);
             final String old = property.getValue().toString();
             String newValue = (old == null ? "": old) + data.toString();
-            entity.addProperty(new Property(null, name, ValueType.PRIMITIVE, 
newValue));
+            properties.add(pos, new Property(null, name, ValueType.PRIMITIVE, 
newValue));
             break;
           }
           pos++;
         }
-        return entity;
       }
     };
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d4772dc/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
----------------------------------------------------------------------
diff --git 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
index aeeb167..0fa3e78 100644
--- 
a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
+++ 
b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java
@@ -51,6 +51,7 @@ public class ContainerProvider {
   public static final String AIRT_PARAM = "AIRTParam";
   public static final String AIRT_TWO_PARAM = "AIRTTwoParam";
   public static final String AIRT_BYTE_NINE_PARAM = "AIRTByteNineParam";
+  public static final String ES_STREAM = "ESStream";
 
   private final CsdlEdmProvider prov;
 
@@ -101,6 +102,7 @@ public class ContainerProvider {
     entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, 
"ESTwoBaseTwoKeyNav"));
     entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, 
"ESKeyNavCont"));
     entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, 
"ESTwoKeyNavCont"));
+    entitySets.add(prov.getEntitySet(ContainerProvider.nameContainer, 
ES_STREAM));
 
     // Singletons
     List<CsdlSingleton> singletons = new ArrayList<CsdlSingleton>();
@@ -294,7 +296,7 @@ public class ContainerProvider {
             .setAnnotations(Arrays.asList(
                 new CsdlAnnotation().setTerm("Core.Description")
                     .setExpression(new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
-                        .setValue("Contains entities with a complext type 
containing all primitive types")),
+                        .setValue("Contains entities with a complex type 
containing all primitive types")),
                 new 
CsdlAnnotation().setTerm(TermProvider.TERM_DATA.getFullQualifiedNameAsString()).setExpression(
                     new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.Bool, 
"true"))));
 
@@ -305,7 +307,7 @@ public class ContainerProvider {
             .setAnnotations(Arrays.asList(
                 new CsdlAnnotation().setTerm("Core.Description")
                     .setExpression(new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
-                        .setValue("Contains entities with a complext type 
containing all collection primitive types")),
+                        .setValue("Contains entities with a complex type 
containing all collection primitive types")),
                 new 
CsdlAnnotation().setTerm(TermProvider.TERM_DATA.getFullQualifiedNameAsString()).setExpression(
                     new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.Bool, 
"true"))));
 
@@ -634,6 +636,17 @@ public class ContainerProvider {
                             + "definition, collection of type definition, 
complex and collection of complex")),
                 new 
CsdlAnnotation().setTerm(TermProvider.TERM_DATA.getFullQualifiedNameAsString()).setExpression(
                     new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.Bool, 
"true"))));
+      } else if (name.equals(ES_STREAM)) {
+        return new CsdlEntitySet()
+            .setName(ES_STREAM)
+            .setType(EntityTypeProvider.nameETMixPrimCollComp)
+            .setAnnotations(Arrays.asList(
+                new CsdlAnnotation().setTerm("Core.Description")
+                    .setExpression(new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.String)
+                        .setValue("Entity set will be streamed and it contains 
entities with various properties of " +
+                                "type primitive, collection of primitive, 
complex and collection of complex")),
+                new 
CsdlAnnotation().setTerm(TermProvider.TERM_DATA.getFullQualifiedNameAsString()).setExpression(
+                    new 
CsdlConstantExpression(CsdlConstantExpression.ConstantExpressionType.Bool, 
"true"))));
       }
     }
 

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2d4772dc/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index bc3ac19..e37cf7e 100644
--- 
a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ 
b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -278,6 +278,8 @@ public class ODataJsonSerializerTest {
       @Override
       public void handleError(ODataContentWriteErrorContext context, 
WritableByteChannel channel) {
         try {
+          Exception ex = context.getException();
+          Assert.assertEquals(ex, context.getODataLibraryException());
           String msgKey = 
context.getODataLibraryException().getMessageKey().getKey();
           String toChannel = "ERROR: " + msgKey;
           channel.write(ByteBuffer.wrap(toChannel.getBytes("UTF-8")));

Reply via email to