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/22 10:39:54 UTC

[11/48] 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/EdmSingletonImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
deleted file mode 100644
index d1aeb20..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSingletonImplTest.java
+++ /dev/null
@@ -1,131 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.mockito.Mockito.mock;
-import static org.mockito.Mockito.when;
-
-import java.util.Arrays;
-
-import org.apache.olingo.commons.api.edm.EdmBindingTarget;
-import org.apache.olingo.commons.api.edm.EdmEntityContainer;
-import org.apache.olingo.commons.api.edm.EdmEntityType;
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmSingleton;
-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.CsdlEntityType;
-import org.apache.olingo.commons.api.edm.provider.CsdlNavigationPropertyBinding;
-import org.apache.olingo.commons.api.edm.provider.CsdlPropertyRef;
-import org.apache.olingo.commons.api.edm.provider.CsdlSingleton;
-import org.apache.olingo.commons.core.edm.EdmEntityContainerImpl;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.EdmSingletonImpl;
-import org.junit.Test;
-
-public class EdmSingletonImplTest {
-
-  @Test
-  public void singleton() throws Exception {
-    CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
-    EdmProviderImpl edm = new EdmProviderImpl(provider);
-
-    final FullQualifiedName typeName = new FullQualifiedName("ns", "entityType");
-    final CsdlEntityType entityTypeProvider = new CsdlEntityType()
-        .setName(typeName.getName())
-        .setKey(Arrays.asList(new CsdlPropertyRef().setName("Id")));
-    when(provider.getEntityType(typeName)).thenReturn(entityTypeProvider);
-
-    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 singletonName = "singleton";
-    final CsdlSingleton singletonProvider =
-        new CsdlSingleton()
-            .setName(singletonName)
-            .setType(typeName)
-            .setNavigationPropertyBindings(
-                Arrays.asList(
-                    new CsdlNavigationPropertyBinding().setPath("path").setTarget(
-                        containerName.getFullQualifiedNameAsString() + "/" + 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 {
-    CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
-    EdmProviderImpl edm = new EdmProviderImpl(provider);
-
-    final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
-    final CsdlEntityContainerInfo containerInfo = new CsdlEntityContainerInfo().setContainerName(containerName);
-    when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
-
-    final String singletonName = "singleton";
-    final CsdlSingleton singletonProvider = new CsdlSingleton()
-        .setNavigationPropertyBindings(Arrays.asList(
-            new CsdlNavigationPropertyBinding().setPath("path")
-                .setTarget(containerName.getFullQualifiedNameAsString() + "/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 {
-    CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
-    EdmProviderImpl edm = new EdmProviderImpl(provider);
-
-    final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
-    final String singletonName = "singleton";
-    final CsdlSingleton singletonProvider = new CsdlSingleton()
-        .setNavigationPropertyBindings(Arrays.asList(
-            new CsdlNavigationPropertyBinding().setPath("path").setTarget("ns.wrongContainer/" + 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 {
-    CsdlEdmProvider provider = mock(CsdlEdmProvider.class);
-    EdmProviderImpl edm = new EdmProviderImpl(provider);
-
-    CsdlSingleton singleton = new CsdlSingleton().setName("name");
-    final EdmSingleton edmSingleton = new EdmSingletonImpl(edm, null, singleton);
-    edmSingleton.getEntityType();
-  }
-}

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/EdmTypeDefinitionImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
deleted file mode 100644
index 63d21f5..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java
+++ /dev/null
@@ -1,77 +0,0 @@
-/*
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- */
-package org.apache.olingo.server.core.edm.provider;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNull;
-import static org.junit.Assert.assertTrue;
-import static org.mockito.Mockito.mock;
-
-import org.apache.olingo.commons.api.edm.EdmException;
-import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
-import org.apache.olingo.commons.api.edm.EdmTypeDefinition;
-import org.apache.olingo.commons.api.edm.FullQualifiedName;
-import org.apache.olingo.commons.api.edm.constants.EdmTypeKind;
-import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition;
-import org.apache.olingo.commons.core.edm.EdmProviderImpl;
-import org.apache.olingo.commons.core.edm.EdmTypeDefinitionImpl;
-import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
-import org.junit.Test;
-
-public class EdmTypeDefinitionImplTest {
-
-  @Test
-  public void typeDefOnStringNoFacets() throws Exception {
-    final FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
-    final CsdlTypeDefinition providerTypeDef =
-        new CsdlTypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("Edm", "String"));
-    final EdmTypeDefinition typeDefImpl =
-        new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
-
-    assertEquals("name", typeDefImpl.getName());
-    assertEquals("namespace", typeDefImpl.getNamespace());
-    assertEquals(String.class, typeDefImpl.getDefaultType());
-    assertEquals(EdmTypeKind.DEFINITION, typeDefImpl.getKind());
-    assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String), typeDefImpl.getUnderlyingType());
-    assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.String)));
-
-    // String validation
-    assertEquals("'StringValue'", typeDefImpl.toUriLiteral("StringValue"));
-    assertEquals("String''Value", typeDefImpl.fromUriLiteral("'String''''Value'"));
-    assertTrue(typeDefImpl.validate("text", null, null, null, null, null));
-    assertEquals("text", typeDefImpl.valueToString("text", null, null, null, null, null));
-    assertEquals("text", typeDefImpl.valueOfString("text", null, null, null, null, null, String.class));
-
-    // Facets must be initial
-    assertNull(typeDefImpl.getMaxLength());
-    assertNull(typeDefImpl.getPrecision());
-    assertNull(typeDefImpl.getScale());
-    assertTrue(typeDefImpl.isUnicode());
-  }
-
-  @Test(expected = EdmException.class)
-  public void invalidTypeResultsInEdmException() throws Exception {
-    FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
-    CsdlTypeDefinition providerTypeDef =
-        new CsdlTypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
-    EdmTypeDefinitionImpl def = new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
-    def.getUnderlyingType();
-  }
-
-}

http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/9c1981c4/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
deleted file mode 100644
index 64c9744..0000000
--- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java
+++ /dev/null
@@ -1,62 +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 java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.commons.api.edm.EdmAnnotatable;
-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.CsdlAnnotatable;
-import org.apache.olingo.commons.api.edm.provider.CsdlAnnotation;
-import org.apache.olingo.commons.core.edm.EdmTypeImpl;
-import org.junit.Test;
-
-public class EdmTypeImplTest {
-
-  @Test
-  public void getterTest() {
-    EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.PRIMITIVE);
-    assertEquals("name", type.getName());
-    assertEquals("namespace", type.getNamespace());
-    assertEquals(EdmTypeKind.PRIMITIVE, type.getKind());
-    EdmAnnotatable an = (EdmAnnotatable) type;
-    assertNotNull(an.getAnnotations().get(0));
-  }
-
-  private class EdmTypeImplTester extends EdmTypeImpl {
-    public EdmTypeImplTester(final FullQualifiedName name, final EdmTypeKind kind) {
-      super(null, name, kind, new AnnoTester());
-    }
-  }
-
-  private class AnnoTester implements CsdlAnnotatable {
-    @Override
-    public List<CsdlAnnotation> getAnnotations() {
-      CsdlAnnotation annotation = new CsdlAnnotation();
-      annotation.setTerm("NS.SimpleTerm");
-      return Arrays.asList(annotation);
-    }
-  }
-}