[OLINGO-917] Fix $entity request handling
This is a contribution from Ramya in https://issues.apache.org/jira/browse/OLINGO-917
This commit is contained in:
parent
84a052dcfa
commit
6a736db10c
|
@ -90,7 +90,7 @@ public class ServiceDispatcher extends RequestURLHierarchyVisitor {
|
||||||
executeIdOption(query, odRequest, odResponse);
|
executeIdOption(query, odRequest, odResponse);
|
||||||
} else {
|
} else {
|
||||||
UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
|
UriInfo uriInfo = new Parser(this.metadata.getEdm(), odata)
|
||||||
.parseUri(path, query, null);
|
.parseUri(path, query, null, odRequest.getRawBaseUri());
|
||||||
|
|
||||||
contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
contentType = ContentNegotiator.doContentNegotiation(uriInfo.getFormatOption(),
|
||||||
odRequest, this.customContentSupport, RepresentationType.ERROR);
|
odRequest, this.customContentSupport, RepresentationType.ERROR);
|
||||||
|
|
|
@ -340,7 +340,8 @@ public abstract class ServiceRequest {
|
||||||
rawPath = rawPath.substring(e+path.length());
|
rawPath = rawPath.substring(e+path.length());
|
||||||
}
|
}
|
||||||
|
|
||||||
UriInfo uriInfo = new Parser(serviceMetadata.getEdm(), odata).parseUri(rawPath, uri.getQuery(), null);
|
UriInfo uriInfo = new Parser(serviceMetadata.getEdm(), odata).parseUri(rawPath, uri.getQuery(), null,
|
||||||
|
getODataRequest().getRawBaseUri());
|
||||||
ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType);
|
ServiceDispatcher dispatcher = new ServiceDispatcher(odata, serviceMetadata, null, customContentType);
|
||||||
dispatcher.visit(uriInfo);
|
dispatcher.visit(uriInfo);
|
||||||
dispatcher.request.setUriInfo(uriInfo);
|
dispatcher.request.setUriInfo(uriInfo);
|
||||||
|
|
|
@ -109,6 +109,7 @@ public class ODataDispatcher {
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case resource:
|
case resource:
|
||||||
|
case entityId:
|
||||||
handleResourceDispatching(request, response);
|
handleResourceDispatching(request, response);
|
||||||
break;
|
break;
|
||||||
|
|
||||||
|
|
|
@ -136,7 +136,7 @@ public class ODataHandlerImpl implements ODataHandler {
|
||||||
final int measurementUriParser = debugger.startRuntimeMeasurement("Parser", "parseUri");
|
final int measurementUriParser = debugger.startRuntimeMeasurement("Parser", "parseUri");
|
||||||
try {
|
try {
|
||||||
uriInfo = new Parser(serviceMetadata.getEdm(), odata)
|
uriInfo = new Parser(serviceMetadata.getEdm(), odata)
|
||||||
.parseUri(request.getRawODataPath(), request.getRawQueryPath(), null);
|
.parseUri(request.getRawODataPath(), request.getRawQueryPath(), null, request.getRawBaseUri());
|
||||||
} catch (final ODataLibraryException e) {
|
} catch (final ODataLibraryException e) {
|
||||||
debugger.stopRuntimeMeasurement(measurementUriParser);
|
debugger.stopRuntimeMeasurement(measurementUriParser);
|
||||||
debugger.stopRuntimeMeasurement(measurementHandle);
|
debugger.stopRuntimeMeasurement(measurementHandle);
|
||||||
|
|
|
@ -146,7 +146,7 @@ public class UriHelperImpl implements UriHelper {
|
||||||
|
|
||||||
try {
|
try {
|
||||||
final List<UriResource> uriResourceParts =
|
final List<UriResource> uriResourceParts =
|
||||||
new Parser(edm, new ODataImpl()).parseUri(oDataPath, null, null).getUriResourceParts();
|
new Parser(edm, new ODataImpl()).parseUri(oDataPath, null, null, rawServiceRoot).getUriResourceParts();
|
||||||
if (uriResourceParts.size() == 1 && uriResourceParts.get(0).getKind() == UriResourceKind.entitySet) {
|
if (uriResourceParts.size() == 1 && uriResourceParts.get(0).getKind() == UriResourceKind.entitySet) {
|
||||||
final UriResourceEntitySet entityUriResource = (UriResourceEntitySet) uriResourceParts.get(0);
|
final UriResourceEntitySet entityUriResource = (UriResourceEntitySet) uriResourceParts.get(0);
|
||||||
|
|
||||||
|
|
|
@ -78,6 +78,8 @@ public class Parser {
|
||||||
private static final String DOLLAR = "$";
|
private static final String DOLLAR = "$";
|
||||||
private static final String AT = "@";
|
private static final String AT = "@";
|
||||||
private static final String NULL = "null";
|
private static final String NULL = "null";
|
||||||
|
private static final String ENTITY = "$entity";
|
||||||
|
private static final String HTTP = "http";
|
||||||
|
|
||||||
private final Edm edm;
|
private final Edm edm;
|
||||||
private final OData odata;
|
private final OData odata;
|
||||||
|
@ -87,7 +89,7 @@ public class Parser {
|
||||||
this.odata = odata;
|
this.odata = odata;
|
||||||
}
|
}
|
||||||
|
|
||||||
public UriInfo parseUri(final String path, final String query, final String fragment)
|
public UriInfo parseUri(final String path, final String query, final String fragment, String baseUri)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
|
|
||||||
UriInfoImpl contextUriInfo = new UriInfoImpl();
|
UriInfoImpl contextUriInfo = new UriInfoImpl();
|
||||||
|
@ -149,16 +151,55 @@ public class Parser {
|
||||||
contextIsCollection = true;
|
contextIsCollection = true;
|
||||||
|
|
||||||
} else if (firstSegment.equals("$entity")) {
|
} else if (firstSegment.equals("$entity")) {
|
||||||
contextUriInfo.setKind(UriInfoKind.entityId);
|
if (null != contextUriInfo.getIdOption()) {
|
||||||
if (numberOfSegments > 1) {
|
String idOptionText = contextUriInfo.getIdOption().getText();
|
||||||
final String typeCastSegment = pathSegmentsDecoded.get(1);
|
if (idOptionText.startsWith(HTTP)) {
|
||||||
ensureLastSegment(typeCastSegment, 2, numberOfSegments);
|
baseUri = UriDecoder.decode(baseUri);
|
||||||
contextType = new ResourcePathParser(edm, contextUriInfo.getAliasMap())
|
if (idOptionText.contains(baseUri)) {
|
||||||
.parseDollarEntityTypeCast(typeCastSegment);
|
idOptionText = idOptionText.substring(baseUri.length() + 1);
|
||||||
contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
|
} else {
|
||||||
|
throw new UriParserSemanticException("$id cannot have an absolute path",
|
||||||
|
UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (numberOfSegments > 1) {
|
||||||
|
/**
|
||||||
|
* If url is of the form
|
||||||
|
* http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/
|
||||||
|
* olingo.odata.test1.ETAllPrim?$id=ESAllPrim(32767)
|
||||||
|
*/
|
||||||
|
final ResourcePathParser resourcePathParser = new ResourcePathParser
|
||||||
|
(edm, contextUriInfo.getAliasMap());
|
||||||
|
String typeCastSegment = pathSegmentsDecoded.get(1);
|
||||||
|
ensureLastSegment(typeCastSegment, 2, numberOfSegments);
|
||||||
|
contextType = resourcePathParser.parseDollarEntityTypeCast(typeCastSegment);
|
||||||
|
contextUriInfo = (UriInfoImpl) new Parser(edm, odata).
|
||||||
|
parseUri("/" + idOptionText, query, fragment, baseUri);
|
||||||
|
contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
|
||||||
|
} else if (numberOfSegments == 1) {
|
||||||
|
/**
|
||||||
|
* If url is of the form
|
||||||
|
* http://localhost:8080/odata-server-tecsvc/odata.svc/$entity?$id=ESAllPrim(32527)
|
||||||
|
*/
|
||||||
|
contextUriInfo = (UriInfoImpl) new Parser(edm, odata).
|
||||||
|
parseUri("/" + idOptionText, query, fragment, baseUri);
|
||||||
|
}
|
||||||
|
contextType = contextUriInfo.getEntityTypeCast();
|
||||||
|
contextUriInfo.setKind(UriInfoKind.entityId);
|
||||||
contextIsCollection = false;
|
contextIsCollection = false;
|
||||||
|
} else {
|
||||||
|
/**
|
||||||
|
* If url is of the form
|
||||||
|
* http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/olingo.odata.test1.ETKeyNav/$ref
|
||||||
|
*/
|
||||||
|
ensureLastSegment(firstSegment, 2, numberOfSegments);
|
||||||
|
/**
|
||||||
|
* If url is of the form
|
||||||
|
* http://localhost:8080/odata-server-tecsvc/odata.svc/$entity/olingo.odata.test1.ETKeyNav
|
||||||
|
*/
|
||||||
|
throw new UriParserSyntaxException("The entity-id MUST be specified using the system query option $id",
|
||||||
|
UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
}
|
||||||
} else if (firstSegment.startsWith("$crossjoin")) {
|
} else if (firstSegment.startsWith("$crossjoin")) {
|
||||||
ensureLastSegment(firstSegment, 1, numberOfSegments);
|
ensureLastSegment(firstSegment, 1, numberOfSegments);
|
||||||
contextUriInfo.setKind(UriInfoKind.crossjoin);
|
contextUriInfo.setKind(UriInfoKind.crossjoin);
|
||||||
|
@ -176,6 +217,14 @@ public class Parser {
|
||||||
UriResource lastSegment = null;
|
UriResource lastSegment = null;
|
||||||
for (final String pathSegment : pathSegmentsDecoded) {
|
for (final String pathSegment : pathSegmentsDecoded) {
|
||||||
count++;
|
count++;
|
||||||
|
if (pathSegment.startsWith(ENTITY)) {
|
||||||
|
/**
|
||||||
|
* If url is of the form
|
||||||
|
* http://localhost:8080/odata-server-tecsvc/odata.svc/ESAllPrim/$entity
|
||||||
|
*/
|
||||||
|
throw new UriParserSyntaxException("The entity-id MUST be specified using the system query option $id",
|
||||||
|
UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
} else {
|
||||||
final UriResource segment = resourcePathParser.parsePathSegment(pathSegment, lastSegment);
|
final UriResource segment = resourcePathParser.parsePathSegment(pathSegment, lastSegment);
|
||||||
if (segment != null) {
|
if (segment != null) {
|
||||||
if (segment instanceof UriResourceCount
|
if (segment instanceof UriResourceCount
|
||||||
|
@ -201,10 +250,16 @@ public class Parser {
|
||||||
contextUriInfo.addResourcePart(segment);
|
contextUriInfo.addResourcePart(segment);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (lastSegment instanceof UriResourcePartTyped) {
|
if (lastSegment instanceof UriResourcePartTyped) {
|
||||||
final UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment;
|
final UriResourcePartTyped typed = (UriResourcePartTyped) lastSegment;
|
||||||
contextType = ParserHelper.getTypeInformation(typed);
|
contextType = ParserHelper.getTypeInformation(typed);
|
||||||
|
if (contextUriInfo.getIdOption() != null && contextType != null) {
|
||||||
|
if (contextType instanceof EdmEntityType) {
|
||||||
|
contextUriInfo.setEntityTypeCast((EdmEntityType) contextType);
|
||||||
|
}
|
||||||
|
}
|
||||||
contextIsCollection = typed.isCollection();
|
contextIsCollection = typed.isCollection();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -78,7 +78,7 @@ public class UriDecoder {
|
||||||
return list;
|
return list;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static String decode(final String encoded) throws UriParserSyntaxException {
|
public static String decode(final String encoded) throws UriParserSyntaxException {
|
||||||
try {
|
try {
|
||||||
return Decoder.decode(encoded);
|
return Decoder.decode(encoded);
|
||||||
} catch (final IllegalArgumentException e) {
|
} catch (final IllegalArgumentException e) {
|
||||||
|
|
|
@ -75,7 +75,9 @@ public class UriParserSemanticException extends UriParserException {
|
||||||
ONLY_FOR_PRIMITIVE_TYPES,
|
ONLY_FOR_PRIMITIVE_TYPES,
|
||||||
/** parameter: function name */
|
/** parameter: function name */
|
||||||
FUNCTION_MUST_USE_COLLECTIONS,
|
FUNCTION_MUST_USE_COLLECTIONS,
|
||||||
COLLECTION_NOT_ALLOWED;
|
COLLECTION_NOT_ALLOWED,
|
||||||
|
/** parameter: not implemented part for system query option $id */
|
||||||
|
NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
|
@ -37,7 +37,9 @@ public class UriParserSyntaxException extends UriParserException {
|
||||||
SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE,
|
SYSTEM_QUERY_OPTION_LEVELS_NOT_ALLOWED_HERE,
|
||||||
SYNTAX,
|
SYNTAX,
|
||||||
/** parameter: alias name */
|
/** parameter: alias name */
|
||||||
DUPLICATED_ALIAS;
|
DUPLICATED_ALIAS,
|
||||||
|
/**Entity id must be followed by system query option id */
|
||||||
|
ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getKey() {
|
public String getKey() {
|
||||||
|
|
|
@ -36,6 +36,7 @@ UriParserSyntaxException.WRONG_VALUE_FOR_SYSTEM_QUERY_OPTION_FORMAT=The system q
|
||||||
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.
|
UriParserSyntaxException.SYNTAX=The URI is malformed.
|
||||||
UriParserSyntaxException.DUPLICATED_ALIAS=Duplicated alias. An alias '%1$s' was already specified!.
|
UriParserSyntaxException.DUPLICATED_ALIAS=Duplicated alias. An alias '%1$s' was already specified!.
|
||||||
|
UriParserSyntaxException.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID=The entity-id must be specified using the system query option $id.
|
||||||
|
|
||||||
SearchParserException.NO_EXPRESSION_FOUND=No expression found.
|
SearchParserException.NO_EXPRESSION_FOUND=No expression found.
|
||||||
SearchParserException.TOKENIZER_EXCEPTION=Exception during tokenizer creation with message '%1$s'.
|
SearchParserException.TOKENIZER_EXCEPTION=Exception during tokenizer creation with message '%1$s'.
|
||||||
|
@ -77,6 +78,7 @@ UriParserSemanticException.IS_PROPERTY=The identifier '%1$s' is already used as
|
||||||
UriParserSemanticException.ONLY_FOR_PRIMITIVE_TYPES='%1$s' is only allowed for primitive-type expressions.
|
UriParserSemanticException.ONLY_FOR_PRIMITIVE_TYPES='%1$s' is only allowed for primitive-type expressions.
|
||||||
UriParserSemanticException.FUNCTION_MUST_USE_COLLECTIONS=Only bound functions with collections of structural types as binding parameter and as return type are allowed; '%1$s' is not such a function.
|
UriParserSemanticException.FUNCTION_MUST_USE_COLLECTIONS=Only bound functions with collections of structural types as binding parameter and as return type are allowed; '%1$s' is not such a function.
|
||||||
UriParserSemanticException.COLLECTION_NOT_ALLOWED=A collection expression is not allowed.
|
UriParserSemanticException.COLLECTION_NOT_ALLOWED=A collection expression is not allowed.
|
||||||
|
UriParserSemanticException.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION=$id with absolute url different from base url is not implemented!
|
||||||
|
|
||||||
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
|
UriValidationException.UNSUPPORTED_QUERY_OPTION=The query option '%1$s' is not supported.
|
||||||
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
|
UriValidationException.UNSUPPORTED_URI_KIND=The URI kind '%1$s' is not supported.
|
||||||
|
|
|
@ -250,7 +250,7 @@ public abstract class TechnicalProcessor implements Processor {
|
||||||
}
|
}
|
||||||
|
|
||||||
protected void validateOptions(final UriInfoResource uriInfo) throws ODataApplicationException {
|
protected void validateOptions(final UriInfoResource uriInfo) throws ODataApplicationException {
|
||||||
if (uriInfo.getIdOption() != null || uriInfo.getApplyOption() != null) {
|
if (uriInfo.getApplyOption() != null) {
|
||||||
throw new ODataApplicationException("Not all of the specified options are supported.",
|
throw new ODataApplicationException("Not all of the specified options are supported.",
|
||||||
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
|
HttpStatusCode.NOT_IMPLEMENTED.getStatusCode(), Locale.ROOT);
|
||||||
}
|
}
|
||||||
|
|
|
@ -141,7 +141,7 @@ public class PreconditionsValidatorTest {
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void simpleEntityValueValidationNotActiveForMedia() throws Exception {
|
public void simpleEntityValueValidationNotActiveForMedia() throws Exception {
|
||||||
final UriInfo uriInfo = new Parser(edm, odata).parseUri("ESMedia(1)/$value", null, null);
|
final UriInfo uriInfo = new Parser(edm, odata).parseUri("ESMedia(1)/$value", null, null, null);
|
||||||
|
|
||||||
CustomETagSupport support = mock(CustomETagSupport.class);
|
CustomETagSupport support = mock(CustomETagSupport.class);
|
||||||
when(support.hasETag(any(EdmBindingTarget.class))).thenReturn(true);
|
when(support.hasETag(any(EdmBindingTarget.class))).thenReturn(true);
|
||||||
|
@ -193,7 +193,7 @@ public class PreconditionsValidatorTest {
|
||||||
|
|
||||||
private boolean mustValidate(final String uri, final String entitySetName)
|
private boolean mustValidate(final String uri, final String entitySetName)
|
||||||
throws UriParserException, UriValidationException, PreconditionException {
|
throws UriParserException, UriValidationException, PreconditionException {
|
||||||
final UriInfo uriInfo = new Parser(edm, odata).parseUri(uri, null, null);
|
final UriInfo uriInfo = new Parser(edm, odata).parseUri(uri, null, null, null);
|
||||||
final List<UriResource> parts = uriInfo.getUriResourceParts();
|
final List<UriResource> parts = uriInfo.getUriResourceParts();
|
||||||
final boolean isMedia = parts.size() >= 2
|
final boolean isMedia = parts.size() >= 2
|
||||||
&& parts.get(parts.size() - 1) instanceof UriResourceValue
|
&& parts.get(parts.size() - 1) instanceof UriResourceValue
|
||||||
|
|
|
@ -498,7 +498,7 @@ public class ApplyParserTest {
|
||||||
|
|
||||||
private ApplyValidator parse(final String path, final String apply)
|
private ApplyValidator parse(final String path, final String apply)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, "$apply=" + apply, null);
|
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, "$apply=" + apply, null, null);
|
||||||
return new ApplyValidator(uriInfo.getApplyOption());
|
return new ApplyValidator(uriInfo.getApplyOption());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,7 +252,7 @@ public class ExpandParserTest {
|
||||||
@Test
|
@Test
|
||||||
public void expandNavigationApplyOption() throws Exception {
|
public void expandNavigationApplyOption() throws Exception {
|
||||||
UriInfo uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
|
UriInfo uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
|
||||||
"$expand=NavPropertyETKeyNavMany($apply=identity),NavPropertyETKeyNavOne", null);
|
"$expand=NavPropertyETKeyNavMany($apply=identity),NavPropertyETKeyNavOne", null, null);
|
||||||
Assert.assertEquals(ApplyItem.Kind.IDENTITY,
|
Assert.assertEquals(ApplyItem.Kind.IDENTITY,
|
||||||
uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0).getKind());
|
uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0).getKind());
|
||||||
Assert.assertEquals("NavPropertyETKeyNavOne",
|
Assert.assertEquals("NavPropertyETKeyNavOne",
|
||||||
|
@ -260,7 +260,7 @@ public class ExpandParserTest {
|
||||||
.getResourcePath().getUriResourceParts().get(0).getSegmentValue());
|
.getResourcePath().getUriResourceParts().get(0).getSegmentValue());
|
||||||
|
|
||||||
uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
|
uriInfo = new Parser(edm, oData).parseUri("ESTwoKeyNav",
|
||||||
"$expand=NavPropertyETKeyNavMany($apply=aggregate(PropertyInt16 with sum as s))", null);
|
"$expand=NavPropertyETKeyNavMany($apply=aggregate(PropertyInt16 with sum as s))", null, null);
|
||||||
final ApplyItem applyItem =
|
final ApplyItem applyItem =
|
||||||
uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0);
|
uriInfo.getExpandOption().getExpandItems().get(0).getApplyOption().getApplyItems().get(0);
|
||||||
Assert.assertEquals(ApplyItem.Kind.AGGREGATE, applyItem.getKind());
|
Assert.assertEquals(ApplyItem.Kind.AGGREGATE, applyItem.getKind());
|
||||||
|
|
|
@ -71,6 +71,8 @@ public class UriParserTest {
|
||||||
testUri.runEx("$all/$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")
|
testUri.runEx("$entity/olingo.odata.test1.ETKeyNav/$ref")
|
||||||
.isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
|
.isExSyntax(UriParserSyntaxException.MessageKeys.MUST_BE_LAST_SEGMENT);
|
||||||
|
testUri.runEx("$entity/olingo.odata.test1.ETKeyNav")
|
||||||
|
.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
|
||||||
testUri.runEx("$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
testUri.runEx("$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
|
||||||
testUri.runEx("", "$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION);
|
testUri.runEx("", "$wrong").isExSyntax(UriParserSyntaxException.MessageKeys.UNKNOWN_SYSTEM_QUERY_OPTION);
|
||||||
|
@ -252,6 +254,78 @@ public class UriParserTest {
|
||||||
.isEntityType(EntityTypeProvider.nameETBase)
|
.isEntityType(EntityTypeProvider.nameETBase)
|
||||||
.isIdText("ESTwoPrim(1)")
|
.isIdText("ESTwoPrim(1)")
|
||||||
.goExpand().first().isSegmentStar();
|
.goExpand().first().isSegmentStar();
|
||||||
|
|
||||||
|
try {
|
||||||
|
testUri.run("$entity/olingo.odata.test1.ETAllNullable")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETAllNullable);
|
||||||
|
} catch (UriParserSyntaxException e) {
|
||||||
|
testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
}
|
||||||
|
testUri.run("$entity/Namespace1_Alias.ETAllPrim", "$id=ESAllPrim(32767)")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETAllPrim)
|
||||||
|
.isIdText("ESAllPrim(32767)");
|
||||||
|
try {
|
||||||
|
testUri.run("ESAllPrim/$entity")
|
||||||
|
.isKind(UriInfoKind.resource);
|
||||||
|
} catch (UriParserSyntaxException e) {
|
||||||
|
testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
testUri.run("ESAllPrim(32767)/NavPropertyETTwoPrimOne/$entity")
|
||||||
|
.isKind(UriInfoKind.resource);
|
||||||
|
} catch(UriParserSyntaxException e) {
|
||||||
|
testUri.isExSyntax(UriParserSyntaxException.MessageKeys.ENTITYID_MISSING_SYSTEM_QUERY_OPTION_ID);
|
||||||
|
}
|
||||||
|
testUri.run("$entity", "$id=ESAllPrim(32767)/NavPropertyETTwoPrimOne")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETTwoPrim)
|
||||||
|
.isIdText("ESAllPrim(32767)/NavPropertyETTwoPrimOne");
|
||||||
|
testUri.run("$entity", "$id=ESAllPrim(32767)", "$select=PropertyString", null)
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETAllPrim)
|
||||||
|
.isIdText("ESAllPrim(32767)");
|
||||||
|
testUri.run("$entity", "$id=ESAllPrim(32767)", "$expand=NavPropertyETTwoPrimOne", null)
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETAllPrim)
|
||||||
|
.isIdText("ESAllPrim(32767)");
|
||||||
|
testUri.run("$entity", "$id=http://localhost:8080/odata-server-tecsvc/odata.svc/"
|
||||||
|
+ "ESAllPrim(32767)/NavPropertyETTwoPrimOne", null,
|
||||||
|
"http://localhost:8080/odata-server-tecsvc/odata.svc")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETTwoPrim)
|
||||||
|
.isIdText("http://localhost:8080/odata-server-tecsvc/odata.svc/"
|
||||||
|
+ "ESAllPrim(32767)/NavPropertyETTwoPrimOne");
|
||||||
|
try {
|
||||||
|
testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecsvc/ESKeyNav(1)",
|
||||||
|
null, "http://localhost:80/tecsvc")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETKeyNav)
|
||||||
|
.isIdText("http://localhost:90/tecsvc/ESKeyNav(1)");
|
||||||
|
} catch (UriParserSemanticException e) {
|
||||||
|
testUri.isExSemantic(UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
|
||||||
|
}
|
||||||
|
try {
|
||||||
|
testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs%27v; c/ESKeyNav(1)",
|
||||||
|
null, "http://localhost:80/tecs%27v; c")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETKeyNav)
|
||||||
|
.isIdText("http://localhost:90/tecs%27v; c/ESKeyNav(1)");
|
||||||
|
} catch (UriParserSemanticException e) {
|
||||||
|
testUri.isExSemantic(UriParserSemanticException.MessageKeys.NOT_IMPLEMENTED_SYSTEM_QUERY_OPTION);
|
||||||
|
}
|
||||||
|
testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs%27v%20c/ESKeyNav(1)",
|
||||||
|
null, "http://localhost:90/tecs%27v%20c")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETKeyNav);
|
||||||
|
String idOption = UriDecoder.decode("http://localhost:90/tecs%27v%20c/ESKeyNav(1)");
|
||||||
|
testUri.isIdText(idOption);
|
||||||
|
testUri.run("$entity/olingo.odata.test1.ETKeyNav", "$id=http://localhost:90/tecs'v c/ESKeyNav(1)",
|
||||||
|
null, "http://localhost:90/tecs'v c")
|
||||||
|
.isKind(UriInfoKind.entityId)
|
||||||
|
.isEntityType(EntityTypeProvider.nameETKeyNav)
|
||||||
|
.isIdText("http://localhost:90/tecs'v c/ESKeyNav(1)");
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -168,7 +168,7 @@ public class FilterValidator implements TestValidator {
|
||||||
|
|
||||||
public FilterValidator runUri(final String path, final String query)
|
public FilterValidator runUri(final String path, final String query)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null);
|
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null, null);
|
||||||
assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
|
assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
|
||||||
setFilter(uriInfo.getFilterOption());
|
setFilter(uriInfo.getFilterOption());
|
||||||
curExpression = filter.getExpression();
|
curExpression = filter.getExpression();
|
||||||
|
@ -181,7 +181,7 @@ public class FilterValidator implements TestValidator {
|
||||||
|
|
||||||
public FilterValidator runUriOrderBy(final String path, final String query)
|
public FilterValidator runUriOrderBy(final String path, final String query)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null);
|
final UriInfo uriInfo = new Parser(edm, odata).parseUri(path, query, null, null);
|
||||||
assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
|
assertTrue("Filtervalidator can only be used on resourcePaths", uriInfo.getKind() == UriInfoKind.resource);
|
||||||
orderBy = uriInfo.getOrderByOption();
|
orderBy = uriInfo.getOrderByOption();
|
||||||
return this;
|
return this;
|
||||||
|
|
|
@ -83,7 +83,7 @@ public class ResourceValidator implements TestValidator {
|
||||||
public ResourceValidator run(final String path) {
|
public ResourceValidator run(final String path) {
|
||||||
UriInfo uriInfoTmp = null;
|
UriInfo uriInfoTmp = null;
|
||||||
try {
|
try {
|
||||||
uriInfoTmp = new Parser(edm, odata).parseUri(path, null, null);
|
uriInfoTmp = new Parser(edm, odata).parseUri(path, null, null, null);
|
||||||
} catch (final ODataLibraryException e) {
|
} catch (final ODataLibraryException e) {
|
||||||
fail("Exception occurred while parsing the URI: " + path + "\n"
|
fail("Exception occurred while parsing the URI: " + path + "\n"
|
||||||
+ " Message: " + e.getMessage());
|
+ " Message: " + e.getMessage());
|
||||||
|
|
|
@ -59,17 +59,28 @@ public class TestUriValidator implements TestValidator {
|
||||||
|
|
||||||
// Execution
|
// Execution
|
||||||
public TestUriValidator run(final String path) throws UriParserException, UriValidationException {
|
public TestUriValidator run(final String path) throws UriParserException, UriValidationException {
|
||||||
return run(path, null, null);
|
return run(path, null, null, null);
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestUriValidator run(final String path, final String query)
|
public TestUriValidator run(final String path, final String query)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
return run(path, query, null);
|
return run(path, query, null, null);
|
||||||
|
}
|
||||||
|
public TestUriValidator run(final String path, final String query, final String fragment, final String baseUri)
|
||||||
|
throws UriParserException, UriValidationException {
|
||||||
|
try {
|
||||||
|
uriInfo = new Parser(edm, odata).parseUri(path, query, fragment, baseUri);
|
||||||
|
new UriValidator().validate(uriInfo, HttpMethod.GET);
|
||||||
|
return this;
|
||||||
|
} catch (UriParserException e) {
|
||||||
|
exception = e;
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public TestUriValidator run(final String path, final String query, final String fragment)
|
public TestUriValidator run(final String path, final String query, final String fragment)
|
||||||
throws UriParserException, UriValidationException {
|
throws UriParserException, UriValidationException {
|
||||||
uriInfo = new Parser(edm, odata).parseUri(path, query, fragment);
|
uriInfo = new Parser(edm, odata).parseUri(path, query, fragment, null);
|
||||||
new UriValidator().validate(uriInfo, HttpMethod.GET);
|
new UriValidator().validate(uriInfo, HttpMethod.GET);
|
||||||
return this;
|
return this;
|
||||||
}
|
}
|
||||||
|
@ -81,7 +92,7 @@ public class TestUriValidator implements TestValidator {
|
||||||
public TestUriValidator runEx(final String path, final String query) {
|
public TestUriValidator runEx(final String path, final String query) {
|
||||||
uriInfo = null;
|
uriInfo = null;
|
||||||
try {
|
try {
|
||||||
run(path, query, null);
|
run(path, query, null, null);
|
||||||
fail("Exception expected");
|
fail("Exception expected");
|
||||||
} catch (UriParserException e) {
|
} catch (UriParserException e) {
|
||||||
exception = e;
|
exception = e;
|
||||||
|
|
|
@ -467,7 +467,7 @@ public class UriValidatorTest {
|
||||||
|
|
||||||
private void validate(final String path, final String query, final HttpMethod method) {
|
private void validate(final String path, final String query, final HttpMethod method) {
|
||||||
try {
|
try {
|
||||||
new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null), method);
|
new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null, null), method);
|
||||||
} catch (final UriParserException e) {
|
} catch (final UriParserException e) {
|
||||||
fail("Failed for " + method + " on URI: " + path + '?' + query);
|
fail("Failed for " + method + " on URI: " + path + '?' + query);
|
||||||
} catch (final UriValidationException e) {
|
} catch (final UriValidationException e) {
|
||||||
|
@ -478,7 +478,7 @@ public class UriValidatorTest {
|
||||||
private void validateWrong(final String path, final String query, final HttpMethod method,
|
private void validateWrong(final String path, final String query, final HttpMethod method,
|
||||||
final UriValidationException.MessageKeys expectedMessageKey) {
|
final UriValidationException.MessageKeys expectedMessageKey) {
|
||||||
try {
|
try {
|
||||||
new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null), method);
|
new UriValidator().validate(new Parser(edm, odata).parseUri(path, query, null, null), method);
|
||||||
fail("Validation Exception not thrown: " + method + ' ' + path + '?' + query);
|
fail("Validation Exception not thrown: " + method + ' ' + path + '?' + query);
|
||||||
} catch (final UriParserException e) {
|
} catch (final UriParserException e) {
|
||||||
fail("Wrong Exception thrown: " + method + ' ' + path + '?' + query);
|
fail("Wrong Exception thrown: " + method + ' ' + path + '?' + query);
|
||||||
|
|
Loading…
Reference in New Issue