Merge from origin/master

This commit is contained in:
Francesco Chicchiriccò 2014-02-21 17:27:52 +01:00
commit 7f76d8a7bc
21 changed files with 183 additions and 1835 deletions

View File

@ -20,6 +20,6 @@ package org.apache.olingo.odata4.server.api.uri.queryoption;
public interface FormatOption extends SystemQueryOption { public interface FormatOption extends SystemQueryOption {
// TODO planned: define best representation for format // TODO planned: define best representation for format to enable plugging in custom formats
String getFormat(); String getFormat();
} }

View File

@ -23,7 +23,7 @@ public enum SupportedQueryOptions {
FORMAT("$format"), FORMAT("$format"),
EXPAND("$expand"), EXPAND("$expand"),
ID("$id"), ID("$id"),
INLINECOUNT("$inlinecount"), COUNT("$count"),
ORDERBY("$orderby"), ORDERBY("$orderby"),
SEARCH("$search"), SEARCH("$search"),
SELECT("$select"), SELECT("$select"),

View File

@ -81,14 +81,12 @@ value : VALUE;
//; 2. Query Options //; 2. Query Options
//;------------------------------------------------------------------------------ //;------------------------------------------------------------------------------
queryOptions : vlQO+=queryOption ( AMP vlQO+=queryOption )*; queryOptions : vlQO+=queryOption ( AMP vlQO+=queryOption )*;//TODO can this be removed
queryOption : systemQueryOption queryOption : systemQueryOption;
| AT_Q aliasAndValue;
systemQueryOption : expand systemQueryOption : expand
| filter | filter
| format
| inlinecount | inlinecount
| orderBy | orderBy
| search | search
@ -148,7 +146,7 @@ orderByItem : vC=commonExpr ( WSP ( vA=ASC | vD=DESC ) )?;
skip : SKIP EQ INT; skip : SKIP EQ INT;
top : TOP EQ INT; top : TOP EQ INT;
format : FORMAT EQ ( ATOM | JSON | XML | PCHARS ( SLASH PCHARS)?); //format : FORMAT EQ ( ATOM | JSON | XML | PCHARS ( SLASH PCHARS)?);
inlinecount : COUNT EQ booleanNonCase; inlinecount : COUNT EQ booleanNonCase;

View File

@ -256,7 +256,7 @@ public class UriInfoImpl implements UriInfo {
formatOption = (FormatOptionImpl) systemOption; formatOption = (FormatOptionImpl) systemOption;
} else if (systemOption.getKind() == SupportedQueryOptions.ID) { } else if (systemOption.getKind() == SupportedQueryOptions.ID) {
idOption = (IdOptionImpl) systemOption; idOption = (IdOptionImpl) systemOption;
} else if (systemOption.getKind() == SupportedQueryOptions.INLINECOUNT) { } else if (systemOption.getKind() == SupportedQueryOptions.COUNT) {
inlineCountOption = (CountOptionImpl) systemOption; inlineCountOption = (CountOptionImpl) systemOption;
} else if (systemOption.getKind() == SupportedQueryOptions.ORDERBY) { } else if (systemOption.getKind() == SupportedQueryOptions.ORDERBY) {
orderByOption = (OrderByOptionImpl) systemOption; orderByOption = (OrderByOptionImpl) systemOption;

View File

@ -195,12 +195,6 @@ public class Parser {
idOption.setText(option.value); idOption.setText(option.value);
idOption.setValue(option.value); idOption.setValue(option.value);
context.contextUriInfo.setSystemQueryOption(idOption); context.contextUriInfo.setSystemQueryOption(idOption);
} else if (option.name.equals("$inlinecount")) {
CountOptionImpl inlineCountOption = new CountOptionImpl();
inlineCountOption.setName(option.name);
inlineCountOption.setText(option.value);
inlineCountOption.setValue(option.value.equals("true") ? true : false);
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$orderby")) { } else if (option.name.equals("$orderby")) {
OrderByEOFContext ctxFilterExpression = OrderByEOFContext ctxFilterExpression =
(OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby); (OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
@ -244,19 +238,7 @@ public class Parser {
inlineCountOption.setText(option.value); inlineCountOption.setText(option.value);
inlineCountOption.setValue(option.value.equals("true") ? true : false); inlineCountOption.setValue(option.value.equals("true") ? true : false);
context.contextUriInfo.setSystemQueryOption(inlineCountOption); context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$level")) {
LevelsOptionImpl inlineCountOption = new LevelsOptionImpl();
inlineCountOption.setName(option.name);
inlineCountOption.setText(option.value);
if (option.value.equals("max")) {
inlineCountOption.setMax();
} else {
inlineCountOption.setValue(Integer.parseInt(option.value));
} }
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
}
} }
} }

View File

