You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by il...@apache.org on 2014/04/29 11:51:45 UTC
[01/11] [OLINGO-236] Refactor complete
Repository: olingo-odata4
Updated Branches:
refs/heads/master 6c7aef90e -> 8042913be
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/QueryOptionsTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/QueryOptionsTestITCase.java
deleted file mode 100644
index 51580f8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/QueryOptionsTestITCase.java
+++ /dev/null
@@ -1,215 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check for query options.
- */
-public class QueryOptionsTestITCase extends AbstractTestITCase {
-
- /**
- * Test <tt>$expand</tt>.
- */
- public void expand() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
-
- final ODataEntity customer = req.execute().getBody();
- assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
- }
-
- /**
- * Test <tt>$filter</tt> and <tt>$orderby</tt>.
- *
- * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
- */
- @Test
- public void filterOrderby() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").filter("(PersonID lt 3)");
-
- // 1. check that filtered entity set looks as expected
- ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON);
-
- ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(2, feed.getEntities().size());
-
- // 2. extract PersonID values - sorted ASC by default
- final List<Integer> former = new ArrayList<Integer>(2);
- for (ODataEntity entity : feed.getEntities()) {
- final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
- assertTrue(personID < 3);
- former.add(personID);
- }
-
- // 3. add orderby clause to filter above
- req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
- req.setFormat(ODataPubFormat.JSON);
- feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(2, feed.getEntities().size());
-
- // 4. extract again VIN value - now they were required to be sorted DESC
- final List<Integer> latter = new ArrayList<Integer>(2);
- for (ODataEntity entity : feed.getEntities()) {
- final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
- assertTrue(personID < 3);
- latter.add(personID);
- }
-
- // 5. reverse latter and expect to be equal to former
- Collections.reverse(latter);
- assertEquals(former, latter);
- }
-
- /**
- * Test <tt>$format</tt>.
- */
- @Test
- public void format() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).format("json");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.ATOM);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertNotNull(res);
- assertTrue(res.getContentType().replaceAll(" ", "").
- startsWith(ODataPubFormat.JSON.toString(client.getServiceVersion())));
- }
-
- /**
- * Test <tt>$skip</tt>.
- */
- public void skip() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
-
- // 1. check that filtered entity set looks as expected
- ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
- ODataEntitySet feed = req.execute().getBody();
- assertEquals(3, feed.getEntities().size());
- }
-
- /**
- * Test <tt>$top</tt>.
- */
- public void top() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
-
- // 1. check that filtered entity set looks as expected
- ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.top(2).build());
- ODataEntitySet feed = req.execute().getBody();
- assertEquals(2, feed.getEntities().size());
- }
-
- /**
- * Test <tt>$skiptoken</tt>.
- */
- @Test
- public void skiptoken() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("People").skipToken("5");
-
- final ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON);
-
- final ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(1, feed.getEntities().size());
-
- for (ODataEntity entity : feed.getEntities()) {
- assertTrue(entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class) > 5);
- }
- }
-
- /**
- * Test <tt>$inlinecount</tt>.
- */
- @Test
- public void inlinecount() {
- final URIBuilder uriBuilder =
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").count(true);
-
- final ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON);
- final ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(feed.getEntities().size(), feed.getCount());
- }
-
- /**
- * Test <tt>$select</tt>.
- */
- @Test
- public void select() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
-
- final ODataEntity customer = req.execute().getBody();
- assertEquals(1, customer.getProperties().size());
- assertEquals(1, customer.getNavigationLinks().size());
- assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
- }
-
- @Test
- public void issue253() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("relatedEntitySelect").appendEntitySetSegment("Customers").appendKeySegment(1).
- expandWithSelect("Orders", "OrderID", "OrderDetails");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
deleted file mode 100644
index 3e7653d..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/ServiceDocumentTestITCase.java
+++ /dev/null
@@ -1,62 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.junit.Test;
-
-public class ServiceDocumentTestITCase extends AbstractTestITCase {
-
- private void retrieveServiceDocument(final ODataFormat format) {
- final ODataServiceDocumentRequest req =
- client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataServiceDocument serviceDocument = res.getBody();
- assertEquals(12, serviceDocument.getEntitySets().size());
- assertEquals(6, serviceDocument.getSingletons().size());
- assertEquals(6, serviceDocument.getFunctionImports().size());
-
- assertEquals(URI.create(testStaticServiceRootURL + "/ProductDetails"),
- serviceDocument.getEntitySetURI("ProductDetails"));
- assertEquals(URI.create(testStaticServiceRootURL + "/Boss"),
- serviceDocument.getSingletonURI("Boss"));
- assertEquals(URI.create(testStaticServiceRootURL + "/GetPerson"),
- serviceDocument.getFunctionImportURI("GetPerson"));
- }
-
- @Test
- public void retrieveServiceDocumentAsXML() {
- retrieveServiceDocument(ODataFormat.XML);
- }
-
- @Test
- public void retrieveServiceDocumentAsJSON() {
- retrieveServiceDocument(ODataFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/resources/sample.png
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/resources/sample.png b/lib/client-core/src/test/resources/sample.png
deleted file mode 100644
index 399ee46..0000000
Binary files a/lib/client-core/src/test/resources/sample.png and /dev/null differ
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/pom.xml
----------------------------------------------------------------------
diff --git a/pom.xml b/pom.xml
index a2fb869..f10e77d 100644
--- a/pom.xml
+++ b/pom.xml
@@ -265,46 +265,6 @@
<log>${cargo.log}</log>
<output>${cargo.output}</output>
</container>
-
- <configuration>
- <type>standalone</type>
- <properties>
- <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>
- <cargo.tomcat.ajp.port>${cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port>
- <cargo.rmi.port>${cargo.rmi.port}</cargo.rmi.port>
-
- <!--<cargo.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n</cargo.jvmargs> -->
- <cargo.jvmargs>-noverify -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m</cargo.jvmargs>
- </properties>
- <files>
- <file>
- <file>${project.build.directory}/test-classes/esigate.properties</file>
- <todir>lib</todir>
- </file>
- </files>
- <configfiles>
- <configfile>
- <file>${project.build.directory}/test-classes/context.xml</file>
- <todir>conf/</todir>
- <tofile>context.xml</tofile>
- </configfile>
- <configfile>
- <file>${project.build.directory}/test-classes/tomcat-users.xml</file>
- <todir>conf/</todir>
- <tofile>tomcat-users.xml</tofile>
- </configfile>
- </configfiles>
- </configuration>
- <deployables>
- <deployable>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-fit</artifactId>
- <type>war</type>
- <properties>
- <context>/</context>
- </properties>
- </deployable>
- </deployables>
</configuration>
</plugin>
[05/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
deleted file mode 100644
index f57b443..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityCreateTestITCase.java
+++ /dev/null
@@ -1,484 +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.client.core.it.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 java.net.URI;
-import java.util.Collections;
-import java.util.HashSet;
-import java.util.LinkedHashMap;
-import java.util.Set;
-import org.apache.http.entity.ContentType;
-import org.apache.olingo.client.api.communication.header.HeaderName;
-import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.http.NoContentException;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-
-import org.junit.Test;
-
-/**
- * This is the unit test class to check create entity operations.
- */
-public class EntityCreateTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- @Test
- public void createAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final int id = 1;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
-
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final int id = 2;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
-
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createWithInlineAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final int id = 3;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual =
- compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
-
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void createWithInlineAsJSON() {
- // this needs to be full, otherwise there is no mean to recognize links
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final int id = 4;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual =
- compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
-
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void createInlineWithoutLinkAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final int id = 5;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- original.addLink(client.getObjectFactory().newDeepInsertEntity(
- "Info", getSampleCustomerInfo(id, "Sample Customer_Info")));
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual =
- compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
-
- boolean found = false;
-
- for (ODataLink link : actual.getNavigationLinks()) {
- assertNotNull(link.getLink());
- if (link.getLink().toASCIIString().endsWith("Customer(" + id + ")/Info")) {
- found = true;
- }
- }
-
- assertTrue(found);
-
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void createInlineWithoutLinkAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final int id = 6;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- original.addLink(client.getObjectFactory().newDeepInsertEntity(
- "Info", getSampleCustomerInfo(id, "Sample Customer_Info")));
-
- createEntity(getServiceRoot(), format, original, "Customer");
- final ODataEntity actual =
- compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
-
- boolean found = false;
-
- for (ODataLink link : actual.getNavigationLinks()) {
- assertNotNull(link.getLink());
- if (link.getLink().toASCIIString().endsWith("Customer(" + id + ")/Info")) {
- found = true;
- }
- }
-
- assertTrue(found);
-
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void createWithNavigationAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final ODataEntity actual = createWithNavigationLink(format, 5);
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createWithNavigationAsJSON() {
- // this needs to be full, otherwise there is no mean to recognize links
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final ODataEntity actual = createWithNavigationLink(format, 6);
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createWithFeedNavigationAsAtom() throws EdmPrimitiveTypeException {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final ODataEntity actual = createWithFeedNavigationLink(format, 7);
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createWithFeedNavigationAsJSON() throws EdmPrimitiveTypeException {
- // this needs to be full, otherwise there is no mean to recognize links
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final ODataEntity actual = createWithFeedNavigationLink(format, 8);
- cleanAfterCreate(format, actual, false, getServiceRoot());
- }
-
- @Test
- public void createWithBackNavigationAsAtom() throws EdmPrimitiveTypeException {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final ODataEntity actual = createWithBackNavigationLink(format, 9);
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void createWithBackNavigationAsJSON() throws EdmPrimitiveTypeException {
- // this needs to be full, otherwise there is no mean to recognize links
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final ODataEntity actual = createWithBackNavigationLink(format, 10);
- cleanAfterCreate(format, actual, true, getServiceRoot());
- }
-
- @Test
- public void multiKeyAsAtom() {
- multiKey(ODataPubFormat.ATOM);
- }
-
- @Test
- public void multiKeyAsJSON() {
- multiKey(ODataPubFormat.JSON);
- }
-
- @Test
- public void createReturnNoContent() {
- final int id = 1;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").build(), original);
- createReq.setPrefer(client.newPreferences().returnNoContent());
-
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(204, createRes.getStatusCode());
- assertEquals(client.newPreferences().returnNoContent(),
- createRes.getHeader(HeaderName.preferenceApplied).iterator().next());
-
- try {
- createRes.getBody();
- fail();
- } catch (NoContentException e) {
- assertNotNull(e);
- }
-
- final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").appendKeySegment(id).build()).
- execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-
- @Test
- public void issue135() {
- final int id = 2;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer");
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
- createReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
- createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
- createReq.setPrefer(client.newPreferences().returnContent());
-
- try {
- final ODataEntityCreateResponse createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
- } catch (Exception e) {
- fail(e.getMessage());
- } finally {
- final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").appendKeySegment(id).
- build()).
- execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
- }
-
- private ODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id)
- throws EdmPrimitiveTypeException {
-
- final String sampleName = "Sample customer";
- final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
-
- final Set<Integer> keys = new HashSet<Integer>();
- keys.add(-100);
- keys.add(-101);
-
- for (Integer key : keys) {
- final ODataEntity order = client.getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Order"));
-
- order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId",
- client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(key)));
- order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
- client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
-
- final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Order").build(), order);
- createReq.setFormat(format);
-
- original.addLink(client.getObjectFactory().newEntitySetNavigationLink(
- "Orders",
- createReq.execute().getBody().getEditLink()));
- }
-
- final ODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
- // now, compare the created one with the actual one and go deeply into the associated customer info.....
- final ODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Orders");
-
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataEntitySet entitySet = res.getBody();
- assertNotNull(entitySet);
- assertEquals(2, entitySet.getCount());
-
- for (ODataEntity entity : entitySet.getEntities()) {
- final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
- final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
- assertTrue(keys.contains(key));
- assertEquals(Integer.valueOf(id), customerId);
- keys.remove(key);
-
- final ODataDeleteRequest deleteReq = client.getCUDRequestFactory().getDeleteRequest(
- URIUtils.getURI(getServiceRoot(), entity.getEditLink().toASCIIString()));
-
- deleteReq.setFormat(format);
- assertEquals(204, deleteReq.execute().getStatusCode());
- }
-
- return actual;
- }
-
- private ODataEntity createWithNavigationLink(final ODataPubFormat format, final int id) {
- final String sampleName = "Sample customer";
-
- final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
- original.addLink(client.getObjectFactory().newEntityNavigationLink(
- "Info", URI.create(getServiceRoot() + "/CustomerInfo(12)")));
-
- final ODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
- // now, compare the created one with the actual one and go deeply into the associated customer info.....
- final ODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Info");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataEntity info = res.getBody();
- assertNotNull(info);
-
- boolean found = false;
-
- for (ODataProperty prop : info.getProperties()) {
- if ("CustomerInfoId".equals(prop.getName())) {
- assertEquals("12", prop.getValue().toString());
- found = true;
- }
- }
-
- assertTrue(found);
-
- return actual;
- }
-
- private ODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id)
- throws EdmPrimitiveTypeException {
-
- final String sampleName = "Sample customer";
-
- ODataEntity customer = getSampleCustomerProfile(id, sampleName, false);
- customer = createEntity(getServiceRoot(), format, customer, "Customer");
-
- ODataEntity order = client.getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Order"));
- getClient().getBinder().add(order,
- client.getObjectFactory().newPrimitiveProperty("CustomerId",
- client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
- getClient().getBinder().add(order,
- client.getObjectFactory().newPrimitiveProperty("OrderId",
- client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
-
- order.addLink(client.getObjectFactory().newEntityNavigationLink(
- "Customer", URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString())));
-
- order = createEntity(getServiceRoot(), format, order, "Order");
-
- final ODataEntity changes = client.getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
- changes.setEditLink(customer.getEditLink());
- changes.addLink(client.getObjectFactory().newEntitySetNavigationLink(
- "Orders", URIUtils.getURI(getServiceRoot(), order.getEditLink().toASCIIString())));
- update(UpdateType.PATCH, changes, format, null);
-
- final ODataEntityRequest<ODataEntity> customerreq = client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(getServiceRoot(), order.getEditLink().toASCIIString() + "/Customer"));
- customerreq.setFormat(format);
-
- customer = customerreq.execute().getBody();
-
- assertEquals(Integer.valueOf(id),
- customer.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
-
- final ODataEntitySetRequest<ODataEntitySet> orderreq = client.getRetrieveRequestFactory().getEntitySetRequest(
- URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "/Orders"));
- orderreq.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySet> orderres = orderreq.execute();
- assertEquals(200, orderres.getStatusCode());
-
- assertEquals(Integer.valueOf(id),
- orderres.getBody().getEntities().get(0).getProperty("OrderId").getPrimitiveValue().
- toCastValue(Integer.class));
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "?$expand=Orders"));
- req.setFormat(format);
-
- customer = req.execute().getBody();
-
- boolean found = false;
- for (ODataLink link : customer.getNavigationLinks()) {
- if (link instanceof ODataInlineEntitySet && "Orders".equals(link.getName())) {
- found = true;
- }
- }
- assertTrue(found);
-
- return customer;
- }
-
- private void multiKey(final ODataPubFormat format) {
- final ODataEntity message = client.getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Message"));
-
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("MessageId",
- client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(1000)));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("FromUsername",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("1")));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("ToUsername",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("xlodhxzzusxecbzptxlfxprneoxkn")));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("Subject",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Test subject")));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("Body",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Test body")));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("IsRead",
- client.getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false)));
-
- final URIBuilder builder =
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Message");
- final ODataEntityCreateRequest<ODataEntity> req = client.getCUDRequestFactory().
- getEntityCreateRequest(builder.build(), message);
- req.setFormat(format);
-
- final ODataEntityCreateResponse<ODataEntity> res = req.execute();
- assertNotNull(res);
- assertEquals(201, res.getStatusCode());
-
- final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
- multiKey.put("FromUsername", "1");
- multiKey.put("MessageId", 1000);
-
- final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().
- getDeleteRequest(builder.appendKeySegment(multiKey).build()).execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
deleted file mode 100644
index de51167..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,242 +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.client.core.it.v3;
-
-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 java.util.LinkedHashMap;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
-import org.apache.olingo.client.api.communication.response.ODataRawResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.op.ResourceFactory;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity retrieve operations.
- */
-public class EntityRetrieveTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- private void withInlineEntry(final ODataPubFormat format) {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).expand("Info");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
- assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString());
- assertEquals(getServiceRoot() + "/Customer(-10)", entity.getEditLink().toASCIIString());
-
- assertEquals(5, entity.getNavigationLinks().size());
- assertTrue(entity.getAssociationLinks().isEmpty());
-
- boolean found = false;
-
- for (ODataLink link : entity.getNavigationLinks()) {
- if (link instanceof ODataInlineEntity) {
- final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
- assertNotNull(inline);
-
- debugEntity(client.getBinder().getEntity(
- inline, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
-
- final List<? extends CommonODataProperty> properties = inline.getProperties();
- assertEquals(2, properties.size());
-
- assertTrue(properties.get(0).getName().equals("CustomerInfoId")
- || properties.get(1).getName().equals("CustomerInfoId"));
- assertTrue(properties.get(0).getValue().toString().equals("11")
- || properties.get(1).getValue().toString().equals("11"));
-
- found = true;
- }
- }
-
- assertTrue(found);
- }
-
- @Test
- public void withInlineEntryFromAtom() {
- withInlineEntry(ODataPubFormat.ATOM);
- }
-
- @Test
- public void withInlineEntryFromJSON() {
- // this needs to be full, otherwise there is no mean to recognize links
- withInlineEntry(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void withInlineFeed(final ODataPubFormat format) {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).expand("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
-
- boolean found = false;
-
- for (ODataLink link : entity.getNavigationLinks()) {
- if (link instanceof ODataInlineEntitySet) {
- final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
- assertNotNull(inline);
-
- debugEntitySet(client.getBinder().getEntitySet(inline, ResourceFactory.entitySetClassForFormat(
- format == ODataPubFormat.ATOM)), "Just read");
-
- found = true;
- }
- }
-
- assertTrue(found);
- }
-
- @Test
- public void withInlineFeedFromAtom() {
- withInlineFeed(ODataPubFormat.ATOM);
- }
-
- @Test
- public void withInlineFeedFromJSON() {
- // this needs to be full, otherwise there is no mean to recognize links
- withInlineFeed(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void rawRequest(final ODataPubFormat format) {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Car").appendKeySegment(16);
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertNull(entitySet);
-
- final ResWrap<ODataEntity> entity = res.getBodyAs(ODataEntity.class);
- assertNotNull(entity.getPayload());
- }
-
- @Test
- public void rawRequestAsAtom() {
- rawRequest(ODataPubFormat.ATOM);
- }
-
- @Test
- public void rawRequestAsJSON() {
- // this needs to be full, otherwise actions will not be provided
- rawRequest(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void multiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
- multiKey.put("FromUsername", "1");
- multiKey.put("MessageId", -10);
-
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Message").appendKeySegment(multiKey);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertEquals("1", entity.getProperty("FromUsername").getPrimitiveValue().toCastValue(String.class));
- }
-
- @Test
- public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
- multiKey(ODataPubFormat.ATOM);
- }
-
- @Test
- public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
- multiKey(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void checkForETagAsATOM() {
- checkForETag(ODataPubFormat.ATOM);
- }
-
- @Test
- public void checkForETagAsJSON() {
- checkForETag(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void checkForETag(final ODataPubFormat format) {
- final CommonURIBuilder<?> uriBuilder =
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Product").appendKeySegment(-10);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final String etag = res.getETag();
- assertTrue(StringUtils.isNotBlank(etag));
-
- final CommonODataEntity product = res.getBody();
- assertEquals(etag, product.getETag());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void issue99() {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Car");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON);
-
- // this statement should cause an IllegalArgumentException bearing JsonParseException
- // since we are attempting to parse an EntitySet as if it was an Entity
- req.execute().getBody();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
deleted file mode 100644
index 077a6b1..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntitySetTestITCase.java
+++ /dev/null
@@ -1,176 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
-import org.apache.olingo.client.api.communication.response.ODataRawResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.op.ResourceFactory;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check basic feed operations.
- */
-public class EntitySetTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- @Test
- public void rawRequestAsAtom() throws IOException {
- rawRequest(ODataPubFormat.ATOM);
- }
-
- @Test
- public void rawRequestAsJSON() throws IOException {
- rawRequest(ODataPubFormat.JSON);
- }
-
- @Test
- public void readWithInlineCountAsJSON() throws IOException {
- readWithInlineCount(ODataPubFormat.JSON);
- }
-
- @Test
- public void readWithInlineCountAsAtom() throws IOException {
- readWithInlineCount(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readODataEntitySetIteratorFromAtom() {
- readODataEntitySetIterator(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSON() {
- readODataEntitySetIterator(ODataPubFormat.JSON);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSONFullMeta() {
- readODataEntitySetIterator(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSONNoMeta() {
- readODataEntitySetIterator(ODataPubFormat.JSON_NO_METADATA);
- }
-
- @Test
- public void readODataEntitySetWithNextFromAtom() {
- readEntitySetWithNextLink(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readODataEntitySetWithNextFromJSON() {
- readEntitySetWithNextLink(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void readEntitySetWithNextLink(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer");
-
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- final ODataEntitySet feed = res.getBody();
-
- assertNotNull(feed);
-
- debugEntitySet(client.getBinder().getEntitySet(feed, ResourceFactory.entitySetClassForFormat(
- ODataPubFormat.ATOM == format)), "Just retrieved feed");
-
- assertEquals(2, feed.getEntities().size());
- assertNotNull(feed.getNext());
-
- final URI expected = URI.create(getServiceRoot() + "/Customer?$skiptoken=-9");
- final URI found = URIUtils.getURI(getServiceRoot(), feed.getNext().toASCIIString());
-
- assertEquals(expected, found);
- }
-
- private void readODataEntitySetIterator(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer");
-
- final ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> req =
- client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySetIterator<ODataEntitySet, ODataEntity>> res = req.execute();
- final ODataEntitySetIterator<ODataEntitySet, ODataEntity> feedIterator = res.getBody();
-
- assertNotNull(feedIterator);
-
- int count = 0;
-
- while (feedIterator.hasNext()) {
- assertNotNull(feedIterator.next());
- count++;
- }
- assertEquals(2, count);
- assertTrue(feedIterator.getNext().toASCIIString().endsWith("Customer?$skiptoken=-9"));
- }
-
- private void readWithInlineCount(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Product").inlineCount(URIBuilder.InlineCount.allpages);
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertEquals(10, entitySet.getPayload().getCount());
- }
-
- private void rawRequest(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Car");
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertNotNull(entitySet.getPayload());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
deleted file mode 100644
index 750709c..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/EntityUpdateTestITCase.java
+++ /dev/null
@@ -1,242 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.fail;
-
-import java.net.URI;
-import java.util.LinkedHashMap;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.header.HeaderName;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity update operations.
- */
-public class EntityUpdateTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- @Test
- public void mergeAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
- final String etag = getETag(uri);
- final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- merge.setEditLink(uri);
- updateEntityDescription(format, merge, UpdateType.MERGE, etag);
- }
-
- @Test
- public void mergeAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
- final String etag = getETag(uri);
- final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- merge.setEditLink(uri);
- updateEntityDescription(format, merge, UpdateType.MERGE, etag);
- }
-
- @Test
- public void patchAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
- final String etag = getETag(uri);
- final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- patch.setEditLink(uri);
- updateEntityDescription(format, patch, UpdateType.PATCH, etag);
- }
-
- @Test
- public void patchAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
- final String etag = getETag(uri);
- final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- patch.setEditLink(uri);
- updateEntityDescription(format, patch, UpdateType.PATCH, etag);
- }
-
- @Test
- public void replaceAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Car").appendKeySegment(14).build());
- updateEntityDescription(format, changes, UpdateType.REPLACE);
- }
-
- @Test
- public void replaceAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Car").appendKeySegment(14).build());
- updateEntityDescription(format, changes, UpdateType.REPLACE);
- }
-
- @Test
- public void patchLinkAsAtom() throws EdmPrimitiveTypeException {
- patchLink(ODataPubFormat.ATOM);
- }
-
- @Test
- public void patchLinkAsJSON() throws EdmPrimitiveTypeException {
- patchLink(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- public void patchLink(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).build();
-
- final ODataEntity patch = client.getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
- patch.setEditLink(uri);
-
- // ---------------------------------------
- // Update to CustomerInfo(12)
- // ---------------------------------------
- URI customerInfoURI = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("CustomerInfo").appendKeySegment(12).build();
-
- patch.addLink(client.getObjectFactory().newEntityNavigationLink("Info", customerInfoURI));
-
- update(UpdateType.PATCH, patch, format, null);
-
- customerInfoURI = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).appendNavigationSegment("Info").build();
-
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(customerInfoURI);
- req.setFormat(format);
-
- ODataEntity newInfo = req.execute().getBody();
-
- assertEquals(Integer.valueOf(12),
- newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
- // ---------------------------------------
-
- // ---------------------------------------
- // Restore to CustomerInfo(11)
- // ---------------------------------------
- patch.getNavigationLinks().clear();
-
- customerInfoURI = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("CustomerInfo").appendKeySegment(11).build();
- read(format, customerInfoURI);
-
- patch.addLink(client.getObjectFactory().newEntityNavigationLink("Info", customerInfoURI));
-
- update(UpdateType.PATCH, patch, format, null);
-
- customerInfoURI = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).appendNavigationSegment("Info").build();
-
- req = client.getRetrieveRequestFactory().getEntityRequest(customerInfoURI);
- req.setFormat(format);
-
- newInfo = req.execute().getBody();
-
- assertEquals(Integer.valueOf(11),
- newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
- // ---------------------------------------
- }
-
- private ODataEntityUpdateRequest<ODataEntity> buildMultiKeyUpdateReq(final ODataPubFormat format)
- throws EdmPrimitiveTypeException {
-
- final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
- multiKey.put("FromUsername", "1");
- multiKey.put("MessageId", -10);
- final ODataEntity message = read(format, client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Message").appendKeySegment(multiKey).build());
- message.getAssociationLinks().clear();
- message.getNavigationLinks().clear();
-
- final boolean before = message.getProperty("IsRead").getPrimitiveValue().toCastValue(Boolean.class);
- message.getProperties().remove(message.getProperty("IsRead"));
- getClient().getBinder().add(message,
- client.getObjectFactory().newPrimitiveProperty("IsRead",
- client.getObjectFactory().newPrimitiveValueBuilder().buildBoolean(!before)));
-
- return client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, message);
- }
-
- private void mergeMultiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final ODataEntityUpdateResponse<ODataEntity> res = buildMultiKeyUpdateReq(format).execute();
- assertEquals(204, res.getStatusCode());
- }
-
- @Test
- public void mergeMultiKeyAsAtom() throws EdmPrimitiveTypeException {
- mergeMultiKey(ODataPubFormat.ATOM);
- }
-
- @Test
- public void mergeMultiKeyAsJSON() throws EdmPrimitiveTypeException {
- mergeMultiKey(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void updateReturnContent() throws EdmPrimitiveTypeException {
- final ODataEntityUpdateRequest<ODataEntity> req =
- buildMultiKeyUpdateReq(client.getConfiguration().getDefaultPubFormat());
- req.setPrefer(client.newPreferences().returnContent());
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- assertEquals(client.newPreferences().returnContent(),
- res.getHeader(HeaderName.preferenceApplied).iterator().next());
- assertNotNull(res.getBody());
- }
-
- @Test
- public void concurrentModification() {
- final URI uri = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
- String etag = getETag(uri);
- final ODataEntity product = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- product.setEditLink(uri);
- updateEntityStringProperty("BaseConcurrency",
- client.getConfiguration().getDefaultPubFormat(), product, UpdateType.MERGE, etag);
-
- try {
- etag += "-invalidone";
- updateEntityStringProperty("BaseConcurrency",
- client.getConfiguration().getDefaultPubFormat(), product, UpdateType.MERGE, etag);
- fail();
- } catch (ODataClientErrorException e) {
- assertEquals(412, e.getStatusLine().getStatusCode());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
deleted file mode 100644
index d5d575d..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ErrorTestITCase.java
+++ /dev/null
@@ -1,172 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.fail;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import java.net.URI;
-import org.apache.http.HttpResponse;
-import org.apache.http.client.HttpClient;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
-import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
-import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmFunctionImport;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check basic entity operations.
- */
-public class ErrorTestITCase extends AbstractTestITCase {
-
- private class ErrorGeneratingRequest
- extends AbstractODataBasicRequest<ODataEntityCreateResponse<ODataEntity>, ODataPubFormat> {
-
- public ErrorGeneratingRequest(final HttpMethod method, final URI uri) {
- super(client, ODataPubFormat.class, method, uri);
- }
-
- @Override
- protected InputStream getPayload() {
- return new ByteArrayInputStream(new byte[0]);
- }
-
- @Override
- public ODataEntityCreateResponse<ODataEntity> execute() {
- final HttpResponse res = doExecute();
- return new ErrorResponseImpl(client, httpClient, res);
- }
-
- private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<ODataEntity> {
-
- private final ODataClient odataClient;
-
- public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) {
- super(client, res);
- this.odataClient = odataClient;
- }
-
- @Override
- public ODataEntity getBody() {
- return odataClient.getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid"));
- }
- }
- }
-
- private void stacktraceError(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("Customer");
-
- final ErrorGeneratingRequest errorReq = new ErrorGeneratingRequest(HttpMethod.POST, uriBuilder.build());
- errorReq.setFormat(format);
-
- try {
- errorReq.execute();
- fail();
- } catch (ODataClientErrorException e) {
- LOG.error("ODataClientErrorException found", e);
- assertEquals(400, e.getStatusLine().getStatusCode());
- assertNotNull(e.getODataError());
- }
- }
-
- @Test
- public void xmlStacktraceError() {
- stacktraceError(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonStacktraceError() {
- stacktraceError(ODataPubFormat.JSON);
- }
-
- private void notfoundError(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("Customer(154)");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- try {
- req.execute();
- fail();
- } catch (ODataClientErrorException e) {
- LOG.error("ODataClientErrorException found", e);
- assertEquals(404, e.getStatusLine().getStatusCode());
- assertNull(e.getCause());
- assertNotNull(e.getODataError());
- }
- }
-
- @Test
- public void xmlNotfoundError() {
- notfoundError(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonNotfoundError() {
- notfoundError(ODataPubFormat.JSON);
- }
-
- private void instreamError(final ODataPubFormat format) {
- final Edm metadata =
- client.getRetrieveRequestFactory().getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(metadata);
-
- final EdmEntityContainer container = metadata.getSchemas().get(0).getEntityContainer();
- final EdmFunctionImport funcImp = container.getFunctionImport("InStreamErrorGetCustomer");
- final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
- final ODataInvokeRequest<ODataEntitySet> req =
- client.getInvokeRequestFactory().getInvokeRequest(builder.build(), funcImp.getUnboundFunction(null));
- req.setFormat(format);
-
- final ODataInvokeResponse<ODataEntitySet> res = req.execute();
- res.getBody();
- fail("Shouldn't get here");
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void atomInstreamError() {
- instreamError(ODataPubFormat.ATOM);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void jsonInstreamError() {
- instreamError(ODataPubFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterFactoryTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterFactoryTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterFactoryTestITCase.java
deleted file mode 100644
index 1422df8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterFactoryTestITCase.java
+++ /dev/null
@@ -1,167 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.client.api.uri.URIFilter;
-import org.apache.olingo.client.api.uri.v3.FilterArgFactory;
-import org.apache.olingo.client.api.uri.v3.FilterFactory;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.junit.Test;
-
-public class FilterFactoryTestITCase extends AbstractTestITCase {
-
- private FilterFactory getFilterFactory() {
- return getClient().getFilterFactory();
- }
-
- private FilterArgFactory getFilterArgFactory() {
- return getFilterFactory().getArgFactory();
- }
-
- private void match(final String entitySet, final URIFilter filter, final int expected) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment(entitySet).filter(filter);
-
- final CommonODataEntitySet feed = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).
- execute().getBody();
- assertNotNull(feed);
- assertEquals(expected, feed.getEntities().size());
- }
-
- @Test
- public void simple() {
- match("Car", getFilterFactory().lt("VIN", 16), 5);
- }
-
- @Test
- public void and() {
- final URIFilter filter =
- getFilterFactory().and(
- getFilterFactory().lt("VIN", 16),
- getFilterFactory().gt("VIN", 12));
-
- match("Car", filter, 3);
- }
-
- @Test
- public void not() {
- final URIFilter filter =
- getFilterFactory().not(
- getFilterFactory().or(
- getFilterFactory().ge("VIN", 16),
- getFilterFactory().le("VIN", 12)));
-
- match("Car", filter, 3);
- }
-
- @Test
- public void operator() {
- URIFilter filter =
- getFilterFactory().eq(
- getFilterArgFactory().add(getFilterArgFactory().property("VIN"), getFilterArgFactory().
- literal(1)),
- getFilterArgFactory().literal(16));
-
- match("Car", filter, 1);
-
- filter =
- getFilterFactory().eq(
- getFilterArgFactory().add(getFilterArgFactory().literal(1), getFilterArgFactory().
- property("VIN")),
- getFilterArgFactory().literal(16));
-
- match("Car", filter, 1);
-
- filter =
- getFilterFactory().eq(
- getFilterArgFactory().literal(16),
- getFilterArgFactory().add(getFilterArgFactory().literal(1), getFilterArgFactory().
- property("VIN")));
-
- match("Car", filter, 1);
- }
-
- @Test
- public void function() {
- final URIFilter filter =
- getFilterFactory().match(
- getFilterArgFactory().startswith(
- getFilterArgFactory().property("Description"), getFilterArgFactory().literal("cen")));
-
- match("Car", filter, 1);
- }
-
- @Test
- public void composed() {
- final URIFilter filter =
- getFilterFactory().gt(
- getFilterArgFactory().length(getFilterArgFactory().property("Description")),
- getFilterArgFactory().add(getFilterArgFactory().property("VIN"), getFilterArgFactory().literal(
- 10)));
-
- match("Car", filter, 5);
- }
-
- @Test
- public void propertyPath() {
- URIFilter filter =
- getFilterFactory().eq(
- getFilterArgFactory().indexof(
- getFilterArgFactory().property("PrimaryContactInfo/HomePhone/PhoneNumber"),
- getFilterArgFactory().literal("ODataJClient")),
- getFilterArgFactory().literal(1));
-
- match("Customer", filter, 0);
-
- filter =
- getFilterFactory().ne(
- getFilterArgFactory().indexof(
- getFilterArgFactory().property("PrimaryContactInfo/HomePhone/PhoneNumber"),
- getFilterArgFactory().literal("lccvussrv")),
- getFilterArgFactory().literal(-1));
-
- match("Customer", filter, 2);
- }
-
- @Test
- public void datetime() {
- final URIFilter filter =
- getFilterFactory().eq(
- getFilterArgFactory().month(
- getFilterArgFactory().property("PurchaseDate")),
- getFilterArgFactory().literal(12));
-
- match("ComputerDetail", filter, 1);
- }
-
- @Test
- public void isof() {
- final URIFilter filter =
- getFilterFactory().match(
- getFilterArgFactory().isof(
- getFilterArgFactory().literal(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee")));
-
- match("Person", filter, 4);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterTestITCase.java
deleted file mode 100644
index 3204fb0..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/FilterTestITCase.java
+++ /dev/null
@@ -1,94 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.junit.Test;
-
-public class FilterTestITCase extends AbstractTestITCase {
-
- private void filterQueryTest(final String entity, final String filter, final int expected) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment(entity).filter(filter);
- final ODataEntitySet entitySet = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).
- execute().getBody();
- assertNotNull(entitySet);
- assertEquals(expected, entitySet.getEntities().size());
- }
-
- @Test
- public void withId() {
- filterQueryTest("Customer", "CustomerId eq -10", 1);
- }
-
- @Test
- public void logical() {
- filterQueryTest("Customer", "CustomerId gt -10", 2);
- filterQueryTest("Customer", "CustomerId lt -10", 0);
- filterQueryTest("Customer", "not endswith(Name,'Chandan')", 2);
- filterQueryTest("Car", "VIN le 18 and VIN gt 12", 6);
- }
-
- @Test
- public void arithmetic() {
- filterQueryTest("Car", "VIN add 5 lt 11", 0);
- filterQueryTest("Car", "VIN div 2 le 8", 7);
- filterQueryTest("Car", "VIN mul 2 le 30", 5);
- filterQueryTest("Person", "PersonId sub 2 lt -10", 2);
- }
-
- @Test
- public void stringOperations() {
- filterQueryTest("Product", "length(Description) eq 7", 1);
- filterQueryTest("Product", "length(Description) eq 7", 1);
- filterQueryTest("Product", "substringof('kdcuklu', Description) eq true", 1);
- filterQueryTest("Product", "startswith(Description, 'k') eq true", 2);
- filterQueryTest("Product", "startswith(Description, 'k') eq true", 2);
- filterQueryTest("Product", "indexof(Description, 'k') eq 0", 2);
- filterQueryTest("Product", "toupper(Description) eq 'KDCUKLU'", 1);
- filterQueryTest("Product", "concat(Description, ', newname') eq 'kdcuklu, newname'", 1);
- }
-
- @Test
- public void math() {
- filterQueryTest("Product", "round(Dimensions/Width) eq 7338", 1);
- filterQueryTest("Product", "round(Dimensions/Width) eq 7338", 1);
- filterQueryTest("Product", "floor(Dimensions/Width) eq 7337", 1);
- filterQueryTest("Product", "ceiling(Dimensions/Width) eq 7338", 1);
- }
-
- @Test
- public void date() {
- filterQueryTest("ComputerDetail", "day(PurchaseDate) eq 15", 1);
- filterQueryTest("ComputerDetail", "month(PurchaseDate) eq 12", 2);
- filterQueryTest("ComputerDetail", "hour(PurchaseDate) eq 1", 1);
- filterQueryTest("ComputerDetail", "minute(PurchaseDate) eq 33", 1);
- filterQueryTest("ComputerDetail", "second(PurchaseDate) eq 35", 1);
- filterQueryTest("ComputerDetail", "year(PurchaseDate) eq 2020", 1);
- }
-
- @Test
- public void isOfTest() {
- filterQueryTest("Customer", "isof(Name,'Edm.String') eq true", 2);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java
deleted file mode 100644
index e3daf11..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/InvokeTestITCase.java
+++ /dev/null
@@ -1,318 +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.client.core.it.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.net.URI;
-import java.util.Collections;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
-import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmFunction;
-import org.apache.olingo.commons.api.edm.EdmFunctionImport;
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.edm.EdmTypeInfo;
-import org.junit.Test;
-
-public class InvokeTestITCase extends AbstractTestITCase {
-
- private void getWithNoParams(final ODataPubFormat format) {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
-
- // 1. get primitive value property
- EdmFunctionImport funcImp = container.getFunctionImport("GetPrimitiveString");
- EdmFunction func = funcImp.getUnboundFunction(null);
-
- URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
-
- ODataInvokeRequest<ODataProperty> req = getClient().getInvokeRequestFactory().
- getInvokeRequest(builder.build(), func);
- req.setFormat(format);
- ODataInvokeResponse<ODataProperty> res = req.execute();
- assertNotNull(res);
-
- ODataProperty property = res.getBody();
- assertNotNull(property);
- assertEquals("Foo", property.getPrimitiveValue().toString());
-
- // 2. get collection of complex type property
- funcImp = container.getFunctionImport("EntityProjectionReturnsCollectionOfComplexTypes");
- func = funcImp.getUnboundFunction(null);
-
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
-
- req = getClient().getInvokeRequestFactory().getInvokeRequest(builder.build(), func);
- req.setFormat(format);
- res = req.execute();
- assertNotNull(res);
-
- property = res.getBody();
- assertNotNull(property);
- assertTrue(property.hasCollectionValue());
- assertFalse(property.getCollectionValue().isEmpty());
- }
-
- @Test
- public void getWithNoParamsAsAtom() {
- getWithNoParams(ODataPubFormat.ATOM);
- }
-
- @Test
- public void getWithNoParamsAsJSON() {
- getWithNoParams(ODataPubFormat.JSON);
- }
-
- private void getWithParams(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- // 1. primitive result
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- EdmFunctionImport funcImp = container.getFunctionImport("GetArgumentPlusOne");
-
- URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
-
- EdmFunction function = funcImp.getUnboundFunction(Collections.singletonList("arg1"));
- EdmParameter param = function.getParameter(function.getParameterNames().get(0));
- ODataPrimitiveValue paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(param.getType()).
- setValue(154).
- build();
-
- final ODataInvokeRequest<ODataProperty> primitiveReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(builder.build(), function,
- Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
- primitiveReq.setFormat(format);
-
- final ODataInvokeResponse<ODataProperty> primitiveRes = primitiveReq.execute();
- assertNotNull(primitiveRes);
-
- final ODataProperty property = primitiveRes.getBody();
- assertNotNull(property);
- assertEquals(Integer.valueOf(155), property.getPrimitiveValue().toCastValue(Integer.class));
-
- // 2. feed result
- funcImp = container.getFunctionImport("GetSpecificCustomer");
-
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
-
- function = funcImp.getUnboundFunction(Collections.singletonList("Name"));
- param = function.getParameter(function.getParameterNames().get(0));
- paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(param.getType()).
- setValue(StringUtils.EMPTY).
- build();
-
- final ODataInvokeRequest<ODataEntitySet> feedReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(builder.build(), function,
- Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
- feedReq.setFormat(format);
-
- final ODataInvokeResponse<ODataEntitySet> feedRes = feedReq.execute();
- assertNotNull(feedRes);
-
- final ODataEntitySet feed = feedRes.getBody();
- assertNotNull(feed);
-
- final Set<Integer> customerIds = new HashSet<Integer>(feed.getEntities().size());
- for (ODataEntity entity : feed.getEntities()) {
- customerIds.add(entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
- }
- assertTrue(customerIds.contains(-8));
- }
-
- @Test
- public void getWithParamsAsAtom() throws EdmPrimitiveTypeException {
- getWithParams(ODataPubFormat.ATOM);
- }
-
- @Test
- public void getWithParamsAsJSON() throws EdmPrimitiveTypeException {
- getWithParams(ODataPubFormat.JSON);
- }
-
- private ODataEntity createEmployee(final ODataPubFormat format) {
- final ODataEntity employee = getClient().getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Employee"));
-
- employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("PersonId",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1244)));
- employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("Test employee")));
- employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
- "ManagersPersonId", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(3777)));
- employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
- "Salary", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1000)));
- employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
- "Title", getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("CEO")));
-
- final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Person");
-
- final ODataEntityCreateRequest<ODataEntity> createReq =
- getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), employee);
- createReq.setFormat(format);
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
-
- final ODataEntityRequest<ODataEntity> req =
- getClient().getRetrieveRequestFactory().getEntityRequest(uriBuilder.appendKeySegment(1244).build());
- return req.execute().getBody();
- }
-
- private void deleteEmployee(final ODataPubFormat format, final Integer id) {
- final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Person").appendKeySegment(id);
-
- final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(uriBuilder.build());
- deleteReq.setFormat(format);
- final ODataDeleteResponse deleteRes = deleteReq.execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-
- @Test
- public void boundPost() throws EdmPrimitiveTypeException {
- // 0. create an employee
- final ODataEntity created = createEmployee(ODataPubFormat.JSON_FULL_METADATA);
- assertNotNull(created);
- final Integer createdId = created.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class);
- assertNotNull(createdId);
-
- // 1. invoke action bound with the employee just created
- final ODataOperation operation = created.getOperations().get(0);
-
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- final EdmAction action = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), operation.getTitle()),
- created.getTypeName(), false);
-
- final ODataInvokeRequest<ODataNoContent> req = getClient().getInvokeRequestFactory().
- getInvokeRequest(operation.getTarget(), action);
- req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
- final ODataInvokeResponse<ODataNoContent> res = req.execute();
- assertNotNull(res);
- assertEquals(204, res.getStatusCode());
-
- // 2. check that invoked action has effectively run
- final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Person").appendKeySegment(createdId);
- final ODataEntityRequest<ODataEntity> retrieveRes =
- getClient().getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- retrieveRes.setFormat(ODataPubFormat.JSON_FULL_METADATA);
- final ODataEntity read = retrieveRes.execute().getBody();
- assertEquals("0", read.getProperty("Salary").getPrimitiveValue().toString());
- assertTrue(read.getProperty("Title").getPrimitiveValue().toString().endsWith("[Sacked]"));
-
- // 3. remove the test employee
- deleteEmployee(ODataPubFormat.JSON_FULL_METADATA, createdId);
- }
-
- @Test
- public void boundPostWithParams() throws EdmPrimitiveTypeException {
- // 1. read employees and store their current salary
- final URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Person").
- appendEntitySetSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee");
- final URI employeesURI = builder.build();
- ODataEntitySet employees = getClient().getRetrieveRequestFactory().
- getEntitySetRequest(employeesURI).execute().getBody();
- assertFalse(employees.getEntities().isEmpty());
- final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.getCount());
- for (ODataEntity employee : employees.getEntities()) {
- preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class),
- employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
- }
- assertFalse(preSalaries.isEmpty());
-
- // 2. invoke action bound, with additional parameter
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
-
- final EdmTypeInfo employeesTypeInfo = new EdmTypeInfo.Builder().setEdm(edm).
- setTypeExpression("Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.Employee)").build();
- final EdmAction action = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), "IncreaseSalaries"),
- employeesTypeInfo.getFullQualifiedName(), employeesTypeInfo.isCollection());
-
- final EdmParameter param = action.getParameter(action.getParameterNames().get(1));
- final ODataPrimitiveValue paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(param.getType()).
- setValue(1).
- build();
-
- final ODataInvokeRequest<ODataNoContent> req = getClient().getInvokeRequestFactory().getInvokeRequest(
- builder.appendOperationCallSegment(action.getName()).build(), action,
- Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
- final ODataInvokeResponse<ODataNoContent> res = req.execute();
- assertNotNull(res);
- assertEquals(204, res.getStatusCode());
-
- // 3. check whether salaries were incremented
- employees = getClient().getRetrieveRequestFactory().getEntitySetRequest(employeesURI).execute().getBody();
- assertFalse(employees.getEntities().isEmpty());
- for (ODataEntity employee : employees.getEntities()) {
- assertTrue(
- preSalaries.get(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class))
- < employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/KeyAsSegmentTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/KeyAsSegmentTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/KeyAsSegmentTestITCase.java
deleted file mode 100644
index 547c3ff..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/KeyAsSegmentTestITCase.java
+++ /dev/null
@@ -1,110 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class KeyAsSegmentTestITCase extends AbstractTestITCase {
-
- @BeforeClass
- public static void enableKeyAsSegment() {
- client.getConfiguration().setKeyAsSegment(true);
- }
-
- private void read(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testKeyAsSegmentServiceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(-10);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
-
- assertFalse(entity.getEditLink().toASCIIString().contains("("));
- assertFalse(entity.getEditLink().toASCIIString().contains(")"));
- }
-
- @Test
- public void fromAtom() {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void fromJSON() {
- read(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void createODataEntityAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final int id = 1;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- createEntity(testKeyAsSegmentServiceRootURL, format, original, "Customer");
- final ODataEntity actual = compareEntities(testKeyAsSegmentServiceRootURL, format, original, id, null);
-
- cleanAfterCreate(format, actual, false, testKeyAsSegmentServiceRootURL);
- }
-
- @Test
- public void createODataEntityAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final int id = 2;
- final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
-
- createEntity(testKeyAsSegmentServiceRootURL, format, original, "Customer");
- final ODataEntity actual = compareEntities(testKeyAsSegmentServiceRootURL, format, original, id, null);
-
- cleanAfterCreate(format, actual, false, testKeyAsSegmentServiceRootURL);
- }
-
- @Test
- public void replaceODataEntityAsAtom() {
- final ODataPubFormat format = ODataPubFormat.ATOM;
- final ODataEntity changes = read(format, client.getURIBuilder(testKeyAsSegmentServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(14).build());
- updateEntityDescription(format, changes, UpdateType.REPLACE);
- }
-
- @Test
- public void replaceODataEntityAsJSON() {
- final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
- final ODataEntity changes = read(format, client.getURIBuilder(testKeyAsSegmentServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(14).build());
- updateEntityDescription(format, changes, UpdateType.REPLACE);
- }
-
- @AfterClass
- public static void disableKeyAsSegment() {
- client.getConfiguration().setKeyAsSegment(false);
- }
-}
[10/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java
new file mode 100644
index 0000000..cc97521
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityCreateTestITCase.java
@@ -0,0 +1,484 @@
+/*
+ * 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.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 java.net.URI;
+import java.util.Collections;
+import java.util.HashSet;
+import java.util.LinkedHashMap;
+import java.util.Set;
+import org.apache.http.entity.ContentType;
+import org.apache.olingo.client.api.communication.header.HeaderName;
+import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.http.NoContentException;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check create entity operations.
+ */
+public class EntityCreateTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ @Test
+ public void createAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final int id = 1;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
+
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final int id = 2;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual = compareEntities(getServiceRoot(), format, original, id, null);
+
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createWithInlineAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final int id = 3;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual =
+ compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
+
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void createWithInlineAsJSON() {
+ // this needs to be full, otherwise there is no mean to recognize links
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final int id = 4;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", true);
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual =
+ compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
+
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void createInlineWithoutLinkAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final int id = 5;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ original.addLink(client.getObjectFactory().newDeepInsertEntity(
+ "Info", getSampleCustomerInfo(id, "Sample Customer_Info")));
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual =
+ compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
+
+ boolean found = false;
+
+ for (ODataLink link : actual.getNavigationLinks()) {
+ assertNotNull(link.getLink());
+ if (link.getLink().toASCIIString().endsWith("Customer(" + id + ")/Info")) {
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void createInlineWithoutLinkAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final int id = 6;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ original.addLink(client.getObjectFactory().newDeepInsertEntity(
+ "Info", getSampleCustomerInfo(id, "Sample Customer_Info")));
+
+ createEntity(getServiceRoot(), format, original, "Customer");
+ final ODataEntity actual =
+ compareEntities(getServiceRoot(), format, original, id, Collections.<String>singleton("Info"));
+
+ boolean found = false;
+
+ for (ODataLink link : actual.getNavigationLinks()) {
+ assertNotNull(link.getLink());
+ if (link.getLink().toASCIIString().endsWith("Customer(" + id + ")/Info")) {
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void createWithNavigationAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final ODataEntity actual = createWithNavigationLink(format, 5);
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createWithNavigationAsJSON() {
+ // this needs to be full, otherwise there is no mean to recognize links
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final ODataEntity actual = createWithNavigationLink(format, 6);
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createWithFeedNavigationAsAtom() throws EdmPrimitiveTypeException {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final ODataEntity actual = createWithFeedNavigationLink(format, 7);
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createWithFeedNavigationAsJSON() throws EdmPrimitiveTypeException {
+ // this needs to be full, otherwise there is no mean to recognize links
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final ODataEntity actual = createWithFeedNavigationLink(format, 8);
+ cleanAfterCreate(format, actual, false, getServiceRoot());
+ }
+
+ @Test
+ public void createWithBackNavigationAsAtom() throws EdmPrimitiveTypeException {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final ODataEntity actual = createWithBackNavigationLink(format, 9);
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void createWithBackNavigationAsJSON() throws EdmPrimitiveTypeException {
+ // this needs to be full, otherwise there is no mean to recognize links
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final ODataEntity actual = createWithBackNavigationLink(format, 10);
+ cleanAfterCreate(format, actual, true, getServiceRoot());
+ }
+
+ @Test
+ public void multiKeyAsAtom() {
+ multiKey(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void multiKeyAsJSON() {
+ multiKey(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void createReturnNoContent() {
+ final int id = 1;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").build(), original);
+ createReq.setPrefer(client.newPreferences().returnNoContent());
+
+ final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+ assertEquals(204, createRes.getStatusCode());
+ assertEquals(client.newPreferences().returnNoContent(),
+ createRes.getHeader(HeaderName.preferenceApplied).iterator().next());
+
+ try {
+ createRes.getBody();
+ fail();
+ } catch (NoContentException e) {
+ assertNotNull(e);
+ }
+
+ final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").appendKeySegment(id).build()).
+ execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+
+ @Test
+ public void issue135() {
+ final int id = 2;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer for issue 135", false);
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer");
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
+ createReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+ createReq.setContentType(ContentType.APPLICATION_ATOM_XML.getMimeType());
+ createReq.setPrefer(client.newPreferences().returnContent());
+
+ try {
+ final ODataEntityCreateResponse createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } finally {
+ final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").appendKeySegment(id).
+ build()).
+ execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+ }
+
+ private ODataEntity createWithFeedNavigationLink(final ODataPubFormat format, final int id)
+ throws EdmPrimitiveTypeException {
+
+ final String sampleName = "Sample customer";
+ final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
+
+ final Set<Integer> keys = new HashSet<Integer>();
+ keys.add(-100);
+ keys.add(-101);
+
+ for (Integer key : keys) {
+ final ODataEntity order = client.getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Order"));
+
+ order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("OrderId",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(key)));
+ order.getProperties().add(client.getObjectFactory().newPrimitiveProperty("CustomerId",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+
+ final ODataEntityCreateRequest<ODataEntity> createReq = client.getCUDRequestFactory().getEntityCreateRequest(
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Order").build(), order);
+ createReq.setFormat(format);
+
+ original.addLink(client.getObjectFactory().newEntitySetNavigationLink(
+ "Orders",
+ createReq.execute().getBody().getEditLink()));
+ }
+
+ final ODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
+ // now, compare the created one with the actual one and go deeply into the associated customer info.....
+ final ODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Orders");
+
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ assertEquals(2, entitySet.getCount());
+
+ for (ODataEntity entity : entitySet.getEntities()) {
+ final Integer key = entity.getProperty("OrderId").getPrimitiveValue().toCastValue(Integer.class);
+ final Integer customerId = entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(keys.contains(key));
+ assertEquals(Integer.valueOf(id), customerId);
+ keys.remove(key);
+
+ final ODataDeleteRequest deleteReq = client.getCUDRequestFactory().getDeleteRequest(
+ URIUtils.getURI(getServiceRoot(), entity.getEditLink().toASCIIString()));
+
+ deleteReq.setFormat(format);
+ assertEquals(204, deleteReq.execute().getStatusCode());
+ }
+
+ return actual;
+ }
+
+ private ODataEntity createWithNavigationLink(final ODataPubFormat format, final int id) {
+ final String sampleName = "Sample customer";
+
+ final ODataEntity original = getSampleCustomerProfile(id, sampleName, false);
+ original.addLink(client.getObjectFactory().newEntityNavigationLink(
+ "Info", URI.create(getServiceRoot() + "/CustomerInfo(12)")));
+
+ final ODataEntity created = createEntity(getServiceRoot(), format, original, "Customer");
+ // now, compare the created one with the actual one and go deeply into the associated customer info.....
+ final ODataEntity actual = compareEntities(getServiceRoot(), format, created, id, null);
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(id).appendEntitySetSegment("Info");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataEntity info = res.getBody();
+ assertNotNull(info);
+
+ boolean found = false;
+
+ for (ODataProperty prop : info.getProperties()) {
+ if ("CustomerInfoId".equals(prop.getName())) {
+ assertEquals("12", prop.getValue().toString());
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+
+ return actual;
+ }
+
+ private ODataEntity createWithBackNavigationLink(final ODataPubFormat format, final int id)
+ throws EdmPrimitiveTypeException {
+
+ final String sampleName = "Sample customer";
+
+ ODataEntity customer = getSampleCustomerProfile(id, sampleName, false);
+ customer = createEntity(getServiceRoot(), format, customer, "Customer");
+
+ ODataEntity order = client.getObjectFactory().newEntity(new FullQualifiedName(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.Order"));
+ getClient().getBinder().add(order,
+ client.getObjectFactory().newPrimitiveProperty("CustomerId",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+ getClient().getBinder().add(order,
+ client.getObjectFactory().newPrimitiveProperty("OrderId",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+
+ order.addLink(client.getObjectFactory().newEntityNavigationLink(
+ "Customer", URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString())));
+
+ order = createEntity(getServiceRoot(), format, order, "Order");
+
+ final ODataEntity changes = client.getObjectFactory().newEntity(new FullQualifiedName(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
+ changes.setEditLink(customer.getEditLink());
+ changes.addLink(client.getObjectFactory().newEntitySetNavigationLink(
+ "Orders", URIUtils.getURI(getServiceRoot(), order.getEditLink().toASCIIString())));
+ update(UpdateType.PATCH, changes, format, null);
+
+ final ODataEntityRequest<ODataEntity> customerreq = client.getRetrieveRequestFactory().getEntityRequest(
+ URIUtils.getURI(getServiceRoot(), order.getEditLink().toASCIIString() + "/Customer"));
+ customerreq.setFormat(format);
+
+ customer = customerreq.execute().getBody();
+
+ assertEquals(Integer.valueOf(id),
+ customer.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
+
+ final ODataEntitySetRequest<ODataEntitySet> orderreq = client.getRetrieveRequestFactory().getEntitySetRequest(
+ URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "/Orders"));
+ orderreq.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySet> orderres = orderreq.execute();
+ assertEquals(200, orderres.getStatusCode());
+
+ assertEquals(Integer.valueOf(id),
+ orderres.getBody().getEntities().get(0).getProperty("OrderId").getPrimitiveValue().
+ toCastValue(Integer.class));
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
+ URIUtils.getURI(getServiceRoot(), customer.getEditLink().toASCIIString() + "?$expand=Orders"));
+ req.setFormat(format);
+
+ customer = req.execute().getBody();
+
+ boolean found = false;
+ for (ODataLink link : customer.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntitySet && "Orders".equals(link.getName())) {
+ found = true;
+ }
+ }
+ assertTrue(found);
+
+ return customer;
+ }
+
+ private void multiKey(final ODataPubFormat format) {
+ final ODataEntity message = client.getObjectFactory().newEntity(new FullQualifiedName(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.Message"));
+
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("MessageId",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildInt32(1000)));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("FromUsername",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("1")));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("ToUsername",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("xlodhxzzusxecbzptxlfxprneoxkn")));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("Subject",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Test subject")));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("Body",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Test body")));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("IsRead",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false)));
+
+ final URIBuilder builder =
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Message");
+ final ODataEntityCreateRequest<ODataEntity> req = client.getCUDRequestFactory().
+ getEntityCreateRequest(builder.build(), message);
+ req.setFormat(format);
+
+ final ODataEntityCreateResponse<ODataEntity> res = req.execute();
+ assertNotNull(res);
+ assertEquals(201, res.getStatusCode());
+
+ final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
+ multiKey.put("FromUsername", "1");
+ multiKey.put("MessageId", 1000);
+
+ final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().
+ getDeleteRequest(builder.appendKeySegment(multiKey).build()).execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
new file mode 100644
index 0000000..1b95c60
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityRetrieveTestITCase.java
@@ -0,0 +1,242 @@
+/*
+ * 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.v3;
+
+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 java.util.LinkedHashMap;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
+import org.apache.olingo.client.api.communication.response.ODataRawResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.op.ResourceFactory;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity retrieve operations.
+ */
+public class EntityRetrieveTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ private void withInlineEntry(final ODataPubFormat format) {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).expand("Info");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+
+ assertNotNull(entity);
+ assertEquals("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer", entity.getTypeName().toString());
+ assertEquals(getServiceRoot() + "/Customer(-10)", entity.getEditLink().toASCIIString());
+
+ assertEquals(5, entity.getNavigationLinks().size());
+ assertTrue(entity.getAssociationLinks().isEmpty());
+
+ boolean found = false;
+
+ for (ODataLink link : entity.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntity) {
+ final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
+ assertNotNull(inline);
+
+ debugEntity(client.getBinder().getEntity(
+ inline, ResourceFactory.entityClassForFormat(format == ODataPubFormat.ATOM)), "Just read");
+
+ final List<? extends CommonODataProperty> properties = inline.getProperties();
+ assertEquals(2, properties.size());
+
+ assertTrue(properties.get(0).getName().equals("CustomerInfoId")
+ || properties.get(1).getName().equals("CustomerInfoId"));
+ assertTrue(properties.get(0).getValue().toString().equals("11")
+ || properties.get(1).getValue().toString().equals("11"));
+
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+ }
+
+ @Test
+ public void withInlineEntryFromAtom() {
+ withInlineEntry(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void withInlineEntryFromJSON() {
+ // this needs to be full, otherwise there is no mean to recognize links
+ withInlineEntry(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void withInlineFeed(final ODataPubFormat format) {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+
+ boolean found = false;
+
+ for (ODataLink link : entity.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntitySet) {
+ final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
+ assertNotNull(inline);
+
+ debugEntitySet(client.getBinder().getEntitySet(inline, ResourceFactory.entitySetClassForFormat(
+ format == ODataPubFormat.ATOM)), "Just read");
+
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+ }
+
+ @Test
+ public void withInlineFeedFromAtom() {
+ withInlineFeed(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void withInlineFeedFromJSON() {
+ // this needs to be full, otherwise there is no mean to recognize links
+ withInlineFeed(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void rawRequest(final ODataPubFormat format) {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Car").appendKeySegment(16);
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertNull(entitySet);
+
+ final ResWrap<ODataEntity> entity = res.getBodyAs(ODataEntity.class);
+ assertNotNull(entity.getPayload());
+ }
+
+ @Test
+ public void rawRequestAsAtom() {
+ rawRequest(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void rawRequestAsJSON() {
+ // this needs to be full, otherwise actions will not be provided
+ rawRequest(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void multiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
+ multiKey.put("FromUsername", "1");
+ multiKey.put("MessageId", -10);
+
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Message").appendKeySegment(multiKey);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertEquals("1", entity.getProperty("FromUsername").getPrimitiveValue().toCastValue(String.class));
+ }
+
+ @Test
+ public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
+ multiKey(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
+ multiKey(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void checkForETagAsATOM() {
+ checkForETag(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void checkForETagAsJSON() {
+ checkForETag(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void checkForETag(final ODataPubFormat format) {
+ final CommonURIBuilder<?> uriBuilder =
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Product").appendKeySegment(-10);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final String etag = res.getETag();
+ assertTrue(StringUtils.isNotBlank(etag));
+
+ final CommonODataEntity product = res.getBody();
+ assertEquals(etag, product.getETag());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void issue99() {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Car");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ // this statement should cause an IllegalArgumentException bearing JsonParseException
+ // since we are attempting to parse an EntitySet as if it was an Entity
+ req.execute().getBody();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
new file mode 100644
index 0000000..6bcd248
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntitySetTestITCase.java
@@ -0,0 +1,176 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
+import org.apache.olingo.client.api.communication.response.ODataRawResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.op.ResourceFactory;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check basic feed operations.
+ */
+public class EntitySetTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ @Test
+ public void rawRequestAsAtom() throws IOException {
+ rawRequest(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void rawRequestAsJSON() throws IOException {
+ rawRequest(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void readWithInlineCountAsJSON() throws IOException {
+ readWithInlineCount(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void readWithInlineCountAsAtom() throws IOException {
+ readWithInlineCount(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromAtom() {
+ readODataEntitySetIterator(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSON() {
+ readODataEntitySetIterator(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSONFullMeta() {
+ readODataEntitySetIterator(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSONNoMeta() {
+ readODataEntitySetIterator(ODataPubFormat.JSON_NO_METADATA);
+ }
+
+ @Test
+ public void readODataEntitySetWithNextFromAtom() {
+ readEntitySetWithNextLink(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readODataEntitySetWithNextFromJSON() {
+ readEntitySetWithNextLink(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void readEntitySetWithNextLink(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer");
+
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ final ODataEntitySet feed = res.getBody();
+
+ assertNotNull(feed);
+
+ debugEntitySet(client.getBinder().getEntitySet(feed, ResourceFactory.entitySetClassForFormat(
+ ODataPubFormat.ATOM == format)), "Just retrieved feed");
+
+ assertEquals(2, feed.getEntities().size());
+ assertNotNull(feed.getNext());
+
+ final URI expected = URI.create(getServiceRoot() + "/Customer?$skiptoken=-9");
+ final URI found = URIUtils.getURI(getServiceRoot(), feed.getNext().toASCIIString());
+
+ assertEquals(expected, found);
+ }
+
+ private void readODataEntitySetIterator(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer");
+
+ final ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> req =
+ client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySetIterator<ODataEntitySet, ODataEntity>> res = req.execute();
+ final ODataEntitySetIterator<ODataEntitySet, ODataEntity> feedIterator = res.getBody();
+
+ assertNotNull(feedIterator);
+
+ int count = 0;
+
+ while (feedIterator.hasNext()) {
+ assertNotNull(feedIterator.next());
+ count++;
+ }
+ assertEquals(2, count);
+ assertTrue(feedIterator.getNext().toASCIIString().endsWith("Customer?$skiptoken=-9"));
+ }
+
+ private void readWithInlineCount(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Product").inlineCount(URIBuilder.InlineCount.allpages);
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertEquals(10, entitySet.getPayload().getCount());
+ }
+
+ private void rawRequest(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Car");
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertNotNull(entitySet.getPayload());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/EntityUpdateTestITCase.java
new file mode 100644
index 0000000..3e78f60
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/EntityUpdateTestITCase.java
@@ -0,0 +1,242 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.net.URI;
+import java.util.LinkedHashMap;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.header.HeaderName;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity update operations.
+ */
+public class EntityUpdateTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ @Test
+ public void mergeAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+ final String etag = getETag(uri);
+ final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ merge.setEditLink(uri);
+ updateEntityDescription(format, merge, UpdateType.MERGE, etag);
+ }
+
+ @Test
+ public void mergeAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+ final String etag = getETag(uri);
+ final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ merge.setEditLink(uri);
+ updateEntityDescription(format, merge, UpdateType.MERGE, etag);
+ }
+
+ @Test
+ public void patchAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+ final String etag = getETag(uri);
+ final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ patch.setEditLink(uri);
+ updateEntityDescription(format, patch, UpdateType.PATCH, etag);
+ }
+
+ @Test
+ public void patchAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+ final String etag = getETag(uri);
+ final ODataEntity patch = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ patch.setEditLink(uri);
+ updateEntityDescription(format, patch, UpdateType.PATCH, etag);
+ }
+
+ @Test
+ public void replaceAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Car").appendKeySegment(14).build());
+ updateEntityDescription(format, changes, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void replaceAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final ODataEntity changes = read(format, client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Car").appendKeySegment(14).build());
+ updateEntityDescription(format, changes, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void patchLinkAsAtom() throws EdmPrimitiveTypeException {
+ patchLink(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void patchLinkAsJSON() throws EdmPrimitiveTypeException {
+ patchLink(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ public void patchLink(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).build();
+
+ final ODataEntity patch = client.getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
+ patch.setEditLink(uri);
+
+ // ---------------------------------------
+ // Update to CustomerInfo(12)
+ // ---------------------------------------
+ URI customerInfoURI = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("CustomerInfo").appendKeySegment(12).build();
+
+ patch.addLink(client.getObjectFactory().newEntityNavigationLink("Info", customerInfoURI));
+
+ update(UpdateType.PATCH, patch, format, null);
+
+ customerInfoURI = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).appendNavigationSegment("Info").build();
+
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(customerInfoURI);
+ req.setFormat(format);
+
+ ODataEntity newInfo = req.execute().getBody();
+
+ assertEquals(Integer.valueOf(12),
+ newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
+ // ---------------------------------------
+
+ // ---------------------------------------
+ // Restore to CustomerInfo(11)
+ // ---------------------------------------
+ patch.getNavigationLinks().clear();
+
+ customerInfoURI = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("CustomerInfo").appendKeySegment(11).build();
+ read(format, customerInfoURI);
+
+ patch.addLink(client.getObjectFactory().newEntityNavigationLink("Info", customerInfoURI));
+
+ update(UpdateType.PATCH, patch, format, null);
+
+ customerInfoURI = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).appendNavigationSegment("Info").build();
+
+ req = client.getRetrieveRequestFactory().getEntityRequest(customerInfoURI);
+ req.setFormat(format);
+
+ newInfo = req.execute().getBody();
+
+ assertEquals(Integer.valueOf(11),
+ newInfo.getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
+ // ---------------------------------------
+ }
+
+ private ODataEntityUpdateRequest<ODataEntity> buildMultiKeyUpdateReq(final ODataPubFormat format)
+ throws EdmPrimitiveTypeException {
+
+ final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
+ multiKey.put("FromUsername", "1");
+ multiKey.put("MessageId", -10);
+ final ODataEntity message = read(format, client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Message").appendKeySegment(multiKey).build());
+ message.getAssociationLinks().clear();
+ message.getNavigationLinks().clear();
+
+ final boolean before = message.getProperty("IsRead").getPrimitiveValue().toCastValue(Boolean.class);
+ message.getProperties().remove(message.getProperty("IsRead"));
+ getClient().getBinder().add(message,
+ client.getObjectFactory().newPrimitiveProperty("IsRead",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildBoolean(!before)));
+
+ return client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, message);
+ }
+
+ private void mergeMultiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final ODataEntityUpdateResponse<ODataEntity> res = buildMultiKeyUpdateReq(format).execute();
+ assertEquals(204, res.getStatusCode());
+ }
+
+ @Test
+ public void mergeMultiKeyAsAtom() throws EdmPrimitiveTypeException {
+ mergeMultiKey(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void mergeMultiKeyAsJSON() throws EdmPrimitiveTypeException {
+ mergeMultiKey(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void updateReturnContent() throws EdmPrimitiveTypeException {
+ final ODataEntityUpdateRequest<ODataEntity> req =
+ buildMultiKeyUpdateReq(client.getConfiguration().getDefaultPubFormat());
+ req.setPrefer(client.newPreferences().returnContent());
+
+ final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ assertEquals(client.newPreferences().returnContent(),
+ res.getHeader(HeaderName.preferenceApplied).iterator().next());
+ assertNotNull(res.getBody());
+ }
+
+ @Test
+ public void concurrentModification() {
+ final URI uri = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+ String etag = getETag(uri);
+ final ODataEntity product = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ product.setEditLink(uri);
+ updateEntityStringProperty("BaseConcurrency",
+ client.getConfiguration().getDefaultPubFormat(), product, UpdateType.MERGE, etag);
+
+ try {
+ etag += "-invalidone";
+ updateEntityStringProperty("BaseConcurrency",
+ client.getConfiguration().getDefaultPubFormat(), product, UpdateType.MERGE, etag);
+ fail();
+ } catch (ODataClientErrorException e) {
+ assertEquals(412, e.getStatusLine().getStatusCode());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java
new file mode 100644
index 0000000..21fb8f8
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/ErrorTestITCase.java
@@ -0,0 +1,172 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.fail;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.URI;
+import org.apache.http.HttpResponse;
+import org.apache.http.client.HttpClient;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
+import org.apache.olingo.client.api.http.HttpMethod;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.api.v3.ODataClient;
+import org.apache.olingo.client.core.communication.request.AbstractODataBasicRequest;
+import org.apache.olingo.client.core.communication.response.AbstractODataResponse;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check basic entity operations.
+ */
+public class ErrorTestITCase extends AbstractTestITCase {
+
+ private class ErrorGeneratingRequest
+ extends AbstractODataBasicRequest<ODataEntityCreateResponse<ODataEntity>, ODataPubFormat> {
+
+ public ErrorGeneratingRequest(final HttpMethod method, final URI uri) {
+ super(client, ODataPubFormat.class, method, uri);
+ }
+
+ @Override
+ protected InputStream getPayload() {
+ return new ByteArrayInputStream(new byte[0]);
+ }
+
+ @Override
+ public ODataEntityCreateResponse<ODataEntity> execute() {
+ final HttpResponse res = doExecute();
+ return new ErrorResponseImpl(client, httpClient, res);
+ }
+
+ private class ErrorResponseImpl extends AbstractODataResponse implements ODataEntityCreateResponse<ODataEntity> {
+
+ private final ODataClient odataClient;
+
+ public ErrorResponseImpl(final ODataClient odataClient, final HttpClient client, final HttpResponse res) {
+ super(client, res);
+ this.odataClient = odataClient;
+ }
+
+ @Override
+ public ODataEntity getBody() {
+ return odataClient.getObjectFactory().newEntity(new FullQualifiedName("Invalid.Invalid"));
+ }
+ }
+ }
+
+ private void stacktraceError(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("Customer");
+
+ final ErrorGeneratingRequest errorReq = new ErrorGeneratingRequest(HttpMethod.POST, uriBuilder.build());
+ errorReq.setFormat(format);
+
+ try {
+ errorReq.execute();
+ fail();
+ } catch (ODataClientErrorException e) {
+ LOG.error("ODataClientErrorException found", e);
+ assertEquals(400, e.getStatusLine().getStatusCode());
+ assertNotNull(e.getODataError());
+ }
+ }
+
+ @Test
+ public void xmlStacktraceError() {
+ stacktraceError(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonStacktraceError() {
+ stacktraceError(ODataPubFormat.JSON);
+ }
+
+ private void notfoundError(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("Customer(154)");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ try {
+ req.execute();
+ fail();
+ } catch (ODataClientErrorException e) {
+ LOG.error("ODataClientErrorException found", e);
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ assertNull(e.getCause());
+ assertNotNull(e.getODataError());
+ }
+ }
+
+ @Test
+ public void xmlNotfoundError() {
+ notfoundError(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonNotfoundError() {
+ notfoundError(ODataPubFormat.JSON);
+ }
+
+ private void instreamError(final ODataPubFormat format) {
+ final Edm metadata =
+ client.getRetrieveRequestFactory().getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(metadata);
+
+ final EdmEntityContainer container = metadata.getSchemas().get(0).getEntityContainer();
+ final EdmFunctionImport funcImp = container.getFunctionImport("InStreamErrorGetCustomer");
+ final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
+ final ODataInvokeRequest<ODataEntitySet> req =
+ client.getInvokeRequestFactory().getInvokeRequest(builder.build(), funcImp.getUnboundFunction(null));
+ req.setFormat(format);
+
+ final ODataInvokeResponse<ODataEntitySet> res = req.execute();
+ res.getBody();
+ fail("Shouldn't get here");
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void atomInstreamError() {
+ instreamError(ODataPubFormat.ATOM);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void jsonInstreamError() {
+ instreamError(ODataPubFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/FilterFactoryTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/FilterFactoryTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/FilterFactoryTestITCase.java
new file mode 100644
index 0000000..2b447ad
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/FilterFactoryTestITCase.java
@@ -0,0 +1,167 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.client.api.uri.URIFilter;
+import org.apache.olingo.client.api.uri.v3.FilterArgFactory;
+import org.apache.olingo.client.api.uri.v3.FilterFactory;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.junit.Test;
+
+public class FilterFactoryTestITCase extends AbstractTestITCase {
+
+ private FilterFactory getFilterFactory() {
+ return getClient().getFilterFactory();
+ }
+
+ private FilterArgFactory getFilterArgFactory() {
+ return getFilterFactory().getArgFactory();
+ }
+
+ private void match(final String entitySet, final URIFilter filter, final int expected) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment(entitySet).filter(filter);
+
+ final CommonODataEntitySet feed = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).
+ execute().getBody();
+ assertNotNull(feed);
+ assertEquals(expected, feed.getEntities().size());
+ }
+
+ @Test
+ public void simple() {
+ match("Car", getFilterFactory().lt("VIN", 16), 5);
+ }
+
+ @Test
+ public void and() {
+ final URIFilter filter =
+ getFilterFactory().and(
+ getFilterFactory().lt("VIN", 16),
+ getFilterFactory().gt("VIN", 12));
+
+ match("Car", filter, 3);
+ }
+
+ @Test
+ public void not() {
+ final URIFilter filter =
+ getFilterFactory().not(
+ getFilterFactory().or(
+ getFilterFactory().ge("VIN", 16),
+ getFilterFactory().le("VIN", 12)));
+
+ match("Car", filter, 3);
+ }
+
+ @Test
+ public void operator() {
+ URIFilter filter =
+ getFilterFactory().eq(
+ getFilterArgFactory().add(getFilterArgFactory().property("VIN"), getFilterArgFactory().
+ literal(1)),
+ getFilterArgFactory().literal(16));
+
+ match("Car", filter, 1);
+
+ filter =
+ getFilterFactory().eq(
+ getFilterArgFactory().add(getFilterArgFactory().literal(1), getFilterArgFactory().
+ property("VIN")),
+ getFilterArgFactory().literal(16));
+
+ match("Car", filter, 1);
+
+ filter =
+ getFilterFactory().eq(
+ getFilterArgFactory().literal(16),
+ getFilterArgFactory().add(getFilterArgFactory().literal(1), getFilterArgFactory().
+ property("VIN")));
+
+ match("Car", filter, 1);
+ }
+
+ @Test
+ public void function() {
+ final URIFilter filter =
+ getFilterFactory().match(
+ getFilterArgFactory().startswith(
+ getFilterArgFactory().property("Description"), getFilterArgFactory().literal("cen")));
+
+ match("Car", filter, 1);
+ }
+
+ @Test
+ public void composed() {
+ final URIFilter filter =
+ getFilterFactory().gt(
+ getFilterArgFactory().length(getFilterArgFactory().property("Description")),
+ getFilterArgFactory().add(getFilterArgFactory().property("VIN"), getFilterArgFactory().literal(
+ 10)));
+
+ match("Car", filter, 5);
+ }
+
+ @Test
+ public void propertyPath() {
+ URIFilter filter =
+ getFilterFactory().eq(
+ getFilterArgFactory().indexof(
+ getFilterArgFactory().property("PrimaryContactInfo/HomePhone/PhoneNumber"),
+ getFilterArgFactory().literal("ODataJClient")),
+ getFilterArgFactory().literal(1));
+
+ match("Customer", filter, 0);
+
+ filter =
+ getFilterFactory().ne(
+ getFilterArgFactory().indexof(
+ getFilterArgFactory().property("PrimaryContactInfo/HomePhone/PhoneNumber"),
+ getFilterArgFactory().literal("lccvussrv")),
+ getFilterArgFactory().literal(-1));
+
+ match("Customer", filter, 2);
+ }
+
+ @Test
+ public void datetime() {
+ final URIFilter filter =
+ getFilterFactory().eq(
+ getFilterArgFactory().month(
+ getFilterArgFactory().property("PurchaseDate")),
+ getFilterArgFactory().literal(12));
+
+ match("ComputerDetail", filter, 1);
+ }
+
+ @Test
+ public void isof() {
+ final URIFilter filter =
+ getFilterFactory().match(
+ getFilterArgFactory().isof(
+ getFilterArgFactory().literal(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee")));
+
+ match("Person", filter, 4);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/FilterTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/FilterTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/FilterTestITCase.java
new file mode 100644
index 0000000..7d3bbdb
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/FilterTestITCase.java
@@ -0,0 +1,94 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.junit.Test;
+
+public class FilterTestITCase extends AbstractTestITCase {
+
+ private void filterQueryTest(final String entity, final String filter, final int expected) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment(entity).filter(filter);
+ final ODataEntitySet entitySet = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).
+ execute().getBody();
+ assertNotNull(entitySet);
+ assertEquals(expected, entitySet.getEntities().size());
+ }
+
+ @Test
+ public void withId() {
+ filterQueryTest("Customer", "CustomerId eq -10", 1);
+ }
+
+ @Test
+ public void logical() {
+ filterQueryTest("Customer", "CustomerId gt -10", 2);
+ filterQueryTest("Customer", "CustomerId lt -10", 0);
+ filterQueryTest("Customer", "not endswith(Name,'Chandan')", 2);
+ filterQueryTest("Car", "VIN le 18 and VIN gt 12", 6);
+ }
+
+ @Test
+ public void arithmetic() {
+ filterQueryTest("Car", "VIN add 5 lt 11", 0);
+ filterQueryTest("Car", "VIN div 2 le 8", 7);
+ filterQueryTest("Car", "VIN mul 2 le 30", 5);
+ filterQueryTest("Person", "PersonId sub 2 lt -10", 2);
+ }
+
+ @Test
+ public void stringOperations() {
+ filterQueryTest("Product", "length(Description) eq 7", 1);
+ filterQueryTest("Product", "length(Description) eq 7", 1);
+ filterQueryTest("Product", "substringof('kdcuklu', Description) eq true", 1);
+ filterQueryTest("Product", "startswith(Description, 'k') eq true", 2);
+ filterQueryTest("Product", "startswith(Description, 'k') eq true", 2);
+ filterQueryTest("Product", "indexof(Description, 'k') eq 0", 2);
+ filterQueryTest("Product", "toupper(Description) eq 'KDCUKLU'", 1);
+ filterQueryTest("Product", "concat(Description, ', newname') eq 'kdcuklu, newname'", 1);
+ }
+
+ @Test
+ public void math() {
+ filterQueryTest("Product", "round(Dimensions/Width) eq 7338", 1);
+ filterQueryTest("Product", "round(Dimensions/Width) eq 7338", 1);
+ filterQueryTest("Product", "floor(Dimensions/Width) eq 7337", 1);
+ filterQueryTest("Product", "ceiling(Dimensions/Width) eq 7338", 1);
+ }
+
+ @Test
+ public void date() {
+ filterQueryTest("ComputerDetail", "day(PurchaseDate) eq 15", 1);
+ filterQueryTest("ComputerDetail", "month(PurchaseDate) eq 12", 2);
+ filterQueryTest("ComputerDetail", "hour(PurchaseDate) eq 1", 1);
+ filterQueryTest("ComputerDetail", "minute(PurchaseDate) eq 33", 1);
+ filterQueryTest("ComputerDetail", "second(PurchaseDate) eq 35", 1);
+ filterQueryTest("ComputerDetail", "year(PurchaseDate) eq 2020", 1);
+ }
+
+ @Test
+ public void isOfTest() {
+ filterQueryTest("Customer", "isof(Name,'Edm.String') eq true", 2);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java
new file mode 100644
index 0000000..02edf6e
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/InvokeTestITCase.java
@@ -0,0 +1,318 @@
+/*
+ * 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.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.net.URI;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
+import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.ODataOperation;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmParameter;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.edm.EdmTypeInfo;
+import org.junit.Test;
+
+public class InvokeTestITCase extends AbstractTestITCase {
+
+ private void getWithNoParams(final ODataPubFormat format) {
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+
+ // 1. get primitive value property
+ EdmFunctionImport funcImp = container.getFunctionImport("GetPrimitiveString");
+ EdmFunction func = funcImp.getUnboundFunction(null);
+
+ URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
+
+ ODataInvokeRequest<ODataProperty> req = getClient().getInvokeRequestFactory().
+ getInvokeRequest(builder.build(), func);
+ req.setFormat(format);
+ ODataInvokeResponse<ODataProperty> res = req.execute();
+ assertNotNull(res);
+
+ ODataProperty property = res.getBody();
+ assertNotNull(property);
+ assertEquals("Foo", property.getPrimitiveValue().toString());
+
+ // 2. get collection of complex type property
+ funcImp = container.getFunctionImport("EntityProjectionReturnsCollectionOfComplexTypes");
+ func = funcImp.getUnboundFunction(null);
+
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
+
+ req = getClient().getInvokeRequestFactory().getInvokeRequest(builder.build(), func);
+ req.setFormat(format);
+ res = req.execute();
+ assertNotNull(res);
+
+ property = res.getBody();
+ assertNotNull(property);
+ assertTrue(property.hasCollectionValue());
+ assertFalse(property.getCollectionValue().isEmpty());
+ }
+
+ @Test
+ public void getWithNoParamsAsAtom() {
+ getWithNoParams(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void getWithNoParamsAsJSON() {
+ getWithNoParams(ODataPubFormat.JSON);
+ }
+
+ private void getWithParams(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ // 1. primitive result
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ EdmFunctionImport funcImp = container.getFunctionImport("GetArgumentPlusOne");
+
+ URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
+
+ EdmFunction function = funcImp.getUnboundFunction(Collections.singletonList("arg1"));
+ EdmParameter param = function.getParameter(function.getParameterNames().get(0));
+ ODataPrimitiveValue paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(param.getType()).
+ setValue(154).
+ build();
+
+ final ODataInvokeRequest<ODataProperty> primitiveReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(builder.build(), function,
+ Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
+ primitiveReq.setFormat(format);
+
+ final ODataInvokeResponse<ODataProperty> primitiveRes = primitiveReq.execute();
+ assertNotNull(primitiveRes);
+
+ final ODataProperty property = primitiveRes.getBody();
+ assertNotNull(property);
+ assertEquals(Integer.valueOf(155), property.getPrimitiveValue().toCastValue(Integer.class));
+
+ // 2. feed result
+ funcImp = container.getFunctionImport("GetSpecificCustomer");
+
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, funcImp.getName()));
+
+ function = funcImp.getUnboundFunction(Collections.singletonList("Name"));
+ param = function.getParameter(function.getParameterNames().get(0));
+ paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(param.getType()).
+ setValue(StringUtils.EMPTY).
+ build();
+
+ final ODataInvokeRequest<ODataEntitySet> feedReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(builder.build(), function,
+ Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
+ feedReq.setFormat(format);
+
+ final ODataInvokeResponse<ODataEntitySet> feedRes = feedReq.execute();
+ assertNotNull(feedRes);
+
+ final ODataEntitySet feed = feedRes.getBody();
+ assertNotNull(feed);
+
+ final Set<Integer> customerIds = new HashSet<Integer>(feed.getEntities().size());
+ for (ODataEntity entity : feed.getEntities()) {
+ customerIds.add(entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
+ }
+ assertTrue(customerIds.contains(-8));
+ }
+
+ @Test
+ public void getWithParamsAsAtom() throws EdmPrimitiveTypeException {
+ getWithParams(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void getWithParamsAsJSON() throws EdmPrimitiveTypeException {
+ getWithParams(ODataPubFormat.JSON);
+ }
+
+ private ODataEntity createEmployee(final ODataPubFormat format) {
+ final ODataEntity employee = getClient().getObjectFactory().newEntity(new FullQualifiedName(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.Employee"));
+
+ employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("PersonId",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1244)));
+ employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("Test employee")));
+ employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
+ "ManagersPersonId", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(3777)));
+ employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
+ "Salary", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1000)));
+ employee.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty(
+ "Title", getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("CEO")));
+
+ final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Person");
+
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), employee);
+ createReq.setFormat(format);
+ final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+
+ final ODataEntityRequest<ODataEntity> req =
+ getClient().getRetrieveRequestFactory().getEntityRequest(uriBuilder.appendKeySegment(1244).build());
+ return req.execute().getBody();
+ }
+
+ private void deleteEmployee(final ODataPubFormat format, final Integer id) {
+ final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Person").appendKeySegment(id);
+
+ final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(uriBuilder.build());
+ deleteReq.setFormat(format);
+ final ODataDeleteResponse deleteRes = deleteReq.execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+
+ @Test
+ public void boundPost() throws EdmPrimitiveTypeException {
+ // 0. create an employee
+ final ODataEntity created = createEmployee(ODataPubFormat.JSON_FULL_METADATA);
+ assertNotNull(created);
+ final Integer createdId = created.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class);
+ assertNotNull(createdId);
+
+ // 1. invoke action bound with the employee just created
+ final ODataOperation operation = created.getOperations().get(0);
+
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ final EdmAction action = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), operation.getTitle()),
+ created.getTypeName(), false);
+
+ final ODataInvokeRequest<ODataNoContent> req = getClient().getInvokeRequestFactory().
+ getInvokeRequest(operation.getTarget(), action);
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+ final ODataInvokeResponse<ODataNoContent> res = req.execute();
+ assertNotNull(res);
+ assertEquals(204, res.getStatusCode());
+
+ // 2. check that invoked action has effectively run
+ final URIBuilder uriBuilder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Person").appendKeySegment(createdId);
+ final ODataEntityRequest<ODataEntity> retrieveRes =
+ getClient().getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ retrieveRes.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+ final ODataEntity read = retrieveRes.execute().getBody();
+ assertEquals("0", read.getProperty("Salary").getPrimitiveValue().toString());
+ assertTrue(read.getProperty("Title").getPrimitiveValue().toString().endsWith("[Sacked]"));
+
+ // 3. remove the test employee
+ deleteEmployee(ODataPubFormat.JSON_FULL_METADATA, createdId);
+ }
+
+ @Test
+ public void boundPostWithParams() throws EdmPrimitiveTypeException {
+ // 1. read employees and store their current salary
+ final URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Person").
+ appendEntitySetSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee");
+ final URI employeesURI = builder.build();
+ ODataEntitySet employees = getClient().getRetrieveRequestFactory().
+ getEntitySetRequest(employeesURI).execute().getBody();
+ assertFalse(employees.getEntities().isEmpty());
+ final Map<Integer, Integer> preSalaries = new HashMap<Integer, Integer>(employees.getCount());
+ for (ODataEntity employee : employees.getEntities()) {
+ preSalaries.put(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class),
+ employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
+ }
+ assertFalse(preSalaries.isEmpty());
+
+ // 2. invoke action bound, with additional parameter
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+
+ final EdmTypeInfo employeesTypeInfo = new EdmTypeInfo.Builder().setEdm(edm).
+ setTypeExpression("Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.Employee)").build();
+ final EdmAction action = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), "IncreaseSalaries"),
+ employeesTypeInfo.getFullQualifiedName(), employeesTypeInfo.isCollection());
+
+ final EdmParameter param = action.getParameter(action.getParameterNames().get(1));
+ final ODataPrimitiveValue paramValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(param.getType()).
+ setValue(1).
+ build();
+
+ final ODataInvokeRequest<ODataNoContent> req = getClient().getInvokeRequestFactory().getInvokeRequest(
+ builder.appendOperationCallSegment(action.getName()).build(), action,
+ Collections.<String, ODataValue>singletonMap(param.getName(), paramValue));
+ final ODataInvokeResponse<ODataNoContent> res = req.execute();
+ assertNotNull(res);
+ assertEquals(204, res.getStatusCode());
+
+ // 3. check whether salaries were incremented
+ employees = getClient().getRetrieveRequestFactory().getEntitySetRequest(employeesURI).execute().getBody();
+ assertFalse(employees.getEntities().isEmpty());
+ for (ODataEntity employee : employees.getEntities()) {
+ assertTrue(
+ preSalaries.get(employee.getProperty("PersonId").getPrimitiveValue().toCastValue(Integer.class))
+ < employee.getProperty("Salary").getPrimitiveValue().toCastValue(Integer.class));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/KeyAsSegmentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/KeyAsSegmentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/KeyAsSegmentTestITCase.java
new file mode 100644
index 0000000..7a1bebc
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/KeyAsSegmentTestITCase.java
@@ -0,0 +1,110 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class KeyAsSegmentTestITCase extends AbstractTestITCase {
+
+ @BeforeClass
+ public static void enableKeyAsSegment() {
+ client.getConfiguration().setKeyAsSegment(true);
+ }
+
+ private void read(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testKeyAsSegmentServiceRootURL).
+ appendEntitySetSegment("Customer").appendKeySegment(-10);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+
+ assertFalse(entity.getEditLink().toASCIIString().contains("("));
+ assertFalse(entity.getEditLink().toASCIIString().contains(")"));
+ }
+
+ @Test
+ public void fromAtom() {
+ read(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void fromJSON() {
+ read(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void createODataEntityAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final int id = 1;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ createEntity(testKeyAsSegmentServiceRootURL, format, original, "Customer");
+ final ODataEntity actual = compareEntities(testKeyAsSegmentServiceRootURL, format, original, id, null);
+
+ cleanAfterCreate(format, actual, false, testKeyAsSegmentServiceRootURL);
+ }
+
+ @Test
+ public void createODataEntityAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final int id = 2;
+ final ODataEntity original = getSampleCustomerProfile(id, "Sample customer", false);
+
+ createEntity(testKeyAsSegmentServiceRootURL, format, original, "Customer");
+ final ODataEntity actual = compareEntities(testKeyAsSegmentServiceRootURL, format, original, id, null);
+
+ cleanAfterCreate(format, actual, false, testKeyAsSegmentServiceRootURL);
+ }
+
+ @Test
+ public void replaceODataEntityAsAtom() {
+ final ODataPubFormat format = ODataPubFormat.ATOM;
+ final ODataEntity changes = read(format, client.getURIBuilder(testKeyAsSegmentServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(14).build());
+ updateEntityDescription(format, changes, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void replaceODataEntityAsJSON() {
+ final ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ final ODataEntity changes = read(format, client.getURIBuilder(testKeyAsSegmentServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(14).build());
+ updateEntityDescription(format, changes, UpdateType.REPLACE);
+ }
+
+ @AfterClass
+ public static void disableKeyAsSegment() {
+ client.getConfiguration().setKeyAsSegment(false);
+ }
+}
[09/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/LinkTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/LinkTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/LinkTestITCase.java
new file mode 100644
index 0000000..5edf429
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/LinkTestITCase.java
@@ -0,0 +1,177 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Collections;
+import java.util.List;
+import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkCollectionRequest;
+import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check basic link operations.
+ */
+public class LinkTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ private ODataLinkCollection doRetrieveLinkURIs(final ODataFormat format, final String linkname) throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10);
+
+ final ODataLinkCollectionRequest req =
+ client.getRetrieveRequestFactory().getLinkCollectionRequest(uriBuilder.build(), linkname);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataLinkCollection> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ return res.getBody();
+ }
+
+ private void retrieveLinkURIs(final ODataFormat format) throws IOException {
+ final List<URI> links = doRetrieveLinkURIs(format, "Logins").getLinks();
+ assertEquals(2, links.size());
+ assertTrue(links.contains(URI.create(getServiceRoot() + "/Login('1')")));
+ assertTrue(links.contains(URI.create(getServiceRoot() + "/Login('4')")));
+ }
+
+ @Test
+ public void retrieveXMLLinkURIsWithNext() throws IOException {
+ final ODataLinkCollection uris = doRetrieveLinkURIs(ODataFormat.XML, "Orders");
+ assertEquals(2, uris.getLinks().size());
+ assertNotNull(uris.getNext());
+ }
+
+ @Test
+ public void retrieveXMLLinkURIs() throws IOException {
+ retrieveLinkURIs(ODataFormat.XML);
+ }
+
+ @Test
+ public void retrieveJSONLinkURIs() throws IOException {
+ retrieveLinkURIs(ODataFormat.JSON);
+ }
+
+ private void createLink(final ODataFormat format) throws IOException {
+ // 1. read current Logins $links (for later usage)
+ final List<URI> before = doRetrieveLinkURIs(format, "Logins").getLinks();
+ assertEquals(2, before.size());
+
+ // 2. create new link
+ final ODataLink newLink = client.getObjectFactory().
+ newAssociationLink(URI.create(getServiceRoot() + "/Login('3')"));
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).appendLinksSegment("Logins");
+
+ final ODataLinkCreateRequest req =
+ client.getCUDRequestFactory().getLinkCreateRequest(uriBuilder.build(), newLink);
+ req.setFormat(format);
+
+ final ODataLinkOperationResponse res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ final List<URI> after = doRetrieveLinkURIs(format, "Logins").getLinks();
+ assertEquals(before.size() + 1, after.size());
+
+ // 3. reset Logins $links as before this test was run
+ after.removeAll(before);
+ assertEquals(Collections.singletonList(newLink.getLink()), after);
+
+ assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
+ client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").
+ appendKeySegment(-10).appendLinksSegment("Logins('3')").build()).execute().getStatusCode());
+ }
+
+ @Test
+ public void createXMLLink() throws IOException {
+ createLink(ODataFormat.XML);
+ }
+
+ @Test
+ public void createJSONLink() throws IOException {
+ createLink(ODataFormat.JSON);
+ }
+
+ private void updateLink(final ODataFormat format, final UpdateType updateType) throws IOException {
+ // 1. read what is the link before the test runs
+ final URI before = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
+
+ // 2. update the link
+ ODataLink newLink = client.getObjectFactory().
+ newAssociationLink(URI.create(getServiceRoot() + "/CustomerInfo(12)"));
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-10).appendLinksSegment("Info");
+
+ ODataLinkUpdateRequest req =
+ client.getCUDRequestFactory().getLinkUpdateRequest(uriBuilder.build(), updateType, newLink);
+ req.setFormat(format);
+
+ ODataLinkOperationResponse res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ URI after = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
+ assertNotEquals(before, after);
+ assertEquals(newLink.getLink(), after);
+
+ // 3. reset back the link value
+ newLink = client.getObjectFactory().newAssociationLink(before);
+ req = client.getCUDRequestFactory().getLinkUpdateRequest(uriBuilder.build(), updateType, newLink);
+ req.setFormat(format);
+
+ res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ after = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
+ assertEquals(before, after);
+ }
+
+ @Test
+ public void updateXMLLink() throws IOException {
+ updateLink(ODataFormat.XML, UpdateType.MERGE);
+ updateLink(ODataFormat.XML, UpdateType.PATCH);
+ updateLink(ODataFormat.XML, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void updateJSONLink() throws IOException {
+ updateLink(ODataFormat.JSON, UpdateType.MERGE);
+ updateLink(ODataFormat.JSON, UpdateType.PATCH);
+ updateLink(ODataFormat.JSON, UpdateType.REPLACE);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java
new file mode 100644
index 0000000..e0bf0f2
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/MediaEntityTestITCase.java
@@ -0,0 +1,189 @@
+/*
+ * 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.v3;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
+import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
+import org.apache.olingo.client.api.communication.request.streamed.MediaEntityUpdateStreamManager;
+import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.streamed.ODataStreamUpdateRequest;
+import org.apache.olingo.client.api.communication.request.streamed.StreamUpdateStreamManager;
+import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.communication.response.ODataStreamUpdateResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataMediaFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNotNull;
+
+import org.junit.Test;
+
+public class MediaEntityTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void read() throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+ retrieveReq.setFormat(ODataMediaFormat.WILDCARD);
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ final byte[] actual = new byte[Integer.parseInt(retrieveRes.getHeader("Content-Length").iterator().next())];
+ IOUtils.read(retrieveRes.getBody(), actual, 0, actual.length);
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void readWithXmlError() throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+ retrieveReq.setFormat(ODataMediaFormat.APPLICATION_XML);
+
+ retrieveReq.execute();
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void readWithJsonError() throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+ retrieveReq.setFormat(ODataMediaFormat.APPLICATION_JSON);
+
+ retrieveReq.execute();
+ }
+
+ @Test
+ public void updateMediaEntityAsAtom() throws Exception {
+ updateMediaEntity(ODataPubFormat.ATOM, 14);
+ }
+
+ @Test
+ public void updateMediaEntityAsJson() throws Exception {
+ updateMediaEntity(ODataPubFormat.JSON, 15);
+ }
+
+ @Test
+ public void createMediaEntityAsAtom() throws Exception {
+ createMediaEntity(ODataPubFormat.ATOM, IOUtils.toInputStream("buffered stream sample"));
+ }
+
+ @Test
+ public void createMediaEntityAsJson() throws Exception {
+ createMediaEntity(ODataPubFormat.JSON, IOUtils.toInputStream("buffered stream sample"));
+ }
+
+ @Test
+ public void issue137() throws Exception {
+ createMediaEntity(ODataPubFormat.JSON, this.getClass().getResourceAsStream("/sample.png"));
+ }
+
+ @Test
+ public void updateNamedStream() throws Exception {
+ URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(16).appendNavigationSegment("Photo");
+
+ final String TO_BE_UPDATED = "buffered stream sample";
+ final InputStream input = new ByteArrayInputStream(TO_BE_UPDATED.getBytes());
+
+ final ODataStreamUpdateRequest updateReq =
+ client.getStreamedRequestFactory().getStreamUpdateRequest(builder.build(), input);
+
+ final StreamUpdateStreamManager streamManager = updateReq.execute();
+ final ODataStreamUpdateResponse updateRes = streamManager.getResponse();
+ updateRes.close();
+ assertEquals(204, updateRes.getStatusCode());
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+ assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
+ }
+
+ private void updateMediaEntity(final ODataPubFormat format, final int id) throws Exception {
+ URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
+
+ final String TO_BE_UPDATED = "new buffered stream sample";
+ final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
+
+ final ODataMediaEntityUpdateRequest<ODataEntity> updateReq =
+ client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input);
+ updateReq.setFormat(format);
+
+ final MediaEntityUpdateStreamManager<ODataEntity> streamManager = updateReq.execute();
+ final ODataMediaEntityUpdateResponse<ODataEntity> updateRes = streamManager.getResponse();
+ assertEquals(204, updateRes.getStatusCode());
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+ assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
+ }
+
+ private void createMediaEntity(final ODataPubFormat format, final InputStream input) throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car");
+
+ final ODataMediaEntityCreateRequest<ODataEntity> createReq =
+ client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
+ createReq.setFormat(format);
+
+ final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute();
+ final ODataMediaEntityCreateResponse<ODataEntity> createRes = streamManager.getResponse();
+ assertEquals(201, createRes.getStatusCode());
+
+ final ODataEntity created = createRes.getBody();
+ assertNotNull(created);
+ assertEquals(2, created.getProperties().size());
+
+ Integer id = null;
+ for (ODataProperty prop : created.getProperties()) {
+ if ("VIN".equals(prop.getName())) {
+ id = prop.getPrimitiveValue().toCastValue(Integer.class);
+ }
+ }
+ assertNotNull(id);
+
+ builder.appendKeySegment(id).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+ assertNotNull(retrieveRes.getBody());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/MetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/MetadataTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/MetadataTestITCase.java
new file mode 100644
index 0000000..d535ad1
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/MetadataTestITCase.java
@@ -0,0 +1,41 @@
+/*
+ * 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.v3;
+
+import org.apache.olingo.client.api.v3.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.fit.AbstractMetadataTestITCase;
+import org.apache.olingo.commons.api.edm.Edm;
+import static org.junit.Assert.assertNotNull;
+import org.junit.Test;
+
+public class MetadataTestITCase extends AbstractMetadataTestITCase {
+
+ @Override
+ protected ODataClient getClient() {
+ return ODataClientFactory.getV3();
+ }
+
+ @Test
+ public void retrieve() {
+ final Edm metadata = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(getTestServiceRoot()).execute().getBody();
+ assertNotNull(metadata);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
new file mode 100644
index 0000000..9b0ce9d
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/OpenTypeTestITCase.java
@@ -0,0 +1,178 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.UUID;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmSchema;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class OpenTypeTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void checkOpenTypeEntityTypesExist() {
+ final Edm metadata = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
+
+ final EdmSchema schema = metadata.getSchemas().get(0);
+
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "Row")).isOpenType());
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "IndexedRow")).isOpenType());
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
+ }
+
+ private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
+ final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
+ return read(format, builder.build());
+ }
+
+ private void read(final ODataPubFormat format) {
+ ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
+ assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
+
+ row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
+ assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
+ }
+
+ @Test
+ public void readAsAtom() {
+ read(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readAsJSON() {
+ read(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void cud(final ODataPubFormat format) {
+ final Integer id = 1426;
+
+ ODataEntity rowIndex = getClient().getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesService.RowIndex"));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("Id",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aString",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aBoolean",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(true)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aDouble",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.5D)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aByte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
+ build()));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTime).setValue(Calendar.getInstance()).
+ build()));
+
+ final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
+ "Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTime).setText("2001-04-05T05:05:04.001").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Time).setText("-P9DT51M10.5063807S").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("SignedByte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Double",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(Double.MAX_VALUE)));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Single",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(Float.MAX_VALUE)));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Short",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Int",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(Integer.MAX_VALUE)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newComplexProperty("aContact", contactDetails));
+
+ final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
+ getEntityCreateRequest(getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("RowIndex").build(), rowIndex);
+ createReq.setFormat(format);
+ final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+
+ final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("RowIndex").appendKeySegment(id);
+ rowIndex = read(format, builder.build());
+ assertNotNull(rowIndex);
+ assertEquals(EdmPrimitiveTypeKind.Int32,
+ rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.String,
+ rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Boolean,
+ rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
+ assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue());
+ assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue());
+ assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue());
+ assertTrue(rowIndex.getProperty("aContact").hasComplexValue());
+ assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue());
+
+ final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
+ getDeleteRequest(rowIndex.getEditLink()).execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+
+ @Test
+ public void cudAsAtom() {
+ cud(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void cudAsJSON() {
+ cud(ODataPubFormat.JSON_FULL_METADATA);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/PrimitiveKeysTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PrimitiveKeysTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PrimitiveKeysTestITCase.java
new file mode 100644
index 0000000..079439b
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PrimitiveKeysTestITCase.java
@@ -0,0 +1,70 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.math.BigDecimal;
+import java.util.UUID;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+
+import org.junit.Test;
+
+public class PrimitiveKeysTestITCase extends AbstractTestITCase {
+
+ private void readEntity(final String entityType, final Object key, final ODataPubFormat format) {
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment(entityType).
+ appendKeySegment(key).
+ build());
+ req.setFormat(format);
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertNotNull(entity.getProperty("Id"));
+ }
+
+ private void readPrimitiveKeys(final ODataPubFormat format) {
+ readEntity("EdmBooleanSet", Boolean.TRUE, format);
+ readEntity("EdmByteSet", 255, format);
+ readEntity("EdmDecimalSet", new BigDecimal("79228162514264337593543950335"), format);
+ readEntity("EdmDoubleSet", 1.7976931348623157E+308D, format);
+ readEntity("EdmSingleSet", 3.4028235E+38F, format);
+ readEntity("EdmGuidSet", UUID.fromString("00000000-0000-0000-0000-000000000000"), format);
+ readEntity("EdmInt16Set", 32767, format);
+ readEntity("EdmInt32Set", -2147483648, format);
+ readEntity("EdmInt64Set", 9223372036854775807L, format);
+ readEntity("EdmStringSet", "$", format);
+ }
+
+ @Test
+ public void readEntityAsAtom() {
+ readPrimitiveKeys(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readEntityAsJSON() {
+ readPrimitiveKeys(ODataPubFormat.JSON_FULL_METADATA);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
new file mode 100644
index 0000000..7e67e54
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyRetrieveTestITCase.java
@@ -0,0 +1,281 @@
+/*
+ * 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.v3;
+
+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;
+
+import java.util.List;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Test;
+
+public class PropertyRetrieveTestITCase extends AbstractTestITCase {
+
+ private void retrievePropertyTest(final ODataFormat format, String entitySegment, String structuralSegment) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment(entitySegment).appendPropertySegment(structuralSegment);
+ final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ req.setFormat(format);
+ try {
+ final ODataProperty property = req.execute().getBody();
+ assertNotNull(property);
+ if (property.hasNullValue()) {
+ assertNull(property.getValue());
+ } else if (property.hasPrimitiveValue()) {
+ final ODataPrimitiveValue value = property.getPrimitiveValue();
+ assertTrue(value.isPrimitive());
+ } else if (property.hasComplexValue()) {
+ final ODataComplexValue value = property.getComplexValue();
+ assertTrue(value.isComplex());
+ } else if (property.hasCollectionValue()) {
+ final ODataCollectionValue value = property.getCollectionValue();
+ assertTrue(value.isCollection());
+ }
+ } catch (ODataClientErrorException e) {
+ if (e.getStatusLine().getStatusCode() != 404 && e.getStatusLine().getStatusCode() != 400) {
+ fail(e.getMessage());
+ }
+ }
+ }
+ //test with json header
+
+ @Test
+ public void jsonRetrieveProperty() {
+ //Primitive types
+ retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.JSON, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.JSON, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retrievePropertyTest(ODataFormat.JSON, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //complex types
+ retrievePropertyTest(ODataFormat.JSON, "Order(-9)", "Concurrency");
+ }
+ //test with json full metadata
+
+ @Test
+ public void jsonFullMetadataRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Order(-9)", "Concurrency");
+ }
+ // json with no metadata
+
+ @Test
+ public void jsonNoMetadataRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "BackupContactInfo");
+ //Collection of Primitives
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Order(-9)", "Concurrency");
+
+ }
+ // json with minimla metadata
+
+ @Test
+ public void jsonmininalRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of complex types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Order(-9)", "Concurrency");
+ }
+ // with xml header
+
+ @Test
+ public void xmlRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retrievePropertyTest(ODataFormat.XML, "Order(-9)", "Concurrency");
+ }
+ // with atom header
+
+ @Test
+ public void atomRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "Name");
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "CustomerId");
+ retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retrievePropertyTest(ODataFormat.XML, "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //complex types
+ retrievePropertyTest(ODataFormat.XML, "Order(-9)", "Concurrency");
+ }
+ // with invalid structural segment
+
+ @Test
+ public void invalidSegmentRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.XML, "Customers(-10)", "Name");
+
+ }
+ // with null pub format
+
+ @Test
+ public void nullSegmentRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(null, "Customers(-10)", "Name");
+
+ }
+ // with null accept header format
+
+ @Test
+ public void nullAcceptRetrieveProperty() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.XML, "Customers(-10)", "Name");
+
+ }
+ // with json pub format and atom accept format
+
+ @Test
+ public void differentFormatAndAcceptRetrieveProperty() {
+ //
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customers(-10)", "Name");
+
+ }
+ //bad request 400 error. Message takes two keys
+
+ @Test
+ public void badRequestTest() {
+ //primitive types
+ retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1')", "Sent");
+ }
+ //navigation link of stream
+
+ @Test
+ public void navigationMediaLink() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/json");
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ final ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ final List<? extends CommonODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)",
+ entity.get(0).getProperties().get(0).getValue().toString());
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)",
+ entity.get(1).getProperties().get(0).getValue().toString());
+ for (int i = 0; i < entity.size(); i++) {
+ assertNotNull(entity.get(0).getProperties().get(0).getValue());
+ }
+ }
+ //navigation link of stream, Bad Request(404 error). 'Photo' is not a valid navigation link
+
+ @Test
+ public void navigationMediaLinkInvalidQuery() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photo");
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/json");
+ try {
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ final List<? extends CommonODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
+ getProperties().get(0).getValue().toString());
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
+ getProperties().get(0).getValue().toString());
+ } catch (ODataClientErrorException e) {
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ }
+ }
+
+ @Test
+ public void navigationMediaLinkInvalidFormat() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/atom+xml");
+ try {
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ final ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ final List<ODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
+ getProperties().get(0).getValue().toString());
+ assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
+ getProperties().get(0).getValue().toString());
+ } catch (ODataClientErrorException e) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
new file mode 100644
index 0000000..c46efc0
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyTestITCase.java
@@ -0,0 +1,360 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataValueUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRawResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.communication.response.ODataValueUpdateResponse;
+import org.apache.olingo.client.api.http.HttpMethod;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataValueFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check basic entity operations.
+ */
+public class PropertyTestITCase extends AbstractTestITCase {
+
+ protected String getServiceRoot() {
+ return testStaticServiceRootURL;
+ }
+
+ @Test
+ public void replacePropertyValue() throws Exception {
+ updatePropertyValue(ODataValueFormat.TEXT, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void replacePrimitivePropertyAsXML() throws IOException, EdmPrimitiveTypeException {
+ updatePrimitiveProperty(ODataFormat.XML);
+ }
+
+ @Test
+ public void replacePrimitivePropertyAsJSON() throws IOException, EdmPrimitiveTypeException {
+ updatePrimitiveProperty(ODataFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void replaceCollectionPropertyAsXML() throws IOException {
+ updateCollectionProperty(ODataFormat.XML);
+ }
+
+ @Test
+ public void replaceCollectionPropertyAsJSON() throws IOException {
+ updateCollectionProperty(ODataFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void replaceComplexPropertyAsXML() throws IOException {
+ updateComplexProperty(ODataFormat.XML, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void replaceComplexPropertyAsJSON() throws IOException {
+ updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.REPLACE);
+ }
+
+ @Test
+ public void patchComplexPropertyAsXML() throws IOException {
+ updateComplexProperty(ODataFormat.XML, UpdateType.PATCH);
+ }
+
+ @Test
+ public void patchComplexPropertyAsJSON() throws IOException {
+ updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH);
+ }
+
+ @Test
+ public void mergeComplexPropertyAsXML() throws IOException {
+ updateComplexProperty(ODataFormat.XML, UpdateType.MERGE);
+ }
+
+ @Test
+ public void mergeComplexPropertyAsJSON() throws IOException {
+ updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.MERGE);
+ }
+
+ @Test
+ public void rawRequestAsXML() throws IOException {
+ rawRequest(ODataFormat.XML);
+ }
+
+ @Test
+ public void rawRequestAsJSON() throws IOException {
+ rawRequest(ODataFormat.JSON);
+ }
+
+ @Test
+ public void readCountValue() throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").count();
+
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+
+ final ODataRetrieveResponse<ODataPrimitiveValue> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataPrimitiveValue value = res.getBody();
+ debugODataValue(value, "Retrieved property");
+
+ assertNotNull(value);
+ // the following assert depends on the test execution order (use >= to be sure)
+ assertTrue(Integer.valueOf(value.toString()) >= 10);
+ }
+
+ @Test
+ public void nullNullableProperty() {
+ final ODataDeleteResponse res = client.getCUDRequestFactory().getDeleteRequest(client.getURIBuilder(
+ getServiceRoot()).
+ appendEntitySetSegment("Order").appendKeySegment(-8).
+ appendPropertySegment("CustomerId").appendValueSegment().build()).
+ execute();
+ assertEquals(204, res.getStatusCode());
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void nullNonNullableProperty() {
+ client.getCUDRequestFactory().getDeleteRequest(client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Driver").appendKeySegment("1").
+ appendPropertySegment("BirthDate").appendValueSegment().build()).
+ execute();
+ }
+
+ private void updatePropertyValue(final ODataValueFormat format, final UpdateType type)
+ throws IOException, EdmPrimitiveTypeException {
+
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-9).
+ appendPropertySegment("PrimaryContactInfo").
+ appendPropertySegment("HomePhone").
+ appendPropertySegment("PhoneNumber").
+ appendValueSegment();
+
+ ODataValueRequest retrieveReq = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ ODataRetrieveResponse<ODataPrimitiveValue> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ ODataPrimitiveValue phoneNumber = retrieveRes.getBody();
+ assertNotNull(phoneNumber);
+
+ final String oldMsg = phoneNumber.toCastValue(String.class);
+ final String newMsg = "new msg (" + System.currentTimeMillis() + ")";
+
+ assertNotEquals(newMsg, oldMsg);
+
+ final ODataPrimitiveValue newVal = client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build();
+
+ final ODataValueUpdateRequest updateReq =
+ client.getCUDRequestFactory().getValueUpdateRequest(uriBuilder.build(), type, newVal);
+ updateReq.setFormat(format);
+
+ final ODataValueUpdateResponse updateRes = updateReq.execute();
+ assertEquals(204, updateRes.getStatusCode());
+
+ retrieveReq = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ phoneNumber = retrieveRes.getBody();
+ assertNotNull(phoneNumber);
+
+ assertEquals(newMsg, phoneNumber.asPrimitive().toCastValue(String.class));
+ }
+
+ private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-9).appendPropertySegment("PrimaryContactInfo");
+
+ ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ ODataProperty primaryContactInfo = client.getObjectFactory().
+ newComplexProperty("PrimaryContactInfo", retrieveRes.getBody().getComplexValue());
+
+ final String newItem = "new item " + System.currentTimeMillis();
+
+ final ODataCollectionValue<ODataValue> originalValue =
+ primaryContactInfo.getComplexValue().get("EmailBag").getCollectionValue();
+
+ final int origSize = originalValue.size();
+
+ originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
+ assertEquals(origSize + 1, originalValue.size());
+
+ final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
+ getPropertyComplexValueUpdateRequest(uriBuilder.build(), type, primaryContactInfo);
+ if (client.getConfiguration().isUseXHTTPMethod()) {
+ assertEquals(HttpMethod.POST, updateReq.getMethod());
+ } else {
+ assertEquals(type.getMethod(), updateReq.getMethod());
+ }
+ updateReq.setFormat(format);
+
+ final ODataPropertyUpdateResponse updateRes = updateReq.execute();
+ assertEquals(204, updateRes.getStatusCode());
+
+ retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ primaryContactInfo = retrieveRes.getBody();
+
+ assertEquals(origSize + 1, primaryContactInfo.getComplexValue().get("EmailBag").getCollectionValue().size());
+ }
+
+ private void updateCollectionProperty(final ODataFormat format) throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-10).
+ appendPropertySegment("PrimaryContactInfo").appendPropertySegment("AlternativeNames");
+
+ ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ ODataProperty alternativeNames = client.getObjectFactory().newCollectionProperty("AlternativeNames",
+ retrieveRes.getBody().getCollectionValue());
+
+ final String newItem = "new item " + System.currentTimeMillis();
+
+ final ODataCollectionValue<ODataValue> originalValue = alternativeNames.getCollectionValue();
+
+ final int origSize = originalValue.size();
+
+ originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
+ assertEquals(origSize + 1, originalValue.size());
+
+ final ODataPropertyUpdateRequest updateReq =
+ client.getCUDRequestFactory().getPropertyCollectionValueUpdateRequest(uriBuilder.build(),
+ alternativeNames);
+ if (client.getConfiguration().isUseXHTTPMethod()) {
+ assertEquals(HttpMethod.POST, updateReq.getMethod());
+ } else {
+ assertEquals(HttpMethod.PUT, updateReq.getMethod());
+ }
+ updateReq.setFormat(format);
+
+ final ODataPropertyUpdateResponse updateRes = updateReq.execute();
+ assertEquals(204, updateRes.getStatusCode());
+
+ retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ alternativeNames = retrieveRes.getBody();
+
+ assertEquals(origSize + 1, alternativeNames.getCollectionValue().size());
+ }
+
+ private void updatePrimitiveProperty(final ODataFormat format) throws IOException, EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
+ uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-9).
+ appendPropertySegment("PrimaryContactInfo").
+ appendPropertySegment("HomePhone").appendPropertySegment("PhoneNumber");
+
+ ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ ODataProperty phoneNumber = retrieveRes.getBody();
+
+ final String oldMsg = phoneNumber.getPrimitiveValue().toCastValue(String.class);
+ final String newMsg = "new item " + System.currentTimeMillis();
+
+ assertNotEquals(newMsg, oldMsg);
+
+ phoneNumber = client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
+ client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build());
+
+ final ODataPropertyUpdateRequest updateReq =
+ client.getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uriBuilder.build(), phoneNumber);
+ if (client.getConfiguration().isUseXHTTPMethod()) {
+ assertEquals(HttpMethod.POST, updateReq.getMethod());
+ } else {
+ assertEquals(HttpMethod.PUT, updateReq.getMethod());
+ }
+ updateReq.setFormat(format);
+
+ ODataPropertyUpdateResponse updateRes = updateReq.execute();
+ assertEquals(204, updateRes.getStatusCode());
+
+ retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ phoneNumber = retrieveRes.getBody();
+ assertEquals(newMsg, phoneNumber.getPrimitiveValue().toCastValue(String.class));
+ }
+
+ private void rawRequest(final ODataFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).appendPropertySegment("BackupContactInfo");
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataProperty> property = res.getBodyAs(ODataProperty.class);
+ assertNotNull(property.getPayload());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
new file mode 100644
index 0000000..cffcec5
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/PropertyValueTestITCase.java
@@ -0,0 +1,166 @@
+/*
+ * 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.v3;
+
+import java.io.IOException;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.format.ODataValueFormat;
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+public class PropertyValueTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void retrieveIntPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment("ProductId").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ assertNotNull(value);
+ assertEquals(-10, Integer.parseInt(value.toString()));
+ }
+
+ @Test
+ public void retrieveBooleanPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment("ProductId").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ assertNotNull(value);
+ assertEquals(-10, Integer.parseInt(value.toString()));
+ }
+
+ @Test
+ public void retrieveStringPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-6).appendPropertySegment("Description").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ assertNotNull(value);
+ assertEquals("expdybhclurfobuyvzmhkgrnrajhamqmkhqpmiypittnp", value.toString());
+ }
+
+ @Test
+ public void retrieveDatePropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-7).appendPropertySegment(
+ "NestedComplexConcurrency/ModifiedDate").appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ assertNotNull(value);
+ assertEquals("7866-11-16T22:25:52.747755+01:00", value.toString());
+ }
+
+ @Test
+ public void retrieveDecimalPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-6).appendPropertySegment("Dimensions/Height").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ assertNotNull(value);
+ assertEquals("-79228162514264337593543950335", value.toString());
+ }
+
+ @Test
+ public void retrieveBinaryPropertyValueTest() throws IOException {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setAccept("application/json");
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
+ + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
+ entity.getProperties().get(0).getValue().toString());
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void retrieveBinaryPropertyValueTestWithAtom() throws IOException {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setAccept("application/atom+xml");
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntity entitySet = res.getBody();
+ assertNotNull(entitySet);
+ assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
+ + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
+ entitySet.getProperties().get(0).getValue().toString());
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void retrieveBinaryPropertyValueTestWithXML() throws IOException {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setAccept("application/xml");
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntity entitySet = res.getBody();
+ assertNotNull(entitySet);
+ assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
+ + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
+ entitySet.getProperties().get(0).getValue().toString());
+ }
+
+ @Test
+ public void retrieveCollectionPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-7).appendPropertySegment(
+ "ComplexConcurrency/QueriedDateTime").appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataValue value = req.execute().getBody();
+ if (value.isPrimitive()) {
+ assertNotNull(value);
+ assertEquals("2013-09-18T00:44:43.6196168", value.toString());
+ }
+ }
+
+ @Test
+ public void retrieveNullPropertyValueTest() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment(
+ "ComplexConcurrency/Token").appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ try {
+ req.execute().getBody();
+ } catch (ODataClientErrorException e) {
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java
new file mode 100644
index 0000000..5b1f306
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/QueryOptionsTestITCase.java
@@ -0,0 +1,202 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.data.AtomEntityImpl;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check for query options.
+ */
+public class QueryOptionsTestITCase extends AbstractTestITCase {
+
+ /**
+ * Test <tt>$expand</tt>.
+ *
+ * @see EntityRetrieveTest#readODataEntityWithInline(org.apache.olingo.commons.api.format.ODataPubFormat)
+ */
+ public void expand() {
+ // empty
+ }
+
+ /**
+ * Test <tt>$filter</tt> and <tt>orderby</tt>.
+ *
+ * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
+ */
+ @Test
+ public void filterOrderby() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").filter("(VIN lt 16)");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(5, feed.getEntities().size());
+
+ // 2. extract VIN values - sorted ASC by default
+ final List<Integer> vinsASC = new ArrayList<Integer>(5);
+ for (ODataEntity entity : feed.getEntities()) {
+ final Integer vin = entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(vin < 16);
+ vinsASC.add(vin);
+ }
+
+ // 3. add orderby clause to filter above
+ req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("VIN desc").build());
+ feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(5, feed.getEntities().size());
+
+ // 4. extract again VIN value - now they were required to be sorted DESC
+ final List<Integer> vinsDESC = new ArrayList<Integer>(5);
+ for (ODataEntity entity : feed.getEntities()) {
+ vinsDESC.add(entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class));
+ }
+
+ // 5. reverse vinsASC and expect to be equal to vinsDESC
+ Collections.reverse(vinsASC);
+ assertEquals(vinsASC, vinsDESC);
+ }
+
+ /**
+ * Test <tt>$format</tt>.
+ */
+ @Test
+ public void format() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).format("json");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertNotNull(res);
+ assertTrue(res.getContentType().replaceAll(" ", "").
+ startsWith(ODataPubFormat.JSON.toString(client.getServiceVersion())));
+ }
+
+ /**
+ * Test <tt>$skip</tt>.
+ *
+ * @see FeedTest#readFeedWithNextLink(org.apache.olingo.commons.api.format.ODataPubFormat)
+ */
+ public void skip() {
+ // empty
+ }
+
+ /**
+ * Test <tt>$top</tt>.
+ *
+ * @see FeedTest#readFeed(org.apache.olingo.commons.api.format.ODataPubFormat)
+ */
+ public void top() {
+ // empty
+ }
+
+ /**
+ * Test <tt>$skiptoken</tt>.
+ */
+ @Test
+ public void skiptoken() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("Customer").skipToken("-10");
+
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntities().size());
+
+ for (ODataEntity entity : feed.getEntities()) {
+ assertTrue(entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class) > -10);
+ }
+ }
+
+ /**
+ * Test <tt>$inlinecount</tt>.
+ */
+ @Test
+ public void inlinecount() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car").
+ inlineCount(InlineCount.allpages);
+
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(feed.getEntities().size(), feed.getCount());
+ }
+
+ /**
+ * Test <tt>$select</tt>.
+ */
+ @Test
+ public void select() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").appendKeySegment(-10).select("CustomerId,Orders").expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ final ODataEntity customer = req.execute().getBody();
+ assertEquals(1, customer.getProperties().size());
+ assertEquals(1, customer.getNavigationLinks().size());
+ assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
+ }
+
+ @Test
+ public void issue131() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").appendKeySegment(-7).select("Name");
+
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+
+ final ODataEntity customer = req.execute().getBody();
+ assertEquals(0, customer.getProperties().size());
+
+ req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+
+ final Entity atomEntry =
+ client.getDeserializer().toEntity(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload();
+ assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve",
+ ((AtomEntityImpl) atomEntry).getSummary());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/ServiceDocumentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/ServiceDocumentTestITCase.java
new file mode 100644
index 0000000..a66874c
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/ServiceDocumentTestITCase.java
@@ -0,0 +1,56 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Test;
+
+public class ServiceDocumentTestITCase extends AbstractTestITCase {
+
+ private void retrieveServiceDocument(final ODataFormat format) {
+ final ODataServiceDocumentRequest req =
+ client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataServiceDocument serviceDocument = res.getBody();
+ assertEquals(24, serviceDocument.getEntitySetTitles().size());
+
+ assertEquals(URI.create(testStaticServiceRootURL + "/ComputerDetail"),
+ serviceDocument.getEntitySetURI("ComputerDetail"));
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsXML() {
+ retrieveServiceDocument(ODataFormat.XML);
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsJSON() {
+ retrieveServiceDocument(ODataFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodEntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodEntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodEntityUpdateTestITCase.java
new file mode 100644
index 0000000..a7589b7
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodEntityUpdateTestITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.v3;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Performs entity update tests using the X-HTTP-METHOD header.
+ */
+public class XHTTPMethodEntityUpdateTestITCase extends EntityUpdateTestITCase {
+
+ @BeforeClass
+ public static void enableXHTTPMethod() {
+ client.getConfiguration().setUseXHTTPMethod(true);
+ }
+
+ @AfterClass
+ public static void disableXHTTPMethod() {
+ client.getConfiguration().setUseXHTTPMethod(false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodPropertyUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodPropertyUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodPropertyUpdateTestITCase.java
new file mode 100644
index 0000000..99ec3b5
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/XHTTPMethodPropertyUpdateTestITCase.java
@@ -0,0 +1,38 @@
+/*
+ * 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.v3;
+
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+/**
+ * Performs property update tests using the X-HTTP-METHOD header.
+ */
+public class XHTTPMethodPropertyUpdateTestITCase extends PropertyTestITCase {
+
+ @BeforeClass
+ public static void enableXHTTPMethod() {
+ client.getConfiguration().setUseXHTTPMethod(true);
+ }
+
+ @AfterClass
+ public static void disableXHTTPMethod() {
+ client.getConfiguration().setUseXHTTPMethod(false);
+ }
+}
[07/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java
new file mode 100644
index 0000000..bb6918b
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityRetrieveTestITCase.java
@@ -0,0 +1,367 @@
+/*
+ * 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.v4;
+
+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 java.net.URI;
+import java.util.LinkedHashMap;
+import java.util.List;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
+import org.apache.olingo.client.api.communication.response.ODataRawResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.ODataLinkType;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check entity retrieve operations.
+ */
+public class EntityRetrieveTestITCase extends AbstractTestITCase {
+
+ private void withInlineEntry(final ODataClient client, final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
+ getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+
+ assertNotNull(entity);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
+ assertTrue(entity.getProperty("Home").hasPrimitiveValue());
+ assertEquals("Edm.GeographyPoint", entity.getProperty("Home").getPrimitiveValue().getTypeName());
+ assertEquals(testStaticServiceRootURL + "/Customers(1)", entity.getEditLink().toASCIIString());
+
+ // In JSON with minimal metadata, links are not provided
+ if (format == ODataPubFormat.ATOM || format == ODataPubFormat.JSON_FULL_METADATA) {
+ assertEquals(3, entity.getNavigationLinks().size());
+
+ if (ODataPubFormat.ATOM == format) {
+ assertTrue(entity.getAssociationLinks().isEmpty());
+ // In JSON, association links for each $ref link will exist.
+ }
+
+ boolean found = false;
+
+ for (ODataLink link : entity.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntity) {
+ final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
+ assertNotNull(inline);
+
+ final List<? extends CommonODataProperty> properties = inline.getProperties();
+ assertEquals(5, properties.size());
+
+ assertTrue(properties.get(0).getName().equals("CompanyID")
+ || properties.get(1).getName().equals("CompanyID")
+ || properties.get(2).getName().equals("CompanyID")
+ || properties.get(3).getName().equals("CompanyID")
+ || properties.get(4).getName().equals("CompanyID"));
+ assertTrue(properties.get(0).getValue().toString().equals("0")
+ || properties.get(1).getValue().toString().equals("0")
+ || properties.get(2).getValue().toString().equals("0")
+ || properties.get(3).getValue().toString().equals("0")
+ || properties.get(4).getValue().toString().equals("0"));
+
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+ }
+ }
+
+ @Test
+ public void withInlineEntryFromAtom() {
+ withInlineEntry(client, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void withInlineEntryFromFullJSON() {
+ withInlineEntry(client, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void withInlineEntryFromJSON() {
+ withInlineEntry(edmClient, ODataPubFormat.JSON);
+ }
+
+ private void withInlineFeed(final ODataClient client, final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
+ getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
+
+ // In JSON with minimal metadata, links are not provided
+ if (format == ODataPubFormat.ATOM || format == ODataPubFormat.JSON_FULL_METADATA) {
+ boolean found = false;
+ for (ODataLink link : entity.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntitySet) {
+ final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
+ assertNotNull(inline);
+
+ found = true;
+ }
+ }
+ assertTrue(found);
+ }
+ }
+
+ @Test
+ public void withInlineFeedFromAtom() {
+ withInlineFeed(client, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void withInlineFeedFromFullJSON() {
+ withInlineFeed(client, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void withInlineFeedFromJSON() {
+ withInlineFeed(edmClient, ODataPubFormat.JSON);
+ }
+
+ private void rawRequest(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5);
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertNull(entitySet);
+
+ final ResWrap<ODataEntity> entity = res.getBodyAs(ODataEntity.class);
+ assertTrue(entity.getPayload().getReference().endsWith("/StaticService/V40/Static.svc/People(5)"));
+ }
+
+ @Test
+ public void rawRequestAsAtom() {
+ rawRequest(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void rawRequestAsJSON() {
+ // this needs to be full, otherwise reference will not be provided
+ rawRequest(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void multiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
+ multiKey.put("ProductID", "6");
+ multiKey.put("ProductDetailID", 1);
+
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("ProductDetails").appendKeySegment(multiKey);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertEquals(Integer.valueOf(1),
+ entity.getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class));
+ }
+
+ @Test
+ public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
+ multiKey(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
+ multiKey(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void checkForETag(final ODataClient client, final ODataPubFormat format) {
+ final URIBuilder uriBuilder =
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final String etag = res.getETag();
+ assertTrue(StringUtils.isNotBlank(etag));
+
+ final ODataEntity order = res.getBody();
+ assertEquals(etag, order.getETag());
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Order", order.getTypeName().toString());
+ assertEquals("Edm.Int32", order.getProperty("OrderID").getPrimitiveValue().getTypeName());
+ assertEquals("Edm.DateTimeOffset", order.getProperty("OrderDate").getPrimitiveValue().getTypeName());
+ assertEquals("Edm.Duration", order.getProperty("ShelfLife").getPrimitiveValue().getTypeName());
+ assertEquals("Collection(Edm.Duration)", order.getProperty("OrderShelfLifes").getCollectionValue().getTypeName());
+ }
+
+ @Test
+ public void checkForETagAsATOM() {
+ checkForETag(client, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void checkForETagAsFullJSON() {
+ checkForETag(client, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void checkForETagAsJSON() {
+ checkForETag(edmClient, ODataPubFormat.JSON);
+ }
+
+ @Test(expected = IllegalArgumentException.class)
+ public void issue99() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ // this statement should cause an IllegalArgumentException bearing JsonParseException
+ // since we are attempting to parse an EntitySet as if it was an Entity
+ req.execute().getBody();
+ }
+
+ private void reference(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
+ appendRefSegment();
+
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertNotNull(res);
+
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertTrue(entity.getReference().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
+
+ final URI referenceURI =
+ client.getURIBuilder(testStaticServiceRootURL).appendEntityIdSegment(entity.getReference()).build();
+
+ req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
+ req.setFormat(format);
+
+ res = req.execute();
+ assertNotNull(res);
+ assertNotNull(res.getBody());
+ }
+
+ @Test
+ public void atomReference() {
+ reference(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonReference() {
+ reference(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void contained(final ODataClient client, final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final URI uri = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101).
+ appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101901).build();
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
+ req.setFormat(format);
+
+ final ODataEntity contained = req.execute().getBody();
+ assertNotNull(contained);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", contained.getTypeName().toString());
+ assertEquals(101901,
+ contained.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
+ assertEquals("Edm.DateTimeOffset", contained.getProperty("CreatedDate").getPrimitiveValue().getTypeName());
+ }
+
+ @Test
+ public void containedFromAtom() throws EdmPrimitiveTypeException {
+ contained(client, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void containedFromFullJSON() throws EdmPrimitiveTypeException {
+ contained(client, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void containedFromJSON() throws EdmPrimitiveTypeException {
+ contained(edmClient, ODataPubFormat.JSON);
+ }
+
+ private void entitySetNavigationLink(final ODataClient client, final ODataPubFormat format) {
+ final URI uri = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101).build();
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
+ req.setFormat(format);
+
+ final ODataEntity entity = req.execute().getBody();
+ assertNotNull(entity);
+
+ // With JSON, entity set navigation links are only recognizable via Edm
+ if (format == ODataPubFormat.ATOM || client instanceof EdmEnabledODataClient) {
+ assertEquals(ODataLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("MyPaymentInstruments").getType());
+ assertEquals(ODataLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("ActiveSubscriptions").getType());
+ }
+ }
+
+ @Test
+ public void entitySetNavigationLinkFromAtom() {
+ entitySetNavigationLink(client, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void entitySetNavigationLinkFromJSON() {
+ // only JSON_FULL_METADATA has links, only Edm can recognize entity set navigation
+ entitySetNavigationLink(edmClient, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java
new file mode 100644
index 0000000..5c78127
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntitySetTestITCase.java
@@ -0,0 +1,179 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
+import org.apache.olingo.client.api.communication.response.ODataRawResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.data.ResWrap;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check basic feed operations.
+ */
+public class EntitySetTestITCase extends AbstractTestITCase {
+
+ private void rawRequest(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People");
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertNotNull(entitySet.getPayload());
+ assertTrue(entitySet.getContextURL().getURI().toASCIIString().endsWith("$metadata#People"));
+ }
+
+ @Test
+ public void rawRequestAsAtom() throws IOException {
+ rawRequest(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void rawRequestAsJSON() throws IOException {
+ rawRequest(ODataPubFormat.JSON);
+ }
+
+ private void readWithInlineCount(final ODataClient client, final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People").count(true);
+
+ final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
+ req.setFormat(format.toString(client.getServiceVersion()));
+
+ final ODataRawResponse res = req.execute();
+ assertNotNull(res);
+
+ final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
+ assertEquals(5, entitySet.getPayload().getCount());
+
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address",
+ entitySet.getPayload().getEntities().get(2).getProperty("HomeAddress").getComplexValue().getTypeName());
+ }
+
+ @Test
+ public void readWithInlineCountAsJSON() throws IOException {
+ readWithInlineCount(edmClient, ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void readWithInlineCountAsFullJSON() throws IOException {
+ readWithInlineCount(client, ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void readWithInlineCountAsAtom() throws IOException {
+ readWithInlineCount(client, ODataPubFormat.ATOM);
+ }
+
+ private void readODataEntitySetIterator(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People");
+
+ final ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> req =
+ client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySetIterator<ODataEntitySet, ODataEntity>> res = req.execute();
+ final ODataEntitySetIterator<ODataEntitySet, ODataEntity> feedIterator = res.getBody();
+
+ assertNotNull(feedIterator);
+
+ int count = 0;
+
+ while (feedIterator.hasNext()) {
+ assertNotNull(feedIterator.next());
+ count++;
+ }
+ assertEquals(5, count);
+ assertTrue(feedIterator.getNext().toASCIIString().endsWith("People?$skiptoken=5"));
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromAtom() {
+ readODataEntitySetIterator(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSON() {
+ readODataEntitySetIterator(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSONFull() {
+ readODataEntitySetIterator(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void readODataEntitySetIteratorFromJSONNo() {
+ readODataEntitySetIterator(ODataPubFormat.JSON_NO_METADATA);
+ }
+
+ private void readEntitySetWithNextLink(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People");
+
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ final ODataEntitySet feed = res.getBody();
+
+ assertNotNull(feed);
+
+ assertEquals(5, feed.getEntities().size());
+ assertNotNull(feed.getNext());
+
+ final URI expected = URI.create(testStaticServiceRootURL + "/People?$skiptoken=5");
+ final URI found = URIUtils.getURI(testStaticServiceRootURL, feed.getNext().toASCIIString());
+
+ assertEquals(expected, found);
+ }
+
+ @Test
+ public void readODataEntitySetWithNextFromAtom() {
+ readEntitySetWithNextLink(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readODataEntitySetWithNextFromJSON() {
+ readEntitySetWithNextLink(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
new file mode 100644
index 0000000..669c10c
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityUpdateTestITCase.java
@@ -0,0 +1,154 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Calendar;
+import java.util.UUID;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class EntityUpdateTestITCase extends AbstractTestITCase {
+
+ private void upsert(final UpdateType updateType, final ODataPubFormat format) {
+ final ODataEntity order = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
+
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(9)));
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
+
+ final URI upsertURI = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Orders").appendKeySegment(9).build();
+ final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
+ getEntityUpdateRequest(upsertURI, updateType, order);
+ req.setFormat(format);
+
+ req.execute();
+ try {
+ final ODataEntity read = read(format, upsertURI);
+ assertNotNull(read);
+ assertEquals(order.getProperty("OrderID"), read.getProperty("OrderID"));
+ assertEquals(order.getProperty("OrderDate").getPrimitiveValue().toString(),
+ read.getProperty("OrderDate").getPrimitiveValue().toString());
+ assertEquals(order.getProperty("ShelfLife").getPrimitiveValue().toString(),
+ read.getProperty("ShelfLife").getPrimitiveValue().toString());
+ } finally {
+ getClient().getCUDRequestFactory().getDeleteRequest(upsertURI).execute();
+ }
+ }
+
+ @Test
+ public void atomUpsert() {
+ upsert(UpdateType.PATCH, ODataPubFormat.ATOM);
+ upsert(UpdateType.REPLACE, ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonUpsert() {
+ upsert(UpdateType.PATCH, ODataPubFormat.JSON);
+ upsert(UpdateType.REPLACE, ODataPubFormat.JSON);
+ }
+
+ private void onContained(final ODataPubFormat format) {
+ final String newName = UUID.randomUUID().toString();
+ final ODataEntity changes = getClient().getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument"));
+ changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("FriendlyName",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(newName)));
+
+ final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101).
+ appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101901).build();
+ final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
+ getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
+ req.setFormat(format);
+
+ final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ final ODataEntity actual = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
+ assertNotNull(actual);
+ assertEquals(newName, actual.getProperty("FriendlyName").getPrimitiveValue().toString());
+ }
+
+ @Test
+ public void atomOnContained() {
+ onContained(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonOnContained() {
+ onContained(ODataPubFormat.JSON);
+ }
+
+ private void bindOperation(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final ODataEntity changes = getClient().getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
+ final ODataLink parent = getClient().getObjectFactory().newEntityNavigationLink("Parent",
+ getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(1).build());
+ changes.getNavigationLinks().add(parent);
+
+ final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).build();
+ final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
+ getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
+ req.setFormat(format);
+
+ final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ final ODataEntity updated = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
+ assertNotNull(updated);
+ final ODataLink updatedLink = updated.getNavigationLink("Parent");
+ assertNotNull(updatedLink);
+
+ final ODataEntity updatedEntity = getClient().getRetrieveRequestFactory().getEntityRequest(updatedLink.getLink()).
+ execute().getBody();
+ assertNotNull(updatedEntity);
+ assertEquals(1, updatedEntity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
+ }
+
+ @Test
+ public void atomBindOperation() throws EdmPrimitiveTypeException {
+ bindOperation(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonBindOperation() throws EdmPrimitiveTypeException {
+ bindOperation(ODataPubFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java
new file mode 100644
index 0000000..a85891e
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/FilterFactoryTestITCase.java
@@ -0,0 +1,63 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
+
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.uri.URIFilter;
+import org.apache.olingo.client.api.uri.v4.FilterArgFactory;
+import org.apache.olingo.client.api.uri.v4.FilterFactory;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class FilterFactoryTestITCase extends AbstractTestITCase {
+
+ private FilterFactory getFilterFactory() {
+ return getClient().getFilterFactory();
+ }
+
+ private FilterArgFactory getFilterArgFactory() {
+ return getFilterFactory().getArgFactory();
+ }
+
+ @Test
+ public void crossjoin() {
+ final URIFilter filter = getFilterFactory().eq(
+ getFilterArgFactory().property("Orders/OrderID"), getFilterArgFactory().property("Customers/Order"));
+
+ final URIBuilder uriBuilder =
+ client.getURIBuilder(testStaticServiceRootURL).appendCrossjoinSegment("Customers", "Orders").filter(filter);
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataEntitySet feed = req.execute().getBody();
+ assertEquals(3, feed.getEntities().size());
+
+ for (ODataEntity entity : feed.getEntities()) {
+ assertEquals(2, entity.getNavigationLinks().size());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java
new file mode 100644
index 0000000..37298b2
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/KeyAsSegmentTestITCase.java
@@ -0,0 +1,122 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+
+public class KeyAsSegmentTestITCase extends AbstractTestITCase {
+
+ @BeforeClass
+ public static void enableKeyAsSegment() {
+ client.getConfiguration().setKeyAsSegment(true);
+ }
+
+ private void read(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testKeyAsSegmentServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101);
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+
+ assertFalse(entity.getEditLink().toASCIIString().contains("("));
+ assertFalse(entity.getEditLink().toASCIIString().contains(")"));
+ }
+
+ @Test
+ public void atomRead() {
+ read(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonRead() {
+ read(ODataPubFormat.JSON);
+ }
+
+ @Test
+ public void atomCreateAndDelete() {
+ createAndDeleteOrder(ODataPubFormat.ATOM, 1000);
+ }
+
+ @Test
+ public void jsonCreateAndDelete() {
+ createAndDeleteOrder(ODataPubFormat.JSON, 1001);
+ }
+
+ private void update(final ODataPubFormat format) {
+ final ODataEntity changes = getClient().getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
+ final ODataProperty middleName = getClient().getObjectFactory().newPrimitiveProperty("MiddleName",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("middle"));
+ changes.getProperties().add(middleName);
+
+ final URI uri = getClient().getURIBuilder(testKeyAsSegmentServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).build();
+ final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
+ getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
+ req.setFormat(format);
+
+ final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
+ assertEquals(204, res.getStatusCode());
+
+ final ODataEntity updated = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
+ assertNotNull(updated);
+ assertFalse(updated.getEditLink().toASCIIString().contains("("));
+ assertFalse(updated.getEditLink().toASCIIString().contains(")"));
+
+ final ODataProperty updatedMiddleName = updated.getProperty("MiddleName");
+ assertNotNull(updatedMiddleName);
+ assertEquals("middle", updatedMiddleName.getPrimitiveValue().toString());
+ }
+
+ @Test
+ public void atomUpdate() {
+ update(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonUpdate() {
+ update(ODataPubFormat.JSON);
+ }
+
+ @AfterClass
+ public static void disableKeyAsSegment() {
+ client.getConfiguration().setKeyAsSegment(false);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java
new file mode 100644
index 0000000..a00e907
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/MetadataTestITCase.java
@@ -0,0 +1,71 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.fit.AbstractMetadataTestITCase;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.junit.Test;
+
+public class MetadataTestITCase extends AbstractMetadataTestITCase {
+
+ @Override
+ protected ODataClient getClient() {
+ return ODataClientFactory.getV4();
+ }
+
+ @Test
+ public void retrieve() {
+ final Edm metadata = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(getTestServiceRoot()).execute().getBody();
+ assertNotNull(metadata);
+
+ final EdmEntityType order = metadata.getEntityType(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService", "Order"));
+ assertNotNull(order);
+
+ final EdmProperty orderDate = order.getStructuralProperty("OrderDate");
+ assertNotNull(orderDate);
+ assertEquals("Edm.DateTimeOffset", orderDate.getType().getFullQualifiedName().toString());
+ }
+
+ @Test
+ public void include() {
+ final Edm metadata = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(getNorthwindServiceRoot()).execute().getBody();
+ assertNotNull(metadata);
+
+ final EdmEntityContainer container = metadata.getEntityContainer(
+ new FullQualifiedName("ODataWebExperimental.Northwind.Model", "NorthwindEntities"));
+ assertNotNull(container);
+
+ final EdmEntitySet categories = container.getEntitySet("Categories");
+ assertNotNull(categories);
+ assertEquals("NorthwindModel", categories.getEntityType().getNamespace());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
new file mode 100644
index 0000000..f49f50b
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/OpenTypeTestITCase.java
@@ -0,0 +1,188 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Calendar;
+import java.util.UUID;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmSchema;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class OpenTypeTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void checkOpenTypeEntityTypesExist() {
+ final Edm metadata = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
+
+ final EdmSchema schema = metadata.getSchemas().get(0);
+
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "Row")).isOpenType());
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "IndexedRow")).isOpenType());
+ assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
+ }
+
+ private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
+ final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
+ return read(format, builder.build());
+ }
+
+ private void read(final ODataPubFormat format) {
+ ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
+ assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
+
+ row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
+ assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
+ }
+
+ @Test
+ public void readAsAtom() {
+ read(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readAsJSON() {
+ read(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void cud(final ODataPubFormat format) {
+ final Integer id = 1426;
+
+ ODataEntity rowIndex = getClient().getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesService.RowIndex"));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("Id",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aString",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aBoolean",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(true)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aDouble",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.5D)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aByte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
+ build()));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
+ build()));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newPrimitiveProperty("aDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
+ build()));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newEnumProperty("aColor", getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
+
+ final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
+ "Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Date).setText("2001-04-05").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("-P9DT51M10.5063807S").build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("SignedByte",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Double",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(Double.MAX_VALUE)));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Single",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(Float.MAX_VALUE)));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Short",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
+ contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Int",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(Integer.MAX_VALUE)));
+ getClient().getBinder().add(rowIndex,
+ getClient().getObjectFactory().newComplexProperty("aContact", contactDetails));
+
+ final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
+ getEntityCreateRequest(getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("RowIndex").build(), rowIndex);
+ createReq.setFormat(format);
+ final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+
+ final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntitySetSegment("RowIndex").appendKeySegment(id);
+ rowIndex = read(format, builder.build());
+ assertNotNull(rowIndex);
+ assertEquals(EdmPrimitiveTypeKind.Int32,
+ rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.String,
+ rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind());
+ assertEquals(EdmPrimitiveTypeKind.Boolean,
+ rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
+ assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue());
+ assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue());
+ assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue());
+ assertNotNull(rowIndex.getProperty("aColor"));
+ assertTrue(rowIndex.getProperty("aContact").hasComplexValue());
+ assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue());
+
+ final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
+ getDeleteRequest(rowIndex.getEditLink()).execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+
+ @Test
+ public void cudAsAtom() {
+ cud(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void cudAsJSON() {
+ cud(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java
new file mode 100644
index 0000000..fbca0fb
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/OperationImportInvokeTestITCase.java
@@ -0,0 +1,258 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
+import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmActionImport;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+
+import org.junit.Test;
+
+public class OperationImportInvokeTestITCase extends AbstractTestITCase {
+
+ private Edm getEdm() {
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ return edm;
+ }
+
+ private void functionImports(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final Edm edm = getEdm();
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ // GetDefaultColor
+ EdmFunctionImport funcImp = container.getFunctionImport("GetDefaultColor");
+
+ final ODataInvokeRequest<ODataProperty> defaultColorReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0));
+ defaultColorReq.setFormat(format);
+ final ODataProperty defaultColor = defaultColorReq.execute().getBody();
+ assertNotNull(defaultColor);
+ assertTrue(defaultColor.hasEnumValue());
+ assertEquals("Red", defaultColor.getEnumValue().getValue());
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Color", defaultColor.getEnumValue().getTypeName());
+
+ // GetPerson2
+ funcImp = container.getFunctionImport("GetPerson2");
+
+ final ODataPrimitiveValue city =
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("London");
+
+ final ODataInvokeRequest<ODataEntity> person2Req = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0),
+ Collections.<String, ODataValue>singletonMap("city", city));
+ person2Req.setFormat(format);
+ final ODataEntity person2 = person2Req.execute().getBody();
+ assertNotNull(person2);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString());
+ assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // GetPerson
+ funcImp = container.getFunctionImport("GetPerson");
+
+ final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
+ newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
+ address.add(client.getObjectFactory().newPrimitiveProperty("Street",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("1 Microsoft Way")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("City",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("London")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("98052")));
+
+ final ODataInvokeRequest<ODataEntity> personReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0),
+ Collections.<String, ODataValue>singletonMap("address", address));
+ personReq.setFormat(format);
+ final ODataEntity person = personReq.execute().getBody();
+ assertNotNull(person);
+ assertEquals(person2, person);
+
+ // GetAllProducts
+ funcImp = container.getFunctionImport("GetAllProducts");
+
+ final ODataInvokeRequest<ODataEntitySet> productsReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0));
+ productsReq.setFormat(format);
+ final ODataEntitySet products = productsReq.execute().getBody();
+ assertNotNull(products);
+ assertEquals(5, products.getCount());
+
+ // GetProductsByAccessLevel
+ funcImp = container.getFunctionImport("GetProductsByAccessLevel");
+
+ final ODataEnumValue accessLevel = getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "None");
+
+ final ODataInvokeRequest<ODataProperty> prodByALReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0),
+ Collections.<String, ODataValue>singletonMap("accessLevel", accessLevel));
+ prodByALReq.setFormat(format);
+ final ODataProperty prodByAL = prodByALReq.execute().getBody();
+ assertNotNull(prodByAL);
+ assertTrue(prodByAL.hasCollectionValue());
+ assertEquals(5, prodByAL.getCollectionValue().size());
+ assertTrue(prodByAL.getCollectionValue().asJavaCollection().contains("Car"));
+ }
+
+ @Test
+ public void atomFunctionImports() throws EdmPrimitiveTypeException {
+ functionImports(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonFunctionImports() throws EdmPrimitiveTypeException {
+ functionImports(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void actionImports(final ODataPubFormat format) {
+ final Edm edm = getEdm();
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ // Discount
+ EdmActionImport actImp = container.getActionImport("Discount");
+
+ final ODataPrimitiveValue percentage = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(22);
+ final ODataInvokeRequest<ODataNoContent> discountReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(actImp.getName()).build(),
+ actImp.getUnboundAction(),
+ Collections.<String, ODataValue>singletonMap("percentage", percentage));
+ discountReq.setFormat(format);
+ final ODataNoContent discount = discountReq.execute().getBody();
+ assertNotNull(discount);
+
+ // ResetBossAddress
+ actImp = container.getActionImport("ResetBossAddress");
+
+ final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
+ newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
+ address.add(client.getObjectFactory().newPrimitiveProperty("Street",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Via Le Mani Dal Naso, 123")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("City",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Tollo")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
+
+ final ODataInvokeRequest<ODataProperty> resetBossAddressReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(actImp.getName()).build(),
+ actImp.getUnboundAction(),
+ Collections.<String, ODataValue>singletonMap("address", address));
+ resetBossAddressReq.setFormat(format);
+ final ODataProperty resetBossAddress = resetBossAddressReq.execute().getBody();
+ assertNotNull(resetBossAddress);
+ }
+
+ @Test
+ public void atomActionImports() {
+ actionImports(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonActionImports() {
+ actionImports(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void bossEmails(final ODataPubFormat format) {
+ final Edm edm = getEdm();
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ // ResetBossEmail
+ final EdmActionImport actImp = container.getActionImport("ResetBossEmail");
+
+ final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> emails =
+ getClient().getObjectFactory().newCollectionValue("Collection(Edm.String)");
+ emails.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("first@olingo.apache.org"));
+ emails.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("second@olingo.apache.org"));
+ ODataInvokeRequest<ODataProperty> bossEmailsReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(actImp.getName()).build(),
+ actImp.getUnboundAction(),
+ Collections.<String, ODataValue>singletonMap("emails", emails));
+ bossEmailsReq.setFormat(format);
+ final ODataProperty bossEmails = bossEmailsReq.execute().getBody();
+ assertNotNull(bossEmails);
+ assertTrue(bossEmails.hasCollectionValue());
+ assertEquals(2, bossEmails.getCollectionValue().size());
+
+ final EdmFunctionImport funcImp = container.getFunctionImport("GetBossEmails");
+
+ final Map<String, ODataValue> params = new LinkedHashMap<String, ODataValue>(2);
+ params.put("start", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(0));
+ params.put("count", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(100));
+ bossEmailsReq = getClient().getInvokeRequestFactory().
+ getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
+ appendOperationCallSegment(funcImp.getName()).build(),
+ funcImp.getUnboundFunctions().get(0),
+ params);
+ bossEmailsReq.setFormat(format);
+ final ODataProperty bossEmailsViaGET = bossEmailsReq.execute().getBody();
+ assertNotNull(bossEmailsViaGET);
+ assertTrue(bossEmailsViaGET.hasCollectionValue());
+ assertEquals(2, bossEmailsViaGET.getCollectionValue().size());
+ assertEquals(bossEmails.getCollectionValue().asJavaCollection(),
+ bossEmailsViaGET.getCollectionValue().asJavaCollection());
+ }
+
+ @Test
+ public void atomBossEmails() throws EdmPrimitiveTypeException {
+ bossEmails(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonBossEmails() throws EdmPrimitiveTypeException {
+ bossEmails(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
new file mode 100644
index 0000000..de7ea50
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyTestITCase.java
@@ -0,0 +1,164 @@
+/*
+ * 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.v4;
+
+import java.io.IOException;
+import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
+import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.http.HttpMethod;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Test;
+
+public class PropertyTestITCase extends AbstractTestITCase {
+
+ private void _enum(final ODataClient client, final ODataFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Products").appendKeySegment(5).appendPropertySegment("CoverColors");
+ final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataProperty prop = req.execute().getBody();
+ assertNotNull(prop);
+ assertEquals("Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)", prop.getValue().getTypeName());
+ }
+
+ @Test
+ public void enumFromXML() {
+ _enum(client, ODataFormat.XML);
+ }
+
+ @Test
+ public void enumFromJSON() {
+ _enum(edmClient, ODataFormat.JSON);
+ }
+
+ @Test
+ public void enumFromFullJSON() {
+ _enum(client, ODataFormat.JSON_FULL_METADATA);
+ }
+
+ private void geospatial(final ODataClient client, final ODataFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Home");
+ final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataProperty prop = req.execute().getBody();
+ assertNotNull(prop);
+ assertEquals("Edm.GeographyPoint", prop.getValue().getTypeName());
+ }
+
+ @Test
+ public void geospatialFromXML() {
+ geospatial(client, ODataFormat.XML);
+ }
+
+ @Test
+ public void geospatialFromJSON() {
+ geospatial(edmClient, ODataFormat.JSON);
+ }
+
+ @Test
+ public void geospatialFromFullJSON() {
+ geospatial(client, ODataFormat.JSON_FULL_METADATA);
+ }
+
+ private void complex(final ODataClient client, final ODataFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(2).appendPropertySegment("HomeAddress");
+ final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataProperty prop = req.execute().getBody();
+ assertNotNull(prop);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address", prop.getValue().getTypeName());
+ }
+
+ @Test
+ public void complexFromXML() {
+ complex(client, ODataFormat.XML);
+ }
+
+ @Test
+ public void complexFromJSON() {
+ complex(edmClient, ODataFormat.JSON);
+ }
+
+ @Test
+ public void complexFromFullJSON() {
+ complex(client, ODataFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void patchComplexPropertyAsJSON() throws IOException {
+ updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH);
+ }
+
+ private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).appendPropertySegment("HomeAddress");
+
+ ODataPropertyRequest<ODataProperty> retrieveReq =
+ client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ ODataProperty homeAddress =
+ client.getObjectFactory().newComplexProperty("HomeAddress",
+ client.getObjectFactory().newComplexValue(retrieveRes.getBody().getComplexValue().getTypeName()));
+
+ homeAddress.getComplexValue().add(client.getObjectFactory().
+ newPrimitiveProperty("City", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Pescara")));
+
+ final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
+ getPropertyComplexValueUpdateRequest(uriBuilder.build(), type, homeAddress);
+ if (client.getConfiguration().isUseXHTTPMethod()) {
+ assertEquals(HttpMethod.POST, updateReq.getMethod());
+ } else {
+ assertEquals(type.getMethod(), updateReq.getMethod());
+ }
+ updateReq.setFormat(format);
+
+ final ODataPropertyUpdateResponse updateRes = updateReq.execute();
+ assertEquals(204, updateRes.getStatusCode());
+
+ retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ retrieveReq.setFormat(format);
+
+ retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ homeAddress = retrieveRes.getBody();
+ assertEquals("Pescara", homeAddress.getComplexValue().get("City").getPrimitiveValue().toString());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java
new file mode 100644
index 0000000..8257bb7
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/PropertyValueTestITCase.java
@@ -0,0 +1,147 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.api.format.ODataValueFormat;
+import org.junit.Test;
+
+public class PropertyValueTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void retrieveIntPropertyValueTest() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PersonID").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ assertEquals("5", req.execute().getBody().toString());
+ }
+
+ @Test
+ public void retrieveBooleanPropertyValueTest() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("IsRegistered").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ assertEquals("true", req.execute().getBody().toString());
+ }
+
+ @Test
+ public void retrieveStringPropertyValueTest() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("FirstName").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ assertEquals("Peter", req.execute().getBody().toString());
+ }
+
+ @Test
+ public void retrieveDatePropertyValueTest() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Orders").appendKeySegment(8).appendPropertySegment("OrderDate").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataPrimitiveValue property = req.execute().getBody();
+ assertEquals("2011-03-04T16:03:57Z", property.toString());
+ }
+
+ @Test
+ public void retrieveDecimalPropertyValueTest() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Height").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataPrimitiveValue property = req.execute().getBody();
+ assertEquals("179", property.toString());
+ }
+
+ @Test
+ public void retrieveBinaryPropertyValueTest() throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataPrimitiveValue property = req.execute().getBody();
+ assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
+ + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=", property.toString());
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void retrieveBinaryPropertyValueTestWithAtom() throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setAccept(ODataPubFormat.ATOM.toString(ODataServiceVersion.V40));
+ req.execute().getBody();
+ }
+
+ @Test(expected = ODataClientErrorException.class)
+ public void retrieveBinaryPropertyValueTestWithXML() throws IOException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setAccept(ODataFormat.XML.toString(client.getServiceVersion()));
+ req.execute().getBody();
+ }
+
+ @Test
+ public void retrieveCollectionPropertyValueTest() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Numbers");
+ final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
+ getPropertyRequest(uriBuilder.build());
+ req.setFormat(ODataFormat.XML);
+ final ODataProperty property = req.execute().getBody();
+ assertTrue(property.getValue().isCollection());
+ assertEquals("555-555-5555", property.getCollectionValue().iterator().next().asPrimitive().toString());
+ }
+
+ @Test
+ public void retrieveNullPropertyValueTest() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("HomeAddress").
+ appendValueSegment();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ final ODataPrimitiveValue property = req.execute().getBody();
+ assertTrue(StringUtils.isBlank(property.toString()));
+ }
+}
[04/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/LinkTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/LinkTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/LinkTestITCase.java
deleted file mode 100644
index a1476a5..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/LinkTestITCase.java
+++ /dev/null
@@ -1,177 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Collections;
-import java.util.List;
-import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.ODataLinkUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.v3.ODataLinkCollectionRequest;
-import org.apache.olingo.client.api.communication.response.ODataLinkOperationResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.client.api.domain.v3.ODataLinkCollection;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check basic link operations.
- */
-public class LinkTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- private ODataLinkCollection doRetrieveLinkURIs(final ODataFormat format, final String linkname) throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10);
-
- final ODataLinkCollectionRequest req =
- client.getRetrieveRequestFactory().getLinkCollectionRequest(uriBuilder.build(), linkname);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataLinkCollection> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- return res.getBody();
- }
-
- private void retrieveLinkURIs(final ODataFormat format) throws IOException {
- final List<URI> links = doRetrieveLinkURIs(format, "Logins").getLinks();
- assertEquals(2, links.size());
- assertTrue(links.contains(URI.create(getServiceRoot() + "/Login('1')")));
- assertTrue(links.contains(URI.create(getServiceRoot() + "/Login('4')")));
- }
-
- @Test
- public void retrieveXMLLinkURIsWithNext() throws IOException {
- final ODataLinkCollection uris = doRetrieveLinkURIs(ODataFormat.XML, "Orders");
- assertEquals(2, uris.getLinks().size());
- assertNotNull(uris.getNext());
- }
-
- @Test
- public void retrieveXMLLinkURIs() throws IOException {
- retrieveLinkURIs(ODataFormat.XML);
- }
-
- @Test
- public void retrieveJSONLinkURIs() throws IOException {
- retrieveLinkURIs(ODataFormat.JSON);
- }
-
- private void createLink(final ODataFormat format) throws IOException {
- // 1. read current Logins $links (for later usage)
- final List<URI> before = doRetrieveLinkURIs(format, "Logins").getLinks();
- assertEquals(2, before.size());
-
- // 2. create new link
- final ODataLink newLink = client.getObjectFactory().
- newAssociationLink(URI.create(getServiceRoot() + "/Login('3')"));
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).appendLinksSegment("Logins");
-
- final ODataLinkCreateRequest req =
- client.getCUDRequestFactory().getLinkCreateRequest(uriBuilder.build(), newLink);
- req.setFormat(format);
-
- final ODataLinkOperationResponse res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- final List<URI> after = doRetrieveLinkURIs(format, "Logins").getLinks();
- assertEquals(before.size() + 1, after.size());
-
- // 3. reset Logins $links as before this test was run
- after.removeAll(before);
- assertEquals(Collections.singletonList(newLink.getLink()), after);
-
- assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
- client.getURIBuilder(getServiceRoot()).appendEntitySetSegment("Customer").
- appendKeySegment(-10).appendLinksSegment("Logins('3')").build()).execute().getStatusCode());
- }
-
- @Test
- public void createXMLLink() throws IOException {
- createLink(ODataFormat.XML);
- }
-
- @Test
- public void createJSONLink() throws IOException {
- createLink(ODataFormat.JSON);
- }
-
- private void updateLink(final ODataFormat format, final UpdateType updateType) throws IOException {
- // 1. read what is the link before the test runs
- final URI before = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
-
- // 2. update the link
- ODataLink newLink = client.getObjectFactory().
- newAssociationLink(URI.create(getServiceRoot() + "/CustomerInfo(12)"));
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-10).appendLinksSegment("Info");
-
- ODataLinkUpdateRequest req =
- client.getCUDRequestFactory().getLinkUpdateRequest(uriBuilder.build(), updateType, newLink);
- req.setFormat(format);
-
- ODataLinkOperationResponse res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- URI after = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
- assertNotEquals(before, after);
- assertEquals(newLink.getLink(), after);
-
- // 3. reset back the link value
- newLink = client.getObjectFactory().newAssociationLink(before);
- req = client.getCUDRequestFactory().getLinkUpdateRequest(uriBuilder.build(), updateType, newLink);
- req.setFormat(format);
-
- res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- after = doRetrieveLinkURIs(format, "Info").getLinks().get(0);
- assertEquals(before, after);
- }
-
- @Test
- public void updateXMLLink() throws IOException {
- updateLink(ODataFormat.XML, UpdateType.MERGE);
- updateLink(ODataFormat.XML, UpdateType.PATCH);
- updateLink(ODataFormat.XML, UpdateType.REPLACE);
- }
-
- @Test
- public void updateJSONLink() throws IOException {
- updateLink(ODataFormat.JSON, UpdateType.MERGE);
- updateLink(ODataFormat.JSON, UpdateType.PATCH);
- updateLink(ODataFormat.JSON, UpdateType.REPLACE);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
deleted file mode 100644
index 133e950..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MediaEntityTestITCase.java
+++ /dev/null
@@ -1,189 +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.client.core.it.v3;
-
-import java.io.ByteArrayInputStream;
-import java.io.InputStream;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
-import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
-import org.apache.olingo.client.api.communication.request.streamed.MediaEntityUpdateStreamManager;
-import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.streamed.ODataStreamUpdateRequest;
-import org.apache.olingo.client.api.communication.request.streamed.StreamUpdateStreamManager;
-import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataMediaEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.communication.response.ODataStreamUpdateResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.format.ODataMediaFormat;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotNull;
-
-import org.junit.Test;
-
-public class MediaEntityTestITCase extends AbstractTestITCase {
-
- @Test
- public void read() throws Exception {
- final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
- retrieveReq.setFormat(ODataMediaFormat.WILDCARD);
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- final byte[] actual = new byte[Integer.parseInt(retrieveRes.getHeader("Content-Length").iterator().next())];
- IOUtils.read(retrieveRes.getBody(), actual, 0, actual.length);
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void readWithXmlError() throws Exception {
- final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
- retrieveReq.setFormat(ODataMediaFormat.APPLICATION_XML);
-
- retrieveReq.execute();
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void readWithJsonError() throws Exception {
- final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(12).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
- retrieveReq.setFormat(ODataMediaFormat.APPLICATION_JSON);
-
- retrieveReq.execute();
- }
-
- @Test
- public void updateMediaEntityAsAtom() throws Exception {
- updateMediaEntity(ODataPubFormat.ATOM, 14);
- }
-
- @Test
- public void updateMediaEntityAsJson() throws Exception {
- updateMediaEntity(ODataPubFormat.JSON, 15);
- }
-
- @Test
- public void createMediaEntityAsAtom() throws Exception {
- createMediaEntity(ODataPubFormat.ATOM, IOUtils.toInputStream("buffered stream sample"));
- }
-
- @Test
- public void createMediaEntityAsJson() throws Exception {
- createMediaEntity(ODataPubFormat.JSON, IOUtils.toInputStream("buffered stream sample"));
- }
-
- @Test
- public void issue137() throws Exception {
- createMediaEntity(ODataPubFormat.JSON, this.getClass().getResourceAsStream("/sample.png"));
- }
-
- @Test
- public void updateNamedStream() throws Exception {
- URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(16).appendNavigationSegment("Photo");
-
- final String TO_BE_UPDATED = "buffered stream sample";
- final InputStream input = new ByteArrayInputStream(TO_BE_UPDATED.getBytes());
-
- final ODataStreamUpdateRequest updateReq =
- client.getStreamedRequestFactory().getStreamUpdateRequest(builder.build(), input);
-
- final StreamUpdateStreamManager streamManager = updateReq.execute();
- final ODataStreamUpdateResponse updateRes = streamManager.getResponse();
- updateRes.close();
- assertEquals(204, updateRes.getStatusCode());
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
- assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
- }
-
- private void updateMediaEntity(final ODataPubFormat format, final int id) throws Exception {
- URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
-
- final String TO_BE_UPDATED = "new buffered stream sample";
- final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
-
- final ODataMediaEntityUpdateRequest<ODataEntity> updateReq =
- client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input);
- updateReq.setFormat(format);
-
- final MediaEntityUpdateStreamManager<ODataEntity> streamManager = updateReq.execute();
- final ODataMediaEntityUpdateResponse<ODataEntity> updateRes = streamManager.getResponse();
- assertEquals(204, updateRes.getStatusCode());
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
- assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
- }
-
- private void createMediaEntity(final ODataPubFormat format, final InputStream input) throws Exception {
- final URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car");
-
- final ODataMediaEntityCreateRequest<ODataEntity> createReq =
- client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
- createReq.setFormat(format);
-
- final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute();
- final ODataMediaEntityCreateResponse<ODataEntity> createRes = streamManager.getResponse();
- assertEquals(201, createRes.getStatusCode());
-
- final ODataEntity created = createRes.getBody();
- assertNotNull(created);
- assertEquals(2, created.getProperties().size());
-
- Integer id = null;
- for (ODataProperty prop : created.getProperties()) {
- if ("VIN".equals(prop.getName())) {
- id = prop.getPrimitiveValue().toCastValue(Integer.class);
- }
- }
- assertNotNull(id);
-
- builder.appendKeySegment(id).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
- assertNotNull(retrieveRes.getBody());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MetadataTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MetadataTestITCase.java
deleted file mode 100644
index a26bfb0..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/MetadataTestITCase.java
+++ /dev/null
@@ -1,41 +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.client.core.it.v3;
-
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.client.core.it.AbstractMetadataTestITCase;
-import org.apache.olingo.commons.api.edm.Edm;
-import static org.junit.Assert.assertNotNull;
-import org.junit.Test;
-
-public class MetadataTestITCase extends AbstractMetadataTestITCase {
-
- @Override
- protected ODataClient getClient() {
- return ODataClientFactory.getV3();
- }
-
- @Test
- public void retrieve() {
- final Edm metadata = getClient().getRetrieveRequestFactory().
- getMetadataRequest(getTestServiceRoot()).execute().getBody();
- assertNotNull(metadata);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
deleted file mode 100644
index e15588d..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/OpenTypeTestITCase.java
+++ /dev/null
@@ -1,178 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Calendar;
-import java.util.UUID;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmSchema;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class OpenTypeTestITCase extends AbstractTestITCase {
-
- @Test
- public void checkOpenTypeEntityTypesExist() {
- final Edm metadata = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
-
- final EdmSchema schema = metadata.getSchemas().get(0);
-
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "Row")).isOpenType());
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "IndexedRow")).isOpenType());
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
- }
-
- private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
- final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
- return read(format, builder.build());
- }
-
- private void read(final ODataPubFormat format) {
- ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
- assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
-
- row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
- assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
- }
-
- @Test
- public void readAsAtom() {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readAsJSON() {
- read(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void cud(final ODataPubFormat format) {
- final Integer id = 1426;
-
- ODataEntity rowIndex = getClient().getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesService.RowIndex"));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("Id",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aString",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aBoolean",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(true)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aDouble",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.5D)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aByte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
- build()));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTime).setValue(Calendar.getInstance()).
- build()));
-
- final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTime).setText("2001-04-05T05:05:04.001").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Time).setText("-P9DT51M10.5063807S").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("SignedByte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Double",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(Double.MAX_VALUE)));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Single",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(Float.MAX_VALUE)));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Short",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Int",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(Integer.MAX_VALUE)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newComplexProperty("aContact", contactDetails));
-
- final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
- getEntityCreateRequest(getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("RowIndex").build(), rowIndex);
- createReq.setFormat(format);
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
-
- final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("RowIndex").appendKeySegment(id);
- rowIndex = read(format, builder.build());
- assertNotNull(rowIndex);
- assertEquals(EdmPrimitiveTypeKind.Int32,
- rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.String,
- rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.Boolean,
- rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
- assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue());
- assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue());
- assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue());
- assertTrue(rowIndex.getProperty("aContact").hasComplexValue());
- assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue());
-
- final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
- getDeleteRequest(rowIndex.getEditLink()).execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-
- @Test
- public void cudAsAtom() {
- cud(ODataPubFormat.ATOM);
- }
-
- @Test
- public void cudAsJSON() {
- cud(ODataPubFormat.JSON_FULL_METADATA);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
deleted file mode 100644
index d4ecbab..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PrimitiveKeysTestITCase.java
+++ /dev/null
@@ -1,70 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.math.BigDecimal;
-import java.util.UUID;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-
-import org.junit.Test;
-
-public class PrimitiveKeysTestITCase extends AbstractTestITCase {
-
- private void readEntity(final String entityType, final Object key, final ODataPubFormat format) {
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment(entityType).
- appendKeySegment(key).
- build());
- req.setFormat(format);
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertNotNull(entity.getProperty("Id"));
- }
-
- private void readPrimitiveKeys(final ODataPubFormat format) {
- readEntity("EdmBooleanSet", Boolean.TRUE, format);
- readEntity("EdmByteSet", 255, format);
- readEntity("EdmDecimalSet", new BigDecimal("79228162514264337593543950335"), format);
- readEntity("EdmDoubleSet", 1.7976931348623157E+308D, format);
- readEntity("EdmSingleSet", 3.4028235E+38F, format);
- readEntity("EdmGuidSet", UUID.fromString("00000000-0000-0000-0000-000000000000"), format);
- readEntity("EdmInt16Set", 32767, format);
- readEntity("EdmInt32Set", -2147483648, format);
- readEntity("EdmInt64Set", 9223372036854775807L, format);
- readEntity("EdmStringSet", "$", format);
- }
-
- @Test
- public void readEntityAsAtom() {
- readPrimitiveKeys(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readEntityAsJSON() {
- readPrimitiveKeys(ODataPubFormat.JSON_FULL_METADATA);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyRetrieveTestITCase.java
deleted file mode 100644
index 59eaef8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyRetrieveTestITCase.java
+++ /dev/null
@@ -1,281 +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.client.core.it.v3;
-
-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;
-
-import java.util.List;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.junit.Test;
-
-public class PropertyRetrieveTestITCase extends AbstractTestITCase {
-
- private void retrievePropertyTest(final ODataFormat format, String entitySegment, String structuralSegment) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment(entitySegment).appendPropertySegment(structuralSegment);
- final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- req.setFormat(format);
- try {
- final ODataProperty property = req.execute().getBody();
- assertNotNull(property);
- if (property.hasNullValue()) {
- assertNull(property.getValue());
- } else if (property.hasPrimitiveValue()) {
- final ODataPrimitiveValue value = property.getPrimitiveValue();
- assertTrue(value.isPrimitive());
- } else if (property.hasComplexValue()) {
- final ODataComplexValue value = property.getComplexValue();
- assertTrue(value.isComplex());
- } else if (property.hasCollectionValue()) {
- final ODataCollectionValue value = property.getCollectionValue();
- assertTrue(value.isCollection());
- }
- } catch (ODataClientErrorException e) {
- if (e.getStatusLine().getStatusCode() != 404 && e.getStatusLine().getStatusCode() != 400) {
- fail(e.getMessage());
- }
- }
- }
- //test with json header
-
- @Test
- public void jsonRetrieveProperty() {
- //Primitive types
- retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.JSON, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.JSON, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of Complex types
- retrievePropertyTest(ODataFormat.JSON, "Customer(-10)", "BackupContactInfo");
- //Collection of primitives
- retrievePropertyTest(ODataFormat.JSON, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //complex types
- retrievePropertyTest(ODataFormat.JSON, "Order(-9)", "Concurrency");
- }
- //test with json full metadata
-
- @Test
- public void jsonFullMetadataRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of Complex types
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)", "BackupContactInfo");
- //Collection of primitives
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //Complex types
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Order(-9)", "Concurrency");
- }
- // json with no metadata
-
- @Test
- public void jsonNoMetadataRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of Complex types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "BackupContactInfo");
- //Collection of Primitives
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //Complex types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Order(-9)", "Concurrency");
-
- }
- // json with minimla metadata
-
- @Test
- public void jsonmininalRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of complex types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)", "BackupContactInfo");
- //Collection of primitives
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //Complex types
- retrievePropertyTest(ODataFormat.JSON_NO_METADATA, "Order(-9)", "Concurrency");
- }
- // with xml header
-
- @Test
- public void xmlRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of Complex types
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "BackupContactInfo");
- //Collection of primitives
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //Complex types
- retrievePropertyTest(ODataFormat.XML, "Order(-9)", "Concurrency");
- }
- // with atom header
-
- @Test
- public void atomRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "Name");
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "CustomerId");
- retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "Sent");
- retrievePropertyTest(ODataFormat.XML, "Message(FromUsername='1',MessageId=-10)", "IsRead");
- //Collection of Complex types
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)", "BackupContactInfo");
- //Collection of primitives
- retrievePropertyTest(ODataFormat.XML, "Customer(-10)/PrimaryContactInfo", "EmailBag");
- //complex types
- retrievePropertyTest(ODataFormat.XML, "Order(-9)", "Concurrency");
- }
- // with invalid structural segment
-
- @Test
- public void invalidSegmentRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.XML, "Customers(-10)", "Name");
-
- }
- // with null pub format
-
- @Test
- public void nullSegmentRetrieveProperty() {
- //primitive types
- retrievePropertyTest(null, "Customers(-10)", "Name");
-
- }
- // with null accept header format
-
- @Test
- public void nullAcceptRetrieveProperty() {
- //primitive types
- retrievePropertyTest(ODataFormat.XML, "Customers(-10)", "Name");
-
- }
- // with json pub format and atom accept format
-
- @Test
- public void differentFormatAndAcceptRetrieveProperty() {
- //
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Customers(-10)", "Name");
-
- }
- //bad request 400 error. Message takes two keys
-
- @Test
- public void badRequestTest() {
- //primitive types
- retrievePropertyTest(ODataFormat.JSON_FULL_METADATA, "Message(FromUsername='1')", "Sent");
- }
- //navigation link of stream
-
- @Test
- public void navigationMediaLink() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setAccept("application/json");
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- assertEquals(200, res.getStatusCode());
- final ODataEntitySet entitySet = res.getBody();
- assertNotNull(entitySet);
- final List<? extends CommonODataEntity> entity = entitySet.getEntities();
- assertNotNull(entity);
- assertEquals(entity.size(), 2);
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)",
- entity.get(0).getProperties().get(0).getValue().toString());
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)",
- entity.get(1).getProperties().get(0).getValue().toString());
- for (int i = 0; i < entity.size(); i++) {
- assertNotNull(entity.get(0).getProperties().get(0).getValue());
- }
- }
- //navigation link of stream, Bad Request(404 error). 'Photo' is not a valid navigation link
-
- @Test
- public void navigationMediaLinkInvalidQuery() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photo");
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setAccept("application/json");
- try {
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- assertEquals(200, res.getStatusCode());
- ODataEntitySet entitySet = res.getBody();
- assertNotNull(entitySet);
- final List<? extends CommonODataEntity> entity = entitySet.getEntities();
- assertNotNull(entity);
- assertEquals(entity.size(), 2);
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
- getProperties().get(0).getValue().toString());
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
- getProperties().get(0).getValue().toString());
- } catch (ODataClientErrorException e) {
- assertEquals(404, e.getStatusLine().getStatusCode());
- }
- }
-
- @Test
- public void navigationMediaLinkInvalidFormat() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setAccept("application/atom+xml");
- try {
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- assertEquals(200, res.getStatusCode());
- final ODataEntitySet entitySet = res.getBody();
- assertNotNull(entitySet);
- final List<ODataEntity> entity = entitySet.getEntities();
- assertNotNull(entity);
- assertEquals(entity.size(), 2);
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
- getProperties().get(0).getValue().toString());
- assertEquals(testStaticServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
- getProperties().get(0).getValue().toString());
- } catch (ODataClientErrorException e) {
- assertEquals(415, e.getStatusLine().getStatusCode());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
deleted file mode 100644
index 2bdc18f..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyTestITCase.java
+++ /dev/null
@@ -1,360 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataValueUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRawResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.communication.response.ODataValueUpdateResponse;
-import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.format.ODataValueFormat;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check basic entity operations.
- */
-public class PropertyTestITCase extends AbstractTestITCase {
-
- protected String getServiceRoot() {
- return testStaticServiceRootURL;
- }
-
- @Test
- public void replacePropertyValue() throws Exception {
- updatePropertyValue(ODataValueFormat.TEXT, UpdateType.REPLACE);
- }
-
- @Test
- public void replacePrimitivePropertyAsXML() throws IOException, EdmPrimitiveTypeException {
- updatePrimitiveProperty(ODataFormat.XML);
- }
-
- @Test
- public void replacePrimitivePropertyAsJSON() throws IOException, EdmPrimitiveTypeException {
- updatePrimitiveProperty(ODataFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void replaceCollectionPropertyAsXML() throws IOException {
- updateCollectionProperty(ODataFormat.XML);
- }
-
- @Test
- public void replaceCollectionPropertyAsJSON() throws IOException {
- updateCollectionProperty(ODataFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void replaceComplexPropertyAsXML() throws IOException {
- updateComplexProperty(ODataFormat.XML, UpdateType.REPLACE);
- }
-
- @Test
- public void replaceComplexPropertyAsJSON() throws IOException {
- updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.REPLACE);
- }
-
- @Test
- public void patchComplexPropertyAsXML() throws IOException {
- updateComplexProperty(ODataFormat.XML, UpdateType.PATCH);
- }
-
- @Test
- public void patchComplexPropertyAsJSON() throws IOException {
- updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH);
- }
-
- @Test
- public void mergeComplexPropertyAsXML() throws IOException {
- updateComplexProperty(ODataFormat.XML, UpdateType.MERGE);
- }
-
- @Test
- public void mergeComplexPropertyAsJSON() throws IOException {
- updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.MERGE);
- }
-
- @Test
- public void rawRequestAsXML() throws IOException {
- rawRequest(ODataFormat.XML);
- }
-
- @Test
- public void rawRequestAsJSON() throws IOException {
- rawRequest(ODataFormat.JSON);
- }
-
- @Test
- public void readCountValue() throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").count();
-
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
-
- final ODataRetrieveResponse<ODataPrimitiveValue> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataPrimitiveValue value = res.getBody();
- debugODataValue(value, "Retrieved property");
-
- assertNotNull(value);
- // the following assert depends on the test execution order (use >= to be sure)
- assertTrue(Integer.valueOf(value.toString()) >= 10);
- }
-
- @Test
- public void nullNullableProperty() {
- final ODataDeleteResponse res = client.getCUDRequestFactory().getDeleteRequest(client.getURIBuilder(
- getServiceRoot()).
- appendEntitySetSegment("Order").appendKeySegment(-8).
- appendPropertySegment("CustomerId").appendValueSegment().build()).
- execute();
- assertEquals(204, res.getStatusCode());
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void nullNonNullableProperty() {
- client.getCUDRequestFactory().getDeleteRequest(client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Driver").appendKeySegment("1").
- appendPropertySegment("BirthDate").appendValueSegment().build()).
- execute();
- }
-
- private void updatePropertyValue(final ODataValueFormat format, final UpdateType type)
- throws IOException, EdmPrimitiveTypeException {
-
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-9).
- appendPropertySegment("PrimaryContactInfo").
- appendPropertySegment("HomePhone").
- appendPropertySegment("PhoneNumber").
- appendValueSegment();
-
- ODataValueRequest retrieveReq = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- ODataRetrieveResponse<ODataPrimitiveValue> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- ODataPrimitiveValue phoneNumber = retrieveRes.getBody();
- assertNotNull(phoneNumber);
-
- final String oldMsg = phoneNumber.toCastValue(String.class);
- final String newMsg = "new msg (" + System.currentTimeMillis() + ")";
-
- assertNotEquals(newMsg, oldMsg);
-
- final ODataPrimitiveValue newVal = client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build();
-
- final ODataValueUpdateRequest updateReq =
- client.getCUDRequestFactory().getValueUpdateRequest(uriBuilder.build(), type, newVal);
- updateReq.setFormat(format);
-
- final ODataValueUpdateResponse updateRes = updateReq.execute();
- assertEquals(204, updateRes.getStatusCode());
-
- retrieveReq = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- phoneNumber = retrieveRes.getBody();
- assertNotNull(phoneNumber);
-
- assertEquals(newMsg, phoneNumber.asPrimitive().toCastValue(String.class));
- }
-
- private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-9).appendPropertySegment("PrimaryContactInfo");
-
- ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- ODataProperty primaryContactInfo = client.getObjectFactory().
- newComplexProperty("PrimaryContactInfo", retrieveRes.getBody().getComplexValue());
-
- final String newItem = "new item " + System.currentTimeMillis();
-
- final ODataCollectionValue<ODataValue> originalValue =
- primaryContactInfo.getComplexValue().get("EmailBag").getCollectionValue();
-
- final int origSize = originalValue.size();
-
- originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
- assertEquals(origSize + 1, originalValue.size());
-
- final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
- getPropertyComplexValueUpdateRequest(uriBuilder.build(), type, primaryContactInfo);
- if (client.getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, updateReq.getMethod());
- } else {
- assertEquals(type.getMethod(), updateReq.getMethod());
- }
- updateReq.setFormat(format);
-
- final ODataPropertyUpdateResponse updateRes = updateReq.execute();
- assertEquals(204, updateRes.getStatusCode());
-
- retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- primaryContactInfo = retrieveRes.getBody();
-
- assertEquals(origSize + 1, primaryContactInfo.getComplexValue().get("EmailBag").getCollectionValue().size());
- }
-
- private void updateCollectionProperty(final ODataFormat format) throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-10).
- appendPropertySegment("PrimaryContactInfo").appendPropertySegment("AlternativeNames");
-
- ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- ODataProperty alternativeNames = client.getObjectFactory().newCollectionProperty("AlternativeNames",
- retrieveRes.getBody().getCollectionValue());
-
- final String newItem = "new item " + System.currentTimeMillis();
-
- final ODataCollectionValue<ODataValue> originalValue = alternativeNames.getCollectionValue();
-
- final int origSize = originalValue.size();
-
- originalValue.add(client.getObjectFactory().newPrimitiveValueBuilder().setText(newItem).build());
- assertEquals(origSize + 1, originalValue.size());
-
- final ODataPropertyUpdateRequest updateReq =
- client.getCUDRequestFactory().getPropertyCollectionValueUpdateRequest(uriBuilder.build(),
- alternativeNames);
- if (client.getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, updateReq.getMethod());
- } else {
- assertEquals(HttpMethod.PUT, updateReq.getMethod());
- }
- updateReq.setFormat(format);
-
- final ODataPropertyUpdateResponse updateRes = updateReq.execute();
- assertEquals(204, updateRes.getStatusCode());
-
- retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- alternativeNames = retrieveRes.getBody();
-
- assertEquals(origSize + 1, alternativeNames.getCollectionValue().size());
- }
-
- private void updatePrimitiveProperty(final ODataFormat format) throws IOException, EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot());
- uriBuilder.appendEntitySetSegment("Customer").appendKeySegment(-9).
- appendPropertySegment("PrimaryContactInfo").
- appendPropertySegment("HomePhone").appendPropertySegment("PhoneNumber");
-
- ODataPropertyRequest<ODataProperty> retrieveReq = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- ODataProperty phoneNumber = retrieveRes.getBody();
-
- final String oldMsg = phoneNumber.getPrimitiveValue().toCastValue(String.class);
- final String newMsg = "new item " + System.currentTimeMillis();
-
- assertNotEquals(newMsg, oldMsg);
-
- phoneNumber = client.getObjectFactory().newPrimitiveProperty("PhoneNumber",
- client.getObjectFactory().newPrimitiveValueBuilder().setText(newMsg).build());
-
- final ODataPropertyUpdateRequest updateReq =
- client.getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uriBuilder.build(), phoneNumber);
- if (client.getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, updateReq.getMethod());
- } else {
- assertEquals(HttpMethod.PUT, updateReq.getMethod());
- }
- updateReq.setFormat(format);
-
- ODataPropertyUpdateResponse updateRes = updateReq.execute();
- assertEquals(204, updateRes.getStatusCode());
-
- retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- phoneNumber = retrieveRes.getBody();
- assertEquals(newMsg, phoneNumber.getPrimitiveValue().toCastValue(String.class));
- }
-
- private void rawRequest(final ODataFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(getServiceRoot()).
- appendEntitySetSegment("Customer").appendKeySegment(-10).appendPropertySegment("BackupContactInfo");
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataProperty> property = res.getBodyAs(ODataProperty.class);
- assertNotNull(property.getPayload());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyValueTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyValueTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyValueTestITCase.java
deleted file mode 100644
index 02a964d..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/PropertyValueTestITCase.java
+++ /dev/null
@@ -1,166 +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.client.core.it.v3;
-
-import java.io.IOException;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.format.ODataValueFormat;
-import static org.junit.Assert.*;
-import org.junit.Test;
-
-public class PropertyValueTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveIntPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment("ProductId").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- assertNotNull(value);
- assertEquals(-10, Integer.parseInt(value.toString()));
- }
-
- @Test
- public void retrieveBooleanPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment("ProductId").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- assertNotNull(value);
- assertEquals(-10, Integer.parseInt(value.toString()));
- }
-
- @Test
- public void retrieveStringPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-6).appendPropertySegment("Description").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- assertNotNull(value);
- assertEquals("expdybhclurfobuyvzmhkgrnrajhamqmkhqpmiypittnp", value.toString());
- }
-
- @Test
- public void retrieveDatePropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-7).appendPropertySegment(
- "NestedComplexConcurrency/ModifiedDate").appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- assertNotNull(value);
- assertEquals("7866-11-16T22:25:52.747755+01:00", value.toString());
- }
-
- @Test
- public void retrieveDecimalPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-6).appendPropertySegment("Dimensions/Height").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- assertNotNull(value);
- assertEquals("-79228162514264337593543950335", value.toString());
- }
-
- @Test
- public void retrieveBinaryPropertyValueTest() throws IOException {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setAccept("application/json");
- ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
- + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
- entity.getProperties().get(0).getValue().toString());
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void retrieveBinaryPropertyValueTestWithAtom() throws IOException {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setAccept("application/atom+xml");
- ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- ODataEntity entitySet = res.getBody();
- assertNotNull(entitySet);
- assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
- + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
- entitySet.getProperties().get(0).getValue().toString());
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void retrieveBinaryPropertyValueTestWithXML() throws IOException {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendNavigationSegment("ProductPhoto(PhotoId=-3,ProductId=-3)").appendPropertySegment("Photo");
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setAccept("application/xml");
- ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
- ODataEntity entitySet = res.getBody();
- assertNotNull(entitySet);
- assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
- + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=",
- entitySet.getProperties().get(0).getValue().toString());
- }
-
- @Test
- public void retrieveCollectionPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-7).appendPropertySegment(
- "ComplexConcurrency/QueriedDateTime").appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataValue value = req.execute().getBody();
- if (value.isPrimitive()) {
- assertNotNull(value);
- assertEquals("2013-09-18T00:44:43.6196168", value.toString());
- }
- }
-
- @Test
- public void retrieveNullPropertyValueTest() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).appendPropertySegment(
- "ComplexConcurrency/Token").appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- try {
- req.execute().getBody();
- } catch (ODataClientErrorException e) {
- assertEquals(404, e.getStatusLine().getStatusCode());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
deleted file mode 100644
index a00f057..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/QueryOptionsTestITCase.java
+++ /dev/null
@@ -1,202 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.api.uri.v3.URIBuilder.InlineCount;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check for query options.
- */
-public class QueryOptionsTestITCase extends AbstractTestITCase {
-
- /**
- * Test <tt>$expand</tt>.
- *
- * @see EntityRetrieveTest#readODataEntityWithInline(org.apache.olingo.commons.api.format.ODataPubFormat)
- */
- public void expand() {
- // empty
- }
-
- /**
- * Test <tt>$filter</tt> and <tt>orderby</tt>.
- *
- * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
- */
- @Test
- public void filterOrderby() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").filter("(VIN lt 16)");
-
- // 1. check that filtered entity set looks as expected
- ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(5, feed.getEntities().size());
-
- // 2. extract VIN values - sorted ASC by default
- final List<Integer> vinsASC = new ArrayList<Integer>(5);
- for (ODataEntity entity : feed.getEntities()) {
- final Integer vin = entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class);
- assertTrue(vin < 16);
- vinsASC.add(vin);
- }
-
- // 3. add orderby clause to filter above
- req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("VIN desc").build());
- feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(5, feed.getEntities().size());
-
- // 4. extract again VIN value - now they were required to be sorted DESC
- final List<Integer> vinsDESC = new ArrayList<Integer>(5);
- for (ODataEntity entity : feed.getEntities()) {
- vinsDESC.add(entity.getProperty("VIN").getPrimitiveValue().toCastValue(Integer.class));
- }
-
- // 5. reverse vinsASC and expect to be equal to vinsDESC
- Collections.reverse(vinsASC);
- assertEquals(vinsASC, vinsDESC);
- }
-
- /**
- * Test <tt>$format</tt>.
- */
- @Test
- public void format() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(-10).format("json");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.ATOM);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertNotNull(res);
- assertTrue(res.getContentType().replaceAll(" ", "").
- startsWith(ODataPubFormat.JSON.toString(client.getServiceVersion())));
- }
-
- /**
- * Test <tt>$skip</tt>.
- *
- * @see FeedTest#readFeedWithNextLink(org.apache.olingo.commons.api.format.ODataPubFormat)
- */
- public void skip() {
- // empty
- }
-
- /**
- * Test <tt>$top</tt>.
- *
- * @see FeedTest#readFeed(org.apache.olingo.commons.api.format.ODataPubFormat)
- */
- public void top() {
- // empty
- }
-
- /**
- * Test <tt>$skiptoken</tt>.
- */
- @Test
- public void skiptoken() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("Customer").skipToken("-10");
-
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- final ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(2, feed.getEntities().size());
-
- for (ODataEntity entity : feed.getEntities()) {
- assertTrue(entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class) > -10);
- }
- }
-
- /**
- * Test <tt>$inlinecount</tt>.
- */
- @Test
- public void inlinecount() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car").
- inlineCount(InlineCount.allpages);
-
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.ATOM);
- final ODataEntitySet feed = req.execute().getBody();
- assertNotNull(feed);
- assertEquals(feed.getEntities().size(), feed.getCount());
- }
-
- /**
- * Test <tt>$select</tt>.
- */
- @Test
- public void select() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(-10).select("CustomerId,Orders").expand("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- final ODataEntity customer = req.execute().getBody();
- assertEquals(1, customer.getProperties().size());
- assertEquals(1, customer.getNavigationLinks().size());
- assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
- }
-
- @Test
- public void issue131() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(-7).select("Name");
-
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.ATOM);
-
- final ODataEntity customer = req.execute().getBody();
- assertEquals(0, customer.getProperties().size());
-
- req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.ATOM);
-
- final Entity atomEntry =
- client.getDeserializer().toEntity(req.execute().getRawResponse(), ODataPubFormat.ATOM).getPayload();
- assertEquals("remotingdestructorprinterswitcheschannelssatellitelanguageresolve",
- ((AtomEntityImpl) atomEntry).getSummary());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ServiceDocumentTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ServiceDocumentTestITCase.java
deleted file mode 100644
index 0a5aefc..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ServiceDocumentTestITCase.java
+++ /dev/null
@@ -1,56 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.commons.api.domain.ODataServiceDocument;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.junit.Test;
-
-public class ServiceDocumentTestITCase extends AbstractTestITCase {
-
- private void retrieveServiceDocument(final ODataFormat format) {
- final ODataServiceDocumentRequest req =
- client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataServiceDocument serviceDocument = res.getBody();
- assertEquals(24, serviceDocument.getEntitySetTitles().size());
-
- assertEquals(URI.create(testStaticServiceRootURL + "/ComputerDetail"),
- serviceDocument.getEntitySetURI("ComputerDetail"));
- }
-
- @Test
- public void retrieveServiceDocumentAsXML() {
- retrieveServiceDocument(ODataFormat.XML);
- }
-
- @Test
- public void retrieveServiceDocumentAsJSON() {
- retrieveServiceDocument(ODataFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodEntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodEntityUpdateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodEntityUpdateTestITCase.java
deleted file mode 100644
index 478840f..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodEntityUpdateTestITCase.java
+++ /dev/null
@@ -1,38 +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.client.core.it.v3;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-/**
- * Performs entity update tests using the X-HTTP-METHOD header.
- */
-public class XHTTPMethodEntityUpdateTestITCase extends EntityUpdateTestITCase {
-
- @BeforeClass
- public static void enableXHTTPMethod() {
- client.getConfiguration().setUseXHTTPMethod(true);
- }
-
- @AfterClass
- public static void disableXHTTPMethod() {
- client.getConfiguration().setUseXHTTPMethod(false);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodPropertyUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodPropertyUpdateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodPropertyUpdateTestITCase.java
deleted file mode 100644
index 7a29059..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/XHTTPMethodPropertyUpdateTestITCase.java
+++ /dev/null
@@ -1,38 +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.client.core.it.v3;
-
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-/**
- * Performs property update tests using the X-HTTP-METHOD header.
- */
-public class XHTTPMethodPropertyUpdateTestITCase extends PropertyTestITCase {
-
- @BeforeClass
- public static void enableXHTTPMethod() {
- client.getConfiguration().setUseXHTTPMethod(true);
- }
-
- @AfterClass
- public static void disableXHTTPMethod() {
- client.getConfiguration().setUseXHTTPMethod(false);
- }
-}
[11/11] git commit: [OLINGO-236] Refactor complete
Posted by il...@apache.org.
[OLINGO-236] Refactor complete
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/8042913b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/8042913b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/8042913b
Branch: refs/heads/master
Commit: 8042913be1aa52477635f7abbcc4cd0423151a7b
Parents: 6c7aef9
Author: Francesco Chicchiriccò <il...@apache.org>
Authored: Tue Apr 29 11:46:27 2014 +0200
Committer: Francesco Chicchiriccò <il...@apache.org>
Committed: Tue Apr 29 11:46:27 2014 +0200
----------------------------------------------------------------------
fit/pom.xml | 62 +-
.../olingo/fit/AbstractBaseTestITCase.java | 98 +++
.../olingo/fit/AbstractMetadataTestITCase.java | 35 +
.../olingo/fit/v3/AbstractTestITCase.java | 516 ++++++++++++++
.../fit/v3/ActionOverloadingTestITCase.java | 181 +++++
.../apache/olingo/fit/v3/AsyncTestITCase.java | 134 ++++
.../fit/v3/AuthEntityRetrieveTestITCase.java | 42 ++
.../apache/olingo/fit/v3/BatchTestITCase.java | 444 ++++++++++++
.../apache/olingo/fit/v3/CountTestITCase.java | 60 ++
.../olingo/fit/v3/EntityCreateTestITCase.java | 484 +++++++++++++
.../olingo/fit/v3/EntityRetrieveTestITCase.java | 242 +++++++
.../olingo/fit/v3/EntitySetTestITCase.java | 176 +++++
.../olingo/fit/v3/EntityUpdateTestITCase.java | 242 +++++++
.../apache/olingo/fit/v3/ErrorTestITCase.java | 172 +++++
.../olingo/fit/v3/FilterFactoryTestITCase.java | 167 +++++
.../apache/olingo/fit/v3/FilterTestITCase.java | 94 +++
.../apache/olingo/fit/v3/InvokeTestITCase.java | 318 +++++++++
.../olingo/fit/v3/KeyAsSegmentTestITCase.java | 110 +++
.../apache/olingo/fit/v3/LinkTestITCase.java | 177 +++++
.../olingo/fit/v3/MediaEntityTestITCase.java | 189 +++++
.../olingo/fit/v3/MetadataTestITCase.java | 41 ++
.../olingo/fit/v3/OpenTypeTestITCase.java | 178 +++++
.../olingo/fit/v3/PrimitiveKeysTestITCase.java | 70 ++
.../fit/v3/PropertyRetrieveTestITCase.java | 281 ++++++++
.../olingo/fit/v3/PropertyTestITCase.java | 360 ++++++++++
.../olingo/fit/v3/PropertyValueTestITCase.java | 166 +++++
.../olingo/fit/v3/QueryOptionsTestITCase.java | 202 ++++++
.../fit/v3/ServiceDocumentTestITCase.java | 56 ++
.../v3/XHTTPMethodEntityUpdateTestITCase.java | 38 +
.../v3/XHTTPMethodPropertyUpdateTestITCase.java | 38 +
.../olingo/fit/v4/AbstractTestITCase.java | 132 ++++
.../apache/olingo/fit/v4/AsyncTestITCase.java | 166 +++++
.../apache/olingo/fit/v4/BatchTestITCase.java | 710 +++++++++++++++++++
.../fit/v4/BoundOperationInvokeTestITCase.java | 339 +++++++++
.../apache/olingo/fit/v4/DeltaTestITCase.java | 86 +++
.../olingo/fit/v4/EntityCreateTestITCase.java | 186 +++++
.../olingo/fit/v4/EntityRetrieveTestITCase.java | 367 ++++++++++
.../olingo/fit/v4/EntitySetTestITCase.java | 179 +++++
.../olingo/fit/v4/EntityUpdateTestITCase.java | 154 ++++
.../olingo/fit/v4/FilterFactoryTestITCase.java | 63 ++
.../olingo/fit/v4/KeyAsSegmentTestITCase.java | 122 ++++
.../olingo/fit/v4/MetadataTestITCase.java | 71 ++
.../olingo/fit/v4/OpenTypeTestITCase.java | 188 +++++
.../fit/v4/OperationImportInvokeTestITCase.java | 258 +++++++
.../olingo/fit/v4/PropertyTestITCase.java | 164 +++++
.../olingo/fit/v4/PropertyValueTestITCase.java | 147 ++++
.../olingo/fit/v4/QueryOptionsTestITCase.java | 215 ++++++
.../fit/v4/ServiceDocumentTestITCase.java | 62 ++
fit/src/test/resources/sample.png | Bin 0 -> 25566 bytes
lib/client-core/pom.xml | 45 --
.../client/core/it/AbstractBaseTestITCase.java | 98 ---
.../core/it/AbstractMetadataTestITCase.java | 35 -
.../client/core/it/v3/AbstractTestITCase.java | 516 --------------
.../core/it/v3/ActionOverloadingTestITCase.java | 181 -----
.../client/core/it/v3/AsyncTestITCase.java | 134 ----
.../it/v3/AuthEntityRetrieveTestITCase.java | 42 --
.../client/core/it/v3/BatchTestITCase.java | 444 ------------
.../client/core/it/v3/CountTestITCase.java | 60 --
.../core/it/v3/EntityCreateTestITCase.java | 484 -------------
.../core/it/v3/EntityRetrieveTestITCase.java | 242 -------
.../client/core/it/v3/EntitySetTestITCase.java | 176 -----
.../core/it/v3/EntityUpdateTestITCase.java | 242 -------
.../client/core/it/v3/ErrorTestITCase.java | 172 -----
.../core/it/v3/FilterFactoryTestITCase.java | 167 -----
.../client/core/it/v3/FilterTestITCase.java | 94 ---
.../client/core/it/v3/InvokeTestITCase.java | 318 ---------
.../core/it/v3/KeyAsSegmentTestITCase.java | 110 ---
.../client/core/it/v3/LinkTestITCase.java | 177 -----
.../core/it/v3/MediaEntityTestITCase.java | 189 -----
.../client/core/it/v3/MetadataTestITCase.java | 41 --
.../client/core/it/v3/OpenTypeTestITCase.java | 178 -----
.../core/it/v3/PrimitiveKeysTestITCase.java | 70 --
.../core/it/v3/PropertyRetrieveTestITCase.java | 281 --------
.../client/core/it/v3/PropertyTestITCase.java | 360 ----------
.../core/it/v3/PropertyValueTestITCase.java | 166 -----
.../core/it/v3/QueryOptionsTestITCase.java | 202 ------
.../core/it/v3/ServiceDocumentTestITCase.java | 56 --
.../v3/XHTTPMethodEntityUpdateTestITCase.java | 38 -
.../v3/XHTTPMethodPropertyUpdateTestITCase.java | 38 -
.../client/core/it/v4/AbstractTestITCase.java | 132 ----
.../client/core/it/v4/AsyncTestITCase.java | 166 -----
.../client/core/it/v4/BatchTestITCase.java | 710 -------------------
.../it/v4/BoundOperationInvokeTestITCase.java | 339 ---------
.../client/core/it/v4/DeltaTestITCase.java | 88 ---
.../core/it/v4/EntityCreateTestITCase.java | 186 -----
.../core/it/v4/EntityRetrieveTestITCase.java | 367 ----------
.../client/core/it/v4/EntitySetTestITCase.java | 179 -----
.../core/it/v4/EntityUpdateTestITCase.java | 154 ----
.../core/it/v4/FilterFactoryTestITCase.java | 63 --
.../core/it/v4/KeyAsSegmentTestITCase.java | 122 ----
.../client/core/it/v4/MetadataTestITCase.java | 71 --
.../client/core/it/v4/OpenTypeTestITCase.java | 188 -----
.../it/v4/OperationImportInvokeTestITCase.java | 258 -------
.../client/core/it/v4/PropertyTestITCase.java | 164 -----
.../core/it/v4/PropertyValueTestITCase.java | 147 ----
.../core/it/v4/QueryOptionsTestITCase.java | 215 ------
.../core/it/v4/ServiceDocumentTestITCase.java | 62 --
lib/client-core/src/test/resources/sample.png | Bin 25566 -> 0 bytes
pom.xml | 40 --
99 files changed, 8971 insertions(+), 9018 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/pom.xml
----------------------------------------------------------------------
diff --git a/fit/pom.xml b/fit/pom.xml
index 699541c..ffbf5cb 100644
--- a/fit/pom.xml
+++ b/fit/pom.xml
@@ -35,7 +35,6 @@
</parent>
<properties>
- <main.basedir>${project.parent.basedir}</main.basedir>
<war.maven.plugin.version>2.4</war.maven.plugin.version>
</properties>
@@ -45,7 +44,7 @@
<artifactId>olingo-commons-core</artifactId>
<version>${project.version}</version>
</dependency>
-
+
<!-- REST services CXF -->
<dependency>
<groupId>org.apache.cxf</groupId>
@@ -91,11 +90,20 @@
<groupId>org.apache.commons</groupId>
<artifactId>commons-vfs2</artifactId>
</dependency>
+
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-client-core</artifactId>
+ <version>${project.version}</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
</dependencies>
<build>
- <defaultGoal>clean package cargo:run</defaultGoal>
-
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
@@ -113,31 +121,47 @@
<packagingExcludes>WEB-INF/classes/esigate.properties,WEB-INF/classes/META-INF/LICENSE*,WEB-INF/classes/META-INF/DEPENDENCIES*</packagingExcludes>
</configuration>
</plugin>
-
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-failsafe-plugin</artifactId>
+ <inherited>true</inherited>
+ <configuration>
+ <systemPropertyVariables>
+ <propertyName>org.slf4j.simpleLogger.defaultLogLevel</propertyName>
+ <org.slf4j.simpleLogger.defaultLogLevel>DEBUG</org.slf4j.simpleLogger.defaultLogLevel>
+ </systemPropertyVariables>
+ </configuration>
+ </plugin>
+
<plugin>
<groupId>org.codehaus.cargo</groupId>
<artifactId>cargo-maven2-plugin</artifactId>
<inherited>true</inherited>
<configuration>
<configuration>
+ <type>standalone</type>
<properties>
- <cargo.jvmargs>-Xdebug -Xrunjdwp:transport=dt_socket,address=8000,server=y,suspend=n
- -noverify -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m</cargo.jvmargs>
+ <cargo.servlet.port>${cargo.servlet.port}</cargo.servlet.port>
+ <cargo.tomcat.ajp.port>${cargo.tomcat.ajp.port}</cargo.tomcat.ajp.port>
+ <cargo.rmi.port>${cargo.rmi.port}</cargo.rmi.port>
+
+ <cargo.jvmargs>-noverify -XX:+CMSClassUnloadingEnabled -XX:+UseConcMarkSweepGC -XX:MaxPermSize=256m</cargo.jvmargs>
</properties>
<files>
<file>
- <file>${project.build.directory}/classes/esigate.properties</file>
+ <file>${project.build.outputDirectory}/esigate.properties</file>
<todir>lib</todir>
</file>
</files>
<configfiles>
<configfile>
- <file>${project.build.directory}/classes/context.xml</file>
+ <file>${project.build.outputDirectory}/context.xml</file>
<todir>conf/</todir>
<tofile>context.xml</tofile>
</configfile>
<configfile>
- <file>${project.build.directory}/classes/tomcat-users.xml</file>
+ <file>${project.build.outputDirectory}/tomcat-users.xml</file>
<todir>conf/</todir>
<tofile>tomcat-users.xml</tofile>
</configfile>
@@ -147,10 +171,26 @@
<deployable>
<properties>
<context>/</context>
- </properties>
+ </properties>
</deployable>
</deployables>
</configuration>
+ <executions>
+ <execution>
+ <id>start-container</id>
+ <phase>pre-integration-test</phase>
+ <goals>
+ <goal>start</goal>
+ </goals>
+ </execution>
+ <execution>
+ <id>stop-container</id>
+ <phase>post-integration-test</phase>
+ <goals>
+ <goal>stop</goal>
+ </goals>
+ </execution>
+ </executions>
</plugin>
</plugins>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
new file mode 100644
index 0000000..e606564
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
@@ -0,0 +1,98 @@
+/*
+ * 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;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.StringWriter;
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.CommonODataClient;
+import org.apache.olingo.commons.api.data.Entity;
+import org.apache.olingo.commons.api.data.EntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.core.data.AtomEntityImpl;
+import org.apache.olingo.commons.core.data.JSONEntityImpl;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+public abstract class AbstractBaseTestITCase {
+
+ /**
+ * Logger.
+ */
+ protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
+
+ @SuppressWarnings("rawtypes")
+ protected abstract CommonODataClient getClient();
+
+ protected void debugEntity(final Entity entity, final String message) {
+ if (LOG.isDebugEnabled()) {
+ final StringWriter writer = new StringWriter();
+ getClient().getSerializer().entity(entity, writer);
+ writer.flush();
+ LOG.debug(message + "\n{}", writer.toString());
+ }
+ }
+
+ protected void debugEntitySet(final EntitySet entitySet, final String message) {
+ if (LOG.isDebugEnabled()) {
+ final StringWriter writer = new StringWriter();
+ getClient().getSerializer().entitySet(entitySet, writer);
+ writer.flush();
+ LOG.debug(message + "\n{}", writer.toString());
+ }
+ }
+
+ protected void debugODataProperty(final CommonODataProperty property, final String message) {
+ LOG.debug(message + "\n{}", property.toString());
+ }
+
+ protected void debugODataValue(final ODataValue value, final String message) {
+ LOG.debug(message + "\n{}", value.toString());
+ }
+
+ protected void debugODataEntity(final CommonODataEntity entity, final String message) {
+ if (LOG.isDebugEnabled()) {
+ StringWriter writer = new StringWriter();
+ getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, AtomEntityImpl.class), writer);
+ writer.flush();
+ LOG.debug(message + " (Atom)\n{}", writer.toString());
+
+ writer = new StringWriter();
+ getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, JSONEntityImpl.class), writer);
+ writer.flush();
+ LOG.debug(message + " (JSON)\n{}", writer.toString());
+ }
+ }
+
+ protected void debugInputStream(final InputStream input, final String message) {
+ if (LOG.isDebugEnabled()) {
+ try {
+ LOG.debug(message + "\n{}", IOUtils.toString(input));
+ } catch (IOException e) {
+ LOG.error("Error writing stream", e);
+ } finally {
+ IOUtils.closeQuietly(input);
+ }
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/AbstractMetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractMetadataTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractMetadataTestITCase.java
new file mode 100644
index 0000000..f9eda5f
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractMetadataTestITCase.java
@@ -0,0 +1,35 @@
+/*
+ * 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;
+
+import org.apache.olingo.client.api.CommonODataClient;
+
+public abstract class AbstractMetadataTestITCase {
+
+ @SuppressWarnings("rawtypes")
+ protected abstract CommonODataClient getClient();
+
+ protected String getTestServiceRoot() {
+ return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/Static.svc";
+ }
+
+ protected String getNorthwindServiceRoot() {
+ return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/NorthWind.svc";
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java
new file mode 100644
index 0000000..d799358
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/AbstractTestITCase.java
@@ -0,0 +1,516 @@
+/*
+ * 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.v3;
+
+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;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.HashSet;
+import java.util.List;
+import java.util.Map;
+import java.util.Set;
+import org.apache.commons.lang3.StringUtils;
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.http.HttpMethod;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.api.v3.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.fit.AbstractBaseTestITCase;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.BeforeClass;
+
+public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
+
+ protected static final FullQualifiedName TEST_PRODUCT_TYPE =
+ new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Product");
+
+ protected static ODataClient client;
+
+ protected static String testStaticServiceRootURL;
+
+ protected static String testKeyAsSegmentServiceRootURL;
+
+ protected static String testActionOverloadingServiceRootURL;
+
+ protected static String testOpenTypeServiceRootURL;
+
+ protected static String testLargeModelServiceRootURL;
+
+ protected static String testAuthServiceRootURL;
+
+ @BeforeClass
+ public static void setUpODataServiceRoot() throws IOException {
+ testStaticServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc";
+ testKeyAsSegmentServiceRootURL = "http://localhost:9080/StaticService/V30/KeyAsSegment.svc";
+ testActionOverloadingServiceRootURL = "http://localhost:9080/StaticService/V30/ActionOverloading.svc";
+ testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V30/OpenType.svc";
+ testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc/large";
+ testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
+ }
+
+ @BeforeClass
+ public static void setClientInstance() {
+ client = ODataClientFactory.getV3();
+ }
+
+ @Override
+ protected ODataClient getClient() {
+ return client;
+ }
+
+ protected void checkLinks(final Collection<ODataLink> original, final Collection<ODataLink> actual) {
+ assertTrue(original.size() <= actual.size());
+
+ for (ODataLink originalLink : original) {
+ ODataLink foundOriginal = null;
+ ODataLink foundActual = null;
+
+ for (ODataLink actualLink : actual) {
+
+ if (actualLink.getType() == originalLink.getType()
+ && (originalLink.getLink() == null
+ || actualLink.getLink().toASCIIString().endsWith(originalLink.getLink().toASCIIString()))
+ && actualLink.getName().equals(originalLink.getName())) {
+
+ foundOriginal = originalLink;
+ foundActual = actualLink;
+ }
+ }
+
+ assertNotNull(foundOriginal);
+ assertNotNull(foundActual);
+
+ if (foundOriginal instanceof ODataInlineEntity && foundActual instanceof ODataInlineEntity) {
+ final CommonODataEntity originalInline = ((ODataInlineEntity) foundOriginal).getEntity();
+ assertNotNull(originalInline);
+
+ final CommonODataEntity actualInline = ((ODataInlineEntity) foundActual).getEntity();
+ assertNotNull(actualInline);
+
+ checkProperties(originalInline.getProperties(), actualInline.getProperties());
+ }
+ }
+ }
+
+ protected void checkProperties(final Collection<? extends CommonODataProperty> original,
+ final Collection<? extends CommonODataProperty> actual) {
+
+ assertTrue(original.size() <= actual.size());
+
+ // re-organize actual properties into a Map<String, ODataProperty>
+ final Map<String, CommonODataProperty> actualProps = new HashMap<String, CommonODataProperty>(actual.size());
+
+ for (CommonODataProperty prop : actual) {
+ assertFalse(actualProps.containsKey(prop.getName()));
+ actualProps.put(prop.getName(), prop);
+ }
+
+ assertTrue(actual.size() <= actualProps.size());
+
+ for (CommonODataProperty prop : original) {
+ assertNotNull(prop);
+ if (actualProps.containsKey(prop.getName())) {
+ final CommonODataProperty actualProp = actualProps.get(prop.getName());
+ assertNotNull(actualProp);
+
+ if (prop.getValue() != null && actualProp.getValue() != null) {
+ checkPropertyValue(prop.getName(), prop.getValue(), actualProp.getValue());
+ }
+ } else {
+ // nothing ... maybe :FC_KeepInContent="false"
+ // ..... no assert can be done ....
+ }
+ }
+ }
+
+ protected void checkPropertyValue(final String propertyName,
+ final ODataValue original, final ODataValue actual) {
+
+ assertNotNull("Null original value for " + propertyName, original);
+ assertNotNull("Null actual value for " + propertyName, actual);
+
+ assertEquals("Type mismatch for '" + propertyName + "': "
+ + original.getClass().getSimpleName() + "-" + actual.getClass().getSimpleName(),
+ original.getClass().getSimpleName(), actual.getClass().getSimpleName());
+
+ if (original.isComplex()) {
+ final List<ODataProperty> originalFileds = new ArrayList<ODataProperty>();
+ for (ODataProperty prop : original.<ODataProperty>asComplex()) {
+ originalFileds.add(prop);
+ }
+
+ final List<ODataProperty> actualFileds = new ArrayList<ODataProperty>();
+ for (ODataProperty prop : actual.<ODataProperty>asComplex()) {
+ actualFileds.add(prop);
+ }
+
+ checkProperties(originalFileds, actualFileds);
+ } else if (original.isCollection()) {
+ assertTrue(original.asCollection().size() <= actual.asCollection().size());
+
+ boolean found = original.asCollection().isEmpty();
+
+ for (ODataValue originalValue : original.asCollection()) {
+ for (ODataValue actualValue : actual.asCollection()) {
+ try {
+ checkPropertyValue(propertyName, originalValue, actualValue);
+ found = true;
+ } catch (AssertionError ignore) {
+ // ignore
+ }
+ }
+ }
+
+ assertTrue("Found " + actual + " but expected " + original, found);
+ } else {
+ assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
+ getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
+ original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
+
+ assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
+ + "-" + actual.asPrimitive().toString(),
+ original.asPrimitive().toString(), actual.asPrimitive().toString());
+ }
+ }
+
+ protected ODataEntity getSampleCustomerInfo(final int id, final String sampleinfo) {
+ final ODataEntity entity = getClient().getObjectFactory().newEntity(new FullQualifiedName(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo"));
+ entity.setMediaEntity(true);
+
+ getClient().getBinder().add(entity,
+ getClient().getObjectFactory().newPrimitiveProperty("Information",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleinfo)));
+
+ return entity;
+ }
+
+ protected ODataEntity getSampleCustomerProfile(
+ final int id, final String sampleName, final boolean withInlineInfo) {
+
+ final ODataEntity entity = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
+
+ // add name attribute
+ getClient().getBinder().add(entity,
+ getClient().getObjectFactory().newPrimitiveProperty("Name",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleName)));
+
+ // add key attribute
+ getClient().getBinder().add(entity,
+ getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+
+ // add BackupContactInfo attribute (collection)
+ final ODataCollectionValue<ODataValue> backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
+ "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
+ getClient().getBinder().add(entity,
+ getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", backupContactInfoValue));
+
+ // add BackupContactInfo.ContactDetails attribute (complex)
+ final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
+ backupContactInfoValue.add(contactDetails);
+
+ // add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
+ final ODataCollectionValue<ODataValue> altNamesValue = getClient().getObjectFactory().
+ newCollectionValue("Collection(Edm.String)");
+ altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname"));
+ contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
+
+ // add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
+ final ODataCollectionValue<ODataValue> emailBagValue = getClient().getObjectFactory().
+ newCollectionValue("Collection(Edm.String)");
+ emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname@mydomain.com"));
+ contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
+
+ // add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
+ final ODataComplexValue<ODataProperty> contactAliasValue = getClient().getObjectFactory().newComplexValue(
+ "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
+ contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
+
+ // add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
+ final ODataCollectionValue<ODataValue> aliasAltNamesValue = getClient().getObjectFactory().
+ newCollectionValue("Collection(Edm.String)");
+ aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myAlternativeName"));
+ contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
+
+ if (withInlineInfo) {
+ final ODataInlineEntity inlineInfo = getClient().getObjectFactory().newDeepInsertEntity(
+ "Info",
+ getSampleCustomerInfo(id, sampleName + "_Info"));
+ inlineInfo.getEntity().setMediaEntity(true);
+ entity.addLink(inlineInfo);
+ }
+
+ return entity;
+ }
+
+ protected String getETag(final URI uri) {
+ final ODataRetrieveResponse<ODataEntity> res = getClient().getRetrieveRequestFactory().
+ getEntityRequest(uri).execute();
+ try {
+ return res.getETag();
+ } finally {
+ res.close();
+ }
+ }
+
+ protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
+ final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
+ getEntityRequest(editLink);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+
+ assertNotNull(entity);
+
+ if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
+ assertEquals(req.getURI(), entity.getEditLink());
+ }
+
+ return entity;
+ }
+
+ protected ODataEntity createEntity(
+ final String serviceRootURL,
+ final ODataPubFormat format,
+ final ODataEntity original,
+ final String entitySetName) {
+
+ final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
+ appendEntitySetSegment(entitySetName);
+
+ debugODataEntity(original, "About to create");
+
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
+ createReq.setFormat(format);
+
+ final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+ assertEquals("Created", createRes.getStatusMessage());
+
+ final ODataEntity created = createRes.getBody();
+ assertNotNull(created);
+
+ debugODataEntity(created, "Just created");
+
+ return created;
+ }
+
+ protected ODataEntity compareEntities(final String serviceRootURL,
+ final ODataPubFormat format,
+ final ODataEntity original,
+ final int actualObjectId,
+ final Collection<String> expands) {
+
+ final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
+ appendEntitySetSegment("Customer").appendKeySegment(actualObjectId);
+
+ // search expanded
+ if (expands != null) {
+ for (String expand : expands) {
+ uriBuilder.expand(expand);
+ }
+ }
+
+ final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
+ getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataEntity actual = res.getBody();
+ assertNotNull(actual);
+
+ // check defined links
+ checkLinks(original.getAssociationLinks(), actual.getAssociationLinks());
+ checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
+ checkLinks(original.getNavigationLinks(), actual.getNavigationLinks());
+
+ // check defined properties equality
+ checkProperties(original.getProperties(), actual.getProperties());
+
+ return actual;
+ }
+
+ protected void cleanAfterCreate(
+ final ODataPubFormat format,
+ final ODataEntity created,
+ final boolean includeInline,
+ final String baseUri) {
+
+ final Set<URI> toBeDeleted = new HashSet<URI>();
+ toBeDeleted.add(created.getEditLink());
+
+ if (includeInline) {
+ for (ODataLink link : created.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntity) {
+ final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
+ if (inline.getEditLink() != null) {
+ toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
+ }
+ }
+
+ if (link instanceof ODataInlineEntitySet) {
+ final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
+ for (CommonODataEntity entity : inline.getEntities()) {
+ if (entity.getEditLink() != null) {
+ toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
+ }
+ }
+ }
+ }
+ }
+
+ assertFalse(toBeDeleted.isEmpty());
+
+ for (URI link : toBeDeleted) {
+ final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(link);
+ final ODataDeleteResponse deleteRes = deleteReq.execute();
+
+ assertEquals(204, deleteRes.getStatusCode());
+ assertEquals("No Content", deleteRes.getStatusMessage());
+
+ deleteRes.close();
+
+ final ODataEntityRequest<ODataEntity> retrieveReq = getClient().getRetrieveRequestFactory().
+ getEntityRequest(link);
+ // bug that needs to be fixed on the SampleService - cannot get entity not found with header
+ // Accept: application/json;odata=minimalmetadata
+ retrieveReq.setFormat(format == ODataPubFormat.JSON_FULL_METADATA ? ODataPubFormat.JSON : format);
+
+ Exception exception = null;
+ try {
+ retrieveReq.execute();
+ fail();
+ } catch (ODataClientErrorException e) {
+ exception = e;
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ }
+ assertNotNull(exception);
+ }
+ }
+
+ protected void updateEntityDescription(
+ final ODataPubFormat format, final ODataEntity changes, final UpdateType type) {
+
+ updateEntityDescription(format, changes, type, null);
+ }
+
+ protected void updateEntityDescription(
+ final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
+
+ updateEntityStringProperty("Description", format, changes, type, etag);
+ }
+
+ protected void updateEntityStringProperty(final String propertyName,
+ final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
+
+ final URI editLink = changes.getEditLink();
+
+ final String newm = "New " + propertyName + "(" + System.currentTimeMillis() + ")";
+
+ ODataProperty propertyValue = changes.getProperty(propertyName);
+
+ final String oldm;
+ if (propertyValue == null) {
+ oldm = null;
+ } else {
+ oldm = propertyValue.getValue().toString();
+ changes.getProperties().remove(propertyValue);
+ }
+
+ assertNotEquals(newm, oldm);
+
+ getClient().getBinder().add(changes,
+ getClient().getObjectFactory().newPrimitiveProperty(propertyName,
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(newm)));
+
+ update(type, changes, format, etag);
+
+ final ODataEntity actual = read(format, editLink);
+
+ propertyValue = null;
+
+ for (ODataProperty prop : actual.getProperties()) {
+ if (prop.getName().equals(propertyName)) {
+ propertyValue = prop;
+ }
+ }
+
+ assertNotNull(propertyValue);
+ assertEquals(newm, propertyValue.getValue().toString());
+ }
+
+ protected void update(
+ final UpdateType type, final ODataEntity changes, final ODataPubFormat format, final String etag) {
+
+ final ODataEntityUpdateRequest<ODataEntity> req =
+ getClient().getCUDRequestFactory().getEntityUpdateRequest(type, changes);
+
+ if (getClient().getConfiguration().isUseXHTTPMethod()) {
+ assertEquals(HttpMethod.POST, req.getMethod());
+ } else {
+ assertEquals(type.getMethod(), req.getMethod());
+ }
+ req.setFormat(format);
+
+ if (StringUtils.isNotBlank(etag)) {
+ req.setIfMatch(etag); // Product include ETag header into the response .....
+ }
+
+ final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
+ assertEquals(204, res.getStatusCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java
new file mode 100644
index 0000000..a28b354
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/ActionOverloadingTestITCase.java
@@ -0,0 +1,181 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
+import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v3.ODataProperty;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmActionImport;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
+import org.junit.Test;
+
+public class ActionOverloadingTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void retrieveProduct() throws EdmPrimitiveTypeException {
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ int execs = 0;
+ for (EdmActionImport actImp : container.getActionImports()) {
+ if ("RetrieveProduct".equals(actImp.getName())) {
+ // 1. unbound
+ final EdmAction unbound = actImp.getUnboundAction();
+ assertNotNull(unbound);
+ assertEquals(EdmInt32.getInstance(), unbound.getReturnType().getType());
+
+ final URIBuilder unboundBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
+ appendOperationCallSegment(URIUtils.operationImportURISegment(container, actImp.getName()));
+ final ODataInvokeResponse<ODataProperty> unboundRes = getClient().getInvokeRequestFactory().
+ <ODataProperty>getInvokeRequest(unboundBuilder.build(), unbound).execute();
+ assertNotNull(unboundRes);
+ assertEquals(200, unboundRes.getStatusCode());
+ assertEquals(Integer.valueOf(-10), unboundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
+ execs++;
+
+ // 2. bound to Product
+ final EdmAction productBound = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), actImp.getName()),
+ new FullQualifiedName(container.getNamespace(), "Product"), false);
+ assertNotNull(productBound);
+ assertEquals(EdmInt32.getInstance(), productBound.getReturnType().getType());
+
+ final ODataEntity product = getClient().getRetrieveRequestFactory().getEntityRequest(
+ getClient().getURIBuilder(testActionOverloadingServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build()).
+ execute().getBody();
+ assertNotNull(product);
+
+ final ODataInvokeResponse<ODataProperty> productBoundRes = getClient().getInvokeRequestFactory().
+ <ODataProperty>getInvokeRequest(product.getOperation(actImp.getName()).getTarget(), unbound).
+ execute();
+ assertNotNull(productBoundRes);
+ assertEquals(200, productBoundRes.getStatusCode());
+ assertEquals(Integer.valueOf(-10), productBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
+ execs++;
+
+ // 3. bound to OrderLine
+ final EdmAction orderLineBound = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), actImp.getName()),
+ new FullQualifiedName(container.getNamespace(), "OrderLine"), false);
+ assertNotNull(orderLineBound);
+ assertEquals(EdmInt32.getInstance(), orderLineBound.getReturnType().getType());
+
+ final Map<String, Object> key = new LinkedHashMap<String, Object>(2);
+ key.put("OrderId", -10);
+ key.put("ProductId", -10);
+ final ODataEntity orderLine = getClient().getRetrieveRequestFactory().getEntityRequest(
+ getClient().getURIBuilder(testActionOverloadingServiceRootURL).
+ appendEntitySetSegment("OrderLine").appendKeySegment(key).build()).
+ execute().getBody();
+ assertNotNull(orderLine);
+
+ final ODataInvokeResponse<ODataProperty> orderLineBoundRes = getClient().getInvokeRequestFactory().
+ <ODataProperty>getInvokeRequest(orderLine.getOperation(actImp.getName()).getTarget(), unbound).
+ execute();
+ assertNotNull(orderLineBoundRes);
+ assertEquals(200, orderLineBoundRes.getStatusCode());
+ assertEquals(Integer.valueOf(-10), orderLineBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
+ execs++;
+ }
+ }
+ assertEquals(3, execs);
+ }
+
+ @Test
+ public void increaseSalaries() {
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ int execs = 0;
+ for (EdmActionImport actImp : container.getActionImports()) {
+ if ("IncreaseSalaries".equals(actImp.getName())) {
+ final Map<String, ODataValue> parameters = new LinkedHashMap<String, ODataValue>(1);
+ parameters.put("n", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(5));
+
+ // 1. bound to employees
+ final EdmAction employeeBound = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), actImp.getName()),
+ new FullQualifiedName(container.getNamespace(), "Employee"), true);
+ assertNotNull(employeeBound);
+ assertNull(employeeBound.getReturnType());
+
+ final URIBuilder employeeBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
+ appendEntitySetSegment("Person").
+ appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee");
+ final ODataEntitySet employees = getClient().getRetrieveRequestFactory().getEntitySetRequest(
+ employeeBuilder.build()).execute().getBody();
+ assertNotNull(employees);
+
+ final ODataInvokeResponse<ODataNoContent> employeeRes = getClient().getInvokeRequestFactory().
+ <ODataNoContent>getInvokeRequest(employeeBuilder.appendOperationCallSegment(actImp.getName()).build(),
+ employeeBound, parameters).execute();
+ assertNotNull(employeeRes);
+ assertEquals(204, employeeRes.getStatusCode());
+ execs++;
+
+ // 1. bound to special employees
+ final EdmAction specEmpBound = edm.getBoundAction(
+ new FullQualifiedName(container.getNamespace(), actImp.getName()),
+ new FullQualifiedName(container.getNamespace(), "SpecialEmployee"), true);
+ assertNotNull(specEmpBound);
+ assertNull(specEmpBound.getReturnType());
+
+ final URIBuilder specEmpBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
+ appendEntitySetSegment("Person").
+ appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee");
+ final ODataEntitySet specEmps = getClient().getRetrieveRequestFactory().getEntitySetRequest(
+ specEmpBuilder.build()).execute().getBody();
+ assertNotNull(specEmps);
+
+ final ODataInvokeResponse<ODataNoContent> specEmpsRes = getClient().getInvokeRequestFactory().
+ <ODataNoContent>getInvokeRequest(specEmpBuilder.appendOperationCallSegment(actImp.getName()).build(),
+ specEmpBound, parameters).execute();
+ assertNotNull(specEmpsRes);
+ assertEquals(204, specEmpsRes.getStatusCode());
+ execs++;
+ }
+ }
+ assertEquals(2, execs);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
new file mode 100644
index 0000000..68d8524
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/AsyncTestITCase.java
@@ -0,0 +1,134 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+
+import java.io.InputStream;
+import java.net.URI;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
+import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
+import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
+import org.junit.Test;
+
+public class AsyncTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void retrieveEntitySet() throws InterruptedException, ExecutionException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product");
+ final Future<ODataRetrieveResponse<ODataEntitySet>> futureRes =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).asyncExecute();
+ assertNotNull(futureRes);
+
+ while (!futureRes.isDone()) {
+ Thread.sleep(1000L);
+ }
+
+ final ODataRetrieveResponse<ODataEntitySet> res = futureRes.get();
+ assertNotNull(res);
+ assertEquals(200, res.getStatusCode());
+ assertFalse(res.getBody().getEntities().isEmpty());
+ }
+
+ @Test
+ public void updateEntity() throws InterruptedException, ExecutionException {
+ final URI uri = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10).build();
+
+ final ODataRetrieveResponse<ODataEntity> entityRes = client.getRetrieveRequestFactory().
+ getEntityRequest(uri).execute();
+ final ODataEntity entity = entityRes.getBody();
+ entity.getAssociationLinks().clear();
+ entity.getNavigationLinks().clear();
+ entity.getEditMediaLinks().clear();
+
+ entity.getProperties().remove(entity.getProperty("Description"));
+ getClient().getBinder().add(entity,
+ client.getObjectFactory().newPrimitiveProperty("Description",
+ client.getObjectFactory().newPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build()));
+
+ final ODataEntityUpdateRequest<ODataEntity> updateReq =
+ client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity);
+ updateReq.setIfMatch(entityRes.getETag());
+ final Future<ODataEntityUpdateResponse<ODataEntity>> futureRes = updateReq.asyncExecute();
+
+ while (!futureRes.isDone()) {
+ Thread.sleep(1000L);
+ }
+
+ final ODataEntityUpdateResponse<ODataEntity> res = futureRes.get();
+ assertNotNull(res);
+ assertEquals(204, res.getStatusCode());
+ }
+
+ /**
+ * @see MediaEntityTest#createMediaEntity(com.msopentech.odatajclient.engine.format.ODataPubFormat)
+ */
+ @Test
+ public void createMediaEntity() throws Exception {
+ URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car");
+
+ final String TO_BE_UPDATED = "async buffered stream sample";
+ final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
+
+ final ODataMediaEntityCreateRequest<ODataEntity> createReq =
+ client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
+
+ final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute();
+ final Future<ODataMediaEntityCreateResponse<ODataEntity>> futureCreateRes = streamManager.getAsyncResponse();
+
+ while (!futureCreateRes.isDone()) {
+ Thread.sleep(1000L);
+ }
+
+ final ODataMediaEntityCreateResponse<ODataEntity> createRes = futureCreateRes.get();
+ assertEquals(201, createRes.getStatusCode());
+
+ final ODataEntity created = createRes.getBody();
+ assertNotNull(created);
+ assertEquals(2, created.getProperties().size());
+
+ final int id = "VIN".equals(created.getProperties().get(0).getName())
+ ? created.getProperties().get(0).getPrimitiveValue().toCastValue(Integer.class)
+ : created.getProperties().get(1).getPrimitiveValue().toCastValue(Integer.class);
+
+ builder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+ assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/AuthEntityRetrieveTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/AuthEntityRetrieveTestITCase.java
new file mode 100644
index 0000000..a991de1
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/AuthEntityRetrieveTestITCase.java
@@ -0,0 +1,42 @@
+/*
+ * 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.v3;
+
+import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
+import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
+import org.junit.AfterClass;
+import org.junit.BeforeClass;
+
+public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
+
+ @BeforeClass
+ public static void enableBasicAuth() {
+ client.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
+ }
+
+ @AfterClass
+ public static void disableBasicAuth() {
+ client.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
+ }
+
+ @Override
+ protected String getServiceRoot() {
+ return testAuthServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/BatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/BatchTestITCase.java
new file mode 100644
index 0000000..02a9273
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/BatchTestITCase.java
@@ -0,0 +1,444 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Iterator;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.http.HttpResponse;
+import org.apache.olingo.client.api.ODataBatchConstants;
+import org.apache.olingo.client.api.communication.request.ODataStreamManager;
+import org.apache.olingo.client.api.communication.request.batch.BatchStreamManager;
+import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
+import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
+import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
+import org.apache.olingo.client.api.communication.request.batch.v3.ODataBatchRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataResponse;
+import org.apache.olingo.client.api.uri.v3.URIBuilder;
+import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
+import org.apache.olingo.client.core.communication.request.Wrapper;
+import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
+import org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
+import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
+import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.v3.ODataEntity;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class BatchTestITCase extends AbstractTestITCase {
+
+ private static final String PREFIX = "!!PREFIX!!";
+
+ private static final String SUFFIX = "!!SUFFIX!!";
+
+ private static final int MAX = 10000;
+
+ @Test
+ public void stringStreaming() {
+ final TestStreamManager streaming = new TestStreamManager();
+
+ new StreamingThread(streaming).start();
+
+ streaming.addObject((PREFIX + "\n").getBytes());
+
+ for (int i = 0; i <= MAX; i++) {
+ streaming.addObject((i + ") send info\n").getBytes());
+ }
+
+ streaming.addObject(SUFFIX.getBytes());
+ streaming.finalizeBody();
+ }
+
+ @Test
+ public void emptyBatchRequest() {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+
+ final BatchStreamManager payload = request.execute();
+ final ODataBatchResponse response = payload.getResponse();
+
+ assertEquals(202, response.getStatusCode());
+ assertEquals("Accepted", response.getStatusMessage());
+
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void changesetWithError() {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+
+ final BatchStreamManager payload = request.execute();
+ final ODataChangeset changeset = payload.addChangeset();
+
+ URIBuilder targetURI;
+ ODataEntityCreateRequest<ODataEntity> createReq;
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
+ for (int i = 1; i <= 2; i++) {
+ // Create Customer into the changeset
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(
+ targetURI.build(),
+ getSampleCustomerProfile(100 + i, "Sample customer", false));
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+ }
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet");
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(
+ targetURI.build(),
+ getSampleCustomerProfile(105, "Sample customer", false));
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
+ for (int i = 3; i <= 4; i++) {
+ // Create Customer into the changeset
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(
+ targetURI.build(),
+ getSampleCustomerProfile(100 + i, "Sample customer", false));
+ createReq.setFormat(ODataPubFormat.ATOM);
+ changeset.addRequest(createReq);
+ }
+
+ final ODataBatchResponse response = payload.getResponse();
+ assertEquals(202, response.getStatusCode());
+ assertEquals("Accepted", response.getStatusMessage());
+
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+ final ODataChangesetResponseItem chgResponseItem = (ODataChangesetResponseItem) iter.next();
+
+ final ODataResponse res = chgResponseItem.next();
+ assertEquals(404, res.getStatusCode());
+ assertEquals("Not Found", res.getStatusMessage());
+ assertEquals(Integer.valueOf(3), Integer.valueOf(
+ res.getHeader(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME).iterator().next()));
+ assertFalse(chgResponseItem.hasNext());
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void changesetWithReference() throws EdmPrimitiveTypeException {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ final BatchStreamManager streamManager = request.execute();
+
+ final ODataChangeset changeset = streamManager.addChangeset();
+ ODataEntity customer = getSampleCustomerProfile(20, "sample customer", false);
+
+ URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
+
+ // add create request
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), customer);
+
+ changeset.addRequest(createReq);
+
+ // retrieve request reference
+ int createRequestRef = changeset.getLastContentId();
+
+ // add update request: link CustomerInfo(17) to the new customer
+ final ODataEntity customerChanges = client.getObjectFactory().newEntity(customer.getTypeName());
+ customerChanges.addLink(client.getObjectFactory().newEntityNavigationLink(
+ "Info",
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("CustomerInfo").
+ appendKeySegment(17).build()));
+
+ final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
+ URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
+
+ changeset.addRequest(updateReq);
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(202, response.getStatusCode());
+ assertEquals("Accepted", response.getStatusMessage());
+
+ // verify response payload ...
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ final ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataChangesetResponseItem);
+
+ final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
+
+ ODataResponse res = chgitem.next();
+ assertEquals(201, res.getStatusCode());
+ assertTrue(res instanceof ODataEntityCreateResponse);
+
+ customer = ((ODataEntityCreateResponse<ODataEntity>) res).getBody();
+
+ ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
+ URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString() + "/Info"));
+
+ assertEquals(Integer.valueOf(17),
+ req.execute().getBody().getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
+
+ res = chgitem.next();
+ assertEquals(204, res.getStatusCode());
+ assertTrue(res instanceof ODataEntityUpdateResponse);
+
+ // clean ...
+ assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
+ URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).execute().
+ getStatusCode());
+
+ try {
+ client.getRetrieveRequestFactory().getEntityRequest(
+ URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).
+ execute().getBody();
+ fail();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void batchRequest() throws EdmPrimitiveTypeException {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+
+ final BatchStreamManager streamManager = request.execute();
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ ODataRetrieve retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+ targetURI.appendEntitySetSegment("Customer").appendKeySegment(-10).
+ expand("Logins").select("CustomerId,Logins/Username");
+
+ // create new request
+ ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+ queryReq.setFormat(ODataPubFormat.ATOM);
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add changeset item
+ // -------------------------------------------
+ final ODataChangeset changeset = streamManager.addChangeset();
+
+ // Update Product into the changeset
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10);
+ final URI editLink = targetURI.build();
+
+ final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
+ merge.setEditLink(editLink);
+
+ merge.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
+ "Description",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("new description from batch")));
+
+ final ODataEntityUpdateRequest changeReq =
+ client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, merge);
+ changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+ changeReq.setIfMatch(getETag(editLink));
+
+ changeset.addRequest(changeReq);
+
+ // Create Customer into the changeset
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
+ final ODataEntity original = getSampleCustomerProfile(1000, "Sample customer", false);
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
+ createReq.setFormat(ODataPubFormat.ATOM);
+ changeset.addRequest(createReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Product").appendKeySegment(-10);
+
+ // create new request
+ queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(202, response.getStatusCode());
+ assertEquals("Accepted", response.getStatusMessage());
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ // retrive the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+
+ ODataEntityRequestImpl<ODataEntity>.ODataEntityResponseImpl entres =
+ (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
+
+ ODataEntity entity = entres.getBody();
+ assertEquals(-10, entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // retrieve the second item (ODataChangeset)
+ item = iter.next();
+ assertTrue(item instanceof ODataChangesetResponseItem);
+
+ final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
+ res = chgitem.next();
+ assertTrue(res instanceof ODataEntityUpdateResponse);
+ assertEquals(204, res.getStatusCode());
+ assertEquals("No Content", res.getStatusMessage());
+
+ res = chgitem.next();
+ assertTrue(res instanceof ODataEntityCreateResponse);
+ assertEquals(201, res.getStatusCode());
+ assertEquals("Created", res.getStatusMessage());
+
+ final ODataEntityCreateResponse<ODataEntity> createres = (ODataEntityCreateResponse<ODataEntity>) res;
+ entity = createres.getBody();
+ assertEquals(new Integer(1000), entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
+
+ // retrive the third item (ODataRetrieve)
+ item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ retitem = (ODataRetrieveResponseItem) item;
+ res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+
+ entres = (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
+ entity = entres.getBody();
+ assertEquals("new description from batch",
+ entity.getProperty("Description").getPrimitiveValue().toCastValue(String.class));
+
+ assertFalse(iter.hasNext());
+ }
+
+ private static class TestStreamManager extends AbstractODataStreamManager<ODataBatchResponse> {
+
+ public TestStreamManager() {
+ super(new Wrapper<Future<HttpResponse>>());
+ }
+
+ public ODataStreamManager<ODataBatchResponse> addObject(byte[] src) {
+ stream(src);
+ return this;
+ }
+
+ @Override
+ protected ODataBatchResponse getResponse(long timeout, TimeUnit unit) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+
+ /**
+ * To be used for debug purposes.
+ */
+ private static class StreamingThread extends Thread {
+
+ private final TestStreamManager streaming;
+
+ public StreamingThread(final TestStreamManager streaming) {
+ this.streaming = streaming;
+ }
+
+ @Override
+ public void run() {
+ try {
+ final StringBuilder builder = new StringBuilder();
+
+ byte[] buff = new byte[1024];
+
+ int len;
+
+ while ((len = streaming.getBody().read(buff)) >= 0) {
+ builder.append(new String(buff, 0, len));
+ }
+
+ assertTrue(builder.toString().startsWith(PREFIX));
+ assertTrue(builder.toString().contains((MAX / 2) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 3) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 20) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 30) + ") send info"));
+ assertTrue(builder.toString().contains(MAX + ") send info"));
+ assertTrue(builder.toString().endsWith(SUFFIX));
+
+ } catch (IOException e) {
+ fail();
+ }
+ }
+ }
+
+ private static class BatchStreamingThread extends Thread {
+
+ private final BatchStreamManager streaming;
+
+ public BatchStreamingThread(final BatchStreamManager streaming) {
+ this.streaming = streaming;
+ }
+
+ @Override
+ public void run() {
+ try {
+ final StringBuilder builder = new StringBuilder();
+
+ byte[] buff = new byte[1024];
+
+ int len;
+
+ while ((len = streaming.getBody().read(buff)) >= 0) {
+ builder.append(new String(buff, 0, len));
+ }
+
+ LOG.debug("Batch request {}", builder.toString());
+
+ assertTrue(builder.toString().contains("Content-Id:2"));
+ assertTrue(builder.toString().contains("GET " + testStaticServiceRootURL));
+ } catch (IOException e) {
+ fail();
+ }
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v3/CountTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v3/CountTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v3/CountTestITCase.java
new file mode 100644
index 0000000..9745ef5
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v3/CountTestITCase.java
@@ -0,0 +1,60 @@
+/*
+ * 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.v3;
+
+import static org.junit.Assert.*;
+import org.junit.Test;
+
+import org.apache.olingo.client.api.communication.ODataClientErrorException;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.format.ODataValueFormat;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+
+public class CountTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void entityCount() {
+ CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").count();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ try {
+ final ODataValue value = req.execute().getBody();
+ assertTrue(10 <= Integer.parseInt(value.toString()));
+ } catch (ODataClientErrorException e) {
+ LOG.error("Error code: {}", e.getStatusLine().getStatusCode(), e);
+ }
+ }
+
+ @Test
+ public void invalidAccept() {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customer").count();
+ final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
+ req.setFormat(ODataValueFormat.TEXT);
+ req.setAccept("application/json;odata=fullmetadata");
+ try {
+ final ODataValue value = req.execute().getBody();
+ fail();
+ } catch (ODataClientErrorException e) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
+ }
+ }
+}
[03/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AbstractTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AbstractTestITCase.java
deleted file mode 100644
index c090ec8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AbstractTestITCase.java
+++ /dev/null
@@ -1,132 +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.client.core.it.v4;
-
-import java.io.IOException;
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.client.core.it.AbstractBaseTestITCase;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.domain.v4.ODataValue;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.core.domain.v4.ODataEntityImpl;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import org.junit.BeforeClass;
-
-public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
-
- protected static final ODataClient client = ODataClientFactory.getV4();
-
- protected static EdmEnabledODataClient edmClient;
-
- protected static String testStaticServiceRootURL;
-
- protected static String testKeyAsSegmentServiceRootURL;
-
- protected static String testOpenTypeServiceRootURL;
-
- protected static String testLargeModelServiceRootURL;
-
- protected static String testAuthServiceRootURL;
-
- @BeforeClass
- public static void setUpODataServiceRoot() throws IOException {
- testStaticServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc";
- testKeyAsSegmentServiceRootURL = "http://localhost:9080/StaticService/V40/KeyAsSegment.svc";
- testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V40/OpenType.svc";
- testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc/large";
- testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
-
- edmClient = ODataClientFactory.getEdmEnabledV4(testStaticServiceRootURL);
- }
-
- @Override
- protected ODataClient getClient() {
- return client;
- }
-
- protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
- final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
-
- if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
- assertEquals(req.getURI(), entity.getEditLink());
- }
-
- return entity;
- }
-
- protected void createAndDeleteOrder(final ODataPubFormat format, final int id) {
- final ODataEntity order = new ODataEntityImpl(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
-
- final ODataProperty orderId = getClient().getObjectFactory().newPrimitiveProperty("OrderID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id));
- order.getProperties().add(orderId);
-
- final ODataProperty orderDate = getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2011-03-04T16:03:57Z").build());
- order.getProperties().add(orderDate);
-
- final ODataProperty shelfLife = getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
- order.getProperties().add(shelfLife);
-
- final ODataCollectionValue<ODataValue> orderShelfLifesValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Duration)");
- orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
- orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build());
- final ODataProperty orderShelfLifes = getClient().getObjectFactory().
- newCollectionProperty("OrderShelfLifes", orderShelfLifesValue);
- order.getProperties().add(orderShelfLifes);
-
- final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Orders").build(), order);
- req.setFormat(format);
- final ODataEntity created = req.execute().getBody();
- assertNotNull(created);
- assertEquals(2, created.getProperty("OrderShelfLifes").getCollectionValue().size());
-
- final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(created.getEditLink());
- final ODataDeleteResponse deleteRes = deleteReq.execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java
deleted file mode 100644
index 815d077..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/AsyncTestITCase.java
+++ /dev/null
@@ -1,166 +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.client.core.it.v4;
-
-import java.net.URI;
-import java.util.List;
-
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.v4.AsyncRequestWrapper;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.communication.response.v4.AsyncResponseWrapper;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-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 org.junit.Test;
-
-public class AsyncTestITCase extends AbstractTestITCase {
-
- @Test
- public void asyncRequestV3Style() throws InterruptedException, ExecutionException {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers");
- final Future<ODataRetrieveResponse<ODataEntitySet>> futureRes =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).asyncExecute();
- assertNotNull(futureRes);
-
- while (!futureRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataRetrieveResponse<ODataEntitySet> res = futureRes.get();
- assertNotNull(res);
- assertEquals(200, res.getStatusCode());
- assertFalse(res.getBody().getEntities().isEmpty());
- }
-
- private void withInlineEntry(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final AsyncRequestWrapper<ODataRetrieveResponse<ODataEntity>> async =
- client.getAsyncRequestFactory().<ODataRetrieveResponse<ODataEntity>>getAsyncRequestWrapper(req);
-
- final AsyncResponseWrapper<ODataRetrieveResponse<ODataEntity>> responseWrapper = async.execute();
-
- assertFalse(responseWrapper.isPreferenceApplied());
-
- final ODataRetrieveResponse<ODataEntity> res = responseWrapper.getODataResponse();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
- assertEquals(testStaticServiceRootURL + "/Customers(PersonID=1)", entity.getEditLink().toASCIIString());
-
- assertEquals(3, entity.getNavigationLinks().size());
-
- if (ODataPubFormat.ATOM == format) {
- assertTrue(entity.getAssociationLinks().isEmpty());
- // In JSON, association links for each $ref link will exist.
- }
-
- boolean found = false;
-
- for (ODataLink link : entity.getNavigationLinks()) {
- if (link instanceof ODataInlineEntity) {
- final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
- assertNotNull(inline);
-
- final List<? extends CommonODataProperty> properties = inline.getProperties();
- assertEquals(5, properties.size());
-
- assertTrue(properties.get(0).getName().equals("CompanyID")
- || properties.get(1).getName().equals("CompanyID")
- || properties.get(2).getName().equals("CompanyID")
- || properties.get(3).getName().equals("CompanyID")
- || properties.get(4).getName().equals("CompanyID"));
- assertTrue(properties.get(0).getValue().toString().equals("0")
- || properties.get(1).getValue().toString().equals("0")
- || properties.get(2).getValue().toString().equals("0")
- || properties.get(3).getValue().toString().equals("0")
- || properties.get(4).getValue().toString().equals("0"));
-
- found = true;
- }
- }
-
- assertTrue(found);
- }
-
- private void asynOrders(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("async").appendEntitySetSegment("Orders");
-
- final ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
- req.setFormat(format);
-
- final AsyncRequestWrapper<ODataRetrieveResponse<ODataEntitySet>> async =
- client.getAsyncRequestFactory().<ODataRetrieveResponse<ODataEntitySet>>getAsyncRequestWrapper(req);
- async.callback(URI.create("http://client.service.it/callback/endpoint"));
-
- final AsyncResponseWrapper<ODataRetrieveResponse<ODataEntitySet>> responseWrapper = async.execute();
-
- assertTrue(responseWrapper.isPreferenceApplied());
- assertTrue(responseWrapper.isDone());
-
- final ODataRetrieveResponse<ODataEntitySet> res = responseWrapper.getODataResponse();
- final ODataEntitySet entitySet = res.getBody();
-
- assertFalse(entitySet.getEntities().isEmpty());
- }
-
- @Test
- public void withInlineEntryAsAtom() {
- withInlineEntry(ODataPubFormat.ATOM);
- }
-
- @Test
- public void withInlineEntryAsJSON() {
- // this needs to be full, otherwise there is no mean to recognize links
- withInlineEntry(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void asynOrdersAsAtom() {
- asynOrders(ODataPubFormat.ATOM);
- }
-
- @Test
- public void asynOrdersAsJSON() {
- asynOrders(ODataPubFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
deleted file mode 100644
index 6c24789..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BatchTestITCase.java
+++ /dev/null
@@ -1,710 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Calendar;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import org.apache.http.HttpResponse;
-import org.apache.olingo.client.api.ODataBatchConstants;
-import org.apache.olingo.client.api.communication.header.HeaderName;
-import org.apache.olingo.client.api.communication.request.ODataStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
-import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
-import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
-import org.apache.olingo.client.api.communication.request.batch.v4.BatchStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest;
-import org.apache.olingo.client.api.communication.request.batch.v4.ODataOutsideUpdate;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.v4.AsyncBatchRequestWrapper;
-import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataResponse;
-import org.apache.olingo.client.api.communication.response.v4.AsyncResponse;
-import org.apache.olingo.client.api.communication.response.v4.AsyncResponseWrapper;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
-import org.apache.olingo.client.core.communication.request.Wrapper;
-import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
-import org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
-import org.apache.olingo.client.core.communication.request.batch.v4.ODataOutsideUpdateResponseItem;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ContentType;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class BatchTestITCase extends AbstractTestITCase {
-
- private static final String PREFIX = "!!PREFIX!!";
-
- private static final String SUFFIX = "!!SUFFIX!!";
-
- private static final int MAX = 10000;
-
- // ------------------------
- // Uncomment to check externally ...
- // ------------------------
- // private final static String testStaticServiceRootURL=
- // "http://odatae2etest.azurewebsites.net/javatest/DefaultService/";
- // private final static String ACCEPT = ContentType.MULTIPART_MIXED;
- // ------------------------
- private final static String ACCEPT = ContentType.APPLICATION_OCTET_STREAM;
-
- @Test
- public void stringStreaming() {
- final TestStreamManager streaming = new TestStreamManager();
-
- new StreamingThread(streaming).start();
-
- streaming.addObject((PREFIX + "\n").getBytes());
-
- for (int i = 0; i <= MAX; i++) {
- streaming.addObject((i + ") send info\n").getBytes());
- }
-
- streaming.addObject(SUFFIX.getBytes());
- streaming.finalizeBody();
- }
-
- @Test
- public void emptyBatchRequest() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
-
- final BatchStreamManager payload = request.execute();
- final ODataBatchResponse response = payload.getResponse();
-
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- assertFalse(iter.hasNext());
- }
-
- @Test
- public void changesetWithError() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
-
- final BatchStreamManager payload = request.execute();
- final ODataChangeset changeset = payload.addChangeset();
-
- URIBuilder targetURI;
- ODataEntityCreateRequest<ODataEntity> createReq;
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
- for (int i = 1; i <= 2; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
- }
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet");
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(105));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
- for (int i = 3; i <= 4; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
- }
-
- final ODataBatchResponse response = payload.getResponse();
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- // retrieve the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
-
- ODataChangesetResponseItem retitem = (ODataChangesetResponseItem) item;
- ODataResponse res = retitem.next();
- assertEquals(404, res.getStatusCode());
- assertEquals("Not Found", res.getStatusMessage());
- assertEquals(Integer.valueOf(3), Integer.valueOf(
- res.getHeader(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME).iterator().next()));
-
- assertFalse(retitem.hasNext());
- assertFalse(iter.hasNext());
- }
-
- @Test
- public void continueOnError() {
- continueOnError(true);
- }
-
- @Test
- public void doNotContinueOnError() {
- continueOnError(false);
- }
-
- private void continueOnError(final boolean continueOnError) {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
- request.continueOnError();
-
- final BatchStreamManager streamManager = request.execute();
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = streamManager.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("UnexistinfEntitySet").appendKeySegment(1);
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.JSON);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- retrieve = streamManager.addRetrieve();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
-
- // create new request
- queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrieve the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertEquals(404, res.getStatusCode());
- assertEquals("Not Found", res.getStatusMessage());
-
- if (continueOnError) {
- item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- retitem = (ODataRetrieveResponseItem) item;
- res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
- }
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void changesetWithReference() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
- final BatchStreamManager streamManager = request.execute();
-
- final ODataChangeset changeset = streamManager.addChangeset();
- ODataEntity order = newOrder(20);
-
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
-
- // add create request
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), order);
-
- changeset.addRequest(createReq);
-
- // retrieve request reference
- int createRequestRef = changeset.getLastContentId();
-
- // add update request: link CustomerInfo(17) to the new customer
- final ODataEntity customerChanges = client.getObjectFactory().newEntity(order.getTypeName());
- customerChanges.addLink(client.getObjectFactory().newEntitySetNavigationLink(
- "OrderDetails",
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("OrderDetails").
- appendKeySegment(new HashMap<String, Object>() {
- private static final long serialVersionUID = 3109256773218160485L;
-
- {
- put("OrderID", 7);
- put("ProductID", 5);
- }
- }).build()));
-
- final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
- URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
-
- changeset.addRequest(updateReq);
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
-
- // verify response payload ...
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- final ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
-
- ODataResponse res = chgitem.next();
- assertEquals(201, res.getStatusCode());
- assertTrue(res instanceof ODataEntityCreateResponse);
-
- order = ((ODataEntityCreateResponse<ODataEntity>) res).getBody();
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().getEntitySetRequest(
- URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString() + "/OrderDetails"));
-
- assertEquals(Integer.valueOf(7),
- req.execute().getBody().getEntities().get(0).getProperty("OrderID").getPrimitiveValue().
- toCastValue(Integer.class));
-
- res = chgitem.next();
- assertEquals(204, res.getStatusCode());
- assertTrue(res instanceof ODataEntityUpdateResponse);
-
- // clean ...
- assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
- URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString())).execute().
- getStatusCode());
-
- try {
- client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString())).
- execute().getBody();
- fail();
- } catch (Exception e) {
- // ignore
- }
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void batchRequestWithOutsideUpdates() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
- final BatchStreamManager streamManager = request.execute();
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = streamManager.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("Customers").appendKeySegment(1).
- expand("Orders").select("PersonID,Orders/OrderID");
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.JSON);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add new order with outside item
- // -------------------------------------------
- final ODataOutsideUpdate outside = streamManager.addOutsideUpdate();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
- final ODataEntity original = newOrder(2000);
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
- createReq.setFormat(ODataPubFormat.JSON);
- outside.setRequest(createReq);
- // -------------------------------------------
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrieve the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- // retrieve the second item (ODataChangeset)
- item = iter.next();
- assertTrue(item instanceof ODataOutsideUpdateResponseItem);
-
- final ODataOutsideUpdateResponseItem outitem = (ODataOutsideUpdateResponseItem) item;
- res = outitem.next();
- assertTrue(res instanceof ODataEntityCreateResponse);
- assertEquals(201, res.getStatusCode());
- assertEquals("Created", res.getStatusMessage());
-
- final ODataEntityCreateResponse<ODataEntity> entres = (ODataEntityCreateResponse<ODataEntity>) res;
- final ODataEntity entity = entres.getBody();
- assertEquals(2000, entity.getProperty("OrderID").getPrimitiveValue().toCastValue(Integer.class).intValue());
-
- assertFalse(iter.hasNext());
- }
-
- @Test
- @SuppressWarnings({"unchecked"})
- public void batchRequest() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- request.setAccept(ACCEPT);
-
- final BatchStreamManager streamManager = request.execute();
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = streamManager.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("Customers").appendKeySegment(1);
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.JSON);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add changeset item
- // -------------------------------------------
- final ODataChangeset changeset = streamManager.addChangeset();
-
- // Update Customer into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
- final URI editLink = targetURI.build();
-
- final ODataEntity patch = client.getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
- patch.setEditLink(editLink);
-
- patch.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
- "LastName",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("new last name")));
-
- final ODataEntityUpdateRequest<ODataEntity> changeReq =
- client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch);
- changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
-
- changeset.addRequest(changeReq);
-
- // Create Order into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
- final ODataEntity original = newOrder(1000);
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- retrieve = streamManager.addRetrieve();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
-
- // create new request
- queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(200, response.getStatusCode());
- assertEquals("OK", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrieve the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- ODataEntityRequestImpl<ODataEntity>.ODataEntityResponseImpl entres =
- (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
-
- ODataEntity entity = entres.getBody();
- assertEquals(1, entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // retrieve the second item (ODataChangeset)
- item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityUpdateResponse);
- assertEquals(204, res.getStatusCode());
- assertEquals("No Content", res.getStatusMessage());
-
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityCreateResponse);
- assertEquals(201, res.getStatusCode());
- assertEquals("Created", res.getStatusMessage());
-
- final ODataEntityCreateResponse<ODataEntity> createres = (ODataEntityCreateResponse<ODataEntity>) res;
- entity = createres.getBody();
- assertEquals(new Integer(1000), entity.getProperty("OrderID").getPrimitiveValue().toCastValue(Integer.class));
-
- // retrive the third item (ODataRetrieve)
- item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- retitem = (ODataRetrieveResponseItem) item;
- res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- entres = (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
- entity = entres.getBody();
- assertEquals("new last name", entity.getProperty("LastName").getPrimitiveValue().toCastValue(String.class));
-
- assertFalse(iter.hasNext());
- }
-
- @Test
- public void async() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(
- URI.create(testStaticServiceRootURL + "/async/").normalize().toASCIIString());
- request.setAccept(ACCEPT);
-
- final AsyncBatchRequestWrapper async = client.getAsyncRequestFactory().getAsyncBatchRequestWrapper(request);
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = async.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("People").appendKeySegment(5);
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.JSON);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- retrieve = async.addRetrieve();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
-
- // create new request
- queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- final AsyncResponseWrapper<ODataBatchResponse> responseWrapper = async.execute();
-
- assertTrue(responseWrapper.isPreferenceApplied());
- assertTrue(responseWrapper.isDone());
-
- final ODataBatchResponse response = responseWrapper.getODataResponse();
-
- assertEquals(200, response.getStatusCode());
- assertEquals("Ok", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrieve the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- // The service return interim results to an asynchronously executing batch.
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertTrue(res instanceof AsyncResponse);
- assertEquals(202, res.getStatusCode());
- assertEquals("Accepted", res.getStatusMessage());
-
- Collection<String> newMonitorLocation = res.getHeader(HeaderName.location);
- if (newMonitorLocation != null && !newMonitorLocation.isEmpty()) {
- responseWrapper.forceNextMonitorCheck(URI.create(newMonitorLocation.iterator().next()));
- // .... now you can start again with isDone() and getODataResponse().
- }
-
- assertFalse(retitem.hasNext());
- assertFalse(iter.hasNext());
- }
-
- private static class TestStreamManager extends AbstractODataStreamManager<ODataBatchResponse> {
-
- public TestStreamManager() {
- super(new Wrapper<Future<HttpResponse>>());
- }
-
- public ODataStreamManager<ODataBatchResponse> addObject(final byte[] src) {
- stream(src);
- return this;
- }
-
- @Override
- protected ODataBatchResponse getResponse(final long timeout, final TimeUnit unit) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- };
-
- /**
- * To be used for debug purposes.
- */
- private static class StreamingThread extends Thread {
-
- private final TestStreamManager streaming;
-
- public StreamingThread(final TestStreamManager streaming) {
- super();
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- assertTrue(builder.toString().startsWith(PREFIX));
- assertTrue(builder.toString().contains((MAX / 2) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 3) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 20) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 30) + ") send info"));
- assertTrue(builder.toString().contains(MAX + ") send info"));
- assertTrue(builder.toString().endsWith(SUFFIX));
-
- } catch (IOException e) {
- fail();
- }
- }
- }
-
- private static class BatchStreamingThread extends Thread {
-
- private final BatchStreamManager streaming;
-
- public BatchStreamingThread(final BatchStreamManager streaming) {
- super();
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- final byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- LOG.debug("Batch request {}", builder.toString());
-
- assertTrue(builder.toString().contains("Content-Id:2"));
- assertTrue(builder.toString().contains("GET " + testStaticServiceRootURL));
- } catch (IOException e) {
- fail();
- }
- }
- }
-
- private ODataEntity newOrder(final int id) {
- final ODataEntity order = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
-
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
- order.getProperties().add(getClient().getObjectFactory().newCollectionProperty("OrderShelfLifes",
- getClient().getObjectFactory().newCollectionValue(EdmPrimitiveTypeKind.Duration.name()).add(
- getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Duration).
- setText("PT0.0000002S").build())));
-
- return order;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
deleted file mode 100644
index f00d14a..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/BoundOperationInvokeTestITCase.java
+++ /dev/null
@@ -1,339 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataOperation;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmFunction;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
-
- private Edm getEdm() {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- return edm;
- }
-
- private void functions(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final Edm edm = getEdm();
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- // GetEmployeesCount
- URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
- ODataEntityRequest<ODataEntity> entityReq =
- getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- ODataEntity entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount");
- assertNotNull(boundOp);
-
- EdmFunction func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(),
- false, null);
- assertNotNull(func);
-
- final ODataInvokeRequest<ODataProperty> getEmployeesCountReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
- getEmployeesCountReq.setFormat(format);
- final ODataProperty getEmployeesCountRes = getEmployeesCountReq.execute().getBody();
- assertNotNull(getEmployeesCountRes);
- assertTrue(getEmployeesCountRes.hasPrimitiveValue());
-
- // GetProductDetails
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Products").appendKeySegment(5);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails");
- assertNotNull(boundOp);
-
- func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
- assertNotNull(func);
-
- final ODataPrimitiveValue count = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1);
- final ODataInvokeRequest<ODataEntitySet> getProductDetailsReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
- Collections.<String, ODataValue>singletonMap("count", count));
- getProductDetailsReq.setFormat(format);
- final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
- assertNotNull(getProductDetailsRes);
- assertEquals(1, getProductDetailsRes.getCount());
-
- // GetRelatedProduct
- final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
- keyMap.put("ProductID", 6);
- keyMap.put("ProductDetailID", 1);
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("ProductDetails").appendKeySegment(keyMap);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct");
- assertNotNull(boundOp);
-
- func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
- assertNotNull(func);
-
- final ODataInvokeRequest<ODataEntity> getRelatedProductReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
- getRelatedProductReq.setFormat(format);
- final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody();
- assertNotNull(getRelatedProductRes);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product",
- getRelatedProductRes.getTypeName().toString());
- assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // GetDefaultPI
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetDefaultPI");
- assertNotNull(boundOp);
-
- func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
- assertNotNull(func);
-
- final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
- getDefaultPIReq.setFormat(format);
- final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
- assertNotNull(getDefaultPIRes);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
- getDefaultPIRes.getTypeName().toString());
- assertEquals(101901,
- getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // GetAccountInfo
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetAccountInfo");
- assertNotNull(boundOp);
-
- func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
- assertNotNull(func);
-
- final ODataInvokeRequest<ODataProperty> getAccountInfoReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
- getAccountInfoReq.setFormat(format);
- final ODataProperty getAccountInfoRes = getAccountInfoReq.execute().getBody();
- assertNotNull(getAccountInfoRes);
- assertTrue(getAccountInfoRes.hasComplexValue());
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.AccountInfo",
- getAccountInfoRes.getComplexValue().getTypeName());
-
- // GetActualAmount
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(
- entity.getNavigationLink("MyGiftCard").getLink());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
- assertEquals(301, entity.getProperty("GiftCardID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount");
- assertNotNull(boundOp);
-
- func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
- assertNotNull(func);
-
- final ODataPrimitiveValue bonusRate = getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.1);
- final ODataInvokeRequest<ODataProperty> getActualAmountReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
- Collections.<String, ODataValue>singletonMap("bonusRate", bonusRate));
- getActualAmountReq.setFormat(format);
- final ODataProperty getActualAmountRes = getActualAmountReq.execute().getBody();
- assertNotNull(getActualAmountRes);
- assertEquals(41.79, getActualAmountRes.getPrimitiveValue().toCastValue(Double.class), 0);
- }
-
- @Test
- public void atomFunctions() throws EdmPrimitiveTypeException {
- functions(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonFunctions() throws EdmPrimitiveTypeException {
- functions(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void actions(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final Edm edm = getEdm();
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- // IncreaseRevenue
- URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
- ODataEntityRequest<ODataEntity> entityReq =
- getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- ODataEntity entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue");
- assertNotNull(boundOp);
-
- EdmAction act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
- assertNotNull(act);
-
- final ODataPrimitiveValue increaseValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Int64).setValue(12).build();
- final ODataInvokeRequest<ODataProperty> increaseRevenueReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
- Collections.<String, ODataValue>singletonMap("IncreaseValue", increaseValue));
- increaseRevenueReq.setFormat(format);
- final ODataProperty increaseRevenueRes = increaseRevenueReq.execute().getBody();
- assertNotNull(increaseRevenueRes);
- assertTrue(increaseRevenueRes.hasPrimitiveValue());
-
- // AddAccessRight
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Products").appendKeySegment(5);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight");
- assertNotNull(boundOp);
-
- act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
- assertNotNull(act);
-
- final ODataEnumValue accessRight = getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute");
- final ODataInvokeRequest<ODataProperty> getProductDetailsReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
- Collections.<String, ODataValue>singletonMap("accessRight", accessRight));
- getProductDetailsReq.setFormat(format);
- final ODataProperty getProductDetailsRes = getProductDetailsReq.execute().getBody();
- assertNotNull(getProductDetailsRes);
- assertTrue(getProductDetailsRes.hasEnumValue());
-
- // ResetAddress
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(2);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.ResetAddress");
- assertNotNull(boundOp);
-
- act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
- edm.getEntityType(entity.getTypeName()).getBaseType().getFullQualifiedName(), false);
- assertNotNull(act);
-
- final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> addresses =
- getClient().getObjectFactory().
- newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.Address)");
- final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
- newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
- address.add(client.getObjectFactory().newPrimitiveProperty("Street",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Piazza La Bomba E Scappa")));
- address.add(client.getObjectFactory().newPrimitiveProperty("City",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Tollo")));
- address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
- addresses.add(address);
- final ODataPrimitiveValue index = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(0);
- final Map<String, ODataValue> params = new LinkedHashMap<String, ODataValue>(2);
- params.put("addresses", addresses);
- params.put("index", index);
- final ODataInvokeRequest<ODataEntity> resetAddressReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act, params);
- resetAddressReq.setFormat(format);
- final ODataEntity resetAddressRes = resetAddressReq.execute().getBody();
- assertNotNull(resetAddressRes);
- assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // RefreshDefaultPI
- builder = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101);
- entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
- entityReq.setFormat(format);
- entity = entityReq.execute().getBody();
- assertNotNull(entity);
-
- boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.RefreshDefaultPI");
- assertNotNull(boundOp);
-
- act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
- assertNotNull(act);
-
- final ODataPrimitiveValue newDate = getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2014-04-09T00:00:00Z").build();
- final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
- getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
- Collections.<String, ODataValue>singletonMap("newDate", newDate));
- getDefaultPIReq.setFormat(format);
- final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
- assertNotNull(getDefaultPIRes);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
- getDefaultPIRes.getTypeName().toString());
- assertEquals(101901,
- getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
- }
-
- @Test
- public void atomActions() throws EdmPrimitiveTypeException {
- actions(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonActions() throws EdmPrimitiveTypeException {
- actions(ODataPubFormat.JSON_FULL_METADATA);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java
deleted file mode 100644
index 49dc262..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/DeltaTestITCase.java
+++ /dev/null
@@ -1,88 +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.client.core.it.v4;
-
-import org.apache.olingo.client.api.communication.header.ODataPreferences;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.v4.ODataDeltaRequest;
-import org.apache.olingo.commons.api.domain.v4.ODataDelta;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class DeltaTestITCase extends AbstractTestITCase {
-
- private void parse(final ODataPubFormat format) {
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().getEntitySetRequest(
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").build());
- req.setPrefer(client.newPreferences().trackChanges());
-
- final ODataEntitySet customers = req.execute().getBody();
- assertNotNull(customers);
- assertNotNull(customers.getDeltaLink());
-
- final ODataDeltaRequest deltaReq = client.getRetrieveRequestFactory().getDeltaRequest(customers.getDeltaLink());
- deltaReq.setFormat(format);
-
- final ODataDelta delta = deltaReq.execute().getBody();
- assertNotNull(delta);
-
- assertNotNull(delta.getDeltaLink());
- assertTrue(delta.getDeltaLink().isAbsolute());
- assertEquals(5, delta.getCount(), 0);
-
- assertEquals(1, delta.getDeletedEntities().size());
- assertTrue(delta.getDeletedEntities().get(0).getId().isAbsolute());
- assertTrue(delta.getDeletedEntities().get(0).getId().toASCIIString().endsWith("Customers('ANTON')"));
-
- assertEquals(1, delta.getAddedLinks().size());
- assertTrue(delta.getAddedLinks().get(0).getSource().isAbsolute());
- assertTrue(delta.getAddedLinks().get(0).getSource().toASCIIString().endsWith("Customers('BOTTM')"));
- assertEquals("Orders", delta.getAddedLinks().get(0).getRelationship());
-
- assertEquals(1, delta.getDeletedLinks().size());
- assertTrue(delta.getDeletedLinks().get(0).getSource().isAbsolute());
- assertTrue(delta.getDeletedLinks().get(0).getSource().toASCIIString().endsWith("Customers('ALFKI')"));
- assertEquals("Orders", delta.getDeletedLinks().get(0).getRelationship());
-
- assertEquals(2, delta.getEntities().size());
- ODataProperty property = delta.getEntities().get(0).getProperty("ContactName");
- assertNotNull(property);
- assertTrue(property.hasPrimitiveValue());
- property = delta.getEntities().get(1).getProperty("ShippingAddress");
- assertNotNull(property);
- assertTrue(property.hasComplexValue());
- }
-
- @Test
- public void atomParse() {
- parse(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonParse() {
- parse(ODataPubFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
deleted file mode 100644
index 66e885f..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityCreateTestITCase.java
+++ /dev/null
@@ -1,186 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URI;
-import java.util.Calendar;
-import org.apache.commons.lang3.RandomUtils;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class EntityCreateTestITCase extends AbstractTestITCase {
-
- @Test
- public void atomCreateAndDelete() {
- createAndDeleteOrder(ODataPubFormat.ATOM, 1000);
- }
-
- @Test
- public void jsonCreateAndDelete() {
- createAndDeleteOrder(ODataPubFormat.JSON, 1001);
- }
-
- private void onContained(final ODataPubFormat format) {
- final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Accounts").
- appendKeySegment(101).appendNavigationSegment("MyPaymentInstruments").build();
-
- // 1. read contained collection before any operation
- ODataEntitySet instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
- assertNotNull(instruments);
- final int sizeBefore = instruments.getCount();
-
- // 2. instantiate an ODataEntity of the same type as the collection above
- final ODataEntity instrument = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument"));
-
- int id = RandomUtils.nextInt(101999, 105000);
- instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("PaymentInstrumentID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
- instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("FriendlyName",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("New one")));
- instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CreatedDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
-
- // 3. create it as contained entity
- final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
- getEntityCreateRequest(uri, instrument);
- final ODataEntityCreateResponse<ODataEntity> res = req.execute();
- assertEquals(201, res.getStatusCode());
-
- // 4. verify that the contained collection effectively grew
- instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
- assertNotNull(instruments);
- final int sizeAfter = instruments.getCount();
- assertEquals(sizeBefore + 1, sizeAfter);
-
- // 5. remove the contained entity created above
- final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
- getDeleteRequest(getClient().getURIBuilder(uri.toASCIIString()).appendKeySegment(id).build()).execute();
- assertEquals(204, deleteRes.getStatusCode());
-
- // 6. verify that the contained collection effectively reduced
- instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
- assertNotNull(instruments);
- final int sizeEnd = instruments.getCount();
- assertEquals(sizeBefore, sizeEnd);
- }
-
- @Test
- public void atomOnContained() {
- onContained(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonOnContained() {
- onContained(ODataPubFormat.JSON);
- }
-
- private void deepInsert(final ODataPubFormat format, final int productId, final int productDetailId)
- throws EdmPrimitiveTypeException {
-
- final ODataEntity product = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Product"));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("Latte")));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityPerUnit",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("100g Bag")));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("UnitPrice",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(3.24f)));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityInStock",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(100)));
- product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Discontinued",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false)));
- product.getProperties().add(getClient().getObjectFactory().newEnumProperty("UserAccess",
- getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute")));
- product.getProperties().add(getClient().getObjectFactory().newEnumProperty("SkinColor",
- getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
- product.getProperties().add(getClient().getObjectFactory().newCollectionProperty("CoverColors",
- getClient().getObjectFactory().
- newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.ProductDetail)")));
- product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Green"));
- product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Red"));
-
- final ODataEntity detail = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"));
- detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
- detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductDetailID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productDetailId)));
- detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductName",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("LatteHQ")));
- detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Description",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("High-Quality Milk")));
-
- final ODataEntitySet details = getClient().getObjectFactory().newEntitySet();
- details.getEntities().add(detail);
-
- final ODataInlineEntitySet inlineDetails = getClient().getObjectFactory().
- newDeepInsertEntitySet("Details", details);
- product.addLink(inlineDetails);
-
- final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Products").build(), product);
- req.setFormat(format);
- final ODataEntityCreateResponse<ODataEntity> res = req.execute();
- assertEquals(201, res.getStatusCode());
-
- final ODataEntity createdProduct = res.getBody();
- assertEquals(productId,
- createdProduct.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- final ODataLink createdLink = createdProduct.getNavigationLink("Details");
- assertNotNull(createdLink);
-
- final ODataEntitySet createdProductDetails =
- getClient().getRetrieveRequestFactory().getEntitySetRequest(createdLink.getLink()).execute().getBody();
- assertNotNull(createdProductDetails);
- assertEquals(productDetailId, createdProductDetails.getEntities().iterator().next().
- getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class), 0);
- }
-
- @Test
- public void atomDeepInsert() throws EdmPrimitiveTypeException {
- deepInsert(ODataPubFormat.ATOM, 10, 10);
- }
-
- @Test
- public void jsonDeepInsert() throws EdmPrimitiveTypeException {
- deepInsert(ODataPubFormat.JSON_FULL_METADATA, 11, 11);
- }
-}
[02/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
deleted file mode 100644
index 4feea96..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,367 +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.client.core.it.v4;
-
-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 java.net.URI;
-import java.util.LinkedHashMap;
-import java.util.List;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
-import org.apache.olingo.client.api.communication.response.ODataRawResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.ODataLinkType;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check entity retrieve operations.
- */
-public class EntityRetrieveTestITCase extends AbstractTestITCase {
-
- private void withInlineEntry(final ODataClient client, final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
- getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
- assertTrue(entity.getProperty("Home").hasPrimitiveValue());
- assertEquals("Edm.GeographyPoint", entity.getProperty("Home").getPrimitiveValue().getTypeName());
- assertEquals(testStaticServiceRootURL + "/Customers(1)", entity.getEditLink().toASCIIString());
-
- // In JSON with minimal metadata, links are not provided
- if (format == ODataPubFormat.ATOM || format == ODataPubFormat.JSON_FULL_METADATA) {
- assertEquals(3, entity.getNavigationLinks().size());
-
- if (ODataPubFormat.ATOM == format) {
- assertTrue(entity.getAssociationLinks().isEmpty());
- // In JSON, association links for each $ref link will exist.
- }
-
- boolean found = false;
-
- for (ODataLink link : entity.getNavigationLinks()) {
- if (link instanceof ODataInlineEntity) {
- final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
- assertNotNull(inline);
-
- final List<? extends CommonODataProperty> properties = inline.getProperties();
- assertEquals(5, properties.size());
-
- assertTrue(properties.get(0).getName().equals("CompanyID")
- || properties.get(1).getName().equals("CompanyID")
- || properties.get(2).getName().equals("CompanyID")
- || properties.get(3).getName().equals("CompanyID")
- || properties.get(4).getName().equals("CompanyID"));
- assertTrue(properties.get(0).getValue().toString().equals("0")
- || properties.get(1).getValue().toString().equals("0")
- || properties.get(2).getValue().toString().equals("0")
- || properties.get(3).getValue().toString().equals("0")
- || properties.get(4).getValue().toString().equals("0"));
-
- found = true;
- }
- }
-
- assertTrue(found);
- }
- }
-
- @Test
- public void withInlineEntryFromAtom() {
- withInlineEntry(client, ODataPubFormat.ATOM);
- }
-
- @Test
- public void withInlineEntryFromFullJSON() {
- withInlineEntry(client, ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void withInlineEntryFromJSON() {
- withInlineEntry(edmClient, ODataPubFormat.JSON);
- }
-
- private void withInlineFeed(final ODataClient client, final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().
- getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
-
- // In JSON with minimal metadata, links are not provided
- if (format == ODataPubFormat.ATOM || format == ODataPubFormat.JSON_FULL_METADATA) {
- boolean found = false;
- for (ODataLink link : entity.getNavigationLinks()) {
- if (link instanceof ODataInlineEntitySet) {
- final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
- assertNotNull(inline);
-
- found = true;
- }
- }
- assertTrue(found);
- }
- }
-
- @Test
- public void withInlineFeedFromAtom() {
- withInlineFeed(client, ODataPubFormat.ATOM);
- }
-
- @Test
- public void withInlineFeedFromFullJSON() {
- withInlineFeed(client, ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void withInlineFeedFromJSON() {
- withInlineFeed(edmClient, ODataPubFormat.JSON);
- }
-
- private void rawRequest(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5);
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertNull(entitySet);
-
- final ResWrap<ODataEntity> entity = res.getBodyAs(ODataEntity.class);
- assertTrue(entity.getPayload().getReference().endsWith("/StaticService/V40/Static.svc/People(5)"));
- }
-
- @Test
- public void rawRequestAsAtom() {
- rawRequest(ODataPubFormat.ATOM);
- }
-
- @Test
- public void rawRequestAsJSON() {
- // this needs to be full, otherwise reference will not be provided
- rawRequest(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void multiKey(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final LinkedHashMap<String, Object> multiKey = new LinkedHashMap<String, Object>();
- multiKey.put("ProductID", "6");
- multiKey.put("ProductDetailID", 1);
-
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("ProductDetails").appendKeySegment(multiKey);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertEquals(Integer.valueOf(1),
- entity.getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class));
- }
-
- @Test
- public void multiKeyAsAtom() throws EdmPrimitiveTypeException {
- multiKey(ODataPubFormat.ATOM);
- }
-
- @Test
- public void multiKeyAsJSON() throws EdmPrimitiveTypeException {
- multiKey(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void checkForETag(final ODataClient client, final ODataPubFormat format) {
- final URIBuilder uriBuilder =
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders").appendKeySegment(8);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final String etag = res.getETag();
- assertTrue(StringUtils.isNotBlank(etag));
-
- final ODataEntity order = res.getBody();
- assertEquals(etag, order.getETag());
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Order", order.getTypeName().toString());
- assertEquals("Edm.Int32", order.getProperty("OrderID").getPrimitiveValue().getTypeName());
- assertEquals("Edm.DateTimeOffset", order.getProperty("OrderDate").getPrimitiveValue().getTypeName());
- assertEquals("Edm.Duration", order.getProperty("ShelfLife").getPrimitiveValue().getTypeName());
- assertEquals("Collection(Edm.Duration)", order.getProperty("OrderShelfLifes").getCollectionValue().getTypeName());
- }
-
- @Test
- public void checkForETagAsATOM() {
- checkForETag(client, ODataPubFormat.ATOM);
- }
-
- @Test
- public void checkForETagAsFullJSON() {
- checkForETag(client, ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void checkForETagAsJSON() {
- checkForETag(edmClient, ODataPubFormat.JSON);
- }
-
- @Test(expected = IllegalArgumentException.class)
- public void issue99() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON);
-
- // this statement should cause an IllegalArgumentException bearing JsonParseException
- // since we are attempting to parse an EntitySet as if it was an Entity
- req.execute().getBody();
- }
-
- private void reference(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Orders").appendKeySegment(8).appendNavigationSegment("CustomerForOrder").
- appendRefSegment();
-
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertNotNull(res);
-
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
- assertTrue(entity.getReference().endsWith("/StaticService/V40/Static.svc/Customers(PersonID=1)"));
-
- final URI referenceURI =
- client.getURIBuilder(testStaticServiceRootURL).appendEntityIdSegment(entity.getReference()).build();
-
- req = client.getRetrieveRequestFactory().getEntityRequest(referenceURI);
- req.setFormat(format);
-
- res = req.execute();
- assertNotNull(res);
- assertNotNull(res.getBody());
- }
-
- @Test
- public void atomReference() {
- reference(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonReference() {
- reference(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void contained(final ODataClient client, final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final URI uri = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101).
- appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101901).build();
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
- req.setFormat(format);
-
- final ODataEntity contained = req.execute().getBody();
- assertNotNull(contained);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument", contained.getTypeName().toString());
- assertEquals(101901,
- contained.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
- assertEquals("Edm.DateTimeOffset", contained.getProperty("CreatedDate").getPrimitiveValue().getTypeName());
- }
-
- @Test
- public void containedFromAtom() throws EdmPrimitiveTypeException {
- contained(client, ODataPubFormat.ATOM);
- }
-
- @Test
- public void containedFromFullJSON() throws EdmPrimitiveTypeException {
- contained(client, ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void containedFromJSON() throws EdmPrimitiveTypeException {
- contained(edmClient, ODataPubFormat.JSON);
- }
-
- private void entitySetNavigationLink(final ODataClient client, final ODataPubFormat format) {
- final URI uri = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101).build();
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uri);
- req.setFormat(format);
-
- final ODataEntity entity = req.execute().getBody();
- assertNotNull(entity);
-
- // With JSON, entity set navigation links are only recognizable via Edm
- if (format == ODataPubFormat.ATOM || client instanceof EdmEnabledODataClient) {
- assertEquals(ODataLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("MyPaymentInstruments").getType());
- assertEquals(ODataLinkType.ENTITY_SET_NAVIGATION, entity.getNavigationLink("ActiveSubscriptions").getType());
- }
- }
-
- @Test
- public void entitySetNavigationLinkFromAtom() {
- entitySetNavigationLink(client, ODataPubFormat.ATOM);
- }
-
- @Test
- public void entitySetNavigationLinkFromJSON() {
- // only JSON_FULL_METADATA has links, only Edm can recognize entity set navigation
- entitySetNavigationLink(edmClient, ODataPubFormat.JSON_FULL_METADATA);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java
deleted file mode 100644
index e4265fe..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntitySetTestITCase.java
+++ /dev/null
@@ -1,179 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetIteratorRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataRawRequest;
-import org.apache.olingo.client.api.communication.response.ODataRawResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.domain.ODataEntitySetIterator;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.data.ResWrap;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-/**
- * This is the unit test class to check basic feed operations.
- */
-public class EntitySetTestITCase extends AbstractTestITCase {
-
- private void rawRequest(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("People");
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertNotNull(entitySet.getPayload());
- assertTrue(entitySet.getContextURL().getURI().toASCIIString().endsWith("$metadata#People"));
- }
-
- @Test
- public void rawRequestAsAtom() throws IOException {
- rawRequest(ODataPubFormat.ATOM);
- }
-
- @Test
- public void rawRequestAsJSON() throws IOException {
- rawRequest(ODataPubFormat.JSON);
- }
-
- private void readWithInlineCount(final ODataClient client, final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("People").count(true);
-
- final ODataRawRequest req = client.getRetrieveRequestFactory().getRawRequest(uriBuilder.build());
- req.setFormat(format.toString(client.getServiceVersion()));
-
- final ODataRawResponse res = req.execute();
- assertNotNull(res);
-
- final ResWrap<ODataEntitySet> entitySet = res.getBodyAs(ODataEntitySet.class);
- assertEquals(5, entitySet.getPayload().getCount());
-
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address",
- entitySet.getPayload().getEntities().get(2).getProperty("HomeAddress").getComplexValue().getTypeName());
- }
-
- @Test
- public void readWithInlineCountAsJSON() throws IOException {
- readWithInlineCount(edmClient, ODataPubFormat.JSON);
- }
-
- @Test
- public void readWithInlineCountAsFullJSON() throws IOException {
- readWithInlineCount(client, ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void readWithInlineCountAsAtom() throws IOException {
- readWithInlineCount(client, ODataPubFormat.ATOM);
- }
-
- private void readODataEntitySetIterator(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("People");
-
- final ODataEntitySetIteratorRequest<ODataEntitySet, ODataEntity> req =
- client.getRetrieveRequestFactory().getEntitySetIteratorRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySetIterator<ODataEntitySet, ODataEntity>> res = req.execute();
- final ODataEntitySetIterator<ODataEntitySet, ODataEntity> feedIterator = res.getBody();
-
- assertNotNull(feedIterator);
-
- int count = 0;
-
- while (feedIterator.hasNext()) {
- assertNotNull(feedIterator.next());
- count++;
- }
- assertEquals(5, count);
- assertTrue(feedIterator.getNext().toASCIIString().endsWith("People?$skiptoken=5"));
- }
-
- @Test
- public void readODataEntitySetIteratorFromAtom() {
- readODataEntitySetIterator(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSON() {
- readODataEntitySetIterator(ODataPubFormat.JSON);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSONFull() {
- readODataEntitySetIterator(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void readODataEntitySetIteratorFromJSONNo() {
- readODataEntitySetIterator(ODataPubFormat.JSON_NO_METADATA);
- }
-
- private void readEntitySetWithNextLink(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
- uriBuilder.appendEntitySetSegment("People");
-
- final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
- getEntitySetRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntitySet> res = req.execute();
- final ODataEntitySet feed = res.getBody();
-
- assertNotNull(feed);
-
- assertEquals(5, feed.getEntities().size());
- assertNotNull(feed.getNext());
-
- final URI expected = URI.create(testStaticServiceRootURL + "/People?$skiptoken=5");
- final URI found = URIUtils.getURI(testStaticServiceRootURL, feed.getNext().toASCIIString());
-
- assertEquals(expected, found);
- }
-
- @Test
- public void readODataEntitySetWithNextFromAtom() {
- readEntitySetWithNextLink(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readODataEntitySetWithNextFromJSON() {
- readEntitySetWithNextLink(ODataPubFormat.JSON_FULL_METADATA);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityUpdateTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityUpdateTestITCase.java
deleted file mode 100644
index 30e6607..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/EntityUpdateTestITCase.java
+++ /dev/null
@@ -1,154 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URI;
-import java.util.Calendar;
-import java.util.UUID;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class EntityUpdateTestITCase extends AbstractTestITCase {
-
- private void upsert(final UpdateType updateType, final ODataPubFormat format) {
- final ODataEntity order = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
-
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(9)));
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
- order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
-
- final URI upsertURI = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Orders").appendKeySegment(9).build();
- final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
- getEntityUpdateRequest(upsertURI, updateType, order);
- req.setFormat(format);
-
- req.execute();
- try {
- final ODataEntity read = read(format, upsertURI);
- assertNotNull(read);
- assertEquals(order.getProperty("OrderID"), read.getProperty("OrderID"));
- assertEquals(order.getProperty("OrderDate").getPrimitiveValue().toString(),
- read.getProperty("OrderDate").getPrimitiveValue().toString());
- assertEquals(order.getProperty("ShelfLife").getPrimitiveValue().toString(),
- read.getProperty("ShelfLife").getPrimitiveValue().toString());
- } finally {
- getClient().getCUDRequestFactory().getDeleteRequest(upsertURI).execute();
- }
- }
-
- @Test
- public void atomUpsert() {
- upsert(UpdateType.PATCH, ODataPubFormat.ATOM);
- upsert(UpdateType.REPLACE, ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonUpsert() {
- upsert(UpdateType.PATCH, ODataPubFormat.JSON);
- upsert(UpdateType.REPLACE, ODataPubFormat.JSON);
- }
-
- private void onContained(final ODataPubFormat format) {
- final String newName = UUID.randomUUID().toString();
- final ODataEntity changes = getClient().getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument"));
- changes.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("FriendlyName",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(newName)));
-
- final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101).
- appendNavigationSegment("MyPaymentInstruments").appendKeySegment(101901).build();
- final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
- getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
- req.setFormat(format);
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- final ODataEntity actual = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
- assertNotNull(actual);
- assertEquals(newName, actual.getProperty("FriendlyName").getPrimitiveValue().toString());
- }
-
- @Test
- public void atomOnContained() {
- onContained(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonOnContained() {
- onContained(ODataPubFormat.JSON);
- }
-
- private void bindOperation(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final ODataEntity changes = getClient().getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
- final ODataLink parent = getClient().getObjectFactory().newEntityNavigationLink("Parent",
- getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(1).build());
- changes.getNavigationLinks().add(parent);
-
- final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).build();
- final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
- getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
- req.setFormat(format);
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- final ODataEntity updated = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
- assertNotNull(updated);
- final ODataLink updatedLink = updated.getNavigationLink("Parent");
- assertNotNull(updatedLink);
-
- final ODataEntity updatedEntity = getClient().getRetrieveRequestFactory().getEntityRequest(updatedLink.getLink()).
- execute().getBody();
- assertNotNull(updatedEntity);
- assertEquals(1, updatedEntity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
- }
-
- @Test
- public void atomBindOperation() throws EdmPrimitiveTypeException {
- bindOperation(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonBindOperation() throws EdmPrimitiveTypeException {
- bindOperation(ODataPubFormat.JSON);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/FilterFactoryTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/FilterFactoryTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/FilterFactoryTestITCase.java
deleted file mode 100644
index 4062de5..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/FilterFactoryTestITCase.java
+++ /dev/null
@@ -1,63 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.apache.olingo.client.core.it.v4.AbstractTestITCase.client;
-
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
-import org.apache.olingo.client.api.uri.URIFilter;
-import org.apache.olingo.client.api.uri.v4.FilterArgFactory;
-import org.apache.olingo.client.api.uri.v4.FilterFactory;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class FilterFactoryTestITCase extends AbstractTestITCase {
-
- private FilterFactory getFilterFactory() {
- return getClient().getFilterFactory();
- }
-
- private FilterArgFactory getFilterArgFactory() {
- return getFilterFactory().getArgFactory();
- }
-
- @Test
- public void crossjoin() {
- final URIFilter filter = getFilterFactory().eq(
- getFilterArgFactory().property("Orders/OrderID"), getFilterArgFactory().property("Customers/Order"));
-
- final URIBuilder uriBuilder =
- client.getURIBuilder(testStaticServiceRootURL).appendCrossjoinSegment("Customers", "Orders").filter(filter);
-
- final ODataEntitySetRequest<ODataEntitySet> req =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
- req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
-
- final ODataEntitySet feed = req.execute().getBody();
- assertEquals(3, feed.getEntities().size());
-
- for (ODataEntity entity : feed.getEntities()) {
- assertEquals(2, entity.getNavigationLinks().size());
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/KeyAsSegmentTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/KeyAsSegmentTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/KeyAsSegmentTestITCase.java
deleted file mode 100644
index 91d4c85..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/KeyAsSegmentTestITCase.java
+++ /dev/null
@@ -1,122 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import java.net.URI;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
-
-public class KeyAsSegmentTestITCase extends AbstractTestITCase {
-
- @BeforeClass
- public static void enableKeyAsSegment() {
- client.getConfiguration().setKeyAsSegment(true);
- }
-
- private void read(final ODataPubFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testKeyAsSegmentServiceRootURL).
- appendEntitySetSegment("Accounts").appendKeySegment(101);
-
- final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
- assertNotNull(entity);
-
- assertFalse(entity.getEditLink().toASCIIString().contains("("));
- assertFalse(entity.getEditLink().toASCIIString().contains(")"));
- }
-
- @Test
- public void atomRead() {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonRead() {
- read(ODataPubFormat.JSON);
- }
-
- @Test
- public void atomCreateAndDelete() {
- createAndDeleteOrder(ODataPubFormat.ATOM, 1000);
- }
-
- @Test
- public void jsonCreateAndDelete() {
- createAndDeleteOrder(ODataPubFormat.JSON, 1001);
- }
-
- private void update(final ODataPubFormat format) {
- final ODataEntity changes = getClient().getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
- final ODataProperty middleName = getClient().getObjectFactory().newPrimitiveProperty("MiddleName",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("middle"));
- changes.getProperties().add(middleName);
-
- final URI uri = getClient().getURIBuilder(testKeyAsSegmentServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).build();
- final ODataEntityUpdateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
- getEntityUpdateRequest(uri, UpdateType.PATCH, changes);
- req.setFormat(format);
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(204, res.getStatusCode());
-
- final ODataEntity updated = getClient().getRetrieveRequestFactory().getEntityRequest(uri).execute().getBody();
- assertNotNull(updated);
- assertFalse(updated.getEditLink().toASCIIString().contains("("));
- assertFalse(updated.getEditLink().toASCIIString().contains(")"));
-
- final ODataProperty updatedMiddleName = updated.getProperty("MiddleName");
- assertNotNull(updatedMiddleName);
- assertEquals("middle", updatedMiddleName.getPrimitiveValue().toString());
- }
-
- @Test
- public void atomUpdate() {
- update(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonUpdate() {
- update(ODataPubFormat.JSON);
- }
-
- @AfterClass
- public static void disableKeyAsSegment() {
- client.getConfiguration().setKeyAsSegment(false);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/MetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/MetadataTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/MetadataTestITCase.java
deleted file mode 100644
index 4bac063..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/MetadataTestITCase.java
+++ /dev/null
@@ -1,71 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.client.core.it.AbstractMetadataTestITCase;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.junit.Test;
-
-public class MetadataTestITCase extends AbstractMetadataTestITCase {
-
- @Override
- protected ODataClient getClient() {
- return ODataClientFactory.getV4();
- }
-
- @Test
- public void retrieve() {
- final Edm metadata = getClient().getRetrieveRequestFactory().
- getMetadataRequest(getTestServiceRoot()).execute().getBody();
- assertNotNull(metadata);
-
- final EdmEntityType order = metadata.getEntityType(
- new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService", "Order"));
- assertNotNull(order);
-
- final EdmProperty orderDate = order.getStructuralProperty("OrderDate");
- assertNotNull(orderDate);
- assertEquals("Edm.DateTimeOffset", orderDate.getType().getFullQualifiedName().toString());
- }
-
- @Test
- public void include() {
- final Edm metadata = getClient().getRetrieveRequestFactory().
- getMetadataRequest(getNorthwindServiceRoot()).execute().getBody();
- assertNotNull(metadata);
-
- final EdmEntityContainer container = metadata.getEntityContainer(
- new FullQualifiedName("ODataWebExperimental.Northwind.Model", "NorthwindEntities"));
- assertNotNull(container);
-
- final EdmEntitySet categories = container.getEntitySet("Categories");
- assertNotNull(categories);
- assertEquals("NorthwindModel", categories.getEntityType().getNamespace());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OpenTypeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OpenTypeTestITCase.java
deleted file mode 100644
index 475a0fb..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OpenTypeTestITCase.java
+++ /dev/null
@@ -1,188 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Calendar;
-import java.util.UUID;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmSchema;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class OpenTypeTestITCase extends AbstractTestITCase {
-
- @Test
- public void checkOpenTypeEntityTypesExist() {
- final Edm metadata = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
-
- final EdmSchema schema = metadata.getSchemas().get(0);
-
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "Row")).isOpenType());
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "IndexedRow")).isOpenType());
- assertTrue(metadata.getEntityType(new FullQualifiedName(schema.getNamespace(), "RowIndex")).isOpenType());
- }
-
- private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
- final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("Row").appendKeySegment(UUID.fromString(uuid));
- return read(format, builder.build());
- }
-
- private void read(final ODataPubFormat format) {
- ODataEntity row = readRow(format, "71f7d0dc-ede4-45eb-b421-555a2aa1e58f");
- assertEquals(EdmPrimitiveTypeKind.Double, row.getProperty("Double").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.Guid, row.getProperty("Id").getPrimitiveValue().getTypeKind());
-
- row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
- assertEquals(EdmPrimitiveTypeKind.Decimal, row.getProperty("Decimal").getPrimitiveValue().getTypeKind());
- }
-
- @Test
- public void readAsAtom() {
- read(ODataPubFormat.ATOM);
- }
-
- @Test
- public void readAsJSON() {
- read(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void cud(final ODataPubFormat format) {
- final Integer id = 1426;
-
- ODataEntity rowIndex = getClient().getObjectFactory().newEntity(
- new FullQualifiedName("Microsoft.Test.OData.Services.OpenTypesService.RowIndex"));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("Id",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aString",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("string")));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aBoolean",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(true)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aDouble",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.5D)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aByte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).
- build()));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
- build()));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newPrimitiveProperty("aDate",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).
- build()));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newEnumProperty("aColor", getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
-
- final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("FirstContacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildBinary("text".getBytes())));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("LastContacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2001-04-05T05:05:05.001+00:01").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Contacted",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Date).setText("2001-04-05").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("GUID",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildGuid(UUID.randomUUID())));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("PreferedContactTime",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Duration).setText("-P9DT51M10.5063807S").build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Byte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Byte).setValue(24).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("SignedByte",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.SByte).setValue(Byte.MAX_VALUE).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Double",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(Double.MAX_VALUE)));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Single",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(Float.MAX_VALUE)));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Short",
- getClient().getObjectFactory().newPrimitiveValueBuilder().
- setType(EdmPrimitiveTypeKind.Int16).setValue(Short.MAX_VALUE).build()));
- contactDetails.add(getClient().getObjectFactory().newPrimitiveProperty("Int",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(Integer.MAX_VALUE)));
- getClient().getBinder().add(rowIndex,
- getClient().getObjectFactory().newComplexProperty("aContact", contactDetails));
-
- final ODataEntityCreateRequest<ODataEntity> createReq = getClient().getCUDRequestFactory().
- getEntityCreateRequest(getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("RowIndex").build(), rowIndex);
- createReq.setFormat(format);
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
-
- final URIBuilder builder = getClient().getURIBuilder(testOpenTypeServiceRootURL).
- appendEntitySetSegment("RowIndex").appendKeySegment(id);
- rowIndex = read(format, builder.build());
- assertNotNull(rowIndex);
- assertEquals(EdmPrimitiveTypeKind.Int32,
- rowIndex.getProperty("Id").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.String,
- rowIndex.getProperty("aString").getPrimitiveValue().getTypeKind());
- assertEquals(EdmPrimitiveTypeKind.Boolean,
- rowIndex.getProperty("aBoolean").getPrimitiveValue().getTypeKind());
- assertTrue(rowIndex.getProperty("aDouble").hasPrimitiveValue());
- assertTrue(rowIndex.getProperty("aByte").hasPrimitiveValue());
- assertTrue(rowIndex.getProperty("aDate").hasPrimitiveValue());
- assertNotNull(rowIndex.getProperty("aColor"));
- assertTrue(rowIndex.getProperty("aContact").hasComplexValue());
- assertTrue(rowIndex.getProperty("aContact").getComplexValue().get("SignedByte").hasPrimitiveValue());
-
- final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
- getDeleteRequest(rowIndex.getEditLink()).execute();
- assertEquals(204, deleteRes.getStatusCode());
- }
-
- @Test
- public void cudAsAtom() {
- cud(ODataPubFormat.ATOM);
- }
-
- @Test
- public void cudAsJSON() {
- cud(ODataPubFormat.JSON_FULL_METADATA);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
deleted file mode 100644
index 96ec485..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/OperationImportInvokeTestITCase.java
+++ /dev/null
@@ -1,258 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-
-import java.util.Collections;
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
-import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v4.ODataEntity;
-import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmFunctionImport;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-
-import org.junit.Test;
-
-public class OperationImportInvokeTestITCase extends AbstractTestITCase {
-
- private Edm getEdm() {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testStaticServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- return edm;
- }
-
- private void functionImports(final ODataPubFormat format) throws EdmPrimitiveTypeException {
- final Edm edm = getEdm();
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- // GetDefaultColor
- EdmFunctionImport funcImp = container.getFunctionImport("GetDefaultColor");
-
- final ODataInvokeRequest<ODataProperty> defaultColorReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0));
- defaultColorReq.setFormat(format);
- final ODataProperty defaultColor = defaultColorReq.execute().getBody();
- assertNotNull(defaultColor);
- assertTrue(defaultColor.hasEnumValue());
- assertEquals("Red", defaultColor.getEnumValue().getValue());
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Color", defaultColor.getEnumValue().getTypeName());
-
- // GetPerson2
- funcImp = container.getFunctionImport("GetPerson2");
-
- final ODataPrimitiveValue city =
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("London");
-
- final ODataInvokeRequest<ODataEntity> person2Req = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0),
- Collections.<String, ODataValue>singletonMap("city", city));
- person2Req.setFormat(format);
- final ODataEntity person2 = person2Req.execute().getBody();
- assertNotNull(person2);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", person2.getTypeName().toString());
- assertEquals(1, person2.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // GetPerson
- funcImp = container.getFunctionImport("GetPerson");
-
- final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
- newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
- address.add(client.getObjectFactory().newPrimitiveProperty("Street",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("1 Microsoft Way")));
- address.add(client.getObjectFactory().newPrimitiveProperty("City",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("London")));
- address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("98052")));
-
- final ODataInvokeRequest<ODataEntity> personReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0),
- Collections.<String, ODataValue>singletonMap("address", address));
- personReq.setFormat(format);
- final ODataEntity person = personReq.execute().getBody();
- assertNotNull(person);
- assertEquals(person2, person);
-
- // GetAllProducts
- funcImp = container.getFunctionImport("GetAllProducts");
-
- final ODataInvokeRequest<ODataEntitySet> productsReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0));
- productsReq.setFormat(format);
- final ODataEntitySet products = productsReq.execute().getBody();
- assertNotNull(products);
- assertEquals(5, products.getCount());
-
- // GetProductsByAccessLevel
- funcImp = container.getFunctionImport("GetProductsByAccessLevel");
-
- final ODataEnumValue accessLevel = getClient().getObjectFactory().
- newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "None");
-
- final ODataInvokeRequest<ODataProperty> prodByALReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0),
- Collections.<String, ODataValue>singletonMap("accessLevel", accessLevel));
- prodByALReq.setFormat(format);
- final ODataProperty prodByAL = prodByALReq.execute().getBody();
- assertNotNull(prodByAL);
- assertTrue(prodByAL.hasCollectionValue());
- assertEquals(5, prodByAL.getCollectionValue().size());
- assertTrue(prodByAL.getCollectionValue().asJavaCollection().contains("Car"));
- }
-
- @Test
- public void atomFunctionImports() throws EdmPrimitiveTypeException {
- functionImports(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonFunctionImports() throws EdmPrimitiveTypeException {
- functionImports(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void actionImports(final ODataPubFormat format) {
- final Edm edm = getEdm();
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- // Discount
- EdmActionImport actImp = container.getActionImport("Discount");
-
- final ODataPrimitiveValue percentage = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(22);
- final ODataInvokeRequest<ODataNoContent> discountReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(actImp.getName()).build(),
- actImp.getUnboundAction(),
- Collections.<String, ODataValue>singletonMap("percentage", percentage));
- discountReq.setFormat(format);
- final ODataNoContent discount = discountReq.execute().getBody();
- assertNotNull(discount);
-
- // ResetBossAddress
- actImp = container.getActionImport("ResetBossAddress");
-
- final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
- newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
- address.add(client.getObjectFactory().newPrimitiveProperty("Street",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Via Le Mani Dal Naso, 123")));
- address.add(client.getObjectFactory().newPrimitiveProperty("City",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("Tollo")));
- address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
-
- final ODataInvokeRequest<ODataProperty> resetBossAddressReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(actImp.getName()).build(),
- actImp.getUnboundAction(),
- Collections.<String, ODataValue>singletonMap("address", address));
- resetBossAddressReq.setFormat(format);
- final ODataProperty resetBossAddress = resetBossAddressReq.execute().getBody();
- assertNotNull(resetBossAddress);
- }
-
- @Test
- public void atomActionImports() {
- actionImports(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonActionImports() {
- actionImports(ODataPubFormat.JSON_FULL_METADATA);
- }
-
- private void bossEmails(final ODataPubFormat format) {
- final Edm edm = getEdm();
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- // ResetBossEmail
- final EdmActionImport actImp = container.getActionImport("ResetBossEmail");
-
- final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> emails =
- getClient().getObjectFactory().newCollectionValue("Collection(Edm.String)");
- emails.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("first@olingo.apache.org"));
- emails.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("second@olingo.apache.org"));
- ODataInvokeRequest<ODataProperty> bossEmailsReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(actImp.getName()).build(),
- actImp.getUnboundAction(),
- Collections.<String, ODataValue>singletonMap("emails", emails));
- bossEmailsReq.setFormat(format);
- final ODataProperty bossEmails = bossEmailsReq.execute().getBody();
- assertNotNull(bossEmails);
- assertTrue(bossEmails.hasCollectionValue());
- assertEquals(2, bossEmails.getCollectionValue().size());
-
- final EdmFunctionImport funcImp = container.getFunctionImport("GetBossEmails");
-
- final Map<String, ODataValue> params = new LinkedHashMap<String, ODataValue>(2);
- params.put("start", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(0));
- params.put("count", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(100));
- bossEmailsReq = getClient().getInvokeRequestFactory().
- getInvokeRequest(getClient().getURIBuilder(testStaticServiceRootURL).
- appendOperationCallSegment(funcImp.getName()).build(),
- funcImp.getUnboundFunctions().get(0),
- params);
- bossEmailsReq.setFormat(format);
- final ODataProperty bossEmailsViaGET = bossEmailsReq.execute().getBody();
- assertNotNull(bossEmailsViaGET);
- assertTrue(bossEmailsViaGET.hasCollectionValue());
- assertEquals(2, bossEmailsViaGET.getCollectionValue().size());
- assertEquals(bossEmails.getCollectionValue().asJavaCollection(),
- bossEmailsViaGET.getCollectionValue().asJavaCollection());
- }
-
- @Test
- public void atomBossEmails() throws EdmPrimitiveTypeException {
- bossEmails(ODataPubFormat.ATOM);
- }
-
- @Test
- public void jsonBossEmails() throws EdmPrimitiveTypeException {
- bossEmails(ODataPubFormat.JSON_FULL_METADATA);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyTestITCase.java
deleted file mode 100644
index 78605bf..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyTestITCase.java
+++ /dev/null
@@ -1,164 +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.client.core.it.v4;
-
-import java.io.IOException;
-import org.apache.olingo.client.api.communication.request.cud.ODataPropertyUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-
-import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
-import org.apache.olingo.client.api.communication.response.ODataPropertyUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.client.api.v4.ODataClient;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.junit.Test;
-
-public class PropertyTestITCase extends AbstractTestITCase {
-
- private void _enum(final ODataClient client, final ODataFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Products").appendKeySegment(5).appendPropertySegment("CoverColors");
- final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataProperty prop = req.execute().getBody();
- assertNotNull(prop);
- assertEquals("Collection(Microsoft.Test.OData.Services.ODataWCFService.Color)", prop.getValue().getTypeName());
- }
-
- @Test
- public void enumFromXML() {
- _enum(client, ODataFormat.XML);
- }
-
- @Test
- public void enumFromJSON() {
- _enum(edmClient, ODataFormat.JSON);
- }
-
- @Test
- public void enumFromFullJSON() {
- _enum(client, ODataFormat.JSON_FULL_METADATA);
- }
-
- private void geospatial(final ODataClient client, final ODataFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Home");
- final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataProperty prop = req.execute().getBody();
- assertNotNull(prop);
- assertEquals("Edm.GeographyPoint", prop.getValue().getTypeName());
- }
-
- @Test
- public void geospatialFromXML() {
- geospatial(client, ODataFormat.XML);
- }
-
- @Test
- public void geospatialFromJSON() {
- geospatial(edmClient, ODataFormat.JSON);
- }
-
- @Test
- public void geospatialFromFullJSON() {
- geospatial(client, ODataFormat.JSON_FULL_METADATA);
- }
-
- private void complex(final ODataClient client, final ODataFormat format) {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(2).appendPropertySegment("HomeAddress");
- final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataProperty prop = req.execute().getBody();
- assertNotNull(prop);
- assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Address", prop.getValue().getTypeName());
- }
-
- @Test
- public void complexFromXML() {
- complex(client, ODataFormat.XML);
- }
-
- @Test
- public void complexFromJSON() {
- complex(edmClient, ODataFormat.JSON);
- }
-
- @Test
- public void complexFromFullJSON() {
- complex(client, ODataFormat.JSON_FULL_METADATA);
- }
-
- @Test
- public void patchComplexPropertyAsJSON() throws IOException {
- updateComplexProperty(ODataFormat.JSON_FULL_METADATA, UpdateType.PATCH);
- }
-
- private void updateComplexProperty(final ODataFormat format, final UpdateType type) throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customers").appendKeySegment(1).appendPropertySegment("HomeAddress");
-
- ODataPropertyRequest<ODataProperty> retrieveReq =
- client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- ODataRetrieveResponse<ODataProperty> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- ODataProperty homeAddress =
- client.getObjectFactory().newComplexProperty("HomeAddress",
- client.getObjectFactory().newComplexValue(retrieveRes.getBody().getComplexValue().getTypeName()));
-
- homeAddress.getComplexValue().add(client.getObjectFactory().
- newPrimitiveProperty("City", client.getObjectFactory().newPrimitiveValueBuilder().buildString("Pescara")));
-
- final ODataPropertyUpdateRequest updateReq = client.getCUDRequestFactory().
- getPropertyComplexValueUpdateRequest(uriBuilder.build(), type, homeAddress);
- if (client.getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, updateReq.getMethod());
- } else {
- assertEquals(type.getMethod(), updateReq.getMethod());
- }
- updateReq.setFormat(format);
-
- final ODataPropertyUpdateResponse updateRes = updateReq.execute();
- assertEquals(204, updateRes.getStatusCode());
-
- retrieveReq = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
- retrieveReq.setFormat(format);
-
- retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
-
- homeAddress = retrieveRes.getBody();
- assertEquals("Pescara", homeAddress.getComplexValue().get("City").getPrimitiveValue().toString());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyValueTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyValueTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyValueTestITCase.java
deleted file mode 100644
index 4b457be..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v4/PropertyValueTestITCase.java
+++ /dev/null
@@ -1,147 +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.client.core.it.v4;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-
-import java.io.IOException;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataPropertyRequest;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
-import org.apache.olingo.client.api.uri.v4.URIBuilder;
-import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
-import org.apache.olingo.commons.api.domain.v4.ODataProperty;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.commons.api.format.ODataFormat;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.apache.olingo.commons.api.format.ODataValueFormat;
-import org.junit.Test;
-
-public class PropertyValueTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveIntPropertyValueTest() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PersonID").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- assertEquals("5", req.execute().getBody().toString());
- }
-
- @Test
- public void retrieveBooleanPropertyValueTest() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("IsRegistered").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- assertEquals("true", req.execute().getBody().toString());
- }
-
- @Test
- public void retrieveStringPropertyValueTest() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("FirstName").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- assertEquals("Peter", req.execute().getBody().toString());
- }
-
- @Test
- public void retrieveDatePropertyValueTest() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Orders").appendKeySegment(8).appendPropertySegment("OrderDate").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataPrimitiveValue property = req.execute().getBody();
- assertEquals("2011-03-04T16:03:57Z", property.toString());
- }
-
- @Test
- public void retrieveDecimalPropertyValueTest() throws EdmPrimitiveTypeException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Height").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataPrimitiveValue property = req.execute().getBody();
- assertEquals("179", property.toString());
- }
-
- @Test
- public void retrieveBinaryPropertyValueTest() throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataPrimitiveValue property = req.execute().getBody();
- assertEquals("fi653p3+MklA/LdoBlhWgnMTUUEo8tEgtbMXnF0a3CUNL9BZxXpSRiD9ebTnmNR0zWPjJ"
- + "VIDx4tdmCnq55XrJh+RW9aI/b34wAogK3kcORw=", property.toString());
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void retrieveBinaryPropertyValueTestWithAtom() throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setAccept(ODataPubFormat.ATOM.toString(ODataServiceVersion.V40));
- req.execute().getBody();
- }
-
- @Test(expected = ODataClientErrorException.class)
- public void retrieveBinaryPropertyValueTestWithXML() throws IOException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("PDC").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setAccept(ODataFormat.XML.toString(client.getServiceVersion()));
- req.execute().getBody();
- }
-
- @Test
- public void retrieveCollectionPropertyValueTest() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("Numbers");
- final ODataPropertyRequest<ODataProperty> req = client.getRetrieveRequestFactory().
- getPropertyRequest(uriBuilder.build());
- req.setFormat(ODataFormat.XML);
- final ODataProperty property = req.execute().getBody();
- assertTrue(property.getValue().isCollection());
- assertEquals("555-555-5555", property.getCollectionValue().iterator().next().asPrimitive().toString());
- }
-
- @Test
- public void retrieveNullPropertyValueTest() {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("People").appendKeySegment(5).appendPropertySegment("HomeAddress").
- appendValueSegment();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- final ODataPrimitiveValue property = req.execute().getBody();
- assertTrue(StringUtils.isBlank(property.toString()));
- }
-}
[06/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
new file mode 100644
index 0000000..baa2bd4
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/QueryOptionsTestITCase.java
@@ -0,0 +1,215 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+/**
+ * This is the unit test class to check for query options.
+ */
+public class QueryOptionsTestITCase extends AbstractTestITCase {
+
+ /**
+ * Test <tt>$expand</tt>.
+ */
+ public void expand() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataEntity customer = req.execute().getBody();
+ assertTrue(customer.getNavigationLink("Orders") instanceof ODataInlineEntitySet);
+ }
+
+ /**
+ * Test <tt>$filter</tt> and <tt>$orderby</tt>.
+ *
+ * @see org.apache.olingo.client.core.v3.FilterFactoryTest for more tests.
+ */
+ @Test
+ public void filterOrderby() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("People").filter("(PersonID lt 3)");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntities().size());
+
+ // 2. extract PersonID values - sorted ASC by default
+ final List<Integer> former = new ArrayList<Integer>(2);
+ for (ODataEntity entity : feed.getEntities()) {
+ final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(personID < 3);
+ former.add(personID);
+ }
+
+ // 3. add orderby clause to filter above
+ req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.orderBy("PersonID desc").build());
+ req.setFormat(ODataPubFormat.JSON);
+ feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(2, feed.getEntities().size());
+
+ // 4. extract again VIN value - now they were required to be sorted DESC
+ final List<Integer> latter = new ArrayList<Integer>(2);
+ for (ODataEntity entity : feed.getEntities()) {
+ final Integer personID = entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class);
+ assertTrue(personID < 3);
+ latter.add(personID);
+ }
+
+ // 5. reverse latter and expect to be equal to former
+ Collections.reverse(latter);
+ assertEquals(former, latter);
+ }
+
+ /**
+ * Test <tt>$format</tt>.
+ */
+ @Test
+ public void format() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).format("json");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.ATOM);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertNotNull(res);
+ assertTrue(res.getContentType().replaceAll(" ", "").
+ startsWith(ODataPubFormat.JSON.toString(client.getServiceVersion())));
+ }
+
+ /**
+ * Test <tt>$skip</tt>.
+ */
+ public void skip() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.skip(2).build());
+ ODataEntitySet feed = req.execute().getBody();
+ assertEquals(3, feed.getEntities().size());
+ }
+
+ /**
+ * Test <tt>$top</tt>.
+ */
+ public void top() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("People");
+
+ // 1. check that filtered entity set looks as expected
+ ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().
+ getEntitySetRequest(uriBuilder.top(2).build());
+ ODataEntitySet feed = req.execute().getBody();
+ assertEquals(2, feed.getEntities().size());
+ }
+
+ /**
+ * Test <tt>$skiptoken</tt>.
+ */
+ @Test
+ public void skiptoken() throws EdmPrimitiveTypeException {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL);
+ uriBuilder.appendEntitySetSegment("People").skipToken("5");
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(1, feed.getEntities().size());
+
+ for (ODataEntity entity : feed.getEntities()) {
+ assertTrue(entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class) > 5);
+ }
+ }
+
+ /**
+ * Test <tt>$inlinecount</tt>.
+ */
+ @Test
+ public void inlinecount() {
+ final URIBuilder uriBuilder =
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").count(true);
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON);
+ final ODataEntitySet feed = req.execute().getBody();
+ assertNotNull(feed);
+ assertEquals(feed.getEntities().size(), feed.getCount());
+ }
+
+ /**
+ * Test <tt>$select</tt>.
+ */
+ @Test
+ public void select() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).select("PersonID,Orders").expand("Orders");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataEntity customer = req.execute().getBody();
+ assertEquals(1, customer.getProperties().size());
+ assertEquals(1, customer.getNavigationLinks().size());
+ assertTrue((customer.getNavigationLinks().get(0) instanceof ODataInlineEntitySet));
+ }
+
+ @Test
+ public void issue253() {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("relatedEntitySelect").appendEntitySetSegment("Customers").appendKeySegment(1).
+ expandWithSelect("Orders", "OrderID", "OrderDetails");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
new file mode 100644
index 0000000..5c01b65
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/ServiceDocumentTestITCase.java
@@ -0,0 +1,62 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.commons.api.domain.ODataServiceDocument;
+import org.apache.olingo.commons.api.format.ODataFormat;
+import org.junit.Test;
+
+public class ServiceDocumentTestITCase extends AbstractTestITCase {
+
+ private void retrieveServiceDocument(final ODataFormat format) {
+ final ODataServiceDocumentRequest req =
+ client.getRetrieveRequestFactory().getServiceDocumentRequest(testStaticServiceRootURL);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataServiceDocument> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+
+ final ODataServiceDocument serviceDocument = res.getBody();
+ assertEquals(12, serviceDocument.getEntitySets().size());
+ assertEquals(6, serviceDocument.getSingletons().size());
+ assertEquals(6, serviceDocument.getFunctionImports().size());
+
+ assertEquals(URI.create(testStaticServiceRootURL + "/ProductDetails"),
+ serviceDocument.getEntitySetURI("ProductDetails"));
+ assertEquals(URI.create(testStaticServiceRootURL + "/Boss"),
+ serviceDocument.getSingletonURI("Boss"));
+ assertEquals(URI.create(testStaticServiceRootURL + "/GetPerson"),
+ serviceDocument.getFunctionImportURI("GetPerson"));
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsXML() {
+ retrieveServiceDocument(ODataFormat.XML);
+ }
+
+ @Test
+ public void retrieveServiceDocumentAsJSON() {
+ retrieveServiceDocument(ODataFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/resources/sample.png
----------------------------------------------------------------------
diff --git a/fit/src/test/resources/sample.png b/fit/src/test/resources/sample.png
new file mode 100644
index 0000000..399ee46
Binary files /dev/null and b/fit/src/test/resources/sample.png differ
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/pom.xml
----------------------------------------------------------------------
diff --git a/lib/client-core/pom.xml b/lib/client-core/pom.xml
index 58025ee..f4206d1 100644
--- a/lib/client-core/pom.xml
+++ b/lib/client-core/pom.xml
@@ -62,14 +62,6 @@
<groupId>org.slf4j</groupId>
<artifactId>slf4j-simple</artifactId>
</dependency>
-
- <dependency>
- <groupId>org.apache.olingo</groupId>
- <artifactId>olingo-fit</artifactId>
- <version>${project.version}</version>
- <type>war</type>
- <scope>test</scope>
- </dependency>
</dependencies>
<build>
@@ -85,39 +77,6 @@
</systemPropertyVariables>
</configuration>
</plugin>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-failsafe-plugin</artifactId>
- <inherited>true</inherited>
- <configuration>
- <systemPropertyVariables>
- <propertyName>org.slf4j.simpleLogger.defaultLogLevel</propertyName>
- <org.slf4j.simpleLogger.defaultLogLevel>DEBUG</org.slf4j.simpleLogger.defaultLogLevel>
- </systemPropertyVariables>
- </configuration>
- </plugin>
-
- <plugin>
- <groupId>org.codehaus.cargo</groupId>
- <artifactId>cargo-maven2-plugin</artifactId>
- <inherited>true</inherited>
- <executions>
- <execution>
- <id>start-container</id>
- <phase>pre-integration-test</phase>
- <goals>
- <goal>start</goal>
- </goals>
- </execution>
- <execution>
- <id>stop-container</id>
- <phase>post-integration-test</phase>
- <goals>
- <goal>stop</goal>
- </goals>
- </execution>
- </executions>
- </plugin>
</plugins>
<resources>
@@ -131,10 +90,6 @@
<directory>src/test/resources</directory>
<filtering>false</filtering>
</testResource>
- <testResource>
- <directory>${basedir}/../../fit/src/main/resources</directory>
- <filtering>true</filtering>
- </testResource>
</testResources>
</build>
</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
deleted file mode 100644
index 33c27a6..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractBaseTestITCase.java
+++ /dev/null
@@ -1,98 +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.client.core.it;
-
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.CommonODataClient;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.core.data.AtomEntityImpl;
-import org.apache.olingo.commons.core.data.JSONEntityImpl;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public abstract class AbstractBaseTestITCase {
-
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
-
- @SuppressWarnings("rawtypes")
- protected abstract CommonODataClient getClient();
-
- protected void debugEntity(final Entity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(entity, writer);
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugEntitySet(final EntitySet entitySet, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- getClient().getSerializer().entitySet(entitySet, writer);
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugODataProperty(final CommonODataProperty property, final String message) {
- LOG.debug(message + "\n{}", property.toString());
- }
-
- protected void debugODataValue(final ODataValue value, final String message) {
- LOG.debug(message + "\n{}", value.toString());
- }
-
- protected void debugODataEntity(final CommonODataEntity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- StringWriter writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, AtomEntityImpl.class), writer);
- writer.flush();
- LOG.debug(message + " (Atom)\n{}", writer.toString());
-
- writer = new StringWriter();
- getClient().getSerializer().entity(getClient().getBinder().getEntity(entity, JSONEntityImpl.class), writer);
- writer.flush();
- LOG.debug(message + " (JSON)\n{}", writer.toString());
- }
- }
-
- protected void debugInputStream(final InputStream input, final String message) {
- if (LOG.isDebugEnabled()) {
- try {
- LOG.debug(message + "\n{}", IOUtils.toString(input));
- } catch (IOException e) {
- LOG.error("Error writing stream", e);
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
deleted file mode 100644
index 623eca8..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/AbstractMetadataTestITCase.java
+++ /dev/null
@@ -1,35 +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.client.core.it;
-
-import org.apache.olingo.client.api.CommonODataClient;
-
-public abstract class AbstractMetadataTestITCase {
-
- @SuppressWarnings("rawtypes")
- protected abstract CommonODataClient getClient();
-
- protected String getTestServiceRoot() {
- return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/Static.svc";
- }
-
- protected String getNorthwindServiceRoot() {
- return "http://localhost:9080/StaticService/" + getClient().getServiceVersion().name() + "/NorthWind.svc";
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
deleted file mode 100644
index 9f06dc4..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AbstractTestITCase.java
+++ /dev/null
@@ -1,516 +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.client.core.it.v3;
-
-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;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.List;
-import java.util.Map;
-import java.util.Set;
-import org.apache.commons.lang3.StringUtils;
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.http.HttpMethod;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.api.v3.ODataClient;
-import org.apache.olingo.client.core.ODataClientFactory;
-import org.apache.olingo.client.core.it.AbstractBaseTestITCase;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.CommonODataEntity;
-import org.apache.olingo.commons.api.domain.CommonODataEntitySet;
-import org.apache.olingo.commons.api.domain.CommonODataProperty;
-import org.apache.olingo.commons.api.domain.ODataCollectionValue;
-import org.apache.olingo.commons.api.domain.ODataComplexValue;
-import org.apache.olingo.commons.api.domain.ODataInlineEntity;
-import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
-import org.apache.olingo.commons.api.domain.ODataLink;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.BeforeClass;
-
-public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
-
- protected static final FullQualifiedName TEST_PRODUCT_TYPE =
- new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Product");
-
- protected static ODataClient client;
-
- protected static String testStaticServiceRootURL;
-
- protected static String testKeyAsSegmentServiceRootURL;
-
- protected static String testActionOverloadingServiceRootURL;
-
- protected static String testOpenTypeServiceRootURL;
-
- protected static String testLargeModelServiceRootURL;
-
- protected static String testAuthServiceRootURL;
-
- @BeforeClass
- public static void setUpODataServiceRoot() throws IOException {
- testStaticServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc";
- testKeyAsSegmentServiceRootURL = "http://localhost:9080/StaticService/V30/KeyAsSegment.svc";
- testActionOverloadingServiceRootURL = "http://localhost:9080/StaticService/V30/ActionOverloading.svc";
- testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V30/OpenType.svc";
- testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V30/Static.svc/large";
- testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
- }
-
- @BeforeClass
- public static void setClientInstance() {
- client = ODataClientFactory.getV3();
- }
-
- @Override
- protected ODataClient getClient() {
- return client;
- }
-
- protected void checkLinks(final Collection<ODataLink> original, final Collection<ODataLink> actual) {
- assertTrue(original.size() <= actual.size());
-
- for (ODataLink originalLink : original) {
- ODataLink foundOriginal = null;
- ODataLink foundActual = null;
-
- for (ODataLink actualLink : actual) {
-
- if (actualLink.getType() == originalLink.getType()
- && (originalLink.getLink() == null
- || actualLink.getLink().toASCIIString().endsWith(originalLink.getLink().toASCIIString()))
- && actualLink.getName().equals(originalLink.getName())) {
-
- foundOriginal = originalLink;
- foundActual = actualLink;
- }
- }
-
- assertNotNull(foundOriginal);
- assertNotNull(foundActual);
-
- if (foundOriginal instanceof ODataInlineEntity && foundActual instanceof ODataInlineEntity) {
- final CommonODataEntity originalInline = ((ODataInlineEntity) foundOriginal).getEntity();
- assertNotNull(originalInline);
-
- final CommonODataEntity actualInline = ((ODataInlineEntity) foundActual).getEntity();
- assertNotNull(actualInline);
-
- checkProperties(originalInline.getProperties(), actualInline.getProperties());
- }
- }
- }
-
- protected void checkProperties(final Collection<? extends CommonODataProperty> original,
- final Collection<? extends CommonODataProperty> actual) {
-
- assertTrue(original.size() <= actual.size());
-
- // re-organize actual properties into a Map<String, ODataProperty>
- final Map<String, CommonODataProperty> actualProps = new HashMap<String, CommonODataProperty>(actual.size());
-
- for (CommonODataProperty prop : actual) {
- assertFalse(actualProps.containsKey(prop.getName()));
- actualProps.put(prop.getName(), prop);
- }
-
- assertTrue(actual.size() <= actualProps.size());
-
- for (CommonODataProperty prop : original) {
- assertNotNull(prop);
- if (actualProps.containsKey(prop.getName())) {
- final CommonODataProperty actualProp = actualProps.get(prop.getName());
- assertNotNull(actualProp);
-
- if (prop.getValue() != null && actualProp.getValue() != null) {
- checkPropertyValue(prop.getName(), prop.getValue(), actualProp.getValue());
- }
- } else {
- // nothing ... maybe :FC_KeepInContent="false"
- // ..... no assert can be done ....
- }
- }
- }
-
- protected void checkPropertyValue(final String propertyName,
- final ODataValue original, final ODataValue actual) {
-
- assertNotNull("Null original value for " + propertyName, original);
- assertNotNull("Null actual value for " + propertyName, actual);
-
- assertEquals("Type mismatch for '" + propertyName + "': "
- + original.getClass().getSimpleName() + "-" + actual.getClass().getSimpleName(),
- original.getClass().getSimpleName(), actual.getClass().getSimpleName());
-
- if (original.isComplex()) {
- final List<ODataProperty> originalFileds = new ArrayList<ODataProperty>();
- for (ODataProperty prop : original.<ODataProperty>asComplex()) {
- originalFileds.add(prop);
- }
-
- final List<ODataProperty> actualFileds = new ArrayList<ODataProperty>();
- for (ODataProperty prop : actual.<ODataProperty>asComplex()) {
- actualFileds.add(prop);
- }
-
- checkProperties(originalFileds, actualFileds);
- } else if (original.isCollection()) {
- assertTrue(original.asCollection().size() <= actual.asCollection().size());
-
- boolean found = original.asCollection().isEmpty();
-
- for (ODataValue originalValue : original.asCollection()) {
- for (ODataValue actualValue : actual.asCollection()) {
- try {
- checkPropertyValue(propertyName, originalValue, actualValue);
- found = true;
- } catch (AssertionError ignore) {
- // ignore
- }
- }
- }
-
- assertTrue("Found " + actual + " but expected " + original, found);
- } else {
- assertTrue("Primitive value for '" + propertyName + "' type mismatch: " + original.asPrimitive().
- getTypeKind() + "-" + actual.asPrimitive().getTypeKind(),
- original.asPrimitive().getTypeKind().equals(actual.asPrimitive().getTypeKind()));
-
- assertEquals("Primitive value for '" + propertyName + "' mismatch: " + original.asPrimitive().toString()
- + "-" + actual.asPrimitive().toString(),
- original.asPrimitive().toString(), actual.asPrimitive().toString());
- }
- }
-
- protected ODataEntity getSampleCustomerInfo(final int id, final String sampleinfo) {
- final ODataEntity entity = getClient().getObjectFactory().newEntity(new FullQualifiedName(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.CustomerInfo"));
- entity.setMediaEntity(true);
-
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("Information",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleinfo)));
-
- return entity;
- }
-
- protected ODataEntity getSampleCustomerProfile(
- final int id, final String sampleName, final boolean withInlineInfo) {
-
- final ODataEntity entity = getClient().getObjectFactory().
- newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.AstoriaDefaultService.Customer"));
-
- // add name attribute
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("Name",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(sampleName)));
-
- // add key attribute
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newPrimitiveProperty("CustomerId",
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
-
- // add BackupContactInfo attribute (collection)
- final ODataCollectionValue<ODataValue> backupContactInfoValue = getClient().getObjectFactory().newCollectionValue(
- "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails)");
- getClient().getBinder().add(entity,
- getClient().getObjectFactory().newCollectionProperty("BackupContactInfo", backupContactInfoValue));
-
- // add BackupContactInfo.ContactDetails attribute (complex)
- final ODataComplexValue<ODataProperty> contactDetails = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.ContactDetails");
- backupContactInfoValue.add(contactDetails);
-
- // add BackupContactInfo.ContactDetails.AlternativeNames attribute (collection)
- final ODataCollectionValue<ODataValue> altNamesValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- altNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname"));
- contactDetails.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", altNamesValue));
-
- // add BackupContactInfo.ContactDetails.EmailBag attribute (collection)
- final ODataCollectionValue<ODataValue> emailBagValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- emailBagValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myname@mydomain.com"));
- contactDetails.add(getClient().getObjectFactory().newCollectionProperty("EmailBag", emailBagValue));
-
- // add BackupContactInfo.ContactDetails.ContactAlias attribute (complex)
- final ODataComplexValue<ODataProperty> contactAliasValue = getClient().getObjectFactory().newComplexValue(
- "Microsoft.Test.OData.Services.AstoriaDefaultService.Aliases");
- contactDetails.add(getClient().getObjectFactory().newComplexProperty("ContactAlias", contactAliasValue));
-
- // add BackupContactInfo.ContactDetails.ContactAlias.AlternativeNames attribute (collection)
- final ODataCollectionValue<ODataValue> aliasAltNamesValue = getClient().getObjectFactory().
- newCollectionValue("Collection(Edm.String)");
- aliasAltNamesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("myAlternativeName"));
- contactAliasValue.add(getClient().getObjectFactory().newCollectionProperty("AlternativeNames", aliasAltNamesValue));
-
- if (withInlineInfo) {
- final ODataInlineEntity inlineInfo = getClient().getObjectFactory().newDeepInsertEntity(
- "Info",
- getSampleCustomerInfo(id, sampleName + "_Info"));
- inlineInfo.getEntity().setMediaEntity(true);
- entity.addLink(inlineInfo);
- }
-
- return entity;
- }
-
- protected String getETag(final URI uri) {
- final ODataRetrieveResponse<ODataEntity> res = getClient().getRetrieveRequestFactory().
- getEntityRequest(uri).execute();
- try {
- return res.getETag();
- } finally {
- res.close();
- }
- }
-
- protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
- final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
- getEntityRequest(editLink);
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- final ODataEntity entity = res.getBody();
-
- assertNotNull(entity);
-
- if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
- assertEquals(req.getURI(), entity.getEditLink());
- }
-
- return entity;
- }
-
- protected ODataEntity createEntity(
- final String serviceRootURL,
- final ODataPubFormat format,
- final ODataEntity original,
- final String entitySetName) {
-
- final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
- appendEntitySetSegment(entitySetName);
-
- debugODataEntity(original, "About to create");
-
- final ODataEntityCreateRequest<ODataEntity> createReq =
- getClient().getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), original);
- createReq.setFormat(format);
-
- final ODataEntityCreateResponse<ODataEntity> createRes = createReq.execute();
- assertEquals(201, createRes.getStatusCode());
- assertEquals("Created", createRes.getStatusMessage());
-
- final ODataEntity created = createRes.getBody();
- assertNotNull(created);
-
- debugODataEntity(created, "Just created");
-
- return created;
- }
-
- protected ODataEntity compareEntities(final String serviceRootURL,
- final ODataPubFormat format,
- final ODataEntity original,
- final int actualObjectId,
- final Collection<String> expands) {
-
- final URIBuilder uriBuilder = getClient().getURIBuilder(serviceRootURL).
- appendEntitySetSegment("Customer").appendKeySegment(actualObjectId);
-
- // search expanded
- if (expands != null) {
- for (String expand : expands) {
- uriBuilder.expand(expand);
- }
- }
-
- final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().
- getEntityRequest(uriBuilder.build());
- req.setFormat(format);
-
- final ODataRetrieveResponse<ODataEntity> res = req.execute();
- assertEquals(200, res.getStatusCode());
-
- final ODataEntity actual = res.getBody();
- assertNotNull(actual);
-
- // check defined links
- checkLinks(original.getAssociationLinks(), actual.getAssociationLinks());
- checkLinks(original.getEditMediaLinks(), actual.getEditMediaLinks());
- checkLinks(original.getNavigationLinks(), actual.getNavigationLinks());
-
- // check defined properties equality
- checkProperties(original.getProperties(), actual.getProperties());
-
- return actual;
- }
-
- protected void cleanAfterCreate(
- final ODataPubFormat format,
- final ODataEntity created,
- final boolean includeInline,
- final String baseUri) {
-
- final Set<URI> toBeDeleted = new HashSet<URI>();
- toBeDeleted.add(created.getEditLink());
-
- if (includeInline) {
- for (ODataLink link : created.getNavigationLinks()) {
- if (link instanceof ODataInlineEntity) {
- final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
- if (inline.getEditLink() != null) {
- toBeDeleted.add(URIUtils.getURI(baseUri, inline.getEditLink().toASCIIString()));
- }
- }
-
- if (link instanceof ODataInlineEntitySet) {
- final CommonODataEntitySet inline = ((ODataInlineEntitySet) link).getEntitySet();
- for (CommonODataEntity entity : inline.getEntities()) {
- if (entity.getEditLink() != null) {
- toBeDeleted.add(URIUtils.getURI(baseUri, entity.getEditLink().toASCIIString()));
- }
- }
- }
- }
- }
-
- assertFalse(toBeDeleted.isEmpty());
-
- for (URI link : toBeDeleted) {
- final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(link);
- final ODataDeleteResponse deleteRes = deleteReq.execute();
-
- assertEquals(204, deleteRes.getStatusCode());
- assertEquals("No Content", deleteRes.getStatusMessage());
-
- deleteRes.close();
-
- final ODataEntityRequest<ODataEntity> retrieveReq = getClient().getRetrieveRequestFactory().
- getEntityRequest(link);
- // bug that needs to be fixed on the SampleService - cannot get entity not found with header
- // Accept: application/json;odata=minimalmetadata
- retrieveReq.setFormat(format == ODataPubFormat.JSON_FULL_METADATA ? ODataPubFormat.JSON : format);
-
- Exception exception = null;
- try {
- retrieveReq.execute();
- fail();
- } catch (ODataClientErrorException e) {
- exception = e;
- assertEquals(404, e.getStatusLine().getStatusCode());
- }
- assertNotNull(exception);
- }
- }
-
- protected void updateEntityDescription(
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type) {
-
- updateEntityDescription(format, changes, type, null);
- }
-
- protected void updateEntityDescription(
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
-
- updateEntityStringProperty("Description", format, changes, type, etag);
- }
-
- protected void updateEntityStringProperty(final String propertyName,
- final ODataPubFormat format, final ODataEntity changes, final UpdateType type, final String etag) {
-
- final URI editLink = changes.getEditLink();
-
- final String newm = "New " + propertyName + "(" + System.currentTimeMillis() + ")";
-
- ODataProperty propertyValue = changes.getProperty(propertyName);
-
- final String oldm;
- if (propertyValue == null) {
- oldm = null;
- } else {
- oldm = propertyValue.getValue().toString();
- changes.getProperties().remove(propertyValue);
- }
-
- assertNotEquals(newm, oldm);
-
- getClient().getBinder().add(changes,
- getClient().getObjectFactory().newPrimitiveProperty(propertyName,
- getClient().getObjectFactory().newPrimitiveValueBuilder().buildString(newm)));
-
- update(type, changes, format, etag);
-
- final ODataEntity actual = read(format, editLink);
-
- propertyValue = null;
-
- for (ODataProperty prop : actual.getProperties()) {
- if (prop.getName().equals(propertyName)) {
- propertyValue = prop;
- }
- }
-
- assertNotNull(propertyValue);
- assertEquals(newm, propertyValue.getValue().toString());
- }
-
- protected void update(
- final UpdateType type, final ODataEntity changes, final ODataPubFormat format, final String etag) {
-
- final ODataEntityUpdateRequest<ODataEntity> req =
- getClient().getCUDRequestFactory().getEntityUpdateRequest(type, changes);
-
- if (getClient().getConfiguration().isUseXHTTPMethod()) {
- assertEquals(HttpMethod.POST, req.getMethod());
- } else {
- assertEquals(type.getMethod(), req.getMethod());
- }
- req.setFormat(format);
-
- if (StringUtils.isNotBlank(etag)) {
- req.setIfMatch(etag); // Product include ETag header into the response .....
- }
-
- final ODataEntityUpdateResponse<ODataEntity> res = req.execute();
- assertEquals(204, res.getStatusCode());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
deleted file mode 100644
index 4273a9c..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/ActionOverloadingTestITCase.java
+++ /dev/null
@@ -1,181 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.LinkedHashMap;
-import java.util.Map;
-import org.apache.olingo.client.api.communication.request.invoke.ODataNoContent;
-import org.apache.olingo.client.api.communication.response.ODataInvokeResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.apache.olingo.commons.api.domain.v3.ODataProperty;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
-import org.junit.Test;
-
-public class ActionOverloadingTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveProduct() throws EdmPrimitiveTypeException {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- int execs = 0;
- for (EdmActionImport actImp : container.getActionImports()) {
- if ("RetrieveProduct".equals(actImp.getName())) {
- // 1. unbound
- final EdmAction unbound = actImp.getUnboundAction();
- assertNotNull(unbound);
- assertEquals(EdmInt32.getInstance(), unbound.getReturnType().getType());
-
- final URIBuilder unboundBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendOperationCallSegment(URIUtils.operationImportURISegment(container, actImp.getName()));
- final ODataInvokeResponse<ODataProperty> unboundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(unboundBuilder.build(), unbound).execute();
- assertNotNull(unboundRes);
- assertEquals(200, unboundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), unboundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
-
- // 2. bound to Product
- final EdmAction productBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "Product"), false);
- assertNotNull(productBound);
- assertEquals(EdmInt32.getInstance(), productBound.getReturnType().getType());
-
- final ODataEntity product = getClient().getRetrieveRequestFactory().getEntityRequest(
- getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).build()).
- execute().getBody();
- assertNotNull(product);
-
- final ODataInvokeResponse<ODataProperty> productBoundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(product.getOperation(actImp.getName()).getTarget(), unbound).
- execute();
- assertNotNull(productBoundRes);
- assertEquals(200, productBoundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), productBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
-
- // 3. bound to OrderLine
- final EdmAction orderLineBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "OrderLine"), false);
- assertNotNull(orderLineBound);
- assertEquals(EdmInt32.getInstance(), orderLineBound.getReturnType().getType());
-
- final Map<String, Object> key = new LinkedHashMap<String, Object>(2);
- key.put("OrderId", -10);
- key.put("ProductId", -10);
- final ODataEntity orderLine = getClient().getRetrieveRequestFactory().getEntityRequest(
- getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("OrderLine").appendKeySegment(key).build()).
- execute().getBody();
- assertNotNull(orderLine);
-
- final ODataInvokeResponse<ODataProperty> orderLineBoundRes = getClient().getInvokeRequestFactory().
- <ODataProperty>getInvokeRequest(orderLine.getOperation(actImp.getName()).getTarget(), unbound).
- execute();
- assertNotNull(orderLineBoundRes);
- assertEquals(200, orderLineBoundRes.getStatusCode());
- assertEquals(Integer.valueOf(-10), orderLineBoundRes.getBody().getPrimitiveValue().toCastValue(Integer.class));
- execs++;
- }
- }
- assertEquals(3, execs);
- }
-
- @Test
- public void increaseSalaries() {
- final Edm edm = getClient().getRetrieveRequestFactory().
- getMetadataRequest(testActionOverloadingServiceRootURL).execute().getBody();
- assertNotNull(edm);
-
- final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
- assertNotNull(container);
-
- int execs = 0;
- for (EdmActionImport actImp : container.getActionImports()) {
- if ("IncreaseSalaries".equals(actImp.getName())) {
- final Map<String, ODataValue> parameters = new LinkedHashMap<String, ODataValue>(1);
- parameters.put("n", getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(5));
-
- // 1. bound to employees
- final EdmAction employeeBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "Employee"), true);
- assertNotNull(employeeBound);
- assertNull(employeeBound.getReturnType());
-
- final URIBuilder employeeBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Person").
- appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.Employee");
- final ODataEntitySet employees = getClient().getRetrieveRequestFactory().getEntitySetRequest(
- employeeBuilder.build()).execute().getBody();
- assertNotNull(employees);
-
- final ODataInvokeResponse<ODataNoContent> employeeRes = getClient().getInvokeRequestFactory().
- <ODataNoContent>getInvokeRequest(employeeBuilder.appendOperationCallSegment(actImp.getName()).build(),
- employeeBound, parameters).execute();
- assertNotNull(employeeRes);
- assertEquals(204, employeeRes.getStatusCode());
- execs++;
-
- // 1. bound to special employees
- final EdmAction specEmpBound = edm.getBoundAction(
- new FullQualifiedName(container.getNamespace(), actImp.getName()),
- new FullQualifiedName(container.getNamespace(), "SpecialEmployee"), true);
- assertNotNull(specEmpBound);
- assertNull(specEmpBound.getReturnType());
-
- final URIBuilder specEmpBuilder = getClient().getURIBuilder(testActionOverloadingServiceRootURL).
- appendEntitySetSegment("Person").
- appendDerivedEntityTypeSegment("Microsoft.Test.OData.Services.AstoriaDefaultService.SpecialEmployee");
- final ODataEntitySet specEmps = getClient().getRetrieveRequestFactory().getEntitySetRequest(
- specEmpBuilder.build()).execute().getBody();
- assertNotNull(specEmps);
-
- final ODataInvokeResponse<ODataNoContent> specEmpsRes = getClient().getInvokeRequestFactory().
- <ODataNoContent>getInvokeRequest(specEmpBuilder.appendOperationCallSegment(actImp.getName()).build(),
- specEmpBound, parameters).execute();
- assertNotNull(specEmpsRes);
- assertEquals(204, specEmpsRes.getStatusCode());
- execs++;
- }
- }
- assertEquals(2, execs);
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
deleted file mode 100644
index 9b9ba9c..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AsyncTestITCase.java
+++ /dev/null
@@ -1,134 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-
-import java.io.InputStream;
-import java.net.URI;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Future;
-import org.apache.commons.io.IOUtils;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataMediaRequest;
-import org.apache.olingo.client.api.communication.request.streamed.MediaEntityCreateStreamManager;
-import org.apache.olingo.client.api.communication.request.streamed.ODataMediaEntityCreateRequest;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataMediaEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.domain.v3.ODataEntitySet;
-import org.junit.Test;
-
-public class AsyncTestITCase extends AbstractTestITCase {
-
- @Test
- public void retrieveEntitySet() throws InterruptedException, ExecutionException {
- final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product");
- final Future<ODataRetrieveResponse<ODataEntitySet>> futureRes =
- client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).asyncExecute();
- assertNotNull(futureRes);
-
- while (!futureRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataRetrieveResponse<ODataEntitySet> res = futureRes.get();
- assertNotNull(res);
- assertEquals(200, res.getStatusCode());
- assertFalse(res.getBody().getEntities().isEmpty());
- }
-
- @Test
- public void updateEntity() throws InterruptedException, ExecutionException {
- final URI uri = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10).build();
-
- final ODataRetrieveResponse<ODataEntity> entityRes = client.getRetrieveRequestFactory().
- getEntityRequest(uri).execute();
- final ODataEntity entity = entityRes.getBody();
- entity.getAssociationLinks().clear();
- entity.getNavigationLinks().clear();
- entity.getEditMediaLinks().clear();
-
- entity.getProperties().remove(entity.getProperty("Description"));
- getClient().getBinder().add(entity,
- client.getObjectFactory().newPrimitiveProperty("Description",
- client.getObjectFactory().newPrimitiveValueBuilder().setText("AsyncTest#updateEntity").build()));
-
- final ODataEntityUpdateRequest<ODataEntity> updateReq =
- client.getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.MERGE, entity);
- updateReq.setIfMatch(entityRes.getETag());
- final Future<ODataEntityUpdateResponse<ODataEntity>> futureRes = updateReq.asyncExecute();
-
- while (!futureRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataEntityUpdateResponse<ODataEntity> res = futureRes.get();
- assertNotNull(res);
- assertEquals(204, res.getStatusCode());
- }
-
- /**
- * @see MediaEntityTest#createMediaEntity(com.msopentech.odatajclient.engine.format.ODataPubFormat)
- */
- @Test
- public void createMediaEntity() throws Exception {
- URIBuilder builder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Car");
-
- final String TO_BE_UPDATED = "async buffered stream sample";
- final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
-
- final ODataMediaEntityCreateRequest<ODataEntity> createReq =
- client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
-
- final MediaEntityCreateStreamManager<ODataEntity> streamManager = createReq.execute();
- final Future<ODataMediaEntityCreateResponse<ODataEntity>> futureCreateRes = streamManager.getAsyncResponse();
-
- while (!futureCreateRes.isDone()) {
- Thread.sleep(1000L);
- }
-
- final ODataMediaEntityCreateResponse<ODataEntity> createRes = futureCreateRes.get();
- assertEquals(201, createRes.getStatusCode());
-
- final ODataEntity created = createRes.getBody();
- assertNotNull(created);
- assertEquals(2, created.getProperties().size());
-
- final int id = "VIN".equals(created.getProperties().get(0).getName())
- ? created.getProperties().get(0).getPrimitiveValue().toCastValue(Integer.class)
- : created.getProperties().get(1).getPrimitiveValue().toCastValue(Integer.class);
-
- builder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Car").appendKeySegment(id).appendValueSegment();
-
- final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
-
- final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
- assertEquals(200, retrieveRes.getStatusCode());
- assertEquals(TO_BE_UPDATED, IOUtils.toString(retrieveRes.getBody()));
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
deleted file mode 100644
index 686e5ca..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/AuthEntityRetrieveTestITCase.java
+++ /dev/null
@@ -1,42 +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.client.core.it.v3;
-
-import org.apache.olingo.client.core.http.BasicAuthHttpClientFactory;
-import org.apache.olingo.client.core.http.DefaultHttpClientFactory;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-
-public class AuthEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
-
- @BeforeClass
- public static void enableBasicAuth() {
- client.getConfiguration().setHttpClientFactory(new BasicAuthHttpClientFactory("odatajclient", "odatajclient"));
- }
-
- @AfterClass
- public static void disableBasicAuth() {
- client.getConfiguration().setHttpClientFactory(new DefaultHttpClientFactory());
- }
-
- @Override
- protected String getServiceRoot() {
- return testAuthServiceRootURL;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
deleted file mode 100644
index 0e67a07..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/BatchTestITCase.java
+++ /dev/null
@@ -1,444 +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.client.core.it.v3;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.fail;
-
-import java.io.IOException;
-import java.net.URI;
-import java.util.Iterator;
-import java.util.concurrent.Future;
-import java.util.concurrent.TimeUnit;
-import org.apache.http.HttpResponse;
-import org.apache.olingo.client.api.ODataBatchConstants;
-import org.apache.olingo.client.api.communication.request.ODataStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.BatchStreamManager;
-import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
-import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
-import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
-import org.apache.olingo.client.api.communication.request.batch.v3.ODataBatchRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
-import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
-import org.apache.olingo.client.api.communication.request.cud.v3.UpdateType;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
-import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
-import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
-import org.apache.olingo.client.api.communication.response.ODataResponse;
-import org.apache.olingo.client.api.uri.v3.URIBuilder;
-import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
-import org.apache.olingo.client.core.communication.request.Wrapper;
-import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
-import org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
-import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
-import org.apache.olingo.client.core.uri.URIUtils;
-import org.apache.olingo.commons.api.domain.v3.ODataEntity;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.format.ODataPubFormat;
-import org.junit.Test;
-
-public class BatchTestITCase extends AbstractTestITCase {
-
- private static final String PREFIX = "!!PREFIX!!";
-
- private static final String SUFFIX = "!!SUFFIX!!";
-
- private static final int MAX = 10000;
-
- @Test
- public void stringStreaming() {
- final TestStreamManager streaming = new TestStreamManager();
-
- new StreamingThread(streaming).start();
-
- streaming.addObject((PREFIX + "\n").getBytes());
-
- for (int i = 0; i <= MAX; i++) {
- streaming.addObject((i + ") send info\n").getBytes());
- }
-
- streaming.addObject(SUFFIX.getBytes());
- streaming.finalizeBody();
- }
-
- @Test
- public void emptyBatchRequest() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager payload = request.execute();
- final ODataBatchResponse response = payload.getResponse();
-
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- assertFalse(iter.hasNext());
- }
-
- @Test
- public void changesetWithError() {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager payload = request.execute();
- final ODataChangeset changeset = payload.addChangeset();
-
- URIBuilder targetURI;
- ODataEntityCreateRequest<ODataEntity> createReq;
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- for (int i = 1; i <= 2; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(100 + i, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
- }
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet");
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(105, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.JSON);
- changeset.addRequest(createReq);
-
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- for (int i = 3; i <= 4; i++) {
- // Create Customer into the changeset
- createReq = client.getCUDRequestFactory().getEntityCreateRequest(
- targetURI.build(),
- getSampleCustomerProfile(100 + i, "Sample customer", false));
- createReq.setFormat(ODataPubFormat.ATOM);
- changeset.addRequest(createReq);
- }
-
- final ODataBatchResponse response = payload.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
- final ODataChangesetResponseItem chgResponseItem = (ODataChangesetResponseItem) iter.next();
-
- final ODataResponse res = chgResponseItem.next();
- assertEquals(404, res.getStatusCode());
- assertEquals("Not Found", res.getStatusMessage());
- assertEquals(Integer.valueOf(3), Integer.valueOf(
- res.getHeader(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME).iterator().next()));
- assertFalse(chgResponseItem.hasNext());
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void changesetWithReference() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
- final BatchStreamManager streamManager = request.execute();
-
- final ODataChangeset changeset = streamManager.addChangeset();
- ODataEntity customer = getSampleCustomerProfile(20, "sample customer", false);
-
- URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
-
- // add create request
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), customer);
-
- changeset.addRequest(createReq);
-
- // retrieve request reference
- int createRequestRef = changeset.getLastContentId();
-
- // add update request: link CustomerInfo(17) to the new customer
- final ODataEntity customerChanges = client.getObjectFactory().newEntity(customer.getTypeName());
- customerChanges.addLink(client.getObjectFactory().newEntityNavigationLink(
- "Info",
- client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("CustomerInfo").
- appendKeySegment(17).build()));
-
- final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
- URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
-
- changeset.addRequest(updateReq);
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
-
- // verify response payload ...
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- final ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
-
- ODataResponse res = chgitem.next();
- assertEquals(201, res.getStatusCode());
- assertTrue(res instanceof ODataEntityCreateResponse);
-
- customer = ((ODataEntityCreateResponse<ODataEntity>) res).getBody();
-
- ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString() + "/Info"));
-
- assertEquals(Integer.valueOf(17),
- req.execute().getBody().getProperty("CustomerInfoId").getPrimitiveValue().toCastValue(Integer.class));
-
- res = chgitem.next();
- assertEquals(204, res.getStatusCode());
- assertTrue(res instanceof ODataEntityUpdateResponse);
-
- // clean ...
- assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).execute().
- getStatusCode());
-
- try {
- client.getRetrieveRequestFactory().getEntityRequest(
- URIUtils.getURI(testStaticServiceRootURL, customer.getEditLink().toASCIIString())).
- execute().getBody();
- fail();
- } catch (Exception e) {
- // ignore
- }
- }
-
- @Test
- @SuppressWarnings("unchecked")
- public void batchRequest() throws EdmPrimitiveTypeException {
- // create your request
- final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
-
- final BatchStreamManager streamManager = request.execute();
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- ODataRetrieve retrieve = streamManager.addRetrieve();
-
- // prepare URI
- URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
- targetURI.appendEntitySetSegment("Customer").appendKeySegment(-10).
- expand("Logins").select("CustomerId,Logins/Username");
-
- // create new request
- ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
- queryReq.setFormat(ODataPubFormat.ATOM);
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add changeset item
- // -------------------------------------------
- final ODataChangeset changeset = streamManager.addChangeset();
-
- // Update Product into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10);
- final URI editLink = targetURI.build();
-
- final ODataEntity merge = client.getObjectFactory().newEntity(TEST_PRODUCT_TYPE);
- merge.setEditLink(editLink);
-
- merge.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
- "Description",
- client.getObjectFactory().newPrimitiveValueBuilder().buildString("new description from batch")));
-
- final ODataEntityUpdateRequest changeReq =
- client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.MERGE, merge);
- changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
- changeReq.setIfMatch(getETag(editLink));
-
- changeset.addRequest(changeReq);
-
- // Create Customer into the changeset
- targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customer");
- final ODataEntity original = getSampleCustomerProfile(1000, "Sample customer", false);
- final ODataEntityCreateRequest<ODataEntity> createReq =
- client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
- createReq.setFormat(ODataPubFormat.ATOM);
- changeset.addRequest(createReq);
- // -------------------------------------------
-
- // -------------------------------------------
- // Add retrieve item
- // -------------------------------------------
- retrieve = streamManager.addRetrieve();
-
- // prepare URI
- targetURI = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Product").appendKeySegment(-10);
-
- // create new request
- queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
-
- retrieve.setRequest(queryReq);
- // -------------------------------------------
-
- final ODataBatchResponse response = streamManager.getResponse();
- assertEquals(202, response.getStatusCode());
- assertEquals("Accepted", response.getStatusMessage());
- final Iterator<ODataBatchResponseItem> iter = response.getBody();
-
- // retrive the first item (ODataRetrieve)
- ODataBatchResponseItem item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
- ODataResponse res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- ODataEntityRequestImpl<ODataEntity>.ODataEntityResponseImpl entres =
- (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
-
- ODataEntity entity = entres.getBody();
- assertEquals(-10, entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class), 0);
-
- // retrieve the second item (ODataChangeset)
- item = iter.next();
- assertTrue(item instanceof ODataChangesetResponseItem);
-
- final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityUpdateResponse);
- assertEquals(204, res.getStatusCode());
- assertEquals("No Content", res.getStatusMessage());
-
- res = chgitem.next();
- assertTrue(res instanceof ODataEntityCreateResponse);
- assertEquals(201, res.getStatusCode());
- assertEquals("Created", res.getStatusMessage());
-
- final ODataEntityCreateResponse<ODataEntity> createres = (ODataEntityCreateResponse<ODataEntity>) res;
- entity = createres.getBody();
- assertEquals(new Integer(1000), entity.getProperty("CustomerId").getPrimitiveValue().toCastValue(Integer.class));
-
- // retrive the third item (ODataRetrieve)
- item = iter.next();
- assertTrue(item instanceof ODataRetrieveResponseItem);
-
- retitem = (ODataRetrieveResponseItem) item;
- res = retitem.next();
- assertTrue(res instanceof ODataEntityResponseImpl);
- assertEquals(200, res.getStatusCode());
- assertEquals("OK", res.getStatusMessage());
-
- entres = (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
- entity = entres.getBody();
- assertEquals("new description from batch",
- entity.getProperty("Description").getPrimitiveValue().toCastValue(String.class));
-
- assertFalse(iter.hasNext());
- }
-
- private static class TestStreamManager extends AbstractODataStreamManager<ODataBatchResponse> {
-
- public TestStreamManager() {
- super(new Wrapper<Future<HttpResponse>>());
- }
-
- public ODataStreamManager<ODataBatchResponse> addObject(byte[] src) {
- stream(src);
- return this;
- }
-
- @Override
- protected ODataBatchResponse getResponse(long timeout, TimeUnit unit) {
- throw new UnsupportedOperationException("Not supported yet.");
- }
- };
-
- /**
- * To be used for debug purposes.
- */
- private static class StreamingThread extends Thread {
-
- private final TestStreamManager streaming;
-
- public StreamingThread(final TestStreamManager streaming) {
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- assertTrue(builder.toString().startsWith(PREFIX));
- assertTrue(builder.toString().contains((MAX / 2) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 3) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 20) + ") send info"));
- assertTrue(builder.toString().contains((MAX / 30) + ") send info"));
- assertTrue(builder.toString().contains(MAX + ") send info"));
- assertTrue(builder.toString().endsWith(SUFFIX));
-
- } catch (IOException e) {
- fail();
- }
- }
- }
-
- private static class BatchStreamingThread extends Thread {
-
- private final BatchStreamManager streaming;
-
- public BatchStreamingThread(final BatchStreamManager streaming) {
- this.streaming = streaming;
- }
-
- @Override
- public void run() {
- try {
- final StringBuilder builder = new StringBuilder();
-
- byte[] buff = new byte[1024];
-
- int len;
-
- while ((len = streaming.getBody().read(buff)) >= 0) {
- builder.append(new String(buff, 0, len));
- }
-
- LOG.debug("Batch request {}", builder.toString());
-
- assertTrue(builder.toString().contains("Content-Id:2"));
- assertTrue(builder.toString().contains("GET " + testStaticServiceRootURL));
- } catch (IOException e) {
- fail();
- }
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java b/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
deleted file mode 100644
index f004c26..0000000
--- a/lib/client-core/src/test/java/org/apache/olingo/client/core/it/v3/CountTestITCase.java
+++ /dev/null
@@ -1,60 +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.client.core.it.v3;
-
-import static org.junit.Assert.*;
-import org.junit.Test;
-
-import org.apache.olingo.client.api.communication.ODataClientErrorException;
-import org.apache.olingo.client.api.communication.request.retrieve.ODataValueRequest;
-import org.apache.olingo.commons.api.domain.ODataValue;
-import org.apache.olingo.commons.api.format.ODataValueFormat;
-import org.apache.olingo.client.api.uri.CommonURIBuilder;
-
-public class CountTestITCase extends AbstractTestITCase {
-
- @Test
- public void entityCount() {
- CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- try {
- final ODataValue value = req.execute().getBody();
- assertTrue(10 <= Integer.parseInt(value.toString()));
- } catch (ODataClientErrorException e) {
- LOG.error("Error code: {}", e.getStatusLine().getStatusCode(), e);
- }
- }
-
- @Test
- public void invalidAccept() {
- final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
- appendEntitySetSegment("Customer").count();
- final ODataValueRequest req = client.getRetrieveRequestFactory().getValueRequest(uriBuilder.build());
- req.setFormat(ODataValueFormat.TEXT);
- req.setAccept("application/json;odata=fullmetadata");
- try {
- final ODataValue value = req.execute().getBody();
- fail();
- } catch (ODataClientErrorException e) {
- assertEquals(415, e.getStatusLine().getStatusCode());
- }
- }
-}
[08/11] [OLINGO-236] Refactor complete
Posted by il...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
new file mode 100644
index 0000000..7e2ef22
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/AbstractTestITCase.java
@@ -0,0 +1,132 @@
+/*
+ * 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.v4;
+
+import java.io.IOException;
+import java.net.URI;
+import org.apache.olingo.client.api.communication.request.cud.ODataDeleteRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.v4.EdmEnabledODataClient;
+import org.apache.olingo.client.api.v4.ODataClient;
+import org.apache.olingo.client.core.ODataClientFactory;
+import org.apache.olingo.fit.AbstractBaseTestITCase;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.domain.v4.ODataValue;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.apache.olingo.commons.core.domain.v4.ODataEntityImpl;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import org.junit.BeforeClass;
+
+public abstract class AbstractTestITCase extends AbstractBaseTestITCase {
+
+ protected static final ODataClient client = ODataClientFactory.getV4();
+
+ protected static EdmEnabledODataClient edmClient;
+
+ protected static String testStaticServiceRootURL;
+
+ protected static String testKeyAsSegmentServiceRootURL;
+
+ protected static String testOpenTypeServiceRootURL;
+
+ protected static String testLargeModelServiceRootURL;
+
+ protected static String testAuthServiceRootURL;
+
+ @BeforeClass
+ public static void setUpODataServiceRoot() throws IOException {
+ testStaticServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc";
+ testKeyAsSegmentServiceRootURL = "http://localhost:9080/StaticService/V40/KeyAsSegment.svc";
+ testOpenTypeServiceRootURL = "http://localhost:9080/StaticService/V40/OpenType.svc";
+ testLargeModelServiceRootURL = "http://localhost:9080/StaticService/V40/Static.svc/large";
+ testAuthServiceRootURL = "http://localhost:9080/DefaultService.svc";
+
+ edmClient = ODataClientFactory.getEdmEnabledV4(testStaticServiceRootURL);
+ }
+
+ @Override
+ protected ODataClient getClient() {
+ return client;
+ }
+
+ protected ODataEntity read(final ODataPubFormat format, final URI editLink) {
+ final ODataEntityRequest<ODataEntity> req = getClient().getRetrieveRequestFactory().getEntityRequest(editLink);
+ req.setFormat(format);
+
+ final ODataRetrieveResponse<ODataEntity> res = req.execute();
+ final ODataEntity entity = res.getBody();
+
+ assertNotNull(entity);
+
+ if (ODataPubFormat.JSON_FULL_METADATA == format || ODataPubFormat.ATOM == format) {
+ assertEquals(req.getURI(), entity.getEditLink());
+ }
+
+ return entity;
+ }
+
+ protected void createAndDeleteOrder(final ODataPubFormat format, final int id) {
+ final ODataEntity order = new ODataEntityImpl(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
+
+ final ODataProperty orderId = getClient().getObjectFactory().newPrimitiveProperty("OrderID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id));
+ order.getProperties().add(orderId);
+
+ final ODataProperty orderDate = getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2011-03-04T16:03:57Z").build());
+ order.getProperties().add(orderDate);
+
+ final ODataProperty shelfLife = getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ order.getProperties().add(shelfLife);
+
+ final ODataCollectionValue<ODataValue> orderShelfLifesValue = getClient().getObjectFactory().
+ newCollectionValue("Collection(Duration)");
+ orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000001S").build());
+ orderShelfLifesValue.add(getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build());
+ final ODataProperty orderShelfLifes = getClient().getObjectFactory().
+ newCollectionProperty("OrderShelfLifes", orderShelfLifesValue);
+ order.getProperties().add(orderShelfLifes);
+
+ final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Orders").build(), order);
+ req.setFormat(format);
+ final ODataEntity created = req.execute().getBody();
+ assertNotNull(created);
+ assertEquals(2, created.getProperty("OrderShelfLifes").getCollectionValue().size());
+
+ final ODataDeleteRequest deleteReq = getClient().getCUDRequestFactory().getDeleteRequest(created.getEditLink());
+ final ODataDeleteResponse deleteRes = deleteReq.execute();
+ assertEquals(204, deleteRes.getStatusCode());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java
new file mode 100644
index 0000000..373a489
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/AsyncTestITCase.java
@@ -0,0 +1,166 @@
+/*
+ * 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.v4;
+
+import java.net.URI;
+import java.util.List;
+
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Future;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.v4.AsyncRequestWrapper;
+import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
+import org.apache.olingo.client.api.communication.response.v4.AsyncResponseWrapper;
+import org.apache.olingo.client.api.uri.CommonURIBuilder;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import static org.apache.olingo.fit.v4.AbstractTestITCase.client;
+import org.apache.olingo.commons.api.domain.CommonODataEntity;
+import org.apache.olingo.commons.api.domain.CommonODataProperty;
+import org.apache.olingo.commons.api.domain.ODataInlineEntity;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+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 org.junit.Test;
+
+public class AsyncTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void asyncRequestV3Style() throws InterruptedException, ExecutionException {
+ final CommonURIBuilder<?> uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers");
+ final Future<ODataRetrieveResponse<ODataEntitySet>> futureRes =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build()).asyncExecute();
+ assertNotNull(futureRes);
+
+ while (!futureRes.isDone()) {
+ Thread.sleep(1000L);
+ }
+
+ final ODataRetrieveResponse<ODataEntitySet> res = futureRes.get();
+ assertNotNull(res);
+ assertEquals(200, res.getStatusCode());
+ assertFalse(res.getBody().getEntities().isEmpty());
+ }
+
+ private void withInlineEntry(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(1).expand("Company");
+
+ final ODataEntityRequest<ODataEntity> req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final AsyncRequestWrapper<ODataRetrieveResponse<ODataEntity>> async =
+ client.getAsyncRequestFactory().<ODataRetrieveResponse<ODataEntity>>getAsyncRequestWrapper(req);
+
+ final AsyncResponseWrapper<ODataRetrieveResponse<ODataEntity>> responseWrapper = async.execute();
+
+ assertFalse(responseWrapper.isPreferenceApplied());
+
+ final ODataRetrieveResponse<ODataEntity> res = responseWrapper.getODataResponse();
+ final ODataEntity entity = res.getBody();
+
+ assertNotNull(entity);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Customer", entity.getTypeName().toString());
+ assertEquals(testStaticServiceRootURL + "/Customers(PersonID=1)", entity.getEditLink().toASCIIString());
+
+ assertEquals(3, entity.getNavigationLinks().size());
+
+ if (ODataPubFormat.ATOM == format) {
+ assertTrue(entity.getAssociationLinks().isEmpty());
+ // In JSON, association links for each $ref link will exist.
+ }
+
+ boolean found = false;
+
+ for (ODataLink link : entity.getNavigationLinks()) {
+ if (link instanceof ODataInlineEntity) {
+ final CommonODataEntity inline = ((ODataInlineEntity) link).getEntity();
+ assertNotNull(inline);
+
+ final List<? extends CommonODataProperty> properties = inline.getProperties();
+ assertEquals(5, properties.size());
+
+ assertTrue(properties.get(0).getName().equals("CompanyID")
+ || properties.get(1).getName().equals("CompanyID")
+ || properties.get(2).getName().equals("CompanyID")
+ || properties.get(3).getName().equals("CompanyID")
+ || properties.get(4).getName().equals("CompanyID"));
+ assertTrue(properties.get(0).getValue().toString().equals("0")
+ || properties.get(1).getValue().toString().equals("0")
+ || properties.get(2).getValue().toString().equals("0")
+ || properties.get(3).getValue().toString().equals("0")
+ || properties.get(4).getValue().toString().equals("0"));
+
+ found = true;
+ }
+ }
+
+ assertTrue(found);
+ }
+
+ private void asynOrders(final ODataPubFormat format) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("async").appendEntitySetSegment("Orders");
+
+ final ODataEntitySetRequest<ODataEntitySet> req =
+ client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setFormat(format);
+
+ final AsyncRequestWrapper<ODataRetrieveResponse<ODataEntitySet>> async =
+ client.getAsyncRequestFactory().<ODataRetrieveResponse<ODataEntitySet>>getAsyncRequestWrapper(req);
+ async.callback(URI.create("http://client.service.it/callback/endpoint"));
+
+ final AsyncResponseWrapper<ODataRetrieveResponse<ODataEntitySet>> responseWrapper = async.execute();
+
+ assertTrue(responseWrapper.isPreferenceApplied());
+ assertTrue(responseWrapper.isDone());
+
+ final ODataRetrieveResponse<ODataEntitySet> res = responseWrapper.getODataResponse();
+ final ODataEntitySet entitySet = res.getBody();
+
+ assertFalse(entitySet.getEntities().isEmpty());
+ }
+
+ @Test
+ public void withInlineEntryAsAtom() {
+ withInlineEntry(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void withInlineEntryAsJSON() {
+ // this needs to be full, otherwise there is no mean to recognize links
+ withInlineEntry(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ @Test
+ public void asynOrdersAsAtom() {
+ asynOrders(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void asynOrdersAsJSON() {
+ asynOrders(ODataPubFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
new file mode 100644
index 0000000..0cf694c
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/BatchTestITCase.java
@@ -0,0 +1,710 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.fail;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+import java.net.URI;
+import java.util.Calendar;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.concurrent.Future;
+import java.util.concurrent.TimeUnit;
+import org.apache.http.HttpResponse;
+import org.apache.olingo.client.api.ODataBatchConstants;
+import org.apache.olingo.client.api.communication.header.HeaderName;
+import org.apache.olingo.client.api.communication.request.ODataStreamManager;
+import org.apache.olingo.client.api.communication.request.batch.ODataBatchResponseItem;
+import org.apache.olingo.client.api.communication.request.batch.ODataChangeset;
+import org.apache.olingo.client.api.communication.request.batch.ODataRetrieve;
+import org.apache.olingo.client.api.communication.request.batch.v4.BatchStreamManager;
+import org.apache.olingo.client.api.communication.request.batch.v4.ODataBatchRequest;
+import org.apache.olingo.client.api.communication.request.batch.v4.ODataOutsideUpdate;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityUpdateRequest;
+import org.apache.olingo.client.api.communication.request.cud.v4.UpdateType;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.v4.AsyncBatchRequestWrapper;
+import org.apache.olingo.client.api.communication.response.ODataBatchResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
+import org.apache.olingo.client.api.communication.response.ODataResponse;
+import org.apache.olingo.client.api.communication.response.v4.AsyncResponse;
+import org.apache.olingo.client.api.communication.response.v4.AsyncResponseWrapper;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.client.core.communication.request.AbstractODataStreamManager;
+import org.apache.olingo.client.core.communication.request.Wrapper;
+import org.apache.olingo.client.core.communication.request.batch.ODataChangesetResponseItem;
+import org.apache.olingo.client.core.communication.request.batch.ODataRetrieveResponseItem;
+import org.apache.olingo.client.core.communication.request.batch.v4.ODataOutsideUpdateResponseItem;
+import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl;
+import org.apache.olingo.client.core.communication.request.retrieve.ODataEntityRequestImpl.ODataEntityResponseImpl;
+import org.apache.olingo.client.core.uri.URIUtils;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ContentType;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class BatchTestITCase extends AbstractTestITCase {
+
+ private static final String PREFIX = "!!PREFIX!!";
+
+ private static final String SUFFIX = "!!SUFFIX!!";
+
+ private static final int MAX = 10000;
+
+ // ------------------------
+ // Uncomment to check externally ...
+ // ------------------------
+ // private final static String testStaticServiceRootURL=
+ // "http://odatae2etest.azurewebsites.net/javatest/DefaultService/";
+ // private final static String ACCEPT = ContentType.MULTIPART_MIXED;
+ // ------------------------
+ private final static String ACCEPT = ContentType.APPLICATION_OCTET_STREAM;
+
+ @Test
+ public void stringStreaming() {
+ final TestStreamManager streaming = new TestStreamManager();
+
+ new StreamingThread(streaming).start();
+
+ streaming.addObject((PREFIX + "\n").getBytes());
+
+ for (int i = 0; i <= MAX; i++) {
+ streaming.addObject((i + ") send info\n").getBytes());
+ }
+
+ streaming.addObject(SUFFIX.getBytes());
+ streaming.finalizeBody();
+ }
+
+ @Test
+ public void emptyBatchRequest() {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+
+ final BatchStreamManager payload = request.execute();
+ final ODataBatchResponse response = payload.getResponse();
+
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void changesetWithError() {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+
+ final BatchStreamManager payload = request.execute();
+ final ODataChangeset changeset = payload.addChangeset();
+
+ URIBuilder targetURI;
+ ODataEntityCreateRequest<ODataEntity> createReq;
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+ for (int i = 1; i <= 2; i++) {
+ // Create Customer into the changeset
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i));
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+ }
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("WrongEntitySet");
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(105));
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+ for (int i = 3; i <= 4; i++) {
+ // Create Customer into the changeset
+ createReq = client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), newOrder(100 + i));
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+ }
+
+ final ODataBatchResponse response = payload.getResponse();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+ // retrieve the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+
+ ODataChangesetResponseItem retitem = (ODataChangesetResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertEquals(404, res.getStatusCode());
+ assertEquals("Not Found", res.getStatusMessage());
+ assertEquals(Integer.valueOf(3), Integer.valueOf(
+ res.getHeader(ODataBatchConstants.CHANGESET_CONTENT_ID_NAME).iterator().next()));
+
+ assertFalse(retitem.hasNext());
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void continueOnError() {
+ continueOnError(true);
+ }
+
+ @Test
+ public void doNotContinueOnError() {
+ continueOnError(false);
+ }
+
+ private void continueOnError(final boolean continueOnError) {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+ request.continueOnError();
+
+ final BatchStreamManager streamManager = request.execute();
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ ODataRetrieve retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+ targetURI.appendEntitySetSegment("UnexistinfEntitySet").appendKeySegment(1);
+
+ // create new request
+ ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+ queryReq.setFormat(ODataPubFormat.JSON);
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
+
+ // create new request
+ queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ // retrieve the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertEquals(404, res.getStatusCode());
+ assertEquals("Not Found", res.getStatusMessage());
+
+ if (continueOnError) {
+ item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ retitem = (ODataRetrieveResponseItem) item;
+ res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void changesetWithReference() throws EdmPrimitiveTypeException {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+ final BatchStreamManager streamManager = request.execute();
+
+ final ODataChangeset changeset = streamManager.addChangeset();
+ ODataEntity order = newOrder(20);
+
+ final URIBuilder uriBuilder = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+
+ // add create request
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(uriBuilder.build(), order);
+
+ changeset.addRequest(createReq);
+
+ // retrieve request reference
+ int createRequestRef = changeset.getLastContentId();
+
+ // add update request: link CustomerInfo(17) to the new customer
+ final ODataEntity customerChanges = client.getObjectFactory().newEntity(order.getTypeName());
+ customerChanges.addLink(client.getObjectFactory().newEntitySetNavigationLink(
+ "OrderDetails",
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("OrderDetails").
+ appendKeySegment(new HashMap<String, Object>() {
+ private static final long serialVersionUID = 3109256773218160485L;
+
+ {
+ put("OrderID", 7);
+ put("ProductID", 5);
+ }
+ }).build()));
+
+ final ODataEntityUpdateRequest<ODataEntity> updateReq = client.getCUDRequestFactory().getEntityUpdateRequest(
+ URI.create("$" + createRequestRef), UpdateType.PATCH, customerChanges);
+
+ changeset.addRequest(updateReq);
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+
+ // verify response payload ...
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ final ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataChangesetResponseItem);
+
+ final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
+
+ ODataResponse res = chgitem.next();
+ assertEquals(201, res.getStatusCode());
+ assertTrue(res instanceof ODataEntityCreateResponse);
+
+ order = ((ODataEntityCreateResponse<ODataEntity>) res).getBody();
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().getEntitySetRequest(
+ URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString() + "/OrderDetails"));
+
+ assertEquals(Integer.valueOf(7),
+ req.execute().getBody().getEntities().get(0).getProperty("OrderID").getPrimitiveValue().
+ toCastValue(Integer.class));
+
+ res = chgitem.next();
+ assertEquals(204, res.getStatusCode());
+ assertTrue(res instanceof ODataEntityUpdateResponse);
+
+ // clean ...
+ assertEquals(204, client.getCUDRequestFactory().getDeleteRequest(
+ URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString())).execute().
+ getStatusCode());
+
+ try {
+ client.getRetrieveRequestFactory().getEntityRequest(
+ URIUtils.getURI(testStaticServiceRootURL, order.getEditLink().toASCIIString())).
+ execute().getBody();
+ fail();
+ } catch (Exception e) {
+ // ignore
+ }
+ }
+
+ @Test
+ @SuppressWarnings("unchecked")
+ public void batchRequestWithOutsideUpdates() throws EdmPrimitiveTypeException {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+ final BatchStreamManager streamManager = request.execute();
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ ODataRetrieve retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+ targetURI.appendEntitySetSegment("Customers").appendKeySegment(1).
+ expand("Orders").select("PersonID,Orders/OrderID");
+
+ // create new request
+ ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+ queryReq.setFormat(ODataPubFormat.JSON);
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add new order with outside item
+ // -------------------------------------------
+ final ODataOutsideUpdate outside = streamManager.addOutsideUpdate();
+
+ // prepare URI
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+ final ODataEntity original = newOrder(2000);
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
+ createReq.setFormat(ODataPubFormat.JSON);
+ outside.setRequest(createReq);
+ // -------------------------------------------
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ // retrieve the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+
+ // retrieve the second item (ODataChangeset)
+ item = iter.next();
+ assertTrue(item instanceof ODataOutsideUpdateResponseItem);
+
+ final ODataOutsideUpdateResponseItem outitem = (ODataOutsideUpdateResponseItem) item;
+ res = outitem.next();
+ assertTrue(res instanceof ODataEntityCreateResponse);
+ assertEquals(201, res.getStatusCode());
+ assertEquals("Created", res.getStatusMessage());
+
+ final ODataEntityCreateResponse<ODataEntity> entres = (ODataEntityCreateResponse<ODataEntity>) res;
+ final ODataEntity entity = entres.getBody();
+ assertEquals(2000, entity.getProperty("OrderID").getPrimitiveValue().toCastValue(Integer.class).intValue());
+
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ @SuppressWarnings({"unchecked"})
+ public void batchRequest() throws EdmPrimitiveTypeException {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(testStaticServiceRootURL);
+ request.setAccept(ACCEPT);
+
+ final BatchStreamManager streamManager = request.execute();
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ ODataRetrieve retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+ targetURI.appendEntitySetSegment("Customers").appendKeySegment(1);
+
+ // create new request
+ ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+ queryReq.setFormat(ODataPubFormat.JSON);
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add changeset item
+ // -------------------------------------------
+ final ODataChangeset changeset = streamManager.addChangeset();
+
+ // Update Customer into the changeset
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
+ final URI editLink = targetURI.build();
+
+ final ODataEntity patch = client.getObjectFactory().newEntity(
+ new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Customer"));
+ patch.setEditLink(editLink);
+
+ patch.getProperties().add(client.getObjectFactory().newPrimitiveProperty(
+ "LastName",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("new last name")));
+
+ final ODataEntityUpdateRequest<ODataEntity> changeReq =
+ client.getCUDRequestFactory().getEntityUpdateRequest(UpdateType.PATCH, patch);
+ changeReq.setFormat(ODataPubFormat.JSON_FULL_METADATA);
+
+ changeset.addRequest(changeReq);
+
+ // Create Order into the changeset
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Orders");
+ final ODataEntity original = newOrder(1000);
+ final ODataEntityCreateRequest<ODataEntity> createReq =
+ client.getCUDRequestFactory().getEntityCreateRequest(targetURI.build(), original);
+ createReq.setFormat(ODataPubFormat.JSON);
+ changeset.addRequest(createReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ retrieve = streamManager.addRetrieve();
+
+ // prepare URI
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
+
+ // create new request
+ queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ final ODataBatchResponse response = streamManager.getResponse();
+ assertEquals(200, response.getStatusCode());
+ assertEquals("OK", response.getStatusMessage());
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ // retrieve the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+
+ ODataEntityRequestImpl<ODataEntity>.ODataEntityResponseImpl entres =
+ (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
+
+ ODataEntity entity = entres.getBody();
+ assertEquals(1, entity.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // retrieve the second item (ODataChangeset)
+ item = iter.next();
+ assertTrue(item instanceof ODataChangesetResponseItem);
+
+ final ODataChangesetResponseItem chgitem = (ODataChangesetResponseItem) item;
+ res = chgitem.next();
+ assertTrue(res instanceof ODataEntityUpdateResponse);
+ assertEquals(204, res.getStatusCode());
+ assertEquals("No Content", res.getStatusMessage());
+
+ res = chgitem.next();
+ assertTrue(res instanceof ODataEntityCreateResponse);
+ assertEquals(201, res.getStatusCode());
+ assertEquals("Created", res.getStatusMessage());
+
+ final ODataEntityCreateResponse<ODataEntity> createres = (ODataEntityCreateResponse<ODataEntity>) res;
+ entity = createres.getBody();
+ assertEquals(new Integer(1000), entity.getProperty("OrderID").getPrimitiveValue().toCastValue(Integer.class));
+
+ // retrive the third item (ODataRetrieve)
+ item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ retitem = (ODataRetrieveResponseItem) item;
+ res = retitem.next();
+ assertTrue(res instanceof ODataEntityResponseImpl);
+ assertEquals(200, res.getStatusCode());
+ assertEquals("OK", res.getStatusMessage());
+
+ entres = (ODataEntityRequestImpl.ODataEntityResponseImpl) res;
+ entity = entres.getBody();
+ assertEquals("new last name", entity.getProperty("LastName").getPrimitiveValue().toCastValue(String.class));
+
+ assertFalse(iter.hasNext());
+ }
+
+ @Test
+ public void async() {
+ // create your request
+ final ODataBatchRequest request = client.getBatchRequestFactory().getBatchRequest(
+ URI.create(testStaticServiceRootURL + "/async/").normalize().toASCIIString());
+ request.setAccept(ACCEPT);
+
+ final AsyncBatchRequestWrapper async = client.getAsyncRequestFactory().getAsyncBatchRequestWrapper(request);
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ ODataRetrieve retrieve = async.addRetrieve();
+
+ // prepare URI
+ URIBuilder targetURI = client.getURIBuilder(testStaticServiceRootURL);
+ targetURI.appendEntitySetSegment("People").appendKeySegment(5);
+
+ // create new request
+ ODataEntityRequest<ODataEntity> queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+ queryReq.setFormat(ODataPubFormat.JSON);
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ // -------------------------------------------
+ // Add retrieve item
+ // -------------------------------------------
+ retrieve = async.addRetrieve();
+
+ // prepare URI
+ targetURI = client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").appendKeySegment(1);
+
+ // create new request
+ queryReq = client.getRetrieveRequestFactory().getEntityRequest(targetURI.build());
+
+ retrieve.setRequest(queryReq);
+ // -------------------------------------------
+
+ final AsyncResponseWrapper<ODataBatchResponse> responseWrapper = async.execute();
+
+ assertTrue(responseWrapper.isPreferenceApplied());
+ assertTrue(responseWrapper.isDone());
+
+ final ODataBatchResponse response = responseWrapper.getODataResponse();
+
+ assertEquals(200, response.getStatusCode());
+ assertEquals("Ok", response.getStatusMessage());
+ final Iterator<ODataBatchResponseItem> iter = response.getBody();
+
+ // retrieve the first item (ODataRetrieve)
+ ODataBatchResponseItem item = iter.next();
+ assertTrue(item instanceof ODataRetrieveResponseItem);
+
+ // The service return interim results to an asynchronously executing batch.
+ ODataRetrieveResponseItem retitem = (ODataRetrieveResponseItem) item;
+ ODataResponse res = retitem.next();
+ assertTrue(res instanceof AsyncResponse);
+ assertEquals(202, res.getStatusCode());
+ assertEquals("Accepted", res.getStatusMessage());
+
+ Collection<String> newMonitorLocation = res.getHeader(HeaderName.location);
+ if (newMonitorLocation != null && !newMonitorLocation.isEmpty()) {
+ responseWrapper.forceNextMonitorCheck(URI.create(newMonitorLocation.iterator().next()));
+ // .... now you can start again with isDone() and getODataResponse().
+ }
+
+ assertFalse(retitem.hasNext());
+ assertFalse(iter.hasNext());
+ }
+
+ private static class TestStreamManager extends AbstractODataStreamManager<ODataBatchResponse> {
+
+ public TestStreamManager() {
+ super(new Wrapper<Future<HttpResponse>>());
+ }
+
+ public ODataStreamManager<ODataBatchResponse> addObject(final byte[] src) {
+ stream(src);
+ return this;
+ }
+
+ @Override
+ protected ODataBatchResponse getResponse(final long timeout, final TimeUnit unit) {
+ throw new UnsupportedOperationException("Not supported yet.");
+ }
+ };
+
+ /**
+ * To be used for debug purposes.
+ */
+ private static class StreamingThread extends Thread {
+
+ private final TestStreamManager streaming;
+
+ public StreamingThread(final TestStreamManager streaming) {
+ super();
+ this.streaming = streaming;
+ }
+
+ @Override
+ public void run() {
+ try {
+ final StringBuilder builder = new StringBuilder();
+
+ byte[] buff = new byte[1024];
+
+ int len;
+
+ while ((len = streaming.getBody().read(buff)) >= 0) {
+ builder.append(new String(buff, 0, len));
+ }
+
+ assertTrue(builder.toString().startsWith(PREFIX));
+ assertTrue(builder.toString().contains((MAX / 2) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 3) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 20) + ") send info"));
+ assertTrue(builder.toString().contains((MAX / 30) + ") send info"));
+ assertTrue(builder.toString().contains(MAX + ") send info"));
+ assertTrue(builder.toString().endsWith(SUFFIX));
+
+ } catch (IOException e) {
+ fail();
+ }
+ }
+ }
+
+ private static class BatchStreamingThread extends Thread {
+
+ private final BatchStreamManager streaming;
+
+ public BatchStreamingThread(final BatchStreamManager streaming) {
+ super();
+ this.streaming = streaming;
+ }
+
+ @Override
+ public void run() {
+ try {
+ final StringBuilder builder = new StringBuilder();
+
+ final byte[] buff = new byte[1024];
+
+ int len;
+
+ while ((len = streaming.getBody().read(buff)) >= 0) {
+ builder.append(new String(buff, 0, len));
+ }
+
+ LOG.debug("Batch request {}", builder.toString());
+
+ assertTrue(builder.toString().contains("Content-Id:2"));
+ assertTrue(builder.toString().contains("GET " + testStaticServiceRootURL));
+ } catch (IOException e) {
+ fail();
+ }
+ }
+ }
+
+ private ODataEntity newOrder(final int id) {
+ final ODataEntity order = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Order"));
+
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("OrderDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
+ order.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ShelfLife",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Duration).setText("PT0.0000002S").build()));
+ order.getProperties().add(getClient().getObjectFactory().newCollectionProperty("OrderShelfLifes",
+ getClient().getObjectFactory().newCollectionValue(EdmPrimitiveTypeKind.Duration.name()).add(
+ getClient().getObjectFactory().newPrimitiveValueBuilder().setType(EdmPrimitiveTypeKind.Duration).
+ setText("PT0.0000002S").build())));
+
+ return order;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
new file mode 100644
index 0000000..88e1ac3
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/BoundOperationInvokeTestITCase.java
@@ -0,0 +1,339 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.util.Collections;
+import java.util.LinkedHashMap;
+import java.util.Map;
+import org.apache.olingo.client.api.communication.request.invoke.ODataInvokeRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
+import org.apache.olingo.client.api.uri.v4.URIBuilder;
+import org.apache.olingo.commons.api.domain.ODataCollectionValue;
+import org.apache.olingo.commons.api.domain.ODataComplexValue;
+import org.apache.olingo.commons.api.domain.ODataOperation;
+import org.apache.olingo.commons.api.domain.ODataPrimitiveValue;
+import org.apache.olingo.commons.api.domain.ODataValue;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataEnumValue;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class BoundOperationInvokeTestITCase extends AbstractTestITCase {
+
+ private Edm getEdm() {
+ final Edm edm = getClient().getRetrieveRequestFactory().
+ getMetadataRequest(testStaticServiceRootURL).execute().getBody();
+ assertNotNull(edm);
+
+ return edm;
+ }
+
+ private void functions(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final Edm edm = getEdm();
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ // GetEmployeesCount
+ URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
+ ODataEntityRequest<ODataEntity> entityReq =
+ getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ ODataEntity entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetEmployeesCount");
+ assertNotNull(boundOp);
+
+ EdmFunction func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(),
+ false, null);
+ assertNotNull(func);
+
+ final ODataInvokeRequest<ODataProperty> getEmployeesCountReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
+ getEmployeesCountReq.setFormat(format);
+ final ODataProperty getEmployeesCountRes = getEmployeesCountReq.execute().getBody();
+ assertNotNull(getEmployeesCountRes);
+ assertTrue(getEmployeesCountRes.hasPrimitiveValue());
+
+ // GetProductDetails
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Products").appendKeySegment(5);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetProductDetails");
+ assertNotNull(boundOp);
+
+ func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
+ assertNotNull(func);
+
+ final ODataPrimitiveValue count = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(1);
+ final ODataInvokeRequest<ODataEntitySet> getProductDetailsReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
+ Collections.<String, ODataValue>singletonMap("count", count));
+ getProductDetailsReq.setFormat(format);
+ final ODataEntitySet getProductDetailsRes = getProductDetailsReq.execute().getBody();
+ assertNotNull(getProductDetailsRes);
+ assertEquals(1, getProductDetailsRes.getCount());
+
+ // GetRelatedProduct
+ final Map<String, Object> keyMap = new LinkedHashMap<String, Object>();
+ keyMap.put("ProductID", 6);
+ keyMap.put("ProductDetailID", 1);
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("ProductDetails").appendKeySegment(keyMap);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetRelatedProduct");
+ assertNotNull(boundOp);
+
+ func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
+ assertNotNull(func);
+
+ final ODataInvokeRequest<ODataEntity> getRelatedProductReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
+ getRelatedProductReq.setFormat(format);
+ final ODataEntity getRelatedProductRes = getRelatedProductReq.execute().getBody();
+ assertNotNull(getRelatedProductRes);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.Product",
+ getRelatedProductRes.getTypeName().toString());
+ assertEquals(6, getRelatedProductRes.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // GetDefaultPI
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetDefaultPI");
+ assertNotNull(boundOp);
+
+ func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
+ assertNotNull(func);
+
+ final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
+ getDefaultPIReq.setFormat(format);
+ final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
+ assertNotNull(getDefaultPIRes);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
+ getDefaultPIRes.getTypeName().toString());
+ assertEquals(101901,
+ getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // GetAccountInfo
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetAccountInfo");
+ assertNotNull(boundOp);
+
+ func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
+ assertNotNull(func);
+
+ final ODataInvokeRequest<ODataProperty> getAccountInfoReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func);
+ getAccountInfoReq.setFormat(format);
+ final ODataProperty getAccountInfoRes = getAccountInfoReq.execute().getBody();
+ assertNotNull(getAccountInfoRes);
+ assertTrue(getAccountInfoRes.hasComplexValue());
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.AccountInfo",
+ getAccountInfoRes.getComplexValue().getTypeName());
+
+ // GetActualAmount
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(
+ entity.getNavigationLink("MyGiftCard").getLink());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+ assertEquals(301, entity.getProperty("GiftCardID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.GetActualAmount");
+ assertNotNull(boundOp);
+
+ func = edm.getBoundFunction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false, null);
+ assertNotNull(func);
+
+ final ODataPrimitiveValue bonusRate = getClient().getObjectFactory().newPrimitiveValueBuilder().buildDouble(1.1);
+ final ODataInvokeRequest<ODataProperty> getActualAmountReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), func,
+ Collections.<String, ODataValue>singletonMap("bonusRate", bonusRate));
+ getActualAmountReq.setFormat(format);
+ final ODataProperty getActualAmountRes = getActualAmountReq.execute().getBody();
+ assertNotNull(getActualAmountRes);
+ assertEquals(41.79, getActualAmountRes.getPrimitiveValue().toCastValue(Double.class), 0);
+ }
+
+ @Test
+ public void atomFunctions() throws EdmPrimitiveTypeException {
+ functions(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonFunctions() throws EdmPrimitiveTypeException {
+ functions(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void actions(final ODataPubFormat format) throws EdmPrimitiveTypeException {
+ final Edm edm = getEdm();
+ final EdmEntityContainer container = edm.getSchemas().get(0).getEntityContainer();
+ assertNotNull(container);
+
+ // IncreaseRevenue
+ URIBuilder builder = getClient().getURIBuilder(testStaticServiceRootURL).appendSingletonSegment("Company");
+ ODataEntityRequest<ODataEntity> entityReq =
+ getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ ODataEntity entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ ODataOperation boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.IncreaseRevenue");
+ assertNotNull(boundOp);
+
+ EdmAction act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
+ assertNotNull(act);
+
+ final ODataPrimitiveValue increaseValue = getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.Int64).setValue(12).build();
+ final ODataInvokeRequest<ODataProperty> increaseRevenueReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
+ Collections.<String, ODataValue>singletonMap("IncreaseValue", increaseValue));
+ increaseRevenueReq.setFormat(format);
+ final ODataProperty increaseRevenueRes = increaseRevenueReq.execute().getBody();
+ assertNotNull(increaseRevenueRes);
+ assertTrue(increaseRevenueRes.hasPrimitiveValue());
+
+ // AddAccessRight
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Products").appendKeySegment(5);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.AddAccessRight");
+ assertNotNull(boundOp);
+
+ act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
+ assertNotNull(act);
+
+ final ODataEnumValue accessRight = getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute");
+ final ODataInvokeRequest<ODataProperty> getProductDetailsReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
+ Collections.<String, ODataValue>singletonMap("accessRight", accessRight));
+ getProductDetailsReq.setFormat(format);
+ final ODataProperty getProductDetailsRes = getProductDetailsReq.execute().getBody();
+ assertNotNull(getProductDetailsRes);
+ assertTrue(getProductDetailsRes.hasEnumValue());
+
+ // ResetAddress
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Customers").appendKeySegment(2);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.ResetAddress");
+ assertNotNull(boundOp);
+
+ act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()),
+ edm.getEntityType(entity.getTypeName()).getBaseType().getFullQualifiedName(), false);
+ assertNotNull(act);
+
+ final ODataCollectionValue<org.apache.olingo.commons.api.domain.v4.ODataValue> addresses =
+ getClient().getObjectFactory().
+ newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.Address)");
+ final ODataComplexValue<ODataProperty> address = getClient().getObjectFactory().
+ newLinkedComplexValue("Microsoft.Test.OData.Services.ODataWCFService.Address");
+ address.add(client.getObjectFactory().newPrimitiveProperty("Street",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Piazza La Bomba E Scappa")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("City",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("Tollo")));
+ address.add(client.getObjectFactory().newPrimitiveProperty("PostalCode",
+ client.getObjectFactory().newPrimitiveValueBuilder().buildString("66010")));
+ addresses.add(address);
+ final ODataPrimitiveValue index = getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(0);
+ final Map<String, ODataValue> params = new LinkedHashMap<String, ODataValue>(2);
+ params.put("addresses", addresses);
+ params.put("index", index);
+ final ODataInvokeRequest<ODataEntity> resetAddressReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act, params);
+ resetAddressReq.setFormat(format);
+ final ODataEntity resetAddressRes = resetAddressReq.execute().getBody();
+ assertNotNull(resetAddressRes);
+ assertEquals(2, resetAddressRes.getProperty("PersonID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ // RefreshDefaultPI
+ builder = getClient().getURIBuilder(testStaticServiceRootURL).
+ appendEntitySetSegment("Accounts").appendKeySegment(101);
+ entityReq = getClient().getRetrieveRequestFactory().getEntityRequest(builder.build());
+ entityReq.setFormat(format);
+ entity = entityReq.execute().getBody();
+ assertNotNull(entity);
+
+ boundOp = entity.getOperation("Microsoft.Test.OData.Services.ODataWCFService.RefreshDefaultPI");
+ assertNotNull(boundOp);
+
+ act = edm.getBoundAction(new FullQualifiedName(boundOp.getTitle()), entity.getTypeName(), false);
+ assertNotNull(act);
+
+ final ODataPrimitiveValue newDate = getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setText("2014-04-09T00:00:00Z").build();
+ final ODataInvokeRequest<ODataEntity> getDefaultPIReq =
+ getClient().getInvokeRequestFactory().getInvokeRequest(boundOp.getTarget(), act,
+ Collections.<String, ODataValue>singletonMap("newDate", newDate));
+ getDefaultPIReq.setFormat(format);
+ final ODataEntity getDefaultPIRes = getDefaultPIReq.execute().getBody();
+ assertNotNull(getDefaultPIRes);
+ assertEquals("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument",
+ getDefaultPIRes.getTypeName().toString());
+ assertEquals(101901,
+ getDefaultPIRes.getProperty("PaymentInstrumentID").getPrimitiveValue().toCastValue(Integer.class), 0);
+ }
+
+ @Test
+ public void atomActions() throws EdmPrimitiveTypeException {
+ actions(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonActions() throws EdmPrimitiveTypeException {
+ actions(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java
new file mode 100644
index 0000000..700ed98
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/DeltaTestITCase.java
@@ -0,0 +1,86 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
+import org.apache.olingo.client.api.communication.request.retrieve.v4.ODataDeltaRequest;
+import org.apache.olingo.commons.api.domain.v4.ODataDelta;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.domain.v4.ODataProperty;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class DeltaTestITCase extends AbstractTestITCase {
+
+ private void parse(final ODataPubFormat format) {
+ final ODataEntitySetRequest<ODataEntitySet> req = client.getRetrieveRequestFactory().getEntitySetRequest(
+ client.getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Customers").build());
+ req.setPrefer(client.newPreferences().trackChanges());
+
+ final ODataEntitySet customers = req.execute().getBody();
+ assertNotNull(customers);
+ assertNotNull(customers.getDeltaLink());
+
+ final ODataDeltaRequest deltaReq = client.getRetrieveRequestFactory().getDeltaRequest(customers.getDeltaLink());
+ deltaReq.setFormat(format);
+
+ final ODataDelta delta = deltaReq.execute().getBody();
+ assertNotNull(delta);
+
+ assertNotNull(delta.getDeltaLink());
+ assertTrue(delta.getDeltaLink().isAbsolute());
+ assertEquals(5, delta.getCount(), 0);
+
+ assertEquals(1, delta.getDeletedEntities().size());
+ assertTrue(delta.getDeletedEntities().get(0).getId().isAbsolute());
+ assertTrue(delta.getDeletedEntities().get(0).getId().toASCIIString().endsWith("Customers('ANTON')"));
+
+ assertEquals(1, delta.getAddedLinks().size());
+ assertTrue(delta.getAddedLinks().get(0).getSource().isAbsolute());
+ assertTrue(delta.getAddedLinks().get(0).getSource().toASCIIString().endsWith("Customers('BOTTM')"));
+ assertEquals("Orders", delta.getAddedLinks().get(0).getRelationship());
+
+ assertEquals(1, delta.getDeletedLinks().size());
+ assertTrue(delta.getDeletedLinks().get(0).getSource().isAbsolute());
+ assertTrue(delta.getDeletedLinks().get(0).getSource().toASCIIString().endsWith("Customers('ALFKI')"));
+ assertEquals("Orders", delta.getDeletedLinks().get(0).getRelationship());
+
+ assertEquals(2, delta.getEntities().size());
+ ODataProperty property = delta.getEntities().get(0).getProperty("ContactName");
+ assertNotNull(property);
+ assertTrue(property.hasPrimitiveValue());
+ property = delta.getEntities().get(1).getProperty("ShippingAddress");
+ assertNotNull(property);
+ assertTrue(property.hasComplexValue());
+ }
+
+ @Test
+ public void atomParse() {
+ parse(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonParse() {
+ parse(ODataPubFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/8042913b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java
new file mode 100644
index 0000000..3e66e1d
--- /dev/null
+++ b/fit/src/test/java/org/apache/olingo/fit/v4/EntityCreateTestITCase.java
@@ -0,0 +1,186 @@
+/*
+ * 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.v4;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.net.URI;
+import java.util.Calendar;
+import org.apache.commons.lang3.RandomUtils;
+import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
+import org.apache.olingo.client.api.communication.response.ODataDeleteResponse;
+import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
+import org.apache.olingo.commons.api.domain.ODataInlineEntitySet;
+import org.apache.olingo.commons.api.domain.ODataLink;
+import org.apache.olingo.commons.api.domain.v4.ODataEntity;
+import org.apache.olingo.commons.api.domain.v4.ODataEntitySet;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.format.ODataPubFormat;
+import org.junit.Test;
+
+public class EntityCreateTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void atomCreateAndDelete() {
+ createAndDeleteOrder(ODataPubFormat.ATOM, 1000);
+ }
+
+ @Test
+ public void jsonCreateAndDelete() {
+ createAndDeleteOrder(ODataPubFormat.JSON, 1001);
+ }
+
+ private void onContained(final ODataPubFormat format) {
+ final URI uri = getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Accounts").
+ appendKeySegment(101).appendNavigationSegment("MyPaymentInstruments").build();
+
+ // 1. read contained collection before any operation
+ ODataEntitySet instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
+ assertNotNull(instruments);
+ final int sizeBefore = instruments.getCount();
+
+ // 2. instantiate an ODataEntity of the same type as the collection above
+ final ODataEntity instrument = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.PaymentInstrument"));
+
+ int id = RandomUtils.nextInt(101999, 105000);
+ instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("PaymentInstrumentID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(id)));
+ instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("FriendlyName",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("New one")));
+ instrument.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("CreatedDate",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().
+ setType(EdmPrimitiveTypeKind.DateTimeOffset).setValue(Calendar.getInstance()).build()));
+
+ // 3. create it as contained entity
+ final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().
+ getEntityCreateRequest(uri, instrument);
+ final ODataEntityCreateResponse<ODataEntity> res = req.execute();
+ assertEquals(201, res.getStatusCode());
+
+ // 4. verify that the contained collection effectively grew
+ instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
+ assertNotNull(instruments);
+ final int sizeAfter = instruments.getCount();
+ assertEquals(sizeBefore + 1, sizeAfter);
+
+ // 5. remove the contained entity created above
+ final ODataDeleteResponse deleteRes = getClient().getCUDRequestFactory().
+ getDeleteRequest(getClient().getURIBuilder(uri.toASCIIString()).appendKeySegment(id).build()).execute();
+ assertEquals(204, deleteRes.getStatusCode());
+
+ // 6. verify that the contained collection effectively reduced
+ instruments = getClient().getRetrieveRequestFactory().getEntitySetRequest(uri).execute().getBody();
+ assertNotNull(instruments);
+ final int sizeEnd = instruments.getCount();
+ assertEquals(sizeBefore, sizeEnd);
+ }
+
+ @Test
+ public void atomOnContained() {
+ onContained(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void jsonOnContained() {
+ onContained(ODataPubFormat.JSON);
+ }
+
+ private void deepInsert(final ODataPubFormat format, final int productId, final int productDetailId)
+ throws EdmPrimitiveTypeException {
+
+ final ODataEntity product = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.Product"));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Name",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("Latte")));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityPerUnit",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("100g Bag")));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("UnitPrice",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildSingle(3.24f)));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("QuantityInStock",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(100)));
+ product.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Discontinued",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildBoolean(false)));
+ product.getProperties().add(getClient().getObjectFactory().newEnumProperty("UserAccess",
+ getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.AccessLevel", "Execute")));
+ product.getProperties().add(getClient().getObjectFactory().newEnumProperty("SkinColor",
+ getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Blue")));
+ product.getProperties().add(getClient().getObjectFactory().newCollectionProperty("CoverColors",
+ getClient().getObjectFactory().
+ newCollectionValue("Collection(Microsoft.Test.OData.Services.ODataWCFService.ProductDetail)")));
+ product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Green"));
+ product.getProperty("CoverColors").getCollectionValue().add(getClient().getObjectFactory().
+ newEnumValue("Microsoft.Test.OData.Services.ODataWCFService.Color", "Red"));
+
+ final ODataEntity detail = getClient().getObjectFactory().
+ newEntity(new FullQualifiedName("Microsoft.Test.OData.Services.ODataWCFService.ProductDetail"));
+ detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productId)));
+ detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductDetailID",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildInt32(productDetailId)));
+ detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("ProductName",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("LatteHQ")));
+ detail.getProperties().add(getClient().getObjectFactory().newPrimitiveProperty("Description",
+ getClient().getObjectFactory().newPrimitiveValueBuilder().buildString("High-Quality Milk")));
+
+ final ODataEntitySet details = getClient().getObjectFactory().newEntitySet();
+ details.getEntities().add(detail);
+
+ final ODataInlineEntitySet inlineDetails = getClient().getObjectFactory().
+ newDeepInsertEntitySet("Details", details);
+ product.addLink(inlineDetails);
+
+ final ODataEntityCreateRequest<ODataEntity> req = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().getURIBuilder(testStaticServiceRootURL).appendEntitySetSegment("Products").build(), product);
+ req.setFormat(format);
+ final ODataEntityCreateResponse<ODataEntity> res = req.execute();
+ assertEquals(201, res.getStatusCode());
+
+ final ODataEntity createdProduct = res.getBody();
+ assertEquals(productId,
+ createdProduct.getProperty("ProductID").getPrimitiveValue().toCastValue(Integer.class), 0);
+
+ final ODataLink createdLink = createdProduct.getNavigationLink("Details");
+ assertNotNull(createdLink);
+
+ final ODataEntitySet createdProductDetails =
+ getClient().getRetrieveRequestFactory().getEntitySetRequest(createdLink.getLink()).execute().getBody();
+ assertNotNull(createdProductDetails);
+ assertEquals(productDetailId, createdProductDetails.getEntities().iterator().next().
+ getProperty("ProductDetailID").getPrimitiveValue().toCastValue(Integer.class), 0);
+ }
+
+ @Test
+ public void atomDeepInsert() throws EdmPrimitiveTypeException {
+ deepInsert(ODataPubFormat.ATOM, 10, 10);
+ }
+
+ @Test
+ public void jsonDeepInsert() throws EdmPrimitiveTypeException {
+ deepInsert(ODataPubFormat.JSON_FULL_METADATA, 11, 11);
+ }
+}