You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/02/19 14:41:54 UTC
[14/29] [OLINGO-170] Moved provider and implementation to server
module
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmKeyPropertyRefImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmKeyPropertyRefImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmKeyPropertyRefImplTest.java
deleted file mode 100644
index 91ea8de..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
-import org.apache.olingo.odata4.commons.api.edm.EdmElement;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
-import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
-import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
-import org.junit.Test;
-
-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.getProperty("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);
- 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);
- 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);
- EdmElement compMock = mock(EdmProperty.class);
- EdmComplexType compTypeMock = mock(EdmComplexType.class);
- EdmElement comp2Mock = mock(EdmProperty.class);
- EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
- when(comp2TypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
- when(comp2Mock.getType()).thenReturn(comp2TypeMock);
- when(compTypeMock.getProperty("comp2")).thenReturn(comp2Mock);
- when(compMock.getType()).thenReturn(compTypeMock);
- when(etMock.getProperty("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/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmMemberImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmMemberImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmMemberImplTest.java
deleted file mode 100644
index 67bebf0..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmMemberImplTest.java
+++ /dev/null
@@ -1,38 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.mockito.Mockito.mock;
-
-import org.apache.olingo.odata4.commons.api.edm.provider.EnumMember;
-import org.junit.Test;
-
-public class EdmMemberImplTest {
-
- @Test
- public void enumMember() {
- EnumMember member = new EnumMember().setName("name").setValue("value");
- EdmMemberImpl memberImpl = new EdmMemberImpl(mock(EdmProviderImpl.class), member);
-
- assertEquals("name", memberImpl.getName());
- assertEquals("value", memberImpl.getValue());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
deleted file mode 100644
index e6187e6..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNamedImplTest.java
+++ /dev/null
@@ -1,41 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmNamed;
-import org.junit.Test;
-
-public class EdmNamedImplTest {
-
- @Test
- public void getNameTest() {
- EdmNamed obj = new EdmNamedImplTester("Name");
- assertEquals("Name", obj.getName());
- }
-
- private class EdmNamedImplTester extends EdmNamedImpl {
-
- public EdmNamedImplTester(final String name) {
- super(null, name);
- }
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmNavigationPropertyImplTest.java
deleted file mode 100644
index d1bc879..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/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.odata4.commons.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.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty;
-import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata4.commons.api.edm.provider.ReferentialConstraint;
-import org.junit.Test;
-
-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, 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, 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, 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, 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, propertyProvider);
- property.getType();
- }
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmParameterImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmParameterImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmParameterImplTest.java
deleted file mode 100644
index f7d3ebc..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/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.odata4.commons.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.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
-import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
-import org.junit.Test;
-
-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();
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmPropertyImplTest.java
deleted file mode 100644
index 9c51393..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/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.odata4.commons.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.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
-import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.Property;
-import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
-import org.junit.Test;
-
-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, 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, 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, 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, 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, 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, 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, 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/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplOverloadingTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplOverloadingTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplOverloadingTest.java
deleted file mode 100644
index b652da2..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/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.odata4.commons.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.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.EdmAction;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
-import org.apache.olingo.odata4.commons.api.edm.provider.Action;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.Function;
-import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
-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 {
- 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"));
- 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"));
- 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.getAction(operationName1, null, null);
- assertNotNull(action);
- assertEquals(operationName1.getNamespace(), action.getNamespace());
- assertEquals(operationName1.getName(), action.getName());
-
- assertNull(edm.getAction(wrongOperationName, null, null));
- }
-
- @Test
- public void boundActionOverloading() {
- EdmAction action = edm.getAction(operationName1, operationType1, false);
- assertNotNull(action);
- assertEquals(operationName1.getNamespace(), action.getNamespace());
- assertEquals(operationName1.getName(), action.getName());
- assertTrue(action == edm.getAction(operationName1, operationType1, false));
-
- EdmAction action2 = edm.getAction(operationName1, operationType1, true);
- assertNotNull(action2);
- assertEquals(operationName1.getNamespace(), action2.getNamespace());
- assertEquals(operationName1.getName(), action2.getName());
- assertTrue(action2 == edm.getAction(operationName1, operationType1, true));
-
- assertNotSame(action, action2);
- }
-
- @Test
- public void simpleFunctionGet() {
- EdmFunction function = edm.getFunction(operationName1, null, null, null);
- assertNotNull(function);
- assertEquals(operationName1.getNamespace(), function.getNamespace());
- assertEquals(operationName1.getName(), function.getName());
-
- EdmFunction function2 = edm.getFunction(operationName1, null, null, new ArrayList<String>());
- assertNotNull(function2);
- assertEquals(operationName1.getNamespace(), function2.getNamespace());
- assertEquals(operationName1.getName(), function2.getName());
-
- assertEquals(function, function2);
-
- assertNull(edm.getFunction(wrongOperationName, null, null, 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.getFunction(operationName1, null, null, new ArrayList<String>());
- assertNotNull(function);
- assertFalse(function.isBound());
-
- EdmFunction function1 = edm.getFunction(operationName1, null, null, parameter1Names);
- assertNotNull(function1);
- assertFalse(function1.isBound());
-
- assertFalse(function == function1);
- assertNotSame(function, function1);
-
- EdmFunction function2 = edm.getFunction(operationName1, null, null, parameter2Names);
- assertNotNull(function2);
- assertFalse(function2.isBound());
-
- assertFalse(function1 == function2);
- assertNotSame(function1, function2);
-
- EdmFunction function3 = edm.getFunction(operationName1, operationType1, false, parameter2Names);
- assertNotNull(function3);
- assertTrue(function3.isBound());
- EdmFunction function4 = edm.getFunction(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.getFunction(badOperationName, operationType1, true, null);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
deleted file mode 100644
index 24fcbd2..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmProviderImplTest.java
+++ /dev/null
@@ -1,231 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.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.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.odata4.commons.api.edm.provider.AliasInfo;
-import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
-import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.odata4.commons.api.exception.ODataException;
-import org.junit.Before;
-import org.junit.Test;
-
-public class EdmProviderImplTest {
-
- private Edm edm;
- private final FullQualifiedName FQN = new FullQualifiedName("testNamespace", "testName");
- private final FullQualifiedName WRONG_FQN = new FullQualifiedName("wrong", "wrong");
-
- @Before
- public void setup() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(FQN);
- when(provider.getEntityContainerInfo(FQN)).thenReturn(containerInfo);
- when(provider.getEntityContainerInfo(null)).thenReturn(containerInfo);
-
- EnumType enumType = new EnumType().setName(FQN.getName());
- when(provider.getEnumType(FQN)).thenReturn(enumType);
-
- TypeDefinition typeDefinition =
- new TypeDefinition().setName(FQN.getName()).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.getAction(FQN, null, null);
- localEdm.getFunction(FQN, null, null, null);
- localEdm.getAction(FQN, FQN, true);
- localEdm.getFunction(FQN, FQN, true, null);
- localEdm.getComplexType(FQN);
- localEdm.getEntityContainer(FQN);
- localEdm.getEntityType(FQN);
- localEdm.getEnumType(FQN);
- localEdm.getTypeDefinition(FQN);
- localEdm.getServiceMetadata();
- }
-
- @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.getAction(fqn, null, null);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- }
-
- try {
- localEdm.getFunction(fqn, null, null, null);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- }
- try {
- localEdm.getAction(fqn, fqn, true);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- }
-
- try {
- localEdm.getFunction(fqn, fqn, true, null);
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.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));
- }
-
- @Test
- public void getServiceMetadata() {
- assertNotNull(edm.getServiceMetadata());
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmReturnTypeImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmReturnTypeImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmReturnTypeImplTest.java
deleted file mode 100644
index ae54cec..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmReturnTypeImplTest.java
+++ /dev/null
@@ -1,129 +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.odata4.commons.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.odata4.commons.api.edm.EdmComplexType;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.ReturnType;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
-import org.junit.Test;
-
-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(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), 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(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), 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();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmServiceMetadataImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmServiceMetadataImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmServiceMetadataImplTest.java
deleted file mode 100644
index 62d3e0f..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmServiceMetadataImplTest.java
+++ /dev/null
@@ -1,188 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
-import static org.junit.Assert.fail;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmEntitySetInfo;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImportInfo;
-import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata;
-import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo;
-import org.apache.olingo.odata4.commons.api.edm.constants.ODataServiceVersion;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntitySet;
-import org.apache.olingo.odata4.commons.api.edm.provider.FunctionImport;
-import org.apache.olingo.odata4.commons.api.edm.provider.Schema;
-import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
-import org.apache.olingo.odata4.commons.api.exception.ODataException;
-import org.junit.Test;
-
-public class EdmServiceMetadataImplTest {
-
- @Test
- public void allGettersMustDeliver() {
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(new CustomProvider(true));
- List<EdmEntitySetInfo> entitySetInfos = serviceMetadata.getEntitySetInfos();
- assertNotNull(entitySetInfos);
- assertEquals(2, entitySetInfos.size());
-
- List<EdmSingletonInfo> singletonInfos = serviceMetadata.getSingletonInfos();
- assertNotNull(singletonInfos);
- assertEquals(2, singletonInfos.size());
-
- List<EdmFunctionImportInfo> functionImportInfos = serviceMetadata.getFunctionImportInfos();
- assertNotNull(functionImportInfos);
- assertEquals(2, functionImportInfos.size());
-
- // Cache test
- assertTrue(entitySetInfos == serviceMetadata.getEntitySetInfos());
- assertTrue(singletonInfos == serviceMetadata.getSingletonInfos());
- assertTrue(functionImportInfos == serviceMetadata.getFunctionImportInfos());
- }
-
- @Test(expected = RuntimeException.class)
- public void getMetadataAsInputStreamIsNotImplemented() {
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(new CustomProvider(true));
- serviceMetadata.getMetadata();
- }
-
- @Test
- public void initialProvider() {
- EdmProvider provider = new EdmProvider() {};
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(provider);
- assertEquals(ODataServiceVersion.V40, serviceMetadata.getDataServiceVersion());
- }
-
- @Test(expected = EdmException.class)
- public void initialProviderEntitySetInfo() {
- EdmProvider provider = new EdmProvider() {};
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(provider);
- serviceMetadata.getEntitySetInfos();
- }
-
- @Test(expected = EdmException.class)
- public void initialProviderSingletonInfo() {
- EdmProvider provider = new EdmProvider() {};
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(provider);
- serviceMetadata.getSingletonInfos();
- }
-
- @Test(expected = EdmException.class)
- public void initialProviderFunctionImportInfo() {
- EdmProvider provider = new EdmProvider() {};
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(provider);
- serviceMetadata.getFunctionImportInfos();
- }
-
- @Test
- public void emptySchemaMustNotResultInException() {
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(new CustomProvider(false));
- assertNotNull(serviceMetadata.getEntitySetInfos());
- assertEquals(0, serviceMetadata.getEntitySetInfos().size());
-
- assertNotNull(serviceMetadata.getSingletonInfos());
- assertEquals(0, serviceMetadata.getSingletonInfos().size());
-
- assertNotNull(serviceMetadata.getFunctionImportInfos());
- assertEquals(0, serviceMetadata.getFunctionImportInfos().size());
- }
-
- @Test
- public void oDataExceptionsGetCaughtAndTransformed() {
- EdmProvider provider = new EdmProvider() {
- @Override
- public List<Schema> getSchemas() throws ODataException {
- throw new ODataException("msg");
- }
- };
-
- EdmServiceMetadata serviceMetadata = new EdmServiceMetadataImpl(provider);
- callGetEntitySetInfosAndExpectException(serviceMetadata);
- callGetSingletonInfosAndExpectException(serviceMetadata);
- callGetFunctionImportInfosAndExpectException(serviceMetadata);
- }
-
- private void callGetFunctionImportInfosAndExpectException(final EdmServiceMetadata svc) {
- try {
- svc.getFunctionImportInfos();
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- return;
- }
- fail("Expected EdmException was not thrown");
-
- }
-
- private void callGetSingletonInfosAndExpectException(final EdmServiceMetadata svc) {
- try {
- svc.getSingletonInfos();
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- return;
- }
- fail("Expected EdmException was not thrown");
- }
-
- private void callGetEntitySetInfosAndExpectException(final EdmServiceMetadata svc) {
- try {
- svc.getEntitySetInfos();
- } catch (EdmException e) {
- assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
- return;
- }
- fail("Expected EdmException was not thrown");
- }
-
- private class CustomProvider extends EdmProvider {
- private List<Schema> schemas;
-
- public CustomProvider(final boolean fillSchema) {
- schemas = new ArrayList<Schema>();
- if (fillSchema) {
- List<EntitySet> entitySets = new ArrayList<EntitySet>();
- entitySets.add(new EntitySet().setName("1"));
- entitySets.add(new EntitySet().setName("2"));
- List<Singleton> singletons = new ArrayList<Singleton>();
- singletons.add(new Singleton().setName("1"));
- singletons.add(new Singleton().setName("2"));
- List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
- functionImports.add(new FunctionImport().setName("1"));
- functionImports.add(new FunctionImport().setName("2"));
- EntityContainer entityContainer =
- new EntityContainer().setName("cont").setEntitySets(entitySets).setSingletons(singletons)
- .setFunctionImports(functionImports);
- Schema schema = new Schema().setEntityContainer(entityContainer);
- schemas.add(schema);
- }
- }
-
- @Override
- public List<Schema> getSchemas() throws ODataException {
- return schemas;
- }
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonImplTest.java
deleted file mode 100644
index fa65363..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonImplTest.java
+++ /dev/null
@@ -1,129 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
-import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityContainerInfo;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.NavigationPropertyBinding;
-import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
-import org.apache.olingo.odata4.commons.api.edm.provider.Target;
-import org.junit.Test;
-
-public class EdmSingletonImplTest {
-
- @Test
- public void singleton() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- final FullQualifiedName typeName = new FullQualifiedName("ns", "entityType");
- final EntityType entityTypeProvider = new EntityType()
- .setName(typeName.getName())
- .setKey(Arrays.asList(new PropertyRef().setPropertyName("Id")));
- when(provider.getEntityType(typeName)).thenReturn(entityTypeProvider);
-
- 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 singletonName = "singleton";
- final Singleton singletonProvider = new Singleton()
- .setName(singletonName)
- .setType(typeName)
- .setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName(singletonName))));
- when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
-
- final EdmSingleton singleton = new EdmSingletonImpl(edm, entityContainer, singletonProvider);
- assertEquals(singletonName, entityContainer.getSingleton(singletonName).getName());
- assertEquals(singletonName, singleton.getName());
- final EdmEntityType entityType = singleton.getEntityType();
- assertEquals(typeName.getNamespace(), entityType.getNamespace());
- assertEquals(typeName.getName(), entityType.getName());
- assertEquals(entityContainer, singleton.getEntityContainer());
- assertNull(singleton.getRelatedBindingTarget(null));
- final EdmBindingTarget target = singleton.getRelatedBindingTarget("path");
- assertEquals(singletonName, target.getName());
- }
-
- @Test(expected = EdmException.class)
- public void wrongTarget() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
- final EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(containerName);
- when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
-
- final String singletonName = "singleton";
- final Singleton singletonProvider = new Singleton()
- .setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(containerName).setTargetName("wrong"))));
- when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
-
- final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
- singleton.getRelatedBindingTarget("path");
- }
-
- @Test(expected = EdmException.class)
- public void wrongTargetContainer() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
- final String singletonName = "singleton";
- final Singleton singletonProvider = new Singleton()
- .setNavigationPropertyBindings(Arrays.asList(
- new NavigationPropertyBinding().setPath("path")
- .setTarget(new Target().setEntityContainer(new FullQualifiedName("ns", "wrongContainer"))
- .setTargetName(singletonName))));
- when(provider.getSingleton(containerName, singletonName)).thenReturn(singletonProvider);
-
- final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
- singleton.getRelatedBindingTarget("path");
- }
-
- @Test(expected = EdmException.class)
- public void nonExsistingEntityType() throws Exception {
- EdmProvider provider = mock(EdmProvider.class);
- EdmProviderImpl edm = new EdmProviderImpl(provider);
-
- Singleton singleton = new Singleton().setName("name");
- final EdmSingleton edmSingleton = new EdmSingletonImpl(edm, null, singleton);
- edmSingleton.getEntityType();
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonInfoImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonInfoImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonInfoImplTest.java
deleted file mode 100644
index bd92137..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmSingletonInfoImplTest.java
+++ /dev/null
@@ -1,51 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmSingletonInfo;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityContainer;
-import org.apache.olingo.odata4.commons.api.edm.provider.Singleton;
-import org.junit.Test;
-
-public class EdmSingletonInfoImplTest {
-
- @Test
- public void singletonTest() {
- Singleton providerSingleton = new Singleton().setName("name");
- EntityContainer providerContainer = new EntityContainer().setName("container");
-
- EdmSingletonInfo info = new EdmSingletonInfoImpl(providerContainer, providerSingleton);
-
- assertEquals("name", info.getSingletonName());
- assertEquals("container", info.getEntityContainerName());
- }
-
- @Test(expected = EdmException.class)
- public void getUriTest() {
- Singleton providerSingleton = new Singleton().setName("name");
- EntityContainer providerContainer = new EntityContainer().setName("container");
-
- EdmSingletonInfo info = new EdmSingletonInfoImpl(providerContainer, providerSingleton);
- info.getEntitySetUri();
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeDefinitionImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeDefinitionImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeDefinitionImplTest.java
deleted file mode 100644
index 62d31e9..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeDefinitionImplTest.java
+++ /dev/null
@@ -1,74 +0,0 @@
-package org.apache.olingo.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmException;
-import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
-import org.junit.Test;
-
-/*******************************************************************************
- * 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.
- ******************************************************************************/
-
-public class EdmTypeDefinitionImplTest {
-
- @Test
- public void typeDefOnStringNoFacets() throws Exception {
- FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
- TypeDefinition providerTypeDef =
- new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("Edm", "String"));
- EdmTypeDefinition typeDefImpl =
- new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
-
- assertEquals("name", typeDefImpl.getName());
- assertEquals("namespace", typeDefImpl.getNamespace());
- assertEquals(String.class, typeDefImpl.getDefaultType());
- assertEquals(EdmTypeKind.DEFINITION, typeDefImpl.getKind());
- assertEquals(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), typeDefImpl.getUnderlyingType());
- assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance()));
-
- // String validation
- assertEquals("'StringValue'", typeDefImpl.toUriLiteral("StringValue"));
- assertEquals("String''Value", typeDefImpl.fromUriLiteral("'String''''Value'"));
- assertTrue(typeDefImpl.validate("text", null, null, null, null, null));
- assertEquals("text", typeDefImpl.valueToString("text", null, null, null, null, null));
- assertEquals("text", typeDefImpl.valueOfString("text", null, null, null, null, null, String.class));
-
- // Facets must be initial
- assertNull(typeDefImpl.getMaxLength());
- assertNull(typeDefImpl.getPrecision());
- assertNull(typeDefImpl.getScale());
- assertNull(typeDefImpl.isUnicode());
- }
-
- @Test(expected = EdmException.class)
- public void invalidTypeResultsInEdmException() throws Exception {
- FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
- TypeDefinition providerTypeDef =
- new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
- new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/e8dccaf0/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java b/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
deleted file mode 100644
index d5de3e1..0000000
--- a/odata4-lib/odata4-commons-core/src/test/java/org/apache/olingo/odata4/commons/core/edm/provider/EdmTypeImplTest.java
+++ /dev/null
@@ -1,44 +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.odata4.commons.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.junit.Test;
-
-public class EdmTypeImplTest {
-
- @Test
- public void getterTest() {
- EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.UNDEFINED);
- assertEquals("name", type.getName());
- assertEquals("namespace", type.getNamespace());
- assertEquals(EdmTypeKind.UNDEFINED, type.getKind());
- }
-
- private class EdmTypeImplTester extends EdmTypeImpl {
- public EdmTypeImplTester(final FullQualifiedName name, final EdmTypeKind kind) {
- super(null, name, kind);
- }
- }
-
-}