@ -96,11 +96,9 @@ public class UriDecoder {
public static void splittPath(final RawUri rawUri, int scipSegments) { public static void splittPath(final RawUri rawUri, int scipSegments) {
List<String> list = splitt(rawUri.path, '/'); List<String> list = splitt(rawUri.path, '/');
if (list.size() > 0) {
if (list.get(0).length() == 0) { if (list.get(0).length() == 0) {
scipSegments++; scipSegments++;
} }
}
if (scipSegments > 0) { if (scipSegments > 0) {
rawUri.pathSegmentList = list.subList(scipSegments, list.size()); rawUri.pathSegmentList = list.subList(scipSegments, list.size());
@ -121,9 +119,9 @@ public class UriDecoder {
start = end + 1; start = end + 1;
} }
if (end == -1) {
list.add(input.substring(start)); list.add(input.substring(start));
}
return list; return list;
} }

View File

@ -106,7 +106,6 @@ import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.ExpandRefO
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FilterContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FilterContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FilterExpressionEOFContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FilterExpressionEOFContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FloorMethodCallExprContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FloorMethodCallExprContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FormatContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FractionalsecondsMethodCallExprContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.FractionalsecondsMethodCallExprContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.GeoDistanceMethodCallExprContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.GeoDistanceMethodCallExprContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.GeoIntersectsMethodCallExprContext; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser.GeoIntersectsMethodCallExprContext;
@ -187,22 +186,16 @@ import org.apache.olingo.odata4.server.core.uri.queryoption.expression.TypeLiter
/** /**
* UriVisitor * UriVisitor
* *
* Converts the URI parse tree from the generate URI parser into an internal representation * Converts the URI parse tree the generated by ANTLR into an internal representation
* which maybe (TODO) given to the application. * which maybe is given to the application.
* While converting the tree is validated against the EDM. * While converting the tree is only validated against the EDM if necessary.
* *
* Attention: * Attention:
* <li> This UriVisitor is at some point more lax than the original ABNF: * <li> This UriVisitor is at somes point more lax than the original ABNF
* <li> It is more tolerable against additional white spaces * <li> It is more tolerable against additional white spaces
* - Whenever it is possible to move edm validation to the AST classes then * Currently not supported
* this should be done ( see visit {@link #visitSelectSegment} for example) * <li>Parsing the context of $metadata</li>
* * <li>Parsing $search</li>
* Not supported
* <li>Parsing the context of $metadata
*
* TODO planned
* <li>Overview testcases
* <li>search
*/ */
public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> { public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
@ -216,7 +209,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
} }
public TypeInformation() { public TypeInformation() {
// TODO Auto-generated constructor stub
} }
} }
@ -226,14 +218,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// --- class --- // --- class ---
public void setContext(final UriContext context) {
this.context = context;
}
public UriInfoImpl getUriInfo() {
return context.contextUriInfo;
}
public UriParseTreeVisitor(final Edm edm, final UriContext context) { public UriParseTreeVisitor(final Edm edm, final UriContext context) {
this.edm = edm; this.edm = edm;
this.context = context; this.context = context;
@ -639,15 +623,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return type.getNamespace() + "." + type.getName(); return type.getNamespace() + "." + type.getName();
} }
@Override
public Object visitAliasAndValue(final AliasAndValueContext ctx) {
AliasQueryOptionImpl alias = new AliasQueryOptionImpl();
alias.setName(ctx.vODI.getText());
alias.setText(ctx.vV.getText());
alias.setAliasValue((ExpressionImpl) ctx.vV.accept(this));
return alias;
}
@Override @Override
public Object visitAllEOF(final AllEOFContext ctx) { public Object visitAllEOF(final AllEOFContext ctx) {
UriInfoImpl crossJoin = new UriInfoImpl().setKind(UriInfoKind.all); UriInfoImpl crossJoin = new UriInfoImpl().setKind(UriInfoKind.all);
@ -1009,7 +984,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (type instanceof EdmEntityType) { if (type instanceof EdmEntityType) {
context.contextUriInfo.addResourcePart(new UriResourceRefImpl()); context.contextUriInfo.addResourcePart(new UriResourceRefImpl());
} else { } else {
throw wrap(new UriParserSemanticException("$ref only allowd on endity types")); throw wrap(new UriParserSemanticException("$ref only allowed on endity types"));
} }
} else { } else {
throw wrap(new UriParserSemanticException("$ref only allowed on typed properties")); throw wrap(new UriParserSemanticException("$ref only allowed on typed properties"));
@ -1120,7 +1095,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
levels.setText(ctx.vM.getText()); levels.setText(ctx.vM.getText());
expandItem.setSystemQueryOption(levels); expandItem.setSystemQueryOption(levels);
} else if (ctx.vL != null) { } else if (ctx.vL != null) {
// TODO set value as integer
LevelsOptionImpl levels = new LevelsOptionImpl(); LevelsOptionImpl levels = new LevelsOptionImpl();
String text = ctx.vL.getText(); String text = ctx.vL.getText();
levels.setText(text); levels.setText(text);
@ -1253,35 +1227,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
.addParameter((ExpressionImpl) ctx.vE1.accept(this)); .addParameter((ExpressionImpl) ctx.vE1.accept(this));
} }
@Override
public Object visitFormat(final FormatContext ctx) {
FormatOptionImpl format = new FormatOptionImpl();
TerminalNodeImpl c2 = (TerminalNodeImpl) ctx.children.get(2);
if (c2.symbol.getType() == UriLexer.ATOM) {
format.setFormat("atom");
} else if (c2.symbol.getType() == UriLexer.JSON) {
format.setFormat("json");
} else if (c2.symbol.getType() == UriLexer.XML) {
format.setFormat("xml");
} else if (c2.symbol.getType() == UriLexer.PCHARS) {
if (ctx.getChildCount() == 2) {
format.setFormat(c2.getText());
} else {
format.setFormat(c2.getText() + "/" + ctx.children.get(4).getText());
}
}
String text = ctx.children.get(2).getText();
if (ctx.getChildCount() > 4) {
text += ctx.children.get(3).getText();
text += ctx.children.get(4).getText();
}
format.setText(text);
return format;
}
@Override @Override
public ExpressionImpl visitFractionalsecondsMethodCallExpr(final FractionalsecondsMethodCallExprContext ctx) { public ExpressionImpl visitFractionalsecondsMethodCallExpr(final FractionalsecondsMethodCallExprContext ctx) {
return new MethodCallImpl() return new MethodCallImpl()
@ -1363,9 +1308,11 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (text.equals("max")) { if (text.equals("max")) {
levels.setMax(); levels.setMax();
} else {
levels.setValue(Integer.parseInt(text));
} }
levels.setText(text); levels.setText(text);
// TODO set value as integer
return levels; return levels;
@ -2034,7 +1981,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// check for action // check for action
EdmAction action = edm.getAction(fullName, finalTypeName, null); EdmAction action = edm.getAction(fullName, finalTypeName, null);
// TODO verify that null ignores if it is a collection
if (action != null) { if (action != null) {
UriResourceActionImpl uriAction = new UriResourceActionImpl(); UriResourceActionImpl uriAction = new UriResourceActionImpl();
@ -2046,7 +1992,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// check for function // check for function
EdmFunction function = edm.getFunction(fullName, finalTypeName, null, null); EdmFunction function = edm.getFunction(fullName, finalTypeName, null, null);
// TODO verify that null ignores if it is a collection
if (function != null) { if (function != null) {
UriResourceFunctionImpl uriFunction = new UriResourceFunctionImpl(); UriResourceFunctionImpl uriFunction = new UriResourceFunctionImpl();
@ -2151,11 +2096,6 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
.addParameter((ExpressionImpl) ctx.vE1.accept(this)); .addParameter((ExpressionImpl) ctx.vE1.accept(this));
} }
@Override
public Object visitUnary(final UnaryContext ctx) {
// TODO implement
return super.visitUnary(ctx);
}
@Override @Override
public ExpressionImpl visitYearMethodCallExpr(final YearMethodCallExprContext ctx) { public ExpressionImpl visitYearMethodCallExpr(final YearMethodCallExprContext ctx) {

View File

@ -18,7 +18,6 @@
*/ */
package org.apache.olingo.odata4.server.core.uri.parser; package org.apache.olingo.odata4.server.core.uri.parser;
//TODO Check name of this exception when implementing proper error handling
public class UriParserException extends Exception { public class UriParserException extends Exception {
/** /**
* *

View File

@ -18,12 +18,8 @@
*/ */
package org.apache.olingo.odata4.server.core.uri.parser; package org.apache.olingo.odata4.server.core.uri.parser;
//TODO Check name of this exception when implementing proper error handling
public class UriParserSemanticException extends UriParserException { public class UriParserSemanticException extends UriParserException {
/**
*
*/
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public UriParserSemanticException(final String message, final Throwable cause) { public UriParserSemanticException(final String message, final Throwable cause) {

View File

@ -26,7 +26,7 @@ public class CountOptionImpl extends SystemQueryOptionImpl implements CountOptio
private boolean count; private boolean count;
public CountOptionImpl() { public CountOptionImpl() {
setKind(SupportedQueryOptions.INLINECOUNT); setKind(SupportedQueryOptions.COUNT);
} }
@Override @Override

View File

@ -59,7 +59,7 @@ public class ExpandItemImpl implements ExpandItem {
expandOption = (ExpandOptionImpl) sysItem; expandOption = (ExpandOptionImpl) sysItem;
} else if (sysItem.getKind() == SupportedQueryOptions.FILTER) { } else if (sysItem.getKind() == SupportedQueryOptions.FILTER) {
filterOption = (FilterOptionImpl) sysItem; filterOption = (FilterOptionImpl) sysItem;
} else if (sysItem.getKind() == SupportedQueryOptions.INLINECOUNT) { } else if (sysItem.getKind() == SupportedQueryOptions.COUNT) {
inlineCountOption = (CountOptionImpl) sysItem; inlineCountOption = (CountOptionImpl) sysItem;
} else if (sysItem.getKind() == SupportedQueryOptions.ORDERBY) { } else if (sysItem.getKind() == SupportedQueryOptions.ORDERBY) {
orderByOption = (OrderByOptionImpl) sysItem; orderByOption = (OrderByOptionImpl) sysItem;

View File

@ -22,7 +22,7 @@ import org.apache.olingo.odata4.server.api.uri.queryoption.SearchOption;
import org.apache.olingo.odata4.server.api.uri.queryoption.SupportedQueryOptions; import org.apache.olingo.odata4.server.api.uri.queryoption.SupportedQueryOptions;
import org.apache.olingo.odata4.server.api.uri.queryoption.search.SearchExpression; import org.apache.olingo.odata4.server.api.uri.queryoption.search.SearchExpression;
// TODO $search is not supported yet // TODO planned: support $search
public class SearchOptionImpl extends SystemQueryOptionImpl implements SearchOption { public class SearchOptionImpl extends SystemQueryOptionImpl implements SearchOption {
public SearchOptionImpl() { public SearchOptionImpl() {
@ -31,7 +31,6 @@ public class SearchOptionImpl extends SystemQueryOptionImpl implements SearchOpt
@Override @Override
public SearchExpression getSearchExpression() { public SearchExpression getSearchExpression() {
// TODO $search is not supported yet
return null; return null;
} }

View File

@ -124,16 +124,17 @@ public class RawUriTest {
checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet")); checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet"));
} }
/*
* @Test @Test
* public void testSplitt() { public void testSplitt() {
* UriRawParser.splitt("", '/'); UriDecoder.splitt("", '/');
* UriRawParser.splitt("a", '/'); UriDecoder.splitt("/", '/');
* UriRawParser.splitt("a/", '/'); UriDecoder.splitt("a", '/');
* UriRawParser.splitt("/a", '/'); UriDecoder.splitt("a/", '/');
* UriRawParser.splitt("a/a", '/'); UriDecoder.splitt("/a", '/');
* } UriDecoder.splitt("a/a", '/');
*/ }
private void checkPath(final RawUri rawUri, final String path, final List<String> list) { private void checkPath(final RawUri rawUri, final String path, final List<String> list) {
assertEquals(path, rawUri.path); assertEquals(path, rawUri.path);

View File

@ -46,7 +46,7 @@ import org.apache.olingo.odata4.server.core.uri.queryoption.expression.Expressio
import org.apache.olingo.odata4.server.core.uri.queryoption.expression.LiteralImpl; import org.apache.olingo.odata4.server.core.uri.queryoption.expression.LiteralImpl;
import org.junit.Test; import org.junit.Test;
public class UriParameterImplTest { public class UriResourceImplTest {
Edm edm = new EdmProviderImpl(new EdmTechTestProvider()); Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
@Test @Test
@ -201,9 +201,11 @@ public class UriParameterImplTest {
assertNotNull(function); assertNotNull(function);
impl.setFunction(function); impl.setFunction(function);
assertEquals(function, impl.getFunction()); assertEquals(function, impl.getFunction());
assertEquals("UFNRTInt16", impl.toString()); assertEquals("UFNRTInt16", impl.toString());
assertEquals(function.getReturnType().getType(), impl.getType()); assertEquals(function.getReturnType().getType(), impl.getType());
assertEquals(false,impl.isParameterListFilled());
// function import // function import
impl = new UriResourceFunctionImpl(); impl = new UriResourceFunctionImpl();
@ -226,6 +228,7 @@ public class UriParameterImplTest {
assertEquals(false, impl.isCollection()); assertEquals(false, impl.isCollection());
assertEquals(parameter, impl.getParameters().get(0)); assertEquals(parameter, impl.getParameters().get(0));
assertEquals(true,impl.isParameterListFilled());
} }
@Test @Test
@ -476,7 +479,7 @@ public class UriParameterImplTest {
assertEquals(true, impl.isCollection()); assertEquals(true, impl.isCollection());
} }
/*
@Test @Test
public void testUriResourceStartingTypeFilterImpl() { public void testUriResourceStartingTypeFilterImpl() {
UriResourceStartingTypeFilterImpl impl = new UriResourceStartingTypeFilterImpl(); UriResourceStartingTypeFilterImpl impl = new UriResourceStartingTypeFilterImpl();
@ -498,5 +501,5 @@ public class UriParameterImplTest {
impl.setKeyPredicates(keyPredicates); impl.setKeyPredicates(keyPredicates);
assertEquals(false, impl.isCollection()); assertEquals(false, impl.isCollection());
}*/ }
} }

View File

@ -18,17 +18,12 @@
*/ */
package org.apache.olingo.odata4.server.core.uri.antlr; package org.apache.olingo.odata4.server.core.uri.antlr;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.fail;
import java.io.UnsupportedEncodingException; import java.io.UnsupportedEncodingException;
import java.net.URLEncoder; import java.net.URLEncoder;
import java.util.Arrays; import java.util.Arrays;
import org.apache.olingo.odata4.commons.api.ODataApplicationException; import org.apache.olingo.odata4.commons.api.ODataApplicationException;
import org.apache.olingo.odata4.commons.api.edm.Edm; import org.apache.olingo.odata4.commons.api.edm.Edm;
import org.apache.olingo.odata4.commons.api.edm.EdmType;
import org.apache.olingo.odata4.commons.api.edm.FullQualifiedName;
import org.apache.olingo.odata4.server.api.uri.UriInfoKind; import org.apache.olingo.odata4.server.api.uri.UriInfoKind;
import org.apache.olingo.odata4.server.api.uri.UriResourceKind; import org.apache.olingo.odata4.server.api.uri.UriResourceKind;
import org.apache.olingo.odata4.server.api.uri.queryoption.expression.BinaryOperatorKind; import org.apache.olingo.odata4.server.api.uri.queryoption.expression.BinaryOperatorKind;
@ -38,7 +33,6 @@ import org.apache.olingo.odata4.server.core.edm.provider.EdmProviderImpl;
import org.apache.olingo.odata4.server.core.testutil.EdmTechProvider; import org.apache.olingo.odata4.server.core.testutil.EdmTechProvider;
import org.apache.olingo.odata4.server.core.testutil.EdmTechTestProvider; import org.apache.olingo.odata4.server.core.testutil.EdmTechTestProvider;
import org.apache.olingo.odata4.server.core.uri.parser.UriParserException; import org.apache.olingo.odata4.server.core.uri.parser.UriParserException;
import org.apache.olingo.odata4.server.core.uri.queryoption.expression.MemberImpl;
import org.apache.olingo.odata4.server.core.uri.testutil.FilterValidator; import org.apache.olingo.odata4.server.core.uri.testutil.FilterValidator;
import org.apache.olingo.odata4.server.core.uri.testutil.ResourceValidator; import org.apache.olingo.odata4.server.core.uri.testutil.ResourceValidator;
import org.apache.olingo.odata4.server.core.uri.testutil.UriValidator; import org.apache.olingo.odata4.server.core.uri.testutil.UriValidator;
@ -68,8 +62,7 @@ public class TestFullResourcePath {
testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath() testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav); .isType(EdmTechProvider.nameETTwoKeyNav);
@ -78,8 +71,7 @@ public class TestFullResourcePath {
testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')").goPath() testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')").goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav); .isType(EdmTechProvider.nameETTwoKeyNav);
@ -88,8 +80,7 @@ public class TestFullResourcePath {
testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath() testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav); .isType(EdmTechProvider.nameETTwoKeyNav);
@ -807,8 +798,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETAllPrim) .isType(EdmTechProvider.nameETAllPrim, false)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.primitiveProperty) .isUriPathInfoKind(UriResourceKind.primitiveProperty)
.isType(EdmTechProvider.nameString); .isType(EdmTechProvider.nameString);
@ -818,8 +808,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETCollAllPrim) .isType(EdmTechProvider.nameETCollAllPrim, false)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.primitiveProperty) .isUriPathInfoKind(UriResourceKind.primitiveProperty)
.isType(EdmTechProvider.nameString); .isType(EdmTechProvider.nameString);
@ -830,8 +819,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, false)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.complexProperty) .isUriPathInfoKind(UriResourceKind.complexProperty)
.at(2) .at(2)
@ -843,8 +831,7 @@ public class TestFullResourcePath {
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.at(1) .at(1)
.isType(EdmTechProvider.nameCTPrimComp) .isType(EdmTechProvider.nameCTPrimComp, true)
.isCollection(true)
.at(2) .at(2)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETAllPrim); .isType(EdmTechProvider.nameETAllPrim);
@ -855,8 +842,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, false)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav); .isType(EdmTechProvider.nameETTwoKeyNav);
@ -866,8 +852,7 @@ public class TestFullResourcePath {
.goPath() .goPath()
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1).isUriPathInfoKind(UriResourceKind.function) .at(1).isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav); .isType(EdmTechProvider.nameETTwoKeyNav);
} }
@ -1118,15 +1103,16 @@ public class TestFullResourcePath {
@Test @Test
public void runEsNameKeyCast() { public void runEsNameKeyCast() {
/*
testUri.runEx("xESTwoPrim(1)/com.sap.odata.test1.ETBase(1)") * testUri.runEx("ESTwoPrim(1)/com.sap.odata.test1.ETBase(1)")
.isExSemantic(0); * .isExSemantic(0);
*
testUri.runEx("xESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)") * testUri.runEx("ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)")
.isExSemantic(0); * .isExSemantic(0);
*
testUri.runEx("xESBase/com.sap.odata.test1.ETTwoPrim(1)") * testUri.runEx("ESBase/com.sap.odata.test1.ETTwoPrim(1)")
.isExSemantic(0); * .isExSemantic(0);
*/
testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETBase") testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETBase")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
@ -4170,7 +4156,6 @@ public class TestFullResourcePath {
.n().isComplex("PropertyComplex") .n().isComplex("PropertyComplex")
.n().isPrimitiveProperty("PropertyInt16", EdmTechProvider.nameInt16, false); .n().isPrimitiveProperty("PropertyInt16", EdmTechProvider.nameInt16, false);
// TODO lambda does not check if the previous path segment is a collection
testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyInt16 eq 1 or d/any" testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyInt16 eq 1 or d/any"
+ "(e:e/CollPropertyString eq 'SomeString'))") + "(e:e/CollPropertyString eq 'SomeString'))")
.is("<NavPropertyETTwoKeyNavMany/<ANY;<<<d/PropertyInt16> eq <1>> or " .is("<NavPropertyETTwoKeyNavMany/<ANY;<<<d/PropertyInt16> eq <1>> or "
@ -4381,7 +4366,6 @@ public class TestFullResourcePath {
.goUpFilterValidator() .goUpFilterValidator()
.root().goParameter(1).isTypedLiteral(EdmTechProvider.nameString); .root().goParameter(1).isTypedLiteral(EdmTechProvider.nameString);
// TODO cross check with abap coding
testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyString,Edm.Guid)") testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyString,Edm.Guid)")
.is("<isof(<PropertyComplex/PropertyComplex/PropertyString>,<Edm.Guid>)>") .is("<isof(<PropertyComplex/PropertyComplex/PropertyString>,<Edm.Guid>)>")
.root() .root()
@ -5020,7 +5004,6 @@ public class TestFullResourcePath {
.goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator() .goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator()
.goOrder(0).right().isEnum(EdmTechProvider.nameENString, Arrays.asList("String1")); .goOrder(0).right().isEnum(EdmTechProvider.nameENString, Arrays.asList("String1"));
// TODO
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1").isExSyntax(0); testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1").isExSyntax(0);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16, PropertyInt32 PropertyDuration").isExSyntax(0); testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16, PropertyInt32 PropertyDuration").isExSyntax(0);
testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 PropertyInt32, PropertyDuration desc").isExSyntax(0); testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 PropertyInt32, PropertyDuration desc").isExSyntax(0);
@ -5062,6 +5045,57 @@ public class TestFullResourcePath {
testUri.run("ESTwoKeyNav?$search= abc AND (def ghi)"); testUri.run("ESTwoKeyNav?$search= abc AND (def ghi)");
} }
@Test
public void testErrors() {
testUri.runEx("FICRTString(wrong1='ABC')/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0);
testUri.runEx("FICRTString(wrong1='ABC', wrong2=1)/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0);
// type filter for entity incompatible
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBase").isExSemantic(0);
// type filter for entity double on entry
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0);
// type filter for entity double on collection
testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav")
.isExSemantic(0);
// type filter for entity double on non key pred
testUri.runEx("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0);
// type filter for complex incompatible
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim"
+ "/com.sap.odata.test1.CTCollAllPrim").isExSemantic(0);
// type filter for complex double on entry
testUri.runEx("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')"
+ "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
// type filter for complex double on collection
testUri.runEx("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')"
+ "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
// type filter for complex double on non key pred
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim"
+ "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0);
testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav").isExSemantic(0);
// $ref
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim/$ref").isExSemantic(0);
testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim/$count").isExSemantic(0);
}
@Test
public void testAlias() {
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath()
.isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicateAlias(1, "PropertyString", "A")
.goUpUriValidator()
.isCustomParameter(0, "@A", "'2'");
}
public static String encode(final String decoded) throws UnsupportedEncodingException { public static String encode(final String decoded) throws UnsupportedEncodingException {
return URLEncoder.encode(decoded, "UTF-8"); return URLEncoder.encode(decoded, "UTF-8");

View File

@ -68,28 +68,19 @@ public class TestLexer {
test.run("$skip=2").isAllText("$skip=2").isType(UriLexer.SKIP); test.run("$skip=2").isAllText("$skip=2").isType(UriLexer.SKIP);
test.run("$skip=123").isAllText("$skip=123").isType(UriLexer.SKIP); test.run("$skip=123").isAllText("$skip=123").isType(UriLexer.SKIP);
// TODO check and add error handling
// test.run("$skip=A").isExType(LexerNoViableAltException.class);
test.run("$top=1").isAllText("$top=1").isType(UriLexer.TOP); test.run("$top=1").isAllText("$top=1").isType(UriLexer.TOP);
test.run("$top=2").isAllText("$top=2").isType(UriLexer.TOP); test.run("$top=2").isAllText("$top=2").isType(UriLexer.TOP);
test.run("$top=123").isAllText("$top=123").isType(UriLexer.TOP); test.run("$top=123").isAllText("$top=123").isType(UriLexer.TOP);
// TODO check and add error handling
// test.run("$top=A").isExType(LexerNoViableAltException.class);
test.run("$levels=1").isAllText("$levels=1").isType(UriLexer.LEVELS); test.run("$levels=1").isAllText("$levels=1").isType(UriLexer.LEVELS);
test.run("$levels=2").isAllText("$levels=2").isType(UriLexer.LEVELS); test.run("$levels=2").isAllText("$levels=2").isType(UriLexer.LEVELS);
test.run("$levels=123").isAllText("$levels=123").isType(UriLexer.LEVELS); test.run("$levels=123").isAllText("$levels=123").isType(UriLexer.LEVELS);
test.run("$levels=max").isAllText("$levels=max").isType(UriLexer.LEVELS); test.run("$levels=max").isAllText("$levels=max").isType(UriLexer.LEVELS);
// TODO check and add error handling
// test.run("$levels=A").isExType(LexerNoViableAltException.class);
test.run("$format=atom").isAllText("$format=atom").isType(UriLexer.FORMAT); test.run("$format=atom").isAllText("$format=atom").isType(UriLexer.FORMAT);
test.run("$format=json").isAllText("$format=json").isType(UriLexer.FORMAT); test.run("$format=json").isAllText("$format=json").isType(UriLexer.FORMAT);
test.run("$format=xml").isAllText("$format=xml").isType(UriLexer.FORMAT); test.run("$format=xml").isAllText("$format=xml").isType(UriLexer.FORMAT);
test.run("$format=abc/def").isAllText("$format=abc/def").isType(UriLexer.FORMAT); test.run("$format=abc/def").isAllText("$format=abc/def").isType(UriLexer.FORMAT);
// TODO check and add error handling
// test.run("$format=abc").isExType(LexerNoViableAltException.class);
test.run("$id=123").isAllText("$id=123").isType(UriLexer.ID); test.run("$id=123").isAllText("$id=123").isType(UriLexer.ID);
test.run("$id=ABC").isAllText("$id=ABC").isType(UriLexer.ID); test.run("$id=ABC").isAllText("$id=ABC").isType(UriLexer.ID);
@ -108,11 +99,8 @@ public class TestLexer {
@Test @Test
public void testQueryExpressions() { public void testQueryExpressions() {
test.globalMode(Lexer.DEFAULT_MODE); test.globalMode(Lexer.DEFAULT_MODE);
// assertEquals("expected","actual");
test.run("$it").isText("$it").isType(UriLexer.IT); test.run("$it").isText("$it").isType(UriLexer.IT);
// TODO check and add error handling
// test.run("$itabc").isText("$it").isType(UriLexer.IMPLICIT_VARIABLE_EXPR);
test.run("$filter=contains(").at(2).isText("contains(").isType(UriLexer.CONTAINS_WORD); test.run("$filter=contains(").at(2).isText("contains(").isType(UriLexer.CONTAINS_WORD);
@ -131,106 +119,6 @@ public class TestLexer {
} }
// ;------------------------------------------------------------------------------
// ; 5. JSON format for function parameters
// ;------------------------------------------------------------------------------
@Test
public void testQueryJSON_and_otheres() {
// QUOTATION_MARK
// test.run("\"").isText("\"").isType(UriLexer.QUOTATION_MARK);
// test.run("%22").isText("%22").isType(UriLexer.QUOTATION_MARK);
// Lexer rule QCHAR_UNESCAPED
test.run("\"abc\"").isText("\"abc\"").isType(UriLexer.STRING_IN_JSON);
// Lexer rule QCHAR_JSON_SPECIAL
/*
* test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*
* // Lexer rule CHAR_IN_JSON
* test.run("\"" + cQCHAR_UNESCAPED + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cQCHAR_JSON_SPECIAL + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*
* // Lexer rule ESCAPE CHAR_IN_JSON
* test.run("\"" + cESCAPE + cQUOTATION_MARK + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + cESCAPE + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "/" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "%2F" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "b" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "f" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "n" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "r" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "t" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
* test.run("\"" + cESCAPE + "u12AB" + "\"").isInput().isType(UriLexer.STRING_IN_JSON);
*/
}
// ;------------------------------------------------------------------------------
// ; 6. Names and identifiers
// ;------------------------------------------------------------------------------
@Test
public void testNamesAndIdentifiers() {
/*
* test.run("Binary").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Boolean").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Byte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Date").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("DateTimeOffset").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Decimal").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Double").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Duration").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Guid").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int16").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int32").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Int64").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("SByte").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Single").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Stream").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("String").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("TimeOfDay").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* test.run("Geography").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run("Geometry").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* String g = "Geography";
* test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*
* g = "Geometry";
* test.run(g ).isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Collection").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiLineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPoint").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "MultiPolygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Point").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "LineString").isInput().isType(UriLexer.PRIMITIVETYPENAME);
* test.run(g + "Polygon").isInput().isType(UriLexer.PRIMITIVETYPENAME);
*/
}
@Test
public void testNameClaches() {
/*
* test.run("Collection").isInput().isType(UriLexer.COLLECTION_CS_FIX);
* test.run("LineString").isInput().isType(UriLexer.LINESTRING_CS_FIX);
* test.run("MultiLineString").isInput().isType(UriLexer.MULTILINESTRING_CS_FIX);
* test.run("MultiPoint").isInput().isType(UriLexer.MULTIPOINT_CS_FIX);
* test.run("MultiPolygon").isInput().isType(UriLexer.MULTIPOLYGON_CS_FIX);
* test.run("Point").isInput().isType(UriLexer.POINT_CS_FIX);
* test.run("Polygon").isInput().isType(UriLexer.POLYGON_CS_FIX);
* test.run("Srid").isInput().isType(UriLexer.SRID_CS);
*/
}
// ;------------------------------------------------------------------------------ // ;------------------------------------------------------------------------------
// ; 7. Literal Data Values // ; 7. Literal Data Values
@ -246,11 +134,6 @@ public class TestLexer {
test.run("binary'ABCD'").isInput().isType(UriLexer.BINARY); test.run("binary'ABCD'").isInput().isType(UriLexer.BINARY);
test.run("BiNaRy'ABCD'").isInput().isType(UriLexer.BINARY); test.run("BiNaRy'ABCD'").isInput().isType(UriLexer.BINARY);
// not a binary TODO add error handling
test.run("BiNaRy'ABCDA'")
.at(0).isText("BiNaRy").isType(UriLexer.ODATAIDENTIFIER)
.at(1).isText("'ABCDA'").isType(UriLexer.STRING);
// boolean // boolean
test.run("true").isInput().isType(UriLexer.TRUE); test.run("true").isInput().isType(UriLexer.TRUE);
test.run("false").isInput().isType(UriLexer.FALSE); test.run("false").isInput().isType(UriLexer.FALSE);
@ -342,28 +225,7 @@ public class TestLexer {
} }
/*
* // ;------------------------------------------------------------------------------
* // ; 0. misc
* // ;------------------------------------------------------------------------------
*
* @Test
* public void testCriticalOrder() {
* // Test lexer rule STRING
* test.run("'abc'").isInput().isType(UriLexer.STRING);
*
* // Test lexer rule SEARCHWORD
* test.run("abc", true).isInput().isType(UriLexer.SEARCHWORD);
*
* // Test lexer rule SEARCHPHRASE
* test.run("\"abc\"", true).isInput().isType(UriLexer.SEARCHPHRASE);
*
* // Test lexer rule ODATAIDENTIFIER
* test.run("abc").isInput().isType(UriLexer.ODATAIDENTIFIER);
*
* test.run("\"abc\"").isInput().isType(UriLexer.STRING_IN_JSON);
* }
*/
@Test @Test
public void testDelims() { public void testDelims() {
String reserved = "/"; String reserved = "/";
@ -383,27 +245,6 @@ public class TestLexer {
// Test lexer rule PCHAR all // Test lexer rule PCHAR all
test.run("$format=" + cPCHAR + "/" + cPCHAR).isAllInput().isType(UriLexer.FORMAT); test.run("$format=" + cPCHAR + "/" + cPCHAR).isAllInput().isType(UriLexer.FORMAT);
/*
* test.run("$format=" + cPCHAR + "/" + cPCHAR + reserved)
* .isType(UriLexer.FORMAT).at(4)
* .isText(cPCHAR);
*/
// Test lexer rule QCHAR_NO_AMP
// String amp = "&";
// Test lexer rule UNRESERVED
// test.run("$id=" + cUNRESERVED).isAllInput().isType(UriLexer.ID);
// test.run("$id=" + cUNRESERVED + amp).isType(UriLexer.ID).at(2).isText(cUNRESERVED);
// Test lexer rule PCT_ENCODED
// test.run("$id=" + cPCT_ENCODED).isAllInput().isType(UriLexer.ID);
// test.run("$id=" + cPCT_ENCODED + amp).isType(UriLexer.ID).at(2).isText(cPCT_ENCODED);
// Test lexer rule OTHER_DELIMS
// test.run("$id=" + cOTHER_DELIMS).isAllInput().isType(UriLexer.ID);
// test.run("$id=" + cOTHER_DELIMS + amp).isType(UriLexer.ID).at(2).isText(cOTHER_DELIMS);
// Lexer rule QCHAR_NO_AMP rest
// test.run("$id=:@/?$'=").isAllText("$id=:@/?$'=").isType(UriLexer.ID);
// test.run("$id=:@/?$'=" + amp).isType(UriLexer.ID).at(2).isText(":@/?$'=");
} }
} }

View File

@ -104,69 +104,57 @@ public class TestUriParserImpl {
testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()") testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameString) .isType(EdmTechProvider.nameString, false);
.isCollection(false);
// returning collection of primitive // returning collection of primitive
testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()") testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameString) .isType(EdmTechProvider.nameString, true);
.isCollection(true);
// returning single complex // returning single complex
testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()") testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameCTTwoPrim) .isType(EdmTechProvider.nameCTTwoPrim, false);
.isCollection(false);
// returning collection of complex // returning collection of complex
testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()") testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameCTTwoPrim) .isType(EdmTechProvider.nameCTTwoPrim, true);
.isCollection(true);
// returning single entity // returning single entity
testRes.run( testRes.run(
esTwoKeyNav + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()") esTwoKeyNav + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, false)
.isTypeFilterOnEntry(EdmTechProvider.nameETBaseTwoKeyNav) .isTypeFilterOnEntry(EdmTechProvider.nameETBaseTwoKeyNav)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, false);
.isCollection(false);
// returning collection of entity (aka entitySet) // returning collection of entity (aka entitySet)
testRes.run(esTwoKeyNav + "/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()") testRes.run(esTwoKeyNav + "/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, false)
.isCollection(false)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.function) .isUriPathInfoKind(UriResourceKind.function)
.isType(EdmTechProvider.nameETTwoKeyNav) .isType(EdmTechProvider.nameETTwoKeyNav, true);
.isCollection(true);
} }
@Test @Test
@ -212,8 +200,7 @@ public class TestUriParserImpl {
testRes.run("ESAllPrim/$count") testRes.run("ESAllPrim/$count")
.at(0) .at(0)
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETAllPrim) .isType(EdmTechProvider.nameETAllPrim,true)
.isCollection(true)
.at(1) .at(1)
.isUriPathInfoKind(UriResourceKind.count); .isUriPathInfoKind(UriResourceKind.count);
@ -517,10 +504,9 @@ public class TestUriParserImpl {
testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase") testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase")
.at(0) .at(0)
.isEntitySet("ESTwoPrim") .isEntitySet("ESTwoPrim")
.isType(EdmTechProvider.nameETTwoPrim) .isType(EdmTechProvider.nameETTwoPrim,true)
.isTypeFilterOnCollection(EdmTechProvider.nameETBase) .isTypeFilterOnCollection(EdmTechProvider.nameETBase)
.isTypeFilterOnEntry(null) .isTypeFilterOnEntry(null);
.isCollection(true);
// filter before key predicate // filter before key predicate
testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)") testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)")
@ -531,9 +517,8 @@ public class TestUriParserImpl {
.isTypeFilterOnCollection(EdmTechProvider.nameETBase) .isTypeFilterOnCollection(EdmTechProvider.nameETBase)
.isTypeFilterOnEntry(null) .isTypeFilterOnEntry(null)
.at(0) .at(0)
.isType(EdmTechProvider.nameETTwoPrim) .isType(EdmTechProvider.nameETTwoPrim,false)
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1");
.isCollection(false);
// filter before key predicate; property of sub type // filter before key predicate; property of sub type
testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)/AdditionalPropertyString_5") testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)/AdditionalPropertyString_5")
@ -553,11 +538,10 @@ public class TestUriParserImpl {
.at(0) .at(0)
.isEntitySet("ESTwoPrim") .isEntitySet("ESTwoPrim")
.isUriPathInfoKind(UriResourceKind.entitySet) .isUriPathInfoKind(UriResourceKind.entitySet)
.isType(EdmTechProvider.nameETTwoPrim) .isType(EdmTechProvider.nameETTwoPrim,false)
.isTypeFilterOnCollection(null) .isTypeFilterOnCollection(null)
.isTypeFilterOnEntry(EdmTechProvider.nameETBase) .isTypeFilterOnEntry(EdmTechProvider.nameETBase)
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1");
.isCollection(false);
// filter after key predicate; property of sub type // filter after key predicate; property of sub type
testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase/AdditionalPropertyString_5") testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")

View File

@ -161,7 +161,7 @@ public class QueryOptionTest {
@Test @Test
public void testInlineCountImpl() { public void testInlineCountImpl() {
CountOptionImpl option = new CountOptionImpl(); CountOptionImpl option = new CountOptionImpl();
assertEquals(SupportedQueryOptions.INLINECOUNT, option.getKind()); assertEquals(SupportedQueryOptions.COUNT, option.getKind());
assertEquals(false, option.getValue()); assertEquals(false, option.getValue());
option.setValue(true); option.setValue(true);

View File

@ -26,7 +26,6 @@ import java.util.List;
import org.antlr.v4.runtime.ParserRuleContext; import org.antlr.v4.runtime.ParserRuleContext;
import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser; import org.apache.olingo.odata4.server.core.uri.antlr.UriParserParser;
// TODO extend to test also exception which can occure while paring
public class ParserValidator { public class ParserValidator {
private String input = null; private String input = null;
@ -55,7 +54,6 @@ public class ParserValidator {
} }
/** /**
* TODO verify
* Used in fast LL Parsing: * Used in fast LL Parsing:
* Don't stop 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 * required
@ -67,8 +65,6 @@ public class ParserValidator {
} }
/** /**
*
* TODO verify
* Used in fast LL Parsing: * Used in fast LL Parsing:
* Allows ContextSensitifity Errors which occur often when using the slower full context 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). * and indicate that there is a context sensitivity ( which may not be an error).
@ -80,7 +76,6 @@ public class ParserValidator {
} }
/** /**
* TODO verify
* Used in fast LL Parsing: * Used in fast LL Parsing:
* Allows ambiguities * Allows ambiguities
* @return * @return
@ -164,80 +159,4 @@ public class ParserValidator {
return this; return this;
} }
// --- Helper ---
/*
* private OdataRelativeUriEOFContext parseInput(final String input) {
* UriParserParser parser = null;
* UriLexerWithTrace lexer = null;
* OdataRelativeUriEOFContext ret = null;
*
* // Use 2 stage approach to improve performance
* // see https://github.com/antlr/antlr4/issues/192
* // TODO verify this
*
* // stage= 1
* try {
* curException = null;
* exceptions.clear();
*
* // create parser
* lexer = new UriLexerWithTrace(new ANTLRInputStream(input), lexerLogLevel);
* parser = new UriParserParser(new CommonTokenStream(lexer));
*
* // write always a error message in case of syntax errors
* // parser.addErrorListener(new TestErrorHandler<Object>());
* // check error message if whether they are allowed or not
* // parser.addErrorListener(new ErrorCollector());
*
* // bail out of parser at first syntax error. --> proceed in catch block with step 2
* parser.setErrorHandler(new BailErrorStrategy());
*
* // user the faster SLL parsing
* parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
*
* // parse
* if (logLevel > 0) {
* System.out.println("Step 1");
* System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode());
* }
* ret = parser.odataRelativeUriEOF();
*
* } catch (Exception exception) {
* curException = exception;
* try {
* // clear status
* curException = null;
* exceptions.clear();
*
* // create parser
* lexer = new UriLexerWithTrace(new ANTLRInputStream(input), lexerLogLevel);
* parser = new UriParserParser(new CommonTokenStream(lexer));
*
* // write always a error message in case of syntax errors
* // parser.addErrorListener(new ErrorCollector(this));
* // check error message if whether they are allowed or not
* // parser.addErrorListener(new ErrorCollector(this));
*
* // Used default error strategy
* parser.setErrorHandler(new DefaultErrorStrategy());
*
* // User the slower SLL parsing
* parser.getInterpreter().setPredictionMode(PredictionMode.LL);
*
* // parse
* if (logLevel > 1) {
* System.out.println("Step 2");
* System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode() + ")");
* }
* ret = parser.odataRelativeUriEOF();
*
* } catch (Exception exception1) {
* curException = exception1;
* // exceptionOnStage = 2;
* }
* }
*
* return ret;
* }
*/
} }

View File

@ -327,7 +327,7 @@ public class ResourceValidator implements Validator {
} }
// TODO remove // TODO remove
public ResourceValidator isCollection(final boolean isCollection) { /*public ResourceValidator isCollection(final boolean isCollection) {
if (!(uriPathInfo instanceof UriResourcePartTyped)) { if (!(uriPathInfo instanceof UriResourcePartTyped)) {
fail("invalid resource kind: " + uriPathInfo.getKind().toString()); fail("invalid resource kind: " + uriPathInfo.getKind().toString());
} }
@ -339,7 +339,7 @@ public class ResourceValidator implements Validator {
} }
assertEquals(isCollection, uriPathInfoTyped.isCollection()); assertEquals(isCollection, uriPathInfoTyped.isCollection());
return this; return this;
} }*/
public ResourceValidator isFilterString(final String expectedFilterTreeAsString) { public ResourceValidator isFilterString(final String expectedFilterTreeAsString) {
@ -369,6 +369,19 @@ public class ResourceValidator implements Validator {
} }
public ResourceValidator isKeyPredicateAlias(final int index, final String name, final String alias) {
if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
fail("invalid resource kind: " + uriPathInfo.getKind().toString());
}
UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo;
List<UriParameter> keyPredicates = info.getKeyPredicates();
assertEquals(name, keyPredicates.get(index).getName());
assertEquals(alias, keyPredicates.get(index).getAlias());
return this;
}
public ResourceValidator isKeyPredicate(final int index, final String name, final String text) { public ResourceValidator isKeyPredicate(final int index, final String name, final String text) {
if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
fail("invalid resource kind: " + uriPathInfo.getKind().toString()); fail("invalid resource kind: " + uriPathInfo.getKind().toString());