You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/04/01 16:18:41 UTC

[14/51] [abbrv] git commit: [OLINGO-175, OLINGO-205] provided V4 document service test

[OLINGO-175, OLINGO-205] provided V4 document service test


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

Branch: refs/heads/master
Commit: bc398d3da20a103db3e9d527619aaa9a1a2641c6
Parents: e4bf213
Author: fmartelli <fa...@gmail.com>
Authored: Thu Mar 27 18:13:42 2014 +0100
Committer: fmartelli <fa...@gmail.com>
Committed: Thu Mar 27 18:13:42 2014 +0100

----------------------------------------------------------------------
 fit/pom.xml                                     |  12 ++
 fit/src/main/resources/v4/services.full.json    | 126 +++++++++++++++++++
 fit/src/main/resources/v4/services.xml          | 102 +++++++++++++++
 .../retrieve/ODataEntityRequestImpl.java        |   4 +-
 .../retrieve/ODataEntitySetRequestImpl.java     |   4 +-
 .../ODataServiceDocumentRequestImpl.java        |   6 +-
 .../v4/ServiceDocumentRetrieveTestITCase.java   |  74 +++++++++++
 .../core/it/v4/ServiceDocumentTestITCase.java   |  60 +++++++++
 8 files changed, 383 insertions(+), 5 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/fit/pom.xml
----------------------------------------------------------------------
diff --git a/fit/pom.xml b/fit/pom.xml
index cac0eca..55587aa 100644
--- a/fit/pom.xml
+++ b/fit/pom.xml
@@ -96,6 +96,18 @@
     <plugins>
       <plugin>
         <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-resources-plugin</artifactId>
