You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by mi...@apache.org on 2015/10/01 12:11:45 UTC
[1/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Repository: olingo-odata4
Updated Branches:
refs/heads/master b9403cd39 -> d6db341db
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXMLDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXMLDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXMLDeserializerActionParametersTest.java
index a533820..f50cbc9 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXMLDeserializerActionParametersTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXMLDeserializerActionParametersTest.java
@@ -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");
+ expectException(PREAMBLE
+ + "<ParameterInt16>1</ParameterInt16>"
+ + "<ParameterInt16>2</ParameterInt16>"
+ + POSTAMBLE,
+ "UARTParam", null, MessageKeys.DUPLICATE_PROPERTY);
}
-
- 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 {
+
+ 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.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
+ .actionParameters(new ByteArrayInputStream(input.getBytes()), action)
+ .getActionParameters();
}
- private Map<String, Parameter> deserialize(final String input, final String actionName, final String typeName)
+ private Map<String, Parameter> deserialize(final String input, final String actionName, final String bindingTypeName)
throws DeserializerException {
- 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();
+ 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());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
index 497e8f5..71f4d35 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
@@ -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());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
index 9f79a84..b115fb8 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -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");
- }
}
[2/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
index ff350a0..12ee6af 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerActionParametersTest.java
@@ -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());
-
- addressValue = (ComplexValue)((List<?>)parameter.getValue()).get(1);
- assertEquals("Two Microsoft Way", addressValue.getValue().get(0).getValue());
- assertEquals(98052, addressValue.getValue().get(1).getValue());
-
- parameter = response.get("param3");
- assertNotNull(parameter);
- assertEquals(Arrays.asList(1, 42, 99), parameter.getValue());
-
- parameter = response.get("param4");
- assertNull(parameter.getValue());
- }
-
- private CsdlParameter createParam(String name, String type) {
- return new CsdlParameter().setName(name).setType(new FullQualifiedName(type));
- }
-
- private CsdlProperty createProperty(String name, String type) {
- return new CsdlProperty().setName(name).setType(type);
+ 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);
+
+ final String input = "{\"Parameter\": [\n"
+ + " { \"PropertyInt16\": 9999, \"PropertyString\": \"One\" },\n"
+ + " { \"PropertyInt16\": -123, \"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.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());
+
+ 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");
- }
-
- @Test(expected = DeserializerException.class)
- public void wrongName() throws Exception {
- deserialize("{\"ParameterWrong\":null}", "UARTParam");
+ expectException("{\"ParameterETAllPrim\":{\"PropertyInt16\":42}}", "BAETAllPrimRT", "ETAllPrim",
+ MessageKeys.UNKNOWN_CONTENT);
}
- @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");
+ expectException("{\"ParameterInt16\":null}", "UARTCTTwoPrimParam", null, MessageKeys.INVALID_NULL_PARAMETER);
+ expectException("{\"ParameterInt16\":\"42\"}", "UARTParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
+ expectException("{\"ParameterInt16\":123456}", "UARTParam", null, MessageKeys.INVALID_VALUE_FOR_PROPERTY);
+ expectException("{\"ParameterInt16\":[42]}", "UARTParam", null, MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
-
- private Map<String, Parameter> deserialize(final String input, final String actionName) throws DeserializerException {
- return OData.newInstance().createDeserializer(CONTENT_TYPE_JSON)
- .actionParameters(new ByteArrayInputStream(input.getBytes()),
- edm.getUnboundAction(new FullQualifiedName("Namespace1_Alias", actionName))).getActionParameters();
+
+ 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 typeName)
+ 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());
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
index 02a461d..f3899d1 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java
@@ -31,7 +31,6 @@ import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.math.BigDecimal;
import java.util.ArrayList;
-import java.util.Collections;
import java.util.Date;
import java.util.List;
@@ -45,25 +44,24 @@ import org.apache.olingo.commons.api.edm.EdmEntityType;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.provider.CsdlMapping;
+import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDate;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.deserializer.DeserializerException;
import org.apache.olingo.server.api.deserializer.ODataDeserializer;
-import org.apache.olingo.server.api.edmx.EdmxReference;
-import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
+import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest;
import org.junit.Test;
public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTest {
+ private static final ContentType CONTENT_TYPE_JSON_IEEE754Compatible =
+ ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true");
+
@Test
public void emptyEntity() throws Exception {
- String entityString = "{}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final String entityString = "{}";
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -89,11 +87,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -136,11 +130,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -157,11 +147,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"" +
"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -187,11 +173,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -222,11 +204,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyInt64\":9223372036854775807," +
"\"PropertySByte\":127," +
"\"PropertyTimeOfDay\":\"01:00:01\"}}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETCompAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -264,17 +242,13 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"cccccc67-89ab-cdef-0123-456789cccccc\"],"
+ "\"CollPropertyTimeOfDay\":[\"04:14:13\",\"23:59:59\",\"01:12:33\"]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETCollAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
assertEquals(17, properties.size());
- // All properties need 3 entires
+ // All properties need 3 entries.
for (Property prop : properties) {
if (!prop.getName().equals("PropertyInt16")) {
assertEquals(ValueType.COLLECTION_PRIMITIVE, prop.getValueType());
@@ -301,12 +275,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -327,19 +296,14 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
}
@Test
- public void eTMixPrimCollCompMIssingPropertyInComplexType() throws Exception {
+ public void eTMixPrimCollCompMissingPropertyInComplexType() throws Exception {
final String entityString = "{"
+ "\"PropertyComp\":{\"PropertyInt16\":111},"
+ "\"CollPropertyComp\":["
+ "{\"PropertyInt16\":123},"
+ "{\"PropertyInt16\":456},"
+ "{\"PropertyInt16\":789}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -384,11 +348,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
}
@@ -402,9 +362,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"Association@odata.associationLink\":\"test\","
+ "\"PropertyString\":\"First Resource - positive values\""
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
+ deserialize(entityString, "ETAllPrim");
}
@Test
@@ -420,10 +378,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":456,\"Navigation@odata.navigationLink\": 12," +
"\"Association@odata.associationLink\": 12,\"PropertyString@odata.type\": 12,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
+ deserialize(entityString, "ETMixPrimCollComp");
}
@Test
@@ -442,11 +397,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\""
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -461,11 +412,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"NavPropertyETTwoPrimOne@odata.bind\":\"ESTwoPrim(2)\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":[\"ESTwoPrim(2)\",\"ESTwoPrim(3)\"]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
assertNotNull(entity);
Link bindingToOne = entity.getNavigationBinding("NavPropertyETTwoPrimOne");
@@ -495,11 +442,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":[]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")))
- .getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim");
Link bindingToMany = entity.getNavigationBinding("NavPropertyETTwoPrimMany");
assertNotNull(bindingToMany);
assertTrue(bindingToMany.getBindingLinks().isEmpty());
@@ -508,11 +451,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
@Test
public void eTMixEnumDefCollCompTest() throws Exception {
InputStream stream = getFileAsStream("EntityETMixEnumDefCollComp.json");
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, edm
- .getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")))
- .getEntity();
+ final Entity entity = deserialize(stream, "ETMixEnumDefCollComp", ContentType.JSON);
assertEquals(6, entity.getProperties().size());
@@ -554,14 +493,10 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"cccccc67-89ab-cdef-0123-456789cccccc\"],"
+ "\"CollPropertyTimeOfDay\":[\"04:14:13\",\"23:59:59\",\"01:12:33\"]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim"))).getEntity();
-
- assertTrue((Boolean) e.getProperty("CollPropertyBoolean").asCollection().get(0));
- assertNull(e.getProperty("CollPropertyBoolean").asCollection().get(1));
- assertFalse((Boolean) e.getProperty("CollPropertyBoolean").asCollection().get(2));
+ final Entity entity = deserialize(entityString, "ETCollAllPrim");
+ assertTrue((Boolean) entity.getProperty("CollPropertyBoolean").asCollection().get(0));
+ assertNull(entity.getProperty("CollPropertyBoolean").asCollection().get(1));
+ assertFalse((Boolean) entity.getProperty("CollPropertyBoolean").asCollection().get(2));
}
@Test
@@ -569,11 +504,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
final String entityString = "{"
+ "\"PropertyComp\":null"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity = deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias",
- "ETMixPrimCollComp"))).getEntity();
-
+ final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
assertNull(entity.getProperty("PropertyComp").getValue());
}
@@ -583,11 +514,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"CollPropertyComp\":["
+ "null,"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
-
- Entity entity = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp"))).getEntity();
+ final Entity entity = deserialize(entityString, "ETMixPrimCollComp");
List<?> collPropertyComp = entity.getProperty("CollPropertyComp").asCollection();
assertNull(collPropertyComp.get(0));
List<Property> complexPropertyProperties = ((ComplexValue) collPropertyComp.get(1)).getValue();
@@ -600,11 +527,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
final String entityString = "{"
+ "\"PropertyComp\":{\"PropertyString\":\"TEST A\",\"PropertyInt16\":null}"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETCompAllPrim"))).getEntity();
-
+ final Entity entity = deserialize(entityString, "ETCompAllPrim");
assertEquals("TEST A", entity.getProperty("PropertyComp").asComplex().getValue().get(0).getValue());
assertNull(entity.getProperty("PropertyComp").asComplex().getValue().get(1).getValue());
}
@@ -616,14 +539,9 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "\"PropertyCompMixedEnumDef\" : {"
+ "\"PropertyEnumString\" : null"
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp"))).getEntity();
-
- assertEquals((short) 2, e.getProperty("PropertyEnumString").getValue());
- Property propertyCompMixedEnumDef = e.getProperty("PropertyCompMixedEnumDef");
+ final Entity entity = deserialize(entityString, "ETMixEnumDefCollComp");
+ assertEquals((short) 2, entity.getProperty("PropertyEnumString").getValue());
+ Property propertyCompMixedEnumDef = entity.getProperty("PropertyCompMixedEnumDef");
assertNull(propertyCompMixedEnumDef.asComplex().getValue().get(0).getValue());
}
@@ -632,20 +550,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
String entityString = "{"
+ "\"PropertyEnumString\" : \"String1,String2\""
+ "}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity e = deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp"))).getEntity();
-
- assertEquals((short) 3, e.getProperty("PropertyEnumString").getValue());
+ final Entity entity = deserialize(entityString, "ETMixEnumDefCollComp");
+ assertEquals((short) 3, entity.getProperty("PropertyEnumString").getValue());
}
@Test
public void mappingTest() throws Exception {
- OData.newInstance().createServiceMetadata(new EdmTechProvider(), Collections.<EdmxReference> emptyList())
- .getEdm();
-
EdmEntityType entityType = mock(EdmEntityType.class);
when(entityType.getFullQualifiedName()).thenReturn(new FullQualifiedName("napespace", "name"));
List<String> propertyNames = new ArrayList<String>();
@@ -670,9 +580,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"{\"PropertyDate\":\"2012-12-03\","
+ "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"}";
InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- Entity entity =
- deserializer.entity(stream, entityType).getEntity();
+ ODataDeserializer deserializer = OData.newInstance().createDeserializer(ContentType.JSON);
+ Entity entity = deserializer.entity(stream, entityType).getEntity();
assertNotNull(entity);
List<Property> properties = entity.getProperties();
assertNotNull(properties);
@@ -686,14 +595,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
// ---------------------------------- Negative Tests -----------------------------------------------------------
- @Test(expected = DeserializerException.class)
+ @Test
public void emptyInput() throws Exception {
- OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entity(
- 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 etAllPrimWithInvalidNullValue() throws Exception {
String entityString =
"{\"PropertyInt16\":null," +
@@ -712,32 +619,19 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void doublePrimitiveProperty() throws Exception {
final String entityString = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," +
"\"PropertyInt16\":32766,\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.DUPLICATE_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETTwoPrim",
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void doubleComplexProperty() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -749,18 +643,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.DUPLICATE_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void doubleComplexPropertyCollection() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -776,18 +663,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]"
+ "}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.DUPLICATE_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void doublePrimitivePropertyCollection() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -800,18 +680,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.DUPLICATE_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void customAnnotationInEntityLeadToNotImplemented() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -823,18 +696,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.NOT_IMPLEMENTED);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void customAnnotationInComplexValueLeadToNotImplemented() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -846,18 +712,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.NOT_IMPLEMENTED);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void customAnnotationInComplexCollectionValueLeadToNotImplemented() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -868,18 +727,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"CollPropertyString@custom.annotation\": 12,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.NOT_IMPLEMENTED);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void unkownContentInEntity() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -891,18 +743,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void unkownContentInComplexProperty() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -913,18 +758,11 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void unkownContentInComplexCollectionProperty() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767,"
@@ -935,15 +773,8 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
+ "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"},"
+ "{\"PropertyInt16\":456,\"unknown\": 12,\"PropertyString\":\"TEST 2\"},"
+ "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- try {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
@Test
@@ -1042,386 +873,241 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
checkPropertyJsonType("{\"PropertyTimeOfDay\":true}");
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindOperationWrongJsonTypeForToOne() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimOne@odata.bind\":[\"ESTwoPrim(2)\"]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindOperationWrongJsonTypeForToMany() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":\"ESTwoPrim(2)\""
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindOperationWrongJsonTypeForToManyNumberInArray() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":[123,456]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_ANNOTATION_TYPE);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindOperationWrongAnnotationFormat() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"@odata.bind\":\"ESTwoPrim(2)\""
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.NAVIGATION_PROPERTY_NOT_FOUND, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.NAVIGATION_PROPERTY_NOT_FOUND);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindingOperationNullOnToOne() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimOne@odata.bind\":null"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindingOperationNullOnToMany() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":null"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void bindingOperationNullInArray() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,"
+ "\"PropertyString\":\"First Resource - positive values\","
+ "\"NavPropertyETTwoPrimMany@odata.bind\":[null]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_NULL_ANNOTATION);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidJsonSyntax() throws Exception {
String entityString =
"{\"PropertyInt16\":32767,}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.JSON_SYNTAX_EXCEPTION);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidJsonValueForPrimTypeArray() throws Exception {
String entityString =
"{\"PropertyInt16\":[]}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidJsonValueForPrimTypeObject() throws Exception {
String entityString =
"{\"PropertyInt16\":{}}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidJsonValueForPrimCollectionTypeObject() throws Exception {
final String entityString = "{"
+ "\"CollPropertyString\":"
+ "{\"Employee1@company.example\":1234}"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidJsonValueForComplexTypeTypeString() throws Exception {
final String entityString = "{"
+ "\"PropertyComp\":\"InvalidString\""
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidNullValueForComplexTypeNullableFalse() throws Exception {
final String entityString = "{"
+ "\"PropertyComp\":null"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoKeyNav")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETTwoKeyNav",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidNullValueForPrimBeforeComplexTypeNullableFalse() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\": null, \"PropertyString\": \"321\", "
+ "\"PropertyComp\":{\"PropertyInt16\": null, "
+ "\"PropertyComp\": {\"PropertyString\":\"StringValue\"}}"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETTwoKeyNav")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETTwoKeyNav",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidNullValueForComplexTypePropertyNullableFalse() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\": 123, "
+ "\"PropertyCompTwoPrim\":{\"PropertyInt16\": null, \"PropertyString\":\"StringValue\"}"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETKeyNav")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETKeyNav",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidNullValueForPrimCollectionNullableFalse() throws Exception {
final String entityString = "{"
+ "\"CollPropertyString\":["
+ "null,"
+ "\"StringValue_1\",\"TEST 3\"]}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETCollAllPrim",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void invalidNullValueForPrimIntCollectionNullableFalse() throws Exception {
final String entityString = "{"
+ "\"CollPropertyInt16\":[123,\"null\",4711]"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETCollAllPrim")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETCollAllPrim",
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void provokedPrimitiveTypeException() throws Exception {
final String entityString = "{"
+ "\"PropertyInt16\":32767000000000000000000000000000000000000"
+ "}";
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixPrimCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixPrimCollComp",
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void eTMixEnumDefCollCompInvalidEnumValueNull() throws Exception {
String entityString = "{"
+ "\"PropertyEnumString\" : null,"
+ "\"PropertyCompMixedEnumDef\" : {"
+ "\"PropertyEnumString\" : \"2\""
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(
- new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_NULL_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixEnumDefCollComp",
+ DeserializerException.MessageKeys.INVALID_NULL_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void eTMixEnumDefCollCompInvalidEnumValueArray() throws Exception {
String entityString = "{"
+ "\"PropertyEnumString\" : [],"
+ "\"PropertyCompEnum\" : {"
+ "\"PropertyEnumString\" : \"2\""
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixEnumDefCollComp",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void eTMixEnumDefCollCompInvalidEnumValueObject() throws Exception {
String entityString = "{"
+ "\"PropertyEnumString\" : {},"
+ "\"PropertyCompEnum\" : {"
+ "\"PropertyEnumString\" : \"2\""
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixEnumDefCollComp",
+ DeserializerException.MessageKeys.INVALID_JSON_TYPE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void eTMixEnumDefCollCompInvalidEnumValue() throws Exception {
String entityString = "{"
+ "\"PropertyEnumString\" : \"invalid\","
+ "\"PropertyCompEnum\" : {"
+ "\"PropertyEnumString\" : \"2\""
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixEnumDefCollComp",
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void eTMixEnumDefCollCompInvalidEnumValueByPrimitiveTypeException() throws Exception {
String entityString = "{"
+ "\"PropertyEnumString\" : \"18\","
+ "\"PropertyCompEnum\" : {"
+ "\"PropertyEnumString\" : \"2\""
+ "}}";
-
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
- try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETMixEnumDefCollComp")));
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, e.getMessageKey());
- throw e;
- }
+ expectException(entityString, "ETMixEnumDefCollComp",
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
@Test
public void ieee754Compatible() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON_IEEE754Compatible);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1439,10 +1125,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
-
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- final Entity entity = deserializer
- .entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim", CONTENT_TYPE_JSON_IEEE754Compatible);
assertEquals(9223372036854775807L, entity.getProperty("PropertyInt64").asPrimitive());
assertEquals(BigDecimal.valueOf(34), entity.getProperty("PropertyDecimal").asPrimitive());
@@ -1450,7 +1133,6 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
@Test
public void ieee754CompatibleNull() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON_IEEE754Compatible);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1468,18 +1150,14 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
-
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- final Entity entity = deserializer
- .entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ final Entity entity = deserialize(entityString, "ETAllPrim", CONTENT_TYPE_JSON_IEEE754Compatible);
assertTrue(entity.getProperty("PropertyInt64").isNull());
assertTrue(entity.getProperty("PropertyDecimal").isNull());
}
- @Test(expected = DeserializerException.class)
+ @Test
public void ieee754CompatibleEmptyString() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON_IEEE754Compatible);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1497,14 +1175,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
-
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ expectException(entityString, "ETAllPrim", CONTENT_TYPE_JSON_IEEE754Compatible,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void ieee754CompatibleNullAsString() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON_IEEE754Compatible);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1522,14 +1198,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
-
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ expectException(entityString, "ETAllPrim", CONTENT_TYPE_JSON_IEEE754Compatible,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void ieee754CompatibleAsNumber() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON_IEEE754Compatible);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1547,14 +1221,12 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
-
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ expectException(entityString, "ETAllPrim", CONTENT_TYPE_JSON_IEEE754Compatible,
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
}
- @Test(expected = DeserializerException.class)
+ @Test
public void ieee754NotCompatibleAsString() throws Exception {
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
String entityString =
"{\"PropertyInt16\":32767," +
"\"PropertyString\":\"First Resource - positive values\"," +
@@ -1572,19 +1244,43 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
"\"PropertyDuration\":\"PT6S\"," +
"\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," +
"\"PropertyTimeOfDay\":\"03:26:05\"}";
+ expectException(entityString, "ETAllPrim",
+ DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
+ }
- final InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim"))).getEntity();
+ protected static Entity deserialize(final InputStream stream, final String entityTypeName,
+ final ContentType contentType) throws DeserializerException {
+ return OData.newInstance().createDeserializer(contentType)
+ .entity(stream, edm.getEntityType(new FullQualifiedName(NAMESPACE, entityTypeName)))
+ .getEntity();
}
- private void checkPropertyJsonType(final String entityString) throws DeserializerException {
- InputStream stream = new ByteArrayInputStream(entityString.getBytes());
- ODataDeserializer deserializer = OData.newInstance().createDeserializer(CONTENT_TYPE_JSON);
+ private static Entity deserialize(final String entityString, final String entityTypeName,
+ final ContentType contentType) throws DeserializerException {
+ return deserialize(new ByteArrayInputStream(entityString.getBytes()), entityTypeName, contentType);
+ }
+
+ protected static Entity deserialize(final String entityString, final String entityTypeName)
+ throws DeserializerException {
+ return deserialize(entityString, entityTypeName, ContentType.JSON);
+ }
+
+ private static void checkPropertyJsonType(final String entityString) throws DeserializerException {
+ expectException(entityString, "ETAllPrim", DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY);
+ }
+
+ protected static void expectException(final String entityString, final String entityTypeName,
+ final DeserializerException.MessageKeys messageKey) {
+ expectException(entityString, entityTypeName, ContentType.JSON, messageKey);
+ }
+
+ private static void expectException(final String entityString, final String entityTypeName,
+ final ContentType contentType, final DeserializerException.MessageKeys messageKey) {
try {
- deserializer.entity(stream, edm.getEntityType(new FullQualifiedName("Namespace1_Alias", "ETAllPrim")));
- fail("Expected an exception but was not thrown: " + this.getClass().getName());
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.INVALID_VALUE_FOR_PROPERTY, e.getMessageKey());
+ deserialize(entityString, entityTypeName, contentType);
+ fail("Expected exception not thrown.");
+ } catch (final DeserializerException e) {
+ assertEquals(messageKey, e.getMessageKey());
}
}
}
[6/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Posted by mi...@apache.org.
[OLINGO-789] server support for action parameters of all types
Signed-off-by: Michael Bolz <mi...@sap.com>
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d6db341d
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d6db341d
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d6db341d
Branch: refs/heads/master
Commit: d6db341db734266536d5177dcb749eae0683c2c7
Parents: b9403cd
Author: Klaus Straubinger <kl...@sap.com>
Authored: Thu Oct 1 10:20:44 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Thu Oct 1 12:11:33 2015 +0200
----------------------------------------------------------------------
.../client/AbstractParamTecSvcITCase.java | 18 +
.../fit/tecsvc/client/AbstractTecSvcITCase.java | 28 +-
.../fit/tecsvc/client/ActionImportITCase.java | 11 +-
.../fit/tecsvc/client/AsyncSupportITCase.java | 24 +-
.../fit/tecsvc/client/DeepInsertITCase.java | 886 +++++++++--------
.../fit/tecsvc/client/DeepInsertXmlITCase.java | 950 -------------------
.../ExpandWithSystemQueryOptionsITCase.java | 12 +-
.../commons/api/edm/EdmNavigationProperty.java | 2 +-
.../olingo/commons/api/edm/EdmParameter.java | 2 +-
.../olingo/commons/api/edm/EdmProperty.java | 4 +-
.../olingo/commons/api/edm/EdmReturnType.java | 2 +-
.../apache/olingo/server/core/ODataImpl.java | 7 +-
.../json/ODataJsonDeserializer.java | 389 +++-----
.../deserializer/xml/ODataXmlDeserializer.java | 52 +-
.../core/serializer/xml/ODataXmlSerializer.java | 46 +-
.../olingo/server/tecsvc/data/ActionData.java | 101 +-
.../olingo/server/tecsvc/data/DataProvider.java | 23 +-
.../tecsvc/data/ActionDataProviderTest.java | 14 +-
.../AbstractODataDeserializerTest.java | 44 +
.../json/AbstractODataDeserializerTest.java | 46 -
.../json/ODataDeserializerDeepInsertTest.java | 125 +--
.../ODataDeserializerEntityCollectionTest.java | 205 ++--
...ataJsonDeserializerActionParametersTest.java | 350 +++----
.../json/ODataJsonDeserializerEntityTest.java | 678 ++++---------
...DataXMLDeserializerActionParametersTest.java | 350 +++----
.../xml/ODataXmlDeserializerTest.java | 211 ++--
.../core/uri/antlr/TestUriParserImpl.java | 11 +-
27 files changed, 1549 insertions(+), 3042 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
index 2d45d79..d6e35a3 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractParamTecSvcITCase.java
@@ -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());
+ }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
index 1333644..c74f345 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AbstractTecSvcITCase.java
@@ -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() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
index b7671cb..c21671b 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ActionImportITCase.java
@@ -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;
- }
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
index f447bbc..f6893d1 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/AsyncSupportITCase.java
@@ -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;
}
}
[4/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertXmlITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertXmlITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertXmlITCase.java
deleted file mode 100644
index d9bda60..0000000
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertXmlITCase.java
+++ /dev/null
@@ -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);
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
index 22794f7..507b9a9 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/ExpandWithSystemQueryOptionsITCase.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
index 9f3a87c..34ddab6 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmNavigationProperty.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmParameter.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmParameter.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmParameter.java
index ded6462..876b6f0 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmParameter.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmParameter.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java
index f530218..aba2b4b 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmProperty.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmReturnType.java
----------------------------------------------------------------------
diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmReturnType.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmReturnType.java
index 311b06a..2f3e142 100644
--- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmReturnType.java
+++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/edm/EdmReturnType.java
@@ -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();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
index 22fdc2b..ad7d410 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/ODataImpl.java
@@ -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
[5/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
index 683c6ed..d8a467a 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/DeepInsertITCase.java
@@ -22,6 +22,7 @@ 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 static org.junit.Assume.assumeTrue;
import java.net.URI;
import java.util.HashMap;
@@ -29,6 +30,8 @@ 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;
@@ -53,20 +56,7 @@ import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.junit.Ignore;
import org.junit.Test;
-/**
- * The issue I see with this unit test, or in general with JSON metadata=minimal case is
- * none of the navigation properties will be represented as such in deserialized form, because
- * no navigation link information will be written when metadata=minimal. The client will
- * interpret those results as complex properties (which I do not think is right).
- *
- * Where as in the atom+xml case, there is no intermediate results, it is equivalent to
- * metadata=full, thus the navigation links and inline content is correctly represented through
- * deserialization.
- *
- * For above reason, the DeepInsertXMLITCase case re-written slightly differently.
- *
- */
-public class DeepInsertITCase extends AbstractTecSvcITCase {
+public class DeepInsertITCase extends AbstractParamTecSvcITCase {
private static final String ES_KEY_NAV = "ESKeyNav";
private static final String ES_TWO_KEY_NAV = "ESTwoKeyNav";
@@ -95,58 +85,74 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
@Test
public void deepInsertExpandedResponse() {
- final URI createURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ assumeTrue("The server XML deserializer does not (yet?!) fill the expand information;"
+ + " the response is therefore not expanded in XML.",
+ isJson()); // TODO: XML case
+ final ODataClient client = getEdmEnabledClient();
+ final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
final ClientObjectFactory factory = getFactory();
final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
// Root entity
- entity.getProperties().add(
- factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 0")));
- entity.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ entity.getProperties()
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("String Property level 0")));
+ entity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 41)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 41)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 0, complex level " +
- "1")))));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 0, complex level 1")))));
// First level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
final ClientEntity firstLevelTwoKeyNav = factory.newEntity(ET_TWO_KEY_NAV);
- firstLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ firstLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 42)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 1, complex level 1")))));
- firstLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
- firstLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 1, complex level 1")))));
+ firstLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 9999)))));
+ firstLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 8888)))));
final ClientInlineEntity firstLevelTwoKeyOneInline =
factory.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, firstLevelTwoKeyNav);
entity.addLink(firstLevelTwoKeyOneInline);
// Second level NavPropertyETTwoKeyNavOne => Type ETTwoKeyNav
final ClientEntity secondLevelTwoKeyNav = factory.newEntity(ET_TWO_KEY_NAV);
- secondLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ secondLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 421)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 421)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 2, complex level 1")))));
- secondLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
- secondLevelTwoKeyNav.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 2, complex level 1")))));
+ secondLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 9999)))));
+ secondLevelTwoKeyNav.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 8888)))));
// Binding links
- secondLevelTwoKeyNav.addLink(factory.newEntityNavigationLink(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, getClient()
- .newURIBuilder(
- SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(new LinkedHashMap<String,
- Object>() {
+ secondLevelTwoKeyNav.addLink(factory.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");
@@ -159,57 +165,76 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Third level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
final ClientEntity thirdLevelTwoKeyNavMany1 = factory.newEntity(ET_TWO_KEY_NAV);
- thirdLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ thirdLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 431)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 431)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 3, complex level " +
- "1")))));
- thirdLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
- thirdLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 3, complex level 1")))));
+ thirdLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 9999)))));
+ thirdLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 8888)))));
final ClientEntity thirdLevelTwoKeyNavMany2 = factory.newEntity(ET_TWO_KEY_NAV);
- thirdLevelTwoKeyNavMany2.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ thirdLevelTwoKeyNavMany2.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 432)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 432)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 3, complex level " +
- "1")))));
- thirdLevelTwoKeyNavMany2.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
- thirdLevelTwoKeyNavMany2.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 3, complex level 1")))));
+ thirdLevelTwoKeyNavMany2.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 9999)))));
+ thirdLevelTwoKeyNavMany2.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 8888)))));
final ClientEntitySet entitySetThirdLevelTwoKeyNavMany = factory.newEntitySet();
entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany1);
entitySetThirdLevelTwoKeyNavMany.getEntities().add(thirdLevelTwoKeyNavMany2);
secondLevelTwoKeyNav.addLink(factory.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
- entitySetThirdLevelTwoKeyNavMany));
+ entitySetThirdLevelTwoKeyNavMany));
// First level NavPropertyETTwoKeyNavMany => Type ETTwoKeyNav
final ClientEntity firstLevelTwoKeyNavMany1 = factory.newEntity(ET_TWO_KEY_NAV);
- firstLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
+ firstLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 422)))
+ factory.newPrimitiveValueBuilder().buildInt16((short) 422)))
.add(factory.newPrimitiveProperty(PROPERTY_STRING,
- factory.newPrimitiveValueBuilder().buildString("String Property level 1, complex level 1")))));
- firstLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
- firstLevelTwoKeyNavMany1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ factory.newPrimitiveValueBuilder().buildString("String Property level 1, complex level 1")))));
+ firstLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 9999)))));
+ firstLevelTwoKeyNavMany1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 8888)))));
final ClientEntitySet entitySetfirstLevelTwoKeyNavMany = factory.newEntitySet();
entitySetfirstLevelTwoKeyNavMany.getEntities().add(firstLevelTwoKeyNavMany1);
entity.addLink(factory.newDeepInsertEntitySet(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY,
- entitySetfirstLevelTwoKeyNavMany));
+ entitySetfirstLevelTwoKeyNavMany));
final ODataEntityCreateResponse<ClientEntity> createResponse =
- getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
+ client.getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
// Check response
final ClientEntity resultEntityFirstLevel =
@@ -254,58 +279,66 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
@Test
public void simpleDeepInsert() throws Exception {
- final URI createURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final ODataClient client = getEdmEnabledClient();
+ final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
final ClientObjectFactory factory = getFactory();
final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 42)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 42)));
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM, factory.newComplexValue(CT_ALL_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
+ factory.newComplexValue(CT_ALL_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 42)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("42")))
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
// Non collection navigation property
// Create related entity(EntitySet: ESTwoKeyNav, Type: ETTwoKeyNav, Nav. Property: NavPropertyETTwoKeyNavOne)
final ClientEntity inlineEntitySingle = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntitySingle.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 43)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 43)));
+ inlineEntitySingle.getProperties()
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
inlineEntitySingle.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
- inlineEntitySingle.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 430)))));
+ factory.newPrimitiveValueBuilder().buildInt16((short) 430)))));
inlineEntitySingle.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 431)))));
inlineEntitySingle.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 432)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 432)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("432")))));
// Collection navigation property
@@ -313,45 +346,49 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Create related entity(EntitySet: ESTwoKeyNav, Type: NavPropertyETTwoKeyNavMany
final ClientEntity inlineEntityCol1 = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntityCol1.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 44)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 44)));
inlineEntityCol1.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("44")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("44")));
inlineEntityCol1.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 441)))));
- inlineEntityCol1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)
+ inlineEntityCol1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 440)))));
+ factory.newPrimitiveValueBuilder().buildInt16((short) 440)))));
inlineEntityCol1.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short) 442)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("442"))
- )));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 442)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("442")))));
final ClientEntity inlineEntityCol2 = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntityCol2.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 45)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 45)));
inlineEntityCol2.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("45")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("45")));
inlineEntityCol2.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 451)))));
- inlineEntityCol2.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)
+ inlineEntityCol2.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 450)))));
+ factory.newPrimitiveValueBuilder().buildInt16((short) 450)))));
inlineEntityCol2.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 452)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("452")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 452)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("452")))));
final ClientInlineEntity newDeepInsertEntityLink =
factory.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntitySingle);
@@ -365,7 +402,7 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
entity.addLink(newDeepInsertEntitySetLink);
// Perform create request
- final ODataEntityCreateResponse<ClientEntity> responseCreate = getClient().getCUDRequestFactory()
+ final ODataEntityCreateResponse<ClientEntity> responseCreate = client.getCUDRequestFactory()
.getEntityCreateRequest(createURI, entity)
.execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), responseCreate.getStatusCode());
@@ -375,241 +412,251 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Fetch ESKeyNav entity with expand of NavPropertyETTwoKeyNavOne nav. property
ClientProperty propertyInt16 = responseCreate.getBody().getProperty(PROPERTY_INT16);
final URI esKeyNavURI =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(
+ 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 = getClient().getRetrieveRequestFactory()
+ final ODataEntityRequest<ClientEntity> esKeyNavRequest = client.getRetrieveRequestFactory()
.getEntityRequest(esKeyNavURI);
esKeyNavRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esKeyNavResponse = esKeyNavRequest.execute();
+ final ClientEntity clientEntity = esKeyNavResponse.getBody();
// Check nav. property NavPropertyETTwoKeyNavOne
- assertNotNull(esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE));
- assertEquals(431, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY));
- assertEquals(2, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue()
- .size());
- Iterator<ClientValue> twoKeyNavManyIterator =
- esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue().iterator();
- final ClientValue firstTwoKeyNavEnity = twoKeyNavManyIterator.next(); // First entity
- assertEquals(441, firstTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- final ClientValue secondTwoKeyNavEnity = twoKeyNavManyIterator.next(); // Second entity
- assertEquals(451, secondTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(clientEntity.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, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE)
- .getComplexValue().get(PROPERTY_INT16)
- .getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE)
- .getComplexValue().get(PROPERTY_STRING)
- .getPrimitiveValue().toValue());
+ 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 = getClient().newURIBuilder(SERVICE_URI)
+ final URI esTwoKeyNavEntitySingleURI = client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_KEY_NAV)
.appendKeySegment(composedKey)
.build();
-
- final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = getClient().getRetrieveRequestFactory()
+ final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = client.getRetrieveRequestFactory()
.getEntityRequest(esTwoKeyNavEntitySingleURI);
esTwoKeyNavSingleRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavSingleResponse = esTwoKeyNavSingleRequest.execute();
- assertEquals(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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, firstTwoKeyNavEnity.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, firstTwoKeyNavEnity.asComplex().get(PROPERTY_STRING).getPrimitiveValue()
- .toValue());
+ 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 =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyOneRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
+ client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
esTwoKeyNavManyOneRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyOneResponse = esTwoKeyNavManyOneRequest.execute();
- assertEquals(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- assertNotNull(esTwoKeyNavManyOneResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
- assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyOneResponse.getBody().getProperty(
- NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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, secondTwoKeyNavEnity.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, secondTwoKeyNavEnity.asComplex().get(PROPERTY_STRING).getPrimitiveValue()
- .toValue());
+ 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 =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyTwoRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
+ client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
esTwoKeyNavManyTwoRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyTwoResponse = esTwoKeyNavManyTwoRequest.execute();
- assertEquals(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- assertNotNull(esTwoKeyNavManyTwoResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
- assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyTwoResponse.getBody().getProperty(
- NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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 URI createURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ public void deepInsertSameEntitySet() throws Exception {
+ final ODataClient client = getEdmEnabledClient();
+ final URI createURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
final ClientObjectFactory factory = getFactory();
final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 42)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 42)));
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))));
-
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM, factory.newComplexValue(CT_ALL_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
+ factory.newComplexValue(CT_ALL_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 42)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("42")))
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
entity.addLink(factory.newEntityNavigationLink("NavPropertyETTwoKeyNavOne",
- getClient().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()));
+ 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 = factory.newEntity(ET_KEY_NAV);
innerEntity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 43)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 43)));
innerEntity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
innerEntity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 431)))));
innerEntity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM, factory.newComplexValue(CT_ALL_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("431"))
- )));
+ .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
+ factory.newComplexValue(CT_ALL_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("431")))));
+ innerEntity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 431)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("431")))));
innerEntity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 431)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("431"))
- )));
- innerEntity
- .getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("431")))
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder()
- .buildInt16((short) 431)))))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("431")))
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 431)))))));
innerEntity.addLink(factory.newEntityNavigationLink("NavPropertyETTwoKeyNavOne",
- getClient().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()));
+ 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 = factory.newDeepInsertEntity(NAV_PROPERTY_ET_KEY_NAV_ONE, innerEntity);
entity.addLink(inlineEntity);
final ODataEntityCreateResponse<ClientEntity> responseCreate =
- getClient().getCUDRequestFactory().getEntityCreateRequest(createURI, entity).execute();
+ 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 =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(esKeyNavEntityKey)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(esKeyNavEntityKey)
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
ODataEntityRequest<ClientEntity> entityRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(fetchEntityURI);
+ 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
- assertEquals(431, entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertShortOrInt(431, navOne.getEntity().getProperty(PROPERTY_COMP_NAV).getComplexValue()
+ .get(PROPERTY_INT16).getPrimitiveValue().toValue());
- Short innerEntityInt16Key =
- entityResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16)
- .getPrimitiveValue().toCastValue(Short.class);
+ Short innerEntityInt16Key = navOne.getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue()
+ .toCastValue(Short.class);
final URI innerEntityURI =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(innerEntityInt16Key)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(innerEntityInt16Key)
.build();
final ODataEntityRequest<ClientEntity> innerRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(innerEntityURI);
+ client.getRetrieveRequestFactory().getEntityRequest(innerEntityURI);
innerRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
ODataRetrieveResponse<ClientEntity> innerResponse = innerRequest.execute();
- assertEquals(431, innerResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16)
+ assertShortOrInt(431, innerResponse.getBody().getProperty(PROPERTY_COMP_NAV)
+ .getComplexValue().get(PROPERTY_INT16)
.getPrimitiveValue().toValue());
}
@Test
- public void consistency() throws EdmPrimitiveTypeException {
+ public void consistency() throws Exception {
+ final EdmEnabledODataClient client = getEdmEnabledClient();
+ final ClientObjectFactory factory = getFactory();
final String cookie = getCookie();
// Do not set PropertyString(Nullable=false)
- final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.getProperties().add(
- getFactory().newCollectionProperty(COL_PROPERTY_STRING,
- getFactory().newCollectionValue(EDM_STRING).add(
- getFactory().newPrimitiveValueBuilder().buildString("Test"))));
+ factory.newCollectionProperty(COL_PROPERTY_STRING,
+ factory.newCollectionValue(EDM_STRING).add(
+ factory.newPrimitiveValueBuilder().buildString("Test"))));
- final URI targetURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
try {
- ODataEntityCreateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory()
+ ODataEntityCreateRequest<ClientEntity> request = client.getCUDRequestFactory()
.getEntityCreateRequest(targetURI, entity);
request.addCustomHeader(HttpHeader.COOKIE, cookie);
request.execute();
@@ -623,20 +670,21 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
}
@Test
- public void invalidType() throws EdmPrimitiveTypeException {
+ public void invalidType() throws Exception {
+ final EdmEnabledODataClient client = getEdmEnabledClient();
+ final ClientObjectFactory factory = getFactory();
final String cookie = getCookie();
- final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
- entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
- getFactory().newPrimitiveValueBuilder().buildInt32(1)));
- final URI targetURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
+ entity.getProperties().add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildInt32(1)));
+ final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build();
try {
- ODataEntityCreateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory()
+ 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());
}
@@ -644,16 +692,15 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
validateSet(targetURI, cookie, (short) 1, (short) 2, (short) 3);
entity.getProperties().add(
- getFactory().newCollectionProperty(PROPERTY_STRING,
- getFactory().newCollectionValue(EDM_STRING).add(
- getFactory().newPrimitiveValueBuilder().buildString("Test"))));
+ factory.newCollectionProperty(PROPERTY_STRING,
+ factory.newCollectionValue(EDM_STRING).add(
+ factory.newPrimitiveValueBuilder().buildString("Test"))));
try {
- ODataEntityCreateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory()
+ 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());
}
@@ -664,40 +711,45 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
@Test
@Ignore
public void deepInsertOnNavigationPropertyInComplexProperty() {
- final ClientEntity inlineEntity = getFactory().newEntity(ET_TWO_KEY_NAV);
- inlineEntity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue(CT_PRIM_COMP)));
- inlineEntity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP_NAV, getFactory().newComplexValue(CT_BASE_PRIM_COMP_NAV)));
- inlineEntity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP_TWO_PRIM, getFactory().newComplexValue(CT_TWO_PRIM)
- .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
- getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
- .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
- getFactory().newPrimitiveValueBuilder().buildString("1")))));
-
- final ClientEntity entity = getFactory().newEntity(ET_TWO_KEY_NAV);
- entity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue(CT_PRIM_COMP)));
- entity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP_NAV, getFactory().newComplexValue(CT_BASE_PRIM_COMP_NAV)));
- entity.getProperties().add(
- getFactory().newComplexProperty(PROPERTY_COMP_TWO_PRIM, getFactory().newComplexValue(CT_TWO_PRIM)
- .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
- getFactory().newPrimitiveValueBuilder().buildInt16((short) 2)))
- .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
- getFactory().newPrimitiveValueBuilder().buildString("2")))));
-
- final ClientLink link = getFactory().newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntity);
- final ClientComplexValue complexValueCreate = getFactory().newComplexValue(CT_NAV_FIVE_PROP);
+ final EdmEnabledODataClient client = getEdmEnabledClient();
+ final ClientObjectFactory factory = getFactory();
+
+ final ClientEntity inlineEntity = factory.newEntity(ET_TWO_KEY_NAV);
+ inlineEntity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
+ inlineEntity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ inlineEntity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 1)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("1")))));
+
+ final ClientEntity entity = factory.newEntity(ET_TWO_KEY_NAV);
+ entity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)));
+ entity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_BASE_PRIM_COMP_NAV)));
+ entity.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 2)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("2")))));
+
+ final ClientLink link = factory.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntity);
+ final ClientComplexValue complexValueCreate = factory.newComplexValue(CT_NAV_FIVE_PROP);
complexValueCreate.getNavigationLinks().add(link);
- entity.getProperties().add(
- getFactory().newCollectionProperty(COL_PROPERTY_COMP_NAV, getFactory().newCollectionValue(CT_NAV_FIVE_PROP)
- .add(complexValueCreate)));
+ entity.getProperties()
+ .add(factory.newCollectionProperty(COL_PROPERTY_COMP_NAV,
+ factory.newCollectionValue(CT_NAV_FIVE_PROP).add(complexValueCreate)));
- final URI targetURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).build();
- final ODataEntityCreateResponse<ClientEntity> response = getEdmEnabledClient().getCUDRequestFactory()
+ final URI targetURI = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).build();
+ final ODataEntityCreateResponse<ClientEntity> response = client.getCUDRequestFactory()
.getEntityCreateRequest(targetURI, entity)
.execute();
@@ -720,7 +772,8 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
@Test
public void deepUpsert() {
- final URI updateURI = getClient().newURIBuilder(SERVICE_URI)
+ final ODataClient client = getEdmEnabledClient();
+ final URI updateURI = client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(815)
.build();
@@ -729,51 +782,58 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Prepare entity(EntitySet: ESKeyNav, Type: ETKeyNav)
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 42)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 42)));
entity.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM, factory.newComplexValue(CT_ALL_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
+ factory.newComplexValue(CT_ALL_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short)
- 42)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("42")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 42)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))));
entity.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("42")))
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_NAV_FIVE_PROP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("42")))
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_NAV_FIVE_PROP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))))));
// Non collection navigation property
// Create related entity(EntitySet: ESTwoKeyNav, Type: ETTwoKeyNav, Nav. Property: NavPropertyETTwoKeyNavOne)
final ClientEntity inlineEntitySingle = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntitySingle.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 43)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 43)));
inlineEntitySingle.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("43")));
inlineEntitySingle.getProperties().add(factory.newComplexProperty(PROPERTY_COMP,
- factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 43)))));
- inlineEntitySingle.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 43)))));
+ inlineEntitySingle.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 431)))));
inlineEntitySingle.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short) 432)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 432)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("432")))));
// Collection navigation property
@@ -781,44 +841,51 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Create related entity(EntitySet: ESTwoKeyNav, Type: NavPropertyETTwoKeyNavMany
final ClientEntity inlineEntityCol1 = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntityCol1.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 44)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short) 44)));
inlineEntityCol1.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("44")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("44")));
inlineEntityCol1.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 441)))));
- inlineEntityCol1.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)
+ inlineEntityCol1.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 441)))));
+ factory.newPrimitiveValueBuilder().buildInt16((short) 441)))));
inlineEntityCol1.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short) 442)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("442"))
- )));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 442)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("442")))));
final ClientEntity inlineEntityCol2 = factory.newEntity(ET_TWO_KEY_NAV);
inlineEntityCol2.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16((short)
- 45)));
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 45)));
inlineEntityCol2.getProperties()
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder().buildString("45")));
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("45")));
inlineEntityCol2.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_NAV, factory.newComplexValue(CT_PRIM_COMP)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ .add(factory.newComplexProperty(PROPERTY_COMP_NAV,
+ factory.newComplexValue(CT_PRIM_COMP)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 451)))));
- inlineEntityCol2.getProperties().add(
- factory.newComplexProperty(PROPERTY_COMP, factory.newComplexValue(CT_PRIM_COMP)
+ inlineEntityCol2.getProperties()
+ .add(factory.newComplexProperty(PROPERTY_COMP,
+ factory.newComplexValue(CT_PRIM_COMP)
.add(factory.newPrimitiveProperty(PROPERTY_INT16,
- factory.newPrimitiveValueBuilder().buildInt16((short) 451)))));
+ factory.newPrimitiveValueBuilder().buildInt16((short) 451)))));
inlineEntityCol2.getProperties()
- .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM, factory.newComplexValue(CT_TWO_PRIM)
- .add(factory.newPrimitiveProperty(PROPERTY_INT16, factory.newPrimitiveValueBuilder().buildInt16
- ((short) 452)))
- .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
- .buildString("452")))));
+ .add(factory.newComplexProperty(PROPERTY_COMP_TWO_PRIM,
+ factory.newComplexValue(CT_TWO_PRIM)
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
+ factory.newPrimitiveValueBuilder().buildInt16((short) 452)))
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
+ factory.newPrimitiveValueBuilder().buildString("452")))));
final ClientInlineEntity newDeepInsertEntityLink =
factory.newDeepInsertEntity(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE, inlineEntitySingle);
@@ -832,7 +899,7 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
entity.addLink(newDeepInsertEntitySetLink);
// Perform update request (upsert)
- final ODataEntityUpdateResponse<ClientEntity> responseCreate = getClient().getCUDRequestFactory()
+ final ODataEntityUpdateResponse<ClientEntity> responseCreate = client.getCUDRequestFactory()
.getEntityUpdateRequest(updateURI, UpdateType.PATCH, entity)
.execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), responseCreate.getStatusCode());
@@ -842,109 +909,115 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
// Fetch ESKeyNav entity with expand of NavPropertyETTwoKeyNavOne nav. property
ClientProperty propertyInt16 = responseCreate.getBody().getProperty(PROPERTY_INT16);
final URI esKeyNavURI =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(
+ 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 = getClient().getRetrieveRequestFactory()
+ 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().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE));
- assertEquals(431, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE).getComplexValue().get(
- PROPERTY_COMP_NAV).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY));
- assertEquals(2, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue()
- .size());
- Iterator<ClientValue> twoKeyNavManyIterator =
- esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_MANY).getCollectionValue().iterator();
- final ClientValue firstTwoKeyNavEnity = twoKeyNavManyIterator.next(); // First entity
- assertEquals(441, firstTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- final ClientValue secondTwoKeyNavEnity = twoKeyNavManyIterator.next(); // Second entity
- assertEquals(451, secondTwoKeyNavEnity.asComplex().get(PROPERTY_COMP_NAV).getValue().asComplex().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE)
- .getComplexValue().get(PROPERTY_INT16)
+ composedKey.put(PROPERTY_INT16, navOne.getEntity().getProperty(PROPERTY_INT16)
.getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, esKeyNavResponse.getBody().getProperty(NAV_PROPERTY_ET_TWO_KEY_NAV_ONE)
- .getComplexValue().get(PROPERTY_STRING)
+ composedKey.put(PROPERTY_STRING, navOne.getEntity().getProperty(PROPERTY_STRING)
.getPrimitiveValue().toValue());
- final URI esTwoKeyNavEntitySingleURI = getClient().newURIBuilder(SERVICE_URI)
+ final URI esTwoKeyNavEntitySingleURI = client.newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_TWO_KEY_NAV)
.appendKeySegment(composedKey)
.build();
- final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = getClient().getRetrieveRequestFactory()
+ final ODataEntityRequest<ClientEntity> esTwoKeyNavSingleRequest = client.getRetrieveRequestFactory()
.getEntityRequest(esTwoKeyNavEntitySingleURI);
esTwoKeyNavSingleRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavSingleResponse = esTwoKeyNavSingleRequest.execute();
- assertEquals(431, esTwoKeyNavSingleResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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, firstTwoKeyNavEnity.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, firstTwoKeyNavEnity.asComplex().get(PROPERTY_STRING).getPrimitiveValue()
- .toValue());
+ 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 =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyOneRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
+ client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyOneURI);
esTwoKeyNavManyOneRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyOneResponse = esTwoKeyNavManyOneRequest.execute();
- assertEquals(441, esTwoKeyNavManyOneResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- assertNotNull(esTwoKeyNavManyOneResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
- assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyOneResponse.getBody().getProperty(
- NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ 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, secondTwoKeyNavEnity.asComplex().get(PROPERTY_INT16).getPrimitiveValue().toValue());
- composedKey.put(PROPERTY_STRING, secondTwoKeyNavEnity.asComplex().get(PROPERTY_STRING).getPrimitiveValue()
- .toValue());
+ 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 =
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_KEY_NAV).appendKeySegment(composedKey)
.expand(NAV_PROPERTY_ET_KEY_NAV_ONE).build();
final ODataEntityRequest<ClientEntity> esTwoKeyNavManyTwoRequest =
- getClient().getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
+ client.getRetrieveRequestFactory().getEntityRequest(esTwoKeyNavEntityManyTwoURI);
esTwoKeyNavManyTwoRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> esTwoKeyNavManyTwoResponse = esTwoKeyNavManyTwoRequest.execute();
- assertEquals(451, esTwoKeyNavManyTwoResponse.getBody().getProperty(PROPERTY_COMP_NAV).getComplexValue().get(
- PROPERTY_INT16).getPrimitiveValue().toValue());
- assertNotNull(esTwoKeyNavManyTwoResponse.getBody().getProperty(NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue());
- assertEquals(propertyInt16.getPrimitiveValue().toValue(), esTwoKeyNavManyTwoResponse.getBody().getProperty(
- NAV_PROPERTY_ET_KEY_NAV_ONE).getComplexValue().get(PROPERTY_INT16).getPrimitiveValue().toValue());
-
+ 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 ODataRetrieveResponse<ClientEntitySet> response = getEdmEnabledClient().getRetrieveRequestFactory()
- .getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build())
+ final EdmEnabledODataClient client = getEdmEnabledClient();
+ 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 ODataEntitySetRequest<ClientEntitySet> request = getEdmEnabledClient().getRetrieveRequestFactory()
+ final EdmEnabledODataClient client = getEdmEnabledClient();
+ final ODataEntitySetRequest<ClientEntitySet> request = client.getRetrieveRequestFactory()
.getEntitySetRequest(uri);
request.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntitySet> response = request.execute();
@@ -953,7 +1026,8 @@ public class DeepInsertITCase extends AbstractTecSvcITCase {
assertEquals(3, response.getBody().getEntities().size());
for (final ClientEntity responseEntity : response.getBody().getEntities()) {
- short propertyInt16 = responseEntity.getProperty(PROPERTY_INT16).getPrimitiveValue().toCastValue(Short.class);
+ short propertyInt16 = responseEntity.getProperty(PROPERTY_INT16)
+ .getPrimitiveValue().toCastValue(Short.class);
boolean found = false;
for (int i = 0; i < keys.length && !found; i++) {
[3/6] olingo-odata4 git commit: [OLINGO-789] server support for
action parameters of all types
Posted by mi...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
index c5c842c..9b9de1d 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializer.java
@@ -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,18 +783,24 @@ 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,
+ } 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);
- } catch (JsonMappingException e) {
- throw new DeserializerException(DUPLICATE_JSON_PROPERTY_DETECTED_MSG, e,
+ } else if (e instanceof JsonMappingException) {
+ return new DeserializerException("Duplicate json property detected.", e,
DeserializerException.MessageKeys.DUPLICATE_PROPERTY);
- } catch (IOException e) {
- throw new DeserializerException(AN_IO_EXCEPTION_OCCURRED_MSG, e,
+ } else {
+ return new DeserializerException("An IOException occurred.", e,
DeserializerException.MessageKeys.IO_EXCEPTION);
- } catch (URISyntaxException e) {
- throw new DeserializerException("failed to read @odata.id", e,
- DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
index a762f5c..776868b 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializer.java
@@ -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) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
index 4e1ba56..27ba073 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializer.java
@@ -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);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java
index 72c34b2..2adf7c2 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/ActionData.java
@@ -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) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
index 1d3ef71..f9e2ee2 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataProvider.java
@@ -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,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
index 199f0f1..3cb1b09 100644
--- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
+++ b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/tecsvc/data/ActionDataProviderTest.java
@@ -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());
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/AbstractODataDeserializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/AbstractODataDeserializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/AbstractODataDeserializerTest.java
new file mode 100644
index 0000000..c90ad6d
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/AbstractODataDeserializerTest.java
@@ -0,0 +1,44 @@
+/*
+ * 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.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.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 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);
+ if (in == null) {
+ throw new IOException("Requested file '" + filename + "' was not found.");
+ }
+ return in;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java
deleted file mode 100644
index 5cc025d..0000000
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/AbstractODataDeserializerTest.java
+++ /dev/null
@@ -1,46 +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.server.core.deserializer.json;
-
-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 InputStream getFileAsStream(final String filename) throws IOException {
- InputStream in = Thread.currentThread().getContextClassLoader().getResourceAsStream(filename);
- if (in == null) {
- throw new IOException("Requested file '" + filename + "' was not found.");
- }
- return in;
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
index 7bae022..8b87a12 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java
@@ -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)
+ @Test
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) {
+ deserialize("EntityESAllPrimExpandedNavPropertyETTwoPrimManyWithCustomAnnotations.json");
+ fail("Expected exception not thrown.");
+ } catch (final DeserializerException e) {
assertEquals(DeserializerException.MessageKeys.NOT_IMPLEMENTED, e.getMessageKey());
- throw e;
}
}
- @Test(expected = DeserializerException.class)
+ @Test
public void expandedToOneInvalidNullValue() throws Exception {
- String entityString =
+ ODataJsonDeserializerEntityTest.expectException(
"{\"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;
- }
+ + "}",
+ "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);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d6db341d/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
index 49b476d..4b2c6c3 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerEntityCollectionTest.java
@@ -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"));
- try {
- OData.newInstance().createDeserializer(CONTENT_TYPE_JSON).entityCollection(stream, edmEntityType);
- } catch (DeserializerException e) {
- assertEquals(DeserializerException.MessageKeys.UNKNOWN_CONTENT, e.getMessageKey());
- throw e;
- }
+ expectException("{\"value\":[],\"unknown\":null}", "ETAllPrim",
+ DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
- @Test(expected = DeserializerException.class)
+ @Test
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"));
+ 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.NOT_IMPLEMENTED, e.getMessageKey());
- throw e;
+ deserialize(stream, entityTypeName);
+ fail("Expected exception not thrown.");
+ } catch (final DeserializerException e) {
+ assertEquals(messageKey, e.getMessageKey());
}
}
+
+ private void expectException(final String entityCollectionString, final String entityTypeName,
+ final DeserializerException.MessageKeys messageKey) {
+ expectException(new ByteArrayInputStream(entityCollectionString.getBytes()), entityTypeName, messageKey);
+ }
}