http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java deleted file mode 100644 index ecfa21e..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ActionOverloadingTestITCase.java +++ /dev/null @@ -1,113 +0,0 @@ -/* - * 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.assertFalse; -import static org.junit.Assert.assertNotNull; - -import org.apache.olingo.client.api.v3.EdmEnabledODataClient; -import org.apache.olingo.commons.api.format.ContentType; -import org.junit.Test; - -//CHECKSTYLE:OFF (Maven checkstyle) -import org.apache.olingo.fit.proxy.v3.actionoverloading.Service; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.Employee; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.OrderLineKey; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee; -import org.apache.olingo.fit.proxy.v3.actionoverloading.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection; -//CHECKSTYLE:ON (Maven checkstyle) - -/** - * This is the unit test class to check actions overloading. - */ -public class ActionOverloadingTestITCase extends AbstractTestITCase { - - private DefaultContainer getContainer() { - final Service<EdmEnabledODataClient> ecf = - Service.getV3(testActionOverloadingServiceRootURL); - ecf.getClient().getConfiguration().setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); - return ecf.getEntityContainer(DefaultContainer.class); - } - - @Test - public void retrieveProduct() { - final DefaultContainer aocontainer = getContainer(); - - int res = aocontainer.operations().retrieveProduct().execute(); - assertEquals(-10, res); - - service.getContext().detachAll(); - - res = aocontainer.getProduct().getByKey(-10).operations().retrieveProduct().execute(); - assertEquals(-10, res); - - service.getContext().detachAll(); - - final OrderLineKey key = new OrderLineKey(); - key.setOrderId(-10); - key.setProductId(-10); - - res = aocontainer.getOrderLine().getByKey(key).operations().retrieveProduct().execute(); - assertEquals(-10, res); - } - - @Test - public void increaseSalaries() { - final DefaultContainer aocontainer = getContainer(); - - EmployeeCollection ecoll = aocontainer.getPerson().execute(EmployeeCollection.class); - assertFalse(ecoll.isEmpty()); - - Employee empl = ecoll.iterator().next(); - assertNotNull(empl); - - empl.getPersonId(); - int salary = empl.getSalary(); - - ecoll.operations().increaseSalaries(5).execute(); - - // the invoke above changed the local entities, re-read - service.getContext().detachAll(); - ecoll = aocontainer.getPerson().execute(EmployeeCollection.class); - empl = ecoll.iterator().next(); - - assertEquals(salary + 5, empl.getSalary(), 0); - - SpecialEmployeeCollection secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class); - assertFalse(secoll.isEmpty()); - - SpecialEmployee sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1]; - assertNotNull(sempl); - - sempl.getPersonId(); - salary = sempl.getSalary(); - - secoll.operations().increaseSalaries(5).execute(); - - // the invoke above changed the local entities, re-read - service.getContext().detachAll(); - secoll = aocontainer.getPerson().execute(SpecialEmployeeCollection.class); - sempl = secoll.toArray(new SpecialEmployee[secoll.size()])[1]; - - assertEquals(salary + 5, sempl.getSalary(), 0); - } -}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java deleted file mode 100644 index 67cb0a1..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/AsyncTestITCase.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * 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.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.util.UUID; -import java.util.concurrent.ExecutionException; -import java.util.concurrent.Future; -import org.junit.Test; - -//CHECKSTYLE:OFF (Maven checkstyle) -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Product; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ProductCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection; -//CHECKSTYLE:ON (Maven checkstyle) - -public class AsyncTestITCase extends AbstractTestITCase { - - @Test - public void retrieveEntitySet() throws InterruptedException, ExecutionException { - final Future<ProductCollection> futureProds = container.getProduct().executeAsync(); - assertNotNull(futureProds); - - while (!futureProds.isDone()) { - Thread.sleep(1000L); - } - - final ProductCollection products = futureProds.get(); - assertNotNull(products); - assertFalse(products.isEmpty()); - for (Product product : products) { - assertNotNull(product); - } - } - - @Test - public void updateEntity() throws InterruptedException, ExecutionException { - final String random = UUID.randomUUID().toString(); - - final Product product = container.getProduct().getByKey(-10); - product.setDescription("AsyncTest#updateEntity " + random); - - final Future<Void> futureFlush = container.flushAsync(); - assertNotNull(futureFlush); - - while (!futureFlush.isDone()) { - Thread.sleep(1000L); - } - - final Future<? extends Product> futureProd = container.getProduct().getByKey(-10).loadAsync(); - assertEquals("AsyncTest#updateEntity " + random, futureProd.get().load().getDescription()); - } - - @Test - public void polymorphQuery() throws Exception { - final Future<EmployeeCollection> queryEmployee = - container.getPerson().executeAsync(EmployeeCollection.class); - assertFalse(queryEmployee.get().isEmpty()); - - final Future<SpecialEmployeeCollection> querySpecialEmployee = - container.getPerson().executeAsync(SpecialEmployeeCollection.class); - assertFalse(querySpecialEmployee.get().isEmpty()); - - assertTrue(container.getPerson().execute().size() - > container.getPerson().execute(EmployeeCollection.class).size() - + container.getPerson().execute(SpecialEmployeeCollection.class).size()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java deleted file mode 100644 index a66442e..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/ContextTestITCase.java +++ /dev/null @@ -1,513 +0,0 @@ -/* - * 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; - -//CHECKSTYLE:OFF (Maven checkstyle) -import org.apache.olingo.ext.proxy.api.annotations.NavigationProperty; -import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler; -import org.apache.olingo.ext.proxy.context.AttachedEntityStatus; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetails; -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.CustomerInfo; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Login; -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.junit.Test; - -import java.lang.reflect.Proxy; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Map; -import org.apache.olingo.ext.proxy.api.PrimitiveCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetailsCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.PhoneCollection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -//CHECKSTYLE:ON (Maven checkstyle) - -/** - * This is the unit test class to check entity retrieve operations. - */ -public class ContextTestITCase extends AbstractTestITCase { - - @Test - public void attachDetachNewEntity() { - final Customer customer1 = container.newEntityInstance(Customer.class); - final Customer customer2 = container.newEntityInstance(Customer.class); - - final EntityInvocationHandler source1 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer1); - final EntityInvocationHandler source2 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer2); - - container.getCustomer().add(customer1); - container.getCustomer().add(customer2); - - assertTrue(service.getContext().entityContext().isAttached(source1)); - assertTrue(service.getContext().entityContext().isAttached(source2)); - - service.getContext().entityContext().detach(source1); - assertFalse(service.getContext().entityContext().isAttached(source1)); - assertTrue(service.getContext().entityContext().isAttached(source2)); - - service.getContext().entityContext().detach(source2); - assertFalse(service.getContext().entityContext().isAttached(source1)); - assertFalse(service.getContext().entityContext().isAttached(source2)); - } - - @Test - public void attachDetachExistingEntity() { - final Customer customer1 = container.getCustomer().getByKey(-10); - final Customer customer2 = container.getCustomer().getByKey(-9); - final Customer customer3 = container.getCustomer().getByKey(-10); - - final EntityInvocationHandler source1 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer1); - final EntityInvocationHandler source2 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer2); - final EntityInvocationHandler source3 = - (EntityInvocationHandler) Proxy.getInvocationHandler(customer3); - - assertFalse(service.getContext().entityContext().isAttached(source1)); - assertFalse(service.getContext().entityContext().isAttached(source2)); - assertFalse(service.getContext().entityContext().isAttached(source3)); - - service.getContext().entityContext().attach(source1); - assertTrue(service.getContext().entityContext().isAttached(source1)); - assertFalse(service.getContext().entityContext().isAttached(source2)); - assertTrue(service.getContext().entityContext().isAttached(source3)); - - service.getContext().entityContext().attach(source2); - assertTrue(service.getContext().entityContext().isAttached(source1)); - assertTrue(service.getContext().entityContext().isAttached(source2)); - assertTrue(service.getContext().entityContext().isAttached(source3)); - - try { - service.getContext().entityContext().attach(source3); - fail(); - } catch (IllegalStateException ignore) { - // ignore - } - - service.getContext().entityContext().detach(source1); - assertFalse(service.getContext().entityContext().isAttached(source1)); - assertTrue(service.getContext().entityContext().isAttached(source2)); - assertFalse(service.getContext().entityContext().isAttached(source3)); - - service.getContext().entityContext().detach(source2); - assertFalse(service.getContext().entityContext().isAttached(source1)); - assertFalse(service.getContext().entityContext().isAttached(source2)); - assertFalse(service.getContext().entityContext().isAttached(source3)); - } - - @Test - public void linkTargetExisting() { - final Customer customer = container.newEntityInstance(Customer.class); - final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(11); - - customer.setInfo(customerInfo); - assertNotNull(customer.getInfo()); - - container.getCustomer().add(customer); - - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); - - assertTrue(service.getContext().entityContext().isAttached(source)); - assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - - checkUnidirectional("Info", source, "Customer", target, false); - - service.getContext().entityContext().detachAll(); - - assertFalse(service.getContext().entityContext().isAttached(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - } - - @Test - public void linkSourceExisting() { - final Customer customer = container.getCustomer().getByKey(-10); - - final CustomerInfo customerInfo = container.newEntityInstance(CustomerInfo.class); - - customer.setInfo(customerInfo); - assertNotNull(customer.getInfo()); - - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); - - assertTrue(service.getContext().entityContext().isAttached(source)); - assertEquals(AttachedEntityStatus.CHANGED, service.getContext().entityContext().getStatus(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - - checkUnidirectional("Info", source, "Customer", target, false); - - service.getContext().entityContext().detachAll(); - - assertFalse(service.getContext().entityContext().isAttached(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - } - - @Test - public void linkBothExisting() { - final Customer customer = container.getCustomer().getByKey(-10); - final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(12); - - customer.setInfo(customerInfo); - assertNotNull(customer.getInfo()); - - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo); - - assertTrue(service.getContext().entityContext().isAttached(source)); - assertEquals(AttachedEntityStatus.CHANGED, service.getContext().entityContext().getStatus(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - - checkUnidirectional("Info", source, "Customer", target, false); - - service.getContext().entityContext().detachAll(); - - assertFalse(service.getContext().entityContext().isAttached(source)); - assertFalse(service.getContext().entityContext().isAttached(target)); - } - - @Test - public void linkEntitySet() { - final Customer customer = container.newEntityInstance(Customer.class); - - final OrderCollection toBeLinked = container.newEntityCollection(OrderCollection.class); - toBeLinked.add(container.newEntityInstance(Order.class)); - toBeLinked.add(container.newEntityInstance(Order.class)); - toBeLinked.add(container.newEntityInstance(Order.class)); - - customer.setOrders(toBeLinked); - assertNotNull(customer.getOrders()); - assertEquals(3, customer.getOrders().size()); - - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - - container.getCustomer().add(customer); - - assertTrue(service.getContext().entityContext().isAttached(source)); - assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source)); - assertEquals(3, ((Collection<?>) (source.getLinkChanges().entrySet().iterator().next().getValue())).size()); - - for (Order order : toBeLinked) { - final EntityInvocationHandler target = (EntityInvocationHandler) Proxy.getInvocationHandler(order); - container.getOrder().add(order); - - assertTrue(service.getContext().entityContext().isAttached(target)); - assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(target)); - checkUnidirectional("Orders", source, "Customer", target, true); - } - - service.getContext().entityContext().detachAll(); - - assertFalse(service.getContext().entityContext().isAttached(source)); - - for (Order order : toBeLinked) { - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(order))); - } - } - - @Test - public void addProperty() { - final Customer customer = container.newEntityInstance(Customer.class); - customer.setCustomerId(100); - - final ContactDetails cd = container.newComplexInstance(ContactDetails.class); - customer.setPrimaryContactInfo(cd); - - PrimitiveCollection<String> alternativeNames = container.newPrimitiveCollection(String.class); - alternativeNames.add("alternative1"); - alternativeNames.add("alternative2"); - cd.setAlternativeNames(alternativeNames); - - final ContactDetails bcd = container.newComplexInstance(ContactDetails.class); - final ContactDetailsCollection bci = container.newComplexCollection(ContactDetailsCollection.class); - bci.add(bcd); - - customer.setBackupContactInfo(bci); - - alternativeNames = container.newPrimitiveCollection(String.class); - alternativeNames.add("alternative3"); - alternativeNames.add("alternative4"); - bcd.setAlternativeNames(alternativeNames); - - assertEquals(Integer.valueOf(100), customer.getCustomerId()); - assertNotNull(customer.getPrimaryContactInfo().getAlternativeNames()); - assertEquals(2, customer.getPrimaryContactInfo().getAlternativeNames().size()); - assertTrue(customer.getPrimaryContactInfo().getAlternativeNames().contains("alternative1")); - assertEquals(2, customer.getBackupContactInfo().iterator().next().getAlternativeNames().size()); - assertTrue(customer.getBackupContactInfo().iterator().next().getAlternativeNames().contains("alternative4")); - - container.getCustomer().add(customer); - - final EntityInvocationHandler source = (EntityInvocationHandler) Proxy.getInvocationHandler(customer); - - assertTrue(service.getContext().entityContext().isAttached(source)); - assertEquals(AttachedEntityStatus.NEW, service.getContext().entityContext().getStatus(source)); - - service.getContext().entityContext().detachAll(); - - assertFalse(service.getContext().entityContext().isAttached(source)); - } - - @Test - public void readEntityInTheContext() { - CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16).load(); - customerInfo.setInformation("some other info ..."); - - assertEquals("some other info ...", customerInfo.getInformation()); - - customerInfo = container.getCustomerInfo().getByKey(16); - assertEquals("some other info ...", customerInfo.getInformation()); - - service.getContext().entityContext().detachAll(); - customerInfo = container.getCustomerInfo().getByKey(16); - assertNotEquals("some other info ...", customerInfo.getInformation()); - } - - @Test - public void readAllWithEntityInTheContext() { - CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16).load(); - customerInfo.setInformation("some other info ..."); - - assertEquals("some other info ...", customerInfo.getInformation()); - - boolean found = false; - for (CustomerInfo info : container.getCustomerInfo().execute()) { - if (info.getCustomerInfoId() == 16) { - assertEquals("some other info ...", customerInfo.getInformation()); - found = true; - } - } - assertTrue(found); - - service.getContext().entityContext().detachAll(); - - found = false; - for (CustomerInfo info : container.getCustomerInfo().execute()) { - if (info.getCustomerInfoId() == 16) { - assertNotEquals("some other info ...", info.getInformation()); - found = true; - } - } - assertTrue(found); - } - - @Test - public void checkContextInCaseOfErrors() { - service.getContext().entityContext().detachAll(); - - final Login login = container.newEntityInstance(Login.class); - - final EntityInvocationHandler handler = (EntityInvocationHandler) Proxy.getInvocationHandler(login); - assertFalse(service.getContext().entityContext().isAttached(handler)); - - container.flush(); // Login will be ignored because not added to an entity set. - - container.getLogin().add(login); // now has been added - - assertTrue(service.getContext().entityContext().isAttached(handler)); - - try { - container.flush(); - fail(); - } catch (Exception e) { - // ignore - } - - assertTrue(service.getContext().entityContext().isAttached(handler)); - - login.setCustomerId(-10); - login.setUsername("customer"); - - container.flush(); - assertFalse(service.getContext().entityContext().isAttached(handler)); - assertNotNull(container.getLogin().getByKey("customer")); - - container.getLogin().delete(login.getUsername()); - assertTrue(service.getContext().entityContext().isAttached(handler)); - - container.flush(); - assertFalse(service.getContext().entityContext().isAttached(handler)); - - try { - container.getLogin().getByKey("customer").load(); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void flushTest() { - Customer customer = container.newEntityInstance(Customer.class); - customer.setCustomerId(300); - customer.setName("samplename"); - - final List<Integer> keys = new ArrayList<Integer>(); - keys.add(-200); - keys.add(-201); - keys.add(-202); - - final OrderCollection toBeLinked = container.newEntityCollection(OrderCollection.class); - for (Integer key : keys) { - final Order order = container.newEntityInstance(Order.class); - order.setOrderId(key); - order.setCustomerId(300); - order.setCustomer(customer); - toBeLinked.add(order); - } - - customer.setOrders(toBeLinked); - - final CustomerInfo customerInfo = container.getCustomerInfo().getByKey(16); - customerInfo.setInformation("some new info ..."); - customer.setInfo(customerInfo); - - final ContactDetails cd = container.newComplexInstance(ContactDetails.class); - PrimitiveCollection<String> alternativeNames = container.newPrimitiveCollection(String.class); - alternativeNames.add("alternative1"); - alternativeNames.add("alternative2"); - cd.setAlternativeNames(alternativeNames); - - final PrimitiveCollection<String> emailBag = container.newPrimitiveCollection(String.class); - alternativeNames.add("[email protected]"); - cd.setEmailBag(emailBag); - - cd.setMobilePhoneBag(container.newComplexCollection(PhoneCollection.class)); // empty - - final ContactDetails bcd = container.newComplexInstance(ContactDetails.class); - - alternativeNames = container.newPrimitiveCollection(String.class); - alternativeNames.add("alternative3"); - alternativeNames.add("alternative4"); - - bcd.setAlternativeNames(alternativeNames); - bcd.setEmailBag(container.newPrimitiveCollection(String.class)); - bcd.setMobilePhoneBag(container.newComplexCollection(PhoneCollection.class)); // empty - - customer.setPrimaryContactInfo(cd); - - final ContactDetailsCollection bci = container.newComplexCollection(ContactDetailsCollection.class); - bci.add(bcd); - - customer.setBackupContactInfo(bci); - - container.getCustomer().add(customer); - - assertTrue(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo))); - assertTrue(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); - for (Order linked : toBeLinked) { - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); - } - - container.flush(); - - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customerInfo))); - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); - for (Order linked : toBeLinked) { - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); - } - - assertEquals("some new info ...", container.getCustomerInfo().getByKey(16).load().getInformation()); - - container.getOrder().delete(toBeLinked); - container.getCustomer().delete(customer.getCustomerId()); - - assertTrue(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); - for (Order linked : toBeLinked) { - assertTrue(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); - } - - container.flush(); - - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(customer))); - for (Order linked : toBeLinked) { - assertFalse(service.getContext().entityContext(). - isAttached((EntityInvocationHandler) Proxy.getInvocationHandler(linked))); - } - } - - private void checkUnlink( - final String sourceName, - final EntityInvocationHandler source) { - - boolean found = false; - for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) { - if (property.getKey().name().equals(sourceName)) { - found = true; - } - } - assertFalse(found); - } - - private void checkLink( - final String sourceName, - final EntityInvocationHandler source, - final EntityInvocationHandler target, - final boolean isCollection) { - - boolean found = false; - for (Map.Entry<NavigationProperty, Object> property : source.getLinkChanges().entrySet()) { - if (property.getKey().name().equals(sourceName)) { - if (isCollection) { - found = false; - for (Object proxy : (Collection<?>) property.getValue()) { - if (target.equals(Proxy.getInvocationHandler(proxy))) { - found = true; - } - } - } else { - found = target.equals(Proxy.getInvocationHandler(property.getValue())); - } - } - } - assertTrue(found); - } - - private void checkUnidirectional( - final String sourceName, - final EntityInvocationHandler source, - final String targetName, - final EntityInvocationHandler target, - final boolean isCollection) { - - checkLink(sourceName, source, target, isCollection); - checkUnlink(targetName, target); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java deleted file mode 100644 index bda7f9e..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityCreateTestITCase.java +++ /dev/null @@ -1,229 +0,0 @@ -/* - * 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; - -//CHECKSTYLE:OFF (Maven checkstyle) -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.Employee; -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.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -//CHECKSTYLE:ON (Maven checkstyle) - -/** - * This is the unit test class to check entity create operations. - */ -public class EntityCreateTestITCase extends AbstractTestITCase { - - @Test - public void create() { - container.getCustomer().getByKey(-10); - final String sampleName = "sample customer from proxy"; - final Integer id = 100; - - getSampleCustomerProfile(id, sampleName, container); - container.flush(); - - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); - - container.getCustomer().delete(actual.getCustomerId()); - actual = container.getCustomer().getByKey(id); - assertNull(actual); - - service.getContext().detachAll(); - actual = container.getCustomer().getByKey(id).load(); - - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); - - try { - container.getCustomer().getByKey(id).load(); - fail(); - } catch (IllegalArgumentException e) { - } - - service.getContext().detachAll(); - - try { - container.getCustomer().getByKey(id).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void createEmployee() { - final Integer id = 101; - - final Employee employee = container.newEntityInstance(Employee.class); - employee.setPersonId(id); - employee.setName("sample employee from proxy"); - employee.setManagersPersonId(-9918); - employee.setSalary(2147483647); - employee.setTitle("CEO"); - - container.getPerson().add(employee); - container.flush(); - - Employee actual = container.getPerson().getByKey(id, Employee.class).load(); - assertNotNull(actual); - assertEquals(id, actual.getPersonId()); - - service.getContext().detachAll(); - actual = container.getPerson().getByKey(id, Employee.class).load(); - assertNotNull(actual); - - container.getPerson().delete(actual.getPersonId()); - container.flush(); - - try { - container.getPerson().getByKey(id, Employee.class).load(); - fail(); - } catch (IllegalArgumentException e) { - } - - service.getContext().detachAll(); - - try { - container.getPerson().getByKey(id, Employee.class).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void createWithNavigation() { - final String sampleName = "sample customer from proxy with navigation"; - final Integer id = 101; - - final Customer original = getSampleCustomerProfile(id, sampleName, container); - original.setInfo(container.getCustomerInfo().getByKey(16)); - container.flush(); - - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); - assertEquals(16, actual.getInfo().load().getCustomerInfoId(), 0); - - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); - - try { - container.getCustomer().getByKey(id).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void createWithBackNavigation() { - final String sampleName = "sample customer from proxy with back navigation"; - final Integer id = 102; - - Order order = container.newEntityInstance(Order.class); - order.setCustomerId(id); - order.setOrderId(id); // same id ... - - final Customer customer = getSampleCustomerProfile(id, sampleName, container); - - final OrderCollection orders = container.newEntityCollection(OrderCollection.class); - orders.add(order); - - customer.setOrders(orders); - order.setCustomer(customer); - container.flush(); - - assertEquals(id, order.getOrderId()); - assertEquals(id, order.getCustomerId()); - - Customer actual = readCustomer(container, id); - checkSampleCustomerProfile(actual, id, sampleName); - - assertEquals(1, actual.getOrders().execute().size()); - assertEquals(id, actual.getOrders().iterator().next().getOrderId()); - assertEquals(id, actual.getOrders().iterator().next().getCustomerId()); - - order = container.getOrder().getByKey(id); - assertEquals(id, order.getCustomer().load().getCustomerId()); - - container.getOrder().delete(actual.getOrders()); - container.flush(); - - try { - container.getOrder().getByKey(id).load(); - fail(); - } catch (IllegalArgumentException e) { - } - - actual = readCustomer(container, id); - assertTrue(actual.getOrders().isEmpty()); - - container.getCustomer().delete(actual.getCustomerId()); - container.flush(); - - try { - container.getCustomer().getByKey(id).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } - - @Test - public void multiKey() { - Message message = container.newEntityInstance(Message.class); - message.setMessageId(100); - message.setFromUsername("fromusername"); - message.setToUsername("myusername"); - message.setIsRead(false); - message.setSubject("test message"); - message.setBody("test"); - - container.getMessage().add(message); - container.flush(); - - MessageKey key = new MessageKey(); - key.setFromUsername("fromusername"); - key.setMessageId(100); - - message = container.getMessage().getByKey(key).load(); - assertNotNull(message); - assertEquals(Integer.valueOf(100), message.getMessageId()); - assertEquals("fromusername", message.getFromUsername()); - assertEquals("myusername", message.getToUsername()); - assertEquals("test message", message.getSubject()); - assertEquals("test", message.getBody()); - - container.getMessage().delete(key); - container.flush(); - - try { - container.getMessage().getByKey(key).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java deleted file mode 100644 index ecbfca0..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityRetrieveTestITCase.java +++ /dev/null @@ -1,226 +0,0 @@ -/* - * 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; - -//CHECKSTYLE:OFF (Maven checkstyle) -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.commons.api.edm.geo.Geospatial; -import org.apache.olingo.commons.api.edm.geo.Geospatial.Type; -import org.apache.olingo.commons.api.edm.geo.MultiLineString; -import org.apache.olingo.commons.api.edm.geo.Point; -import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.DefaultContainer; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.AllSpatialTypes; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ComputerDetail; -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.ContactDetails; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Contractor; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContractorCollection; -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.CustomerInfo; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection; -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.Person; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.PersonCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Phone; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Product; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployee; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.SpecialEmployeeCollection; -import org.junit.Test; - -import java.lang.reflect.Proxy; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.Collection; -import org.apache.olingo.ext.proxy.api.PrimitiveCollection; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -//CHECKSTYLE:ON (Maven checkstyle) - -/** - * This is the unit test class to check entity retrieve operations. - */ -public class EntityRetrieveTestITCase extends AbstractTestITCase { - - protected DefaultContainer getContainer() { - return container; - } - - @Test - public void exists() { - assertTrue(getContainer().getCar().exists(15)); - assertFalse(getContainer().getComputerDetail().exists(-11)); - } - - @Test - public void get() { - readCustomer(getContainer(), -10); - } - - @Test - public void getAll() { - final PersonCollection all = getContainer().getPerson().execute(); - assertNotNull(all); - assertFalse(all.isEmpty()); - for (Person person : all) { - assertNotNull(person); - } - - final EmployeeCollection employees = getContainer().getPerson().execute(EmployeeCollection.class); - assertNotNull(employees); - assertFalse(employees.isEmpty()); - for (Employee employee : employees) { - assertNotNull(employee); - } - - final SpecialEmployeeCollection specEmployees = getContainer().getPerson().execute(SpecialEmployeeCollection.class); - assertNotNull(specEmployees); - assertFalse(specEmployees.isEmpty()); - for (SpecialEmployee employee : specEmployees) { - assertNotNull(employee); - } - - final ContractorCollection contractors = getContainer().getPerson().execute(ContractorCollection.class); - assertNotNull(contractors); - assertFalse(contractors.isEmpty()); - for (Contractor contractor : contractors) { - assertNotNull(contractor); - } - - assertTrue(employees.size() > specEmployees.size()); - assertTrue(all.size() > employees.size() + contractors.size()); - } - - @Test - public void navigate() { - final Order order = getContainer().getOrder().getByKey(-9).load(); - assertEquals(-9, order.getOrderId(), 0); - - final ConcurrencyInfo concurrency = order.getConcurrency(); - assertNotNull(concurrency); - final Calendar actual = Calendar.getInstance(); - actual.clear(); - actual.set(2012, 1, 12, 11, 32, 50); - actual.set(Calendar.MILLISECOND, 507); - assertEquals(actual.getTimeInMillis(), concurrency.getQueriedDateTime().getTime()); - assertEquals(78, order.getCustomerId(), 0); - } - - @Test - public void withGeospatial() { - final AllSpatialTypes allSpatialTypes = getContainer().getAllGeoTypesSet().getByKey(-10).load(); - assertNotNull(allSpatialTypes); - assertEquals(-10, allSpatialTypes.getId(), 0); - - final MultiLineString geogMultiLine = allSpatialTypes.getGeogMultiLine(); - assertNotNull(geogMultiLine); - assertEquals(Type.MULTILINESTRING, geogMultiLine.getType()); - assertEquals(Geospatial.Dimension.GEOGRAPHY, geogMultiLine.getDimension()); - assertFalse(geogMultiLine.isEmpty()); - - final Point geogPoint = allSpatialTypes.getGeogPoint(); - assertNotNull(geogPoint); - assertEquals(Type.POINT, geogPoint.getType()); - assertEquals(Geospatial.Dimension.GEOGRAPHY, geogPoint.getDimension()); - assertEquals(52.8606, geogPoint.getX(), 0); - assertEquals(173.334, geogPoint.getY(), 0); - } - - @Test - public void withInlineEntry() { - final Customer customer = readCustomer(getContainer(), -10); - final CustomerInfo customerInfo = customer.getInfo().load(); - assertNotNull(customerInfo); - assertEquals(11, customerInfo.getCustomerInfoId(), 0); - } - - @Test - public void withInlineFeed() { - final Customer customer = readCustomer(getContainer(), -10); - final OrderCollection orders = customer.getOrders().execute(); - assertFalse(orders.isEmpty()); - } - - @Test - public void withActions() { - final ComputerDetail computerDetail = getContainer().getComputerDetail().getByKey(-10).load(); - assertEquals(-10, computerDetail.getComputerDetailId(), 0); - - try { - assertNotNull(computerDetail.operations().getClass().getMethod( - "resetComputerDetailsSpecifications", PrimitiveCollection.class, Timestamp.class)); - } catch (Exception e) { - fail(); - } - } - - @Test - public void multiKey() { - final MessageKey messageKey = new MessageKey(); - messageKey.setFromUsername("1"); - messageKey.setMessageId(-10); - - final Message message = getContainer().getMessage().getByKey(messageKey).load(); - assertEquals("1", message.getFromUsername()); - } - - @Test - public void checkForETag() { - Product product = getContainer().getProduct().getByKey(-10).load(); - assertTrue(StringUtils.isNotBlank( - ((EntityInvocationHandler) Proxy.getInvocationHandler(product)).getETag())); - } - - @Test - public void collectionsAndComplexes() { - final Customer customer = readCustomer(getContainer(), -10); - boolean found = false; - - assertTrue(customer.getPrimaryContactInfo().getEmailBag().contains("psgdkmxamznjulzbsohqjytbxhnojbufe")); - - final Collection<ContactDetails> backupContactInfo = customer.getBackupContactInfo(); - assertEquals(9, backupContactInfo.size()); - - for (ContactDetails contact : backupContactInfo) { - if (contact.getContactAlias() != null && contact.getContactAlias().getAlternativeNames() != null && contact. - getContactAlias().getAlternativeNames().contains("vxiefursgkqzptijhincpdm")) { - found = true; - } - } - assertTrue(found); - found = false; - - for (ContactDetails contact : backupContactInfo) { - for (Phone phone : contact.getMobilePhoneBag()) { - if ("gqvuusqrrriljkospoxbdod".equals(phone.getExtension())) { - found = true; - } - } - } - assertTrue(found); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java deleted file mode 100644 index aa3a66c..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntitySetTestITCase.java +++ /dev/null @@ -1,99 +0,0 @@ -/* - * 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 org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Car; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Computer; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Customer; -import org.junit.Test; - -import java.io.IOException; -import java.util.Iterator; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -/** - * This is the unit test class to check basic feed operations. - */ -public class EntitySetTestITCase extends AbstractTestITCase { - - @Test - public void count() { - assertNotNull(container.getMessage()); - assertTrue(10 <= container.getMessage().count()); - - assertTrue(container.getCustomer().count() > 0); - } - - @Test - public void execute() { - int count = 0; - for (Customer customer : container.getCustomer().execute()) { - assertNotNull(customer); - count++; - } - assertTrue(count < 10); - } - - @Test - public void readEntitySetWithNextLink() { - int count = 0; - for (Customer customer : container.getCustomer().execute()) { - assertNotNull(customer); - count++; - } - assertEquals(2, count); - - int iterating = 0; - for (Customer customer : container.getCustomer()) { - assertNotNull(customer); - iterating++; - } - assertTrue(count < iterating); - } - - @Test - public void readODataEntitySet() throws IOException { - assertTrue(container.getCar().count() >= 10); - - final Iterable<Car> car = container.getCar().execute(); - assertNotNull(car); - - final Iterator<Car> itor = car.iterator(); - - int count = 0; - while (itor.hasNext()) { - assertNotNull(itor.next()); - count++; - } - assertTrue(count >= 10); - } - - @Test - public void readEntitySetIterator() { - int count = 0; - for (Computer computer : container.getComputer()) { - assertNotNull(computer); - count++; - } - assertTrue(count >= 10); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/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 deleted file mode 100644 index fd2be17..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/EntityUpdateTestITCase.java +++ /dev/null @@ -1,120 +0,0 @@ -/* - * 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; - -//CHECKSTYLE:OFF (Maven checkstyle) -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import org.apache.commons.lang3.StringUtils; -import org.apache.olingo.ext.proxy.commons.EntityInvocationHandler; -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; - -import java.lang.reflect.Proxy; -//CHECKSTYLE:ON (Maven checkstyle) - -/** - * This is the unit test class to check entity update operations. - */ -public class EntityUpdateTestITCase extends AbstractTestITCase { - - @Test - public void update() { - Order order = container.getOrder().getByKey(-9).load(); - - final ConcurrencyInfo ci = order.getConcurrency(); - ci.setToken("XXX"); - - container.flush(); - - order = container.getOrder().getByKey(-9).load(); - assertEquals("XXX", order.getConcurrency().getToken()); - } - - @Test - public void multiKey() { - final MessageKey key = new MessageKey(); - key.setFromUsername("1"); - key.setMessageId(-10); - - Message message = container.getMessage().getByKey(key); - - message.setBody("XXX"); - - container.flush(); - - message = container.getMessage().getByKey(key).load(); - assertEquals("XXX", message.getBody()); - } - - @Test - public void patchLink() { - Order order = container.newEntityInstance(Order.class); - order.setOrderId(400); - order.setCustomerId(-9); - - OrderCollection orders = container.newEntityCollection(OrderCollection.class); - orders.add(order); - - Customer customer = container.getCustomer().getByKey(-9); - customer.setOrders(orders); - order.setCustomer(customer); - - container.flush(); - - order = container.getOrder().getByKey(400).load(); - assertEquals(400, order.getOrderId().intValue()); - assertEquals(-9, order.getCustomerId().intValue()); - - customer = container.getCustomer().getByKey(-9); - - assertEquals(2, customer.getOrders().execute().size()); - - int count = 0; - for (Order inside : customer.getOrders()) { - if (inside.getOrderId() == 400) { - count++; - } - } - assertEquals(1, count); - assertEquals(-9, order.getCustomer().load().getCustomerId(), 0); - } - - @Test - public void concurrentModification() { - Product product = container.getProduct().getByKey(-10).load(); - final String etag = ((EntityInvocationHandler) Proxy.getInvocationHandler(product)).getETag(); - assertTrue(StringUtils.isNotBlank(etag)); - - final String baseConcurrency = String.valueOf(System.currentTimeMillis()); - product.setBaseConcurrency(baseConcurrency); - - container.flush(); - - product = container.getProduct().getByKey(-10).load(); - assertEquals(baseConcurrency, product.getBaseConcurrency()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java deleted file mode 100644 index aea7c0d..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/FilterTestITCase.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * 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 org.apache.olingo.ext.proxy.api.Sort; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Person; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Car; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types - .CarCollection; -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 - .EmployeeCollection; -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 - .SpecialEmployeeCollection; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - -//CHECKSTYLE:OFF (Maven checkstyle) -//CHECKSTYLE:ON (Maven checkstyle) - -public class FilterTestITCase extends AbstractTestITCase { - - @Test - public void filterOrderby() { - org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Car cars = - container.getCar(); - - CarCollection result = cars.filter(service.getClient().getFilterFactory().lt("VIN", 16)).execute(); - - // 1. check that filtered entity set looks as expected - assertEquals(5, result.size()); - - // 2. extract VIN values - sorted ASC by default - final List<Integer> vinsASC = new ArrayList<Integer>(5); - for (Car car : result) { - assertTrue(car.getVIN() < 16); - vinsASC.add(car.getVIN()); - } - - // 3. add orderby clause to filter above - result = cars.orderBy(new Sort("VIN", Sort.Direction.DESC)).execute(); - assertNotNull(result); - assertEquals(5, result.size()); - - // 4. extract again VIN value - now they were required to be sorted DESC - final List<Integer> vinsDESC = new ArrayList<Integer>(5); - for (Car car : result) { - assertTrue(car.getVIN() < 16); - vinsDESC.add(car.getVIN()); - } - - // 5. reverse vinsASC and expect to be equal to vinsDESC - Collections.reverse(vinsASC); - assertEquals(vinsASC, vinsDESC); - } - - @Test - public void single() { - org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.Car cars = - container.getCar(); - - assertEquals(1, cars.filter(service.getClient().getFilterFactory().eq("VIN", 16)).execute().size()); - } - - @Test - public void derived() { - final Person person = container.getPerson(); - final EmployeeCollection employee = person.execute(EmployeeCollection.class); - final SpecialEmployeeCollection specialEmployee = person.execute(SpecialEmployeeCollection.class); - - assertFalse(employee.isEmpty()); - assertFalse(specialEmployee.isEmpty()); - - assertTrue(person.execute().size() > employee.size() + specialEmployee.size()); - } - - @Test - public void loadWithSelect() { - final Order order = container.getOrder().getByKey(-9); - assertNull(order.getCustomerId()); - assertNull(order.getOrderId()); - - order.select("OrderId"); - order.load(); - - assertNull(order.getCustomerId()); - assertNotNull(order.getOrderId()); - - order.clearQueryOptions(); - order.load(); - assertNotNull(order.getCustomerId()); - assertNotNull(order.getOrderId()); - } - - @Test - public void loadWithSelectAndExpand() { - final Customer customer = container.getCustomer().getByKey(-10); - customer.expand("Info"); - customer.select("Info", "CustomerId"); - - customer.load(); - assertEquals(11, customer.getInfo().getCustomerInfoId(), 0); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java deleted file mode 100644 index f1eb965..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/InvokeTestITCase.java +++ /dev/null @@ -1,244 +0,0 @@ -/* - * 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; - -//CHECKSTYLE:OFF (Maven checkstyle) -import org.apache.olingo.ext.proxy.api.PrimitiveCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ComputerDetail; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetails; -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.CustomerCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Dimensions; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Employee; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.EmployeeCollection; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Product; - -import org.apache.commons.lang3.StringUtils; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.util.Calendar; -import java.util.HashMap; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.ContactDetailsCollection; - -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -//CHECKSTYLE:ON (Maven checkstyle) - -public class InvokeTestITCase extends AbstractTestITCase { - - @Test - public void getWithNoParams() { - // 1. primitive result - final String string = container.operations().getPrimitiveString().execute(); - assertEquals("Foo", string); - - // 2. complex collection result - final ContactDetailsCollection details = - container.operations().entityProjectionReturnsCollectionOfComplexTypes().execute(); - assertFalse(details.isEmpty()); - for (ContactDetails detail : details) { - assertNotNull(detail); - } - assertNotNull(details.iterator().next()); - } - - @Test - public void getWithParam() { - // 1. primitive result - assertEquals(155, container.operations().getArgumentPlusOne(154).execute(), 0); - - // 2. entity collection result - final CustomerCollection customers = container.operations().getSpecificCustomer(StringUtils.EMPTY).execute(); - assertNotNull(customers); - assertFalse(customers.isEmpty()); - final Set<Integer> customerIds = new HashSet<Integer>(customers.size()); - for (Customer customer : customers) { - assertNotNull(customer); - customerIds.add(customer.getCustomerId()); - } - assertTrue(customerIds.contains(-8)); - } - - @Test - public void entityBoundPost() { - // 0. create an employee - final Integer id = 101; - - Employee employee = container.newEntityInstance(Employee.class); - employee.setPersonId(id); - employee.setName("sample employee from proxy"); - employee.setManagersPersonId(-9918); - employee.setSalary(2147483647); - employee.setTitle("CEO"); - - container.getPerson().add(employee); - container.flush(); - - employee = container.getPerson().getByKey(id, Employee.class).load(); - assertNotNull(employee); - assertEquals(id, employee.getPersonId()); - - try { - // 1. invoke action bound to the employee just created - employee.operations().sack().execute(); - - // 2. check that invoked action has effectively run - employee = container.getPerson().getByKey(id, Employee.class).load(); - assertEquals(0, employee.getSalary(), 0); - assertTrue(employee.getTitle().endsWith("[Sacked]")); - } catch (Exception e) { - fail("Should never get here"); - } finally { - // 3. remove the test employee - container.getPerson().delete(employee.getPersonId()); - container.flush(); - } - } - - @Test - public void entityCollectionBoundPostWithParam() { - EmployeeCollection employees = container.getPerson().execute(EmployeeCollection.class); - assertFalse(employees.isEmpty()); - final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.size()); - for (Employee employee : employees) { - preSalaries.put(employee.getPersonId(), employee.getSalary()); - } - assertFalse(preSalaries.isEmpty()); - - employees.operations().increaseSalaries(1).execute(); - - employees = container.getPerson().execute(EmployeeCollection.class); - assertFalse(employees.isEmpty()); - for (Employee employee : employees) { - assertTrue(preSalaries.get(employee.getPersonId()) < employee.getSalary()); - } - } - - @Test - public void changeProductDimensions() { - // 0. create a product - final Integer id = 101; - - Product product = container.newEntityInstance(Product.class); - product.setProductId(id); - product.setDescription("New product"); - - final Dimensions origDimensions = container.newComplexInstance(Dimensions.class); - origDimensions.setDepth(BigDecimal.ZERO); - origDimensions.setHeight(BigDecimal.ZERO); - origDimensions.setWidth(BigDecimal.ZERO); - product.setDimensions(origDimensions); - - container.getProduct().add(product); - container.flush(); - - product = container.getProduct().getByKey(id).load(); - assertNotNull(product); - assertEquals(id, product.getProductId()); - assertEquals(BigDecimal.ZERO, product.getDimensions().getDepth()); - assertEquals(BigDecimal.ZERO, product.getDimensions().getHeight()); - assertEquals(BigDecimal.ZERO, product.getDimensions().getWidth()); - - try { - // 1. invoke action bound to the product just created - final Dimensions newDimensions = container.newComplexInstance(Dimensions.class); - newDimensions.setDepth(BigDecimal.ONE); - newDimensions.setHeight(BigDecimal.ONE); - newDimensions.setWidth(BigDecimal.ONE); - - product.operations().changeProductDimensions(newDimensions).execute(); - - // 2. check that invoked action has effectively run - product = container.getProduct().getByKey(id).load(); - assertEquals(BigDecimal.ONE, product.getDimensions().getDepth()); - assertEquals(BigDecimal.ONE, product.getDimensions().getHeight()); - assertEquals(BigDecimal.ONE, product.getDimensions().getWidth()); - } catch (Exception e) { - fail("Should never get here"); - } finally { - // 3. remove the test product - container.getProduct().delete(product.getProductId()); - container.flush(); - } - } - - @Test - public void resetComputerDetailsSpecifications() { - // 0. create a computer detail - final Integer id = 101; - - final Calendar purchaseDate = Calendar.getInstance(); - purchaseDate.clear(); - purchaseDate.set(Calendar.YEAR, 1); - purchaseDate.set(Calendar.MONTH, 0); - purchaseDate.set(Calendar.DAY_OF_MONTH, 1); - - ComputerDetail computerDetail = container.newEntityInstance(ComputerDetail.class); - computerDetail.setComputerDetailId(id); - - final PrimitiveCollection<String> sb = container.newPrimitiveCollection(String.class); - sb.add("First spec"); - computerDetail.setSpecificationsBag(sb); - - computerDetail.setPurchaseDate(new Timestamp(purchaseDate.getTimeInMillis())); - - container.getComputerDetail().add(computerDetail); - container.flush(); - - computerDetail = container.getComputerDetail().getByKey(id).load(); - assertNotNull(computerDetail); - assertEquals(id, computerDetail.getComputerDetailId()); - assertEquals(1, computerDetail.getSpecificationsBag().size()); - assertTrue(computerDetail.getSpecificationsBag().contains("First spec")); - assertEquals(purchaseDate.getTimeInMillis(), computerDetail.getPurchaseDate().getTime()); - - try { - final PrimitiveCollection<String> cds = container.newPrimitiveCollection(String.class); - cds.add("Second spec"); - - // 1. invoke action bound to the computer detail just created - computerDetail.operations().resetComputerDetailsSpecifications( - cds, new Timestamp(Calendar.getInstance().getTimeInMillis())).execute(); - - // 2. check that invoked action has effectively run - computerDetail = container.getComputerDetail().getByKey(id).load(); - assertNotNull(computerDetail); - assertEquals(id, computerDetail.getComputerDetailId()); - assertEquals(1, computerDetail.getSpecificationsBag().size()); - assertTrue(computerDetail.getSpecificationsBag().contains("Second spec")); - assertNotEquals(purchaseDate.getTimeInMillis(), computerDetail.getPurchaseDate()); - } catch (Exception e) { - fail("Should never get here"); - } finally { - // 3. remove the test product - container.getComputerDetail().delete(computerDetail.getComputerDetailId()); - container.flush(); - } - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java deleted file mode 100644 index d4ded24..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/MediaEntityTestITCase.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * 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.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.fit.proxy.v3.staticservice.microsoft.test.odata.services.astoriadefaultservice.types.Car; -import org.junit.Test; -import java.io.ByteArrayInputStream; -import java.io.IOException; -import java.io.InputStream; -import org.apache.olingo.ext.proxy.api.EdmStreamValue; - -/** - * This is the unit test class to check media entity retrieve operations. - */ -public class MediaEntityTestITCase extends AbstractTestITCase { - - @Test - public void read() throws IOException { - final InputStream is = container.getCar().getByKey(12).load().loadStream().getStream(); - assertNotNull(is); - IOUtils.closeQuietly(is); - } - - @Test - public void updateReadStreamedProperty() throws IOException { - final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")"; - final InputStream input = new ByteArrayInputStream(TO_BE_UPDATED.getBytes()); - - Car car = container.getCar().getByKey(12); - car.setPhoto(container.newEdmStreamValue("application/octet-stream", input)); - - container.flush(); - - car = container.getCar().getByKey(12); - final EdmStreamValue value = car.getPhoto().load(); - assertEquals(TO_BE_UPDATED, IOUtils.toString(value.getStream())); - IOUtils.closeQuietly(value.getStream()); - } - - @Test - public void update() throws IOException { - final Car car = container.getCar().getByKey(14); - assertNotNull(car); - - final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")"; - InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); - - car.uploadStream(container.newEdmStreamValue("*/*", input)); - - container.flush(); - - input = container.getCar().getByKey(14).loadStream().getStream(); - assertEquals(TO_BE_UPDATED, IOUtils.toString(input)); - IOUtils.closeQuietly(input); - - service.getContext().detachAll(); - } - - @Test - public void create() throws IOException { - Car car = container.newEntityInstance(Car.class); - - final String TO_BE_UPDATED = "buffered stream sample (" + System.currentTimeMillis() + ")"; - InputStream input = IOUtils.toInputStream(TO_BE_UPDATED); - - final String DESC = "DESC - " + System.currentTimeMillis(); - car.uploadStream(container.newEdmStreamValue("*/*", input)); - car.setDescription(DESC); - - container.getCar().add(car); - container.flush(); - - int key = car.getVIN(); - assertTrue(key > 0); - - service.getContext().detachAll(); - - car = container.getCar().getByKey(key).load(); - assertEquals(DESC, car.getDescription()); - input = car.loadStream().getStream(); - assertEquals(TO_BE_UPDATED, IOUtils.toString(input)); - IOUtils.closeQuietly(input); - - container.getCar().delete(key); - container.flush(); - - try { - container.getCar().getByKey(key).load(); - fail(); - } catch (IllegalArgumentException e) { - } - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c8865db8/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java deleted file mode 100644 index 5e51ad6..0000000 --- a/fit/src/test/java/org/apache/olingo/fit/proxy/v3/OpenTypeTestITCase.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * 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.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.math.BigDecimal; -import java.sql.Timestamp; -import java.text.ParseException; -import java.text.SimpleDateFormat; -import java.util.Calendar; -import java.util.UUID; -import org.apache.olingo.client.api.v3.EdmEnabledODataClient; -import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.ext.proxy.api.annotations.EntityType; -import org.apache.olingo.fit.proxy.v3.opentype.Service; -import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.DefaultContainer; -import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.ContactDetails; -import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.IndexedRow; -import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.Row; -import org.apache.olingo.fit.proxy.v3.opentype.microsoft.test.odata.services.opentypesservicev3.types.RowIndex; -import org.junit.BeforeClass; -import org.junit.Test; - -/** - * This is the unit test class to check actions overloading. - */ -public class OpenTypeTestITCase extends AbstractTestITCase { - - private static Service<EdmEnabledODataClient> otservice; - - private static DefaultContainer otcontainer; - - @BeforeClass - public static void initContainer() { - otservice = Service.getV3(testOpenTypeServiceRootURL); - otservice.getClient().getConfiguration(). - setDefaultBatchAcceptFormat(ContentType.APPLICATION_OCTET_STREAM); - otcontainer = otservice.getEntityContainer(DefaultContainer.class); - assertNotNull(otcontainer); - } - - @Test - public void checkOpenTypeEntityTypesExist() { - assertTrue(otcontainer.newEntityInstance(Row.class).getClass().getInterfaces()[0]. - getAnnotation(EntityType.class).openType()); - assertTrue(otcontainer.newEntityInstance(RowIndex.class).getClass().getInterfaces()[0]. - getAnnotation(EntityType.class).openType()); - assertTrue(otcontainer.newEntityInstance(IndexedRow.class).getClass().getInterfaces()[0]. - getAnnotation(EntityType.class).openType()); - otservice.getContext().detachAll(); - } - - @Test - public void read() { - Row row = otcontainer.getRow().getByKey(UUID.fromString("71f7d0dc-ede4-45eb-b421-555a2aa1e58f")).load(); - assertEquals(Double.class, row.readAdditionalProperty("Double").getClass()); - assertEquals("71f7d0dc-ede4-45eb-b421-555a2aa1e58f", row.getId().toString()); - - row = otcontainer.getRow().getByKey(UUID.fromString("672b8250-1e6e-4785-80cf-b94b572e42b3")).load(); - assertEquals(BigDecimal.class, row.readAdditionalProperty("Decimal").getClass()); - } - - @Test - public void cud() throws ParseException { - final Integer id = 1426; - - RowIndex rowIndex = otcontainer.newEntityInstance(RowIndex.class); - rowIndex.setId(id); - rowIndex.addAdditionalProperty("aString", "string"); - rowIndex.addAdditionalProperty("aBoolean", true); - rowIndex.addAdditionalProperty("aDouble", 1.5D); - rowIndex.addAdditionalProperty("aByte", Byte.MAX_VALUE); - rowIndex.addAdditionalProperty("aDate", Calendar.getInstance()); - - final ContactDetails contact = otcontainer.newComplexInstance(ContactDetails.class); - contact.setFirstContacted("text".getBytes()); - - Calendar cal = Calendar.getInstance(); - cal.clear(); - cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2001-04-05T05:05:05.001")); - - contact.setLastContacted(new Timestamp(cal.getTimeInMillis())); - - cal = Calendar.getInstance(); - cal.clear(); - cal.setTime(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss.SSS").parse("2001-04-05T05:05:04.001")); - contact.setContacted(new Timestamp(cal.getTimeInMillis())); - - contact.setGUID(UUID.randomUUID()); - contact.setPreferedContactTime(BigDecimal.ONE); - contact.setByte(Short.valueOf("24")); - contact.setSignedByte(Byte.MAX_VALUE); - contact.setDouble(Double.valueOf(Double.MAX_VALUE)); - contact.setSingle(Float.MAX_VALUE); - contact.setShort(Short.MAX_VALUE); - contact.setInt(Integer.MAX_VALUE); - rowIndex.addAdditionalProperty("aContact", contact); - - otcontainer.getRowIndex().add(rowIndex); - otcontainer.flush(); - - rowIndex = otcontainer.getRowIndex().getByKey(id).load(); - assertEquals(String.class, rowIndex.readAdditionalProperty("aString").getClass()); - assertEquals(Boolean.class, rowIndex.readAdditionalProperty("aBoolean").getClass()); - assertEquals(Double.class, rowIndex.readAdditionalProperty("aDouble").getClass()); - assertEquals(Byte.class, rowIndex.readAdditionalProperty("aByte").getClass()); - assertEquals(Byte.MAX_VALUE, rowIndex.readAdditionalProperty("aByte")); - assertTrue(Timestamp.class.isAssignableFrom(rowIndex.readAdditionalProperty("aDate").getClass())); - assertEquals(ContactDetails.class, rowIndex.readAdditionalProperty("aContact").getClass().getInterfaces()[0]); - - otservice.getContext().detachAll(); - - otcontainer.getRowIndex().delete(id); - otcontainer.flush(); - - try { - otcontainer.getRowIndex().getByKey(id).load(); - } catch (IllegalArgumentException e) { - } - } -}
