diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java index 9e1537d1b..aa77ced21 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java @@ -421,7 +421,7 @@ public class BatchClientITCase extends AbstractParamTecSvcITCase { assertEquals(1, oDataResponse.getHeader(HttpHeader.ODATA_VERSION).size()); assertEquals("4.0", oDataResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next()); assertEquals(1, oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).size()); - assertEquals(isJson() ? "517" : "2138", oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).iterator().next()); + assertEquals(isJson() ? "517" : "2114", oDataResponse.getHeader(HttpHeader.CONTENT_LENGTH).iterator().next()); assertContentType(oDataResponse.getContentType()); } diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java index bac2927bc..30c95d41e 100644 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/EntityReferencesITCase.java @@ -168,7 +168,7 @@ public class EntityReferencesITCase extends AbstractParamTecSvcITCase { @Test public void responseNonExistingEntity() { final URI uri = getClient().newURIBuilder(SERVICE_URI) - .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0) + .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(-32768) .appendNavigationSegment(NAV_PROPERTY_ET_TWO_PRIM_ONE).appendRefSegment().build(); try { diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java new file mode 100644 index 000000000..75967b64e --- /dev/null +++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedAndMixedTypeTestITCase.java @@ -0,0 +1,378 @@ +/* + * 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.tecsvc.http; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; + +import java.net.HttpURLConnection; +import java.net.URL; + +import org.apache.commons.io.IOUtils; +import org.apache.olingo.client.api.ODataClient; +import org.apache.olingo.commons.api.format.ContentType; +import org.apache.olingo.commons.api.http.HttpHeader; +import org.apache.olingo.commons.api.http.HttpMethod; +import org.apache.olingo.commons.api.http.HttpStatusCode; +import org.apache.olingo.fit.AbstractBaseTestITCase; +import org.apache.olingo.fit.tecsvc.TecSvcConst; +import org.junit.Test; + +public class DerivedAndMixedTypeTestITCase extends AbstractBaseTestITCase { + + private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/"; + + @Test + public void queryESCompCollDerivedJson() throws Exception { + URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + + assertTrue(content.contains( + "[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":" + + "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{\"@odata.type\":" + + "\"#olingo.odata.test1.CTBaseAno\",\"PropertyString\":\"Num111\",\"AdditionalPropString\":" + + "\"Test123\"},\"CollPropertyCompAno\":[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + + "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + + "{\"PropertyString\":\"TESTabcd\"}]}]}" )); + } + + @Test + public void queryESCompCollDerivedXml() throws Exception { + URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=xml"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.APPLICATION_XML, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("" + + "Num111" + + "Test123" + + "" + + "" + + "" + + "TEST12345" + + "Additional12345" )); + } + + @Test + public void queryESAllPrimDerivedJson() throws Exception { + URL url = new URL(SERVICE_URI + "ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=json"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\"," + + "\"PropertyInt16\":32766," + + "\"PropertyString\":\"Test String1\"," + + "\"AdditionalPropertyString_5\":\"Additional String1\"" )); + } + + @Test + public void queryESAllPrimDerivedXml() throws Exception { + URL url = new URL(SERVICE_URI + "ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=xml"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("term=\"#olingo.odata.test1.ETBase\"/>")); + assertTrue(content.contains( + "32766" + + "Test String1" + + "Additional String1")); + } + + @Test + public void queryESCompCollDerivedJsonNone() throws Exception { + URL url = new URL(SERVICE_URI + "ESCompCollDerived"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=none"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON_NO_METADATA, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + + assertTrue(content.contains( + "[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":" + + "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{"+ + "\"PropertyString\":\"Num111\",\"AdditionalPropString\":" + + "\"Test123\"},\"CollPropertyCompAno\":[{" + + "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + + "{\"PropertyString\":\"TESTabcd\"}]}]}" )); + } + @Test + public void queryESCompCollDerivedJsonFull() throws Exception { + URL url = new URL(SERVICE_URI + "ESCompCollDerived"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=full"); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON_FULL_METADATA, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + + assertTrue(content.contains("\"PropertyInt16\":32767,\"PropertyCompAno\":null," + + "\"CollPropertyCompAno@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\"," + + "\"CollPropertyCompAno\":[{\"@odata.type\":" + + "\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TEST9876\"}]}," + + "{\"@odata.type\":\"#olingo.odata.test1.ETDeriveCollComp\",\"@odata.id\":\"ESCompCollDerived(12345)\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":12345,\"PropertyCompAno\":" + + "{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + + "\"PropertyString\":\"Num111\",\"AdditionalPropString\":\"Test123\"}," + + "\"CollPropertyCompAno@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\",\"CollPropertyCompAno\":" + + "[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + + "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TESTabcd\"}]}]}" )); + } + + @Override + protected ODataClient getClient() { + return null; + } + + @Test + public void queryESMixPrimWithLambdaDerived_JsonFull_Olingo1122() throws Exception { + URL url = new URL(SERVICE_URI + "ESMixPrimCollComp?$filter=CollPropertyComp/any" + + "(f:f/olingo.odata.test1.CTBase/AdditionalPropString%20eq%20%27ADD%20TEST%27)"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=full"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON_FULL_METADATA, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"value\":" + + "[{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\"," + + "\"@odata.id\":\"ESMixPrimCollComp(32767)\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":32767," + + "\"CollPropertyString@odata.type\":\"#Collection(String)\"," + + "\"CollPropertyString\":" + + "[\"Employee1@company.example\",\"Employee2@company.example\"," + + "\"Employee3@company.example\"]," + + "\"PropertyComp\":" + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\"}," + + "\"CollPropertyComp@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\"," + + "\"CollPropertyComp\":" + + "[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":123," + + "\"PropertyString\":\"TEST 1\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":456," + + "\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":789," + + "\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]}," + + "{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\"," + + "\"@odata.id\":\"ESMixPrimCollComp(7)\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":7,\"CollPropertyString@odata.type\":\"#Collection(String)\"," + + "\"CollPropertyString\":[\"Employee1@company.example\"," + + "\"Employee2@company.example\"," + + "\"Employee3@company.example\"]," + + "\"PropertyComp\":{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"}," + + "\"CollPropertyComp@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\"," + + "\"CollPropertyComp\":[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\",\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]},{\"@odata.type\":\"#olingo.odata.test1.ETMixPrimCollComp\"," + + "\"@odata.id\":\"ESMixPrimCollComp(0)\",\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":0," + + "\"CollPropertyString@odata.type\":\"#Collection(String)\",\"CollPropertyString\":" + + "[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]," + + "\"PropertyComp\":{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\",\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":333,\"PropertyString\":\"TEST C\"}," + + "\"CollPropertyComp@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrim)\"," + + "\"CollPropertyComp\":" + + "[{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]}]")); + } + + @Test + public void queryESMixPrimWithLambdaDerived_JsonMinimal_Olingo1122() throws Exception { + URL url = new URL(SERVICE_URI + "ESMixPrimCollComp?$filter=CollPropertyComp/any" + + "(f:f/olingo.odata.test1.CTBase/AdditionalPropString%20eq%20%27ADD%20TEST%27)"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=minimal"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"value\":[{\"PropertyInt16\":32767," + + "\"CollPropertyString\":[\"Employee1@company.example\"," + + "\"Employee2@company.example\"," + + "\"Employee3@company.example\"]," + + "\"PropertyComp\":{\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}," + + "\"CollPropertyComp\":[" + + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]}," + + "{\"PropertyInt16\":7,\"CollPropertyString\":" + + "[\"Employee1@company.example\"," + + "\"Employee2@company.example\"," + + "\"Employee3@company.example\"]," + + "\"PropertyComp\":{\"PropertyInt16\":222,\"PropertyString\":\"TEST B\"}," + + "\"CollPropertyComp\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]}," + + "{\"PropertyInt16\":0,\"CollPropertyString\":[" + + "\"Employee1@company.example\"," + + "\"Employee2@company.example\"," + + "\"Employee3@company.example\"]," + + "\"PropertyComp\":{\"PropertyInt16\":333,\"PropertyString\":\"TEST C\"}," + + "\"CollPropertyComp\":[" + + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + + "\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"," + + "\"AdditionalPropString\":\"ADD TEST\"}]}]")); + } + + @Test + public void queryESTwoPrimWithEntityTypeCast() throws Exception { + URL url = new URL(SERVICE_URI + "ESTwoPrim(111)/olingo.odata.test1.ETBase"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=full"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON_FULL_METADATA, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\"," + + "\"@odata.id\":\"ESBase(111)\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\"," + + "\"AdditionalPropertyString_5\":\"TEST A 0815\"")); + } + + @Test + public void queryESTwoPrimWithEntityTypeCastInFilter() throws Exception { + URL url = new URL(SERVICE_URI + "ESTwoPrim?$filter=olingo.odata.test1.ETBase/" + + "AdditionalPropertyString_5%20eq%20%27TEST%20A%200815%27"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=full"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON_FULL_METADATA, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"value\":[{\"@odata.type\":\"#olingo.odata.test1.ETBase\"," + + "\"@odata.id\":\"ESBase(111)\"," + + "\"PropertyInt16@odata.type\":\"#Int16\"," + + "\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\"," + + "\"AdditionalPropertyString_5\":\"TEST A 0815\"}]")); + } + + @Test + public void queryESAllPrimWithEntityTypeCastInExpand() throws Exception { + URL url = new URL(SERVICE_URI + "ESAllPrim(0)?$expand=NavPropertyETTwoPrimOne/olingo.odata.test1.ETBase"); + + HttpURLConnection connection = (HttpURLConnection) url.openConnection(); + connection.setRequestMethod(HttpMethod.GET.name()); + connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=minimal"); + connection.connect(); + + assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); + assertEquals(ContentType.JSON, + ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); + + final String content = IOUtils.toString(connection.getInputStream()); + assertTrue(content.contains("\"PropertyInt16\":0," + + "\"PropertyString\":\"\"," + + "\"PropertyBoolean\":false," + + "\"PropertyByte\":0," + + "\"PropertySByte\":0," + + "\"PropertyInt32\":0," + + "\"PropertyInt64\":0," + + "\"PropertySingle\":0.0," + + "\"PropertyDouble\":0.0," + + "\"PropertyDecimal\":0," + + "\"PropertyBinary\":\"\"," + + "\"PropertyDate\":\"1970-01-01\"," + + "\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\"," + + "\"PropertyDuration\":\"PT0S\"," + + "\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789cccddd\"," + + "\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":{" + + "\"@odata.type\":\"#olingo.odata.test1.ETBase\"," + + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"," + + "\"AdditionalPropertyString_5\":\"TEST A 0815\"}")); + } +} diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java deleted file mode 100644 index e7d4a8033..000000000 --- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/DerivedTypeTestITCase.java +++ /dev/null @@ -1,176 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.fit.tecsvc.http; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; - -import java.net.HttpURLConnection; -import java.net.URL; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.client.api.ODataClient; -import org.apache.olingo.commons.api.format.ContentType; -import org.apache.olingo.commons.api.http.HttpHeader; -import org.apache.olingo.commons.api.http.HttpMethod; -import org.apache.olingo.commons.api.http.HttpStatusCode; -import org.apache.olingo.fit.AbstractBaseTestITCase; -import org.apache.olingo.fit.tecsvc.TecSvcConst; -import org.junit.Test; - -public class DerivedTypeTestITCase extends AbstractBaseTestITCase { - - private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/"; - - @Test - public void queryESCompCollDerivedJson() throws Exception { - URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=json"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - assertEquals(ContentType.JSON, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); - - final String content = IOUtils.toString(connection.getInputStream()); - - assertTrue(content.contains( - "[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":" + - "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{\"@odata.type\":" + - "\"#olingo.odata.test1.CTBaseAno\",\"PropertyString\":\"Num111\",\"AdditionalPropString\":" + - "\"Test123\"},\"CollPropertyCompAno\":[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + - "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + - "{\"PropertyString\":\"TESTabcd\"}]}]}" )); - } - - @Test - public void queryESCompCollDerivedXml() throws Exception { - URL url = new URL(SERVICE_URI + "ESCompCollDerived?$format=xml"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - assertEquals(ContentType.APPLICATION_XML, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); - - final String content = IOUtils.toString(connection.getInputStream()); - assertTrue(content.contains("" + - "Num111" + - "Test123" + - "" + - "" + - "" + - "TEST12345" + - "Additional12345" )); - } - - @Test - public void queryESAllPrimDerivedJson() throws Exception { - URL url = new URL(SERVICE_URI + "ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=json"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - - final String content = IOUtils.toString(connection.getInputStream()); - assertTrue(content.contains("\"@odata.type\":\"#olingo.odata.test1.ETBase\"," + - "\"PropertyInt16\":32766," + - "\"PropertyString\":\"Test String1\"," + - "\"AdditionalPropertyString_5\":\"Additional String1\"" )); - } - - @Test - public void queryESAllPrimDerivedXml() throws Exception { - URL url = new URL(SERVICE_URI + "ESAllPrimDerived(0)?$expand=NavPropertyETTwoPrimMany&$format=xml"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - - final String content = IOUtils.toString(connection.getInputStream()); - assertTrue(content.contains("term=\"#olingo.odata.test1.ETBase\"/>")); - assertTrue(content.contains( - "32766" + - "Test String1" + - "Additional String1")); - } - - @Test - public void queryESCompCollDerivedJsonNone() throws Exception { - URL url = new URL(SERVICE_URI + "ESCompCollDerived"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=none"); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - assertEquals(ContentType.JSON_NO_METADATA, ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); - - final String content = IOUtils.toString(connection.getInputStream()); - - assertTrue(content.contains( - "[{\"PropertyInt16\":32767,\"PropertyCompAno\":null,\"CollPropertyCompAno\":[{\"PropertyString\":" + - "\"TEST9876\"}]},{\"PropertyInt16\":12345,\"PropertyCompAno\":{"+ - "\"PropertyString\":\"Num111\",\"AdditionalPropString\":" + - "\"Test123\"},\"CollPropertyCompAno\":[{" + - "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + - "{\"PropertyString\":\"TESTabcd\"}]}]}" )); - } - @Test - public void queryESCompCollDerivedJsonFull() throws Exception { - URL url = new URL(SERVICE_URI + "ESCompCollDerived"); - - HttpURLConnection connection = (HttpURLConnection) url.openConnection(); - connection.setRequestProperty(HttpHeader.ACCEPT, "application/json;odata.metadata=full"); - connection.setRequestMethod(HttpMethod.GET.name()); - connection.connect(); - - assertEquals(HttpStatusCode.OK.getStatusCode(), connection.getResponseCode()); - assertEquals(ContentType.JSON_FULL_METADATA, - ContentType.create(connection.getHeaderField(HttpHeader.CONTENT_TYPE))); - - final String content = IOUtils.toString(connection.getInputStream()); - - assertTrue(content.contains("\"PropertyInt16\":32767,\"PropertyCompAno\":null," + - "\"CollPropertyCompAno@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\"," + - "\"CollPropertyCompAno\":[{\"@odata.type\":" + - "\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TEST9876\"}]}," + - "{\"@odata.type\":\"#olingo.odata.test1.ETDeriveCollComp\",\"@odata.id\":\"ESCompCollDerived(12345)\"," + - "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":12345,\"PropertyCompAno\":" + - "{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + - "\"PropertyString\":\"Num111\",\"AdditionalPropString\":\"Test123\"}," + - "\"CollPropertyCompAno@odata.type\":\"#Collection(olingo.odata.test1.CTTwoPrimAno)\",\"CollPropertyCompAno\":" + - "[{\"@odata.type\":\"#olingo.odata.test1.CTBaseAno\"," + - "\"PropertyString\":\"TEST12345\",\"AdditionalPropString\":\"Additional12345\"}," + - "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrimAno\",\"PropertyString\":\"TESTabcd\"}]}]}" )); - } - - @Override - protected ODataClient getClient() { - return null; - } - -} diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java index 29ef5cb86..ff61fc874 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/ExpressionParser.java @@ -753,7 +753,7 @@ public class ExpressionParser { throws UriParserException, UriValidationException { if (lastTokenKind == TokenKind.QualifiedName) { - // Type cast or bound function + // Type cast to an entity type or complex type or bound function final FullQualifiedName fullQualifiedName = new FullQualifiedName(tokenizer.getText()); final EdmEntityType edmEntityType = edm.getEntityType(fullQualifiedName); @@ -761,6 +761,26 @@ public class ExpressionParser { if (allowTypeFilter) { setTypeFilter(lastResource, edmEntityType); + if (tokenizer.next(TokenKind.SLASH)) { + if (tokenizer.next(TokenKind.QualifiedName)) { + parseBoundFunction(fullQualifiedName, uriInfo, lastResource); + } else if (tokenizer.next(TokenKind.ODataIdentifier)) { + parsePropertyPathExpr(uriInfo, lastResource); + } else { + throw new UriParserSyntaxException("Expected OData Identifier or Full Qualified Name.", + UriParserSyntaxException.MessageKeys.SYNTAX); + } + } + } else { + throw new UriParserSemanticException("Type filters are not chainable.", + UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE, + lastResource.getType().getFullQualifiedName().getFullQualifiedNameAsString(), + fullQualifiedName.getFullQualifiedNameAsString()); + } + } else if (edm.getComplexType(fullQualifiedName) != null) { + if (allowTypeFilter) { + setTypeFilter(lastResource, edm.getComplexType(fullQualifiedName)); + if (tokenizer.next(TokenKind.SLASH)) { if (tokenizer.next(TokenKind.QualifiedName)) { parseBoundFunction(fullQualifiedName, uriInfo, lastResource); diff --git a/lib/server-tecsvc/pom.xml b/lib/server-tecsvc/pom.xml index add7dfa00..3202779bd 100644 --- a/lib/server-tecsvc/pom.xml +++ b/lib/server-tecsvc/pom.xml @@ -132,7 +132,7 @@ org.apache.olingo odata-server-core ${project.version} - runtime + diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java index e3d932f5e..0b8ec36aa 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java @@ -1371,19 +1371,29 @@ public class DataCreator { return entityCollection; } - @SuppressWarnings("unchecked") private Property createCollPropertyComp() { - return createComplexCollection("CollPropertyComp", + return createComplexDerievedCollection("CollPropertyComp", ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), - Arrays.asList( - createPrimitive("PropertyInt16", (short) 123), - createPrimitive("PropertyString", "TEST 1")), - Arrays.asList( - createPrimitive("PropertyInt16", (short) 456), - createPrimitive("PropertyString", "TEST 2")), - Arrays.asList( - createPrimitive("PropertyInt16", (short) 789), - createPrimitive("PropertyString", "TEST 3"))); + Arrays.asList(new ComplexValue[] { + createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), + Arrays.asList(new Property[] { + createPrimitive("PropertyInt16", (short) 123), + createPrimitive("PropertyString", "TEST 1") + } + )), + createComplexValue(ComplexTypeProvider.nameCTTwoPrim.getFullQualifiedNameAsString(), + Arrays.asList(new Property[] { + createPrimitive("PropertyInt16", (short) 456), + createPrimitive("PropertyString", "TEST 2") + } + )), + createComplexValue(ComplexTypeProvider.nameCTBase.getFullQualifiedNameAsString(), + Arrays.asList(new Property[] { + createPrimitive("PropertyInt16", (short) 789), + createPrimitive("PropertyString", "TEST 3"), + createPrimitive("AdditionalPropString", "ADD TEST") + } + ))})); } private EntityCollection createESAllKey(final Edm edm, final OData odata) { @@ -1526,6 +1536,7 @@ public class DataCreator { private void linkESAllPrim(final Map data) { final EntityCollection entityCollection = data.get("ESAllPrim"); final List targetEntities = data.get("ESTwoPrim").getEntities(); + final List targetESBaseEntities = data.get("ESBase").getEntities(); setLinks(entityCollection.getEntities().get(0), "NavPropertyETTwoPrimMany", targetEntities.get(1)); setLink(entityCollection.getEntities().get(0), "NavPropertyETTwoPrimOne", targetEntities.get(3)); @@ -1533,6 +1544,8 @@ public class DataCreator { setLinks(entityCollection.getEntities().get(2), "NavPropertyETTwoPrimMany", targetEntities.get(0), targetEntities.get(2), targetEntities.get(3)); + + setLink(entityCollection.getEntities().get(2), "NavPropertyETTwoPrimOne", targetESBaseEntities.get(0)); } private void linkESAllPrimDerived(final Map data) { 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 2a6f072ce..03d02dd68 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 @@ -46,6 +46,8 @@ import org.apache.olingo.server.api.uri.UriResourceEntitySet; import org.apache.olingo.server.api.uri.UriResourceFunction; import org.apache.olingo.server.api.uri.UriResourceNavigation; import org.apache.olingo.server.api.uri.UriResourceSingleton; +import org.apache.olingo.server.api.uri.queryoption.expression.Binary; +import org.apache.olingo.server.api.uri.queryoption.expression.Member; import org.apache.olingo.server.tecsvc.data.DataProvider; /** @@ -241,6 +243,24 @@ public abstract class TechnicalProcessor implements Processor { return dataProvider.readFunctionEntityCollection(uriResource.getFunction(), uriResource.getParameters(), uriInfo); } else { + if (uriInfo.getFilterOption() != null) { + if (uriInfo.getFilterOption().getExpression() instanceof Binary) { + Binary expression = (Binary) uriInfo.getFilterOption().getExpression(); + if (expression.getLeftOperand() instanceof Member) { + Member member = (Member) expression.getLeftOperand(); + if (member.getStartTypeFilter() != null) { + EdmEntityType entityType = (EdmEntityType) member.getStartTypeFilter(); + EdmEntityContainer container = this.serviceMetadata.getEdm().getEntityContainer(); + List entitySets = container.getEntitySets(); + for (EdmEntitySet entitySet : entitySets) { + if (entityType.getName().equals(entitySet.getEntityType().getName())) { + return dataProvider.readAll(entitySet); + } + } + } + } + } + } EdmEntitySet entitySet = getEntitySetBasedOnTypeCast(((UriResourceEntitySet)resourcePaths.get(0))); return dataProvider.readAll(entitySet); } diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java index 475925c2c..d02b892b4 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/processor/queryoptions/expression/ExpressionVisitorImpl.java @@ -18,15 +18,19 @@ */ package org.apache.olingo.server.tecsvc.processor.queryoptions.expression; +import java.util.Iterator; import java.util.List; import java.util.Locale; +import org.apache.olingo.commons.api.data.ComplexValue; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.edm.Edm; +import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmEnumType; import org.apache.olingo.commons.api.edm.EdmFunction; import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException; +import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; import org.apache.olingo.commons.api.edm.EdmProperty; import org.apache.olingo.commons.api.edm.EdmType; import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; @@ -37,7 +41,10 @@ import org.apache.olingo.server.api.uri.UriInfoResource; import org.apache.olingo.server.api.uri.UriParameter; import org.apache.olingo.server.api.uri.UriResource; import org.apache.olingo.server.api.uri.UriResourceFunction; +import org.apache.olingo.server.api.uri.UriResourceLambdaAny; +import org.apache.olingo.server.api.uri.UriResourceLambdaVariable; import org.apache.olingo.server.api.uri.UriResourceProperty; +import org.apache.olingo.server.api.uri.queryoption.expression.Binary; import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; import org.apache.olingo.server.api.uri.queryoption.expression.Expression; import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; @@ -46,6 +53,7 @@ import org.apache.olingo.server.api.uri.queryoption.expression.Literal; import org.apache.olingo.server.api.uri.queryoption.expression.Member; import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind; +import org.apache.olingo.server.core.uri.UriResourceLambdaVarImpl; import org.apache.olingo.server.tecsvc.data.DataProvider; import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.TypedOperand; import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operand.UntypedOperand; @@ -56,9 +64,10 @@ import org.apache.olingo.server.tecsvc.processor.queryoptions.expression.operati public class ExpressionVisitorImpl implements ExpressionVisitor { - private final Entity entity; + private Entity entity; private final UriInfoResource uriInfo; private final Edm edm; + private ComplexValue complexValue; public ExpressionVisitorImpl(final Entity entity, final UriInfoResource uriInfo, final Edm edm) { this.entity = entity; @@ -66,6 +75,12 @@ public class ExpressionVisitorImpl implements ExpressionVisitor this.edm = edm; } + public ExpressionVisitorImpl(final ComplexValue complexValue, final UriInfoResource uriInfo, final Edm edm) { + this.complexValue = complexValue; + this.uriInfo = uriInfo; + this.edm = edm; + } + @Override public VisitorOperand visitBinaryOperator(final BinaryOperatorKind operator, final VisitorOperand left, final VisitorOperand right) throws ExpressionVisitException, ODataApplicationException { @@ -184,6 +199,7 @@ public class ExpressionVisitorImpl implements ExpressionVisitor return new UntypedOperand(literal.getText()); } + @SuppressWarnings("unchecked") @Override public VisitorOperand visitMember(final Member member) throws ExpressionVisitException, ODataApplicationException { @@ -197,18 +213,39 @@ public class ExpressionVisitorImpl implements ExpressionVisitor Property currentProperty = entity.getProperty(currentEdmProperty.getName()); for (int i = 1; i < uriResourceParts.size(); i++) { if (currentProperty.isComplex()) { - currentEdmProperty = ((UriResourceProperty) uriResourceParts.get(i)).getProperty(); - final List complex = currentProperty.asComplex().getValue(); - for (final Property innerProperty : complex) { - if (innerProperty.getName().equals(currentEdmProperty.getName())) { - currentProperty = innerProperty; - break; + if (uriResourceParts.get(i) instanceof UriResourceLambdaAny) { + UriResourceLambdaAny any = ((UriResourceLambdaAny) uriResourceParts.get(i)); + if (any.getExpression() instanceof Binary) { + Binary expression = (Binary) any.getExpression(); + if (currentProperty.isCollection()) { + final List complex = (List) currentProperty.asCollection(); + Iterator itr = complex.iterator(); + while (itr.hasNext()) { + final ComplexValue value = itr.next(); + VisitorOperand operand = expression.accept(new ExpressionVisitorImpl(value, uriInfo, edm)); + final TypedOperand typedOperand = operand.asTypedOperand(); + if (typedOperand.is(OData.newInstance().createPrimitiveTypeInstance + (EdmPrimitiveTypeKind.Boolean))) { + if (Boolean.TRUE.equals(typedOperand.getTypedValue(Boolean.class))) { + return operand; + } + } + } + } + } + } else { + currentEdmProperty = ((UriResourceProperty) uriResourceParts.get(i)).getProperty(); + final List complex = currentProperty.asComplex().getValue(); + for (final Property innerProperty : complex) { + if (innerProperty.getName().equals(currentEdmProperty.getName())) { + currentProperty = innerProperty; + break; + } } } } } return new TypedOperand(currentProperty.getValue(), currentEdmProperty.getType(), currentEdmProperty); - } else if (initialPart instanceof UriResourceFunction) { final EdmFunction function = ((UriResourceFunction) initialPart).getFunction(); if (uriResourceParts.size() > 1) { @@ -225,6 +262,20 @@ public class ExpressionVisitorImpl implements ExpressionVisitor dataProvider.readFunctionPrimitiveComplex(function, parameters, uriInfo), type); + } else if (initialPart instanceof UriResourceLambdaVariable) { + EdmComplexType complexType = (EdmComplexType) ((UriResourceLambdaVarImpl)initialPart).getTypeFilter(); + EdmProperty currentEdmProperty = ((UriResourceProperty) uriResourceParts.get(1)).getProperty(); + Property currentProperty = null; + List properties = complexValue.getValue(); + for (final Property innerProperty : properties) { + if (innerProperty.getName().equals(currentEdmProperty.getName()) && + complexType.getProperty(innerProperty.getName()) != null) { + currentProperty = innerProperty; + break; + } + } + return new TypedOperand(currentProperty == null ? null : currentProperty.getValue(), + currentEdmProperty.getType(), currentEdmProperty); } else { return throwNotImplemented(); } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java index 90cd5939a..ef7880e99 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java @@ -626,7 +626,8 @@ public class ODataJsonSerializerTest { + "\"CollPropertyComp\":[" + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," - + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}"; + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\",\"PropertyInt16\":789," + + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD TEST\"}]}"; Assert.assertEquals(expectedResult, resultString); } @@ -1574,7 +1575,9 @@ public class ODataJsonSerializerTest { + "\"NavPropertyETAllPrimMany\":[" + "{\"@odata.id\":\"ESAllPrim(-32768)\",\"PropertyInt32\":-2147483648," + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}," - + "{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":null," + + "{\"@odata.id\":\"ESAllPrim(0)\",\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":{" + + "\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST A 0815\"}," + "\"NavPropertyETTwoPrimMany\":[" + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," @@ -1621,7 +1624,9 @@ public class ODataJsonSerializerTest { + "\"PropertyDouble\":0.0,\"PropertyDecimal\":0,\"PropertyBinary\":\"\"," + "\"PropertyDate\":\"1970-01-01\",\"PropertyDateTimeOffset\":\"2005-12-03T00:00:00Z\"," + "\"PropertyDuration\":\"PT0S\",\"PropertyGuid\":\"76543201-23ab-cdef-0123-456789cccddd\"," - + "\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":null," + + "\"PropertyTimeOfDay\":\"00:01:01\",\"NavPropertyETTwoPrimOne\":{" + + "\"@odata.type\":\"#olingo.odata.test1.ETBase\",\"PropertyInt16\":111," + + "\"PropertyString\":\"TEST A\",\"AdditionalPropertyString_5\":\"TEST A 0815\"}," + "\"NavPropertyETTwoPrimMany\":[" + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," @@ -1811,7 +1816,8 @@ public class ODataJsonSerializerTest { + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\"," + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," - + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}", + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\",\"PropertyInt16\":789," + + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD TEST\"}]}", resultString); } @@ -1824,7 +1830,7 @@ public class ODataJsonSerializerTest { .complexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, null).getContent()); Assert.assertEquals("{\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," - + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}", + + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD TEST\"}]}", resultString); } @@ -1850,9 +1856,9 @@ public class ODataJsonSerializerTest { + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":456," + "\"PropertyString\":\"TEST 2\"}," - + "{\"@odata.type\":\"#olingo.odata.test1.CTTwoPrim\"," + + "{\"@odata.type\":\"#olingo.odata.test1.CTBase\"," + "\"PropertyInt16@odata.type\":\"#Int16\",\"PropertyInt16\":789," - + "\"PropertyString\":\"TEST 3\"}]}"; + + "\"PropertyString\":\"TEST 3\",\"AdditionalPropString\":\"ADD TEST\"}]}"; Assert.assertEquals(expectedResult, resultString); } diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java index 166f4027b..9097d728b 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java @@ -288,8 +288,8 @@ public class ODataXmlSerializerTest { " \n" + " \n" + " \n" + + + "type=\"application/atom+xml;type=entry\" title=\"NavPropertyETTwoPrimOne\" " + + "href=\"ESBase(111)\" />\n" + " \n" + @@ -670,9 +670,10 @@ public class ODataXmlSerializerTest { " 456\n" + " TEST 2\n" + " \n" + - " \n" + + " \n" + " 789\n" + " TEST 3\n" + + " ADD TEST\n" + " \n" + " \n" + " \n" + @@ -2321,15 +2322,42 @@ public class ODataXmlSerializerTest { " \n" + " \n" + - " \n" + + " type=\"application/atom+xml;type=entry\" title=\"NavPropertyETTwoPrimOne\"\n" + + " href=\"ESBase(111)\">\n" + + " \n "+ + " \n "+ + " ESBase(111)\n "+ + " \n "+ + " \n "+ + " " + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + + "" + + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ + " 111\n "+ + " TEST A\n "+ + " TEST A 0815\n "+ + " \n "+ + " \n "+ + " \n "+ + " \n "+ " " + " \n" + - " \n" + + " \n "+ " \n" + " \n" + " ESTwoPrim(32766)\n" + @@ -2630,9 +2658,10 @@ public class ODataXmlSerializerTest { " 456\n" + " TEST 2\n" + " \n" + - " \n" + + " \n" + " 789\n" + " TEST 3\n" + + " ADD TEST\n" + " \n" + ""; checkXMLEqual(expected, resultString);