[OLINGO-62] more tests for EDM providers
Change-Id: I95bc3475385d4124c3251837ed763bb82ff5b63a Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
parent
7955eadf02
commit
ae46250b03
|
@ -0,0 +1,81 @@
|
|||
/*******************************************************************************
|
||||
* 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.EdmEntitySet;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
|
||||
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.EntitySet;
|
||||
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.Target;
|
||||
import org.junit.Test;
|
||||
|
||||
public class EdmEntitySetImplTest {
|
||||
|
||||
@Test
|
||||
public void entitySet() 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 entitySetName = "entitySet";
|
||||
final EntitySet entitySetProvider = new EntitySet()
|
||||
.setName(entitySetName)
|
||||
.setType(typeName)
|
||||
.setIncludeInServiceDocument(true)
|
||||
.setNavigationPropertyBindings(Arrays.asList(
|
||||
new NavigationPropertyBinding().setPath("path")
|
||||
.setTarget(new Target().setEntityContainer(containerName).setTargetName(entitySetName))));
|
||||
when(provider.getEntitySet(containerName, entitySetName)).thenReturn(entitySetProvider);
|
||||
|
||||
final EdmEntitySet entitySet = new EdmEntitySetImpl(edm, entityContainer, entitySetProvider);
|
||||
assertEquals(entitySetName, entityContainer.getEntitySet(entitySetName).getName());
|
||||
assertEquals(entitySetName, entitySet.getName());
|
||||
final EdmEntityType entityType = entitySet.getEntityType();
|
||||
assertEquals(typeName.getNamespace(), entityType.getNamespace());
|
||||
assertEquals(typeName.getName(), entityType.getName());
|
||||
assertEquals(entityContainer, entitySet.getEntityContainer());
|
||||
assertNull(entitySet.getRelatedBindingTarget(null));
|
||||
final EdmBindingTarget target = entitySet.getRelatedBindingTarget("path");
|
||||
assertEquals(entitySetName, target.getName());
|
||||
}
|
||||
}
|
|
@ -0,0 +1,84 @@
|
|||
/*******************************************************************************
|
||||
* 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 java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
|
||||
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.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.Function;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.FunctionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
|
||||
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 EdmFunctionImportImplTest {
|
||||
|
||||
@Test
|
||||
public void functionImport() throws Exception {
|
||||
EdmProvider provider = mock(EdmProvider.class);
|
||||
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
||||
|
||||
final FullQualifiedName functionName = new FullQualifiedName("ns", "function");
|
||||
final Function functionProvider = new Function()
|
||||
.setName(functionName.getName())
|
||||
.setParameters(Collections.<Parameter> emptyList())
|
||||
.setBound(false)
|
||||
.setComposable(false)
|
||||
.setReturnType(new ReturnType().setType(EdmPrimitiveTypeKind.Boolean.getFullQualifiedName()));
|
||||
when(provider.getFunctions(functionName)).thenReturn(Arrays.asList(functionProvider));
|
||||
|
||||
final FullQualifiedName containerName = new FullQualifiedName("ns", "container");
|
||||
final EntityContainerInfo containerInfo = new EntityContainerInfo().setContainerName(containerName);
|
||||
when(provider.getEntityContainerInfo(containerName)).thenReturn(containerInfo);
|
||||
final EdmEntityContainer entityContainer = new EdmEntityContainerImpl(edm, provider, containerInfo);
|
||||
|
||||
final String functionImportName = "functionImport";
|
||||
final FunctionImport functionImportProvider = new FunctionImport()
|
||||
.setName(functionImportName)
|
||||
.setFunction(functionName)
|
||||
.setIncludeInServiceDocument(true);
|
||||
when(provider.getFunctionImport(containerName, functionImportName)).thenReturn(functionImportProvider);
|
||||
|
||||
final EdmFunctionImport functionImport =
|
||||
new EdmFunctionImportImpl(edm, "test", entityContainer, functionImportProvider);
|
||||
assertEquals(functionImportName, entityContainer.getFunctionImport(functionImportName).getName());
|
||||
assertEquals("test", functionImport.getName());
|
||||
final EdmFunction function = functionImport.getFunction(Collections.<String> emptyList());
|
||||
assertEquals(functionName.getNamespace(), function.getNamespace());
|
||||
assertEquals(functionName.getName(), function.getName());
|
||||
assertFalse(function.isBound());
|
||||
assertFalse(function.isComposable());
|
||||
assertEquals(EdmPrimitiveTypeKind.Boolean.getEdmPrimitiveTypeInstance(), function.getReturnType().getType());
|
||||
assertEquals(entityContainer, functionImport.getEntityContainer());
|
||||
assertNull(functionImport.getReturnedEntitySet());
|
||||
}
|
||||
}
|
|
@ -22,9 +22,11 @@ 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;
|
||||
|
@ -40,89 +42,114 @@ import org.junit.Test;
|
|||
|
||||
public class EdmPropertyImplTest {
|
||||
|
||||
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 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());
|
||||
}
|
||||
|
||||
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 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 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
|
||||
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 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());
|
||||
}
|
||||
@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 = IllegalArgumentException.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());
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,122 @@
|
|||
/*******************************************************************************
|
||||
* 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.junit.Assert.fail;
|
||||
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");
|
||||
fail();
|
||||
}
|
||||
|
||||
@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");
|
||||
fail();
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue