[OLINGO-62] final tests and implementation

Test coverage 99,4 percent
This commit is contained in:
Christian Amend 2014-01-31 16:28:04 +01:00
parent 0756824d07
commit b886528b13
10 changed files with 388 additions and 60 deletions

View File

@ -41,12 +41,10 @@ public class FunctionMapKey {
}
this.bindingParameterTypeName = bindingParameterTypeName;
this.isBindingParameterCollection = isBindingParameterCollection;
this.parameterNames = new ArrayList<String>();
if (parameterNames != null) {
this.parameterNames = new ArrayList<String>();
this.parameterNames.addAll(parameterNames);
Collections.sort(this.parameterNames);
} else {
this.parameterNames = null;
}
}
@ -66,12 +64,12 @@ public class FunctionMapKey {
hash = hash + "collectionNull";
}
if (parameterNames != null) {
if (!parameterNames.isEmpty()) {
for (String name : parameterNames) {
hash = hash + name;
}
} else {
hash = hash + "parameterNamesNull";
hash = hash + "parameterNamesEmpty";
}
return hash.hashCode();
@ -95,8 +93,7 @@ public class FunctionMapKey {
.equals(other.isBindingParameterCollection))) {
if (parameterNames == null && other.parameterNames == null) {
return true;
} else if (parameterNames != null && other.parameterNames != null
&& parameterNames.size() == other.parameterNames.size()) {
} else if (parameterNames.size() == other.parameterNames.size()) {
for (String name : parameterNames) {
if (!other.parameterNames.contains(name)) {
return false;

View File

@ -44,17 +44,20 @@ public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntit
this.entityType = entityType;
if (baseType == null) {
entityBaseType = null;
if (entityType.getKey() == null && !entityType.isAbstract()) {
List<PropertyRef> key = entityType.getKey();
if (key == null && !entityType.isAbstract()) {
throw new EdmException("Non-Abstract entity types must define a key.");
}
for (PropertyRef ref : entityType.getKey()) {
EdmKeyPropertyRef edmKeyRef = new EdmKeyPropertyRefImpl(this, ref);
if (ref.getAlias() != null) {
keyPredicateNames.add(ref.getAlias());
keyPropertyRefs.put(ref.getAlias(), edmKeyRef);
} else {
keyPredicateNames.add(ref.getPropertyName());
keyPropertyRefs.put(ref.getPropertyName(), edmKeyRef);
if (key != null) {
for (PropertyRef ref : key) {
EdmKeyPropertyRef edmKeyRef = new EdmKeyPropertyRefImpl(this, ref);
if (ref.getAlias() != null) {
keyPredicateNames.add(ref.getAlias());
keyPropertyRefs.put(ref.getAlias(), edmKeyRef);
} else {
keyPredicateNames.add(ref.getPropertyName());
keyPropertyRefs.put(ref.getPropertyName(), edmKeyRef);
}
}
}
} else {
@ -75,32 +78,30 @@ public class EdmEntityTypeImpl extends EdmStructuralTypeImpl implements EdmEntit
@Override
public List<String> getKeyPredicateNames() {
if (baseType != null) {
if (keyPredicateNames.isEmpty() && baseType != null) {
return entityBaseType.getKeyPredicateNames();
} else {
return keyPredicateNames;
}
return keyPredicateNames;
}
@Override
public List<EdmKeyPropertyRef> getKeyPropertyRefs() {
if (baseType != null) {
return entityBaseType.getKeyPropertyRefs();
} else {
if (keyPropertyRefsList == null) {
keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
}
return keyPropertyRefsList;
if (keyPropertyRefsList == null) {
keyPropertyRefsList = new ArrayList<EdmKeyPropertyRef>(keyPropertyRefs.values());
}
if (keyPropertyRefsList.isEmpty() && entityBaseType != null) {
return entityBaseType.getKeyPropertyRefs();
}
return keyPropertyRefsList;
}
@Override
public EdmKeyPropertyRef getKeyPropertyRef(final String keyPredicateName) {
if (baseType != null) {
EdmKeyPropertyRef edmKeyPropertyRef = keyPropertyRefs.get(keyPredicateName);
if (edmKeyPropertyRef == null && entityBaseType != null) {
return entityBaseType.getKeyPropertyRef(keyPredicateName);
} else {
return keyPropertyRefs.get(keyPredicateName);
}
return edmKeyPropertyRef;
}
@Override

View File

@ -23,8 +23,6 @@ import org.apache.olingo.odata4.commons.api.edm.EdmException;
import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.commons.api.edm.EdmStructuralType;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
@ -63,22 +61,24 @@ public class EdmKeyPropertyRefImpl implements EdmKeyPropertyRef {
+ ref.getPropertyName());
}
} else {
if (ref.getPath() == null || ref.getPath().isEmpty()) {
throw new EdmException("Alias but no path specified for propertyRef");
}
String[] splitPath = ref.getPath().split("/");
EdmStructuralType structType = edmEntityType;
for (int i = 0; i < splitPath.length; i++) {
property = (EdmProperty) structType.getProperty(splitPath[i]);
for (int i = 0; i < splitPath.length - 1; i++) {
EdmProperty property = (EdmProperty) structType.getProperty(splitPath[i]);
if (property == null) {
throw new EdmException("Invalid key property ref specified. Can´t find property with name: "
+ splitPath[i]);
}
EdmType childType = property.getType();
if (childType.getKind() == EdmTypeKind.COMPLEX) {
structType = (EdmStructuralType) childType;
} else {
if (i + 1 != splitPath.length) {
throw new EdmException("Invalid path: " + ref.getPath() + " Must end after: " + splitPath[i]);
}
throw new EdmException("Invalid property ref specified. Can´t find property with name: "
+ splitPath[i] + " at type: " + structType.getNamespace() + "." + structType.getName());
}
structType = (EdmStructuralType) property.getType();
}
property = (EdmProperty) structType.getProperty(splitPath[splitPath.length - 1]);
if (property == null) {
throw new EdmException("Invalid property ref specified. Can´t find property with name: "
+ splitPath[splitPath.length - 1] + " at type: " + structType.getNamespace() + "."
+ structType.getName());
}
}
}

View File

@ -170,6 +170,10 @@ public class EdmProviderImpl extends EdmImpl {
return null;
}
}
List<String> parameterNamesCopy = parameterNames;
if (parameterNamesCopy == null) {
parameterNamesCopy = Collections.emptyList();
}
EdmFunctionImpl functionImpl = null;
for (Function function : functions) {
if (function.isBound() == true) {
@ -180,12 +184,12 @@ public class EdmProviderImpl extends EdmImpl {
Parameter bindingParameter = providerParameters.get(0);
if (bindingParameterTypeName.equals(bindingParameter.getType())
&& isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) {
if (parameterNames.size() == providerParameters.size() - 1) {
if (parameterNamesCopy.size() == providerParameters.size() - 1) {
List<String> providerParameterNames = new ArrayList<String>();
for (int i = 1; i < providerParameters.size(); i++) {
providerParameterNames.add(providerParameters.get(i).getName());
}
if (parameterNames.containsAll(providerParameterNames)) {
if (parameterNamesCopy.containsAll(providerParameterNames)) {
functionImpl = new EdmFunctionImpl(this, functionName, function);
break;
}

View File

@ -76,6 +76,13 @@ public class EdmComplexTypeImplTest {
type = new EdmComplexTypeImpl(edm, name, complexType);
}
@Test
public void noPropertiesAndNoNavPropertiesMustNotResultInException() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
ComplexType complexType = new ComplexType().setName("n");
new EdmComplexTypeImpl(edm, new FullQualifiedName("n", "n"), complexType);
}
@Test
public void typeMustBeCompatibletoBasetype() {
assertTrue(type.compatibleTo(baseType));

View File

@ -32,6 +32,7 @@ import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
import org.apache.olingo.odata4.commons.api.edm.EdmException;
import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
@ -51,7 +52,6 @@ public class EdmEntityTypeImplTest {
private EdmEntityType typeWithBaseType;
private EdmEntityType typeWithComplexKey;
// TODO: test with abstract types and keys
@Before
public void setupTypes() throws Exception {
EdmProvider provider = mock(EdmProvider.class);
@ -185,6 +185,7 @@ public class EdmEntityTypeImplTest {
assertNotNull(keyPropertyRefs);
assertEquals(1, keyPropertyRefs.size());
assertEquals("Id", keyPropertyRefs.get(0).getKeyPropertyName());
assertTrue(keyPropertyRefs == typeWithBaseType.getKeyPropertyRefs());
}
@Test
@ -241,4 +242,35 @@ public class EdmEntityTypeImplTest {
assertTrue(property == typeWithBaseType.getProperty("nav2"));
}
@Test(expected = EdmException.class)
public void noKeyOnTypeWithoutBaseTypeMustResultInException() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n");
new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
@Test
public void abstractTypeDoesNotNeedKey() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n").setAbstract(true);
new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
@Test(expected = EdmException.class)
public void invalidBaseType() {
EdmProviderImpl edm = mock(EdmProviderImpl.class);
EntityType entityType = new EntityType().setName("n").setBaseType(new FullQualifiedName("wrong", "wrong"));
new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
@Test
public void abstractTypeWithAbstractBaseTypeDoesNotNeedKey() throws Exception {
EdmProvider provider = mock(EdmProvider.class);
EdmProviderImpl edm = new EdmProviderImpl(provider);
FullQualifiedName baseName = new FullQualifiedName("n", "base");
when(provider.getEntityType(baseName)).thenReturn(new EntityType().setName("base").setAbstract(true));
EntityType entityType = new EntityType().setName("n").setAbstract(true).setBaseType(baseName);
new EdmEntityTypeImpl(edm, new FullQualifiedName("n", "n"), entityType);
}
}

View File

@ -0,0 +1,142 @@
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
******************************************************************************/
package org.apache.olingo.odata4.commons.core.edm.provider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
import org.apache.olingo.odata4.commons.api.edm.EdmElement;
import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
import org.apache.olingo.odata4.commons.api.edm.EdmException;
import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
import org.junit.Test;
public class EdmKeyPropertyRefImplTest {
@Test
public void noAlias() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
when(etMock.getProperty("Id")).thenReturn(keyPropertyMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
assertEquals("Id", ref.getKeyPropertyName());
assertNull(ref.getAlias());
assertNull(ref.getPath());
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
assertTrue(property == ref.getProperty());
}
@Test
public void aliasForPropertyInComplexPropertyOneLevel() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/Id");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmElement compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getProperty("comp")).thenReturn(compMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
assertEquals("alias", ref.getAlias());
assertEquals("comp/Id", ref.getPath());
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
}
@Test(expected = EdmException.class)
public void aliasForPropertyInComplexPropertyButWrongPath() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/wrong");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmElement compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getProperty("comp")).thenReturn(compMock);
new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty();
}
@Test(expected = EdmException.class)
public void aliasForPropertyInComplexPropertyButWrongPath2() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("wrong/Id");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmElement compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
when(compTypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getProperty("comp")).thenReturn(compMock);
new EdmKeyPropertyRefImpl(etMock, providerRef).getProperty();
}
@Test
public void aliasForPropertyInComplexPropertyTwoLevels() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("comp/comp2/Id");
EdmEntityType etMock = mock(EdmEntityType.class);
EdmProperty keyPropertyMock = mock(EdmProperty.class);
EdmElement compMock = mock(EdmProperty.class);
EdmComplexType compTypeMock = mock(EdmComplexType.class);
EdmElement comp2Mock = mock(EdmProperty.class);
EdmComplexType comp2TypeMock = mock(EdmComplexType.class);
when(comp2TypeMock.getProperty("Id")).thenReturn(keyPropertyMock);
when(comp2Mock.getType()).thenReturn(comp2TypeMock);
when(compTypeMock.getProperty("comp2")).thenReturn(comp2Mock);
when(compMock.getType()).thenReturn(compTypeMock);
when(etMock.getProperty("comp")).thenReturn(compMock);
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(etMock, providerRef);
EdmProperty property = ref.getProperty();
assertNotNull(property);
assertTrue(property == keyPropertyMock);
}
@Test(expected = EdmException.class)
public void oneKeyNoAliasButInvalidProperty() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id");
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
ref.getProperty();
}
@Test(expected = EdmException.class)
public void aliasButNoPath() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias");
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
ref.getProperty();
}
@Test(expected = EdmException.class)
public void aliasButEmptyPath() {
PropertyRef providerRef = new PropertyRef().setPropertyName("Id").setAlias("alias").setPath("");
EdmKeyPropertyRef ref = new EdmKeyPropertyRefImpl(mock(EdmEntityType.class), providerRef);
ref.getProperty();
}
}

View File

@ -19,8 +19,11 @@
package org.apache.olingo.odata4.commons.core.edm.provider;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertNotSame;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
@ -29,6 +32,7 @@ import java.util.List;
import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
import org.apache.olingo.odata4.commons.api.edm.EdmException;
import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
import org.apache.olingo.odata4.commons.api.edm.provider.Action;
import org.apache.olingo.odata4.commons.api.edm.provider.EdmProvider;
@ -41,43 +45,154 @@ import org.junit.Test;
public class EdmProviderImplOverloadingTest {
private Edm edm;
private final FullQualifiedName FQN = new FullQualifiedName("testNamespace", "testName");
private final FullQualifiedName WRONG_FQN = new FullQualifiedName("wrong", "wrong");
private final FullQualifiedName operationName1 = new FullQualifiedName("n", "o1");
private final FullQualifiedName operationType1 = new FullQualifiedName("n", "t1");
private final FullQualifiedName operationType2 = new FullQualifiedName("n", "t2");
private final FullQualifiedName wrongOperationName = new FullQualifiedName("wrong", "wrong");
private final FullQualifiedName badOperationName = new FullQualifiedName("bad", "bad");
@Before
public void setup() throws Exception {
EdmProvider provider = mock(EdmProvider.class);
Action action = new Action().setName(FQN.getName());
List<Action> actions = new ArrayList<Action>();
Action action = new Action().setName(operationName1.getName());
actions.add(action);
when(provider.getActions(FQN)).thenReturn(actions);
List<Parameter> action1Parameters = new ArrayList<Parameter>();
action1Parameters.add(new Parameter().setType(operationType1).setCollection(false));
action =
new Action().setName(operationName1.getName()).setBound(true).setParameters(action1Parameters);
actions.add(action);
List<Parameter> action2Parameters = new ArrayList<Parameter>();
action2Parameters.add(new Parameter().setType(operationType1).setCollection(true));
action =
new Action().setName(operationName1.getName()).setBound(true).setParameters(action2Parameters);
actions.add(action);
when(provider.getActions(operationName1)).thenReturn(actions);
Function function = new Function().setName(FQN.getName()).setParameters(new ArrayList<Parameter>());
List<Function> functions = new ArrayList<Function>();
Function function = new Function().setName(operationName1.getName());
functions.add(function);
when(provider.getFunctions(FQN)).thenReturn(functions);
List<Parameter> function1Parameters = new ArrayList<Parameter>();
function1Parameters.add(new Parameter().setType(operationType1).setName("a"));
function = new Function().setName(operationName1.getName()).setParameters(function1Parameters);
functions.add(function);
List<Parameter> function2Parameters = new ArrayList<Parameter>();
function2Parameters.add(new Parameter().setType(operationType1).setName("b"));
function = new Function().setName(operationName1.getName()).setParameters(function2Parameters);
functions.add(function);
List<Parameter> function3Parameters = new ArrayList<Parameter>();
function3Parameters.add(new Parameter().setName("a").setType(operationType1));
function3Parameters.add(new Parameter().setName("b"));
function = new Function().setName(operationName1.getName()).setParameters(function3Parameters).setBound(true);
functions.add(function);
List<Parameter> function4Parameters = new ArrayList<Parameter>();
function4Parameters.add(new Parameter().setName("a").setType(operationType2));
function4Parameters.add(new Parameter().setName("b"));
function = new Function().setName(operationName1.getName()).setParameters(function4Parameters).setBound(true);
functions.add(function);
when(provider.getFunctions(operationName1)).thenReturn(functions);
List<Function> badFunctions = new ArrayList<Function>();
Function badFunction = new Function().setName(operationName1.getName()).setBound(true).setParameters(null);
badFunctions.add(badFunction);
when(provider.getFunctions(badOperationName)).thenReturn(badFunctions);
edm = new EdmProviderImpl(provider);
}
@Test
public void simpleActionGet() {
EdmAction action = edm.getAction(FQN, null, null);
EdmAction action = edm.getAction(operationName1, null, null);
assertNotNull(action);
assertEquals(FQN.getNamespace(), action.getNamespace());
assertEquals(FQN.getName(), action.getName());
assertEquals(operationName1.getNamespace(), action.getNamespace());
assertEquals(operationName1.getName(), action.getName());
assertNull(edm.getAction(WRONG_FQN, null, null));
assertNull(edm.getAction(wrongOperationName, null, null));
}
@Test
public void boundActionOverloading() {
EdmAction action = edm.getAction(operationName1, operationType1, false);
assertNotNull(action);
assertEquals(operationName1.getNamespace(), action.getNamespace());
assertEquals(operationName1.getName(), action.getName());
assertTrue(action == edm.getAction(operationName1, operationType1, false));
EdmAction action2 = edm.getAction(operationName1, operationType1, true);
assertNotNull(action2);
assertEquals(operationName1.getNamespace(), action2.getNamespace());
assertEquals(operationName1.getName(), action2.getName());
assertTrue(action2 == edm.getAction(operationName1, operationType1, true));
assertNotSame(action, action2);
}
@Test
public void simpleFunctionGet() {
EdmFunction function = edm.getFunction(FQN, null, null, new ArrayList<String>());
EdmFunction function = edm.getFunction(operationName1, null, null, null);
assertNotNull(function);
assertEquals(FQN.getNamespace(), function.getNamespace());
assertEquals(FQN.getName(), function.getName());
assertEquals(operationName1.getNamespace(), function.getNamespace());
assertEquals(operationName1.getName(), function.getName());
assertNull(edm.getFunction(WRONG_FQN, null, null, new ArrayList<String>()));
EdmFunction function2 = edm.getFunction(operationName1, null, null, new ArrayList<String>());
assertNotNull(function2);
assertEquals(operationName1.getNamespace(), function2.getNamespace());
assertEquals(operationName1.getName(), function2.getName());
assertEquals(function, function2);
assertNull(edm.getFunction(wrongOperationName, null, null, new ArrayList<String>()));
}
@Test
public void functionOverloading() {
ArrayList<String> parameter1Names = new ArrayList<String>();
parameter1Names.add("a");
List<String> parameter2Names = new ArrayList<String>();
parameter2Names.add("b");
EdmFunction function = edm.getFunction(operationName1, null, null, new ArrayList<String>());
assertNotNull(function);
assertFalse(function.isBound());
EdmFunction function1 = edm.getFunction(operationName1, null, null, parameter1Names);
assertNotNull(function1);
assertFalse(function1.isBound());
assertFalse(function == function1);
assertNotSame(function, function1);
EdmFunction function2 = edm.getFunction(operationName1, null, null, parameter2Names);
assertNotNull(function2);
assertFalse(function2.isBound());
assertFalse(function1 == function2);
assertNotSame(function1, function2);
EdmFunction function3 = edm.getFunction(operationName1, operationType1, false, parameter2Names);
assertNotNull(function3);
assertTrue(function3.isBound());
EdmFunction function4 = edm.getFunction(operationName1, operationType2, false, parameter2Names);
assertNotNull(function4);
assertTrue(function4.isBound());
assertFalse(function3 == function4);
assertNotSame(function3, function4);
assertFalse(function1 == function3);
assertFalse(function1 == function4);
assertFalse(function2 == function3);
assertFalse(function2 == function4);
assertNotSame(function1, function3);
assertNotSame(function1, function4);
assertNotSame(function2, function3);
assertNotSame(function2, function4);
}
@Test(expected = EdmException.class)
public void noParametersAtBoundFunctionReslutsInException() {
edm.getFunction(badOperationName, operationType1, true, null);
}
}

View File

@ -83,6 +83,24 @@ public class EdmProviderImplTest {
edm = new EdmProviderImpl(provider);
}
@Test
public void nothingSpecifiedMustNotResultInExceptions() throws Exception {
EdmProvider localProvider = mock(EdmProvider.class);
when(localProvider.getActions(FQN)).thenReturn(null);
when(localProvider.getFunctions(FQN)).thenReturn(null);
Edm localEdm = new EdmProviderImpl(localProvider);
localEdm.getAction(FQN, null, null);
localEdm.getFunction(FQN, null, null, null);
localEdm.getAction(FQN, FQN, true);
localEdm.getFunction(FQN, FQN, true, null);
localEdm.getComplexType(FQN);
localEdm.getEntityContainer(FQN);
localEdm.getEntityType(FQN);
localEdm.getEnumType(FQN);
localEdm.getTypeDefinition(FQN);
localEdm.getServiceMetadata();
}
@Test
public void convertExceptionsTest() throws Exception {
EdmProvider localProvider = mock(EdmProvider.class);
@ -115,6 +133,17 @@ public class EdmProviderImplTest {
} catch (EdmException e) {
assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
}
try {
localEdm.getAction(fqn, fqn, true);
} catch (EdmException e) {
assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
}
try {
localEdm.getFunction(fqn, fqn, true, null);
} catch (EdmException e) {
assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
}
}
private void callMethodAndExpectEdmException(final Edm localEdm, final String methodName) throws Exception {

View File

@ -12,6 +12,7 @@ import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
import org.junit.Test;
/*******************************************************************************
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file