provided integration test for proxy API design review

This commit is contained in:
fmartelli 2014-07-14 17:33:24 +02:00
parent bda51643b1
commit e914d17be8
4 changed files with 156 additions and 41 deletions

View File

@ -71,6 +71,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.
*

View File

@ -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);
}
}

View File

@ -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) {
}
}
}

View File

@ -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());
}
}