You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2016/09/08 12:05:27 UTC
[3/3] olingo-odata4 git commit: [OLINGO-1004] refactored some JSON
conformance tests
[OLINGO-1004] refactored some JSON conformance tests
Signed-off-by: Christian Amend <ch...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/f2fd0355
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/f2fd0355
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/f2fd0355
Branch: refs/heads/master
Commit: f2fd03553ffdd1bd9052e9718079d4e33573fc5b
Parents: e2f64e6
Author: Morten Riedel <Mo...@sap.com>
Authored: Wed Sep 7 10:48:08 2016 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Thu Sep 8 14:01:39 2016 +0200
----------------------------------------------------------------------
.../base/JSONFormatConformanceTestITCase.java | 35 ---------
.../client/JSONFormatConformanceTestITCase.java | 74 ++++++++++++++++++++
2 files changed, 74 insertions(+), 35 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f2fd0355/fit/src/test/java/org/apache/olingo/fit/base/JSONFormatConformanceTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/base/JSONFormatConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/base/JSONFormatConformanceTestITCase.java
index ae04c0f..62bdb20 100644
--- a/fit/src/test/java/org/apache/olingo/fit/base/JSONFormatConformanceTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/base/JSONFormatConformanceTestITCase.java
@@ -19,7 +19,6 @@
package org.apache.olingo.fit.base;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
@@ -49,40 +48,6 @@ import org.junit.Test;
* </a>.
*/
public class JSONFormatConformanceTestITCase extends AbstractTestITCase {
-
- /**
- * MUST either:
- * <ol>
- * <li>understand <tt>odata.metadata=minimal</tt> (section 3.1.1) or</li>
- * <li>explicitly specify <tt>odata.metadata=none</tt>(section 3.1.3) or <tt>odata.metadata=full</tt> (section 3.1.2)
- * in the request (client)</li>
- * </ol>
- * .
- */
- @Test
- public void item1() throws EdmPrimitiveTypeException {
- final URI uri = edmClient.newURIBuilder().
- appendEntitySetSegment("Accounts").appendKeySegment(102).
- appendNavigationSegment("MyPaymentInstruments").appendKeySegment(102902).build();
- final ODataEntityRequest<ClientEntity> req = edmClient.getRetrieveRequestFactory().getEntityRequest(uri);
-
- // request format (via Accept header) is set to minimal by default
- assertEquals("application/json;odata.metadata=minimal", req.getAccept());
-
- final ODataRetrieveResponse<ClientEntity> res = req.execute();
-
- // response is odata.metadata=minimal
- assertFalse(res.getContentType().contains("odata.metadata=none"));
- assertFalse(res.getContentType().contains("odata.metadata=full"));
-
- // response payload is understood
- final ClientEntity entity = res.getBody();
- assertNotNull(entity);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", entity.getTypeName().toString());
- assertEquals(102902, entity.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
- assertEquals("Edm.DateTimeOffset", entity.getProperty("CreatedDate").getPrimitiveValue().getTypeName());
- }
-
/**
* MUST be prepared to consume a response with full metadata.
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f2fd0355/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/JSONFormatConformanceTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/JSONFormatConformanceTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/JSONFormatConformanceTestITCase.java
new file mode 100644
index 0000000..ee2f1bf
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/JSONFormatConformanceTestITCase.java
@@ -0,0 +1,74 @@
+/*
+ * Copyright 2016 The Apache Software Foundation.
+ *
+ * Licensed 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.fit.tecsvc.client;
+
+import java.net.URI;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.olingo.client.api.EdmEnabledODataClient;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.domain.ClientEntity;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assume.assumeTrue;
+import org.junit.Test;
+
+
+public class JSONFormatConformanceTestITCase extends AbstractParamTecSvcITCase {
+
+ /**
+ * MUST either:
+ * <ol>
+ * <li>understand <tt>odata.metadata=minimal</tt> (section 3.1.1) or</li>
+ * <li>explicitly specify <tt>odata.metadata=none</tt>(section 3.1.3) or <tt>odata.metadata=full</tt> (section 3.1.2)
+ * in the request (client)</li>
+ * </ol>
+ * .
+ */
+ @Test
+ public void item1() throws EdmPrimitiveTypeException {
+ assumeTrue("json conformance test with content type", isJson());
+ final EdmEnabledODataClient edmClient = getEdmEnabledClient();
+ Map<String, Object> segmentValues = new LinkedHashMap<String, Object>();
+ segmentValues.put("PropertyInt16", 1);
+ segmentValues.put("PropertyString", "1");
+ final URI uri = edmClient.newURIBuilder().
+ appendEntitySetSegment("ESKeyNav").appendKeySegment(1).
+ appendNavigationSegment("NavPropertyETTwoKeyNavMany").appendKeySegment(segmentValues).build();
+ final ODataEntityRequest<ClientEntity> req = edmClient.getRetrieveRequestFactory().getEntityRequest(uri);
+
+ // request format (via Accept header) is set to minimal by default
+ //FIXME: set format to minimal?
+ assertEquals("application/json", req.getAccept());
+
+ final ODataRetrieveResponse<ClientEntity> res = req.execute();
+
+ // response is odata.metadata=minimal
+ assertFalse(res.getContentType().contains("odata.metadata=none"));
+ assertFalse(res.getContentType().contains("odata.metadata=full"));
+
+ // response payload is understood
+ final ClientEntity entity = res.getBody();
+ assertNotNull(entity);
+ String entityType = entity.getTypeName().toString();
+ assertEquals("olingo.odata.test1.ETTwoKeyNav", entityType);
+ assertEquals(1, entity.getProperty("PropertyInt16").getPrimitiveValue().toCastValue(Integer.class), 0);
+ assertEquals("olingo.odata.test1.CTPrimComp", entity.getProperty("PropertyComp").getComplexValue().getTypeName());
+ }
+}