+        <version>2.6</version>
+        <configuration>
+          <useDefaultDelimiters>false</useDefaultDelimiters>
+          <delimiters>
+            <delimiter>${*}</delimiter>
+          </delimiters>
+        </configuration>
+      </plugin>
+      
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
         <artifactId>maven-war-plugin</artifactId>
         <version>${war.maven.plugin.version}</version>
         <configuration>

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/fit/src/main/resources/v4/services.full.json
----------------------------------------------------------------------
diff --git a/fit/src/main/resources/v4/services.full.json b/fit/src/main/resources/v4/services.full.json
new file mode 100644
index 0000000..d769332
--- /dev/null
+++ b/fit/src/main/resources/v4/services.full.json
@@ -0,0 +1,126 @@
+{
+  "@odata.context": "http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/$metadata",
+  "value":
+          [
+            {
+              "name": "People",
+              "kind": "EntitySet",
+              "url": "People"
+            },
+            {
+              "name": "Customers",
+              "kind": "EntitySet",
+              "url": "Customers"
+            },
+            {
+              "name": "Employees",
+              "kind": "EntitySet",
+              "url": "Employees"
+            },
+            {
+              "name": "Products",
+              "kind": "EntitySet",
+              "url": "Products"
+            },
+            {
+              "name": "ProductDetails",
+              "kind": "EntitySet",
+              "url": "ProductDetails"
+            },
+            {
+              "name": "ProductReviews",
+              "kind": "EntitySet",
+              "url": "ProductReviews"
+            },
+            {
+              "name": "Orders",
+              "kind": "EntitySet",
+              "url": "Orders"
+            },
+            {
+              "name": "OrderDetails",
+              "kind": "EntitySet",
+              "url": "OrderDetails"
+            },
+            {
+              "name": "Departments",
+              "kind": "EntitySet",
+              "url": "Departments"
+            },
+            {
+              "name": "Accounts",
+              "kind": "EntitySet",
+              "url": "Accounts"
+            },
+            {
+              "name": "StoredPIs",
+              "kind": "EntitySet",
+              "url": "StoredPIs"
+            },
+            {
+              "name": "SubscriptionTemplates",
+              "kind": "EntitySet",
+              "url": "SubscriptionTemplates"
+            },
+            {
+              "name": "Boss",
+              "kind": "Singleton",
+              "url": "Boss"
+            },
+            {
+              "name": "VipCustomer",
+              "kind": "Singleton",
+              "url": "VipCustomer"
+            },
+            {
+              "name": "Company",
+              "kind": "Singleton",
+              "url": "Company"
+            },
+            {
+              "name": "PublicCompany",
+              "kind": "Singleton",
+              "url": "PublicCompany"
+            },
+            {
+              "name": "LabourUnion",
+              "kind": "Singleton",
+              "url": "LabourUnion"
+            },
+            {
+              "name": "DefaultStoredPI",
+              "kind": "Singleton",
+              "url": "DefaultStoredPI"
+            },
+            {
+              "name": "GetDefaultColor",
+              "kind": "FunctionImport",
+              "url": "GetDefaultColor"
+            },
+            {
+              "name": "GetPerson",
+              "kind": "FunctionImport",
+              "url": "GetPerson"
+            },
+            {
+              "name": "GetPerson2",
+              "kind": "FunctionImport",
+              "url": "GetPerson2"
+            },
+            {
+              "name": "GetAllProducts",
+              "kind": "FunctionImport",
+              "url": "GetAllProducts"
+            },
+            {
+              "name": "GetBossEmails",
+              "kind": "FunctionImport",
+              "url": "GetBossEmails"
+            },
+            {
+              "name": "GetProductsByAccessLevel",
+              "kind": "FunctionImport",
+              "url": "GetProductsByAccessLevel"
+            }
+          ]
+}
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/fit/src/main/resources/v4/services.xml
----------------------------------------------------------------------
diff --git a/fit/src/main/resources/v4/services.xml b/fit/src/main/resources/v4/services.xml
new file mode 100644
index 0000000..5ae733b
--- /dev/null
+++ b/fit/src/main/resources/v4/services.xml
@@ -0,0 +1,102 @@
+<?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.
+
+-->
+<service xml:base="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/" 
+         xmlns="http://www.w3.org/2007/app" 
+         xmlns:atom="http://www.w3.org/2005/Atom" 
+         xmlns:m="http://docs.oasis-open.org/odata/ns/metadata" 
+         m:context="http://localhost:${cargo.servlet.port}/StaticService/V40/Static.svc/$metadata">
+  <workspace>
+    <atom:title type="text">InMemoryEntities</atom:title>
+    <collection href="People">
+      <atom:title type="text">People</atom:title>
+    </collection>
+    <collection href="Customers">
+      <atom:title type="text">Customers</atom:title>
+    </collection>
+    <collection href="Employees">
+      <atom:title type="text">Employees</atom:title>
+    </collection>
+    <collection href="Products">
+      <atom:title type="text">Products</atom:title>
+    </collection>
+    <collection href="ProductDetails">
+      <atom:title type="text">ProductDetails</atom:title>
+    </collection>
+    <collection href="ProductReviews">
+      <atom:title type="text">ProductReviews</atom:title>
+    </collection>
+    <collection href="Orders">
+      <atom:title type="text">Orders</atom:title>
+    </collection>
+    <collection href="OrderDetails">
+      <atom:title type="text">OrderDetails</atom:title>
+    </collection>
+    <collection href="Departments">
+      <atom:title type="text">Departments</atom:title>
+    </collection>
+    <collection href="Accounts">
+      <atom:title type="text">Accounts</atom:title>
+    </collection>
+    <collection href="StoredPIs">
+      <atom:title type="text">StoredPIs</atom:title>
+    </collection>
+    <collection href="SubscriptionTemplates">
+      <atom:title type="text">SubscriptionTemplates</atom:title>
+    </collection>
+    <m:singleton href="Boss">
+      <atom:title type="text">Boss</atom:title>
+    </m:singleton>
+    <m:singleton href="VipCustomer">
+      <atom:title type="text">VipCustomer</atom:title>
+    </m:singleton>
+    <m:singleton href="Company">
+      <atom:title type="text">Company</atom:title>
+    </m:singleton>
+    <m:singleton href="PublicCompany">
+      <atom:title type="text">PublicCompany</atom:title>
+    </m:singleton>
+    <m:singleton href="LabourUnion">
+      <atom:title type="text">LabourUnion</atom:title>
+    </m:singleton>
+    <m:singleton href="DefaultStoredPI">
+      <atom:title type="text">DefaultStoredPI</atom:title>
+    </m:singleton>
+    <m:function-import href="GetDefaultColor">
+      <atom:title type="text">GetDefaultColor</atom:title>
+    </m:function-import>
+    <m:function-import href="GetPerson">
+      <atom:title type="text">GetPerson</atom:title>
+    </m:function-import>
+    <m:function-import href="GetPerson2">
+      <atom:title type="text">GetPerson2</atom:title>
+    </m:function-import>
+    <m:function-import href="GetAllProducts">
+      <atom:title type="text">GetAllProducts</atom:title>
+    </m:function-import>
+    <m:function-import href="GetBossEmails">
+      <atom:title type="text">GetBossEmails</atom:title>
+    </m:function-import>
+    <m:function-import href="GetProductsByAccessLevel">
+      <atom:title type="text">GetProductsByAccessLevel</atom:title>
+    </m:function-import>
+  </workspace>
+</service>
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
index 481d41e..2c8955e 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntityRequestImpl.java
@@ -85,10 +85,10 @@ public class ODataEntityRequestImpl extends AbstractODataRetrieveRequest<ODataEn
     public ODataEntity getBody() {
       if (entity == null) {
         try {
-          final Container<Entry> entry =
+          final Container<Entry> container =
                   odataClient.getDeserializer().toEntry(getRawResponse(), ODataPubFormat.fromString(getContentType()));
 
-          entity = odataClient.getBinder().getODataEntity(extractFromContainer(entry));
+          entity = odataClient.getBinder().getODataEntity(extractFromContainer(container));
         } finally {
           this.close();
         }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
index bb46ce8..e6d5783 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataEntitySetRequestImpl.java
@@ -87,10 +87,10 @@ public class ODataEntitySetRequestImpl extends AbstractODataRetrieveRequest<ODat
     public ODataEntitySet getBody() {
       if (entitySet == null) {
         try {
-          final Container<Feed> feed =
+          final Container<Feed> container =
                   odataClient.getDeserializer().toFeed(getRawResponse(), ODataPubFormat.fromString(getContentType()));
 
-          entitySet = odataClient.getBinder().getODataEntitySet(extractFromContainer(feed));
+          entitySet = odataClient.getBinder().getODataEntitySet(extractFromContainer(container));
         } finally {
           this.close();
         }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
index 128e250..bf37a32 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/communication/request/retrieve/ODataServiceDocumentRequestImpl.java
@@ -24,6 +24,8 @@ import org.apache.http.client.HttpClient;
 import org.apache.olingo.client.api.CommonODataClient;
 import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
 import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.data.ServiceDocument;
+import org.apache.olingo.commons.api.data.Container;
 import org.apache.olingo.commons.api.domain.ODataServiceDocument;
 import org.apache.olingo.commons.api.format.ODataFormat;
 
@@ -81,8 +83,10 @@ public class ODataServiceDocumentRequestImpl extends AbstractODataRetrieveReques
     public ODataServiceDocument getBody() {
       if (serviceDocument == null) {
         try {
-          serviceDocument = odataClient.getReader().readServiceDocument(
+          final Container<ServiceDocument> container = odataClient.getDeserializer().toServiceDocument(
                   getRawResponse(), ODataFormat.fromString(getContentType()));
+
+          serviceDocument = odataClient.getBinder().getODataServiceDocument(extractFromContainer(container));
         } finally {
           this.close();
         }

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentRetrieveTestITCase.java
new file mode 100644
index 0000000..0562670
--- /dev/null
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentRetrieveTestITCase.java
@@ -0,0 +1,74 @@
+/*
+ * 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.olingo.client.core.it.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ServiceDocumentRetrieveTestITCase extends AbstractTestITCase {
+
+  private void retrieveServiceDocumentTest(final ODataFormat reqFormat, final String acceptFormat) {
+    final ODataServiceDocumentRequest req =
+            client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
+    req.setFormat(reqFormat);
+    req.setAccept(acceptFormat);
+    final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
+    assertEquals(200, res.getStatusCode());
+    final ODataServiceDocument serviceDocument = res.getBody();
+    assertEquals(12, serviceDocument.getEntitySetTitles().size());
+    assertEquals(URI.create(testStaticServiceRootURL + "/Customers"), serviceDocument.getEntitySetURI("Customers"));
+    assertTrue(res.getContextURL().toASCIIString().endsWith("/StaticService/V40/Static.svc/$metadata"));
+  }
+
+  @Test
+  @Ignore
+  public void jsonTest() {
+    retrieveServiceDocumentTest(ODataFormat.JSON, "application/json");
+  }
+
+  @Test
+  @Ignore
+  public void jsonNoMetadataTest() {
+    retrieveServiceDocumentTest(ODataFormat.JSON_NO_METADATA, "application/json");
+  }
+
+  @Test
+  public void xmlTest() {
+    retrieveServiceDocumentTest(ODataFormat.XML, "application/xml");
+  }
+
+  @Test(expected = ODataClientErrorException.class)
+  public void atomAcceptTest() {
+    retrieveServiceDocumentTest(ODataFormat.XML, "application/atom+xml");
+  }
+
+  @Test
+  public void nullServiceFormatTest() {
+    retrieveServiceDocumentTest(null, "application/xml");
+  }
+}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/bc398d3d/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
new file mode 100644
index 0000000..4d7f5d7
--- /dev/null
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
@@ -0,0 +1,60 @@
+/*
+ * 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.olingo.client.core.it.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class ServiceDocumentTestITCase extends AbstractTestITCase {
+
+  private void retrieveServiceDocument(final ODataFormat format) {
+    final ODataServiceDocumentRequest req =
+            client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
+    req.setFormat(format);
+
+    final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
+    assertEquals(200, res.getStatusCode());
+
+    final ODataServiceDocument serviceDocument = res.getBody();
+    assertEquals(12, serviceDocument.getEntitySetTitles().size());
+
+    assertEquals(URI.create(testStaticServiceRootURL + "/ProductDetails"),
+            serviceDocument.getEntitySetURI("ProductDetails"));
+    assertTrue(res.getContextURL().toASCIIString().endsWith("/StaticService/V40/Static.svc/$metadata"));
+  }
+
+  @Test
+  public void retrieveServiceDocumentAsXML() {
+    retrieveServiceDocument(ODataFormat.XML);
+  }
+
+  @Test
+  @Ignore
+  public void retrieveServiceDocumentAsJSON() {
+    retrieveServiceDocument(ODataFormat.JSON);
+  }
+}