[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;
|
||||
|
||||
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.List;
|
||||
|
||||
|
@ -45,4 +50,17 @@ public abstract class AbstractParamTecSvcITCase extends AbstractTecSvcITCase {
|
|||
protected ContentType getContentType() {
|
||||
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;
|
||||
|
||||
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 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) {
|
||||
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());
|
||||
}
|
||||
protected abstract ContentType getContentType();
|
||||
|
||||
@Override
|
||||
protected ODataClient getClient() {
|
||||
|
@ -85,12 +65,8 @@ public abstract class AbstractTecSvcITCase extends AbstractBaseTestITCase {
|
|||
return odata;
|
||||
}
|
||||
|
||||
protected EdmEnabledODataClient getClient(final String serviceRoot) {
|
||||
return ODataClientFactory.getEdmEnabledClient(serviceRoot, getContentType());
|
||||
}
|
||||
|
||||
protected EdmEnabledODataClient getEdmEnabledClient() {
|
||||
return getClient(SERVICE_URI);
|
||||
return ODataClientFactory.getEdmEnabledClient(SERVICE_URI, getContentType());
|
||||
}
|
||||
|
||||
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.assertNotNull;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.Assume.assumeTrue;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
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.ClientValue;
|
||||
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.HttpStatusCode;
|
||||
import org.apache.olingo.fit.tecsvc.TecSvcConst;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ActionImportITCase extends AbstractTecSvcITCase {
|
||||
public class ActionImportITCase extends AbstractParamTecSvcITCase {
|
||||
|
||||
@Test
|
||||
public void noReturnTypeAction() throws Exception {
|
||||
|
@ -293,6 +293,8 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
|
|||
|
||||
private <T extends ClientInvokeResult> ODataInvokeResponse<T> callAction(final String name,
|
||||
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();
|
||||
ODataInvokeRequest<T> request = getClient().getInvokeRequestFactory()
|
||||
.getActionInvokeRequest(actionURI, resultRef, parameters);
|
||||
|
@ -309,9 +311,4 @@ public class ActionImportITCase extends AbstractTecSvcITCase {
|
|||
}
|
||||
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.EntityCollection;
|
||||
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.http.HttpHeader;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
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 NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
|
||||
|
@ -70,7 +69,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
|||
|
||||
final ODataRetrieveResponse<ClientEntity> response = client.getRetrieveRequestFactory()
|
||||
.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());
|
||||
|
||||
// first async request
|
||||
|
@ -98,9 +97,8 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
|||
assertNotNull(first.getODataResponse());
|
||||
ODataResponse firstResponse = first.getODataResponse();
|
||||
assertEquals(HttpStatusCode.OK.getStatusCode(), firstResponse.getStatusCode());
|
||||
ResWrap<Entity> entity = client.getDeserializer(ContentType.APPLICATION_JSON)
|
||||
.toEntity(firstResponse.getRawResponse());
|
||||
assertEquals(32767, entity.getPayload().getProperty("PropertyInt16").asPrimitive());
|
||||
ResWrap<Entity> entity = client.getDeserializer(getContentType()).toEntity(firstResponse.getRawResponse());
|
||||
assertShortOrInt(32767, entity.getPayload().getProperty("PropertyInt16").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(2, firstResponse.getHeaderNames().size());
|
||||
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());
|
||||
EntityCollection firstResponseEntitySet = firWrap.getPayload();
|
||||
assertEquals(3, firstResponseEntitySet.getEntities().size());
|
||||
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());
|
||||
}
|
||||
|
||||
|
@ -190,7 +188,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
|||
assertNotNull(createdEntity);
|
||||
final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
|
||||
assertNotNull(property1);
|
||||
assertEquals(42, property1.getPrimitiveValue().toValue());
|
||||
assertShortOrInt(42, property1.getPrimitiveValue().toValue());
|
||||
final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
|
||||
assertNotNull(property2);
|
||||
assertNull(property2.getPrimitiveValue());
|
||||
|
@ -220,7 +218,7 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
|||
assertEquals("4.0", firstResponse.getHeader(HttpHeader.ODATA_VERSION).iterator().next());
|
||||
|
||||
final ClientEntity entity = firstResponse.getBody();
|
||||
assertEquals(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
||||
assertShortOrInt(32767, entity.getProperty("PropertyInt16").getPrimitiveValue().toValue());
|
||||
assertEquals("First Resource - positive values",
|
||||
entity.getProperty("PropertyString").getPrimitiveValue().toValue());
|
||||
}
|
||||
|
@ -266,11 +264,11 @@ public final class AsyncSupportITCase extends AbstractTecSvcITCase {
|
|||
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()) {
|
||||
ClientProperty ep = entity.getProperty("PropertyInt16");
|
||||
ClientProperty ep = entity.getProperty(property);
|
||||
if (ep != null) {
|
||||
assertEquals(value, ep.getPrimitiveValue().toValue());
|
||||
assertShortOrInt(value, ep.getPrimitiveValue().toValue());
|
||||
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
|
||||
@Ignore("Server do not support navigation property count annotations")
|
||||
public void count() {
|
||||
final ODataClient client = getClient(SERVICE_URI);
|
||||
final ODataClient client = getEdmEnabledClient();
|
||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||
options.put(QueryOption.SELECT, "PropertyInt16");
|
||||
options.put(QueryOption.COUNT, true);
|
||||
|
@ -254,7 +254,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
|||
@Test
|
||||
public void singleEntityWithExpand() {
|
||||
/* 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>();
|
||||
options.put(QueryOption.FILTER, "PropertyInt16 lt 2");
|
||||
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')
|
||||
// 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>();
|
||||
options.put(QueryOption.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
|
||||
public void systemQueryOptionOnThirdLevel() {
|
||||
final ODataClient client = getClient(SERVICE_URI);
|
||||
final ODataClient client = getEdmEnabledClient();
|
||||
Map<QueryOption, Object> options = new HashMap<QueryOption, Object>();
|
||||
options.put(QueryOption.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
|
||||
public void expandWithSearchQuery() {
|
||||
final ODataClient client = getClient(SERVICE_URI);
|
||||
final ODataClient client = getEdmEnabledClient();
|
||||
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
||||
expandOptions.put(QueryOption.SEARCH, "abc");
|
||||
expandOptions.put(QueryOption.FILTER, "PropertyInt16 eq 1");
|
||||
|
@ -463,7 +463,7 @@ public class ExpandWithSystemQueryOptionsITCase extends AbstractParamTecSvcITCas
|
|||
|
||||
@Test
|
||||
public void expandWithLevels() {
|
||||
final ODataClient client = getClient(SERVICE_URI);
|
||||
final ODataClient client = getEdmEnabledClient();
|
||||
Map<QueryOption, Object> expandOptions = new HashMap<QueryOption, Object>();
|
||||
expandOptions.put(QueryOption.LEVELS, 2);
|
||||
|
||||
|
|
|
@ -31,7 +31,7 @@ public interface EdmNavigationProperty extends EdmElement, EdmAnnotationsTarget,
|
|||
EdmEntityType getType();
|
||||
|
||||
/**
|
||||
* @return true if nullable or null if not specified
|
||||
* @return true if nullable or not specified
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
|||
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();
|
||||
|
||||
|
|
|
@ -42,7 +42,7 @@ public interface EdmProperty extends EdmElement, EdmMappable, EdmAnnotationsTarg
|
|||
boolean isPrimitive();
|
||||
|
||||
/**
|
||||
* @return true if nullable or null if not specified
|
||||
* @return true if nullable or not specified
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
|
@ -67,7 +67,7 @@ public interface EdmProperty extends EdmElement, EdmMappable, EdmAnnotationsTarg
|
|||
SRID getSrid();
|
||||
|
||||
/**
|
||||
* @return true if unicode or null if not specified
|
||||
* @return true if unicode or not specified
|
||||
*/
|
||||
boolean isUnicode();
|
||||
|
||||
|
|
|
@ -26,7 +26,7 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
|
|||
public interface EdmReturnType extends EdmTyped {
|
||||
|
||||
/**
|
||||
* @return true if nullable or null if not specified
|
||||
* @return true if nullable or not specified
|
||||
*/
|
||||
boolean isNullable();
|
||||
|
||||
|
|
|
@ -112,18 +112,15 @@ public class ODataImpl extends OData {
|
|||
|
||||
@Override
|
||||
public ODataDeserializer createDeserializer(final ContentType contentType) throws DeserializerException {
|
||||
ODataDeserializer deserializer;
|
||||
|
||||
if (contentType.isCompatible(ContentType.JSON)) {
|
||||
deserializer = new ODataJsonDeserializer(contentType);
|
||||
return new ODataJsonDeserializer(contentType);
|
||||
} else if (contentType.isCompatible(ContentType.APPLICATION_XML)
|
||||
|| contentType.isCompatible(ContentType.APPLICATION_ATOM_XML)) {
|
||||
deserializer = new ODataXmlDeserializer();
|
||||
return new ODataXmlDeserializer();
|
||||
} else {
|
||||
throw new DeserializerException("Unsupported format: " + contentType.toContentTypeString(),
|
||||
DeserializerException.MessageKeys.UNSUPPORTED_FORMAT, contentType.toContentTypeString());
|
||||
}
|
||||
return deserializer;
|
||||
}
|
||||
|
||||
@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.EdmType;
|
||||
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.core.edm.primitivetype.EdmPrimitiveTypeFactory;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerResult;
|
||||
|
@ -72,13 +72,9 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
|
|||
|
||||
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_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;
|
||||
|
||||
public ODataJsonDeserializer(final ContentType contentType) {
|
||||
|
@ -89,33 +85,21 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
public DeserializerResult entityCollection(final InputStream stream, final EdmEntityType edmEntityType)
|
||||
throws DeserializerException {
|
||||
try {
|
||||
final ObjectNode tree = parseJsonTree(stream);
|
||||
|
||||
return DeserializerResultImpl.with().entityCollection(consumeEntitySetNode(edmEntityType, tree, null))
|
||||
return DeserializerResultImpl.with().entityCollection(
|
||||
consumeEntityCollectionNode(edmEntityType, parseJsonTree(stream), null))
|
||||
.build();
|
||||
} catch (JsonParseException 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_JSON_PROPERTY);
|
||||
} catch (IOException e) {
|
||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e, DeserializerException.MessageKeys.IO_EXCEPTION);
|
||||
} catch (final IOException e) {
|
||||
throw wrapParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
private EntityCollection consumeEntitySetNode(final EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
private EntityCollection consumeEntityCollectionNode(final EdmEntityType edmEntityType, ObjectNode tree,
|
||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
EntityCollection entitySet = new EntityCollection();
|
||||
|
||||
// Consume entities
|
||||
JsonNode jsonNode = tree.get(Constants.VALUE);
|
||||
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));
|
||||
tree.remove(Constants.VALUE);
|
||||
} else {
|
||||
|
@ -145,16 +129,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
|
||||
private List<Entity> consumeEntitySetArray(final EdmEntityType edmEntityType, final JsonNode jsonNode,
|
||||
final ExpandTreeBuilder expandBuilder) throws DeserializerException {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (JsonNode arrayElement : jsonNode) {
|
||||
if (arrayElement.isArray() || arrayElement.isValueNode()) {
|
||||
throw new DeserializerException("Nested Arrays and primitive values are not allowed for an entity value.",
|
||||
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||
if (jsonNode.isArray()) {
|
||||
List<Entity> entities = new ArrayList<Entity>();
|
||||
for (JsonNode arrayElement : jsonNode) {
|
||||
if (arrayElement.isArray() || arrayElement.isValueNode()) {
|
||||
throw new DeserializerException("Nested Arrays and primitive values are not allowed for an entity value.",
|
||||
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||
}
|
||||
entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
|
||||
}
|
||||
|
||||
entities.add(consumeEntityNode(edmEntityType, (ObjectNode) arrayElement, expandBuilder));
|
||||
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);
|
||||
}
|
||||
return entities;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -167,17 +155,9 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
return DeserializerResultImpl.with().entity(consumeEntityNode(edmEntityType, tree, expandBuilder))
|
||||
.expandOption(expandBuilder.build())
|
||||
.build();
|
||||
|
||||
} catch (JsonParseException 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);
|
||||
} catch (final IOException e) {
|
||||
throw wrapParseException(e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private Entity consumeEntityNode(final EdmEntityType edmEntityType, final ObjectNode tree,
|
||||
|
@ -224,15 +204,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
assertJsonNodeIsEmpty(tree);
|
||||
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) {
|
||||
throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
|
||||
DeserializerException.MessageKeys.IO_EXCEPTION);
|
||||
throw wrapParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -264,17 +237,15 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
case DEFINITION:
|
||||
case ENUM:
|
||||
case COMPLEX:
|
||||
case ENTITY:
|
||||
Parameter parameter = createParameter(node.get(paramName), paramName, edmParameter);
|
||||
parameters.put(paramName, parameter);
|
||||
node.remove(paramName);
|
||||
break;
|
||||
case ENTITY:
|
||||
throw new DeserializerException("Entity parameters are not allowed",
|
||||
DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE);
|
||||
default:
|
||||
throw new DeserializerException("Invalid type kind " + edmParameter.getType().getKind().toString()
|
||||
+ " for action parameter: " + paramName, DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE,
|
||||
paramName);
|
||||
throw new DeserializerException(
|
||||
"Invalid type kind " + edmParameter.getType().getKind() + " for action parameter: " + paramName,
|
||||
DeserializerException.MessageKeys.INVALID_ACTION_PARAMETER_TYPE, paramName);
|
||||
}
|
||||
}
|
||||
return parameters;
|
||||
|
@ -286,7 +257,7 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
parameter.setName(paramName);
|
||||
if (node == null || node.isNull()) {
|
||||
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);
|
||||
}
|
||||
if (edmParameter.isCollection()) {
|
||||
|
@ -294,24 +265,34 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
MessageKeys.INVALID_NULL_PARAMETER, paramName);
|
||||
}
|
||||
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 {
|
||||
final Entity entity = consumeEntityNode((EdmEntityType) edmParameter.getType(), (ObjectNode) node, null);
|
||||
parameter.setValue(ValueType.ENTITY, entity);
|
||||
}
|
||||
} else {
|
||||
Property consumePropertyNode =
|
||||
final Property property =
|
||||
consumePropertyNode(edmParameter.getName(), edmParameter.getType(), edmParameter.isCollection(),
|
||||
edmParameter.isNullable(), edmParameter.getMaxLength(), edmParameter.getPrecision(), edmParameter
|
||||
.getScale(), true, edmParameter.getMapping(), node);
|
||||
parameter.setValue(consumePropertyNode.getValueType(), consumePropertyNode.getValue());
|
||||
edmParameter.isNullable(), edmParameter.getMaxLength(),
|
||||
edmParameter.getPrecision(), edmParameter.getScale(), true, edmParameter.getMapping(), node);
|
||||
parameter.setValue(property.getValueType(), property.getValue());
|
||||
}
|
||||
return parameter;
|
||||
}
|
||||
|
||||
/**
|
||||
* Consume all remaining fields of Json ObjectNode and try to map found values
|
||||
* to according Entity fields and omit to be ignored OData fields (e.g. control information).
|
||||
* Consumes all remaining fields of Json ObjectNode and tries to map found values
|
||||
* 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 node json node which is consumed
|
||||
* @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,
|
||||
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)
|
||||
throws DeserializerException {
|
||||
String[] splitKey = key.split("@");
|
||||
String[] splitKey = key.split(ODATA_ANNOTATION_MARKER);
|
||||
String navigationPropertyName = splitKey[0];
|
||||
EdmNavigationProperty edmNavigationProperty = edmEntityType.getNavigationProperty(navigationPropertyName);
|
||||
if (edmNavigationProperty == null) {
|
||||
|
@ -488,23 +469,16 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
throws DeserializerException {
|
||||
switch (type.getKind()) {
|
||||
case PRIMITIVE:
|
||||
Object value = readPrimitiveValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
||||
jsonNode);
|
||||
property.setValue(ValueType.PRIMITIVE, value);
|
||||
break;
|
||||
case DEFINITION:
|
||||
value = readTypeDefinitionValue(name, type, isNullable, mapping, jsonNode);
|
||||
property.setValue(ValueType.PRIMITIVE, value);
|
||||
break;
|
||||
case ENUM:
|
||||
value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
||||
jsonNode);
|
||||
property.setValue(ValueType.ENUM, value);
|
||||
Object value = readPrimitiveValue(name, (EdmPrimitiveType) type,
|
||||
isNullable, maxLength, precision, scale, isUnicode, mapping, jsonNode);
|
||||
property.setValue(type.getKind() == EdmTypeKind.ENUM ? ValueType.ENUM : ValueType.PRIMITIVE,
|
||||
value);
|
||||
break;
|
||||
case COMPLEX:
|
||||
value = readComplexNode(name, type, isNullable, jsonNode);
|
||||
property.setValue(ValueType.COMPLEX, value);
|
||||
|
||||
break;
|
||||
default:
|
||||
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();
|
||||
switch (type.getKind()) {
|
||||
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:
|
||||
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:
|
||||
while (iterator.hasNext()) {
|
||||
JsonNode arrayElement = iterator.next();
|
||||
Object value = readEnumValue(name, type, isNullable, maxLength, precision, scale, isUnicode, mapping,
|
||||
arrayElement);
|
||||
Object value = readPrimitiveValue(name, (EdmPrimitiveType) type,
|
||||
isNullable, maxLength, precision, scale, isUnicode, mapping, arrayElement);
|
||||
valueArray.add(value);
|
||||
}
|
||||
property.setValue(ValueType.COLLECTION_ENUM, valueArray);
|
||||
property.setValue(type.getKind() == EdmTypeKind.ENUM ?
|
||||
ValueType.COLLECTION_ENUM :
|
||||
ValueType.COLLECTION_PRIMITIVE,
|
||||
valueArray);
|
||||
break;
|
||||
case COMPLEX:
|
||||
while (iterator.hasNext()) {
|
||||
|
@ -626,22 +588,20 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
return complexValue;
|
||||
}
|
||||
|
||||
private Object readTypeDefinitionValue(final String name, final EdmType type,
|
||||
final boolean isNullable, final EdmMapping mapping, final JsonNode jsonNode) throws DeserializerException {
|
||||
private Object readPrimitiveValue(final String name, final EdmPrimitiveType 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;
|
||||
}
|
||||
checkJsonTypeBasedOnPrimitiveType(name, type, jsonNode);
|
||||
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, type);
|
||||
try {
|
||||
EdmTypeDefinition edmTypeDefinition = (EdmTypeDefinition) type;
|
||||
checkJsonTypeBasedOnPrimitiveType(name, edmTypeDefinition.getUnderlyingType().getName(),
|
||||
jsonNode);
|
||||
Class<?> javaClass = getJavaClassForPrimitiveType(mapping, edmTypeDefinition.getUnderlyingType());
|
||||
return edmTypeDefinition.valueOfString(jsonNode.asText(), isNullable,
|
||||
edmTypeDefinition.getMaxLength(),
|
||||
edmTypeDefinition.getPrecision(), edmTypeDefinition.getScale(), edmTypeDefinition.isUnicode(),
|
||||
return type.valueOfString(jsonNode.asText(),
|
||||
isNullable, maxLength, precision, scale, isUnicode,
|
||||
javaClass);
|
||||
} catch (EdmPrimitiveTypeException e) {
|
||||
} catch (final EdmPrimitiveTypeException e) {
|
||||
throw new DeserializerException(
|
||||
"Invalid value: " + jsonNode.asText() + " for property: " + name, e,
|
||||
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.",
|
||||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, name);
|
||||
}
|
||||
|
||||
}
|
||||
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 edmPrimitiveType
|
||||
* @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 ?
|
||||
edmPrimitiveType.getDefaultType() :
|
||||
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
|
||||
* an <code>DeserializerException</code>.
|
||||
*
|
||||
* Validates that node is empty (<code>node.size() == 0</code>).
|
||||
* @param node node to be checked
|
||||
* @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,
|
||||
final JsonNode jsonNode)
|
||||
throws DeserializerException {
|
||||
|
||||
EdmPrimitiveTypeKind primKind;
|
||||
try {
|
||||
primKind = EdmPrimitiveTypeKind.valueOf(edmPrimitiveTypeName);
|
||||
} catch (IllegalArgumentException e) {
|
||||
throw new DeserializerException("Unknown Primitive Type: " + edmPrimitiveTypeName, e,
|
||||
DeserializerException.MessageKeys.UNKNOWN_PRIMITIVE_TYPE, edmPrimitiveTypeName, propertyName);
|
||||
private void checkJsonTypeBasedOnPrimitiveType(final String propertyName, final EdmPrimitiveType edmPrimitiveType,
|
||||
final JsonNode jsonNode) 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;
|
||||
try {
|
||||
primKind = EdmPrimitiveTypeKind.valueOf(name);
|
||||
} catch (final IllegalArgumentException e) {
|
||||
throw new DeserializerException("Unknown Primitive Type: " + name, e,
|
||||
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) {
|
||||
throw new DeserializerException("Invalid json type: " + jsonNode.getNodeType() + " for edm " + primKind
|
||||
+ " property: " + propertyName, DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName);
|
||||
throw new DeserializerException(
|
||||
"Invalid json type: " + jsonNode.getNodeType() + " for " + edmPrimitiveType + " property: " + propertyName,
|
||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, propertyName);
|
||||
}
|
||||
}
|
||||
|
||||
private boolean matchIEEENumberCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
||||
switch (primKind) {
|
||||
case Int64:
|
||||
case Decimal:
|
||||
// Numbers (either numbers or string)
|
||||
if (isIEEE754Compatible) {
|
||||
return node.isTextual();
|
||||
} else {
|
||||
return node.isNumber();
|
||||
}
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
private boolean matchIEEENumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||
return (isIEEE754Compatible ? node.isTextual() : node.isNumber())
|
||||
&& (primKind == EdmPrimitiveTypeKind.Int64 || primKind == EdmPrimitiveTypeKind.Decimal);
|
||||
}
|
||||
|
||||
private boolean matchBooleanCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
||||
if (node.isBoolean()) {
|
||||
switch (primKind) {
|
||||
case Boolean:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
private boolean matchBooleanCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||
return node.isBoolean() && primKind == EdmPrimitiveTypeKind.Boolean;
|
||||
}
|
||||
|
||||
private boolean matchNumberCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
||||
if (node.isNumber()) {
|
||||
switch (primKind) {
|
||||
// Numbers (must be numbers)
|
||||
case Int16:
|
||||
case Int32:
|
||||
case Byte:
|
||||
case SByte:
|
||||
case Single:
|
||||
case Double:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
private boolean matchNumberCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||
return node.isNumber() &&
|
||||
(primKind == EdmPrimitiveTypeKind.Int16
|
||||
|| primKind == EdmPrimitiveTypeKind.Int32
|
||||
|| primKind == EdmPrimitiveTypeKind.Byte
|
||||
|| primKind == EdmPrimitiveTypeKind.SByte
|
||||
|| primKind == EdmPrimitiveTypeKind.Single
|
||||
|| primKind == EdmPrimitiveTypeKind.Double);
|
||||
}
|
||||
|
||||
private boolean matchTextualCase(JsonNode node, EdmPrimitiveTypeKind primKind) {
|
||||
if (node.isTextual()) {
|
||||
switch (primKind) {
|
||||
case String:
|
||||
case Binary:
|
||||
case Date:
|
||||
case DateTimeOffset:
|
||||
case Duration:
|
||||
case Guid:
|
||||
case TimeOfDay:
|
||||
return true;
|
||||
default:
|
||||
return false;
|
||||
}
|
||||
}
|
||||
return false;
|
||||
private boolean matchTextualCase(final JsonNode node, final EdmPrimitiveTypeKind primKind) {
|
||||
return node.isTextual() &&
|
||||
(primKind == EdmPrimitiveTypeKind.String
|
||||
|| primKind == EdmPrimitiveTypeKind.Binary
|
||||
|| primKind == EdmPrimitiveTypeKind.Date
|
||||
|| primKind == EdmPrimitiveTypeKind.DateTimeOffset
|
||||
|| primKind == EdmPrimitiveTypeKind.Duration
|
||||
|| primKind == EdmPrimitiveTypeKind.Guid
|
||||
|| primKind == EdmPrimitiveTypeKind.TimeOfDay);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
@ -866,14 +749,8 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
tree);
|
||||
}
|
||||
return DeserializerResultImpl.with().property(property).build();
|
||||
} catch (JsonParseException 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);
|
||||
} catch (final IOException e) {
|
||||
throw wrapParseException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -906,21 +783,27 @@ public class ODataJsonDeserializer implements ODataDeserializer {
|
|||
throw new DeserializerException("Missing entity reference", DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
||||
}
|
||||
return DeserializerResultImpl.with().entityReferences(parsedValues).build();
|
||||
} catch (JsonParseException 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);
|
||||
} catch (URISyntaxException e) {
|
||||
} catch (final IOException e) {
|
||||
throw wrapParseException(e);
|
||||
} catch (final URISyntaxException e) {
|
||||
throw new DeserializerException("failed to read @odata.id", e,
|
||||
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) {
|
||||
return contentType.getParameters().containsKey(ContentType.PARAMETER_IEEE754_COMPATIBLE)
|
||||
&& 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.DeserializerResult;
|
||||
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 com.fasterxml.aalto.stax.InputFactoryImpl;
|
||||
|
@ -69,11 +70,9 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
|||
|
||||
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
|
||||
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("http://docs.oasis-open.org/odata/ns/metadata", "ref");
|
||||
private static final QName PARAMETERS_ELEMENT =
|
||||
new QName("http://docs.oasis-open.org/odata/ns/metadata", "parameters");
|
||||
private static final QName ID_ATTR = new QName(NS_ATOM, ATOM);
|
||||
private static final QName REF_ELEMENT = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
|
||||
private static final QName PARAMETERS_ELEMENT = new QName(Constants.NS_METADATA, "parameters");
|
||||
private static final QName ID_ATTR = new QName(Constants.NS_ATOM, ATOM);
|
||||
|
||||
private final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
|
||||
private final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
|
||||
|
@ -83,16 +82,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
|||
private final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
|
||||
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 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 {
|
||||
return FACTORY.createXMLEventReader(input);
|
||||
}
|
||||
|
@ -715,12 +705,12 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
|||
public DeserializerResult actionParameters(InputStream stream, EdmAction edmAction)
|
||||
throws DeserializerException {
|
||||
Map<String, Parameter> parameters = new LinkedHashMap<String, Parameter>();
|
||||
if(edmAction.getParameterNames() == null || edmAction.getParameterNames().isEmpty()
|
||||
|| (edmAction.isBound() && edmAction.getParameterNames().size() == 1)) {
|
||||
if (edmAction.getParameterNames() == null || edmAction.getParameterNames().isEmpty()
|
||||
|| edmAction.isBound() && edmAction.getParameterNames().size() == 1) {
|
||||
return DeserializerResultImpl.with().actionParameters(parameters)
|
||||
.build();
|
||||
}
|
||||
|
||||
|
||||
try {
|
||||
final XMLEventReader reader = getReader(stream);
|
||||
while (reader.hasNext()) {
|
||||
|
@ -729,14 +719,26 @@ public class ODataXmlDeserializer implements ODataDeserializer {
|
|||
consumeParameters(edmAction, reader, event.asStartElement(), parameters);
|
||||
}
|
||||
}
|
||||
// NULL fill for missing parameters
|
||||
Parameter nullParameter = new Parameter();
|
||||
nullParameter.setValue(ValueType.PRIMITIVE, null);
|
||||
for (String param:edmAction.getParameterNames()) {
|
||||
if (parameters.get(param) == null) {
|
||||
parameters.put(param, nullParameter);
|
||||
// EDM checks.
|
||||
for (final String param : edmAction.getParameterNames()) {
|
||||
Parameter parameter = parameters.get(param);
|
||||
if (parameter == null) {
|
||||
final EdmParameter edmParameter = edmAction.getParameter(param);
|
||||
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)
|
||||
.build();
|
||||
} catch (XMLStreamException e) {
|
||||
|
|
|
@ -72,16 +72,16 @@ import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
|
|||
|
||||
public class ODataXmlSerializer extends AbstractODataSerializer {
|
||||
|
||||
private static final String DATA = "d";
|
||||
private static final String CONTEXT = "context";
|
||||
/** The default character set is UTF-8. */
|
||||
public static final String DEFAULT_CHARSET = "UTF-8";
|
||||
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 NS_METADATA = "http://docs.oasis-open.org/odata/ns/metadata";
|
||||
private static final String NS_DATA = "http://docs.oasis-open.org/odata/ns/data";
|
||||
private static final String NS_SCHEMA = "http://docs.oasis-open.org/odata/ns/scheme";
|
||||
private static final String NS_METADATA = Constants.NS_METADATA;
|
||||
private static final String DATA = "d";
|
||||
private static final String NS_DATA = Constants.NS_DATASERVICES;
|
||||
private static final String NS_SCHEMA = Constants.NS_SCHEME;
|
||||
|
||||
@Override
|
||||
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
|
||||
|
@ -235,7 +235,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
ContextURLBuilder.create(contextURL).toASCIIString());
|
||||
writeMetadataETag(metadata, writer);
|
||||
|
||||
if (options != null) {
|
||||
if (options != null && options.getId() != null) {
|
||||
writer.writeStartElement(ATOM, "id", NS_ATOM);
|
||||
writer.writeCharacters(options.getId());
|
||||
writer.writeEndElement();
|
||||
|
@ -364,16 +364,20 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
writer.writeAttribute(METADATA, NS_METADATA, "etag", entity.getETag());
|
||||
}
|
||||
|
||||
writer.writeStartElement(NS_ATOM, "id");
|
||||
writer.writeCharacters(entity.getId().toASCIIString());
|
||||
writer.writeEndElement();
|
||||
if (entity.getId() != null) {
|
||||
writer.writeStartElement(NS_ATOM, "id");
|
||||
writer.writeCharacters(entity.getId().toASCIIString());
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
writerAuthorInfo(entity.getTitle(), writer);
|
||||
|
||||
writer.writeStartElement(NS_ATOM, "link");
|
||||
writer.writeAttribute("rel", "edit");
|
||||
writer.writeAttribute("href", entity.getId().toASCIIString());
|
||||
writer.writeEndElement();
|
||||
if (entity.getId() != null) {
|
||||
writer.writeStartElement(NS_ATOM, "link");
|
||||
writer.writeAttribute("rel", "edit");
|
||||
writer.writeAttribute("href", entity.getId().toASCIIString());
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
||||
if (entityType.hasStream()) {
|
||||
writer.writeStartElement(NS_ATOM, "content");
|
||||
|
@ -551,12 +555,14 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
Link link = linked.getNavigationLink(navigationPropertyName);
|
||||
if (link == null) {
|
||||
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.setTitle(navigationPropertyName);
|
||||
EntityCollection target = new EntityCollection();
|
||||
link.setInlineEntitySet(target);
|
||||
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
|
||||
if (linked.getId() != null) {
|
||||
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
|
||||
}
|
||||
}
|
||||
return link;
|
||||
}
|
||||
|
@ -575,7 +581,9 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
if (link.getTitle() != null) {
|
||||
writer.writeAttribute("title", link.getTitle());
|
||||
}
|
||||
writer.writeAttribute("href", link.getHref());
|
||||
if (link.getHref() != null) {
|
||||
writer.writeAttribute("href", link.getHref());
|
||||
}
|
||||
if (close) {
|
||||
writer.writeEndElement();
|
||||
}
|
||||
|
@ -606,11 +614,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
|
|||
SerializerException {
|
||||
writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA);
|
||||
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!",
|
||||
SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
|
||||
} else {
|
||||
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
|
||||
}
|
||||
} else {
|
||||
writePropertyValue(metadata, edmProperty, property, selectedPaths, writer);
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
package org.apache.olingo.server.tecsvc.data;
|
||||
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
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.Property;
|
||||
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.EdmPrimitiveTypeException;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.commons.api.http.HttpStatusCode;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.serializer.SerializerException;
|
||||
import org.apache.olingo.server.tecsvc.data.DataProvider.DataProviderException;
|
||||
|
||||
public class ActionData {
|
||||
|
@ -101,57 +104,45 @@ public class ActionData {
|
|||
throws DataProviderException {
|
||||
if ("UARTCTTwoPrimParam".equals(name)) {
|
||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||
final Short number = paramInt16 == null ? (short) 32767 : (Short) paramInt16.asPrimitive();
|
||||
return createCTTwoPrimComplexProperty(number, "UARTCTTwoPrimParam string value");
|
||||
final Short number = paramInt16 == null || paramInt16.isNull() ?
|
||||
(short) 32767 :
|
||||
(Short) paramInt16.asPrimitive();
|
||||
return createCTTwoPrimComplexProperty(name, number, "UARTCTTwoPrimParam string value");
|
||||
}
|
||||
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
||||
}
|
||||
|
||||
private static Property createCTTwoPrimComplexProperty(final Short number, final String text) {
|
||||
ComplexValue compValue = new ComplexValue();
|
||||
Property propInt = new Property();
|
||||
propInt.setName("PropertyInt16");
|
||||
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;
|
||||
private static Property createCTTwoPrimComplexProperty(final String name, final Short number, final String text) {
|
||||
return DataCreator.createComplex(name,
|
||||
DataCreator.createPrimitive("PropertyInt16", number),
|
||||
DataCreator.createPrimitive("PropertyString", text));
|
||||
}
|
||||
|
||||
protected static Property complexCollectionAction(final String name, final Map<String, Parameter> parameters)
|
||||
throws DataProviderException {
|
||||
if ("UARTCollCTTwoPrimParam".equals(name)) {
|
||||
List<ComplexValue> complexCollection = new ArrayList<ComplexValue>();
|
||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 16, "Test123").asComplex());
|
||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 17, "Test456").asComplex());
|
||||
complexCollection.add(createCTTwoPrimComplexProperty((short) 18, "Test678").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();
|
||||
complexCollProperty.setValue(ValueType.COLLECTION_COMPLEX, complexCollection);
|
||||
return complexCollProperty;
|
||||
final Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||
final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive();
|
||||
if (number >= 1) {
|
||||
complexCollection.add(createCTTwoPrimComplexProperty(null, (short) 16, "Test123").asComplex());
|
||||
}
|
||||
if (number >= 2) {
|
||||
complexCollection.add(createCTTwoPrimComplexProperty(null, (short) 17, "Test456").asComplex());
|
||||
}
|
||||
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.");
|
||||
}
|
||||
|
||||
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)) {
|
||||
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");
|
||||
for (Entity entity : entityCollection.getEntities()) {
|
||||
|
@ -180,7 +171,8 @@ public class ActionData {
|
|||
}
|
||||
}
|
||||
} 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);
|
||||
} else {
|
||||
return new EntityActionResult().setEntity(entityCollection.getEntities().get(0));
|
||||
|
@ -189,8 +181,9 @@ public class ActionData {
|
|||
throw new DataProviderException("Action " + name + " is not yet implemented.");
|
||||
}
|
||||
|
||||
private static Entity createAllPrimEntity(final Short key, final String val, final Calendar date) {
|
||||
return new Entity().addProperty(DataCreator.createPrimitive("PropertyInt16", key))
|
||||
private static Entity createAllPrimEntity(final Short key, final String val, final Calendar date,
|
||||
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("PropertyBoolean", false))
|
||||
.addProperty(DataCreator.createPrimitive("PropertyByte", null))
|
||||
|
@ -206,28 +199,31 @@ public class ActionData {
|
|||
.addProperty(DataCreator.createPrimitive("PropertyDuration", null))
|
||||
.addProperty(DataCreator.createPrimitive("PropertyGuid", 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)
|
||||
throws DataProviderException {
|
||||
protected static EntityCollection entityCollectionAction(final String name, final Map<String, Parameter> parameters,
|
||||
final OData oData, final Edm edm) throws DataProviderException {
|
||||
if ("UARTCollETKeyNavParam".equals(name)) {
|
||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||
final Short number = paramInt16 == null ? 0 : (Short) paramInt16.asPrimitive();
|
||||
EntityCollection collection = new EntityCollection();
|
||||
Parameter paramInt16 = parameters.get("ParameterInt16");
|
||||
final Short number = paramInt16 == null || paramInt16.isNull() ? 0 : (Short) paramInt16.asPrimitive();
|
||||
if (number > 0) {
|
||||
for (short i = 1; i <= number; i++) {
|
||||
collection.getEntities().add(createETKeyNavEntity(i));
|
||||
collection.getEntities().add(createETKeyNavEntity(i, oData, edm));
|
||||
}
|
||||
}
|
||||
return collection;
|
||||
} else if ("UARTCollETAllPrimParam".equals(name)) {
|
||||
Parameter paramTimeOfDay = parameters.get("ParameterTimeOfDay");
|
||||
EntityCollection collection = new EntityCollection();
|
||||
if (paramTimeOfDay != null) {
|
||||
Parameter paramTimeOfDay = parameters.get("ParameterTimeOfDay");
|
||||
if (paramTimeOfDay != null && !paramTimeOfDay.isNull()) {
|
||||
Calendar timeOfDay = (Calendar) paramTimeOfDay.asPrimitive();
|
||||
int count = timeOfDay.get(Calendar.HOUR_OF_DAY);
|
||||
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;
|
||||
|
@ -236,8 +232,9 @@ public class ActionData {
|
|||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
private static Entity createETKeyNavEntity(final Short number) {
|
||||
return new Entity()
|
||||
private static Entity createETKeyNavEntity(final Short number, final OData oData, final Edm edm)
|
||||
throws DataProviderException {
|
||||
Entity entity = new Entity()
|
||||
.addProperty(DataCreator.createPrimitive("PropertyInt16", number))
|
||||
.addProperty(DataCreator.createPrimitive("PropertyString", "UARTCollETKeyNavParam int16 value: " + number))
|
||||
.addProperty(DataCreator.createComplex("PropertyCompNav",
|
||||
|
@ -253,6 +250,18 @@ public class ActionData {
|
|||
DataCreator.createPrimitive("PropertyString", ""),
|
||||
DataCreator.createComplex("PropertyCompNav",
|
||||
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) {
|
||||
|
|
|
@ -77,9 +77,12 @@ public class DataProvider {
|
|||
}
|
||||
|
||||
public EntityCollection readAll(final EdmEntitySet edmEntitySet) throws DataProviderException {
|
||||
final EntityCollection entityCollection = data.get(edmEntitySet.getName());
|
||||
|
||||
return (entityCollection == null) ? createEntityCollection(edmEntitySet) : entityCollection;
|
||||
EntityCollection entityCollection = data.get(edmEntitySet.getName());
|
||||
if (entityCollection == null) {
|
||||
entityCollection = new EntityCollection();
|
||||
data.put(edmEntitySet.getName(), entityCollection);
|
||||
}
|
||||
return entityCollection;
|
||||
}
|
||||
|
||||
public Entity read(final EdmEntitySet edmEntitySet, final List<UriParameter> keys) throws DataProviderException {
|
||||
|
@ -146,7 +149,7 @@ public class DataProvider {
|
|||
final EdmEntityType edmEntityType = edmEntitySet.getEntityType();
|
||||
EntityCollection entitySet = readAll(edmEntitySet);
|
||||
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();
|
||||
newEntity.setType(edmEntityType.getFullQualifiedName().getFullQualifiedNameAsString());
|
||||
for (final String keyName : edmEntityType.getKeyPredicateNames()) {
|
||||
|
@ -163,14 +166,6 @@ public class DataProvider {
|
|||
|
||||
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)
|
||||
throws DataProviderException {
|
||||
|
@ -545,12 +540,12 @@ public class DataProvider {
|
|||
|
||||
public EntityActionResult processActionEntity(final String name, final Map<String, Parameter> actionParameters)
|
||||
throws DataProviderException {
|
||||
return ActionData.entityAction(name, actionParameters, data);
|
||||
return ActionData.entityAction(name, actionParameters, data, odata, edm);
|
||||
}
|
||||
|
||||
public EntityCollection processActionEntityCollection(final String name,
|
||||
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,
|
||||
|
|
|
@ -161,7 +161,7 @@ public class ActionDataProviderTest {
|
|||
paramInt16.setValue(ValueType.PRIMITIVE, new Short((short) 32767));
|
||||
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);
|
||||
assertFalse(result.isCreated());
|
||||
assertEquals((short) 32767, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||
|
@ -175,7 +175,7 @@ public class ActionDataProviderTest {
|
|||
final Map<String, Parameter> parameters = Collections.singletonMap("ParameterInt16", paramInt16);
|
||||
|
||||
try {
|
||||
ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data);
|
||||
ActionData.entityAction("UARTETTwoKeyTwoPrimParam", parameters, data, oData, edm);
|
||||
fail("Expected a DataProviderException but wasn't thrown");
|
||||
} catch (DataProviderException e) {
|
||||
assertEquals("Entity not found with key: 12345", e.getMessage());
|
||||
|
@ -186,7 +186,7 @@ public class ActionDataProviderTest {
|
|||
@Test
|
||||
public void actionUARTETAllPrimParamWithoutParam() throws Exception {
|
||||
final EntityActionResult result = ActionData.entityAction("UARTETAllPrimParam",
|
||||
Collections.<String, Parameter> emptyMap(), data);
|
||||
Collections.<String, Parameter> emptyMap(), data, oData, edm);
|
||||
assertNotNull(result);
|
||||
assertFalse(result.isCreated());
|
||||
assertEquals(Short.MAX_VALUE, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||
|
@ -199,7 +199,7 @@ public class ActionDataProviderTest {
|
|||
paramDate.setValue(ValueType.PRIMITIVE, null);
|
||||
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);
|
||||
assertTrue(result.isCreated());
|
||||
assertEquals((short) 1, result.getEntity().getProperty("PropertyInt16").asPrimitive());
|
||||
|
@ -212,7 +212,7 @@ public class ActionDataProviderTest {
|
|||
paramInt16.setValue(ValueType.PRIMITIVE, Short.valueOf((short) 5));
|
||||
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);
|
||||
assertEquals(5, result.getEntities().size());
|
||||
}
|
||||
|
@ -224,7 +224,7 @@ public class ActionDataProviderTest {
|
|||
paramTimeOfDay.setValue(ValueType.PRIMITIVE, getTime(5, 0, 0));
|
||||
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);
|
||||
assertEquals(5, result.getEntities().size());
|
||||
}
|
||||
|
@ -232,7 +232,7 @@ public class ActionDataProviderTest {
|
|||
@Test
|
||||
public void actionUARTCollETAllPrimParamNoParam() throws Exception {
|
||||
final EntityCollection result = ActionData.entityCollectionAction("UARTCollETAllPrimParam",
|
||||
Collections.<String, Parameter> emptyMap());
|
||||
Collections.<String, Parameter> emptyMap(), oData, edm);
|
||||
assertNotNull(result);
|
||||
assertEquals(0, result.getEntities().size());
|
||||
}
|
||||
|
|
|
@ -16,25 +16,23 @@
|
|||
* specific language governing permissions and limitations
|
||||
* 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.InputStream;
|
||||
import java.util.Collections;
|
||||
|
||||
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.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
|
||||
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(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
|
||||
|
||||
protected static final String NAMESPACE = "Namespace1_Alias";
|
||||
protected static final Edm edm = OData.newInstance()
|
||||
.createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference> emptyList())
|
||||
.getEdm();
|
||||
|
||||
protected InputStream getFileAsStream(final String filename) throws IOException {
|
||||
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.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.io.InputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import org.apache.olingo.commons.api.Constants;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
import org.apache.olingo.commons.api.data.Link;
|
||||
import org.apache.olingo.commons.api.edm.EdmEntityType;
|
||||
import org.apache.olingo.commons.api.edm.FullQualifiedName;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTest {
|
||||
|
||||
@Test
|
||||
public void esAllPrimExpandedToOne() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOne.json");
|
||||
Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType).getEntity();
|
||||
final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOne.json");
|
||||
|
||||
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimOne");
|
||||
assertNotNull(navigationLink);
|
||||
|
||||
|
@ -51,16 +50,12 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
|||
|
||||
@Test
|
||||
public void esAllPrimExpandedToOneWithODataAnnotations() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithODataAnnotations.json");
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
||||
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithODataAnnotations.json");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void esAllPrimExpandedToMany() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");
|
||||
Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType).getEntity();
|
||||
final Entity entity = deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimMany.json");
|
||||
|
||||
Link navigationLink = entity.getNavigationLink("NavPropertyETTwoPrimMany");
|
||||
assertNotNull(navigationLink);
|
||||
|
@ -74,61 +69,46 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
|||
|
||||
@Test
|
||||
public void esAllPrimExpandedToManyWithODataAnnotations() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithODataAnnotations.json");
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
||||
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithODataAnnotations.json");
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void esAllPrimExpandedToOneWithCustomAnnotations() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithCustomAnnotations.json");
|
||||
try {
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType);
|
||||
} catch (DeserializerException e) {
|
||||
deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimOneWithCustomAnnotations.json");
|
||||
fail("Expected exception not thrown.");
|
||||
} catch (final DeserializerException e) {
|
||||
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
|
||||
public void expandedToOneValidNullValue() throws Exception {
|
||||
String entityString =
|
||||
final Entity entity = ODataJsonDeserializerEntityTest.deserialize(
|
||||
"{\"PropertyInt16\":32767,"
|
||||
+ "\"NavPropertyETAllPrimOne\":null"
|
||||
+ "}";
|
||||
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoPrim"));
|
||||
final Entity entity = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(stream, edmEntityType)
|
||||
.getEntity();
|
||||
+ "}",
|
||||
"ETTwoPrim");
|
||||
|
||||
assertEquals(1, entity.getNavigationLinks().size());
|
||||
final Link link = entity.getNavigationLinks().get(0);
|
||||
|
@ -138,51 +118,38 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe
|
|||
assertNull(link.getInlineEntitySet());
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void expandedToOneInvalidStringValue() throws Exception {
|
||||
String entityString =
|
||||
ODataJsonDeserializerEntityTest.expectException(
|
||||
"{\"PropertyInt16\":32767,"
|
||||
+ "\"NavPropertyETTwoPrimOne\":\"First Resource - positive values\""
|
||||
+ "}";
|
||||
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_VALUE_FOR_NAVIGATION_PROPERTY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
+ "}",
|
||||
"ETAllPrim",
|
||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void expandedToManyInvalidNullValue() throws Exception {
|
||||
String entityString =
|
||||
ODataJsonDeserializerEntityTest.expectException(
|
||||
"{\"PropertyInt16\":32767,"
|
||||
+ "\"NavPropertyETTwoPrimMany\":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;
|
||||
}
|
||||
+ "}",
|
||||
"ETAllPrim",
|
||||
DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void expandedToManyInvalidStringValue() throws Exception {
|
||||
String entityString =
|
||||
ODataJsonDeserializerEntityTest.expectException(
|
||||
"{\"PropertyInt16\":32767,"
|
||||
+ "\"NavPropertyETTwoPrimMany\":\"First Resource - positive values\""
|
||||
+ "}";
|
||||
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_VALUE_FOR_NAVIGATION_PROPERTY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
+ "}",
|
||||
"ETAllPrim",
|
||||
DeserializerException.MessageKeys.INVALID_VALUE_FOR_NAVIGATION_PROPERTY);
|
||||
}
|
||||
|
||||
private Entity deserialize(final String resourceName) throws IOException, DeserializerException {
|
||||
return ODataJsonDeserializerEntityTest.deserialize(getFileAsStream(resourceName),
|
||||
"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.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
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.EntityCollection;
|
||||
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.format.ContentType;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||
import org.junit.Test;
|
||||
|
||||
public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserializerTest {
|
||||
|
||||
@Test
|
||||
public void esAllPrim() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("ESAllPrim.json");
|
||||
EntityCollection entitySet =
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
||||
.getEntityCollection();
|
||||
|
||||
final EntityCollection entitySet = deserialize(getFileAsStream("ESAllPrim.json"), "ETAllPrim");
|
||||
assertNotNull(entitySet);
|
||||
assertEquals(3, entitySet.getEntities().size());
|
||||
|
||||
|
@ -75,12 +72,7 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
|
|||
|
||||
@Test
|
||||
public void eSCompCollComp() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompCollComp"));
|
||||
InputStream stream = getFileAsStream("ESCompCollComp.json");
|
||||
EntityCollection entitySet =
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
||||
.getEntityCollection();
|
||||
|
||||
final EntityCollection entitySet = deserialize(getFileAsStream("ESCompCollComp.json"), "ETCompCollComp");
|
||||
assertNotNull(entitySet);
|
||||
assertEquals(2, entitySet.getEntities().size());
|
||||
|
||||
|
@ -89,172 +81,115 @@ public class ODataDeserializerEntityCollectionTest extends AbstractODataDeserial
|
|||
|
||||
@Test
|
||||
public void esAllPrimODataAnnotationsAreIgnored() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("ESAllPrimWithODataAnnotations.json");
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
||||
deserialize(getFileAsStream("ESAllPrimWithODataAnnotations.json"), "ETAllPrim");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void emptyETAllPrim() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : []}";
|
||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
EntityCollection entityCollection =
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType)
|
||||
.getEntityCollection();
|
||||
final EntityCollection entityCollection = deserialize(entityCollectionString, "ETAllPrim");
|
||||
assertNotNull(entityCollection.getEntities());
|
||||
assertTrue(entityCollection.getEntities().isEmpty());
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void esAllPrimCustomAnnotationsLeadToNotImplemented() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("ESAllPrimWithCustomAnnotations.json");
|
||||
try {
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
||||
} catch (DeserializerException e) {
|
||||
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException(getFileAsStream("ESAllPrimWithCustomAnnotations.json"), "ETAllPrim",
|
||||
DeserializerException.MessageKeys.NOT_IMPLEMENTED);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void esAllPrimDoubleKeysLeadToException() throws Exception {
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
InputStream stream = getFileAsStream("ESAllPrimWithDoubleKey.json");
|
||||
try {
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
||||
} catch (DeserializerException e) {
|
||||
assertEquals(DeserializerException.MessageKeys.DUPLICATE_JSON_PROPERTY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException(getFileAsStream("ESAllPrimWithDoubleKey.json"), "ETAllPrim",
|
||||
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongValueTagJsonValueNull() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : 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.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : null}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongValueTagJsonValueNumber() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : 1234}";
|
||||
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.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : 1234}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongValueTagJsonValueObject() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : {}}";
|
||||
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.VALUE_TAG_MUST_BE_AN_ARRAY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : {}}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.VALUE_TAG_MUST_BE_AN_ARRAY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void valueTagMissing() throws Exception {
|
||||
String entityCollectionString = "{}";
|
||||
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.VALUE_ARRAY_NOT_PRESENT, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.VALUE_ARRAY_NOT_PRESENT);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongValueInValueArrayNumber() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : [1234,123]}";
|
||||
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.INVALID_ENTITY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : [1234,123]}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongValueInValueArrayNestedArray() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : [[],[]]}";
|
||||
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.INVALID_ENTITY, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : [[],[]]}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.INVALID_ENTITY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void invalidJsonSyntax() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : }";
|
||||
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.JSON_SYNTAX_EXCEPTION, e.getMessageKey());
|
||||
throw e;
|
||||
}
|
||||
expectException("{\"value\" : }", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void emptyInput() throws Exception {
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(
|
||||
new ByteArrayInputStream(new byte[] {}),
|
||||
edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
|
||||
expectException("", "ETAllPrim", DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void unknownContentInCollection() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : [],"
|
||||
+ "\"unknown\":null"
|
||||
+ "}";
|
||||
InputStream stream = new ByteArrayInputStream(entityCollectionString.getBytes());
|
||||
EdmEntityType edmEntityType = edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"));
|
||||
expectException("{\"value\":[],\"unknown\":null}", "ETAllPrim",
|
||||
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
|
||||
}
|
||||
|
||||
@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 {
|
||||
OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
|
||||
} catch (DeserializerException e) {
|
||||
assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
|
||||
throw e;
|
||||
deserialize(stream, entityTypeName);
|
||||
fail("Expected exception not thrown.");
|
||||
} catch (final DeserializerException e) {
|
||||
assertEquals(messageKey, e.getMessageKey());
|
||||
}
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
public void customAnnotationNotSupportedYet() throws Exception {
|
||||
String entityCollectionString = "{\"value\" : [],"
|
||||
+ "\"@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;
|
||||
}
|
||||
private void expectException(final String entityCollectionString, final String entityTypeName,
|
||||
final DeserializerException.MessageKeys messageKey) {
|
||||
expectException(new ByteArrayInputStream(entityCollectionString.getBytes()), entityTypeName, messageKey);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,184 +19,190 @@
|
|||
package org.apache.olingo.server.core.deserializer.json;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
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.Property;
|
||||
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.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.core.edm.EdmActionImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
|
||||
import org.apache.olingo.commons.api.format.ContentType;
|
||||
import org.apache.olingo.server.api.OData;
|
||||
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.mockito.Mockito;
|
||||
|
||||
public class ODataJsonDeserializerActionParametersTest extends AbstractODataDeserializerTest {
|
||||
|
||||
@Test
|
||||
public void empty() throws Exception {
|
||||
final String input = "{}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UART");
|
||||
final Map<String, Parameter> parameters = deserialize("{}", "UART", null);
|
||||
assertNotNull(parameters);
|
||||
assertTrue(parameters.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void primitive() throws Exception {
|
||||
final String input = "{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
||||
final Map<String, Parameter> parameters = deserialize(
|
||||
"{\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}",
|
||||
"UARTTwoParam", null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(2, parameters.size());
|
||||
Parameter parameter = parameters.get("ParameterInt16");
|
||||
assertNotNull(parameter);
|
||||
assertTrue(parameter.isPrimitive());
|
||||
assertFalse(parameter.isCollection());
|
||||
assertEquals((short) 42, parameter.getValue());
|
||||
parameter = parameters.get("ParameterDuration");
|
||||
assertNotNull(parameter);
|
||||
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
|
||||
public void complex() throws Exception {
|
||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
||||
CsdlComplexType address = new CsdlComplexType();
|
||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
||||
createProperty("Zip", "Edm.Int32")));
|
||||
address.setName("Address");
|
||||
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>();
|
||||
parameters.add(createParam("param1", "Edm.Int16"));
|
||||
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");
|
||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
||||
|
||||
final String input = "{\n" +
|
||||
" \"param1\": 42,\n" +
|
||||
" \"param2\": {\n" +
|
||||
" \"Street\": \"One 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)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());
|
||||
EdmParameter parameter = mock(EdmParameter.class);
|
||||
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||
EdmAction action = mock(EdmAction.class);
|
||||
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||
|
||||
final String input = "{\"Parameter\": { \"PropertyString\": \"Yes\", \"PropertyInt16\": 42 }}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||
|
||||
assertNotNull(parameters);
|
||||
assertEquals(1, parameters.size());
|
||||
final Parameter parameterData = parameters.get("Parameter");
|
||||
assertNotNull(parameterData);
|
||||
assertTrue(parameterData.isComplex());
|
||||
assertFalse(parameterData.isCollection());
|
||||
final List<Property> complexValues = parameterData.asComplex().getValue();
|
||||
assertEquals((short) 42, complexValues.get(0).getValue());
|
||||
assertEquals("Yes", complexValues.get(1).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void complexCollection() throws Exception {
|
||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
||||
CsdlComplexType address = new CsdlComplexType();
|
||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
||||
createProperty("Zip", "Edm.Int32")));
|
||||
address.setName("Address");
|
||||
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>();
|
||||
parameters.add(createParam("param1", "Edm.Int16"));
|
||||
parameters.add(createParam("param2", "namespace.Address").setCollection(true));
|
||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
||||
|
||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
||||
|
||||
final String input = "{\n" +
|
||||
" \"param1\": 42,\n" +
|
||||
" \"param2\": [{\n" +
|
||||
" \"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());
|
||||
EdmParameter parameter = mock(EdmParameter.class);
|
||||
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||
when(parameter.isCollection()).thenReturn(true);
|
||||
EdmAction action = mock(EdmAction.class);
|
||||
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||
|
||||
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());
|
||||
}
|
||||
final String input = "{\"Parameter\": [\n"
|
||||
+ " { \"PropertyInt16\": 9999, \"PropertyString\": \"One\" },\n"
|
||||
+ " { \"PropertyInt16\": -123, \"PropertyString\": \"Two\" }]}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||
|
||||
private CsdlParameter createParam(String name, String type) {
|
||||
return new CsdlParameter().setName(name).setType(new FullQualifiedName(type));
|
||||
}
|
||||
assertNotNull(parameters);
|
||||
assertEquals(1, parameters.size());
|
||||
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());
|
||||
|
||||
private CsdlProperty createProperty(String name, String type) {
|
||||
return new CsdlProperty().setName(name).setType(type);
|
||||
complexValue = (ComplexValue) parameterData.asCollection().get(1);
|
||||
assertEquals((short) -123, complexValue.getValue().get(0).getValue());
|
||||
assertEquals("Two", complexValue.getValue().get(1).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
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());
|
||||
}
|
||||
|
||||
@Test
|
||||
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
|
||||
public void boundEmpty() throws Exception {
|
||||
final String input = "{}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
||||
final Map<String, Parameter> parameters = deserialize("{}", "BAETAllPrimRT", "ETAllPrim");
|
||||
assertNotNull(parameters);
|
||||
assertTrue(parameters.isEmpty());
|
||||
}
|
||||
|
@ -206,7 +212,7 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
|||
final String input =
|
||||
"{\"ParameterDuration@odata.type\":\"Edm.Duration\","
|
||||
+ "\"ParameterDuration\":\"P42DT11H22M33S\",\"ParameterInt16\":42}";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam", null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(2, parameters.size());
|
||||
Parameter parameter = parameters.get("ParameterInt16");
|
||||
|
@ -218,9 +224,9 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testParameterWithNullLiteral() throws Exception {
|
||||
final Map<String, Parameter> parameters = deserialize("{\"ParameterInt16\":1,\"ParameterDuration\":null}",
|
||||
"UARTCollStringTwoParam");
|
||||
public void parameterWithNullLiteral() throws Exception {
|
||||
final Map<String, Parameter> parameters = deserialize("{\"ParameterInt16\":1,\"ParameterDuration\":null}",
|
||||
"UARTCollStringTwoParam", null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(2, parameters.size());
|
||||
Parameter parameter = parameters.get("ParameterInt16");
|
||||
|
@ -231,52 +237,60 @@ public class ODataJsonDeserializerActionParametersTest extends AbstractODataDese
|
|||
assertEquals(null, parameter.getValue());
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
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 {
|
||||
deserialize("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim");
|
||||
expectException("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim",
|
||||
MessageKeys.UNKNOWN_CONTENT);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
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)
|
||||
@Test
|
||||
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 {
|
||||
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 {
|
||||
deserialize("{\"ParameterInt16\":\"42\"}", "UARTParam");
|
||||
}
|
||||
|
||||
private Map<String, Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
|
||||
return OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
||||
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
|
||||
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, final String typeName)
|
||||
private Map<String, Parameter> deserialize(final String input, final EdmAction action) throws DeserializerException {
|
||||
return OData.newInstance().createDeserializer(ContentType.JSON)
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action)
|
||||
.getActionParameters();
|
||||
}
|
||||
|
||||
private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName)
|
||||
throws DeserializerException {
|
||||
return OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
||||
edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
|
||||
new FullQualifiedName("Namespace1_Alias", typeName), false)).getActionParameters();
|
||||
return deserialize(input,
|
||||
bindingTypeName == null ?
|
||||
edm.getUnboundAction(new FullQualifiedName(NAMESPACE, actionName)) :
|
||||
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;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
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.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.EdmParameter;
|
||||
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
|
||||
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.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.deserializer.DeserializerException;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
|
||||
import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys;
|
||||
import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||
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
|
||||
public void empty() throws Exception {
|
||||
final String input = "";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UART");
|
||||
final Map<String, Parameter> parameters = deserialize(PREAMBLE + POSTAMBLE, "UART", null);
|
||||
assertNotNull(parameters);
|
||||
assertTrue(parameters.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void primitive() throws Exception {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterInt16>42</ParameterInt16>"
|
||||
+"<ParameterDuration>P42DT11H22M33S</ParameterDuration>"
|
||||
+"</metadata:parameters>";
|
||||
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam");
|
||||
final String input = PREAMBLE
|
||||
+ "<ParameterDuration>P42DT11H22M33S</ParameterDuration>"
|
||||
+ "<ParameterInt16>42</ParameterInt16>"
|
||||
+ POSTAMBLE;
|
||||
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTTwoParam", null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(2, parameters.size());
|
||||
Parameter parameter = parameters.get("ParameterInt16");
|
||||
|
@ -80,158 +78,115 @@ public class ODataXMLDeserializerActionParametersTest {
|
|||
assertNotNull(parameter);
|
||||
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
|
||||
public void complex() throws Exception {
|
||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
||||
CsdlComplexType address = new CsdlComplexType();
|
||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
||||
createProperty("Zip", "Edm.Int32")));
|
||||
address.setName("Address");
|
||||
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>();
|
||||
parameters.add(createParam("param1", "Edm.Int16"));
|
||||
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");
|
||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
||||
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">\n" +
|
||||
" <param1>42</param1>\n" +
|
||||
" <param2 metadata:type=\"#namespace.Address\">\n" +
|
||||
" <Street>One Microsoft Way</Street>\n" +
|
||||
" <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());
|
||||
EdmParameter parameter = mock(EdmParameter.class);
|
||||
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||
EdmAction action = mock(EdmAction.class);
|
||||
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||
|
||||
final String input = PREAMBLE
|
||||
+ "<Parameter>"
|
||||
+ "<PropertyInt16>42</PropertyInt16>"
|
||||
+ "<PropertyString>Yes</PropertyString>"
|
||||
+ "</Parameter>"
|
||||
+ POSTAMBLE;
|
||||
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||
|
||||
assertNotNull(parameters);
|
||||
assertEquals(1, parameters.size());
|
||||
final Parameter parameterData = parameters.get("Parameter");
|
||||
assertNotNull(parameterData);
|
||||
assertTrue(parameterData.isComplex());
|
||||
assertFalse(parameterData.isCollection());
|
||||
final List<Property> complexValues = parameterData.asComplex().getValue();
|
||||
assertEquals((short) 42, complexValues.get(0).getValue());
|
||||
assertEquals("Yes", complexValues.get(1).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void complexCollection() throws Exception {
|
||||
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
||||
CsdlComplexType address = new CsdlComplexType();
|
||||
address.setProperties(Arrays.asList(createProperty("Street", "Edm.String"),
|
||||
createProperty("Zip", "Edm.Int32")));
|
||||
address.setName("Address");
|
||||
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>();
|
||||
parameters.add(createParam("param1", "Edm.Int16"));
|
||||
parameters.add(createParam("param2", "namespace.Address").setCollection(true));
|
||||
parameters.add(createParam("param3", "Edm.Int32").setCollection(true));
|
||||
parameters.add(createParam("param4", "Edm.String").setNullable(true));
|
||||
|
||||
FullQualifiedName actionName = new FullQualifiedName("namespace", "action");
|
||||
CsdlAction csdlAction = new CsdlAction().setName("action1").setParameters(parameters);
|
||||
EdmAction action = new EdmActionImpl(provider, actionName, csdlAction);
|
||||
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>" +
|
||||
"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">\n" +
|
||||
" <param1>42</param1>\n" +
|
||||
" <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());
|
||||
EdmParameter parameter = mock(EdmParameter.class);
|
||||
when(parameter.getType()).thenReturn(edm.getComplexType(new FullQualifiedName(NAMESPACE, "CTTwoPrim")));
|
||||
when(parameter.isCollection()).thenReturn(true);
|
||||
EdmAction action = mock(EdmAction.class);
|
||||
when(action.getParameterNames()).thenReturn(Collections.singletonList("Parameter"));
|
||||
when(action.getParameter("Parameter")).thenReturn(parameter);
|
||||
|
||||
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());
|
||||
}
|
||||
final String input = PREAMBLE
|
||||
+ "<Parameter>"
|
||||
+ "<metadata:element>"
|
||||
+ "<PropertyInt16>9999</PropertyInt16><PropertyString>One</PropertyString>"
|
||||
+ "</metadata:element>"
|
||||
+ "<metadata:element>"
|
||||
+ "<PropertyInt16>-123</PropertyInt16><PropertyString>Two</PropertyString>"
|
||||
+ "</metadata:element>"
|
||||
+ "</Parameter>"
|
||||
+ POSTAMBLE;
|
||||
final Map<String, Parameter> parameters = deserialize(input, action);
|
||||
|
||||
private CsdlParameter createParam(String name, String type) {
|
||||
return new CsdlParameter().setName(name).setType(new FullQualifiedName(type));
|
||||
}
|
||||
assertNotNull(parameters);
|
||||
assertEquals(1, parameters.size());
|
||||
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());
|
||||
|
||||
private CsdlProperty createProperty(String name, String type) {
|
||||
return new CsdlProperty().setName(name).setType(type);
|
||||
complexValue = (ComplexValue) parameterData.asCollection().get(1);
|
||||
assertEquals((short) -123, complexValue.getValue().get(0).getValue());
|
||||
assertEquals("Two", complexValue.getValue().get(1).getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void boundEmpty() throws Exception {
|
||||
final String input = "";
|
||||
final Map<String, Parameter> parameters = deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
||||
final Map<String, Parameter> parameters = deserialize(PREAMBLE + POSTAMBLE,
|
||||
"BAETAllPrimRT", "ETAllPrim");
|
||||
assertNotNull(parameters);
|
||||
assertTrue(parameters.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testParameterWithNullLiteral() throws Exception {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterInt16>1</ParameterInt16>"
|
||||
+"</metadata:parameters>";
|
||||
|
||||
final Map<String, Parameter> parameters = deserialize(input,
|
||||
"UARTCollStringTwoParam");
|
||||
public void parameterWithNullLiteral() throws Exception {
|
||||
final String input = PREAMBLE
|
||||
+ "<ParameterInt16>1</ParameterInt16>"
|
||||
+ "<ParameterDuration metadata:null=\"true\" />"
|
||||
+ POSTAMBLE;
|
||||
final Map<String, Parameter> parameters = deserialize(input, "UARTCollStringTwoParam", null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(2, parameters.size());
|
||||
Parameter parameter = parameters.get("ParameterInt16");
|
||||
|
@ -241,63 +196,62 @@ public class ODataXMLDeserializerActionParametersTest {
|
|||
assertNotNull(parameter);
|
||||
assertEquals(null, parameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void bindingParameter() throws Exception {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterETAllPrim>1</ParameterETAllPrim>"
|
||||
+"</metadata:parameters>";
|
||||
final String input = PREAMBLE + "<ParameterETAllPrim>1</ParameterETAllPrim>" + POSTAMBLE;
|
||||
deserialize(input, "BAETAllPrimRT", "ETAllPrim");
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void wrongName() throws Exception {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterWrong>1</ParameterWrong>"
|
||||
+"</metadata:parameters>";
|
||||
deserialize(input, "UARTParam");
|
||||
expectException(PREAMBLE + "<ParameterWrong>1</ParameterWrong>" + POSTAMBLE,
|
||||
"UARTParam", null, MessageKeys.UNKNOWN_CONTENT);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
public void nullNotNullable() throws Exception {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterInt16>null</ParameterInt16>"
|
||||
+"</metadata:parameters>";
|
||||
deserialize(input, "UARTCTTwoPrimParam");
|
||||
expectException(PREAMBLE + "<ParameterInt16>null</ParameterInt16>" + POSTAMBLE,
|
||||
"UARTCTTwoPrimParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
|
||||
}
|
||||
|
||||
@Test(expected = DeserializerException.class)
|
||||
@Test
|
||||
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 {
|
||||
final String input = "<?xml version='1.0' encoding='UTF-8'?>"
|
||||
+"<metadata:parameters xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+"<ParameterInt16>1</ParameterInt16>"
|
||||
+"<ParameterInt16>2</ParameterInt16>"
|
||||
+"</metadata:parameters>";
|
||||
deserialize(input, "UARTParam");
|
||||
}
|
||||
|
||||
protected static final Edm edm = OData.newInstance().createServiceMetadata(
|
||||
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)
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
||||
edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
|
||||
expectException(PREAMBLE
|
||||
+ "<ParameterInt16>1</ParameterInt16>"
|
||||
+ "<ParameterInt16>2</ParameterInt16>"
|
||||
+ POSTAMBLE,
|
||||
"UARTParam", null, MessageKeys.DUPLICATE_PROPERTY);
|
||||
}
|
||||
|
||||
private Map<String, Parameter> deserialize(final String input, final String actionName, final String typeName)
|
||||
throws DeserializerException {
|
||||
private Map<String, Parameter> deserialize(final String input, final EdmAction action) throws DeserializerException {
|
||||
return OData.newInstance().createDeserializer(ContentType.APPLICATION_XML)
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()),
|
||||
edm.getBoundAction(new FullQualifiedName("Namespace1_Alias", actionName),
|
||||
new FullQualifiedName("Namespace1_Alias", typeName), false)).getActionParameters();
|
||||
.actionParameters(new ByteArrayInputStream(input.getBytes()), action)
|
||||
.getActionParameters();
|
||||
}
|
||||
|
||||
private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName)
|
||||
throws DeserializerException {
|
||||
return deserialize(input,
|
||||
bindingTypeName == null ?
|
||||
edm.getUnboundAction(new FullQualifiedName(NAMESPACE, actionName)) :
|
||||
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;
|
||||
|
||||
import java.io.ByteArrayInputStream;
|
||||
import java.math.BigDecimal;
|
||||
import java.net.URI;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.olingo.commons.api.data.ComplexValue;
|
||||
import org.apache.olingo.commons.api.data.Entity;
|
||||
|
@ -40,39 +41,22 @@ import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
|
|||
import org.apache.olingo.commons.core.edm.EdmComplexTypeImpl;
|
||||
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.EdmByte;
|
||||
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.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.server.api.ServiceMetadata;
|
||||
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
|
||||
import org.apache.olingo.server.api.edmx.EdmxReference;
|
||||
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.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
|
||||
import org.custommonkey.xmlunit.XMLUnit;
|
||||
import org.junit.Assert;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
public class ODataXmlDeserializerTest {
|
||||
|
||||
private static final ServiceMetadata metadata = new ServiceMetadataImpl(
|
||||
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("WmetadataETag"));
|
||||
private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer();
|
||||
private final ODataDeserializer serializer = new ODataXmlDeserializer();
|
||||
|
||||
public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
|
||||
|
||||
private static final EdmEntityContainer entityContainer = edm.getEntityContainer();
|
||||
private final ODataDeserializer deserializer = new ODataXmlDeserializer();
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
XMLUnit.setIgnoreComments(true);
|
||||
|
@ -81,64 +65,24 @@ public class ODataXmlDeserializerTest {
|
|||
XMLUnit.setNormalizeWhitespace(true);
|
||||
XMLUnit.setCompareUnmatched(false);
|
||||
}
|
||||
|
||||
protected Object edmInt16(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmInt16.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
||||
EdmInt16.getInstance().getDefaultType());
|
||||
}
|
||||
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 byte[] edmBinary(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmBinary.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
byte[].class);
|
||||
}
|
||||
protected Object edmDate(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmDate.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
||||
EdmDate.getInstance().getDefaultType());
|
||||
return EdmDate.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmDate.getInstance().getDefaultType());
|
||||
}
|
||||
protected Object edmDateTimeOffset(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmDateTimeOffset.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
||||
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());
|
||||
return EdmDateTimeOffset.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmDateTimeOffset.getInstance().getDefaultType());
|
||||
}
|
||||
protected Object edmTimeOfDay(String value) throws EdmPrimitiveTypeException {
|
||||
return EdmTimeOfDay.getInstance().valueOfString(value, true, 10, 10, 10, true,
|
||||
EdmTimeOfDay.getInstance().getDefaultType());
|
||||
return EdmTimeOfDay.getInstance().valueOfString(value, true, null, null, null, true,
|
||||
EdmTimeOfDay.getInstance().getDefaultType());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void entitySimple() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
|
@ -179,32 +123,31 @@ public class ODataXmlDeserializerTest {
|
|||
" </atom:content>\n" +
|
||||
"</atom:entry>\n";
|
||||
|
||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
edmEntitySet.getEntityType()).getEntity();
|
||||
|
||||
Assert.assertEquals(16, result.getProperties().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(edmByte("255"), result.getProperty("PropertyByte").asPrimitive());
|
||||
Assert.assertEquals(edmSByte("127"), result.getProperty("PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(edmInt32("2147483647"), result.getProperty("PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(edmInt64("9223372036854775807"), result.getProperty("PropertyInt64").asPrimitive());
|
||||
Assert.assertEquals(edmSingle("1.79E20"), result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(edmDouble("-1.79E19"), result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(edmDecimal("34"), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
// Assert.assertEquals(edmBinary("ASNFZ4mrze8="), result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals((short) 255, result.getProperty("PropertyByte").asPrimitive());
|
||||
Assert.assertEquals((byte) 127, result.getProperty("PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(2147483647, result.getProperty("PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(9223372036854775807L, result.getProperty("PropertyInt64").asPrimitive());
|
||||
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(edmDuration("PT6S"), result.getProperty("PropertyDuration")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(edmGUID("01234567-89ab-cdef-0123-456789abcdef"), result.getProperty("PropertyGuid")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||
result.getProperty("PropertyGuid").asPrimitive());
|
||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void entitySimpleWithTypes() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
|
||||
|
@ -247,32 +190,31 @@ public class ODataXmlDeserializerTest {
|
|||
" </atom:content>\n" +
|
||||
"</atom:entry>\n";
|
||||
|
||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
edmEntitySet.getEntityType()).getEntity();
|
||||
|
||||
Assert.assertEquals(16, result.getProperties().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(edmByte("255"), result.getProperty("PropertyByte").asPrimitive());
|
||||
Assert.assertEquals(edmSByte("127"), result.getProperty("PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(edmInt32("2147483647"), result.getProperty("PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(edmInt64("9223372036854775807"), result.getProperty("PropertyInt64").asPrimitive());
|
||||
Assert.assertEquals(edmSingle("1.79E20"), result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(edmDouble("-1.79E19"), result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(edmDecimal("34"), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
// Assert.assertEquals(edmBinary("ASNFZ4mrze8="), result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals((short) 255, result.getProperty("PropertyByte").asPrimitive());
|
||||
Assert.assertEquals((byte) 127, result.getProperty("PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(2147483647, result.getProperty("PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(9223372036854775807L, result.getProperty("PropertyInt64").asPrimitive());
|
||||
Assert.assertEquals(1.79E20F, result.getProperty("PropertySingle").asPrimitive());
|
||||
Assert.assertEquals(-1.79E19, result.getProperty("PropertyDouble").asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(34), result.getProperty("PropertyDecimal").asPrimitive());
|
||||
Assert.assertArrayEquals(edmBinary("ASNFZ4mrze8="), (byte[]) result.getProperty("PropertyBinary").asPrimitive());
|
||||
Assert.assertEquals(edmDate("2012-12-03"), result.getProperty("PropertyDate").asPrimitive());
|
||||
Assert.assertEquals(edmDateTimeOffset("2012-12-03T07:16:23Z"), result.getProperty("PropertyDateTimeOffset")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(edmDuration("PT6S"), result.getProperty("PropertyDuration")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(edmGUID("01234567-89ab-cdef-0123-456789abcdef"), result.getProperty("PropertyGuid")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals(BigDecimal.valueOf(6), result.getProperty("PropertyDuration").asPrimitive());
|
||||
Assert.assertEquals(UUID.fromString("01234567-89ab-cdef-0123-456789abcdef"),
|
||||
result.getProperty("PropertyGuid").asPrimitive());
|
||||
Assert.assertEquals(edmTimeOfDay("03:26:05"), result.getProperty("PropertyTimeOfDay").asPrimitive());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void entityCompAllPrim() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
|
||||
|
@ -309,7 +251,7 @@ public class ODataXmlDeserializerTest {
|
|||
+ "</atom:content>"
|
||||
+ "</atom:entry>";
|
||||
|
||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
edmEntitySet.getEntityType()).getEntity();
|
||||
|
||||
Assert.assertEquals("olingo.odata.test1.ETCompAllPrim",result.getType());
|
||||
|
@ -317,8 +259,8 @@ public class ODataXmlDeserializerTest {
|
|||
Assert.assertEquals(2, result.getProperties().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"));
|
||||
Property comp = result.getProperty("PropertyComp");
|
||||
Assert.assertEquals("olingo.odata.test1.CTAllPrim", comp.getType());
|
||||
|
@ -326,14 +268,14 @@ public class ODataXmlDeserializerTest {
|
|||
|
||||
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(edmByte("255"), getCVProperty(cv, "PropertyByte").asPrimitive());
|
||||
Assert.assertEquals(edmSByte("127"), getCVProperty(cv, "PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(edmInt32("2147483647"), getCVProperty(cv, "PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(edmInt64("9223372036854775807"), getCVProperty(cv, "PropertyInt64").asPrimitive());
|
||||
Assert.assertEquals((short) 255, getCVProperty(cv, "PropertyByte").asPrimitive());
|
||||
Assert.assertEquals((byte) 127, getCVProperty(cv, "PropertySByte").asPrimitive());
|
||||
Assert.assertEquals(2147483647, getCVProperty(cv, "PropertyInt32").asPrimitive());
|
||||
Assert.assertEquals(9223372036854775807L, getCVProperty(cv, "PropertyInt64").asPrimitive());
|
||||
}
|
||||
|
||||
|
||||
private Property getCVProperty(ComplexValue cv, String name) {
|
||||
for (Property p:cv.getValue()) {
|
||||
if (p.getName().equals(name)) {
|
||||
|
@ -343,7 +285,6 @@ public class ODataXmlDeserializerTest {
|
|||
return null;
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void entityMixPrimCollComp() throws Exception {
|
||||
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
|
||||
|
@ -384,7 +325,7 @@ public class ODataXmlDeserializerTest {
|
|||
" </atom:content>\n" +
|
||||
"</atom:entry>\n";
|
||||
|
||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
edmEntitySet.getEntityType()).getEntity();
|
||||
|
||||
Assert.assertEquals(4, result.getProperties().size());
|
||||
|
@ -398,22 +339,22 @@ public class ODataXmlDeserializerTest {
|
|||
ComplexValue cv = (ComplexValue)comp.getValue();
|
||||
|
||||
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());
|
||||
|
||||
comp = result.getProperty("CollPropertyComp");
|
||||
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());
|
||||
@SuppressWarnings("unchecked")
|
||||
List<ComplexValue> properties = (List<ComplexValue>)comp.getValue();
|
||||
|
||||
Assert.assertEquals(3, properties.size());
|
||||
|
||||
Assert.assertEquals(edmInt16("123"), getCVProperty(properties.get(0), "PropertyInt16")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals("TEST 1", getCVProperty(properties.get(0), "PropertyString")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals((short) 123,
|
||||
getCVProperty(properties.get(0), "PropertyInt16").asPrimitive());
|
||||
Assert.assertEquals("TEST 1",
|
||||
getCVProperty(properties.get(0), "PropertyString").asPrimitive());
|
||||
|
||||
Assert.assertEquals(edmInt16("789"), getCVProperty(properties.get(2), "PropertyInt16")
|
||||
.asPrimitive());
|
||||
Assert.assertEquals((short) 789, getCVProperty(properties.get(2), "PropertyInt16").asPrimitive());
|
||||
Assert.assertEquals("TEST 3", getCVProperty(properties.get(2), "PropertyString")
|
||||
.asPrimitive());
|
||||
}
|
||||
|
@ -461,13 +402,13 @@ public class ODataXmlDeserializerTest {
|
|||
"</atom:entry>\n" +
|
||||
"";
|
||||
|
||||
Entity result = serializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
|
||||
edmEntitySet.getEntityType()).getEntity();
|
||||
|
||||
Assert.assertEquals(2, result.getProperties().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(1, result.getNavigationLinks().size());
|
||||
|
@ -491,8 +432,8 @@ public class ODataXmlDeserializerTest {
|
|||
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\">"
|
||||
+ "234</metadata:value>";
|
||||
|
||||
Property result = serializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||
Assert.assertEquals(edmInt16("234"), result.getValue());
|
||||
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
|
||||
Assert.assertEquals((short) 234, result.getValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -503,7 +444,7 @@ public class ODataXmlDeserializerTest {
|
|||
+ "<metadata:value xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\" "
|
||||
+ "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());
|
||||
}
|
||||
|
||||
|
@ -517,7 +458,7 @@ public class ODataXmlDeserializerTest {
|
|||
+ "<metadata:element>Employee2@company.example</metadata:element>"
|
||||
+ "<metadata:element>Employee3@company.example</metadata:element>"
|
||||
+ "</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",
|
||||
"Employee3@company.example"), result.getValue());
|
||||
|
||||
|
@ -557,7 +498,7 @@ public class ODataXmlDeserializerTest {
|
|||
" <data:PostalCode>12209</data:PostalCode>\n" +
|
||||
"</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.assertTrue(result.getValue() instanceof ComplexValue);
|
||||
|
@ -588,15 +529,15 @@ public class ODataXmlDeserializerTest {
|
|||
" <data:PropertyString>TEST 3</data:PropertyString>\n" +
|
||||
" </metadata:element>\n" +
|
||||
"</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();
|
||||
|
||||
Assert.assertEquals(3, complex.size());
|
||||
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(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());
|
||||
}
|
||||
|
||||
|
@ -607,7 +548,7 @@ public class ODataXmlDeserializerTest {
|
|||
" xmlns=\"http://www.w3.org/2005/Atom\" "+
|
||||
" 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();
|
||||
Assert.assertEquals(1, result.size());
|
||||
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" +
|
||||
"</feed>";
|
||||
|
||||
List<URI> result = serializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
||||
List<URI> result = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
|
||||
.getEntityReferences();
|
||||
Assert.assertEquals(2, result.size());
|
||||
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
|
||||
|
|
|
@ -18,12 +18,11 @@
|
|||
*/
|
||||
package org.apache.olingo.server.core.uri.antlr;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.olingo.commons.api.edm.Edm;
|
||||
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.server.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.server.api.uri.UriResourceKind;
|
||||
|
@ -326,7 +325,7 @@ public class TestUriParserImpl {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEntitySet() throws UnsupportedEncodingException {
|
||||
public void entitySet() throws Exception {
|
||||
|
||||
// plain entity set
|
||||
testRes.run("ESAllPrim")
|
||||
|
@ -351,7 +350,7 @@ public class TestUriParserImpl {
|
|||
.isKeyPredicate(1, "PropertyString", "'ABC'");
|
||||
|
||||
// with all keys
|
||||
testRes.run("ESAllKey(" + encode(allKeys) + ")")
|
||||
testRes.run("ESAllKey(" + Encoder.encode(allKeys) + ")")
|
||||
.isEntitySet("ESAllKey")
|
||||
.isKeyPredicate(0, "PropertyString", "'ABC'")
|
||||
.isKeyPredicate(1, "PropertyInt16", "1")
|
||||
|
@ -1165,8 +1164,4 @@ public class TestUriParserImpl {
|
|||
testUri.runEx("ESMixPrimCollComp", "$select=/PropertyInt16")
|
||||
.isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
||||
}
|
||||
|
||||
public static String encode(final String decoded) throws UnsupportedEncodingException {
|
||||
return URLEncoder.encode(decoded, "UTF-8");
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue