[OLINGO-62] Edm Tests for EdmTypeDef etc
This commit is contained in:
parent
a2ba493b80
commit
8577d29d79
|
@ -33,4 +33,8 @@ public class EdmException extends RuntimeException {
|
||||||
super(msg);
|
super(msg);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public EdmException(String string, Exception e) {
|
||||||
|
super(string, e);
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -42,11 +42,10 @@ public class EdmParameterImpl extends EdmElementImpl implements EdmParameter {
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
FullQualifiedName typeName = parameter.getType();
|
FullQualifiedName typeName = parameter.getType();
|
||||||
if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
|
if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
|
||||||
EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(typeName.getName());
|
try {
|
||||||
if (kind != null) {
|
typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
|
||||||
typeImpl = kind.getEdmPrimitiveTypeInstance();
|
} catch (IllegalArgumentException e) {
|
||||||
} else {
|
throw new EdmException("Cannot find type with name: " + typeName, e);
|
||||||
throw new EdmException("Cannot find type with name: " + typeName);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typeImpl = edm.getComplexType(typeName);
|
typeImpl = edm.getComplexType(typeName);
|
||||||
|
|
|
@ -44,11 +44,10 @@ public class EdmPropertyImpl extends EdmElementImpl implements EdmProperty {
|
||||||
if (propertyType == null) {
|
if (propertyType == null) {
|
||||||
FullQualifiedName typeName = property.getType();
|
FullQualifiedName typeName = property.getType();
|
||||||
if (isPrimitive) {
|
if (isPrimitive) {
|
||||||
EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(typeName.getName());
|
try {
|
||||||
if (kind != null) {
|
propertyType = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
|
||||||
propertyType = kind.getEdmPrimitiveTypeInstance();
|
} catch (IllegalArgumentException e) {
|
||||||
} else {
|
throw new EdmException("Cannot find type with name: " + typeName, e);
|
||||||
throw new EdmException("Cannot find type with name: " + typeName);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
propertyType = edm.getComplexType(typeName);
|
propertyType = edm.getComplexType(typeName);
|
||||||
|
|
|
@ -43,11 +43,10 @@ public class EdmReturnTypeImpl implements EdmReturnType {
|
||||||
if (typeImpl == null) {
|
if (typeImpl == null) {
|
||||||
FullQualifiedName typeName = returnType.getType();
|
FullQualifiedName typeName = returnType.getType();
|
||||||
if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
|
if (EdmPrimitiveType.EDM_NAMESPACE.equals(typeName.getNamespace())) {
|
||||||
EdmPrimitiveTypeKind kind = EdmPrimitiveTypeKind.valueOf(typeName.getName());
|
try {
|
||||||
if (kind != null) {
|
typeImpl = EdmPrimitiveTypeKind.valueOf(typeName.getName()).getEdmPrimitiveTypeInstance();
|
||||||
typeImpl = kind.getEdmPrimitiveTypeInstance();
|
} catch (IllegalArgumentException e) {
|
||||||
} else {
|
throw new EdmException("Cannot find type with name: " + typeName, e);
|
||||||
throw new EdmException("Can<EFBFBD>t find type with name: " + typeName);
|
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
typeImpl = edm.getComplexType(typeName);
|
typeImpl = edm.getComplexType(typeName);
|
||||||
|
|
|
@ -18,6 +18,7 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.apache.olingo.odata4.commons.core.edm.provider;
|
package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
|
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.EdmPrimitiveType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
|
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveTypeException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
|
import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
|
||||||
|
@ -37,9 +38,13 @@ public class EdmTypeDefinitionImpl extends EdmNamedImpl implements EdmTypeDefini
|
||||||
super(edm, typeDefinitionName.getName());
|
super(edm, typeDefinitionName.getName());
|
||||||
this.typeDefinitionName = typeDefinitionName;
|
this.typeDefinitionName = typeDefinitionName;
|
||||||
this.typeDefinition = typeDefinition;
|
this.typeDefinition = typeDefinition;
|
||||||
//TODO: Should we check for edmNamespace in the underlying type name?
|
// TODO: Should we check for edmNamespace in the underlying type name?
|
||||||
this.edmPrimitiveTypeInstance =
|
try {
|
||||||
EdmPrimitiveTypeKind.valueOf(typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
|
this.edmPrimitiveTypeInstance =
|
||||||
|
EdmPrimitiveTypeKind.valueOf(typeDefinition.getUnderlyingType().getName()).getEdmPrimitiveTypeInstance();
|
||||||
|
} catch (IllegalArgumentException e) {
|
||||||
|
throw new EdmException("Invalid underlying type: " + typeDefinitionName, e);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
|
|
|
@ -18,23 +18,36 @@
|
||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.apache.olingo.odata4.commons.core.edm.provider;
|
package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Mockito.*;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmEntitySet;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.Action;
|
import org.apache.olingo.odata4.commons.api.edm.provider.Action;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.EntitySetPath;
|
import org.apache.olingo.odata4.commons.api.edm.provider.EntitySetPath;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
|
import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.ReturnType;
|
import org.apache.olingo.odata4.commons.api.edm.provider.ReturnType;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
public class EdmActionImplTest {
|
public class EdmActionImplTest {
|
||||||
|
|
||||||
private EdmActionImpl actionImpl1;
|
private EdmAction actionImpl1;
|
||||||
private EdmActionImpl actionImpl2;
|
private EdmAction actionImpl2;
|
||||||
private EdmActionImpl actionImpl3;
|
private EdmAction actionImpl3;
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void setup() {
|
public void setup() {
|
||||||
|
@ -46,7 +59,7 @@ public class EdmActionImplTest {
|
||||||
actionImpl1 = new EdmActionImpl(provider, action1Name, action1);
|
actionImpl1 = new EdmActionImpl(provider, action1Name, action1);
|
||||||
|
|
||||||
FullQualifiedName action2Name = new FullQualifiedName("namespace", "action2");
|
FullQualifiedName action2Name = new FullQualifiedName("namespace", "action2");
|
||||||
FullQualifiedName returnTypeName = new FullQualifiedName("returnNamespace", "returnName");
|
FullQualifiedName returnTypeName = new FullQualifiedName("Edm", "String");
|
||||||
ReturnType returnType = new ReturnType().setType(returnTypeName);
|
ReturnType returnType = new ReturnType().setType(returnTypeName);
|
||||||
Action action2 = new Action().setName("action2").setParameters(parameters).setReturnType(returnType);
|
Action action2 = new Action().setName("action2").setParameters(parameters).setReturnType(returnType);
|
||||||
actionImpl2 = new EdmActionImpl(provider, action2Name, action2);
|
actionImpl2 = new EdmActionImpl(provider, action2Name, action2);
|
||||||
|
@ -57,7 +70,86 @@ public class EdmActionImplTest {
|
||||||
new Action().setName("action3").setParameters(parameters).setReturnType(returnType).setEntitySetPath(
|
new Action().setName("action3").setParameters(parameters).setReturnType(returnType).setEntitySetPath(
|
||||||
entitySetPath);
|
entitySetPath);
|
||||||
actionImpl3 = new EdmActionImpl(provider, action3Name, action3);
|
actionImpl3 = new EdmActionImpl(provider, action3Name, action3);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void action1BasicMethodCalls() {
|
||||||
|
assertTrue(actionImpl1.isBound());
|
||||||
|
assertEquals(EdmTypeKind.ACTION, actionImpl1.getKind());
|
||||||
|
assertNull(actionImpl1.getReturnType());
|
||||||
|
// assertEquals("returnName", actionImpl1.getReturnType().getType().getName());
|
||||||
|
assertNotNull(actionImpl1.getParameterNames());
|
||||||
|
|
||||||
|
for (String name : actionImpl1.getParameterNames()) {
|
||||||
|
EdmParameter parameter = actionImpl1.getParameter(name);
|
||||||
|
assertNotNull(parameter);
|
||||||
|
assertEquals(name, parameter.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNull(actionImpl1.getReturnedEntitySet(null));
|
||||||
|
assertNull(actionImpl1.getReturnedEntitySet(mock(EdmEntitySet.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void action2BasicMethodCalls() {
|
||||||
|
assertFalse(actionImpl2.isBound());
|
||||||
|
assertEquals(EdmTypeKind.ACTION, actionImpl2.getKind());
|
||||||
|
assertEquals("String", actionImpl2.getReturnType().getType().getName());
|
||||||
|
assertNotNull(actionImpl2.getParameterNames());
|
||||||
|
|
||||||
|
for (String name : actionImpl2.getParameterNames()) {
|
||||||
|
EdmParameter parameter = actionImpl2.getParameter(name);
|
||||||
|
assertNotNull(parameter);
|
||||||
|
assertEquals(name, parameter.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
assertNull(actionImpl2.getReturnedEntitySet(null));
|
||||||
|
assertNull(actionImpl2.getReturnedEntitySet(mock(EdmEntitySet.class)));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void action3BasicMethodCalls() {
|
||||||
|
assertFalse(actionImpl3.isBound());
|
||||||
|
assertEquals(EdmTypeKind.ACTION, actionImpl3.getKind());
|
||||||
|
assertEquals("String", actionImpl3.getReturnType().getType().getName());
|
||||||
|
assertNotNull(actionImpl3.getParameterNames());
|
||||||
|
|
||||||
|
for (String name : actionImpl3.getParameterNames()) {
|
||||||
|
EdmParameter parameter = actionImpl3.getParameter(name);
|
||||||
|
assertNotNull(parameter);
|
||||||
|
assertEquals(name, parameter.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
actionImpl3.getReturnedEntitySet(null);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void action3getReturnedEntitySetWithEntitySet() {
|
||||||
|
EdmEntitySet set = mock(EdmEntitySet.class);
|
||||||
|
when(set.getRelatedBindingTarget("path")).thenReturn(set);
|
||||||
|
|
||||||
|
EdmEntitySet returnedEntitySet = actionImpl3.getReturnedEntitySet(set);
|
||||||
|
|
||||||
|
assertEquals(set, returnedEntitySet);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void action3getReturnedEntitySetWithNullReturn() {
|
||||||
|
EdmEntitySet set = mock(EdmEntitySet.class);
|
||||||
|
when(set.getRelatedBindingTarget("path")).thenReturn(null);
|
||||||
|
|
||||||
|
actionImpl3.getReturnedEntitySet(set);
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void action3getReturnedEntitySetWithSingleton() {
|
||||||
|
EdmSingleton singleton = mock(EdmSingleton.class);
|
||||||
|
EdmEntitySet set = mock(EdmEntitySet.class);
|
||||||
|
when(set.getRelatedBindingTarget("path")).thenReturn(singleton);
|
||||||
|
|
||||||
|
actionImpl3.getReturnedEntitySet(set);
|
||||||
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,6 +30,7 @@ import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
|
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
|
import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
|
import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
|
@ -124,4 +125,16 @@ public class EdmComplexTypeImplTest {
|
||||||
property = type.getProperty("nav2");
|
property = type.getProperty("nav2");
|
||||||
assertTrue(property == type.getProperty("nav2"));
|
assertTrue(property == type.getProperty("nav2"));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void nonExistingBaseType() throws Exception {
|
||||||
|
EdmProvider provider = mock(EdmProvider.class);
|
||||||
|
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
||||||
|
FullQualifiedName typeWithNonexistingBaseTypeName = new FullQualifiedName("namespace", "typeName");
|
||||||
|
ComplexType complexTypeForNonexistingBaseType =
|
||||||
|
new ComplexType().setBaseType(new FullQualifiedName("wrong", "wrong"));
|
||||||
|
complexTypeForNonexistingBaseType.setName("typeName");
|
||||||
|
when(provider.getComplexType(typeWithNonexistingBaseTypeName)).thenReturn(complexTypeForNonexistingBaseType);
|
||||||
|
new EdmComplexTypeImpl(edm, typeWithNonexistingBaseTypeName, complexTypeForNonexistingBaseType);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -24,14 +24,11 @@ import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmMember;
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.EnumMember;
|
import org.apache.olingo.odata4.commons.api.edm.provider.EnumMember;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
|
import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
|
||||||
|
|
|
@ -0,0 +1,75 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* Licensed to the Apache Software Foundation (ASF) under one
|
||||||
|
* or more contributor license agreements. See the NOTICE file
|
||||||
|
* distributed with this work for additional information
|
||||||
|
* regarding copyright ownership. The ASF licenses this file
|
||||||
|
* to you under the Apache License, Version 2.0 (the
|
||||||
|
* "License"); you may not use this file except in compliance
|
||||||
|
* with the License. You may obtain a copy of the License at
|
||||||
|
*
|
||||||
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
|
*
|
||||||
|
* Unless required by applicable law or agreed to in writing,
|
||||||
|
* software distributed under the License is distributed on an
|
||||||
|
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||||
|
* KIND, either express or implied. See the License for the
|
||||||
|
* specific language governing permissions and limitations
|
||||||
|
* under the License.
|
||||||
|
******************************************************************************/
|
||||||
|
package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
|
||||||
|
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.ReturnType;
|
||||||
|
import org.junit.Before;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EdmFunctionImplTest {
|
||||||
|
|
||||||
|
private EdmFunction functionImpl1;
|
||||||
|
private EdmFunction functionImpl2;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setupFunctions() {
|
||||||
|
EdmProviderImpl provider = mock(EdmProviderImpl.class);
|
||||||
|
|
||||||
|
Function function1 = new Function().setReturnType(new ReturnType().setType(new FullQualifiedName("Edm", "String")));
|
||||||
|
functionImpl1 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function1);
|
||||||
|
Function function2 = new Function().setComposable(true);
|
||||||
|
functionImpl2 = new EdmFunctionImpl(provider, new FullQualifiedName("namespace", "name"), function2);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isComposableDefaultFalse() {
|
||||||
|
assertFalse(functionImpl1.isComposable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void isComposableSetToTrue() {
|
||||||
|
assertTrue(functionImpl2.isComposable());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void existingReturnTypeGetsReturned() {
|
||||||
|
EdmReturnType returnType = functionImpl1.getReturnType();
|
||||||
|
assertNotNull(returnType);
|
||||||
|
assertEquals("String", returnType.getType().getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void nonExistingReturnTypeResultsInException() {
|
||||||
|
functionImpl2.getReturnType();
|
||||||
|
fail();
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
|
@ -20,11 +20,13 @@ package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
|
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||||
|
@ -55,5 +57,17 @@ public class EdmNavigationPropertyImplTest {
|
||||||
assertEquals(EdmTypeKind.ENTITY, type.getKind());
|
assertEquals(EdmTypeKind.ENTITY, type.getKind());
|
||||||
assertEquals("ns", type.getNamespace());
|
assertEquals("ns", type.getNamespace());
|
||||||
assertEquals("entity", type.getName());
|
assertEquals("entity", type.getName());
|
||||||
|
|
||||||
|
//Test caching
|
||||||
|
EdmType cachedType = property.getType();
|
||||||
|
assertTrue(type == cachedType);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void navigationPropertyWithNonExistentType() throws Exception {
|
||||||
|
EdmProviderImpl edm = mock(EdmProviderImpl.class);
|
||||||
|
NavigationProperty propertyProvider = new NavigationProperty();
|
||||||
|
EdmNavigationProperty property = new EdmNavigationPropertyImpl(edm, propertyProvider);
|
||||||
|
property.getType();
|
||||||
}
|
}
|
||||||
}
|
}
|
|
@ -24,6 +24,7 @@ import static org.junit.Assert.assertNull;
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
|
import org.apache.olingo.odata4.commons.api.edm.EdmParameter;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmType;
|
||||||
|
@ -80,7 +81,7 @@ public class EdmParameterImplTest {
|
||||||
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
||||||
assertFalse(parameter.isCollection());
|
assertFalse(parameter.isCollection());
|
||||||
final EdmType type = parameter.getType();
|
final EdmType type = parameter.getType();
|
||||||
// TODO: assertEquals(EdmTypeKind.ENUM, type.getKind());
|
assertEquals(EdmTypeKind.ENUM, type.getKind());
|
||||||
assertEquals("ns", type.getNamespace());
|
assertEquals("ns", type.getNamespace());
|
||||||
assertEquals("enum", type.getName());
|
assertEquals("enum", type.getName());
|
||||||
}
|
}
|
||||||
|
@ -96,7 +97,7 @@ public class EdmParameterImplTest {
|
||||||
parameterProvider.setType(typeName);
|
parameterProvider.setType(typeName);
|
||||||
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
||||||
final EdmType type = parameter.getType();
|
final EdmType type = parameter.getType();
|
||||||
// TODO: assertEquals(EdmTypeKind.DEFINITION, type.getKind());
|
assertEquals(EdmTypeKind.DEFINITION, type.getKind());
|
||||||
assertEquals("ns", type.getNamespace());
|
assertEquals("ns", type.getNamespace());
|
||||||
assertEquals("definition", type.getName());
|
assertEquals("definition", type.getName());
|
||||||
}
|
}
|
||||||
|
@ -117,4 +118,23 @@ public class EdmParameterImplTest {
|
||||||
assertEquals(Integer.valueOf(128), parameter.getMaxLength());
|
assertEquals(Integer.valueOf(128), parameter.getMaxLength());
|
||||||
assertFalse(parameter.isNullable());
|
assertFalse(parameter.isNullable());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void getTypeWithInvalidSimpleType() {
|
||||||
|
EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class));
|
||||||
|
Parameter parameterProvider = new Parameter();
|
||||||
|
parameterProvider.setType(new FullQualifiedName("Edm", "wrong"));
|
||||||
|
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
||||||
|
parameter.getType();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void getTypeWithNonexistingType() {
|
||||||
|
EdmProviderImpl edm = new EdmProviderImpl(mock(EdmProvider.class));
|
||||||
|
Parameter parameterProvider = new Parameter();
|
||||||
|
parameterProvider.setType(new FullQualifiedName("wrong", "wrong"));
|
||||||
|
final EdmParameter parameter = new EdmParameterImpl(edm, parameterProvider);
|
||||||
|
parameter.getType();
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
|
@ -119,7 +119,7 @@ public class EdmPropertyImplTest {
|
||||||
fail();
|
fail();
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = IllegalArgumentException.class)
|
@Test(expected = EdmException.class)
|
||||||
public void getTypeReturnsNoTypeKind() throws Exception {
|
public void getTypeReturnsNoTypeKind() throws Exception {
|
||||||
EdmProvider provider = mock(EdmProvider.class);
|
EdmProvider provider = mock(EdmProvider.class);
|
||||||
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
EdmProviderImpl edm = new EdmProviderImpl(provider);
|
||||||
|
|
|
@ -0,0 +1,31 @@
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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 org.apache.olingo.odata4.commons.api.edm.provider.ReturnType;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EdmReturnTypeImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void primitiveReturnType(){
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -20,7 +20,6 @@ package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.fail;
|
|
||||||
import static org.mockito.Mockito.mock;
|
import static org.mockito.Mockito.mock;
|
||||||
import static org.mockito.Mockito.when;
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
@ -98,7 +97,6 @@ public class EdmSingletonImplTest {
|
||||||
|
|
||||||
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
|
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
|
||||||
singleton.getRelatedBindingTarget("path");
|
singleton.getRelatedBindingTarget("path");
|
||||||
fail();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = EdmException.class)
|
@Test(expected = EdmException.class)
|
||||||
|
@ -117,6 +115,15 @@ public class EdmSingletonImplTest {
|
||||||
|
|
||||||
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
|
final EdmSingleton singleton = new EdmSingletonImpl(edm, null, singletonProvider);
|
||||||
singleton.getRelatedBindingTarget("path");
|
singleton.getRelatedBindingTarget("path");
|
||||||
fail();
|
}
|
||||||
|
|
||||||
|
@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();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -0,0 +1,73 @@
|
||||||
|
package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
/*******************************************************************************
|
||||||
|
* 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.
|
||||||
|
******************************************************************************/
|
||||||
|
import static org.junit.Assert.assertNull;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
import static org.mockito.Mockito.mock;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmTypeDefinition;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
|
||||||
|
import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
|
||||||
|
import org.junit.Test;
|
||||||
|
|
||||||
|
public class EdmTypeDefinitionImplTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void typeDefOnStringNoFacets() throws Exception {
|
||||||
|
FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
|
||||||
|
TypeDefinition providerTypeDef =
|
||||||
|
new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("Edm", "String"));
|
||||||
|
EdmTypeDefinition typeDefImpl =
|
||||||
|
new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
|
||||||
|
|
||||||
|
assertEquals("name", typeDefImpl.getName());
|
||||||
|
assertEquals("namespace", typeDefImpl.getNamespace());
|
||||||
|
assertEquals(String.class, typeDefImpl.getDefaultType());
|
||||||
|
assertEquals(EdmTypeKind.DEFINITION, typeDefImpl.getKind());
|
||||||
|
assertEquals(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance(), typeDefImpl.getUnderlyingType());
|
||||||
|
assertTrue(typeDefImpl.isCompatible(EdmPrimitiveTypeKind.String.getEdmPrimitiveTypeInstance()));
|
||||||
|
|
||||||
|
// String validation
|
||||||
|
assertEquals("'StringValue'", typeDefImpl.toUriLiteral("StringValue"));
|
||||||
|
assertEquals("String''Value", typeDefImpl.fromUriLiteral("'String''''Value'"));
|
||||||
|
assertTrue(typeDefImpl.validate("text", null, null, null, null, null));
|
||||||
|
assertEquals("text", typeDefImpl.valueToString("text", null, null, null, null, null));
|
||||||
|
assertEquals("text", typeDefImpl.valueOfString("text", null, null, null, null, null, String.class));
|
||||||
|
|
||||||
|
// Facets must be initial
|
||||||
|
assertNull(typeDefImpl.getMaxLength());
|
||||||
|
assertNull(typeDefImpl.getPrecision());
|
||||||
|
assertNull(typeDefImpl.getScale());
|
||||||
|
assertNull(typeDefImpl.isUnicode());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void invalidTypeResultsInEdmException() throws Exception {
|
||||||
|
FullQualifiedName typeDefName = new FullQualifiedName("namespace", "name");
|
||||||
|
TypeDefinition providerTypeDef =
|
||||||
|
new TypeDefinition().setName("typeDef").setUnderlyingType(new FullQualifiedName("wrong", "wrong"));
|
||||||
|
new EdmTypeDefinitionImpl(mock(EdmProviderImpl.class), typeDefName, providerTypeDef);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
Reference in New Issue