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:53 UTC
[09/11] [OLINGO-236] Refactor complete
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);
+ }
+}