http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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 091a55b..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmEnumTest.java +++ /dev/null @@ -1,236 +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 org.apache.olingo.commons.api.edm.EdmEnumType; -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.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.edm.provider.EnumMember; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.junit.Test; - -import java.util.Arrays; -import java.util.List; - -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; - -public class EdmEnumTest { - - private final EdmEnumType instance; - private final EdmEnumType nonFlagsInstance; - - public EdmEnumTest() { - final List<EnumMember> memberList = Arrays.asList( - new EnumMember().setName("first").setValue("1"), - new EnumMember().setName("second").setValue("64")); - - final FullQualifiedName enumName = new FullQualifiedName("namespace", "name"); - - instance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, - new EnumType().setName("name").setMembers(memberList).setFlags(true) - .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); - - nonFlagsInstance = new EdmEnumTypeImpl(mock(EdmProviderImpl.class), enumName, - new EnumType().setName("name").setMembers(memberList).setFlags(false) - .setUnderlyingType(EdmPrimitiveTypeKind.SByte.getFullQualifiedName())); - } - - @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)); - assertFalse(instance.isCompatible(instance.getUnderlyingType())); - } - - @Test - public void defaultType() throws Exception { - assertEquals(Byte.class, instance.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); - } - - @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"); - } - - 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/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java deleted file mode 100644 index 30a6394..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImplTest.java +++ /dev/null @@ -1,75 +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 org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.EdmReturnType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.Function; -import org.apache.olingo.server.api.edm.provider.ReturnType; -import org.junit.Before; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; - -public class EdmFunctionImplTest { - - private EdmFunction functionImpl1; - private EdmFunction functionImpl2; - - @Before - public void setupFunctions() { - EdmProviderImpl provider = mock(EdmProviderImpl.class); - - Function function1 = new Function().setReturnType(new ReturnType().setType(new FullQualifiedName("Edm", "String"))); - functionImpl1 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function1); - Function function2 = new Function().setComposable(true); - functionImpl2 = EdmFunctionImpl.getInstance(provider, new FullQualifiedName("namespace", "name"), function2); - } - - @Test - public void isComposableDefaultFalse() { - assertFalse(functionImpl1.isComposable()); - } - - @Test - public void isComposableSetToTrue() { - assertTrue(functionImpl2.isComposable()); - } - - @Test - public void existingReturnTypeGetsReturned() { - EdmReturnType returnType = functionImpl1.getReturnType(); - assertNotNull(returnType); - assertEquals("String", returnType.getType().getName()); - } - - @Test(expected = EdmException.class) - public void nonExistingReturnTypeResultsInException() { - functionImpl2.getReturnType(); - fail(); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java deleted file mode 100644 index a653ccb..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java +++ /dev/null @@ -1,85 +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 org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityContainerInfo; -import org.apache.olingo.server.api.edm.provider.Function; -import org.apache.olingo.server.api.edm.provider.FunctionImport; -import org.apache.olingo.server.api.edm.provider.Parameter; -import org.apache.olingo.server.api.edm.provider.ReturnType; -import org.junit.Test; - -import java.util.Arrays; -import java.util.Collections; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmFunctionImportImplTest { - - @Test - public void functionImport() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - - final FullQualifiedName functionName = new FullQualifiedName("ns", "function"); - final Function functionProvider = new Function() - .setName(functionName.getName()) - .setParameters(Collections.<Parameter> emptyList()) - .setBound(false) - .setComposable(false) - .setReturnType(new ReturnType().setType(EdmPrimitiveTypeKind.Boolean.getFullQualifiedName())); - when(provider.getFunctions(functionName)).thenReturn(Arrays.asList(functionProvider)); - - final FullQualifiedName containerName = new FullQualifiedName("ns", "container"); - final EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(containerName); - when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo); - final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo); - - final String functionImportName = "functionImport"; - final FunctionImport functionImportProvider = new FunctionImport() - .setName(functionImportName) - .setFunction(functionName) - .setIncludeInServiceDocument(true); - when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider); - - final EdmFunctionImport functionImport = new EdmFunctionImportImpl(edm, entityContainer, functionImportProvider); - assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName()); - assertEquals("functionImport", functionImport.getName()); - final EdmFunction function = functionImport.getUnboundFunction(Collections.<String> emptyList()); - assertEquals(functionName.getNamespace(), function.getNamespace()); - assertEquals(functionName.getName(), function.getName()); - assertFalse(function.isBound()); - assertFalse(function.isComposable()); - assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), - function.getReturnType().getType()); - assertEquals(entityContainer, functionImport.getEntityContainer()); - assertNull(functionImport.getReturnedEntitySet()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmKeyPropertyRefImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmKeyPropertyRefImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmKeyPropertyRefImplTest.java deleted file mode 100644 index 2bb62e9..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmKeyPropertyRefImplTest.java +++ /dev/null @@ -1,142 +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 org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmElement; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmKeyPropertyRef; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.server.api.edm.provider.PropertyRef; -import org.junit.Test; - -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; - -public class EdmKeyPropertyRefImplTest { - - @Test - public void noAlias() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id"); - EdmEntityType etMock = mock(EdmEntityType.class); - EdmProperty keyPropertyMock = mock(EdmProperty.class); - when(etMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); - assertEquals("Id", ref.getKeyPropertyName()); - assertNull(ref.getAlias()); - assertNull(ref.getPath()); - - EdmProperty property = ref.getProperty(); - assertNotNull(property); - assertTrue(property == keyPropertyMock); - assertTrue(property == ref.getProperty()); - } - - @Test - public void aliasForPropertyInComplexPropertyOneLevel() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/Id"); - EdmEntityType etMock = mock(EdmEntityType.class); - EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmProperty compMock = mock(EdmProperty.class); - EdmComplexType compTypeMock = mock(EdmComplexType.class); - when(compTypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); - when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getStructuralProperty("comp")).thenReturn(compMock); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); - assertEquals("alias", ref.getAlias()); - assertEquals("comp/Id", ref.getPath()); - - EdmProperty property = ref.getProperty(); - assertNotNull(property); - assertTrue(property == keyPropertyMock); - } - - @Test(expected = EdmException.class) - public void aliasForPropertyInComplexPropertyButWrongPath() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/wrong"); - EdmEntityType etMock = mock(EdmEntityType.class); - EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmElement compMock = mock(EdmProperty.class); - EdmComplexType compTypeMock = mock(EdmComplexType.class); - when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock); - when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getProperty("comp")).thenReturn(compMock); - new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty(); - } - - @Test(expected = EdmException.class) - public void aliasForPropertyInComplexPropertyButWrongPath2() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("wrong/Id"); - EdmEntityType etMock = mock(EdmEntityType.class); - EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmElement compMock = mock(EdmProperty.class); - EdmComplexType compTypeMock = mock(EdmComplexType.class); - when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock); - when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getProperty("comp")).thenReturn(compMock); - new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty(); - } - - @Test - public void aliasForPropertyInComplexPropertyTwoLevels() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/comp2/Id"); - EdmEntityType etMock = mock(EdmEntityType.class); - EdmProperty keyPropertyMock = mock(EdmProperty.class); - EdmProperty compMock = mock(EdmProperty.class); - EdmComplexType compTypeMock = mock(EdmComplexType.class); - EdmProperty comp2Mock = mock(EdmProperty.class); - EdmComplexType comp2TypeMock = mock(EdmComplexType.class); - when(comp2TypeMock.getStructuralProperty("Id")).thenReturn(keyPropertyMock); - when(comp2Mock.getType()).thenReturn(comp2TypeMock); - when(compTypeMock.getStructuralProperty("comp2")).thenReturn(comp2Mock); - when(compMock.getType()).thenReturn(compTypeMock); - when(etMock.getStructuralProperty("comp")).thenReturn(compMock); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef); - - EdmProperty property = ref.getProperty(); - assertNotNull(property); - assertTrue(property == keyPropertyMock); - } - - @Test(expected = EdmException.class) - public void oneKeyNoAliasButInvalidProperty() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id"); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef); - ref.getProperty(); - } - - @Test(expected = EdmException.class) - public void aliasButNoPath() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias"); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef); - ref.getProperty(); - } - - @Test(expected = EdmException.class) - public void aliasButEmptyPath() { - PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath(""); - EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef); - ref.getProperty(); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMemberImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMemberImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMemberImplTest.java deleted file mode 100644 index 210ffbb..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMemberImplTest.java +++ /dev/null @@ -1,39 +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 org.apache.olingo.server.api.edm.provider.EnumMember; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; - -public class EdmMemberImplTest { - - @Test - public void enumMember() { - final EnumMember member = new EnumMember().setName("name").setValue("value"); - final EdmMemberImpl memberImpl = - new EdmMemberImpl(mock(EdmProviderImpl.class), null, member.getName(), member.getValue()); - - assertEquals("name", memberImpl.getName()); - assertEquals("value", memberImpl.getValue()); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java deleted file mode 100644 index e5f364f..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNamedImplTest.java +++ /dev/null @@ -1,42 +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 org.apache.olingo.commons.api.edm.EdmNamed; -import org.apache.olingo.commons.core.edm.EdmNamedImpl; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -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/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNavigationPropertyImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNavigationPropertyImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNavigationPropertyImplTest.java deleted file mode 100644 index b0f6e78..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNavigationPropertyImplTest.java +++ /dev/null @@ -1,144 +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 org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmNavigationProperty; -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.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.NavigationProperty; -import org.apache.olingo.server.api.edm.provider.PropertyRef; -import org.apache.olingo.server.api.edm.provider.ReferentialConstraint; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmNavigationPropertyImplTest { - - @Test - public void navigationProperty() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); - EntityType entityTypeProvider = new EntityType(); - entityTypeProvider.setKey(Collections.<PropertyRef> emptyList()); - when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); - NavigationProperty propertyProvider = new NavigationProperty(); - propertyProvider.setType(entityTypeName); - propertyProvider.setNullable(false); - EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, entityTypeName, propertyProvider); - assertFalse(property.isCollection()); - assertFalse(property.isNullable()); - EdmType type = property.getType(); - assertEquals(EdmTypeKind.ENTITY, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("entity", type.getName()); - assertNull(property.getReferencingPropertyName("referencedPropertyName")); - assertNull(property.getPartner()); - - // Test caching - EdmType cachedType = property.getType(); - assertTrue(type == cachedType); - } - - @Test - public void navigationPropertyWithReferntialConstraint() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); - EntityType entityTypeProvider = new EntityType(); - entityTypeProvider.setKey(Collections.<PropertyRef> emptyList()); - when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); - NavigationProperty propertyProvider = new NavigationProperty(); - propertyProvider.setType(entityTypeName); - propertyProvider.setNullable(false); - List<ReferentialConstraint> referentialConstraints = new ArrayList<ReferentialConstraint>(); - referentialConstraints.add(new ReferentialConstraint().setProperty("property").setReferencedProperty( - "referencedProperty")); - propertyProvider.setReferentialConstraints(referentialConstraints); - EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, entityTypeName, propertyProvider); - assertEquals("property", property.getReferencingPropertyName("referencedProperty")); - assertNull(property.getReferencingPropertyName("wrong")); - } - - @Test - public void navigationPropertyWithPartner() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); - EntityType entityTypeProvider = new EntityType(); - entityTypeProvider.setKey(Collections.<PropertyRef> emptyList()); - - List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>(); - navigationProperties.add(new NavigationProperty().setName("partnerName").setType(entityTypeName)); - entityTypeProvider.setNavigationProperties(navigationProperties); - when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); - NavigationProperty propertyProvider = new NavigationProperty(); - propertyProvider.setType(entityTypeName); - propertyProvider.setNullable(false); - propertyProvider.setPartner("partnerName"); - EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, entityTypeName, propertyProvider); - EdmNavigationProperty partner = property.getPartner(); - assertNotNull(partner); - - // Caching - assertTrue(partner == property.getPartner()); - } - - @Test(expected = EdmException.class) - public void navigationPropertyWithNonexistentPartner() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity"); - EntityType entityTypeProvider = new EntityType(); - entityTypeProvider.setKey(Collections.<PropertyRef> emptyList()); - - List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>(); - navigationProperties.add(new NavigationProperty().setName("partnerName").setType(entityTypeName)); - entityTypeProvider.setNavigationProperties(navigationProperties); - when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider); - NavigationProperty propertyProvider = new NavigationProperty(); - propertyProvider.setType(entityTypeName); - propertyProvider.setNullable(false); - propertyProvider.setPartner("wrong"); - EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, entityTypeName, propertyProvider); - property.getPartner(); - } - - @Test(expected = EdmException.class) - public void navigationPropertyWithNonExistentType() throws Exception { - EdmProviderImpl edm = mock(EdmProviderImpl.class); - NavigationProperty propertyProvider = new NavigationProperty(); - EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, null, propertyProvider); - property.getType(); - } -} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmParameterImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmParameterImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmParameterImplTest.java deleted file mode 100644 index b06c693..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmParameterImplTest.java +++ /dev/null @@ -1,140 +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 org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmParameter; -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -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.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.apache.olingo.server.api.edm.provider.Parameter; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmParameterImplTest { - - @Test - public void getTypeReturnsPrimitiveType() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(EdmPrimitiveTypeKind.Binary.getFullQualifiedName()); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - final EdmType type = parameter.getType(); - assertEquals(EdmTypeKind.PRIMITIVE, type.getKind()); - assertEquals(EdmPrimitiveType.EDM_NAMESPACE, type.getNamespace()); - assertEquals(EdmPrimitiveTypeKind.Binary.toString(), type.getName()); - } - - @Test - public void getTypeReturnsComplexType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex"); - ComplexType complexTypeProvider = new ComplexType(); - when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(complexTypeName); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - assertFalse(parameter.isCollection()); - final EdmType type = parameter.getType(); - assertEquals(EdmTypeKind.COMPLEX, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("complex", type.getName()); - } - - @Test - public void getTypeReturnsEnumType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum"); - EnumType enumTypeProvider = new EnumType(); - when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(enumTypeName); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - assertFalse(parameter.isCollection()); - final EdmType type = parameter.getType(); - assertEquals(EdmTypeKind.ENUM, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("enum", type.getName()); - } - - @Test - public void getTypeReturnsTypeDefinition() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName typeName = new FullQualifiedName("ns", "definition"); - TypeDefinition typeProvider = new TypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String")); - when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(typeName); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - final EdmType type = parameter.getType(); - assertEquals(EdmTypeKind.DEFINITION, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("definition", type.getName()); - } - - @Test - public void facets() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); - parameterProvider.setPrecision(42); - parameterProvider.setScale(12); - parameterProvider.setMaxLength(128); - parameterProvider.setNullable(false); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - assertNull(parameter.getMapping()); - assertEquals(Integer.valueOf(42), parameter.getPrecision()); - assertEquals(Integer.valueOf(12), parameter.getScale()); - assertEquals(Integer.valueOf(128), parameter.getMaxLength()); - assertFalse(parameter.isNullable()); - } - - @Test(expected = EdmException.class) - public void getTypeWithInvalidSimpleType() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(new FullQualifiedName("Edm", "wrong")); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - parameter.getType(); - } - - @Test(expected = EdmException.class) - public void getTypeWithNonexistingType() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Parameter parameterProvider = new Parameter(); - parameterProvider.setType(new FullQualifiedName("wrong", "wrong")); - final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider); - parameter.getType(); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java deleted file mode 100644 index d212084..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java +++ /dev/null @@ -1,155 +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 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.EdmProperty; -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.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.apache.olingo.server.api.edm.provider.Property; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.junit.Test; - -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 static org.mockito.Mockito.when; - -public class EdmPropertyImplTest { - - @Test - public void getTypeReturnsPrimitiveType() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Property propertyProvider = new Property(); - propertyProvider.setType(EdmPrimitiveTypeKind.Binary.getFullQualifiedName()); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - assertTrue(property.isPrimitive()); - final EdmType type = property.getType(); - assertEquals(EdmTypeKind.PRIMITIVE, type.getKind()); - assertEquals(EdmPrimitiveType.EDM_NAMESPACE, type.getNamespace()); - assertEquals(EdmPrimitiveTypeKind.Binary.toString(), type.getName()); - } - - @Test - public void getTypeReturnsComplexType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex"); - ComplexType complexTypeProvider = new ComplexType(); - when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider); - Property propertyProvider = new Property(); - propertyProvider.setType(complexTypeName); - final EdmProperty property = new EdmPropertyImpl(edm, complexTypeName, propertyProvider); - assertFalse(property.isCollection()); - assertFalse(property.isPrimitive()); - final EdmType type = property.getType(); - assertEquals(EdmTypeKind.COMPLEX, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("complex", type.getName()); - } - - @Test - public void getTypeReturnsEnumType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum"); - EnumType enumTypeProvider = new EnumType(); - when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider); - Property propertyProvider = new Property(); - propertyProvider.setType(enumTypeName); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - assertFalse(property.isCollection()); - assertFalse(property.isPrimitive()); - final EdmType type = property.getType(); - assertEquals(EdmTypeKind.ENUM, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("enum", type.getName()); - } - - @Test - public void getTypeReturnsTypeDefinition() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final FullQualifiedName typeName = new FullQualifiedName("ns", "definition"); - TypeDefinition typeProvider = new TypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String")); - when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider); - Property propertyProvider = new Property(); - propertyProvider.setType(typeName); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - assertFalse(property.isPrimitive()); - final EdmType type = property.getType(); - assertEquals(EdmTypeKind.DEFINITION, type.getKind()); - assertEquals("ns", type.getNamespace()); - assertEquals("definition", type.getName()); - } - - @Test(expected = EdmException.class) - public void getTypeReturnsWrongType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final Property propertyProvider = new Property() - .setType(new FullQualifiedName("ns", "wrong")); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - property.getType(); - fail(); - } - - @Test(expected = EdmException.class) - public void getTypeReturnsNoTypeKind() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - final Property propertyProvider = new Property() - .setType(new FullQualifiedName(EdmPrimitiveType.EDM_NAMESPACE, "type")); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - property.getType(); - fail(); - } - - @Test - public void facets() { - EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class)); - Property propertyProvider = new Property(); - propertyProvider.setType(EdmPrimitiveTypeKind.String.getFullQualifiedName()); - propertyProvider.setPrecision(42); - propertyProvider.setScale(12); - propertyProvider.setMaxLength(128); - propertyProvider.setUnicode(true); - propertyProvider.setNullable(false); - propertyProvider.setDefaultValue("x"); - final EdmProperty property = new EdmPropertyImpl(edm, null, propertyProvider); - assertTrue(property.isPrimitive()); - assertNull(property.getMapping()); - assertNull(property.getMimeType()); - assertEquals(Integer.valueOf(42), property.getPrecision()); - assertEquals(Integer.valueOf(12), property.getScale()); - assertEquals(Integer.valueOf(128), property.getMaxLength()); - assertTrue(property.isUnicode()); - assertFalse(property.isNullable()); - assertEquals("x", property.getDefaultValue()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java deleted file mode 100644 index 641769c..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java +++ /dev/null @@ -1,198 +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 org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.Action; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.Function; -import org.apache.olingo.server.api.edm.provider.Parameter; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmProviderImplOverloadingTest { - - private Edm edm; - private final FullQualifiedName operationName1 = new FullQualifiedName("n", "o1"); - private final FullQualifiedName operationType1 = new FullQualifiedName("n", "t1"); - private final FullQualifiedName operationType2 = new FullQualifiedName("n", "t2"); - private final FullQualifiedName wrongOperationName = new FullQualifiedName("wrong", "wrong"); - private final FullQualifiedName badOperationName = new FullQualifiedName("bad", "bad"); - - @Before - public void setup() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - - List<Action> actions = new ArrayList<Action>(); - Action action = new Action().setName(operationName1.getName()); - actions.add(action); - List<Parameter> action1Parameters = new ArrayList<Parameter>(); - action1Parameters.add(new Parameter().setType(operationType1).setCollection(false)); - action = - new Action().setName(operationName1.getName()).setBound(true).setParameters(action1Parameters); - actions.add(action); - List<Parameter> action2Parameters = new ArrayList<Parameter>(); - action2Parameters.add(new Parameter().setType(operationType1).setCollection(true)); - action = - new Action().setName(operationName1.getName()).setBound(true).setParameters(action2Parameters); - actions.add(action); - when(provider.getActions(operationName1)).thenReturn(actions); - - List<Function> functions = new ArrayList<Function>(); - Function function = new Function().setName(operationName1.getName()); - functions.add(function); - List<Parameter> function1Parameters = new ArrayList<Parameter>(); - function1Parameters.add(new Parameter().setType(operationType1).setName("a")); - function = new Function().setName(operationName1.getName()).setParameters(function1Parameters); - functions.add(function); - List<Parameter> function2Parameters = new ArrayList<Parameter>(); - function2Parameters.add(new Parameter().setType(operationType1).setName("b")); - function = new Function().setName(operationName1.getName()).setParameters(function2Parameters); - functions.add(function); - List<Parameter> function3Parameters = new ArrayList<Parameter>(); - function3Parameters.add(new Parameter().setName("a").setType(operationType1)); - function3Parameters.add(new Parameter().setName("b").setType(operationType1)); - function = new Function().setName(operationName1.getName()).setParameters(function3Parameters).setBound(true); - functions.add(function); - List<Parameter> function4Parameters = new ArrayList<Parameter>(); - function4Parameters.add(new Parameter().setName("a").setType(operationType2)); - function4Parameters.add(new Parameter().setName("b").setType(operationType2)); - function = new Function().setName(operationName1.getName()).setParameters(function4Parameters).setBound(true); - functions.add(function); - when(provider.getFunctions(operationName1)).thenReturn(functions); - - List<Function> badFunctions = new ArrayList<Function>(); - Function badFunction = new Function().setName(operationName1.getName()).setBound(true).setParameters(null); - badFunctions.add(badFunction); - - when(provider.getFunctions(badOperationName)).thenReturn(badFunctions); - - edm = new EdmProviderImpl(provider); - } - - @Test - public void simpleActionGet() { - EdmAction action = edm.getUnboundAction(operationName1); - assertNotNull(action); - assertEquals(operationName1.getNamespace(), action.getNamespace()); - assertEquals(operationName1.getName(), action.getName()); - - assertNull(edm.getUnboundAction(wrongOperationName)); - } - - @Test - public void boundActionOverloading() { - EdmAction action = edm.getBoundAction(operationName1, operationType1, false); - assertNotNull(action); - assertEquals(operationName1.getNamespace(), action.getNamespace()); - assertEquals(operationName1.getName(), action.getName()); - assertTrue(action == edm.getBoundAction(operationName1, operationType1, false)); - - EdmAction action2 = edm.getBoundAction(operationName1, operationType1, true); - assertNotNull(action2); - assertEquals(operationName1.getNamespace(), action2.getNamespace()); - assertEquals(operationName1.getName(), action2.getName()); - assertTrue(action2 == edm.getBoundAction(operationName1, operationType1, true)); - - assertNotSame(action, action2); - } - - @Test - public void simpleFunctionGet() { - EdmFunction function = edm.getUnboundFunction(operationName1, null); - assertNotNull(function); - assertEquals(operationName1.getNamespace(), function.getNamespace()); - assertEquals(operationName1.getName(), function.getName()); - - EdmFunction function2 = edm.getUnboundFunction(operationName1, new ArrayList<String>()); - assertNotNull(function2); - assertEquals(operationName1.getNamespace(), function2.getNamespace()); - assertEquals(operationName1.getName(), function2.getName()); - - assertEquals(function, function2); - - assertNull(edm.getUnboundFunction(wrongOperationName, new ArrayList<String>())); - } - - @Test - public void functionOverloading() { - ArrayList<String> parameter1Names = new ArrayList<String>(); - parameter1Names.add("a"); - List<String> parameter2Names = new ArrayList<String>(); - parameter2Names.add("b"); - EdmFunction function = edm.getUnboundFunction(operationName1, new ArrayList<String>()); - assertNotNull(function); - assertFalse(function.isBound()); - - EdmFunction function1 = edm.getUnboundFunction(operationName1, parameter1Names); - assertNotNull(function1); - assertFalse(function1.isBound()); - - assertFalse(function == function1); - assertNotSame(function, function1); - - EdmFunction function2 = edm.getUnboundFunction(operationName1, parameter2Names); - assertNotNull(function2); - assertFalse(function2.isBound()); - - assertFalse(function1 == function2); - assertNotSame(function1, function2); - - EdmFunction function3 = edm.getBoundFunction(operationName1, operationType1, false, parameter2Names); - assertNotNull(function3); - assertTrue(function3.isBound()); - EdmFunction function4 = edm.getBoundFunction(operationName1, operationType2, false, parameter2Names); - assertNotNull(function4); - assertTrue(function4.isBound()); - - assertFalse(function3 == function4); - assertNotSame(function3, function4); - - assertFalse(function1 == function3); - assertFalse(function1 == function4); - assertFalse(function2 == function3); - assertFalse(function2 == function4); - assertNotSame(function1, function3); - assertNotSame(function1, function4); - assertNotSame(function2, function3); - assertNotSame(function2, function4); - } - - @Test(expected = EdmException.class) - public void noParametersAtBoundFunctionReslutsInException() { - edm.getBoundFunction(badOperationName, operationType1, true, null); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java deleted file mode 100644 index c8a4e38..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java +++ /dev/null @@ -1,224 +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 org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmTypeDefinition; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.AliasInfo; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityContainerInfo; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.apache.olingo.server.api.edm.provider.PropertyRef; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.junit.Before; -import org.junit.Test; - -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Method; -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.fail; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -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()).setUnderlyingType(new FullQualifiedName("Edm", "String")); - 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); - - List<AliasInfo> aliasInfos = new ArrayList<AliasInfo>(); - aliasInfos.add(new AliasInfo().setAlias("alias").setNamespace("namespace")); - when(provider.getAliasInfos()).thenReturn(aliasInfos); - - edm = new EdmProviderImpl(provider); - } - - @Test - public void nothingSpecifiedMustNotResultInExceptions() throws Exception { - EdmProvider localProvider = mock(EdmProvider.class); - when(localProvider.getActions(FQN)).thenReturn(null); - when(localProvider.getFunctions(FQN)).thenReturn(null); - Edm localEdm = new EdmProviderImpl(localProvider); - localEdm.getUnboundAction(FQN); - localEdm.getUnboundFunction(FQN, null); - localEdm.getBoundAction(FQN, FQN, true); - localEdm.getBoundFunction(FQN, FQN, true, null); - localEdm.getComplexType(FQN); - localEdm.getEntityContainer(FQN); - localEdm.getEntityType(FQN); - localEdm.getEnumType(FQN); - localEdm.getTypeDefinition(FQN); - } - - @Test - public void convertExceptionsTest() throws Exception { - EdmProvider localProvider = mock(EdmProvider.class); - FullQualifiedName fqn = new FullQualifiedName("namespace", "name"); - when(localProvider.getEntityContainerInfo(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getEnumType(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getTypeDefinition(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getEntityType(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getComplexType(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getActions(fqn)).thenThrow(new ODataException("msg")); - when(localProvider.getFunctions(fqn)).thenThrow(new ODataException("msg")); - - Edm localEdm = new EdmProviderImpl(localProvider); - - callMethodAndExpectEdmException(localEdm, "getEntityContainer"); - callMethodAndExpectEdmException(localEdm, "getEnumType"); - callMethodAndExpectEdmException(localEdm, "getTypeDefinition"); - callMethodAndExpectEdmException(localEdm, "getEntityType"); - callMethodAndExpectEdmException(localEdm, "getComplexType"); - - // seperate because of signature - try { - localEdm.getUnboundAction(fqn); - } catch (EdmException e) { - assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); - } - - try { - localEdm.getUnboundFunction(fqn, null); - } catch (EdmException e) { - assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); - } - try { - localEdm.getBoundAction(fqn, fqn, true); - } catch (EdmException e) { - assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); - } - - try { - localEdm.getBoundFunction(fqn, fqn, true, null); - } catch (EdmException e) { - assertEquals("org.apache.olingo.commons.api.ODataException: msg", e.getMessage()); - } - } - - private void callMethodAndExpectEdmException(final Edm localEdm, final String methodName) throws Exception { - Method method = localEdm.getClass().getMethod(methodName, FullQualifiedName.class); - try { - method.invoke(localEdm, new FullQualifiedName("namespace", "name")); - } catch (InvocationTargetException e) { - Throwable cause = e.getCause(); - if (cause instanceof EdmException) { - return; - } - } - fail("EdmException expected for method: " + methodName); - } - - @Test(expected = EdmException.class) - public void convertExceptionsAliasTest() throws Exception { - EdmProvider localProvider = mock(EdmProvider.class); - when(localProvider.getAliasInfos()).thenThrow(new ODataException("msg")); - - Edm localEdm = new EdmProviderImpl(localProvider); - localEdm.getEntityContainer(null); - } - - @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)); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmReturnTypeImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmReturnTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmReturnTypeImplTest.java deleted file mode 100644 index fb69f12..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmReturnTypeImplTest.java +++ /dev/null @@ -1,130 +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 org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.EdmReturnType; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.EdmTypeDefinition; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.edm.provider.ReturnType; -import org.junit.Test; - -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.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmReturnTypeImplTest { - - @Test - public void primitiveReturnType() { - ReturnType providerType = new ReturnType().setType(new FullQualifiedName("Edm", "String")); - - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType); - - assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeImpl.getType()); - assertFalse(typeImpl.isCollection()); - - assertNull(typeImpl.getPrecision()); - assertNull(typeImpl.getMaxLength()); - assertNull(typeImpl.getScale()); - assertNull(typeImpl.isNullable()); - } - - @Test - public void primitiveCollectionReturnType() { - ReturnType providerType = new ReturnType().setType(new FullQualifiedName("Edm", "String")).setCollection(true); - - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType); - - assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeImpl.getType()); - assertTrue(typeImpl.isCollection()); - } - - @Test(expected = EdmException.class) - public void invalidPrimitiveType() { - ReturnType providerType = new ReturnType().setType(new FullQualifiedName("Edm", "wrong")).setCollection(true); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType); - typeImpl.getType(); - } - - @Test - public void complexType() { - EdmProviderImpl mock = mock(EdmProviderImpl.class); - FullQualifiedName baseType = new FullQualifiedName("namespace", "type"); - EdmComplexType edmType = mock(EdmComplexType.class); - when(mock.getComplexType(baseType)).thenReturn(edmType); - ReturnType providerType = new ReturnType().setType(baseType); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType); - EdmType returnedType = typeImpl.getType(); - assertEquals(edmType, returnedType); - } - - @Test - public void entityType() { - EdmProviderImpl mock = mock(EdmProviderImpl.class); - FullQualifiedName baseType = new FullQualifiedName("namespace", "type"); - EdmEntityType edmType = mock(EdmEntityType.class); - when(mock.getEntityType(baseType)).thenReturn(edmType); - ReturnType providerType = new ReturnType().setType(baseType); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType); - EdmType returnedType = typeImpl.getType(); - assertEquals(edmType, returnedType); - } - - @Test - public void enumType() { - EdmProviderImpl mock = mock(EdmProviderImpl.class); - FullQualifiedName baseType = new FullQualifiedName("namespace", "type"); - EdmEnumType edmType = mock(EdmEnumType.class); - when(mock.getEnumType(baseType)).thenReturn(edmType); - ReturnType providerType = new ReturnType().setType(baseType); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType); - EdmType returnedType = typeImpl.getType(); - assertEquals(edmType, returnedType); - } - - @Test - public void typeDefinition() { - EdmProviderImpl mock = mock(EdmProviderImpl.class); - FullQualifiedName baseType = new FullQualifiedName("namespace", "type"); - EdmTypeDefinition edmType = mock(EdmTypeDefinition.class); - when(mock.getTypeDefinition(baseType)).thenReturn(edmType); - ReturnType providerType = new ReturnType().setType(baseType); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType); - EdmType returnedType = typeImpl.getType(); - assertEquals(edmType, returnedType); - } - - @Test(expected = EdmException.class) - public void invalidType() { - ReturnType providerType = new ReturnType().setType(new FullQualifiedName("wrong", "wrong")); - EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType); - typeImpl.getType(); - } - -}
