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 2013/12/06 15:51:43 UTC
[07/21] [OLINGO-77] Refactored java package names
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32Test.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32Test.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32Test.java
new file mode 100644
index 0000000..db34161
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt32Test.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigInteger;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmInt32Test extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(Uint7.getInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Byte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.SByte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int16.getEdmPrimitiveTypeInstance()));
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("127", instance.toUriLiteral("127"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("127", instance.fromUriLiteral("127"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("0", instance.valueToString(0, null, null, null, null, null));
+ assertEquals("8", instance.valueToString((byte) 8, null, null, null, null, null));
+ assertEquals("16", instance.valueToString((short) 16, null, null, null, null, null));
+ assertEquals("32", instance.valueToString(Integer.valueOf(32), null, null, null, null, null));
+ assertEquals("255", instance.valueToString(255L, null, null, null, null, null));
+ assertEquals("-2147483648", instance.valueToString(BigInteger.valueOf(Integer.MIN_VALUE), null, null, null, null,
+ null));
+
+ expectContentErrorInValueToString(instance, 12345678901L);
+ expectContentErrorInValueToString(instance, -2147483649L);
+ expectContentErrorInValueToString(instance, BigInteger.valueOf(2147483648L));
+
+ expectTypeErrorInValueToString(instance, 1.0);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals(Byte.valueOf((byte) 1), instance.valueOfString("1", null, null, null, null, null, Byte.class));
+ assertEquals(Short.valueOf((short) 2), instance.valueOfString("2", null, null, null, null, null, Short.class));
+ assertEquals(Integer.valueOf(-10000000), instance.valueOfString("-10000000", null, null, null, null, null,
+ Integer.class));
+ assertEquals(Long.valueOf(10000000), instance.valueOfString("10000000", null, null, null, null, null, Long.class));
+ assertEquals(BigInteger.TEN, instance.valueOfString("10", null, null, null, null, null, BigInteger.class));
+
+ expectContentErrorInValueOfString(instance, "-2147483649");
+ expectContentErrorInValueOfString(instance, "1.0");
+
+ expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class);
+
+ expectTypeErrorInValueOfString(instance, "1");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64Test.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64Test.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64Test.java
new file mode 100644
index 0000000..6ebb0d4
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmInt64Test.java
@@ -0,0 +1,94 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigInteger;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmInt64Test extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.Int64.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(Uint7.getInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Byte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.SByte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int16.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance()));
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("127", instance.toUriLiteral("127"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("127", instance.fromUriLiteral("127"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("0", instance.valueToString(0, null, null, null, null, null));
+ assertEquals("8", instance.valueToString((byte) 8, null, null, null, null, null));
+ assertEquals("16", instance.valueToString((short) 16, null, null, null, null, null));
+ assertEquals("32", instance.valueToString(Integer.valueOf(32), null, null, null, null, null));
+ assertEquals("255", instance.valueToString(255L, null, null, null, null, null));
+ assertEquals("12345678901", instance.valueToString(12345678901L, null, null, null, null, null));
+ assertEquals("1234567890123456789", instance.valueToString(new BigInteger("1234567890123456789"), null, null, null,
+ null, null));
+ assertEquals("-1234567890123456789", instance.valueToString(new BigInteger("-1234567890123456789"), null, null,
+ null, null, null));
+
+ expectContentErrorInValueToString(instance, new BigInteger("123456789012345678901"));
+
+ expectTypeErrorInValueToString(instance, 1.0);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals(Short.valueOf((short) 1), instance.valueOfString("1", null, null, null, null, null, Short.class));
+ assertEquals(Integer.valueOf(2), instance.valueOfString("2", null, null, null, null, null, Integer.class));
+ assertEquals(Long.valueOf(-1234567890123456789L), instance.valueOfString("-1234567890123456789", null, null, null,
+ null, null, Long.class));
+ assertEquals(BigInteger.ONE, instance.valueOfString("1", null, null, null, null, null, BigInteger.class));
+ assertEquals(Long.valueOf(0), instance.valueOfString("0", null, null, null, null, null, Long.class));
+ assertEquals(Byte.valueOf((byte) 0), instance.valueOfString("0", null, null, null, null, null, Byte.class));
+
+ expectContentErrorInValueOfString(instance, "-12345678901234567890");
+ expectContentErrorInValueOfString(instance, "1.0");
+ expectContentErrorInValueOfString(instance, "0L");
+ expectContentErrorInValueOfString(instance, "0x42");
+
+ expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-2147483649", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "2147483648", Integer.class);
+
+ expectTypeErrorInValueOfString(instance, "1");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNullTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNullTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNullTest.java
new file mode 100644
index 0000000..9d39c55
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmNullTest.java
@@ -0,0 +1,49 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertNull;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmNullTest extends PrimitiveTypeBaseTest {
+
+ @Test
+ public void checkNull() throws Exception {
+ for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
+ final EdmPrimitiveType instance = kind.getEdmPrimitiveTypeInstance();
+ assertNull(instance.valueToString(null, null, null, null, null, null));
+ assertNull(instance.valueToString(null, true, null, null, null, null));
+
+ expectNullErrorInValueToString(instance);
+ }
+ }
+
+ @Test
+ public void checkValueOfNull() throws Exception {
+ for (EdmPrimitiveTypeKind kind : EdmPrimitiveTypeKind.values()) {
+ final EdmPrimitiveType instance = kind.getEdmPrimitiveTypeInstance();
+ assertNull(instance.valueOfString(null, null, null, null, null, null, instance.getDefaultType()));
+ assertNull(instance.valueOfString(null, true, null, null, null, null, instance.getDefaultType()));
+
+ expectNullErrorInValueOfString(instance);
+ }
+ }
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByteTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByteTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByteTest.java
new file mode 100644
index 0000000..249c4bc
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSByteTest.java
@@ -0,0 +1,80 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigInteger;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmSByteTest extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.SByte.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(Uint7.getInstance()));
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("127", instance.toUriLiteral("127"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("127", instance.fromUriLiteral("127"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("0", instance.valueToString(0, null, null, null, null, null));
+ assertEquals("8", instance.valueToString((byte) 8, null, null, null, null, null));
+ assertEquals("16", instance.valueToString((short) 16, null, null, null, null, null));
+ assertEquals("32", instance.valueToString(Integer.valueOf(32), null, null, null, null, null));
+ assertEquals("64", instance.valueToString(64L, null, null, null, null, null));
+ assertEquals("-128", instance.valueToString(BigInteger.valueOf(Byte.MIN_VALUE), null, null, null, null, null));
+
+ expectContentErrorInValueToString(instance, -129);
+ expectContentErrorInValueToString(instance, 128);
+ expectContentErrorInValueToString(instance, BigInteger.valueOf(128));
+
+ expectTypeErrorInValueToString(instance, 'A');
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals(Byte.valueOf((byte) 1), instance.valueOfString("1", null, null, null, null, null, Byte.class));
+ assertEquals(Short.valueOf((short) -2), instance.valueOfString("-2", null, null, null, null, null, Short.class));
+ assertEquals(Byte.valueOf((byte) 127), instance.valueOfString("127", null, null, null, null, null, Byte.class));
+ assertEquals(Byte.valueOf((byte) -128), instance.valueOfString("-128", null, null, null, null, null, Byte.class));
+ assertEquals(Integer.valueOf(0), instance.valueOfString("0", null, null, null, null, null, Integer.class));
+ assertEquals(Long.valueOf(0), instance.valueOfString("0", null, null, null, null, null, Long.class));
+ assertEquals(BigInteger.TEN, instance.valueOfString("10", null, null, null, null, null, BigInteger.class));
+
+ expectContentErrorInValueOfString(instance, "128");
+ expectContentErrorInValueOfString(instance, "-129");
+ expectContentErrorInValueOfString(instance, "1.0");
+
+ expectTypeErrorInValueOfString(instance, "1");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java
new file mode 100644
index 0000000..adfa8a1
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmSingleTest.java
@@ -0,0 +1,136 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+
+import java.math.BigDecimal;
+import java.math.BigInteger;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmSingleTest extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.Single.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void compatibility() {
+ assertTrue(instance.isCompatible(Uint7.getInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Byte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.SByte.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int16.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int32.getEdmPrimitiveTypeInstance()));
+ assertTrue(instance.isCompatible(EdmPrimitiveTypeKind.Int64.getEdmPrimitiveTypeInstance()));
+ }
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("127", instance.toUriLiteral("127"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("127", instance.fromUriLiteral("127"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("0", instance.valueToString(0, null, null, null, null, null));
+ assertEquals("8", instance.valueToString((byte) 8, null, null, null, null, null));
+ assertEquals("16", instance.valueToString((short) 16, null, null, null, null, null));
+ assertEquals("32", instance.valueToString(Integer.valueOf(32), null, null, null, null, null));
+ assertEquals("255", instance.valueToString(255L, null, null, null, null, null));
+ assertEquals("0.00390625", instance.valueToString(1.0 / 256, null, null, null, null, null));
+ assertEquals("4.2E-8", instance.valueToString(42e-9, null, null, null, null, null));
+ assertEquals("INF", instance.valueToString(Double.POSITIVE_INFINITY, null, null, null, null, null));
+ assertEquals("-INF", instance.valueToString(Double.NEGATIVE_INFINITY, null, null, null, null, null));
+ assertEquals("NaN", instance.valueToString(Double.NaN, null, null, null, null, null));
+ assertEquals("-0.125", instance.valueToString(-0.125f, null, null, null, null, null));
+ assertEquals("INF", instance.valueToString(Float.POSITIVE_INFINITY, null, null, null, null, null));
+ assertEquals("-INF", instance.valueToString(Float.NEGATIVE_INFINITY, null, null, null, null, null));
+ assertEquals("NaN", instance.valueToString(Float.NaN, null, null, null, null, null));
+ assertEquals("-123456.75", instance.valueToString(new BigDecimal("-123456.75"), null, null, null, null, null));
+
+ expectContentErrorInValueToString(instance, 12345678L);
+ expectContentErrorInValueToString(instance, new BigDecimal("123456789"));
+ expectContentErrorInValueToString(instance, new BigDecimal(BigInteger.ONE, -39));
+ expectContentErrorInValueToString(instance, 42e38);
+ expectContentErrorInValueToString(instance, 12345.6789);
+ expectContentErrorInValueToString(instance, 1E-50);
+
+ expectTypeErrorInValueToString(instance, 'A');
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals(Float.valueOf(1.42F), instance.valueOfString("1.42", null, null, null, null, null, Float.class));
+ assertEquals(Double.valueOf(-42.42), instance.valueOfString("-42.42", null, null, null, null, null, Double.class));
+ assertEquals(Float.valueOf(42.0F), instance.valueOfString("42", null, null, null, null, null, Float.class));
+ assertEquals(Float.valueOf(2.2E38F), instance.valueOfString("22E37", null, null, null, null, null, Float.class));
+ assertEquals(Float.valueOf(1.23E-38F), instance.valueOfString("12.3E-39", null, null, null, null, null,
+ Float.class));
+ assertEquals(BigDecimal.TEN, instance.valueOfString("10", null, null, null, null, null, BigDecimal.class));
+ assertEquals(Byte.valueOf((byte) 0), instance.valueOfString("0", null, null, null, null, null, Byte.class));
+ assertEquals(Short.valueOf((short) 1), instance.valueOfString("1.00", null, null, null, null, null, Short.class));
+ assertEquals(Integer.valueOf(42), instance.valueOfString("4.2E1", null, null, null, null, null, Integer.class));
+ assertEquals(Long.valueOf(12345678), instance.valueOfString("12345.678E+03", null, null, null, null, null,
+ Long.class));
+
+ assertEquals(Float.valueOf(Float.NaN), instance.valueOfString("NaN", null, null, null, null, null, Float.class));
+ assertEquals(Float.valueOf(Float.NEGATIVE_INFINITY), instance.valueOfString("-INF", null, null, null, null, null,
+ Float.class));
+ assertEquals(Float.valueOf(Float.POSITIVE_INFINITY), instance.valueOfString("INF", null, null, null, null, null,
+ Float.class));
+ assertEquals(Double.valueOf(Double.NaN), instance.valueOfString("NaN", null, null, null, null, null,
+ Double.class));
+ assertEquals(Double.valueOf(Double.NEGATIVE_INFINITY), instance.valueOfString("-INF", null, null, null, null, null,
+ Double.class));
+
+ expectContentErrorInValueOfString(instance, "0.");
+ expectContentErrorInValueOfString(instance, ".0");
+ expectContentErrorInValueOfString(instance, "1E-50");
+ expectContentErrorInValueOfString(instance, "12345.6789");
+ expectContentErrorInValueOfString(instance, "42E42");
+ expectContentErrorInValueOfString(instance, "42.42.42");
+ expectContentErrorInValueOfString(instance, "42.42.42");
+ expectContentErrorInValueOfString(instance, "42D");
+ expectContentErrorInValueOfString(instance, "0x42P4");
+
+ expectUnconvertibleErrorInValueOfString(instance, "INF", BigDecimal.class);
+ expectUnconvertibleErrorInValueOfString(instance, "NaN", BigDecimal.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-INF", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "NaN", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "5E-1", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "5E-1", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "5E-1", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "5E-1", Long.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-129", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "128", Byte.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-32769", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "32768", Short.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-2147483.65E3", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "2147483.65E3", Integer.class);
+ expectUnconvertibleErrorInValueOfString(instance, "-1E19", Long.class);
+ expectUnconvertibleErrorInValueOfString(instance, "1E19", Long.class);
+
+ expectTypeErrorInValueOfString(instance, "1.42");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmStringTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmStringTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmStringTest.java
new file mode 100644
index 0000000..d6021c7
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmStringTest.java
@@ -0,0 +1,77 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmStringTest extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("'StringValue'", instance.toUriLiteral("StringValue"));
+ assertEquals("'String''Value'", instance.toUriLiteral("String'Value"));
+ assertEquals("'String''''''Value'", instance.toUriLiteral("String'''Value"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("String''Value", instance.fromUriLiteral("'String''''Value'"));
+
+ expectErrorInFromUriLiteral(instance, "");
+ expectErrorInFromUriLiteral(instance, "'");
+ expectErrorInFromUriLiteral(instance, "'\"");
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ assertEquals("text", instance.valueToString("text", null, null, null, null, null));
+ assertEquals("a\nb", instance.valueToString("a\nb", null, null, null, null, null));
+ assertEquals("true", instance.valueToString(true, null, null, null, null, null));
+ assertEquals("a'b", instance.valueToString("a'b", null, null, null, null, null));
+
+ assertEquals("text", instance.valueToString("text", null, null, null, null, true));
+ assertEquals("text", instance.valueToString("text", null, 4, null, null, null));
+ assertEquals("text", instance.valueToString("text", null, Integer.MAX_VALUE, null, null, null));
+
+ expectFacetsErrorInValueToString(instance, "schräg", null, null, null, null, false);
+ expectFacetsErrorInValueToString(instance, "text", null, 3, null, null, null);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ assertEquals("text", instance.valueOfString("text", null, null, null, null, null, String.class));
+ assertEquals("a\nb", instance.valueOfString("a\nb", null, null, null, null, null, String.class));
+ assertEquals("true", instance.valueOfString("true", null, null, null, null, null, String.class));
+ assertEquals("'a''b'", instance.valueOfString("'a''b'", null, null, null, null, null, String.class));
+
+ assertEquals("text", instance.valueOfString("text", null, null, null, null, true, String.class));
+ assertEquals("text", instance.valueOfString("text", null, 4, null, null, null, String.class));
+ assertEquals("text", instance.valueOfString("text", null, Integer.MAX_VALUE, null, null, null, String.class));
+
+ expectFacetsErrorInValueOfString(instance, "schräg", null, null, null, null, false);
+ expectFacetsErrorInValueOfString(instance, "text", null, 3, null, null, null);
+
+ expectTypeErrorInValueOfString(instance, "text");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
new file mode 100644
index 0000000..ed23a50
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/EdmTimeOfDayTest.java
@@ -0,0 +1,92 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Calendar;
+import java.util.TimeZone;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.junit.Test;
+
+public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
+
+ private final EdmPrimitiveType instance = EdmPrimitiveTypeKind.TimeOfDay.getEdmPrimitiveTypeInstance();
+
+ @Test
+ public void toUriLiteral() throws Exception {
+ assertEquals("11:12", instance.toUriLiteral("11:12"));
+ assertEquals("11:12:13.012", instance.toUriLiteral("11:12:13.012"));
+ }
+
+ @Test
+ public void fromUriLiteral() throws Exception {
+ assertEquals("11:12", instance.fromUriLiteral("11:12"));
+ assertEquals("11:12:13.012", instance.fromUriLiteral("11:12:13.012"));
+ }
+
+ @Test
+ public void valueToString() throws Exception {
+ Calendar dateTime = Calendar.getInstance();
+ dateTime.clear();
+ dateTime.setTimeZone(TimeZone.getTimeZone("GMT+11:30"));
+ dateTime.set(1, 2, 3, 4, 5, 6);
+ assertEquals("04:05:06", instance.valueToString(dateTime, null, null, null, null, null));
+
+ dateTime.add(Calendar.MILLISECOND, 42);
+ assertEquals("04:05:06.042", instance.valueToString(dateTime, null, null, 3, null, null));
+ assertEquals("04:05:06.042", instance.valueToString(dateTime, null, null, 4, null, null));
+
+ expectFacetsErrorInValueToString(instance, dateTime, null, null, null, null, null);
+ expectFacetsErrorInValueToString(instance, dateTime, null, null, 2, null, null);
+
+ expectTypeErrorInValueToString(instance, 0);
+ }
+
+ @Test
+ public void valueOfString() throws Exception {
+ Calendar dateTime = Calendar.getInstance();
+ dateTime.clear();
+ dateTime.setTimeZone(TimeZone.getTimeZone("GMT"));
+
+ assertEquals(dateTime, instance.valueOfString("00:00", null, null, null, null, null, Calendar.class));
+ assertEquals(dateTime, instance.valueOfString("00:00:00", null, null, null, null, null, Calendar.class));
+ assertEquals(dateTime, instance.valueOfString("00:00:00.000000000000", null, null, null, null, null,
+ Calendar.class));
+
+ dateTime.set(Calendar.MILLISECOND, 999);
+ assertEquals(dateTime, instance.valueOfString("00:00:00.999", null, null, 3, null, null, Calendar.class));
+ assertEquals(dateTime, instance.valueOfString("00:00:00.999", null, null, 3, null, null, Calendar.class));
+
+ expectFacetsErrorInValueOfString(instance, "11:12:13.123", null, null, null, null, null);
+ expectFacetsErrorInValueOfString(instance, "11:12:13.123", null, null, 2, null, null);
+
+ expectContentErrorInValueOfString(instance, "24:32:02");
+ expectContentErrorInValueOfString(instance, "011:12:13");
+ expectContentErrorInValueOfString(instance, "11:12:13:14");
+ expectContentErrorInValueOfString(instance, "111213");
+ expectContentErrorInValueOfString(instance, "1:2:3");
+ expectContentErrorInValueOfString(instance, "11:12:13.0.1");
+ expectContentErrorInValueOfString(instance, "11:12:13.");
+ expectContentErrorInValueOfString(instance, "11:12:13.0000000000000");
+
+ expectTypeErrorInValueOfString(instance, "11:12:13");
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
new file mode 100644
index 0000000..2450a45
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/PrimitiveTypeBaseTest.java
@@ -0,0 +1,117 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
+import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
+
+public abstract class PrimitiveTypeBaseTest {
+
+ 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 messageReferenceString) {
+ try {
+ instance.valueToString(value, isNullable, maxLength, precision, scale, isUnicode);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
+ }
+ }
+
+ private void expectErrorInValueToString(final EdmPrimitiveType instance, final Object value,
+ final String messageReference) {
+ expectErrorInValueToString(instance, value, null, null, null, null, null, messageReference);
+ }
+
+ protected void expectTypeErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
+ expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
+ }
+
+ protected void expectContentErrorInValueToString(final EdmPrimitiveType instance, final Object value) {
+ expectErrorInValueToString(instance, value, "EdmPrimitiveTypeException.VALUE_ILLEGAL_CONTENT");
+ }
+
+ protected void expectFacetsErrorInValueToString(final EdmPrimitiveType instance, final Object value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) {
+ expectErrorInValueToString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
+ "EdmPrimitiveTypeException.VALUE_FACETS_NOT_MATCHED");
+ }
+
+ protected void expectNullErrorInValueToString(final EdmPrimitiveType instance) {
+ expectErrorInValueToString(instance, null, false, null, null, null, null,
+ "EdmPrimitiveTypeException.VALUE_NULL_NOT_ALLOWED");
+ }
+
+ 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 messageReferenceString) {
+ try {
+ instance.valueOfString(value, isNullable, maxLength, precision, scale, isUnicode, returnType);
+ fail("Expected exception not thrown");
+ } catch (final EdmPrimitiveTypeException e) {
+ assertNotNull(e.getLocalizedMessage());
+ assertTrue(e.getLocalizedMessage().startsWith(messageReferenceString));
+ }
+ }
+
+ protected void expectTypeErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
+ expectErrorInValueOfString(instance, value, null, null, null, null, null, Class.class,
+ "EdmPrimitiveTypeException.VALUE_TYPE_NOT_SUPPORTED");
+ }
+
+ protected void expectUnconvertibleErrorInValueOfString(final EdmPrimitiveType instance, final String value,
+ final Class<?> type) {
+ expectErrorInValueOfString(instance, value, null, null, null, null, null, type,
+ "EdmPrimitiveTypeException.LITERAL_UNCONVERTIBLE_TO_VALUE_TYPE");
+ }
+
+ protected void expectContentErrorInValueOfString(final EdmPrimitiveType instance, final String value) {
+ expectErrorInValueOfString(instance, value, null, null, null, null, null, instance.getDefaultType(),
+ "EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT");
+ }
+
+ protected void expectFacetsErrorInValueOfString(final EdmPrimitiveType instance, final String value,
+ final Boolean isNullable, final Integer maxLength, final Integer precision,
+ final Integer scale, final Boolean isUnicode) {
+ expectErrorInValueOfString(instance, value, isNullable, maxLength, precision, scale, isUnicode,
+ instance.getDefaultType(), "EdmPrimitiveTypeException.LITERAL_FACETS_NOT_MATCHED");
+ }
+
+ protected void expectNullErrorInValueOfString(final EdmPrimitiveType instance) {
+ expectErrorInValueOfString(instance, null, false, null, null, null, null, instance.getDefaultType(),
+ "EdmPrimitiveTypeException.LITERAL_NULL_NOT_ALLOWED");
+ }
+
+ 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());
+ assertTrue(e.getLocalizedMessage().startsWith("EdmPrimitiveTypeException.LITERAL_ILLEGAL_CONTENT"));
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/UInt7Test.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/UInt7Test.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/UInt7Test.java
new file mode 100644
index 0000000..e27abae
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/primitivetype/UInt7Test.java
@@ -0,0 +1,33 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.primitivetype;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertTrue;
+
+import org.junit.Test;
+
+public class UInt7Test extends PrimitiveTypeBaseTest {
+
+ @Test
+ public void compatibility() {
+ assertTrue(Uint7.getInstance().isCompatible(Uint7.getInstance()));
+ assertFalse(Uint7.getInstance().isCompatible(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance()));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmComplexTypeImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmComplexTypeImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmComplexTypeImplTest.java
new file mode 100644
index 0000000..622ef04
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmComplexTypeImplTest.java
@@ -0,0 +1,127 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
+import org.apache.olingo.odata4.commons.api.edm.EdmElement;
+import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.provider.Property;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EdmComplexTypeImplTest {
+
+ private EdmComplexType baseType;
+ private EdmComplexType type;
+
+ @Before
+ public void setupTypes() throws Exception {
+ EdmProvider provider = mock(EdmProvider.class);
+ EdmProviderImpl edm = new EdmProviderImpl(provider);
+
+ FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
+ ComplexType baseComplexType = new ComplexType();
+ List<Property> baseProperties = new ArrayList<Property>();
+ baseProperties.add(new Property().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ List<NavigationProperty> baseNavigationProperties = new ArrayList<NavigationProperty>();
+ baseNavigationProperties.add(new NavigationProperty().setName("nav1"));
+ baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties)
+ .setNavigationProperties(baseNavigationProperties);
+ when(provider.getComplexType(baseName)).thenReturn(baseComplexType);
+
+ baseType = new EdmComplexTypeImpl(edm, baseName, baseComplexType);
+
+ FullQualifiedName name = new FullQualifiedName("namespace", "typeName");
+ ComplexType complexType = new ComplexType().setBaseType(baseName);
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new Property().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nav2"));
+ complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties)
+ .setNavigationProperties(navigationProperties);
+ when(provider.getComplexType(name)).thenReturn(complexType);
+
+ type = new EdmComplexTypeImpl(edm, name, complexType);
+ }
+
+ @Test
+ public void getBaseType() {
+ assertNull(baseType.getBaseType());
+ assertNotNull(type.getBaseType());
+ }
+
+ @Test
+ public void propertiesBehaviour() {
+ List<String> propertyNames = baseType.getPropertyNames();
+ assertEquals(1, propertyNames.size());
+ assertEquals("prop1", baseType.getProperty("prop1").getName());
+ }
+
+ @Test
+ public void propertiesBehaviourWithBaseType() {
+ List<String> propertyNames = type.getPropertyNames();
+ assertEquals(2, propertyNames.size());
+ assertEquals("prop1", type.getProperty("prop1").getName());
+ assertEquals("prop2", type.getProperty("prop2").getName());
+ }
+
+ @Test
+ public void navigationPropertiesBehaviour() {
+ List<String> navigationPropertyNames = baseType.getNavigationPropertyNames();
+ assertEquals(1, navigationPropertyNames.size());
+ assertEquals("nav1", baseType.getProperty("nav1").getName());
+ }
+
+ @Test
+ public void navigationPropertiesBehaviourWithBaseType() {
+ List<String> navigationPropertyNames = type.getNavigationPropertyNames();
+ assertEquals(2, navigationPropertyNames.size());
+ assertEquals("nav1", type.getProperty("nav1").getName());
+ assertEquals("nav2", type.getProperty("nav2").getName());
+ }
+
+ @Test
+ public void propertyCaching() {
+ EdmElement property = type.getProperty("prop1");
+ assertTrue(property == type.getProperty("prop1"));
+
+ property = type.getProperty("prop2");
+ assertTrue(property == type.getProperty("prop2"));
+
+ property = type.getProperty("nav1");
+ assertTrue(property == type.getProperty("nav1"));
+
+ property = type.getProperty("nav2");
+ assertTrue(property == type.getProperty("nav2"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmEntityTypeImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmEntityTypeImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmEntityTypeImplTest.java
new file mode 100644
index 0000000..cd58d82
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmEntityTypeImplTest.java
@@ -0,0 +1,241 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
+import org.apache.olingo.odata4.commons.api.edm.EdmElement;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
+import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
+import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
+import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty;
+import org.apache.olingo.odata4.commons.api.edm.provider.Property;
+import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EdmEntityTypeImplTest {
+
+ private EdmEntityType baseType;
+ private EdmEntityType typeWithBaseType;
+ private EdmEntityType typeWithComplexKey;
+
+ // TODO: test with abstract types and keys
+ @Before
+ public void setupTypes() throws Exception {
+ EdmProvider provider = mock(EdmProvider.class);
+ EdmProviderImpl edm = new EdmProviderImpl(provider);
+
+ FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName");
+ EntityType baseType = new EntityType();
+ baseType.setName(baseName.getName());
+ List<Property> properties = new ArrayList<Property>();
+ properties.add(new Property().setName("Id").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ properties.add(new Property().setName("Name").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ baseType.setProperties(properties);
+ List<PropertyRef> key = new ArrayList<PropertyRef>();
+ key.add(new PropertyRef().setPropertyName("Id"));
+ baseType.setKey(key);
+ List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>();
+ navigationProperties.add(new NavigationProperty().setName("nav1"));
+ baseType.setNavigationProperties(navigationProperties);
+ when(provider.getEntityType(baseName)).thenReturn(baseType);
+
+ this.baseType = new EdmEntityTypeImpl(edm, baseName, baseType);
+
+ FullQualifiedName typeName = new FullQualifiedName("namespace", "typeName");
+ EntityType type = new EntityType();
+ type.setName(typeName.getName());
+ type.setBaseType(baseName);
+ List<Property> typeProperties = new ArrayList<Property>();
+ typeProperties.add(new Property().setName("address").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ typeProperties.add(new Property().setName("email").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ type.setProperties(typeProperties);
+ List<NavigationProperty> typeNavigationProperties = new ArrayList<NavigationProperty>();
+ typeNavigationProperties.add(new NavigationProperty().setName("nav2"));
+ type.setNavigationProperties(typeNavigationProperties);
+ when(provider.getEntityType(typeName)).thenReturn(type);
+
+ typeWithBaseType = new EdmEntityTypeImpl(edm, typeName, type);
+
+ FullQualifiedName typeWithComplexKeyName = new FullQualifiedName("namespace", "typeName");
+ EntityType typeWithComplexKeyProvider = new EntityType();
+ typeWithComplexKeyProvider.setName(typeWithComplexKeyName.getName());
+ List<Property> typeWithComplexKeyProperties = new ArrayList<Property>();
+ typeWithComplexKeyProperties.add(new Property().setName("Id").setType(
+ EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+
+ List<Property> complexTypeProperties = new ArrayList<Property>();
+ complexTypeProperties.add(new Property().setName("ComplexPropName").setType(
+ EdmPrimitiveTypeKind.String.getFullQualifiedName()));
+ FullQualifiedName complexTypeName = new FullQualifiedName("namespace", "complexTypeName");
+ when(provider.getComplexType(complexTypeName)).thenReturn(
+ new ComplexType().setName("complexTypeName").setProperties(complexTypeProperties));
+
+ typeWithComplexKeyProperties.add(new Property().setName("Comp").setType(complexTypeName));
+ typeWithComplexKeyProvider.setProperties(typeWithComplexKeyProperties);
+ List<PropertyRef> keyForTypeWithComplexKey = new ArrayList<PropertyRef>();
+ keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("Id"));
+ keyForTypeWithComplexKey.add(new PropertyRef().setPropertyName("ComplexPropName").setAlias("alias").setPath(
+ "Comp/ComplexPropName"));
+ typeWithComplexKeyProvider.setKey(keyForTypeWithComplexKey);
+ when(provider.getEntityType(typeWithComplexKeyName)).thenReturn(typeWithComplexKeyProvider);
+
+ typeWithComplexKey = new EdmEntityTypeImpl(edm, typeWithComplexKeyName, typeWithComplexKeyProvider);
+ }
+
+ @Test
+ public void complexKeyWithAlias() {
+ List<String> keyPredicateNames = typeWithComplexKey.getKeyPredicateNames();
+ assertEquals(2, keyPredicateNames.size());
+ assertEquals("Id", keyPredicateNames.get(0));
+ assertEquals("alias", keyPredicateNames.get(1));
+
+ EdmKeyPropertyRef keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("Id");
+ assertNotNull(keyPropertyRef);
+ assertEquals("Id", keyPropertyRef.getKeyPropertyName());
+ assertNull(keyPropertyRef.getAlias());
+ EdmProperty keyProperty = keyPropertyRef.getProperty();
+ assertNotNull(keyProperty);
+ assertEquals(typeWithComplexKey.getProperty("Id"), keyProperty);
+
+ keyPropertyRef = typeWithComplexKey.getKeyPropertyRef("alias");
+ assertNotNull(keyPropertyRef);
+ assertEquals("ComplexPropName", keyPropertyRef.getKeyPropertyName());
+ assertEquals("alias", keyPropertyRef.getAlias());
+ assertEquals("Comp/ComplexPropName", keyPropertyRef.getPath());
+
+ keyProperty = keyPropertyRef.getProperty();
+ assertNotNull(keyProperty);
+ EdmElement complexProperty = typeWithComplexKey.getProperty("Comp");
+ EdmComplexType complexType = (EdmComplexType) complexProperty.getType();
+ assertNotNull(complexType);
+ assertEquals(complexType.getProperty("ComplexPropName"), keyProperty);
+ }
+
+ @Test
+ public void keyBehaviour() {
+ List<String> keyPredicateNames = baseType.getKeyPredicateNames();
+ assertEquals(1, keyPredicateNames.size());
+ assertEquals("Id", keyPredicateNames.get(0));
+
+ EdmKeyPropertyRef keyPropertyRef = baseType.getKeyPropertyRef("Id");
+ assertNotNull(keyPropertyRef);
+ assertEquals("Id", keyPropertyRef.getKeyPropertyName());
+ assertNull(keyPropertyRef.getAlias());
+
+ EdmProperty keyProperty = keyPropertyRef.getProperty();
+ assertNotNull(keyProperty);
+ assertEquals(baseType.getProperty("Id"), keyProperty);
+
+ List<EdmKeyPropertyRef> keyPropertyRefs = baseType.getKeyPropertyRefs();
+ assertNotNull(keyPropertyRefs);
+ assertEquals(1, keyPropertyRefs.size());
+ assertEquals("Id", keyPropertyRefs.get(0).getKeyPropertyName());
+ }
+
+ @Test
+ public void keyBehaviourWithBasetype() {
+ List<String> keyPredicateNames = typeWithBaseType.getKeyPredicateNames();
+ assertEquals(1, keyPredicateNames.size());
+ assertEquals("Id", keyPredicateNames.get(0));
+
+ EdmKeyPropertyRef keyPropertyRef = typeWithBaseType.getKeyPropertyRef("Id");
+ assertNotNull(keyPropertyRef);
+ assertEquals("Id", keyPropertyRef.getKeyPropertyName());
+ assertNull(keyPropertyRef.getAlias());
+
+ // Should we support this?
+ // EdmPoperty keyProperty = keyPropertyRef.getProperty();
+
+ List<EdmKeyPropertyRef> keyPropertyRefs = typeWithBaseType.getKeyPropertyRefs();
+ assertNotNull(keyPropertyRefs);
+ assertEquals(1, keyPropertyRefs.size());
+ assertEquals("Id", keyPropertyRefs.get(0).getKeyPropertyName());
+ }
+
+ @Test
+ public void getBaseType() {
+ assertNull(baseType.getBaseType());
+ assertNotNull(typeWithBaseType.getBaseType());
+ }
+
+ @Test
+ public void propertiesBehaviour() {
+ List<String> propertyNames = baseType.getPropertyNames();
+ assertEquals(2, propertyNames.size());
+ assertEquals("Id", baseType.getProperty("Id").getName());
+ assertEquals("Name", baseType.getProperty("Name").getName());
+ }
+
+ @Test
+ public void propertiesBehaviourWithBaseType() {
+ List<String> propertyNames = typeWithBaseType.getPropertyNames();
+ assertEquals(4, propertyNames.size());
+ assertEquals("Id", typeWithBaseType.getProperty("Id").getName());
+ assertEquals("Name", typeWithBaseType.getProperty("Name").getName());
+ assertEquals("address", typeWithBaseType.getProperty("address").getName());
+ assertEquals("email", typeWithBaseType.getProperty("email").getName());
+ }
+
+ @Test
+ public void navigationPropertiesBehaviour() {
+ List<String> navigationPropertyNames = baseType.getNavigationPropertyNames();
+ assertEquals(1, navigationPropertyNames.size());
+ assertEquals("nav1", baseType.getProperty("nav1").getName());
+ }
+
+ @Test
+ public void navigationPropertiesBehaviourWithBaseType() {
+ List<String> navigationPropertyNames = typeWithBaseType.getNavigationPropertyNames();
+ assertEquals(2, navigationPropertyNames.size());
+ assertEquals("nav1", typeWithBaseType.getProperty("nav1").getName());
+ assertEquals("nav2", typeWithBaseType.getProperty("nav2").getName());
+ }
+
+ @Test
+ public void propertyCaching() {
+ EdmElement property = typeWithBaseType.getProperty("Id");
+ assertTrue(property == typeWithBaseType.getProperty("Id"));
+
+ property = typeWithBaseType.getProperty("address");
+ assertTrue(property == typeWithBaseType.getProperty("address"));
+
+ property = typeWithBaseType.getProperty("nav1");
+ assertTrue(property == typeWithBaseType.getProperty("nav1"));
+
+ property = typeWithBaseType.getProperty("nav2");
+ assertTrue(property == typeWithBaseType.getProperty("nav2"));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
new file mode 100644
index 0000000..e6187e6
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmNamed;
+import org.junit.Test;
+
+public class EdmNamedImplTest {
+
+ @Test
+ public void getNameTest() {
+ EdmNamed obj = new EdmNamedImplTester("Name");
+ assertEquals("Name", obj.getName());
+ }
+
+ private class EdmNamedImplTester extends EdmNamedImpl {
+
+ public EdmNamedImplTester(final String name) {
+ super(null, name);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java
new file mode 100644
index 0000000..ebc16f4
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java
@@ -0,0 +1,35 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.provider;
+
+import org.junit.Test;
+
+public class EdmPropertyImplTest {
+
+ @Test
+ public void getTypeReturnsSimpleType() {
+
+ }
+
+ @Test
+ public void getTypeReturnsComplexType() {
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
new file mode 100644
index 0000000..9c50e32
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
@@ -0,0 +1,170 @@
+/*******************************************************************************
+ * 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.odata4.commons.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.odata4.commons.api.edm.Edm;
+import org.apache.olingo.odata4.commons.api.edm.EdmAction;
+import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
+import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
+import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
+import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
+import org.apache.olingo.odata4.commons.api.edm.helper.EntityContainerInfo;
+import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
+import org.apache.olingo.odata4.commons.api.edm.provider.Action;
+import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
+import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
+import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
+import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
+import org.apache.olingo.odata4.commons.api.edm.provider.Function;
+import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
+import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
+import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
+import org.junit.Before;
+import org.junit.Test;
+
+public class EdmProviderImplTest {
+
+ private Edm edm;
+ private final FullQualifiedName FQN = new FullQualifiedName("testNamespace", "testName");
+ private final FullQualifiedName WRONG_FQN = new FullQualifiedName("wrong", "wrong");
+
+ @Before
+ public void setup() throws Exception {
+ EdmProvider provider = mock(EdmProvider.class);
+ EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(FQN);
+ when(provider.getEntityContainerInfo(FQN)).thenReturn(containerInfo);
+ when(provider.getEntityContainerInfo(null)).thenReturn(containerInfo);
+
+ EnumType enumType = new EnumType().setName(FQN.getName());
+ when(provider.getEnumType(FQN)).thenReturn(enumType);
+
+ TypeDefinition typeDefinition = new TypeDefinition().setName(FQN.getName());
+ when(provider.getTypeDefinition(FQN)).thenReturn(typeDefinition);
+
+ EntityType entityType = new EntityType().setName(FQN.getName()).setKey(new ArrayList<PropertyRef>());
+ when(provider.getEntityType(FQN)).thenReturn(entityType);
+
+ ComplexType complexType = new ComplexType().setName(FQN.getName());
+ when(provider.getComplexType(FQN)).thenReturn(complexType);
+
+ Action action = new Action().setName(FQN.getName());
+ List<Action> actions = new ArrayList<Action>();
+ actions.add(action);
+ when(provider.getActions(FQN)).thenReturn(actions);
+
+ Function function = new Function().setName(FQN.getName()).setParameters(new ArrayList<Parameter>());
+ List<Function> functions = new ArrayList<Function>();
+ functions.add(function);
+ when(provider.getFunctions(FQN)).thenReturn(functions);
+
+ edm = new EdmProviderImpl(provider);
+ }
+
+ @Test
+ public void getEntityContainer() {
+ EdmEntityContainer entityContainer = edm.getEntityContainer(FQN);
+ assertNotNull(entityContainer);
+ assertEquals(FQN.getNamespace(), entityContainer.getNamespace());
+ assertEquals(FQN.getName(), entityContainer.getName());
+
+ entityContainer = edm.getEntityContainer(null);
+ assertNotNull(entityContainer);
+ assertEquals(FQN.getNamespace(), entityContainer.getNamespace());
+ assertEquals(FQN.getName(), entityContainer.getName());
+
+ assertNull(edm.getEntityContainer(WRONG_FQN));
+ }
+
+ @Test
+ public void getEnumType() {
+ EdmEnumType enumType = edm.getEnumType(FQN);
+ assertNotNull(enumType);
+ assertEquals(FQN.getNamespace(), enumType.getNamespace());
+ assertEquals(FQN.getName(), enumType.getName());
+
+ assertNull(edm.getEnumType(WRONG_FQN));
+ }
+
+ @Test
+ public void getTypeDefinition() {
+ EdmTypeDefinition typeDefinition = edm.getTypeDefinition(FQN);
+ assertNotNull(typeDefinition);
+ assertEquals(FQN.getNamespace(), typeDefinition.getNamespace());
+ assertEquals(FQN.getName(), typeDefinition.getName());
+
+ assertNull(edm.getTypeDefinition(WRONG_FQN));
+ }
+
+ @Test
+ public void getEntityType() {
+ EdmEntityType entityType = edm.getEntityType(FQN);
+ assertNotNull(entityType);
+ assertEquals(FQN.getNamespace(), entityType.getNamespace());
+ assertEquals(FQN.getName(), entityType.getName());
+
+ assertNull(edm.getEntityType(WRONG_FQN));
+ }
+
+ @Test
+ public void getComplexType() {
+ EdmComplexType complexType = edm.getComplexType(FQN);
+ assertNotNull(complexType);
+ assertEquals(FQN.getNamespace(), complexType.getNamespace());
+ assertEquals(FQN.getName(), complexType.getName());
+
+ assertNull(edm.getComplexType(WRONG_FQN));
+ }
+
+ @Test
+ public void getAction() {
+ EdmAction action = edm.getAction(FQN, null, null);
+ assertNotNull(action);
+ assertEquals(FQN.getNamespace(), action.getNamespace());
+ assertEquals(FQN.getName(), action.getName());
+
+ assertNull(edm.getAction(WRONG_FQN, null, null));
+ }
+
+ @Test
+ public void getFunction() {
+ EdmFunction function = edm.getFunction(FQN, null, null, new ArrayList<String>());
+ assertNotNull(function);
+ assertEquals(FQN.getNamespace(), function.getNamespace());
+ assertEquals(FQN.getName(), function.getName());
+
+ assertNull(edm.getFunction(WRONG_FQN, null, null, new ArrayList<String>()));
+ }
+
+ @Test
+ public void getServiceMetadata() {
+ assertNotNull(edm.getServiceMetadata());
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
new file mode 100644
index 0000000..579b496
--- /dev/null
+++ b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
@@ -0,0 +1,44 @@
+/*******************************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ ******************************************************************************/
+package org.apache.olingo.odata4.commons.core.edm.provider;
+
+import static org.junit.Assert.assertEquals;
+
+import org.apache.olingo.odata4.commons.api.edm.EdmType;
+import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
+import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
+import org.junit.Test;
+
+public class EdmTypeImplTest {
+
+ @Test
+ public void getterTest() {
+ EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.UNDEFINED);
+ assertEquals("name", type.getName());
+ assertEquals("namespace", type.getNamespace());
+ assertEquals(EdmTypeKind.UNDEFINED, type.getKind());
+ }
+
+ private class EdmTypeImplTester extends EdmTypeImpl {
+ public EdmTypeImplTester(final FullQualifiedName name, final EdmTypeKind kind) {
+ super(null, name, kind);
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/ODataConsumer.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/ODataConsumer.java b/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/ODataConsumer.java
deleted file mode 100644
index d8b6c1a..0000000
--- a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/ODataConsumer.java
+++ /dev/null
@@ -1,50 +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.consumer.api;
-
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.provider.EdmProvider;
-
-//TODO: Exceptionhandling
-public abstract class ODataConsumer {
-
- private static final String IMPLEMENTATION = "org.apache.olingo.consumer.core.ODataConsumerImpl";
-
- public static ODataConsumer create() {
- ODataConsumer instance;
-
- try {
- final Class<?> clazz = Class.forName(ODataConsumer.IMPLEMENTATION);
-
- /*
- * We explicitly do not use the singleton pattern to keep the server state free
- * and avoid class loading issues also during hot deployment.
- */
- final Object object = clazz.newInstance();
- instance = (ODataConsumer) object;
-
- } catch (final Exception e) {
- throw new RuntimeException(e);
- }
- return instance;
- }
-
- public abstract Edm createEdm(EdmProvider provider);
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/AnnotationProperty.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/AnnotationProperty.java b/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/AnnotationProperty.java
deleted file mode 100644
index 0bea37c..0000000
--- a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/AnnotationProperty.java
+++ /dev/null
@@ -1,23 +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.consumer.api.deserializer;
-
-public interface AnnotationProperty extends Property {
- String getValue();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ComplexValue.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ComplexValue.java b/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ComplexValue.java
deleted file mode 100644
index dcfd06e..0000000
--- a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ComplexValue.java
+++ /dev/null
@@ -1,35 +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.consumer.api.deserializer;
-
-import java.util.List;
-import java.util.Map;
-
-public interface ComplexValue extends Value {
-
- Value getValue(String name);
-
- List<Property> getProperties();
-
- Map<String, NavigationProperty> getNavigationProperties();
-
- Map<String, AnnotationProperty> getAnnotationProperties();
-
- Map<String, StructuralProperty> getStructuralProperties();
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ConsumerException.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ConsumerException.java b/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ConsumerException.java
deleted file mode 100644
index aaf75e2..0000000
--- a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/ConsumerException.java
+++ /dev/null
@@ -1,36 +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.consumer.api.deserializer;
-
-public class ConsumerException extends Exception {
-
- private static final long serialVersionUID = 1L;
-
- public ConsumerException() {
- super();
- }
-
- public ConsumerException(final String message) {
- super(message);
- }
-
- public ConsumerException(final String message, final Throwable cause) {
- super(message, cause);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/82ae6060/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/Entity.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/Entity.java b/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/Entity.java
deleted file mode 100644
index 1ea3b50..0000000
--- a/odata4-lib/odata4-consumer-api/src/main/java/org/apache/olingo/consumer/api/deserializer/Entity.java
+++ /dev/null
@@ -1,59 +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.consumer.api.deserializer;
-
-import java.util.List;
-import java.util.Map;
-
-public interface Entity {
-
- String getODataContext();
-
- String getODataMetaDataEtag();
-
- String getODataType();
-
- Long getODataCount();
-
- String getODataNextLink();
-
- String getODataDeltaLink();
-
- String getODataId();
-
- String getODataETag();
-
- String getODataEditLink();
-
- String getODataReadLink();
-
- List<Property> getProperties();
-
- Map<String, NavigationProperty> getNavigationProperties();
-
- Map<String, AnnotationProperty> getAnnotationProperties();
-
- Map<String, StructuralProperty> getStructuralProperties();
-
- Property getProperty(String name);
-
- <T extends Property> T getProperty(String name, Class<T> clazz);
-
- Object getPropertyContent(String name);
-}