http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java deleted file mode 100644 index 03007b3..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmSchemaImplTest.java +++ /dev/null @@ -1,357 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.core.edm.provider; - -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmActionImport; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmSchema; -import org.apache.olingo.commons.api.edm.EdmSingleton; -import org.apache.olingo.commons.api.edm.EdmTypeDefinition; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.Action; -import org.apache.olingo.server.api.edm.provider.ActionImport; -import org.apache.olingo.server.api.edm.provider.AliasInfo; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityContainer; -import org.apache.olingo.server.api.edm.provider.EntityContainerInfo; -import org.apache.olingo.server.api.edm.provider.EntitySet; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.apache.olingo.server.api.edm.provider.Function; -import org.apache.olingo.server.api.edm.provider.FunctionImport; -import org.apache.olingo.server.api.edm.provider.Schema; -import org.apache.olingo.server.api.edm.provider.Singleton; -import org.apache.olingo.server.api.edm.provider.Term; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.junit.Before; -import org.junit.Test; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -public class EdmSchemaImplTest { - - private EdmSchema schema; - private Edm edm; - - @Before - public void before() { - EdmProvider provider = new LocalProvider(); - edm = new EdmProviderImpl(provider); - schema = edm.getSchemas().get(0); - - } - - @Test - public void initialSchemaTest() { - EdmProvider provider = mock(EdmProvider.class); - edm = new EdmProviderImpl(provider); - edm.getSchemas(); - } - - @Test - public void emptySchemaTest() throws Exception { - ArrayList<Schema> schemas = new ArrayList<Schema>(); - Schema providerSchema = new Schema(); - schemas.add(providerSchema); - EdmProvider provider = mock(EdmProvider.class); - when(provider.getSchemas()).thenReturn(schemas); - edm = new EdmProviderImpl(provider); - edm.getSchemas(); - } - - @Test - public void basicGetters() { - assertEquals("org.namespace", schema.getNamespace()); - assertEquals("alias", schema.getAlias()); - } - - @Test - public void getTypeDefinitions() { - List<EdmTypeDefinition> typeDefinitions = schema.getTypeDefinitions(); - assertNotNull(typeDefinitions); - assertEquals(2, typeDefinitions.size()); - - for (EdmTypeDefinition def : typeDefinitions) { - assertTrue(def == edm.getTypeDefinition(new FullQualifiedName("org.namespace", def.getName()))); - } - } - - @Test - public void getEnumTypes() { - List<EdmEnumType> enumTypes = schema.getEnumTypes(); - assertNotNull(enumTypes); - assertEquals(2, enumTypes.size()); - - for (EdmEnumType enumType : enumTypes) { - assertTrue(enumType == edm.getEnumType(new FullQualifiedName("org.namespace", enumType.getName()))); - } - } - - @Test - public void getEntityTypes() { - List<EdmEntityType> entityTypes = schema.getEntityTypes(); - assertNotNull(entityTypes); - assertEquals(2, entityTypes.size()); - - for (EdmEntityType entityType : entityTypes) { - assertTrue(entityType == edm.getEntityType(new FullQualifiedName("org.namespace", entityType.getName()))); - } - } - - @Test - public void getComplexTypes() { - List<EdmComplexType> complexTypes = schema.getComplexTypes(); - assertNotNull(complexTypes); - assertEquals(2, complexTypes.size()); - - for (EdmComplexType complexType : complexTypes) { - assertTrue(complexType == edm.getComplexType(new FullQualifiedName("org.namespace", complexType.getName()))); - } - } - - @Test - public void getActions() { - List<EdmAction> actions = schema.getActions(); - assertNotNull(actions); - assertEquals(2, actions.size()); - - for (EdmAction action : actions) { - assertTrue(action == edm.getUnboundAction(new FullQualifiedName("org.namespace", action.getName()))); - } - } - - @Test - public void getFunctions() { - List<EdmFunction> functions = schema.getFunctions(); - assertNotNull(functions); - assertEquals(2, functions.size()); - - for (EdmFunction function : functions) { - FullQualifiedName functionName = new FullQualifiedName("org.namespace", function.getName()); - assertTrue(function == edm.getUnboundFunction(functionName, null)); - } - } - - @Test - public void getContainer() { - EdmEntityContainer container = schema.getEntityContainer(); - assertNotNull(container); - - List<EdmEntitySet> entitySets = container.getEntitySets(); - assertNotNull(entitySets); - assertEquals(2, entitySets.size()); - for (EdmEntitySet obj : entitySets) { - assertNotNull(obj.getEntityType()); - } - - List<EdmSingleton> singletons = container.getSingletons(); - assertNotNull(singletons); - assertEquals(2, singletons.size()); - for (EdmSingleton obj : singletons) { - assertNotNull(obj.getEntityType()); - } - - List<EdmActionImport> actionImports = container.getActionImports(); - assertNotNull(actionImports); - assertEquals(2, actionImports.size()); - for (EdmActionImport obj : actionImports) { - assertNotNull(obj.getUnboundAction()); - } - - List<EdmFunctionImport> functionImports = container.getFunctionImports(); - assertNotNull(functionImports); - assertEquals(2, functionImports.size()); - for (EdmFunctionImport obj : functionImports) { - assertNotNull(obj.getFunctionFqn()); - } - - assertTrue(container == edm.getEntityContainer(new FullQualifiedName(schema.getNamespace(), container.getName()))); - assertTrue(container == edm.getEntityContainer(null)); - } - - private class LocalProvider extends EdmProvider { - - private static final String ALIAS = "alias"; - private static final String NAMESPACE = "org.namespace"; - - @Override - public EnumType getEnumType(final FullQualifiedName enumTypeName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public TypeDefinition getTypeDefinition(final FullQualifiedName typeDefinitionName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public List<Action> getActions(final FullQualifiedName actionName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public List<Function> getFunctions(final FullQualifiedName functionName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public Term getTerm(final FullQualifiedName termName) throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName) - throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public Singleton getSingleton(final FullQualifiedName entityContainer, final String singletonName) - throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public ActionImport getActionImport(final FullQualifiedName entityContainer, final String actionImportName) - throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public FunctionImport getFunctionImport(final FullQualifiedName entityContainer, final String functionImportName) - throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public EntityContainerInfo getEntityContainerInfo(final FullQualifiedName entityContainerName) - throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public List<AliasInfo> getAliasInfos() throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - - @Override - public List<Schema> getSchemas() throws ODataException { - Schema providerSchema = new Schema(); - providerSchema.setNamespace(NAMESPACE); - providerSchema.setAlias(ALIAS); - EntityContainer container = new EntityContainer().setName("container"); - - List<EntitySet> entitySets = new ArrayList<EntitySet>(); - entitySets.add(new EntitySet().setName("entitySetName") - .setType(new FullQualifiedName(NAMESPACE, "entityType1"))); - entitySets - .add(new EntitySet().setName("entitySetName2").setType(new FullQualifiedName(NAMESPACE, "entityType2"))); - container.setEntitySets(entitySets); - - List<Singleton> singletons = new ArrayList<Singleton>(); - singletons.add(new Singleton().setName("singletonName") - .setType(new FullQualifiedName(NAMESPACE, "entityType1"))); - singletons - .add(new Singleton().setName("singletonName2").setType(new FullQualifiedName(NAMESPACE, "entityType2"))); - container.setSingletons(singletons); - - List<ActionImport> actionImports = new ArrayList<ActionImport>(); - actionImports.add(new ActionImport().setName("actionImportName").setAction( - new FullQualifiedName(NAMESPACE, "action1"))); - actionImports.add(new ActionImport().setName("actionImportName2").setAction( - new FullQualifiedName(NAMESPACE, "action2"))); - container.setActionImports(actionImports); - - List<FunctionImport> functionImports = new ArrayList<FunctionImport>(); - functionImports.add(new FunctionImport().setName("functionImportName").setFunction( - new FullQualifiedName(NAMESPACE, "function1"))); - functionImports.add(new FunctionImport().setName("functionImportName2").setFunction( - new FullQualifiedName(NAMESPACE, "function2"))); - container.setFunctionImports(functionImports); - providerSchema.setEntityContainer(container); - - List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>(); - typeDefinitions.add(new TypeDefinition().setName("typeDefinition1")); - typeDefinitions.add(new TypeDefinition().setName("typeDefinition2")); - providerSchema.setTypeDefinitions(typeDefinitions); - - List<EnumType> enumTypes = new ArrayList<EnumType>(); - enumTypes.add(new EnumType().setName("enumType1")); - enumTypes.add(new EnumType().setName("enumType2")); - providerSchema.setEnumTypes(enumTypes); - - List<EntityType> entityTypes = new ArrayList<EntityType>(); - entityTypes.add(new EntityType().setName("entityType1")); - entityTypes.add(new EntityType().setName("entityType2") - .setBaseType(new FullQualifiedName(NAMESPACE, "entityType1"))); - providerSchema.setEntityTypes(entityTypes); - - List<ComplexType> complexTypes = new ArrayList<ComplexType>(); - complexTypes.add(new ComplexType().setName("complexType1")); - complexTypes.add(new ComplexType().setName("complexType2").setBaseType( - new FullQualifiedName(NAMESPACE, "complexType1"))); - providerSchema.setComplexTypes(complexTypes); - - List<Action> actions = new ArrayList<Action>(); - actions.add(new Action().setName("action1")); - actions.add(new Action().setName("action2")); - providerSchema.setActions(actions); - - List<Function> functions = new ArrayList<Function>(); - functions.add(new Function().setName("function1")); - functions.add(new Function().setName("function2")); - providerSchema.setFunctions(functions); - ArrayList<Schema> schemas = new ArrayList<Schema>(); - schemas.add(providerSchema); - return schemas; - } - - @Override - public EntityContainer getEntityContainer() throws ODataException { - throw new RuntimeException("Provider must not be called in the schema case"); - } - } -}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/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 4611d6f..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/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.server.core.edm.provider; - -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.Target; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityContainerInfo; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.NavigationPropertyBinding; -import org.apache.olingo.server.api.edm.provider.PropertyRef; -import org.apache.olingo.server.api.edm.provider.Singleton; -import org.junit.Test; - -import java.util.Arrays; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -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/olingo-odata4/blob/f7a7b484/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 5fc116c..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeDefinitionImplTest.java +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.core.edm.provider; - -import org.apache.olingo.commons.api.edm.EdmException; -import org.apache.olingo.commons.api.edm.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.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -public class EdmTypeDefinitionImplTest { - - @Test - public void typeDefOnStringNoFacets() throws Exception { - final FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name"); - final TypeDefinition providerTypeDef = - new TypeDefinition().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()); - 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")); - EdmTypeDefinitionImpl def = new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef); - def.getUnderlyingType(); - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/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 141ff32..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/edm/provider/EdmTypeImplTest.java +++ /dev/null @@ -1,45 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.core.edm.provider; - -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.constants.EdmTypeKind; -import org.apache.olingo.commons.core.edm.EdmTypeImpl; -import org.junit.Test; - -import static org.junit.Assert.assertEquals; - -public class EdmTypeImplTest { - - @Test - public void getterTest() { - EdmType type = new EdmTypeImplTester(new FullQualifiedName("namespace", "name"), EdmTypeKind.UNDEFINED); - assertEquals("name", type.getName()); - assertEquals("namespace", type.getNamespace()); - assertEquals(EdmTypeKind.UNDEFINED, type.getKind()); - } - - private class EdmTypeImplTester extends EdmTypeImpl { - public EdmTypeImplTester(final FullQualifiedName name, final EdmTypeKind kind) { - super(null, name, kind); - } - } - -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java deleted file mode 100644 index 85a30ac..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/BatchResponseSerializerTest.java +++ /dev/null @@ -1,227 +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.serializer; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; - -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; -import java.util.UUID; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.http.HttpHeader; -import org.apache.olingo.commons.api.http.HttpStatusCode; -import org.apache.olingo.server.api.ODataResponse; -import org.apache.olingo.server.api.deserializer.batch.ODataResponsePart; -import org.apache.olingo.server.core.deserializer.batch.BatchParserCommon; -import org.apache.olingo.server.core.deserializer.batch.BufferedReaderIncludingLineEndings; -import org.apache.olingo.server.core.serializer.BatchResponseSerializer; -import org.junit.Test; - -public class BatchResponseSerializerTest { - private static final String CRLF = "\r\n"; - private static final String BOUNDARY = "batch_" + UUID.randomUUID().toString(); - - @Test - public void testBatchResponse() throws Exception { - final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>(); - ODataResponse response = new ODataResponse(); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, "application/json"); - response.setContent(IOUtils.toInputStream("Walter Winter" + CRLF)); - - List<ODataResponse> responses = new ArrayList<ODataResponse>(1); - responses.add(response); - parts.add(new ODataResponsePart(responses, false)); - - ODataResponse changeSetResponse = new ODataResponse(); - changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); - changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1"); - responses = new ArrayList<ODataResponse>(1); - responses.add(changeSetResponse); - parts.add(new ODataResponsePart(responses, true)); - - BatchResponseSerializer serializer = new BatchResponseSerializer(); - final InputStream content = serializer.serialize(parts, BOUNDARY); - assertNotNull(content); - final BufferedReaderIncludingLineEndings reader = - new BufferedReaderIncludingLineEndings(new InputStreamReader(content)); - final List<String> body = reader.toList(); - reader.close(); - - int line = 0; - assertEquals(24, body.size()); - assertTrue(body.get(line++).contains("--batch_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++)); - assertEquals("Content-Type: application/json" + CRLF, body.get(line++)); - assertEquals("Content-Length: 15" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("Walter Winter" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--batch_")); - assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_")); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals("Content-Id: 1" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++)); - assertEquals("Content-Length: 0" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertTrue(body.get(line++).contains("--batch_")); - } - - @Test - public void testBatchResponseWithEndingCRLF() throws Exception { - final List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>(); - ODataResponse response = new ODataResponse(); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, "application/json"); - response.setContent(IOUtils.toInputStream("Walter Winter")); - - List<ODataResponse> responses = new ArrayList<ODataResponse>(1); - responses.add(response); - parts.add(new ODataResponsePart(responses, false)); - - ODataResponse changeSetResponse = new ODataResponse(); - changeSetResponse.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); - changeSetResponse.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1"); - responses = new ArrayList<ODataResponse>(1); - responses.add(changeSetResponse); - parts.add(new ODataResponsePart(responses, true)); - - BatchResponseSerializer serializer = new BatchResponseSerializer(); - final InputStream content = serializer.serialize(parts, BOUNDARY); - assertNotNull(content); - final BufferedReaderIncludingLineEndings reader = - new BufferedReaderIncludingLineEndings(new InputStreamReader(content)); - final List<String> body = reader.toList(); - reader.close(); - - int line = 0; - assertEquals(23, body.size()); - assertTrue(body.get(line++).contains("--batch_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++)); - assertEquals("Content-Type: application/json" + CRLF, body.get(line++)); - assertEquals("Content-Length: 13" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("Walter Winter" + CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--batch_")); - assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_")); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals("Content-Id: 1" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++)); - assertEquals("Content-Length: 0" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertTrue(body.get(line++).contains("--batch_")); - } - - @Test - public void testResponse() throws Exception { - List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>(); - ODataResponse response = new ODataResponse(); - response.setStatusCode(HttpStatusCode.OK.getStatusCode()); - response.setHeader(HttpHeader.CONTENT_TYPE, "application/json"); - response.setContent(IOUtils.toInputStream("Walter Winter")); - - List<ODataResponse> responses = new ArrayList<ODataResponse>(1); - responses.add(response); - parts.add(new ODataResponsePart(responses, false)); - - final BatchResponseSerializer serializer = new BatchResponseSerializer(); - final InputStream content = serializer.serialize(parts, BOUNDARY); - - assertNotNull(content); - final BufferedReaderIncludingLineEndings reader = - new BufferedReaderIncludingLineEndings(new InputStreamReader(content)); - final List<String> body = reader.toList(); - reader.close(); - - int line = 0; - assertEquals(10, body.size()); - assertTrue(body.get(line++).contains("--batch_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 200 OK" + CRLF, body.get(line++)); - assertEquals("Content-Type: application/json" + CRLF, body.get(line++)); - assertEquals("Content-Length: 13" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("Walter Winter" + CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--batch_")); - } - - @Test - public void testChangeSetResponse() throws Exception { - List<ODataResponsePart> parts = new ArrayList<ODataResponsePart>(); - ODataResponse response = new ODataResponse(); - response.setHeader(BatchParserCommon.HTTP_CONTENT_ID, "1"); - response.setStatusCode(HttpStatusCode.NO_CONTENT.getStatusCode()); - - List<ODataResponse> responses = new ArrayList<ODataResponse>(1); - responses.add(response); - parts.add(new ODataResponsePart(responses, true)); - - BatchResponseSerializer serializer = new BatchResponseSerializer(); - final InputStream content = serializer.serialize(parts, BOUNDARY); - - assertNotNull(content); - - final BufferedReaderIncludingLineEndings reader = - new BufferedReaderIncludingLineEndings(new InputStreamReader(content)); - final List<String> body = reader.toList(); - reader.close(); - - int line = 0; - assertEquals(14, body.size()); - assertTrue(body.get(line++).contains("--batch_")); - assertTrue(body.get(line++).contains("Content-Type: multipart/mixed; boundary=changeset_")); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertEquals("Content-Type: application/http" + CRLF, body.get(line++)); - assertEquals("Content-Transfer-Encoding: binary" + CRLF, body.get(line++)); - assertEquals("Content-Id: 1" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals("HTTP/1.1 204 No Content" + CRLF, body.get(line++)); - assertEquals("Content-Length: 0" + CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertEquals(CRLF, body.get(line++)); - assertTrue(body.get(line++).contains("--changeset_")); - assertTrue(body.get(line++).contains("--batch_")); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerTest.java deleted file mode 100644 index ce319fc..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/FixedFormatSerializerTest.java +++ /dev/null @@ -1,57 +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.serializer; - -import static org.junit.Assert.assertEquals; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.serializer.FixedFormatSerializer; -import org.apache.olingo.server.api.serializer.PrimitiveValueSerializerOptions; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.junit.Test; - -public class FixedFormatSerializerTest { - - private final FixedFormatSerializer serializer; - - public FixedFormatSerializerTest() throws SerializerException { - serializer = OData.newInstance().createFixedFormatSerializer(); - } - - @Test - public void binary() throws Exception { - assertEquals("ABC", IOUtils.toString(serializer.binary(new byte [] { 0x41, 0x42, 0x43 }))); - } - - @Test - public void count() throws Exception { - assertEquals("42", IOUtils.toString(serializer.count(42))); - } - - @Test - public void primitiveValue() throws Exception { - final EdmPrimitiveType type = EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Int32); - assertEquals("42", IOUtils.toString(serializer.primitiveValue(type, 42, - PrimitiveValueSerializerOptions.with().nullable(true).build()))); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java deleted file mode 100644 index 83368d6..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ComplexTypeHelper.java +++ /dev/null @@ -1,66 +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.serializer.json; - -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.NavigationProperty; -import org.apache.olingo.server.api.edm.provider.Property; -import org.apache.olingo.server.core.edm.provider.EdmComplexTypeImpl; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; - -public class ComplexTypeHelper { - - public static EdmComplexType createType() throws ODataException { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - - FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); - ComplexType baseComplexType = new ComplexType(); - List<Property> baseProperties = new ArrayList<Property>(); - baseProperties.add(new Property().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); - List<NavigationProperty> baseNavigationProperties = new ArrayList<NavigationProperty>(); - baseNavigationProperties.add(new NavigationProperty().setName("nav1")); - baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties) - .setNavigationProperties(baseNavigationProperties); - when(provider.getComplexType(baseName)).thenReturn(baseComplexType); - - FullQualifiedName name = new FullQualifiedName("namespace", "typeName"); - ComplexType complexType = new ComplexType().setBaseType(baseName); - List<Property> properties = new ArrayList<Property>(); - properties.add(new Property().setName("prop2").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); - List<NavigationProperty> navigationProperties = new ArrayList<NavigationProperty>(); - navigationProperties.add(new NavigationProperty().setName("nav2")); - complexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(properties) - .setNavigationProperties(navigationProperties); - when(provider.getComplexType(name)).thenReturn(complexType); - - return EdmComplexTypeImpl.getInstance(edm, name, complexType); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java deleted file mode 100644 index 4e44db4..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java +++ /dev/null @@ -1,136 +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.serializer.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.ODataServerError; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.JsonNodeType; - -public class ODataErrorSerializerTest { - - ODataSerializer ser; - - @Before - public void before() throws Exception { - ser = OData.newInstance().createSerializer(ODataFormat.JSON); - } - - @Test - public void basicODataErrorNoCode() throws Exception { - ODataServerError error = new ODataServerError(); - error.setMessage("ErrorMessage"); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\"}}", jsonString); - } - - @Test - public void basicODataErrorWithCode() throws Exception { - ODataServerError error = new ODataServerError(); - error.setCode("Code").setMessage("ErrorMessage"); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\"}}", jsonString); - } - - @Test - public void basicODataErrorWithCodeAndTarget() throws Exception { - ODataServerError error = new ODataServerError(); - error.setCode("Code").setMessage("ErrorMessage").setTarget("Target"); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString); - } - - @Test(expected = SerializerException.class) - public void nullErrorResultsInException() throws Exception { - ser.error(null); - } - - @Test - public void emptyDetailsList() throws Exception { - ODataServerError error = new ODataServerError(); - error.setMessage("ErrorMessage").setDetails(new ArrayList<ODataErrorDetail>()); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\",\"details\":[]}}", jsonString); - } - - @Test - public void nothingSetAtODataErrorObject() throws Exception { - ODataServerError error = new ODataServerError(); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":null}}", jsonString); - } - - @Test - public void singleDetailNothingSet() throws Exception { - List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>(); - details.add(new ODataErrorDetail()); - ODataServerError error = new ODataServerError().setDetails(details); - InputStream stream = ser.error(error); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":null,\"details\":[{\"code\":null,\"message\":null}]}}", - jsonString); - } - - @Test - public void verifiedWithJacksonParser() throws Exception { - List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>(); - details.add(new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget")); - ODataServerError error = - new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details); - InputStream stream = ser.error(error); - JsonNode tree = new ObjectMapper().readTree(stream); - assertNotNull(tree); - tree = tree.get("error"); - assertNotNull(tree); - assertEquals("Code", tree.get("code").textValue()); - assertEquals("Message", tree.get("message").textValue()); - assertEquals("Target", tree.get("target").textValue()); - - tree = tree.get("details"); - assertNotNull(tree); - assertEquals(JsonNodeType.ARRAY, tree.getNodeType()); - - tree = tree.get(0); - assertNotNull(tree); - assertEquals("detailCode", tree.get("code").textValue()); - assertEquals("detailMessage", tree.get("message").textValue()); - assertEquals("detailTarget", tree.get("target").textValue()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java deleted file mode 100644 index da7cb08..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ /dev/null @@ -1,71 +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.serializer.json; - -import static org.junit.Assert.assertEquals; - -import java.io.BufferedReader; -import java.io.IOException; -import java.io.InputStream; -import java.io.InputStreamReader; -import java.util.ArrayList; -import java.util.List; - -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.core.data.PropertyImpl; -import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; -import org.junit.Test; - -public class ODataJsonSerializerTest { - @Test - public void testCollectionComplex() throws ODataException, IOException { - final List<Property> col = new ArrayList<Property>(); - col.add(new PropertyImpl(null, "ComplexOne", ValueType.COMPLEX, getValues(1))); - col.add(new PropertyImpl(null, "ComplexTwo", ValueType.COMPLEX, getValues(2))); - final Property complexCollection = new PropertyImpl(null, "ComplexCol", ValueType.COLLECTION_COMPLEX, col); - - final ODataJsonSerializer serializer = new ODataJsonSerializer(ODataFormat.APPLICATION_JSON); - final ComplexSerializerOptions options = ComplexSerializerOptions.with() - .contextURL(ContextURL.with().selectList("ComplexCollection").build()).build(); - final InputStream in = serializer.complexCollection(ComplexTypeHelper.createType(), complexCollection, options); - final BufferedReader reader = new BufferedReader(new InputStreamReader(in)); - - String line; - while ((line = reader.readLine()) != null) { - if (line.contains("value")) { - assertEquals("{\"@odata.context\":\"$metadata(ComplexCollection)\",\"value\":" - + "[{\"prop1\":\"test1\",\"prop2\":\"test11\"},{\"prop1\":\"test2\",\"prop2\":\"test22\"}]}", line); - } - } - - } - - private List<Property> getValues(int i) { - final List<Property> values = new ArrayList<Property>(); - - values.add(new PropertyImpl(null, "prop1", ValueType.PRIMITIVE, "test" + i)); - values.add(new PropertyImpl(null, "prop2", ValueType.PRIMITIVE, "test" + i + i)); - - return values; - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java deleted file mode 100644 index 0e8e8bd..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLBuilderTest.java +++ /dev/null @@ -1,201 +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.serializer.utils; - -import static org.junit.Assert.assertEquals; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.net.URI; -import java.util.ArrayList; -import java.util.List; - -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.ContextURL.Suffix; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.core.edm.primitivetype.EdmString; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.NavigationProperty; -import org.apache.olingo.server.api.edm.provider.Property; -import org.apache.olingo.server.core.edm.provider.EdmComplexTypeImpl; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.junit.Test; -import org.mockito.Mockito; - -public class ContextURLBuilderTest { - - @Test - public void buildServiceDocument() { - final ContextURL contextURL = ContextURL.with() - .serviceRoot(URI.create("http://host/service/")).build(); - assertEquals("http://host/service/$metadata", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildRelative() { - final ContextURL contextURL = ContextURL.with().build(); - assertEquals("$metadata", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildEntitySet() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(entitySet) - .build(); - assertEquals("http://host/service/$metadata#Customers", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildDerivedEntitySet() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - EdmEntityType derivedType = Mockito.mock(EdmEntityType.class); - Mockito.when(derivedType.getFullQualifiedName()).thenReturn(new FullQualifiedName("Model", "VipCustomer")); - final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(entitySet) - .derived(derivedType) - .build(); - assertEquals("http://host/service/$metadata#Customers/Model.VipCustomer", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test(expected = IllegalArgumentException.class) - public void buildDerivedEntitySetWithoutEntitySet() { - EdmEntityType derivedType = Mockito.mock(EdmEntityType.class); - Mockito.when(derivedType.getFullQualifiedName()).thenReturn(new FullQualifiedName("Model", "VipCustomer")); - ContextURLBuilder.create(ContextURL.with().derived(derivedType).build()); - } - - @Test - public void buildDerivedEntity() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - EdmEntityType derivedType = Mockito.mock(EdmEntityType.class); - Mockito.when(derivedType.getFullQualifiedName()).thenReturn(new FullQualifiedName("Model", "VipCustomer")); - final ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(entitySet) - .derived(derivedType) - .suffix(Suffix.ENTITY) - .build(); - assertEquals("http://host/service/$metadata#Customers/Model.VipCustomer/$entity", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildProperty() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(entitySet) - .keyPath("1") - .navOrPropertyPath("Name") - .build(); - assertEquals("http://host/service/$metadata#Customers(1)/Name", - ContextURLBuilder.create(contextURL).toASCIIString()); - - contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(entitySet) - .keyPath("one=1,two='two'") - .navOrPropertyPath("ComplexName") - .selectList("Part1") - .build(); - assertEquals("http://host/service/$metadata#Customers(one=1,two='two')/ComplexName(Part1)", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildPrimitiveType() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .type(EdmString.getInstance()) - .build(); - assertEquals("http://host/service/$metadata#Edm.String", - ContextURLBuilder.create(contextURL).toASCIIString()); - - contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .type(EdmString.getInstance()).asCollection() - .build(); - assertEquals("http://host/service/$metadata#Collection(Edm.String)", - ContextURLBuilder.create(contextURL).toString()); - } - - @Test - public void buildComplexType() throws Exception { - EdmProvider provider = mock(EdmProvider.class); - EdmProviderImpl edm = new EdmProviderImpl(provider); - - FullQualifiedName baseName = new FullQualifiedName("namespace", "BaseTypeName"); - ComplexType baseComplexType = new ComplexType(); - List<Property> baseProperties = new ArrayList<Property>(); - baseProperties.add(new Property().setName("prop1").setType(EdmPrimitiveTypeKind.String.getFullQualifiedName())); - List<NavigationProperty> baseNavigationProperties = new ArrayList<NavigationProperty>(); - baseNavigationProperties.add(new NavigationProperty().setName("nav1")); - baseComplexType.setName("BaseTypeName").setAbstract(false).setOpenType(false).setProperties(baseProperties) - .setNavigationProperties(baseNavigationProperties); - when(provider.getComplexType(baseName)).thenReturn(baseComplexType); - - EdmComplexType baseType = EdmComplexTypeImpl.getInstance(edm, baseName, baseComplexType); - - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - ContextURL contextURL = ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .type(baseType) - .build(); - assertEquals("http://host/service/$metadata#namespace.BaseTypeName", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test(expected = IllegalArgumentException.class) - public void buildSuffixWithoutEntitySet() { - ContextURLBuilder.create(ContextURL.with().suffix(Suffix.ENTITY).build()); - } - - @Test - public void buildReference() { - final ContextURL contextURL = ContextURL.with().suffix(Suffix.REFERENCE).build(); - assertEquals("$metadata#$ref", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test(expected = IllegalArgumentException.class) - public void buildReferenceWithEntitySet() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Customers"); - ContextURLBuilder.create(ContextURL.with().entitySet(entitySet).suffix(Suffix.REFERENCE).build()); - } - - @Test - public void buildWithCharactersToBeEscaped() { - EdmEntitySet entitySet = Mockito.mock(EdmEntitySet.class); - Mockito.when(entitySet.getName()).thenReturn("Entitäten"); - EdmEntityType derivedType = Mockito.mock(EdmEntityType.class); - Mockito.when(derivedType.getFullQualifiedName()).thenReturn( - new FullQualifiedName("Namensräumchen", "UnüblicherName")); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet).derived(derivedType).build(); - assertEquals("$metadata#Entit%C3%A4ten/Namensr%C3%A4umchen.Un%C3%BCblicherName", - ContextURLBuilder.create(contextURL).toString()); - } -}
