better segment handling in server URI parser

Change-Id: Id9b20d66f878c44c3d60cc5cfc2214d3692e1603

Signed-off-by: Christian Amend <chrisam@apache.org>
This commit is contained in:
Klaus Straubinger 2014-10-02 08:47:30 +02:00 committed by Christian Amend
parent 11bee5dc0e
commit aaa0916188
12 changed files with 484 additions and 531 deletions

View File

@ -89,9 +89,6 @@ public class ODataHandler {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null); ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, null); handleException(request, response, serverError, null);
} catch (ODataHandlerException e) { } catch (ODataHandlerException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, null);
} catch (ODataTranslatedException e) {
ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null); ODataServerError serverError = ODataExceptionHelper.createServerErrorObject(e, null);
handleException(request, response, serverError, requestedContentType); handleException(request, response, serverError, requestedContentType);
} catch (ODataApplicationException e) { } catch (ODataApplicationException e) {
@ -106,14 +103,12 @@ public class ODataHandler {
private void processInternal(final ODataRequest request, ContentType requestedContentType, private void processInternal(final ODataRequest request, ContentType requestedContentType,
final ODataResponse response) final ODataResponse response)
throws ODataTranslatedException, UriParserException, UriValidationException, ContentNegotiatorException, throws ODataHandlerException, UriParserException, UriValidationException, ContentNegotiatorException,
ODataApplicationException { ODataApplicationException {
validateODataVersion(request, response); validateODataVersion(request, response);
Parser parser = new Parser(); Parser parser = new Parser();
String odUri = final UriInfo uriInfo = parser.parseUri(request.getRawODataPath(), request.getRawQueryPath(), null, edm);
request.getRawODataPath() + (request.getRawQueryPath() == null ? "" : "?" + request.getRawQueryPath());
UriInfo uriInfo = parser.parseUri(odUri, edm);
UriValidator validator = new UriValidator(); UriValidator validator = new UriValidator();
validator.validate(uriInfo, request.getMethod()); validator.validate(uriInfo, request.getMethod());
@ -165,7 +160,7 @@ public class ODataHandler {
} }
private void handleResourceDispatching(final ODataRequest request, final ODataResponse response, private void handleResourceDispatching(final ODataRequest request, final ODataResponse response,
final UriInfo uriInfo) throws ODataTranslatedException { final UriInfo uriInfo) throws ODataHandlerException, ContentNegotiatorException {
int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1; int lastPathSegmentIndex = uriInfo.getUriResourceParts().size() - 1;
UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex); UriResource lastPathSegment = uriInfo.getUriResourceParts().get(lastPathSegmentIndex);
ContentType requestedContentType = null; ContentType requestedContentType = null;
@ -243,7 +238,7 @@ public class ODataHandler {
} }
private void validateODataVersion(final ODataRequest request, final ODataResponse response) private void validateODataVersion(final ODataRequest request, final ODataResponse response)
throws ODataTranslatedException { throws ODataHandlerException {
String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION); String maxVersion = request.getHeader(HttpHeader.ODATA_MAX_VERSION);
response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString()); response.setHeader(HttpHeader.ODATA_VERSION, ODataServiceVersion.V40.toString());
@ -255,8 +250,7 @@ public class ODataHandler {
} }
} }
private <T extends Processor> T selectProcessor(final Class<T> cls) private <T extends Processor> T selectProcessor(final Class<T> cls) throws ODataHandlerException {
throws ODataTranslatedException {
@SuppressWarnings("unchecked") @SuppressWarnings("unchecked")
T p = (T) processors.get(cls); T p = (T) processors.get(cls);
@ -279,4 +273,4 @@ public class ODataHandler {
} }
} }
} }
} }

View File

