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

View File

@ -76,62 +76,58 @@ public class Parser {
return this;
}
public UriInfo parseUri(final String input, final Edm edm) throws UriParserException {
boolean readQueryParameter = false;
boolean readFragment = false;
public UriInfo parseUri(final String path, final String query, final String fragment, final Edm edm)
throws UriParserException {
UriContext context = new UriContext();
UriParseTreeVisitor uriParseTreeVisitor = new UriParseTreeVisitor(edm, context);
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
String firstSegment = "";
if (uri.pathSegmentListDecoded.size() > 0) {
firstSegment = uri.pathSegmentListDecoded.get(0);
}
final String firstSegment = uri.pathSegmentListDecoded.isEmpty() ? "" : uri.pathSegmentListDecoded.get(0);
if (firstSegment.length() == 0) {
readQueryParameter = true;
if (firstSegment.isEmpty()) {
ensureLastSegment(firstSegment, 0, uri.pathSegmentListDecoded.size());
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.service);
} else if (firstSegment.startsWith("$batch")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
BatchEOFContext ctxBatchEOF =
(BatchEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Batch);
uriParseTreeVisitor.visitBatchEOF(ctxBatchEOF);
readQueryParameter = true;
} else if (firstSegment.startsWith("$metadata")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
MetadataEOFContext ctxMetadataEOF =
(MetadataEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.Metadata);
uriParseTreeVisitor.visitMetadataEOF(ctxMetadataEOF);
readQueryParameter = true;
readFragment = true;
context.contextUriInfo.setFragment(uri.fragment);
} else if (firstSegment.startsWith("$entity")) {
context.contextUriInfo = new UriInfoImpl().setKind(UriInfoKind.entityId);
if (uri.pathSegmentListDecoded.size() > 1) {
final String typeCastSegment = uri.pathSegmentListDecoded.get(1);
ensureLastSegment(typeCastSegment, 2, uri.pathSegmentListDecoded.size());
EntityEOFContext ctxEntityEOF =
(EntityEOFContext) parseRule(uri.pathSegmentListDecoded.get(1), ParserEntryRules.Entity);
(EntityEOFContext) parseRule(typeCastSegment, ParserEntryRules.Entity);
uriParseTreeVisitor.visitEntityEOF(ctxEntityEOF);
}
readQueryParameter = true;
} else if (firstSegment.startsWith("$all")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
AllEOFContext ctxResourcePathEOF =
(AllEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.All);
uriParseTreeVisitor.visitAllEOF(ctxResourcePathEOF);
readQueryParameter = true;
} else if (firstSegment.startsWith("$crossjoin")) {
ensureLastSegment(firstSegment, 1, uri.pathSegmentListDecoded.size());
CrossjoinEOFContext ctxResourcePathEOF =
(CrossjoinEOFContext) parseRule(uri.pathSegmentListDecoded.get(0), ParserEntryRules.CrossJoin);
uriParseTreeVisitor.visitCrossjoinEOF(ctxResourcePathEOF);
readQueryParameter = true;
} else {
List<PathSegmentEOFContext> ctxPathSegments = new ArrayList<PathSegmentEOFContext>();
for (String pathSegment : uri.pathSegmentListDecoded) {
@ -155,141 +151,131 @@ public class Parser {
UriParseTreeVisitor.TypeInformation typeInfo =
uriParseTreeVisitor.new TypeInformation(myType.type, typed.isCollection());
context.contextTypes.push(typeInfo);
}
readQueryParameter = true;
}
if (readQueryParameter) {
// second, read the system query options and the custom query options
for (RawUri.QueryOption option : uri.queryOptionListDecoded) {
if (option.name.startsWith("$")) {
SystemQueryOption systemOption = null;
if (option.name.equals(SystemQueryOptionKind.FILTER.toString())) {
FilterExpressionEOFContext ctxFilterExpression =
(FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
// second, read the system query options and the custom query options
for (RawUri.QueryOption option : uri.queryOptionListDecoded) {
if (option.name.startsWith("$")) {
SystemQueryOption systemOption = null;
if (option.name.equals(SystemQueryOptionKind.FILTER.toString())) {
FilterExpressionEOFContext ctxFilterExpression =
(FilterExpressionEOFContext) parseRule(option.value, ParserEntryRules.FilterExpression);
FilterOptionImpl filterOption =
(FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
FilterOptionImpl filterOption =
(FilterOptionImpl) uriParseTreeVisitor.visitFilterExpressionEOF(ctxFilterExpression);
systemOption = filterOption;
systemOption = filterOption;
} else if (option.name.equals(SystemQueryOptionKind.FORMAT.toString())) {
FormatOptionImpl formatOption = new FormatOptionImpl();
formatOption.setName(option.name);
formatOption.setText(option.value);
if (option.value.equalsIgnoreCase(ODataFormat.JSON.name())
|| option.value.equalsIgnoreCase(ODataFormat.XML.name())
|| option.value.equalsIgnoreCase(ODataFormat.ATOM.name())
|| isFormatSyntaxValid(option)) {
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 if (option.name.equals(SystemQueryOptionKind.FORMAT.toString())) {
FormatOptionImpl formatOption = new FormatOptionImpl();
formatOption.setName(option.name);
formatOption.setText(option.value);
if (option.value.equalsIgnoreCase(ODataFormat.JSON.name())
|| option.value.equalsIgnoreCase(ODataFormat.XML.name())
|| option.value.equalsIgnoreCase(ODataFormat.ATOM.name())
|| isFormatSyntaxValid(option.value)) {
formatOption.setFormat(option.value);
} else {
throw new UriParserSyntaxException("Unknown system query option!",
UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION, option.name);
throw new UriParserSyntaxException("Illegal value of $format option!",
UriParserSyntaxException.MessageKeys.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT, option.value);
}
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);
}
}
}
systemOption = formatOption;
if (readFragment) {
context.contextUriInfo.setFragment(uri.fragment);
} 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 {
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;
@ -300,9 +286,17 @@ public class Parser {
}
}
private boolean isFormatSyntaxValid(RawUri.QueryOption option) {
final int index = option.value.indexOf('/');
return index > 0 && index < option.value.length() - 1 && index == option.value.lastIndexOf('/');
private void ensureLastSegment(final String segment, final int pos, final int size)
throws UriParserSyntaxException {
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)

View File

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

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

View File

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

View File

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

View File

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

View File

@ -86,22 +86,22 @@ public class ResourceValidator implements TestValidator {
// --- Execution ---
public ResourceValidator run(final String uri) {
public ResourceValidator run(final String path) {
ParserWithLogging testParser = new ParserWithLogging();
UriInfo uriInfoTmp = null;
uriPathInfo = null;
try {
uriInfoTmp = testParser.parseUri(uri, edm);
uriInfoTmp = testParser.parseUri(path, null, null, edm);
} 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());
}
try {
new UriValidator().validate(uriInfoTmp, HttpMethod.GET);
} 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());
}

View File

@ -58,20 +58,36 @@ public class TestUriValidator implements TestValidator {
}
// 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();
UriValidator validator = new UriValidator();
uriInfo = parser.parseUri(uri, edm);
uriInfo = parser.parseUri(path, query, null, edm);
validator.validate(uriInfo, HttpMethod.GET);
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();
uriInfo = null;
try {
uriInfo = parser.parseUri(uri, edm);
uriInfo = parser.parseUri(path, query, null, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET);
fail("Exception expected");
} catch (UriParserException e) {
@ -83,20 +99,6 @@ public class TestUriValidator implements TestValidator {
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
public ResourceValidator goPath() {
if (uriInfo.getKind() != UriInfoKind.resource) {

View File

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