Repository: olingo-odata4 Updated Branches: refs/heads/master 266c7b4ae -> 5cdf64db2
OLINGO-317] Fixed context url in TechnicalScenario Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/5cdf64db Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5cdf64db Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5cdf64db Branch: refs/heads/master Commit: 5cdf64db23d9093bd7c5b46ccc2952e79d9ca1e0 Parents: 266c7b4 Author: Michael Bolz <[email protected]> Authored: Fri Aug 8 06:33:31 2014 +0200 Committer: Michael Bolz <[email protected]> Committed: Fri Aug 8 06:33:31 2014 +0200 ---------------------------------------------------------------------- .../olingo/fit/tecsvc/client/BasicITCase.java | 41 ++++++++++++++++++++ .../tecsvc/processor/TechnicalProcessor.java | 9 +++-- 2 files changed, 46 insertions(+), 4 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cdf64db/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java ---------------------------------------------------------------------- diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java index 1cb234c..51be0c8 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java @@ -25,12 +25,14 @@ import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNull; import static org.junit.Assert.assertThat; +import java.io.IOException; import java.net.URI; import java.util.Collections; import java.util.List; import org.apache.olingo.client.api.CommonODataClient; import org.apache.olingo.client.api.communication.request.retrieve.EdmMetadataRequest; +import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest; import org.apache.olingo.client.api.communication.request.retrieve.ODataServiceDocumentRequest; import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse; @@ -47,6 +49,7 @@ import org.apache.olingo.commons.api.format.ContentType; import org.apache.olingo.commons.api.format.ODataFormat; import org.apache.olingo.fit.AbstractBaseTestITCase; import org.apache.olingo.commons.api.http.HttpStatusCode; +import org.apache.olingo.fit.server.StringHelper; import org.apache.olingo.fit.tecsvc.TecSvcConst; import org.junit.Before; import org.junit.Test; @@ -126,6 +129,44 @@ public class BasicITCase extends AbstractBaseTestITCase { assertEquals(0, property.getPrimitiveValue().toValue()); } + @Test + public void readEntityRawResult() throws IOException { + final ODataEntityRequest<ODataEntity> request = odata.getRetrieveRequestFactory() + .getEntityRequest(URI.create(SERVICE_URI + "/ESCollAllPrim(1)")); + assertNotNull(request); + + final ODataRetrieveResponse<ODataEntity> response = request.execute(); + assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode()); + assertThat(response.getContentType(), containsString(ContentType.APPLICATION_JSON.toContentTypeString())); + + // + final String expectedResult = "{" + + "\"@odata.context\":\"$metadata#ESCollAllPrim/$entity\"," + + "\"PropertyInt16\":1," + + "\"CollPropertyString\":" + + "[\"[email protected]\",\"[email protected]\",\"[email protected]\"]," + + "\"CollPropertyBoolean\":[true,false,true]," + + "\"CollPropertyByte\":[50,200,249]," + + "\"CollPropertySByte\":[-120,120,126]," + + "\"CollPropertyInt16\":[1000,2000,30112]," + + "\"CollPropertyInt32\":[23232323,11223355,10000001]," + + "\"CollPropertyInt64\":[929292929292,333333333333,444444444444]," + + "\"CollPropertySingle\":[1790.0,26600.0,3210.0]," + + "\"CollPropertyDouble\":[-17900.0,-2.78E7,3210.0]," + + "\"CollPropertyDecimal\":[12,-2,1234]," + + "\"CollPropertyBinary\":[\"q83v\",\"ASNF\",\"VGeJ\"]," + + "\"CollPropertyDate\":[\"1958-12-03\",\"1999-08-05\",\"2013-06-25\"]," + + "\"CollPropertyDateTimeOffset\":[\"2015-08-12T03:08:34Z\",\"1970-03-28T12:11:10Z\"," + + "\"1948-02-17T09:09:09Z\"]," + + "\"CollPropertyDuration\":[\"PT13S\",\"PT5H28M0S\",\"PT1H0S\"]," + + "\"CollPropertyGuid\":[\"ffffff67-89ab-cdef-0123-456789aaaaaa\",\"eeeeee67-89ab-cdef-0123-456789bbbbbb\"," + + "\"cccccc67-89ab-cdef-0123-456789cccccc\"]," + + "\"CollPropertyTimeOfDay\":[\"04:14:13\",\"23:59:59\",\"01:12:33\"]" + + "}"; + StringHelper.Stream s = StringHelper.toStream(response.getRawResponse()); + assertEquals(expectedResult, s.asString()); + } + @Override protected CommonODataClient getClient() { return null; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5cdf64db/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java index 3ea7b1e..3e4dde4 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/TechnicalProcessor.java @@ -21,6 +21,7 @@ package org.apache.olingo.server.tecsvc.processor; import org.apache.olingo.commons.api.data.ContextURL; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.EntitySet; +import org.apache.olingo.commons.api.data.ContextURL.Suffix; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmEntitySet; import org.apache.olingo.commons.api.format.ContentType; @@ -72,7 +73,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode()); } else { ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType)); - response.setContent(serializer.entitySet(edmEntitySet, entitySet, getContextUrl(edmEntitySet))); + response.setContent(serializer.entitySet(edmEntitySet, entitySet, getContextUrl(edmEntitySet, false))); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); } @@ -97,7 +98,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc response.setStatusCode(HttpStatusCode.NOT_FOUND.getStatusCode()); } else { ODataSerializer serializer = odata.createSerializer(ODataFormat.fromContentType(requestedContentType)); - response.setContent(serializer.entity(edmEntitySet, entity, getContextUrl(edmEntitySet))); + response.setContent(serializer.entity(edmEntitySet, entity, getContextUrl(edmEntitySet, true))); response.setStatusCode(HttpStatusCode.OK.getStatusCode()); response.setHeader(HttpHeader.CONTENT_TYPE, requestedContentType.toContentTypeString()); } @@ -153,7 +154,7 @@ public class TechnicalProcessor implements EntityCollectionProcessor, EntityProc return uriResource.getEntitySet(); } - private ContextURL getContextUrl(final EdmEntitySet entitySet) { - return ContextURL.Builder.create().entitySet(entitySet).build(); + private ContextURL getContextUrl(final EdmEntitySet entitySet, final boolean isSingleEntity) { + return ContextURL.Builder.create().entitySet(entitySet).suffix(isSingleEntity ? Suffix.ENTITY : null).build(); } }
