You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by fm...@apache.org on 2014/05/13 15:16:57 UTC
git commit: [OLINGO-260] provided entity update integration test on
proxy
Repository: olingo-odata4
Updated Branches:
refs/heads/master 36219a267 -> f170953ce
[OLINGO-260] provided entity update integration test on proxy
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/f170953c
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/f170953c
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/f170953c
Branch: refs/heads/master
Commit: f170953cecd1d3e29214e520ad8e586214e5f115
Parents: 36219a2
Author: fmartelli <fa...@gmail.com>
Authored: Tue May 13 15:16:45 2014 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Tue May 13 15:16:45 2014 +0200
----------------------------------------------------------------------
.../resources/V30/Customer/-9/links/Orders.xml | 24 ++++
.../fit/proxy/v3/EntityUpdateTestITCase.java | 127 +++++++++++++++++++
.../fit/proxy/v4/EntityUpdateTestITCase.java | 118 +++++++++++++++++
3 files changed, 269 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f170953c/fit/src/main/resources/V30/Customer/-9/links/Orders.xml
----------------------------------------------------------------------
diff --git a/fit/src/main/resources/V30/Customer/-9/links/Orders.xml b/fit/src/main/resources/V30/Customer/-9/links/Orders.xml
new file mode 100644
index 0000000..6b6b5d8
--- /dev/null
+++ b/fit/src/main/resources/V30/Customer/-9/links/Orders.xml
@@ -0,0 +1,24 @@
+<?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.
+
+-->
+<links xmlns="http://schemas.microsoft.com/ado/2007/08/dataservices">
+ <uri>http://localhost:8080/DefaultService.svc/Order(-9)</uri>
+</links>
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f170953c/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java
new file mode 100644
index 0000000..82660eb
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java
@@ -0,0 +1,127 @@
+/*
+ * 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.fit.proxy.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+
+import java.lang.reflect.Proxy;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.ConcurrencyInfo;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.Customer;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.Message;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.MessageKey;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.Order;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.OrderCollection;
+import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.
+ types.Product;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity update operations.
+ */
+public class EntityUpdateTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void update() {
+ Order order = container.getOrder().get(-9);
+
+ final ConcurrencyInfo ci = order.getConcurrency();
+ ci.setToken("XXX");
+
+ container.flush();
+
+ order = container.getOrder().get(-9);
+ assertEquals("XXX", order.getConcurrency().getToken());
+ }
+
+ @Test
+ public void multiKey() {
+ final MessageKey key = new MessageKey();
+ key.setFromUsername("1");
+ key.setMessageId(-10);
+
+ Message message = container.getMessage().get(key);
+ assertNotNull(message);
+
+ message.setBody("XXX");
+
+ container.flush();
+
+ message = container.getMessage().get(key);
+ assertNotNull(message);
+ assertEquals("XXX", message.getBody());
+ }
+
+ @Test
+ public void patchLink() {
+ Order order = container.getOrder().newOrder();
+ order.setOrderId(400);
+ order.setCustomerId(-9);
+
+ OrderCollection orders = container.getOrder().newOrderCollection();
+ orders.add(order);
+
+ Customer customer = container.getCustomer().get(-9);
+ customer.setOrders(orders);
+ order.setCustomer(customer);
+
+ container.flush();
+
+ order = container.getOrder().get(400);
+ assertEquals(400, order.getOrderId().intValue());
+ assertEquals(-9, order.getCustomerId().intValue());
+
+ customer = container.getCustomer().get(-9);
+
+ assertEquals(2, customer.getOrders().size());
+
+ int count = 0;
+ for (Order inside : customer.getOrders()) {
+ if (inside.getOrderId() == 400) {
+ count++;
+ }
+ }
+ assertEquals(1, count);
+ assertEquals(-9, order.getCustomer().getCustomerId(), 0);
+ }
+
+ @Test
+ public void concurrentModification() {
+ Product product = container.getProduct().get(-10);
+ final String etag = ((EntityTypeInvocationHandler) Proxy.getInvocationHandler(product)).getETag();
+ assertTrue(StringUtils.isNotBlank(etag));
+
+ final String baseConcurrency = String.valueOf(System.currentTimeMillis());
+ product.setBaseConcurrency(baseConcurrency);
+
+ container.flush();
+
+ product = container.getProduct().get(-10);
+ assertEquals(baseConcurrency, product.getBaseConcurrency());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f170953c/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java
new file mode 100644
index 0000000..cd00901
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/EntityUpdateTestITCase.java
@@ -0,0 +1,118 @@
+/*
+ * 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.fit.proxy.v4;
+
+import java.lang.reflect.Proxy;
+import java.math.BigDecimal;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.ext.proxy.commons.EntityTypeInvocationHandler;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Address;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderCollection;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Customer;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderDetail;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.OrderDetailKey;
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity update operations.
+ */
+public class EntityUpdateTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void update() {
+ Person person = container.getPeople().get(1);
+
+ final Address address = person.getHomeAddress();
+ address.setCity("XXX");
+
+ container.flush();
+
+ person = container.getPeople().get(1);
+ assertEquals("XXX", person.getHomeAddress().getCity());
+ }
+
+ @Test
+ public void multiKey() {
+ final OrderDetailKey orderDetailKey = new OrderDetailKey();
+ orderDetailKey.setOrderID(7);
+ orderDetailKey.setProductID(5);
+
+ OrderDetail orderDetail = container.getOrderDetails().get(orderDetailKey);
+ assertNotNull(orderDetail);
+ assertEquals(7, orderDetail.getOrderID(), 0);
+ assertEquals(5, orderDetail.getProductID(), 0);
+
+ orderDetail.setQuantity(5);
+
+ container.flush();
+
+ orderDetail = container.getOrderDetails().get(orderDetailKey);
+ orderDetail.setQuantity(5);
+ }
+
+ @Test
+ public void patchLink() {
+ Order order = container.getOrders().newOrder();
+ order.setOrderID(400);
+
+ OrderCollection orders = container.getOrders().newOrderCollection();
+ orders.add(order);
+
+ Customer customer = container.getCustomers().get(1);
+ customer.setOrders(orders);
+ order.setCustomerForOrder(customer);
+
+ container.flush();
+
+ order = container.getOrders().get(400);
+ assertEquals(400, order.getOrderID().intValue());
+
+ customer = container.getCustomers().get(1);
+
+ assertEquals(2, customer.getOrders().size());
+
+ int count = 0;
+ for (Order inside : customer.getOrders()) {
+ if (inside.getOrderID() == 400) {
+ count++;
+ }
+ }
+ assertEquals(1, count);
+ assertEquals(1, order.getCustomerForOrder().getPersonID(), 0);
+ }
+
+ @Test
+ public void concurrentModification() {
+ Order order = container.getOrders().get(8);
+ final String etag = ((EntityTypeInvocationHandler) Proxy.getInvocationHandler(order)).getETag();
+ assertTrue(StringUtils.isNotBlank(etag));
+
+ order.setShelfLife(BigDecimal.TEN);
+
+ container.flush();
+
+ order = container.getOrders().get(8);
+ assertEquals(BigDecimal.TEN, order.getShelfLife());
+ }
+}