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/03/31 17:57:38 UTC
git commit: [OLINGO-175] V4 Entity create test
Repository: olingo-odata4
Updated Branches:
refs/heads/olingo200 c73772f04 -> 850d44e00
[OLINGO-175] V4 Entity create 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/850d44e0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/850d44e0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/850d44e0
Branch: refs/heads/olingo200
Commit: 850d44e00ebf4a8e9a588b0cf5a46ae4d4a5fb55
Parents: c73772f
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Mon Mar 31 17:57:31 2014 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Mon Mar 31 17:57:31 2014 +0200
----------------------------------------------------------------------
.../olingo/fit/utils/AbstractUtilities.java | 13 +++
.../org/apache/olingo/fit/utils/Commons.java | 1 +
.../core/it/v4/EntityCreateTestITCase.java | 84 ++++++++++++++++++++
3 files changed, 98 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/850d44e0/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
index 5b23366..b4d71b5 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/AbstractUtilities.java
@@ -511,6 +511,19 @@ public abstract class AbstractUtilities {
}
}
sequence.put(entitySetName, Integer.valueOf(res));
+ } else if ("Orders".equals(entitySetName)) {
+ try {
+ final Map<String, InputStream> value =
+ getPropertyValues(entity, Collections.<String>singletonList("OrderID"));
+ res = value.isEmpty() ? null : IOUtils.toString(value.values().iterator().next());
+ } catch (Exception e) {
+ if (sequence.containsKey(entitySetName)) {
+ res = String.valueOf(sequence.get(entitySetName) + 1);
+ } else {
+ throw new Exception(String.format("Unable to retrieve entity key value for %s", entitySetName));
+ }
+ }
+ sequence.put(entitySetName, Integer.valueOf(res));
} else if ("Customer".equals(entitySetName)) {
try {
final Map<String, InputStream> value =
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/850d44e0/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
index c0031f1..a1c658a 100644
--- a/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
+++ b/fit/src/main/java/org/apache/olingo/fit/utils/Commons.java
@@ -67,6 +67,7 @@ public abstract class Commons {
sequence.put("Order", 1000);
sequence.put("ComputerDetail", 1000);
sequence.put("AllGeoTypesSet", 1000);
+ sequence.put("Orders", 1000);
mediaContent.put("CustomerInfo", "CustomerinfoId");
mediaContent.put("Car", "VIN");
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/850d44e0/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
new file mode 100644
index 0000000..0044e73
--- /dev/null
+++ b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
@@ -0,0 +1,84 @@
+/*
+ * 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.assertNotNull;
+
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.domain.v3.ODataCollectionValueImpl;
+import org.apache.olingo.commons.core.domain.v4.ODataEntityImpl;
+import org.junit.Test;
+
+public class EntityCreateTestITCase extends AbstractTestITCase {
+
+ private void createOrder(final ODataPubFormat format, final int id) {
+ final ODataEntity order = new ODataEntityImpl("Microsoft.Test.OData.Services.ODataWCFService.Order");
+
+ final ODataProperty orderId = getClient().getObjectFactory().newPrimitiveProperty("OrderID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Int32).setValue(id).build());
+ order.getProperties().add(orderId);
+
+ final ODataProperty orderDate = getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2011-03-04T16:03:57Z").build());
+ order.getProperties().add(orderDate);
+
+ final ODataProperty shelfLife = getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ order.getProperties().add(shelfLife);
+
+ // TODO: this should be possible via getClient().getObjectFactory().newCollectionValue()
+ final ODataCollectionValue<ODataValue> orderShelfLifesValue =
+ new ODataCollectionValueImpl("Collection(Duration)");
+ orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build());
+ final ODataProperty orderShelfLifes = getClient().getObjectFactory().newCollectionProperty("OrderShelfLifes",
+ orderShelfLifesValue);
+ order.getProperties().add(orderShelfLifes);
+
+ final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Orders").build(), order);
+ req.setFormat(format);
+ final ODataEntity created = req.execute().getBody();
+ assertNotNull(created);
+ assertEquals(2, created.getProperty("OrderShelfLifes").getCollectionValue().size());
+ }
+
+ @Test
+ public void atom() {
+ createOrder(ODataPubFormat.ATOM, 1000);
+ }
+
+ @Test
+ public void json() {
+ createOrder(ODataPubFormat.JSON, 1001);
+ }
+}