@ -76,62 +76,58 @@ public class Parser {
return this; return this;
} }
public UriInfo parseUri(final String input, final Edm edm) throws UriParserException { public UriInfo parseUri(final String path, final String query, final String fragment, final Edm edm)
throws UriParserException {
boolean readQueryParameter = false;
boolean readFragment = false;
UriContext context = new UriContext(); UriContext context = new UriContext();
UriParseTreeVisitor uriParseTreeVisitor = new UriParseTreeVisitor(edm, context); UriParseTreeVisitor uriParseTreeVisitor = new UriParseTreeVisitor(edm, context);
try { try {
RawUri uri = UriDecoder.decodeUri(input, 0); // -> 0 segments are before the service url final RawUri uri = UriDecoder.decodeUri(path, query, fragment, 0); // -> 0 segments are before the service url
// first, read the decoded path segments // first, read the decoded path segments
String firstSegment = ""; final String firstSegment = uri.pathSegmentListDecoded.isEmpty() ? "" : uri.pathSegmentListDecoded.get(0);
if (uri.pathSegmentListDecoded.size() > 0) {
firstSegment = uri.pathSegmentListDecoded.get(0);
}
if (firstSegment.length() == 0) { if (firstSegment.isEmpty()) {
readQueryParameter = true; ensureLastSegment(firstSegment, 0, uri.pathSegmentListDecoded.size());
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.service); context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.service);
} else if (firstSegment.startsWith("$batch")) { } else if (firstSegment.startsWith("$batch")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
BatchEOFContext ctxBatchEOF = BatchEOFContext ctxBatchEOF =
(BatchEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Batch); (BatchEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Batch);
uriParseTreeVisitor.visitBatchEOF(ctxBatchEOF); uriParseTreeVisitor.visitBatchEOF(ctxBatchEOF);
readQueryParameter = true;
} else if (firstSegment.startsWith("$metadata")) { } else if (firstSegment.startsWith("$metadata")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
MetadataEOFContext ctxMetadataEOF = MetadataEOFContext ctxMetadataEOF =
(MetadataEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Metadata); (MetadataEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Metadata);
uriParseTreeVisitor.visitMetadataEOF(ctxMetadataEOF); uriParseTreeVisitor.visitMetadataEOF(ctxMetadataEOF);
readQueryParameter = true;
readFragment = true; context.contextUriInfo.setFragment(uri.fragment);
} else if (firstSegment.startsWith("$entity")) { } else if (firstSegment.startsWith("$entity")) {
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.entityId); context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.entityId);
if (uri.pathSegmentListDecoded.size() > 1) { if (uri.pathSegmentListDecoded.size() > 1) {
final String typeCastSegment = uri.pathSegmentListDecoded.get(1);
ensureLastSegment(typeCastSegment, 2, uri.pathSegmentListDecoded.size());
EntityEOFContext ctxEntityEOF = EntityEOFContext ctxEntityEOF =
(EntityEOFContext) parseRule(uri.pathSegmentListDecoded.get(1), ParserEntryRules.Entity); (EntityEOFContext) parseRule(typeCastSegment, ParserEntryRules.Entity);
uriParseTreeVisitor.visitEntityEOF(ctxEntityEOF); uriParseTreeVisitor.visitEntityEOF(ctxEntityEOF);
} }
readQueryParameter = true;
} else if (firstSegment.startsWith("$all")) { } else if (firstSegment.startsWith("$all")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
AllEOFContext ctxResourcePathEOF = AllEOFContext ctxResourcePathEOF =
(AllEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.All); (AllEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.All);
uriParseTreeVisitor.visitAllEOF(ctxResourcePathEOF); uriParseTreeVisitor.visitAllEOF(ctxResourcePathEOF);
readQueryParameter = true;
} else if (firstSegment.startsWith("$crossjoin")) { } else if (firstSegment.startsWith("$crossjoin")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
CrossjoinEOFContext ctxResourcePathEOF = CrossjoinEOFContext ctxResourcePathEOF =
(CrossjoinEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.CrossJoin); (CrossjoinEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.CrossJoin);
uriParseTreeVisitor.visitCrossjoinEOF(ctxResourcePathEOF); uriParseTreeVisitor.visitCrossjoinEOF(ctxResourcePathEOF);
readQueryParameter = true;
} else { } else {
List<PathSegmentEOFContext> ctxPathSegments = new ArrayList<PathSegmentEOFContext>(); List<PathSegmentEOFContext> ctxPathSegments = new ArrayList<PathSegmentEOFContext>();
for (String pathSegment : uri.pathSegmentListDecoded) { for (String pathSegment : uri.pathSegmentListDecoded) {
@ -155,141 +151,131 @@ public class Parser {
UriParseTreeVisitor.TypeInformation typeInfo = UriParseTreeVisitor.TypeInformation typeInfo =
uriParseTreeVisitor.new TypeInformation(myType.type, typed.isCollection()); uriParseTreeVisitor.new TypeInformation(myType.type, typed.isCollection());
context.contextTypes.push(typeInfo); context.contextTypes.push(typeInfo);
} }
readQueryParameter = true;
} }
if (readQueryParameter) { // second, read the system query options and the custom query options
// second, read the system query options and the custom query options for (RawUri.QueryOption option : uri.queryOptionListDecoded) {
for (RawUri.QueryOption option : uri.queryOptionListDecoded) { if (option.name.startsWith("$")) {
if (option.name.startsWith("$")) { SystemQueryOption systemOption = null;
SystemQueryOption systemOption = null; if (option.name.equals(SystemQueryOptionKind.FILTER.toString())) {
if (option.name.equals(SystemQueryOptionKind.FILTER.toString())) { FilterExpressionEOFContext ctxFilterExpression =
FilterExpressionEOFContext ctxFilterExpression = (FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
(FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
FilterOptionImpl filterOption = FilterOptionImpl filterOption =
(FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression); (FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
systemOption = filterOption; systemOption = filterOption;
} else if (option.name.equals(SystemQueryOptionKind.FORMAT.toString())) { } else if (option.name.equals(SystemQueryOptionKind.FORMAT.toString())) {
FormatOptionImpl formatOption = new FormatOptionImpl(); FormatOptionImpl formatOption = new FormatOptionImpl();
formatOption.setName(option.name); formatOption.setName(option.name);
formatOption.setText(option.value); formatOption.setText(option.value);
if (option.value.equalsIgnoreCase(ODataFormat.JSON.name()) if (option.value.equalsIgnoreCase(ODataFormat.JSON.name())
|| option.value.equalsIgnoreCase(ODataFormat.XML.name()) || option.value.equalsIgnoreCase(ODataFormat.XML.name())
|| option.value.equalsIgnoreCase(ODataFormat.ATOM.name()) || option.value.equalsIgnoreCase(ODataFormat.ATOM.name())
|| isFormatSyntaxValid(option)) { || isFormatSyntaxValid(option.value)) {
formatOption.setFormat(option.value); formatOption.setFormat(option.value);
} else {
throw new UriParserSyntaxException("Illegal value of $format option!",
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT, option.value);
}
systemOption = formatOption;
} else if (option.name.equals(SystemQueryOptionKind.EXPAND.toString())) {
ExpandItemsEOFContext ctxExpandItems =
(ExpandItemsEOFContext) parseRule(option.value, ParserEntryRules.ExpandItems);
ExpandOptionImpl expandOption =
(ExpandOptionImpl) uriParseTreeVisitor.visitExpandItemsEOF(ctxExpandItems);
systemOption = expandOption;
} else if (option.name.equals(SystemQueryOptionKind.ID.toString())) {
IdOptionImpl idOption = new IdOptionImpl();
idOption.setName(option.name);
idOption.setText(option.value);
idOption.setValue(option.value);
systemOption = idOption;
} else if (option.name.equals(SystemQueryOptionKind.LEVELS.toString())) {
throw new UriParserSyntaxException("System query option '$levels' is allowed only inside '$expand'!",
UriParserSyntaxException.MessageKeys.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE);
} else if (option.name.equals(SystemQueryOptionKind.ORDERBY.toString())) {
OrderByEOFContext ctxOrderByExpression =
(OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
OrderByOptionImpl orderByOption =
(OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxOrderByExpression);
systemOption = orderByOption;
} else if (option.name.equals(SystemQueryOptionKind.SEARCH.toString())) {
throw new RuntimeException("System query option '$search' not implemented!");
} else if (option.name.equals(SystemQueryOptionKind.SELECT.toString())) {
SelectEOFContext ctxSelectEOF =
(SelectEOFContext) parseRule(option.value, ParserEntryRules.Select);
SelectOptionImpl selectOption =
(SelectOptionImpl) uriParseTreeVisitor.visitSelectEOF(ctxSelectEOF);
systemOption = selectOption;
} else if (option.name.equals(SystemQueryOptionKind.SKIP.toString())) {
SkipOptionImpl skipOption = new SkipOptionImpl();
skipOption.setName(option.name);
skipOption.setText(option.value);
try {
skipOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSyntaxException("Illegal value of $skip option!", e,
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = skipOption;
} else if (option.name.equals(SystemQueryOptionKind.SKIPTOKEN.toString())) {
SkipTokenOptionImpl skipTokenOption = new SkipTokenOptionImpl();
skipTokenOption.setName(option.name);
skipTokenOption.setText(option.value);
skipTokenOption.setValue(option.value);
systemOption = skipTokenOption;
} else if (option.name.equals(SystemQueryOptionKind.TOP.toString())) {
TopOptionImpl topOption = new TopOptionImpl();
topOption.setName(option.name);
topOption.setText(option.value);
try {
topOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSyntaxException("Illegal value of $top option!", e,
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = topOption;
} else if (option.name.equals(SystemQueryOptionKind.COUNT.toString())) {
CountOptionImpl inlineCountOption = new CountOptionImpl();
inlineCountOption.setName(option.name);
inlineCountOption.setText(option.value);
if (option.value.equals("true") || option.value.equals("false")) {
inlineCountOption.setValue(Boolean.parseBoolean(option.value));
} else {
throw new UriParserSyntaxException("Illegal value of $count option!",
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = inlineCountOption;
} else { } else {
throw new UriParserSyntaxException("Unknown system query option!", throw new UriParserSyntaxException("Illegal value of $format option!",
UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION, option.name); UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT, option.value);
} }
try { systemOption = formatOption;
context.contextUriInfo.setSystemQueryOption(systemOption);
} catch (final ODataRuntimeException e) {
throw new UriParserSyntaxException("Double system query option!", e,
UriParserSyntaxException.MessageKeys.DOUBLE_SYSTEM_QUERY_OPTION, option.name);
}
} else {
CustomQueryOptionImpl customOption = new CustomQueryOptionImpl();
customOption.setName(option.name);
customOption.setText(option.value);
context.contextUriInfo.addCustomQueryOption(customOption);
}
}
}
if (readFragment) { } else if (option.name.equals(SystemQueryOptionKind.EXPAND.toString())) {
context.contextUriInfo.setFragment(uri.fragment); ExpandItemsEOFContext ctxExpandItems =
(ExpandItemsEOFContext) parseRule(option.value, ParserEntryRules.ExpandItems);
ExpandOptionImpl expandOption =
(ExpandOptionImpl) uriParseTreeVisitor.visitExpandItemsEOF(ctxExpandItems);
systemOption = expandOption;
} else if (option.name.equals(SystemQueryOptionKind.ID.toString())) {
IdOptionImpl idOption = new IdOptionImpl();
idOption.setName(option.name);
idOption.setText(option.value);
idOption.setValue(option.value);
systemOption = idOption;
} else if (option.name.equals(SystemQueryOptionKind.LEVELS.toString())) {
throw new UriParserSyntaxException("System query option '$levels' is allowed only inside '$expand'!",
UriParserSyntaxException.MessageKeys.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE);
} else if (option.name.equals(SystemQueryOptionKind.ORDERBY.toString())) {
OrderByEOFContext ctxOrderByExpression =
(OrderByEOFContext) parseRule(option.value, ParserEntryRules.Orderby);
OrderByOptionImpl orderByOption =
(OrderByOptionImpl) uriParseTreeVisitor.visitOrderByEOF(ctxOrderByExpression);
systemOption = orderByOption;
} else if (option.name.equals(SystemQueryOptionKind.SEARCH.toString())) {
throw new RuntimeException("System query option '$search' not implemented!");
} else if (option.name.equals(SystemQueryOptionKind.SELECT.toString())) {
SelectEOFContext ctxSelectEOF =
(SelectEOFContext) parseRule(option.value, ParserEntryRules.Select);
SelectOptionImpl selectOption =
(SelectOptionImpl) uriParseTreeVisitor.visitSelectEOF(ctxSelectEOF);
systemOption = selectOption;
} else if (option.name.equals(SystemQueryOptionKind.SKIP.toString())) {
SkipOptionImpl skipOption = new SkipOptionImpl();
skipOption.setName(option.name);
skipOption.setText(option.value);
try {
skipOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSyntaxException("Illegal value of $skip option!", e,
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = skipOption;
} else if (option.name.equals(SystemQueryOptionKind.SKIPTOKEN.toString())) {
SkipTokenOptionImpl skipTokenOption = new SkipTokenOptionImpl();
skipTokenOption.setName(option.name);
skipTokenOption.setText(option.value);
skipTokenOption.setValue(option.value);
systemOption = skipTokenOption;
} else if (option.name.equals(SystemQueryOptionKind.TOP.toString())) {
TopOptionImpl topOption = new TopOptionImpl();
topOption.setName(option.name);
topOption.setText(option.value);
try {
topOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSyntaxException("Illegal value of $top option!", e,
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = topOption;
} else if (option.name.equals(SystemQueryOptionKind.COUNT.toString())) {
CountOptionImpl inlineCountOption = new CountOptionImpl();
inlineCountOption.setName(option.name);
inlineCountOption.setText(option.value);
if (option.value.equals("true") || option.value.equals("false")) {
inlineCountOption.setValue(Boolean.parseBoolean(option.value));
} else {
throw new UriParserSyntaxException("Illegal value of $count option!",
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
option.name, option.value);
}
systemOption = inlineCountOption;
} else {
throw new UriParserSyntaxException("Unknown system query option!",
UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION, option.name);
}
try {
context.contextUriInfo.setSystemQueryOption(systemOption);
} catch (final ODataRuntimeException e) {
throw new UriParserSyntaxException("Double system query option!", e,
UriParserSyntaxException.MessageKeys.DOUBLE_SYSTEM_QUERY_OPTION, option.name);
}
} else {
CustomQueryOptionImpl customOption = new CustomQueryOptionImpl();
customOption.setName(option.name);
customOption.setText(option.value);
context.contextUriInfo.addCustomQueryOption(customOption);
}
} }
return context.contextUriInfo; return context.contextUriInfo;
@ -300,9 +286,17 @@ public class Parser {
} }
} }
private boolean isFormatSyntaxValid(RawUri.QueryOption option) { private void ensureLastSegment(final String segment, final int pos, final int size)
final int index = option.value.indexOf('/'); throws UriParserSyntaxException {
return index > 0 && index < option.value.length() - 1 && index == option.value.lastIndexOf('/'); if (pos < size) {
throw new UriParserSyntaxException(segment + " must be the last segment.",
UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT, segment);
}
}
private boolean isFormatSyntaxValid(final String value) {
final int index = value.indexOf('/');
return index > 0 && index < value.length() - 1 && index == value.lastIndexOf('/');
} }
private ParserRuleContext parseRule(final String input, final ParserEntryRules entryPoint) private ParserRuleContext parseRule(final String input, final ParserEntryRules entryPoint)

View File

@ -19,69 +19,57 @@
package org.apache.olingo.server.core.uri.parser; package org.apache.olingo.server.core.uri.parser;
import org.apache.olingo.commons.core.Decoder; import org.apache.olingo.commons.core.Decoder;
import org.apache.olingo.server.core.uri.parser.RawUri.QueryOption;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.LinkedList; import java.util.LinkedList;
import java.util.List; import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
public class UriDecoder { public class UriDecoder {
private static final Pattern uriPattern = public static RawUri decodeUri(final String path, final String query, final String fragment,
Pattern.compile("^(([^:/?#]+):)?(//([^/?#]*))?([^?#]*)(\\?([^#]*))?(#(.*))?"); final int skipSegments) throws UriParserSyntaxException {
public static RawUri decodeUri(final String uri, final int skipSegments) throws UriParserSyntaxException {
RawUri rawUri = new RawUri(); RawUri rawUri = new RawUri();
Matcher m = uriPattern.matcher(uri); rawUri.path = path;
if (m.matches()) { rawUri.queryOptionString = query;
rawUri.scheme = m.group(2); rawUri.fragment = fragment;
rawUri.authority = m.group(4);
rawUri.path = m.group(5);
rawUri.queryOptionString = m.group(7);
rawUri.fragment = m.group(9);
}
splitPath(rawUri, skipSegments); rawUri.pathSegmentList = splitPath(path, skipSegments);
splitOptions(rawUri); rawUri.queryOptionList = splitOptions(query);
decode(rawUri); decode(rawUri);
return rawUri; return rawUri;
} }
private static void decode(final RawUri rawUri) throws UriParserSyntaxException { private static void decode(RawUri rawUri) throws UriParserSyntaxException {
rawUri.pathSegmentListDecoded = new ArrayList<String>(); rawUri.pathSegmentListDecoded = new ArrayList<String>();
for (String segment : rawUri.pathSegmentList) { for (String segment : rawUri.pathSegmentList) {
rawUri.pathSegmentListDecoded.add(decode(segment)); rawUri.pathSegmentListDecoded.add(decode(segment));
} }
rawUri.queryOptionListDecoded = new ArrayList<QueryOption>(); rawUri.queryOptionListDecoded = new ArrayList<RawUri.QueryOption>();
for (QueryOption optionPair : rawUri.queryOptionList) { for (RawUri.QueryOption optionPair : rawUri.queryOptionList) {
rawUri.queryOptionListDecoded.add(new QueryOption( rawUri.queryOptionListDecoded.add(new RawUri.QueryOption(
decode(optionPair.name), decode(optionPair.name),
decode(optionPair.value))); decode(optionPair.value)));
} }
} }
private static void splitOptions(final RawUri rawUri) { private static List<RawUri.QueryOption> splitOptions(final String queryOptionString) {
rawUri.queryOptionList = new ArrayList<RawUri.QueryOption>(); if (queryOptionString == null) {
return Collections.<RawUri.QueryOption> emptyList();
if (rawUri.queryOptionString == null) {
return;
} }
List<String> options = split(rawUri.queryOptionString, '&'); List<RawUri.QueryOption> queryOptionList = new ArrayList<RawUri.QueryOption>();
for (String option : split(queryOptionString, '&')) {
for (String option : options) {
if (option.length() != 0) { if (option.length() != 0) {
List<String> pair = splitFirst(option, '='); final List<String> pair = splitFirst(option, '=');
rawUri.queryOptionList.add( queryOptionList.add(new RawUri.QueryOption(pair.get(0), pair.get(1)));
new RawUri.QueryOption(pair.get(0), pair.get(1)));
} }
} }
return queryOptionList;
} }
private static List<String> splitFirst(final String input, final char c) { private static List<String> splitFirst(final String input, final char c) {
@ -93,16 +81,16 @@ public class UriDecoder {
} }
} }
public static void splitPath(final RawUri rawUri, int skipSegments) { private static List<String> splitPath(final String path, int skipSegments) {
List<String> list = split(rawUri.path, '/'); List<String> list = split(path, '/');
if (list.get(0).length() == 0) { // Empty path segments of the resource path are removed.
skipSegments++; while (list.remove("")) {
// this place intentionally left blank
;
} }
rawUri.pathSegmentList = skipSegments > 0 ? return skipSegments > 0 ? list.subList(skipSegments, list.size()) : list;
list.subList(skipSegments, list.size()) :
list;
} }
public static List<String> split(final String input, final char c) { public static List<String> split(final String input, final char c) {

View File

@ -24,12 +24,13 @@ public class UriParserSyntaxException extends UriParserException {
private static final long serialVersionUID = 5887744747812478226L; private static final long serialVersionUID = 5887744747812478226L;
public static enum MessageKeys implements MessageKey { public static enum MessageKeys implements MessageKey {
/** parameter: segment */ MUST_BE_LAST_SEGMENT,
/** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION, /** parameter: query-option name */ UNKNOWN_SYSTEM_QUERY_OPTION,
/** parameter: query-option name */ DOUBLE_SYSTEM_QUERY_OPTION, /** parameter: query-option name */ DOUBLE_SYSTEM_QUERY_OPTION,
/** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION, /** parameters: query-option name, query-option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION,
SYNTAX, /** parameter: $format option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT,
SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE, SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE,
/** parameter: $format option value */ WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT; SYNTAX;
@Override @Override
public String getKey() { public String getKey() {

View File

@ -24,12 +24,13 @@ ODataHandlerException.PROCESSOR_NOT_IMPLEMENTED=No processor for interface '%1$s
ODataHandlerException.FUNCTIONALITY_NOT_IMPLEMENTED=The requested functionality has not been implemented (yet). ODataHandlerException.FUNCTIONALITY_NOT_IMPLEMENTED=The requested functionality has not been implemented (yet).
ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported. ODataHandlerException.ODATA_VERSION_NOT_SUPPORTED=OData version '%1$s' is not supported.
UriParserSyntaxException.MUST_BE_LAST_SEGMENT=The segment '%1$s' must be the last segment.
UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined. UriParserSyntaxException.UNKNOWN_SYSTEM_QUERY_OPTION=The system query option '%1$s' is not defined.
UriParserSyntaxException.DOUBLE_SYSTEM_QUERY_OPTION=The system query option '%1$s' can be specified only once. UriParserSyntaxException.DOUBLE_SYSTEM_QUERY_OPTION=The system query option '%1$s' can be specified only once.
UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'. UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION=The system query option '%1$s' has the not-allowed value '%2$s'.
UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system query option '$format' must be either 'json', 'xml', 'atom', or a valid content type; the value '%1$s' is neither. UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system query option '$format' must be either 'json', 'xml', 'atom', or a valid content type; the value '%1$s' is neither.
UriParserSyntaxException.SYNTAX=The URI is malformed.
UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here. UriParserSyntaxException.SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE=The system query option '$levels' is not allowed here.
UriParserSyntaxException.SYNTAX=The URI is malformed.
UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no function with parameters '%2$s'. UriParserSemanticException.FUNCTION_NOT_FOUND=The function import '%1$s' has no function with parameters '%2$s'.
UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts. UriParserSemanticException.RESOURCE_PART_ONLY_FOR_TYPED_PARTS='%1$s' is only allowed for typed parts.

View File

@ -23,53 +23,54 @@ import org.apache.olingo.server.core.uri.parser.UriDecoder;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections;
import java.util.List; import java.util.List;
import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertEquals;
public class RawUriTest { public class RawUriTest {
private RawUri runRawParser(final String uri, final int skipSegments) throws UriParserSyntaxException { private RawUri runRawParser(final String path, final String query, final int skipSegments)
return UriDecoder.decodeUri(uri, skipSegments); throws UriParserSyntaxException {
return UriDecoder.decodeUri(path, query, null, skipSegments);
} }
@Test @Test
public void testOption() throws Exception { public void testOption() throws Exception {
RawUri rawUri; RawUri rawUri;
rawUri = runRawParser("?", 0); rawUri = runRawParser("", "", 0);
checkOptionCount(rawUri, 0); checkOptionCount(rawUri, 0);
rawUri = runRawParser("?a", 0); rawUri = runRawParser("", "a", 0);
checkOption(rawUri, 0, "a", ""); checkOption(rawUri, 0, "a", "");
rawUri = runRawParser("?a=b", 0); rawUri = runRawParser("", "a=b", 0);
checkOption(rawUri, 0, "a", "b"); checkOption(rawUri, 0, "a", "b");
rawUri = runRawParser("?=", 0); rawUri = runRawParser("", "=", 0);
checkOption(rawUri, 0, "", ""); checkOption(rawUri, 0, "", "");
rawUri = runRawParser("?=b", 0); rawUri = runRawParser("", "=b", 0);
checkOption(rawUri, 0, "", "b"); checkOption(rawUri, 0, "", "b");
rawUri = runRawParser("?a&c", 0); rawUri = runRawParser("", "a&c", 0);
checkOption(rawUri, 0, "a", ""); checkOption(rawUri, 0, "a", "");
checkOption(rawUri, 1, "c", ""); checkOption(rawUri, 1, "c", "");
rawUri = runRawParser("?a=b&c", 0); rawUri = runRawParser("", "a=b&c", 0);
checkOption(rawUri, 0, "a", "b"); checkOption(rawUri, 0, "a", "b");
checkOption(rawUri, 1, "c", ""); checkOption(rawUri, 1, "c", "");
rawUri = runRawParser("?a=b&c=d", 0); rawUri = runRawParser("", "a=b&c=d", 0);
checkOption(rawUri, 0, "a", "b"); checkOption(rawUri, 0, "a", "b");
checkOption(rawUri, 1, "c", "d"); checkOption(rawUri, 1, "c", "d");
rawUri = runRawParser("?=&=", 0); rawUri = runRawParser("", "=&=", 0);
checkOption(rawUri, 0, "", ""); checkOption(rawUri, 0, "", "");
checkOption(rawUri, 1, "", ""); checkOption(rawUri, 1, "", "");
rawUri = runRawParser("?=&c=d", 0); rawUri = runRawParser("", "=&c=d", 0);
checkOption(rawUri, 0, "", ""); checkOption(rawUri, 0, "", "");
checkOption(rawUri, 1, "c", "d"); checkOption(rawUri, 1, "c", "d");
} }
@ -89,40 +90,38 @@ public class RawUriTest {
public void testPath() throws Exception { public void testPath() throws Exception {
RawUri rawUri; RawUri rawUri;
rawUri = runRawParser("http://test.org", 0); rawUri = runRawParser("", null, 0);
checkPath(rawUri, "", new ArrayList<String>()); checkPath(rawUri, "", Collections.<String> emptyList());
rawUri = runRawParser("http://test.org/", 0); rawUri = runRawParser("/", null, 0);
checkPath(rawUri, "/", Arrays.asList("")); checkPath(rawUri, "/", Collections.<String> emptyList());
rawUri = runRawParser("http://test.org/entitySet", 0); rawUri = runRawParser("/entitySet", null, 0);
checkPath(rawUri, "/entitySet", Arrays.asList("entitySet")); checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 0); rawUri = runRawParser("//entitySet", null, 0);
checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); checkPath(rawUri, "//entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 1); rawUri = runRawParser("entitySet", null, 0);
checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("", 0);
checkPath(rawUri, "", new ArrayList<String>());
rawUri = runRawParser("/", 0);
checkPath(rawUri, "/", Arrays.asList(""));
rawUri = runRawParser("/entitySet", 0);
checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("entitySet", 0);
checkPath(rawUri, "entitySet", Arrays.asList("entitySet")); checkPath(rawUri, "entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("nonServiceSegment/entitySet", 0); rawUri = runRawParser("/nonServiceSegment/entitySet", null, 0);
checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
rawUri = runRawParser("/nonServiceSegment/entitySet", null, 1);
checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("nonServiceSegment/entitySet", null, 0);
checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
rawUri = runRawParser("nonServiceSegment/entitySet", 1); rawUri = runRawParser("nonServiceSegment/entitySet", null, 1);
checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet")); checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet"));
rawUri = runRawParser("http://test.org/a?abc=xx+yz", 0); rawUri = runRawParser("non//Service/Segment///entitySet/", null, 3);
checkPath(rawUri, "non//Service/Segment///entitySet/", Arrays.asList("entitySet"));
rawUri = runRawParser("/a", "abc=xx+yz", 0);
checkPath(rawUri, "/a", Arrays.asList("a"));
} }
@Test @Test
@ -140,15 +139,13 @@ public class RawUriTest {
assertEquals(list.size(), rawUri.pathSegmentListDecoded.size()); assertEquals(list.size(), rawUri.pathSegmentListDecoded.size());
int i = 0; for (int i = 0; i < list.size(); i++) {
while (i < list.size()) {
assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i)); assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i));
i++;
} }
} }
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void wrongPercentEncoding() throws Exception { public void wrongPercentEncoding() throws Exception {
runRawParser("%wrong", 0); runRawParser("%wrong", null, 0);
} }
} }

View File

@ -901,18 +901,18 @@ public class TestFullResourcePath {
@Test @Test
public void runCrossjoinError() throws Exception { public void runCrossjoinError() throws Exception {
testUri.runEx("$crossjoin").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); testUri.runEx("$crossjoin").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
testUri.runEx("$crossjoin/error").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); testUri.runEx("$crossjoin/error").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.runEx("$crossjoin()").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); testUri.runEx("$crossjoin()").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
// testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid") testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid")
// .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX); .isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
} }
@Test @Test
public void runEntityId() throws Exception { public void runEntityId() throws Exception {
testUri.run("$entity?$id=ESKeyNav(1)") testUri.run("$entity", "$id=ESKeyNav(1)")
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isIdText("ESKeyNav(1)"); .isIdText("ESKeyNav(1)");
testUri.run("$entity/olingo.odata.test1.ETKeyNav?$id=ESKeyNav(1)") testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=ESKeyNav(1)")
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isEntityType(EntityTypeProvider.nameETKeyNav) .isEntityType(EntityTypeProvider.nameETKeyNav)
.isIdText("ESKeyNav(1)"); .isIdText("ESKeyNav(1)");
@ -1823,9 +1823,9 @@ public class TestFullResourcePath {
@Test @Test
public void runFunctionImpEsAlias() throws Exception { public void runFunctionImpEsAlias() throws Exception {
testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)?@parameterAlias=1"); testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)", "@parameterAlias=1");
testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)/$count?@parameterAlias=1"); testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)/$count", "@parameterAlias=1");
testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@invalidAlias)?@validAlias=1"); testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@invalidAlias)", "@validAlias=1");
} }
@Test @Test
@ -2062,18 +2062,18 @@ public class TestFullResourcePath {
@Test @Test
public void runExpand() throws Exception { public void runExpand() throws Exception {
testUri.run("ESKeyNav(1)?$expand=*") testUri.run("ESKeyNav(1)", "$expand=*")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.isSegmentStar(); .isSegmentStar();
testUri.run("ESKeyNav(1)?$expand=*/$ref") testUri.run("ESKeyNav(1)", "$expand=*/$ref")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.isSegmentStar() .isSegmentStar()
.isSegmentRef(); .isSegmentRef();
testUri.run("ESKeyNav(1)?$expand=*/$ref,NavPropertyETKeyNavMany") testUri.run("ESKeyNav(1)", "$expand=*/$ref,NavPropertyETKeyNavMany")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.isSegmentStar().isSegmentRef() .isSegmentStar().isSegmentRef()
@ -2081,19 +2081,19 @@ public class TestFullResourcePath {
.goPath().first() .goPath().first()
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
testUri.run("ESKeyNav(1)?$expand=*($levels=3)") testUri.run("ESKeyNav(1)", "$expand=*($levels=3)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.isSegmentStar() .isSegmentStar()
.isLevelText("3"); .isLevelText("3");
testUri.run("ESKeyNav(1)?$expand=*($levels=max)") testUri.run("ESKeyNav(1)", "$expand=*($levels=max)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.isSegmentStar() .isSegmentStar()
.isLevelText("max"); .isLevelText("max");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2101,7 +2101,7 @@ public class TestFullResourcePath {
.isType(EntityTypeProvider.nameETKeyNav, true) .isType(EntityTypeProvider.nameETKeyNav, true)
.n().isRef(); .n().isRef();
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$ref") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne/$ref")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2109,7 +2109,7 @@ public class TestFullResourcePath {
.isType(EntityTypeProvider.nameETKeyNav, false) .isType(EntityTypeProvider.nameETKeyNav, false)
.n().isRef(); .n().isRef();
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($filter=PropertyInt16 eq 1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($filter=PropertyInt16 eq 1)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2118,7 +2118,7 @@ public class TestFullResourcePath {
.n().isRef() .n().isRef()
.goUpExpandValidator().isFilterSerialized("<<PropertyInt16> eq <1>>"); .goUpExpandValidator().isFilterSerialized("<<PropertyInt16> eq <1>>");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($orderby=PropertyInt16)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($orderby=PropertyInt16)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2129,7 +2129,7 @@ public class TestFullResourcePath {
.isSortOrder(0, false) .isSortOrder(0, false)
.goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2139,7 +2139,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isSkipText("1"); .isSkipText("1");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($top=2)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($top=2)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2149,7 +2149,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isTopText("2"); .isTopText("2");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($count=true)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($count=true)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2159,7 +2159,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isInlineCountText("true"); .isInlineCountText("true");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1;$top=3)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1;$top=3)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2170,7 +2170,7 @@ public class TestFullResourcePath {
.isSkipText("1") .isSkipText("1")
.isTopText("3"); .isTopText("3");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1%3b$top=3)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref($skip=1%3b$top=3)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2181,7 +2181,7 @@ public class TestFullResourcePath {
.isSkipText("1") .isSkipText("1")
.isTopText("3"); .isTopText("3");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$count")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2189,7 +2189,7 @@ public class TestFullResourcePath {
.isType(EntityTypeProvider.nameETKeyNav, true) .isType(EntityTypeProvider.nameETKeyNav, true)
.n().isCount(); .n().isCount();
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$count") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne/$count")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2197,7 +2197,7 @@ public class TestFullResourcePath {
.isType(EntityTypeProvider.nameETKeyNav, false) .isType(EntityTypeProvider.nameETKeyNav, false)
.n().isCount(); .n().isCount();
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count($filter=PropertyInt16 gt 1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$count($filter=PropertyInt16 gt 1)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2207,7 +2207,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isFilterSerialized("<<PropertyInt16> gt <1>>"); .isFilterSerialized("<<PropertyInt16> gt <1>>");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($filter=PropertyInt16 eq 1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($filter=PropertyInt16 eq 1)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2216,7 +2216,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isFilterSerialized("<<PropertyInt16> eq <1>>"); .isFilterSerialized("<<PropertyInt16> eq <1>>");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($orderby=PropertyInt16)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($orderby=PropertyInt16)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2226,7 +2226,7 @@ public class TestFullResourcePath {
.isSortOrder(0, false) .isSortOrder(0, false)
.goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2235,7 +2235,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isSkipText("1"); .isSkipText("1");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($top=2)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($top=2)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2244,7 +2244,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isTopText("2"); .isTopText("2");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($count=true)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($count=true)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2253,7 +2253,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isInlineCountText("true"); .isInlineCountText("true");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($select=PropertyString)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($select=PropertyString)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2263,7 +2263,7 @@ public class TestFullResourcePath {
.isSelectText("PropertyString") .isSelectText("PropertyString")
.goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($expand=NavPropertyETTwoKeyNavOne)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($expand=NavPropertyETTwoKeyNavOne)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2274,7 +2274,7 @@ public class TestFullResourcePath {
.goPath().first() .goPath().first()
.isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($expand=NavPropertyETKeyNavMany)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($expand=NavPropertyETKeyNavMany)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2285,7 +2285,7 @@ public class TestFullResourcePath {
.goPath().first() .goPath().first()
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne($levels=5)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne($levels=5)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2294,7 +2294,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isLevelText("5"); .isLevelText("5");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($select=PropertyString)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($select=PropertyString)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2304,7 +2304,7 @@ public class TestFullResourcePath {
.isSelectText("PropertyString") .isSelectText("PropertyString")
.goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne($levels=max)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavOne($levels=max)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2313,7 +2313,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.isLevelText("max"); .isLevelText("max");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1;$top=2)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1;$top=2)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2323,7 +2323,7 @@ public class TestFullResourcePath {
.isSkipText("1") .isSkipText("1")
.isTopText("2"); .isTopText("2");
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1%3b$top=2)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany($skip=1%3b$top=2)")
.isKind(UriInfoKind.resource).goPath().goExpand() .isKind(UriInfoKind.resource).goPath().goExpand()
.first() .first()
.goPath().first() .goPath().first()
@ -2333,7 +2333,7 @@ public class TestFullResourcePath {
.isSkipText("1") .isSkipText("1")
.isTopText("2"); .isTopText("2");
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')?$expand=NavPropertyETKeyNavMany") testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')", "$expand=NavPropertyETKeyNavMany")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.first() .first()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
@ -2344,8 +2344,7 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
.isType(EntityTypeProvider.nameETKeyNav, true); .isType(EntityTypeProvider.nameETKeyNav, true);
testUri.run("ESTwoKeyNav?" testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany")
+ "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.goExpand().first() .goExpand().first()
.isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav)
@ -2355,8 +2354,8 @@ public class TestFullResourcePath {
// .n() // .n()
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')?" testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')",
+ "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany") "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicate(1, "PropertyString", "'Hugo'") .isKeyPredicate(1, "PropertyString", "'Hugo'")
@ -2368,8 +2367,8 @@ public class TestFullResourcePath {
// .n() // .n()
.isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?" testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')",
+ "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETTwoKeyNavMany") "$expand=olingo.odata.test1.ETBaseTwoKeyNav/NavPropertyETTwoKeyNavMany")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicate(1, "PropertyString", "'2'") .isKeyPredicate(1, "PropertyString", "'2'")
@ -2381,8 +2380,9 @@ public class TestFullResourcePath {
// .n() // .n()
.isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true); .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true);
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$expand=olingo.odata.test1.ETBaseTwoKeyNav" testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')",
+ "/NavPropertyETTwoKeyNavMany/olingo.odata.test1.ETTwoBaseTwoKeyNav") "$expand=olingo.odata.test1.ETBaseTwoKeyNav"
+ "/NavPropertyETTwoKeyNavMany/olingo.odata.test1.ETTwoBaseTwoKeyNav")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicate(1, "PropertyString", "'2'") .isKeyPredicate(1, "PropertyString", "'2'")
@ -2395,7 +2395,7 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true)
.isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav); .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
testUri.run("ESTwoKeyNav?$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav/NavPropertyETTwoKeyNavOne") testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav/NavPropertyETTwoKeyNavOne")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.goExpand().first() .goExpand().first()
.isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav)
@ -2408,7 +2408,7 @@ public class TestFullResourcePath {
.n() .n()
.isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
testUri.run("ESTwoKeyNav?$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav" testUri.run("ESTwoKeyNav", "$expand=olingo.odata.test1.ETBaseTwoKeyNav/PropertyCompNav"
+ "/olingo.odata.test1.CTTwoBasePrimCompNav/NavPropertyETTwoKeyNavOne") + "/olingo.odata.test1.CTTwoBasePrimCompNav/NavPropertyETTwoKeyNavOne")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.goExpand().first() .goExpand().first()
@ -2422,7 +2422,7 @@ public class TestFullResourcePath {
.n() .n()
.isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref,NavPropertyETTwoKeyNavMany($skip=2;$top=1)") testUri.run("ESKeyNav(1)", "$expand=NavPropertyETKeyNavMany/$ref,NavPropertyETTwoKeyNavMany($skip=2;$top=1)")
.isKind(UriInfoKind.resource).goPath().first() .isKind(UriInfoKind.resource).goPath().first()
.goExpand().first() .goExpand().first()
.goPath() .goPath()
@ -2437,7 +2437,7 @@ public class TestFullResourcePath {
.isSkipText("2") .isSkipText("2")
.isTopText("1"); .isTopText("1");
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$expand=olingo.odata.test1.ETBaseTwoKeyNav" testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')", "$expand=olingo.odata.test1.ETBaseTwoKeyNav"
+ "/NavPropertyETTwoKeyNavMany/olingo.odata.test1.ETTwoBaseTwoKeyNav($select=PropertyString)") + "/NavPropertyETTwoKeyNavMany/olingo.odata.test1.ETTwoBaseTwoKeyNav($select=PropertyString)")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.first() .first()
@ -2455,7 +2455,7 @@ public class TestFullResourcePath {
.goUpExpandValidator() .goUpExpandValidator()
.goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($expand=NavPropertyETKeyNavMany(" testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($expand=NavPropertyETKeyNavMany("
+ "$expand=NavPropertyETKeyNavOne))") + "$expand=NavPropertyETKeyNavOne))")
.isKind(UriInfoKind.resource) .isKind(UriInfoKind.resource)
.goPath().first() .goPath().first()
@ -2474,7 +2474,7 @@ public class TestFullResourcePath {
.isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
.isType(EntityTypeProvider.nameETKeyNav); .isType(EntityTypeProvider.nameETKeyNav);
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$select=olingo.odata.test1.ETBaseTwoKeyNav" testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')", "$select=olingo.odata.test1.ETBaseTwoKeyNav"
+ "/PropertyInt16") + "/PropertyInt16")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.first() .first()
@ -2485,7 +2485,7 @@ public class TestFullResourcePath {
.first() .first()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($select=PropertyInt16)") testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyInt16)")
.isKind(UriInfoKind.resource) .isKind(UriInfoKind.resource)
.goPath().first() .goPath().first()
.goExpand().first() .goExpand().first()
@ -2496,7 +2496,7 @@ public class TestFullResourcePath {
.isSelectText("PropertyInt16") .isSelectText("PropertyInt16")
.goSelectItem(0).isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .goSelectItem(0).isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($select=PropertyComp/PropertyInt16)") testUri.run("ESKeyNav", "$expand=NavPropertyETKeyNavOne($select=PropertyComp/PropertyInt16)")
.isKind(UriInfoKind.resource) .isKind(UriInfoKind.resource)
.goPath().first() .goPath().first()
.goExpand().first() .goExpand().first()
@ -2510,103 +2510,103 @@ public class TestFullResourcePath {
@Test @Test
public void runTop() throws Exception { public void runTop() throws Exception {
// top // top
testUri.run("ESKeyNav?$top=1") testUri.run("ESKeyNav", "$top=1")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isEntitySet("ESKeyNav") .isEntitySet("ESKeyNav")
.isTopText("1"); .isTopText("1");
testUri.run("ESKeyNav?$top=0") testUri.run("ESKeyNav", "$top=0")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isEntitySet("ESKeyNav") .isEntitySet("ESKeyNav")
.isTopText("0"); .isTopText("0");
testUri.run("ESKeyNav?$top=-3") testUri.run("ESKeyNav", "$top=-3")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isEntitySet("ESKeyNav") .isEntitySet("ESKeyNav")
.isTopText("-3"); .isTopText("-3");
testUri.runEx("ESKeyNav?$top=undefined") testUri.runEx("ESKeyNav", "$top=undefined")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
testUri.runEx("ESKeyNav?$top=") testUri.runEx("ESKeyNav", "$top=")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
} }
@Test @Test
public void runFormat() throws Exception { public void runFormat() throws Exception {
// format // format
testUri.run("ESKeyNav(1)?$format=atom") testUri.run("ESKeyNav(1)", "$format=atom")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText("atom"); .isFormatText("atom");
testUri.run("ESKeyNav(1)?$format=json") testUri.run("ESKeyNav(1)", "$format=json")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText("json"); .isFormatText("json");
testUri.run("ESKeyNav(1)?$format=xml") testUri.run("ESKeyNav(1)", "$format=xml")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText("xml"); .isFormatText("xml");
testUri.run("ESKeyNav(1)?$format=IANA_content_type/must_contain_a_slash") testUri.run("ESKeyNav(1)", "$format=IANA_content_type/must_contain_a_slash")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText("IANA_content_type/must_contain_a_slash"); .isFormatText("IANA_content_type/must_contain_a_slash");
testUri.run("ESKeyNav(1)?$format=Test_all_valid_signsSpecified_for_format_signs%26-._~$@%27/Aa123%26-._~$@%27") testUri.run("ESKeyNav(1)", "$format=Test_all_valid_signsSpecified_for_format_signs%26-._~$@%27/Aa123%26-._~$@%27")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText("Test_all_valid_signsSpecified_for_format_signs&-._~$@'/Aa123&-._~$@'"); .isFormatText("Test_all_valid_signsSpecified_for_format_signs&-._~$@'/Aa123&-._~$@'");
testUri.run("ESKeyNav(1)?$format=" + HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8) testUri.run("ESKeyNav(1)", "$format=" + HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8)
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8); .isFormatText(HttpContentType.APPLICATION_ATOM_XML_ENTRY_UTF8);
testUri.runEx("ESKeyNav(1)?$format=noSlash") testUri.runEx("ESKeyNav(1)", "$format=noSlash")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
testUri.runEx("ESKeyNav(1)?$format=slashAtEnd/") testUri.runEx("ESKeyNav(1)", "$format=slashAtEnd/")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
testUri.runEx("ESKeyNav(1)?$format=/startsWithSlash") testUri.runEx("ESKeyNav(1)", "$format=/startsWithSlash")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
testUri.runEx("ESKeyNav(1)?$format=two/Slashes/tooMuch") testUri.runEx("ESKeyNav(1)", "$format=two/Slashes/tooMuch")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
testUri.runEx("ESKeyNav(1)?$format=") testUri.runEx("ESKeyNav(1)", "$format=")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT);
} }
@Test @Test
public void runCount() throws Exception { public void runCount() throws Exception {
// count // count
testUri.run("ESAllPrim?$count=true") testUri.run("ESAllPrim", "$count=true")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isInlineCountText("true"); .isInlineCountText("true");
testUri.run("ESAllPrim?$count=false") testUri.run("ESAllPrim", "$count=false")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isInlineCountText("false"); .isInlineCountText("false");
testUri.runEx("ESAllPrim?$count=undefined") testUri.runEx("ESAllPrim", "$count=undefined")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
testUri.runEx("ESAllPrim?$count=") testUri.runEx("ESAllPrim", "$count=")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
} }
@Test @Test
public void skip() throws Exception { public void skip() throws Exception {
// skip // skip
testUri.run("ESAllPrim?$skip=3") testUri.run("ESAllPrim", "$skip=3")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isSkipText("3"); .isSkipText("3");
testUri.run("ESAllPrim?$skip=0") testUri.run("ESAllPrim", "$skip=0")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isSkipText("0"); .isSkipText("0");
testUri.run("ESAllPrim?$skip=-3") testUri.run("ESAllPrim", "$skip=-3")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isSkipText("-3"); .isSkipText("-3");
testUri.runEx("ESAllPrim?$skip=F") testUri.runEx("ESAllPrim", "$skip=F")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
testUri.runEx("ESAllPrim?$skip=") testUri.runEx("ESAllPrim", "$skip=")
.isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION);
} }
@Test @Test
public void skiptoken() throws Exception { public void skiptoken() throws Exception {
testUri.run("ESAllPrim?$skiptoken=foo") testUri.run("ESAllPrim", "$skiptoken=foo")
.isKind(UriInfoKind.resource).goPath() .isKind(UriInfoKind.resource).goPath()
.isSkipTokenText("foo"); .isSkipTokenText("foo");
} }
@Test @Test
public void notExistingSystemQueryOption() throws Exception { public void notExistingSystemQueryOption() throws Exception {
testUri.runEx("ESAllPrim?$wrong=error") testUri.runEx("ESAllPrim", "$wrong=error")
.isExSyntax(UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION); .isExSyntax(UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION);
} }
@ -2631,6 +2631,13 @@ public class TestFullResourcePath {
.isKind(UriInfoKind.crossjoin) .isKind(UriInfoKind.crossjoin)
.isCrossJoinEntityList(Arrays.asList("ESKeyNav")); .isCrossJoinEntityList(Arrays.asList("ESKeyNav"));
testUri.runEx("$metadata/$ref").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.runEx("$batch/$ref").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.runEx("$crossjoin(ESKeyNav)/$ref").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.runEx("$all/$ref").isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.runEx("$entity/olingo.odata.test1.ETKeyNav/$ref")
.isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
testUri.run("ESKeyNav") testUri.run("ESKeyNav")
.isKind(UriInfoKind.resource) .isKind(UriInfoKind.resource)
.goPath().first() .goPath().first()
@ -5069,37 +5076,37 @@ public class TestFullResourcePath {
@Ignore("$search currently not implemented") @Ignore("$search currently not implemented")
public void testSearch() throws Exception { public void testSearch() throws Exception {
testUri.run("ESTwoKeyNav?$search=abc"); testUri.run("ESTwoKeyNav", "$search=abc");
testUri.run("ESTwoKeyNav?$search=NOT abc"); testUri.run("ESTwoKeyNav", "$search=NOT abc");
testUri.run("ESTwoKeyNav?$search=abc AND def"); testUri.run("ESTwoKeyNav", "$search=abc AND def");
testUri.run("ESTwoKeyNav?$search=abc OR def"); testUri.run("ESTwoKeyNav", "$search=abc OR def");
testUri.run("ESTwoKeyNav?$search=abc def"); testUri.run("ESTwoKeyNav", "$search=abc def");
testUri.run("ESTwoKeyNav?$search=abc AND def AND ghi"); testUri.run("ESTwoKeyNav", "$search=abc AND def AND ghi");
testUri.run("ESTwoKeyNav?$search=abc AND def OR ghi"); testUri.run("ESTwoKeyNav", "$search=abc AND def OR ghi");
testUri.run("ESTwoKeyNav?$search=abc AND def ghi"); testUri.run("ESTwoKeyNav", "$search=abc AND def ghi");
testUri.run("ESTwoKeyNav?$search=abc OR def AND ghi"); testUri.run("ESTwoKeyNav", "$search=abc OR def AND ghi");
testUri.run("ESTwoKeyNav?$search=abc OR def OR ghi"); testUri.run("ESTwoKeyNav", "$search=abc OR def OR ghi");
testUri.run("ESTwoKeyNav?$search=abc OR def ghi"); testUri.run("ESTwoKeyNav", "$search=abc OR def ghi");
testUri.run("ESTwoKeyNav?$search=abc def AND ghi"); testUri.run("ESTwoKeyNav", "$search=abc def AND ghi");
testUri.run("ESTwoKeyNav?$search=abc def OR ghi"); testUri.run("ESTwoKeyNav", "$search=abc def OR ghi");
testUri.run("ESTwoKeyNav?$search=abc def ghi"); testUri.run("ESTwoKeyNav", "$search=abc def ghi");
// mixed not // mixed not
testUri.run("ESTwoKeyNav?$search= abc def AND ghi"); testUri.run("ESTwoKeyNav", "$search= abc def AND ghi");
testUri.run("ESTwoKeyNav?$search=NOT abc NOT def OR NOT ghi"); testUri.run("ESTwoKeyNav", "$search=NOT abc NOT def OR NOT ghi");
testUri.run("ESTwoKeyNav?$search= abc def NOT ghi"); testUri.run("ESTwoKeyNav", "$search= abc def NOT ghi");
// parenthesis // parenthesis
testUri.run("ESTwoKeyNav?$search= (abc)"); testUri.run("ESTwoKeyNav", "$search= (abc)");
testUri.run("ESTwoKeyNav?$search= (abc AND def)"); testUri.run("ESTwoKeyNav", "$search= (abc AND def)");
testUri.run("ESTwoKeyNav?$search= (abc AND def) OR ghi "); testUri.run("ESTwoKeyNav", "$search= (abc AND def) OR ghi ");
testUri.run("ESTwoKeyNav?$search= (abc AND def) ghi "); testUri.run("ESTwoKeyNav", "$search= (abc AND def) ghi ");
testUri.run("ESTwoKeyNav?$search= abc AND (def OR ghi)"); testUri.run("ESTwoKeyNav", "$search= abc AND (def OR ghi)");
testUri.run("ESTwoKeyNav?$search= abc AND (def ghi)"); testUri.run("ESTwoKeyNav", "$search= abc AND (def ghi)");
} }
@Test @Test
@ -5156,7 +5163,7 @@ public class TestFullResourcePath {
@Test @Test
public void testAlias() throws Exception { public void testAlias() throws Exception {
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath() testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)", "@A='2'").goPath()
.isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicateAlias(1, "PropertyString", "@A") .isKeyPredicateAlias(1, "PropertyString", "@A")
.isInAliasToValueMap("@A", "'2'") .isInAliasToValueMap("@A", "'2'")

View File

@ -236,7 +236,7 @@ public class TestUriParserImpl {
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void testEntityFailOnValidation1() throws Exception { public void testEntityFailOnValidation1() throws Exception {
// simple entity set; with qualifiedentityTypeName; with filter // simple entity set; with qualifiedentityTypeName; with filter
testUri.run("$entity/olingo.odata.test1.ETTwoPrim?$filter=PropertyInt16 eq 123&$id=ESAllKey") testUri.run("$entity/olingo.odata.test1.ETTwoPrim", "$filter=PropertyInt16 eq 123&$id=ESAllKey")
.isIdText("ESAllKey") .isIdText("ESAllKey")
.goFilter().is("<<PropertyInt16> eq <123>>"); .goFilter().is("<<PropertyInt16> eq <123>>");
} }
@ -244,8 +244,8 @@ public class TestUriParserImpl {
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void testEntityFailOnValidation2() throws Exception { public void testEntityFailOnValidation2() throws Exception {
// simple entity set; with qualifiedentityTypeName; with 2xformat(before and after), expand, filter // simple entity set; with qualifiedentityTypeName; with 2xformat(before and after), expand, filter
testUri.run("$entity/olingo.odata.test1.ETTwoPrim?" testUri.run("$entity/olingo.odata.test1.ETTwoPrim",
+ "$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 123&$format=atom&$select=*") "$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 123&$format=atom&$select=*")
.isFormatText("atom") .isFormatText("atom")
.isCustomParameter(0, "abc", "123") .isCustomParameter(0, "abc", "123")
.isIdText("ESBase") .isIdText("ESBase")
@ -257,64 +257,64 @@ public class TestUriParserImpl {
public void testEntity() throws Exception { public void testEntity() throws Exception {
// simple entity set // simple entity set
testUri.run("$entity?$id=ESAllPrim").isKind(UriInfoKind.entityId) testUri.run("$entity", "$id=ESAllPrim").isKind(UriInfoKind.entityId)
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isIdText("ESAllPrim"); .isIdText("ESAllPrim");
// simple entity set; $format before $id // simple entity set; $format before $id
testUri.run("$entity?$format=xml&$id=ETAllPrim").isKind(UriInfoKind.entityId) testUri.run("$entity", "$format=xml&$id=ETAllPrim").isKind(UriInfoKind.entityId)
.isFormatText("xml") .isFormatText("xml")
.isIdText("ETAllPrim"); .isIdText("ETAllPrim");
testUri.run("$entity?$format=xml&abc=123&$id=ESAllKey").isKind(UriInfoKind.entityId) testUri.run("$entity", "$format=xml&abc=123&$id=ESAllKey").isKind(UriInfoKind.entityId)
.isFormatText("xml") .isFormatText("xml")
.isCustomParameter(0, "abc", "123") .isCustomParameter(0, "abc", "123")
.isIdText("ESAllKey"); .isIdText("ESAllKey");
// simple entity set; $format after $id // simple entity set; $format after $id
testUri.run("$entity?$id=ETAllPrim&$format=xml").isKind(UriInfoKind.entityId) testUri.run("$entity", "$id=ETAllPrim&$format=xml").isKind(UriInfoKind.entityId)
.isIdText("ETAllPrim") .isIdText("ETAllPrim")
.isFormatText("xml"); .isFormatText("xml");
// simple entity set; $format and custom parameter after $id // simple entity set; $format and custom parameter after $id
testUri.run("$entity?$id=ETAllPrim&$format=xml&abc=123").isKind(UriInfoKind.entityId) testUri.run("$entity", "$id=ETAllPrim&$format=xml&abc=123").isKind(UriInfoKind.entityId)
.isIdText("ETAllPrim") .isIdText("ETAllPrim")
.isFormatText("xml") .isFormatText("xml")
.isCustomParameter(0, "abc", "123"); .isCustomParameter(0, "abc", "123");
// simple entity set; $format before $id and custom parameter after $id // simple entity set; $format before $id and custom parameter after $id
testUri.run("$entity?$format=xml&$id=ETAllPrim&abc=123").isKind(UriInfoKind.entityId) testUri.run("$entity", "$format=xml&$id=ETAllPrim&abc=123").isKind(UriInfoKind.entityId)
.isFormatText("xml") .isFormatText("xml")
.isIdText("ETAllPrim") .isIdText("ETAllPrim")
.isCustomParameter(0, "abc", "123"); .isCustomParameter(0, "abc", "123");
// simple entity set; with qualifiedentityTypeName // simple entity set; with qualifiedentityTypeName
testUri.run("$entity/olingo.odata.test1.ETTwoPrim?$id=ESBase") testUri.run("$entity/olingo.odata.test1.ETTwoPrim", "$id=ESBase")
.isEntityType(EntityTypeProvider.nameETTwoPrim) .isEntityType(EntityTypeProvider.nameETTwoPrim)
.isIdText("ESBase"); .isIdText("ESBase");
// simple entity set; with qualifiedentityTypeName; // simple entity set; with qualifiedentityTypeName;
testUri.run("$entity/olingo.odata.test1.ETBase?$id=ESTwoPrim") testUri.run("$entity/olingo.odata.test1.ETBase", "$id=ESTwoPrim")
.isEntityType(EntityTypeProvider.nameETBase) .isEntityType(EntityTypeProvider.nameETBase)
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isIdText("ESTwoPrim"); .isIdText("ESTwoPrim");
// simple entity set; with qualifiedentityTypeName; with format // simple entity set; with qualifiedentityTypeName; with format
testUri.run("$entity/olingo.odata.test1.ETBase?$id=ESTwoPrim&$format=atom") testUri.run("$entity/olingo.odata.test1.ETBase", "$id=ESTwoPrim&$format=atom")
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isEntityType(EntityTypeProvider.nameETBase) .isEntityType(EntityTypeProvider.nameETBase)
.isIdText("ESTwoPrim") .isIdText("ESTwoPrim")
.isFormatText("atom"); .isFormatText("atom");
// simple entity set; with qualifiedentityTypeName; with select // simple entity set; with qualifiedentityTypeName; with select
testUri.run("$entity/olingo.odata.test1.ETBase?$id=ESTwoPrim&$select=*") testUri.run("$entity/olingo.odata.test1.ETBase", "$id=ESTwoPrim&$select=*")
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isEntityType(EntityTypeProvider.nameETBase) .isEntityType(EntityTypeProvider.nameETBase)
.isIdText("ESTwoPrim") .isIdText("ESTwoPrim")
.isSelectItemStar(0); .isSelectItemStar(0);
// simple entity set; with qualifiedentityTypeName; with expand // simple entity set; with qualifiedentityTypeName; with expand
testUri.run("$entity/olingo.odata.test1.ETBase?$id=ESTwoPrim&$expand=*") testUri.run("$entity/olingo.odata.test1.ETBase", "$id=ESTwoPrim&$expand=*")
.isKind(UriInfoKind.entityId) .isKind(UriInfoKind.entityId)
.isEntityType(EntityTypeProvider.nameETBase) .isEntityType(EntityTypeProvider.nameETBase)
.isIdText("ESTwoPrim") .isIdText("ESTwoPrim")
@ -367,7 +367,7 @@ public class TestUriParserImpl {
} }
@Test @Test
public void testEntitySet_NavigationPropperty() { public void testEntitySet_NavigationProperty() {
// plain entity set ... // plain entity set ...
@ -711,153 +711,155 @@ public class TestUriParserImpl {
testUri.run("$metadata") testUri.run("$metadata")
.isKind(UriInfoKind.metadata); .isKind(UriInfoKind.metadata);
testUri.run("$metadata?$format=atom") testUri.run("$metadata", "$format=atom")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom"); .isFormatText("atom");
// with context (client usage) // with context (client usage)
testUri.run("$metadata#$ref") testUri.run("$metadata", null, "$ref")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFragmentText("$ref"); .isFragmentText("$ref");
testUri.run("$metadata?$format=atom#$ref") testUri.run("$metadata", "$format=atom", "$ref")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("$ref"); .isFragmentText("$ref");
testUri.run("$metadata?$format=atom#Collection($ref)") testUri.run("$metadata", "$format=atom", "Collection($ref)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("Collection($ref)"); .isFragmentText("Collection($ref)");
testUri.run("$metadata?$format=atom#Collection(Edm.EntityType)") testUri.run("$metadata", "$format=atom", "Collection(Edm.EntityType)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("Collection(Edm.EntityType)"); .isFragmentText("Collection(Edm.EntityType)");
testUri.run("$metadata?$format=atom#Collection(Edm.ComplexType)") testUri.run("$metadata", "$format=atom", "Collection(Edm.ComplexType)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("Collection(Edm.ComplexType)"); .isFragmentText("Collection(Edm.ComplexType)");
testUri.run("$metadata?$format=atom#SINav") testUri.run("$metadata", "$format=atom", "SINav")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav"); .isFragmentText("SINav");
testUri.run("$metadata?$format=atom#SINav/PropertyInt16") testUri.run("$metadata", "$format=atom", "SINav/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/PropertyInt16"); .isFragmentText("SINav/PropertyInt16");
testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne") testUri.run("$metadata", "$format=atom", "SINav/NavPropertyETKeyNavOne")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/NavPropertyETKeyNavOne"); .isFragmentText("SINav/NavPropertyETKeyNavOne");
testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)") testUri.run("$metadata", "$format=atom", "SINav/NavPropertyETKeyNavMany(1)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/NavPropertyETKeyNavMany(1)"); .isFragmentText("SINav/NavPropertyETKeyNavMany(1)");
testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne/PropertyInt16") testUri.run("$metadata", "$format=atom", "SINav/NavPropertyETKeyNavOne/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/NavPropertyETKeyNavOne/PropertyInt16"); .isFragmentText("SINav/NavPropertyETKeyNavOne/PropertyInt16");
testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)/PropertyInt16") testUri.run("$metadata", "$format=atom", "SINav/NavPropertyETKeyNavMany(1)/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16"); .isFragmentText("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16");
testUri.run("$metadata?$format=atom#SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16") testUri.run("$metadata", "$format=atom", "SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16"); .isFragmentText("SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16");
testUri.run("$metadata?$format=atom#SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16") testUri.run("$metadata", "$format=atom",
"SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16"); .isFragmentText("SINav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16");
testUri.run("$metadata?$format=atom#olingo.odata.test1.ETAllKey") testUri.run("$metadata", "$format=atom", "olingo.odata.test1.ETAllKey")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("olingo.odata.test1.ETAllKey"); .isFragmentText("olingo.odata.test1.ETAllKey");
testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedEntity") testUri.run("$metadata", "$format=atom", "ESTwoPrim/$deletedEntity")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESTwoPrim/$deletedEntity"); .isFragmentText("ESTwoPrim/$deletedEntity");
testUri.run("$metadata?$format=atom#ESTwoPrim/$link") testUri.run("$metadata", "$format=atom", "ESTwoPrim/$link")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESTwoPrim/$link"); .isFragmentText("ESTwoPrim/$link");
testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedLink") testUri.run("$metadata", "$format=atom", "ESTwoPrim/$deletedLink")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESTwoPrim/$deletedLink"); .isFragmentText("ESTwoPrim/$deletedLink");
testUri.run("$metadata?$format=atom#ESKeyNav") testUri.run("$metadata", "$format=atom", "ESKeyNav")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav"); .isFragmentText("ESKeyNav");
testUri.run("$metadata?$format=atom#ESKeyNav/PropertyInt16") testUri.run("$metadata", "$format=atom", "ESKeyNav/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/PropertyInt16"); .isFragmentText("ESKeyNav/PropertyInt16");
testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne") testUri.run("$metadata", "$format=atom", "ESKeyNav/NavPropertyETKeyNavOne")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/NavPropertyETKeyNavOne"); .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne");
testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)") testUri.run("$metadata", "$format=atom", "ESKeyNav/NavPropertyETKeyNavMany(1)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)"); .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)");
testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16") testUri.run("$metadata", "$format=atom", "ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16"); .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16");
testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16") testUri.run("$metadata", "$format=atom", "ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16"); .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16");
testUri.run("$metadata?$format=atom#ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16") testUri.run("$metadata", "$format=atom",
"ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16"); .isFragmentText("ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16");
testUri.run( testUri.run(
"$metadata?$format=atom#ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16") "$metadata", "$format=atom", "ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16"); .isFragmentText("ESKeyNav/olingo.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16");
testUri.run("$metadata?$format=atom#ESKeyNav(PropertyInt16,PropertyString)") testUri.run("$metadata", "$format=atom", "ESKeyNav(PropertyInt16,PropertyString)")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav(PropertyInt16,PropertyString)"); .isFragmentText("ESKeyNav(PropertyInt16,PropertyString)");
testUri.run("$metadata?$format=atom#ESKeyNav/$entity") testUri.run("$metadata", "$format=atom", "ESKeyNav/$entity")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/$entity"); .isFragmentText("ESKeyNav/$entity");
testUri.run("$metadata?$format=atom#ESKeyNav/$delta") testUri.run("$metadata", "$format=atom", "ESKeyNav/$delta")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/$delta"); .isFragmentText("ESKeyNav/$delta");
testUri.run("$metadata?$format=atom#ESKeyNav/(PropertyInt16,PropertyString)/$delta") testUri.run("$metadata", "$format=atom", "ESKeyNav/(PropertyInt16,PropertyString)/$delta")
.isKind(UriInfoKind.metadata) .isKind(UriInfoKind.metadata)
.isFormatText("atom") .isFormatText("atom")
.isFragmentText("ESKeyNav/(PropertyInt16,PropertyString)/$delta"); .isFragmentText("ESKeyNav/(PropertyInt16,PropertyString)/$delta");
@ -995,8 +997,8 @@ public class TestUriParserImpl {
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void testMemberStartingWithCastFailOnValidation1() throws Exception { public void testMemberStartingWithCastFailOnValidation1() throws Exception {
// on EntityType entry // on EntityType entry
testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')?" testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')",
+ "$filter=olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate") "$filter=olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate")
.goFilter().root().isMember() .goFilter().root().isMember()
.isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath() .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
// .at(0) // .at(0)
@ -1008,8 +1010,8 @@ public class TestUriParserImpl {
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void testMemberStartingWithCastFailOnValidation2() throws Exception { public void testMemberStartingWithCastFailOnValidation2() throws Exception {
testUri.run("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?" testUri.run("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')",
+ "$filter=olingo.odata.test1.CTBase/AdditionalPropString") "$filter=olingo.odata.test1.CTBase/AdditionalPropString")
.goFilter().root().isMember() .goFilter().root().isMember()
.isMemberStartType(ComplexTypeProvider.nameCTBase).goPath() .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath()
// .at(0) // .at(0)
@ -1023,7 +1025,7 @@ public class TestUriParserImpl {
public void testMemberStartingWithCast() throws Exception { public void testMemberStartingWithCast() throws Exception {
// on EntityType collection // on EntityType collection
testUri.run("ESTwoKeyNav?$filter=olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate") testUri.run("ESTwoKeyNav", "$filter=olingo.odata.test1.ETBaseTwoKeyNav/PropertyDate")
.goFilter().root().isMember() .goFilter().root().isMember()
.isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath() .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
// .at(0) // .at(0)
@ -1033,8 +1035,8 @@ public class TestUriParserImpl {
.at(0).isType(PropertyProvider.nameDate); .at(0).isType(PropertyProvider.nameDate);
// on Complex collection // on Complex collection
testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?" testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')",
+ "$filter=olingo.odata.test1.CTBase/AdditionalPropString") "$filter=olingo.odata.test1.CTBase/AdditionalPropString")
.goFilter().root().isMember() .goFilter().root().isMember()
.isMemberStartType(ComplexTypeProvider.nameCTBase).goPath() .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath()
// .at(0) // .at(0)
@ -1052,27 +1054,27 @@ public class TestUriParserImpl {
@Test @Test
public void testLambda() throws Exception { public void testLambda() throws Exception {
testUri.run("ESTwoKeyNav?$filter=CollPropertyComp/all( l : true )") testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/all( l : true )")
.goFilter().is("<CollPropertyComp/<ALL;<true>>>"); .goFilter().is("<CollPropertyComp/<ALL;<true>>>");
testUri.run("ESTwoKeyNav?$filter=CollPropertyComp/any( l : true )") testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( l : true )")
.goFilter().is("<CollPropertyComp/<ANY;<true>>>"); .goFilter().is("<CollPropertyComp/<ANY;<true>>>");
testUri.run("ESTwoKeyNav?$filter=CollPropertyComp/any( )") testUri.run("ESTwoKeyNav", "$filter=CollPropertyComp/any( )")
.goFilter().is("<CollPropertyComp/<ANY;>>"); .goFilter().is("<CollPropertyComp/<ANY;>>");
testUri.run("ESTwoKeyNav?$filter=all( l : true )") testUri.run("ESTwoKeyNav", "$filter=all( l : true )")
.goFilter().is("<<ALL;<true>>>"); .goFilter().is("<<ALL;<true>>>");
testUri.run("ESTwoKeyNav?$filter=any( l : true )") testUri.run("ESTwoKeyNav", "$filter=any( l : true )")
.goFilter().is("<<ANY;<true>>>"); .goFilter().is("<<ANY;<true>>>");
testUri.run("ESTwoKeyNav?$filter=any( )") testUri.run("ESTwoKeyNav", "$filter=any( )")
.goFilter().is("<<ANY;>>"); .goFilter().is("<<ANY;>>");
} }
@Test @Test
public void testCustomQueryOption() throws Exception { public void testCustomQueryOption() throws Exception {
testUri.run("ESTwoKeyNav?custom") testUri.run("ESTwoKeyNav", "custom")
.isCustomParameter(0, "custom", ""); .isCustomParameter(0, "custom", "");
testUri.run("ESTwoKeyNav?custom=ABC") testUri.run("ESTwoKeyNav", "custom=ABC")
.isCustomParameter(0, "custom", "ABC"); .isCustomParameter(0, "custom", "ABC");
} }
@ -1092,52 +1094,47 @@ public class TestUriParserImpl {
@Test @Test
public void testSelect() throws Exception { public void testSelect() throws Exception {
testUri.run("ESTwoKeyNav?$select=*") testUri.run("ESTwoKeyNav", "$select=*")
.isSelectItemStar(0); .isSelectItemStar(0);
testUri.run("ESTwoKeyNav?$select=olingo.odata.test1.*") testUri.run("ESTwoKeyNav", "$select=olingo.odata.test1.*")
.isSelectItemAllOp(0, new FullQualifiedName("olingo.odata.test1", "*")); .isSelectItemAllOp(0, new FullQualifiedName("olingo.odata.test1", "*"));
testUri.run("ESTwoKeyNav?$select=PropertyString") testUri.run("ESTwoKeyNav", "$select=PropertyString")
.goSelectItemPath(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); .goSelectItemPath(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
testUri.run("ESTwoKeyNav?$select=PropertyComp") testUri.run("ESTwoKeyNav", "$select=PropertyComp")
.goSelectItemPath(0).isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false); .goSelectItemPath(0).isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false);
testUri.run("ESTwoKeyNav?$select=PropertyComp/PropertyInt16") testUri.run("ESTwoKeyNav", "$select=PropertyComp/PropertyInt16")
.goSelectItemPath(0) .goSelectItemPath(0)
.first() .first()
.isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false) .isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false)
.n() .n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
testUri.run("ESTwoKeyNav?$select=PropertyComp/PropertyComp") testUri.run("ESTwoKeyNav", "$select=PropertyComp/PropertyComp")
.goSelectItemPath(0) .goSelectItemPath(0)
.first() .first()
.isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false) .isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTPrimComp, false)
.n() .n()
.isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTAllPrim, false); .isComplexProperty("PropertyComp", ComplexTypeProvider.nameCTAllPrim, false);
testUri.run("ESTwoKeyNav?$select=olingo.odata.test1.ETBaseTwoKeyNav") testUri.run("ESTwoKeyNav", "$select=olingo.odata.test1.ETBaseTwoKeyNav")
.isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav); .isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav);
testUri.run("ESTwoKeyNav/PropertyCompNav?$select=olingo.odata.test1.CTTwoBasePrimCompNav") testUri.run("ESTwoKeyNav/PropertyCompNav", "$select=olingo.odata.test1.CTTwoBasePrimCompNav")
.isSelectStartType(0, ComplexTypeProvider.nameCTTwoBasePrimCompNav); .isSelectStartType(0, ComplexTypeProvider.nameCTTwoBasePrimCompNav);
testUri.run("ESTwoKeyNav?$select=PropertyCompNav/olingo.odata.test1.CTTwoBasePrimCompNav") testUri.run("ESTwoKeyNav", "$select=PropertyCompNav/olingo.odata.test1.CTTwoBasePrimCompNav")
.goSelectItemPath(0) .goSelectItemPath(0)
.first() .first()
.isComplexProperty("PropertyCompNav", ComplexTypeProvider.nameCTBasePrimCompNav, false) .isComplexProperty("PropertyCompNav", ComplexTypeProvider.nameCTBasePrimCompNav, false)
.n() .n()
.isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav); .isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav);
;
} }
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

@ -106,90 +106,74 @@ public class FilterValidator implements TestValidator {
// --- Execution --- // --- Execution ---
public FilterValidator runOrderByOnETAllPrim(final String orderBy) throws UriParserException { public FilterValidator runOrderByOnETAllPrim(final String orderBy) throws UriParserException {
String uri = "ESAllPrim?$orderby=" + orderBy.trim(); return runUriOrderBy("ESAllPrim", "$orderby=" + orderBy.trim());
return runUriOrderBy(uri);
} }
public FilterValidator runOrderByOnETTwoKeyNav(final String orderBy) throws UriParserException { public FilterValidator runOrderByOnETTwoKeyNav(final String orderBy) throws UriParserException {
String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim(); return runUriOrderBy("ESTwoKeyNav", "$orderby=" + orderBy.trim());
return runUriOrderBy(uri);
} }
public FilterValidator runOrderByOnETTwoKeyNavEx(final String orderBy) throws UriParserException { public FilterValidator runOrderByOnETTwoKeyNavEx(final String orderBy) throws UriParserException {
String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim(); return runUriOrderByEx("ESTwoKeyNav", "$orderby=" + orderBy.trim());
return runUriOrderByEx(uri);
} }
public FilterValidator runOnETTwoKeyNav(final String filter) throws UriParserException { public FilterValidator runOnETTwoKeyNav(final String filter) throws UriParserException {
String uri = "ESTwoKeyNav?$filter=" + filter.trim(); return runUri("ESTwoKeyNav", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnETTwoKeyNavSingle(final String filter) throws UriParserException { public FilterValidator runOnETTwoKeyNavSingle(final String filter) throws UriParserException {
String uri = "SINav?$filter=" + filter.trim(); return runUri("SINav", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException { public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException {
String uri = "ESTwoKeyNav?$filter=" + filter.trim(); return runUriEx("ESTwoKeyNav", "$filter=" + filter.trim());
return runUriEx(uri);
} }
public FilterValidator runOnETAllPrim(final String filter) throws UriParserException { public FilterValidator runOnETAllPrim(final String filter) throws UriParserException {
String uri = "ESAllPrim(1)?$filter=" + filter.trim(); return runUri("ESAllPrim(1)", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnETKeyNav(final String filter) throws UriParserException { public FilterValidator runOnETKeyNav(final String filter) throws UriParserException {
String uri = "ESKeyNav(1)?$filter=" + filter.trim(); return runUri("ESKeyNav(1)", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnETKeyNavEx(final String filter) throws UriParserException { public FilterValidator runOnETKeyNavEx(final String filter) throws UriParserException {
String uri = "ESKeyNav(1)?$filter=" + filter.trim(); return runUriEx("ESKeyNav(1)", "$filter=" + filter.trim());
return runUriEx(uri);
} }
public FilterValidator runOnCTTwoPrim(final String filter) throws UriParserException { public FilterValidator runOnCTTwoPrim(final String filter) throws UriParserException {
String uri = "SINav/PropertyCompTwoPrim?$filter=" + filter.trim(); return runUri("SINav/PropertyCompTwoPrim", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnString(final String filter) throws UriParserException { public FilterValidator runOnString(final String filter) throws UriParserException {
String uri = "SINav/PropertyString?$filter=" + filter.trim(); return runUri("SINav/PropertyString", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnInt32(final String filter) throws UriParserException { public FilterValidator runOnInt32(final String filter) throws UriParserException {
String uri = "ESCollAllPrim(1)/CollPropertyInt32?$filter=" + filter.trim(); return runUri("ESCollAllPrim(1)/CollPropertyInt32", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnDateTimeOffset(final String filter) throws UriParserException { public FilterValidator runOnDateTimeOffset(final String filter) throws UriParserException {
String uri = "ESCollAllPrim(1)/CollPropertyDateTimeOffset?$filter=" + filter.trim(); return runUri("ESCollAllPrim(1)/CollPropertyDateTimeOffset", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnDuration(final String filter) throws UriParserException { public FilterValidator runOnDuration(final String filter) throws UriParserException {
String uri = "ESCollAllPrim(1)/CollPropertyDuration?$filter=" + filter.trim(); return runUri("ESCollAllPrim(1)/CollPropertyDuration", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runOnTimeOfDay(final String filter) throws UriParserException { public FilterValidator runOnTimeOfDay(final String filter) throws UriParserException {
String uri = "ESCollAllPrim(1)/CollPropertyTimeOfDay?$filter=" + filter.trim(); return runUri("ESCollAllPrim(1)/CollPropertyTimeOfDay", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runESabc(final String filter) throws UriParserException { public FilterValidator runESabc(final String filter) throws UriParserException {
String uri = "ESabc?$filter=" + filter.trim(); return runUri("ESabc", "$filter=" + filter.trim());
return runUri(uri);
} }
public FilterValidator runUri(final String uri) throws UriParserException { public FilterValidator runUri(final String path, final String query) throws UriParserException {
Parser parser = new Parser(); Parser parser = new Parser();
UriInfo uriInfo = null; UriInfo uriInfo = null;
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
if (uriInfo.getKind() != UriInfoKind.resource) { if (uriInfo.getKind() != UriInfoKind.resource) {
fail("Filtervalidator can only be used on resourcePaths"); fail("Filtervalidator can only be used on resourcePaths");
@ -200,12 +184,12 @@ public class FilterValidator implements TestValidator {
return this; return this;
} }
public FilterValidator runUriEx(final String uri) { public FilterValidator runUriEx(final String path, final String query) {
Parser parser = new Parser(); Parser parser = new Parser();
UriInfo uriInfo = null; UriInfo uriInfo = null;
try { try {
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
} catch (UriParserException e) { } catch (UriParserException e) {
exception = e; exception = e;
return this; return this;
@ -220,11 +204,11 @@ public class FilterValidator implements TestValidator {
return this; return this;
} }
public FilterValidator runUriOrderBy(final String uri) throws UriParserException { public FilterValidator runUriOrderBy(final String path, final String query) throws UriParserException {
Parser parser = new Parser(); Parser parser = new Parser();
UriInfo uriInfo = null; UriInfo uriInfo = null;
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
if (uriInfo.getKind() != UriInfoKind.resource) { if (uriInfo.getKind() != UriInfoKind.resource) {
fail("Filtervalidator can only be used on resourcePaths"); fail("Filtervalidator can only be used on resourcePaths");
@ -234,12 +218,12 @@ public class FilterValidator implements TestValidator {
return this; return this;
} }
public FilterValidator runUriOrderByEx(final String uri) { public FilterValidator runUriOrderByEx(final String path, final String query) {
Parser parser = new Parser(); Parser parser = new Parser();
UriInfo uriInfo = null; UriInfo uriInfo = null;
try { try {
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
} catch (UriParserException e) { } catch (UriParserException e) {
exception = e; exception = e;
return this; return this;

View File

@ -86,22 +86,22 @@ public class ResourceValidator implements TestValidator {
// --- Execution --- // --- Execution ---
public ResourceValidator run(final String uri) { public ResourceValidator run(final String path) {
ParserWithLogging testParser = new ParserWithLogging(); ParserWithLogging testParser = new ParserWithLogging();
UriInfo uriInfoTmp = null; UriInfo uriInfoTmp = null;
uriPathInfo = null; uriPathInfo = null;
try { try {
uriInfoTmp = testParser.parseUri(uri, edm); uriInfoTmp = testParser.parseUri(path, null, null, edm);
} catch (final UriParserException e) { } catch (final UriParserException e) {
fail("Exception occurred while parsing the URI: " + uri + "\n" fail("Exception occurred while parsing the URI: " + path + "\n"
+ " Message: " + e.getMessage()); + " Message: " + e.getMessage());
} }
try { try {
new UriValidator().validate(uriInfoTmp, HttpMethod.GET); new UriValidator().validate(uriInfoTmp, HttpMethod.GET);
} catch (final UriValidationException e) { } catch (final UriValidationException e) {
fail("Exception occurred while validating the URI: " + uri + "\n" fail("Exception occurred while validating the URI: " + path + "\n"
+ " Message: " + e.getMessage()); + " Message: " + e.getMessage());
} }

View File

@ -58,20 +58,36 @@ public class TestUriValidator implements TestValidator {
} }
// Execution // Execution
public TestUriValidator run(final String uri) throws UriParserException, UriValidationException { public TestUriValidator run(final String path) throws UriParserException, UriValidationException {
return run(path, null);
}
public TestUriValidator run(final String path, final String query)
throws UriParserException, UriValidationException {
Parser parser = new Parser(); Parser parser = new Parser();
UriValidator validator = new UriValidator(); UriValidator validator = new UriValidator();
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
validator.validate(uriInfo, HttpMethod.GET); validator.validate(uriInfo, HttpMethod.GET);
return this; return this;
} }
public TestUriValidator runEx(final String uri) { public TestUriValidator run(final String path, final String query, final String fragment)
throws UriParserException, UriValidationException {
uriInfo = new Parser().parseUri(path, query, fragment, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET);
return this;
}
public TestUriValidator runEx(final String path) {
return runEx(path, null);
}
public TestUriValidator runEx(final String path, final String query) {
Parser parser = new Parser(); Parser parser = new Parser();
uriInfo = null; uriInfo = null;
try { try {
uriInfo = parser.parseUri(uri, edm); uriInfo = parser.parseUri(path, query, null, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET); new UriValidator().validate(uriInfo, HttpMethod.GET);
fail("Exception expected"); fail("Exception expected");
} catch (UriParserException e) { } catch (UriParserException e) {
@ -83,20 +99,6 @@ public class TestUriValidator implements TestValidator {
return this; return this;
} }
public TestUriValidator log(final String uri) {
ParserWithLogging parserTest = new ParserWithLogging();
parserTest.setLogLevel(1);
uriInfo = null;
try {
uriInfo = parserTest.parseUri(uri, edm);
} catch (UriParserException e) {
fail("Exception occured while parsing the URI: " + uri + "\n"
+ " Exception: " + e.getMessage());
}
return this;
}
// Navigation // Navigation
public ResourceValidator goPath() { public ResourceValidator goPath() {
if (uriInfo.getKind() != UriInfoKind.resource) { if (uriInfo.getKind() != UriInfoKind.resource) {

View File

@ -31,6 +31,7 @@ import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -268,88 +269,77 @@ public class UriValidatorTest {
@Test @Test
public void validateSelect() throws Exception { public void validateSelect() throws Exception {
String[] uris = { "/ESAllPrim(1)?$select=PropertyString" }; parseAndValidate("/ESAllPrim(1)", "$select=PropertyString", HttpMethod.GET);
for (String uri : uris) {
parseAndValidate(uri, HttpMethod.GET);
}
} }
@Test @Test
public void validateForHttpMethods() throws Exception { public void validateForHttpMethods() throws Exception {
String uri = URI_ENTITY; String uri = URI_ENTITY;
parseAndValidate(uri, HttpMethod.GET); parseAndValidate(uri, null, HttpMethod.GET);
parseAndValidate(uri, HttpMethod.POST); parseAndValidate(uri, null, HttpMethod.POST);
parseAndValidate(uri, HttpMethod.PUT); parseAndValidate(uri, null, HttpMethod.PUT);
parseAndValidate(uri, HttpMethod.DELETE); parseAndValidate(uri, null, HttpMethod.DELETE);
parseAndValidate(uri, HttpMethod.PATCH); parseAndValidate(uri, null, HttpMethod.PATCH);
parseAndValidate(uri, HttpMethod.MERGE); parseAndValidate(uri, null, HttpMethod.MERGE);
} }
@Test @Test
public void validateOrderBy() throws Exception { public void validateOrderBy() throws Exception {
String[] uris = { "/ESAllPrim?$orderby=PropertyString" }; parseAndValidate("/ESAllPrim", "$orderby=PropertyString", HttpMethod.GET);
for (String uri : uris) {
parseAndValidate(uri, HttpMethod.GET);
}
} }
@Test(expected = UriParserSemanticException.class) @Test(expected = UriParserSemanticException.class)
public void validateOrderByInvalid() throws Exception { public void validateOrderByInvalid() throws Exception {
String uri = "/ESAllPrim(1)?$orderby=XXXX"; parseAndValidate("/ESAllPrim(1)", "$orderby=XXXX", HttpMethod.GET);
parseAndValidate(uri, HttpMethod.GET);
} }
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void validateCountInvalid() throws Exception { public void validateCountInvalid() throws Exception {
parseAndValidate("ESAllPrim?$count=foo", HttpMethod.GET); parseAndValidate("ESAllPrim", "$count=foo", HttpMethod.GET);
} }
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void validateTopInvalid() throws Exception { public void validateTopInvalid() throws Exception {
parseAndValidate("ESAllPrim?$top=foo", HttpMethod.GET); parseAndValidate("ESAllPrim", "$top=foo", HttpMethod.GET);
} }
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void validateSkipInvalid() throws Exception { public void validateSkipInvalid() throws Exception {
parseAndValidate("ESAllPrim?$skip=foo", HttpMethod.GET); parseAndValidate("ESAllPrim", "$skip=foo", HttpMethod.GET);
} }
@Test(expected = UriParserSyntaxException.class) @Test(expected = UriParserSyntaxException.class)
public void validateDoubleSystemOptions() throws Exception { public void validateDoubleSystemOptions() throws Exception {
parseAndValidate("ESAllPrim?$skip=1&$skip=2", HttpMethod.GET); parseAndValidate("ESAllPrim", "$skip=1&$skip=2", HttpMethod.GET);
} }
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongKey() throws Exception { public void validateKeyPredicatesWrongKey() throws Exception {
String uri = "ESTwoKeyNav(xxx=1, yyy='abc')"; parseAndValidate("ESTwoKeyNav(xxx=1, yyy='abc')", null, HttpMethod.GET);
parseAndValidate(uri, HttpMethod.GET);
} }
@Test @Test
public void validateKeyPredicates() throws Exception { public void validateKeyPredicates() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16=1, PropertyString='abc')"; parseAndValidate("ESTwoKeyNav(PropertyInt16=1, PropertyString='abc')", null, HttpMethod.GET);
parseAndValidate(uri, HttpMethod.GET);
} }
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongValueType() throws Exception { public void validateKeyPredicatesWrongValueType() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString=1)"; parseAndValidate("ESTwoKeyNav(PropertyInt16='abc', PropertyString=1)", null, HttpMethod.GET);
parseAndValidate(uri, HttpMethod.GET);
} }
@Test(expected = UriValidationException.class) @Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongValueTypeForValidateMethod() throws Exception { public void validateKeyPredicatesWrongValueTypeForValidateMethod() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString='abc')"; parseAndValidate("ESTwoKeyNav(PropertyInt16='abc', PropertyString='abc')", null, HttpMethod.GET);
parseAndValidate(uri, HttpMethod.GET);
} }
@Test @Test
public void checkValidSystemQueryOption() throws Exception { public void checkValidSystemQueryOption() throws Exception {
String[] uris = constructUri(urisWithValidSystemQueryOptions); List<String[]> uris = constructUri(urisWithValidSystemQueryOptions);
for (String uri : uris) { for (String[] uri : uris) {
try { try {
parseAndValidate(uri, HttpMethod.GET); parseAndValidate(uri[0], uri[1], HttpMethod.GET);
} catch (final UriParserException e) { } catch (final UriParserException e) {
fail("Failed for uri: " + uri); fail("Failed for uri: " + uri);
} catch (final UriValidationException e) { } catch (final UriValidationException e) {
@ -360,11 +350,11 @@ public class UriValidatorTest {
@Test @Test
public void checkNonValidSystemQueryOption() throws Exception { public void checkNonValidSystemQueryOption() throws Exception {
String[] uris = constructUri(urisWithNonValidSystemQueryOptions); List<String[]> uris = constructUri(urisWithNonValidSystemQueryOptions);
for (String uri : uris) { for (String[] uri : uris) {
try { try {
parseAndValidate(uri, HttpMethod.GET); parseAndValidate(uri[0], uri[1], HttpMethod.GET);
fail("Validation Exception not thrown: " + uri); fail("Validation Exception not thrown: " + uri);
} catch (UriParserSemanticException e) { } catch (UriParserSemanticException e) {
} catch (UriValidationException e) { } catch (UriValidationException e) {
@ -372,27 +362,25 @@ public class UriValidatorTest {
} }
} }
private String[] constructUri(final String[][] uriParameterMatrix) { private List<String[]> constructUri(final String[][] uriParameterMatrix) {
ArrayList<String> uris = new ArrayList<String>(); List<String[]> uris = new ArrayList<String[]>();
for (String[] uriParameter : uriParameterMatrix) { for (String[] uriParameter : uriParameterMatrix) {
String uri = uriParameter[0]; String path = uriParameter[0];
if (uriParameter.length > 1) { String query = "";
uri += "?";
}
for (int i = 1; i < uriParameter.length; i++) { for (int i = 1; i < uriParameter.length; i++) {
uri += uriParameter[i]; query += uriParameter[i];
if (i < (uriParameter.length - 1)) { if (i < (uriParameter.length - 1)) {
uri += "&"; query += "&";
} }
} }
uris.add(uri); uris.add(new String[] { path, query });
} }
return uris.toArray(new String[uris.size()]); return uris;
} }
private void parseAndValidate(final String uri, final HttpMethod method) private void parseAndValidate(final String path, final String query, final HttpMethod method)
throws UriParserException, UriValidationException { throws UriParserException, UriValidationException {
UriInfo uriInfo = parser.parseUri(uri.trim(), edm); UriInfo uriInfo = parser.parseUri(path.trim(), query, null, edm);
new UriValidator().validate(uriInfo, method); new UriValidator().validate(uriInfo, method);
} }