You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ed...@apache.org on 2014/02/14 23:22:04 UTC
[28/51] [partial] [OLINGO-146] Java Client Lib contributed under SGA from Microsoft Open Technologies, Inc. The majority of this was written by Francesco Chicchiriccò
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityTestITCase.java
new file mode 100644
index 0000000..0c19ad4
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityTestITCase.java
@@ -0,0 +1,211 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static com.msopentech.odatajclient.engine.it.AbstractTestITCase.testDefaultServiceRootURL;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.msopentech.odatajclient.engine.client.http.HttpClientException;
+import com.msopentech.odatajclient.engine.communication.ODataClientErrorException;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataMediaRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityCreateRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityCreateRequest.MediaEntityCreateStreamManager;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityUpdateRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityUpdateRequest.MediaEntityUpdateStreamManager;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataStreamUpdateRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataStreamUpdateRequest.StreamUpdateStreamManager;
+import com.msopentech.odatajclient.engine.communication.response.ODataMediaEntityCreateResponse;
+import com.msopentech.odatajclient.engine.communication.response.ODataMediaEntityUpdateResponse;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.communication.response.ODataStreamUpdateResponse;
+import com.msopentech.odatajclient.engine.data.ODataEntity;
+import com.msopentech.odatajclient.engine.data.ODataProperty;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+import com.msopentech.odatajclient.engine.format.ODataMediaFormat;
+import com.msopentech.odatajclient.engine.format.ODataPubFormat;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import org.apache.commons.io.IOUtils;
+import org.junit.Test;
+
+public class MediaEntityTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void read() throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("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(testDefaultServiceRootURL).
+ appendEntityTypeSegment("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(testDefaultServiceRootURL).
+ appendEntityTypeSegment("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 issue136() throws Exception {
+ byte[] input = new byte[65000];
+ for (int i = 0; i < 65000; i++) {
+ input[i] = (byte) i;
+ }
+ createMediaEntity(ODataPubFormat.ATOM, new ByteArrayInputStream(input));
+ }
+
+ @Test(expected = HttpClientException.class)
+ public void issue136FailsWithException() throws Exception {
+ byte[] input = new byte[68000];
+ for (int i = 0; i < 68000; i++) {
+ input[i] = (byte) i;
+ }
+ createMediaEntity(ODataPubFormat.ATOM, new ByteArrayInputStream(input));
+ }
+
+ @Test
+ public void updateNamedStream() throws Exception {
+ URIBuilder builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("Car").appendKeySegment(16).appendStructuralSegment("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(testDefaultServiceRootURL).
+ appendEntityTypeSegment("Car").appendKeySegment(id).appendValueSegment();
+
+ final String TO_BE_UPDATED = "new buffered stream sample";
+ final InputStream input = IOUtils.toInputStream(TO_BE_UPDATED);
+
+ final ODataMediaEntityUpdateRequest updateReq =
+ client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input);
+ updateReq.setFormat(format);
+
+ final MediaEntityUpdateStreamManager streamManager = updateReq.execute();
+ final ODataMediaEntityUpdateResponse updateRes = streamManager.getResponse();
+ assertEquals(204, updateRes.getStatusCode());
+
+ builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("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()));
+ }
+
+ private void createMediaEntity(final ODataPubFormat format, final InputStream input) throws Exception {
+ final URIBuilder builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntitySetSegment("Car");
+
+ final ODataMediaEntityCreateRequest createReq =
+ client.getStreamedRequestFactory().getMediaEntityCreateRequest(builder.build(), input);
+ createReq.setFormat(format);
+
+ final MediaEntityCreateStreamManager streamManager = createReq.execute();
+ final ODataMediaEntityCreateResponse 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().<Integer>toCastValue();
+ }
+ }
+ 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/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityUpdateTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityUpdateTestITCase.java
new file mode 100644
index 0000000..1457038
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MediaEntityUpdateTestITCase.java
@@ -0,0 +1,156 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.*;
+
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataMediaRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityUpdateRequest;
+import com.msopentech.odatajclient.engine.communication.request.streamed.ODataMediaEntityUpdateRequest.MediaEntityUpdateStreamManager;
+import java.io.InputStream;
+import java.net.URI;
+
+import org.apache.commons.lang3.StringUtils;
+import org.junit.Test;
+
+import com.msopentech.odatajclient.engine.communication.response.ODataMediaEntityUpdateResponse;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.format.ODataPubFormat;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+import org.apache.commons.io.IOUtils;
+import org.apache.commons.io.input.BoundedInputStream;
+import org.apache.commons.lang3.builder.EqualsBuilder;
+
+public class MediaEntityUpdateTestITCase extends AbstractTestITCase {
+
+ private void updateMediaEntity(
+ final ODataPubFormat format,
+ final String prefer,
+ final String image,
+ final int id) throws Exception {
+
+ URIBuilder builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("Car").appendKeySegment(id).appendValueSegment();
+
+ // The sample service has an upload request size of 65k
+ InputStream input = new BoundedInputStream(getClass().getResourceAsStream(image), 65000);
+ final byte[] expected = new byte[65000];
+ IOUtils.read(input, expected, 0, expected.length);
+ IOUtils.closeQuietly(input);
+
+ input = new BoundedInputStream(getClass().getResourceAsStream(image), 65000);
+
+ final ODataMediaEntityUpdateRequest updateReq =
+ client.getStreamedRequestFactory().getMediaEntityUpdateRequest(builder.build(), input);
+ updateReq.setFormat(format);
+ updateReq.setPrefer(prefer);
+ final URI uri = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("Car").appendKeySegment(id).build();
+ final String etag = getETag(uri);
+ if (StringUtils.isNotBlank(etag)) {
+ updateReq.setIfMatch(etag);
+ }
+ final MediaEntityUpdateStreamManager streamManager = updateReq.execute();
+ final ODataMediaEntityUpdateResponse updateRes = streamManager.getResponse();
+ assertEquals(204, updateRes.getStatusCode());
+
+ builder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment("Car").appendKeySegment(id).appendValueSegment();
+
+ final ODataMediaRequest retrieveReq = client.getRetrieveRequestFactory().getMediaRequest(builder.build());
+
+ final ODataRetrieveResponse<InputStream> retrieveRes = retrieveReq.execute();
+ assertEquals(200, retrieveRes.getStatusCode());
+
+ final byte[] actual = new byte[65000];
+ IOUtils.read(retrieveRes.getBody(), actual, 0, actual.length);
+ assertTrue(new EqualsBuilder().append(expected, actual).isEquals());
+ }
+ // update media with JSON full metadata
+
+ @Test
+ public void updateMediaWithJSON() {
+ ODataPubFormat format = ODataPubFormat.JSON_FULL_METADATA;
+ String prefer = "return-content";
+ String media1 = "/images/big_buck_bunny.mp4";
+ String media2 = "/images/Renault.jpg";
+ String media3 = "/images/image1.png";
+ String media4 = "/images/20051210-w50s.flv";
+ int id = 11;
+ try {
+ updateMediaEntity(format, prefer, media1, id);
+ updateMediaEntity(format, prefer, media2, id);
+ updateMediaEntity(format, prefer, media3, id);
+ updateMediaEntity(format, prefer, media4, id);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } catch (AssertionError e) {
+ fail(e.getMessage());
+ }
+ }
+ // update media with ATOM
+
+ @Test
+ public void updateMediaWithATOM() {
+ ODataPubFormat format = ODataPubFormat.ATOM;
+ String prefer = "return-content";
+ String media = "/images/big_buck_bunny.mp4";
+ int id = 12;
+ try {
+ updateMediaEntity(format, prefer, media, id);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } catch (AssertionError e) {
+ fail(e.getMessage());
+ }
+ }
+ // update media with JSON minimla metadata
+
+ @Test
+ public void updateMediaWithJSONMinimal() {
+ ODataPubFormat format = ODataPubFormat.JSON;
+ String prefer = "return-content";
+ String media = "/images/big_buck_bunny.mp4";
+ int id = 13;
+ try {
+ updateMediaEntity(format, prefer, media, id);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } catch (AssertionError e) {
+ fail(e.getMessage());
+ }
+ }
+ // update media with JSON no metadata
+
+ @Test
+ public void updateMediaWithJSONNoMetadata() {
+ ODataPubFormat format = ODataPubFormat.JSON_NO_METADATA;
+ String prefer = "return-content";
+ String media = "/images/big_buck_bunny.mp4";
+ int id = 14;
+ try {
+ updateMediaEntity(format, prefer, media, id);
+ } catch (Exception e) {
+ fail(e.getMessage());
+ } catch (AssertionError e) {
+ fail(e.getMessage());
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MetadataRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MetadataRetrieveTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MetadataRetrieveTestITCase.java
new file mode 100644
index 0000000..10ebe97
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/MetadataRetrieveTestITCase.java
@@ -0,0 +1,146 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import com.msopentech.odatajclient.engine.communication.ODataClientErrorException;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataV3MetadataRequest;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.metadata.EdmType;
+import com.msopentech.odatajclient.engine.metadata.EdmV3Metadata;
+import com.msopentech.odatajclient.engine.metadata.EdmV3Type;
+import com.msopentech.odatajclient.engine.metadata.edm.AbstractEntityType;
+import com.msopentech.odatajclient.engine.metadata.edm.v3.EntityType;
+import com.msopentech.odatajclient.engine.format.ODataPubFormat;
+
+public class MetadataRetrieveTestITCase extends AbstractTestITCase {
+
+ private void retreiveMetadataTest(final ODataPubFormat reqFormat, final String acceptFormat) {
+ // testing entity types which are not open
+ final ODataV3MetadataRequest req = client.getRetrieveRequestFactory().
+ getMetadataRequest(testDefaultServiceRootURL);
+ req.setFormat(reqFormat);
+ req.setAccept(acceptFormat);
+ try {
+ final ODataRetrieveResponse<EdmV3Metadata> res = req.execute();
+ final EdmV3Metadata metadata = res.getBody();
+ assertNotNull(metadata);
+ assertEquals(24, metadata.getSchemas().get(0).getEntityContainers().get(0).getEntitySets().size());
+ final EdmType productCollection =
+ new EdmV3Type(metadata, "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.Product)");
+ assertTrue(productCollection.isCollection());
+ assertFalse(productCollection.isSimpleType());
+ assertFalse(productCollection.isEnumType());
+ assertFalse(productCollection.isComplexType());
+ assertTrue(productCollection.isEntityType());
+ final AbstractEntityType type = productCollection.getEntityType();
+ assertNotNull(type);
+ assertFalse(type.isOpenType());
+ assertEquals("Product", type.getName());
+ final EdmType stream = new EdmV3Type(metadata, "Edm.Stream");
+ assertNotNull(stream);
+ assertTrue(stream.isSimpleType());
+ assertFalse(stream.isCollection());
+ assertFalse(stream.isEnumType());
+ assertFalse(stream.isComplexType());
+ assertFalse(stream.isEntityType());
+ final EdmType customerCollection =
+ new EdmV3Type(metadata, "Collection(Microsoft.Test.OData.Services.AstoriaDefaultService.Customer)");
+ final AbstractEntityType customer = customerCollection.getEntityType();
+ assertNotNull(type);
+ assertFalse(customer.isOpenType());
+ assertEquals("Customer", customer.getName());
+
+ //testing open types
+ ODataV3MetadataRequest req1 =
+ client.getRetrieveRequestFactory().getMetadataRequest(testOpenTypeServiceRootURL);
+
+ req.setFormat(reqFormat);
+ req.setAccept(acceptFormat);
+ final ODataRetrieveResponse<EdmV3Metadata> res1 = req1.execute();
+ final EdmV3Metadata metadata1 = res1.getBody();
+ List<EntityType> types = metadata1.getSchema(0).getEntityTypes();
+ for (int i = 0; i < types.size(); i++) {
+ assertTrue(types.get(0).isOpenType());
+ }
+ } catch (ODataClientErrorException e) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
+ }
+ }
+
+ @Test
+ public void jsonTest() {
+ retreiveMetadataTest(ODataPubFormat.JSON, "application/json");
+ }
+
+ @Test
+ public void atomTest() {
+ retreiveMetadataTest(ODataPubFormat.ATOM, "application/atom+xml");
+ }
+
+ @Test
+ public void xmlTest() {
+ retreiveMetadataTest(ODataPubFormat.JSON, "application/xml");
+ }
+
+ @Test
+ public void fullMetadataTest() {
+ retreiveMetadataTest(ODataPubFormat.JSON_FULL_METADATA, "application/json");
+ }
+
+ @Test
+ public void noMetadataTest() {
+ retreiveMetadataTest(ODataPubFormat.JSON_NO_METADATA, "application/json");
+ }
+
+ @Test
+ public void nullAcceptTest() {
+ retreiveMetadataTest(ODataPubFormat.JSON_NO_METADATA, null);
+ }
+
+ @Test
+ public void nullFormatTest() {
+ retreiveMetadataTest(null, "application/json");
+ }
+
+ @Test
+ public void atomWithNoAcceptTest() {
+ retreiveMetadataTest(ODataPubFormat.ATOM, null);
+ }
+
+ @Test
+ public void noFormatTest() {
+ retreiveMetadataTest(null, "application/xml");
+ }
+
+ @Test
+ public void large() {
+ final EdmV3Metadata metadata = client.getRetrieveRequestFactory().
+ getMetadataRequest(testLargeModelServiceRootURL).execute().getBody();
+ assertNotNull(metadata);
+
+ assertEquals(400, metadata.getSchemas().get(0).getEntityContainers().get(0).getEntitySets().size());
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/NavigationLinkTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/NavigationLinkTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/NavigationLinkTestITCase.java
new file mode 100644
index 0000000..99f786a
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/NavigationLinkTestITCase.java
@@ -0,0 +1,137 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import com.msopentech.odatajclient.engine.communication.ODataClientErrorException;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataEntityRequest;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataEntitySetRequest;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.data.ODataEntity;
+import com.msopentech.odatajclient.engine.data.ODataEntitySet;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+
+public class NavigationLinkTestITCase extends AbstractTestITCase {
+ //collection of navigation links
+
+ private void getListNavigationLinks(String acceptFormat) {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Customer").appendKeySegment(-10).appendLinksSegment("Orders");
+ ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setAccept(acceptFormat);
+ ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ List<ODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ for (int i = 0; i < entity.size(); i++) {
+ assertNotNull(entity.get(i).getProperties().get(0).getValue());
+ }
+ }
+ //invalid query
+
+ private void getListNavigationLinksInvalidSegment(String acceptFormat) {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Customer").appendKeySegment(-10).appendLinksSegment("Address");
+ ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setAccept(acceptFormat);
+ ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(415, res.getStatusCode());
+ }
+ //Reference navigation link
+
+ private void getSingleNavigationLinks(String acceptFormat) {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Customer").appendKeySegment(-10).appendLinksSegment("Orders").
+ appendKeySegment(-10);
+ ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setAccept(acceptFormat);
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntity entity = res.getBody();
+ assertNotNull(entity.getProperties().get(0).getValue());
+ }
+ // reference navigation link
+
+ private void getReferenceNavigationLinks(String acceptFormat) {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Customer").appendKeySegment(-10).appendLinksSegment("Logins").
+ appendKeySegment(-1);
+ ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(uriBuilder.build());
+ req.setAccept(acceptFormat);
+ try {
+ ODataRetrieveResponse<ODataEntity> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntity entity = res.getBody();
+ assertNotNull(entity);
+ assertNotNull(entity.getProperties().get(0).getValue());
+ } catch (ODataClientErrorException e) {
+ if (e.getStatusLine().getStatusCode() == 415) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
+ }
+ if (e.getStatusLine().getStatusCode() == 404) {
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ }
+ }
+ }
+ // json header test
+
+ @Test
+ public void withJSON() {
+ getListNavigationLinks("application/json");
+ getSingleNavigationLinks("application/json");
+ }
+ // atom header test
+
+ @Test(expected = ODataClientErrorException.class)
+ public void withATOM() {
+ getListNavigationLinks("application/atom+xml");
+ getSingleNavigationLinks("application/atom+xml");
+ getReferenceNavigationLinks("application/atom+xml");
+ }
+ // unable to deserialize. xml is an invalid accept header for collection reference link
+
+ @Test(expected = IllegalArgumentException.class)
+ public void withXML() {
+ getListNavigationLinks("application/xml");
+ getSingleNavigationLinks("application/xml");
+ getReferenceNavigationLinks("application/xml");
+ }
+ //with no accept header test
+
+ @Test
+ public void withNull() {
+ getListNavigationLinks(null);
+ getSingleNavigationLinks(null);
+ getReferenceNavigationLinks(null);
+ }
+ // with an invalid navigation segment which does not exists. 404 error is returned
+
+ @Test(expected = ODataClientErrorException.class)
+ public void withInvalidSegment() {
+ getListNavigationLinksInvalidSegment("application/json");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityCreateTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityCreateTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityCreateTestITCase.java
new file mode 100644
index 0000000..cbcb3e5
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityCreateTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibEntityCreateTestITCase extends EntityCreateTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityRetrieveTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityRetrieveTestITCase.java
new file mode 100644
index 0000000..af6f72c
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityRetrieveTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibEntityRetrieveTestITCase extends EntityRetrieveTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntitySetTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntitySetTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntitySetTestITCase.java
new file mode 100644
index 0000000..d340c3c
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntitySetTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibEntitySetTestITCase extends EntitySetTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityUpdateTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityUpdateTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityUpdateTestITCase.java
new file mode 100644
index 0000000..7184718
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibEntityUpdateTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibEntityUpdateTestITCase extends EntityUpdateTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibLinkTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibLinkTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibLinkTestITCase.java
new file mode 100644
index 0000000..8a15aef
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibLinkTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibLinkTestITCase extends LinkTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibPropertyTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibPropertyTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibPropertyTestITCase.java
new file mode 100644
index 0000000..8d2ade1
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/ODataLibPropertyTestITCase.java
@@ -0,0 +1,28 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+public class ODataLibPropertyTestITCase extends PropertyTestITCase {
+
+ @Override
+ protected String getServiceRoot() {
+ return testODataWriterDefaultServiceRootURL;
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/OpenTypeTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/OpenTypeTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/OpenTypeTestITCase.java
new file mode 100644
index 0000000..a3d846e
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/OpenTypeTestITCase.java
@@ -0,0 +1,241 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import com.msopentech.odatajclient.engine.communication.request.cud.ODataEntityCreateRequest;
+import com.msopentech.odatajclient.engine.communication.response.ODataDeleteResponse;
+import com.msopentech.odatajclient.engine.communication.response.ODataEntityCreateResponse;
+import com.msopentech.odatajclient.engine.data.ODataComplexValue;
+import com.msopentech.odatajclient.engine.data.ODataEntity;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+import com.msopentech.odatajclient.engine.metadata.EdmV3Metadata;
+import com.msopentech.odatajclient.engine.metadata.edm.EdmSimpleType;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Geospatial;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.GeospatialCollection;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.LineString;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiLineString;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPoint;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.MultiPolygon;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Point;
+import com.msopentech.odatajclient.engine.metadata.edm.geospatial.Polygon;
+import com.msopentech.odatajclient.engine.format.ODataPubFormat;
+import java.util.ArrayList;
+import java.util.Date;
+import java.util.List;
+import java.util.UUID;
+import org.junit.Test;
+
+public class OpenTypeTestITCase extends AbstractTestITCase {
+
+ @Test
+ public void checkOpenTypeEntityTypesExist() {
+ final EdmV3Metadata metadata = client.getRetrieveRequestFactory().
+ getMetadataRequest(testOpenTypeServiceRootURL).execute().getBody();
+
+ assertTrue(metadata.getSchemas().get(0).getEntityType("Row").isOpenType());
+ assertTrue(metadata.getSchemas().get(0).getEntityType("IndexedRow").isOpenType());
+ assertTrue(metadata.getSchemas().get(0).getEntityType("RowIndex").isOpenType());
+ }
+
+ private ODataEntity readRow(final ODataPubFormat format, final String uuid) {
+ final URIBuilder builder = client.getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntityTypeSegment("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(EdmSimpleType.Double.toString(), row.getProperty("Double").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.Guid.toString(), row.getProperty("Id").getPrimitiveValue().getTypeName());
+
+ row = readRow(format, "672b8250-1e6e-4785-80cf-b94b572e42b3");
+ assertEquals(EdmSimpleType.Decimal.toString(), row.getProperty("Decimal").getPrimitiveValue().getTypeName());
+ }
+
+ @Test
+ public void readAsAtom() {
+ read(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readAsJSON() {
+ read(ODataPubFormat.JSON_FULL_METADATA);
+ }
+
+ private void cud(final ODataPubFormat format) {
+ final UUID guid = UUID.randomUUID();
+
+ ODataEntity row = client.getObjectFactory().newEntity("Microsoft.Test.OData.Services.OpenTypesService.Row");
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("Id",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Guid).setValue(guid).build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aString",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.String).setValue("string").build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aBoolean",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Boolean).setValue(true).build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aLong",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Int64).setValue(15L).build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aDouble",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Double).setValue(1.5D).build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aByte",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.SByte).setValue(Byte.MAX_VALUE).build()));
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aDate",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.DateTime).
+ setValue(new Date()).build()));
+
+ final Point point = new Point(Geospatial.Dimension.GEOGRAPHY);
+ point.setX(1.2);
+ point.setY(2.1);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aPoint",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeographyPoint).
+ setValue(point).build()));
+ final List<Point> points = new ArrayList<Point>();
+ points.add(point);
+ points.add(point);
+ final MultiPoint multipoint = new MultiPoint(Geospatial.Dimension.GEOMETRY, points);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aMultiPoint",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeometryMultiPoint).
+ setValue(multipoint).build()));
+ final LineString lineString = new LineString(Geospatial.Dimension.GEOMETRY, points);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aLineString",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeometryLineString).
+ setValue(lineString).build()));
+ final List<LineString> lineStrings = new ArrayList<LineString>();
+ lineStrings.add(lineString);
+ lineStrings.add(lineString);
+ final MultiLineString multiLineString = new MultiLineString(Geospatial.Dimension.GEOGRAPHY, lineStrings);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aMultiLineString",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeometryMultiLineString).
+ setValue(multiLineString).build()));
+ final Point otherPoint = new Point(Geospatial.Dimension.GEOGRAPHY);
+ otherPoint.setX(3.4);
+ otherPoint.setY(4.3);
+ points.set(1, otherPoint);
+ points.add(otherPoint);
+ points.add(point);
+ final Polygon polygon =
+ new Polygon(Geospatial.Dimension.GEOGRAPHY, points, points);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aPolygon",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeographyPolygon).
+ setValue(polygon).build()));
+ final List<Polygon> polygons = new ArrayList<Polygon>();
+ polygons.add(polygon);
+ polygons.add(polygon);
+ final MultiPolygon multiPolygon = new MultiPolygon(Geospatial.Dimension.GEOGRAPHY, polygons);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aMultiPolygon",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeographyMultiPolygon).
+ setValue(multiPolygon).build()));
+ final List<Geospatial> geospatials = new ArrayList<Geospatial>();
+ geospatials.add(otherPoint);
+ geospatials.add(polygon);
+ geospatials.add(multiLineString);
+ geospatials.add(multiPolygon);
+ final GeospatialCollection geoColl = new GeospatialCollection(Geospatial.Dimension.GEOGRAPHY, geospatials);
+ row.addProperty(client.getObjectFactory().newPrimitiveProperty("aCollection",
+ client.getGeospatialValueBuilder().setType(EdmSimpleType.GeographyCollection).
+ setValue(geoColl).build()));
+
+ final ODataComplexValue contactDetails =
+ new ODataComplexValue("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails");
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("FirstContacted",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Binary).setValue("text".getBytes()).
+ build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("LastContacted",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.DateTimeOffset).
+ setText("2001-04-05T05:05:05.001+00:01").build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Contacted",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.DateTime).
+ setText("2001-04-05T05:05:04.001").build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("GUID",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Guid).
+ setValue(UUID.randomUUID()).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("PreferedContactTime",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Time).
+ setText("-P9DT51M10.5063807S").build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Byte",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Byte).setValue(Integer.valueOf(241)).
+ build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("SignedByte",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.SByte).setValue(Byte.MAX_VALUE).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Double",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Double).setValue(Double.MAX_VALUE).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Single",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Single).setValue(Float.MAX_VALUE).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Short",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Int16).setValue(Short.MAX_VALUE).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Int",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Int32).setValue(Integer.MAX_VALUE).build()));
+ contactDetails.add(client.getObjectFactory().newPrimitiveProperty("Long",
+ client.getPrimitiveValueBuilder().setType(EdmSimpleType.Int64).setValue(Long.MAX_VALUE).build()));
+ row.addProperty(client.getObjectFactory().newComplexProperty("aContact", contactDetails));
+
+ final ODataEntityCreateRequest createReq = client.getCUDRequestFactory().
+ getEntityCreateRequest(client.getURIBuilder(testOpenTypeServiceRootURL).
+ appendEntityTypeSegment("Row").build(), row);
+ createReq.setFormat(format);
+ final ODataEntityCreateResponse createRes = createReq.execute();
+ assertEquals(201, createRes.getStatusCode());
+
+ row = readRow(format, guid.toString());
+ assertNotNull(row);
+ assertEquals(EdmSimpleType.Guid.toString(), row.getProperty("Id").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.String.toString(), row.getProperty("aString").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.Boolean.toString(), row.getProperty("aBoolean").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.Int64.toString(), row.getProperty("aLong").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.Double.toString(), row.getProperty("aDouble").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.SByte.toString(), row.getProperty("aByte").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.DateTime.toString(), row.getProperty("aDate").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeographyPoint.toString(),
+ row.getProperty("aPoint").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeometryMultiPoint.toString(),
+ row.getProperty("aMultiPoint").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeometryLineString.toString(),
+ row.getProperty("aLineString").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeometryMultiLineString.toString(),
+ row.getProperty("aMultiLineString").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeographyPolygon.toString(),
+ row.getProperty("aPolygon").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeographyMultiPolygon.toString(),
+ row.getProperty("aMultiPolygon").getPrimitiveValue().getTypeName());
+ assertEquals(EdmSimpleType.GeographyCollection.toString(),
+ row.getProperty("aCollection").getPrimitiveValue().getTypeName());
+ assertEquals("Microsoft.Test.OData.Services.OpenTypesService.ContactDetails",
+ row.getProperty("aContact").getComplexValue().getTypeName());
+ assertEquals(EdmSimpleType.SByte.toString(),
+ row.getProperty("aContact").getComplexValue().get("SignedByte").getPrimitiveValue().getTypeName());
+
+ final ODataDeleteResponse deleteRes = client.getCUDRequestFactory().getDeleteRequest(row.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/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PrimitiveKeysTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PrimitiveKeysTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PrimitiveKeysTestITCase.java
new file mode 100644
index 0000000..f506e8f
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PrimitiveKeysTestITCase.java
@@ -0,0 +1,83 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataEntityRequest;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.RetrieveRequestFactory;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.data.ODataDuration;
+import com.msopentech.odatajclient.engine.data.ODataEntity;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+import com.msopentech.odatajclient.engine.format.ODataPubFormat;
+import java.math.BigDecimal;
+import java.util.UUID;
+import org.junit.Test;
+
+public class PrimitiveKeysTestITCase extends AbstractTestITCase {
+
+ private void readEntity(final String entityType, final Object key, final ODataPubFormat format) {
+ final ODataEntityRequest req = client.getRetrieveRequestFactory().getEntityRequest(
+ client.getURIBuilder(testPrimitiveKeysServiceRootURL).appendEntityTypeSegment(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) {
+ // commented as per #115
+ //readEntity("EdmBinarySet", new byte[] {Byte.valueOf("2"), Byte.valueOf("3"), Byte.valueOf("4")}, 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.40282347E+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);
+ readEntity("EdmTimeSet", new ODataDuration("-P10675199DT2H48M5.4775808S"), format);
+ // commented as per #115
+ //readEntity("EdmDateTimeSet",
+ // ODataTimestamp.parse(EdmSimpleType.DATE_TIME.pattern(), "0001-01-01T00:00:00"),
+ // format);
+ //readEntity("EdmDateTimeOffsetSet",
+ // ODataTimestamp.parse(EdmSimpleType.DATE_TIME_OFFSET.pattern(), "2013-08-14T13:33:46.1045905+02:00"),
+ // format);
+ }
+
+ @Test
+ public void readEntityAsAtom() {
+ readPrimitiveKeys(ODataPubFormat.ATOM);
+ }
+
+ @Test
+ public void readEntityAsJSON() {
+ readPrimitiveKeys(ODataPubFormat.JSON);
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/7baecb90/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PropertyRetrieveTestITCase.java
----------------------------------------------------------------------
diff --git a/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PropertyRetrieveTestITCase.java b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PropertyRetrieveTestITCase.java
new file mode 100644
index 0000000..5f1d62c
--- /dev/null
+++ b/ODataJClient/engine/src/test/java/com/msopentech/odatajclient/engine/it/PropertyRetrieveTestITCase.java
@@ -0,0 +1,314 @@
+/**
+ * Copyright © Microsoft Open Technologies, Inc.
+ *
+ * All Rights Reserved
+ *
+ * Licensed 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
+ *
+ * THIS CODE IS PROVIDED *AS IS* BASIS, WITHOUT WARRANTIES OR CONDITIONS
+ * OF ANY KIND, EITHER EXPRESS OR IMPLIED, INCLUDING WITHOUT LIMITATION
+ * ANY IMPLIED WARRANTIES OR CONDITIONS OF TITLE, FITNESS FOR A
+ * PARTICULAR PURPOSE, MERCHANTABILITY OR NON-INFRINGEMENT.
+ *
+ * See the Apache License, Version 2.0 for the specific language
+ * governing permissions and limitations under the License.
+ */
+package com.msopentech.odatajclient.engine.it;
+
+import static org.junit.Assert.*;
+
+import java.util.List;
+
+import org.junit.Test;
+
+import com.msopentech.odatajclient.engine.communication.ODataClientErrorException;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataEntitySetRequest;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.ODataPropertyRequest;
+import com.msopentech.odatajclient.engine.communication.request.retrieve.RetrieveRequestFactory;
+import com.msopentech.odatajclient.engine.communication.response.ODataRetrieveResponse;
+import com.msopentech.odatajclient.engine.data.ODataCollectionValue;
+import com.msopentech.odatajclient.engine.data.ODataComplexValue;
+import com.msopentech.odatajclient.engine.data.ODataEntity;
+import com.msopentech.odatajclient.engine.data.ODataEntitySet;
+import com.msopentech.odatajclient.engine.data.ODataPrimitiveValue;
+import com.msopentech.odatajclient.engine.data.ODataProperty;
+import com.msopentech.odatajclient.engine.uri.URIBuilder;
+import com.msopentech.odatajclient.engine.format.ODataFormat;
+
+public class PropertyRetrieveTestITCase extends AbstractTestITCase {
+ // retrieve property
+
+ private void retreivePropertyTest(final ODataFormat format, final String accept, String entitySegment,
+ String structuralSegment) {
+ final URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendEntityTypeSegment(entitySegment).appendStructuralSegment(structuralSegment);
+ final ODataPropertyRequest req = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build());
+ req.setFormat(format);
+ req.setAccept(accept);
+ try {
+ final ODataProperty property = client.getRetrieveRequestFactory().getPropertyRequest(uriBuilder.build()).
+ 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) {
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ } else if (e.getStatusLine().getStatusCode() == 400) {
+ assertEquals(400, e.getStatusLine().getStatusCode());
+ }
+ }
+ }
+ //test with json header
+
+ @Test
+ public void jsonRetrieveProperty() {
+ //Primitive types
+ retreivePropertyTest(ODataFormat.JSON, "application/json", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.JSON, "application/json", "Customer(-10)", "CustomerId");
+ retreivePropertyTest(ODataFormat.JSON, "application/json",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.JSON, "application/json",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retreivePropertyTest(ODataFormat.JSON, "application/json", "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retreivePropertyTest(ODataFormat.JSON, "application/json",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //complex types
+ retreivePropertyTest(ODataFormat.JSON, "application/json", "Order(-9)", "Concurrency");
+ }
+ //test with json full metadata
+
+ @Test
+ public void jsonFullMetadataRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata", "Customer(-10)",
+ "Name");
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata", "Customer(-10)",
+ "CustomerId");
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Order(-9)", "Concurrency");
+ }
+ // json with no metadata
+
+ @Test
+ public void jsonNoMetadataRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Customer(-10)", "CustomerId");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Customer(-10)", "BackupContactInfo");
+ //Collection of Primitives
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=nometadata",
+ "Order(-9)", "Concurrency");
+
+ }
+ // json with minimla metadata
+
+ @Test
+ public void jsonmininalRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal",
+ "Customer(-10)", "CustomerId");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of complex types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal", "Customer(-10)",
+ "BackupContactInfo");
+ //Collection of primitives
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retreivePropertyTest(ODataFormat.JSON_NO_METADATA, "application/json;odata=minimal",
+ "Order(-9)", "Concurrency");
+ }
+ // with xml header
+
+ @Test
+ public void xmlRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.XML, "application/xml", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.XML, "application/xml", "Customer(-10)", "CustomerId");
+ retreivePropertyTest(ODataFormat.XML, "application/xml",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.XML, "application/xml",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retreivePropertyTest(ODataFormat.XML, "application/xml", "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retreivePropertyTest(ODataFormat.XML, "application/xml",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //Complex types
+ retreivePropertyTest(ODataFormat.XML, "application/xml", "Order(-9)", "Concurrency");
+ }
+ // with atom header
+
+ @Test
+ public void atomRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml", "Customer(-10)", "Name");
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml", "Customer(-10)", "CustomerId");
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml",
+ "Message(FromUsername='1',MessageId=-10)", "Sent");
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml",
+ "Message(FromUsername='1',MessageId=-10)", "IsRead");
+ //Collection of Complex types
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml", "Customer(-10)", "BackupContactInfo");
+ //Collection of primitives
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml",
+ "Customer(-10)/PrimaryContactInfo", "EmailBag");
+ //complex types
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml",
+ "Order(-9)", "Concurrency");
+ }
+ // with invalid structural segment
+
+ @Test
+ public void invalidSegmentRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.XML, "application/atom+xml", "Customers(-10)", "Name");
+
+ }
+ // with null pub format
+
+ @Test
+ public void nullSegmentRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(null, "application/atom+xml", "Customers(-10)", "Name");
+
+ }
+ // with null accept header format
+
+ @Test
+ public void nullAcceptRetrieveProperty() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.XML, null, "Customers(-10)", "Name");
+
+ }
+ // with json pub format and atom accept format
+
+ @Test
+ public void differentFormatAndAcceptRetrieveProperty() {
+ //
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/atom+xml", "Customers(-10)", "Name");
+
+ }
+ //bad request 400 error. Message takes two keys
+
+ @Test
+ public void badRequestTest() {
+ //primitive types
+ retreivePropertyTest(ODataFormat.JSON_FULL_METADATA, "application/json;odata=fullmetadata",
+ "Message(FromUsername='1')", "Sent");
+ }
+ //navigation link of stream
+
+ @Test
+ public void navigationMediaLink() {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
+ ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/json");
+ ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ List<ODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testDefaultServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)",
+ entity.get(0).getProperties().get(0).getValue().toString());
+ assertEquals(testDefaultServiceRootURL + "/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() {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Product").appendKeySegment(-7).appendLinksSegment("Photo");
+ ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/json");
+ try {
+ ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ List<ODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testDefaultServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
+ getProperties().get(0).getValue().toString());
+ assertEquals(testDefaultServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
+ getProperties().get(0).getValue().toString());
+ } catch (ODataClientErrorException e) {
+ assertEquals(404, e.getStatusLine().getStatusCode());
+ }
+ }
+ //invalid accept format
+
+ @Test
+ public void navigationMediaLinkInvalidFormat() {
+ URIBuilder uriBuilder = client.getURIBuilder(testDefaultServiceRootURL).
+ appendNavigationLinkSegment("Product").appendKeySegment(-7).appendLinksSegment("Photos");
+ ODataEntitySetRequest req = client.getRetrieveRequestFactory().getEntitySetRequest(uriBuilder.build());
+ req.setAccept("application/atom+xml");
+ try {
+ ODataRetrieveResponse<ODataEntitySet> res = req.execute();
+ assertEquals(200, res.getStatusCode());
+ ODataEntitySet entitySet = res.getBody();
+ assertNotNull(entitySet);
+ List<ODataEntity> entity = entitySet.getEntities();
+ assertNotNull(entity);
+ assertEquals(entity.size(), 2);
+ assertEquals(testDefaultServiceRootURL + "/ProductPhoto(PhotoId=-3,ProductId=-3)", entity.get(0).
+ getProperties().get(0).getValue().toString());
+ assertEquals(testDefaultServiceRootURL + "/ProductPhoto(PhotoId=-2,ProductId=-2)", entity.get(1).
+ getProperties().get(0).getValue().toString());
+ } catch (ODataClientErrorException e) {
+ assertEquals(415, e.getStatusLine().getStatusCode());
+ }
+ }
+}