[OLINGO-1122]Addressing derived types in filter and expand

This commit is contained in:
ramya vasanth 2017-07-25 09:43:57 +05:30
parent ecf7f56ec8
commit f6dd0deacc
11 changed files with 555 additions and 214 deletions

View File

@ -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());
}

View File

@ -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 {

View File

@ -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("<d:PropertyCompAno m:type=\"#olingo.odata.test1.CTBaseAno\">" +
"<d:PropertyString>Num111</d:PropertyString>" +
"<d:AdditionalPropString>Test123</d:AdditionalPropString>" +
"</d:PropertyCompAno>" +
"<d:CollPropertyCompAno m:type=\"#Collection(olingo.odata.test1.CTTwoPrimAno)\">" +
"<m:element m:type=\"olingo.odata.test1.CTBaseAno\">" +
"<d:PropertyString>TEST12345</d:PropertyString>" +
"<d:AdditionalPropString>Additional12345</d:AdditionalPropString>" ));
}
@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(
"<d:PropertyInt16 m:type=\"Int16\">32766</d:PropertyInt16>" +
"<d:PropertyString>Test String1</d:PropertyString>" +
"<d:AdditionalPropertyString_5>Additional String1</d:AdditionalPropertyString_5>"));
}
@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\"}"));
}
}

View File

@ -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("<d:PropertyCompAno m:type=\"#olingo.odata.test1.CTBaseAno\">" +
"<d:PropertyString>Num111</d:PropertyString>" +
"<d:AdditionalPropString>Test123</d:AdditionalPropString>" +
"</d:PropertyCompAno>" +
"<d:CollPropertyCompAno m:type=\"#Collection(olingo.odata.test1.CTTwoPrimAno)\">" +
"<m:element m:type=\"olingo.odata.test1.CTBaseAno\">" +
"<d:PropertyString>TEST12345</d:PropertyString>" +
"<d:AdditionalPropString>Additional12345</d:AdditionalPropString>" ));
}
@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(
"<d:PropertyInt16 m:type=\"Int16\">32766</d:PropertyInt16>" +
"<d:PropertyString>Test String1</d:PropertyString>" +
"<d:AdditionalPropertyString_5>Additional String1</d:AdditionalPropertyString_5>"));
}
@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;
}
}

View File

@ -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);

View File

@ -132,7 +132,7 @@
<groupId>org.apache.olingo</groupId>
<artifactId>odata-server-core</artifactId>
<version>${project.version}</version>
<scope>runtime</scope>
<!-- <scope>runtime</scope> -->
</dependency>
<dependency>

View File

@ -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<String, EntityCollection> data) {
final EntityCollection entityCollection = data.get("ESAllPrim");
final List<Entity> targetEntities = data.get("ESTwoPrim").getEntities();
final List<Entity> 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<String, EntityCollection> data) {

View File

@ -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<EdmEntitySet> 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);
}

View File

@ -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<VisitorOperand> {
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<VisitorOperand>
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<VisitorOperand>
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<VisitorOperand>
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<Property> 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<ComplexValue> complex = (List<ComplexValue>) currentProperty.asCollection();
Iterator<ComplexValue> 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<Property> 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<VisitorOperand>
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<Property> 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();
}

View File

@ -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);
}

View File

@ -288,8 +288,8 @@ public class ODataXmlSerializerTest {
" </a:author>\n" +
" <a:link rel=\"edit\" href=\"ESAllPrim(0)\" />\n" +
" <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\" "
+ "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimOne\" "
+ "href=\"ESAllPrim(0)/NavPropertyETTwoPrimOne\" />\n" +
+ "type=\"application/atom+xml;type=entry\" title=\"NavPropertyETTwoPrimOne\" "
+ "href=\"ESBase(111)\" />\n" +
" <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\" "
+ "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimMany\" "
+ "href=\"ESAllPrim(0)/NavPropertyETTwoPrimMany\" />\n" +
@ -670,9 +670,10 @@ public class ODataXmlSerializerTest {
" <d:PropertyInt16 m:type=\"Int16\">456</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 2</d:PropertyString>\n" +
" </m:element>\n" +
" <m:element>\n" +
" <m:element m:type=\"olingo.odata.test1.CTBase\">\n" +
" <d:PropertyInt16 m:type=\"Int16\">789</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 3</d:PropertyString>\n" +
" <d:AdditionalPropString>ADD TEST</d:AdditionalPropString>\n" +
" </m:element>\n" +
" </d:CollPropertyComp>\n" +
" </m:properties>\n" +
@ -2321,15 +2322,42 @@ public class ODataXmlSerializerTest {
" <a:link rel=\"edit\" href=\"ESAllPrim(0)\" />\n" +
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimOne\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimOne\"\n" +
" href=\"ESAllPrim(0)/NavPropertyETTwoPrimOne\">\n" +
" <m:inline />\n" +
" type=\"application/atom+xml;type=entry\" title=\"NavPropertyETTwoPrimOne\"\n" +
" href=\"ESBase(111)\">\n" +
" <m:inline>\n "+
" <a:entry>\n "+
" <a:id>ESBase(111)</a:id>\n "+
" <a:title/>\n "+
" <a:summary/>\n "+
" <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ "</a:updated>" +
" <a:author>\n "+
" <a:name/>\n "+
" </a:author>\n "+
" <a:link rel=\"edit\" href=\"ESBase(111)\"/>\n "+
" <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimOne\" "
+ "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimOne\" "
+ "href=\"ESBase(111)/NavPropertyETAllPrimOne\"/>\n "+
" <a:link rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimMany\" "
+ "type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimMany\" "
+ "href=\"ESBase(111)/NavPropertyETAllPrimMany\"/>\n "+
" <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\" "
+ "term=\"#olingo.odata.test1.ETBase\"/>\n "+
" <a:content type=\"application/xml\">\n "+
" <m:properties>\n "+
" <d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>\n "+
" <d:PropertyString>TEST A</d:PropertyString>\n "+
" <d:AdditionalPropertyString_5>TEST A 0815</d:AdditionalPropertyString_5>\n "+
" </m:properties>\n "+
" </a:content>\n "+
" </a:entry>\n "+
" </m:inline>\n "+
" </a:link>" +
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETTwoPrimMany\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETTwoPrimMany\"\n" +
" href=\"ESAllPrim(0)/NavPropertyETTwoPrimMany\">\n" +
" <m:inline>\n" +
" <m:inline>\n "+
" <a:feed>\n" +
" <a:entry>\n" +
" <a:id>ESTwoPrim(32766)</a:id>\n" +
@ -2630,9 +2658,10 @@ public class ODataXmlSerializerTest {
" <d:PropertyInt16 m:type=\"Int16\">456</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 2</d:PropertyString>\n" +
" </m:element>\n" +
" <m:element>\n" +
" <m:element m:type=\"olingo.odata.test1.CTBase\">\n" +
" <d:PropertyInt16 m:type=\"Int16\">789</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 3</d:PropertyString>\n" +
" <d:AdditionalPropString>ADD TEST</d:AdditionalPropString>\n" +
" </m:element>\n" +
"</m:value>";
checkXMLEqual(expected, resultString);