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/07/16 11:27:13 UTC
[50/58] [abbrv] git commit: provided integration test for proxy API
design review
provided integration test for proxy API design review
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/e914d17b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/e914d17b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/e914d17b
Branch: refs/heads/master
Commit: e914d17be8b64478cf543eac797c205f645d7c23
Parents: bda5164
Author: fmartelli <fa...@gmail.com>
Authored: Mon Jul 14 17:33:24 2014 +0200
Committer: fmartelli <fa...@gmail.com>
Committed: Mon Jul 14 17:33:24 2014 +0200
----------------------------------------------------------------------
.../olingo/ext/proxy/api/AbstractEntitySet.java | 8 ++
.../commons/EntitySetInvocationHandler.java | 21 +--
.../fit/proxy/v4/APIBasicDesignTestITCase.java | 135 +++++++++++++++++++
.../olingo/fit/proxy/v4/FilterTestITCase.java | 33 -----
4 files changed, 156 insertions(+), 41 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e914d17b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
index 302096e..93ab552 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/api/AbstractEntitySet.java
@@ -72,6 +72,14 @@ public interface AbstractEntitySet<
void delete(KEY key) throws IllegalArgumentException;
/**
+ * Deletes the given entity in a batch.
+ *
+ * @param <S>
+ * @param entity to be deleted
+ */
+ <S extends T> void delete(S entities);
+
+ /**
* Deletes the given entities in a batch.
*
* @param <S>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e914d17b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
----------------------------------------------------------------------
diff --git a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
index b969c03..434dfdb 100644
--- a/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
+++ b/ext/client-proxy/src/main/java/org/apache/olingo/ext/proxy/commons/EntitySetInvocationHandler.java
@@ -376,16 +376,21 @@ class EntitySetInvocationHandler<
}
@Override
- public <S extends T> void delete(final Iterable<S> entities) {
+ public <S extends T> void delete(final S entity) {
final EntityContext entityContext = getContext().entityContext();
- for (T en : entities) {
- final EntityInvocationHandler entity = (EntityInvocationHandler) Proxy.getInvocationHandler(en);
- if (entityContext.isAttached(entity)) {
- entityContext.setStatus(entity, AttachedEntityStatus.DELETED);
- } else {
- entityContext.attach(entity, AttachedEntityStatus.DELETED);
- }
+ final EntityInvocationHandler handler = (EntityInvocationHandler) Proxy.getInvocationHandler(entity);
+ if (entityContext.isAttached(handler)) {
+ entityContext.setStatus(handler, AttachedEntityStatus.DELETED);
+ } else {
+ entityContext.attach(handler, AttachedEntityStatus.DELETED);
+ }
+ }
+
+ @Override
+ public <S extends T> void delete(final Iterable<S> entities) {
+ for (S en : entities) {
+ delete(en);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e914d17b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
new file mode 100644
index 0000000..e7a020a
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/APIBasicDesignTestITCase.java
@@ -0,0 +1,135 @@
+/*
+ * 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 static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.math.BigDecimal;
+import java.sql.Timestamp;
+import java.util.Arrays;
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.ext.proxy.Service;
+import static org.apache.olingo.fit.proxy.v4.AbstractTestITCase.container;
+//CHECKSTYLE:OFF (Maven checkstyle)
+import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.InMemoryEntities;
+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.Order;
+//CHECKSTYLE:ON (Maven checkstyle)
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity create operations.
+ */
+public class APIBasicDesignTestITCase extends AbstractTestITCase {
+
+ protected Service<EdmEnabledODataClient> getContainerFactory() {
+ return containerFactory;
+ }
+
+ protected InMemoryEntities getContainer() {
+ return container;
+ }
+
+ @Test
+ public void readAndCheckForPrimitive() {
+ final Customer customer = container.getCustomers().getByKey(1);
+ assertNotNull(customer);
+ assertNull(customer.getPersonID());
+
+ assertEquals(1, customer.load().getPersonID(), 0);
+ }
+
+ @Test
+ public void loadWithSelect() {
+ org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order order =
+ container.getOrders().getByKey(8);
+ assertNull(order.getOrderID());
+ assertNull(order.getOrderDate());
+
+ order.select("OrderID");
+ order.load();
+
+ assertNull(order.getOrderDate());
+ assertNotNull(order.getOrderID());
+
+ order.clear();
+ order.load();
+ assertNotNull(order.getOrderDate());
+ assertNotNull(order.getOrderID());
+ }
+
+ @Test
+ public void loadWithSelectAndExpand() {
+ final Customer customer = container.getCustomers().getByKey(1);
+
+ customer.expand("Orders");
+ customer.select("Orders", "PersonID");
+
+ customer.load();
+ assertEquals(1, customer.getOrders().size());
+ }
+
+ @Test
+ public void createDelete() {
+ // Create order ....
+ final Order order = container.getOrders().newOrder();
+ order.setOrderID(1105);
+
+ final Calendar orderDate = Calendar.getInstance(TimeZone.getTimeZone("GMT"));
+ orderDate.clear();
+ orderDate.set(2011, 3, 4, 16, 3, 57);
+ order.setOrderDate(new Timestamp(orderDate.getTimeInMillis()));
+
+ order.setShelfLife(BigDecimal.ZERO);
+ order.setOrderShelfLifes(Arrays.asList(new BigDecimal[] {BigDecimal.TEN.negate(), BigDecimal.TEN}));
+
+ container.flush();
+
+ Order actual = container.getOrders().getByKey(1105);
+ assertNull(actual.getOrderID());
+
+ actual.load();
+ assertEquals(1105, actual.getOrderID(), 0);
+ assertEquals(orderDate.getTimeInMillis(), actual.getOrderDate().getTime());
+ assertEquals(BigDecimal.ZERO, actual.getShelfLife());
+ assertEquals(2, actual.getOrderShelfLifes().size());
+
+ containerFactory.getContext().detachAll();
+
+ // Delete order ...
+ container.getOrders().delete(container.getOrders().getByKey(1105));
+ actual = container.getOrders().getByKey(1105);
+ assertNull(actual);
+
+ container.flush();
+
+ containerFactory.getContext().detachAll();
+ try {
+ container.getOrders().getByKey(105).load();
+ fail();
+ } catch (IllegalArgumentException e) {
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/e914d17b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java
index 2b66aba..ca66587 100644
--- a/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/proxy/v4/FilterTestITCase.java
@@ -21,8 +21,6 @@ package org.apache.olingo.fit.proxy.v4;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
import java.util.ArrayList;
import java.util.Collections;
@@ -31,7 +29,6 @@ import java.util.List;
import org.apache.olingo.ext.proxy.api.Search;
import org.apache.olingo.ext.proxy.api.Sort;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.People;
-import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Customer;
//CHECKSTYLE:OFF (Maven checkstyle)
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Person;
import org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.PersonCollection;
@@ -85,34 +82,4 @@ public class FilterTestITCase extends AbstractTestITCase {
final PersonCollection result = search.getResult();
assertFalse(result.isEmpty());
}
-
- @Test
- public void loadWithSelect() {
- org.apache.olingo.fit.proxy.v4.staticservice.microsoft.test.odata.services.odatawcfservice.types.Order order =
- container.getOrders().getByKey(8);
- assertNull(order.getOrderID());
- assertNull(order.getOrderDate());
-
- order.select("OrderID");
- order.load();
-
- assertNull(order.getOrderDate());
- assertNotNull(order.getOrderID());
-
- order.clear();
- order.load();
- assertNotNull(order.getOrderDate());
- assertNotNull(order.getOrderID());
- }
-
- @Test
- public void loadWithSelectAndExpand() {
- final Customer customer = container.getCustomers().getByKey(1);
-
- customer.expand("Orders");
- customer.select("Orders", "PersonID");
-
- customer.load();
- assertEquals(1, customer.getOrders().size());
- }
}