You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2015/10/08 13:46:52 UTC
[3/6] olingo-odata4 git commit: [OLINGO-786] Move edm tests to
commons core
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/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 2131881..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmFunctionImportImplTest.java
+++ /dev/null
@@ -1,88 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-import java.util.Collections;
-
-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.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
-import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
-import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport;
-import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
-import org.apache.olingo.commons.api.edm.provider.CsdlReturnType;
-import org.apache.olingo.commons.core.edm.EdmEntityContainerImpl;
-import org.apache.olingo.commons.core.edm.EdmFunctionImportImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-
-public class EdmFunctionImportImplTest {
-
- @Test
- public void functionImport() throws Exception {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- final FullQualifiedName functionName = new FullQualifiedName("ns", "function");
- final CsdlFunction functionProvider = new CsdlFunction()
- .setName(functionName.getName())
- .setParameters(Collections.<CsdlParameter> emptyList())
- .setBound(false)
- .setComposable(false)
- .setReturnType(new CsdlReturnType().setType(EdmPrimitiveTypeKind.Boolean.getFullQualifiedName()));
- when(provider.getFunctions(functionName)).thenReturn(Arrays.asList(functionProvider));
-
- final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
- final CsdlEntityContainerInfo containerInfo = new CsdlEntityContainerInfo().setContainerName(containerName);
- when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
- final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo);
-
- final String functionImportName = "functionImport";
- final CsdlFunctionImport functionImportProvider = new CsdlFunctionImport()
- .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/9c1981c4/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 00b2fc5..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmKeyPropertyRefImplTest.java
+++ /dev/null
@@ -1,141 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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 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.commons.api.edm.provider.CsdlPropertyRef;
-import org.apache.olingo.commons.core.edm.EdmKeyPropertyRefImpl;
-import org.junit.Test;
-
-public class EdmKeyPropertyRefImplTest {
-
- @Test
- public void noAlias() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("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.getName());
- assertNull(ref.getAlias());
-
- EdmProperty property = ref.getProperty();
- assertNotNull(property);
- assertTrue(property == keyPropertyMock);
- assertTrue(property == ref.getProperty());
- }
-
- @Test
- public void aliasForPropertyInComplexPropertyOneLevel() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/Id").setAlias("alias");
- 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());
-
- EdmProperty property = ref.getProperty();
- assertNotNull(property);
- assertTrue(property == keyPropertyMock);
- }
-
- @Test(expected = EdmException.class)
- public void aliasForPropertyInComplexPropertyButWrongPath() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/wrong").setAlias("alias");
- 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() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("wrong/Id").setAlias("alias");
- 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() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("comp/comp2/Id").setAlias("alias");
- 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() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("Id");
- EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
- ref.getProperty();
- }
-
- @Test(expected = EdmException.class)
- public void aliasButNoPath() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("Id").setAlias("alias");
- EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
- ref.getProperty();
- }
-
- @Test(expected = EdmException.class)
- public void aliasButEmptyPath() {
- CsdlPropertyRef providerRef = new CsdlPropertyRef().setName("").setAlias("alias");
- EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
- ref.getProperty();
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMappingTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMappingTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMappingTest.java
deleted file mode 100644
index c284edf..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMappingTest.java
+++ /dev/null
@@ -1,72 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-
-import java.util.Date;
-
-import org.apache.olingo.commons.api.edm.EdmParameter;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmProperty;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.provider.CsdlMapping;
-import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
-import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
-import org.apache.olingo.commons.core.edm.EdmParameterImpl;
-import org.apache.olingo.commons.core.edm.EdmPropertyImpl;
-import org.junit.Test;
-
-public class EdmMappingTest {
-
- @Test
- public void initialMappingMustBeNull() {
- CsdlProperty property = new CsdlProperty().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
- EdmProperty edmProperty = new EdmPropertyImpl(null, new FullQualifiedName("namespace.name"), property);
-
- assertNull(edmProperty.getMapping());
-
- CsdlParameter parameter = new CsdlParameter().setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName());
- EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
-
- assertNull(edmParameter.getMapping());
- }
-
- @Test
- public void getDataClassForPrimTypeViaMapping() {
- CsdlMapping mapping = new CsdlMapping().setMappedJavaClass(Date.class);
- CsdlProperty property = new CsdlProperty()
- .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
- .setMapping(mapping);
- EdmProperty edmProperty = new EdmPropertyImpl(null, new FullQualifiedName("namespace.name"), property);
-
- assertNotNull(edmProperty.getMapping());
- assertEquals(Date.class, edmProperty.getMapping().getMappedJavaClass());
-
- CsdlParameter parameter = new CsdlParameter()
- .setType(EdmPrimitiveTypeKind.DateTimeOffset.getFullQualifiedName())
- .setMapping(mapping);
- EdmParameter edmParameter = new EdmParameterImpl(null, parameter);
-
- assertNotNull(edmParameter.getMapping());
- assertEquals(Date.class, edmParameter.getMapping().getMappedJavaClass());
- }
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/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 a5e774c..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmMemberImplTest.java
+++ /dev/null
@@ -1,40 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumMember;
-import org.apache.olingo.commons.core.edm.EdmMemberImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Test;
-
-public class EdmMemberImplTest {
-
- @Test
- public void enumMember() {
- final CsdlEnumMember member = new CsdlEnumMember().setName("name").setValue("value");
- final EdmMemberImpl memberImpl = new EdmMemberImpl(mock(EdmProviderImpl.class), null, member);
-
- assertEquals("name", memberImpl.getName());
- assertEquals("value", memberImpl.getValue());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/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 bfab176..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmNavigationPropertyImplTest.java
+++ /dev/null
@@ -1,146 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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;
-
-import java.util.ArrayList;
-import java.util.Collections;
-import java.util.List;
-
-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.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
-import org.apache.olingo.commons.api.edm.provider.CsdlNavigationProperty;
-import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
-import org.apache.olingo.commons.api.edm.provider.CsdlReferentialConstraint;
-import org.apache.olingo.commons.core.edm.EdmNavigationPropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Test;
-
-public class EdmNavigationPropertyImplTest {
-
- @Test
- public void navigationProperty() throws Exception {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
- CsdlEntityType entityTypeProvider = new CsdlEntityType();
- entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
- when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
- CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
- CsdlEntityType entityTypeProvider = new CsdlEntityType();
- entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
- when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
- CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
- propertyProvider.setType(entityTypeName);
- propertyProvider.setNullable(false);
- List<CsdlReferentialConstraint> referentialConstraints = new ArrayList<CsdlReferentialConstraint>();
- referentialConstraints.add(new CsdlReferentialConstraint().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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
- CsdlEntityType entityTypeProvider = new CsdlEntityType();
- entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
-
- List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
- navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
- entityTypeProvider.setNavigationProperties(navigationProperties);
- when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
- CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName entityTypeName = new FullQualifiedName("ns", "entity");
- CsdlEntityType entityTypeProvider = new CsdlEntityType();
- entityTypeProvider.setKey(Collections.<CsdlPropertyRef> emptyList());
-
- List<CsdlNavigationProperty> navigationProperties = new ArrayList<CsdlNavigationProperty>();
- navigationProperties.add(new CsdlNavigationProperty().setName("partnerName").setType(entityTypeName));
- entityTypeProvider.setNavigationProperties(navigationProperties);
- when(provider.getEntityType(entityTypeName)).thenReturn(entityTypeProvider);
- CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
- 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);
- CsdlNavigationProperty propertyProvider = new CsdlNavigationProperty();
- 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/9c1981c4/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 5babbdb..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmParameterImplTest.java
+++ /dev/null
@@ -1,143 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-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.commons.api.edm.provider.CsdlComplexType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmParameterImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Test;
-
-public class EdmParameterImplTest {
-
- @Test
- public void getTypeReturnsPrimitiveType() {
- EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
- CsdlParameter parameterProvider = new CsdlParameter();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex");
- CsdlComplexType complexTypeProvider = new CsdlComplexType();
- when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider);
- CsdlParameter parameterProvider = new CsdlParameter();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum");
- CsdlEnumType enumTypeProvider = new CsdlEnumType();
- when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider);
- CsdlParameter parameterProvider = new CsdlParameter();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName typeName = new FullQualifiedName("ns", "definition");
- CsdlTypeDefinition typeProvider =
- new CsdlTypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String"));
- when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider);
- CsdlParameter parameterProvider = new CsdlParameter();
- 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(CsdlEdmProvider.class));
- CsdlParameter parameterProvider = new CsdlParameter();
- 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(CsdlEdmProvider.class));
- CsdlParameter parameterProvider = new CsdlParameter();
- 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(CsdlEdmProvider.class));
- CsdlParameter parameterProvider = new CsdlParameter();
- 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/9c1981c4/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 e9f907f..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmPropertyImplTest.java
+++ /dev/null
@@ -1,158 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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;
-
-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.commons.api.edm.provider.CsdlComplexType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.api.edm.provider.CsdlProperty;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmPropertyImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Test;
-
-public class EdmPropertyImplTest {
-
- @Test
- public void getTypeReturnsPrimitiveType() {
- EdmProviderImpl edm = new EdmProviderImpl(mock(CsdlEdmProvider.class));
- CsdlProperty propertyProvider = new CsdlProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName complexTypeName = new FullQualifiedName("ns", "complex");
- CsdlComplexType complexTypeProvider = new CsdlComplexType();
- when(provider.getComplexType(complexTypeName)).thenReturn(complexTypeProvider);
- CsdlProperty propertyProvider = new CsdlProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName enumTypeName = new FullQualifiedName("ns", "enum");
- CsdlEnumType enumTypeProvider = new CsdlEnumType();
- when(provider.getEnumType(enumTypeName)).thenReturn(enumTypeProvider);
- CsdlProperty propertyProvider = new CsdlProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final FullQualifiedName typeName = new FullQualifiedName("ns", "definition");
- CsdlTypeDefinition typeProvider =
- new CsdlTypeDefinition().setUnderlyingType(new FullQualifiedName("Edm", "String"));
- when(provider.getTypeDefinition(typeName)).thenReturn(typeProvider);
- CsdlProperty propertyProvider = new CsdlProperty();
- 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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final CsdlProperty propertyProvider = new CsdlProperty()
- .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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
- final CsdlProperty propertyProvider = new CsdlProperty()
- .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(CsdlEdmProvider.class));
- CsdlProperty propertyProvider = new CsdlProperty();
- 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/9c1981c4/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 45d3d2b..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplOverloadingTest.java
+++ /dev/null
@@ -1,199 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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;
-
-import java.util.ArrayList;
-import java.util.List;
-
-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.commons.api.edm.provider.CsdlAction;
-import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
-import org.apache.olingo.commons.api.edm.provider.CsdlParameter;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Before;
-import org.junit.Test;
-
-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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
-
- List<CsdlAction> actions = new ArrayList<CsdlAction>();
- CsdlAction action = new CsdlAction().setName(operationName1.getName());
- actions.add(action);
- List<CsdlParameter> action1Parameters = new ArrayList<CsdlParameter>();
- action1Parameters.add(new CsdlParameter().setType(operationType1).setCollection(false));
- action =
- new CsdlAction().setName(operationName1.getName()).setBound(true).setParameters(action1Parameters);
- actions.add(action);
- List<CsdlParameter> action2Parameters = new ArrayList<CsdlParameter>();
- action2Parameters.add(new CsdlParameter().setType(operationType1).setCollection(true));
- action =
- new CsdlAction().setName(operationName1.getName()).setBound(true).setParameters(action2Parameters);
- actions.add(action);
- when(provider.getActions(operationName1)).thenReturn(actions);
-
- List<CsdlFunction> functions = new ArrayList<CsdlFunction>();
- CsdlFunction function = new CsdlFunction().setName(operationName1.getName());
- functions.add(function);
- List<CsdlParameter> function1Parameters = new ArrayList<CsdlParameter>();
- function1Parameters.add(new CsdlParameter().setType(operationType1).setName("a"));
- function = new CsdlFunction().setName(operationName1.getName()).setParameters(function1Parameters);
- functions.add(function);
- List<CsdlParameter> function2Parameters = new ArrayList<CsdlParameter>();
- function2Parameters.add(new CsdlParameter().setType(operationType1).setName("b"));
- function = new CsdlFunction().setName(operationName1.getName()).setParameters(function2Parameters);
- functions.add(function);
- List<CsdlParameter> function3Parameters = new ArrayList<CsdlParameter>();
- function3Parameters.add(new CsdlParameter().setName("a").setType(operationType1));
- function3Parameters.add(new CsdlParameter().setName("b").setType(operationType1));
- function = new CsdlFunction().setName(operationName1.getName()).setParameters(function3Parameters).setBound(true);
- functions.add(function);
- List<CsdlParameter> function4Parameters = new ArrayList<CsdlParameter>();
- function4Parameters.add(new CsdlParameter().setName("a").setType(operationType2));
- function4Parameters.add(new CsdlParameter().setName("b").setType(operationType2));
- function = new CsdlFunction().setName(operationName1.getName()).setParameters(function4Parameters).setBound(true);
- functions.add(function);
- when(provider.getFunctions(operationName1)).thenReturn(functions);
-
- List<CsdlFunction> badFunctions = new ArrayList<CsdlFunction>();
- CsdlFunction badFunction = new CsdlFunction().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/9c1981c4/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 c094b1d..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmProviderImplTest.java
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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;
-
-import java.lang.reflect.InvocationTargetException;
-import java.lang.reflect.Method;
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.commons.api.ex.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.commons.api.edm.provider.CsdlAliasInfo;
-import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-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 {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- CsdlEntityContainerInfo containerInfo = new CsdlEntityContainerInfo().setContainerName(FQN);
- when(provider.getEntityContainerInfo(FQN)).thenReturn(containerInfo);
- when(provider.getEntityContainerInfo(null)).thenReturn(containerInfo);
-
- CsdlEnumType enumType = new CsdlEnumType().setName(FQN.getName());
- when(provider.getEnumType(FQN)).thenReturn(enumType);
-
- CsdlTypeDefinition typeDefinition =
- new CsdlTypeDefinition().setName(FQN.getName()).setUnderlyingType(new FullQualifiedName("Edm", "String"));
- when(provider.getTypeDefinition(FQN)).thenReturn(typeDefinition);
-
- CsdlEntityType entityType = new CsdlEntityType().setName(FQN.getName()).setKey(new ArrayList<CsdlPropertyRef>());
- when(provider.getEntityType(FQN)).thenReturn(entityType);
-
- CsdlComplexType complexType = new CsdlComplexType().setName(FQN.getName());
- when(provider.getComplexType(FQN)).thenReturn(complexType);
-
- List<CsdlAliasInfo> aliasInfos = new ArrayList<CsdlAliasInfo>();
- aliasInfos.add(new CsdlAliasInfo().setAlias("alias").setNamespace("namespace"));
- when(provider.getAliasInfos()).thenReturn(aliasInfos);
-
- edm = new EdmProviderImpl(provider);
- }
-
- @Test
- public void nothingSpecifiedMustNotResultInExceptions() throws Exception {
- CsdlEdmProvider localProvider = mock(CsdlEdmProvider.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 {
- CsdlEdmProvider localProvider = mock(CsdlEdmProvider.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.ex.ODataException: msg", e.getMessage());
- }
-
- try {
- localEdm.getUnboundFunction(fqn, null);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.commons.api.ex.ODataException: msg", e.getMessage());
- }
- try {
- localEdm.getBoundAction(fqn, fqn, true);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.commons.api.ex.ODataException: msg", e.getMessage());
- }
-
- try {
- localEdm.getBoundFunction(fqn, fqn, true, null);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.commons.api.ex.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 {
- CsdlEdmProvider localProvider = mock(CsdlEdmProvider.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/9c1981c4/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 ac36635..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmReturnTypeImplTest.java
+++ /dev/null
@@ -1,134 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.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;
-
-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.api.edm.provider.CsdlReturnType;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.EdmReturnTypeImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-
-public class EdmReturnTypeImplTest {
-
- @Test
- public void primitiveReturnType() {
- CsdlReturnType providerType = new CsdlReturnType().setType(new FullQualifiedName("Edm", "String"));
-
- EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType);
-
- assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeImpl.getType());
- assertFalse(typeImpl.isCollection());
- assertTrue(typeImpl.isNullable());
-
- assertNull(typeImpl.getPrecision());
- assertNull(typeImpl.getMaxLength());
- assertNull(typeImpl.getScale());
- }
-
- @Test
- public void primitiveCollectionReturnType() {
- CsdlReturnType providerType = new CsdlReturnType().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() {
- CsdlReturnType providerType = new CsdlReturnType().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);
- CsdlReturnType providerType = new CsdlReturnType().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);
- CsdlReturnType providerType = new CsdlReturnType().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);
- CsdlReturnType providerType = new CsdlReturnType().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);
- CsdlReturnType providerType = new CsdlReturnType().setType(baseType);
- EdmReturnType typeImpl = new EdmReturnTypeImpl(mock, providerType);
- EdmType returnedType = typeImpl.getType();
- assertEquals(edmType, returnedType);
- }
-
- @Test(expected = EdmException.class)
- public void invalidType() {
- CsdlReturnType providerType = new CsdlReturnType().setType(new FullQualifiedName("wrong", "wrong"));
- EdmReturnType typeImpl = new EdmReturnTypeImpl(mock(EdmProviderImpl.class), providerType);
- typeImpl.getType();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
deleted file mode 100644
index fd344c5..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java
+++ /dev/null
@@ -1,363 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-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.commons.api.ex.ODataException;
-import org.apache.olingo.commons.api.edm.Edm;
-import org.apache.olingo.commons.api.edm.EdmAction;
-import org.apache.olingo.commons.api.edm.EdmActionImport;
-import org.apache.olingo.commons.api.edm.EdmComplexType;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntitySet;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmEnumType;
-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.EdmSchema;
-import org.apache.olingo.commons.api.edm.EdmSingleton;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.provider.CsdlAbstractEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlAction;
-import org.apache.olingo.commons.api.edm.provider.CsdlActionImport;
-import org.apache.olingo.commons.api.edm.provider.CsdlAliasInfo;
-import org.apache.olingo.commons.api.edm.provider.CsdlComplexType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainer;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityContainerInfo;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntitySet;
-import org.apache.olingo.commons.api.edm.provider.CsdlEntityType;
-import org.apache.olingo.commons.api.edm.provider.CsdlEnumType;
-import org.apache.olingo.commons.api.edm.provider.CsdlFunction;
-import org.apache.olingo.commons.api.edm.provider.CsdlFunctionImport;
-import org.apache.olingo.commons.api.edm.provider.CsdlSchema;
-import org.apache.olingo.commons.api.edm.provider.CsdlSingleton;
-import org.apache.olingo.commons.api.edm.provider.CsdlTerm;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.junit.Before;
-import org.junit.Test;
-
-public class EdmSchemaImplTest {
-
- private EdmSchema schema;
- private Edm edm;
-
- @Before
- public void before() {
- CsdlEdmProvider provider = new LocalProvider();
- edm = new EdmProviderImpl(provider);
- schema = edm.getSchemas().get(0);
-
- }
-
- @Test
- public void initialSchemaTest() {
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- edm = new EdmProviderImpl(provider);
- edm.getSchemas();
- }
-
- @Test
- public void emptySchemaTest() throws Exception {
- ArrayList<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
- CsdlSchema providerSchema = new CsdlSchema();
- schemas.add(providerSchema);
- CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
- when(provider.getSchemas()).thenReturn(schemas);
- edm = new EdmProviderImpl(provider);
- edm.getSchemas();
- }
-
- @Test
- public void basicGetters() {
- assertEquals("org.namespace", schema.getNamespace());
- assertEquals("alias", schema.getAlias());
- }
-
- @Test
- public void getTypeDefinitions() {
- List<EdmTypeDefinition> typeDefinitions = schema.getTypeDefinitions();
- assertNotNull(typeDefinitions);
- assertEquals(2, typeDefinitions.size());
-
- for (EdmTypeDefinition def : typeDefinitions) {
- assertTrue(def == edm.getTypeDefinition(new FullQualifiedName("org.namespace", def.getName())));
- }
- }
-
- @Test
- public void getEnumTypes() {
- List<EdmEnumType> enumTypes = schema.getEnumTypes();
- assertNotNull(enumTypes);
- assertEquals(2, enumTypes.size());
-
- for (EdmEnumType enumType : enumTypes) {
- assertTrue(enumType == edm.getEnumType(new FullQualifiedName("org.namespace", enumType.getName())));
- }
- }
-
- @Test
- public void getEntityTypes() {
- List<EdmEntityType> entityTypes = schema.getEntityTypes();
- assertNotNull(entityTypes);
- assertEquals(2, entityTypes.size());
-
- for (EdmEntityType entityType : entityTypes) {
- assertTrue(entityType == edm.getEntityType(new FullQualifiedName("org.namespace", entityType.getName())));
- }
- }
-
- @Test
- public void getComplexTypes() {
- List<EdmComplexType> complexTypes = schema.getComplexTypes();
- assertNotNull(complexTypes);
- assertEquals(2, complexTypes.size());
-
- for (EdmComplexType complexType : complexTypes) {
- assertTrue(complexType == edm.getComplexType(new FullQualifiedName("org.namespace", complexType.getName())));
- }
- }
-
- @Test
- public void getActions() {
- List<EdmAction> actions = schema.getActions();
- assertNotNull(actions);
- assertEquals(2, actions.size());
-
- for (EdmAction action : actions) {
- assertTrue(action == edm.getUnboundAction(new FullQualifiedName("org.namespace", action.getName())));
- }
- }
-
- @Test
- public void getFunctions() {
- List<EdmFunction> functions = schema.getFunctions();
- assertNotNull(functions);
- assertEquals(2, functions.size());
-
- for (EdmFunction function : functions) {
- FullQualifiedName functionName = new FullQualifiedName("org.namespace", function.getName());
- assertTrue(function == edm.getUnboundFunction(functionName, null));
- }
- }
-
- @Test
- public void getContainer() {
- EdmEntityContainer container = schema.getEntityContainer();
- assertNotNull(container);
-
- List<EdmEntitySet> entitySets = container.getEntitySets();
- assertNotNull(entitySets);
- assertEquals(2, entitySets.size());
- for (EdmEntitySet obj : entitySets) {
- assertNotNull(obj.getEntityType());
- }
-
- List<EdmSingleton> singletons = container.getSingletons();
- assertNotNull(singletons);
- assertEquals(2, singletons.size());
- for (EdmSingleton obj : singletons) {
- assertNotNull(obj.getEntityType());
- }
-
- List<EdmActionImport> actionImports = container.getActionImports();
- assertNotNull(actionImports);
- assertEquals(2, actionImports.size());
- for (EdmActionImport obj : actionImports) {
- assertNotNull(obj.getUnboundAction());
- }
-
- List<EdmFunctionImport> functionImports = container.getFunctionImports();
- assertNotNull(functionImports);
- assertEquals(2, functionImports.size());
- for (EdmFunctionImport obj : functionImports) {
- assertNotNull(obj.getFunctionFqn());
- }
-
- assertTrue(container == edm.getEntityContainer(new FullQualifiedName(schema.getNamespace(), container.getName())));
- assertTrue(container == edm.getEntityContainer(null));
- }
-
- private class LocalProvider extends CsdlAbstractEdmProvider {
-
- private static final String ALIAS = "alias";
- private static final String NAMESPACE = "org.namespace";
-
- @Override
- public CsdlEnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlTypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlEntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public List<CsdlAction> getActions(final FullQualifiedName actionName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public List<CsdlFunction> getFunctions(final FullQualifiedName functionName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlTerm getTerm(final FullQualifiedName termName) throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlEntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
- throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlSingleton getSingleton(final FullQualifiedName entityContainer, final String singletonName)
- throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName)
- throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlFunctionImport getFunctionImport(final FullQualifiedName entityContainer,
- final String functionImportName)
- throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public CsdlEntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName)
- throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public List<CsdlAliasInfo> getAliasInfos() throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
-
- @Override
- public List<CsdlSchema> getSchemas() throws ODataException {
- CsdlSchema providerSchema = new CsdlSchema();
- providerSchema.setNamespace(NAMESPACE);
- providerSchema.setAlias(ALIAS);
- CsdlEntityContainer container = new CsdlEntityContainer().setName("container");
-
- List<CsdlEntitySet> entitySets = new ArrayList<CsdlEntitySet>();
- entitySets.add(new CsdlEntitySet().setName("entitySetName")
- .setType(new FullQualifiedName(NAMESPACE, "entityType1")));
- entitySets
- .add(new CsdlEntitySet().setName("entitySetName2").setType(new FullQualifiedName(NAMESPACE, "entityType2")));
- container.setEntitySets(entitySets);
-
- List<CsdlSingleton> singletons = new ArrayList<CsdlSingleton>();
- singletons.add(new CsdlSingleton().setName("singletonName")
- .setType(new FullQualifiedName(NAMESPACE, "entityType1")));
- singletons
- .add(new CsdlSingleton().setName("singletonName2").setType(new FullQualifiedName(NAMESPACE, "entityType2")));
- container.setSingletons(singletons);
-
- List<CsdlActionImport> actionImports = new ArrayList<CsdlActionImport>();
- actionImports.add(new CsdlActionImport().setName("actionImportName").setAction(
- new FullQualifiedName(NAMESPACE, "action1")));
- actionImports.add(new CsdlActionImport().setName("actionImportName2").setAction(
- new FullQualifiedName(NAMESPACE, "action2")));
- container.setActionImports(actionImports);
-
- List<CsdlFunctionImport> functionImports = new ArrayList<CsdlFunctionImport>();
- functionImports.add(new CsdlFunctionImport().setName("functionImportName").setFunction(
- new FullQualifiedName(NAMESPACE, "function1")));
- functionImports.add(new CsdlFunctionImport().setName("functionImportName2").setFunction(
- new FullQualifiedName(NAMESPACE, "function2")));
- container.setFunctionImports(functionImports);
- providerSchema.setEntityContainer(container);
-
- List<CsdlTypeDefinition> typeDefinitions = new ArrayList<CsdlTypeDefinition>();
- typeDefinitions.add(new CsdlTypeDefinition().setName("typeDefinition1").setUnderlyingType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- typeDefinitions.add(new CsdlTypeDefinition().setName("typeDefinition2").setUnderlyingType(
- EdmPrimitiveTypeKind.String.getFullQualifiedName()));
- providerSchema.setTypeDefinitions(typeDefinitions);
-
- List<CsdlEnumType> enumTypes = new ArrayList<CsdlEnumType>();
- enumTypes.add(new CsdlEnumType().setName("enumType1"));
- enumTypes.add(new CsdlEnumType().setName("enumType2"));
- providerSchema.setEnumTypes(enumTypes);
-
- List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>();
- entityTypes.add(new CsdlEntityType().setName("entityType1"));
- entityTypes.add(new CsdlEntityType().setName("entityType2")
- .setBaseType(new FullQualifiedName(NAMESPACE, "entityType1")));
- providerSchema.setEntityTypes(entityTypes);
-
- List<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>();
- complexTypes.add(new CsdlComplexType().setName("complexType1"));
- complexTypes.add(new CsdlComplexType().setName("complexType2").setBaseType(
- new FullQualifiedName(NAMESPACE, "complexType1")));
- providerSchema.setComplexTypes(complexTypes);
-
- List<CsdlAction> actions = new ArrayList<CsdlAction>();
- actions.add(new CsdlAction().setName("action1"));
- actions.add(new CsdlAction().setName("action2"));
- providerSchema.setActions(actions);
-
- List<CsdlFunction> functions = new ArrayList<CsdlFunction>();
- functions.add(new CsdlFunction().setName("function1"));
- functions.add(new CsdlFunction().setName("function2"));
- providerSchema.setFunctions(functions);
- ArrayList<CsdlSchema> schemas = new ArrayList<CsdlSchema>();
- schemas.add(providerSchema);
- return schemas;
- }
-
- @Override
- public CsdlEntityContainer getEntityContainer() throws ODataException {
- throw new RuntimeException("Provider must not be called in the schema case");
- }
- }
-}