You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/10/13 10:46:08 UTC
[01/11] olingo-odata4 git commit: [OLINGO-789] Minor clean up
Repository: olingo-odata4
Updated Branches:
refs/heads/olingo786 5d66c9cf1 -> 576acf466
[OLINGO-789] Minor clean up
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/26c923b6
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/26c923b6
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/26c923b6
Branch: refs/heads/olingo786
Commit: 26c923b6f3b0ac64956fcf8550c8cd1902692c5f
Parents: b736c43
Author: Michael Bolz <mi...@sap.com>
Authored: Mon Oct 5 08:24:48 2015 +0200
Committer: Michael Bolz <mi...@sap.com>
Committed: Mon Oct 5 08:24:48 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/server/tecsvc/data/ActionData.java | 10 ++++------
1 file changed, 4 insertions(+), 6 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/26c923b6/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 1169959..d14267d 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
@@ -54,8 +54,7 @@ public class ActionData {
return DataCreator.createPrimitive(null, "UARTString string value");
} else if ("UARTByteNineParam".equals(name)) {
short count = 0; // counts non-empty parameters
- for (final String parameterName : parameters.keySet()) {
- final Parameter parameter = parameters.get(parameterName);
+ for (final Parameter parameter : parameters.values()) {
if (!(parameter.isNull()
|| !parameter.isCollection()
&& (parameter.isComplex() && parameter.asComplex().getValue().isEmpty()
@@ -81,10 +80,9 @@ public class ActionData {
String param16String = valueAsString(paramInt16, EdmPrimitiveTypeKind.Int16, oData);
String paramDurationString = valueAsString(paramDuration, EdmPrimitiveTypeKind.Duration, oData);
- return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(new String[] {
- name + " int16 value: " + param16String,
- name + " duration value: " + paramDurationString
- }));
+ return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(
+ name + " int16 value: " + param16String,
+ name + " duration value: " + paramDurationString));
} catch(EdmPrimitiveTypeException e) {
throw new DataProviderException("EdmPrimitiveTypeException", e);
}
[04/11] olingo-odata4 git commit: [OLINGO-780] Minor EDM adjustment
Posted by ch...@apache.org.
[OLINGO-780] Minor EDM adjustment
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/f221962f
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/f221962f
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/f221962f
Branch: refs/heads/olingo786
Commit: f221962f72aa60bb970a40a63d262847316e9a44
Parents: 0989fbd
Author: Christian Holzer <c....@sap.com>
Authored: Wed Oct 7 15:20:52 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Wed Oct 7 15:20:52 2015 +0200
----------------------------------------------------------------------
.../tecsvc/provider/FunctionProvider.java | 12 +++++-----
.../server/tecsvc/provider/SchemaProvider.java | 2 +-
.../core/uri/antlr/TestFullResourcePath.java | 24 ++++++--------------
3 files changed, 14 insertions(+), 24 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f221962f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
index a83abab..73e218f 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/FunctionProvider.java
@@ -50,8 +50,8 @@ public class FunctionProvider {
public static final FullQualifiedName nameBFCCTPrimCompRTETTwoKeyNavParam =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCCTPrimCompRTETTwoKeyNavParam");
- public static final FullQualifiedName nameBFCESAllPrimRTCTAllPrim =
- new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCESAllPrimRTCTAllPrim");
+ public static final FullQualifiedName nameBFNESAllPrimRTCTAllPrim =
+ new FullQualifiedName(SchemaProvider.NAMESPACE, "BFNESAllPrimRTCTAllPrim");
public static final FullQualifiedName nameBFCESBaseTwoKeyNavRTESBaseTwoKey =
new FullQualifiedName(SchemaProvider.NAMESPACE, "BFCESBaseTwoKeyNavRTESBaseTwoKey");
@@ -574,22 +574,22 @@ public class FunctionProvider {
.setParameters(Arrays.asList(
new CsdlParameter().setName("BindingParam").setType(EntityTypeProvider.nameETBaseTwoKeyNav)
.setCollection(true).setNullable(false)))
- .setComposable(false)
+ .setComposable(true)
.setReturnType(
new CsdlReturnType().setType(EntityTypeProvider.nameETBaseTwoKeyNav).setCollection(true)
.setNullable(false))
);
- } else if (functionName.equals(nameBFCESAllPrimRTCTAllPrim)) {
+ } else if (functionName.equals(nameBFNESAllPrimRTCTAllPrim)) {
return Arrays.asList(
new CsdlFunction()
- .setName("BFCESAllPrimRTCTAllPrim")
+ .setName("BFNESAllPrimRTCTAllPrim")
.setBound(true)
.setParameters(
Arrays.asList(
new CsdlParameter().setName("BindingParam").setType(EntityTypeProvider.nameETAllPrim)
.setCollection(true).setNullable(false)))
- .setComposable(true)
+ .setComposable(false)
.setReturnType(
new CsdlReturnType().setType(ComplexTypeProvider.nameCTAllPrim).setNullable(false))
);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f221962f/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
index 03588b3..16ec8ba 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java
@@ -163,7 +163,7 @@ public class SchemaProvider {
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCStringRTESTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCETBaseTwoKeyNavRTETTwoKeyNav));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESBaseTwoKeyNavRTESBaseTwoKey));
- functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESAllPrimRTCTAllPrim));
+ functions.addAll(prov.getFunctions(FunctionProvider.nameBFNESAllPrimRTCTAllPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTCollCTTwoPrim));
functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTString));
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f221962f/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 7df684e..4d39d97 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -294,12 +294,12 @@ public class TestFullResourcePath {
@Test
public void runBfuncBnEsRtCprop() throws Exception {
- testUri.run("ESAllPrim/olingo.odata.test1.BFCESAllPrimRTCTAllPrim()")
+ testUri.run("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESAllPrim")
.n()
- .isFunction("BFCESAllPrimRTCTAllPrim")
+ .isFunction("BFNESAllPrimRTCTAllPrim")
.isType(ComplexTypeProvider.nameCTAllPrim);
testUri.run("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()/olingo.odata.test1.CTBase")
@@ -1188,25 +1188,15 @@ public class TestFullResourcePath {
testUri.runEx("FICRTCollETMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='1')", "$search=test")
.isExSemantic(MessageKeys.NOT_IMPLEMENTED);
- testUri.run("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()")
+ testUri.run("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()")
.isKind(UriInfoKind.resource)
.goPath().first()
- .isEntitySet("ESBaseTwoKeyNav")
+ .isEntitySet("ESAllPrim")
.at(1)
- .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey");
+ .isFunction("BFNESAllPrimRTCTAllPrim");
- testUri.run("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()"
- + "(PropertyInt16=1,PropertyString='1')")
- .isKind(UriInfoKind.resource)
- .goPath().first()
- .isEntitySet("ESBaseTwoKeyNav")
- .at(1)
- .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey")
- .isKeyPredicate(0, "PropertyInt16", "1")
- .isKeyPredicate(1, "PropertyString", "'1'");
-
- testUri.runEx("ESBaseTwoKeyNav/olingo.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()"
- + "(PropertyInt16=1,PropertyString='1')/NavPropertyETBaseTwoKeyNavOne")
+ testUri.runEx("ESAllPrim/olingo.odata.test1.BFNESAllPrimRTCTAllPrim()"
+ + "/PropertyString")
.isExValidation(UriValidationException.MessageKeys.UNALLOWED_RESOURCE_PATH);
}
[11/11] olingo-odata4 git commit: [OLINGO-786] Fix merge issues
Posted by ch...@apache.org.
[OLINGO-786] Fix merge issues
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/576acf46
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/576acf46
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/576acf46
Branch: refs/heads/olingo786
Commit: 576acf466b20a7103523512c3a2f4872ac026037
Parents: b1d03d6
Author: Christian Amend <ch...@sap.com>
Authored: Tue Oct 13 10:45:13 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Oct 13 10:45:13 2015 +0200
----------------------------------------------------------------------
.../olingo/commons/core/edm/EdmEnumTest.java | 354 -------------------
.../commons/core/edm/EdmTypeDefinitionTest.java | 137 -------
.../server/core/edm/provider/EdmEnumTest.java | 90 ++---
.../edm/provider/EdmTypeDefinitionImplTest.java | 60 +++-
4 files changed, 95 insertions(+), 546 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/576acf46/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
deleted file mode 100644
index 18bb798..0000000
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
+++ /dev/null
@@ -1,354 +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.commons.core.edm;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertArrayEquals;
-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.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.EdmEnumType;
-import org.apache.olingo.commons.api.edm.EdmException;
-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.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-
-public class EdmEnumTest {
-
- private final EdmEnumType instance;
- private final EdmEnumType otherInstance;
- private final EdmEnumType nonFlagsInstance;
- private final EdmEnumType int16EnumType;
- private final EdmEnumType int32EnumType;
- private final EdmEnumType int32FlagType;
-
- public EdmEnumTest() {
- final List<CsdlEnumMember> memberList = Arrays.asList(
- new CsdlEnumMember().setName("first").setValue("1"),
- new CsdlEnumMember().setName("second").setValue("64"));
-
- final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
-
- instance = new EdmEnumTypeImpl(null, enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- otherInstance = new EdmEnumTypeImpl(null, enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- nonFlagsInstance = new EdmEnumTypeImpl(null, enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- int16EnumType = new EdmEnumTypeImpl(null,
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType().setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
- .setMembers(Arrays.asList(
- new CsdlEnumMember().setName("A").setValue("0"),
- new CsdlEnumMember().setName("B").setValue("1"),
- new CsdlEnumMember().setName("C").setValue("2"))));
-
- int32EnumType = new EdmEnumTypeImpl(null,
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType().setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(Arrays.asList(
- new CsdlEnumMember().setName("A").setValue("0"),
- new CsdlEnumMember().setName("B").setValue("1"),
- new CsdlEnumMember().setName("C").setValue("2"))));
-
- int32FlagType = new EdmEnumTypeImpl(null,
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType().setName("MyEnum")
- .setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(Arrays.asList(
- new CsdlEnumMember().setName("A").setValue("2"),
- new CsdlEnumMember().setName("B").setValue("4"),
- new CsdlEnumMember().setName("C").setValue("8"))));
- }
-
- @Test
- public void nameSpace() throws Exception {
- assertEquals("namespace", instance.getNamespace());
- }
-
- @Test
- public void name() throws Exception {
- assertEquals("name", instance.getName());
- }
-
- @Test
- public void kind() throws Exception {
- assertEquals(EdmTypeKind.ENUM, instance.getKind());
- }
-
- @Test
- public void compatibility() {
- assertTrue(instance.isCompatible(instance));
- assertTrue(instance.isCompatible(otherInstance));
- assertFalse(instance.isCompatible(instance.getUnderlyingType()));
- }
-
- @Test
- public void defaultType() throws Exception {
- assertEquals(Byte.class, instance.getDefaultType());
- EdmEnumType instance = new EdmEnumTypeImpl(null,
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType().setName("MyEnum"));
- assertEquals(Integer.class, instance.getUnderlyingType().getDefaultType());
- }
-
- @Test
- public void members() throws Exception {
- assertArrayEquals(new String[] { "first", "second" }, instance.getMemberNames().toArray());
- assertEquals("64", instance.getMember("second").getValue());
- assertNull(instance.getMember("notExisting"));
- }
-
- @Test
- public void underlyingType() throws Exception {
- assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
- }
-
- @Test
- public void validate() throws Exception {
- assertTrue(instance.validate(null, null, null, null, null, null));
- assertTrue(instance.validate(null, true, null, null, null, null));
- assertFalse(instance.validate(null, false, null, null, null, null));
- assertFalse(instance.validate("", null, null, null, null, null));
- assertFalse(instance.validate("something", null, null, null, null, null));
-
- assertTrue(instance.validate("second", null, null, null, null, null));
- assertTrue(instance.validate("first,second", null, null, null, null, null));
- assertTrue(instance.validate("64", null, null, null, null, null));
- assertTrue(instance.validate("1,64", null, null, null, null, null));
- }
-
- @Test
- public void toUriLiteral() throws Exception {
- assertNull(instance.toUriLiteral(null));
- assertEquals("namespace.name'first'", instance.toUriLiteral("first"));
- }
-
- @Test
- public void fromUriLiteral() throws Exception {
- assertNull(instance.fromUriLiteral(null));
- assertEquals("first", instance.fromUriLiteral("namespace.name'first'"));
-
- expectErrorInFromUriLiteral(instance, "");
- expectErrorInFromUriLiteral(instance, "name'first'");
- expectErrorInFromUriLiteral(instance, "namespace.name'first");
- expectErrorInFromUriLiteral(instance, "namespace.namespace'first");
- }
-
- @Test
- public void valueToString() throws Exception {
- assertNull(instance.valueToString(null, null, null, null, null, null));
- assertNull(instance.valueToString(null, true, null, null, null, null));
- assertEquals("first", instance.valueToString(1, null, null, null, null, null));
- assertEquals("first", instance.valueToString((byte) 1, null, null, null, null, null));
- assertEquals("first", instance.valueToString((short) 1, null, null, null, null, null));
- assertEquals("second", instance.valueToString(Integer.valueOf(64), null, null, null, null, null));
- assertEquals("second", instance.valueToString(64L, null, null, null, null, null));
- assertEquals("first,second", instance.valueToString(65, null, null, null, null, null));
-
- expectNullErrorInValueToString(instance);
- expectContentErrorInValueToString(instance, 3);
- expectTypeErrorInValueToString(instance, 1.0);
-
- assertEquals("A", int32EnumType.valueToString(0, false, 0, 0, 0, false));
- assertEquals("B", int32EnumType.valueToString(1, false, 0, 0, 0, false));
- assertEquals("C", int32EnumType.valueToString(2, false, 0, 0, 0, false));
-
- assertEquals("A", int16EnumType.valueToString(0, false, 0, 0, 0, false));
- assertEquals("B", int16EnumType.valueToString(1, false, 0, 0, 0, false));
- assertEquals("C", int16EnumType.valueToString(2, false, 0, 0, 0, false));
-
- assertEquals("A", int32FlagType.valueToString(2, false, 0, 0, 0, false));
- assertEquals("B", int32FlagType.valueToString(4, false, 0, 0, 0, false));
- assertEquals("C", int32FlagType.valueToString(8, false, 0, 0, 0, false));
- assertEquals("A,B", int32FlagType.valueToString(0x2 + 0x4, false, 0, 0, 0, false));
- assertEquals("B,C", int32FlagType.valueToString(0x4 + 0x8, false, 0, 0, 0, false));
- }
-
- @Test
- public void valueOfString() throws Exception {
- assertNull(instance.valueOfString(null, null, null, null, null, null, Byte.class));
- assertNull(instance.valueOfString(null, true, null, null, null, null, Byte.class));
- assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", null, null, null, null, null, Short.class));
- assertEquals(Integer.valueOf(1), instance.valueOfString("1", null, null, null, null, null, Integer.class));
- assertEquals(Long.valueOf(64L), instance.valueOfString("64", null, null, null, null, null, Long.class));
- assertEquals(Long.valueOf(1), instance.valueOfString("first", null, null, null, null, null, Long.class));
- assertEquals(Byte.valueOf((byte) 65), instance.valueOfString("first,64", null, null, null, null, null, Byte.class));
- assertEquals(Integer.valueOf(1), instance.valueOfString("1,1,first", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(1), nonFlagsInstance.valueOfString("1", null, null, null, null, null, Integer.class));
- expectContentErrorInValueOfString(nonFlagsInstance, "1,64");
-
- expectNullErrorInValueOfString(instance);
- expectContentErrorInValueOfString(instance, "2");
- expectContentErrorInValueOfString(instance, "1,");
- expectContentErrorInValueOfString(instance, ",1");
- expectTypeErrorInValueOfString(instance, "1");
-
- assertEquals(Integer.valueOf(0), int32EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(1), int32EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(2), int32EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(0), int16EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(1), int16EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(2), int16EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(2), int32FlagType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(4), int32FlagType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(8), int32FlagType.valueOfString("C", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("A,B", null, null, null, null, null,
- Integer.class));
- assertEquals(Integer.valueOf(0x4 + 0x8), int32FlagType.valueOfString("B,C", null, null, null, null, null,
- Integer.class));
- assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("B,A", null, null, null, null, null,
- Integer.class));
- }
-
- private void expectErrorInValueToString(final EdmEnumType instance,
- final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode,
- final String message) {
- try {
- instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- private void expectErrorInUnderlyingType(final EdmPrimitiveTypeKind underlyingType, final String message) {
- try {
- new EdmEnumTypeImpl(null,
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(underlyingType.getFullQualifiedName())
- .setMembers(Arrays.asList(
- new CsdlEnumMember().setName("A").setValue("0"))));
- fail("Expected exception not thrown");
- } catch (final EdmException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- @Test
- public void unsupportedUnderlyingType() throws Exception {
- // Test some random unsupported types
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Date, "");
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Geography, "");
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Guid, "");
- }
-
- @Test
- public void outOfRangeValueToString() throws Exception {
- expectErrorInValueToString(int16EnumType, Integer.MAX_VALUE, null, null, null, null, null, "");
- }
-
- protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
- try {
- instance.fromUriLiteral(value);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
- }
- }
-
- private void expectErrorInValueToString(final EdmPrimitiveType instance,
- final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode,
- final String message) {
- try {
- instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
- expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
- }
-
- protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
- expectErrorInValueToString(instance, value, null, null, null, null, null, "value type");
- }
-
- protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
- expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid.");
- }
-
- private void expectErrorInValueOfString(final EdmPrimitiveType instance,
- final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
- final Integer scale, final Boolean isUnicode, final Class<?> returnType,
- final String message) {
-
- try {
- instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
- expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
- "The value type class java.lang.Class is not supported.");
- }
-
- protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
- expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
- "illegal content");
- }
-
- protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
- expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
- "The literal 'null' is not allowed.");
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/576acf46/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
deleted file mode 100644
index 3d41db4..0000000
--- a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
+++ /dev/null
@@ -1,137 +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.commons.core.edm;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-
-import org.apache.olingo.commons.api.edm.EdmAnnotationsTarget.TargetType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
-import org.apache.olingo.commons.core.edm.primitivetype.PrimitiveTypeBaseTest;
-import org.junit.Test;
-
-public class EdmTypeDefinitionTest extends PrimitiveTypeBaseTest {
-
- private final EdmPrimitiveType instance = new EdmTypeDefinitionImpl(null,
- new FullQualifiedName("namespace", "def"),
- new CsdlTypeDefinition().setName("def")
- .setUnderlyingType(EdmString.getInstance().getFullQualifiedName())
- .setMaxLength(5)
- .setUnicode(false));
-
- @Test
- public void defaultType() throws Exception {
- assertEquals(String.class, instance.getDefaultType());
- }
-
- @Test
- public void compatibility() {
- assertTrue(instance.isCompatible(instance));
- for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
- if (kind != EdmPrimitiveTypeKind.String) {
- assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind)));
- }
- }
- }
-
- @Test
- public void toUriLiteral() throws Exception {
- assertEquals("'Value'", instance.toUriLiteral("Value"));
- }
-
- @Test
- public void fromUriLiteral() throws Exception {
- assertEquals("Value", instance.fromUriLiteral("'Value'"));
- }
-
- @Test
- public void valueToString() throws Exception {
- assertEquals("text", instance.valueToString("text", null, null, null, null, null));
-
- expectFacetsErrorInValueToString(instance, "longtext", null, null, null, null, null);
- expectFacetsErrorInValueToString(instance, "text", null, 3, null, null, null);
- expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, null);
- expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, false);
- }
-
- @Test
- public void valueOfString() throws Exception {
- assertEquals("text", instance.valueOfString("text", null, null, null, null, null, String.class));
-
- expectFacetsErrorInValueOfString(instance, "longtext", null, null, null, null, null);
- expectFacetsErrorInValueOfString(instance, "text", null, 3, null, null, null);
- expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, null);
- expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, false);
-
- expectTypeErrorInValueOfString(instance, "text");
- }
-
- @Test
- public void typeDefOnStringNoFacets() throws Exception {
- final EdmTypeDefinition typeDef = new EdmTypeDefinitionImpl(null,
- new FullQualifiedName("namespace", "name"),
- new CsdlTypeDefinition().setName("typeDef")
- .setUnderlyingType(EdmString.getInstance().getFullQualifiedName()));
-
- assertEquals("name", typeDef.getName());
- assertEquals("namespace", typeDef.getNamespace());
- assertEquals(new FullQualifiedName("namespace", "name"), typeDef.getFullQualifiedName());
- assertEquals(String.class, typeDef.getDefaultType());
- assertEquals(EdmTypeKind.DEFINITION, typeDef.getKind());
- assertEquals(EdmString.getInstance(), typeDef.getUnderlyingType());
- assertTrue(typeDef.isCompatible(EdmString.getInstance()));
- assertEquals(TargetType.TypeDefinition, typeDef.getAnnotationsTargetType());
- assertEquals(typeDef.getFullQualifiedName(), typeDef.getAnnotationsTargetFQN());
- assertEquals(typeDef.getName(), typeDef.getAnnotationsTargetPath());
-
- // String validation
- assertEquals("'StringValue'", typeDef.toUriLiteral("StringValue"));
- assertEquals("String''Value", typeDef.fromUriLiteral("'String''''Value'"));
- assertTrue(typeDef.validate("text", null, null, null, null, null));
- assertEquals("text", typeDef.valueToString("text", null, null, null, null, null));
- assertEquals("text", typeDef.valueOfString("text", null, null, null, null, null, String.class));
-
- // Facets must be initial
- assertNull(typeDef.getMaxLength());
- assertNull(typeDef.getPrecision());
- assertNull(typeDef.getScale());
- assertNull(typeDef.getSrid());
- assertTrue(typeDef.isUnicode());
- }
-
- @Test(expected = EdmException.class)
- public void invalidTypeResultsInEdmException() throws Exception {
- new EdmTypeDefinitionImpl(null,
- new FullQualifiedName("namespace", "name"),
- new CsdlTypeDefinition().setName("typeDef")
- .setUnderlyingType(new FullQualifiedName("wrong", "wrong")))
- .getUnderlyingType();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/576acf46/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
index 25dcb03..8741cd9 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
@@ -17,7 +17,6 @@
* under the License.
*/
package org.apache.olingo.server.core.edm.provider;
-
import static org.hamcrest.CoreMatchers.containsString;
import static org.junit.Assert.assertArrayEquals;
import static org.junit.Assert.assertEquals;
@@ -27,12 +26,10 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
import java.util.Arrays;
import java.util.List;
-import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEnumType;
import org.apache.olingo.commons.api.edm.EdmException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
@@ -43,10 +40,8 @@ import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
import org.apache.olingo.commons.core.edm.EdmEnumTypeImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
import org.junit.Test;
-import org.mockito.Mockito;
public class EdmEnumTest {
@@ -64,54 +59,46 @@ public class EdmEnumTest {
final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
- instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
+ instance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
- otherInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
+ otherInstance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
- nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
+ nonFlagsInstance = new EdmEnumTypeImpl(null, enumName,
new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
.setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
- int16EnumType = new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
- .setMembers(
- Arrays.asList(
- new CsdlEnumMember().setName("A")
- .setValue("0"),
- new CsdlEnumMember().setName("B")
- .setValue("1"),
- new CsdlEnumMember().setName("C")
- .setValue("2"))));
-
- int32EnumType =
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(
- Arrays
- .asList(new CsdlEnumMember().setName("A").setValue("0"), new CsdlEnumMember().setName("B")
- .setValue("1"),
+ int16EnumType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(false)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"),
+ new CsdlEnumMember().setName("B").setValue("1"),
new CsdlEnumMember().setName("C").setValue("2"))));
- int32FlagType =
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(
- Arrays
- .asList(new CsdlEnumMember().setName("A").setValue("2"), new CsdlEnumMember().setName("B")
- .setValue("4"),
+ int32EnumType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(false)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"),
+ new CsdlEnumMember().setName("B").setValue("1"),
+ new CsdlEnumMember().setName("C").setValue("2"))));
+
+ int32FlagType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(true)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("2"),
+ new CsdlEnumMember().setName("B").setValue("4"),
new CsdlEnumMember().setName("C").setValue("8"))));
}
@@ -140,10 +127,9 @@ public class EdmEnumTest {
@Test
public void defaultType() throws Exception {
assertEquals(Byte.class, instance.getDefaultType());
- EdmEnumType instance = new EdmEnumTypeImpl(Mockito.mock(Edm.class),
+ EdmEnumType instance = new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType()
- .setName("MyEnum"));
+ new CsdlEnumType().setName("MyEnum"));
assertEquals(Integer.class, instance.getUnderlyingType().getDefaultType());
}
@@ -272,20 +258,16 @@ public class EdmEnumTest {
}
}
- private void expectErrorInUnderlyingType(
- final EdmPrimitiveTypeKind underlyingType,
- final String message) {
+ private void expectErrorInUnderlyingType(final EdmPrimitiveTypeKind underlyingType, final String message) {
try {
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
+ new EdmEnumTypeImpl(null,
new FullQualifiedName("testNamespace", "testName"),
new CsdlEnumType()
.setName("MyEnum")
.setFlags(false)
.setUnderlyingType(underlyingType.getFullQualifiedName())
- .setMembers(
- Arrays.asList(
- new CsdlEnumMember().setName("A")
- .setValue("0"))));
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"))));
fail("Expected exception not thrown");
} catch (final EdmException e) {
assertNotNull(e.getLocalizedMessage());
@@ -369,4 +351,4 @@ public class EdmEnumTest {
expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
"The literal 'null' is not allowed.");
}
-}
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/576acf46/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
index 0cc37fa..d8afb95 100644
--- a/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
+++ b/lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
@@ -19,12 +19,14 @@
package org.apache.olingo.server.core.edm.provider;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
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 org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
@@ -33,10 +35,66 @@ import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.core.edm.EdmProviderImpl;
import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
+import org.apache.olingo.commons.core.edm.primitivetype.PrimitiveTypeBaseTest;
import org.junit.Test;
-public class EdmTypeDefinitionImplTest {
+public class EdmTypeDefinitionImplTest extends PrimitiveTypeBaseTest {
+ private final EdmPrimitiveType instance = new EdmTypeDefinitionImpl(null,
+ new FullQualifiedName("namespace", "def"),
+ new CsdlTypeDefinition().setName("def")
+ .setUnderlyingType(EdmString.getInstance().getFullQualifiedName())
+ .setMaxLength(5)
+ .setUnicode(false));
+
+ @Test
+ public void defaultType() throws Exception {
+ assertEquals(String.class, instance.getDefaultType());
+ }
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(instance));
+ for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
+ if (kind != EdmPrimitiveTypeKind.String) {
+ assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind)));
+ }
+ }
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("'Value'", instance.toUriLiteral("Value"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("Value", instance.fromUriLiteral("'Value'"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("text", instance.valueToString("text", null, null, null, null, null));
+
+ expectFacetsErrorInValueToString(instance, "longtext", null, null, null, null, null);
+ expectFacetsErrorInValueToString(instance, "text", null, 3, null, null, null);
+ expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, null);
+ expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, false);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals("text", instance.valueOfString("text", null, null, null, null, null, String.class));
+
+ expectFacetsErrorInValueOfString(instance, "longtext", null, null, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "text", null, 3, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, false);
+
+ expectTypeErrorInValueOfString(instance, "text");
+ }
+
@Test
public void typeDefOnStringNoFacets() throws Exception {
final FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
[02/11] olingo-odata4 git commit: [OLINGO-792] Improve URI parser
error message
Posted by ch...@apache.org.
[OLINGO-792] Improve URI parser error message
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/d0b225bf
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/d0b225bf
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/d0b225bf
Branch: refs/heads/olingo786
Commit: d0b225bf18a8ed06a090f92fd5f55dee7767a7cc
Parents: 26c923b
Author: Christian Holzer <c....@sap.com>
Authored: Tue Oct 6 16:41:09 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Tue Oct 6 16:41:09 2015 +0200
----------------------------------------------------------------------
.../server/core/uri/parser/UriParseTreeVisitor.java | 5 ++---
.../core/uri/parser/UriParserSemanticException.java | 2 ++
.../main/resources/server-core-exceptions-i18n.properties | 1 +
.../server/core/uri/antlr/TestFullResourcePath.java | 10 ++++++++--
4 files changed, 13 insertions(+), 5 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index edd6058..f61c6ee 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -662,9 +662,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// do a check for bound functions (which requires a parameter list)
if (ctx.vlNVO.size() == 0) {
- throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString()
- + "'",
- UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED, fullBindingTypeName.toString()));
+ throw wrap(new UriParserSemanticException("Unknown type for type cast " + fullFilterName.toString()
+ + " not found", UriParserSemanticException.MessageKeys.UNKNOWN_TYPE , fullFilterName.toString()));
}
context.contextReadingFunctionParameters = true;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 75744c9..672d093 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -48,6 +48,8 @@ public class UriParserSemanticException extends UriParserException {
FUNCTION_PARAMETERS_EXPECTED,
/** parameter: resource part */
UNKNOWN_PART,
+ /** parameter: type */
+ UNKNOWN_TYPE,
/** parameter: expression */
ONLY_FOR_TYPED_PARTS,
/** parameter: entity type name */
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index de14eb0..3484ab3 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -50,6 +50,7 @@ UriParserSemanticException.FUNCTION_PARAMETERS_EXPECTED=Function parameters expe
UriParserSemanticException.UNKNOWN_PART=The part '%1$s' is not defined.
UriParserSemanticException.ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts.
UriParserSemanticException.UNKNOWN_ENTITY_TYPE=The entity type '%1$s' is not defined.
+UriParserSemanticException.UNKNOWN_TYPE=The type of the type cast '%1$s' is not defined.
UriParserSemanticException.ONLY_FOR_COLLECTIONS='%1$s' is only allowed for collections.
UriParserSemanticException.ONLY_FOR_ENTITY_TYPES='%1$s' is only allowed for entity types.
UriParserSemanticException.ONLY_FOR_STRUCTURAL_TYPES='%1$s' is only allowed for structural types.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/d0b225bf/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 5c06e2c..3b2ff14 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -5442,7 +5442,7 @@ public class TestFullResourcePath {
.isExSemantic(UriParserSemanticException.MessageKeys.TYPE_FILTER_NOT_CHAINABLE);
testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav")
- .isExSemantic(UriParserSemanticException.MessageKeys.FUNCTION_PARAMETERS_EXPECTED);
+ .isExSemantic(UriParserSemanticException.MessageKeys.UNKNOWN_TYPE);
// $ref
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyCompTwoPrim/$ref")
@@ -5563,7 +5563,13 @@ public class TestFullResourcePath {
testUri.runEx("AIRTESAllPrimParam/FICRTString()").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
testUri.runEx("AIRTESAllPrimParam/AIRTString").isExSemantic(MessageKeys.RESOURCE_PART_ONLY_FOR_TYPED_PARTS);
}
-
+
+ @Test
+ public void invalidTypeCast() {
+ testUri.runEx("ESAllPrim/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
+ testUri.runEx("ESAllPrim(0)/namespace.Invalid").isExSemantic(MessageKeys.UNKNOWN_TYPE);
+ }
+
@Test
public void navPropertySameNameAsEntitySet() throws Exception {
testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
[09/11] olingo-odata4 git commit: [OLINGO-795] server support for
Enums and Type Definitions
Posted by ch...@apache.org.
[OLINGO-795] server support for Enums and Type Definitions
Signed-off-by: Christian Amend <ch...@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/5d364dfa
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/5d364dfa
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/5d364dfa
Branch: refs/heads/olingo786
Commit: 5d364dfa275a523df8cdd95a158245b05c55c3a5
Parents: 9933cb0
Author: Klaus Straubinger <kl...@sap.com>
Authored: Fri Oct 9 14:14:13 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Fri Oct 9 14:47:21 2015 +0200
----------------------------------------------------------------------
.../olingo/fit/AbstractBaseTestITCase.java | 94 +---
.../olingo/fit/tecsvc/client/BasicITCase.java | 443 ++++++++++---------
.../fit/tecsvc/client/BatchClientITCase.java | 5 +-
.../olingo/fit/tecsvc/http/PingITCase.java | 4 +
.../commons/core/edm/EdmEnumTypeImpl.java | 68 +--
.../commons/core/edm/EdmTypeDefinitionImpl.java | 58 +--
.../olingo/commons/core/edm/EdmEnumTest.java | 354 +++++++++++++++
.../commons/core/edm/EdmTypeDefinitionTest.java | 137 ++++++
.../deserializer/xml/ODataXmlDeserializer.java | 41 +-
.../serializer/AbstractODataSerializer.java | 5 +-
.../serializer/json/ODataJsonSerializer.java | 26 +-
.../json/ServiceDocumentJsonSerializer.java | 49 +-
.../core/serializer/xml/ODataXmlSerializer.java | 201 ++++-----
.../xml/ServiceDocumentXmlSerializer.java | 87 ++--
.../server/core/edm/provider/EdmEnumTest.java | 372 ----------------
.../edm/provider/EdmTypeDefinitionImplTest.java | 77 ----
.../xml/ServiceDocumentXmlSerializerTest.java | 14 +-
.../olingo/server/tecsvc/data/DataCreator.java | 6 +-
.../olingo/server/tecsvc/data/DataProvider.java | 41 +-
.../tecsvc/provider/PropertyProvider.java | 4 +-
.../tecsvc/provider/TypeDefinitionProvider.java | 6 +-
.../json/ODataJsonDeserializerEntityTest.java | 4 +
.../xml/ODataXmlDeserializerTest.java | 189 ++++----
.../json/ODataJsonSerializerTest.java | 64 ++-
.../serializer/json/ServiceDocumentTest.java | 21 +-
.../serializer/xml/MetadataDocumentTest.java | 29 +-
.../serializer/xml/ODataXmlSerializerTest.java | 284 +++++++-----
27 files changed, 1361 insertions(+), 1322 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
index 9595573..a14484a 100644
--- a/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/AbstractBaseTestITCase.java
@@ -19,8 +19,6 @@
package org.apache.olingo.fit;
import java.io.IOException;
-import java.io.InputStream;
-import java.io.StringWriter;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
@@ -30,39 +28,26 @@ import javax.servlet.http.HttpServletResponse;
import org.apache.catalina.LifecycleException;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.client.api.ODataClient;
-import org.apache.olingo.client.api.domain.ClientEntity;
-import org.apache.olingo.client.api.domain.ClientProperty;
-import org.apache.olingo.client.api.domain.ClientValue;
-import org.apache.olingo.client.api.serialization.ODataSerializerException;
-import org.apache.olingo.commons.api.data.Entity;
-import org.apache.olingo.commons.api.data.EntityCollection;
-import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.fit.server.TomcatTestServer;
import org.apache.olingo.server.tecsvc.TechnicalServlet;
import org.apache.olingo.server.tecsvc.async.TechnicalStatusMonitorServlet;
import org.junit.AfterClass;
import org.junit.BeforeClass;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
public abstract class AbstractBaseTestITCase {
- /**
- * Logger.
- */
- protected static final Logger LOG = LoggerFactory.getLogger(AbstractBaseTestITCase.class);
-
protected abstract ODataClient getClient();
+
private static TomcatTestServer server;
@BeforeClass
public static void init()
throws LifecycleException, IOException, InstantiationException, IllegalAccessException, ClassNotFoundException {
server = TomcatTestServer.init(9080)
- .addServlet(TechnicalServlet.class, "/odata-server-tecsvc/odata.svc/*")
- .addServlet(TechnicalStatusMonitorServlet.class, "/odata-server-tecsvc/status/*")
- .addServlet(StaticContent.create("org-odata-core-v1.xml"),
- "/odata-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
+ .addServlet(TechnicalServlet.class, "/odata-server-tecsvc/odata.svc/*")
+ .addServlet(TechnicalStatusMonitorServlet.class, "/odata-server-tecsvc/status/*")
+ .addServlet(StaticContent.create("org-odata-core-v1.xml"),
+ "/odata-server-tecsvc/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml")
.addWebApp(false)
.start();
}
@@ -72,75 +57,6 @@ public abstract class AbstractBaseTestITCase {
server.invalidateAllSessions();
}
- protected void debugEntity(final Entity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- try {
- getClient().getSerializer(ContentType.JSON).write(writer, entity);
- } catch (final ODataSerializerException e) {
- // Debug
- }
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugEntitySet(final EntityCollection entitySet, final String message) {
- if (LOG.isDebugEnabled()) {
- final StringWriter writer = new StringWriter();
- try {
- getClient().getSerializer(ContentType.JSON).write(writer, entitySet);
- } catch (final ODataSerializerException e) {
- // Debug
- }
- writer.flush();
- LOG.debug(message + "\n{}", writer.toString());
- }
- }
-
- protected void debugODataProperty(final ClientProperty property, final String message) {
- LOG.debug(message + "\n{}", property.toString());
- }
-
- protected void debugODataValue(final ClientValue value, final String message) {
- LOG.debug(message + "\n{}", value.toString());
- }
-
- protected void debugODataEntity(final ClientEntity entity, final String message) {
- if (LOG.isDebugEnabled()) {
- StringWriter writer = new StringWriter();
- try {
- getClient().getSerializer(ContentType.APPLICATION_ATOM_XML).write(writer, getClient().getBinder()
- .getEntity(entity));
- } catch (final ODataSerializerException e) {
- // Debug
- }
- writer.flush();
- LOG.debug(message + " (Atom)\n{}", writer.toString());
-
- writer = new StringWriter();
- try {
- getClient().getSerializer(ContentType.JSON).write(writer, getClient().getBinder().getEntity(entity));
- } catch (final ODataSerializerException e) {
- // Debug
- }
- writer.flush();
- LOG.debug(message + " (JSON)\n{}", writer.toString());
- }
- }
-
- protected void debugInputStream(final InputStream input, final String message) {
- if (LOG.isDebugEnabled()) {
- try {
- LOG.debug(message + "\n{}", IOUtils.toString(input));
- } catch (IOException e) {
- LOG.error("Error writing stream", e);
- } finally {
- IOUtils.closeQuietly(input);
- }
- }
- }
-
public static class StaticContent extends HttpServlet {
private static final long serialVersionUID = -6663569573355398997L;
private final String resourceName;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
index ed7221b..8656e6e 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BasicITCase.java
@@ -27,6 +27,7 @@ import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
+import static org.junit.Assume.assumeTrue;
import java.math.BigDecimal;
import java.net.URI;
@@ -78,22 +79,24 @@ import org.junit.Ignore;
import org.junit.Test;
public class BasicITCase extends AbstractParamTecSvcITCase {
-
+
private static final String CONTENT_TYPE_JSON_IEEE754_COMPATIBLE =
ContentType.create(ContentType.JSON, ContentType.PARAMETER_IEEE754_COMPATIBLE, "true").toContentTypeString();
- private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
- private static final String ET_ALL_PRIM_NAME = "ETAllPrim";
- private static final FullQualifiedName ET_ALL_PRIM = new FullQualifiedName(SERVICE_NAMESPACE, ET_ALL_PRIM_NAME);
+ private static final FullQualifiedName ET_ALL_PRIM = new FullQualifiedName(SERVICE_NAMESPACE, "ETAllPrim");
+ private static final FullQualifiedName ET_KEY_NAV = new FullQualifiedName(SERVICE_NAMESPACE, "ETKeyNav");
private static final String PROPERTY_INT16 = "PropertyInt16";
private static final String PROPERTY_INT64 = "PropertyInt64";
private static final String PROPERTY_DECIMAL = "PropertyDecimal";
+ private static final String PROPERTY_STRING = "PropertyString";
+ private static final String PROPERTY_COMP = "PropertyComp";
private static final String PROPERTY_COMP_ALL_PRIM = "PropertyCompAllPrim";
private static final String NAV_PROPERTY_ET_TWO_PRIM_ONE = "NavPropertyETTwoPrimOne";
private static final String ES_ALL_PRIM = "ESAllPrim";
private static final String ES_TWO_PRIM = "ESTwoPrim";
private static final String ES_KEY_NAV = "ESKeyNav";
+ private static final String ES_MIX_PRIM_COLL_COMP = "ESMixPrimCollComp";
@Test
public void readServiceDocument() {
@@ -108,7 +111,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
ClientServiceDocument serviceDocument = response.getBody();
assertNotNull(serviceDocument);
- assertThat(serviceDocument.getEntitySetNames(), hasItem("ESAllPrim"));
+ assertThat(serviceDocument.getEntitySetNames(), hasItem(ES_ALL_PRIM));
assertThat(serviceDocument.getFunctionImportNames(), hasItem("FICRTCollCTTwoPrim"));
assertThat(serviceDocument.getSingletonNames(), hasItem("SIMedia"));
}
@@ -127,8 +130,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(edm);
assertEquals(2, edm.getSchemas().size());
- assertEquals("olingo.odata.test1", edm.getSchema("olingo.odata.test1").getNamespace());
- assertEquals("Namespace1_Alias", edm.getSchema("olingo.odata.test1").getAlias());
+ assertEquals(SERVICE_NAMESPACE, edm.getSchema(SERVICE_NAMESPACE).getNamespace());
+ assertEquals("Namespace1_Alias", edm.getSchema(SERVICE_NAMESPACE).getAlias());
assertEquals("Org.OData.Core.V1", edm.getSchema("Org.OData.Core.V1").getNamespace());
assertEquals("Core", edm.getSchema("Org.OData.Core.V1").getAlias());
}
@@ -147,7 +150,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(xmlMetadata);
assertEquals(2, xmlMetadata.getSchemas().size());
- assertEquals("olingo.odata.test1", xmlMetadata.getSchema("olingo.odata.test1").getNamespace());
+ assertEquals(SERVICE_NAMESPACE, xmlMetadata.getSchema(SERVICE_NAMESPACE).getNamespace());
final List<Reference> references = xmlMetadata.getReferences();
assertEquals(1, references.size());
assertThat(references.get(0).getUri().toASCIIString(), containsString("vocabularies/Org.OData.Core.V1"));
@@ -157,7 +160,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void readEntitySet() {
ODataEntitySetRequest<ClientEntitySet> request = getClient().getRetrieveRequestFactory()
.getEntitySetRequest(getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").build());
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).build());
assertNotNull(request);
setCookieHeader(request);
@@ -179,14 +182,10 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(3, entities.size());
final ClientEntity entity = entities.get(2);
assertNotNull(entity);
- final ClientProperty property = entity.getProperty("PropertyInt16");
+ final ClientProperty property = entity.getProperty(PROPERTY_INT16);
assertNotNull(property);
assertNotNull(property.getPrimitiveValue());
- if (isJson()) {
- assertEquals(0, property.getPrimitiveValue().toValue());
- } else {
- assertEquals((short)0, property.getPrimitiveValue().toValue());
- }
+ assertShortOrInt(0, property.getPrimitiveValue().toValue());
}
@Test
@@ -211,7 +210,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void readException() throws Exception {
ODataEntityRequest<ClientEntity> request = getClient().getRetrieveRequestFactory()
.getEntityRequest(getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").appendKeySegment("42").build());
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).appendKeySegment("42").build());
assertNotNull(request);
setCookieHeader(request);
@@ -245,20 +244,14 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertNotNull(property.getCollectionValue());
assertEquals(3, property.getCollectionValue().size());
Iterator<ClientValue> iterator = property.getCollectionValue().iterator();
- if(isJson()) {
- assertEquals(1000, iterator.next().asPrimitive().toValue());
- assertEquals(2000, iterator.next().asPrimitive().toValue());
- assertEquals(30112, iterator.next().asPrimitive().toValue());
- } else {
- assertEquals((short)1000, iterator.next().asPrimitive().toValue());
- assertEquals((short)2000, iterator.next().asPrimitive().toValue());
- assertEquals((short)30112, iterator.next().asPrimitive().toValue());
- }
+ assertShortOrInt(1000, iterator.next().asPrimitive().toValue());
+ assertShortOrInt(2000, iterator.next().asPrimitive().toValue());
+ assertShortOrInt(30112, iterator.next().asPrimitive().toValue());
}
@Test
public void deleteEntity() throws Exception {
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataDeleteRequest request = getClient().getCUDRequestFactory().getDeleteRequest(uri);
final ODataDeleteResponse response = request.execute();
@@ -278,14 +271,14 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void patchEntity() throws Exception {
- ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ ClientEntity patchEntity = getFactory().newEntity(ET_ALL_PRIM);
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("new")));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyDecimal",
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_DECIMAL,
getFactory().newPrimitiveValueBuilder().buildDecimal(new BigDecimal(42.875))));
- patchEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ patchEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(null)));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataEntityUpdateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.PATCH, patchEntity);
@@ -295,36 +288,28 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the patched properties have changed and the other properties not.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientProperty property1 = entity.getProperty("PropertyString");
+ final ClientProperty property1 = entity.getProperty(PROPERTY_STRING);
assertNotNull(property1);
assertEquals("new", property1.getPrimitiveValue().toValue());
- final ClientProperty property2 = entity.getProperty("PropertyDecimal");
+ final ClientProperty property2 = entity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
- if (isJson()) {
- assertEquals(42.875, property2.getPrimitiveValue().toValue());
- } else {
- assertEquals(new BigDecimal(42.875), property2.getPrimitiveValue().toValue());
- }
- final ClientProperty property3 = entity.getProperty("PropertyInt64");
+ assertEquals(isJson() ? 42.875 : new BigDecimal(42.875),
+ property2.getPrimitiveValue().toValue());
+ final ClientProperty property3 = entity.getProperty(PROPERTY_INT64);
assertNotNull(property3);
assertNull(property3.getPrimitiveValue());
final ClientProperty property4 = entity.getProperty("PropertyDuration");
assertNotNull(property4);
- if (isJson()) {
- assertEquals("PT6S", property4.getPrimitiveValue().toValue());
- } else {
- assertEquals(new BigDecimal(6), property4.getPrimitiveValue().toValue());
- }
-
+ assertEquals(isJson() ? "PT6S" : BigDecimal.valueOf(6), property4.getPrimitiveValue().toValue());
}
@Test
public void updateEntity() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM);
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64((long) 42)));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").appendKeySegment(32767)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(32767)
.build();
final ODataEntityUpdateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.REPLACE, newEntity);
@@ -334,26 +319,22 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the updated properties have changed and that other properties have their default values.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientProperty property1 = entity.getProperty("PropertyInt64");
+ final ClientProperty property1 = entity.getProperty(PROPERTY_INT64);
assertNotNull(property1);
- if (isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((long)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = entity.getProperty("PropertyDecimal");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = entity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
assertNull(property2.getPrimitiveValue());
}
@Test
public void patchEntityWithComplex() throws Exception {
- ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETCompComp"));
- patchEntity.getProperties().add(getFactory().newComplexProperty("PropertyComp",
- getFactory().newComplexValue("olingo.odata.test1.CTCompComp").add(
- getFactory().newComplexProperty("PropertyComp",
- getFactory().newComplexValue("olingo.odata.test1.CTTwoPrim").add(
- getFactory().newPrimitiveProperty("PropertyInt16",
+ ClientEntity patchEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETCompComp"));
+ patchEntity.getProperties().add(getFactory().newComplexProperty(PROPERTY_COMP,
+ getFactory().newComplexValue(SERVICE_NAMESPACE + ".CTCompComp").add(
+ getFactory().newComplexProperty(PROPERTY_COMP,
+ getFactory().newComplexValue(SERVICE_NAMESPACE + ".CTTwoPrim").add(
+ getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short)42)))))));
ODataClient client = getClient();
final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESCompComp").appendKeySegment(1).build();
@@ -365,40 +346,36 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
// Check that the patched properties have changed and the other properties not.
final ClientEntity entity = response.getBody();
assertNotNull(entity);
- final ClientComplexValue complex = entity.getProperty("PropertyComp").getComplexValue()
- .get("PropertyComp").getComplexValue();
+ final ClientComplexValue complex = entity.getProperty(PROPERTY_COMP).getComplexValue()
+ .get(PROPERTY_COMP).getComplexValue();
assertNotNull(complex);
- final ClientProperty property1 = complex.get("PropertyInt16");
+ final ClientProperty property1 = complex.get(PROPERTY_INT16);
assertNotNull(property1);
- if (isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((short)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = complex.get("PropertyString");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = complex.get(PROPERTY_STRING);
assertNotNull(property2);
assertEquals("String 1", property2.getPrimitiveValue().toValue());
}
@Test
public void updateEntityWithComplex() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ ClientEntity newEntity = getFactory().newEntity(ET_KEY_NAV);
newEntity.getProperties().add(getFactory().newComplexProperty("PropertyCompCompNav", null));
// The following properties must not be null
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test")));
newEntity.getProperties().add(
getFactory().newComplexProperty("PropertyCompTwoPrim",
getFactory().newComplexValue("CTTwoPrim")
.add(getFactory().newPrimitiveProperty(
- "PropertyInt16",
+ PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
.add(getFactory().newPrimitiveProperty(
- "PropertyString",
+ PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test2")))));
ODataClient client = getClient();
- final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").appendKeySegment(1).build();
+ final URI uri = client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
final ODataEntityUpdateRequest<ClientEntity> request = client.getCUDRequestFactory().getEntityUpdateRequest(
uri, UpdateType.REPLACE, newEntity);
final ODataEntityUpdateResponse<ClientEntity> response = request.execute();
@@ -410,67 +387,88 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ClientComplexValue complex = entity.getProperty("PropertyCompCompNav").getComplexValue()
.get("PropertyCompNav").getComplexValue();
assertNotNull(complex);
- final ClientProperty property = complex.get("PropertyInt16");
+ final ClientProperty property = complex.get(PROPERTY_INT16);
assertNotNull(property);
assertNull(property.getPrimitiveValue());
}
@Test
public void createEntity() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyInt64",
+ ClientEntity newEntity = getFactory().newEntity(ET_ALL_PRIM);
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64((long) 42)));
final ODataClient client = getClient();
newEntity.addLink(getFactory().newEntityNavigationLink(NAV_PROPERTY_ET_TWO_PRIM_ONE,
client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESTwoPrim")
+ .appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32766)
.build()));
final ODataEntityCreateRequest<ClientEntity> createRequest = client.getCUDRequestFactory().getEntityCreateRequest(
- client.newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESAllPrim").build(),
+ client.newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build(),
newEntity);
assertNotNull(createRequest);
final ODataEntityCreateResponse<ClientEntity> createResponse = createRequest.execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), createResponse.getStatusCode());
- assertEquals(SERVICE_URI + "ESAllPrim(1)", createResponse.getHeader(HttpHeader.LOCATION).iterator().next());
+ assertEquals(SERVICE_URI + ES_ALL_PRIM + "(1)", createResponse.getHeader(HttpHeader.LOCATION).iterator().next());
final ClientEntity createdEntity = createResponse.getBody();
assertNotNull(createdEntity);
- final ClientProperty property1 = createdEntity.getProperty("PropertyInt64");
+ final ClientProperty property1 = createdEntity.getProperty(PROPERTY_INT64);
assertNotNull(property1);
- if(isJson()) {
- assertEquals(42, property1.getPrimitiveValue().toValue());
- } else {
- assertEquals((long)42, property1.getPrimitiveValue().toValue());
- }
- final ClientProperty property2 = createdEntity.getProperty("PropertyDecimal");
+ assertShortOrInt(42, property1.getPrimitiveValue().toValue());
+ final ClientProperty property2 = createdEntity.getProperty(PROPERTY_DECIMAL);
assertNotNull(property2);
assertNull(property2.getPrimitiveValue());
}
@Test
public void createEntityMinimalResponse() throws Exception {
- ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETTwoPrim"));
- newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETTwoPrim"));
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("new")));
ODataEntityCreateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESTwoPrim").build(),
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).build(),
newEntity);
request.setPrefer(getClient().newPreferences().returnMinimal());
final ODataEntityCreateResponse<ClientEntity> response = request.execute();
assertEquals(HttpStatusCode.NO_CONTENT.getStatusCode(), response.getStatusCode());
assertEquals("return=minimal", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
- final String location = SERVICE_URI + "ESTwoPrim(1)";
+ final String location = SERVICE_URI + ES_TWO_PRIM + "(1)";
assertEquals(location, response.getHeader(HttpHeader.LOCATION).iterator().next());
assertEquals(location, response.getHeader(HttpHeader.ODATA_ENTITY_ID).iterator().next());
}
@Test
+ public void createEntityWithEnumAndTypeDefinition() throws Exception {
+ ClientEntity newEntity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETMixEnumDefCollComp"));
+ newEntity.getProperties().add(getFactory().newEnumProperty("PropertyEnumString",
+ getFactory().newEnumValue(null, "String2")));
+ newEntity.getProperties().add(getFactory().newPrimitiveProperty("PropertyDefString",
+ getFactory().newPrimitiveValueBuilder().buildString("Test String")));
+ final ODataEntityCreateRequest<ClientEntity> request = getClient().getCUDRequestFactory().getEntityCreateRequest(
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESMixEnumDefCollComp").build(),
+ newEntity);
+ final ODataEntityCreateResponse<ClientEntity> response = request.execute();
+ final ClientEntity createdEntity = response.getBody();
+ assertNotNull(createdEntity);
+ ClientProperty property = createdEntity.getProperty("PropertyEnumString");
+ assertNotNull(property);
+ // TODO: Improve client value types.
+ assertEquals("String2", isJson() ? property.getPrimitiveValue().toValue() : property.getEnumValue().getValue());
+ property = createdEntity.getProperty("PropertyDefString");
+ assertNotNull(property);
+ // TODO: Improve client value types.
+ assertEquals("Test String", isJson() ?
+ property.getPrimitiveValue().toValue() :
+ property.getEnumValue().getValue());
+ }
+
+ @Test
public void readEntityWithExpandedNavigationProperty() {
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build();
@@ -488,7 +486,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity();
assertNotNull(inlineEntity);
- assertShortOrInt(2, inlineEntity.getEntity().getProperty("PropertyInt16").getPrimitiveValue().toValue());
+ assertShortOrInt(2, inlineEntity.getEntity().getProperty(PROPERTY_INT16).getPrimitiveValue().toValue());
// NavPropertyETKeyNavMany
assertNotNull(response.getBody().getNavigationLink("NavPropertyETKeyNavMany"));
@@ -500,42 +498,42 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, inlineEntitySet.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
assertShortOrInt(2, inlineEntitySet.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
}
@Test
public void updateCollectionOfComplexCollection() {
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETKeyNav"));
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
entity.getProperties().add(
getFactory().newCollectionProperty("CollPropertyComp",
getFactory().newCollectionValue("CTPrimComp")
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 42)))
- .add(getFactory().newComplexProperty("PropertyComp",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP,
getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("42"))))))
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 43)))
- .add(getFactory().newComplexProperty("PropertyComp",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP,
getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("43"))))))));
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(3)
.build();
@@ -553,26 +551,18 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.iterator();
ClientComplexValue complexProperty = collectionIterator.next().asComplex();
- if (isJson()) {
- assertEquals(42, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)42, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty.get("PropertyComp"));
+ assertShortOrInt(42, complexProperty.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty.get(PROPERTY_COMP));
- ClientComplexValue innerComplexProperty = complexProperty.get("PropertyComp").getComplexValue();
- assertEquals("42", innerComplexProperty.get("PropertyString").getPrimitiveValue().toValue());
+ ClientComplexValue innerComplexProperty = complexProperty.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("42", innerComplexProperty.get(PROPERTY_STRING).getPrimitiveValue().toValue());
complexProperty = collectionIterator.next().asComplex();
- if (isJson()) {
- assertEquals(43, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)43, complexProperty.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty.get("PropertyComp"));
+ assertShortOrInt(43, complexProperty.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty.get(PROPERTY_COMP));
- innerComplexProperty = complexProperty.get("PropertyComp").getComplexValue();
- assertEquals("43", innerComplexProperty.get("PropertyString").getPrimitiveValue().toValue());
+ innerComplexProperty = complexProperty.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("43", innerComplexProperty.get(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
@@ -581,30 +571,30 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
* Create a new entity which contains a collection of complex collections
* Check if all not filled fields are created by the server
*/
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
entity.getProperties().add(
- getFactory().newPrimitiveProperty("PropertyString",
+ getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Complex collection test")));
entity.getProperties().add(getFactory().newComplexProperty("PropertyCompTwoPrim",
getFactory().newComplexValue("CTTwoPrim")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("1")))));
entity.getProperties().add(getFactory().newCollectionProperty("CollPropertyComp",
getFactory().newCollectionValue("CTPrimComp")
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 1)))
- .add(getFactory().newComplexProperty("PropertyComp", getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue("CTAllPrim")
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("1"))))))
.add(getFactory().newComplexValue("CTPrimComp")
- .add(getFactory().newComplexProperty("PropertyComp", getFactory().newComplexValue("CTAllPrim")
- .add(getFactory().newPrimitiveProperty("PropertyString",
+ .add(getFactory().newComplexProperty(PROPERTY_COMP, getFactory().newComplexValue("CTAllPrim")
+ .add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("2")))
- .add(getFactory().newPrimitiveProperty("PropertyInt16",
+ .add(getFactory().newPrimitiveProperty(PROPERTY_INT16,
getFactory().newPrimitiveValueBuilder().buildInt16((short) 2)))
.add(getFactory().newPrimitiveProperty("PropertySingle",
getFactory().newPrimitiveValueBuilder().buildSingle(2.0f))))))));
@@ -616,13 +606,13 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
private static final long serialVersionUID = 1L;
{
- put("PropertyInt16", 1);
- put("PropertyString", "1");
+ put(PROPERTY_INT16, 1);
+ put(PROPERTY_STRING, "1");
}
}).build()));
final ODataEntityCreateResponse<ClientEntity> response = getClient().getCUDRequestFactory().getEntityCreateRequest(
- getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESKeyNav").build(), entity)
+ getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV).build(), entity)
.execute();
// Check if not declared fields are also available
@@ -632,55 +622,46 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(2, newEntity.getProperty("CollPropertyComp").getCollectionValue().size());
final Iterator<ClientValue> iter = newEntity.getProperty("CollPropertyComp").getCollectionValue().iterator();
final ClientComplexValue complexProperty1 = iter.next().asComplex();
- if (isJson()) {
- assertEquals(1, complexProperty1.get("PropertyInt16").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)1, complexProperty1.get("PropertyInt16").getPrimitiveValue().toValue());
- }
- assertNotNull(complexProperty1.get("PropertyComp"));
- final ClientComplexValue innerComplexProperty1 = complexProperty1.get("PropertyComp").getComplexValue();
- assertEquals("1", innerComplexProperty1.get("PropertyString").getPrimitiveValue().toValue());
+ assertShortOrInt(1, complexProperty1.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertNotNull(complexProperty1.get(PROPERTY_COMP));
+ final ClientComplexValue innerComplexProperty1 = complexProperty1.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("1", innerComplexProperty1.get(PROPERTY_STRING).getPrimitiveValue().toValue());
assertTrue(innerComplexProperty1.get("PropertyBinary").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyBoolean").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyByte").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDate").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDateTimeOffset").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_DECIMAL).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDouble").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyDuration").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyGuid").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_INT16).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyInt32").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty1.get(PROPERTY_INT64).hasNullValue());
assertTrue(innerComplexProperty1.get("PropertySByte").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertyTimeOfDay").hasNullValue());
- assertTrue(innerComplexProperty1.get("PropertyInt16").hasNullValue());
assertTrue(innerComplexProperty1.get("PropertySingle").hasNullValue());
final ClientComplexValue complexProperty2 = iter.next().asComplex();
- assertTrue(complexProperty2.get("PropertyInt16").hasNullValue());
- assertNotNull(complexProperty2.get("PropertyComp"));
- final ClientComplexValue innerComplexProperty2 = complexProperty2.get("PropertyComp").getComplexValue();
- assertEquals("2", innerComplexProperty2.get("PropertyString").getPrimitiveValue().toValue());
- if(isJson()) {
- assertEquals(2, innerComplexProperty2.get("PropertyInt16").getPrimitiveValue().toValue());
- assertEquals(Double.valueOf(2), innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
- } else {
- assertEquals((short)2, innerComplexProperty2.get("PropertyInt16").getPrimitiveValue().toValue());
- assertEquals(Float.valueOf(2), innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
- }
-
+ assertTrue(complexProperty2.get(PROPERTY_INT16).hasNullValue());
+ assertNotNull(complexProperty2.get(PROPERTY_COMP));
+ final ClientComplexValue innerComplexProperty2 = complexProperty2.get(PROPERTY_COMP).getComplexValue();
+ assertEquals("2", innerComplexProperty2.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertShortOrInt(2, innerComplexProperty2.get(PROPERTY_INT16).getPrimitiveValue().toValue());
+ assertEquals(isJson() ? 2.0 : (Number) 2.0F,
+ innerComplexProperty2.get("PropertySingle").getPrimitiveValue().toValue());
+
assertTrue(innerComplexProperty2.get("PropertyBinary").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyBoolean").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyByte").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDate").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDateTimeOffset").hasNullValue());
- assertTrue(innerComplexProperty2.get("PropertyDecimal").hasNullValue());
+ assertTrue(innerComplexProperty2.get(PROPERTY_DECIMAL).hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDouble").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyDuration").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyGuid").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyInt32").hasNullValue());
- assertTrue(innerComplexProperty2.get("PropertyInt64").hasNullValue());
+ assertTrue(innerComplexProperty2.get(PROPERTY_INT64).hasNullValue());
assertTrue(innerComplexProperty2.get("PropertySByte").hasNullValue());
assertTrue(innerComplexProperty2.get("PropertyTimeOfDay").hasNullValue());
@@ -692,9 +673,9 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
public void complexPropertyWithNotNullablePrimitiveValue() {
// PropertyComp is null, but the primitive values in PropertyComp must not be null
final ClientEntity entity = getFactory().newEntity(
- new FullQualifiedName("olingo.odata.test1", "ETMixPrimCollComp"));
+ new FullQualifiedName(SERVICE_NAMESPACE, "ETMixPrimCollComp"));
final URI targetURI = getEdmEnabledClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESMixPrimCollComp").build();
+ .appendEntitySetSegment(ES_MIX_PRIM_COLL_COMP).build();
try {
getEdmEnabledClient().getCUDRequestFactory().getEntityCreateRequest(targetURI, entity).execute();
@@ -706,43 +687,43 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void upsert() throws EdmPrimitiveTypeException {
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETTwoPrim"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(new FullQualifiedName(SERVICE_NAMESPACE, "ETTwoPrim"));
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString("Test")));
- final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment("ESTwoPrim").appendKeySegment(33)
+ final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM).appendKeySegment(33)
.build();
final ODataEntityUpdateResponse<ClientEntity> updateResponse =
getEdmEnabledClient().getCUDRequestFactory().getEntityUpdateRequest(uri, UpdateType.PATCH, entity).execute();
assertEquals(HttpStatusCode.CREATED.getStatusCode(), updateResponse.getStatusCode());
- assertEquals("Test", updateResponse.getBody().getProperty("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Test", updateResponse.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
final String cookie = updateResponse.getHeader(HttpHeader.SET_COOKIE).iterator().next();
- final Short key = updateResponse.getBody().getProperty("PropertyInt16")
+ final Short key = updateResponse.getBody().getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toCastValue(Short.class);
final ODataEntityRequest<ClientEntity> entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESTwoPrim")
+ .appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(key)
.build());
entityRequest.addCustomHeader(HttpHeader.COOKIE, cookie);
final ODataRetrieveResponse<ClientEntity> responseEntityRequest = entityRequest.execute();
assertEquals(HttpStatusCode.OK.getStatusCode(), responseEntityRequest.getStatusCode());
- assertEquals("Test", responseEntityRequest.getBody().getProperty("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Test", responseEntityRequest.getBody().getProperty(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
public void updatePropertyWithNull() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESAllPrim")
+ .appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(32767)
.build();
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETAllPrim"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString(null)));
ODataEntityUpdateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory()
@@ -752,19 +733,19 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
assertEquals("return=representation", response.getHeader(HttpHeader.PREFERENCE_APPLIED).iterator().next());
- assertTrue(response.getBody().getProperty("PropertyString").hasNullValue());
- assertShortOrInt(34, response.getBody().getProperty("PropertyDecimal").getPrimitiveValue().toValue());
+ assertTrue(response.getBody().getProperty(PROPERTY_STRING).hasNullValue());
+ assertShortOrInt(34, response.getBody().getProperty(PROPERTY_DECIMAL).getPrimitiveValue().toValue());
}
@Test(expected = ODataClientErrorException.class)
public void updatePropertyWithNullNotAllowed() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(32767)
.build();
- final ClientEntity entity = getFactory().newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
- entity.getProperties().add(getFactory().newPrimitiveProperty("PropertyString",
+ final ClientEntity entity = getFactory().newEntity(ET_KEY_NAV);
+ entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_STRING,
getFactory().newPrimitiveValueBuilder().buildString(null)));
getEdmEnabledClient().getCUDRequestFactory().getEntityUpdateRequest(targetURI, UpdateType.PATCH, entity).execute();
@@ -773,22 +754,22 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateMerge() {
final URI targetURI = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.build();
final ClientObjectFactory factory = getFactory();
- final ClientEntity entity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.addLink(factory.newEntityNavigationLink("NavPropertyETKeyNavOne", targetURI));
entity.addLink(factory.newEntitySetNavigationLink("NavPropertyETKeyNavMany", getClient().newURIBuilder
(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav").appendKeySegment(3).build()));
+ .appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build()));
entity.getProperties().add(factory.newCollectionProperty("CollPropertyString",
factory.newCollectionValue("Edm.String").add(
factory.newPrimitiveValueBuilder().buildString("Single entry!"))));
- entity.getProperties().add(factory.newComplexProperty("PropertyCompAllPrim",
+ entity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
factory.newComplexValue("CTAllPrim")
- .add(factory.newPrimitiveProperty("PropertyString",
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("Changed")))));
final ODataEntityUpdateResponse<ClientEntity> response = getEdmEnabledClient().getCUDRequestFactory()
@@ -801,7 +782,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataEntityRequest<ClientEntity> entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(
getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build());
@@ -812,7 +793,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, entityResponse.getBody().getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity()
.getEntity()
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -827,7 +808,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -836,7 +817,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -845,7 +826,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(2)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -858,40 +839,40 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertFalse(collectionIterator.hasNext());
final ClientComplexValue complexValue = entityResponse.getBody()
- .getProperty("PropertyCompAllPrim")
+ .getProperty(PROPERTY_COMP_ALL_PRIM)
.getComplexValue();
- assertEquals("Changed", complexValue.get("PropertyString").getPrimitiveValue().toValue());
+ assertEquals("Changed", complexValue.get(PROPERTY_STRING).getPrimitiveValue().toValue());
}
@Test
public void updateReplace() {
final ODataClient client = getClient();
final URI targetURI = client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.build();
final ClientObjectFactory factory = getFactory();
- final ClientEntity entity = factory.newEntity(new FullQualifiedName("olingo.odata.test1", "ETKeyNav"));
+ final ClientEntity entity = factory.newEntity(ET_KEY_NAV);
entity.addLink(factory.newEntityNavigationLink("NavPropertyETKeyNavOne", targetURI));
entity.addLink(factory.newEntitySetNavigationLink("NavPropertyETKeyNavMany", client.newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment("ESKeyNav").appendKeySegment(3).build()));
- entity.getProperties().add(factory.newPrimitiveProperty("PropertyString", factory
+ .appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(3).build()));
+ entity.getProperties().add(factory.newPrimitiveProperty(PROPERTY_STRING, factory
.newPrimitiveValueBuilder()
.buildString("Must not be null")));
entity.getProperties().add(factory.newComplexProperty("PropertyCompTwoPrim", factory.newComplexValue
("CTTwoPrim")
- .add(factory.newPrimitiveProperty("PropertyString", factory.newPrimitiveValueBuilder()
+ .add(factory.newPrimitiveProperty(PROPERTY_STRING, factory.newPrimitiveValueBuilder()
.buildString("Must not be null")))
- .add(factory.newPrimitiveProperty("PropertyInt16",
+ .add(factory.newPrimitiveProperty(PROPERTY_INT16,
factory.newPrimitiveValueBuilder().buildInt16((short) 42)))));
entity.getProperties().add(factory.newCollectionProperty("CollPropertyString",
factory.newCollectionValue("Edm.String")
.add(factory.newPrimitiveValueBuilder().buildString("Single entry!"))));
- entity.getProperties().add(factory.newComplexProperty("PropertyCompAllPrim",
+ entity.getProperties().add(factory.newComplexProperty(PROPERTY_COMP_ALL_PRIM,
factory.newComplexValue("CTAllPrim").add(
- factory.newPrimitiveProperty("PropertyString",
+ factory.newPrimitiveProperty(PROPERTY_STRING,
factory.newPrimitiveValueBuilder().buildString("Changed")))));
ODataEntityUpdateRequest<ClientEntity> request = getEdmEnabledClient().getCUDRequestFactory()
@@ -905,7 +886,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataEntityRequest<ClientEntity> entityRequest = getEdmEnabledClient().getRetrieveRequestFactory()
.getEntityRequest(
getEdmEnabledClient().newURIBuilder()
- .appendEntitySetSegment("ESKeyNav")
+ .appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.expand("NavPropertyETKeyNavOne", "NavPropertyETKeyNavMany")
.build());
@@ -916,7 +897,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertShortOrInt(1, entityResponse.getBody().getNavigationLink("NavPropertyETKeyNavOne")
.asInlineEntity()
.getEntity()
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -931,7 +912,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(0)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -940,7 +921,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(1)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -949,7 +930,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
.getEntitySet()
.getEntities()
.get(2)
- .getProperty("PropertyInt16")
+ .getProperty(PROPERTY_INT16)
.getPrimitiveValue()
.toValue());
@@ -962,30 +943,32 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
assertFalse(collectionIterator.hasNext());
final ClientComplexValue propCompAllPrim = entityResponse.getBody()
- .getProperty("PropertyCompAllPrim")
+ .getProperty(PROPERTY_COMP_ALL_PRIM)
.getComplexValue();
- assertEquals("Changed", propCompAllPrim.get("PropertyString").getPrimitiveValue().toValue());
- assertTrue(propCompAllPrim.get("PropertyInt16").hasNullValue());
+ assertEquals("Changed", propCompAllPrim.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertTrue(propCompAllPrim.get(PROPERTY_INT16).hasNullValue());
assertTrue(propCompAllPrim.get("PropertyDate").hasNullValue());
final ClientComplexValue propCompTwoPrim = entityResponse.getBody()
.getProperty("PropertyCompTwoPrim")
.getComplexValue();
- assertEquals("Must not be null", propCompTwoPrim.get("PropertyString").getPrimitiveValue().toValue());
- assertShortOrInt(42, propCompTwoPrim.get("PropertyInt16").getPrimitiveValue().toValue());
+ assertEquals("Must not be null", propCompTwoPrim.get(PROPERTY_STRING).getPrimitiveValue().toValue());
+ assertShortOrInt(42, propCompTwoPrim.get(PROPERTY_INT16).getPrimitiveValue().toValue());
assertNotNull(entityResponse.getBody().getProperty("PropertyCompNav").getComplexValue());
assertTrue(entityResponse.getBody()
.getProperty("PropertyCompNav")
.getComplexValue()
- .get("PropertyInt16")
+ .get(PROPERTY_INT16)
.hasNullValue());
}
@Test
public void createEntityWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build();
final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767).build();
@@ -1010,6 +993,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void createEntityWithIEEE754CompatibleParameterNull() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM).build();
final URI linkURI = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_TWO_PRIM)
.appendKeySegment(32767).build();
@@ -1033,9 +1018,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+ .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(Long.MAX_VALUE)));
@@ -1064,9 +1051,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameterNull() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
- .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+ .appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildInt64(null)));
@@ -1093,9 +1082,11 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEntityWithIEEE754CompatibleParameterWithNullString() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_ALL_PRIM).appendKeySegment(0).build();
-
+
final ClientEntity entity = getFactory().newEntity(ET_ALL_PRIM);
entity.getProperties().add(getFactory().newPrimitiveProperty(PROPERTY_INT64,
getFactory().newPrimitiveValueBuilder().buildString("null")));
@@ -1117,10 +1108,12 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateEdmInt64PropertyWithIEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(0)
.appendPropertySegment(PROPERTY_INT64).build();
-
+
final ODataPropertyUpdateRequest requestUpdate =
getEdmEnabledClient().getCUDRequestFactory().getPropertyPrimitiveValueUpdateRequest(uri,
getFactory().newPrimitiveProperty(PROPERTY_INT64,
@@ -1142,10 +1135,12 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updateComplexPropertyWithIEEE754CompatibleParamter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM).build();
-
+
final ODataPropertyUpdateRequest requestUpdate = getEdmEnabledClient().getCUDRequestFactory()
.getPropertyComplexValueUpdateRequest(uri, UpdateType.PATCH,
getFactory().newComplexProperty(PROPERTY_COMP_ALL_PRIM,
@@ -1177,6 +1172,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void updatePropertyEdmDecimalWithIEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.appendKeySegment(0)
.appendPropertySegment(PROPERTY_DECIMAL).build();
@@ -1202,6 +1199,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESAllPrimCollectionWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_ALL_PRIM)
.orderBy(PROPERTY_INT16)
.build();
@@ -1235,6 +1234,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESKeyNavCheckComplexPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI)
.appendEntitySetSegment(ES_KEY_NAV).appendKeySegment(1).build();
@@ -1262,6 +1263,8 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
@Test
public void readESKEyNavComplexPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendNavigationSegment(PROPERTY_COMP_ALL_PRIM)
@@ -1286,8 +1289,10 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
}
@Test
- @Ignore
+ @Ignore("The client does not recognize the IEEE754Compatible content-type parameter.")
public void readEdmInt64PropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM)
@@ -1300,13 +1305,15 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataRetrieveResponse<ClientProperty> response = request.execute();
saveCookieHeader(response);
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
-
+
assertEquals(Long.MAX_VALUE, response.getBody().getPrimitiveValue().toValue());
}
@Test
- @Ignore
+ @Ignore("The client does not recognize the IEEE754Compatible content-type parameter.")
public void readEdmDecimalPropertyWithIEEE754CompatibleParameter() {
+ assumeTrue("There is no IEEE754Compatible content-type parameter in XML.", isJson());
+
final URI uri = getClient().newURIBuilder(SERVICE_URI).appendEntitySetSegment(ES_KEY_NAV)
.appendKeySegment(1)
.appendPropertySegment(PROPERTY_COMP_ALL_PRIM)
@@ -1319,7 +1326,7 @@ public class BasicITCase extends AbstractParamTecSvcITCase {
final ODataRetrieveResponse<ClientProperty> response = request.execute();
saveCookieHeader(response);
assertEquals(HttpStatusCode.OK.getStatusCode(), response.getStatusCode());
-
+
assertEquals(BigDecimal.valueOf(34), response.getBody().getPrimitiveValue().toValue());
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
index ce31ec2..273779c 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/client/BatchClientITCase.java
@@ -59,10 +59,9 @@ import org.junit.Test;
public class BatchClientITCase extends AbstractParamTecSvcITCase {
- private static final String SERVICE_NAMESPACE = "olingo.odata.test1";
private static final String ES_NOT_AVAILABLE_NAME = "ESNotAvailable";
- private static final FullQualifiedName ES_NOT_AVAILABLE = new FullQualifiedName(SERVICE_NAMESPACE,
- ES_NOT_AVAILABLE_NAME);
+ private static final FullQualifiedName ES_NOT_AVAILABLE =
+ new FullQualifiedName(SERVICE_NAMESPACE, ES_NOT_AVAILABLE_NAME);
private static final String PROPERTY_STRING = "PropertyString";
@Before
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
index 5a20f29..170fec4 100644
--- a/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/tecsvc/http/PingITCase.java
@@ -30,9 +30,13 @@ import org.apache.olingo.commons.api.http.HttpStatusCode;
import org.apache.olingo.fit.AbstractBaseTestITCase;
import org.apache.olingo.fit.tecsvc.TecSvcConst;
import org.junit.Test;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class PingITCase extends AbstractBaseTestITCase {
+ private static final Logger LOG = LoggerFactory.getLogger(PingITCase.class);
+
private static final String SERVICE_URI = TecSvcConst.BASE_URI + "/";
private static final String REDIRECT_URI = TecSvcConst.BASE_URI;
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
index 2cc1d39..6996ff2 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
@@ -21,10 +21,9 @@ package org.apache.olingo.commons.core.edm;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
-import java.util.HashSet;
import java.util.LinkedHashMap;
import java.util.List;
-import java.util.Set;
+import java.util.Map;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEnumType;
@@ -42,21 +41,12 @@ import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
- private static final Set<EdmPrimitiveTypeKind> VALID_UNDERLYING_TYPES = new HashSet<EdmPrimitiveTypeKind>();
- static {
- VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Byte);
- VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.SByte);
- VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int16);
- VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int32);
- VALID_UNDERLYING_TYPES.add(EdmPrimitiveTypeKind.Int64);
- }
-
private final EdmPrimitiveType underlyingType;
private final CsdlEnumType enumType;
private final String uriPrefix;
private final String uriSuffix;
private List<String> memberNames;
- private LinkedHashMap<String, EdmMember> membersMap;
+ private Map<String, EdmMember> membersMap;
public EdmEnumTypeImpl(final Edm edm, final FullQualifiedName enumName, final CsdlEnumType enumType) {
super(edm, enumName, EdmTypeKind.ENUM, enumType);
@@ -64,12 +54,16 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
if (enumType.getUnderlyingType() == null) {
underlyingType = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32);
} else {
- EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
-
- if (!VALID_UNDERLYING_TYPES.contains(underlyingTypeKind)) {
+ final EdmPrimitiveTypeKind underlyingTypeKind = EdmPrimitiveTypeKind.valueOfFQN(enumType.getUnderlyingType());
+ if (underlyingTypeKind == EdmPrimitiveTypeKind.Byte
+ || underlyingTypeKind == EdmPrimitiveTypeKind.SByte
+ || underlyingTypeKind == EdmPrimitiveTypeKind.Int16
+ || underlyingTypeKind == EdmPrimitiveTypeKind.Int32
+ || underlyingTypeKind == EdmPrimitiveTypeKind.Int64) {
+ underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
+ } else {
throw new EdmException("Not allowed as underlying type: " + underlyingTypeKind);
}
- underlyingType = EdmPrimitiveTypeFactory.getInstance(underlyingTypeKind);
}
this.enumType = enumType;
@@ -99,7 +93,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
}
private void createEdmMembers() {
- final LinkedHashMap<String, EdmMember> membersMapLocal = new LinkedHashMap<String, EdmMember>();
+ final Map<String, EdmMember> membersMapLocal = new LinkedHashMap<String, EdmMember>();
final List<String> memberNamesLocal = new ArrayList<String>();
if (enumType.getMembers() != null) {
for (final CsdlEnumMember member : enumType.getMembers()) {
@@ -154,7 +148,7 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
- throws EdmPrimitiveTypeException {
+ throws EdmPrimitiveTypeException {
if (value == null) {
if (isNullable != null && !isNullable) {
@@ -173,10 +167,9 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
}
}
- private String constructEnumValue(final long value)
- throws EdmPrimitiveTypeException {
+ private String constructEnumValue(final long value) throws EdmPrimitiveTypeException {
long remaining = value;
- final StringBuilder result = new StringBuilder();
+ StringBuilder result = new StringBuilder();
final boolean flags = isFlags();
for (final EdmMember member : getMembers()) {
@@ -228,16 +221,13 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
@Override
public String toUriLiteral(final String literal) {
- return literal == null ? null
- : uriPrefix.isEmpty() && uriSuffix.isEmpty() ? literal : uriPrefix + literal + uriSuffix;
+ return literal == null ? null : uriPrefix + literal + uriSuffix;
}
@Override
public String fromUriLiteral(final String literal) throws EdmPrimitiveTypeException {
if (literal == null) {
return null;
- } else if (uriPrefix.isEmpty() && uriSuffix.isEmpty()) {
- return literal;
} else if (literal.length() >= uriPrefix.length() + uriSuffix.length()
&& literal.startsWith(uriPrefix) && literal.endsWith(uriSuffix)) {
return literal.substring(uriPrefix.length(), literal.length() - uriSuffix.length());
@@ -265,29 +255,17 @@ public class EdmEnumTypeImpl extends EdmTypeImpl implements EdmEnumType {
public FullQualifiedName getAnnotationsTargetFQN() {
return getFullQualifiedName();
}
-
+
@Override
public int hashCode() {
- return this.getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
+ return getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
}
-
+
@Override
- public boolean equals(Object obj){
- if(obj == null){
- return false;
- }
-
- if(obj == this){
- return true;
- }
-
- if(obj instanceof EdmEnumType){
- EdmEnumType other = (EdmEnumType) obj;
- if(this.getFullQualifiedName().equals(other.getFullQualifiedName())){
- return true;
- }
- }
-
- return false;
+ public boolean equals(final Object obj) {
+ return obj != null
+ && (obj == this
+ || obj instanceof EdmEnumType
+ && getFullQualifiedName().equals(((EdmEnumType) obj).getFullQualifiedName()));
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
index 9c777d9..efd1f7c 100644
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
@@ -30,41 +30,24 @@ import org.apache.olingo.commons.api.edm.geo.SRID;
import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDefinition {
+public class EdmTypeDefinitionImpl extends EdmTypeImpl implements EdmTypeDefinition {
private CsdlTypeDefinition typeDefinition;
- private FullQualifiedName typeDefinitionName;
private EdmPrimitiveType edmPrimitiveTypeInstance;
public EdmTypeDefinitionImpl(final Edm edm, final FullQualifiedName typeDefinitionName,
final CsdlTypeDefinition typeDefinition) {
- super(edm, typeDefinitionName.getName(), typeDefinition);
- this.typeDefinitionName = typeDefinitionName;
+ super(edm, typeDefinitionName, EdmTypeKind.DEFINITION, typeDefinition);
this.typeDefinition = typeDefinition;
}
@Override
- public FullQualifiedName getFullQualifiedName() {
- return typeDefinitionName;
- }
-
- @Override
- public String getNamespace() {
- return typeDefinitionName.getNamespace();
- }
-
- @Override
- public EdmTypeKind getKind() {
- return EdmTypeKind.DEFINITION;
- }
-
- @Override
public EdmPrimitiveType getUnderlyingType() {
if (edmPrimitiveTypeInstance == null) {
try {
if (typeDefinition.getUnderlyingType() == null) {
throw new EdmException("Underlying Type for type definition: "
- + typeDefinitionName.getFullQualifiedNameAsString() + " must not be null.");
+ + typeName.getFullQualifiedNameAsString() + " must not be null.");
}
edmPrimitiveTypeInstance = EdmPrimitiveTypeFactory.getInstance(
EdmPrimitiveTypeKind.valueOfFQN(typeDefinition.getUnderlyingType()));
@@ -102,7 +85,7 @@ public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDe
@Override
public boolean isCompatible(final EdmPrimitiveType primitiveType) {
- return getUnderlyingType().isCompatible(primitiveType);
+ return this == primitiveType || getUnderlyingType().isCompatible(primitiveType);
}
@Override
@@ -112,27 +95,34 @@ public class EdmTypeDefinitionImpl extends AbstractEdmNamed implements EdmTypeDe
@Override
public boolean validate(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode) {
-
- return getUnderlyingType().validate(value, isNullable, maxLength, precision, scale, isUnicode);
+ final Integer precision, final Integer scale, final Boolean isUnicode) {
+ return getUnderlyingType().validate(value, isNullable,
+ maxLength == null ? getMaxLength() : maxLength,
+ precision == null ? getPrecision() : precision,
+ scale == null ? getScale() : scale,
+ isUnicode == null ? isUnicode() : isUnicode);
}
@Override
public <T> T valueOfString(final String value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode, final Class<T> returnType) throws EdmPrimitiveTypeException {
-
- return getUnderlyingType().
- valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ final Integer precision, final Integer scale, final Boolean isUnicode, final Class<T> returnType)
+ throws EdmPrimitiveTypeException {
+ return getUnderlyingType().valueOfString(value, isNullable,
+ maxLength == null ? getMaxLength() : maxLength,
+ precision == null ? getPrecision() : precision,
+ scale == null ? getScale() : scale,
+ isUnicode == null ? isUnicode() : isUnicode,
+ returnType);
}
@Override
public String valueToString(final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale,
- final Boolean isUnicode) throws EdmPrimitiveTypeException {
-
- return getUnderlyingType().valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ final Integer precision, final Integer scale, final Boolean isUnicode) throws EdmPrimitiveTypeException {
+ return getUnderlyingType().valueToString(value, isNullable,
+ maxLength == null ? getMaxLength() : maxLength,
+ precision == null ? getPrecision() : precision,
+ scale == null ? getScale() : scale,
+ isUnicode == null ? isUnicode() : isUnicode);
}
@Override
[05/11] olingo-odata4 git commit: [OLINGO-794] Removed outdated
'inlinecount'
Posted by ch...@apache.org.
[OLINGO-794] Removed outdated 'inlinecount'
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/9933cb0b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/9933cb0b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/9933cb0b
Branch: refs/heads/olingo786
Commit: 9933cb0bdc0828735ea746b26d5fc5d205da2198
Parents: f221962
Author: mibo <mi...@apache.org>
Authored: Fri Oct 9 14:30:56 2015 +0200
Committer: mibo <mi...@apache.org>
Committed: Fri Oct 9 14:38:22 2015 +0200
----------------------------------------------------------------------
.../java/org/apache/olingo/fit/AbstractServices.java | 6 +++---
fit/src/main/java/org/apache/olingo/fit/Services.java | 2 +-
.../apache/olingo/fit/base/QueryOptionsTestITCase.java | 2 +-
.../org/apache/olingo/client/api/uri/QueryOption.java | 12 ++----------
.../client/core/domain/AbstractClientEntitySet.java | 2 +-
5 files changed, 8 insertions(+), 16 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9933cb0b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
index 100aff5..fc886ff 100644
--- a/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
+++ b/fit/src/main/java/org/apache/olingo/fit/AbstractServices.java
@@ -936,7 +936,7 @@ public abstract class AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
- @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
+ @QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
@QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken,
@@ -1038,7 +1038,7 @@ public abstract class AbstractServices {
* @param accept Accept header.
* @param name entity set or function name.
* @param format format query option.
- * @param count inlinecount query option.
+ * @param count count query option.
* @param filter filter query option.
* @param orderby orderby query option.
* @param skiptoken skiptoken query option.
@@ -1053,7 +1053,7 @@ public abstract class AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
- @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
+ @QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
@QueryParam("$skiptoken") @DefaultValue(StringUtils.EMPTY) final String skiptoken) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9933cb0b/fit/src/main/java/org/apache/olingo/fit/Services.java
----------------------------------------------------------------------
diff --git a/fit/src/main/java/org/apache/olingo/fit/Services.java b/fit/src/main/java/org/apache/olingo/fit/Services.java
index cb85329..45f11a5 100644
--- a/fit/src/main/java/org/apache/olingo/fit/Services.java
+++ b/fit/src/main/java/org/apache/olingo/fit/Services.java
@@ -383,7 +383,7 @@ public class Services extends AbstractServices {
@QueryParam("$top") @DefaultValue(StringUtils.EMPTY) final String top,
@QueryParam("$skip") @DefaultValue(StringUtils.EMPTY) final String skip,
@QueryParam("$format") @DefaultValue(StringUtils.EMPTY) final String format,
- @QueryParam("$inlinecount") @DefaultValue(StringUtils.EMPTY) final String count,
+ @QueryParam("$count") @DefaultValue(StringUtils.EMPTY) final String count,
@QueryParam("$filter") @DefaultValue(StringUtils.EMPTY) final String filter,
@QueryParam("$search") @DefaultValue(StringUtils.EMPTY) final String search,
@QueryParam("$orderby") @DefaultValue(StringUtils.EMPTY) final String orderby,
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9933cb0b/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
----------------------------------------------------------------------
diff --git a/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java b/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
index cd937ab..0705384 100644
--- a/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
+++ b/fit/src/test/java/org/apache/olingo/fit/base/QueryOptionsTestITCase.java
@@ -185,7 +185,7 @@ public class QueryOptionsTestITCase extends AbstractTestITCase {
}
/**
- * Test <tt>$inlinecount</tt>.
+ * Test <tt>$count</tt>.
*/
@Test
public void count() {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9933cb0b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
----------------------------------------------------------------------
diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
index 06e884e..8d87197 100644
--- a/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
+++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/uri/QueryOption.java
@@ -72,9 +72,8 @@ public enum QueryOption {
*/
SKIP,
/**
- * This query option applies only to the OData 2.0 protocol to the AtomPub protocol. The value of a $skiptoken query
- * option is an opaque token which identifies an index into the collection of entities identified by the URI
- * containing the $skiptoken parameter.
+ * The value of a $skiptoken query option is an opaque token which identifies an index into the collection
+ * of entities identified by the URI containing the $skiptoken parameter.
*/
SKIPTOKEN,
/**
@@ -83,13 +82,6 @@ public enum QueryOption {
*/
FILTER,
/**
- * For a value of "allpages", this option indicates that the response to the request MUST include the count of the
- * number of entities in the EntitySet, identified by the resource path section of the URI after all $filter system
- * query options have been applied. For a value of "none", this option indicates that the response to the request MUST
- * NOT include the count value.
- */
- INLINECOUNT,
- /**
* Search expressions are used within the $search system query option to request entities matching the specified
* expression.
*/
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9933cb0b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
----------------------------------------------------------------------
diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
index b57960a..d59af93 100644
--- a/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
+++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/domain/AbstractClientEntitySet.java
@@ -33,7 +33,7 @@ public abstract class AbstractClientEntitySet extends AbstractClientPayload impl
/**
* Number of ODataEntities contained in this entity set.
* <br/>
- * If <tt>$inlinecount</tt> was requested, this value comes from there.
+ * If <tt>$count</tt> was requested, this value comes from there.
*/
private Integer count;
[06/11] olingo-odata4 git commit: [OLINGO-795] server support for
Enums and Type Definitions
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
index 1feb17e..2e8ea14 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerTest.java
@@ -28,8 +28,10 @@ import java.util.Collections;
import java.util.Date;
import org.apache.commons.io.IOUtils;
+import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
+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.Property;
@@ -81,11 +83,11 @@ import org.xml.sax.SAXException;
public class ODataXmlSerializerTest {
private static final ServiceMetadata metadata = new ServiceMetadataImpl(
- new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("WmetadataETag"));
+ new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("metadataETag"));
private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer();
private static final DifferenceListener DIFFERENCE_LISTENER = new CustomDifferenceListener();
private static final int MAX_ALLOWED_UPDATED_DIFFERENCE = 2000;
- private static final String UPDATED_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+ private static final SimpleDateFormat UPDATED_FORMAT = new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'");
private final DataProvider data = new DataProvider(OData.newInstance(), metadata.getEdm());
private final ODataSerializer serializer = new ODataXmlSerializer();
@@ -115,12 +117,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -182,12 +183,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
"m:context=\"$metadata#ESAllPrim/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -279,7 +279,7 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host:port$metadata#ESCompAllPrim\" "
- + "m:metadata-etag=\"WmetadataETag\">"
+ + "m:metadata-etag=\"metadataETag\">"
+ "<a:id>http://host/svc/ESCompAllPrim</a:id>"
+ "<m:count>4</m:count>"
+ "<a:link rel=\"next\" href=\"/next\"/>"
@@ -304,12 +304,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host/service/$metadata#ESCollAllPrim/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESCollAllPrim(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- "<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ "<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -421,12 +420,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESCompAllPrim/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\" m:etag=\"W/"32767"\">\n" +
+ " m:metadata-etag=\"metadataETag\" m:etag=\"W/"32767"\">\n" +
" <a:id>ESCompAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- "<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ "<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -476,12 +474,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" +
" m:context=\"$metadata#ESMixPrimCollComp/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -537,12 +534,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESMixPrimCollComp/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -562,6 +558,90 @@ public class ODataXmlSerializerTest {
}
@Test
+ public void enumAndTypeDefinition() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
+ Entity entity = new Entity();
+ entity.addProperty(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1));
+ entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6));
+ entity.addProperty(new Property(null, "CollPropertyEnumString", ValueType.COLLECTION_ENUM,
+ Arrays.asList(2, 4, 6)));
+ entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
+ entity.addProperty(new Property(null, "CollPropertyDefString", ValueType.COLLECTION_PRIMITIVE,
+ Arrays.asList("Test1", "Test2")));
+ ComplexValue complexValue = new ComplexValue();
+ complexValue.getValue().add(entity.getProperty("PropertyEnumString"));
+ complexValue.getValue().add(entity.getProperty("CollPropertyEnumString"));
+ complexValue.getValue().add(entity.getProperty("PropertyDefString"));
+ complexValue.getValue().add(entity.getProperty("CollPropertyDefString"));
+ entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, complexValue));
+ entity.addProperty(new Property(null, "CollPropertyCompMixedEnumDef", ValueType.COLLECTION_COMPLEX,
+ Collections.singletonList(complexValue)));
+ final long currentTimeMillis = System.currentTimeMillis();
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
+ .build()).getContent());
+ checkXMLEqual(resultString,
+ "<?xml version='1.0' encoding='UTF-8'?>\n"
+ + "<a:entry xmlns:a=\"" + Constants.NS_ATOM + "\""
+ + " xmlns:m=\"" + Constants.NS_METADATA + "\" xmlns:d=\"" + Constants.NS_DATASERVICES + "\""
+ + " m:context=\"$metadata#ESMixEnumDefCollComp/$entity\" m:metadata-etag=\"metadataETag\">\n"
+ + " <a:title /> <a:summary />\n"
+ + " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>\n"
+ + " <a:author> <a:name /> </a:author>\n"
+ + " <a:category scheme=\"" + Constants.NS_SCHEME + "\"\n"
+ + " term=\"#olingo.odata.test1.ETMixEnumDefCollComp\" />\n"
+ + " <a:content type=\"application/xml\">\n"
+ + " <m:properties>\n"
+ + " <d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " <d:PropertyCompMixedEnumDef m:type=\"#olingo.odata.test1.CTMixEnumDef\">\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " </d:PropertyCompMixedEnumDef>\n"
+ + " <d:CollPropertyCompMixedEnumDef m:type=\"#Collection(olingo.odata.test1.CTMixEnumDef)\">\n"
+ + " <m:element>\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " </m:element>\n"
+ + " </d:CollPropertyCompMixedEnumDef>\n"
+ + " </m:properties>\n"
+ + " </a:content>\n"
+ + "</a:entry>");
+ }
+
+ @Test
public void entityTwoPrimNoMetadata() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
@@ -605,12 +685,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
" m:context=\"$metadata#ESMedia/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -643,14 +722,13 @@ public class ODataXmlSerializerTest {
"<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" m:context=\"$metadata#ESMedia\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESMedia</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -667,8 +745,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -685,8 +762,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(3)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -703,8 +779,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(4)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -740,14 +815,13 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"http://host/svc$metadata#ESAllNullable\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESAllNullable</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESAllNullable(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -775,82 +849,82 @@ public class ODataXmlSerializerTest {
" <d:PropertyTimeOfDay m:null=\"true\" />\n" +
" <d:CollPropertyString m:type=\"#Collection(String)\">\n" +
" <m:element>spiderman@comic.com</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>spidergirl@comic.com</m:element>\n" +
" </d:CollPropertyString>\n" +
" <d:CollPropertyBoolean m:type=\"#Collection(Boolean)\">\n" +
" <m:element>true</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>false</m:element>\n" +
" </d:CollPropertyBoolean>\n" +
" <d:CollPropertyByte m:type=\"#Collection(Byte)\">\n" +
" <m:element>50</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>249</m:element>\n" +
" </d:CollPropertyByte>\n" +
" <d:CollPropertySByte m:type=\"#Collection(SByte)\">\n" +
" <m:element>-120</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>126</m:element>\n" +
" </d:CollPropertySByte>\n" +
" <d:CollPropertyInt16 m:type=\"#Collection(Int16)\">\n" +
" <m:element>1000</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>30112</m:element>\n" +
" </d:CollPropertyInt16>\n" +
" <d:CollPropertyInt32 m:type=\"#Collection(Int32)\">\n" +
" <m:element>23232323</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>10000001</m:element>\n" +
" </d:CollPropertyInt32>\n" +
" <d:CollPropertyInt64 m:type=\"#Collection(Int64)\">\n" +
" <m:element>929292929292</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>444444444444</m:element>\n" +
" </d:CollPropertyInt64>\n" +
" <d:CollPropertySingle m:type=\"#Collection(Single)\">\n" +
" <m:element>1790.0</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>3210.0</m:element>\n" +
" </d:CollPropertySingle>\n" +
" <d:CollPropertyDouble m:type=\"#Collection(Double)\">\n" +
" <m:element>-17900.0</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>3210.0</m:element>\n" +
" </d:CollPropertyDouble>\n" +
" <d:CollPropertyDecimal m:type=\"#Collection(Decimal)\">\n" +
" <m:element>12</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>1234</m:element>\n" +
" </d:CollPropertyDecimal>\n" +
" <d:CollPropertyBinary m:type=\"#Collection(Binary)\">\n" +
" <m:element>q83v</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>VGeJ</m:element>\n" +
" </d:CollPropertyBinary>\n" +
" <d:CollPropertyDate m:type=\"#Collection(Date)\">\n" +
" <m:element>1958-12-03</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>2013-06-25</m:element>\n" +
" </d:CollPropertyDate>\n" +
" <d:CollPropertyDateTimeOffset m:type=\"#Collection(DateTimeOffset)\">\n" +
" <m:element>2015-08-12T03:08:34Z</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>1948-02-17T09:09:09Z</m:element>\n" +
" </d:CollPropertyDateTimeOffset>\n" +
" <d:CollPropertyDuration m:type=\"#Collection(Duration)\">\n" +
" <m:element>PT13S</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>PT1H0S</m:element>\n" +
" </d:CollPropertyDuration>\n" +
" <d:CollPropertyGuid m:type=\"#Collection(Guid)\">\n" +
" <m:element>ffffff67-89ab-cdef-0123-456789aaaaaa</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>cccccc67-89ab-cdef-0123-456789cccccc</m:element>\n" +
" </d:CollPropertyGuid>\n" +
" <d:CollPropertyTimeOfDay m:type=\"#Collection(TimeOfDay)\">\n" +
" <m:element>04:14:13</m:element>\n" +
- " <m:element d:null=\"true\" />\n" +
+ " <m:element m:null=\"true\" />\n" +
" <m:element>00:37:13</m:element>\n" +
" </d:CollPropertyTimeOfDay>\n" +
" </m:properties>\n" +
@@ -884,12 +958,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
" m:context=\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -937,14 +1010,13 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESCompComp(PropertyComp/PropertyComp/PropertyString)\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESCompComp</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- "<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ "<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -965,8 +1037,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- "<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ "<a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1011,14 +1082,13 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" \n" +
" m:context=\"$metadata#ESCompComp(PropertyComp/PropertyComp)\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>http://host/svc/ESCompComp</a:id>\n" +
" <a:entry>\n" +
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1040,8 +1110,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1080,12 +1149,11 @@ public class ODataXmlSerializerTest {
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" m:context=\"$metadata#ESTwoPrim/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1099,8 +1167,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1191,12 +1258,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1210,8 +1276,7 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1278,12 +1343,11 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim(PropertySByte)/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1297,8 +1361,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1332,8 +1396,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1396,12 +1460,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:context=\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1462,12 +1525,11 @@ public class ODataXmlSerializerTest {
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\"\n" +
" m:context=\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1486,8 +1548,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1518,8 +1580,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(0)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1540,9 +1602,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
-
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1568,8 +1629,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1595,8 +1656,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
- " <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
- .format(new Date(currentTimeMillis)) + "</a:updated>" +
+ " <a:updated>" + UPDATED_FORMAT.format(new Date(currentTimeMillis))
+ + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@@ -1660,7 +1721,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESAllPrim(32767)/PropertyString\" "
- + "m:metadata-etag=\"WmetadataETag\">"
+ + "m:metadata-etag=\"metadataETag\">"
+ "First Resource - positive values</m:value>";
Assert.assertEquals(expected, resultString);
}
@@ -1680,7 +1741,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESAllPrim(4242)/PropertyString\" "
- + "m:metadata-etag=\"WmetadataETag\" "
+ + "m:metadata-etag=\"metadataETag\" "
+ "m:null=\"true\"/>";
Assert.assertEquals(expected, response);
}
@@ -1701,7 +1762,7 @@ public class ODataXmlSerializerTest {
String expected = "<?xml version='1.0' encoding='UTF-8'?>"
+ "<m:value xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\" "
+ "m:context=\"$metadata#ESCollAllPrim(1)/CollPropertyString\" "
- + "m:metadata-etag=\"WmetadataETag\" m:type=\"#Collection(String)\">"
+ + "m:metadata-etag=\"metadataETag\" m:type=\"#Collection(String)\">"
+ "<m:element>Employee1@company.example</m:element>"
+ "<m:element>Employee2@company.example</m:element>"
+ "<m:element>Employee3@company.example</m:element>"
@@ -1727,7 +1788,7 @@ public class ODataXmlSerializerTest {
+ "xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:type=\"#olingo.odata.test1.CTTwoPrim\" "
+ "m:context=\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\" "
- + "m:metadata-etag=\"WmetadataETag\">"
+ + "m:metadata-etag=\"metadataETag\">"
+ "<d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>"
+ "<d:PropertyString>TEST A</d:PropertyString>"
+ "</m:value>";
@@ -1751,7 +1812,7 @@ public class ODataXmlSerializerTest {
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "
+ "m:type=\"#Collection(olingo.odata.test1.CTTwoPrim)\"\n" +
" m:context=\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"\n" +
- " m:metadata-etag=\"WmetadataETag\">\n" +
+ " m:metadata-etag=\"metadataETag\">\n" +
" <m:element>\n" +
" <d:PropertyInt16 m:type=\"Int16\">123</d:PropertyInt16>\n" +
" <d:PropertyString>TEST 1</d:PropertyString>\n" +
@@ -1838,31 +1899,28 @@ public class ODataXmlSerializerTest {
private static class CustomDifferenceListener implements DifferenceListener {
-
@Override
public int differenceFound(Difference difference) {
final String xpath = "/updated[1]/text()[1]";
if(difference.getControlNodeDetail().getXpathLocation().endsWith(xpath)) {
String controlValue = difference.getControlNodeDetail().getValue();
String testValue = difference.getTestNodeDetail().getValue();
- // allow a difference from two seconds
- SimpleDateFormat sdf = new SimpleDateFormat(UPDATED_FORMAT);
+ // Allow a difference of up to 2 seconds.
try {
- long controlTime = sdf.parse(controlValue).getTime();
- long testTime = sdf.parse(testValue).getTime();
+ long controlTime = UPDATED_FORMAT.parse(controlValue).getTime();
+ long testTime = UPDATED_FORMAT.parse(testValue).getTime();
long diff = controlTime - testTime;
- if(diff < 0) {
+ if (diff < 0) {
diff = diff * -1;
}
- if(diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
- // allow a difference from 2 seconds
+ if (diff <= MAX_ALLOWED_UPDATED_DIFFERENCE) {
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
} catch (ParseException e) {
throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
}
}
- //Yes it is a difference so throw an exception
+ // Yes it is a difference so throw an exception.
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
[10/11] olingo-odata4 git commit: Merge branch 'master' into olingo786
Posted by ch...@apache.org.
Merge branch 'master' into olingo786
Conflicts:
lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
lib/commons-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/xml/ODataXmlDeserializerTest.java
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/b1d03d6b
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/b1d03d6b
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/b1d03d6b
Branch: refs/heads/olingo786
Commit: b1d03d6ba98677e71a9db13b27f75fab77862058
Parents: 5d66c9c 5d364df
Author: Christian Amend <ch...@sap.com>
Authored: Tue Oct 13 10:35:50 2015 +0200
Committer: Christian Amend <ch...@sap.com>
Committed: Tue Oct 13 10:35:50 2015 +0200
----------------------------------------------------------------------
.../org/apache/olingo/fit/AbstractServices.java | 6 +-
.../java/org/apache/olingo/fit/Services.java | 2 +-
.../olingo/fit/AbstractBaseTestITCase.java | 94 +---
.../olingo/fit/base/QueryOptionsTestITCase.java | 2 +-
.../olingo/fit/tecsvc/client/BasicITCase.java | 443 ++++++++++---------
.../fit/tecsvc/client/BatchClientITCase.java | 5 +-
.../olingo/fit/tecsvc/http/PingITCase.java | 4 +
.../olingo/client/api/uri/QueryOption.java | 12 +-
.../core/domain/AbstractClientEntitySet.java | 2 +-
.../commons/core/edm/EdmEnumTypeImpl.java | 68 +--
.../commons/core/edm/EdmTypeDefinitionImpl.java | 58 +--
.../olingo/commons/core/edm/EdmEnumTest.java | 354 +++++++++++++++
.../commons/core/edm/EdmTypeDefinitionTest.java | 137 ++++++
.../deserializer/xml/ODataXmlDeserializer.java | 41 +-
.../serializer/AbstractODataSerializer.java | 5 +-
.../serializer/json/ODataJsonSerializer.java | 26 +-
.../json/ServiceDocumentJsonSerializer.java | 49 +-
.../core/serializer/xml/ODataXmlSerializer.java | 201 ++++-----
.../xml/ServiceDocumentXmlSerializer.java | 87 ++--
.../core/uri/parser/UriParseTreeVisitor.java | 24 +-
.../uri/parser/UriParserSemanticException.java | 8 +-
.../server-core-exceptions-i18n.properties | 2 +
.../xml/ServiceDocumentXmlSerializerTest.java | 14 +-
.../olingo/server/tecsvc/data/ActionData.java | 10 +-
.../olingo/server/tecsvc/data/DataCreator.java | 6 +-
.../olingo/server/tecsvc/data/DataProvider.java | 41 +-
.../tecsvc/provider/FunctionProvider.java | 12 +-
.../tecsvc/provider/PropertyProvider.java | 4 +-
.../server/tecsvc/provider/SchemaProvider.java | 2 +-
.../tecsvc/provider/TypeDefinitionProvider.java | 6 +-
.../json/ODataJsonDeserializerEntityTest.java | 4 +
.../xml/ODataXmlDeserializerTest.java | 189 ++++----
.../json/ODataJsonSerializerTest.java | 64 ++-
.../serializer/json/ServiceDocumentTest.java | 21 +-
.../serializer/xml/MetadataDocumentTest.java | 29 +-
.../serializer/xml/ODataXmlSerializerTest.java | 284 +++++++-----
.../core/uri/antlr/TestFullResourcePath.java | 43 +-
37 files changed, 1432 insertions(+), 927 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b1d03d6b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
----------------------------------------------------------------------
diff --cc lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
index d3dac72,6996ff2..47bfe64
--- a/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
+++ b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmEnumTypeImpl.java
@@@ -250,29 -240,32 +240,17 @@@ public class EdmEnumTypeImpl extends Ed
public boolean isFlags() {
return enumType.isFlags();
}
-
+
@Override
- public TargetType getAnnotationsTargetType() {
- return TargetType.EnumType;
- }
-
- @Override
- public String getAnnotationsTargetPath() {
- return null;
- }
-
- @Override
- public FullQualifiedName getAnnotationsTargetFQN() {
- return getFullQualifiedName();
- }
-
- @Override
public int hashCode() {
- return this.getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
+ return getFullQualifiedName().getFullQualifiedNameAsString().hashCode();
}
-
+
@Override
- public boolean equals(Object obj){
- if(obj == null){
- return false;
- }
-
- if(obj == this){
- return true;
- }
-
- if(obj instanceof EdmEnumType){
- EdmEnumType other = (EdmEnumType) obj;
- if(this.getFullQualifiedName().equals(other.getFullQualifiedName())){
- return true;
- }
- }
-
- return false;
+ public boolean equals(final Object obj) {
+ return obj != null
+ && (obj == this
+ || obj instanceof EdmEnumType
+ && getFullQualifiedName().equals(((EdmEnumType) obj).getFullQualifiedName()));
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b1d03d6b/lib/commons-core/src/main/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionImpl.java
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/b1d03d6b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
[03/11] olingo-odata4 git commit: [OLINGO-791] Namespaces are not
longer allowed for entity sets, singeltons, action imports, function imports
Posted by ch...@apache.org.
[OLINGO-791] Namespaces are not longer allowed for entity sets, singeltons, action imports, function imports
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/0989fbd0
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/0989fbd0
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/0989fbd0
Branch: refs/heads/olingo786
Commit: 0989fbd0743fa3349133d7911644759052a13a36
Parents: d0b225b
Author: Christian Holzer <c....@sap.com>
Authored: Tue Oct 6 17:27:02 2015 +0200
Committer: Christian Holzer <c....@sap.com>
Committed: Tue Oct 6 17:27:02 2015 +0200
----------------------------------------------------------------------
.../core/uri/parser/UriParseTreeVisitor.java | 19 ++++++++++++++++++-
.../uri/parser/UriParserSemanticException.java | 6 ++++--
.../server-core-exceptions-i18n.properties | 1 +
.../core/uri/antlr/TestFullResourcePath.java | 9 +++++++++
4 files changed, 32 insertions(+), 3 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
index f61c6ee..7ea1adb 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParseTreeVisitor.java
@@ -331,6 +331,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmEntitySet != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceEntitySetImpl().setEntitSet(edmEntitySet));
return null;
@@ -341,6 +342,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmSingleton != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceSingletonImpl().setSingleton(edmSingleton));
return null;
@@ -351,6 +353,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (edmActionImport != null
&& (parts.isEmpty() || !(parts.get(0) instanceof UriResourcePartTyped)
|| parts.get(0) instanceof UriResourceRoot)) {
+ ensureNamespaceIsNull(ctx.vNS);
context.contextUriInfo.addResourcePart(
new UriResourceActionImpl().setActionImport(edmActionImport));
return null;
@@ -396,7 +399,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
+ "' with parameters [" + tmp.toString() + "] not found",
UriParserSemanticException.MessageKeys.FUNCTION_NOT_FOUND, edmFunctionImport.getName(), tmp.toString()));
}
-
+
+ ensureNamespaceIsNull(ctx.vNS);
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
context.contextUriInfo.addResourcePart(uriResource);
return null;
@@ -708,6 +712,19 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriParserSemanticException.MessageKeys.UNKNOWN_PART, fullFilterName.toString()));
}
}
+
+ /**
+ * Ensures that the namespace of the first resource parts is null
+ * @param vNS namespace or null
+ */
+ private void ensureNamespaceIsNull(final NamespaceContext vNS) {
+ if(vNS != null && context.contextUriInfo.getLastResourcePart() == null) {
+ // First resource part and namespace is not null!
+ throw wrap(new UriParserSemanticException("Namespace is not allowed for EntitySets, Singeltons, "
+ + " Action Imports and Function Imports. Found " + vNS.getText(),
+ UriParserSemanticException.MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT, vNS.getText()));
+ }
+ }
private String getName(final EdmType type) {
return type.getFullQualifiedName().getFullQualifiedNameAsString();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
index 672d093..6803e7a 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/uri/parser/UriParserSemanticException.java
@@ -77,8 +77,10 @@ public class UriParserSemanticException extends UriParserException {
/** parameter: resource_name */
RESOURCE_NOT_FOUND,
/** parameter: not implemented part */
- NOT_IMPLEMENTED;
-
+ NOT_IMPLEMENTED,
+ /** parameter: namespace **/
+ NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT;
+
@Override
public String getKey() {
return name();
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
index 3484ab3..267db11 100644
--- a/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
+++ b/lib/server-core/src/main/resources/server-core-exceptions-i18n.properties
@@ -67,6 +67,7 @@ UriParserSemanticException.NOT_FOR_ENTITY_TYPE=Not allowed for entity type.
UriParserSemanticException.PREVIOUS_PART_TYPED=The previous part is typed.
UriParserSemanticException.RESOURCE_NOT_FOUND=Cannot find EntitySet, Singleton, ActionImport or FunctionImport with name '%1$s'.
UriParserSemanticException.NOT_IMPLEMENTED=%1$s is not implemented!
+UriParserSemanticException.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT=Namespace is not allowed for Entity Sets, Singeltons, Action Imports and Function Imports. Found '%1$s'.
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/0989fbd0/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
index 3b2ff14..7df684e 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -5571,6 +5571,15 @@ public class TestFullResourcePath {
}
@Test
+ public void testFirstResourcePathWithNamespace() {
+ testUri.runEx("olingo.odata.test1.ESAllPrim").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.ESAllPrim(0)").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.FINRTInt16()").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.AIRTString").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ testUri.runEx("olingo.odata.test1.SINav").isExSemantic(MessageKeys.NAMESPACE_NOT_ALLOWED_AT_FIRST_ELEMENT);
+ }
+
+ @Test
public void navPropertySameNameAsEntitySet() throws Exception {
testUri.run("ESNavProp(1)/ESNavProp(2)/ESNavProp(3)/ESNavProp")
.goPath()
[08/11] olingo-odata4 git commit: [OLINGO-795] server support for
Enums and Type Definitions
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
new file mode 100644
index 0000000..18bb798
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmEnumTest.java
@@ -0,0 +1,354 @@
+/*
+ * 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.commons.core.edm;
+
+import static org.hamcrest.CoreMatchers.containsString;
+import static org.junit.Assert.assertArrayEquals;
+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.assertThat;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmException;
+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.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
+import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.junit.Test;
+
+public class EdmEnumTest {
+
+ private final EdmEnumType instance;
+ private final EdmEnumType otherInstance;
+ private final EdmEnumType nonFlagsInstance;
+ private final EdmEnumType int16EnumType;
+ private final EdmEnumType int32EnumType;
+ private final EdmEnumType int32FlagType;
+
+ public EdmEnumTest() {
+ final List<CsdlEnumMember> memberList = Arrays.asList(
+ new CsdlEnumMember().setName("first").setValue("1"),
+ new CsdlEnumMember().setName("second").setValue("64"));
+
+ final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
+
+ instance = new EdmEnumTypeImpl(null, enumName,
+ new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
+ .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
+
+ otherInstance = new EdmEnumTypeImpl(null, enumName,
+ new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
+ .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
+
+ nonFlagsInstance = new EdmEnumTypeImpl(null, enumName,
+ new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
+ .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
+
+ int16EnumType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(false)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"),
+ new CsdlEnumMember().setName("B").setValue("1"),
+ new CsdlEnumMember().setName("C").setValue("2"))));
+
+ int32EnumType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(false)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"),
+ new CsdlEnumMember().setName("B").setValue("1"),
+ new CsdlEnumMember().setName("C").setValue("2"))));
+
+ int32FlagType = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum")
+ .setFlags(true)
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("2"),
+ new CsdlEnumMember().setName("B").setValue("4"),
+ new CsdlEnumMember().setName("C").setValue("8"))));
+ }
+
+ @Test
+ public void nameSpace() throws Exception {
+ assertEquals("namespace", instance.getNamespace());
+ }
+
+ @Test
+ public void name() throws Exception {
+ assertEquals("name", instance.getName());
+ }
+
+ @Test
+ public void kind() throws Exception {
+ assertEquals(EdmTypeKind.ENUM, instance.getKind());
+ }
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(instance));
+ assertTrue(instance.isCompatible(otherInstance));
+ assertFalse(instance.isCompatible(instance.getUnderlyingType()));
+ }
+
+ @Test
+ public void defaultType() throws Exception {
+ assertEquals(Byte.class, instance.getDefaultType());
+ EdmEnumType instance = new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType().setName("MyEnum"));
+ assertEquals(Integer.class, instance.getUnderlyingType().getDefaultType());
+ }
+
+ @Test
+ public void members() throws Exception {
+ assertArrayEquals(new String[] { "first", "second" }, instance.getMemberNames().toArray());
+ assertEquals("64", instance.getMember("second").getValue());
+ assertNull(instance.getMember("notExisting"));
+ }
+
+ @Test
+ public void underlyingType() throws Exception {
+ assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
+ }
+
+ @Test
+ public void validate() throws Exception {
+ assertTrue(instance.validate(null, null, null, null, null, null));
+ assertTrue(instance.validate(null, true, null, null, null, null));
+ assertFalse(instance.validate(null, false, null, null, null, null));
+ assertFalse(instance.validate("", null, null, null, null, null));
+ assertFalse(instance.validate("something", null, null, null, null, null));
+
+ assertTrue(instance.validate("second", null, null, null, null, null));
+ assertTrue(instance.validate("first,second", null, null, null, null, null));
+ assertTrue(instance.validate("64", null, null, null, null, null));
+ assertTrue(instance.validate("1,64", null, null, null, null, null));
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertNull(instance.toUriLiteral(null));
+ assertEquals("namespace.name'first'", instance.toUriLiteral("first"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertNull(instance.fromUriLiteral(null));
+ assertEquals("first", instance.fromUriLiteral("namespace.name'first'"));
+
+ expectErrorInFromUriLiteral(instance, "");
+ expectErrorInFromUriLiteral(instance, "name'first'");
+ expectErrorInFromUriLiteral(instance, "namespace.name'first");
+ expectErrorInFromUriLiteral(instance, "namespace.namespace'first");
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertNull(instance.valueToString(null, null, null, null, null, null));
+ assertNull(instance.valueToString(null, true, null, null, null, null));
+ assertEquals("first", instance.valueToString(1, null, null, null, null, null));
+ assertEquals("first", instance.valueToString((byte) 1, null, null, null, null, null));
+ assertEquals("first", instance.valueToString((short) 1, null, null, null, null, null));
+ assertEquals("second", instance.valueToString(Integer.valueOf(64), null, null, null, null, null));
+ assertEquals("second", instance.valueToString(64L, null, null, null, null, null));
+ assertEquals("first,second", instance.valueToString(65, null, null, null, null, null));
+
+ expectNullErrorInValueToString(instance);
+ expectContentErrorInValueToString(instance, 3);
+ expectTypeErrorInValueToString(instance, 1.0);
+
+ assertEquals("A", int32EnumType.valueToString(0, false, 0, 0, 0, false));
+ assertEquals("B", int32EnumType.valueToString(1, false, 0, 0, 0, false));
+ assertEquals("C", int32EnumType.valueToString(2, false, 0, 0, 0, false));
+
+ assertEquals("A", int16EnumType.valueToString(0, false, 0, 0, 0, false));
+ assertEquals("B", int16EnumType.valueToString(1, false, 0, 0, 0, false));
+ assertEquals("C", int16EnumType.valueToString(2, false, 0, 0, 0, false));
+
+ assertEquals("A", int32FlagType.valueToString(2, false, 0, 0, 0, false));
+ assertEquals("B", int32FlagType.valueToString(4, false, 0, 0, 0, false));
+ assertEquals("C", int32FlagType.valueToString(8, false, 0, 0, 0, false));
+ assertEquals("A,B", int32FlagType.valueToString(0x2 + 0x4, false, 0, 0, 0, false));
+ assertEquals("B,C", int32FlagType.valueToString(0x4 + 0x8, false, 0, 0, 0, false));
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertNull(instance.valueOfString(null, null, null, null, null, null, Byte.class));
+ assertNull(instance.valueOfString(null, true, null, null, null, null, Byte.class));
+ assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", null, null, null, null, null, Short.class));
+ assertEquals(Integer.valueOf(1), instance.valueOfString("1", null, null, null, null, null, Integer.class));
+ assertEquals(Long.valueOf(64L), instance.valueOfString("64", null, null, null, null, null, Long.class));
+ assertEquals(Long.valueOf(1), instance.valueOfString("first", null, null, null, null, null, Long.class));
+ assertEquals(Byte.valueOf((byte) 65), instance.valueOfString("first,64", null, null, null, null, null, Byte.class));
+ assertEquals(Integer.valueOf(1), instance.valueOfString("1,1,first", null, null, null, null, null, Integer.class));
+
+ assertEquals(Integer.valueOf(1), nonFlagsInstance.valueOfString("1", null, null, null, null, null, Integer.class));
+ expectContentErrorInValueOfString(nonFlagsInstance, "1,64");
+
+ expectNullErrorInValueOfString(instance);
+ expectContentErrorInValueOfString(instance, "2");
+ expectContentErrorInValueOfString(instance, "1,");
+ expectContentErrorInValueOfString(instance, ",1");
+ expectTypeErrorInValueOfString(instance, "1");
+
+ assertEquals(Integer.valueOf(0), int32EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(1), int32EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(2), int32EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
+
+ assertEquals(Integer.valueOf(0), int16EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(1), int16EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(2), int16EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
+
+ assertEquals(Integer.valueOf(2), int32FlagType.valueOfString("A", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(4), int32FlagType.valueOfString("B", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(8), int32FlagType.valueOfString("C", null, null, null, null, null, Integer.class));
+ assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("A,B", null, null, null, null, null,
+ Integer.class));
+ assertEquals(Integer.valueOf(0x4 + 0x8), int32FlagType.valueOfString("B,C", null, null, null, null, null,
+ Integer.class));
+ assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("B,A", null, null, null, null, null,
+ Integer.class));
+ }
+
+ private void expectErrorInValueToString(final EdmEnumType instance,
+ final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale, final Boolean isUnicode,
+ final String message) {
+ try {
+ instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertThat(e.getLocalizedMessage(), containsString(message));
+ }
+ }
+
+ private void expectErrorInUnderlyingType(final EdmPrimitiveTypeKind underlyingType, final String message) {
+ try {
+ new EdmEnumTypeImpl(null,
+ new FullQualifiedName("testNamespace", "testName"),
+ new CsdlEnumType()
+ .setName("MyEnum")
+ .setFlags(false)
+ .setUnderlyingType(underlyingType.getFullQualifiedName())
+ .setMembers(Arrays.asList(
+ new CsdlEnumMember().setName("A").setValue("0"))));
+ fail("Expected exception not thrown");
+ } catch (final EdmException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertThat(e.getLocalizedMessage(), containsString(message));
+ }
+ }
+
+ @Test
+ public void unsupportedUnderlyingType() throws Exception {
+ // Test some random unsupported types
+ expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Date, "");
+ expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Geography, "");
+ expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Guid, "");
+ }
+
+ @Test
+ public void outOfRangeValueToString() throws Exception {
+ expectErrorInValueToString(int16EnumType, Integer.MAX_VALUE, null, null, null, null, null, "");
+ }
+
+ protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
+ try {
+ instance.fromUriLiteral(value);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
+ }
+ }
+
+ private void expectErrorInValueToString(final EdmPrimitiveType instance,
+ final Object value, final Boolean isNullable, final Integer maxLength,
+ final Integer precision, final Integer scale, final Boolean isUnicode,
+ final String message) {
+ try {
+ instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertThat(e.getLocalizedMessage(), containsString(message));
+ }
+ }
+
+ protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
+ expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
+ }
+
+ protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
+ expectErrorInValueToString(instance, value, null, null, null, null, null, "value type");
+ }
+
+ protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
+ expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid.");
+ }
+
+ private void expectErrorInValueOfString(final EdmPrimitiveType instance,
+ final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode, final Class<?> returnType,
+ final String message) {
+
+ try {
+ instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertThat(e.getLocalizedMessage(), containsString(message));
+ }
+ }
+
+ protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
+ expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
+ "The value type class java.lang.Class is not supported.");
+ }
+
+ protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
+ expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
+ "illegal content");
+ }
+
+ protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
+ expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
+ "The literal 'null' is not allowed.");
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
----------------------------------------------------------------------
diff --git a/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
new file mode 100644
index 0000000..3d41db4
--- /dev/null
+++ b/lib/commons-core/src/test/java/org/apache/olingo/commons/core/edm/EdmTypeDefinitionTest.java
@@ -0,0 +1,137 @@
+/*
+ * 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.commons.core.edm;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.apache.olingo.commons.api.edm.EdmAnnotationsTarget.TargetType;
+import org.apache.olingo.commons.api.edm.EdmException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
+import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
+import org.apache.olingo.commons.core.edm.primitivetype.PrimitiveTypeBaseTest;
+import org.junit.Test;
+
+public class EdmTypeDefinitionTest extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = new EdmTypeDefinitionImpl(null,
+ new FullQualifiedName("namespace", "def"),
+ new CsdlTypeDefinition().setName("def")
+ .setUnderlyingType(EdmString.getInstance().getFullQualifiedName())
+ .setMaxLength(5)
+ .setUnicode(false));
+
+ @Test
+ public void defaultType() throws Exception {
+ assertEquals(String.class, instance.getDefaultType());
+ }
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(instance));
+ for (final EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
+ if (kind != EdmPrimitiveTypeKind.String) {
+ assertFalse(instance.isCompatible(EdmPrimitiveTypeFactory.getInstance(kind)));
+ }
+ }
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("'Value'", instance.toUriLiteral("Value"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("Value", instance.fromUriLiteral("'Value'"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("text", instance.valueToString("text", null, null, null, null, null));
+
+ expectFacetsErrorInValueToString(instance, "longtext", null, null, null, null, null);
+ expectFacetsErrorInValueToString(instance, "text", null, 3, null, null, null);
+ expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, null);
+ expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, false);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals("text", instance.valueOfString("text", null, null, null, null, null, String.class));
+
+ expectFacetsErrorInValueOfString(instance, "longtext", null, null, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "text", null, 3, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, false);
+
+ expectTypeErrorInValueOfString(instance, "text");
+ }
+
+ @Test
+ public void typeDefOnStringNoFacets() throws Exception {
+ final EdmTypeDefinition typeDef = new EdmTypeDefinitionImpl(null,
+ new FullQualifiedName("namespace", "name"),
+ new CsdlTypeDefinition().setName("typeDef")
+ .setUnderlyingType(EdmString.getInstance().getFullQualifiedName()));
+
+ assertEquals("name", typeDef.getName());
+ assertEquals("namespace", typeDef.getNamespace());
+ assertEquals(new FullQualifiedName("namespace", "name"), typeDef.getFullQualifiedName());
+ assertEquals(String.class, typeDef.getDefaultType());
+ assertEquals(EdmTypeKind.DEFINITION, typeDef.getKind());
+ assertEquals(EdmString.getInstance(), typeDef.getUnderlyingType());
+ assertTrue(typeDef.isCompatible(EdmString.getInstance()));
+ assertEquals(TargetType.TypeDefinition, typeDef.getAnnotationsTargetType());
+ assertEquals(typeDef.getFullQualifiedName(), typeDef.getAnnotationsTargetFQN());
+ assertEquals(typeDef.getName(), typeDef.getAnnotationsTargetPath());
+
+ // String validation
+ assertEquals("'StringValue'", typeDef.toUriLiteral("StringValue"));
+ assertEquals("String''Value", typeDef.fromUriLiteral("'String''''Value'"));
+ assertTrue(typeDef.validate("text", null, null, null, null, null));
+ assertEquals("text", typeDef.valueToString("text", null, null, null, null, null));
+ assertEquals("text", typeDef.valueOfString("text", null, null, null, null, null, String.class));
+
+ // Facets must be initial
+ assertNull(typeDef.getMaxLength());
+ assertNull(typeDef.getPrecision());
+ assertNull(typeDef.getScale());
+ assertNull(typeDef.getSrid());
+ assertTrue(typeDef.isUnicode());
+ }
+
+ @Test(expected = EdmException.class)
+ public void invalidTypeResultsInEdmException() throws Exception {
+ new EdmTypeDefinitionImpl(null,
+ new FullQualifiedName("namespace", "name"),
+ new CsdlTypeDefinition().setName("typeDef")
+ .setUnderlyingType(new FullQualifiedName("wrong", "wrong")))
+ .getUnderlyingType();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/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 9fb08ab..8ff833c 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
@@ -71,19 +71,16 @@ import com.fasterxml.aalto.stax.InputFactoryImpl;
public class ODataXmlDeserializer implements ODataDeserializer {
private static final XMLInputFactory FACTORY = new InputFactoryImpl();
- private static final String ATOM = "a";
- 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);
- private final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
- private final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
- private final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
- 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 static final QName propertiesQName = new QName(Constants.NS_METADATA, Constants.PROPERTIES);
+ private static final QName propertyValueQName = new QName(Constants.NS_METADATA, Constants.VALUE);
+ private static final QName contextQName = new QName(Constants.NS_METADATA, Constants.CONTEXT);
+ private static final QName nullQName = new QName(Constants.NS_METADATA, Constants.ATTR_NULL);
+ private static final QName inlineQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_INLINE);
+ private static final QName entryRefQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_ENTRY_REF);
+ private static final QName etagQName = new QName(Constants.NS_METADATA, Constants.ATOM_ATTR_ETAG);
+ private static final QName countQName = new QName(Constants.NS_METADATA, Constants.ATOM_ELEM_COUNT);
+ private static final QName parametersQName = new QName(Constants.NS_METADATA, "parameters");
protected XMLEventReader getReader(final InputStream input) throws XMLStreamException {
return FACTORY.createXMLEventReader(input);
@@ -330,7 +327,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
link.setInlineEntitySet(entitySet(reader, inline, navigationProperty.getType()));
}
}
- } else if (REF_ELEMENT.equals(event.asStartElement().getName())) {
+ } else if (entryRefQName.equals(event.asStartElement().getName())) {
if (navigationProperty.isCollection()) {
throw new DeserializerException("Binding annotation: " + link.getTitle() +
" must be collection of entity refercences",
@@ -362,7 +359,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
while (reader.hasNext() && !foundEndElement) {
final XMLEvent event = reader.nextEvent();
- if (event.isStartElement() && REF_ELEMENT.equals(event.asStartElement().getName())) {
+ if (event.isStartElement() && entryRefQName.equals(event.asStartElement().getName())) {
references.add(entityRef(reader, event.asStartElement()));
}
@@ -671,11 +668,8 @@ public class ODataXmlDeserializer implements ODataDeserializer {
final XMLEvent event = reader.nextEvent();
if (event.isStartElement()) {
StartElement start = event.asStartElement();
- if (REF_ELEMENT.equals(start.getName())) {
- Attribute context = start.getAttributeByName(ID_ATTR);
- if (context == null) {
- context = start.getAttributeByName(new QName("id"));
- }
+ if (entryRefQName.equals(start.getName())) {
+ Attribute context = start.getAttributeByName(Constants.QNAME_ATOM_ATTR_ID);
URI uri = URI.create(context.getValue());
references.add(uri);
}
@@ -683,8 +677,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
}
return DeserializerResultImpl.with().entityReferences(references).build();
} catch (XMLStreamException e) {
- throw new DeserializerException("An IOException occurred", e,
- DeserializerException.MessageKeys.IO_EXCEPTION);
+ throw new DeserializerException(e.getMessage(), e, DeserializerException.MessageKeys.IO_EXCEPTION);
}
}
@@ -702,7 +695,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
final XMLEventReader reader = getReader(stream);
while (reader.hasNext()) {
final XMLEvent event = reader.nextEvent();
- if (event.isStartElement() && PARAMETERS_ELEMENT.equals(event.asStartElement().getName())) {
+ if (event.isStartElement() && parametersQName.equals(event.asStartElement().getName())) {
consumeParameters(edmAction, reader, event.asStartElement(), parameters);
}
}
@@ -765,7 +758,7 @@ public class ODataXmlDeserializer implements ODataDeserializer {
}
}
if (!found) {
- throw new DeserializerException("failed to read "+event.asStartElement().getName().getLocalPart(),
+ throw new DeserializerException("failed to read " + event.asStartElement().getName().getLocalPart(),
DeserializerException.MessageKeys.UNKNOWN_CONTENT);
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
index c279586..0f0eff6 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/AbstractODataSerializer.java
@@ -25,7 +25,7 @@ import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
public abstract class AbstractODataSerializer implements ODataSerializer {
-
+
protected static final String IO_EXCEPTION_TEXT = "An I/O exception occurred.";
protected void closeCircleStreamBufferOutput(OutputStream outputStream, SerializerException cachedException)
@@ -37,11 +37,10 @@ public abstract class AbstractODataSerializer implements ODataSerializer {
if (cachedException != null) {
throw cachedException;
} else {
- throw new SerializerException("An I/O exception occurred.", e,
+ throw new SerializerException(IO_EXCEPTION_TEXT, e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
index 642a91e..1ddc979 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializer.java
@@ -42,7 +42,9 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+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.ODataServerError;
@@ -399,25 +401,25 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
private void writePropertyValue(final EdmProperty edmProperty,
final Property property, final Set<List<String>> selectedPaths, final JsonGenerator json)
throws IOException, SerializerException {
+ final EdmType type = edmProperty.getType();
try {
- if (edmProperty.isPrimitive()) {
+ if (edmProperty.isPrimitive()
+ || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) {
if (edmProperty.isCollection()) {
- writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
+ writePrimitiveCollection((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
} else {
- writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
+ writePrimitive((EdmPrimitiveType) type, property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
}
- } else if (edmProperty.isCollection()) {
- writeComplexCollection((EdmComplexType) edmProperty.getType(), property, selectedPaths, json);
} else if (property.isComplex()) {
- writeComplexValue((EdmComplexType) edmProperty.getType(), property.asComplex().getValue(), selectedPaths, json);
- } else if (property.isEnum()) {
- writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
- edmProperty.isNullable(), edmProperty.getMaxLength(),
- edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), json);
+ if (edmProperty.isCollection()) {
+ writeComplexCollection((EdmComplexType) type, property, selectedPaths, json);
+ } else {
+ writeComplexValue((EdmComplexType) type, property.asComplex().getValue(), selectedPaths, json);
+ }
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@@ -437,6 +439,7 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
for (Object value : property.asCollection()) {
switch (property.getValueType()) {
case COLLECTION_PRIMITIVE:
+ case COLLECTION_ENUM:
try {
writePrimitiveValue(type, value, isNullable, maxLength, precision, scale, isUnicode, json);
} catch (EdmPrimitiveTypeException e) {
@@ -448,9 +451,6 @@ public class ODataJsonSerializer extends AbstractODataSerializer {
case COLLECTION_GEOSPATIAL:
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
- case COLLECTION_ENUM:
- json.writeString(value.toString());
- break;
default:
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
index 0136df4..2cae476 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java
@@ -21,7 +21,6 @@ package org.apache.olingo.server.core.serializer.json;
import java.io.IOException;
import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
@@ -73,48 +72,42 @@ public class ServiceDocumentJsonSerializer {
gen.writeArrayFieldStart(Constants.VALUE);
- final Edm edm = metadata.getEdm();
- writeEntitySets(gen, edm);
- writeFunctionImports(gen, edm);
- writeSingletons(gen, edm);
+ final EdmEntityContainer container = metadata.getEdm().getEntityContainer();
+ writeEntitySets(gen, container);
+ writeFunctionImports(gen, container);
+ writeSingletons(gen, container);
}
- private void writeEntitySets(final JsonGenerator gen, final Edm edm) throws IOException {
- EdmEntityContainer container = edm.getEntityContainer(null);
-
+ private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
if (edmEntitySet.isIncludeInServiceDocument()) {
- gen.writeStartObject();
- gen.writeObjectField(Constants.JSON_NAME, edmEntitySet.getName());
- gen.writeObjectField(Constants.JSON_URL, edmEntitySet.getName());
- gen.writeEndObject();
+ writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName());
}
}
}
- private void writeFunctionImports(final JsonGenerator gen, final Edm edm) throws IOException {
- EdmEntityContainer container = edm.getEntityContainer(null);
-
+ private void writeFunctionImports(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
if (edmFunctionImport.isIncludeInServiceDocument()) {
- gen.writeStartObject();
- gen.writeObjectField(Constants.JSON_NAME, edmFunctionImport.getName());
- gen.writeObjectField(Constants.JSON_URL, edmFunctionImport.getName());
- gen.writeObjectField(KIND, FUNCTION_IMPORT);
- gen.writeEndObject();
+ writeElement(gen, FUNCTION_IMPORT, edmFunctionImport.getName(), edmFunctionImport.getName());
}
}
}
- private void writeSingletons(final JsonGenerator gen, final Edm edm) throws IOException {
- EdmEntityContainer container = edm.getEntityContainer(null);
-
+ private void writeSingletons(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
for (EdmSingleton edmSingleton : container.getSingletons()) {
- gen.writeStartObject();
- gen.writeObjectField(Constants.JSON_NAME, edmSingleton.getName());
- gen.writeObjectField(Constants.JSON_URL, edmSingleton.getName());
- gen.writeObjectField(KIND, SINGLETON);
- gen.writeEndObject();
+ writeElement(gen, SINGLETON, edmSingleton.getName(), edmSingleton.getName());
+ }
+ }
+
+ private void writeElement(JsonGenerator gen, final String kind, final String reference, final String title)
+ throws IOException {
+ gen.writeStartObject();
+ gen.writeObjectField(Constants.JSON_NAME, title);
+ gen.writeObjectField(Constants.JSON_URL, reference);
+ if (kind != null) {
+ gen.writeObjectField(KIND, kind);
}
+ gen.writeEndObject();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/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 27ba073..3e77239 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
@@ -31,7 +31,6 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.ex.ODataErrorDetail;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.Entity;
@@ -49,13 +48,14 @@ import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.commons.api.ex.ODataErrorDetail;
import org.apache.olingo.commons.core.edm.primitivetype.EdmString;
import org.apache.olingo.server.api.ODataServerError;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.serializer.ComplexSerializerOptions;
import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.EntitySerializerOptions;
-import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions;
import org.apache.olingo.server.api.serializer.ReferenceCollectionSerializerOptions;
import org.apache.olingo.server.api.serializer.ReferenceSerializerOptions;
@@ -72,16 +72,14 @@ import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
public class ODataXmlSerializer extends AbstractODataSerializer {
- private static final String CONTEXT = "context";
/** The default character set is UTF-8. */
- public static final String DEFAULT_CHARSET = "UTF-8";
+ public static final String DEFAULT_CHARSET = Constants.UTF8;
private static final String ATOM = "a";
private static final String NS_ATOM = Constants.NS_ATOM;
- private static final String METADATA = "m";
+ private static final String METADATA = Constants.PREFIX_METADATA;
private static final String NS_METADATA = Constants.NS_METADATA;
- private static final String DATA = "d";
+ private static final String DATA = Constants.PREFIX_DATASERVICES;
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)
@@ -155,13 +153,13 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writer.writeStartElement("error");
writer.writeDefaultNamespace(NS_METADATA);
writeErrorDetails(String.valueOf(error.getStatusCode()), error.getMessage(), error.getTarget(), writer);
if (error.getDetails() != null && !error.getDetails().isEmpty()) {
- writer.writeStartElement("details");
+ writer.writeStartElement(Constants.ERROR_DETAILS);
for (ODataErrorDetail inner : error.getDetails()) {
writeErrorDetails(inner.getCode(), inner.getMessage(), inner.getTarget(), writer);
}
@@ -191,17 +189,17 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeErrorDetails(String code, String message, String target, XMLStreamWriter writer)
throws XMLStreamException {
if (code != null) {
- writer.writeStartElement("code");
- writer.writeCharacters(String.valueOf(code));
+ writer.writeStartElement(Constants.ERROR_CODE);
+ writer.writeCharacters(code);
writer.writeEndElement();
}
- writer.writeStartElement("message");
+ writer.writeStartElement(Constants.ERROR_MESSAGE);
writer.writeCharacters(message);
writer.writeEndElement();
if (target != null) {
- writer.writeStartElement("target");
+ writer.writeStartElement(Constants.ERROR_TARGET);
writer.writeCharacters(target);
writer.writeEndElement();
}
@@ -225,18 +223,18 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
- writer.writeStartElement(ATOM, "feed", NS_ATOM);
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
- writer.writeAttribute(METADATA, NS_METADATA, "context",
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
if (options != null && options.getId() != null) {
- writer.writeStartElement(ATOM, "id", NS_ATOM);
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ID, NS_ATOM);
writer.writeCharacters(options.getId());
writer.writeEndElement();
}
@@ -293,7 +291,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writeEntity(metadata, entityType, entity, contextURL,
options == null ? null : options.getExpand(),
options == null ? null : options.getSelect(), writer, true);
@@ -329,7 +327,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
if (metadata != null
&& metadata.getServiceMetadataETagSupport() != null
&& metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
- writer.writeAttribute(METADATA, NS_METADATA, "metadata-etag",
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG,
metadata.getServiceMetadataETagSupport().getMetadataETag());
}
}
@@ -347,25 +345,24 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final SelectOption select, final XMLStreamWriter writer, final boolean top)
throws XMLStreamException, SerializerException {
- writer.writeStartElement(ATOM, "entry", NS_ATOM);
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_ENTRY, NS_ATOM);
if (top) {
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
if (contextURL != null) { // top-level entity
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
-
}
}
if (entity.getETag() != null) {
- writer.writeAttribute(METADATA, NS_METADATA, "etag", entity.getETag());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_ETAG, entity.getETag());
}
if (entity.getId() != null) {
- writer.writeStartElement(NS_ATOM, "id");
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_ID);
writer.writeCharacters(entity.getId().toASCIIString());
writer.writeEndElement();
}
@@ -373,24 +370,21 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
writerAuthorInfo(entity.getTitle(), writer);
if (entity.getId() != null) {
- writer.writeStartElement(NS_ATOM, "link");
- writer.writeAttribute("rel", "edit");
- writer.writeAttribute("href", entity.getId().toASCIIString());
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_LINK);
+ writer.writeAttribute(Constants.ATTR_REL, Constants.EDIT_LINK_REL);
+ writer.writeAttribute(Constants.ATTR_HREF, entity.getId().toASCIIString());
writer.writeEndElement();
}
if (entityType.hasStream()) {
- writer.writeStartElement(NS_ATOM, "content");
- writer.writeAttribute("type", entity.getMediaContentType());
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT);
+ writer.writeAttribute(Constants.ATTR_TYPE, entity.getMediaContentType());
if (entity.getMediaContentSource() != null) {
- writer.writeAttribute("src", entity.getMediaContentSource().toString());
+ writer.writeAttribute(Constants.ATOM_ATTR_SRC, entity.getMediaContentSource().toString());
} else {
String id = entity.getId().toASCIIString();
- if (id.endsWith("/")) {
- writer.writeAttribute("src", id + "$value");
- } else {
- writer.writeAttribute("src", id + "/$value");
- }
+ writer.writeAttribute(Constants.ATOM_ATTR_SRC,
+ id + (id.endsWith("/") ? "" : "/") + "$value");
}
writer.writeEndElement();
}
@@ -403,18 +397,19 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
EdmEntityType resolvedType = resolveEntityType(metadata, entityType, entity.getType());
writeNavigationProperties(metadata, resolvedType, entity, expand, writer);
- writer.writeStartElement(ATOM, "category", NS_ATOM);
- writer.writeAttribute("scheme", NS_SCHEMA);
- writer.writeAttribute("term", "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_CATEGORY, NS_ATOM);
+ writer.writeAttribute(Constants.ATOM_ATTR_SCHEME, Constants.NS_SCHEME);
+ writer.writeAttribute(Constants.ATOM_ATTR_TERM,
+ "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement();
// In the case media, content is sibiling
if (!entityType.hasStream()) {
- writer.writeStartElement(NS_ATOM, "content");
- writer.writeAttribute("type", "application/xml");
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_CONTENT);
+ writer.writeAttribute(Constants.ATTR_TYPE, "application/xml");
}
- writer.writeStartElement(METADATA, "properties", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.PROPERTIES, NS_METADATA);
writeProperties(metadata, resolvedType, entity.getProperties(), select, writer);
writer.writeEndElement(); // properties
@@ -425,15 +420,15 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException {
- writer.writeStartElement(NS_ATOM, "title");
+ writer.writeStartElement(NS_ATOM, Constants.ATTR_TITLE);
if (title != null) {
writer.writeCharacters(title);
}
writer.writeEndElement();
- writer.writeStartElement(NS_ATOM, "summary");
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_SUMMARY);
writer.writeEndElement();
- writer.writeStartElement(NS_ATOM, "updated");
+ writer.writeStartElement(NS_ATOM, Constants.ATOM_ELEM_UPDATED);
writer.writeCharacters(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis())));
writer.writeEndElement();
@@ -528,7 +523,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
}
if (navigationLink != null) {
writeLink(writer, navigationLink, false);
- writer.writeStartElement(METADATA, "inline", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.ATOM_ELEM_INLINE, NS_METADATA);
writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(),
@@ -573,16 +568,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeLink(final XMLStreamWriter writer, final Link link, final boolean close)
throws XMLStreamException {
- writer.writeStartElement(ATOM, "link", NS_ATOM);
- writer.writeAttribute("rel", link.getRel());
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
+ writer.writeAttribute(Constants.ATTR_REL, link.getRel());
if (link.getType() != null) {
- writer.writeAttribute("type", link.getType());
+ writer.writeAttribute(Constants.ATTR_TYPE, link.getType());
}
if (link.getTitle() != null) {
- writer.writeAttribute("title", link.getTitle());
+ writer.writeAttribute(Constants.ATTR_TITLE, link.getTitle());
}
if (link.getHref() != null) {
- writer.writeAttribute("href", link.getHref());
+ writer.writeAttribute(Constants.ATTR_HREF, link.getHref());
}
if (close) {
writer.writeEndElement();
@@ -595,7 +590,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throws XMLStreamException, SerializerException {
if (property.isCollection()) {
if (navigationLink != null && navigationLink.getInlineEntitySet() != null) {
- writer.writeStartElement(ATOM, "feed", NS_ATOM);
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writeEntitySet(metadata, property.getType(), navigationLink.getInlineEntitySet(), innerExpand,
innerSelect, writer);
writer.writeEndElement();
@@ -615,7 +610,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
writer.writeStartElement(DATA, edmProperty.getName(), NS_DATA);
if (property == null || property.isNull()) {
if (edmProperty.isNullable()) {
- writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
throw new SerializerException("Non-nullable property not present!",
SerializerException.MessageKeys.MISSING_PROPERTY, edmProperty.getName());
@@ -648,9 +643,14 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Property property, final Set<List<String>> selectedPaths,
final XMLStreamWriter writer) throws XMLStreamException, SerializerException {
try {
- if (edmProperty.isPrimitive()) {
+ if (edmProperty.isPrimitive()
+ || edmProperty.getType().getKind() == EdmTypeKind.ENUM
+ || edmProperty.getType().getKind() == EdmTypeKind.DEFINITION) {
if (edmProperty.isCollection()) {
- writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + edmProperty.getType().getName() + ")");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
+ edmProperty.isPrimitive() ?
+ "#Collection(" + edmProperty.getType().getName() + ")" :
+ collectionType(edmProperty.getType()));
writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
@@ -661,19 +661,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
writer);
}
- } else if (edmProperty.isCollection()) {
- writer.writeAttribute(METADATA, NS_METADATA, "type", collectionType(edmProperty.getType()));
- writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
} else if (property.isComplex()) {
- writer.writeAttribute(METADATA, NS_METADATA, "type",
- "#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
- writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
- selectedPaths, writer);
- } else if (property.isEnum()) {
- writePrimitive((EdmPrimitiveType) edmProperty.getType(), property,
- edmProperty.isNullable(), edmProperty.getMaxLength(),
- edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
- writer);
+ if (edmProperty.isCollection()) {
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, collectionType(edmProperty.getType()));
+ writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
+ } else {
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
+ "#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
+ writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
+ selectedPaths, writer);
+ }
} else {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, edmProperty.getName());
@@ -690,7 +687,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Boolean isUnicode,
final XMLStreamWriter writer) throws XMLStreamException, EdmPrimitiveTypeException, SerializerException {
for (Object value : property.asCollection()) {
- writer.writeStartElement(METADATA, "element", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
switch (property.getValueType()) {
case COLLECTION_PRIMITIVE:
case COLLECTION_ENUM:
@@ -711,9 +708,9 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final Property property, final Set<List<String>> selectedPaths, final XMLStreamWriter writer)
throws XMLStreamException, SerializerException {
for (Object value : property.asCollection()) {
- writer.writeStartElement(METADATA, "element", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.ELEM_ELEMENT, NS_METADATA);
if (derivedComplexType(type, property.getType()) != null) {
- writer.writeAttribute(METADATA, NS_METADATA, "type", property.getType());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, property.getType());
}
switch (property.getValueType()) {
case COLLECTION_COMPLEX:
@@ -733,7 +730,10 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throws EdmPrimitiveTypeException, XMLStreamException, SerializerException {
if (property.isPrimitive()) {
if (!(type instanceof EdmString)) {
- writer.writeAttribute(METADATA, NS_METADATA, "type", type.getName());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
+ type.getKind() == EdmTypeKind.DEFINITION ?
+ "#" + type.getFullQualifiedName().getFullQualifiedNameAsString() :
+ type.getName());
}
writePrimitiveValue(type, property.asPrimitive(),
isNullable, maxLength, precision, scale, isUnicode, writer);
@@ -741,7 +741,8 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
} else if (property.isEnum()) {
- writer.writeAttribute(METADATA, NS_METADATA, "type", "#" + type.getName());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
+ "#" + type.getFullQualifiedName().getFullQualifiedNameAsString());
writePrimitiveValue(type, property.asEnum(),
isNullable, maxLength, precision, scale, isUnicode, writer);
} else {
@@ -757,7 +758,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
final String value = type.valueToString(primitiveValue,
isNullable, maxLength, precision, scale, isUnicode);
if (value == null) {
- writer.writeAttribute(DATA, NS_DATA, "null", "true");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
writer.writeCharacters(value);
}
@@ -797,16 +798,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
- writer.writeStartElement(METADATA, "value", NS_METADATA);
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+ writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) {
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
if (property.isNull()) {
- writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
writePrimitive(type, property,
options == null ? null : options.isNullable(),
@@ -853,17 +854,17 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
- writer.writeStartElement(METADATA, "value", NS_METADATA);
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+ writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
- writer.writeAttribute(METADATA, NS_METADATA, "type", "#"
- + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE,
+ "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
if (property.isNull()) {
- writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NULL, "true");
} else {
final List<Property> values = property.asComplex().getValue();
writeProperties(metadata, resolvedType, values, options == null ? null : options.getSelect(), writer);
@@ -899,15 +900,15 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
- writer.writeStartElement(METADATA, "value", NS_METADATA);
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+ writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) {
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
- writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + type.getName() + ")");
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, "#Collection(" + type.getName() + ")");
writePrimitiveCollection(type, property,
options == null ? null : options.isNullable(),
options == null ? null : options.getMaxLength(),
@@ -952,11 +953,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartElement(METADATA, "value", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.VALUE, NS_METADATA);
writer.writeNamespace(METADATA, NS_METADATA);
writer.writeNamespace(DATA, NS_DATA);
- writer.writeAttribute(METADATA, NS_METADATA, "type", collectionType(type));
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_TYPE, collectionType(type));
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
writeMetadataETag(metadata, writer);
writeComplexCollection(metadata, type, property, null, writer);
@@ -993,7 +994,7 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
writeReference(entity, options == null ? null : options.getContextURL(), writer, true);
writer.writeEndDocument();
writer.flush();
@@ -1020,11 +1021,11 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
if (top) {
writer.writeNamespace(METADATA, NS_METADATA);
if (contextURL != null) { // top-level entity
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT,
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
ContextURLBuilder.create(contextURL).toASCIIString());
}
}
- writer.writeAttribute("id", entity.getId().toASCIIString());
+ writer.writeAttribute(Constants.ATOM_ATTR_ID, entity.getId().toASCIIString());
writer.writeEndElement();
}
@@ -1043,13 +1044,13 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
CircleStreamBuffer buffer = new CircleStreamBuffer();
outputStream = buffer.getOutputStream();
XMLStreamWriter writer = XMLOutputFactory.newInstance().createXMLStreamWriter(outputStream, DEFAULT_CHARSET);
- writer.writeStartDocument(ODataSerializer.DEFAULT_CHARSET, "1.0");
- writer.writeStartElement(ATOM, "feed", NS_ATOM);
+ writer.writeStartDocument(DEFAULT_CHARSET, "1.0");
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_FEED, NS_ATOM);
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(METADATA, NS_METADATA);
if (options != null && options.getContextURL() != null) { // top-level entity
- writer.writeAttribute(METADATA, NS_METADATA, CONTEXT, ContextURLBuilder.create(options.getContextURL())
- .toASCIIString());
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT,
+ ContextURLBuilder.create(options.getContextURL()).toASCIIString());
}
if (options != null && options.getCount() != null && options.getCount().getValue()
&& entitySet.getCount() != null) {
@@ -1083,16 +1084,16 @@ public class ODataXmlSerializer extends AbstractODataSerializer {
private void writeCount(final EntityCollection entitySet, XMLStreamWriter writer)
throws XMLStreamException {
- writer.writeStartElement(METADATA, "count", NS_METADATA);
+ writer.writeStartElement(METADATA, Constants.ATOM_ELEM_COUNT, NS_METADATA);
writer.writeCharacters(String.valueOf(entitySet.getCount()));
writer.writeEndElement();
}
private void writeNextLink(final EntityCollection entitySet, XMLStreamWriter writer)
throws XMLStreamException {
- writer.writeStartElement(ATOM, "link", NS_ATOM);
- writer.writeAttribute("rel", "next");
- writer.writeAttribute("href", entitySet.getNext().toASCIIString());
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_LINK, NS_ATOM);
+ writer.writeAttribute(Constants.ATTR_REL, Constants.NEXT_LINK_REL);
+ writer.writeAttribute(Constants.ATTR_HREF, entitySet.getNext().toASCIIString());
writer.writeEndElement();
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
index b931227..6d130ba 100644
--- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
+++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java
@@ -22,7 +22,6 @@ import javax.xml.stream.XMLStreamException;
import javax.xml.stream.XMLStreamWriter;
import org.apache.olingo.commons.api.Constants;
-import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmFunctionImport;
@@ -33,18 +32,12 @@ import org.apache.olingo.server.api.serializer.ODataSerializer;
import org.apache.olingo.server.api.serializer.SerializerException;
public class ServiceDocumentXmlSerializer {
- public static final String KIND = "kind";
-
- public static final String FUNCTION_IMPORT = "FunctionImport";
- public static final String SINGLETON = "Singleton";
- public static final String SERVICE_DOCUMENT = "ServiceDocument";
-
private static final String APP = "app";
private static final String NS_APP = "http://www.w3.org/2007/app";
private static final String ATOM = "atom";
- 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 = "metadata";
- private static final String NS_METADATA = "http://docs.oasis-open.org/odata/ns/metadata";
+ private static final String NS_METADATA = Constants.NS_METADATA;
private final ServiceMetadata metadata;
private final String serviceRoot;
@@ -69,81 +62,73 @@ public class ServiceDocumentXmlSerializer {
writer.writeNamespace(ATOM, NS_ATOM);
writer.writeNamespace(APP, NS_APP);
writer.writeNamespace(METADATA, NS_METADATA);
- writer.writeAttribute(METADATA, NS_METADATA, "context", metadataUri);
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.CONTEXT, metadataUri);
if (metadata != null
&& metadata.getServiceMetadataETagSupport() != null
&& metadata.getServiceMetadataETagSupport().getMetadataETag() != null) {
- writer.writeAttribute(METADATA, NS_METADATA, "metadata-etag",
+ writer.writeAttribute(METADATA, NS_METADATA, Constants.ATOM_ATTR_METADATAETAG,
metadata.getServiceMetadataETagSupport().getMetadataETag());
}
writer.writeStartElement(APP, "workspace", NS_APP);
- final Edm edm = metadata.getEdm();
-
- writer.writeStartElement(ATOM, "title", NS_APP);
- writer.writeCharacters(edm.getEntityContainer(null).getFullQualifiedName().getFullQualifiedNameAsString());
+ final EdmEntityContainer container = metadata.getEdm().getEntityContainer();
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
+ writer.writeCharacters(container.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement();
- writeEntitySets(writer, edm);
- writeFunctionImports(writer, edm);
- writeSingletons(writer, edm);
+ writeEntitySets(writer, container);
+ writeFunctionImports(writer, container);
+ writeSingletons(writer, container);
writeServiceDocuments(writer);
writer.writeEndElement(); // end workspace
writer.writeEndElement(); // end service
}
private void writeServiceDocuments(XMLStreamWriter writer) throws XMLStreamException {
-
- for (EdmxReference reference : this.metadata.getReferences()) {
- writer.writeStartElement(METADATA, "service-document", NS_METADATA);
- writer.writeAttribute("href", reference.getUri().toASCIIString());
- writer.writeStartElement(ATOM, "title", NS_ATOM);
- writer.writeCharacters(reference.getUri().toASCIIString());
- writer.writeEndElement();
- writer.writeEndElement();
+ for (EdmxReference reference : metadata.getReferences()) {
+ final String referenceString = reference.getUri().toASCIIString();
+ writeElement(writer, false, "service-document", referenceString, referenceString);
}
}
- private void writeEntitySets(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
- EdmEntityContainer container = edm.getEntityContainer(null);
+ private void writeEntitySets(final XMLStreamWriter writer, final EdmEntityContainer container)
+ throws XMLStreamException {
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
if (edmEntitySet.isIncludeInServiceDocument()) {
- writer.writeStartElement(APP, "collection", NS_APP);
- writer.writeAttribute("href", edmEntitySet.getName());
- writer.writeStartElement(ATOM, "title", NS_ATOM);
- writer.writeCharacters(edmEntitySet.getName());
- writer.writeEndElement();
- writer.writeEndElement();
+ writeElement(writer, true, "collection", edmEntitySet.getName(), edmEntitySet.getName());
}
}
}
- private void writeFunctionImports(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
- EdmEntityContainer container = edm.getEntityContainer(null);
-
+ private void writeFunctionImports(final XMLStreamWriter writer, final EdmEntityContainer container)
+ throws XMLStreamException {
for (EdmFunctionImport edmFunctionImport : container.getFunctionImports()) {
if (edmFunctionImport.isIncludeInServiceDocument()) {
- writer.writeStartElement(METADATA, "function-import", NS_METADATA);
- writer.writeAttribute("href", edmFunctionImport.getName());
- writer.writeStartElement(ATOM, "title", NS_ATOM);
- writer.writeCharacters(edmFunctionImport.getName());
- writer.writeEndElement();
- writer.writeEndElement();
+ writeElement(writer, false, "function-import", edmFunctionImport.getName(), edmFunctionImport.getName());
}
}
}
- private void writeSingletons(final XMLStreamWriter writer, final Edm edm) throws XMLStreamException {
- EdmEntityContainer container = edm.getEntityContainer(null);
+ private void writeSingletons(final XMLStreamWriter writer, final EdmEntityContainer container)
+ throws XMLStreamException {
for (EdmSingleton edmSingleton : container.getSingletons()) {
- writer.writeStartElement(METADATA, "singleton", NS_METADATA);
- writer.writeAttribute("href", edmSingleton.getName());
- writer.writeStartElement(ATOM, "title", NS_ATOM);
- writer.writeCharacters(edmSingleton.getName());
- writer.writeEndElement();
- writer.writeEndElement();
+ writeElement(writer, false, "singleton", edmSingleton.getName(), edmSingleton.getName());
}
}
+
+ private void writeElement(XMLStreamWriter writer, final boolean isApp, final String kind, final String reference,
+ final String title) throws XMLStreamException {
+ if (isApp) {
+ writer.writeStartElement(APP, kind, NS_APP);
+ } else {
+ writer.writeStartElement(METADATA, kind, NS_METADATA);
+ }
+ writer.writeAttribute(Constants.ATTR_HREF, reference);
+ writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
+ writer.writeCharacters(title);
+ writer.writeEndElement();
+ writer.writeEndElement();
+ }
}
[07/11] olingo-odata4 git commit: [OLINGO-795] server support for
Enums and Type Definitions
Posted by ch...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
deleted file mode 100644
index 25dcb03..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java
+++ /dev/null
@@ -1,372 +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.edm.provider;
-
-import static org.hamcrest.CoreMatchers.containsString;
-import static org.junit.Assert.assertArrayEquals;
-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.assertThat;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-import static org.mockito.Mockito.mock;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmEnumType;
-import org.apache.olingo.commons.api.edm.EdmException;
-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.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.core.edm.EdmEnumTypeImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-import org.mockito.Mockito;
-
-public class EdmEnumTest {
-
- private final EdmEnumType instance;
- private final EdmEnumType otherInstance;
- private final EdmEnumType nonFlagsInstance;
- private final EdmEnumType int16EnumType;
- private final EdmEnumType int32EnumType;
- private final EdmEnumType int32FlagType;
-
- public EdmEnumTest() {
- final List<CsdlEnumMember> memberList = Arrays.asList(
- new CsdlEnumMember().setName("first").setValue("1"),
- new CsdlEnumMember().setName("second").setValue("64"));
-
- final FullQualifiedName enumName = new FullQualifiedName("namespace", "name");
-
- instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- otherInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName,
- new CsdlEnumType().setName("name").setMembers(memberList).setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName()));
-
- int16EnumType = new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
- .setMembers(
- Arrays.asList(
- new CsdlEnumMember().setName("A")
- .setValue("0"),
- new CsdlEnumMember().setName("B")
- .setValue("1"),
- new CsdlEnumMember().setName("C")
- .setValue("2"))));
-
- int32EnumType =
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(
- Arrays
- .asList(new CsdlEnumMember().setName("A").setValue("0"), new CsdlEnumMember().setName("B")
- .setValue("1"),
- new CsdlEnumMember().setName("C").setValue("2"))));
-
- int32FlagType =
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"), new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(true)
- .setUnderlyingType(EdmPrimitiveTypeKind.Int32.getFullQualifiedName())
- .setMembers(
- Arrays
- .asList(new CsdlEnumMember().setName("A").setValue("2"), new CsdlEnumMember().setName("B")
- .setValue("4"),
- new CsdlEnumMember().setName("C").setValue("8"))));
- }
-
- @Test
- public void nameSpace() throws Exception {
- assertEquals("namespace", instance.getNamespace());
- }
-
- @Test
- public void name() throws Exception {
- assertEquals("name", instance.getName());
- }
-
- @Test
- public void kind() throws Exception {
- assertEquals(EdmTypeKind.ENUM, instance.getKind());
- }
-
- @Test
- public void compatibility() {
- assertTrue(instance.isCompatible(instance));
- assertTrue(instance.isCompatible(otherInstance));
- assertFalse(instance.isCompatible(instance.getUnderlyingType()));
- }
-
- @Test
- public void defaultType() throws Exception {
- assertEquals(Byte.class, instance.getDefaultType());
- EdmEnumType instance = new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType()
- .setName("MyEnum"));
- assertEquals(Integer.class, instance.getUnderlyingType().getDefaultType());
- }
-
- @Test
- public void members() throws Exception {
- assertArrayEquals(new String[] { "first", "second" }, instance.getMemberNames().toArray());
- assertEquals("64", instance.getMember("second").getValue());
- assertNull(instance.getMember("notExisting"));
- }
-
- @Test
- public void underlyingType() throws Exception {
- assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.SByte), instance.getUnderlyingType());
- }
-
- @Test
- public void validate() throws Exception {
- assertTrue(instance.validate(null, null, null, null, null, null));
- assertTrue(instance.validate(null, true, null, null, null, null));
- assertFalse(instance.validate(null, false, null, null, null, null));
- assertFalse(instance.validate("", null, null, null, null, null));
- assertFalse(instance.validate("something", null, null, null, null, null));
-
- assertTrue(instance.validate("second", null, null, null, null, null));
- assertTrue(instance.validate("first,second", null, null, null, null, null));
- assertTrue(instance.validate("64", null, null, null, null, null));
- assertTrue(instance.validate("1,64", null, null, null, null, null));
- }
-
- @Test
- public void toUriLiteral() throws Exception {
- assertNull(instance.toUriLiteral(null));
- assertEquals("namespace.name'first'", instance.toUriLiteral("first"));
- }
-
- @Test
- public void fromUriLiteral() throws Exception {
- assertNull(instance.fromUriLiteral(null));
- assertEquals("first", instance.fromUriLiteral("namespace.name'first'"));
-
- expectErrorInFromUriLiteral(instance, "");
- expectErrorInFromUriLiteral(instance, "name'first'");
- expectErrorInFromUriLiteral(instance, "namespace.name'first");
- expectErrorInFromUriLiteral(instance, "namespace.namespace'first");
- }
-
- @Test
- public void valueToString() throws Exception {
- assertNull(instance.valueToString(null, null, null, null, null, null));
- assertNull(instance.valueToString(null, true, null, null, null, null));
- assertEquals("first", instance.valueToString(1, null, null, null, null, null));
- assertEquals("first", instance.valueToString((byte) 1, null, null, null, null, null));
- assertEquals("first", instance.valueToString((short) 1, null, null, null, null, null));
- assertEquals("second", instance.valueToString(Integer.valueOf(64), null, null, null, null, null));
- assertEquals("second", instance.valueToString(64L, null, null, null, null, null));
- assertEquals("first,second", instance.valueToString(65, null, null, null, null, null));
-
- expectNullErrorInValueToString(instance);
- expectContentErrorInValueToString(instance, 3);
- expectTypeErrorInValueToString(instance, 1.0);
-
- assertEquals("A", int32EnumType.valueToString(0, false, 0, 0, 0, false));
- assertEquals("B", int32EnumType.valueToString(1, false, 0, 0, 0, false));
- assertEquals("C", int32EnumType.valueToString(2, false, 0, 0, 0, false));
-
- assertEquals("A", int16EnumType.valueToString(0, false, 0, 0, 0, false));
- assertEquals("B", int16EnumType.valueToString(1, false, 0, 0, 0, false));
- assertEquals("C", int16EnumType.valueToString(2, false, 0, 0, 0, false));
-
- assertEquals("A", int32FlagType.valueToString(2, false, 0, 0, 0, false));
- assertEquals("B", int32FlagType.valueToString(4, false, 0, 0, 0, false));
- assertEquals("C", int32FlagType.valueToString(8, false, 0, 0, 0, false));
- assertEquals("A,B", int32FlagType.valueToString(0x2 + 0x4, false, 0, 0, 0, false));
- assertEquals("B,C", int32FlagType.valueToString(0x4 + 0x8, false, 0, 0, 0, false));
- }
-
- @Test
- public void valueOfString() throws Exception {
- assertNull(instance.valueOfString(null, null, null, null, null, null, Byte.class));
- assertNull(instance.valueOfString(null, true, null, null, null, null, Byte.class));
- assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", null, null, null, null, null, Short.class));
- assertEquals(Integer.valueOf(1), instance.valueOfString("1", null, null, null, null, null, Integer.class));
- assertEquals(Long.valueOf(64L), instance.valueOfString("64", null, null, null, null, null, Long.class));
- assertEquals(Long.valueOf(1), instance.valueOfString("first", null, null, null, null, null, Long.class));
- assertEquals(Byte.valueOf((byte) 65), instance.valueOfString("first,64", null, null, null, null, null, Byte.class));
- assertEquals(Integer.valueOf(1), instance.valueOfString("1,1,first", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(1), nonFlagsInstance.valueOfString("1", null, null, null, null, null, Integer.class));
- expectContentErrorInValueOfString(nonFlagsInstance, "1,64");
-
- expectNullErrorInValueOfString(instance);
- expectContentErrorInValueOfString(instance, "2");
- expectContentErrorInValueOfString(instance, "1,");
- expectContentErrorInValueOfString(instance, ",1");
- expectTypeErrorInValueOfString(instance, "1");
-
- assertEquals(Integer.valueOf(0), int32EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(1), int32EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(2), int32EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(0), int16EnumType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(1), int16EnumType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(2), int16EnumType.valueOfString("C", null, null, null, null, null, Integer.class));
-
- assertEquals(Integer.valueOf(2), int32FlagType.valueOfString("A", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(4), int32FlagType.valueOfString("B", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(8), int32FlagType.valueOfString("C", null, null, null, null, null, Integer.class));
- assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("A,B", null, null, null, null, null,
- Integer.class));
- assertEquals(Integer.valueOf(0x4 + 0x8), int32FlagType.valueOfString("B,C", null, null, null, null, null,
- Integer.class));
- assertEquals(Integer.valueOf(0x2 + 0x4), int32FlagType.valueOfString("B,A", null, null, null, null, null,
- Integer.class));
- }
-
- private void expectErrorInValueToString(final EdmEnumType instance,
- final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode,
- final String message) {
- try {
- instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- private void expectErrorInUnderlyingType(
- final EdmPrimitiveTypeKind underlyingType,
- final String message) {
- try {
- new EdmEnumTypeImpl(Mockito.mock(Edm.class),
- new FullQualifiedName("testNamespace", "testName"),
- new CsdlEnumType()
- .setName("MyEnum")
- .setFlags(false)
- .setUnderlyingType(underlyingType.getFullQualifiedName())
- .setMembers(
- Arrays.asList(
- new CsdlEnumMember().setName("A")
- .setValue("0"))));
- fail("Expected exception not thrown");
- } catch (final EdmException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- @Test
- public void unsupportedUnderlyingType() throws Exception {
- // Test some random unsupported types
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Date, "");
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Geography, "");
- expectErrorInUnderlyingType(EdmPrimitiveTypeKind.Guid, "");
- }
-
- @Test
- public void outOfRangeValueToString() throws Exception {
- expectErrorInValueToString(int16EnumType, Integer.MAX_VALUE, null, null, null, null, null, "");
- }
-
- protected void expectErrorInFromUriLiteral(final EdmPrimitiveType instance, final String value) {
- try {
- instance.fromUriLiteral(value);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString("' has illegal content."));
- }
- }
-
- private void expectErrorInValueToString(final EdmPrimitiveType instance,
- final Object value, final Boolean isNullable, final Integer maxLength,
- final Integer precision, final Integer scale, final Boolean isUnicode,
- final String message) {
- try {
- instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
- expectErrorInValueToString(instance, null, false, null, null, null, null, "The value NULL is not allowed.");
- }
-
- protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
- expectErrorInValueToString(instance, value, null, null, null, null, null, "value type");
- }
-
- protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
- expectErrorInValueToString(instance, value, null, null, null, null, null, "' is not valid.");
- }
-
- private void expectErrorInValueOfString(final EdmPrimitiveType instance,
- final String value, final Boolean isNullable, final Integer maxLength, final Integer precision,
- final Integer scale, final Boolean isUnicode, final Class<?> returnType,
- final String message) {
-
- try {
- instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
- fail("Expected exception not thrown");
- } catch (final EdmPrimitiveTypeException e) {
- assertNotNull(e.getLocalizedMessage());
- assertThat(e.getLocalizedMessage(), containsString(message));
- }
- }
-
- protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
- expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
- "The value type class java.lang.Class is not supported.");
- }
-
- protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
- expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
- "illegal content");
- }
-
- protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
- expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
- "The literal 'null' is not allowed.");
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
deleted file mode 100644
index 63d21f5..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
+++ /dev/null
@@ -1,77 +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.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-
-public class EdmTypeDefinitionImplTest {
-
- @Test
- public void typeDefOnStringNoFacets() throws Exception {
- final FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
- final CsdlTypeDefinition providerTypeDef =
- new CsdlTypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("Edm", "String"));
- final EdmTypeDefinition typeDefImpl =
- new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
-
- assertEquals("name", typeDefImpl.getName());
- assertEquals("namespace", typeDefImpl.getNamespace());
- assertEquals(String.class, typeDefImpl.getDefaultType());
- assertEquals(EdmTypeKind.DEFINITION, typeDefImpl.getKind());
- assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeDefImpl.getUnderlyingType());
- assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)));
-
- // String validation
- assertEquals("'StringValue'", typeDefImpl.toUriLiteral("StringValue"));
- assertEquals("String''Value", typeDefImpl.fromUriLiteral("'String''''Value'"));
- assertTrue(typeDefImpl.validate("text", null, null, null, null, null));
- assertEquals("text", typeDefImpl.valueToString("text", null, null, null, null, null));
- assertEquals("text", typeDefImpl.valueOfString("text", null, null, null, null, null, String.class));
-
- // Facets must be initial
- assertNull(typeDefImpl.getMaxLength());
- assertNull(typeDefImpl.getPrecision());
- assertNull(typeDefImpl.getScale());
- assertTrue(typeDefImpl.isUnicode());
- }
-
- @Test(expected = EdmException.class)
- public void invalidTypeResultsInEdmException() throws Exception {
- FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
- CsdlTypeDefinition providerTypeDef =
- new CsdlTypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
- EdmTypeDefinitionImpl def = new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
- def.getUnderlyingType();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java
index 04bf11d..1fdb256 100644
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java
+++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java
@@ -23,7 +23,6 @@ import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import java.io.InputStream;
-import java.util.ArrayList;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
@@ -43,7 +42,6 @@ import org.apache.olingo.server.api.serializer.SerializerException;
import org.apache.olingo.server.core.ServiceMetadataImpl;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mockito;
public class ServiceDocumentXmlSerializerTest {
private static ODataSerializer serializer;
@@ -52,16 +50,16 @@ public class ServiceDocumentXmlSerializerTest {
public static void init() throws SerializerException {
serializer = OData.newInstance().createSerializer(ContentType.APPLICATION_ATOM_XML);
}
-
+
@Test
public void writeServiceWithEmptyMockedEdm() throws Exception {
final Edm edm = mock(Edm.class);
EdmEntityContainer container = mock(EdmEntityContainer.class);
- Mockito.stub(container.getFullQualifiedName()).toReturn(new FullQualifiedName("service.test"));
- when(container.getEntitySets()).thenReturn(new ArrayList<EdmEntitySet>());
- when(container.getFunctionImports()).thenReturn(new ArrayList<EdmFunctionImport>());
- when(container.getSingletons()).thenReturn(new ArrayList<EdmSingleton>());
- when(edm.getEntityContainer(null)).thenReturn(container);
+ when(container.getFullQualifiedName()).thenReturn(new FullQualifiedName("service", "test"));
+ when(container.getEntitySets()).thenReturn(Collections.<EdmEntitySet> emptyList());
+ when(container.getFunctionImports()).thenReturn(Collections.<EdmFunctionImport> emptyList());
+ when(container.getSingletons()).thenReturn(Collections.<EdmSingleton> emptyList());
+ when(edm.getEntityContainer()).thenReturn(container);
ServiceMetadata metadata = mock(ServiceMetadata.class);
when(metadata.getEdm()).thenReturn(edm);
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
index 01af921..ccc7de5 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java
@@ -1138,7 +1138,11 @@ public class DataCreator {
}
protected static Property createPrimitiveCollection(final String name, final Object... values) {
- return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, Arrays.asList(values));
+ List<Object> propertyValues = new ArrayList<Object>();
+ for (final Object value : values) {
+ propertyValues.add(value);
+ }
+ return new Property(null, name, ValueType.COLLECTION_PRIMITIVE, propertyValues);
}
protected static Property createComplex(final String name, final Property... properties) {
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/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 f9e2ee2..a4f63f1 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
@@ -48,6 +48,7 @@ import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
import org.apache.olingo.commons.api.edm.EdmStructuredType;
+import org.apache.olingo.commons.api.edm.EdmType;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.commons.api.http.HttpStatusCode;
@@ -235,9 +236,10 @@ public class DataProvider {
private Property createProperty(final EdmProperty edmProperty, final String propertyName)
throws DataProviderException {
+ final EdmType type = edmProperty.getType();
Property newProperty;
-
- if (edmProperty.isPrimitive()) {
+ if (edmProperty.isPrimitive()
+ || type.getKind() == EdmTypeKind.ENUM || type.getKind() == EdmTypeKind.DEFINITION) {
newProperty = edmProperty.isCollection() ?
DataCreator.createPrimitiveCollection(propertyName) :
DataCreator.createPrimitive(propertyName, null);
@@ -248,10 +250,9 @@ public class DataProvider {
newProperty = newProperty2;
} else {
newProperty = DataCreator.createComplex(propertyName);
- createProperties((EdmComplexType) edmProperty.getType(), newProperty.asComplex().getValue());
+ createProperties((EdmComplexType) type, newProperty.asComplex().getValue());
}
}
-
return newProperty;
}
@@ -414,40 +415,36 @@ public class DataProvider {
@SuppressWarnings("unchecked")
public void updateProperty(final EdmProperty edmProperty, Property property, final Property newProperty,
final boolean patch) throws DataProviderException {
- if (edmProperty.isPrimitive()) {
- if (newProperty != null || !patch) {
- final Object value = newProperty == null ? null : newProperty.getValue();
- updatePropertyValue(property, value);
- }
- } else if (edmProperty.isCollection()) {
+ final EdmType type = edmProperty.getType();
+ if (edmProperty.isCollection()) {
// Updating collection properties means replacing all entries with the given ones.
property.asCollection().clear();
if (newProperty != null) {
- if (edmProperty.getType().getKind() == EdmTypeKind.COMPLEX) {
- // Complex type
- final List<ComplexValue> complexValues = (List<ComplexValue>) newProperty.asCollection();
-
- // Create each complex value
- for (final ComplexValue complexValue : complexValues) {
+ if (type.getKind() == EdmTypeKind.COMPLEX) {
+ // Create each complex value.
+ for (final ComplexValue complexValue : (List<ComplexValue>) newProperty.asCollection()) {
((List<ComplexValue>) property.asCollection()).add(createComplexValue(edmProperty, complexValue, patch));
}
} else {
// Primitive type
- final List<Object> values = (List<Object>) newProperty.asCollection();
- ((List<Object>) property.asCollection()).addAll(values);
+ ((List<Object>) property.asCollection()).addAll(newProperty.asCollection());
}
}
- } else {
- final EdmComplexType type = (EdmComplexType) edmProperty.getType();
- for (final String propertyName : type.getPropertyNames()) {
+ } else if (type.getKind() == EdmTypeKind.COMPLEX) {
+ for (final String propertyName : ((EdmComplexType) type).getPropertyNames()) {
final List<Property> newProperties = newProperty == null || newProperty.asComplex() == null ? null :
newProperty.asComplex().getValue();
- updateProperty(type.getStructuralProperty(propertyName),
+ updateProperty(((EdmComplexType) type).getStructuralProperty(propertyName),
findProperty(propertyName, property.asComplex().getValue()),
newProperties == null ? null : findProperty(propertyName, newProperties),
patch);
}
+ } else {
+ if (newProperty != null || !patch) {
+ final Object value = newProperty == null ? null : newProperty.getValue();
+ updatePropertyValue(property, value);
+ }
}
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
index 690e1d3..c8c4549 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/PropertyProvider.java
@@ -777,12 +777,10 @@ public class PropertyProvider {
// TypeDefinition Properties ---------------------------------------------------------------------------------------
public static final CsdlProperty propertyTypeDefinition_TDString = new CsdlProperty()
.setName("PropertyDefString")
- .setType(TypeDefinitionProvider.nameTDString)
- .setMaxLength(15);
+ .setType(TypeDefinitionProvider.nameTDString);
public static final CsdlProperty collPropertyTypeDefinition_TDString = new CsdlProperty()
.setName("CollPropertyDefString")
.setType(TypeDefinitionProvider.nameTDString)
- .setMaxLength(15)
.setCollection(true);
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
index 3a357a2..1c2be72 100644
--- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
+++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/TypeDefinitionProvider.java
@@ -28,10 +28,10 @@ public class TypeDefinitionProvider {
public CsdlTypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) {
if (nameTDString.equals(typeDefinitionName)) {
- return new CsdlTypeDefinition().setName(nameTDString.getName()).setUnderlyingType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()).setMaxLength(15);
+ return new CsdlTypeDefinition().setName(nameTDString.getName())
+ .setUnderlyingType(EdmPrimitiveTypeKind.String.getFullQualifiedName())
+ .setMaxLength(15);
}
return null;
}
-
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/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 f3899d1..fbaf085 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
@@ -466,6 +466,10 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe
Property complexProperty = entity.getProperty("PropertyCompMixedEnumDef");
List<Property> value = complexProperty.asComplex().getValue();
assertEquals((short) 2, value.get(0).getValue());
+
+ defProperty = ((ComplexValue) entity.getProperty("CollPropertyCompMixedEnumDef").asCollection().get(1))
+ .getValue().get(2);
+ assertEquals("string", defProperty.getValue());
stream.close();
}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/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 71f4d35..8b9431b 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
@@ -25,21 +25,15 @@ import java.util.Arrays;
import java.util.List;
import java.util.UUID;
+import org.apache.olingo.commons.api.Constants;
import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.Entity;
import org.apache.olingo.commons.api.data.Link;
import org.apache.olingo.commons.api.data.Property;
-import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.EdmEntityContainer;
import org.apache.olingo.commons.api.edm.EdmEntitySet;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
-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.EdmDate;
import org.apache.olingo.commons.core.edm.primitivetype.EdmDateTimeOffset;
@@ -50,7 +44,6 @@ import org.custommonkey.xmlunit.XMLUnit;
import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
-import org.mockito.Mockito;
public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
@@ -264,7 +257,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Assert.assertNotNull(result.getProperty("PropertyComp"));
Property comp = result.getProperty("PropertyComp");
Assert.assertEquals("olingo.odata.test1.CTAllPrim", comp.getType());
- ComplexValue cv = (ComplexValue)comp.getValue();
+ ComplexValue cv = comp.asComplex();
Assert.assertEquals(16, cv.getValue().size());
@@ -277,14 +270,14 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
}
private Property getCVProperty(ComplexValue cv, String name) {
- for (Property p:cv.getValue()) {
+ for (Property p : cv.getValue()) {
if (p.getName().equals(name)) {
return p;
}
}
return null;
}
-
+
@Test
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
@@ -336,7 +329,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Property comp = result.getProperty("PropertyComp");
Assert.assertEquals("olingo.odata.test1.CTTwoPrim", comp.getType());
- ComplexValue cv = (ComplexValue)comp.getValue();
+ ComplexValue cv = comp.asComplex();
Assert.assertEquals(2, cv.getValue().size());
Assert.assertEquals((short) 111, getCVProperty(cv, "PropertyInt16").asPrimitive());
@@ -344,21 +337,85 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
comp = result.getProperty("CollPropertyComp");
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", comp.getType());
- @SuppressWarnings("unchecked")
- List<ComplexValue> properties = (List<ComplexValue>)comp.getValue();
-
+
+ List<?> properties = comp.asCollection();
Assert.assertEquals(3, properties.size());
- Assert.assertEquals((short) 123,
- getCVProperty(properties.get(0), "PropertyInt16").asPrimitive());
- Assert.assertEquals("TEST 1",
- getCVProperty(properties.get(0), "PropertyString").asPrimitive());
+ Assert.assertEquals((short) 123, getCVProperty((ComplexValue) properties.get(0), "PropertyInt16").asPrimitive());
+ Assert.assertEquals("TEST 1", getCVProperty((ComplexValue) properties.get(0), "PropertyString").asPrimitive());
- Assert.assertEquals((short) 789, getCVProperty(properties.get(2), "PropertyInt16").asPrimitive());
- Assert.assertEquals("TEST 3", getCVProperty(properties.get(2), "PropertyString")
- .asPrimitive());
+ Assert.assertEquals((short) 789, getCVProperty((ComplexValue) properties.get(2), "PropertyInt16").asPrimitive());
+ Assert.assertEquals("TEST 3", getCVProperty((ComplexValue) properties.get(2), "PropertyString").asPrimitive());
}
-
+
+ @Test
+ public void entityMixEnumDefCollComp() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
+ final String payload = "<?xml version='1.0' encoding='UTF-8'?>\n"
+ + "<a:entry xmlns:a=\"" + Constants.NS_ATOM + "\""
+ + " xmlns:m=\"" + Constants.NS_METADATA + "\" xmlns:d=\"" + Constants.NS_DATASERVICES + "\">\n"
+ + " <a:content type=\"application/xml\">\n"
+ + " <m:properties>\n"
+ + " <d:PropertyInt16 m:type=\"Int16\">1</d:PropertyInt16>\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " <d:PropertyCompMixedEnumDef m:type=\"#olingo.odata.test1.CTMixEnumDef\">\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " </d:PropertyCompMixedEnumDef>\n"
+ + " <d:CollPropertyCompMixedEnumDef m:type=\"#Collection(olingo.odata.test1.CTMixEnumDef)\">\n"
+ + " <m:element>\n"
+ + " <d:PropertyEnumString m:type=\"#olingo.odata.test1.ENString\">String2,String3"
+ + "</d:PropertyEnumString>\n"
+ + " <d:CollPropertyEnumString m:type=\"#Collection(olingo.odata.test1.ENString)\">\n"
+ + " <m:element>String2</m:element>\n"
+ + " <m:element>String3</m:element>\n"
+ + " <m:element>String2,String3</m:element>\n"
+ + " </d:CollPropertyEnumString>\n"
+ + " <d:PropertyDefString m:type=\"#olingo.odata.test1.TDString\">Test</d:PropertyDefString>\n"
+ + " <d:CollPropertyDefString m:type=\"#Collection(olingo.odata.test1.TDString)\">\n"
+ + " <m:element>Test1</m:element>\n"
+ + " <m:element>Test2</m:element>\n"
+ + " </d:CollPropertyDefString>\n"
+ + " </m:element>\n"
+ + " </d:CollPropertyCompMixedEnumDef>\n"
+ + " </m:properties>\n"
+ + " </a:content>\n"
+ + "</a:entry>";
+ final Entity result = deserializer.entity(new ByteArrayInputStream(payload.getBytes()),
+ edmEntitySet.getEntityType()).getEntity();
+
+ Assert.assertEquals(7, result.getProperties().size());
+
+ Assert.assertEquals((short) 1, result.getProperty("PropertyInt16").asPrimitive());
+ Assert.assertEquals((short) 6, result.getProperty("PropertyEnumString").asEnum());
+ Assert.assertEquals(3, result.getProperty("CollPropertyEnumString").asCollection().size());
+ Assert.assertEquals("Test", result.getProperty("PropertyDefString").asPrimitive());
+ Assert.assertEquals(2, result.getProperty("CollPropertyDefString").asCollection().size());
+ Assert.assertEquals(4, result.getProperty("PropertyCompMixedEnumDef").asComplex().getValue().size());
+ Assert.assertEquals(1, result.getProperty("CollPropertyCompMixedEnumDef").asCollection().size());
+ }
+
@Test
public void entityWithNavigation() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
@@ -461,54 +518,30 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
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());
-
}
-
+
@Test
public void complexProperty() throws Exception {
- Edm edm = Mockito.mock(Edm.class);
-
- CsdlProperty street = new CsdlProperty().setName("Street")
- .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
- CsdlProperty city = new CsdlProperty().setName("City")
- .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
- CsdlProperty region = new CsdlProperty().setName("Region")
- .setType(EdmPrimitiveTypeKind.String.getFullQualifiedName());
- CsdlProperty postalcode = new CsdlProperty().setName("PostalCode")
- .setType(EdmPrimitiveTypeKind.Int64.getFullQualifiedName());
-
- CsdlComplexType ct = new CsdlComplexType()
- .setName("Model.Address")
- .setProperties(Arrays.asList(street, city, region, postalcode));
- EdmComplexTypeImpl complexType = new EdmComplexTypeImpl(edm, new FullQualifiedName("Model.Address"), ct);
-
- Mockito.stub(edm.getComplexType(new FullQualifiedName("Model.Address"))).toReturn(complexType);
-
- CsdlProperty prop = new CsdlProperty();
- prop.setName("ShipTo");
- prop.setType(new FullQualifiedName("Model.Address"));
- EdmPropertyImpl edmProperty = new EdmPropertyImpl(edm, null, prop);
-
- String payload = "<data:ShipTo xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" " +
- " xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
- " metadata:type=\"#Model.Address\">\n" +
- " <data:Street>Obere Str. 57</data:Street>\n" +
- " <data:City>Berlin</data:City>\n" +
- " <data:Region metadata:null=\"true\"/>\n" +
- " <data:PostalCode>12209</data:PostalCode>\n" +
- "</data:ShipTo>";
-
- Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
+ final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp");
+ final String payload = "<data:PropertyComp xmlns:data=\"http://docs.oasis-open.org/odata/ns/data\" "
+ + " xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n"
+ + " metadata:type=\"#olingo.odata.test1.CTTwoPrim\">\n"
+ + " <data:PropertyInt16>123</data:PropertyInt16>\n"
+ + " <data:PropertyString metadata:null=\"true\"/>\n"
+ + "</data:PropertyComp>";
- Assert.assertEquals("ShipTo", result.getName());
- Assert.assertTrue(result.getValue() instanceof ComplexValue);
- ComplexValue cv = (ComplexValue)result.getValue();
- Assert.assertEquals("Model.Address", result.getType());
- Assert.assertEquals("Berlin", getCVProperty(cv, "City").asPrimitive());
- Assert.assertEquals("Obere Str. 57", getCVProperty(cv, "Street").asPrimitive());
+ final Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty)
+ .getProperty();
+
+ Assert.assertEquals("PropertyComp", result.getName());
+ Assert.assertTrue(result.isComplex());
+ final ComplexValue cv = result.asComplex();
+ Assert.assertEquals("olingo.odata.test1.CTTwoPrim", result.getType());
+ Assert.assertEquals((short) 123, getCVProperty(cv, "PropertyInt16").asPrimitive());
+ Assert.assertTrue(getCVProperty(cv, "PropertyString").isNull());
}
-
- @SuppressWarnings("unchecked")
+
@Test
public void complexCollectionProperty() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
@@ -531,16 +564,20 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
"</metadata:value>";
Property result = deserializer.property(new ByteArrayInputStream(payload.getBytes()), edmProperty).getProperty();
- List<ComplexValue> complex = (List<ComplexValue>)result.getValue();
-
- Assert.assertEquals(3, complex.size());
+ List<?> complexCollection = result.asCollection();
+
+ Assert.assertEquals(3, complexCollection.size());
Assert.assertEquals("Collection(olingo.odata.test1.CTTwoPrim)", result.getType());
- Assert.assertEquals((short) 123, getCVProperty(complex.get(0), "PropertyInt16").asPrimitive());
- Assert.assertEquals("TEST 1", getCVProperty(complex.get(0), "PropertyString").asPrimitive());
- Assert.assertEquals((short) 789, getCVProperty(complex.get(2), "PropertyInt16").asPrimitive());
- Assert.assertEquals("TEST 3", getCVProperty(complex.get(2), "PropertyString").asPrimitive());
+ Assert.assertEquals((short) 123,
+ getCVProperty((ComplexValue) complexCollection.get(0), "PropertyInt16").asPrimitive());
+ Assert.assertEquals("TEST 1",
+ getCVProperty((ComplexValue) complexCollection.get(0), "PropertyString").asPrimitive());
+ Assert.assertEquals((short) 789,
+ getCVProperty((ComplexValue) complexCollection.get(2), "PropertyInt16").asPrimitive());
+ Assert.assertEquals("TEST 3",
+ getCVProperty((ComplexValue) complexCollection.get(2), "PropertyString").asPrimitive());
}
-
+
@Test
public void entityReference() throws Exception {
String payload = "<metadata:ref xmlns:metadata=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@@ -553,7 +590,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
Assert.assertEquals(1, result.size());
Assert.assertEquals("http://host/service/Orders(10643)", result.get(0).toASCIIString());
}
-
+
@Test
public void entityReferences() throws Exception {
String payload = "<feed xmlns=\"http://www.w3.org/2005/Atom\"\n" +
@@ -562,7 +599,7 @@ public class ODataXmlDeserializerTest extends AbstractODataDeserializerTest {
" <metadata:ref id=\"http://host/service/Orders(10643)\" />\n" +
" <metadata:ref id=\"http://host/service/Orders(10759)\" />\n" +
"</feed>";
-
+
List<URI> result = deserializer.entityReferences(new ByteArrayInputStream(payload.getBytes()))
.getEntityReferences();
Assert.assertEquals(2, result.size());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
index a882fa6..b5da9ae 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java
@@ -24,6 +24,7 @@ import java.util.Arrays;
import java.util.Collections;
import org.apache.commons.io.IOUtils;
+import org.apache.olingo.commons.api.data.ComplexValue;
import org.apache.olingo.commons.api.data.ContextURL;
import org.apache.olingo.commons.api.data.ContextURL.Suffix;
import org.apache.olingo.commons.api.data.Entity;
@@ -113,7 +114,7 @@ public class ODataJsonSerializerTest {
public void entityAllPrimAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
+ entity.getProperties().retainAll(Collections.singletonList(entity.getProperties().get(0)));
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
entity,
EntitySerializerOptions.with()
@@ -292,7 +293,7 @@ public class ODataJsonSerializerTest {
public void entityMixPrimCollCompAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
- entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0)));
+ entity.getProperties().retainAll(Collections.singletonList(entity.getProperties().get(0)));
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@@ -305,6 +306,45 @@ public class ODataJsonSerializerTest {
}
@Test
+ public void enumAndTypeDefinition() throws Exception {
+ final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixEnumDefCollComp");
+ Entity entity = new Entity();
+ entity.addProperty(new Property(null, "PropertyInt16", ValueType.PRIMITIVE, 1));
+ entity.addProperty(new Property(null, "PropertyEnumString", ValueType.ENUM, 6));
+ entity.addProperty(new Property(null, "CollPropertyEnumString", ValueType.COLLECTION_ENUM,
+ Arrays.asList(2, 4, 6)));
+ entity.addProperty(new Property(null, "PropertyDefString", ValueType.PRIMITIVE, "Test"));
+ entity.addProperty(new Property(null, "CollPropertyDefString", ValueType.COLLECTION_PRIMITIVE,
+ Arrays.asList("Test1", "Test2")));
+ ComplexValue complexValue = new ComplexValue();
+ complexValue.getValue().add(entity.getProperty("PropertyEnumString"));
+ complexValue.getValue().add(entity.getProperty("CollPropertyEnumString"));
+ complexValue.getValue().add(entity.getProperty("PropertyDefString"));
+ complexValue.getValue().add(entity.getProperty("CollPropertyDefString"));
+ entity.addProperty(new Property(null, "PropertyCompMixedEnumDef", ValueType.COMPLEX, complexValue));
+ entity.addProperty(new Property(null, "CollPropertyCompMixedEnumDef", ValueType.COLLECTION_COMPLEX,
+ Collections.singletonList(complexValue)));
+ final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
+ EntitySerializerOptions.with()
+ .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
+ .build()).getContent());
+ Assert.assertEquals("{\"@odata.context\":\"$metadata#ESMixEnumDefCollComp/$entity\","
+ + "\"@odata.metadataEtag\":\"W/\\\"metadataETag\\\"\","
+ + "\"PropertyInt16\":1,"
+ + "\"PropertyEnumString\":\"String2,String3\","
+ + "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ + "\"PropertyDefString\":\"Test\","
+ + "\"CollPropertyDefString\":[\"Test1\",\"Test2\"],"
+ + "\"PropertyCompMixedEnumDef\":{\"PropertyEnumString\":\"String2,String3\","
+ + "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ + "\"PropertyDefString\":\"Test\",\"CollPropertyDefString\":[\"Test1\",\"Test2\"]},"
+ + "\"CollPropertyCompMixedEnumDef\":[{\"PropertyEnumString\":\"String2,String3\","
+ + "\"CollPropertyEnumString\":[\"String2\",\"String3\",\"String2,String3\"],"
+ + "\"PropertyDefString\":\"Test\",\"CollPropertyDefString\":[\"Test1\",\"Test2\"]}]}",
+ resultString);
+ }
+
+ @Test
public void entityTwoPrimNoMetadata() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
@@ -452,7 +492,7 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp");
final EdmEntityType entityType = edmEntitySet.getEntityType();
final EntityCollection entitySet = data.readAll(edmEntitySet);
- final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+ final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
InputStream result = serializer
.entityCollection(metadata, entityType, entitySet,
@@ -501,7 +541,7 @@ public class ODataJsonSerializerTest {
public void expand() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
- final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
+ final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
@@ -537,11 +577,11 @@ public class ODataJsonSerializerTest {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim");
final EdmEntityType entityType = edmEntitySet.getEntityType();
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
- final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+ final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate")));
ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne");
Mockito.when(expandItem.getSelectOption()).thenReturn(select);
- final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem));
+ final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItem));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
@@ -568,7 +608,7 @@ public class ODataJsonSerializerTest {
Mockito.when(expandItemAll.isStar()).thenReturn(true);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
expandItem, expandItem, expandItemAll));
- final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+ final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
@@ -595,8 +635,8 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemAll = Mockito.mock(ExpandItem.class);
Mockito.when(expandItemAll.isStar()).thenReturn(true);
- final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemAll));
- final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+ final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemAll));
+ final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay")));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
@@ -623,13 +663,13 @@ public class ODataJsonSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(1);
ExpandItem expandItemSecond = Mockito.mock(ExpandItem.class);
Mockito.when(expandItemSecond.isStar()).thenReturn(true);
- final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemSecond));
+ final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemSecond));
ExpandItem expandItemFirst = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany");
Mockito.when(expandItemFirst.getExpandOption()).thenReturn(expandInner);
- final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
+ final SelectOption select = ExpandSelectMock.mockSelectOption(Collections.singletonList(
ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32")));
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
- final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
+ final ExpandOption expand = ExpandSelectMock.mockExpandOption(Collections.singletonList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
index 066103c..3b5f58f 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
@@ -30,20 +30,29 @@ import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ServiceMetadata;
import org.apache.olingo.server.api.edmx.EdmxReference;
+import org.apache.olingo.server.api.etag.ServiceMetadataETagSupport;
import org.apache.olingo.server.api.serializer.ODataSerializer;
-import org.apache.olingo.server.tecsvc.MetadataETagSupport;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
public class ServiceDocumentTest {
+ private static final String serviceRoot = "http://localhost:8080/odata.svc";
private static final ServiceMetadata metadata = OData.newInstance().createServiceMetadata(
- new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("W/\"metadataETag\""));
+ new EdmTechProvider(), Collections.<EdmxReference> emptyList(),
+ new ServiceMetadataETagSupport() {
+ @Override
+ public String getServiceDocumentETag() {
+ return "W/\"serviceDocumentETag\"";
+ }
+ @Override
+ public String getMetadataETag() {
+ return "W/\"metadataETag\"";
+ }
+ });
@Test
public void writeServiceDocumentJson() throws Exception {
- final String serviceRoot = "http://localhost:8080/odata.svc";
-
OData server = OData.newInstance();
assertNotNull(server);
@@ -54,7 +63,8 @@ public class ServiceDocumentTest {
assertNotNull(result);
final String jsonString = IOUtils.toString(result);
- assertTrue(jsonString.contains(metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
+ assertTrue(jsonString.contains(
+ metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
assertTrue(jsonString.contains("ESAllPrim"));
assertTrue(jsonString.contains("ESCollAllPrim"));
@@ -75,7 +85,6 @@ public class ServiceDocumentTest {
@Test
public void serviceDocumentNoMetadata() throws Exception {
- final String serviceRoot = "http://localhost:8080/odata.svc";
final String result = IOUtils.toString(
OData.newInstance().createSerializer(ContentType.JSON_NO_METADATA)
.serviceDocument(metadata, serviceRoot).getContent());
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/5d364dfa/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
index 6f59060..a55398f 100644
--- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -23,8 +23,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import java.net.URI;
-import java.util.Arrays;
-import java.util.List;
+import java.util.Collections;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.format.ContentType;
@@ -44,7 +43,10 @@ public class MetadataDocumentTest {
public void writeMetadataWithTechnicalScenario() throws Exception {
final OData odata = OData.newInstance();
final ServiceMetadata serviceMetadata = odata.createServiceMetadata(
- new EdmTechProvider(), getEdmxReferences());
+ new EdmTechProvider(),
+ Collections.singletonList(
+ new EdmxReference(URI.create(CORE_VOCABULARY))
+ .addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"))));
final String metadata = IOUtils.toString(
odata.createSerializer(ContentType.APPLICATION_XML).metadataDocument(serviceMetadata).getContent());
@@ -138,23 +140,8 @@ public class MetadataDocumentTest {
// TypeDefCheck
assertThat(metadata,
- containsString("<Property Name=\"PropertyDefString\" Type=\"Namespace1_Alias.TDString\" MaxLength=\"15\"/>"));
- assertThat(metadata, containsString("<Property Name=\"CollPropertyDefString\" " +
- "Type=\"Collection(Namespace1_Alias.TDString)\" MaxLength=\"15\"/>"));
- }
-
- /**
- * <code>
- * <edmx:Reference Uri="http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml">
- * <edmx:Include Namespace="Org.OData.Core.V1" Alias="Core"/>
- * </edmx:Reference>
- * </code>
- *
- * @return default emdx reference
- */
- private List<EdmxReference> getEdmxReferences() {
- EdmxReference reference = new EdmxReference(URI.create(CORE_VOCABULARY));
- reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core"));
- return Arrays.asList(reference);
+ containsString("<Property Name=\"PropertyDefString\" Type=\"Namespace1_Alias.TDString\"/>"));
+ assertThat(metadata,
+ containsString("<Property Name=\"CollPropertyDefString\" Type=\"Collection(Namespace1_Alias.TDString)\"/>"));
}
}