[OLINGO-63] Uri Parser: Add support for $filter
This commit is contained in:
parent
10ac7ee37e
commit
021afffb50
|
@ -35,4 +35,7 @@ public interface EdmType extends EdmNamed {
|
|||
* @return {@link EdmTypeKind} of this {@link EdmType}
|
||||
*/
|
||||
EdmTypeKind getKind();
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -20,5 +20,5 @@
|
|||
package org.apache.olingo.odata4.producer.api.uri;
|
||||
|
||||
public enum UriPathInfoKind {
|
||||
entitySet, navEntitySet, singleton, action, function;
|
||||
entitySet, navEntitySet, singleton, action, function, it;
|
||||
}
|
||||
|
|
|
@ -158,17 +158,23 @@ DESC : 'desc';
|
|||
MUL : 'mul';
|
||||
DIV : 'div';
|
||||
MOD : 'mod';
|
||||
|
||||
ADD : 'add';
|
||||
SUB : 'sub';
|
||||
|
||||
GT : 'gt';
|
||||
GE : 'ge';
|
||||
LT : 'lt';
|
||||
LE : 'le';
|
||||
ISOF : 'isof';
|
||||
|
||||
EQ_ALPHA : 'eq';
|
||||
NE : 'ne';
|
||||
|
||||
AND : 'and';
|
||||
OR : 'or';
|
||||
ISOF : 'isof';
|
||||
|
||||
|
||||
NOT : 'not';
|
||||
MINUS :'-';
|
||||
NANINFINITY : 'NaN' | '-INF' | 'INF';
|
||||
|
|
|
@ -124,19 +124,16 @@ value : VALUE;
|
|||
|
||||
queryOptions : qo+=queryOption ( AMP qo+=queryOption )*;
|
||||
|
||||
queryOption : systemQueryOption
|
||||
| AT aliasAndValue
|
||||
| customQueryOption
|
||||
queryOption : systemQueryOption
|
||||
| AT aliasAndValue
|
||||
| customQueryOption
|
||||
;
|
||||
|
||||
entityOptions : (eob+=entityOption AMP )* ID EQ REST ( AMP eoa+=entityOption )*;
|
||||
entityOption : ( expand | format | select )
|
||||
| customQueryOption
|
||||
|
||||
;
|
||||
|
||||
|
||||
|
||||
systemQueryOption : expand
|
||||
| filter
|
||||
| format
|
||||
|
@ -273,12 +270,12 @@ commonExpr : OPEN commonExpr CLOSE
|
|||
| methodCallExpr #altMethod
|
||||
| ( unary WSP ) commonExpr #altUnary
|
||||
| memberExpr #altMember
|
||||
| commonExpr (WSP MUL WSP | WSP DIV WSP | WSP MOD WSP ) commonExpr #altMult
|
||||
| commonExpr (WSP ADD WSP | WSP SUB WSP) commonExpr #altAdd
|
||||
| commonExpr (WSP MUL WSP | WSP DIV WSP | WSP MOD WSP ) commonExpr #altMult
|
||||
| commonExpr (WSP ADD WSP | WSP SUB WSP) commonExpr #altAdd
|
||||
| commonExpr (WSP GT WSP | WSP GE WSP | WSP LT WSP | WSP LE WSP | WSP ISOF WSP) commonExpr #altComparism
|
||||
| commonExpr (WSP EQ_ALPHA WSP | WSP NE WSP) commonExpr #altEquality
|
||||
| commonExpr (WSP AND WSP) commonExpr #altAnd
|
||||
| commonExpr (WSP OR WSP) commonExpr #altOr
|
||||
| commonExpr (WSP EQ_ALPHA WSP | WSP NE WSP) commonExpr #altEquality
|
||||
| commonExpr (WSP AND WSP) commonExpr #altAnd
|
||||
| commonExpr (WSP OR WSP) commonExpr #altOr
|
||||
| rootExpr #altRoot //; $...
|
||||
| AT odataIdentifier #altAlias // @...
|
||||
| primitiveLiteral #altLiteral // ...
|
||||
|
@ -288,7 +285,8 @@ unary : (MINUS| NOT) ;
|
|||
|
||||
rootExpr : ROOT pathSegments;
|
||||
|
||||
memberExpr : '$it' | '$it/'? pathSegments;
|
||||
memberExpr : '$it'
|
||||
| '$it/'? ps=pathSegments;
|
||||
|
||||
anyExpr : 'any' OPEN WSP /* [ lambdaVariableExpr BWS COLON BWS lambdaPredicateExpr ] WS* */ CLOSE;
|
||||
allExpr : 'all' OPEN WSP /* lambdaVariableExpr BWS COLON BWS lambdaPredicateExpr WS* */ CLOSE;
|
||||
|
|
|
@ -43,11 +43,13 @@ public class ParserAdapter {
|
|||
lexer = new UriLexer(new ANTLRInputStream(input));
|
||||
parser = new UriParserParser(new CommonTokenStream(lexer));
|
||||
|
||||
// Bail out of parser at first syntax error. --> proceeds in catch block with step 2
|
||||
// bail out of parser at first syntax error. --> proceeds in catch block with step 2
|
||||
parser.setErrorHandler(new BailErrorStrategy());
|
||||
|
||||
// User the faster LL parsing
|
||||
// user the faster LL parsing
|
||||
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
|
||||
|
||||
// parse
|
||||
ret = parser.odataRelativeUriEOF();
|
||||
|
||||
} catch (ParseCancellationException hardException) {
|
||||
|
@ -56,7 +58,6 @@ public class ParserAdapter {
|
|||
// create parser
|
||||
lexer = new UriLexer(new ANTLRInputStream(input));
|
||||
parser = new UriParserParser(new CommonTokenStream(lexer));
|
||||
|
||||
|
||||
// Used default error strategy
|
||||
parser.setErrorHandler(new DefaultErrorStrategy());
|
||||
|
@ -64,6 +65,7 @@ public class ParserAdapter {
|
|||
// User the slower SLL parsing
|
||||
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
|
||||
|
||||
// parse
|
||||
ret = parser.odataRelativeUriEOF();
|
||||
|
||||
} catch (Exception weakException) {
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri;
|
||||
|
||||
public enum SystemQueryParameter {
|
||||
FILTER("$filter"),
|
||||
FORMAT("$format"),
|
||||
ID("$id"),
|
||||
INLINECOUNT("$inlinecount"),
|
||||
ORDERBY("$orderby"),
|
||||
SEARCH("$search"),
|
||||
SELECT("$select"),
|
||||
SKIP("$skip"),
|
||||
SKIPTOKEN("$skiptoken"),
|
||||
TOP("$top");
|
||||
|
||||
String syntax;
|
||||
|
||||
private SystemQueryParameter(final String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return syntax;
|
||||
}
|
||||
}
|
|
@ -18,12 +18,19 @@
|
|||
******************************************************************************/
|
||||
package org.apache.olingo.odata4.producer.core.uri;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
|
||||
|
||||
public class UriInfoImpl {
|
||||
|
||||
private UriInfoKind kind;
|
||||
|
||||
private Map<String, List<Object>> queryParameter = new HashMap<String, List<Object>>();
|
||||
|
||||
public UriInfoImpl setKind(final UriInfoKind kind) {
|
||||
this.kind = kind;
|
||||
return this;
|
||||
|
@ -33,4 +40,16 @@ public class UriInfoImpl {
|
|||
return kind;
|
||||
}
|
||||
|
||||
public List<Object> getQueryParameters(String name) {
|
||||
return queryParameter.get(name);
|
||||
}
|
||||
|
||||
public void addQueryParameter(String name, Object object) {
|
||||
List<Object> entry = queryParameter.get(name);
|
||||
if (entry != null) {
|
||||
entry.add(object);
|
||||
} else {
|
||||
queryParameter.put(name, Arrays.asList(object));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -19,13 +19,19 @@
|
|||
package org.apache.olingo.odata4.producer.core.uri;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Expression;
|
||||
|
||||
public class UriInfoImplPath extends UriInfoImpl {
|
||||
|
||||
List<UriPathInfoImpl> pathInfos = new ArrayList<UriPathInfoImpl>();
|
||||
private List<UriPathInfoImpl> pathInfos = new ArrayList<UriPathInfoImpl>();
|
||||
|
||||
private Expression spFilter;
|
||||
|
||||
public UriInfoImplPath() {
|
||||
this.setKind(UriInfoKind.path);
|
||||
|
@ -47,4 +53,35 @@ public class UriInfoImplPath extends UriInfoImpl {
|
|||
return pathInfos.get(index);
|
||||
}
|
||||
|
||||
public void setSystemParameter(SystemQueryParameter filter, Expression expression) {
|
||||
spFilter = expression;
|
||||
addQueryParameter(filter.toString(), expression);
|
||||
}
|
||||
|
||||
public Expression getFilter() {
|
||||
return this.spFilter;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "";
|
||||
int i = 0;
|
||||
while (i < pathInfos.size()) {
|
||||
if ( i > 0 ) {
|
||||
ret += "/";
|
||||
}
|
||||
|
||||
ret += pathInfos.get(i).toString();
|
||||
|
||||
|
||||
|
||||
i++;
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -21,6 +21,9 @@ package org.apache.olingo.odata4.producer.core.uri;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
import javax.annotation.processing.SupportedAnnotationTypes;
|
||||
|
||||
import org.antlr.v4.runtime.tree.ParseTree;
|
||||
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.EdmActionImport;
|
||||
|
@ -37,24 +40,54 @@ import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
|
|||
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.helper.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltAddContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltAliasContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltAndContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltBatchContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltComparismContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltEntityCastContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltEntityContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltEqualityContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltLiteralContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltMemberContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltMetadataContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltMethodContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltMultContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltOrContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltPharenthesisContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltResourcePathContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltRootContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.AltUnaryContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.CustomQueryOptionContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.ExpandContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.FilterContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.FormatContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.IdContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.InlinecountContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.MemberExprContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValueListContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValueOptListContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.NameValuePairContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OrderbyContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.PathSegmentContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.PathSegmentsContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.QueryOptionContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.QueryOptionsContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.ResourcePathContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.SearchContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.SelectContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.SkipContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.SkiptokenContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.SystemQueryOptionContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.TopContext;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.*;
|
||||
|
||||
public class UriParserImpl {
|
||||
private Edm edm = null;
|
||||
private EdmEntityContainer edmEntityContainer = null;
|
||||
private UriPathInfoImpl lastUriPathInfo;
|
||||
|
||||
public UriParserImpl(Edm edm) {
|
||||
this.edm = edm;
|
||||
|
@ -68,7 +101,9 @@ public class UriParserImpl {
|
|||
|
||||
private UriInfoImpl readODataRelativeUriEOF(OdataRelativeUriEOFContext node) {
|
||||
OdataRelativeUriContext first = (OdataRelativeUriContext) node.getChild(0);
|
||||
return readODataRelativeUri(first);
|
||||
|
||||
UriInfoImpl uriInfo = readODataRelativeUri(first);
|
||||
return uriInfo;
|
||||
}
|
||||
|
||||
private UriInfoImpl readODataRelativeUri(OdataRelativeUriContext node) {
|
||||
|
@ -94,7 +129,12 @@ public class UriParserImpl {
|
|||
QueryOptionsContext qoc = (QueryOptionsContext) node.getChild(2); // is null if there are no options
|
||||
|
||||
if (rpc.vPSs != null) {
|
||||
return readPathSegments(rpc.vPSs);
|
||||
UriInfoImplPath uriInfo = readPathSegments(rpc.vPSs, null);
|
||||
|
||||
if (qoc != null) {
|
||||
readQueryParameter(uriInfo, qoc);
|
||||
}
|
||||
return uriInfo;
|
||||
} else if (rpc.vCJ != null) {
|
||||
return new UriInfoImplCrossjoin();
|
||||
} else if (rpc.vAll != null) {
|
||||
|
@ -104,21 +144,165 @@ public class UriParserImpl {
|
|||
return null;
|
||||
}
|
||||
|
||||
private UriInfoImpl readPathSegments(PathSegmentsContext pathSegments) {
|
||||
int iSegment = 0;
|
||||
private void readQueryParameter(UriInfoImplPath uriInfoImplPath, QueryOptionsContext qoc) {
|
||||
for (QueryOptionContext queryOption : qoc.qo) {
|
||||
readQueryOption(uriInfoImplPath, queryOption);
|
||||
}
|
||||
}
|
||||
|
||||
private void readQueryOption(UriInfoImplPath uriInfoImplPath, QueryOptionContext queryOption) {
|
||||
ParseTree firstChild = queryOption.getChild(0);
|
||||
|
||||
if (firstChild instanceof SystemQueryOptionContext) {
|
||||
readSystemQueryOption(uriInfoImplPath, firstChild);
|
||||
} else if (firstChild instanceof CustomQueryOptionContext) {
|
||||
// TODO read custom request option
|
||||
} else if (firstChild.getText().equals("@")) {
|
||||
// TODO read ailas and value
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
private void readSystemQueryOption(UriInfoImplPath uriInfoImplPath, ParseTree systemQueryOption) {
|
||||
ParseTree firstChild = systemQueryOption.getChild(0);
|
||||
if (firstChild instanceof ExpandContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof FilterContext) {
|
||||
Expression expression = readFilterOption(firstChild);
|
||||
uriInfoImplPath.setSystemParameter(SystemQueryParameter.FILTER, expression);
|
||||
return;
|
||||
} else if (firstChild instanceof FormatContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof IdContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof InlinecountContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof OrderbyContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof SearchContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof SelectContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof SkipContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof SkiptokenContext) {
|
||||
// TODO implement
|
||||
} else if (firstChild instanceof TopContext) {
|
||||
// TODO implement
|
||||
}
|
||||
}
|
||||
|
||||
private Expression readFilterOption(ParseTree filter) {
|
||||
return readCommonExpression(filter.getChild(2));
|
||||
}
|
||||
|
||||
private Expression readCommonExpression(ParseTree expressionContext) {
|
||||
// Expression ret = null;
|
||||
|
||||
if (expressionContext instanceof AltPharenthesisContext) {
|
||||
return readCommonExpression(expressionContext.getChild(1));
|
||||
} else if (expressionContext instanceof AltMethodContext) {
|
||||
return readMethod(expressionContext);
|
||||
} else if (expressionContext instanceof AltUnaryContext) {
|
||||
UnaryOperator unary = new UnaryOperator();
|
||||
unary.setOperator(SupportedUnaryOperators.get(expressionContext.getChild(0).getText()));
|
||||
unary.setOperand(readCommonExpression(expressionContext.getChild(1)));
|
||||
return unary;
|
||||
} else if (expressionContext instanceof AltMemberContext) {
|
||||
return readMember(expressionContext);
|
||||
} else if (expressionContext instanceof AltMultContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltAddContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltComparismContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltEqualityContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltAndContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltOrContext) {
|
||||
return readBinary(expressionContext);
|
||||
} else if (expressionContext instanceof AltRootContext) {
|
||||
// TODO
|
||||
} else if (expressionContext instanceof AltAliasContext) {
|
||||
Alias alias = new Alias();
|
||||
alias.setReference(expressionContext.getChild(1).getText());
|
||||
// TODO collect all aliases and verify them afterwards
|
||||
return alias;
|
||||
} else if (expressionContext instanceof AltLiteralContext) {
|
||||
Literal literal = new Literal();
|
||||
literal.setText(expressionContext.getText());
|
||||
return literal;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private Expression readMember(ParseTree expressionContext) {
|
||||
MemberExprContext context = (MemberExprContext) expressionContext.getChild(0);
|
||||
|
||||
Member member = new Member();
|
||||
|
||||
UriPathInfoIT pathInfoIT = new UriPathInfoIT();
|
||||
|
||||
|
||||
if (context.ps!= null) {
|
||||
if (context.getChild(0).getText().startsWith("$it/")) {
|
||||
member.setIT(true); // TODO check if this is required
|
||||
pathInfoIT.setIsExplicitIT(true);
|
||||
}
|
||||
UriParserImpl parser = new UriParserImpl(this.edm);
|
||||
|
||||
UriInfoImplPath path = parser.readPathSegments(context.ps,
|
||||
new UriPathInfoIT().setType(lastUriPathInfo.getType()));
|
||||
member.setPath(path);
|
||||
} else {
|
||||
member.setIT(true);
|
||||
}
|
||||
return member;
|
||||
|
||||
}
|
||||
|
||||
private Expression readMethod(ParseTree expressionContext) {
|
||||
MethodCall expression = new MethodCall();
|
||||
expression.setMethod(SupportedMethodCalls.get(expressionContext.getChild(0).getText()));
|
||||
int i = 1;
|
||||
while (i < expressionContext.getChildCount()) {
|
||||
expression.addParameter(readCommonExpression(expressionContext.getChild(i)));
|
||||
i++;
|
||||
}
|
||||
return expression;
|
||||
}
|
||||
|
||||
private Expression readBinary(ParseTree expressionContext) {
|
||||
BinaryOperator expression = new BinaryOperator();
|
||||
expression.setLeftOperand(readCommonExpression(expressionContext.getChild(0)));
|
||||
expression.setOperator(SupportedBinaryOperators.get(expressionContext.getChild(2).getText()));
|
||||
expression.setRightOperand(readCommonExpression(expressionContext.getChild(4)));
|
||||
return expression;
|
||||
}
|
||||
|
||||
private UriInfoImplPath readPathSegments(PathSegmentsContext pathSegments, UriPathInfoImpl usePrevPathInfo) {
|
||||
|
||||
UriPathInfoImpl prevPathInfo = usePrevPathInfo;
|
||||
UriInfoImplPath infoImpl = new UriInfoImplPath();
|
||||
PathSegmentContext firstChild = (PathSegmentContext) pathSegments.vlPS.get(iSegment);
|
||||
UriPathInfoImpl firstPathInfo = readFirstPathSegment(infoImpl, firstChild);
|
||||
|
||||
int iSegment = 0;
|
||||
|
||||
iSegment++;
|
||||
|
||||
UriPathInfoImpl prevPathInfo = firstPathInfo;
|
||||
if (prevPathInfo == null) {
|
||||
PathSegmentContext firstChild = (PathSegmentContext) pathSegments.vlPS.get(iSegment);
|
||||
UriPathInfoImpl firstPathInfo = readFirstPathSegment(infoImpl, firstChild);
|
||||
iSegment++;
|
||||
prevPathInfo = firstPathInfo;
|
||||
} else {
|
||||
infoImpl.addPathInfo(prevPathInfo);
|
||||
}
|
||||
|
||||
while (iSegment < pathSegments.vlPS.size()) {
|
||||
PathSegmentContext nextChild = (PathSegmentContext) pathSegments.vlPS.get(iSegment);
|
||||
prevPathInfo = readNextPathSegment(infoImpl, nextChild, prevPathInfo);
|
||||
iSegment++;
|
||||
}
|
||||
lastUriPathInfo = prevPathInfo;
|
||||
return infoImpl;
|
||||
}
|
||||
|
||||
|
|
|
@ -40,5 +40,10 @@ public class UriPathInfoActionImpl extends UriPathInfoImpl {
|
|||
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return action.getName() + super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -33,8 +33,16 @@ public class UriPathInfoEntitySetImpl extends UriPathInfoImpl {
|
|||
|
||||
this.edmEntitySet = edmES;
|
||||
this.setType(edmES.getEntityType());
|
||||
this.setCollection(true);
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return edmEntitySet.getName() + super.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -54,4 +54,11 @@ public class UriPathInfoFunctionImpl extends UriPathInfoImpl {
|
|||
this.keyPredicates = keyPredicates;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return function.getName() + super.toString();
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,53 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmAction;
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
|
||||
|
||||
/**
|
||||
* Covers Functionimports and BoundFunction in URI
|
||||
*/
|
||||
public class UriPathInfoIT extends UriPathInfoImpl {
|
||||
|
||||
private boolean explicitIT;
|
||||
|
||||
|
||||
public UriPathInfoIT() {
|
||||
this.setKind(UriPathInfoKind.it);
|
||||
this.setCollection(false);
|
||||
}
|
||||
@Override
|
||||
public String toString() {
|
||||
|
||||
if (explicitIT) {
|
||||
return "$it" + super.toString();
|
||||
}
|
||||
return super.toString();
|
||||
}
|
||||
|
||||
|
||||
public UriPathInfoIT setIsExplicitIT(boolean explicitIT) {
|
||||
this.explicitIT =explicitIT;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -28,6 +28,7 @@ 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.helper.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Expression;
|
||||
|
||||
public abstract class UriPathInfoImpl {
|
||||
|
||||
|
@ -64,6 +65,14 @@ public abstract class UriPathInfoImpl {
|
|||
return initialType;
|
||||
}
|
||||
|
||||
public EdmType getCollectionTypeFilter() {
|
||||
return collectionTypeFilter;
|
||||
}
|
||||
|
||||
public EdmType getSingleTypeFilter() {
|
||||
return singleTypeFilter;
|
||||
}
|
||||
|
||||
public FullQualifiedName getFullType() {
|
||||
return new FullQualifiedName(finalType.getNamespace(), finalType.getName());
|
||||
}
|
||||
|
@ -78,7 +87,7 @@ public abstract class UriPathInfoImpl {
|
|||
}
|
||||
|
||||
public UriPathInfoImpl setKeyPredicates(UriKeyPredicateList keyPredicates) {
|
||||
if ( this.isCollection()!= true) {
|
||||
if (this.isCollection() != true) {
|
||||
// throw exception
|
||||
}
|
||||
this.keyPredicates = keyPredicates;
|
||||
|
@ -165,7 +174,7 @@ public abstract class UriPathInfoImpl {
|
|||
return pathList.get(index).property;
|
||||
|
||||
}
|
||||
|
||||
|
||||
public UriPathInfoImpl setCollection(boolean isCollection) {
|
||||
this.isCollection = isCollection;
|
||||
return this;
|
||||
|
@ -175,4 +184,19 @@ public abstract class UriPathInfoImpl {
|
|||
|
||||
return isCollection;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
String ret = "";
|
||||
int i = 0;
|
||||
while (i < pathList.size()) {
|
||||
if (i > 0) {
|
||||
ret += "/";
|
||||
}
|
||||
ret += pathList.get(i).property.getName();
|
||||
i++;
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -34,5 +34,10 @@ public class UriPathInfoNavEntitySet extends UriPathInfoImpl {
|
|||
this.setType(sourceNavigationProperty.getType());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return sourceNavigationProperty.getName()+super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -24,16 +24,21 @@ import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
|
|||
public class UriPathInfoSingletonImpl extends UriPathInfoImpl {
|
||||
|
||||
private EdmSingleton singleton;
|
||||
|
||||
|
||||
public UriPathInfoSingletonImpl() {
|
||||
this.setKind(UriPathInfoKind.singleton);
|
||||
}
|
||||
|
||||
public UriPathInfoSingletonImpl setSingleton(EdmSingleton singleton) {
|
||||
|
||||
|
||||
this.singleton = singleton;
|
||||
this.setType(singleton.getEntityType());
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return singleton.getName() + super.toString();
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -0,0 +1,37 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
|
||||
public class Alias extends Expression {
|
||||
|
||||
private String referenceName;
|
||||
//TODO add object which is referenced
|
||||
|
||||
public void setReference(String referenceName) {
|
||||
this.referenceName = referenceName;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object accept(ExpressionVisitor visitor) throws ExceptionVisitExpression {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public class BinaryOperator extends Expression implements Visitable {
|
||||
|
||||
private SupportedBinaryOperators operator;
|
||||
private Expression left;
|
||||
private Expression right;
|
||||
|
||||
public BinaryOperator setOperator(SupportedBinaryOperators operator) {
|
||||
this.operator = operator;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void setLeftOperand(Expression operand) {
|
||||
this.left = operand;
|
||||
|
||||
}
|
||||
|
||||
public void setRightOperand(Expression operand) {
|
||||
this.right = operand;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ExpressionVisitor<T> visitor) throws ExceptionVisitExpression {
|
||||
T left = this.left.accept(visitor);
|
||||
T right = this.right.accept(visitor);
|
||||
return visitor.visitBinaryOperator(operator,left,right);
|
||||
}
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public class ExceptionVisitExpression extends Exception {
|
||||
|
||||
}
|
|
@ -0,0 +1,25 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public abstract class Expression implements Visitable{
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -0,0 +1,34 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public interface ExpressionVisitor<T> {
|
||||
|
||||
T visitBinaryOperator(SupportedBinaryOperators operator, T left, T right) throws ExceptionVisitExpression;
|
||||
|
||||
T visitUnaryOperator( SupportedUnaryOperators operator, T operand) throws ExceptionVisitExpression;
|
||||
|
||||
T visitMethoCall( SupportedMethodCalls methodCall, List<T> parameters)throws ExceptionVisitExpression;
|
||||
|
||||
T visitLiteral(String literal) throws ExceptionVisitExpression;
|
||||
|
||||
T visitMember(Member member) throws ExceptionVisitExpression;;
|
||||
}
|
|
@ -0,0 +1,35 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public class Literal extends Expression implements Visitable {
|
||||
|
||||
private String text;
|
||||
|
||||
public void setText(String text) {
|
||||
this.text = text;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ExpressionVisitor<T> visitor) throws ExceptionVisitExpression {
|
||||
return visitor.visitLiteral(text);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriInfoImplPath;
|
||||
|
||||
public class Member extends Expression implements Visitable {
|
||||
|
||||
private boolean isIT;
|
||||
UriInfoImplPath path;
|
||||
|
||||
public Member setIT(boolean isIT) {
|
||||
this.isIT = isIT;
|
||||
return this;
|
||||
}
|
||||
|
||||
public boolean isIT() {
|
||||
return isIT;
|
||||
}
|
||||
|
||||
public Member setPath(UriInfoImplPath pathSegments) {
|
||||
this.path = pathSegments;
|
||||
return this;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> T accept(ExpressionVisitor<T> visitor) throws ExceptionVisitExpression {
|
||||
return visitor.visitMember(this);
|
||||
|
||||
}
|
||||
|
||||
public UriInfoImplPath getPath() {
|
||||
return path;
|
||||
}
|
||||
}
|
|
@ -0,0 +1,43 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
public class MethodCall extends Expression implements Visitable{
|
||||
|
||||
private SupportedMethodCalls method;
|
||||
private List<Expression> parameters = new ArrayList<Expression>();
|
||||
|
||||
public void setMethod(SupportedMethodCalls methodCalls) {
|
||||
this.method = methodCalls;
|
||||
}
|
||||
|
||||
public void addParameter(Expression readCommonExpression) {
|
||||
parameters.add(readCommonExpression);
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object accept(ExpressionVisitor visitor) throws ExceptionVisitExpression {
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public enum SupportedBinaryOperators {
|
||||
MUL("mul"), DIV("div"), MOD("mod"),
|
||||
ADD("add"), SUB("sub"), GT("gt"), GE("ge"), LT("lt"), LE("le"),
|
||||
ISOF("isof"),
|
||||
EQ("eq"), NE("ne"),
|
||||
AND("and"), OR("or");
|
||||
|
||||
private String syntax;
|
||||
|
||||
private SupportedBinaryOperators(final String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
public static SupportedBinaryOperators get(String operator) {
|
||||
for (SupportedBinaryOperators op : SupportedBinaryOperators.values()) {
|
||||
if (op.toString().equals(operator)) {
|
||||
return op;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,48 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public enum SupportedMethodCalls {
|
||||
MUL("mul"), DIV("div"), MOD("mod"),
|
||||
ADD("add"), SUB("sub"), GT("gt"), GE("ge"), LT("lt"), LE("le"),
|
||||
ISOF("isof"),
|
||||
EQ("eq"), NE("ne"),
|
||||
AND("and"), OR("or");
|
||||
|
||||
private String syntax;
|
||||
|
||||
private SupportedMethodCalls(final String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
public static SupportedMethodCalls get(String operator) {
|
||||
for (SupportedMethodCalls op : SupportedMethodCalls.values()) {
|
||||
if (op.toString().equals(operator)) {
|
||||
return op;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,44 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public enum SupportedUnaryOperators {
|
||||
MINUS("-"), NOT("not");
|
||||
|
||||
private String syntax;
|
||||
|
||||
private SupportedUnaryOperators(final String syntax) {
|
||||
this.syntax = syntax;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return syntax;
|
||||
}
|
||||
|
||||
public static SupportedUnaryOperators get(String operator) {
|
||||
for (SupportedUnaryOperators op : SupportedUnaryOperators.values()) {
|
||||
if (op.toString().equals(operator)) {
|
||||
return op;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,42 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
public class UnaryOperator extends Expression implements Visitable {
|
||||
|
||||
private SupportedUnaryOperators operator;
|
||||
private Expression expression;
|
||||
|
||||
public void setOperand(Expression expression) {
|
||||
this.expression = expression;
|
||||
|
||||
}
|
||||
|
||||
public void setOperator(SupportedUnaryOperators operator) {
|
||||
this.operator = operator;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public Object accept(ExpressionVisitor visitor) throws ExceptionVisitExpression {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,51 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.expression;
|
||||
|
||||
import org.antlr.v4.runtime.tree.ParseTreeVisitor;
|
||||
|
||||
|
||||
|
||||
/* TODO update documentation*/
|
||||
public interface Visitable {
|
||||
|
||||
/**
|
||||
* Method {@link #accept(ExpressionVisitor)} is called when traversing the expression tree. This method is invoked on
|
||||
* each
|
||||
* expression used as node in an expression tree. The implementations should
|
||||
* behave as follows:
|
||||
* <li>Call accept on all sub nodes and store the returned Objects
|
||||
* <li>Call the appropriate method on the {@link ExpressionVisitor} instance and provide the stored objects to that
|
||||
* instance
|
||||
* <li>Return the object which should be passed to the processing algorithm of the parent expression node
|
||||
* <br>
|
||||
* <br>
|
||||
* @param visitor
|
||||
* Object ( implementing {@link ExpressionVisitor}) whose methods are called during traversing a expression node of
|
||||
* the expression tree.
|
||||
* @return
|
||||
* Object which should be passed to the processing algorithm of the parent expression node
|
||||
* @throws ExceptionVisitExpression
|
||||
* Exception occurred the OData library while traversing the tree
|
||||
* @throws ODataApplicationException
|
||||
* Exception thrown by the application who implemented the visitor
|
||||
*/
|
||||
<T> T accept(ExpressionVisitor<T> visitor) throws ExceptionVisitExpression;
|
||||
}
|
||||
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.queryoption;
|
||||
|
||||
public class Filter extends SystemQueryOption {
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.queryoption;
|
||||
|
||||
public class QueryOption {
|
||||
|
||||
}
|
|
@ -0,0 +1,23 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.uri.queryoption;
|
||||
|
||||
public class SystemQueryOption extends QueryOption {
|
||||
|
||||
}
|
|
@ -1,743 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
package org.apache.olingo.odata4.producer.core.testutil;
|
||||
|
||||
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.EdmActionImport;
|
||||
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.EdmEntitySet;
|
||||
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.EdmFunction;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmKeyPropertyRef;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmPrimitiveType;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmReturnType;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmServiceMetadata;
|
||||
import org.apache.olingo.odata4.commons.api.edm.EdmSingleton;
|
||||
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.EdmTypeDefinition;
|
||||
import org.apache.olingo.odata4.commons.api.edm.constants.EdmTypeKind;
|
||||
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
|
||||
|
||||
public class EdmMock implements Edm {
|
||||
public static final String NAMESPACE_SCHEMA = "RefScenario";
|
||||
public static final FullQualifiedName CONTAINER_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Container1");
|
||||
|
||||
public static final FullQualifiedName ACTION_IMPORT1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "actionImport1");
|
||||
public static final FullQualifiedName COMPANY_SINGLETON_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Company");
|
||||
public static final FullQualifiedName TEAMS_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Teams");
|
||||
public static final FullQualifiedName MANAGERS_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Managers");
|
||||
public static final FullQualifiedName EMPLOYEES_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "Employees");
|
||||
public static final FullQualifiedName EMPLOYEES_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "EmployeeType");
|
||||
public static final FullQualifiedName TEAMS_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "TeamType");
|
||||
public static final FullQualifiedName MANAGERS_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "ManagerType");
|
||||
public static final FullQualifiedName COMPANY_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "CompanyType");
|
||||
public static final FullQualifiedName FUNCTION1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "function1");
|
||||
public static final FullQualifiedName FUNCTION_MAXIMAL_AGE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MaximalAge");
|
||||
public static final FullQualifiedName FUNCTION_EMPLOYEE_SEARCH_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"EmployeeSearch");
|
||||
public static final FullQualifiedName FUNCTION_ALL_USED_ROOMS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllUsedRoomIds");
|
||||
public static final FullQualifiedName FUNCTION_MOST_COMMON_LOCATION_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MostCommonLocation");
|
||||
public static final FullQualifiedName FUNCTION_ALL_LOCATIONS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllLocations");
|
||||
public static final FullQualifiedName ACTION1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "action1");
|
||||
public static final FullQualifiedName TYPE_DEF1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "tdtypeDef1");
|
||||
public static final FullQualifiedName RATING_ENUM_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "eRating");
|
||||
public static final FullQualifiedName LOCATION_TYPE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA, "cLocation");
|
||||
public static final FullQualifiedName NON_BINDING_PARAMETER = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"NonBindingParameter");
|
||||
|
||||
public static final FullQualifiedName FUNCTION_IMPORT1_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"functionImport1");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"EmployeeSearch");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_MAXIMAL_AGE_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"MaximalAge");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_ALL_USED_ROOMS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllUsedRoomIds");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "MostCommonLocation");
|
||||
public static final FullQualifiedName FUNCTION_IMPORT_ALL_LOCATIONS_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"AllLocations");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_entity");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_pprop_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_pprop");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_cprop");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_cprop_coll");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_entity_set_rt_pprop_coll");
|
||||
public static final FullQualifiedName BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "bf_singleton_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_pprop_rt_entity_set");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_ENTITY_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_rt_entity");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_PPROP_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_rt_pprop");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_RT_PPROP_COLL_NAME = new FullQualifiedName(
|
||||
NAMESPACE_SCHEMA, "ba_entity_rt_pprop_coll");
|
||||
public static final FullQualifiedName BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME = new FullQualifiedName(NAMESPACE_SCHEMA,
|
||||
"ba_entity_set_rt_cprop");
|
||||
|
||||
private final EdmEntityType companyType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType managerType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType employeeType = mock(EdmEntityType.class);
|
||||
private final EdmEntityType teamType = mock(EdmEntityType.class);
|
||||
|
||||
private final EdmFunction function1 = mock(EdmFunction.class);
|
||||
private final EdmFunction maximalAgeFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction mostCommonLocationFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction allUsedRoomIdsFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction employeeSearchFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction allLocationsFunction = mock(EdmFunction.class);
|
||||
|
||||
private final EdmFunction boundFunctionEntitySetRtEntity = mock(EdmFunction.class);
|
||||
private final EdmFunction boundEntityColFunction = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionPPropRtEntitySet = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtPProp = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtCProp = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtCPropColl = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionEntitySetRtPPropColl = mock(EdmFunction.class);
|
||||
private final EdmFunction boundFunctionSingletonRtEntitySet = mock(EdmFunction.class);
|
||||
|
||||
private final EdmAction action1 = mock(EdmAction.class);
|
||||
private final EdmAction boundActionPpropRtEntitySet = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtEntity = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtPProp = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntityRtPPropColl = mock(EdmAction.class);
|
||||
private final EdmAction boundActionEntitySetRtCProp = mock(EdmAction.class);
|
||||
private final EdmEnumType ratingEnumType = mock(EdmEnumType.class);
|
||||
private final EdmTypeDefinition typeDef1 = mock(EdmTypeDefinition.class);
|
||||
private final EdmComplexType locationType = mock(EdmComplexType.class);
|
||||
|
||||
private final EdmEntitySet employeesSet = mock(EdmEntitySet.class);
|
||||
private final EdmEntitySet managersSet = mock(EdmEntitySet.class);
|
||||
private final EdmEntitySet teamsSet = mock(EdmEntitySet.class);
|
||||
private final EdmSingleton company = mock(EdmSingleton.class);
|
||||
private final EdmActionImport actionImport1 = mock(EdmActionImport.class);
|
||||
private final EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport employeeSearchFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport maximalAgeFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport mostCommonLocationFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport allUsedRoomIdsFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmFunctionImport allLocationsFunctionImport = mock(EdmFunctionImport.class);
|
||||
private final EdmEntityContainer container1 = mock(EdmEntityContainer.class);
|
||||
|
||||
public EdmMock() {
|
||||
enhanceEmployeesEntitySet();
|
||||
enhanceManagersEntitySet();
|
||||
enhanceTeamsEntitySet();
|
||||
enhanceCompany();
|
||||
enhanceContainer1();
|
||||
|
||||
enhanceEmployeeType();
|
||||
enhanceManagerType();
|
||||
enhanceTeamType();
|
||||
enhanceCompanyType();
|
||||
enhanceLocationType();
|
||||
|
||||
enhanceActionImport1();
|
||||
enhanceFunctionImport1();
|
||||
enhanceFunctionImportEmployeeSearch();
|
||||
enhanceMaximalAgeFunctionImport();
|
||||
enhanceMostCommonLocationFunctionImport();
|
||||
enhanceAllUsedRoomIdsFunctionImport();
|
||||
enhanceAllLocationsFunctionImport();
|
||||
|
||||
enhanceAction1();
|
||||
enhanceFunction1();
|
||||
enhanceFunctionEmployeeSearch();
|
||||
enhanceMaximalAgeFunction();
|
||||
enhanceMostCommonLocationFunction();
|
||||
enhanceAllUsedRoomIdsFunction();
|
||||
enhanceAllLocationsFunction();
|
||||
enhanceBoundEntityFunction();
|
||||
enhanceBoundFunctionEntitySetRtEntitySet();
|
||||
enhanceBoundFunctionPPropRtEntitySet();
|
||||
enhanceBoundFunctionEntitySetRtPProp();
|
||||
enhanceBoundFunctionEntitySetRtPPropColl();
|
||||
enhanceBoundFunctionEntitySetRtCProp();
|
||||
enhanceBoundFunctionEntitySetRtCPropColl();
|
||||
enhanceBoundFunctionSingletonRtEntitySet();
|
||||
enhanceBoundActionPPropRtEntitySet();
|
||||
enhanceBoundActionEntityRtEntity();
|
||||
enhanceBoundActionEntityRtPProp();
|
||||
enhanceBoundActionEntityRtPPropColl();
|
||||
enhanceBoundActionEntitySetRtCProp();
|
||||
}
|
||||
|
||||
private void enhanceTeamType() {
|
||||
when(teamType.getName()).thenReturn(TEAMS_TYPE_NAME.getName());
|
||||
when(teamType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(teamType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(teamType.hasStream()).thenReturn(false);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(teamType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(teamType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(teamType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(teamType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(teamType, "Id");
|
||||
|
||||
addNavigationProperty(teamType, "nt_Employees", true, employeeType);
|
||||
|
||||
addProperty(teamType, "Name", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(teamType, "IsScrumTeam", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(teamType, "Rating", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
private void enhanceManagerType() {
|
||||
when(managerType.getName()).thenReturn(MANAGERS_TYPE_NAME.getName());
|
||||
when(managerType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(managerType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(managerType.hasStream()).thenReturn(true);
|
||||
when(managerType.getBaseType()).thenReturn(employeeType);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(managerType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(managerType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(managerType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(managerType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(managerType, "EmployeeId");
|
||||
|
||||
addNavigationProperty(managerType, "ne_Manager", false, managerType);
|
||||
addNavigationProperty(managerType, "ne_Team", false, teamType);
|
||||
addNavigationProperty(managerType, "nm_Employees", true, employeeType);
|
||||
|
||||
addProperty(managerType, "EmployeeName", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "ManagerId", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "Location", false, locationType);
|
||||
addProperty(managerType, "Age", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "EntryDate", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(managerType, "ImageUrl", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
// when().thenReturn();
|
||||
private void enhanceEmployeeType() {
|
||||
when(employeeType.getName()).thenReturn(EMPLOYEES_TYPE_NAME.getName());
|
||||
when(employeeType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(employeeType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
when(employeeType.hasStream()).thenReturn(true);
|
||||
List<String> keyPredicateNames = new ArrayList<String>();
|
||||
when(employeeType.getKeyPredicateNames()).thenReturn(keyPredicateNames);
|
||||
List<EdmKeyPropertyRef> keyPropertyRefs = new ArrayList<EdmKeyPropertyRef>();
|
||||
when(employeeType.getKeyPropertyRefs()).thenReturn(keyPropertyRefs);
|
||||
List<String> navigationNames = new ArrayList<String>();
|
||||
when(employeeType.getNavigationPropertyNames()).thenReturn(navigationNames);
|
||||
List<String> propertyNames = new ArrayList<String>();
|
||||
when(employeeType.getPropertyNames()).thenReturn(propertyNames);
|
||||
|
||||
addKeyProperty(employeeType, "EmployeeId");
|
||||
|
||||
addNavigationProperty(employeeType, "ne_Manager", false, managerType);
|
||||
addNavigationProperty(employeeType, "ne_Team", false, teamType);
|
||||
|
||||
addProperty(employeeType, "EmployeeName", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "ManagerId", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "Location", false, locationType);
|
||||
addProperty(employeeType, "Age", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "EntryDate", true, mock(EdmPrimitiveType.class));
|
||||
addProperty(employeeType, "ImageUrl", true, mock(EdmPrimitiveType.class));
|
||||
}
|
||||
|
||||
private void enhanceLocationType() {
|
||||
addProperty(locationType, "Country", true, mock(EdmPrimitiveType.class));
|
||||
when(locationType.getName()).thenReturn(LOCATION_TYPE_NAME.getName());
|
||||
}
|
||||
|
||||
private void enhanceCompanyType() {
|
||||
when(companyType.getName()).thenReturn(COMPANY_TYPE_NAME.getName());
|
||||
when(companyType.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(companyType.getKind()).thenReturn(EdmTypeKind.ENTITY);
|
||||
}
|
||||
|
||||
private void addNavigationProperty(final EdmEntityType entityType, final String propertyName,
|
||||
final boolean isCollection, final EdmType type) {
|
||||
EdmNavigationProperty property = mock(EdmNavigationProperty.class);
|
||||
entityType.getNavigationPropertyNames().add(propertyName);
|
||||
when(property.getName()).thenReturn(propertyName);
|
||||
when(entityType.getProperty(propertyName)).thenReturn(property);
|
||||
when(property.isCollection()).thenReturn(isCollection);
|
||||
when(property.getType()).thenReturn(type);
|
||||
}
|
||||
|
||||
private void addKeyProperty(final EdmEntityType entityType, final String propertyName) {
|
||||
entityType.getKeyPredicateNames().add(propertyName);
|
||||
EdmProperty keyProp = addProperty(entityType, propertyName, true, mock(EdmPrimitiveType.class));
|
||||
EdmKeyPropertyRef keyRef = mock(EdmKeyPropertyRef.class);
|
||||
when(keyRef.getKeyPropertyName()).thenReturn(propertyName);
|
||||
when(keyRef.getProperty()).thenReturn(keyProp);
|
||||
entityType.getKeyPropertyRefs().add(keyRef);
|
||||
when(entityType.getKeyPropertyRef(propertyName)).thenReturn(keyRef);
|
||||
}
|
||||
|
||||
private EdmProperty addProperty(final EdmStructuralType structuralType, final String propertyName,
|
||||
final boolean isPrimitive, final EdmType type) {
|
||||
EdmProperty property = mock(EdmProperty.class);
|
||||
when(property.getName()).thenReturn(propertyName);
|
||||
structuralType.getPropertyNames().add(propertyName);
|
||||
when(structuralType.getProperty(propertyName)).thenReturn(property);
|
||||
when(property.isPrimitive()).thenReturn(isPrimitive);
|
||||
when(property.getType()).thenReturn(type);
|
||||
return property;
|
||||
}
|
||||
|
||||
private void enhanceContainer1() {
|
||||
when(container1.getName()).thenReturn(CONTAINER_NAME.getName());
|
||||
when(container1.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
|
||||
when(container1.getEntitySet(EMPLOYEES_SET_NAME.getName())).thenReturn(employeesSet);
|
||||
when(container1.getEntitySet(MANAGERS_SET_NAME.getName())).thenReturn(managersSet);
|
||||
when(container1.getEntitySet(TEAMS_SET_NAME.getName())).thenReturn(teamsSet);
|
||||
when(container1.getSingleton(COMPANY_SINGLETON_NAME.getName())).thenReturn(company);
|
||||
when(container1.getActionImport(ACTION_IMPORT1_NAME.getName())).thenReturn(actionImport1);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT1_NAME.getName())).thenReturn(functionImport1);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName())).thenReturn(maximalAgeFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME.getName())).thenReturn(
|
||||
mostCommonLocationFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_ALL_USED_ROOMS_NAME.getName())).thenReturn(
|
||||
allUsedRoomIdsFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME.getName())).thenReturn(
|
||||
employeeSearchFunctionImport);
|
||||
when(container1.getFunctionImport(FUNCTION_IMPORT_ALL_LOCATIONS_NAME.getName())).thenReturn(
|
||||
allLocationsFunctionImport);
|
||||
|
||||
/*
|
||||
* when(container1.getElement(EMPLOYEES_SET_NAME.getName())).thenReturn(employeesSet);
|
||||
* when(container1.getElement(TEAMS_SET_NAME.getName())).thenReturn(teamsSet);
|
||||
* when(container1.getElement(COMPANY_SINGLETON_NAME.getName())).thenReturn(company);
|
||||
* when(container1.getElement(ACTION_IMPORT1_NAME.getName())).thenReturn(actionImport1);
|
||||
* when(container1.getElement(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName())).thenReturn(maximalAgeFunctionImport);
|
||||
*/
|
||||
}
|
||||
|
||||
private void enhanceActionImport1() {
|
||||
when(actionImport1.getName()).thenReturn(ACTION_IMPORT1_NAME.getName());
|
||||
when(actionImport1.getEntityContainer()).thenReturn(container1);
|
||||
when(actionImport1.getReturnedEntitySet()).thenReturn(employeesSet);
|
||||
when(actionImport1.getAction()).thenReturn(action1);
|
||||
}
|
||||
|
||||
private void enhanceFunctionImport1() {
|
||||
when(functionImport1.getName()).thenReturn(FUNCTION_IMPORT1_NAME.getName());
|
||||
when(functionImport1.getEntityContainer()).thenReturn(container1);
|
||||
when(functionImport1.getReturnedEntitySet()).thenReturn(teamsSet);
|
||||
when(functionImport1.getFunction(null)).thenReturn(function1);
|
||||
}
|
||||
|
||||
private void enhanceFunctionImportEmployeeSearch() {
|
||||
when(employeeSearchFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_EMPLOYEE_SEARCH_NAME.getName());
|
||||
when(employeeSearchFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(employeeSearchFunctionImport.getReturnedEntitySet()).thenReturn(teamsSet);
|
||||
when(employeeSearchFunctionImport.getFunction(null)).thenReturn(employeeSearchFunction);
|
||||
}
|
||||
|
||||
private void enhanceFunctionEmployeeSearch() {
|
||||
when(employeeSearchFunction.getName()).thenReturn(FUNCTION1_NAME.getName());
|
||||
when(employeeSearchFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(employeeSearchFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(employeeSearchFunction.getReturnType().getType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
private void enhanceMaximalAgeFunctionImport() {
|
||||
when(maximalAgeFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_MAXIMAL_AGE_NAME.getName());
|
||||
when(maximalAgeFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(maximalAgeFunctionImport.getFunction(null)).thenReturn(maximalAgeFunction);
|
||||
}
|
||||
|
||||
private void enhanceMaximalAgeFunction() {
|
||||
when(maximalAgeFunction.getName()).thenReturn(FUNCTION_MAXIMAL_AGE_NAME.getName());
|
||||
when(maximalAgeFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(maximalAgeFunction.getReturnType().isCollection()).thenReturn(false);
|
||||
when(maximalAgeFunction.getReturnType().getType()).thenReturn(mock(EdmPrimitiveType.class));
|
||||
|
||||
}
|
||||
|
||||
private void enhanceAllUsedRoomIdsFunctionImport() {
|
||||
when(allUsedRoomIdsFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_ALL_USED_ROOMS_NAME.getName());
|
||||
when(allUsedRoomIdsFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(allUsedRoomIdsFunctionImport.getFunction(null)).thenReturn(allUsedRoomIdsFunction);
|
||||
}
|
||||
|
||||
private void enhanceAllUsedRoomIdsFunction() {
|
||||
when(allUsedRoomIdsFunction.getName()).thenReturn(FUNCTION_ALL_USED_ROOMS_NAME.getName());
|
||||
when(allUsedRoomIdsFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(allUsedRoomIdsFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(allUsedRoomIdsFunction.getReturnType().getType()).thenReturn(mock(EdmPrimitiveType.class));
|
||||
|
||||
}
|
||||
|
||||
private void enhanceMostCommonLocationFunctionImport() {
|
||||
when(mostCommonLocationFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_MOST_COMMON_LOCATION_NAME.getName());
|
||||
when(mostCommonLocationFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(mostCommonLocationFunctionImport.getFunction(null)).thenReturn(mostCommonLocationFunction);
|
||||
}
|
||||
|
||||
private void enhanceMostCommonLocationFunction() {
|
||||
when(mostCommonLocationFunction.getName()).thenReturn(FUNCTION_MOST_COMMON_LOCATION_NAME.getName());
|
||||
when(mostCommonLocationFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(mostCommonLocationFunction.getReturnType().isCollection()).thenReturn(false);
|
||||
when(mostCommonLocationFunction.getReturnType().getType()).thenReturn(locationType);
|
||||
|
||||
}
|
||||
|
||||
private void enhanceAllLocationsFunctionImport() {
|
||||
when(allLocationsFunctionImport.getName()).thenReturn(FUNCTION_IMPORT_ALL_LOCATIONS_NAME.getName());
|
||||
when(allLocationsFunctionImport.getEntityContainer()).thenReturn(container1);
|
||||
when(allLocationsFunctionImport.getFunction(null)).thenReturn(allLocationsFunction);
|
||||
}
|
||||
|
||||
private void enhanceAllLocationsFunction() {
|
||||
when(allLocationsFunction.getName()).thenReturn(FUNCTION_ALL_LOCATIONS_NAME.getName());
|
||||
when(allLocationsFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(allLocationsFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(allLocationsFunction.getReturnType().getType()).thenReturn(locationType);
|
||||
|
||||
}
|
||||
|
||||
private void enhanceBoundEntityFunction() {
|
||||
when(boundFunctionEntitySetRtEntity.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME.getName());
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundFunctionEntitySetRtEntity.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionEntitySetRtEntity.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtEntity.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtEntitySet() {
|
||||
when(boundEntityColFunction.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundEntityColFunction.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundEntityColFunction.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundEntityColFunction.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundEntityColFunction.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundEntityColFunction.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionPPropRtEntitySet() {
|
||||
when(boundFunctionPPropRtEntitySet.getName()).thenReturn(BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionPPropRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionPPropRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionPPropRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtPProp() {
|
||||
when(boundFunctionEntitySetRtPProp.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME.getName());
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType().isCollection()).thenReturn(false);
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundFunctionEntitySetRtPProp.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundFunctionEntitySetRtPProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtPProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtPPropColl() {
|
||||
when(boundFunctionEntitySetRtPPropColl.getName())
|
||||
.thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME.getName());
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundFunctionEntitySetRtPPropColl.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundFunctionEntitySetRtPPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtPPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtCProp() {
|
||||
when(boundFunctionEntitySetRtCProp.getName()).thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME.getName());
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundFunctionEntitySetRtCProp.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundFunctionEntitySetRtCProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtCProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionEntitySetRtCPropColl() {
|
||||
when(boundFunctionEntitySetRtCPropColl.getName())
|
||||
.thenReturn(BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME.getName());
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionEntitySetRtCPropColl.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundFunctionEntitySetRtCPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionEntitySetRtCPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundFunctionSingletonRtEntitySet() {
|
||||
when(boundFunctionSingletonRtEntitySet.getName()).thenReturn(BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundFunctionSingletonRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundFunctionSingletonRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundFunctionSingletonRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionPPropRtEntitySet() {
|
||||
when(boundActionPpropRtEntitySet.getName()).thenReturn(BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME.getName());
|
||||
when(boundActionPpropRtEntitySet.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionPpropRtEntitySet.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundActionPpropRtEntitySet.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundActionPpropRtEntitySet.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionPpropRtEntitySet.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtEntity() {
|
||||
when(boundActionEntityRtEntity.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_ENTITY_NAME.getName());
|
||||
when(boundActionEntityRtEntity.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionEntityRtEntity.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntityRtEntity.getReturnType().getType()).thenReturn(employeeType);
|
||||
when(boundActionEntityRtEntity.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtEntity.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtPProp() {
|
||||
when(boundActionEntityRtPProp.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_PPROP_NAME.getName());
|
||||
when(boundActionEntityRtPProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundActionEntityRtPProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntityRtPProp.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundActionEntityRtPProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtPProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntityRtPPropColl() {
|
||||
when(boundActionEntityRtPPropColl.getName()).thenReturn(BOUND_ACTION_ENTITY_RT_PPROP_NAME.getName());
|
||||
when(boundActionEntityRtPPropColl.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
EdmPrimitiveType primitiveType = mock(EdmPrimitiveType.class);
|
||||
when(boundActionEntityRtPPropColl.getReturnType().isCollection()).thenReturn(true);
|
||||
when(boundActionEntityRtPPropColl.getReturnType().getType()).thenReturn(primitiveType);
|
||||
when(boundActionEntityRtPPropColl.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntityRtPPropColl.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceBoundActionEntitySetRtCProp() {
|
||||
when(boundActionEntitySetRtCProp.getName()).thenReturn(BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME.getName());
|
||||
when(boundActionEntitySetRtCProp.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(boundActionEntitySetRtCProp.getReturnType().isCollection()).thenReturn(false);
|
||||
when(boundActionEntitySetRtCProp.getReturnType().getType()).thenReturn(locationType);
|
||||
when(boundActionEntitySetRtCProp.getNamespace()).thenReturn(NAMESPACE_SCHEMA);
|
||||
when(boundActionEntitySetRtCProp.isBound()).thenReturn(true);
|
||||
}
|
||||
|
||||
private void enhanceFunction1() {
|
||||
when(function1.getName()).thenReturn(FUNCTION1_NAME.getName());
|
||||
when(function1.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(function1.getReturnType().isCollection()).thenReturn(false);
|
||||
when(function1.getReturnType().getType()).thenReturn(teamType);
|
||||
}
|
||||
|
||||
private void enhanceAction1() {
|
||||
when(action1.getReturnType()).thenReturn(mock(EdmReturnType.class));
|
||||
when(action1.getReturnType().isCollection()).thenReturn(false);
|
||||
when(action1.getReturnType().getType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
private void enhanceCompany() {
|
||||
when(company.getName()).thenReturn(COMPANY_SINGLETON_NAME.getName());
|
||||
when(company.getEntityContainer()).thenReturn(container1);
|
||||
when(company.getEntityType()).thenReturn(companyType);
|
||||
}
|
||||
|
||||
private void enhanceManagersEntitySet() {
|
||||
when(managersSet.getName()).thenReturn(MANAGERS_SET_NAME.getName());
|
||||
when(managersSet.getEntityContainer()).thenReturn(container1);
|
||||
when(managersSet.getEntityType()).thenReturn(managerType);
|
||||
}
|
||||
|
||||
private void enhanceTeamsEntitySet() {
|
||||
when(teamsSet.getName()).thenReturn(TEAMS_SET_NAME.getName());
|
||||
when(teamsSet.getEntityContainer()).thenReturn(container1);
|
||||
when(teamsSet.getEntityType()).thenReturn(teamType);
|
||||
}
|
||||
|
||||
private void enhanceEmployeesEntitySet() {
|
||||
when(employeesSet.getName()).thenReturn(EMPLOYEES_SET_NAME.getName());
|
||||
when(employeesSet.getEntityContainer()).thenReturn(container1);
|
||||
when(employeesSet.getEntityType()).thenReturn(employeeType);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityContainer getEntityContainer(final FullQualifiedName fqn) {
|
||||
|
||||
if (fqn == null || NAMESPACE_SCHEMA.equals(fqn.getNamespace()) && CONTAINER_NAME.equals(fqn.getName())) {
|
||||
return container1;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEnumType getEnumType(final FullQualifiedName fqn) {
|
||||
if (RATING_ENUM_TYPE_NAME.equals(fqn)) {
|
||||
return ratingEnumType;
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmTypeDefinition getTypeDefinition(final FullQualifiedName fqn) {
|
||||
if (TYPE_DEF1_NAME.equals(fqn)) {
|
||||
return typeDef1;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmEntityType getEntityType(final FullQualifiedName fqn) {
|
||||
if (NAMESPACE_SCHEMA.equals(fqn.getNamespace())) {
|
||||
if (EMPLOYEES_TYPE_NAME.equals(fqn)) {
|
||||
return employeeType;
|
||||
} else if (MANAGERS_TYPE_NAME.equals(fqn)) {
|
||||
return managerType;
|
||||
} else if (TEAMS_TYPE_NAME.equals(fqn)) {
|
||||
return teamType;
|
||||
} else if (COMPANY_TYPE_NAME.equals(fqn)) {
|
||||
return companyType;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmComplexType getComplexType(final FullQualifiedName fqn) {
|
||||
if (LOCATION_TYPE_NAME.equals(fqn)) {
|
||||
return locationType;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmServiceMetadata getServiceMetadata() {
|
||||
return mock(EdmServiceMetadata.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmAction getAction(final FullQualifiedName actionFqn, final FullQualifiedName bindingParameterTypeFqn,
|
||||
final Boolean isBindingParameterTypeCollection) {
|
||||
if (NAMESPACE_SCHEMA.equals(actionFqn.getNamespace())) {
|
||||
if (ACTION1_NAME.equals(actionFqn)) {
|
||||
return action1;
|
||||
} else if (BOUND_ACTION_PPROP_RT_ENTITY_SET_NAME.equals(actionFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionPpropRtEntitySet;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_ENTITY_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtEntity;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_PPROP_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtPProp;
|
||||
} else if (BOUND_ACTION_ENTITY_RT_PPROP_COLL_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntityRtPPropColl;
|
||||
} else if (BOUND_ACTION_ENTITY_SET_RT_CPROP_NAME.equals(actionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundActionEntitySetRtCProp;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public EdmFunction getFunction(final FullQualifiedName functionFqn,
|
||||
final FullQualifiedName bindingParameterTypeFqn,
|
||||
final Boolean isBindingParameterTypeCollection, final List<String> bindingParameterNames) {
|
||||
if (functionFqn != null) {
|
||||
if (NAMESPACE_SCHEMA.equals(functionFqn.getNamespace())) {
|
||||
if (FUNCTION1_NAME.equals(functionFqn)) {
|
||||
return function1;
|
||||
} else if (FUNCTION_ALL_LOCATIONS_NAME.equals(functionFqn)) {
|
||||
return allLocationsFunction;
|
||||
} else if (FUNCTION_EMPLOYEE_SEARCH_NAME.equals(functionFqn)) {
|
||||
return employeeSearchFunction;
|
||||
} else if (FUNCTION_MAXIMAL_AGE_NAME.equals(functionFqn)) {
|
||||
return maximalAgeFunction;
|
||||
} else if (FUNCTION_MOST_COMMON_LOCATION_NAME.equals(functionFqn)) {
|
||||
return mostCommonLocationFunction;
|
||||
} else if (FUNCTION_ALL_USED_ROOMS_NAME.equals(functionFqn)) {
|
||||
return allUsedRoomIdsFunction;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtEntity;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundEntityColFunction;
|
||||
} else if (BOUND_FUNCTION_PPROP_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionPPropRtEntitySet;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_PPROP_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtPProp;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_PPROP_COLL_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtPPropColl;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_CPROP_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtCProp;
|
||||
} else if (BOUND_FUNCTION_ENTITY_SET_RT_CPROP_COLL_NAME.equals(functionFqn)
|
||||
&& EMPLOYEES_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.TRUE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionEntitySetRtCPropColl;
|
||||
} else if (BOUND_FUNCTION_SINGLETON_RT_ENTITY_SET_NAME.equals(functionFqn)
|
||||
&& COMPANY_TYPE_NAME.equals(bindingParameterTypeFqn)
|
||||
&& Boolean.FALSE.equals(isBindingParameterTypeCollection)) {
|
||||
return boundFunctionSingletonRtEntitySet;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
}
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,89 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.testutil;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.EntitySet;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.Property;
|
||||
import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
|
||||
import org.apache.olingo.odata4.commons.api.exception.ODataException;
|
||||
|
||||
//Adds a abc entity set with properties a,b,c,d,e,f to the technical reference scenario
|
||||
public class EdmTechTestProvider extends EdmTechProvider {
|
||||
|
||||
public static final FullQualifiedName nameCTabc = new FullQualifiedName(nameSpace, "CTabc");
|
||||
|
||||
Property propertyAInt16 = new Property().setName("a").setType(nameInt16);
|
||||
Property propertyBInt16 = new Property().setName("b").setType(nameInt16);
|
||||
Property propertyCInt16 = new Property().setName("c").setType(nameInt16);
|
||||
Property propertyDInt16 = new Property().setName("d").setType(nameInt16);
|
||||
Property propertyEInt16 = new Property().setName("e").setType(nameInt16);
|
||||
Property propertyFInt16 = new Property().setName("f").setType(nameInt16);
|
||||
public static final FullQualifiedName nameETabc = new FullQualifiedName(nameSpace, "ETabc");
|
||||
|
||||
@Override
|
||||
public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
|
||||
if (complexTypeName.equals(nameCTabc)) {
|
||||
return new ComplexType()
|
||||
.setName("CTabc")
|
||||
.setProperties(Arrays.asList(
|
||||
propertyAInt16, propertyBInt16, propertyCInt16,
|
||||
propertyDInt16, propertyEInt16, propertyFInt16
|
||||
));
|
||||
|
||||
}
|
||||
|
||||
return super.getComplexType(complexTypeName);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String name) throws ODataException {
|
||||
if (entityContainer == nameContainer) {
|
||||
if (name.equals("ESabc")) {
|
||||
return new EntitySet()
|
||||
.setName("ESabc")
|
||||
.setType(nameETabc);
|
||||
}
|
||||
}
|
||||
|
||||
return super.getEntitySet(entityContainer, name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
|
||||
List<PropertyRef> oneKeyPropertyInt16 = Arrays.asList(new PropertyRef().setPropertyName("a"));
|
||||
|
||||
if (entityTypeName.equals(nameETabc)) {
|
||||
return new EntityType()
|
||||
.setName("ETabc")
|
||||
.setProperties(Arrays.asList(
|
||||
propertyAInt16, propertyBInt16, propertyCInt16,
|
||||
propertyDInt16, propertyEInt16, propertyFInt16))
|
||||
.setKey(oneKeyPropertyInt16);
|
||||
}
|
||||
|
||||
return super.getEntityType(entityTypeName);
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,87 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.testutil;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriInfoImplPath;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.ExceptionVisitExpression;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.ExpressionVisitor;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Literal;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Member;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.SupportedBinaryOperators;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.SupportedMethodCalls;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.SupportedUnaryOperators;
|
||||
|
||||
public class FilterTreeToText implements ExpressionVisitor<String> {
|
||||
|
||||
@Override
|
||||
public String visitBinaryOperator(SupportedBinaryOperators operator, String left, String right)
|
||||
throws ExceptionVisitExpression {
|
||||
return "<" + left + " " + operator.toString() + " " + right + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitUnaryOperator(SupportedUnaryOperators operator, String operand) throws ExceptionVisitExpression {
|
||||
return "<" + operator + " " + operand.toString() + ">";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitMethoCall(SupportedMethodCalls methodCall, List<String> parameters)
|
||||
throws ExceptionVisitExpression {
|
||||
String text = "<" + methodCall + "(";
|
||||
int i = 0;
|
||||
while (i< parameters.size()) {
|
||||
if (i > 0 ) {
|
||||
text +=",";
|
||||
}
|
||||
text += parameters.get(i);
|
||||
i++;
|
||||
}
|
||||
// TODO Auto-generated method stub
|
||||
return text + ")";
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public String visitLiteral(String literal) throws ExceptionVisitExpression {
|
||||
return "" + literal + "";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String visitMember(Member member) throws ExceptionVisitExpression {
|
||||
String ret = "";
|
||||
if (member.isIT()) {
|
||||
ret += "$it";
|
||||
}
|
||||
|
||||
UriInfoImplPath path = member.getPath();
|
||||
if (path!= null) {
|
||||
/*if (member.isIT()) {
|
||||
ret +="/";
|
||||
}*/
|
||||
|
||||
ret += path.toString();
|
||||
|
||||
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,69 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.testutil;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriInfoImplPath;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.ExceptionVisitExpression;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Expression;
|
||||
|
||||
public class FilterValidator {
|
||||
|
||||
UriResourcePathValidator uriResourcePathValidator;
|
||||
Expression filterTree;
|
||||
|
||||
public FilterValidator(UriResourcePathValidator uriResourcePathValidator) {
|
||||
|
||||
this.uriResourcePathValidator = uriResourcePathValidator;
|
||||
|
||||
filterTree = ((UriInfoImplPath) uriResourcePathValidator.uriInfo).getFilter();
|
||||
if (filterTree == null) {
|
||||
fail("FilterValidator: no filter found");
|
||||
}
|
||||
return;
|
||||
}
|
||||
|
||||
// Validates the serialized filterTree against a given filterString
|
||||
// The given filterString is compressed before to allow better readable code in the unit tests
|
||||
public FilterValidator isCompr(String toBeCompr) {
|
||||
return is(compress(toBeCompr));
|
||||
}
|
||||
|
||||
public FilterValidator is(String expectedFilterAsString) {
|
||||
try {
|
||||
String actualFilterAsText = filterTree.accept(new FilterTreeToText());
|
||||
assertEquals(expectedFilterAsString, actualFilterAsText);
|
||||
} catch (ExceptionVisitExpression e) {
|
||||
fail("Exception occured while converting the filterTree into text" + "\n"
|
||||
+ " Exception: " + e.getMessage());
|
||||
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
private String compress(String expected) {
|
||||
String ret = expected.replaceAll("\\s+", " ");
|
||||
ret = ret.replaceAll("< ", "<");
|
||||
ret = ret.replaceAll(" >", ">");
|
||||
return ret;
|
||||
}
|
||||
}
|
|
@ -30,7 +30,7 @@ import org.antlr.v4.runtime.tree.RuleNode;
|
|||
import org.antlr.v4.runtime.tree.TerminalNode;
|
||||
import org.antlr.v4.runtime.tree.Tree;
|
||||
|
||||
public class ParseTreeSerializer {
|
||||
public class ParseTreeToText {
|
||||
|
||||
public static String getTreeAsText(final Tree contextTree, final String[] ruleNames) {
|
||||
return toStringTree(contextTree, Arrays.asList(ruleNames));
|
|
@ -44,93 +44,35 @@ import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
|
|||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
|
||||
|
||||
/**
|
||||
* @author d039346
|
||||
*
|
||||
*/
|
||||
// TODO extend to test also exception which can occure while paring
|
||||
public class ParserValidator {
|
||||
public class UriLexerTrace extends UriLexer {
|
||||
ParserValidator parserValidator = null;
|
||||
|
||||
public UriLexerTrace(final ParserValidator parserValidator, final ANTLRInputStream antlrInputStream) {
|
||||
super(antlrInputStream);
|
||||
this.parserValidator = parserValidator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public Token emit() {
|
||||
Token t =
|
||||
_factory.create(_tokenFactorySourcePair, _type, _text, _channel, _tokenStartCharIndex, getCharIndex() - 1,
|
||||
_tokenStartLine, _tokenStartCharPositionInLine);
|
||||
|
||||
if (parserValidator.logLevel > 1) {
|
||||
String out = String.format("%1$-" + 20 + "s", t.getText());
|
||||
;
|
||||
int tokenType = t.getType();
|
||||
if (tokenType == -1) {
|
||||
out += "-1/EOF";
|
||||
} else {
|
||||
out += UriLexer.tokenNames[tokenType];
|
||||
}
|
||||
System.out.println(out);
|
||||
}
|
||||
emit(t);
|
||||
|
||||
return t;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMode(final int m) {
|
||||
String out = UriLexer.modeNames[_mode] + "-->";
|
||||
super.pushMode(m);
|
||||
out += UriLexer.modeNames[_mode];
|
||||
if (parserValidator.logLevel > 1) {
|
||||
System.out.print(out + " ");
|
||||
}
|
||||
;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int popMode() {
|
||||
String out = UriLexer.modeNames[_mode] + "-->";
|
||||
int m = super.popMode();
|
||||
out += UriLexer.modeNames[_mode];
|
||||
|
||||
if (parserValidator.logLevel > 1) {
|
||||
System.out.print(out + " ");
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
private List<Exception> exceptions = new ArrayList<Exception>();
|
||||
private ParserRuleContext root;
|
||||
|
||||
private String input = null;
|
||||
// private int exceptionOnStage = -1;
|
||||
private Exception curException = null;
|
||||
// private int exceptionOnStage = -1;
|
||||
// private Exception curWeakException = null;
|
||||
private boolean allowFullContext;
|
||||
private boolean allowContextSensitifity;
|
||||
private boolean allowAmbiguity;
|
||||
private int logLevel = 0;
|
||||
public int logLevel = 0;
|
||||
private int lexerLogLevel = 0;
|
||||
|
||||
// private int lexerLogLevel = 0;
|
||||
|
||||
public ParserValidator run(final String uri) {
|
||||
input = uri;
|
||||
// just run a short lexer step. E.g. to print the tokens
|
||||
if (lexerLogLevel > 0) {
|
||||
(new TokenValidator()).log(lexerLogLevel).run(input);
|
||||
(new TokenValidator()).setLog(lexerLogLevel).run(input);
|
||||
}
|
||||
root = parseInput(uri);
|
||||
// LOG > 0 - Write serialized tree
|
||||
if (logLevel > 0) {
|
||||
if (root != null) {
|
||||
System.out.println(ParseTreeSerializer.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
|
||||
System.out.println(ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
|
||||
} else {
|
||||
System.out.println("root == null");
|
||||
}
|
||||
|
@ -152,8 +94,9 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO verify
|
||||
* Used in fast LL Parsing:
|
||||
* Don't stops the parsing process when the slower full context parsing (with prediction mode SLL) is
|
||||
* Don't stop the parsing process when the slower full context parsing (with prediction mode SLL) is
|
||||
* required
|
||||
* @return
|
||||
*/
|
||||
|
@ -163,6 +106,7 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO verify
|
||||
* Used in fast LL Parsing:
|
||||
* Allows ContextSensitifity Errors which occur often when using the slower full context parsing
|
||||
* and indicate that there is a context sensitivity ( which may not be an error).
|
||||
|
@ -174,6 +118,7 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
/**
|
||||
* TODO verify
|
||||
* Used in fast LL Parsing:
|
||||
* Allows ambiguities
|
||||
* @return
|
||||
|
@ -184,23 +129,25 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
public ParserValidator isText(final String expected) {
|
||||
// make sure that there are no exceptions
|
||||
|
||||
assertEquals(null, curException);
|
||||
|
||||
assertEquals(0, exceptions.size());
|
||||
|
||||
String text = ParseTreeSerializer.getTreeAsText(root, new UriParserParser(null).getRuleNames());
|
||||
String text = ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames());
|
||||
|
||||
assertEquals(expected, text);
|
||||
return this;
|
||||
}
|
||||
|
||||
public ParserValidator isExType(final Class<?> exClass) {
|
||||
public ParserValidator isExeptionType(final Class<?> exClass) {
|
||||
assertEquals(exClass, curException.getClass());
|
||||
return this;
|
||||
}
|
||||
|
||||
private OdataRelativeUriEOFContext parseInput(final String input) {
|
||||
UriParserParser parser = null;
|
||||
UriLexer lexer = null;
|
||||
UriLexerWithTrace lexer = null;
|
||||
OdataRelativeUriEOFContext ret = null;
|
||||
|
||||
// Use 2 stage approach to improve performance
|
||||
|
@ -212,38 +159,42 @@ public class ParserValidator {
|
|||
curException = null;
|
||||
exceptions.clear();
|
||||
// create parser
|
||||
lexer = new UriLexerTrace(this, new ANTLRInputStream(input));
|
||||
lexer = new UriLexerWithTrace( new ANTLRInputStream(input), this.lexerLogLevel);
|
||||
parser = new UriParserParser(new CommonTokenStream(lexer));
|
||||
|
||||
// write single tokens to System.out
|
||||
if (logLevel > 1) {
|
||||
// can not be used because the listener is called bevore the mode changes
|
||||
// can not be used because the listener is called before the mode changes
|
||||
// TODO verify this
|
||||
parser.addParseListener(new TokenWriter());
|
||||
}
|
||||
// write always a error message in case of syntax errors
|
||||
//parser.addErrorListener(new TestErrorHandler<Object>());
|
||||
// parser.addErrorListener(new TestErrorHandler<Object>());
|
||||
// check error message if whether they are allowed or not
|
||||
parser.addErrorListener(new ErrorCollector(this));
|
||||
|
||||
// Bail out of parser at first syntax error. --> procceds in catch block with step 2
|
||||
// bail out of parser at first syntax error. --> proceed in catch block with step 2
|
||||
parser.setErrorHandler(new BailErrorStrategy());
|
||||
|
||||
// User the faster LL parsing
|
||||
// user the faster LL parsing
|
||||
parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
|
||||
|
||||
// parse
|
||||
if (logLevel > 1) {
|
||||
System.out.println("Step 1 (LL)");
|
||||
System.out.println("Step 1");
|
||||
System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode() + ")");
|
||||
}
|
||||
ret = parser.odataRelativeUriEOF();
|
||||
|
||||
} catch (Exception ex) {
|
||||
curException = ex;
|
||||
} catch (Exception exception) {
|
||||
curException = exception;
|
||||
try {
|
||||
// clear status
|
||||
curException = null;
|
||||
exceptions.clear();
|
||||
|
||||
// create parser
|
||||
lexer = new UriLexerTrace(this, new ANTLRInputStream(input));
|
||||
lexer = new UriLexerWithTrace(new ANTLRInputStream(input), this.lexerLogLevel);
|
||||
parser = new UriParserParser(new CommonTokenStream(lexer));
|
||||
|
||||
// write single tokens to System.out
|
||||
|
@ -252,7 +203,7 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
// write always a error message in case of syntax errors
|
||||
parser.addErrorListener(new TestErrorHandler<Object>());
|
||||
parser.addErrorListener(new ErrorCollector(this));
|
||||
// check error message if whether they are allowed or not
|
||||
parser.addErrorListener(new ErrorCollector(this));
|
||||
|
||||
|
@ -262,13 +213,15 @@ public class ParserValidator {
|
|||
// User the slower SLL parsing
|
||||
parser.getInterpreter().setPredictionMode(PredictionMode.LL);
|
||||
|
||||
// parse
|
||||
if (logLevel > 1) {
|
||||
System.out.println("Step 2 (SLL)");
|
||||
System.out.println("Step 2");
|
||||
System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode() + ")");
|
||||
}
|
||||
ret = parser.odataRelativeUriEOF();
|
||||
|
||||
} catch (Exception ex1) {
|
||||
curException = ex1;
|
||||
} catch (Exception exception1) {
|
||||
curException = exception1;
|
||||
// exceptionOnStage = 2;
|
||||
}
|
||||
}
|
||||
|
@ -277,7 +230,7 @@ public class ParserValidator {
|
|||
}
|
||||
|
||||
private static class ErrorCollector implements ANTLRErrorListener {
|
||||
ParserValidator tokenValidator;
|
||||
private ParserValidator tokenValidator;
|
||||
|
||||
public ErrorCollector(final ParserValidator tokenValidator) {
|
||||
this.tokenValidator = tokenValidator;
|
||||
|
@ -288,7 +241,10 @@ public class ParserValidator {
|
|||
final int charPositionInLine,
|
||||
final String msg, final RecognitionException e) {
|
||||
|
||||
// Collect the exception
|
||||
// TODO needs to be improved
|
||||
tokenValidator.exceptions.add(e);
|
||||
System.out.println("syntaxError");
|
||||
trace(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
|
||||
|
||||
fail("syntaxError");
|
||||
|
@ -299,16 +255,16 @@ public class ParserValidator {
|
|||
final boolean exact,
|
||||
final BitSet ambigAlts, final ATNConfigSet configs) {
|
||||
|
||||
if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("reportAmbiguity: ");
|
||||
System.out.println(" ambigAlts: " + ambigAlts);
|
||||
System.out.println(" configs: " + configs);
|
||||
System.out.println(" input: " + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
|
||||
}
|
||||
|
||||
if (!tokenValidator.allowAmbiguity) {
|
||||
System.out.println("reportAmbiguity " +
|
||||
ambigAlts + ":" + configs +
|
||||
", input=" + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
|
||||
printStack(recognizer);
|
||||
fail("reportAmbiguity");
|
||||
} else if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("allowed Ambiguity " +
|
||||
ambigAlts + ":" + configs +
|
||||
", input=" + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -316,14 +272,16 @@ public class ParserValidator {
|
|||
public void reportAttemptingFullContext(final Parser recognizer, final DFA dfa, final int startIndex,
|
||||
final int stopIndex,
|
||||
final BitSet conflictingAlts, final ATNConfigSet configs) {
|
||||
|
||||
// The grammar should be written in order to avoid attempting a full context parse because its negative
|
||||
// impact on the performance, so trace and stop here
|
||||
if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("allowed AttemptingFullContext");
|
||||
}
|
||||
|
||||
if (!tokenValidator.allowFullContext) {
|
||||
printStack(recognizer);
|
||||
fail("reportAttemptingFullContext");
|
||||
} else if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("allowed AttemptingFullContext");
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -331,41 +289,52 @@ public class ParserValidator {
|
|||
public void reportContextSensitivity(final Parser recognizer, final DFA dfa, final int startIndex,
|
||||
final int stopIndex, final int prediction,
|
||||
final ATNConfigSet configs) {
|
||||
|
||||
if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("allowed ContextSensitivity");
|
||||
}
|
||||
|
||||
if (!tokenValidator.allowContextSensitifity) {
|
||||
printStack(recognizer);
|
||||
fail("reportContextSensitivity");
|
||||
} else if (tokenValidator.logLevel > 0) {
|
||||
System.out.println("allowed ContextSensitivity");
|
||||
}
|
||||
}
|
||||
|
||||
private void printStack(final Parser recognizer) {
|
||||
/*
|
||||
* private void printStack(final Parser recognizer) {
|
||||
* List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
|
||||
* Collections.reverse(stack);
|
||||
*
|
||||
* System.out.println(" Rule stack: " + stack);
|
||||
* }
|
||||
*/
|
||||
private void printStack(final Recognizer<?, ?> recognizer) {
|
||||
List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
|
||||
Collections.reverse(stack);
|
||||
|
||||
System.out.println("rule stack: " + stack);
|
||||
System.out.println(" rule stack: " + stack);
|
||||
}
|
||||
|
||||
public void trace(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
|
||||
final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
|
||||
|
||||
System.err.println("-");
|
||||
// check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
|
||||
List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
|
||||
Collections.reverse(stack);
|
||||
System.err.println("rule stack: " + stack);
|
||||
// TODO check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
|
||||
|
||||
printStack(recognizer);
|
||||
|
||||
if (e != null && e.getOffendingToken() != null) {
|
||||
|
||||
// String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
//String lexerTokenName = TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
String lexerTokenName = "";
|
||||
try {
|
||||
lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
} catch (ArrayIndexOutOfBoundsException es) {
|
||||
lexerTokenName = "token error";
|
||||
}
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " +
|
||||
System.err.println(" line " + line + ":" + charPositionInLine + " at " +
|
||||
offendingSymbol + "/" + lexerTokenName + ": " + msg);
|
||||
} else {
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
|
||||
System.err.println(" line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -1,56 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
package org.apache.olingo.odata4.producer.core.testutil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
import org.antlr.v4.runtime.BaseErrorListener;
|
||||
import org.antlr.v4.runtime.Parser;
|
||||
import org.antlr.v4.runtime.RecognitionException;
|
||||
import org.antlr.v4.runtime.Recognizer;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
|
||||
|
||||
public class TestErrorHandler<T> extends BaseErrorListener {
|
||||
@Override
|
||||
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
|
||||
final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
|
||||
System.err.println("-");
|
||||
// check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
|
||||
List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
|
||||
Collections.reverse(stack);
|
||||
System.err.println("rule stack: " + stack);
|
||||
if (e != null && e.getOffendingToken() != null) {
|
||||
|
||||
// String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
String lexerTokenName = "";
|
||||
try {
|
||||
lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
} catch (ArrayIndexOutOfBoundsException es) {
|
||||
lexerTokenName = "token error";
|
||||
}
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " +
|
||||
offendingSymbol + "/" + lexerTokenName + ": " + msg);
|
||||
} else {
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -36,6 +36,7 @@ import org.antlr.v4.runtime.atn.ATNConfigSet;
|
|||
import org.antlr.v4.runtime.dfa.DFA;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
|
||||
|
||||
//TODO extend to test also exception which can occure while paring
|
||||
public class TokenValidator {
|
||||
private List<? extends Token> tokens = null;
|
||||
private List<Exception> exceptions = new ArrayList<Exception>();
|
||||
|
@ -43,7 +44,6 @@ public class TokenValidator {
|
|||
private Exception curException = null;
|
||||
private String input = null;
|
||||
private int logLevel = 0;
|
||||
|
||||
private int mode;
|
||||
|
||||
public TokenValidator run(final String uri) {
|
||||
|
@ -82,62 +82,20 @@ public class TokenValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator log(final int logLevel) {
|
||||
public TokenValidator setLog(final int logLevel) {
|
||||
this.logLevel = logLevel;
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isText(final String expected) {
|
||||
assertEquals(expected, curToken.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isAllText(final String expected) {
|
||||
String tmp = "";
|
||||
|
||||
for (Token curToken : tokens) {
|
||||
tmp += curToken.getText();
|
||||
}
|
||||
assertEquals(expected, tmp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isAllInput() {
|
||||
String tmp = "";
|
||||
|
||||
for (Token curToken : tokens) {
|
||||
tmp += curToken.getText();
|
||||
}
|
||||
assertEquals(input, tmp);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isInput() {
|
||||
assertEquals(input, curToken.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isType(final int expected) {
|
||||
// assertEquals(UriLexer.tokenNames[expected], UriLexer.tokenNames[curToken.getType()]);
|
||||
assertEquals(UriLexer.tokenNames[expected], UriLexer.tokenNames[curToken.getType()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isExType(final Class<?> exClass) {
|
||||
assertEquals(exClass, curException.getClass());
|
||||
return this;
|
||||
}
|
||||
|
||||
private List<? extends Token> parseInput(final String input) {
|
||||
ANTLRInputStream inputStream = new ANTLRInputStream(input);
|
||||
|
||||
UriLexer lexer = new TestUriLexer(this, inputStream, mode);
|
||||
// lexer.setInSearch(searchMode);
|
||||
// lexer.removeErrorListeners();
|
||||
UriLexer lexer = new UriLexerWithTrace(inputStream, logLevel, mode);
|
||||
lexer.addErrorListener(new ErrorCollector(this));
|
||||
return lexer.getAllTokens();
|
||||
}
|
||||
|
||||
// navigate within the tokenlist
|
||||
public TokenValidator first() {
|
||||
try {
|
||||
curToken = tokens.get(0);
|
||||
|
@ -147,26 +105,11 @@ public class TokenValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator exFirst() {
|
||||
try {
|
||||
curException = exceptions.get(0);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
curException = null;
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public TokenValidator last() {
|
||||
curToken = tokens.get(tokens.size() - 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator exLast() {
|
||||
curException = exceptions.get(exceptions.size() - 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator at(final int index) {
|
||||
try {
|
||||
curToken = tokens.get(index);
|
||||
|
@ -176,6 +119,22 @@ public class TokenValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator exLast() {
|
||||
curException = exceptions.get(exceptions.size() - 1);
|
||||
return this;
|
||||
}
|
||||
|
||||
// navigate within the exception list
|
||||
public TokenValidator exFirst() {
|
||||
try {
|
||||
curException = exceptions.get(0);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
curException = null;
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public TokenValidator exAt(final int index) {
|
||||
try {
|
||||
curException = exceptions.get(index);
|
||||
|
@ -185,36 +144,48 @@ public class TokenValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
private static class TestUriLexer extends UriLexer {
|
||||
private TokenValidator validator;
|
||||
|
||||
public TestUriLexer(final TokenValidator validator, final CharStream input, final int mode) {
|
||||
super(input);
|
||||
super.mode(mode);
|
||||
this.validator = validator;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMode(final int m) {
|
||||
if (validator.logLevel > 0) {
|
||||
System.out.println("OnMode" + ": " + UriLexer.modeNames[m]);
|
||||
}
|
||||
super.pushMode(m);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public int popMode() {
|
||||
int m = super.popMode();
|
||||
if (validator.logLevel > 0) {
|
||||
System.out.println("OnMode" + ": " + UriLexer.modeNames[m]);
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
|
||||
// test functions
|
||||
public TokenValidator isText(final String expected) {
|
||||
assertEquals(expected, curToken.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isAllText(final String expected) {
|
||||
String actual = "";
|
||||
|
||||
for (Token curToken : tokens) {
|
||||
actual += curToken.getText();
|
||||
}
|
||||
assertEquals(expected, actual);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isAllInput() {
|
||||
String actual = "";
|
||||
|
||||
for (Token curToken : tokens) {
|
||||
actual += curToken.getText();
|
||||
}
|
||||
assertEquals(input, actual);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isInput() {
|
||||
assertEquals(input, curToken.getText());
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isType(final int expected) {
|
||||
assertEquals(UriLexer.tokenNames[expected], UriLexer.tokenNames[curToken.getType()]);
|
||||
return this;
|
||||
}
|
||||
|
||||
public TokenValidator isExType(final Class<?> exClass) {
|
||||
assertEquals(exClass, curException.getClass());
|
||||
return this;
|
||||
}
|
||||
|
||||
// TODO create ErrorCollector for both ParserValidator and LexerValidator
|
||||
private static class ErrorCollector implements ANTLRErrorListener {
|
||||
TokenValidator tokenValidator;
|
||||
|
||||
|
|
|
@ -1,54 +0,0 @@
|
|||
/*******************************************************************************
|
||||
* Licensed to the Apache Software Foundation (ASF) under one
|
||||
* or more contributor license agreements. See the NOTICE file
|
||||
* distributed with this work for additional information
|
||||
* regarding copyright ownership. The ASF licenses this file
|
||||
* to you under the Apache License, Version 2.0 (the
|
||||
* "License"); you may not use this file except in compliance
|
||||
* with the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing,
|
||||
* software distributed under the License is distributed on an
|
||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
||||
* KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations
|
||||
* under the License.
|
||||
******************************************************************************/
|
||||
package org.apache.olingo.odata4.producer.core.testutil;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import org.antlr.v4.runtime.BaseErrorListener;
|
||||
import org.antlr.v4.runtime.Parser;
|
||||
import org.antlr.v4.runtime.RecognitionException;
|
||||
import org.antlr.v4.runtime.Recognizer;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
|
||||
|
||||
public class TraceErrorHandler<T> extends BaseErrorListener {
|
||||
@Override
|
||||
public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
|
||||
final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
|
||||
System.err.println("-");
|
||||
// check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
|
||||
List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
|
||||
Collections.reverse(stack);
|
||||
System.err.println("rule stack: " + stack);
|
||||
if (e != null && e.getOffendingToken() != null) {
|
||||
|
||||
// String lexerTokenName =TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
String lexerTokenName = "";
|
||||
try {
|
||||
lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
|
||||
} catch (ArrayIndexOutOfBoundsException es) {
|
||||
lexerTokenName = "token error";
|
||||
}
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " +
|
||||
offendingSymbol + "/" + lexerTokenName + ": " + msg);
|
||||
} else {
|
||||
System.err.println("line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
|
||||
}
|
||||
}
|
||||
}
|
|
@ -0,0 +1,86 @@
|
|||
/*******************************************************************************
|
||||
* 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.producer.core.testutil;
|
||||
|
||||
import org.antlr.v4.runtime.ANTLRInputStream;
|
||||
import org.antlr.v4.runtime.Token;
|
||||
import org.apache.olingo.odata4.producer.core.uri.antlr.UriLexer;
|
||||
|
||||
public class UriLexerWithTrace extends UriLexer{
|
||||
int logLevel = 0;
|
||||
|
||||
|
||||
public UriLexerWithTrace( final ANTLRInputStream antlrInputStream, int logLevel) {
|
||||
super(antlrInputStream);
|
||||
this.logLevel = logLevel;
|
||||
}
|
||||
|
||||
public UriLexerWithTrace( final ANTLRInputStream antlrInputStream, int logLevel, final int mode) {
|
||||
super(antlrInputStream);
|
||||
super.mode(mode);
|
||||
this.logLevel = logLevel;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void emit(Token token) {
|
||||
if (logLevel > 1) {
|
||||
String out = String.format("%1$-" + 20 + "s", token.getText());
|
||||
|
||||
int tokenType = token.getType();
|
||||
if (tokenType == -1) {
|
||||
out += "-1/EOF";
|
||||
} else {
|
||||
out += UriLexer.tokenNames[tokenType];
|
||||
}
|
||||
System.out.println("Lexer.emit(...):" + out);
|
||||
}
|
||||
|
||||
super.emit(token);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void pushMode(final int m) {
|
||||
|
||||
String out = UriLexer.modeNames[_mode] + "-->";
|
||||
|
||||
super.pushMode(m);
|
||||
|
||||
out += UriLexer.modeNames[_mode];
|
||||
|
||||
if (logLevel > 1) {
|
||||
System.out.print(out + " ");
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public int popMode() {
|
||||
|
||||
String out = UriLexer.modeNames[_mode] + "-->";
|
||||
|
||||
int m = super.popMode();
|
||||
|
||||
out += UriLexer.modeNames[_mode];
|
||||
|
||||
if (logLevel > 1) {
|
||||
System.out.print(out + " ");
|
||||
}
|
||||
|
||||
return m;
|
||||
}
|
||||
}
|
|
@ -24,17 +24,7 @@ import static org.junit.Assert.fail;
|
|||
|
||||
import java.util.List;
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.Edm;
|
||||
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.EdmType;
|
||||
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
|
||||
|
@ -47,37 +37,64 @@ import org.apache.olingo.odata4.producer.core.uri.UriParserException;
|
|||
import org.apache.olingo.odata4.producer.core.uri.UriParserImpl;
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriPathInfoImpl;
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriPathInfoEntitySetImpl;
|
||||
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.ExceptionVisitExpression;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Expression;
|
||||
|
||||
public class UriResourcePathValidator {
|
||||
private Edm edm;
|
||||
private UriInfoImpl uriInfo = null;
|
||||
// this validator can only be used on resourcePaths
|
||||
public UriInfoImplPath uriInfo = null;
|
||||
private UriPathInfoImpl uriPathInfo = null;
|
||||
|
||||
public UriResourcePathValidator run(String uri) {
|
||||
UriInfoImpl uriInfoTmp = null;
|
||||
uriPathInfo = null;
|
||||
try {
|
||||
uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
|
||||
} catch (UriParserException e) {
|
||||
fail("Exception occured while parsing the URI: " + uri + "\n"
|
||||
+ " Exception: " + e.getMessage());
|
||||
}
|
||||
|
||||
if (!(uriInfoTmp instanceof UriInfoImplPath)) {
|
||||
fail("Validator can only be used on resourcePaths");
|
||||
}
|
||||
this.uriInfo = (UriInfoImplPath) uriInfoTmp;
|
||||
|
||||
last();
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
// short cut which avoid adding the ESabc?$filter when testing filter to each URI
|
||||
public FilterValidator runFilter(String filter) {
|
||||
String uri = "ESabc?$filter=" + filter.trim(); // TODO check what to do with trailing spaces in the URI
|
||||
this.run(uri);
|
||||
return new FilterValidator(this);
|
||||
}
|
||||
|
||||
public UriResourcePathValidator setEdm(final Edm edm) {
|
||||
this.edm = edm;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public UriResourcePathValidator run(String uri) {
|
||||
// navigation for uriPathInfo
|
||||
public UriResourcePathValidator at(int index) {
|
||||
try {
|
||||
uriInfo = new UriParserImpl(edm).ParseUri(uri);
|
||||
} catch (UriParserException e) {
|
||||
fail("Exception occured");
|
||||
uriPathInfo = uriInfo.getUriPathInfo(index);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
uriPathInfo = null;
|
||||
}
|
||||
|
||||
uriPathInfo = null;
|
||||
if (uriInfo instanceof UriInfoImplPath) {
|
||||
last();
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isUriPathInfoKind(UriPathInfoKind infoType) {
|
||||
|
||||
assertNotNull(uriPathInfo);
|
||||
assertEquals(infoType, uriPathInfo.getKind());
|
||||
public UriResourcePathValidator first() {
|
||||
try {
|
||||
uriPathInfo = ((UriInfoImplPath) uriInfo).getUriPathInfo(0);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
uriPathInfo = null;
|
||||
}
|
||||
return this;
|
||||
}
|
||||
|
||||
|
@ -91,79 +108,107 @@ public class UriResourcePathValidator {
|
|||
return this;
|
||||
}
|
||||
|
||||
// check types
|
||||
|
||||
public UriResourcePathValidator at(int index) {
|
||||
if (uriInfo instanceof UriInfoImplPath) {
|
||||
try {
|
||||
uriPathInfo = ((UriInfoImplPath) uriInfo).getUriPathInfo(index);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
uriPathInfo = null;
|
||||
}
|
||||
} else {
|
||||
fail("UriInfo not instanceof UriInfoImplPath");
|
||||
|
||||
public UriResourcePathValidator isInitialType(FullQualifiedName expectedType) {
|
||||
EdmType actualType = uriPathInfo.getInitialType();
|
||||
if (actualType == null) {
|
||||
fail("isInitialType: actualType == null");
|
||||
}
|
||||
|
||||
FullQualifiedName actualTypeName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
|
||||
assertEquals(expectedType.toString(), actualTypeName.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator first() {
|
||||
if (uriInfo instanceof UriInfoImplPath) {
|
||||
try {
|
||||
uriPathInfo = ((UriInfoImplPath) uriInfo).getUriPathInfo(0);
|
||||
} catch (IndexOutOfBoundsException ex) {
|
||||
uriPathInfo = null;
|
||||
}
|
||||
} else {
|
||||
fail("UriInfo not instanceof UriInfoImplPath");
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* blic void isKind(UriInfoKind batch) {
|
||||
* // TODO assertEquals(batch, uriInfo.getKind());
|
||||
* }
|
||||
*/
|
||||
public UriResourcePathValidator isKeyPredicate(int index, String name, String value) {
|
||||
if (uriPathInfo instanceof UriPathInfoEntitySetImpl) {
|
||||
UriPathInfoEntitySetImpl info = (UriPathInfoEntitySetImpl) uriPathInfo;
|
||||
UriKeyPredicateList keyPredicates = info.getKeyPredicates();
|
||||
assertEquals(name, keyPredicates.getName(index));
|
||||
assertEquals(value, keyPredicates.getValue(index));
|
||||
}
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isType(FullQualifiedName type) {
|
||||
EdmType actualType = uriPathInfo.getType();
|
||||
if (actualType == null ) {
|
||||
if (actualType == null) {
|
||||
fail("type information not set");
|
||||
}
|
||||
assertEquals(type, new FullQualifiedName(actualType.getNamespace(), actualType.getName()));
|
||||
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
|
||||
assertEquals(type.toString(), actualName.toString());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
public UriResourcePathValidator isSingleTypeFilter(FullQualifiedName type) {
|
||||
// input parameter type may be null in order to assert that the singleTypeFilter is not set
|
||||
EdmType actualType = uriPathInfo.getSingleTypeFilter();
|
||||
if (type == null) {
|
||||
assertEquals(type, actualType);
|
||||
} else {
|
||||
assertEquals(type.toString(), new FullQualifiedName(actualType.getNamespace(), actualType.getName()).toString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isCollectionTypeFilter(FullQualifiedName expectedType) {
|
||||
// input parameter type may be null in order to assert that the collectionTypeFilter is not set
|
||||
EdmType actualType = uriPathInfo.getCollectionTypeFilter();
|
||||
if (expectedType == null) {
|
||||
assertEquals(expectedType, actualType);
|
||||
} else {
|
||||
FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
|
||||
assertEquals(expectedType.toString(), actualName.toString());
|
||||
}
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
// other functions
|
||||
public UriResourcePathValidator hasQueryParameter(String parameter, int count) {
|
||||
if (uriInfo == null) {
|
||||
fail("hasQueryParameter: uriInfo == null");
|
||||
}
|
||||
|
||||
int actualCount = uriInfo.getQueryParameters(parameter).size();
|
||||
assertEquals(count, actualCount);
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isCollection(boolean isCollection) {
|
||||
EdmType actualType = uriPathInfo.getType();
|
||||
if (actualType == null ) {
|
||||
fail("type information not set");
|
||||
EdmType type = uriPathInfo.getType();
|
||||
if (type == null) {
|
||||
fail("isCollection: type == null");
|
||||
}
|
||||
assertEquals(isCollection, uriPathInfo.isCollection());
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isInitialType(FullQualifiedName type) {
|
||||
EdmType actualType = uriPathInfo.getInitialType();
|
||||
if (actualType == null ) {
|
||||
fail("type information not set");
|
||||
|
||||
public UriResourcePathValidator isFilterString(String expectedFilterTreeAsString) {
|
||||
Expression filterTree = this.uriInfo.getFilter();
|
||||
try {
|
||||
String filterTreeAsString = filterTree.accept(new FilterTreeToText());
|
||||
assertEquals(expectedFilterTreeAsString, filterTreeAsString);
|
||||
} catch (ExceptionVisitExpression e) {
|
||||
fail("isFilterString: Exception " + e.getMessage() + " occured");
|
||||
}
|
||||
assertEquals(type, new FullQualifiedName(actualType.getNamespace(), actualType.getName()));
|
||||
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isKeyPredicate(int index, String name, String value) {
|
||||
if (!(uriPathInfo instanceof UriPathInfoEntitySetImpl)) {
|
||||
//TODO add and "or" for FunctionImports
|
||||
fail("isKeyPredicate: uriPathInfo is not instanceof UriPathInfoEntitySetImpl");
|
||||
}
|
||||
|
||||
UriPathInfoEntitySetImpl info = (UriPathInfoEntitySetImpl) uriPathInfo;
|
||||
UriKeyPredicateList keyPredicates = info.getKeyPredicates();
|
||||
assertEquals(name, keyPredicates.getName(index));
|
||||
assertEquals(value, keyPredicates.getValue(index));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isKind(UriInfoKind kind) {
|
||||
assertEquals(kind, uriInfo.getKind());
|
||||
return this;
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isProperties(List<String> asList) {
|
||||
assertNotNull(uriPathInfo);
|
||||
|
@ -171,33 +216,33 @@ public class UriResourcePathValidator {
|
|||
int index = 0;
|
||||
while (index < asList.size()) {
|
||||
String propertyName = uriPathInfo.getProperty(index).getName();
|
||||
|
||||
assertEquals(asList.get(index), propertyName);
|
||||
|
||||
index++;
|
||||
}
|
||||
|
||||
return this;
|
||||
|
||||
|
||||
}
|
||||
|
||||
public void isKind(UriInfoKind kind) {
|
||||
|
||||
assertEquals(kind, uriInfo.getKind());
|
||||
}
|
||||
|
||||
|
||||
public UriResourcePathValidator isProperty(int index, String name, FullQualifiedName type) {
|
||||
if ( index >= uriPathInfo.getPropertyCount()) {
|
||||
fail("not enougth properties in pathinfo found");
|
||||
if (index >= uriPathInfo.getPropertyCount()) {
|
||||
fail("isProperty: invalid index");
|
||||
}
|
||||
|
||||
EdmElement property = uriPathInfo.getProperty(index);
|
||||
|
||||
|
||||
assertEquals(name, property.getName());
|
||||
assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
|
||||
return this;
|
||||
|
||||
}
|
||||
|
||||
public UriResourcePathValidator isUriPathInfoKind(UriPathInfoKind infoType) {
|
||||
assertNotNull(uriPathInfo);
|
||||
assertEquals(infoType, uriPathInfo.getKind());
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -40,7 +40,7 @@ public class TestParser {
|
|||
|
||||
@Test
|
||||
public void test() {
|
||||
test.log(2).aAM().aFC().aCS().run("ODI?$filter=(1) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
|
||||
test.aAM().aFC().aCS().run("ODI?$filter=(1) mul 2").isText("odataRelativeUriEOF(odataRelativeUri("
|
||||
+ "resourcePath(pathSegments(pathSegment(odataIdentifier(ODI)))) ? queryOptions("
|
||||
+ "queryOption(systemQueryOption("
|
||||
+ "filter($filter = commonExpr("
|
||||
|
|
|
@ -18,16 +18,24 @@
|
|||
******************************************************************************/
|
||||
package org.apache.olingo.odata4.producer.core.uri.antlr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Arrays;
|
||||
|
||||
import org.apache.olingo.odata4.commons.api.edm.Edm;
|
||||
import org.apache.olingo.odata4.commons.api.edm.helper.FullQualifiedName;
|
||||
import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
|
||||
import org.apache.olingo.odata4.commons.core.edm.provider.EdmProviderImpl;
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
|
||||
import org.apache.olingo.odata4.producer.api.uri.UriPathInfoKind;
|
||||
import org.apache.olingo.odata4.producer.core.testutil.EdmTechProvider;
|
||||
import org.apache.olingo.odata4.producer.core.testutil.EdmTechTestProvider;
|
||||
import org.apache.olingo.odata4.producer.core.testutil.FilterTreeToText;
|
||||
import org.apache.olingo.odata4.producer.core.testutil.UriResourcePathValidator;
|
||||
import org.apache.olingo.odata4.producer.core.uri.SystemQueryParameter;
|
||||
import org.apache.olingo.odata4.producer.core.uri.UriInfoImplPath;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.ExceptionVisitExpression;
|
||||
import org.apache.olingo.odata4.producer.core.uri.expression.Expression;
|
||||
import org.junit.Test;
|
||||
|
||||
public class TestUriParserImpl {
|
||||
|
@ -53,7 +61,7 @@ public class TestUriParserImpl {
|
|||
|
||||
public TestUriParserImpl() {
|
||||
test = new UriResourcePathValidator();
|
||||
edm = new EdmProviderImpl(new EdmTechProvider());
|
||||
edm = new EdmProviderImpl(new EdmTechTestProvider());
|
||||
test.setEdm(edm);
|
||||
}
|
||||
|
||||
|
@ -68,9 +76,10 @@ public class TestUriParserImpl {
|
|||
|
||||
@Test
|
||||
public void testShortUris() {
|
||||
test.run("$batch").isKind(UriInfoKind.batch);
|
||||
test.run("$all").isKind(UriInfoKind.all);
|
||||
test.run("$crossjoin(abc)").isKind(UriInfoKind.crossjoin);
|
||||
//TODO create on validator for these URIs, because the will more complicated in future
|
||||
//test.run("$batch").isKind(UriInfoKind.batch);
|
||||
//test.run("$all").isKind(UriInfoKind.all);
|
||||
//test.run("$crossjoin(abc)").isKind(UriInfoKind.crossjoin);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -116,7 +125,9 @@ public class TestUriParserImpl {
|
|||
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'")
|
||||
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
|
||||
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
|
||||
}
|
||||
|
||||
public void testEntitySet_Prop() {
|
||||
// with property
|
||||
test.run("ESAllPrim(1)/PropertyString")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
|
@ -138,13 +149,14 @@ public class TestUriParserImpl {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testEntitySetNav() {
|
||||
public void testEntitySet_NavProp() {
|
||||
|
||||
test.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne")
|
||||
.at(0)
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isInitialType(EdmTechProvider.nameETKeyNav)
|
||||
.isType(EdmTechProvider.nameETTwoKeyNav)
|
||||
.isInitialType(EdmTechProvider.nameETKeyNav)
|
||||
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isProperty(0, "NavPropertyETTwoKeyNavOne", EdmTechProvider.nameETTwoKeyNav)
|
||||
.at(1)
|
||||
|
@ -200,17 +212,57 @@ public class TestUriParserImpl {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testTypeFilter() {
|
||||
// test.run("ESTwoPrim");
|
||||
public void testEntitySet_TypeFilter() {
|
||||
|
||||
// filter
|
||||
test.run("ESTwoPrim/com.sap.odata.test1.ETBase")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isType(new FullQualifiedName("com.sap.odata.test1", "ETBase"));
|
||||
.isInitialType(EdmTechProvider.nameETTwoPrim)
|
||||
.isCollectionTypeFilter(EdmTechProvider.nameETBase)
|
||||
.isSingleTypeFilter(null)
|
||||
.isType(EdmTechProvider.nameETBase)
|
||||
.isCollection(true);
|
||||
|
||||
test.run("ESTwoPrim/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")
|
||||
// filter before key predicate
|
||||
test.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isType(new FullQualifiedName("Edm", "String"))
|
||||
.isProperties(Arrays.asList("AdditionalPropertyString_5"))
|
||||
.isProperty(0, "AdditionalPropertyString_5", EdmTechProvider.nameString);
|
||||
.isInitialType(EdmTechProvider.nameETTwoPrim)
|
||||
.isCollectionTypeFilter(EdmTechProvider.nameETBase)
|
||||
.isSingleTypeFilter(null)
|
||||
.isType(EdmTechProvider.nameETBase)
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isCollection(false);
|
||||
|
||||
test.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)/AdditionalPropertyString_5")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isInitialType(EdmTechProvider.nameETTwoPrim)
|
||||
.isCollectionTypeFilter(EdmTechProvider.nameETBase)
|
||||
.isSingleTypeFilter(null)
|
||||
.isType(EdmTechProvider.nameString)
|
||||
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isProperty(0, "AdditionalPropertyString_5", EdmTechProvider.nameString)
|
||||
.isCollection(false);
|
||||
|
||||
// filter after key predicate
|
||||
test.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isInitialType(EdmTechProvider.nameETTwoPrim)
|
||||
.isCollectionTypeFilter(null)
|
||||
.isSingleTypeFilter(EdmTechProvider.nameETBase)
|
||||
.isType(EdmTechProvider.nameETBase)
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isCollection(false);
|
||||
|
||||
test.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.isType(EdmTechProvider.nameString)
|
||||
.isInitialType(EdmTechProvider.nameETTwoPrim)
|
||||
.isCollectionTypeFilter(null)
|
||||
.isSingleTypeFilter(EdmTechProvider.nameETBase)
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isProperty(0, "AdditionalPropertyString_5", EdmTechProvider.nameString)
|
||||
.isCollection(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -234,8 +286,8 @@ public class TestUriParserImpl {
|
|||
test.run("SINav/NavPropertyETKeyNavOne")
|
||||
.at(0)
|
||||
.isUriPathInfoKind(UriPathInfoKind.singleton)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isCollection(false)
|
||||
.at(1)
|
||||
.isType(EdmTechProvider.nameETKeyNav);
|
||||
|
@ -243,8 +295,8 @@ public class TestUriParserImpl {
|
|||
test.run("SINav/NavPropertyETKeyNavOne/PropertyInt16")
|
||||
.at(0)
|
||||
.isUriPathInfoKind(UriPathInfoKind.singleton)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isCollection(false)
|
||||
.at(1)
|
||||
.isInitialType(EdmTechProvider.nameETKeyNav)
|
||||
|
@ -253,8 +305,9 @@ public class TestUriParserImpl {
|
|||
test.run("SINav/NavPropertyETKeyNavMany(1)")
|
||||
.at(0)
|
||||
.isUriPathInfoKind(UriPathInfoKind.singleton)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
|
||||
.isCollection(true)
|
||||
.at(1)
|
||||
.isType(EdmTechProvider.nameETKeyNav);
|
||||
|
@ -262,8 +315,8 @@ public class TestUriParserImpl {
|
|||
test.run("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16")
|
||||
.at(0)
|
||||
.isUriPathInfoKind(UriPathInfoKind.singleton)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isInitialType(EdmTechProvider.nameETTwoKeyNav)
|
||||
.isType(EdmTechProvider.nameETKeyNav)
|
||||
.isCollection(true)
|
||||
.at(1)
|
||||
.isInitialType(EdmTechProvider.nameETKeyNav)
|
||||
|
@ -273,7 +326,7 @@ public class TestUriParserImpl {
|
|||
|
||||
@Test
|
||||
public void testActionImport() {
|
||||
|
||||
|
||||
test.run("AIRTPrimParam")
|
||||
.isUriPathInfoKind(UriPathInfoKind.action)
|
||||
.isType(EdmTechProvider.nameString);
|
||||
|
@ -293,16 +346,19 @@ public class TestUriParserImpl {
|
|||
.isType(EdmTechProvider.nameETCollAllPrim)
|
||||
.isCollection(true);
|
||||
|
||||
//the parser can to this, but should not, as defined per ABNF
|
||||
/*
|
||||
test.run("AIRTETCollAllPrimParam(1)")
|
||||
.isUriPathInfoKind(UriPathInfoKind.action)
|
||||
.isType(EdmTechProvider.nameETCollAllPrim)
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isCollection(false);
|
||||
.isCollection(false);
|
||||
test.run("AIRTETCollAllPrimParam(ParameterInt16=1)")
|
||||
.isUriPathInfoKind(UriPathInfoKind.action)
|
||||
.isType(EdmTechProvider.nameETCollAllPrim)
|
||||
.isKeyPredicate(0, "PropertyInt16", "1")
|
||||
.isCollection(false);
|
||||
*/
|
||||
}
|
||||
|
||||
/*
|
||||
|
@ -346,9 +402,48 @@ public class TestUriParserImpl {
|
|||
|
||||
@Test
|
||||
public void testErrors() {
|
||||
//the following is wrong and must throw an error behind an Action are not () allowed
|
||||
//test.run("AIRTPrimParam()");
|
||||
// the following is wrong and must throw an error behind an Action are not () allowed
|
||||
// test.run("AIRTPrimParam()");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilter() {
|
||||
test.run("ESAllPrim?$filter=1")
|
||||
.isUriPathInfoKind(UriPathInfoKind.entitySet)
|
||||
.hasQueryParameter(SystemQueryParameter.FILTER.toString(), 1)
|
||||
.isFilterString("1");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterSimpleSameBinaryBinaryBinaryPriority() {
|
||||
|
||||
test.runFilter("1 add 2 add 3 add 4").is("<<<1 add 2> add 3> add 4>");
|
||||
test.runFilter("1 add 2 add 3 div 4").is("<<1 add 2> add <3 div 4>>");
|
||||
test.runFilter("1 add 2 div 3 add 4").is("<<1 add <2 div 3>> add 4>");
|
||||
test.runFilter("1 add 2 div 3 div 4").is("<1 add <<2 div 3> div 4>>");
|
||||
test.runFilter("1 div 2 add 3 add 4").is("<<<1 div 2> add 3> add 4>");
|
||||
test.runFilter("1 div 2 add 3 div 4").is("<<1 div 2> add <3 div 4>>");
|
||||
test.runFilter("1 div 2 div 3 add 4").is("<<<1 div 2> div 3> add 4>");
|
||||
test.runFilter("1 div 2 div 3 div 4").is("<<<1 div 2> div 3> div 4>");
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testFilterComplexMixedPriority() {
|
||||
test.runFilter("a or c and e ").isCompr("< a or < c and e >>");
|
||||
test.runFilter("a or c and e eq f").isCompr("< a or < c and <e eq f>>>");
|
||||
test.runFilter("a or c eq d and e ").isCompr("< a or <<c eq d> and e >>");
|
||||
test.runFilter("a or c eq d and e eq f").isCompr("< a or <<c eq d> and <e eq f>>>");
|
||||
test.runFilter("a eq b or c and e ").isCompr("<<a eq b> or < c and e >>");
|
||||
test.runFilter("a eq b or c and e eq f").isCompr("<<a eq b> or < c and <e eq f>>>");
|
||||
test.runFilter("a eq b or c eq d and e ").isCompr("<<a eq b> or <<c eq d> and e >>");
|
||||
test.runFilter("a eq b or c eq d and e eq f").isCompr("<<a eq b> or <<c eq d> and <e eq f>>>");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void textFilterMember() {
|
||||
test.runFilter("a").is("a");
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue