mirror of
https://github.com/apache/olingo-odata4.git
synced 2025-03-06 16:49:09 +00:00
[OLINGO-62] Refactor overloading and more tests
This commit is contained in:
parent
fb833de3ae
commit
dbd0146311
@ -18,6 +18,7 @@
|
|||||||
******************************************************************************/
|
******************************************************************************/
|
||||||
package org.apache.olingo.odata4.commons.core.edm;
|
package org.apache.olingo.odata4.commons.core.edm;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
|
|
||||||
public class ActionMapKey {
|
public class ActionMapKey {
|
||||||
@ -27,6 +28,10 @@ public class ActionMapKey {
|
|||||||
|
|
||||||
public ActionMapKey(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
public ActionMapKey(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection) {
|
final Boolean isBindingParameterCollection) {
|
||||||
|
if (actionName == null || bindingParameterTypeName == null || isBindingParameterCollection == null) {
|
||||||
|
throw new EdmException(
|
||||||
|
"Action name, binding parameter type and binding parameter collection must not be null for bound actions");
|
||||||
|
}
|
||||||
this.actionName = actionName;
|
this.actionName = actionName;
|
||||||
this.bindingParameterTypeName = bindingParameterTypeName;
|
this.bindingParameterTypeName = bindingParameterTypeName;
|
||||||
this.isBindingParameterCollection = isBindingParameterCollection;
|
this.isBindingParameterCollection = isBindingParameterCollection;
|
||||||
@ -34,20 +39,8 @@ public class ActionMapKey {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
String forHash = actionName.toString();
|
String forHash =
|
||||||
|
actionName.toString() + bindingParameterTypeName.toString() + isBindingParameterCollection.toString();
|
||||||
if (bindingParameterTypeName != null) {
|
|
||||||
forHash = forHash + bindingParameterTypeName.toString();
|
|
||||||
} else {
|
|
||||||
forHash = forHash + "TypeNull";
|
|
||||||
}
|
|
||||||
|
|
||||||
if (isBindingParameterCollection != null) {
|
|
||||||
forHash = forHash + isBindingParameterCollection.toString();
|
|
||||||
} else {
|
|
||||||
forHash = forHash + "CollectionNull";
|
|
||||||
}
|
|
||||||
|
|
||||||
return forHash.hashCode();
|
return forHash.hashCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -60,16 +53,9 @@ public class ActionMapKey {
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
final ActionMapKey other = (ActionMapKey) obj;
|
final ActionMapKey other = (ActionMapKey) obj;
|
||||||
|
if (actionName.equals(other.actionName) && bindingParameterTypeName.equals(other.bindingParameterTypeName)
|
||||||
if (actionName.equals(other.actionName)) {
|
&& isBindingParameterCollection.equals(other.isBindingParameterCollection)) {
|
||||||
if ((bindingParameterTypeName == null && other.bindingParameterTypeName == null)
|
return true;
|
||||||
|| (bindingParameterTypeName != null && bindingParameterTypeName.equals(other.bindingParameterTypeName))) {
|
|
||||||
if ((isBindingParameterCollection == null && other.isBindingParameterCollection == null)
|
|
||||||
|| (isBindingParameterCollection != null && isBindingParameterCollection
|
|
||||||
.equals(other.isBindingParameterCollection))) {
|
|
||||||
return true;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
@ -42,8 +42,10 @@ public abstract class EdmImpl implements Edm {
|
|||||||
new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
new HashMap<FullQualifiedName, EdmTypeDefinition>();
|
||||||
private final Map<FullQualifiedName, EdmEntityType> entityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
|
private final Map<FullQualifiedName, EdmEntityType> entityTypes = new HashMap<FullQualifiedName, EdmEntityType>();
|
||||||
private final Map<FullQualifiedName, EdmComplexType> complexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
|
private final Map<FullQualifiedName, EdmComplexType> complexTypes = new HashMap<FullQualifiedName, EdmComplexType>();
|
||||||
private final Map<ActionMapKey, EdmAction> actions = new HashMap<ActionMapKey, EdmAction>();
|
private final Map<FullQualifiedName, EdmAction> unboundActions = new HashMap<FullQualifiedName, EdmAction>();
|
||||||
private final Map<FunctionMapKey, EdmFunction> functions = new HashMap<FunctionMapKey, EdmFunction>();
|
private final Map<FunctionMapKey, EdmFunction> unboundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||||
|
private final Map<ActionMapKey, EdmAction> boundActions = new HashMap<ActionMapKey, EdmAction>();
|
||||||
|
private final Map<FunctionMapKey, EdmFunction> boundFunctions = new HashMap<FunctionMapKey, EdmFunction>();
|
||||||
private EdmServiceMetadata serviceMetadata;
|
private EdmServiceMetadata serviceMetadata;
|
||||||
private Map<String, String> aliasToNamespaceInfo;
|
private Map<String, String> aliasToNamespaceInfo;
|
||||||
|
|
||||||
@ -119,16 +121,27 @@ public abstract class EdmImpl implements Edm {
|
|||||||
public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
public EdmAction getAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection) {
|
final Boolean isBindingParameterCollection) {
|
||||||
FullQualifiedName actionFqn = resolvePossibleAlias(actionName);
|
FullQualifiedName actionFqn = resolvePossibleAlias(actionName);
|
||||||
FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
|
if (bindingParameterTypeName == null) {
|
||||||
ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection);
|
EdmAction action = unboundActions.get(actionName);
|
||||||
EdmAction action = actions.get(key);
|
if (action == null) {
|
||||||
if (action == null) {
|
action = createUnboundAction(actionFqn);
|
||||||
action = createAction(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection);
|
if (action != null) {
|
||||||
if (action != null) {
|
unboundActions.put(actionName, action);
|
||||||
actions.put(key, action);
|
}
|
||||||
}
|
}
|
||||||
|
return action;
|
||||||
|
} else {
|
||||||
|
FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
|
||||||
|
ActionMapKey key = new ActionMapKey(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection);
|
||||||
|
EdmAction action = boundActions.get(key);
|
||||||
|
if (action == null) {
|
||||||
|
action = createBoundAction(actionFqn, bindingParameterTypeFqn, isBindingParameterCollection);
|
||||||
|
if (action != null) {
|
||||||
|
boundActions.put(key, action);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return action;
|
||||||
}
|
}
|
||||||
return action;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -136,18 +149,31 @@ public abstract class EdmImpl implements Edm {
|
|||||||
final FullQualifiedName bindingParameterTypeName,
|
final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
||||||
FullQualifiedName functionFqn = resolvePossibleAlias(functionName);
|
FullQualifiedName functionFqn = resolvePossibleAlias(functionName);
|
||||||
FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
|
if(bindingParameterTypeName == null){
|
||||||
FunctionMapKey key =
|
FunctionMapKey key =
|
||||||
new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
|
new FunctionMapKey(functionFqn, bindingParameterTypeName, isBindingParameterCollection, parameterNames);
|
||||||
EdmFunction function = functions.get(key);
|
EdmFunction function = unboundFunctions.get(key);
|
||||||
if (function == null) {
|
if (function == null) {
|
||||||
function = createFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection,
|
function = createUnboundFunction(functionFqn, parameterNames);
|
||||||
parameterNames);
|
if (function != null) {
|
||||||
if (function != null) {
|
unboundFunctions.put(key, function);
|
||||||
functions.put(key, function);
|
}
|
||||||
}
|
}
|
||||||
|
return function;
|
||||||
|
}else{
|
||||||
|
FullQualifiedName bindingParameterTypeFqn = resolvePossibleAlias(bindingParameterTypeName);
|
||||||
|
FunctionMapKey key =
|
||||||
|
new FunctionMapKey(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection, parameterNames);
|
||||||
|
EdmFunction function = boundFunctions.get(key);
|
||||||
|
if (function == null) {
|
||||||
|
function = createBoundFunction(functionFqn, bindingParameterTypeFqn, isBindingParameterCollection,
|
||||||
|
parameterNames);
|
||||||
|
if (function != null) {
|
||||||
|
boundFunctions.put(key, function);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return function;
|
||||||
}
|
}
|
||||||
return function;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -187,13 +213,16 @@ public abstract class EdmImpl implements Edm {
|
|||||||
|
|
||||||
protected abstract EdmComplexType createComplexType(FullQualifiedName complexTypeName);
|
protected abstract EdmComplexType createComplexType(FullQualifiedName complexTypeName);
|
||||||
|
|
||||||
protected abstract EdmAction createAction(FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
|
protected abstract EdmAction createUnboundAction(FullQualifiedName actionName);
|
||||||
|
|
||||||
|
protected abstract EdmFunction createUnboundFunction(FullQualifiedName functionName, List<String> parameterNames);
|
||||||
|
|
||||||
|
protected abstract EdmAction createBoundAction(FullQualifiedName actionName, FullQualifiedName bindingParameterTypeName,
|
||||||
Boolean isBindingParameterCollection);
|
Boolean isBindingParameterCollection);
|
||||||
|
|
||||||
protected abstract EdmFunction createFunction(FullQualifiedName functionName,
|
protected abstract EdmFunction createBoundFunction(FullQualifiedName functionName,
|
||||||
FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
|
FullQualifiedName bindingParameterTypeName, Boolean isBindingParameterCollection,
|
||||||
List<String> parameterNames);
|
List<String> parameterNames);
|
||||||
|
|
||||||
protected abstract EdmServiceMetadata createServiceMetadata();
|
protected abstract EdmServiceMetadata createServiceMetadata();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -22,6 +22,7 @@ import java.util.ArrayList;
|
|||||||
import java.util.Collections;
|
import java.util.Collections;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
|
|
||||||
public class FunctionMapKey {
|
public class FunctionMapKey {
|
||||||
@ -34,6 +35,10 @@ public class FunctionMapKey {
|
|||||||
public FunctionMapKey(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName,
|
public FunctionMapKey(final FullQualifiedName functionName, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
final Boolean isBindingParameterCollection, final List<String> parameterNames) {
|
||||||
this.functionName = functionName;
|
this.functionName = functionName;
|
||||||
|
if (bindingParameterTypeName != null && isBindingParameterCollection == null) {
|
||||||
|
throw new EdmException(
|
||||||
|
"Indicator that the bindingparameter is a collection must not be null if its an bound function.");
|
||||||
|
}
|
||||||
this.bindingParameterTypeName = bindingParameterTypeName;
|
this.bindingParameterTypeName = bindingParameterTypeName;
|
||||||
this.isBindingParameterCollection = isBindingParameterCollection;
|
this.isBindingParameterCollection = isBindingParameterCollection;
|
||||||
if (parameterNames != null) {
|
if (parameterNames != null) {
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package org.apache.olingo.odata4.commons.core.edm.provider;
|
package org.apache.olingo.odata4.commons.core.edm.provider;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
import java.util.Collections;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -49,6 +50,8 @@ import org.apache.olingo.odata4.commons.core.edm.EdmImpl;
|
|||||||
public class EdmProviderImpl extends EdmImpl {
|
public class EdmProviderImpl extends EdmImpl {
|
||||||
|
|
||||||
private final EdmProvider provider;
|
private final EdmProvider provider;
|
||||||
|
private final Map<FullQualifiedName, List<Action>> actionsMap = new HashMap<FullQualifiedName, List<Action>>();
|
||||||
|
private final Map<FullQualifiedName, List<Function>> functionsMap = new HashMap<FullQualifiedName, List<Function>>();
|
||||||
|
|
||||||
public EdmProviderImpl(final EdmProvider provider) {
|
public EdmProviderImpl(final EdmProvider provider) {
|
||||||
this.provider = provider;
|
this.provider = provider;
|
||||||
@ -121,110 +124,76 @@ public class EdmProviderImpl extends EdmImpl {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmAction createAction(final FullQualifiedName actionName, final FullQualifiedName bindingParameterTypeName,
|
public EdmAction createBoundAction(final FullQualifiedName actionName,
|
||||||
final Boolean isBindingParameterCollection) {
|
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection) {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
List<Action> actions = provider.getActions(actionName);
|
List<Action> actions = actionsMap.get(actionName);
|
||||||
if (actions != null) {
|
if (actions == null) {
|
||||||
EdmActionImpl actionImpl = null;
|
actions = provider.getActions(actionName);
|
||||||
if (bindingParameterTypeName == null) {
|
if (actions != null) {
|
||||||
// Search for first unbound action
|
actionsMap.put(actionName, actions);
|
||||||
for (Action action : actions) {
|
|
||||||
if (action.isBound() == false) {
|
|
||||||
actionImpl = new EdmActionImpl(this, actionName, action);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Search for bound action where binding parameter matches
|
return null;
|
||||||
boolean isCollection = false;
|
|
||||||
if (isBindingParameterCollection == null) {
|
|
||||||
isCollection = false;
|
|
||||||
} else {
|
|
||||||
isCollection = isBindingParameterCollection;
|
|
||||||
}
|
|
||||||
for (Action action : actions) {
|
|
||||||
if (action.isBound() == true) {
|
|
||||||
List<Parameter> parameters = action.getParameters();
|
|
||||||
Parameter parameter = parameters.get(0);
|
|
||||||
if (bindingParameterTypeName.equals(parameter.getType()) && isCollection == parameter.isCollection()) {
|
|
||||||
actionImpl = new EdmActionImpl(this, actionName, action);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return actionImpl;
|
|
||||||
}
|
}
|
||||||
return null;
|
EdmActionImpl actionImpl = null;
|
||||||
|
// Search for bound action where binding parameter matches
|
||||||
|
for (Action action : actions) {
|
||||||
|
if (action.isBound() == true) {
|
||||||
|
List<Parameter> parameters = action.getParameters();
|
||||||
|
Parameter parameter = parameters.get(0);
|
||||||
|
if (bindingParameterTypeName.equals(parameter.getType())
|
||||||
|
&& isBindingParameterCollection.booleanValue() == parameter.isCollection()) {
|
||||||
|
actionImpl = new EdmActionImpl(this, actionName, action);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return actionImpl;
|
||||||
} catch (ODataException e) {
|
} catch (ODataException e) {
|
||||||
throw new EdmException(e);
|
throw new EdmException(e);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmFunction createFunction(final FullQualifiedName functionName,
|
public EdmFunction createBoundFunction(final FullQualifiedName functionName,
|
||||||
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
|
final FullQualifiedName bindingParameterTypeName, final Boolean isBindingParameterCollection,
|
||||||
final List<String> parameterNames) {
|
final List<String> parameterNames) {
|
||||||
try {
|
try {
|
||||||
List<Function> functions = provider.getFunctions(functionName);
|
List<Function> functions = functionsMap.get(functionName);
|
||||||
if (functions != null) {
|
if (functions == null) {
|
||||||
EdmFunctionImpl functionImpl = null;
|
functions = provider.getFunctions(functionName);
|
||||||
// TODO: Should we throw an edmexception when parameternames is null?
|
if (functions != null) {
|
||||||
if (bindingParameterTypeName == null) {
|
functionsMap.put(functionName, functions);
|
||||||
// Search for matching unbound function
|
|
||||||
for (Function function : functions) {
|
|
||||||
if (function.isBound() == false) {
|
|
||||||
List<Parameter> parameters = function.getParameters();
|
|
||||||
// TODO add check for parameters == null;
|
|
||||||
if (parameterNames.size() == parameters.size()) {
|
|
||||||
List<String> functionParameterNames = new ArrayList<String>();
|
|
||||||
for (Parameter parameter : parameters) {
|
|
||||||
functionParameterNames.add(parameter.getName());
|
|
||||||
}
|
|
||||||
|
|
||||||
if (parameterNames.containsAll(functionParameterNames)) {
|
|
||||||
functionImpl = new EdmFunctionImpl(this, functionName, function);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
}
|
|
||||||
} else {
|
} else {
|
||||||
// Search for matching bound function
|
return null;
|
||||||
boolean isCollection = false;
|
}
|
||||||
if (isBindingParameterCollection == null) {
|
}
|
||||||
isCollection = false;
|
EdmFunctionImpl functionImpl = null;
|
||||||
} else {
|
for (Function function : functions) {
|
||||||
isCollection = isBindingParameterCollection;
|
if (function.isBound() == true) {
|
||||||
|
List<Parameter> parameters = function.getParameters();
|
||||||
|
if (parameters == null || parameters.size() == 0) {
|
||||||
|
throw new EdmException("No parameter specified for bound function: " + functionName);
|
||||||
}
|
}
|
||||||
for (Function function : functions) {
|
Parameter bindingParameter = parameters.get(0);
|
||||||
if (function.isBound() == true) {
|
if (bindingParameterTypeName.equals(bindingParameter.getType())
|
||||||
List<Parameter> parameters = function.getParameters();
|
&& isBindingParameterCollection.booleanValue() == bindingParameter.isCollection()) {
|
||||||
Parameter bindingParameter = parameters.get(0);
|
if (parameterNames.size() == parameters.size()) {
|
||||||
if (bindingParameterTypeName.equals(bindingParameter.getType())
|
List<String> functionParameterNames = new ArrayList<String>();
|
||||||
&& isCollection == bindingParameter.isCollection()) {
|
for (Parameter parameter : parameters) {
|
||||||
// bindingparameter type matches now only parameter names have to match
|
functionParameterNames.add(parameter.getName());
|
||||||
List<String> functionParameterNames = new ArrayList<String>();
|
}
|
||||||
for (int i = 1; i < parameters.size(); i++) {
|
if (parameterNames.containsAll(functionParameterNames)) {
|
||||||
functionParameterNames.add(parameters.get(i).getName());
|
functionImpl = new EdmFunctionImpl(this, functionName, function);
|
||||||
}
|
break;
|
||||||
|
|
||||||
if (parameterNames.containsAll(functionParameterNames)) {
|
|
||||||
functionImpl = new EdmFunctionImpl(this, functionName, function);
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return functionImpl;
|
|
||||||
}
|
}
|
||||||
return null;
|
return functionImpl;
|
||||||
} catch (ODataException e) {
|
} catch (ODataException e) {
|
||||||
throw new EdmException(e);
|
throw new EdmException(e);
|
||||||
}
|
}
|
||||||
@ -251,4 +220,72 @@ public class EdmProviderImpl extends EdmImpl {
|
|||||||
return aliasToNamespaceInfos;
|
return aliasToNamespaceInfos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmAction createUnboundAction(FullQualifiedName actionName) {
|
||||||
|
try {
|
||||||
|
List<Action> actions = actionsMap.get(actionName);
|
||||||
|
if (actions == null) {
|
||||||
|
actions = provider.getActions(actionName);
|
||||||
|
if (actions != null) {
|
||||||
|
actionsMap.put(actionName, actions);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
EdmActionImpl actionImpl = null;
|
||||||
|
// Search for first unbound action
|
||||||
|
for (Action action : actions) {
|
||||||
|
if (action.isBound() == false) {
|
||||||
|
actionImpl = new EdmActionImpl(this, actionName, action);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return actionImpl;
|
||||||
|
} catch (ODataException e) {
|
||||||
|
throw new EdmException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmFunction createUnboundFunction(FullQualifiedName functionName, List<String> parameterNames) {
|
||||||
|
try {
|
||||||
|
List<Function> functions = functionsMap.get(functionName);
|
||||||
|
if (functions == null) {
|
||||||
|
functions = provider.getFunctions(functionName);
|
||||||
|
if (functions != null) {
|
||||||
|
functionsMap.put(functionName, functions);
|
||||||
|
} else {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
List<String> parameterNamesCopy = parameterNames;
|
||||||
|
if (parameterNamesCopy == null) {
|
||||||
|
parameterNamesCopy = Collections.emptyList();
|
||||||
|
}
|
||||||
|
EdmFunctionImpl functionImpl = null;
|
||||||
|
for (Function function : functions) {
|
||||||
|
if (function.isBound() == false) {
|
||||||
|
List<Parameter> providerParameters = function.getParameters();
|
||||||
|
if (providerParameters == null) {
|
||||||
|
providerParameters = Collections.emptyList();
|
||||||
|
}
|
||||||
|
if (parameterNamesCopy.size() == providerParameters.size()) {
|
||||||
|
List<String> functionParameterNames = new ArrayList<String>();
|
||||||
|
for (Parameter parameter : providerParameters) {
|
||||||
|
functionParameterNames.add(parameter.getName());
|
||||||
|
}
|
||||||
|
|
||||||
|
if (parameterNamesCopy.containsAll(functionParameterNames)) {
|
||||||
|
functionImpl = new EdmFunctionImpl(this, functionName, function);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return functionImpl;
|
||||||
|
} catch (ODataException e) {
|
||||||
|
throw new EdmException(e);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -24,6 +24,7 @@ import java.util.List;
|
|||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
|
|
||||||
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.EdmStructuralType;
|
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.EdmType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||||
@ -32,7 +33,6 @@ import org.apache.olingo.odata4.commons.api.edm.provider.NavigationProperty;
|
|||||||
import org.apache.olingo.odata4.commons.api.edm.provider.Property;
|
import org.apache.olingo.odata4.commons.api.edm.provider.Property;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.StructuralType;
|
import org.apache.olingo.odata4.commons.api.edm.provider.StructuralType;
|
||||||
|
|
||||||
|
|
||||||
public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmStructuralType {
|
public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmStructuralType {
|
||||||
|
|
||||||
private final Map<String, EdmElement> properties = new HashMap<String, EdmElement>();
|
private final Map<String, EdmElement> properties = new HashMap<String, EdmElement>();
|
||||||
@ -107,12 +107,13 @@ public abstract class EdmStructuralTypeImpl extends EdmTypeImpl implements EdmSt
|
|||||||
}
|
}
|
||||||
return navigationPropertyNames;
|
return navigationPropertyNames;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean compatibleTo(EdmType targetType) {
|
public boolean compatibleTo(EdmType targetType) {
|
||||||
EdmStructuralType sourceType = this;
|
EdmStructuralType sourceType = this;
|
||||||
|
if (targetType == null) {
|
||||||
|
throw new EdmException("Target type must not be null");
|
||||||
|
}
|
||||||
while (sourceType.getName() != targetType.getName() ||
|
while (sourceType.getName() != targetType.getName() ||
|
||||||
sourceType.getNamespace() != targetType.getNamespace()) {
|
sourceType.getNamespace() != targetType.getNamespace()) {
|
||||||
sourceType = sourceType.getBaseType();
|
sourceType = sourceType.getBaseType();
|
||||||
|
@ -20,7 +20,9 @@ package org.apache.olingo.odata4.commons.core.edm;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
|
import static org.junit.Assert.fail;
|
||||||
|
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.EdmException;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -29,56 +31,69 @@ public class ActionMapKeyTest {
|
|||||||
private final FullQualifiedName fqn = new FullQualifiedName("namespace", "name");
|
private final FullQualifiedName fqn = new FullQualifiedName("namespace", "name");
|
||||||
private final FullQualifiedName fqnType = new FullQualifiedName("namespace2", "name2");
|
private final FullQualifiedName fqnType = new FullQualifiedName("namespace2", "name2");
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void invalidParametersTest() {
|
||||||
|
createAndCheckForEdmException(null, null, null);
|
||||||
|
createAndCheckForEdmException(fqn, null, null);
|
||||||
|
createAndCheckForEdmException(fqn, fqnType, null);
|
||||||
|
createAndCheckForEdmException(fqn, null, true);
|
||||||
|
createAndCheckForEdmException(null, fqnType, true);
|
||||||
|
createAndCheckForEdmException(null, fqnType, null);
|
||||||
|
createAndCheckForEdmException(null, null, true);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
private void createAndCheckForEdmException(FullQualifiedName fqn, FullQualifiedName typeName, Boolean collection) {
|
||||||
|
try {
|
||||||
|
new ActionMapKey(fqn, typeName, collection);
|
||||||
|
} catch (EdmException e) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
fail("EdmException expected for parameters: " + fqn + " " + typeName + " " + collection);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testEqualsMethod() {
|
public void testEqualsMethod() {
|
||||||
ActionMapKey key1 = new ActionMapKey(fqn, null, null);
|
ActionMapKey key;
|
||||||
ActionMapKey someKey = new ActionMapKey(fqn, null, null);
|
ActionMapKey someKey;
|
||||||
assertEquals(key1, someKey);
|
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, null, new Boolean(true));
|
key = new ActionMapKey(fqn, fqnType, false);
|
||||||
someKey = new ActionMapKey(fqn, null, true);
|
|
||||||
assertEquals(key1, someKey);
|
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, fqnType, false);
|
|
||||||
someKey = new ActionMapKey(fqn, fqnType, false);
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
assertEquals(key1, someKey);
|
assertEquals(key, someKey);
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, fqnType, null);
|
key = new ActionMapKey(fqn, fqnType, new Boolean(false));
|
||||||
someKey = new ActionMapKey(fqn, fqnType, null);
|
|
||||||
assertEquals(key1, someKey);
|
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, fqnType, true);
|
|
||||||
someKey = new ActionMapKey(fqn, fqnType, null);
|
|
||||||
assertNotSame(key1, someKey);
|
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, fqnType, true);
|
|
||||||
someKey = new ActionMapKey(fqn, fqnType, false);
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
assertNotSame(key1, someKey);
|
assertEquals(key, someKey);
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, null, true);
|
key = new ActionMapKey(fqn, fqnType, true);
|
||||||
someKey = new ActionMapKey(fqn, fqnType, false);
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
assertNotSame(key1, someKey);
|
assertNotSame(key, someKey);
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, null, true);
|
key = new ActionMapKey(fqn, fqnType, true);
|
||||||
someKey = new ActionMapKey(fqn, null, false);
|
someKey = new ActionMapKey(fqn, fqnType, new Boolean(false));
|
||||||
assertNotSame(key1, someKey);
|
assertNotSame(key, someKey);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testHashMethod() {
|
public void testHashMethod() {
|
||||||
ActionMapKey key1 = new ActionMapKey(fqn, null, null);
|
ActionMapKey key;
|
||||||
ActionMapKey someKey = new ActionMapKey(fqn, null, null);
|
ActionMapKey someKey;
|
||||||
assertEquals(key1.hashCode(), someKey.hashCode());
|
|
||||||
|
|
||||||
key1 = new ActionMapKey(fqn, null, new Boolean(true));
|
|
||||||
someKey = new ActionMapKey(fqn, null, true);
|
|
||||||
assertEquals(key1.hashCode(), someKey.hashCode());
|
|
||||||
|
|
||||||
someKey = new ActionMapKey(fqn, fqnType, true);
|
|
||||||
assertNotSame(key1.hashCode(), someKey.hashCode());
|
|
||||||
|
|
||||||
|
key = new ActionMapKey(fqn, fqnType, false);
|
||||||
someKey = new ActionMapKey(fqn, fqnType, false);
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
assertNotSame(key1.hashCode(), someKey.hashCode());
|
assertEquals(key.hashCode(), someKey.hashCode());
|
||||||
|
|
||||||
|
key = new ActionMapKey(fqn, fqnType, new Boolean(false));
|
||||||
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
|
assertEquals(key.hashCode(), someKey.hashCode());
|
||||||
|
|
||||||
|
key = new ActionMapKey(fqn, fqnType, true);
|
||||||
|
someKey = new ActionMapKey(fqn, fqnType, false);
|
||||||
|
assertNotSame(key.hashCode(), someKey.hashCode());
|
||||||
|
|
||||||
|
key = new ActionMapKey(fqn, fqnType, true);
|
||||||
|
someKey = new ActionMapKey(fqn, fqnType, new Boolean(false));
|
||||||
|
assertNotSame(key.hashCode(), someKey.hashCode());
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,6 @@ package org.apache.olingo.odata4.commons.core.edm;
|
|||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNotSame;
|
import static org.junit.Assert.assertNotSame;
|
||||||
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 static org.mockito.Mockito.when;
|
||||||
@ -142,7 +141,7 @@ public class EdmImplCachingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheActionSimple() {
|
public void cacheUnboundAction() {
|
||||||
EdmAction action = edm.getAction(NAME1, null, null);
|
EdmAction action = edm.getAction(NAME1, null, null);
|
||||||
assertNotNull(action);
|
assertNotNull(action);
|
||||||
|
|
||||||
@ -158,37 +157,24 @@ public class EdmImplCachingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheActionComlex() {
|
public void cacheBoundAction() {
|
||||||
EdmAction action = edm.getAction(NAME1, null, null);
|
EdmAction action = edm.getAction(NAME1, NAME2, true);
|
||||||
assertNotNull(action);
|
assertNotNull(action);
|
||||||
|
|
||||||
EdmAction cachedAction = edm.getAction(NAME1, null, true);
|
EdmAction cachedAction = edm.getAction(NAME1, NAME2, true);
|
||||||
assertNull(cachedAction);
|
assertNotNull(cachedAction);
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, null, false);
|
assertTrue(action == cachedAction);
|
||||||
assertNull(cachedAction);
|
assertEquals(action, cachedAction);
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME2, null);
|
EdmAction action2 = edm.getAction(NAME2, NAME2, true);
|
||||||
assertNull(cachedAction);
|
assertNotNull(action2);
|
||||||
|
assertNotSame(action, action2);
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME2, true);
|
|
||||||
assertNull(cachedAction);
|
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME2, false);
|
|
||||||
assertNull(cachedAction);
|
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME1, null);
|
|
||||||
assertNull(cachedAction);
|
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME1, true);
|
|
||||||
assertNull(cachedAction);
|
|
||||||
|
|
||||||
cachedAction = edm.getAction(NAME1, NAME1, false);
|
|
||||||
assertNull(cachedAction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheFunctionSimple() {
|
public void cacheUnboundFunctionNoParameters() {
|
||||||
EdmFunction function = edm.getFunction(NAME1, null, null, null);
|
EdmFunction function = edm.getFunction(NAME1, null, null, null);
|
||||||
assertNotNull(function);
|
assertNotNull(function);
|
||||||
|
|
||||||
@ -205,35 +191,43 @@ public class EdmImplCachingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheFunctionComplex() {
|
public void cacheBoundFunction() {
|
||||||
EdmFunction function = edm.getFunction(NAME1, null, null, null);
|
EdmFunction function = edm.getFunction(NAME1, NAME2, true, new ArrayList<String>());
|
||||||
assertNotNull(function);
|
assertNotNull(function);
|
||||||
|
|
||||||
EdmFunction cachedfunction = edm.getFunction(NAME1, null, false, null);
|
EdmFunction cachedfunction = edm.getFunction(NAME1, NAME2, true, new ArrayList<String>());
|
||||||
assertNull(cachedfunction);
|
assertNotNull(cachedfunction);
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, null, true, null);
|
assertTrue(function == cachedfunction);
|
||||||
assertNull(cachedfunction);
|
assertEquals(function, cachedfunction);
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, null, new Boolean(true), null);
|
EdmFunction function2 = edm.getFunction(NAME2, NAME2, true, new ArrayList<String>());
|
||||||
assertNull(cachedfunction);
|
assertNotNull(function2);
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, NAME2, null, null);
|
assertNotSame(function, function2);
|
||||||
assertNull(cachedfunction);
|
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, NAME2, true, null);
|
|
||||||
assertNull(cachedfunction);
|
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, NAME2, false, null);
|
|
||||||
assertNull(cachedfunction);
|
|
||||||
|
|
||||||
cachedfunction = edm.getFunction(NAME1, null, null, new ArrayList<String>());
|
|
||||||
assertNull(cachedfunction);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void cacheFunctionComplexWithListContent() {
|
public void cacheUnboundFunctionWithParameters() {
|
||||||
|
ArrayList<String> parameters1 = new ArrayList<String>();
|
||||||
|
parameters1.add("A");
|
||||||
|
parameters1.add("B");
|
||||||
|
EdmFunction function = edm.getFunction(NAME1, NAME2, true, parameters1);
|
||||||
|
assertNotNull(function);
|
||||||
|
|
||||||
|
ArrayList<String> parameters2 = new ArrayList<String>();
|
||||||
|
parameters2.add("B");
|
||||||
|
parameters2.add("A");
|
||||||
|
EdmFunction cachedfunction = edm.getFunction(NAME1, NAME2, true, parameters2);
|
||||||
|
assertNotNull(cachedfunction);
|
||||||
|
|
||||||
|
assertTrue(function == cachedfunction);
|
||||||
|
assertEquals(function, cachedfunction);
|
||||||
|
|
||||||
|
EdmFunction function2 = edm.getFunction(NAME2, NAME2, true, new ArrayList<String>());
|
||||||
|
assertNotNull(function2);
|
||||||
|
|
||||||
|
assertNotSame(function, function2);
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
@ -312,9 +306,9 @@ public class EdmImplCachingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmAction createAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
public EdmAction createBoundAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection) {
|
final Boolean isBindingParameterCollection) {
|
||||||
if (NAME1.equals(fqn) && bindingParameterTypeName == null && isBindingParameterCollection == null) {
|
if (NAME1.equals(fqn)) {
|
||||||
EdmAction action = mock(EdmAction.class);
|
EdmAction action = mock(EdmAction.class);
|
||||||
when(action.getNamespace()).thenReturn(fqn.getNamespace());
|
when(action.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
when(action.getName()).thenReturn(fqn.getName());
|
when(action.getName()).thenReturn(fqn.getName());
|
||||||
@ -329,10 +323,10 @@ public class EdmImplCachingTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmFunction createFunction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
public EdmFunction createBoundFunction(final FullQualifiedName fqn,
|
||||||
|
final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection, final List<String> bindingParameterNames) {
|
final Boolean isBindingParameterCollection, final List<String> bindingParameterNames) {
|
||||||
if (NAME1.equals(fqn) && bindingParameterTypeName == null && isBindingParameterCollection == null
|
if (NAME1.equals(fqn)) {
|
||||||
&& bindingParameterNames == null) {
|
|
||||||
EdmFunction function = mock(EdmFunction.class);
|
EdmFunction function = mock(EdmFunction.class);
|
||||||
when(function.getNamespace()).thenReturn(fqn.getNamespace());
|
when(function.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
when(function.getName()).thenReturn(fqn.getName());
|
when(function.getName()).thenReturn(fqn.getName());
|
||||||
@ -355,5 +349,37 @@ public class EdmImplCachingTest {
|
|||||||
protected Map<String, String> createAliasToNamespaceInfo() {
|
protected Map<String, String> createAliasToNamespaceInfo() {
|
||||||
return new HashMap<String, String>();
|
return new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmAction createUnboundAction(FullQualifiedName fqn) {
|
||||||
|
if (NAME1.equals(fqn)) {
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(action.getName()).thenReturn(fqn.getName());
|
||||||
|
return action;
|
||||||
|
} else if (NAME2.equals(fqn)) {
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(action.getName()).thenReturn(fqn.getName());
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmFunction createUnboundFunction(FullQualifiedName fqn, List<String> parameterNames) {
|
||||||
|
if (NAME1.equals(fqn)) {
|
||||||
|
EdmFunction function = mock(EdmFunction.class);
|
||||||
|
when(function.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(function.getName()).thenReturn(fqn.getName());
|
||||||
|
return function;
|
||||||
|
} else if (NAME2.equals(fqn)) {
|
||||||
|
EdmFunction function = mock(EdmFunction.class);
|
||||||
|
when(function.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(function.getName()).thenReturn(fqn.getName());
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -20,10 +20,12 @@ package org.apache.olingo.odata4.commons.core.edm;
|
|||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
|
import static org.junit.Assert.assertNotSame;
|
||||||
import static org.junit.Assert.assertNull;
|
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 java.util.ArrayList;
|
||||||
import java.util.HashMap;
|
import java.util.HashMap;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
import java.util.Map;
|
import java.util.Map;
|
||||||
@ -108,6 +110,13 @@ public class EdmImplCallCreateTest {
|
|||||||
assertNotNull(action);
|
assertNotNull(action);
|
||||||
assertEquals(FQN.getNamespace(), action.getNamespace());
|
assertEquals(FQN.getNamespace(), action.getNamespace());
|
||||||
assertEquals(FQN.getName(), action.getName());
|
assertEquals(FQN.getName(), action.getName());
|
||||||
|
|
||||||
|
EdmAction action2 = edm.getAction(FQN, FQN, true);
|
||||||
|
assertNotNull(action2);
|
||||||
|
assertEquals(FQN.getNamespace(), action2.getNamespace());
|
||||||
|
assertEquals(FQN.getName(), action2.getName());
|
||||||
|
|
||||||
|
assertNotSame(action, action2);
|
||||||
|
|
||||||
assertNull(edm.getAction(WRONG_FQN, null, null));
|
assertNull(edm.getAction(WRONG_FQN, null, null));
|
||||||
}
|
}
|
||||||
@ -118,6 +127,13 @@ public class EdmImplCallCreateTest {
|
|||||||
assertNotNull(function);
|
assertNotNull(function);
|
||||||
assertEquals(FQN.getNamespace(), function.getNamespace());
|
assertEquals(FQN.getNamespace(), function.getNamespace());
|
||||||
assertEquals(FQN.getName(), function.getName());
|
assertEquals(FQN.getName(), function.getName());
|
||||||
|
|
||||||
|
EdmFunction function2 = edm.getFunction(FQN, FQN, true, new ArrayList<String>());
|
||||||
|
assertNotNull(function2);
|
||||||
|
assertEquals(FQN.getNamespace(), function2.getNamespace());
|
||||||
|
assertEquals(FQN.getName(), function2.getName());
|
||||||
|
|
||||||
|
assertNotSame(function, function2);
|
||||||
|
|
||||||
assertNull(edm.getFunction(WRONG_FQN, null, null, null));
|
assertNull(edm.getFunction(WRONG_FQN, null, null, null));
|
||||||
}
|
}
|
||||||
@ -189,7 +205,7 @@ public class EdmImplCallCreateTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmAction createAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
public EdmAction createBoundAction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection) {
|
final Boolean isBindingParameterCollection) {
|
||||||
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
||||||
EdmAction action = mock(EdmAction.class);
|
EdmAction action = mock(EdmAction.class);
|
||||||
@ -201,7 +217,7 @@ public class EdmImplCallCreateTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public EdmFunction createFunction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
public EdmFunction createBoundFunction(final FullQualifiedName fqn, final FullQualifiedName bindingParameterTypeName,
|
||||||
final Boolean isBindingParameterCollection, final List<String> bindingParameterNames) {
|
final Boolean isBindingParameterCollection, final List<String> bindingParameterNames) {
|
||||||
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
||||||
EdmFunction function = mock(EdmFunction.class);
|
EdmFunction function = mock(EdmFunction.class);
|
||||||
@ -221,5 +237,27 @@ public class EdmImplCallCreateTest {
|
|||||||
protected Map<String, String> createAliasToNamespaceInfo() {
|
protected Map<String, String> createAliasToNamespaceInfo() {
|
||||||
return new HashMap<String, String>();
|
return new HashMap<String, String>();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmAction createUnboundAction(FullQualifiedName fqn) {
|
||||||
|
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
||||||
|
EdmAction action = mock(EdmAction.class);
|
||||||
|
when(action.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(action.getName()).thenReturn(fqn.getName());
|
||||||
|
return action;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
protected EdmFunction createUnboundFunction(FullQualifiedName fqn, List<String> parameterNames) {
|
||||||
|
if (FQN.getNamespace().equals(fqn.getNamespace()) && FQN.getName().equals(fqn.getName())) {
|
||||||
|
EdmFunction function = mock(EdmFunction.class);
|
||||||
|
when(function.getNamespace()).thenReturn(fqn.getNamespace());
|
||||||
|
when(function.getName()).thenReturn(fqn.getName());
|
||||||
|
return function;
|
||||||
|
}
|
||||||
|
return null;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -19,6 +19,7 @@
|
|||||||
package org.apache.olingo.odata4.commons.core.edm.provider;
|
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.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
import static org.junit.Assert.assertTrue;
|
import static org.junit.Assert.assertTrue;
|
||||||
@ -75,6 +76,21 @@ public class EdmComplexTypeImplTest {
|
|||||||
type = new EdmComplexTypeImpl(edm, name, complexType);
|
type = new EdmComplexTypeImpl(edm, name, complexType);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void typeMustBeCompatibletoBasetype() {
|
||||||
|
assertTrue(type.compatibleTo(baseType));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void baseTypeMustNotBeCompatibleToType() {
|
||||||
|
assertFalse(baseType.compatibleTo(type));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void nullForCompatibleTypeMustResultInEdmException() {
|
||||||
|
assertFalse(type.compatibleTo(null));
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getBaseType() {
|
public void getBaseType() {
|
||||||
assertNull(baseType.getBaseType());
|
assertNull(baseType.getBaseType());
|
||||||
|
@ -0,0 +1,83 @@
|
|||||||
|
/*******************************************************************************
|
||||||
|
* 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.mockito.Mockito.mock;
|
||||||
|
import static org.mockito.Mockito.when;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
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.EdmFunction;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.provider.Action;
|
||||||
|
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.Function;
|
||||||
|
import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
|
||||||
|
import org.junit.Before;
|
||||||
|
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");
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() throws Exception {
|
||||||
|
EdmProvider provider = mock(EdmProvider.class);
|
||||||
|
|
||||||
|
Action action = new Action().setName(FQN.getName());
|
||||||
|
List<Action> actions = new ArrayList<Action>();
|
||||||
|
actions.add(action);
|
||||||
|
when(provider.getActions(FQN)).thenReturn(actions);
|
||||||
|
|
||||||
|
Function function = new Function().setName(FQN.getName()).setParameters(new ArrayList<Parameter>());
|
||||||
|
List<Function> functions = new ArrayList<Function>();
|
||||||
|
functions.add(function);
|
||||||
|
when(provider.getFunctions(FQN)).thenReturn(functions);
|
||||||
|
edm = new EdmProviderImpl(provider);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleActionGet() {
|
||||||
|
EdmAction action = edm.getAction(FQN, null, null);
|
||||||
|
assertNotNull(action);
|
||||||
|
assertEquals(FQN.getNamespace(), action.getNamespace());
|
||||||
|
assertEquals(FQN.getName(), action.getName());
|
||||||
|
|
||||||
|
assertNull(edm.getAction(WRONG_FQN, null, null));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void simpleFunctionGet() {
|
||||||
|
EdmFunction function = edm.getFunction(FQN, null, null, new ArrayList<String>());
|
||||||
|
assertNotNull(function);
|
||||||
|
assertEquals(FQN.getNamespace(), function.getNamespace());
|
||||||
|
assertEquals(FQN.getName(), function.getName());
|
||||||
|
|
||||||
|
assertNull(edm.getFunction(WRONG_FQN, null, null, new ArrayList<String>()));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
@ -21,31 +21,32 @@ 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.assertNotNull;
|
import static org.junit.Assert.assertNotNull;
|
||||||
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;
|
||||||
|
|
||||||
|
import java.lang.reflect.InvocationTargetException;
|
||||||
|
import java.lang.reflect.Method;
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.Edm;
|
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.EdmComplexType;
|
import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.EdmEntityContainer;
|
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.EdmEntityType;
|
||||||
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.EdmFunction;
|
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.EdmTypeDefinition;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.Action;
|
import org.apache.olingo.odata4.commons.api.edm.provider.AliasInfo;
|
||||||
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.EntityContainerInfo;
|
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.EntityType;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
|
import org.apache.olingo.odata4.commons.api.edm.provider.EnumType;
|
||||||
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.Function;
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.Parameter;
|
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
|
import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
|
||||||
import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
|
import org.apache.olingo.odata4.commons.api.edm.provider.TypeDefinition;
|
||||||
|
import org.apache.olingo.odata4.commons.api.exception.ODataException;
|
||||||
import org.junit.Before;
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
@ -75,19 +76,69 @@ public class EdmProviderImplTest {
|
|||||||
ComplexType complexType = new ComplexType().setName(FQN.getName());
|
ComplexType complexType = new ComplexType().setName(FQN.getName());
|
||||||
when(provider.getComplexType(FQN)).thenReturn(complexType);
|
when(provider.getComplexType(FQN)).thenReturn(complexType);
|
||||||
|
|
||||||
Action action = new Action().setName(FQN.getName());
|
List<AliasInfo> aliasInfos = new ArrayList<AliasInfo>();
|
||||||
List<Action> actions = new ArrayList<Action>();
|
aliasInfos.add(new AliasInfo().setAlias("alias").setNamespace("namespace"));
|
||||||
actions.add(action);
|
when(provider.getAliasInfos()).thenReturn(aliasInfos);
|
||||||
when(provider.getActions(FQN)).thenReturn(actions);
|
|
||||||
|
|
||||||
Function function = new Function().setName(FQN.getName()).setParameters(new ArrayList<Parameter>());
|
|
||||||
List<Function> functions = new ArrayList<Function>();
|
|
||||||
functions.add(function);
|
|
||||||
when(provider.getFunctions(FQN)).thenReturn(functions);
|
|
||||||
|
|
||||||
edm = new EdmProviderImpl(provider);
|
edm = new EdmProviderImpl(provider);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void convertExceptionsTest() throws Exception{
|
||||||
|
EdmProvider localProvider = mock(EdmProvider.class);
|
||||||
|
FullQualifiedName fqn = new FullQualifiedName("namespace", "name");
|
||||||
|
when(localProvider.getEntityContainerInfo(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getEnumType(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getTypeDefinition(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getEntityType(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getComplexType(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getActions(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
when(localProvider.getFunctions(fqn)).thenThrow(new ODataException("msg"));
|
||||||
|
|
||||||
|
Edm localEdm = new EdmProviderImpl(localProvider);
|
||||||
|
|
||||||
|
callMethodAndExpectEdmException(localEdm, "getEntityContainer");
|
||||||
|
callMethodAndExpectEdmException(localEdm, "getEnumType");
|
||||||
|
callMethodAndExpectEdmException(localEdm, "getTypeDefinition");
|
||||||
|
callMethodAndExpectEdmException(localEdm, "getEntityType");
|
||||||
|
callMethodAndExpectEdmException(localEdm, "getComplexType");
|
||||||
|
|
||||||
|
//seperate because of signature
|
||||||
|
try {
|
||||||
|
localEdm.getAction(fqn, null, null);
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
|
||||||
|
}
|
||||||
|
|
||||||
|
try {
|
||||||
|
localEdm.getFunction(fqn, null, null, null);
|
||||||
|
} catch (EdmException e) {
|
||||||
|
assertEquals("org.apache.olingo.odata4.commons.api.exception.ODataException: msg", e.getMessage());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
private void callMethodAndExpectEdmException(Edm localEdm, String methodName) throws Exception {
|
||||||
|
Method method = localEdm.getClass().getMethod(methodName, FullQualifiedName.class);
|
||||||
|
try {
|
||||||
|
method.invoke(localEdm, new FullQualifiedName("namespace", "name"));
|
||||||
|
} catch (InvocationTargetException e) {
|
||||||
|
Throwable cause = e.getCause();
|
||||||
|
if(cause instanceof EdmException){
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
fail("EdmException expected for method: " + methodName);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = EdmException.class)
|
||||||
|
public void convertExceptionsAliasTest() throws Exception{
|
||||||
|
EdmProvider localProvider = mock(EdmProvider.class);
|
||||||
|
when(localProvider.getAliasInfos()).thenThrow(new ODataException("msg"));
|
||||||
|
|
||||||
|
Edm localEdm = new EdmProviderImpl(localProvider);
|
||||||
|
localEdm.getEntityContainer(null);
|
||||||
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getEntityContainer() {
|
public void getEntityContainer() {
|
||||||
EdmEntityContainer entityContainer = edm.getEntityContainer(FQN);
|
EdmEntityContainer entityContainer = edm.getEntityContainer(FQN);
|
||||||
@ -143,26 +194,6 @@ public class EdmProviderImplTest {
|
|||||||
assertNull(edm.getComplexType(WRONG_FQN));
|
assertNull(edm.getComplexType(WRONG_FQN));
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getAction() {
|
|
||||||
EdmAction action = edm.getAction(FQN, null, null);
|
|
||||||
assertNotNull(action);
|
|
||||||
assertEquals(FQN.getNamespace(), action.getNamespace());
|
|
||||||
assertEquals(FQN.getName(), action.getName());
|
|
||||||
|
|
||||||
assertNull(edm.getAction(WRONG_FQN, null, null));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
|
||||||
public void getFunction() {
|
|
||||||
EdmFunction function = edm.getFunction(FQN, null, null, new ArrayList<String>());
|
|
||||||
assertNotNull(function);
|
|
||||||
assertEquals(FQN.getNamespace(), function.getNamespace());
|
|
||||||
assertEquals(FQN.getName(), function.getName());
|
|
||||||
|
|
||||||
assertNull(edm.getFunction(WRONG_FQN, null, null, new ArrayList<String>()));
|
|
||||||
}
|
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void getServiceMetadata() {
|
public void getServiceMetadata() {
|
||||||
assertNotNull(edm.getServiceMetadata());
|
assertNotNull(edm.getServiceMetadata());
|
||||||
|
Loading…
x
Reference in New Issue
Block a user