[OLINGO-789] server support for action parameters of all types
Signed-off-by: Michael Bolz <michael.bolz@sap.com>
This commit is contained in:
parent
b9403cd394
commit
d6db341db7
|
@ -18,6 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.fit.tecsvc.client;
|
package org.apache.olingo.fit.tecsvc.client;
|
||||||
|
|
||||||
|
import static org.hamcrest.CoreMatchers.startsWith;
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertThat;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -45,4 +50,17 @@ public abstract class AbstractParamTecSvcITCase extends AbstractTecSvcITCase {
|
||||||
protected ContentType getContentType() {
|
protected ContentType getContentType() {
|
||||||
return contentType;
|
return contentType;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected void assertContentType(final String content) {
|
||||||
|
assertThat(content, startsWith(contentType.toContentTypeString()));
|
||||||
|
}
|
||||||
|
|
||||||
|
protected boolean isJson() {
|
||||||
|
return ContentType.JSON.isCompatible(contentType);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected void assertShortOrInt(final int value, final Object n) {
|
||||||
|
assertTrue(n instanceof Number);
|
||||||
|
assertEquals(value, ((Number) n).intValue());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -18,11 +18,6 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.fit.tecsvc.client;
|
package org.apache.olingo.fit.tecsvc.client;
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
|
|
||||||
import java.util.Collection;
|
import java.util.Collection;
|
||||||
|
|
||||||
import org.apache.olingo.client.api.EdmEnabledODataClient;
|
import org.apache.olingo.client.api.EdmEnabledODataClient;
|
||||||
|
@ -61,22 +56,7 @@ public abstract class AbstractTecSvcITCase extends AbstractBaseTestITCase {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void assertShortOrInt(final int value, final Object n) {
|
protected abstract ContentType getContentType();
|
||||||
assertTrue(n instanceof Number);
|
|
||||||
assertEquals(value, ((Number) n).intValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected void assertContentType(final String content) {
|
|
||||||
assertThat(content, containsString(getContentType().toContentTypeString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
protected ContentType getContentType() {
|
|
||||||
return ContentType.APPLICATION_JSON;
|
|
||||||
}
|
|
||||||
|
|
||||||
protected boolean isJson() {
|
|
||||||
return ContentType.JSON.isCompatible(getContentType());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ODataClient getClient() {
|
protected ODataClient getClient() {
|
||||||
|
@ -85,12 +65,8 @@ public abstract class AbstractTecSvcITCase extends AbstractBaseTestITCase {
|
||||||
return odata;
|
return odata;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected EdmEnabledODataClient getClient(final String serviceRoot) {
|
|
||||||
return ODataClientFactory.getEdmEnabledClient(serviceRoot, getContentType());
|
|
||||||
}
|
|
||||||
|
|
||||||
protected EdmEnabledODataClient getEdmEnabledClient() {
|
protected EdmEnabledODataClient getEdmEnabledClient() {
|
||||||
return getClient(SERVICE_URI);
|
return ODataClientFactory.getEdmEnabledClient(SERVICE_URI, getContentType());
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ClientObjectFactory getFactory() {
|
protected ClientObjectFactory getFactory() {
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.olingo.fit.tecsvc.client;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.fail;
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.junit.Assume.assumeTrue;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
|
@ -42,13 +43,12 @@ import org.apache.olingo.client.api.domain.ClientInvokeResult;
|
||||||
import org.apache.olingo.client.api.domain.ClientProperty;
|
import org.apache.olingo.client.api.domain.ClientProperty;
|
||||||
import org.apache.olingo.client.api.domain.ClientValue;
|
import org.apache.olingo.client.api.domain.ClientValue;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ActionImportITCase extends AbstractTecSvcITCase {
|
public class ActionImportITCase extends AbstractParamTecSvcITCase {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void noReturnTypeAction() throws Exception {
|
public void noReturnTypeAction() throws Exception {
|
||||||
|
@ -293,6 +293,8 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
|
||||||
|
|
||||||
private <T extends ClientInvokeResult> ODataInvokeResponse<T> callAction(final String name,
|
private <T extends ClientInvokeResult> ODataInvokeResponse<T> callAction(final String name,
|
||||||
final Class<T> resultRef, final Map<String, ClientValue> parameters, final boolean returnMinimal) {
|
final Class<T> resultRef, final Map<String, ClientValue> parameters, final boolean returnMinimal) {
|
||||||
|
assumeTrue("The client would send wrongly formatted parameters in XML.",
|
||||||
|
parameters == null || parameters.isEmpty() || isJson()); // TODO: XML case
|
||||||
final URI actionURI = getClient().newURIBuilder(TecSvcConst.BASE_URI).appendActionCallSegment(name).build();
|
final URI actionURI = getClient().newURIBuilder(TecSvcConst.BASE_URI).appendActionCallSegment(name).build();
|
||||||
ODataInvokeRequest<T> request = getClient().getInvokeRequestFactory()
|
ODataInvokeRequest<T> request = getClient().getInvokeRequestFactory()
|
||||||
.getActionInvokeRequest(actionURI, resultRef, parameters);
|
.getActionInvokeRequest(actionURI, resultRef, parameters);
|
||||||
|
@ -309,9 +311,4 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
|
||||||
}
|
}
|
||||||
return response;
|
return response;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ContentType getContentType() {
|
|
||||||
return ContentType.APPLICATION_JSON;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -48,13 +48,12 @@ import org.apache.olingo.client.api.domain.ClientProperty;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.EntityCollection;
|
import org.apache.olingo.commons.api.data.EntityCollection;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.format.PreferenceName;
|
import org.apache.olingo.commons.api.format.PreferenceName;
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
import org.apache.olingo.commons.api.http.HttpHeader;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
public final class AsyncSupportITCase extends AbstractParamTecSvcITCase {
|
||||||
|
|
||||||
private static final String ES_ALL_PRIM = "ESAllPrim";
|
private static final String ES_ALL_PRIM = "ESAllPrim";
|
||||||
private static final String NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
|
private static final String NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
|
||||||
|
@ -70,7 +69,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
|
|
||||||
final ODataRetrieveResponse<ClientEntity> response = client.getRetrieveRequestFactory()
|
final ODataRetrieveResponse<ClientEntity> response = client.getRetrieveRequestFactory()
|
||||||
.getEntityRequest(uri).execute();
|
.getEntityRequest(uri).execute();
|
||||||
assertEquals(32767, response.getBody().getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
assertShortOrInt(32767, response.getBody().getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
||||||
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
||||||
|
|
||||||
// first async request
|
// first async request
|
||||||
|
@ -98,9 +97,8 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
assertNotNull(first.getODataResponse());
|
assertNotNull(first.getODataResponse());
|
||||||
ODataResponse firstResponse = first.getODataResponse();
|
ODataResponse firstResponse = first.getODataResponse();
|
||||||
assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
|
assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
|
||||||
ResWrap<Entity> entity = client.getDeserializer(ContentType.APPLICATION_JSON)
|
ResWrap<Entity> entity = client.getDeserializer(getContentType()).toEntity(firstResponse.getRawResponse());
|
||||||
.toEntity(firstResponse.getRawResponse());
|
assertShortOrInt(32767, entity.getPayload().getProperty("PropertyInt16").asPrimitive());
|
||||||
assertEquals(32767, entity.getPayload().getProperty("PropertyInt16").asPrimitive());
|
|
||||||
assertEquals("First Resource - positive values", entity.getPayload().getProperty("PropertyString").asPrimitive());
|
assertEquals("First Resource - positive values", entity.getPayload().getProperty("PropertyString").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -144,12 +142,12 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
|
assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
|
||||||
assertEquals(2, firstResponse.getHeaderNames().size());
|
assertEquals(2, firstResponse.getHeaderNames().size());
|
||||||
assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
|
assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
|
||||||
ResWrap<EntityCollection> firWrap = client.getDeserializer(ContentType.APPLICATION_JSON)
|
ResWrap<EntityCollection> firWrap = client.getDeserializer(getContentType())
|
||||||
.toEntitySet(firstResponse.getRawResponse());
|
.toEntitySet(firstResponse.getRawResponse());
|
||||||
EntityCollection firstResponseEntitySet = firWrap.getPayload();
|
EntityCollection firstResponseEntitySet = firWrap.getPayload();
|
||||||
assertEquals(3, firstResponseEntitySet.getEntities().size());
|
assertEquals(3, firstResponseEntitySet.getEntities().size());
|
||||||
Entity firstResponseEntity = firstResponseEntitySet.getEntities().get(0);
|
Entity firstResponseEntity = firstResponseEntitySet.getEntities().get(0);
|
||||||
assertEquals(32767, firstResponseEntity.getProperty("PropertyInt16").asPrimitive());
|
assertShortOrInt(32767, firstResponseEntity.getProperty("PropertyInt16").asPrimitive());
|
||||||
assertEquals("First Resource - positive values", firstResponseEntity.getProperty("PropertyString").asPrimitive());
|
assertEquals("First Resource - positive values", firstResponseEntity.getProperty("PropertyString").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -190,7 +188,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
assertNotNull(createdEntity);
|
assertNotNull(createdEntity);
|
||||||
final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
|
final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
|
||||||
assertNotNull(property1);
|
assertNotNull(property1);
|
||||||
assertEquals(42, property1.getPrimitiveValue().toValue());
|
assertShortOrInt(42, property1.getPrimitiveValue().toValue());
|
||||||
final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
|
final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
|
||||||
assertNotNull(property2);
|
assertNotNull(property2);
|
||||||
assertNull(property2.getPrimitiveValue());
|
assertNull(property2.getPrimitiveValue());
|
||||||
|
@ -220,7 +218,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
|
assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
|
||||||
|
|
||||||
final ClientEntity entity = firstResponse.getBody();
|
final ClientEntity entity = firstResponse.getBody();
|
||||||
assertEquals(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
assertShortOrInt(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
||||||
assertEquals("First Resource - positive values",
|
assertEquals("First Resource - positive values",
|
||||||
entity.getProperty("PropertyString").getPrimitiveValue().toValue());
|
entity.getProperty("PropertyString").getPrimitiveValue().toValue());
|
||||||
}
|
}
|
||||||
|
@ -266,11 +264,11 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
||||||
return client.getRetrieveRequestFactory().getEntityRequest(uri);
|
return client.getRetrieveRequestFactory().getEntityRequest(uri);
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkEntityAvailableWith(ClientEntitySet entitySet, String property, Object value) {
|
private void checkEntityAvailableWith(ClientEntitySet entitySet, String property, int value) {
|
||||||
for (ClientEntity entity : entitySet.getEntities()) {
|
for (ClientEntity entity : entitySet.getEntities()) {
|
||||||
ClientProperty ep = entity.getProperty("PropertyInt16");
|
ClientProperty ep = entity.getProperty(property);
|
||||||
if (ep != null) {
|
if (ep != null) {
|
||||||
assertEquals(value, ep.getPrimitiveValue().toValue());
|
assertShortOrInt(value, ep.getPrimitiveValue().toValue());
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -1,950 +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.client;
|
|
||||||
|
|
||||||
import static org.hamcrest.CoreMatchers.containsString;
|
|
||||||
import static org.junit.Assert.assertEquals;
|
|
||||||
import static org.junit.Assert.assertNotNull;
|
|
||||||
import static org.junit.Assert.assertThat;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
|
|
||||||
import java.net.URI;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Iterator;
|
|
||||||
import java.util.LinkedHashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
import org.apache.olingo.client.api.EdmEnabledODataClient;
|
|
||||||
import org.apache.olingo.client.api.ODataClient;
|
|
||||||
import org.apache.olingo.client.api.communication.ODataClientErrorException;
|
|
||||||
import org.apache.olingo.client.api.communication.request.cud.ODataEntityCreateRequest;
|
|
||||||
import org.apache.olingo.client.api.communication.request.cud.UpdateType;
|
|
||||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntityRequest;
|
|
||||||
import org.apache.olingo.client.api.communication.request.retrieve.ODataEntitySetRequest;
|
|
||||||
import org.apache.olingo.client.api.communication.response.ODataEntityCreateResponse;
|
|
||||||
import org.apache.olingo.client.api.communication.response.ODataEntityUpdateResponse;
|
|
||||||
import org.apache.olingo.client.api.communication.response.ODataRetrieveResponse;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientComplexValue;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientEntity;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientEntitySet;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientInlineEntity;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientInlineEntitySet;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientLink;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientObjectFactory;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientProperty;
|
|
||||||
import org.apache.olingo.client.api.domain.ClientValue;
|
|
||||||
import org.apache.olingo.client.core.ODataClientFactory;
|
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpHeader;
|
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
|
||||||
import org.junit.Ignore;
|
|
||||||
import org.junit.Test;
|
|
||||||
|
|
||||||
/**
|
|
||||||
* see the class comment on {@link DeepInsertITCase}
|
|
||||||
*/
|
|
||||||
public class DeepInsertXmlITCase extends AbstractParamTecSvcITCase {
|
|
||||||
|
|
||||||
private static final String ES_KEY_NAV = "ESKeyNav";
|
|
||||||
private static final String ES_TWO_KEY_NAV = "ESTwoKeyNav";
|
|
||||||
private static final String ET_KEY_NAV_NAME = "ETKeyNav";
|
|
||||||
private static final String ET_TWO_KEY_NAV_NAME = "ETTwoKeyNav";
|
|
||||||
private static final FullQualifiedName ET_KEY_NAV = new FullQualifiedName(SERVICE_NAMESPACE, ET_KEY_NAV_NAME);
|
|
||||||
private static final FullQualifiedName ET_TWO_KEY_NAV =
|
|
||||||
new FullQualifiedName(SERVICE_NAMESPACE, ET_TWO_KEY_NAV_NAME);
|
|
||||||
private static final String CT_PRIM_COMP = "CTPrimComp";
|
|
||||||
private static final String CT_TWO_PRIM = "CTTwoPrim";
|
|
||||||
private static final String CT_ALL_PRIM = "CTAllPrim";
|
|
||||||
private static final String CT_NAV_FIVE_PROP = "CTNavFiveProp";
|
|
||||||
private static final String CT_BASE_PRIM_COMP_NAV = "CTBasePrimCompNav";
|
|
||||||
private static final String PROPERTY_INT16 = "PropertyInt16";
|
|
||||||
private static final String PROPERTY_STRING = "PropertyString";
|
|
||||||
private static final String PROPERTY_COMP = "PropertyComp";
|
|
||||||
private static final String PROPERTY_COMP_NAV = "PropertyCompNav";
|
|
||||||
private static final String PROPERTY_COMP_COMP_NAV = "PropertyCompCompNav";
|
|
||||||
private static final String PROPERTY_COMP_TWO_PRIM = "PropertyCompTwoPrim";
|
|
||||||
private static final String PROPERTY_COMP_ALL_PRIM = "PropertyCompAllPrim";
|
|
||||||
private static final String NAV_PROPERTY_ET_KEY_NAV_ONE = "NavPropertyETKeyNavOne";
|
|
||||||
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_ONE = "NavPropertyETTwoKeyNavOne";
|
|
||||||
private static final String NAV_PROPERTY_ET_TWO_KEY_NAV_MANY = "NavPropertyETTwoKeyNavMany";
|
|
||||||
private static final String COL_PROPERTY_STRING = "CollPropertyString";
|
|
||||||
private static final String COL_PROPERTY_COMP_NAV = "CollPropertyCompNav";
|
|
||||||
private static final String EDM_STRING = "Edm.String";
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deepInsertExpandedResponse() {
|
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
|
||||||
client.getConfiguration().setDefaultPubFormat(ContentType.JSON);
|
|
||||||
final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final ClientEntity entity = of.newEntity(ET_KEY_NAV);
|
|
||||||
|
|
||||||
// Root entity
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newPrimitiveProperty(PROPERTY_STRING,
|
|
||||||
of.newPrimitiveValueBuilder().buildString("String Property level 0")));
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 41)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 0, complex level 1")))));
|
|
||||||
|
|
||||||
// First level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
|
|
||||||
final ClientEntity firstLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
firstLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 1, complex level 1")))));
|
|
||||||
firstLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
firstLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
final ClientInlineEntity firstLevelTwoKeyOneInline =
|
|
||||||
of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, firstLevelTwoKeyNav);
|
|
||||||
entity.addLink(firstLevelTwoKeyOneInline);
|
|
||||||
|
|
||||||
// Second level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
|
|
||||||
final ClientEntity secondLevelTwoKeyNav = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
secondLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 421)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 2, complex level 1")))));
|
|
||||||
secondLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
secondLevelTwoKeyNav.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
|
|
||||||
// Binding links
|
|
||||||
secondLevelTwoKeyNav.addLink(of.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, client.newURIBuilder(
|
|
||||||
SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(new LinkedHashMap<String, Object>() {
|
|
||||||
private static final long serialVersionUID = 3109256773218160485L;
|
|
||||||
{
|
|
||||||
put(PROPERTY_INT16, 3);
|
|
||||||
put(PROPERTY_STRING, "1");
|
|
||||||
}
|
|
||||||
}).build()));
|
|
||||||
|
|
||||||
final ClientInlineEntity secondLevelTwoKeyOneInline =
|
|
||||||
of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, secondLevelTwoKeyNav);
|
|
||||||
firstLevelTwoKeyNav.addLink(secondLevelTwoKeyOneInline);
|
|
||||||
|
|
||||||
// Third level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
|
|
||||||
final ClientEntity thirdLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
thirdLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 3, complex level 1")))));
|
|
||||||
thirdLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
thirdLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
|
|
||||||
final ClientEntity thirdLevelTwoKeyNavMany2 = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
thirdLevelTwoKeyNavMany2.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 432)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 3, complex level 1")))));
|
|
||||||
thirdLevelTwoKeyNavMany2.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
thirdLevelTwoKeyNavMany2.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
|
|
||||||
final ClientEntitySet entitySetThirdLevelTwoKeyNavMany = of.newEntitySet();
|
|
||||||
entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany1);
|
|
||||||
entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany2);
|
|
||||||
secondLevelTwoKeyNav.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
|
|
||||||
entitySetThirdLevelTwoKeyNavMany));
|
|
||||||
|
|
||||||
// First level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
|
|
||||||
final ClientEntity firstLevelTwoKeyNavMany1 = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
firstLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 422)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString(
|
|
||||||
"String Property level 1, complex level 1")))));
|
|
||||||
firstLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
firstLevelTwoKeyNavMany1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
|
|
||||||
final ClientEntitySet entitySetfirstLevelTwoKeyNavMany = of.newEntitySet();
|
|
||||||
entitySetfirstLevelTwoKeyNavMany.getEntities().add(firstLevelTwoKeyNavMany1);
|
|
||||||
entity.addLink(of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
|
|
||||||
entitySetfirstLevelTwoKeyNavMany));
|
|
||||||
|
|
||||||
final ODataEntityCreateResponse<ClientEntity> createResponse =
|
|
||||||
client.getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
|
|
||||||
|
|
||||||
// Check response
|
|
||||||
final ClientEntity resultEntityFirstLevel =
|
|
||||||
createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE)
|
|
||||||
.asInlineEntity().getEntity();
|
|
||||||
assertEquals(42, resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
assertEquals("String Property level 1, complex level 1",
|
|
||||||
resultEntityFirstLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
final ClientEntity resultEntitySecondLevel =
|
|
||||||
resultEntityFirstLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).asInlineEntity().getEntity();
|
|
||||||
assertEquals(421, resultEntitySecondLevel.getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
assertEquals("String Property level 2, complex level 1", resultEntitySecondLevel
|
|
||||||
.getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
final ClientEntitySet thirdLevelEntitySetNavMany =
|
|
||||||
resultEntitySecondLevel.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY)
|
|
||||||
.asInlineEntitySet().getEntitySet();
|
|
||||||
assertEquals(2, thirdLevelEntitySetNavMany.getEntities().size());
|
|
||||||
|
|
||||||
assertEquals(431, thirdLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(0)
|
|
||||||
.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
assertEquals(432, thirdLevelEntitySetNavMany.getEntities().get(1).getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertEquals("String Property level 3, complex level 1", thirdLevelEntitySetNavMany.getEntities().get(1)
|
|
||||||
.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue().get(PROPERTY_STRING).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
final ClientEntitySet firstLevelEntitySetNavMany =
|
|
||||||
createResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY)
|
|
||||||
.asInlineEntitySet().getEntitySet();
|
|
||||||
assertEquals(1, firstLevelEntitySetNavMany.getEntities().size());
|
|
||||||
assertEquals(422, firstLevelEntitySetNavMany.getEntities().get(0).getProperty(PROPERTY_COMP_TWO_PRIM)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertEquals("String Property level 1, complex level 1", firstLevelEntitySetNavMany.getEntities().get(0)
|
|
||||||
.getProperty(PROPERTY_COMP_TWO_PRIM).getComplexValue()
|
|
||||||
.get(PROPERTY_STRING).getPrimitiveValue().toValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void simpleDeepInsert() throws EdmPrimitiveTypeException {
|
|
||||||
final ODataClient client = getClient();
|
|
||||||
final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final ClientEntity entity = client.getObjectFactory().newEntity(ET_KEY_NAV);
|
|
||||||
|
|
||||||
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16,
|
|
||||||
of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
|
|
||||||
|
|
||||||
// Non collection navigation property
|
|
||||||
// Create related entity(EntitySet: ESTwoKeyNav, Type: ETTwoKeyNav, Nav. Property: NavPropertyETTwoKeyNavOne)
|
|
||||||
final ClientEntity inlineEntitySingle = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 43)));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("43")));
|
|
||||||
inlineEntitySingle.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 430)))));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 432)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("432")))));
|
|
||||||
|
|
||||||
// Collection navigation property
|
|
||||||
// The navigation property has a partner navigation property named "NavPropertyETKeyNavOne"
|
|
||||||
// Create related entity(EntitySet: ESTwoKeyNav, Type: NavPropertyETTwoKeyNavMany
|
|
||||||
final ClientEntity inlineEntityCol1 = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 44)));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("44")));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 441)))));
|
|
||||||
inlineEntityCol1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 440)))));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 442)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("442")))));
|
|
||||||
|
|
||||||
final ClientEntity inlineEntityCol2 = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 45)));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("45")));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 451)))));
|
|
||||||
inlineEntityCol2.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 450)))));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 452)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("452")))));
|
|
||||||
|
|
||||||
final ClientInlineEntity newDeepInsertEntityLink =
|
|
||||||
of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntitySingle);
|
|
||||||
final ClientEntitySet newDeepInsertEntitySet = of.newEntitySet();
|
|
||||||
newDeepInsertEntitySet.getEntities().add(inlineEntityCol1);
|
|
||||||
newDeepInsertEntitySet.getEntities().add(inlineEntityCol2);
|
|
||||||
final ClientInlineEntitySet newDeepInsertEntitySetLink =
|
|
||||||
of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, newDeepInsertEntitySet);
|
|
||||||
|
|
||||||
entity.addLink(newDeepInsertEntityLink);
|
|
||||||
entity.addLink(newDeepInsertEntitySetLink);
|
|
||||||
|
|
||||||
// Perform create request
|
|
||||||
final ODataEntityCreateResponse<ClientEntity> responseCreate = client.getCUDRequestFactory()
|
|
||||||
.getEntityCreateRequest(createURI, entity)
|
|
||||||
.execute();
|
|
||||||
assertEquals(HttpStatusCode.CREATED.getStatusCode(), responseCreate.getStatusCode());
|
|
||||||
|
|
||||||
final String cookie = responseCreate.getHeader(HttpHeader.SET_COOKIE).toString();
|
|
||||||
|
|
||||||
// Fetch ESKeyNav entity with expand of NavPropertyETTwoKeyNavOne nav. property
|
|
||||||
ClientProperty propertyInt16 = responseCreate.getBody().getProperty(PROPERTY_INT16);
|
|
||||||
final URI esKeyNavURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(
|
|
||||||
propertyInt16.getPrimitiveValue().toValue()).expand(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE,
|
|
||||||
NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esKeyNavRequest = client.getRetrieveRequestFactory()
|
|
||||||
.getEntityRequest(esKeyNavURI);
|
|
||||||
esKeyNavRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esKeyNavResponse = esKeyNavRequest.execute();
|
|
||||||
|
|
||||||
ClientEntity clientEntity = esKeyNavResponse.getBody();
|
|
||||||
// Check nav. property NavPropertyETTwoKeyNavOne
|
|
||||||
assertNotNull(clientEntity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE));
|
|
||||||
ClientInlineEntity navOne = (ClientInlineEntity)clientEntity.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE);
|
|
||||||
assertShortOrInt(431, navOne.getEntity().getProperty(
|
|
||||||
PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check nav. property NavPropertyETTwoKeyNavMany
|
|
||||||
assertNotNull(esKeyNavResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY));
|
|
||||||
ClientInlineEntitySet navMany = (ClientInlineEntitySet)clientEntity
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY);
|
|
||||||
assertEquals(2, navMany.getEntitySet().getEntities().size());
|
|
||||||
|
|
||||||
assertShortOrInt(441, navMany.getEntitySet().getEntities().get(0).getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getValue().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertShortOrInt(451, navMany.getEntitySet().getEntities().get(1).getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getValue().asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Fetch ESTwoKeyNav entities and check if available and the partner relation have been set up
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavOne)
|
|
||||||
Map<String, Object> composedKey = new HashMap<String, Object>();
|
|
||||||
composedKey.put(PROPERTY_INT16, navOne.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING, navOne.getEntity().getProperty(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
final URI esTwoKeyNavEntitySingleURI = client.newURIBuilder(SERVICE_URI)
|
|
||||||
.appendEntitySetSegment(ES_TWO_KEY_NAV)
|
|
||||||
.appendKeySegment(composedKey)
|
|
||||||
.build();
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = client.getRetrieveRequestFactory()
|
|
||||||
.getEntityRequest(esTwoKeyNavEntitySingleURI);
|
|
||||||
esTwoKeyNavSingleRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavSingleResponse = esTwoKeyNavSingleRequest.execute();
|
|
||||||
assertShortOrInt(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue()
|
|
||||||
.get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavMany(0))
|
|
||||||
composedKey.clear();
|
|
||||||
composedKey.put(PROPERTY_INT16, navMany.getEntitySet().getEntities().get(0).getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING, navMany.getEntitySet().getEntities().get(0).getProperty(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
URI esTwoKeyNavEntityManyOneURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
|
|
||||||
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyOneRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
|
|
||||||
esTwoKeyNavManyOneRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyOneResponse = esTwoKeyNavManyOneRequest.execute();
|
|
||||||
|
|
||||||
assertShortOrInt(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
assertNotNull(esTwoKeyNavManyOneResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
|
|
||||||
ClientInlineEntity nvLink = (ClientInlineEntity)esTwoKeyNavManyOneResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE);
|
|
||||||
assertEquals(propertyInt16.getPrimitiveValue().toValue(), nvLink.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavMany(1))
|
|
||||||
composedKey.clear();
|
|
||||||
composedKey.put(PROPERTY_INT16, navMany.getEntitySet().getEntities().get(1).getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING, navMany.getEntitySet().getEntities().get(1).getProperty(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
URI esTwoKeyNavEntityManyTwoURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
|
|
||||||
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyTwoRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
|
|
||||||
esTwoKeyNavManyTwoRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyTwoResponse = esTwoKeyNavManyTwoRequest.execute();
|
|
||||||
|
|
||||||
assertShortOrInt(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertNotNull(esTwoKeyNavManyTwoResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
|
|
||||||
|
|
||||||
nvLink = (ClientInlineEntity)esTwoKeyNavManyTwoResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE);
|
|
||||||
assertEquals(propertyInt16.getPrimitiveValue().toValue(), nvLink.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deepInsertSameEntitySet() throws EdmPrimitiveTypeException {
|
|
||||||
final ODataClient client = getClient();
|
|
||||||
final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final ClientEntity entity = client.getObjectFactory().newEntity(ET_KEY_NAV);
|
|
||||||
|
|
||||||
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16,
|
|
||||||
of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
|
|
||||||
entity.addLink(of.newEntityNavigationLink("NavPropertyETTwoKeyNavOne",
|
|
||||||
client.newURIBuilder(SERVICE_URI)
|
|
||||||
.appendEntitySetSegment(ES_TWO_KEY_NAV)
|
|
||||||
.appendKeySegment(new LinkedHashMap<String, Object>() {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
put(PROPERTY_INT16, 1);
|
|
||||||
put(PROPERTY_STRING, "1");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build()));
|
|
||||||
|
|
||||||
// Prepare inline entity(EntitySet: ESKeyNav, Type: ETKeyNav)
|
|
||||||
final ClientEntity innerEntity = of.newEntity(ET_KEY_NAV);
|
|
||||||
innerEntity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 43)));
|
|
||||||
innerEntity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("43")));
|
|
||||||
innerEntity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))));
|
|
||||||
innerEntity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))));
|
|
||||||
innerEntity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))));
|
|
||||||
innerEntity
|
|
||||||
.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("431")))
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder()
|
|
||||||
.buildInt16((short) 431)))))));
|
|
||||||
innerEntity.addLink(of.newEntityNavigationLink("NavPropertyETTwoKeyNavOne",
|
|
||||||
client.newURIBuilder(SERVICE_URI)
|
|
||||||
.appendEntitySetSegment(ES_TWO_KEY_NAV)
|
|
||||||
.appendKeySegment(new LinkedHashMap<String, Object>() {
|
|
||||||
private static final long serialVersionUID = 1L;
|
|
||||||
|
|
||||||
{
|
|
||||||
put(PROPERTY_INT16, 1);
|
|
||||||
put(PROPERTY_STRING, "1");
|
|
||||||
}
|
|
||||||
})
|
|
||||||
.build()));
|
|
||||||
|
|
||||||
ClientInlineEntity inlineEntity = of.newDeepInsertEntity(NAV_PROPERTY_ET_KEY_NAV_ONE, innerEntity);
|
|
||||||
entity.addLink(inlineEntity);
|
|
||||||
|
|
||||||
final ODataEntityCreateResponse<ClientEntity> responseCreate =
|
|
||||||
client.getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
|
|
||||||
final String cookie = responseCreate.getHeader(HttpHeader.SET_COOKIE).iterator().next();
|
|
||||||
final Short esKeyNavEntityKey =
|
|
||||||
responseCreate.getBody().getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class);
|
|
||||||
|
|
||||||
// Fetch Entity
|
|
||||||
URI fetchEntityURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(esKeyNavEntityKey)
|
|
||||||
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
|
|
||||||
|
|
||||||
ODataEntityRequest<ClientEntity> entityRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(fetchEntityURI);
|
|
||||||
entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> entityResponse = entityRequest.execute();
|
|
||||||
|
|
||||||
ClientEntity clientEntity = entityResponse.getBody();
|
|
||||||
ClientInlineEntity navOne =
|
|
||||||
(ClientInlineEntity) clientEntity.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE);
|
|
||||||
|
|
||||||
// Check values
|
|
||||||
assertShortOrInt(431, navOne.getEntity().getProperty(PROPERTY_COMP_NAV).getComplexValue()
|
|
||||||
.get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
Short innerEntityInt16Key = navOne.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toCastValue(Short.class);
|
|
||||||
|
|
||||||
final URI innerEntityURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(innerEntityInt16Key)
|
|
||||||
.build();
|
|
||||||
final ODataEntityRequest<ClientEntity> innerRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(innerEntityURI);
|
|
||||||
innerRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
ODataRetrieveResponse<ClientEntity> innerResponse = innerRequest.execute();
|
|
||||||
|
|
||||||
assertShortOrInt(431, innerResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void consistency() throws EdmPrimitiveTypeException {
|
|
||||||
final EdmEnabledODataClient client = getClient(SERVICE_URI);
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final String cookie = getCookie();
|
|
||||||
|
|
||||||
// Do not set PropertyString(Nullable=false)
|
|
||||||
final ClientEntity entity = of.newEntity(ET_KEY_NAV);
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newCollectionProperty(COL_PROPERTY_STRING,
|
|
||||||
of.newCollectionValue(EDM_STRING).add(
|
|
||||||
of.newPrimitiveValueBuilder().buildString("Test"))));
|
|
||||||
|
|
||||||
final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory()
|
|
||||||
.getEntityCreateRequest(targetURI, entity);
|
|
||||||
request.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
request.execute();
|
|
||||||
fail("Expecting bad request");
|
|
||||||
} catch (ODataClientErrorException e) {
|
|
||||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
// Entity must not be created
|
|
||||||
validateSet(targetURI, cookie, (short) 1, (short) 2, (short) 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void invalidType() throws EdmPrimitiveTypeException {
|
|
||||||
final EdmEnabledODataClient client = getClient(SERVICE_URI);
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final String cookie = getCookie();
|
|
||||||
|
|
||||||
final ClientEntity entity = of.newEntity(ET_KEY_NAV);
|
|
||||||
entity.getProperties().add(of.newPrimitiveProperty(PROPERTY_STRING,
|
|
||||||
of.newPrimitiveValueBuilder().buildInt32(1)));
|
|
||||||
final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
|
|
||||||
|
|
||||||
try {
|
|
||||||
ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory()
|
|
||||||
.getEntityCreateRequest(targetURI, entity);
|
|
||||||
request.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
request.execute();
|
|
||||||
} catch (ODataClientErrorException e) {
|
|
||||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
validateSet(targetURI, cookie, (short) 1, (short) 2, (short) 3);
|
|
||||||
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newCollectionProperty(PROPERTY_STRING,
|
|
||||||
of.newCollectionValue(EDM_STRING).add(
|
|
||||||
of.newPrimitiveValueBuilder().buildString("Test"))));
|
|
||||||
|
|
||||||
try {
|
|
||||||
ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory()
|
|
||||||
.getEntityCreateRequest(targetURI, entity);
|
|
||||||
request.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
request.execute();
|
|
||||||
} catch (ODataClientErrorException e) {
|
|
||||||
assertEquals(HttpStatusCode.BAD_REQUEST.getStatusCode(), e.getStatusLine().getStatusCode());
|
|
||||||
}
|
|
||||||
|
|
||||||
validateSet(targetURI, cookie, (short) 1, (short) 2, (short) 3);
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
@Ignore
|
|
||||||
public void deepInsertOnNavigationPropertyInComplexProperty() {
|
|
||||||
final EdmEnabledODataClient client = getClient(SERVICE_URI);
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
|
|
||||||
final ClientEntity inlineEntity = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
inlineEntity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
inlineEntity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 1)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("1")))));
|
|
||||||
|
|
||||||
final ClientEntity entity = of.newEntity(ET_TWO_KEY_NAV);
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)));
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 2)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("2")))));
|
|
||||||
|
|
||||||
final ClientLink link = of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntity);
|
|
||||||
final ClientComplexValue complexValueCreate = of.newComplexValue(CT_NAV_FIVE_PROP);
|
|
||||||
complexValueCreate.getNavigationLinks().add(link);
|
|
||||||
|
|
||||||
entity.getProperties().add(
|
|
||||||
of.newCollectionProperty(COL_PROPERTY_COMP_NAV, of.newCollectionValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(complexValueCreate)));
|
|
||||||
|
|
||||||
final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).build();
|
|
||||||
final ODataEntityCreateResponse<ClientEntity> response = client.getCUDRequestFactory()
|
|
||||||
.getEntityCreateRequest(targetURI, entity)
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
assertEquals(HttpStatusCode.CREATED.getStatusCode(), response.getStatusCode());
|
|
||||||
final Iterator<ClientValue> iter = response.getBody()
|
|
||||||
.getProperty(COL_PROPERTY_COMP_NAV)
|
|
||||||
.getCollectionValue()
|
|
||||||
.iterator();
|
|
||||||
|
|
||||||
assertTrue(iter.hasNext());
|
|
||||||
final ClientComplexValue complexValue = iter.next().asComplex();
|
|
||||||
final ClientLink linkedEntity = complexValue.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE);
|
|
||||||
assertNotNull(linkedEntity);
|
|
||||||
assertEquals(1, linkedEntity.asInlineEntity()
|
|
||||||
.getEntity()
|
|
||||||
.getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue()
|
|
||||||
.toValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void deepUpsert() {
|
|
||||||
final ODataClient client = getClient();
|
|
||||||
final URI updateURI = client.newURIBuilder(SERVICE_URI)
|
|
||||||
.appendEntitySetSegment(ES_KEY_NAV)
|
|
||||||
.appendKeySegment(815)
|
|
||||||
.build();
|
|
||||||
final ClientObjectFactory of = client.getObjectFactory();
|
|
||||||
final ClientEntity entity = client.getObjectFactory().newEntity(ET_KEY_NAV);
|
|
||||||
|
|
||||||
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_ALL_PRIM, of.newComplexValue(CT_ALL_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 42)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))));
|
|
||||||
entity.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("42")))
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_NAV_FIVE_PROP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16,
|
|
||||||
of.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
|
|
||||||
|
|
||||||
// Non collection navigation property
|
|
||||||
// Create related entity(EntitySet: ESTwoKeyNav, Type: ETTwoKeyNav, Nav. Property: NavPropertyETTwoKeyNavOne)
|
|
||||||
final ClientEntity inlineEntitySingle = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 43)));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("43")));
|
|
||||||
inlineEntitySingle.getProperties().add(of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 43)))));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 431)))));
|
|
||||||
inlineEntitySingle.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 432)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("432")))));
|
|
||||||
|
|
||||||
// Collection navigation property
|
|
||||||
// The navigation property has a partner navigation property named "NavPropertyETKeyNavOne"
|
|
||||||
// Create related entity(EntitySet: ESTwoKeyNav, Type: NavPropertyETTwoKeyNavMany
|
|
||||||
final ClientEntity inlineEntityCol1 = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 44)));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("44")));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 441)))));
|
|
||||||
inlineEntityCol1.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 441)))));
|
|
||||||
inlineEntityCol1.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 442)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("442")))));
|
|
||||||
|
|
||||||
final ClientEntity inlineEntityCol2 = client.getObjectFactory().newEntity(ET_TWO_KEY_NAV);
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 45)));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("45")));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_NAV, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 451)))));
|
|
||||||
inlineEntityCol2.getProperties().add(
|
|
||||||
of.newComplexProperty(PROPERTY_COMP, of.newComplexValue(CT_PRIM_COMP)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 451)))));
|
|
||||||
inlineEntityCol2.getProperties()
|
|
||||||
.add(of.newComplexProperty(PROPERTY_COMP_TWO_PRIM, of.newComplexValue(CT_TWO_PRIM)
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_INT16, of.newPrimitiveValueBuilder().buildInt16((short) 452)))
|
|
||||||
.add(of.newPrimitiveProperty(PROPERTY_STRING, of.newPrimitiveValueBuilder().buildString("452")))));
|
|
||||||
|
|
||||||
final ClientInlineEntity newDeepInsertEntityLink =
|
|
||||||
of.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntitySingle);
|
|
||||||
final ClientEntitySet newDeepInsertEntitySet = of.newEntitySet();
|
|
||||||
newDeepInsertEntitySet.getEntities().add(inlineEntityCol1);
|
|
||||||
newDeepInsertEntitySet.getEntities().add(inlineEntityCol2);
|
|
||||||
final ClientInlineEntitySet newDeepInsertEntitySetLink =
|
|
||||||
of.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY, newDeepInsertEntitySet);
|
|
||||||
|
|
||||||
entity.addLink(newDeepInsertEntityLink);
|
|
||||||
entity.addLink(newDeepInsertEntitySetLink);
|
|
||||||
|
|
||||||
// Perform update request (upsert)
|
|
||||||
final ODataEntityUpdateResponse<ClientEntity> responseCreate = client.getCUDRequestFactory()
|
|
||||||
.getEntityUpdateRequest(updateURI, UpdateType.PATCH, entity)
|
|
||||||
.execute();
|
|
||||||
assertEquals(HttpStatusCode.CREATED.getStatusCode(), responseCreate.getStatusCode());
|
|
||||||
|
|
||||||
final String cookie = responseCreate.getHeader(HttpHeader.SET_COOKIE).toString();
|
|
||||||
|
|
||||||
// Fetch ESKeyNav entity with expand of NavPropertyETTwoKeyNavOne nav. property
|
|
||||||
ClientProperty propertyInt16 = responseCreate.getBody().getProperty(PROPERTY_INT16);
|
|
||||||
final URI esKeyNavURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(
|
|
||||||
propertyInt16.getPrimitiveValue().toValue()).expand(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE,
|
|
||||||
NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esKeyNavRequest = client.getRetrieveRequestFactory()
|
|
||||||
.getEntityRequest(esKeyNavURI);
|
|
||||||
esKeyNavRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esKeyNavResponse = esKeyNavRequest.execute();
|
|
||||||
|
|
||||||
// Check nav. property NavPropertyETTwoKeyNavOne
|
|
||||||
assertNotNull(esKeyNavResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE));
|
|
||||||
ClientInlineEntity navOne = (ClientInlineEntity)esKeyNavResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE);
|
|
||||||
assertShortOrInt(431, navOne.getEntity().getProperty(PROPERTY_COMP_NAV).getComplexValue()
|
|
||||||
.get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check nav. property NavPropertyETTwoKeyNavMany
|
|
||||||
assertNotNull(esKeyNavResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY));
|
|
||||||
ClientInlineEntitySet navMany = (ClientInlineEntitySet)esKeyNavResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY);
|
|
||||||
assertEquals(2, navMany.getEntitySet().getEntities().size());
|
|
||||||
|
|
||||||
assertShortOrInt(441, navMany.getEntitySet().getEntities().get(0).getProperty(PROPERTY_COMP_NAV).getValue()
|
|
||||||
.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
assertShortOrInt(451, navMany.getEntitySet().getEntities().get(1).getProperty(PROPERTY_COMP_NAV).getValue()
|
|
||||||
.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Fetch ESTwoKeyNav entities and check if available and the partner relation have been set up
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavOne)
|
|
||||||
Map<String, Object> composedKey = new HashMap<String, Object>();
|
|
||||||
composedKey.put(PROPERTY_INT16, navOne.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING, navOne.getEntity().getProperty(PROPERTY_STRING)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
final URI esTwoKeyNavEntitySingleURI = client.newURIBuilder(SERVICE_URI)
|
|
||||||
.appendEntitySetSegment(ES_TWO_KEY_NAV)
|
|
||||||
.appendKeySegment(composedKey)
|
|
||||||
.build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = client.getRetrieveRequestFactory()
|
|
||||||
.getEntityRequest(esTwoKeyNavEntitySingleURI);
|
|
||||||
esTwoKeyNavSingleRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavSingleResponse = esTwoKeyNavSingleRequest.execute();
|
|
||||||
assertShortOrInt(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavMany(0))
|
|
||||||
composedKey.clear();
|
|
||||||
composedKey.put(PROPERTY_INT16, navMany.getEntitySet().getEntities().get(0)
|
|
||||||
.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING,navMany.getEntitySet().getEntities().get(0)
|
|
||||||
.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
URI esTwoKeyNavEntityManyOneURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
|
|
||||||
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyOneRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
|
|
||||||
esTwoKeyNavManyOneRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyOneResponse = esTwoKeyNavManyOneRequest.execute();
|
|
||||||
|
|
||||||
assertShortOrInt(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertNotNull(esTwoKeyNavManyOneResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
|
|
||||||
ClientInlineEntity nvLink = (ClientInlineEntity)esTwoKeyNavManyOneResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE);
|
|
||||||
assertEquals(propertyInt16.getPrimitiveValue().toValue(), nvLink.getEntity().getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
// Check ESTwoKeyNav(Created via NavPropertyETTwoKeyNavMany(1))
|
|
||||||
composedKey.clear();
|
|
||||||
composedKey.put(PROPERTY_INT16, navMany.getEntitySet().getEntities().get(1)
|
|
||||||
.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
composedKey.put(PROPERTY_STRING,navMany.getEntitySet().getEntities().get(1)
|
|
||||||
.getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
|
|
||||||
|
|
||||||
URI esTwoKeyNavEntityManyTwoURI =
|
|
||||||
client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
|
|
||||||
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
|
|
||||||
|
|
||||||
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyTwoRequest =
|
|
||||||
client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
|
|
||||||
esTwoKeyNavManyTwoRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyTwoResponse = esTwoKeyNavManyTwoRequest.execute();
|
|
||||||
|
|
||||||
assertShortOrInt(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP_NAV)
|
|
||||||
.getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
assertNotNull(esTwoKeyNavManyTwoResponse.getBody().getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE));
|
|
||||||
nvLink = (ClientInlineEntity)esTwoKeyNavManyTwoResponse.getBody()
|
|
||||||
.getNavigationLink(NAV_PROPERTY_ET_KEY_NAV_ONE);
|
|
||||||
assertEquals(propertyInt16.getPrimitiveValue().toValue(),nvLink.getEntity()
|
|
||||||
.getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private String getCookie() {
|
|
||||||
final EdmEnabledODataClient client = getClient(SERVICE_URI);
|
|
||||||
final ODataRetrieveResponse<ClientEntitySet> response = client.getRetrieveRequestFactory()
|
|
||||||
.getEntitySetRequest(client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build())
|
|
||||||
.execute();
|
|
||||||
|
|
||||||
return response.getHeader(HttpHeader.SET_COOKIE).iterator().next();
|
|
||||||
}
|
|
||||||
|
|
||||||
private void validateSet(final URI uri, final String cookie, final short... keys)
|
|
||||||
throws EdmPrimitiveTypeException {
|
|
||||||
final EdmEnabledODataClient client = getClient(SERVICE_URI);
|
|
||||||
final ODataEntitySetRequest<ClientEntitySet> request = client.getRetrieveRequestFactory()
|
|
||||||
.getEntitySetRequest(uri);
|
|
||||||
request.addCustomHeader(HttpHeader.COOKIE, cookie);
|
|
||||||
final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
|
|
||||||
|
|
||||||
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
|
|
||||||
assertEquals(3, response.getBody().getEntities().size());
|
|
||||||
|
|
||||||
for (final ClientEntity responseEntity : response.getBody().getEntities()) {
|
|
||||||
short propertyInt16 = responseEntity.getProperty(PROPERTY_INT16)
|
|
||||||
.getPrimitiveValue().toCastValue(Short.class);
|
|
||||||
|
|
||||||
boolean found = false;
|
|
||||||
for (int i = 0; i < keys.length && !found; i++) {
|
|
||||||
if (propertyInt16 == keys[i]) {
|
|
||||||
found = true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!found) {
|
|
||||||
fail("Invalid key " + propertyInt16);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected ODataClient getClient() {
|
|
||||||
ODataClient odata = ODataClientFactory.getClient();
|
|
||||||
odata.getConfiguration().setDefaultPubFormat(ContentType.APPLICATION_ATOM_XML);
|
|
||||||
return odata;
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected void assertContentType(final String content) {
|
|
||||||
assertThat(content, containsString(ContentType.APPLICATION_ATOM_XML.toContentTypeString()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Override
|
|
||||||
protected EdmEnabledODataClient getClient(final String serviceRoot) {
|
|
||||||
return ODataClientFactory.getEdmEnabledClient(serviceRoot, ContentType.APPLICATION_ATOM_XML);
|
|
||||||
}
|
|
||||||
}
|
|
|
@ -216,7 +216,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
@Test
|
@Test
|
||||||
@Ignore("Server do not support navigation property count annotations")
|
@Ignore("Server do not support navigation property count annotations")
|
||||||
public void count() {
|
public void count() {
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||||
options.put(QueryOption.SELECT, "PropertyInt16");
|
options.put(QueryOption.SELECT, "PropertyInt16");
|
||||||
options.put(QueryOption.COUNT, true);
|
options.put(QueryOption.COUNT, true);
|
||||||
|
@ -254,7 +254,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
@Test
|
@Test
|
||||||
public void singleEntityWithExpand() {
|
public void singleEntityWithExpand() {
|
||||||
/* A single entity request will be dispatched to a different processor method than entity set request */
|
/* A single entity request will be dispatched to a different processor method than entity set request */
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||||
options.put(QueryOption.FILTER, "PropertyInt16 lt 2");
|
options.put(QueryOption.FILTER, "PropertyInt16 lt 2");
|
||||||
Map<String, Object> keys = new HashMap<String, Object>();
|
Map<String, Object> keys = new HashMap<String, Object>();
|
||||||
|
@ -295,7 +295,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
// Entity with Key (PropertyInt16=1, PropertyString='2') holds references to (PropertyInt16=1, PropertyString='1')
|
// Entity with Key (PropertyInt16=1, PropertyString='2') holds references to (PropertyInt16=1, PropertyString='1')
|
||||||
// Define filters to select explicit the entities at any level => Circle
|
// Define filters to select explicit the entities at any level => Circle
|
||||||
|
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||||
options.put(QueryOption.EXPAND, NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
options.put(QueryOption.EXPAND, NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
||||||
+ "($expand=" + NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
+ "($expand=" + NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
||||||
|
@ -370,7 +370,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void systemQueryOptionOnThirdLevel() {
|
public void systemQueryOptionOnThirdLevel() {
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||||
options.put(QueryOption.EXPAND, NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
options.put(QueryOption.EXPAND, NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
||||||
+ "($expand=" + NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
+ "($expand=" + NAV_PROPERTY_ET_TWO_KEY_NAV_MANY
|
||||||
|
@ -443,7 +443,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expandWithSearchQuery() {
|
public void expandWithSearchQuery() {
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
||||||
expandOptions.put(QueryOption.SEARCH, "abc");
|
expandOptions.put(QueryOption.SEARCH, "abc");
|
||||||
expandOptions.put(QueryOption.FILTER, "PropertyInt16 eq 1");
|
expandOptions.put(QueryOption.FILTER, "PropertyInt16 eq 1");
|
||||||
|
@ -463,7 +463,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expandWithLevels() {
|
public void expandWithLevels() {
|
||||||
final ODataClient client = getClient(SERVICE_URI);
|
final ODataClient client = getEdmEnabledClient();
|
||||||
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
||||||
expandOptions.put(QueryOption.LEVELS, 2);
|
expandOptions.put(QueryOption.LEVELS, 2);
|
||||||
|
|
||||||
|
|
|
@ -31,7 +31,7 @@ public interface EdmNavigationProperty extends EdmElement, EdmAnnotationsTarget,
|
||||||
EdmEntityType getType();
|
EdmEntityType getType();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if nullable or null if not specified
|
* @return true if nullable or not specified
|
||||||
*/
|
*/
|
||||||
boolean isNullable();
|
boolean isNullable();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
||||||
public interface EdmParameter extends EdmElement, EdmMappable, EdmAnnotatable {
|
public interface EdmParameter extends EdmElement, EdmMappable, EdmAnnotatable {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if nullable or null if not specified
|
* @return true if nullable or not specified
|
||||||
*/
|
*/
|
||||||
boolean isNullable();
|
boolean isNullable();
|
||||||
|
|
||||||
|
|
|
@ -42,7 +42,7 @@ public interface EdmProperty extends EdmElement, EdmMappable, EdmAnnotationsTarg
|
||||||
boolean isPrimitive();
|
boolean isPrimitive();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if nullable or null if not specified
|
* @return true if nullable or not specified
|
||||||
*/
|
*/
|
||||||
boolean isNullable();
|
boolean isNullable();
|
||||||
|
|
||||||
|
@ -67,7 +67,7 @@ public interface EdmProperty extends EdmElement, EdmMappable, EdmAnnotationsTarg
|
||||||
SRID getSrid();
|
SRID getSrid();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if unicode or null if not specified
|
* @return true if unicode or not specified
|
||||||
*/
|
*/
|
||||||
boolean isUnicode();
|
boolean isUnicode();
|
||||||
|
|
||||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
||||||
public interface EdmReturnType extends EdmTyped {
|
public interface EdmReturnType extends EdmTyped {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @return true if nullable or null if not specified
|
* @return true if nullable or not specified
|
||||||
*/
|
*/
|
||||||
boolean isNullable();
|
boolean isNullable();
|
||||||
|
|
||||||
|
|
|
@ -112,18 +112,15 @@ public class ODataImpl extends OData {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
|
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
|
||||||
ODataDeserializer deserializer;
|
|
||||||
|
|
||||||
if (contentType.isCompatible(ContentType.JSON)) {
|
if (contentType.isCompatible(ContentType.JSON)) {
|
||||||
deserializer = new ODataJsonDeserializer(contentType);
|
return new ODataJsonDeserializer(contentType);
|
||||||
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|
||||||
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
|
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
|
||||||
deserializer = new ODataXmlDeserializer();
|
return new ODataXmlDeserializer();
|
||||||
} else {
|
} else {
|
||||||
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
|
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||||
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||||
}
|
}
|
||||||
return deserializer;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -50,8 +50,8 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.EdmProperty;
|
import org.apache.olingo.commons.api.edm.EdmProperty;
|
||||||
import org.apache.olingo.commons.api.edm.EdmType;
|
import org.apache.olingo.commons.api.edm.EdmType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
|
||||||
|
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
||||||
|
@ -72,13 +72,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
||||||
|
|
||||||
public class ODataJsonDeserializer implements ODataDeserializer {
|
public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
private static final String AN_IO_EXCEPTION_OCCURRED_MSG = "An IOException occurred";
|
|
||||||
private static final String DUPLICATE_JSON_PROPERTY_DETECTED_MSG = "Duplicate json property detected";
|
|
||||||
private static final String AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG = "A JsonParseException occurred";
|
|
||||||
private static final String ODATA_ANNOTATION_MARKER = "@";
|
private static final String ODATA_ANNOTATION_MARKER = "@";
|
||||||
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
|
private static final String ODATA_CONTROL_INFORMATION_PREFIX = "@odata.";
|
||||||
private static final EdmPrimitiveType EDM_INT64 = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int64);
|
|
||||||
private static final EdmPrimitiveType EDM_DECIMAL = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal);
|
|
||||||
private final boolean isIEEE754Compatible;
|
private final boolean isIEEE754Compatible;
|
||||||
|
|
||||||
public ODataJsonDeserializer(final ContentType contentType) {
|
public ODataJsonDeserializer(final ContentType contentType) {
|
||||||
|
@ -89,33 +85,21 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
public DeserializerResult entityCollection(final InputStream stream, final EdmEntityType edmEntityType)
|
public DeserializerResult entityCollection(final InputStream stream, final EdmEntityType edmEntityType)
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
try {
|
try {
|
||||||
final ObjectNode tree = parseJsonTree(stream);
|
return DeserializerResultImpl.with().entityCollection(
|
||||||
|
consumeEntityCollectionNode(edmEntityType, parseJsonTree(stream), null))
|
||||||
return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
|
|
||||||
.build();
|
.build();
|
||||||
} catch (JsonParseException e) {
|
} catch (final IOException e) {
|
||||||
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
|
throw wrapParseException(e);
|
||||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
|
||||||
} catch (JsonMappingException e) {
|
|
||||||
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.DUPLICATE_JSON_PROPERTY);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityCollection consumeEntitySetNode(final EdmEntityType edmEntityType, final ObjectNode tree,
|
private EntityCollection consumeEntityCollectionNode(final EdmEntityType edmEntityType, ObjectNode tree,
|
||||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||||
EntityCollection entitySet = new EntityCollection();
|
EntityCollection entitySet = new EntityCollection();
|
||||||
|
|
||||||
// Consume entities
|
// Consume entities
|
||||||
JsonNode jsonNode = tree.get(Constants.VALUE);
|
JsonNode jsonNode = tree.get(Constants.VALUE);
|
||||||
if (jsonNode != null) {
|
if (jsonNode != null) {
|
||||||
if (!jsonNode.isArray()) {
|
|
||||||
throw new DeserializerException("The content of the value tag must be an Array but is not. ",
|
|
||||||
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
|
||||||
}
|
|
||||||
|
|
||||||
entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode, expandBuilder));
|
entitySet.getEntities().addAll(consumeEntitySetArray(edmEntityType, jsonNode, expandBuilder));
|
||||||
tree.remove(Constants.VALUE);
|
tree.remove(Constants.VALUE);
|
||||||
} else {
|
} else {
|
||||||
|
@ -145,16 +129,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
private List<Entity> consumeEntitySetArray(final EdmEntityType edmEntityType, final JsonNode jsonNode,
|
private List<Entity> consumeEntitySetArray(final EdmEntityType edmEntityType, final JsonNode jsonNode,
|
||||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||||
|
if (jsonNode.isArray()) {
|
||||||
List<Entity> entities = new ArrayList<Entity>();
|
List<Entity> entities = new ArrayList<Entity>();
|
||||||
for (JsonNode arrayElement : jsonNode) {
|
for (JsonNode arrayElement : jsonNode) {
|
||||||
if (arrayElement.isArray() || arrayElement.isValueNode()) {
|
if (arrayElement.isArray() || arrayElement.isValueNode()) {
|
||||||
throw new DeserializerException("Nested Arrays and primitive values are not allowed for an entity value.",
|
throw new DeserializerException("Nested Arrays and primitive values are not allowed for an entity value.",
|
||||||
DeserializerException.MessageKeys.INVALID_ENTITY);
|
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||||
}
|
}
|
||||||
|
|
||||||
entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
|
entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
|
||||||
}
|
}
|
||||||
return entities;
|
return entities;
|
||||||
|
} else {
|
||||||
|
throw new DeserializerException("The content of the value tag must be an Array but is not.",
|
||||||
|
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -167,17 +155,9 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
|
return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
|
||||||
.expandOption(expandBuilder.build())
|
.expandOption(expandBuilder.build())
|
||||||
.build();
|
.build();
|
||||||
|
} catch (final IOException e) {
|
||||||
} catch (JsonParseException e) {
|
throw wrapParseException(e);
|
||||||
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
|
||||||
} catch (JsonMappingException e) {
|
|
||||||
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private Entity consumeEntityNode(final EdmEntityType edmEntityType, final ObjectNode tree,
|
private Entity consumeEntityNode(final EdmEntityType edmEntityType, final ObjectNode tree,
|
||||||
|
@ -224,15 +204,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
assertJsonNodeIsEmpty(tree);
|
assertJsonNodeIsEmpty(tree);
|
||||||
return DeserializerResultImpl.with().actionParameters(parameters).build();
|
return DeserializerResultImpl.with().actionParameters(parameters).build();
|
||||||
|
|
||||||
} catch (final JsonParseException e) {
|
|
||||||
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
|
||||||
} catch (final JsonMappingException e) {
|
|
||||||
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
|
||||||
} catch (final IOException e) {
|
} catch (final IOException e) {
|
||||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
|
throw wrapParseException(e);
|
||||||
DeserializerException.MessageKeys.IO_EXCEPTION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -264,17 +237,15 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
case DEFINITION:
|
case DEFINITION:
|
||||||
case ENUM:
|
case ENUM:
|
||||||
case COMPLEX:
|
case COMPLEX:
|
||||||
|
case ENTITY:
|
||||||
Parameter parameter = createParameter(node.get(paramName), paramName, edmParameter);
|
Parameter parameter = createParameter(node.get(paramName), paramName, edmParameter);
|
||||||
parameters.put(paramName, parameter);
|
parameters.put(paramName, parameter);
|
||||||
node.remove(paramName);
|
node.remove(paramName);
|
||||||
break;
|
break;
|
||||||
case ENTITY:
|
|
||||||
throw new DeserializerException("Entity parameters are not allowed",
|
|
||||||
DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE);
|
|
||||||
default:
|
default:
|
||||||
throw new DeserializerException("Invalid type kind " + edmParameter.getType().getKind().toString()
|
throw new DeserializerException(
|
||||||
+ " for action parameter: " + paramName, DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE,
|
"Invalid type kind " + edmParameter.getType().getKind() + " for action parameter: " + paramName,
|
||||||
paramName);
|
DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE, paramName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return parameters;
|
return parameters;
|
||||||
|
@ -286,7 +257,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
parameter.setName(paramName);
|
parameter.setName(paramName);
|
||||||
if (node == null || node.isNull()) {
|
if (node == null || node.isNull()) {
|
||||||
if (!edmParameter.isNullable()) {
|
if (!edmParameter.isNullable()) {
|
||||||
throw new DeserializerException("Non-nullable parameter not present or null",
|
throw new DeserializerException("Non-nullable parameter not present or null: " + paramName,
|
||||||
MessageKeys.INVALID_NULL_PARAMETER, paramName);
|
MessageKeys.INVALID_NULL_PARAMETER, paramName);
|
||||||
}
|
}
|
||||||
if (edmParameter.isCollection()) {
|
if (edmParameter.isCollection()) {
|
||||||
|
@ -294,24 +265,34 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
MessageKeys.INVALID_NULL_PARAMETER, paramName);
|
MessageKeys.INVALID_NULL_PARAMETER, paramName);
|
||||||
}
|
}
|
||||||
parameter.setValue(ValueType.PRIMITIVE, null);
|
parameter.setValue(ValueType.PRIMITIVE, null);
|
||||||
|
} else if (edmParameter.getType().getKind() == EdmTypeKind.ENTITY) {
|
||||||
|
if (edmParameter.isCollection()) {
|
||||||
|
EntityCollection entityCollection = new EntityCollection();
|
||||||
|
entityCollection.getEntities().addAll(
|
||||||
|
consumeEntitySetArray((EdmEntityType) edmParameter.getType(), node, null));
|
||||||
|
parameter.setValue(ValueType.COLLECTION_ENTITY, entityCollection);
|
||||||
} else {
|
} else {
|
||||||
Property consumePropertyNode =
|
final Entity entity = consumeEntityNode((EdmEntityType) edmParameter.getType(), (ObjectNode) node, null);
|
||||||
|
parameter.setValue(ValueType.ENTITY, entity);
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
final Property property =
|
||||||
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
|
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
|
||||||
edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
|
edmParameter.isNullable(), edmParameter.getMaxLength(),
|
||||||
.getScale(), true, edmParameter.getMapping(), node);
|
edmParameter.getPrecision(), edmParameter.getScale(), true, edmParameter.getMapping(), node);
|
||||||
parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
|
parameter.setValue(property.getValueType(), property.getValue());
|
||||||
}
|
}
|
||||||
return parameter;
|
return parameter;
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Consume all remaining fields of Json ObjectNode and try to map found values
|
* Consumes all remaining fields of Json ObjectNode and tries to map found values
|
||||||
* to according Entity fields and omit to be ignored OData fields (e.g. control information).
|
* to according Entity fields and omits OData fields to be ignored (e.g., control information).
|
||||||
*
|
*
|
||||||
* @param edmEntityType edm entity type which for which the json node is consumed
|
* @param edmEntityType edm entity type which for which the json node is consumed
|
||||||
* @param node json node which is consumed
|
* @param node json node which is consumed
|
||||||
* @param entity entity instance which is filled
|
* @param entity entity instance which is filled
|
||||||
* @throws DeserializerException if an exception during consummation occurs
|
* @throws DeserializerException if an exception during consumation occurs
|
||||||
*/
|
*/
|
||||||
private void consumeRemainingJsonNodeFields(final EdmEntityType edmEntityType, final ObjectNode node,
|
private void consumeRemainingJsonNodeFields(final EdmEntityType edmEntityType, final ObjectNode node,
|
||||||
final Entity entity) throws DeserializerException {
|
final Entity entity) throws DeserializerException {
|
||||||
|
@ -420,7 +401,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
private Link consumeBindingLink(final String key, final JsonNode jsonNode, final EdmEntityType edmEntityType)
|
private Link consumeBindingLink(final String key, final JsonNode jsonNode, final EdmEntityType edmEntityType)
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
String[] splitKey = key.split("@");
|
String[] splitKey = key.split(ODATA_ANNOTATION_MARKER);
|
||||||
String navigationPropertyName = splitKey[0];
|
String navigationPropertyName = splitKey[0];
|
||||||
EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
|
EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
|
||||||
if (edmNavigationProperty == null) {
|
if (edmNavigationProperty == null) {
|
||||||
|
@ -488,23 +469,16 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
switch (type.getKind()) {
|
switch (type.getKind()) {
|
||||||
case PRIMITIVE:
|
case PRIMITIVE:
|
||||||
Object value = readPrimitiveValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
|
||||||
jsonNode);
|
|
||||||
property.setValue(ValueType.PRIMITIVE, value);
|
|
||||||
break;
|
|
||||||
case DEFINITION:
|
case DEFINITION:
|
||||||
value = readTypeDefinitionValue(name, type, isNullable, mapping, jsonNode);
|
|
||||||
property.setValue(ValueType.PRIMITIVE, value);
|
|
||||||
break;
|
|
||||||
case ENUM:
|
case ENUM:
|
||||||
value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
Object value = readPrimitiveValue(name, (EdmPrimitiveType) type,
|
||||||
jsonNode);
|
isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode);
|
||||||
property.setValue(ValueType.ENUM, value);
|
property.setValue(type.getKind() == EdmTypeKind.ENUM ? ValueType.ENUM : ValueType.PRIMITIVE,
|
||||||
|
value);
|
||||||
break;
|
break;
|
||||||
case COMPLEX:
|
case COMPLEX:
|
||||||
value = readComplexNode(name, type, isNullable, jsonNode);
|
value = readComplexNode(name, type, isNullable, jsonNode);
|
||||||
property.setValue(ValueType.COMPLEX, value);
|
property.setValue(ValueType.COMPLEX, value);
|
||||||
|
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
throw new DeserializerException("Invalid Type Kind for a property found: " + type.getKind(),
|
throw new DeserializerException("Invalid Type Kind for a property found: " + type.getKind(),
|
||||||
|
@ -553,30 +527,18 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
Iterator<JsonNode> iterator = jsonNode.iterator();
|
Iterator<JsonNode> iterator = jsonNode.iterator();
|
||||||
switch (type.getKind()) {
|
switch (type.getKind()) {
|
||||||
case PRIMITIVE:
|
case PRIMITIVE:
|
||||||
while (iterator.hasNext()) {
|
|
||||||
JsonNode arrayElement = iterator.next();
|
|
||||||
Object value = readPrimitiveValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
|
||||||
arrayElement);
|
|
||||||
valueArray.add(value);
|
|
||||||
}
|
|
||||||
property.setValue(ValueType.COLLECTION_PRIMITIVE, valueArray);
|
|
||||||
break;
|
|
||||||
case DEFINITION:
|
case DEFINITION:
|
||||||
while (iterator.hasNext()) {
|
|
||||||
JsonNode arrayElement = iterator.next();
|
|
||||||
Object value = readTypeDefinitionValue(name, type, isNullable, mapping, arrayElement);
|
|
||||||
valueArray.add(value);
|
|
||||||
}
|
|
||||||
property.setValue(ValueType.COLLECTION_PRIMITIVE, valueArray);
|
|
||||||
break;
|
|
||||||
case ENUM:
|
case ENUM:
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
JsonNode arrayElement = iterator.next();
|
JsonNode arrayElement = iterator.next();
|
||||||
Object value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
Object value = readPrimitiveValue(name, (EdmPrimitiveType) type,
|
||||||
arrayElement);
|
isNullable, maxLength, precision, scale, isUnicode, mapping, arrayElement);
|
||||||
valueArray.add(value);
|
valueArray.add(value);
|
||||||
}
|
}
|
||||||
property.setValue(ValueType.COLLECTION_ENUM, valueArray);
|
property.setValue(type.getKind() == EdmTypeKind.ENUM ?
|
||||||
|
ValueType.COLLECTION_ENUM :
|
||||||
|
ValueType.COLLECTION_PRIMITIVE,
|
||||||
|
valueArray);
|
||||||
break;
|
break;
|
||||||
case COMPLEX:
|
case COMPLEX:
|
||||||
while (iterator.hasNext()) {
|
while (iterator.hasNext()) {
|
||||||
|
@ -626,22 +588,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
return complexValue;
|
return complexValue;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readTypeDefinitionValue(final String name, final EdmType type,
|
private Object readPrimitiveValue(final String name, final EdmPrimitiveType type,
|
||||||
final boolean isNullable, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
|
final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
|
||||||
|
final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
|
||||||
checkForValueNode(name, jsonNode);
|
checkForValueNode(name, jsonNode);
|
||||||
if (isValidNull(name, isNullable, jsonNode)) {
|
if (isValidNull(name, isNullable, jsonNode)) {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode);
|
||||||
|
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, type);
|
||||||
try {
|
try {
|
||||||
EdmTypeDefinition edmTypeDefinition = (EdmTypeDefinition) type;
|
return type.valueOfString(jsonNode.asText(),
|
||||||
checkJsonTypeBasedOnPrimitiveType(name, edmTypeDefinition.getUnderlyingType().getName(),
|
isNullable, maxLength, precision, scale, isUnicode,
|
||||||
jsonNode);
|
|
||||||
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmTypeDefinition.getUnderlyingType());
|
|
||||||
return edmTypeDefinition.valueOfString(jsonNode.asText(), isNullable,
|
|
||||||
edmTypeDefinition.getMaxLength(),
|
|
||||||
edmTypeDefinition.getPrecision(), edmTypeDefinition.getScale(), edmTypeDefinition.isUnicode(),
|
|
||||||
javaClass);
|
javaClass);
|
||||||
} catch (EdmPrimitiveTypeException e) {
|
} catch (final EdmPrimitiveTypeException e) {
|
||||||
throw new DeserializerException(
|
throw new DeserializerException(
|
||||||
"Invalid value: " + jsonNode.asText() + " for property: " + name, e,
|
"Invalid value: " + jsonNode.asText() + " for property: " + name, e,
|
||||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
||||||
|
@ -657,72 +617,23 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
throw new DeserializerException("Property: " + name + " must not be null.",
|
throw new DeserializerException("Property: " + name + " must not be null.",
|
||||||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
|
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
private Object readEnumValue(final String name, final EdmType type,
|
|
||||||
final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
|
|
||||||
final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
|
|
||||||
checkForValueNode(name, jsonNode);
|
|
||||||
if (isValidNull(name, isNullable, jsonNode)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
EdmEnumType edmEnumType = (EdmEnumType) type;
|
|
||||||
// Enum values must be strings
|
|
||||||
if (!jsonNode.isTextual()) {
|
|
||||||
throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for enum property: " + name,
|
|
||||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmEnumType.getUnderlyingType());
|
|
||||||
return edmEnumType.valueOfString(jsonNode.asText(),
|
|
||||||
isNullable, maxLength, precision, scale, isUnicode, javaClass);
|
|
||||||
} catch (EdmPrimitiveTypeException e) {
|
|
||||||
throw new DeserializerException(
|
|
||||||
"Invalid value: " + jsonNode.asText() + " for property: " + name, e,
|
|
||||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
private Object readPrimitiveValue(final String name, final EdmType type,
|
|
||||||
final boolean isNullable, final Integer maxLength, final Integer precision, final Integer scale,
|
|
||||||
final boolean isUnicode, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
|
|
||||||
checkForValueNode(name, jsonNode);
|
|
||||||
if (isValidNull(name, isNullable, jsonNode)) {
|
|
||||||
return null;
|
|
||||||
}
|
|
||||||
try {
|
|
||||||
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) type;
|
|
||||||
checkJsonTypeBasedOnPrimitiveType(name, edmPrimitiveType.getName(), jsonNode);
|
|
||||||
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmPrimitiveType);
|
|
||||||
String jsonNodeAsText = jsonNode.asText();
|
|
||||||
|
|
||||||
if (isIEEE754Compatible
|
|
||||||
&& (edmPrimitiveType.equals(EDM_INT64) || edmPrimitiveType.equals(EDM_DECIMAL))
|
|
||||||
&& jsonNodeAsText.length() == 0) {
|
|
||||||
throw new DeserializerException("IEEE754Compatible values must not be of length 0",
|
|
||||||
MessageKeys.INVALID_NULL_PROPERTY, name);
|
|
||||||
}
|
|
||||||
|
|
||||||
return edmPrimitiveType.valueOfString(jsonNodeAsText, isNullable, maxLength, precision, scale, isUnicode,
|
|
||||||
javaClass);
|
|
||||||
} catch (EdmPrimitiveTypeException e) {
|
|
||||||
throw new DeserializerException(
|
|
||||||
"Invalid value: " + jsonNode.asText() + " for property: " + name, e,
|
|
||||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, name);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This method either returns the primitive types default class or the manually mapped class if present.
|
* Returns the primitive type's default class or the manually mapped class if present.
|
||||||
* @param mapping
|
* @param mapping
|
||||||
* @param edmPrimitiveType
|
* @param edmPrimitiveType
|
||||||
* @return the java class to be used during deserialization
|
* @return the java class to be used during deserialization
|
||||||
*/
|
*/
|
||||||
private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType edmPrimitiveType) {
|
private Class<?> getJavaClassForPrimitiveType(final EdmMapping mapping, final EdmPrimitiveType type) {
|
||||||
|
final EdmPrimitiveType edmPrimitiveType =
|
||||||
|
type.getKind() == EdmTypeKind.ENUM ?
|
||||||
|
((EdmEnumType) type).getUnderlyingType() :
|
||||||
|
type.getKind() == EdmTypeKind.DEFINITION ?
|
||||||
|
((EdmTypeDefinition) type).getUnderlyingType() :
|
||||||
|
type;
|
||||||
return mapping == null || mapping.getMappedJavaClass() == null ?
|
return mapping == null || mapping.getMappedJavaClass() == null ?
|
||||||
edmPrimitiveType.getDefaultType() :
|
edmPrimitiveType.getDefaultType() :
|
||||||
mapping.getMappedJavaClass();
|
mapping.getMappedJavaClass();
|
||||||
|
@ -743,9 +654,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Validate that node is empty (<code>node.size == 0</code>) and if not throw
|
* Validates that node is empty (<code>node.size() == 0</code>).
|
||||||
* an <code>DeserializerException</code>.
|
|
||||||
*
|
|
||||||
* @param node node to be checked
|
* @param node node to be checked
|
||||||
* @throws DeserializerException if node is not empty
|
* @throws DeserializerException if node is not empty
|
||||||
*/
|
*/
|
||||||
|
@ -757,90 +666,64 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final String edmPrimitiveTypeName,
|
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final EdmPrimitiveType edmPrimitiveType,
|
||||||
final JsonNode jsonNode)
|
final JsonNode jsonNode) throws DeserializerException {
|
||||||
throws DeserializerException {
|
boolean valid = true;
|
||||||
|
if (edmPrimitiveType.getKind() == EdmTypeKind.DEFINITION) {
|
||||||
|
checkJsonTypeBasedOnPrimitiveType(propertyName,
|
||||||
|
((EdmTypeDefinition) edmPrimitiveType).getUnderlyingType(), jsonNode);
|
||||||
|
} else if (edmPrimitiveType.getKind() == EdmTypeKind.ENUM) {
|
||||||
|
// Enum values must be strings.
|
||||||
|
valid = jsonNode.isTextual();
|
||||||
|
} else {
|
||||||
|
final String name = edmPrimitiveType.getName();
|
||||||
EdmPrimitiveTypeKind primKind;
|
EdmPrimitiveTypeKind primKind;
|
||||||
try {
|
try {
|
||||||
primKind = EdmPrimitiveTypeKind.valueOf(edmPrimitiveTypeName);
|
primKind = EdmPrimitiveTypeKind.valueOf(name);
|
||||||
} catch (IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
throw new DeserializerException("Unknown Primitive Type: " + edmPrimitiveTypeName, e,
|
throw new DeserializerException("Unknown Primitive Type: " + name, e,
|
||||||
DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, edmPrimitiveTypeName, propertyName);
|
DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, name, propertyName);
|
||||||
|
}
|
||||||
|
valid = matchTextualCase(jsonNode, primKind)
|
||||||
|
|| matchNumberCase(jsonNode, primKind)
|
||||||
|
|| matchBooleanCase(jsonNode, primKind)
|
||||||
|
|| matchIEEENumberCase(jsonNode, primKind);
|
||||||
}
|
}
|
||||||
|
|
||||||
boolean valid = matchTextualCase(jsonNode, primKind);
|
|
||||||
valid |= matchNumberCase(jsonNode, primKind);
|
|
||||||
valid |= matchBooleanCase(jsonNode, primKind);
|
|
||||||
valid |= matchIEEENumberCase(jsonNode, primKind);
|
|
||||||
|
|
||||||
if (!valid) {
|
if (!valid) {
|
||||||
throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for edm " + primKind
|
throw new DeserializerException(
|
||||||
+ " property: " + propertyName, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName);
|
"Invalid json type: " + jsonNode.getNodeType() + " for " + edmPrimitiveType + " property: " + propertyName,
|
||||||
|
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchIEEENumberCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
private boolean matchIEEENumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||||
switch (primKind) {
|
return (isIEEE754Compatible ? node.isTextual() : node.isNumber())
|
||||||
case Int64:
|
&& (primKind == EdmPrimitiveTypeKind.Int64 || primKind == EdmPrimitiveTypeKind.Decimal);
|
||||||
case Decimal:
|
|
||||||
// Numbers (either numbers or string)
|
|
||||||
if (isIEEE754Compatible) {
|
|
||||||
return node.isTextual();
|
|
||||||
} else {
|
|
||||||
return node.isNumber();
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchBooleanCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
private boolean matchBooleanCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||||
if (node.isBoolean()) {
|
return node.isBoolean() && primKind == EdmPrimitiveTypeKind.Boolean;
|
||||||
switch (primKind) {
|
|
||||||
case Boolean:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchNumberCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
private boolean matchNumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||||
if (node.isNumber()) {
|
return node.isNumber() &&
|
||||||
switch (primKind) {
|
(primKind == EdmPrimitiveTypeKind.Int16
|
||||||
// Numbers (must be numbers)
|
|| primKind == EdmPrimitiveTypeKind.Int32
|
||||||
case Int16:
|
|| primKind == EdmPrimitiveTypeKind.Byte
|
||||||
case Int32:
|
|| primKind == EdmPrimitiveTypeKind.SByte
|
||||||
case Byte:
|
|| primKind == EdmPrimitiveTypeKind.Single
|
||||||
case SByte:
|
|| primKind == EdmPrimitiveTypeKind.Double);
|
||||||
case Single:
|
|
||||||
case Double:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private boolean matchTextualCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
private boolean matchTextualCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||||
if (node.isTextual()) {
|
return node.isTextual() &&
|
||||||
switch (primKind) {
|
(primKind == EdmPrimitiveTypeKind.String
|
||||||
case String:
|
|| primKind == EdmPrimitiveTypeKind.Binary
|
||||||
case Binary:
|
|| primKind == EdmPrimitiveTypeKind.Date
|
||||||
case Date:
|
|| primKind == EdmPrimitiveTypeKind.DateTimeOffset
|
||||||
case DateTimeOffset:
|
|| primKind == EdmPrimitiveTypeKind.Duration
|
||||||
case Duration:
|
|| primKind == EdmPrimitiveTypeKind.Guid
|
||||||
case Guid:
|
|| primKind == EdmPrimitiveTypeKind.TimeOfDay);
|
||||||
case TimeOfDay:
|
|
||||||
return true;
|
|
||||||
default:
|
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return false;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
@ -866,14 +749,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
tree);
|
tree);
|
||||||
}
|
}
|
||||||
return DeserializerResultImpl.with().property(property).build();
|
return DeserializerResultImpl.with().property(property).build();
|
||||||
} catch (JsonParseException e) {
|
} catch (final IOException e) {
|
||||||
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
|
throw wrapParseException(e);
|
||||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
|
||||||
} catch (JsonMappingException e) {
|
|
||||||
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -906,21 +783,27 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
||||||
throw new DeserializerException("Missing entity reference", DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
throw new DeserializerException("Missing entity reference", DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
||||||
}
|
}
|
||||||
return DeserializerResultImpl.with().entityReferences(parsedValues).build();
|
return DeserializerResultImpl.with().entityReferences(parsedValues).build();
|
||||||
} catch (JsonParseException e) {
|
} catch (final IOException e) {
|
||||||
throw new DeserializerException(AN_JSON_PARSE_EXCEPTION_OCCURRED_MSG, e,
|
throw wrapParseException(e);
|
||||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
} catch (final URISyntaxException e) {
|
||||||
} catch (JsonMappingException e) {
|
|
||||||
throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
|
||||||
} catch (IOException e) {
|
|
||||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
|
|
||||||
DeserializerException.MessageKeys.IO_EXCEPTION);
|
|
||||||
} catch (URISyntaxException e) {
|
|
||||||
throw new DeserializerException("failed to read @odata.id", e,
|
throw new DeserializerException("failed to read @odata.id", e,
|
||||||
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private DeserializerException wrapParseException(final IOException e) {
|
||||||
|
if (e instanceof JsonParseException) {
|
||||||
|
return new DeserializerException("A JsonParseException occurred.", e,
|
||||||
|
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||||
|
} else if (e instanceof JsonMappingException) {
|
||||||
|
return new DeserializerException("Duplicate json property detected.", e,
|
||||||
|
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
||||||
|
} else {
|
||||||
|
return new DeserializerException("An IOException occurred.", e,
|
||||||
|
DeserializerException.MessageKeys.IO_EXCEPTION);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private boolean isODataIEEE754Compatible(final ContentType contentType) {
|
private boolean isODataIEEE754Compatible(final ContentType contentType) {
|
||||||
return contentType.getParameters().containsKey(ContentType.PARAMETER_IEEE754_COMPATIBLE)
|
return contentType.getParameters().containsKey(ContentType.PARAMETER_IEEE754_COMPATIBLE)
|
||||||
&& Boolean.TRUE.toString().equalsIgnoreCase(
|
&& Boolean.TRUE.toString().equalsIgnoreCase(
|
||||||
|
|
|
@ -61,6 +61,7 @@ import org.apache.olingo.commons.core.edm.primitivetype.SingletonPrimitiveType;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
||||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||||
|
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||||
import org.apache.olingo.server.core.deserializer.DeserializerResultImpl;
|
import org.apache.olingo.server.core.deserializer.DeserializerResultImpl;
|
||||||
|
|
||||||
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
import com.fasterxml.aalto.stax.InputFactoryImpl;
|
||||||
|
@ -69,11 +70,9 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
||||||
|
|
||||||
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
|
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
|
||||||
private static final String ATOM = "a";
|
private static final String ATOM = "a";
|
||||||
private static final String NS_ATOM = "http://www.w3.org/2005/Atom";
|
private static final QName REF_ELEMENT = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
|
||||||
private static final QName REF_ELEMENT = new QName("http://docs.oasis-open.org/odata/ns/metadata", "ref");
|
private static final QName PARAMETERS_ELEMENT = new QName(Constants.NS_METADATA, "parameters");
|
||||||
private static final QName PARAMETERS_ELEMENT =
|
private static final QName ID_ATTR = new QName(Constants.NS_ATOM, ATOM);
|
||||||
new QName("http://docs.oasis-open.org/odata/ns/metadata", "parameters");
|
|
||||||
private static final QName ID_ATTR = new QName(NS_ATOM, ATOM);
|
|
||||||
|
|
||||||
private final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
|
private final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
|
||||||
private final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
|
private final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
|
||||||
|
@ -84,15 +83,6 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
||||||
private final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
|
private final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
|
||||||
private final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
|
private final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
|
||||||
|
|
||||||
// private void namespaces(final XMLStreamWriter writer) throws XMLStreamException {
|
|
||||||
// writer.writeNamespace(StringUtils.EMPTY, Constants.NS_ATOM);
|
|
||||||
// writer.writeNamespace(XMLConstants.XML_NS_PREFIX, XMLConstants.XML_NS_URI);
|
|
||||||
// writer.writeNamespace(Constants.PREFIX_METADATA, Constants.NS_METADATA);
|
|
||||||
// writer.writeNamespace(Constants.PREFIX_DATASERVICES, Constants.NS_DATASERVICES);
|
|
||||||
// writer.writeNamespace(Constants.PREFIX_GML, Constants.NS_GML);
|
|
||||||
// writer.writeNamespace(Constants.PREFIX_GEORSS, Constants.NS_GEORSS);
|
|
||||||
// }
|
|
||||||
|
|
||||||
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
|
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
|
||||||
return FACTORY.createXMLEventReader(input);
|
return FACTORY.createXMLEventReader(input);
|
||||||
}
|
}
|
||||||
|
@ -716,7 +706,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
|
Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
|
||||||
if (edmAction.getParameterNames() == null || edmAction.getParameterNames().isEmpty()
|
if (edmAction.getParameterNames() == null || edmAction.getParameterNames().isEmpty()
|
||||||
|| (edmAction.isBound() && edmAction.getParameterNames().size() == 1)) {
|
|| edmAction.isBound() && edmAction.getParameterNames().size() == 1) {
|
||||||
return DeserializerResultImpl.with().actionParameters(parameters)
|
return DeserializerResultImpl.with().actionParameters(parameters)
|
||||||
.build();
|
.build();
|
||||||
}
|
}
|
||||||
|
@ -729,12 +719,24 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
||||||
consumeParameters(edmAction, reader, event.asStartElement(), parameters);
|
consumeParameters(edmAction, reader, event.asStartElement(), parameters);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// NULL fill for missing parameters
|
// EDM checks.
|
||||||
Parameter nullParameter = new Parameter();
|
for (final String param : edmAction.getParameterNames()) {
|
||||||
nullParameter.setValue(ValueType.PRIMITIVE, null);
|
Parameter parameter = parameters.get(param);
|
||||||
for (String param:edmAction.getParameterNames()) {
|
if (parameter == null) {
|
||||||
if (parameters.get(param) == null) {
|
final EdmParameter edmParameter = edmAction.getParameter(param);
|
||||||
parameters.put(param, nullParameter);
|
if (!edmParameter.isNullable()) {
|
||||||
|
throw new DeserializerException("Non-nullable parameter not present or null: " + param,
|
||||||
|
MessageKeys.INVALID_NULL_PARAMETER, param);
|
||||||
|
}
|
||||||
|
if (edmParameter.isCollection()) {
|
||||||
|
throw new DeserializerException("Collection must not be null for parameter: " + param,
|
||||||
|
MessageKeys.INVALID_NULL_PARAMETER, param);
|
||||||
|
}
|
||||||
|
// NULL fill for missing parameters.
|
||||||
|
parameter = new Parameter();
|
||||||
|
parameter.setName(param);
|
||||||
|
parameter.setValue(ValueType.PRIMITIVE, null);
|
||||||
|
parameters.put(param, parameter);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return DeserializerResultImpl.with().actionParameters(parameters)
|
return DeserializerResultImpl.with().actionParameters(parameters)
|
||||||
|
|
|
@ -72,16 +72,16 @@ import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
|
||||||
|
|
||||||
public class ODataXmlSerializer extends AbstractODataSerializer {
|
public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
|
|
||||||
private static final String DATA = "d";
|
|
||||||
private static final String CONTEXT = "context";
|
private static final String CONTEXT = "context";
|
||||||
/** The default character set is UTF-8. */
|
/** The default character set is UTF-8. */
|
||||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||||
private static final String ATOM = "a";
|
private static final String ATOM = "a";
|
||||||
private static final String NS_ATOM = "http://www.w3.org/2005/Atom";
|
private static final String NS_ATOM = Constants.NS_ATOM;
|
||||||
private static final String METADATA = "m";
|
private static final String METADATA = "m";
|
||||||
private static final String NS_METADATA = "http://docs.oasis-open.org/odata/ns/metadata";
|
private static final String NS_METADATA = Constants.NS_METADATA;
|
||||||
private static final String NS_DATA = "http://docs.oasis-open.org/odata/ns/data";
|
private static final String DATA = "d";
|
||||||
private static final String NS_SCHEMA = "http://docs.oasis-open.org/odata/ns/scheme";
|
private static final String NS_DATA = Constants.NS_DATASERVICES;
|
||||||
|
private static final String NS_SCHEMA = Constants.NS_SCHEME;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
|
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
|
||||||
|
@ -235,7 +235,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
ContextURLBuilder.create(contextURL).toASCIIString());
|
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||||
writeMetadataETag(metadata, writer);
|
writeMetadataETag(metadata, writer);
|
||||||
|
|
||||||
if (options != null) {
|
if (options != null && options.getId() != null) {
|
||||||
writer.writeStartElement(ATOM, "id", NS_ATOM);
|
writer.writeStartElement(ATOM, "id", NS_ATOM);
|
||||||
writer.writeCharacters(options.getId());
|
writer.writeCharacters(options.getId());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
@ -364,16 +364,20 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
writer.writeAttribute(METADATA, NS_METADATA, "etag", entity.getETag());
|
writer.writeAttribute(METADATA, NS_METADATA, "etag", entity.getETag());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (entity.getId() != null) {
|
||||||
writer.writeStartElement(NS_ATOM, "id");
|
writer.writeStartElement(NS_ATOM, "id");
|
||||||
writer.writeCharacters(entity.getId().toASCIIString());
|
writer.writeCharacters(entity.getId().toASCIIString());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
writerAuthorInfo(entity.getTitle(), writer);
|
writerAuthorInfo(entity.getTitle(), writer);
|
||||||
|
|
||||||
|
if (entity.getId() != null) {
|
||||||
writer.writeStartElement(NS_ATOM, "link");
|
writer.writeStartElement(NS_ATOM, "link");
|
||||||
writer.writeAttribute("rel", "edit");
|
writer.writeAttribute("rel", "edit");
|
||||||
writer.writeAttribute("href", entity.getId().toASCIIString());
|
writer.writeAttribute("href", entity.getId().toASCIIString());
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
|
}
|
||||||
|
|
||||||
if (entityType.hasStream()) {
|
if (entityType.hasStream()) {
|
||||||
writer.writeStartElement(NS_ATOM, "content");
|
writer.writeStartElement(NS_ATOM, "content");
|
||||||
|
@ -551,13 +555,15 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
Link link = linked.getNavigationLink(navigationPropertyName);
|
Link link = linked.getNavigationLink(navigationPropertyName);
|
||||||
if (link == null) {
|
if (link == null) {
|
||||||
link = new Link();
|
link = new Link();
|
||||||
link.setRel("http://docs.oasis-open.org/odata/ns/related/" + navigationPropertyName);
|
link.setRel(Constants.NS_NAVIGATION_LINK_REL + navigationPropertyName);
|
||||||
link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
|
link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
|
||||||
link.setTitle(navigationPropertyName);
|
link.setTitle(navigationPropertyName);
|
||||||
EntityCollection target = new EntityCollection();
|
EntityCollection target = new EntityCollection();
|
||||||
link.setInlineEntitySet(target);
|
link.setInlineEntitySet(target);
|
||||||
|
if (linked.getId() != null) {
|
||||||
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
|
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
return link;
|
return link;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -575,7 +581,9 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
if (link.getTitle() != null) {
|
if (link.getTitle() != null) {
|
||||||
writer.writeAttribute("title", link.getTitle());
|
writer.writeAttribute("title", link.getTitle());
|
||||||
}
|
}
|
||||||
|
if (link.getHref() != null) {
|
||||||
writer.writeAttribute("href", link.getHref());
|
writer.writeAttribute("href", link.getHref());
|
||||||
|
}
|
||||||
if (close) {
|
if (close) {
|
||||||
writer.writeEndElement();
|
writer.writeEndElement();
|
||||||
}
|
}
|
||||||
|
@ -606,11 +614,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||||
SerializerException {
|
SerializerException {
|
||||||
writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA);
|
writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA);
|
||||||
if (property == null || property.isNull()) {
|
if (property == null || property.isNull()) {
|
||||||
if (edmProperty.isNullable() == Boolean.FALSE) {
|
if (edmProperty.isNullable()) {
|
||||||
|
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
|
||||||
|
} else {
|
||||||
throw new SerializerException("Non-nullable property not present!",
|
throw new SerializerException("Non-nullable property not present!",
|
||||||
SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
|
SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
|
||||||
} else {
|
|
||||||
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
writePropertyValue(metadata, edmProperty, property, selectedPaths, writer);
|
writePropertyValue(metadata, edmProperty, property, selectedPaths, writer);
|
||||||
|
|
|
@ -19,6 +19,7 @@
|
||||||
package org.apache.olingo.server.tecsvc.data;
|
package org.apache.olingo.server.tecsvc.data;
|
||||||
|
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
|
import java.net.URI;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -31,11 +32,13 @@ import org.apache.olingo.commons.api.data.EntityCollection;
|
||||||
import org.apache.olingo.commons.api.data.Parameter;
|
import org.apache.olingo.commons.api.data.Parameter;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.data.ValueType;
|
import org.apache.olingo.commons.api.data.ValueType;
|
||||||
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
|
||||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
|
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||||
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
||||||
|
|
||||||
public class ActionData {
|
public class ActionData {
|
||||||
|
@ -101,57 +104,45 @@ public class ActionData {
|
||||||
throws DataProviderException {
|
throws DataProviderException {
|
||||||
if ("UARTCTTwoPrimParam".equals(name)) {
|
if ("UARTCTTwoPrimParam".equals(name)) {
|
||||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||||
final Short number = paramInt16 == null ? (short) 32767 : (Short) paramInt16.asPrimitive();
|
final Short number = paramInt16 == null || paramInt16.isNull() ?
|
||||||
return createCTTwoPrimComplexProperty(number, "UARTCTTwoPrimParam string value");
|
(short) 32767 :
|
||||||
|
(Short) paramInt16.asPrimitive();
|
||||||
|
return createCTTwoPrimComplexProperty(name, number, "UARTCTTwoPrimParam string value");
|
||||||
}
|
}
|
||||||
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Property createCTTwoPrimComplexProperty(final Short number, final String text) {
|
private static Property createCTTwoPrimComplexProperty(final String name, final Short number, final String text) {
|
||||||
ComplexValue compValue = new ComplexValue();
|
return DataCreator.createComplex(name,
|
||||||
Property propInt = new Property();
|
DataCreator.createPrimitive("PropertyInt16", number),
|
||||||
propInt.setName("PropertyInt16");
|
DataCreator.createPrimitive("PropertyString", text));
|
||||||
propInt.setValue(ValueType.PRIMITIVE, number);
|
|
||||||
compValue.getValue().add(propInt);
|
|
||||||
Property propString = new Property();
|
|
||||||
propString.setName("PropertyString");
|
|
||||||
propString.setValue(ValueType.PRIMITIVE, text);
|
|
||||||
compValue.getValue().add(propString);
|
|
||||||
|
|
||||||
Property complexProp = new Property();
|
|
||||||
complexProp.setValue(ValueType.COMPLEX, compValue);
|
|
||||||
return complexProp;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Property complexCollectionAction(final String name, final Map<String, Parameter> parameters)
|
protected static Property complexCollectionAction(final String name, final Map<String, Parameter> parameters)
|
||||||
throws DataProviderException {
|
throws DataProviderException {
|
||||||
if ("UARTCollCTTwoPrimParam".equals(name)) {
|
if ("UARTCollCTTwoPrimParam".equals(name)) {
|
||||||
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
|
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
|
||||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 16, "Test123").asComplex());
|
final Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 17, "Test456").asComplex());
|
final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive();
|
||||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 18, "Test678").asComplex());
|
if (number >= 1) {
|
||||||
|
complexCollection.add(createCTTwoPrimComplexProperty(null, (short) 16, "Test123").asComplex());
|
||||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
|
||||||
if (paramInt16 != null) {
|
|
||||||
Short number = (Short) paramInt16.asPrimitive();
|
|
||||||
if (number < 0) {
|
|
||||||
complexCollection.clear();
|
|
||||||
} else if (number >= 0 && number < complexCollection.size()) {
|
|
||||||
complexCollection = complexCollection.subList(0, number);
|
|
||||||
}
|
}
|
||||||
Property complexCollProperty = new Property();
|
if (number >= 2) {
|
||||||
complexCollProperty.setValue(ValueType.COLLECTION_COMPLEX, complexCollection);
|
complexCollection.add(createCTTwoPrimComplexProperty(null, (short) 17, "Test456").asComplex());
|
||||||
return complexCollProperty;
|
|
||||||
}
|
}
|
||||||
|
if (number >= 3) {
|
||||||
|
complexCollection.add(createCTTwoPrimComplexProperty(null, (short) 18, "Test678").asComplex());
|
||||||
|
}
|
||||||
|
return new Property(null, name, ValueType.COLLECTION_COMPLEX, complexCollection);
|
||||||
}
|
}
|
||||||
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static EntityActionResult entityAction(final String name, final Map<String, Parameter> parameters,
|
protected static EntityActionResult entityAction(final String name, final Map<String, Parameter> parameters,
|
||||||
final Map<String, EntityCollection> data) throws DataProviderException {
|
final Map<String, EntityCollection> data, final OData oData, final Edm edm) throws DataProviderException {
|
||||||
if ("UARTETTwoKeyTwoPrimParam".equals(name)) {
|
if ("UARTETTwoKeyTwoPrimParam".equals(name)) {
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
final Short number = parameter == null ? 0 : (Short) parameter.asPrimitive();
|
final Short number = parameter == null || parameter.isNull() ? 0 : (Short) parameter.asPrimitive();
|
||||||
|
|
||||||
EntityCollection entityCollection = data.get("ESTwoKeyTwoPrim");
|
EntityCollection entityCollection = data.get("ESTwoKeyTwoPrim");
|
||||||
for (Entity entity : entityCollection.getEntities()) {
|
for (Entity entity : entityCollection.getEntities()) {
|
||||||
|
@ -180,7 +171,8 @@ public class ActionData {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} while (!freeKey);
|
} while (!freeKey);
|
||||||
return new EntityActionResult().setEntity(createAllPrimEntity(key, "UARTETAllPrimParam string value", date))
|
return new EntityActionResult().setEntity(
|
||||||
|
createAllPrimEntity(key, "UARTETAllPrimParam string value", date, oData, edm))
|
||||||
.setCreated(true);
|
.setCreated(true);
|
||||||
} else {
|
} else {
|
||||||
return new EntityActionResult().setEntity(entityCollection.getEntities().get(0));
|
return new EntityActionResult().setEntity(entityCollection.getEntities().get(0));
|
||||||
|
@ -189,8 +181,9 @@ public class ActionData {
|
||||||
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Entity createAllPrimEntity(final Short key, final String val, final Calendar date) {
|
private static Entity createAllPrimEntity(final Short key, final String val, final Calendar date,
|
||||||
return new Entity().addProperty(DataCreator.createPrimitive("PropertyInt16", key))
|
final OData oData, final Edm edm) throws DataProviderException {
|
||||||
|
Entity entity = new Entity().addProperty(DataCreator.createPrimitive("PropertyInt16", key))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyString", val))
|
.addProperty(DataCreator.createPrimitive("PropertyString", val))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyBoolean", false))
|
.addProperty(DataCreator.createPrimitive("PropertyBoolean", false))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyByte", null))
|
.addProperty(DataCreator.createPrimitive("PropertyByte", null))
|
||||||
|
@ -206,28 +199,31 @@ public class ActionData {
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyDuration", null))
|
.addProperty(DataCreator.createPrimitive("PropertyDuration", null))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyGuid", null))
|
.addProperty(DataCreator.createPrimitive("PropertyGuid", null))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyTimeOfDay", null));
|
.addProperty(DataCreator.createPrimitive("PropertyTimeOfDay", null));
|
||||||
|
setEntityId(entity, "ESAllPrim", oData, edm);
|
||||||
|
return entity;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static EntityCollection entityCollectionAction(final String name, final Map<String, Parameter> parameters)
|
protected static EntityCollection entityCollectionAction(final String name, final Map<String, Parameter> parameters,
|
||||||
throws DataProviderException {
|
final OData oData, final Edm edm) throws DataProviderException {
|
||||||
if ("UARTCollETKeyNavParam".equals(name)) {
|
if ("UARTCollETKeyNavParam".equals(name)) {
|
||||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
|
||||||
final Short number = paramInt16 == null ? 0 : (Short) paramInt16.asPrimitive();
|
|
||||||
EntityCollection collection = new EntityCollection();
|
EntityCollection collection = new EntityCollection();
|
||||||
|
Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||||
|
final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive();
|
||||||
if (number > 0) {
|
if (number > 0) {
|
||||||
for (short i = 1; i <= number; i++) {
|
for (short i = 1; i <= number; i++) {
|
||||||
collection.getEntities().add(createETKeyNavEntity(i));
|
collection.getEntities().add(createETKeyNavEntity(i, oData, edm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return collection;
|
return collection;
|
||||||
} else if ("UARTCollETAllPrimParam".equals(name)) {
|
} else if ("UARTCollETAllPrimParam".equals(name)) {
|
||||||
Parameter paramTimeOfDay = parameters.get("ParameterTimeOfDay");
|
|
||||||
EntityCollection collection = new EntityCollection();
|
EntityCollection collection = new EntityCollection();
|
||||||
if (paramTimeOfDay != null) {
|
Parameter paramTimeOfDay = parameters.get("ParameterTimeOfDay");
|
||||||
|
if (paramTimeOfDay != null && !paramTimeOfDay.isNull()) {
|
||||||
Calendar timeOfDay = (Calendar) paramTimeOfDay.asPrimitive();
|
Calendar timeOfDay = (Calendar) paramTimeOfDay.asPrimitive();
|
||||||
int count = timeOfDay.get(Calendar.HOUR_OF_DAY);
|
int count = timeOfDay.get(Calendar.HOUR_OF_DAY);
|
||||||
for (short i = 1; i <= count; i++) {
|
for (short i = 1; i <= count; i++) {
|
||||||
collection.getEntities().add(createAllPrimEntity(i, "UARTCollETAllPrimParam int16 value: " + i, null));
|
collection.getEntities().add(
|
||||||
|
createAllPrimEntity(i, "UARTCollETAllPrimParam int16 value: " + i, null, oData, edm));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
return collection;
|
return collection;
|
||||||
|
@ -236,8 +232,9 @@ public class ActionData {
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
@SuppressWarnings("unchecked")
|
||||||
private static Entity createETKeyNavEntity(final Short number) {
|
private static Entity createETKeyNavEntity(final Short number, final OData oData, final Edm edm)
|
||||||
return new Entity()
|
throws DataProviderException {
|
||||||
|
Entity entity = new Entity()
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyInt16", number))
|
.addProperty(DataCreator.createPrimitive("PropertyInt16", number))
|
||||||
.addProperty(DataCreator.createPrimitive("PropertyString", "UARTCollETKeyNavParam int16 value: " + number))
|
.addProperty(DataCreator.createPrimitive("PropertyString", "UARTCollETKeyNavParam int16 value: " + number))
|
||||||
.addProperty(DataCreator.createComplex("PropertyCompNav",
|
.addProperty(DataCreator.createComplex("PropertyCompNav",
|
||||||
|
@ -253,6 +250,18 @@ public class ActionData {
|
||||||
DataCreator.createPrimitive("PropertyString", ""),
|
DataCreator.createPrimitive("PropertyString", ""),
|
||||||
DataCreator.createComplex("PropertyCompNav",
|
DataCreator.createComplex("PropertyCompNav",
|
||||||
DataCreator.createPrimitive("PropertyInt16", (short) 0))));
|
DataCreator.createPrimitive("PropertyInt16", (short) 0))));
|
||||||
|
setEntityId(entity, "ESKeyNav", oData, edm);
|
||||||
|
return entity;
|
||||||
|
}
|
||||||
|
|
||||||
|
private static void setEntityId(Entity entity, final String entitySetName, final OData oData, final Edm edm)
|
||||||
|
throws DataProviderException {
|
||||||
|
try {
|
||||||
|
entity.setId(URI.create(oData.createUriHelper().buildCanonicalURL(
|
||||||
|
edm.getEntityContainer().getEntitySet(entitySetName), entity)));
|
||||||
|
} catch (final SerializerException e) {
|
||||||
|
throw new DataProviderException("Unable to set entity ID!", e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static Property createKeyNavAllPrimComplexValue(final String name) {
|
protected static Property createKeyNavAllPrimComplexValue(final String name) {
|
||||||
|
|
|
@ -77,9 +77,12 @@ public class DataProvider {
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityCollection readAll(final EdmEntitySet edmEntitySet) throws DataProviderException {
|
public EntityCollection readAll(final EdmEntitySet edmEntitySet) throws DataProviderException {
|
||||||
final EntityCollection entityCollection = data.get(edmEntitySet.getName());
|
EntityCollection entityCollection = data.get(edmEntitySet.getName());
|
||||||
|
if (entityCollection == null) {
|
||||||
return (entityCollection == null) ? createEntityCollection(edmEntitySet) : entityCollection;
|
entityCollection = new EntityCollection();
|
||||||
|
data.put(edmEntitySet.getName(), entityCollection);
|
||||||
|
}
|
||||||
|
return entityCollection;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Entity read(final EdmEntitySet edmEntitySet, final List<UriParameter> keys) throws DataProviderException {
|
public Entity read(final EdmEntitySet edmEntitySet, final List<UriParameter> keys) throws DataProviderException {
|
||||||
|
@ -146,7 +149,7 @@ public class DataProvider {
|
||||||
final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
|
final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
|
||||||
EntityCollection entitySet = readAll(edmEntitySet);
|
EntityCollection entitySet = readAll(edmEntitySet);
|
||||||
final List<Entity> entities = entitySet.getEntities();
|
final List<Entity> entities = entitySet.getEntities();
|
||||||
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntitySet.getEntityType());
|
final Map<String, Object> newKey = findFreeComposedKey(entities, edmEntityType);
|
||||||
Entity newEntity = new Entity();
|
Entity newEntity = new Entity();
|
||||||
newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
|
newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
|
||||||
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
|
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
|
||||||
|
@ -164,14 +167,6 @@ public class DataProvider {
|
||||||
return newEntity;
|
return newEntity;
|
||||||
}
|
}
|
||||||
|
|
||||||
private EntityCollection createEntityCollection(final EdmEntitySet edmEntitySet) {
|
|
||||||
if(data.get(edmEntitySet.getName()) == null ) {
|
|
||||||
data.put(edmEntitySet.getName(), new EntityCollection());
|
|
||||||
}
|
|
||||||
|
|
||||||
return data.get(edmEntitySet.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
|
private Map<String, Object> findFreeComposedKey(final List<Entity> entities, final EdmEntityType entityType)
|
||||||
throws DataProviderException {
|
throws DataProviderException {
|
||||||
// Weak key construction
|
// Weak key construction
|
||||||
|
@ -545,12 +540,12 @@ public class DataProvider {
|
||||||
|
|
||||||
public EntityActionResult processActionEntity(final String name, final Map<String, Parameter> actionParameters)
|
public EntityActionResult processActionEntity(final String name, final Map<String, Parameter> actionParameters)
|
||||||
throws DataProviderException {
|
throws DataProviderException {
|
||||||
return ActionData.entityAction(name, actionParameters, data);
|
return ActionData.entityAction(name, actionParameters, data, odata, edm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public EntityCollection processActionEntityCollection(final String name,
|
public EntityCollection processActionEntityCollection(final String name,
|
||||||
final Map<String, Parameter> actionParameters) throws DataProviderException {
|
final Map<String, Parameter> actionParameters) throws DataProviderException {
|
||||||
return ActionData.entityCollectionAction(name, actionParameters);
|
return ActionData.entityCollectionAction(name, actionParameters, odata, edm);
|
||||||
}
|
}
|
||||||
|
|
||||||
public void createReference(final Entity entity, final EdmNavigationProperty navigationProperty, final URI entityId,
|
public void createReference(final Entity entity, final EdmNavigationProperty navigationProperty, final URI entityId,
|
||||||
|
|
|
@ -161,7 +161,7 @@ public class ActionDataProviderTest {
|
||||||
paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 32767));
|
paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 32767));
|
||||||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
||||||
|
|
||||||
EntityActionResult result = ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data);
|
EntityActionResult result = ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data, oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertFalse(result.isCreated());
|
assertFalse(result.isCreated());
|
||||||
assertEquals((short) 32767, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
assertEquals((short) 32767, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||||
|
@ -175,7 +175,7 @@ public class ActionDataProviderTest {
|
||||||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data);
|
ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data, oData, edm);
|
||||||
fail("Expected a DataProviderException but wasn't thrown");
|
fail("Expected a DataProviderException but wasn't thrown");
|
||||||
} catch (DataProviderException e) {
|
} catch (DataProviderException e) {
|
||||||
assertEquals("Entity not found with key: 12345", e.getMessage());
|
assertEquals("Entity not found with key: 12345", e.getMessage());
|
||||||
|
@ -186,7 +186,7 @@ public class ActionDataProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void actionUARTETAllPrimParamWithoutParam() throws Exception {
|
public void actionUARTETAllPrimParamWithoutParam() throws Exception {
|
||||||
final EntityActionResult result = ActionData.entityAction("UARTETAllPrimParam",
|
final EntityActionResult result = ActionData.entityAction("UARTETAllPrimParam",
|
||||||
Collections.<String, Parameter> emptyMap(), data);
|
Collections.<String, Parameter> emptyMap(), data, oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertFalse(result.isCreated());
|
assertFalse(result.isCreated());
|
||||||
assertEquals(Short.MAX_VALUE, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
assertEquals(Short.MAX_VALUE, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||||
|
@ -199,7 +199,7 @@ public class ActionDataProviderTest {
|
||||||
paramDate.setValue(ValueType.PRIMITIVE, null);
|
paramDate.setValue(ValueType.PRIMITIVE, null);
|
||||||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterDate", paramDate);
|
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterDate", paramDate);
|
||||||
|
|
||||||
EntityActionResult result = ActionData.entityAction("UARTETAllPrimParam", parameters, data);
|
EntityActionResult result = ActionData.entityAction("UARTETAllPrimParam", parameters, data, oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertTrue(result.isCreated());
|
assertTrue(result.isCreated());
|
||||||
assertEquals((short) 1, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
assertEquals((short) 1, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||||
|
@ -212,7 +212,7 @@ public class ActionDataProviderTest {
|
||||||
paramInt16.setValue(ValueType.PRIMITIVE, Short.valueOf((short) 5));
|
paramInt16.setValue(ValueType.PRIMITIVE, Short.valueOf((short) 5));
|
||||||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
||||||
|
|
||||||
EntityCollection result = ActionData.entityCollectionAction("UARTCollETKeyNavParam", parameters);
|
EntityCollection result = ActionData.entityCollectionAction("UARTCollETKeyNavParam", parameters, oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(5, result.getEntities().size());
|
assertEquals(5, result.getEntities().size());
|
||||||
}
|
}
|
||||||
|
@ -224,7 +224,7 @@ public class ActionDataProviderTest {
|
||||||
paramTimeOfDay.setValue(ValueType.PRIMITIVE, getTime(5, 0, 0));
|
paramTimeOfDay.setValue(ValueType.PRIMITIVE, getTime(5, 0, 0));
|
||||||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterTimeOfDay", paramTimeOfDay);
|
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterTimeOfDay", paramTimeOfDay);
|
||||||
|
|
||||||
EntityCollection result = ActionData.entityCollectionAction("UARTCollETAllPrimParam", parameters);
|
EntityCollection result = ActionData.entityCollectionAction("UARTCollETAllPrimParam", parameters, oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(5, result.getEntities().size());
|
assertEquals(5, result.getEntities().size());
|
||||||
}
|
}
|
||||||
|
@ -232,7 +232,7 @@ public class ActionDataProviderTest {
|
||||||
@Test
|
@Test
|
||||||
public void actionUARTCollETAllPrimParamNoParam() throws Exception {
|
public void actionUARTCollETAllPrimParamNoParam() throws Exception {
|
||||||
final EntityCollection result = ActionData.entityCollectionAction("UARTCollETAllPrimParam",
|
final EntityCollection result = ActionData.entityCollectionAction("UARTCollETAllPrimParam",
|
||||||
Collections.<String, Parameter> emptyMap());
|
Collections.<String, Parameter> emptyMap(), oData, edm);
|
||||||
assertNotNull(result);
|
assertNotNull(result);
|
||||||
assertEquals(0, result.getEntities().size());
|
assertEquals(0, result.getEntities().size());
|
||||||
}
|
}
|
||||||
|
|
|
@ -16,25 +16,23 @@
|
||||||
* specific language governing permissions and limitations
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.server.core.deserializer.json;
|
package org.apache.olingo.server.core.deserializer;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||||
|
|
||||||
public class AbstractODataDeserializerTest {
|
public class AbstractODataDeserializerTest {
|
||||||
protected static final ContentType CONTENT_TYPE_JSON = ContentType.JSON;
|
|
||||||
protected static final ContentType CONTENT_TYPE_JSON_IEEE754Compatible =
|
|
||||||
ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true");
|
|
||||||
|
|
||||||
protected static final Edm edm = OData.newInstance().createServiceMetadata(
|
protected static final String NAMESPACE = "Namespace1_Alias";
|
||||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
protected static final Edm edm = OData.newInstance()
|
||||||
|
.createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference> emptyList())
|
||||||
|
.getEdm();
|
||||||
|
|
||||||
protected InputStream getFileAsStream(final String filename) throws IOException {
|
protected InputStream getFileAsStream(final String filename) throws IOException {
|
||||||
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
|
InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
|
|
@ -21,25 +21,24 @@ package org.apache.olingo.server.core.deserializer.json;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.IOException;
|
||||||
import java.io.InputStream;
|
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.Constants;
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.Link;
|
import org.apache.olingo.commons.api.data.Link;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
|
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTest {
|
public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrimExpandedToOne() throws Exception {
|
public void esAllPrimExpandedToOne() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOne.json");
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOne.json");
|
|
||||||
Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType).getEntity();
|
|
||||||
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimOne");
|
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimOne");
|
||||||
assertNotNull(navigationLink);
|
assertNotNull(navigationLink);
|
||||||
|
|
||||||
|
@ -51,16 +50,12 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrimExpandedToOneWithODataAnnotations() throws Exception {
|
public void esAllPrimExpandedToOneWithODataAnnotations() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithODataAnnotations.json");
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithODataAnnotations.json");
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrimExpandedToMany() throws Exception {
|
public void esAllPrimExpandedToMany() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");
|
|
||||||
Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType).getEntity();
|
|
||||||
|
|
||||||
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany");
|
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany");
|
||||||
assertNotNull(navigationLink);
|
assertNotNull(navigationLink);
|
||||||
|
@ -74,61 +69,46 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrimExpandedToManyWithODataAnnotations() throws Exception {
|
public void esAllPrimExpandedToManyWithODataAnnotations() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithODataAnnotations.json");
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithODataAnnotations.json");
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void esAllPrimExpandedToOneWithCustomAnnotations() throws Exception {
|
public void esAllPrimExpandedToOneWithCustomAnnotations() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithCustomAnnotations.json");
|
|
||||||
try {
|
try {
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithCustomAnnotations.json");
|
||||||
} catch (DeserializerException e) {
|
fail("Expected exception not thrown.");
|
||||||
|
} catch (final DeserializerException e) {
|
||||||
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
|
||||||
public void esAllPrimExpandedToManyWithCustomAnnotations() throws Exception {
|
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithCustomAnnotations.json");
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
|
||||||
public void expandedToOneInvalidNullValue() throws Exception {
|
|
||||||
String entityString =
|
|
||||||
"{\"PropertyInt16\":32767,"
|
|
||||||
+ "\"NavPropertyETTwoPrimOne\":null"
|
|
||||||
+ "}";
|
|
||||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void esAllPrimExpandedToManyWithCustomAnnotations() throws Exception {
|
||||||
|
try {
|
||||||
|
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithCustomAnnotations.json");
|
||||||
|
fail("Expected exception not thrown.");
|
||||||
|
} catch (final DeserializerException e) {
|
||||||
|
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void expandedToOneInvalidNullValue() throws Exception {
|
||||||
|
ODataJsonDeserializerEntityTest.expectException(
|
||||||
|
"{\"PropertyInt16\":32767,"
|
||||||
|
+ "\"NavPropertyETTwoPrimOne\":null"
|
||||||
|
+ "}",
|
||||||
|
"ETAllPrim",
|
||||||
|
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void expandedToOneValidNullValue() throws Exception {
|
public void expandedToOneValidNullValue() throws Exception {
|
||||||
String entityString =
|
final Entity entity = ODataJsonDeserializerEntityTest.deserialize(
|
||||||
"{\"PropertyInt16\":32767,"
|
"{\"PropertyInt16\":32767,"
|
||||||
+ "\"NavPropertyETAllPrimOne\":null"
|
+ "\"NavPropertyETAllPrimOne\":null"
|
||||||
+ "}";
|
+ "}",
|
||||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
"ETTwoPrim");
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoPrim"));
|
|
||||||
final Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType)
|
|
||||||
.getEntity();
|
|
||||||
|
|
||||||
assertEquals(1, entity.getNavigationLinks().size());
|
assertEquals(1, entity.getNavigationLinks().size());
|
||||||
final Link link = entity.getNavigationLinks().get(0);
|
final Link link = entity.getNavigationLinks().get(0);
|
||||||
|
@ -138,51 +118,38 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
||||||
assertNull(link.getInlineEntitySet());
|
assertNull(link.getInlineEntitySet());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void expandedToOneInvalidStringValue() throws Exception {
|
public void expandedToOneInvalidStringValue() throws Exception {
|
||||||
String entityString =
|
ODataJsonDeserializerEntityTest.expectException(
|
||||||
"{\"PropertyInt16\":32767,"
|
"{\"PropertyInt16\":32767,"
|
||||||
+ "\"NavPropertyETTwoPrimOne\":\"First Resource - positive values\""
|
+ "\"NavPropertyETTwoPrimOne\":\"First Resource - positive values\""
|
||||||
+ "}";
|
+ "}",
|
||||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
"ETAllPrim",
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY);
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void expandedToManyInvalidNullValue() throws Exception {
|
public void expandedToManyInvalidNullValue() throws Exception {
|
||||||
String entityString =
|
ODataJsonDeserializerEntityTest.expectException(
|
||||||
"{\"PropertyInt16\":32767,"
|
"{\"PropertyInt16\":32767,"
|
||||||
+ "\"NavPropertyETTwoPrimMany\":null"
|
+ "\"NavPropertyETTwoPrimMany\":null"
|
||||||
+ "}";
|
+ "}",
|
||||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
"ETAllPrim",
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void expandedToManyInvalidStringValue() throws Exception {
|
public void expandedToManyInvalidStringValue() throws Exception {
|
||||||
String entityString =
|
ODataJsonDeserializerEntityTest.expectException(
|
||||||
"{\"PropertyInt16\":32767,"
|
"{\"PropertyInt16\":32767,"
|
||||||
+ "\"NavPropertyETTwoPrimMany\":\"First Resource - positive values\""
|
+ "\"NavPropertyETTwoPrimMany\":\"First Resource - positive values\""
|
||||||
+ "}";
|
+ "}",
|
||||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
"ETAllPrim",
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY);
|
||||||
try {
|
}
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
private Entity deserialize(final String resourceName) throws IOException, DeserializerException {
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY, e.getMessageKey());
|
return ODataJsonDeserializerEntityTest.deserialize(getFileAsStream(resourceName),
|
||||||
throw e;
|
"ETAllPrim", ContentType.JSON);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -21,6 +21,7 @@ package org.apache.olingo.server.core.deserializer.json;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.io.InputStream;
|
import java.io.InputStream;
|
||||||
|
@ -30,22 +31,18 @@ import java.util.List;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
import org.apache.olingo.commons.api.data.EntityCollection;
|
import org.apache.olingo.commons.api.data.EntityCollection;
|
||||||
import org.apache.olingo.commons.api.data.Property;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
|
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserializerTest {
|
public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserializerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrim() throws Exception {
|
public void esAllPrim() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
final EntityCollection entitySet = deserialize(getFileAsStream("ESAllPrim.json"), "ETAllPrim");
|
||||||
InputStream stream = getFileAsStream("ESAllPrim.json");
|
|
||||||
EntityCollection entitySet =
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
|
||||||
.getEntityCollection();
|
|
||||||
|
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
assertEquals(3, entitySet.getEntities().size());
|
assertEquals(3, entitySet.getEntities().size());
|
||||||
|
|
||||||
|
@ -75,12 +72,7 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void eSCompCollComp() throws Exception {
|
public void eSCompCollComp() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompCollComp"));
|
final EntityCollection entitySet = deserialize(getFileAsStream("ESCompCollComp.json"), "ETCompCollComp");
|
||||||
InputStream stream = getFileAsStream("ESCompCollComp.json");
|
|
||||||
EntityCollection entitySet =
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
|
||||||
.getEntityCollection();
|
|
||||||
|
|
||||||
assertNotNull(entitySet);
|
assertNotNull(entitySet);
|
||||||
assertEquals(2, entitySet.getEntities().size());
|
assertEquals(2, entitySet.getEntities().size());
|
||||||
|
|
||||||
|
@ -89,172 +81,115 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void esAllPrimODataAnnotationsAreIgnored() throws Exception {
|
public void esAllPrimODataAnnotationsAreIgnored() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
deserialize(getFileAsStream("ESAllPrimWithODataAnnotations.json"), "ETAllPrim");
|
||||||
InputStream stream = getFileAsStream("ESAllPrimWithODataAnnotations.json");
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void emptyETAllPrim() throws Exception {
|
public void emptyETAllPrim() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : []}";
|
String entityCollectionString = "{\"value\" : []}";
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
final EntityCollection entityCollection = deserialize(entityCollectionString, "ETAllPrim");
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
EntityCollection entityCollection =
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
|
||||||
.getEntityCollection();
|
|
||||||
assertNotNull(entityCollection.getEntities());
|
assertNotNull(entityCollection.getEntities());
|
||||||
assertTrue(entityCollection.getEntities().isEmpty());
|
assertTrue(entityCollection.getEntities().isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void esAllPrimCustomAnnotationsLeadToNotImplemented() throws Exception {
|
public void esAllPrimCustomAnnotationsLeadToNotImplemented() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
expectException(getFileAsStream("ESAllPrimWithCustomAnnotations.json"), "ETAllPrim",
|
||||||
InputStream stream = getFileAsStream("ESAllPrimWithCustomAnnotations.json");
|
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void esAllPrimDoubleKeysLeadToException() throws Exception {
|
public void esAllPrimDoubleKeysLeadToException() throws Exception {
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
expectException(getFileAsStream("ESAllPrimWithDoubleKey.json"), "ETAllPrim",
|
||||||
InputStream stream = getFileAsStream("ESAllPrimWithDoubleKey.json");
|
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.DUPLICATE_JSON_PROPERTY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongValueTagJsonValueNull() throws Exception {
|
public void wrongValueTagJsonValueNull() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : null}";
|
expectException("{\"value\" : null}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongValueTagJsonValueNumber() throws Exception {
|
public void wrongValueTagJsonValueNumber() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : 1234}";
|
expectException("{\"value\" : 1234}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongValueTagJsonValueObject() throws Exception {
|
public void wrongValueTagJsonValueObject() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : {}}";
|
expectException("{\"value\" : {}}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void valueTagMissing() throws Exception {
|
public void valueTagMissing() throws Exception {
|
||||||
String entityCollectionString = "{}";
|
expectException("{}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.VALUE_ARRAY_NOT_PRESENT);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.VALUE_ARRAY_NOT_PRESENT, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongValueInValueArrayNumber() throws Exception {
|
public void wrongValueInValueArrayNumber() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : [1234,123]}";
|
expectException("{\"value\" : [1234,123]}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_ENTITY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongValueInValueArrayNestedArray() throws Exception {
|
public void wrongValueInValueArrayNestedArray() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : [[],[]]}";
|
expectException("{\"value\" : [[],[]]}", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.INVALID_ENTITY, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void invalidJsonSyntax() throws Exception {
|
public void invalidJsonSyntax() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : }";
|
expectException("{\"value\" : }", "ETAllPrim",
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void emptyInput() throws Exception {
|
public void emptyInput() throws Exception {
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(
|
expectException("", "ETAllPrim", DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||||
new ByteArrayInputStream(new byte[] {}),
|
|
||||||
edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void unknownContentInCollection() throws Exception {
|
public void unknownContentInCollection() throws Exception {
|
||||||
String entityCollectionString = "{\"value\" : [],"
|
expectException("{\"value\":[],\"unknown\":null}", "ETAllPrim",
|
||||||
+ "\"unknown\":null"
|
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
||||||
+ "}";
|
}
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
@Test
|
||||||
|
public void customAnnotationNotSupportedYet() throws Exception {
|
||||||
|
expectException("{\"value\": [], \"@custom.annotation\": null}", "ETAllPrim",
|
||||||
|
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityCollection deserialize(final InputStream stream, final String entityTypeName)
|
||||||
|
throws DeserializerException {
|
||||||
|
return OData.newInstance().createDeserializer(ContentType.JSON)
|
||||||
|
.entityCollection(stream, edm.getEntityType(new FullQualifiedName(NAMESPACE, entityTypeName)))
|
||||||
|
.getEntityCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private EntityCollection deserialize(final String input, final String entityTypeName)
|
||||||
|
throws DeserializerException {
|
||||||
|
return OData.newInstance().createDeserializer(ContentType.JSON)
|
||||||
|
.entityCollection(new ByteArrayInputStream(input.getBytes()),
|
||||||
|
edm.getEntityType(new FullQualifiedName(NAMESPACE, entityTypeName)))
|
||||||
|
.getEntityCollection();
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectException(final InputStream stream, final String entityTypeName,
|
||||||
|
final DeserializerException.MessageKeys messageKey) {
|
||||||
try {
|
try {
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
deserialize(stream, entityTypeName);
|
||||||
} catch (DeserializerException e) {
|
fail("Expected exception not thrown.");
|
||||||
assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
|
} catch (final DeserializerException e) {
|
||||||
throw e;
|
assertEquals(messageKey, e.getMessageKey());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
private void expectException(final String entityCollectionString, final String entityTypeName,
|
||||||
public void customAnnotationNotSupportedYet() throws Exception {
|
final DeserializerException.MessageKeys messageKey) {
|
||||||
String entityCollectionString = "{\"value\" : [],"
|
expectException(new ByteArrayInputStream(entityCollectionString.getBytes()), entityTypeName, messageKey);
|
||||||
+ "\"@custom.annotation\":null"
|
|
||||||
+ "}";
|
|
||||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
|
||||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
|
||||||
try {
|
|
||||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
|
||||||
} catch (DeserializerException e) {
|
|
||||||
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
|
||||||
throw e;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,184 +19,190 @@
|
||||||
package org.apache.olingo.server.core.deserializer.json;
|
package org.apache.olingo.server.core.deserializer.json;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
import java.util.Collections;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||||
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
|
import org.apache.olingo.commons.api.data.EntityCollection;
|
||||||
import org.apache.olingo.commons.api.data.Parameter;
|
import org.apache.olingo.commons.api.data.Parameter;
|
||||||
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmParameter;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
|
||||||
import org.apache.olingo.commons.core.edm.EdmActionImpl;
|
|
||||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
|
||||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
|
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||||
|
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
public class ODataJsonDeserializerActionParametersTest extends AbstractODataDeserializerTest {
|
public class ODataJsonDeserializerActionParametersTest extends AbstractODataDeserializerTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() throws Exception {
|
public void empty() throws Exception {
|
||||||
final String input = "{}";
|
final Map<String, Parameter> parameters = deserialize("{}", "UART", null);
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "UART");
|
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertTrue(parameters.isEmpty());
|
assertTrue(parameters.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void primitive() throws Exception {
|
public void primitive() throws Exception {
|
||||||
final String input = "{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
|
final Map<String, Parameter> parameters = deserialize(
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
"{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}",
|
||||||
|
"UARTTwoParam", null);
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
assertNotNull(parameter);
|
assertNotNull(parameter);
|
||||||
|
assertTrue(parameter.isPrimitive());
|
||||||
|
assertFalse(parameter.isCollection());
|
||||||
assertEquals((short) 42, parameter.getValue());
|
assertEquals((short) 42, parameter.getValue());
|
||||||
parameter = parameters.get("ParameterDuration");
|
parameter = parameters.get("ParameterDuration");
|
||||||
assertNotNull(parameter);
|
assertNotNull(parameter);
|
||||||
assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
|
assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primitiveCollection() throws Exception {
|
||||||
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
|
when(parameter.getType()).thenReturn(
|
||||||
|
OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration));
|
||||||
|
when(parameter.isCollection()).thenReturn(true);
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
|
|
||||||
|
final String input = "{\"Parameter\": [ \"PT0S\", \"PT42S\", \"PT1H2M3S\" ]}";
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
|
assertNotNull(parameters);
|
||||||
|
assertEquals(1, parameters.size());
|
||||||
|
Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isPrimitive());
|
||||||
|
assertTrue(parameterData.isCollection());
|
||||||
|
assertEquals(BigDecimal.ZERO, parameterData.asCollection().get(0));
|
||||||
|
assertEquals(BigDecimal.valueOf(42), parameterData.asCollection().get(1));
|
||||||
|
assertEquals(BigDecimal.valueOf(3723), parameterData.asCollection().get(2));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void complex() throws Exception {
|
public void complex() throws Exception {
|
||||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
CsdlComplexType address = new CsdlComplexType();
|
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
EdmAction action = mock(EdmAction.class);
|
||||||
createProperty("Zip", "Edm.Int32")));
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
address.setName("Address");
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
EdmComplexTypeImpl edmAddress = new EdmComplexTypeImpl(provider,
|
|
||||||
new FullQualifiedName("namespace.Address"), address);
|
|
||||||
Mockito.stub(provider.getComplexType(Mockito.any(FullQualifiedName.class))).toReturn(edmAddress);
|
|
||||||
|
|
||||||
List<CsdlParameter> parameters = new ArrayList<CsdlParameter>();
|
final String input = "{\"Parameter\": { \"PropertyString\": \"Yes\", \"PropertyInt16\": 42 }}";
|
||||||
parameters.add(createParam("param1", "Edm.Int16"));
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
parameters.add(createParam("param2", "namespace.Address"));
|
|
||||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
|
||||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
|
||||||
|
|
||||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
assertNotNull(parameters);
|
||||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
assertEquals(1, parameters.size());
|
||||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
final Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
final String input = "{\n" +
|
assertTrue(parameterData.isComplex());
|
||||||
" \"param1\": 42,\n" +
|
assertFalse(parameterData.isCollection());
|
||||||
" \"param2\": {\n" +
|
final List<Property> complexValues = parameterData.asComplex().getValue();
|
||||||
" \"Street\": \"One Microsoft Way\",\n" +
|
assertEquals((short) 42, complexValues.get(0).getValue());
|
||||||
" \"Zip\": 98052\n" +
|
assertEquals("Yes", complexValues.get(1).getValue());
|
||||||
" },\n" +
|
|
||||||
" \"param3\": [ 1, 42, 99 ],\n" +
|
|
||||||
" \"param4\": null\n" +
|
|
||||||
"}";
|
|
||||||
final Map<String, Parameter> response = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action).getActionParameters();
|
|
||||||
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(4, response.size());
|
|
||||||
Parameter parameter = response.get("param1");
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals((short) 42, parameter.getValue());
|
|
||||||
parameter = response.get("param2");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
ComplexValue addressValue = (ComplexValue)parameter.getValue();
|
|
||||||
assertEquals("Street", addressValue.getValue().get(0).getName());
|
|
||||||
assertEquals("One Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals("Zip", addressValue.getValue().get(1).getName());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param3");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
assertEquals(Arrays.asList(1, 42, 99), parameter.getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param4");
|
|
||||||
assertNull(parameter.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void complexCollection() throws Exception {
|
public void complexCollection() throws Exception {
|
||||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
CsdlComplexType address = new CsdlComplexType();
|
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
when(parameter.isCollection()).thenReturn(true);
|
||||||
createProperty("Zip", "Edm.Int32")));
|
EdmAction action = mock(EdmAction.class);
|
||||||
address.setName("Address");
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
EdmComplexTypeImpl edmAddress = new EdmComplexTypeImpl(provider,
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
new FullQualifiedName("namespace.Address"), address);
|
|
||||||
Mockito.stub(provider.getComplexType(Mockito.any(FullQualifiedName.class))).toReturn(edmAddress);
|
|
||||||
|
|
||||||
List<CsdlParameter> parameters = new ArrayList<CsdlParameter>();
|
final String input = "{\"Parameter\": [\n"
|
||||||
parameters.add(createParam("param1", "Edm.Int16"));
|
+ " { \"PropertyInt16\": 9999, \"PropertyString\": \"One\" },\n"
|
||||||
parameters.add(createParam("param2", "namespace.Address").setCollection(true));
|
+ " { \"PropertyInt16\": -123, \"PropertyString\": \"Two\" }]}";
|
||||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
|
||||||
|
|
||||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
assertNotNull(parameters);
|
||||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
assertEquals(1, parameters.size());
|
||||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isComplex());
|
||||||
|
assertTrue(parameterData.isCollection());
|
||||||
|
ComplexValue complexValue = (ComplexValue) parameterData.asCollection().get(0);
|
||||||
|
assertEquals((short) 9999, complexValue.getValue().get(0).getValue());
|
||||||
|
assertEquals("One", complexValue.getValue().get(1).getValue());
|
||||||
|
|
||||||
final String input = "{\n" +
|
complexValue = (ComplexValue) parameterData.asCollection().get(1);
|
||||||
" \"param1\": 42,\n" +
|
assertEquals((short) -123, complexValue.getValue().get(0).getValue());
|
||||||
" \"param2\": [{\n" +
|
assertEquals("Two", complexValue.getValue().get(1).getValue());
|
||||||
" \"Street\": \"One Microsoft Way\",\n" +
|
|
||||||
" \"Zip\": 98052\n" +
|
|
||||||
" },\n" +
|
|
||||||
" {\n" +
|
|
||||||
" \"Street\": \"Two Microsoft Way\",\n" +
|
|
||||||
" \"Zip\": 98052\n" +
|
|
||||||
" }],\n" +
|
|
||||||
" \"param3\": [ 1, 42, 99 ],\n" +
|
|
||||||
" \"param4\": null\n" +
|
|
||||||
"}";
|
|
||||||
final Map<String, Parameter> response = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action).getActionParameters();
|
|
||||||
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(4, response.size());
|
|
||||||
Parameter parameter = response.get("param1");
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals((short) 42, parameter.getValue());
|
|
||||||
parameter = response.get("param2");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
ComplexValue addressValue = (ComplexValue)((List<?>)parameter.getValue()).get(0);
|
|
||||||
assertEquals("One Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
addressValue = (ComplexValue)((List<?>)parameter.getValue()).get(1);
|
|
||||||
assertEquals("Two Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param3");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
assertEquals(Arrays.asList(1, 42, 99), parameter.getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param4");
|
|
||||||
assertNull(parameter.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private CsdlParameter createParam(String name, String type) {
|
@Test
|
||||||
return new CsdlParameter().setName(name).setType(new FullQualifiedName(type));
|
public void entity() throws Exception {
|
||||||
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
|
when(parameter.getType()).thenReturn(edm.getEntityType(new FullQualifiedName(NAMESPACE, "ETTwoPrim")));
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
|
|
||||||
|
final String input = "{\"Parameter\": { \"PropertyInt16\": 42, \"PropertyString\": \"Yes\" }}";
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
|
assertNotNull(parameters);
|
||||||
|
assertEquals(1, parameters.size());
|
||||||
|
final Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isEntity());
|
||||||
|
assertFalse(parameterData.isCollection());
|
||||||
|
final List<Property> entityValues = parameterData.asEntity().getProperties();
|
||||||
|
assertEquals((short) 42, entityValues.get(0).getValue());
|
||||||
|
assertEquals("Yes", entityValues.get(1).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
private CsdlProperty createProperty(String name, String type) {
|
@Test
|
||||||
return new CsdlProperty().setName(name).setType(type);
|
public void entityCollection() throws Exception {
|
||||||
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
|
when(parameter.getType()).thenReturn(edm.getEntityType(new FullQualifiedName(NAMESPACE, "ETTwoPrim")));
|
||||||
|
when(parameter.isCollection()).thenReturn(true);
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
|
|
||||||
|
final String input = "{\"Parameter\": [\n"
|
||||||
|
+ " { \"PropertyInt16\": 1234, \"PropertyString\": \"One\" },\n"
|
||||||
|
+ " { \"PropertyInt16\": -321, \"PropertyString\": \"Two\" }]}";
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
|
assertNotNull(parameters);
|
||||||
|
assertEquals(1, parameters.size());
|
||||||
|
Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isEntity());
|
||||||
|
assertTrue(parameterData.isCollection());
|
||||||
|
Entity entity = ((EntityCollection) parameterData.getValue()).getEntities().get(0);
|
||||||
|
assertEquals((short) 1234, entity.getProperties().get(0).getValue());
|
||||||
|
assertEquals("One", entity.getProperties().get(1).getValue());
|
||||||
|
|
||||||
|
entity = ((EntityCollection) parameterData.getValue()).getEntities().get(1);
|
||||||
|
assertEquals((short) -321, entity.getProperties().get(0).getValue());
|
||||||
|
assertEquals("Two", entity.getProperties().get(1).getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void boundEmpty() throws Exception {
|
public void boundEmpty() throws Exception {
|
||||||
final String input = "{}";
|
final Map<String, Parameter> parameters = deserialize("{}", "BAETAllPrimRT", "ETAllPrim");
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertTrue(parameters.isEmpty());
|
assertTrue(parameters.isEmpty());
|
||||||
}
|
}
|
||||||
|
@ -206,7 +212,7 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
||||||
final String input =
|
final String input =
|
||||||
"{\"ParameterDuration@odata.type\":\"Edm.Duration\","
|
"{\"ParameterDuration@odata.type\":\"Edm.Duration\","
|
||||||
+ "\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
|
+ "\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam", null);
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
|
@ -218,9 +224,9 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParameterWithNullLiteral() throws Exception {
|
public void parameterWithNullLiteral() throws Exception {
|
||||||
final Map<String, Parameter> parameters = deserialize("{\"ParameterInt16\":1,\"ParameterDuration\":null}",
|
final Map<String, Parameter> parameters = deserialize("{\"ParameterInt16\":1,\"ParameterDuration\":null}",
|
||||||
"UARTCollStringTwoParam");
|
"UARTCollStringTwoParam", null);
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
|
@ -231,52 +237,60 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
||||||
assertEquals(null, parameter.getValue());
|
assertEquals(null, parameter.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void noContent() throws Exception {
|
public void noContent() throws Exception {
|
||||||
deserialize("", "BAETAllPrimRT", "ETAllPrim");
|
expectException("", "UARTTwoParam", null, MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||||
|
expectException("", "BAETAllPrimRT", "ETAllPrim", MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void bindingParameter() throws Exception {
|
public void bindingParameter() throws Exception {
|
||||||
deserialize("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim");
|
expectException("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim",
|
||||||
|
MessageKeys.UNKNOWN_CONTENT);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongName() throws Exception {
|
|
||||||
deserialize("{\"ParameterWrong\":null}", "UARTParam");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
|
||||||
public void nullNotNullable() throws Exception {
|
|
||||||
deserialize("{\"ParameterInt16\":null}", "UARTCTTwoPrimParam");
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
|
||||||
public void missingParameter() throws Exception {
|
public void missingParameter() throws Exception {
|
||||||
deserialize("{}", "UARTCTTwoPrimParam");
|
expectException("{\"ParameterWrong\":null}", "UARTParam", null, MessageKeys.UNKNOWN_CONTENT);
|
||||||
|
expectException("{}", "UARTCTTwoPrimParam", null, MessageKeys.INVALID_NULL_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void parameterTwice() throws Exception {
|
public void parameterTwice() throws Exception {
|
||||||
deserialize("{\"ParameterInt16\":1,\"ParameterInt16\":2}", "UARTParam");
|
expectException("{\"ParameterInt16\":1,\"ParameterInt16\":2}", "UARTParam", null, MessageKeys.DUPLICATE_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongType() throws Exception {
|
public void wrongType() throws Exception {
|
||||||
deserialize("{\"ParameterInt16\":\"42\"}", "UARTParam");
|
expectException("{\"ParameterInt16\":null}", "UARTCTTwoPrimParam", null, MessageKeys.INVALID_NULL_PARAMETER);
|
||||||
|
expectException("{\"ParameterInt16\":\"42\"}", "UARTParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||||
|
expectException("{\"ParameterInt16\":123456}", "UARTParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||||
|
expectException("{\"ParameterInt16\":[42]}", "UARTParam", null, MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
|
private Map<String, Parameter> deserialize(final String input, final EdmAction action) throws DeserializerException {
|
||||||
return OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
return OData.newInstance().createDeserializer(ContentType.JSON)
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
.actionParameters(new ByteArrayInputStream(input.getBytes()), action)
|
||||||
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
|
.getActionParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Parameter> deserialize(final String input, final String actionName, final String typeName)
|
private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName)
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
return OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
return deserialize(input,
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
bindingTypeName == null ?
|
||||||
edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
|
edm.getUnboundAction(new FullQualifiedName(NAMESPACE, actionName)) :
|
||||||
new FullQualifiedName("Namespace1_Alias", typeName), false)).getActionParameters();
|
edm.getBoundAction(new FullQualifiedName(NAMESPACE, actionName),
|
||||||
|
new FullQualifiedName(NAMESPACE, bindingTypeName),
|
||||||
|
false));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectException(final String input, final String actionName, final String bindingTypeName,
|
||||||
|
final DeserializerException.MessageKeys messageKey) {
|
||||||
|
try {
|
||||||
|
deserialize(input, actionName, bindingTypeName);
|
||||||
|
fail("Expected exception not thrown.");
|
||||||
|
} catch (final DeserializerException e) {
|
||||||
|
assertEquals(messageKey, e.getMessageKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -19,58 +19,56 @@
|
||||||
package org.apache.olingo.server.core.deserializer.xml;
|
package org.apache.olingo.server.core.deserializer.xml;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
import java.math.BigDecimal;
|
import java.math.BigDecimal;
|
||||||
import java.util.ArrayList;
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
|
import org.apache.olingo.commons.api.Constants;
|
||||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||||
import org.apache.olingo.commons.api.data.Parameter;
|
import org.apache.olingo.commons.api.data.Parameter;
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.data.Property;
|
||||||
import org.apache.olingo.commons.api.edm.EdmAction;
|
import org.apache.olingo.commons.api.edm.EdmAction;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmParameter;
|
||||||
|
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlAction;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
|
|
||||||
import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
|
||||||
import org.apache.olingo.commons.api.format.ContentType;
|
import org.apache.olingo.commons.api.format.ContentType;
|
||||||
import org.apache.olingo.commons.core.edm.EdmActionImpl;
|
|
||||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
|
||||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
|
||||||
import org.apache.olingo.server.api.OData;
|
import org.apache.olingo.server.api.OData;
|
||||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
|
||||||
|
|
||||||
public class ODataXMLDeserializerActionParametersTest {
|
public class ODataXMLDeserializerActionParametersTest extends AbstractODataDeserializerTest {
|
||||||
|
|
||||||
|
private static final String PREAMBLE = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||||
|
+ "<metadata:parameters xmlns:data=\"" + Constants.NS_DATASERVICES + "\""
|
||||||
|
+ " xmlns:metadata=\"" + Constants.NS_METADATA + "\">";
|
||||||
|
private static final String POSTAMBLE = "</metadata:parameters>";
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void empty() throws Exception {
|
public void empty() throws Exception {
|
||||||
final String input = "";
|
final Map<String, Parameter> parameters = deserialize(PREAMBLE + POSTAMBLE, "UART", null);
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "UART");
|
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertTrue(parameters.isEmpty());
|
assertTrue(parameters.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void primitive() throws Exception {
|
public void primitive() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
final String input = PREAMBLE
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
|
||||||
+"<ParameterInt16>42</ParameterInt16>"
|
|
||||||
+ "<ParameterDuration>P42DT11H22M33S</ParameterDuration>"
|
+ "<ParameterDuration>P42DT11H22M33S</ParameterDuration>"
|
||||||
+"</metadata:parameters>";
|
+ "<ParameterInt16>42</ParameterInt16>"
|
||||||
|
+ POSTAMBLE;
|
||||||
|
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam", null);
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
|
@ -81,157 +79,114 @@ public class ODataXMLDeserializerActionParametersTest {
|
||||||
assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
|
assertEquals(BigDecimal.valueOf(3669753), parameter.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primitiveCollection() throws Exception {
|
||||||
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
|
when(parameter.getType()).thenReturn(
|
||||||
|
OData.newInstance().createPrimitiveTypeInstance(EdmPrimitiveTypeKind.Duration));
|
||||||
|
when(parameter.isCollection()).thenReturn(true);
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
|
|
||||||
|
final String input = PREAMBLE
|
||||||
|
+ "<Parameter>"
|
||||||
|
+ "<metadata:element>PT0S</metadata:element>"
|
||||||
|
+ "<metadata:element>PT42S</metadata:element>"
|
||||||
|
+ "<metadata:element>PT1H2M3S</metadata:element>"
|
||||||
|
+ "</Parameter>"
|
||||||
|
+ POSTAMBLE;
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
|
assertNotNull(parameters);
|
||||||
|
assertEquals(1, parameters.size());
|
||||||
|
Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isPrimitive());
|
||||||
|
assertTrue(parameterData.isCollection());
|
||||||
|
assertEquals(BigDecimal.ZERO, parameterData.asCollection().get(0));
|
||||||
|
assertEquals(BigDecimal.valueOf(42), parameterData.asCollection().get(1));
|
||||||
|
assertEquals(BigDecimal.valueOf(3723), parameterData.asCollection().get(2));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void complex() throws Exception {
|
public void complex() throws Exception {
|
||||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
CsdlComplexType address = new CsdlComplexType();
|
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
EdmAction action = mock(EdmAction.class);
|
||||||
createProperty("Zip", "Edm.Int32")));
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
address.setName("Address");
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
EdmComplexTypeImpl edmAddress = new EdmComplexTypeImpl(provider,
|
|
||||||
new FullQualifiedName("namespace.Address"), address);
|
|
||||||
Mockito.stub(provider.getComplexType(Mockito.any(FullQualifiedName.class))).toReturn(edmAddress);
|
|
||||||
|
|
||||||
List<CsdlParameter> parameters = new ArrayList<CsdlParameter>();
|
final String input = PREAMBLE
|
||||||
parameters.add(createParam("param1", "Edm.Int16"));
|
+ "<Parameter>"
|
||||||
parameters.add(createParam("param2", "namespace.Address"));
|
+ "<PropertyInt16>42</PropertyInt16>"
|
||||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
+ "<PropertyString>Yes</PropertyString>"
|
||||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
+ "</Parameter>"
|
||||||
|
+ POSTAMBLE;
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
assertNotNull(parameters);
|
||||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
assertEquals(1, parameters.size());
|
||||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
final Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>" +
|
assertTrue(parameterData.isComplex());
|
||||||
"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">\n" +
|
assertFalse(parameterData.isCollection());
|
||||||
" <param1>42</param1>\n" +
|
final List<Property> complexValues = parameterData.asComplex().getValue();
|
||||||
" <param2 metadata:type=\"#namespace.Address\">\n" +
|
assertEquals((short) 42, complexValues.get(0).getValue());
|
||||||
" <Street>One Microsoft Way</Street>\n" +
|
assertEquals("Yes", complexValues.get(1).getValue());
|
||||||
" <Zip>98052</Zip>\n" +
|
|
||||||
" </param2>\n" +
|
|
||||||
" <param3>\n" +
|
|
||||||
" <element>1</element>\n" +
|
|
||||||
" <element>42</element>\n" +
|
|
||||||
" <element>99</element>\n" +
|
|
||||||
" </param3>\n" +
|
|
||||||
" <param4 metadata:null=\"true\"/>\n" +
|
|
||||||
"</metadata:parameters>";
|
|
||||||
final Map<String, Parameter> response = OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action).getActionParameters();
|
|
||||||
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(4, response.size());
|
|
||||||
Parameter parameter = response.get("param1");
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals((short) 42, parameter.getValue());
|
|
||||||
parameter = response.get("param2");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
ComplexValue addressValue = (ComplexValue)parameter.getValue();
|
|
||||||
assertEquals("Street", addressValue.getValue().get(0).getName());
|
|
||||||
assertEquals("One Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals("Zip", addressValue.getValue().get(1).getName());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param3");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
assertEquals(Arrays.asList(1, 42, 99), parameter.getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param4");
|
|
||||||
assertNull(parameter.getValue());
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void complexCollection() throws Exception {
|
public void complexCollection() throws Exception {
|
||||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
EdmParameter parameter = mock(EdmParameter.class);
|
||||||
CsdlComplexType address = new CsdlComplexType();
|
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
when(parameter.isCollection()).thenReturn(true);
|
||||||
createProperty("Zip", "Edm.Int32")));
|
EdmAction action = mock(EdmAction.class);
|
||||||
address.setName("Address");
|
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||||
EdmComplexTypeImpl edmAddress = new EdmComplexTypeImpl(provider,
|
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||||
new FullQualifiedName("namespace.Address"), address);
|
|
||||||
Mockito.stub(provider.getComplexType(Mockito.any(FullQualifiedName.class))).toReturn(edmAddress);
|
|
||||||
|
|
||||||
List<CsdlParameter> parameters = new ArrayList<CsdlParameter>();
|
final String input = PREAMBLE
|
||||||
parameters.add(createParam("param1", "Edm.Int16"));
|
+ "<Parameter>"
|
||||||
parameters.add(createParam("param2", "namespace.Address").setCollection(true));
|
+ "<metadata:element>"
|
||||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
+ "<PropertyInt16>9999</PropertyInt16><PropertyString>One</PropertyString>"
|
||||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
+ "</metadata:element>"
|
||||||
|
+ "<metadata:element>"
|
||||||
|
+ "<PropertyInt16>-123</PropertyInt16><PropertyString>Two</PropertyString>"
|
||||||
|
+ "</metadata:element>"
|
||||||
|
+ "</Parameter>"
|
||||||
|
+ POSTAMBLE;
|
||||||
|
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||||
|
|
||||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
assertNotNull(parameters);
|
||||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
assertEquals(1, parameters.size());
|
||||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
Parameter parameterData = parameters.get("Parameter");
|
||||||
|
assertNotNull(parameterData);
|
||||||
|
assertTrue(parameterData.isComplex());
|
||||||
|
assertTrue(parameterData.isCollection());
|
||||||
|
ComplexValue complexValue = (ComplexValue) parameterData.asCollection().get(0);
|
||||||
|
assertEquals((short) 9999, complexValue.getValue().get(0).getValue());
|
||||||
|
assertEquals("One", complexValue.getValue().get(1).getValue());
|
||||||
|
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>" +
|
complexValue = (ComplexValue) parameterData.asCollection().get(1);
|
||||||
"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">\n" +
|
assertEquals((short) -123, complexValue.getValue().get(0).getValue());
|
||||||
" <param1>42</param1>\n" +
|
assertEquals("Two", complexValue.getValue().get(1).getValue());
|
||||||
" <param2 metadata:type=\"#namespace.Address\">\n" +
|
|
||||||
" <element>" +
|
|
||||||
" <Street>One Microsoft Way</Street>\n" +
|
|
||||||
" <Zip>98052</Zip>\n" +
|
|
||||||
" </element>" +
|
|
||||||
" <element>" +
|
|
||||||
" <Street>Two Microsoft Way</Street>\n" +
|
|
||||||
" <Zip>98052</Zip>\n" +
|
|
||||||
" </element>" +
|
|
||||||
" </param2>\n" +
|
|
||||||
" <param3>\n" +
|
|
||||||
" <element>1</element>\n" +
|
|
||||||
" <element>42</element>\n" +
|
|
||||||
" <element>99</element>\n" +
|
|
||||||
" </param3>\n" +
|
|
||||||
" <param4 metadata:null=\"true\"/>\n" +
|
|
||||||
"</metadata:parameters>";
|
|
||||||
final Map<String, Parameter> response = OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action).getActionParameters();
|
|
||||||
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals(4, response.size());
|
|
||||||
Parameter parameter = response.get("param1");
|
|
||||||
assertNotNull(response);
|
|
||||||
assertEquals((short) 42, parameter.getValue());
|
|
||||||
parameter = response.get("param2");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
ComplexValue addressValue = (ComplexValue)((List<?>)parameter.getValue()).get(0);
|
|
||||||
assertEquals("One Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
addressValue = (ComplexValue)((List<?>)parameter.getValue()).get(1);
|
|
||||||
assertEquals("Two Microsoft Way", addressValue.getValue().get(0).getValue());
|
|
||||||
assertEquals(98052, addressValue.getValue().get(1).getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param3");
|
|
||||||
assertNotNull(parameter);
|
|
||||||
assertEquals(Arrays.asList(1, 42, 99), parameter.getValue());
|
|
||||||
|
|
||||||
parameter = response.get("param4");
|
|
||||||
assertNull(parameter.getValue());
|
|
||||||
}
|
|
||||||
|
|
||||||
private CsdlParameter createParam(String name, String type) {
|
|
||||||
return new CsdlParameter().setName(name).setType(new FullQualifiedName(type));
|
|
||||||
}
|
|
||||||
|
|
||||||
private CsdlProperty createProperty(String name, String type) {
|
|
||||||
return new CsdlProperty().setName(name).setType(type);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void boundEmpty() throws Exception {
|
public void boundEmpty() throws Exception {
|
||||||
final String input = "";
|
final Map<String, Parameter> parameters = deserialize(PREAMBLE + POSTAMBLE,
|
||||||
final Map<String, Parameter> parameters = deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
"BAETAllPrimRT", "ETAllPrim");
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertTrue(parameters.isEmpty());
|
assertTrue(parameters.isEmpty());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testParameterWithNullLiteral() throws Exception {
|
public void parameterWithNullLiteral() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
final String input = PREAMBLE
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
|
||||||
+ "<ParameterInt16>1</ParameterInt16>"
|
+ "<ParameterInt16>1</ParameterInt16>"
|
||||||
+"</metadata:parameters>";
|
+ "<ParameterDuration metadata:null=\"true\" />"
|
||||||
|
+ POSTAMBLE;
|
||||||
final Map<String, Parameter> parameters = deserialize(input,
|
final Map<String, Parameter> parameters = deserialize(input, "UARTCollStringTwoParam", null);
|
||||||
"UARTCollStringTwoParam");
|
|
||||||
assertNotNull(parameters);
|
assertNotNull(parameters);
|
||||||
assertEquals(2, parameters.size());
|
assertEquals(2, parameters.size());
|
||||||
Parameter parameter = parameters.get("ParameterInt16");
|
Parameter parameter = parameters.get("ParameterInt16");
|
||||||
|
@ -244,60 +199,59 @@ public class ODataXMLDeserializerActionParametersTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void bindingParameter() throws Exception {
|
public void bindingParameter() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
final String input = PREAMBLE + "<ParameterETAllPrim>1</ParameterETAllPrim>" + POSTAMBLE;
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
|
||||||
+"<ParameterETAllPrim>1</ParameterETAllPrim>"
|
|
||||||
+"</metadata:parameters>";
|
|
||||||
deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void wrongName() throws Exception {
|
public void wrongName() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
expectException(PREAMBLE + "<ParameterWrong>1</ParameterWrong>" + POSTAMBLE,
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
"UARTParam", null, MessageKeys.UNKNOWN_CONTENT);
|
||||||
+"<ParameterWrong>1</ParameterWrong>"
|
|
||||||
+"</metadata:parameters>";
|
|
||||||
deserialize(input, "UARTParam");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void nullNotNullable() throws Exception {
|
public void nullNotNullable() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
expectException(PREAMBLE + "<ParameterInt16>null</ParameterInt16>" + POSTAMBLE,
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
"UARTCTTwoPrimParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||||
+"<ParameterInt16>null</ParameterInt16>"
|
|
||||||
+"</metadata:parameters>";
|
|
||||||
deserialize(input, "UARTCTTwoPrimParam");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void missingParameter() throws Exception {
|
public void missingParameter() throws Exception {
|
||||||
deserialize("", "UARTCTTwoPrimParam");
|
expectException(PREAMBLE + POSTAMBLE, "UARTCTTwoPrimParam", null, MessageKeys.INVALID_NULL_PARAMETER);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = DeserializerException.class)
|
@Test
|
||||||
public void parameterTwice() throws Exception {
|
public void parameterTwice() throws Exception {
|
||||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
expectException(PREAMBLE
|
||||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
|
||||||
+ "<ParameterInt16>1</ParameterInt16>"
|
+ "<ParameterInt16>1</ParameterInt16>"
|
||||||
+ "<ParameterInt16>2</ParameterInt16>"
|
+ "<ParameterInt16>2</ParameterInt16>"
|
||||||
+"</metadata:parameters>";
|
+ POSTAMBLE,
|
||||||
deserialize(input, "UARTParam");
|
"UARTParam", null, MessageKeys.DUPLICATE_PROPERTY);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected static final Edm edm = OData.newInstance().createServiceMetadata(
|
private Map<String, Parameter> deserialize(final String input, final EdmAction action) throws DeserializerException {
|
||||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
|
||||||
|
|
||||||
private Map<String, Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
|
|
||||||
return OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
return OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
.actionParameters(new ByteArrayInputStream(input.getBytes()), action)
|
||||||
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
|
.getActionParameters();
|
||||||
}
|
}
|
||||||
|
|
||||||
private Map<String, Parameter> deserialize(final String input, final String actionName, final String typeName)
|
private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName)
|
||||||
throws DeserializerException {
|
throws DeserializerException {
|
||||||
return OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
return deserialize(input,
|
||||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
bindingTypeName == null ?
|
||||||
edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
|
edm.getUnboundAction(new FullQualifiedName(NAMESPACE, actionName)) :
|
||||||
new FullQualifiedName("Namespace1_Alias", typeName), false)).getActionParameters();
|
edm.getBoundAction(new FullQualifiedName(NAMESPACE, actionName),
|
||||||
|
new FullQualifiedName(NAMESPACE, bindingTypeName),
|
||||||
|
false));
|
||||||
|
}
|
||||||
|
|
||||||
|
private void expectException(final String input, final String actionName, final String bindingTypeName,
|
||||||
|
final DeserializerException.MessageKeys messageKey) {
|
||||||
|
try {
|
||||||
|
deserialize(input, actionName, bindingTypeName);
|
||||||
|
fail("Expected exception not thrown.");
|
||||||
|
} catch (final DeserializerException e) {
|
||||||
|
assertEquals(messageKey, e.getMessageKey());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,10 +19,11 @@
|
||||||
package org.apache.olingo.server.core.deserializer.xml;
|
package org.apache.olingo.server.core.deserializer.xml;
|
||||||
|
|
||||||
import java.io.ByteArrayInputStream;
|
import java.io.ByteArrayInputStream;
|
||||||
|
import java.math.BigDecimal;
|
||||||
import java.net.URI;
|
import java.net.URI;
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
import java.util.Collections;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
import java.util.UUID;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||||
import org.apache.olingo.commons.api.data.Entity;
|
import org.apache.olingo.commons.api.data.Entity;
|
||||||
|
@ -40,38 +41,21 @@ import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
||||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||||
import org.apache.olingo.commons.core.edm.EdmPropertyImpl;
|
import org.apache.olingo.commons.core.edm.EdmPropertyImpl;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
|
import org.apache.olingo.commons.core.edm.primitivetype.EdmBinary;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmByte;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDecimal;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDouble;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmDuration;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmGuid;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt16;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt32;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmInt64;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSByte;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmSingle;
|
|
||||||
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
import org.apache.olingo.commons.core.edm.primitivetype.EdmTimeOfDay;
|
||||||
import org.apache.olingo.server.api.ServiceMetadata;
|
|
||||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||||
import org.apache.olingo.server.core.ServiceMetadataImpl;
|
|
||||||
import org.apache.olingo.server.core.deserializer.xml.ODataXmlDeserializer;
|
|
||||||
import org.apache.olingo.server.tecsvc.MetadataETagSupport;
|
|
||||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
|
||||||
import org.custommonkey.xmlunit.XMLUnit;
|
import org.custommonkey.xmlunit.XMLUnit;
|
||||||
import org.junit.Assert;
|
import org.junit.Assert;
|
||||||
import org.junit.BeforeClass;
|
import org.junit.BeforeClass;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.mockito.Mockito;
|
import org.mockito.Mockito;
|
||||||
|
|
||||||
public class ODataXmlDeserializerTest {
|
public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
||||||
|
|
||||||
private static final ServiceMetadata metadata = new ServiceMetadataImpl(
|
private static final EdmEntityContainer entityContainer = edm.getEntityContainer();
|
||||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("WmetadataETag"));
|
private final ODataDeserializer deserializer = new ODataXmlDeserializer();
|
||||||
private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer();
|
|
||||||
private final ODataDeserializer serializer = new ODataXmlDeserializer();
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void setup() {
|
public static void setup() {
|
||||||
|
@ -82,60 +66,20 @@ public class ODataXmlDeserializerTest {
|
||||||
XMLUnit.setCompareUnmatched(false);
|
XMLUnit.setCompareUnmatched(false);
|
||||||
}
|
}
|
||||||
|
|
||||||
protected Object edmInt16(String value) throws EdmPrimitiveTypeException {
|
protected byte[] edmBinary(String value) throws EdmPrimitiveTypeException {
|
||||||
return EdmInt16.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
return EdmBinary.getInstance().valueOfString(value, true, null, null, null, true,
|
||||||
EdmInt16.getInstance().getDefaultType());
|
byte[].class);
|
||||||
}
|
|
||||||
protected Object edmInt32(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmInt32.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmInt32.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmInt64(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmInt64.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmInt64.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmSingle(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmSingle.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmSingle.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmDouble(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmDouble.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmDouble.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmSByte(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmSByte.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmSByte.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmByte(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmByte.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmByte.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmDecimal(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmDecimal.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmDecimal.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmBinary(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmBinary.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmBinary.getInstance().getDefaultType());
|
|
||||||
}
|
}
|
||||||
protected Object edmDate(String value) throws EdmPrimitiveTypeException {
|
protected Object edmDate(String value) throws EdmPrimitiveTypeException {
|
||||||
return EdmDate.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
return EdmDate.getInstance().valueOfString(value, true, null, null, null, true,
|
||||||
EdmDate.getInstance().getDefaultType());
|
EdmDate.getInstance().getDefaultType());
|
||||||
}
|
}
|
||||||
protected Object edmDateTimeOffset(String value) throws EdmPrimitiveTypeException {
|
protected Object edmDateTimeOffset(String value) throws EdmPrimitiveTypeException {
|
||||||
return EdmDateTimeOffset.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
return EdmDateTimeOffset.getInstance().valueOfString(value, true, null, null, null, true,
|
||||||
EdmDateTimeOffset.getInstance().getDefaultType());
|
EdmDateTimeOffset.getInstance().getDefaultType());
|
||||||
}
|
}
|
||||||
protected Object edmDuration(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmDuration.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmDuration.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmGUID(String value) throws EdmPrimitiveTypeException {
|
|
||||||
return EdmGuid.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
|
||||||
EdmGuid.getInstance().getDefaultType());
|
|
||||||
}
|
|
||||||
protected Object edmTimeOfDay(String value) throws EdmPrimitiveTypeException {
|
protected Object edmTimeOfDay(String value) throws EdmPrimitiveTypeException {
|
||||||
return EdmTimeOfDay.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
return EdmTimeOfDay.getInstance().valueOfString(value, true, null, null, null, true,
|
||||||
EdmTimeOfDay.getInstance().getDefaultType());
|
EdmTimeOfDay.getInstance().getDefaultType());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -179,29 +123,28 @@ public class ODataXmlDeserializerTest {
|
||||||
" </atom:content>\n" +
|
" </atom:content>\n" +
|
||||||
"</atom:entry>\n";
|
"</atom:entry>\n";
|
||||||
|
|
||||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||||
edmEntitySet.getEntityType()).getEntity();
|
edmEntitySet.getEntityType()).getEntity();
|
||||||
|
|
||||||
Assert.assertEquals(16, result.getProperties().size());
|
Assert.assertEquals(16, result.getProperties().size());
|
||||||
Assert.assertEquals(2, result.getNavigationBindings().size());
|
Assert.assertEquals(2, result.getNavigationBindings().size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("32767"), result.getProperty("PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 32767, result.getProperty("PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("First Resource - positive values", result.getProperty("PropertyString").asPrimitive());
|
Assert.assertEquals("First Resource - positive values", result.getProperty("PropertyString").asPrimitive());
|
||||||
Assert.assertEquals(edmByte("255"), result.getProperty("PropertyByte").asPrimitive());
|
Assert.assertEquals((short) 255, result.getProperty("PropertyByte").asPrimitive());
|
||||||
Assert.assertEquals(edmSByte("127"), result.getProperty("PropertySByte").asPrimitive());
|
Assert.assertEquals((byte) 127, result.getProperty("PropertySByte").asPrimitive());
|
||||||
Assert.assertEquals(edmInt32("2147483647"), result.getProperty("PropertyInt32").asPrimitive());
|
Assert.assertEquals(2147483647, result.getProperty("PropertyInt32").asPrimitive());
|
||||||
Assert.assertEquals(edmInt64("9223372036854775807"), result.getProperty("PropertyInt64").asPrimitive());
|
Assert.assertEquals(9223372036854775807L, result.getProperty("PropertyInt64").asPrimitive());
|
||||||
Assert.assertEquals(edmSingle("1.79E20"), result.getProperty("PropertySingle").asPrimitive());
|
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||||
Assert.assertEquals(edmDouble("-1.79E19"), result.getProperty("PropertyDouble").asPrimitive());
|
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||||
Assert.assertEquals(edmDecimal("34"), result.getProperty("PropertyDecimal").asPrimitive());
|
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||||
// Assert.assertEquals(edmBinary("ASNFZ4mrze8="), result.getProperty("PropertyBinary").asPrimitive());
|
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||||
.asPrimitive());
|
.asPrimitive());
|
||||||
Assert.assertEquals(edmDuration("PT6S"), result.getProperty("PropertyDuration")
|
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||||
.asPrimitive());
|
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||||
Assert.assertEquals(edmGUID("01234567-89ab-cdef-0123-456789abcdef"), result.getProperty("PropertyGuid")
|
result.getProperty("PropertyGuid").asPrimitive());
|
||||||
.asPrimitive());
|
|
||||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -247,29 +190,28 @@ public class ODataXmlDeserializerTest {
|
||||||
" </atom:content>\n" +
|
" </atom:content>\n" +
|
||||||
"</atom:entry>\n";
|
"</atom:entry>\n";
|
||||||
|
|
||||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||||
edmEntitySet.getEntityType()).getEntity();
|
edmEntitySet.getEntityType()).getEntity();
|
||||||
|
|
||||||
Assert.assertEquals(16, result.getProperties().size());
|
Assert.assertEquals(16, result.getProperties().size());
|
||||||
Assert.assertEquals(2, result.getNavigationBindings().size());
|
Assert.assertEquals(2, result.getNavigationBindings().size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("32767"), result.getProperty("PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 32767, result.getProperty("PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("First Resource - positive values", result.getProperty("PropertyString").asPrimitive());
|
Assert.assertEquals("First Resource - positive values", result.getProperty("PropertyString").asPrimitive());
|
||||||
Assert.assertEquals(edmByte("255"), result.getProperty("PropertyByte").asPrimitive());
|
Assert.assertEquals((short) 255, result.getProperty("PropertyByte").asPrimitive());
|
||||||
Assert.assertEquals(edmSByte("127"), result.getProperty("PropertySByte").asPrimitive());
|
Assert.assertEquals((byte) 127, result.getProperty("PropertySByte").asPrimitive());
|
||||||
Assert.assertEquals(edmInt32("2147483647"), result.getProperty("PropertyInt32").asPrimitive());
|
Assert.assertEquals(2147483647, result.getProperty("PropertyInt32").asPrimitive());
|
||||||
Assert.assertEquals(edmInt64("9223372036854775807"), result.getProperty("PropertyInt64").asPrimitive());
|
Assert.assertEquals(9223372036854775807L, result.getProperty("PropertyInt64").asPrimitive());
|
||||||
Assert.assertEquals(edmSingle("1.79E20"), result.getProperty("PropertySingle").asPrimitive());
|
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||||
Assert.assertEquals(edmDouble("-1.79E19"), result.getProperty("PropertyDouble").asPrimitive());
|
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||||
Assert.assertEquals(edmDecimal("34"), result.getProperty("PropertyDecimal").asPrimitive());
|
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||||
// Assert.assertEquals(edmBinary("ASNFZ4mrze8="), result.getProperty("PropertyBinary").asPrimitive());
|
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||||
.asPrimitive());
|
.asPrimitive());
|
||||||
Assert.assertEquals(edmDuration("PT6S"), result.getProperty("PropertyDuration")
|
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||||
.asPrimitive());
|
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||||
Assert.assertEquals(edmGUID("01234567-89ab-cdef-0123-456789abcdef"), result.getProperty("PropertyGuid")
|
result.getProperty("PropertyGuid").asPrimitive());
|
||||||
.asPrimitive());
|
|
||||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -309,7 +251,7 @@ public class ODataXmlDeserializerTest {
|
||||||
+ "</atom:content>"
|
+ "</atom:content>"
|
||||||
+ "</atom:entry>";
|
+ "</atom:entry>";
|
||||||
|
|
||||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||||
edmEntitySet.getEntityType()).getEntity();
|
edmEntitySet.getEntityType()).getEntity();
|
||||||
|
|
||||||
Assert.assertEquals("olingo.odata.test1.ETCompAllPrim",result.getType());
|
Assert.assertEquals("olingo.odata.test1.ETCompAllPrim",result.getType());
|
||||||
|
@ -317,7 +259,7 @@ public class ODataXmlDeserializerTest {
|
||||||
Assert.assertEquals(2, result.getProperties().size());
|
Assert.assertEquals(2, result.getProperties().size());
|
||||||
Assert.assertEquals(0, result.getNavigationLinks().size());
|
Assert.assertEquals(0, result.getNavigationLinks().size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("32767"), result.getProperty("PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 32767, result.getProperty("PropertyInt16").asPrimitive());
|
||||||
|
|
||||||
Assert.assertNotNull(result.getProperty("PropertyComp"));
|
Assert.assertNotNull(result.getProperty("PropertyComp"));
|
||||||
Property comp = result.getProperty("PropertyComp");
|
Property comp = result.getProperty("PropertyComp");
|
||||||
|
@ -326,12 +268,12 @@ public class ODataXmlDeserializerTest {
|
||||||
|
|
||||||
Assert.assertEquals(16, cv.getValue().size());
|
Assert.assertEquals(16, cv.getValue().size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("32767"), getCVProperty(cv, "PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 32767, getCVProperty(cv, "PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("First Resource - first", getCVProperty(cv, "PropertyString").asPrimitive());
|
Assert.assertEquals("First Resource - first", getCVProperty(cv, "PropertyString").asPrimitive());
|
||||||
Assert.assertEquals(edmByte("255"), getCVProperty(cv, "PropertyByte").asPrimitive());
|
Assert.assertEquals((short) 255, getCVProperty(cv, "PropertyByte").asPrimitive());
|
||||||
Assert.assertEquals(edmSByte("127"), getCVProperty(cv, "PropertySByte").asPrimitive());
|
Assert.assertEquals((byte) 127, getCVProperty(cv, "PropertySByte").asPrimitive());
|
||||||
Assert.assertEquals(edmInt32("2147483647"), getCVProperty(cv, "PropertyInt32").asPrimitive());
|
Assert.assertEquals(2147483647, getCVProperty(cv, "PropertyInt32").asPrimitive());
|
||||||
Assert.assertEquals(edmInt64("9223372036854775807"), getCVProperty(cv, "PropertyInt64").asPrimitive());
|
Assert.assertEquals(9223372036854775807L, getCVProperty(cv, "PropertyInt64").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
private Property getCVProperty(ComplexValue cv, String name) {
|
private Property getCVProperty(ComplexValue cv, String name) {
|
||||||
|
@ -343,7 +285,6 @@ public class ODataXmlDeserializerTest {
|
||||||
return null;
|
return null;
|
||||||
}
|
}
|
||||||
|
|
||||||
@SuppressWarnings("unchecked")
|
|
||||||
@Test
|
@Test
|
||||||
public void entityMixPrimCollComp() throws Exception {
|
public void entityMixPrimCollComp() throws Exception {
|
||||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
|
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
|
||||||
|
@ -384,7 +325,7 @@ public class ODataXmlDeserializerTest {
|
||||||
" </atom:content>\n" +
|
" </atom:content>\n" +
|
||||||
"</atom:entry>\n";
|
"</atom:entry>\n";
|
||||||
|
|
||||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||||
edmEntitySet.getEntityType()).getEntity();
|
edmEntitySet.getEntityType()).getEntity();
|
||||||
|
|
||||||
Assert.assertEquals(4, result.getProperties().size());
|
Assert.assertEquals(4, result.getProperties().size());
|
||||||
|
@ -398,22 +339,22 @@ public class ODataXmlDeserializerTest {
|
||||||
ComplexValue cv = (ComplexValue)comp.getValue();
|
ComplexValue cv = (ComplexValue)comp.getValue();
|
||||||
|
|
||||||
Assert.assertEquals(2, cv.getValue().size());
|
Assert.assertEquals(2, cv.getValue().size());
|
||||||
Assert.assertEquals(edmInt16("111"), getCVProperty(cv, "PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 111, getCVProperty(cv, "PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("TEST A", getCVProperty(cv, "PropertyString").asPrimitive());
|
Assert.assertEquals("TEST A", getCVProperty(cv, "PropertyString").asPrimitive());
|
||||||
|
|
||||||
comp = result.getProperty("CollPropertyComp");
|
comp = result.getProperty("CollPropertyComp");
|
||||||
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());
|
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());
|
||||||
|
@SuppressWarnings("unchecked")
|
||||||
List<ComplexValue> properties = (List<ComplexValue>)comp.getValue();
|
List<ComplexValue> properties = (List<ComplexValue>)comp.getValue();
|
||||||
|
|
||||||
Assert.assertEquals(3, properties.size());
|
Assert.assertEquals(3, properties.size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("123"), getCVProperty(properties.get(0), "PropertyInt16")
|
Assert.assertEquals((short) 123,
|
||||||
.asPrimitive());
|
getCVProperty(properties.get(0), "PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("TEST 1", getCVProperty(properties.get(0), "PropertyString")
|
Assert.assertEquals("TEST 1",
|
||||||
.asPrimitive());
|
getCVProperty(properties.get(0), "PropertyString").asPrimitive());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("789"), getCVProperty(properties.get(2), "PropertyInt16")
|
Assert.assertEquals((short) 789, getCVProperty(properties.get(2), "PropertyInt16").asPrimitive());
|
||||||
.asPrimitive());
|
|
||||||
Assert.assertEquals("TEST 3", getCVProperty(properties.get(2), "PropertyString")
|
Assert.assertEquals("TEST 3", getCVProperty(properties.get(2), "PropertyString")
|
||||||
.asPrimitive());
|
.asPrimitive());
|
||||||
}
|
}
|
||||||
|
@ -461,13 +402,13 @@ public class ODataXmlDeserializerTest {
|
||||||
"</atom:entry>\n" +
|
"</atom:entry>\n" +
|
||||||
"";
|
"";
|
||||||
|
|
||||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||||
edmEntitySet.getEntityType()).getEntity();
|
edmEntitySet.getEntityType()).getEntity();
|
||||||
|
|
||||||
Assert.assertEquals(2, result.getProperties().size());
|
Assert.assertEquals(2, result.getProperties().size());
|
||||||
Assert.assertEquals(1, result.getNavigationLinks().size());
|
Assert.assertEquals(1, result.getNavigationLinks().size());
|
||||||
|
|
||||||
Assert.assertEquals(edmInt16("32767"), result.getProperty("PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 32767, result.getProperty("PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("Test String4", result.getProperty("PropertyString").asPrimitive());
|
Assert.assertEquals("Test String4", result.getProperty("PropertyString").asPrimitive());
|
||||||
|
|
||||||
Assert.assertEquals(1, result.getNavigationLinks().size());
|
Assert.assertEquals(1, result.getNavigationLinks().size());
|
||||||
|
@ -491,8 +432,8 @@ public class ODataXmlDeserializerTest {
|
||||||
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||||
+ "234</metadata:value>";
|
+ "234</metadata:value>";
|
||||||
|
|
||||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||||
Assert.assertEquals(edmInt16("234"), result.getValue());
|
Assert.assertEquals((short) 234, result.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -503,7 +444,7 @@ public class ODataXmlDeserializerTest {
|
||||||
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
|
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
|
||||||
+ "metadata:null=\"true\"/>";
|
+ "metadata:null=\"true\"/>";
|
||||||
|
|
||||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||||
Assert.assertNull(result.getValue());
|
Assert.assertNull(result.getValue());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -517,7 +458,7 @@ public class ODataXmlDeserializerTest {
|
||||||
+ "<metadata:element>Employee2@company.example</metadata:element>"
|
+ "<metadata:element>Employee2@company.example</metadata:element>"
|
||||||
+ "<metadata:element>Employee3@company.example</metadata:element>"
|
+ "<metadata:element>Employee3@company.example</metadata:element>"
|
||||||
+ "</metadata:value>";
|
+ "</metadata:value>";
|
||||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||||
Assert.assertEquals(Arrays.asList("Employee1@company.example", "Employee2@company.example",
|
Assert.assertEquals(Arrays.asList("Employee1@company.example", "Employee2@company.example",
|
||||||
"Employee3@company.example"), result.getValue());
|
"Employee3@company.example"), result.getValue());
|
||||||
|
|
||||||
|
@ -557,7 +498,7 @@ public class ODataXmlDeserializerTest {
|
||||||
" <data:PostalCode>12209</data:PostalCode>\n" +
|
" <data:PostalCode>12209</data:PostalCode>\n" +
|
||||||
"</data:ShipTo>";
|
"</data:ShipTo>";
|
||||||
|
|
||||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||||
|
|
||||||
Assert.assertEquals("ShipTo", result.getName());
|
Assert.assertEquals("ShipTo", result.getName());
|
||||||
Assert.assertTrue(result.getValue() instanceof ComplexValue);
|
Assert.assertTrue(result.getValue() instanceof ComplexValue);
|
||||||
|
@ -588,15 +529,15 @@ public class ODataXmlDeserializerTest {
|
||||||
" <data:PropertyString>TEST 3</data:PropertyString>\n" +
|
" <data:PropertyString>TEST 3</data:PropertyString>\n" +
|
||||||
" </metadata:element>\n" +
|
" </metadata:element>\n" +
|
||||||
"</metadata:value>";
|
"</metadata:value>";
|
||||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||||
|
|
||||||
List<ComplexValue> complex = (List<ComplexValue>)result.getValue();
|
List<ComplexValue> complex = (List<ComplexValue>)result.getValue();
|
||||||
|
|
||||||
Assert.assertEquals(3, complex.size());
|
Assert.assertEquals(3, complex.size());
|
||||||
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", result.getType());
|
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", result.getType());
|
||||||
Assert.assertEquals(edmInt16("123"), getCVProperty(complex.get(0), "PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 123, getCVProperty(complex.get(0), "PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("TEST 1", getCVProperty(complex.get(0), "PropertyString").asPrimitive());
|
Assert.assertEquals("TEST 1", getCVProperty(complex.get(0), "PropertyString").asPrimitive());
|
||||||
Assert.assertEquals(edmInt16("789"), getCVProperty(complex.get(2), "PropertyInt16").asPrimitive());
|
Assert.assertEquals((short) 789, getCVProperty(complex.get(2), "PropertyInt16").asPrimitive());
|
||||||
Assert.assertEquals("TEST 3", getCVProperty(complex.get(2), "PropertyString").asPrimitive());
|
Assert.assertEquals("TEST 3", getCVProperty(complex.get(2), "PropertyString").asPrimitive());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -607,7 +548,7 @@ public class ODataXmlDeserializerTest {
|
||||||
" xmlns=\"http://www.w3.org/2005/Atom\" "+
|
" xmlns=\"http://www.w3.org/2005/Atom\" "+
|
||||||
" id=\"http://host/service/Orders(10643)\" />";
|
" id=\"http://host/service/Orders(10643)\" />";
|
||||||
|
|
||||||
List<URI> result = serializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
List<URI> result = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
||||||
.getEntityReferences();
|
.getEntityReferences();
|
||||||
Assert.assertEquals(1, result.size());
|
Assert.assertEquals(1, result.size());
|
||||||
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
|
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
|
||||||
|
@ -622,7 +563,7 @@ public class ODataXmlDeserializerTest {
|
||||||
" <metadata:ref id=\"http://host/service/Orders(10759)\" />\n" +
|
" <metadata:ref id=\"http://host/service/Orders(10759)\" />\n" +
|
||||||
"</feed>";
|
"</feed>";
|
||||||
|
|
||||||
List<URI> result = serializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
List<URI> result = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
||||||
.getEntityReferences();
|
.getEntityReferences();
|
||||||
Assert.assertEquals(2, result.size());
|
Assert.assertEquals(2, result.size());
|
||||||
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
|
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
|
||||||
|
|
|
@ -18,12 +18,11 @@
|
||||||
*/
|
*/
|
||||||
package org.apache.olingo.server.core.uri.antlr;
|
package org.apache.olingo.server.core.uri.antlr;
|
||||||
|
|
||||||
import java.io.UnsupportedEncodingException;
|
|
||||||
import java.net.URLEncoder;
|
|
||||||
import java.util.Arrays;
|
import java.util.Arrays;
|
||||||
|
|
||||||
import org.apache.olingo.commons.api.edm.Edm;
|
import org.apache.olingo.commons.api.edm.Edm;
|
||||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||||
|
import org.apache.olingo.commons.core.Encoder;
|
||||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||||
import org.apache.olingo.server.api.uri.UriInfoKind;
|
import org.apache.olingo.server.api.uri.UriInfoKind;
|
||||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||||
|
@ -326,7 +325,7 @@ public class TestUriParserImpl {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEntitySet() throws UnsupportedEncodingException {
|
public void entitySet() throws Exception {
|
||||||
|
|
||||||
// plain entity set
|
// plain entity set
|
||||||
testRes.run("ESAllPrim")
|
testRes.run("ESAllPrim")
|
||||||
|
@ -351,7 +350,7 @@ public class TestUriParserImpl {
|
||||||
.isKeyPredicate(1, "PropertyString", "'ABC'");
|
.isKeyPredicate(1, "PropertyString", "'ABC'");
|
||||||
|
|
||||||
// with all keys
|
// with all keys
|
||||||
testRes.run("ESAllKey(" + encode(allKeys) + ")")
|
testRes.run("ESAllKey(" + Encoder.encode(allKeys) + ")")
|
||||||
.isEntitySet("ESAllKey")
|
.isEntitySet("ESAllKey")
|
||||||
.isKeyPredicate(0, "PropertyString", "'ABC'")
|
.isKeyPredicate(0, "PropertyString", "'ABC'")
|
||||||
.isKeyPredicate(1, "PropertyInt16", "1")
|
.isKeyPredicate(1, "PropertyInt16", "1")
|
||||||
|
@ -1165,8 +1164,4 @@ public class TestUriParserImpl {
|
||||||
testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16")
|
testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
||||||
}
|
}
|
||||||
|
|
||||||
public static String encode(final String decoded) throws UnsupportedEncodingException {
|
|
||||||
return URLEncoder.encode(decoded, "UTF-8");
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue