[OLINGO-348] Make Uri Parser exception translatable

This commit is contained in:
Christian Amend 2014-08-06 17:09:29 +02:00
parent 5c0b34a92d
commit d19afa013b
19 changed files with 353 additions and 140 deletions

View File

@ -68,7 +68,8 @@ public final class EdmDecimal extends SingletonPrimitiveType {
}
private static boolean validateLiteral(final String value) {
return PATTERN.matcher(value).matches();
boolean valid = PATTERN.matcher(value).matches();
return valid;
}
private static final boolean validatePrecisionAndScale(final String value, final Integer precision,

View File

@ -90,4 +90,10 @@ public class EdmTimeOfDayTest extends PrimitiveTypeBaseTest {
expectTypeErrorInValueOfString(instance, "11:12:13");
}
@Test
public void tests() throws Exception {
instance.validate("12:34:55", null, null, null, null, null);
}
}

View File

@ -115,4 +115,10 @@ public interface UriInfoResource {
*/
List<UriResource> getUriResourceParts();
/**
* @param alias
* @return the value for the given alias or null if no value is defined
*/
String getValueForAlias(String alias);
}

View File

@ -74,7 +74,7 @@ public class ODataHandler {
processInternal(request, requestedContentType, response);
} catch (UriParserException e) {
e.printStackTrace();
} catch (ContentNegotiatorException e) {
Locale requestedLocale = null;
ODataServerError serverError =

View File

@ -62,6 +62,7 @@ public class UriInfoImpl implements UriInfo {
private EdmEntityType entityTypeCast; // for $entity
private List<CustomQueryOptionImpl> customQueryOptions = new ArrayList<CustomQueryOptionImpl>();
private HashMap<String, String> aliasToValue = new HashMap<String, String>();
HashMap<SystemQueryOptionKind, SystemQueryOption> systemQueryOptions =
new HashMap<SystemQueryOptionKind, SystemQueryOption>();
@ -134,6 +135,11 @@ public class UriInfoImpl implements UriInfo {
return retList;
}
@Override
public String getValueForAlias(String alias) {
return aliasToValue.get(alias);
}
@Override
public EdmEntityType getEntityTypeCast() {
return entityTypeCast;
@ -228,6 +234,9 @@ public class UriInfoImpl implements UriInfo {
public void addCustomQueryOption(final QueryOptionImpl item) {
customQueryOptions.add((CustomQueryOptionImpl) item);
if (item.getName().startsWith("@")) {
aliasToValue.put(item.getName(), item.getText());
}
}
public UriInfoImpl setSystemQueryOption(final SystemQueryOptionImpl systemOption) {

View File

@ -221,7 +221,8 @@ public class Parser {
try {
inlineCountOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSemanticException("Illegal value of $skip option!", e);
throw new UriParserSemanticException("Illegal value of $skip option!", e,
UriParserSemanticException.MessageKeys.TEST);
}
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$skiptoken")) {
@ -237,7 +238,8 @@ public class Parser {
try {
inlineCountOption.setValue(Integer.parseInt(option.value));
} catch (final NumberFormatException e) {
throw new UriParserSemanticException("Illegal value of $top option!", e);
throw new UriParserSemanticException("Illegal value of $top option!", e,
UriParserSemanticException.MessageKeys.TEST);
}
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
} else if (option.name.equals("$count")) {
@ -248,7 +250,8 @@ public class Parser {
if (option.value.equals("true") || option.value.equals("false")) {
inlineCountOption.setValue(Boolean.parseBoolean(option.value));
} else {
throw new UriParserSemanticException("Illegal value of $count option!");
throw new UriParserSemanticException("Illegal value of $count option!",
UriParserSemanticException.MessageKeys.TEST);
}
context.contextUriInfo.setSystemQueryOption(inlineCountOption);
}
@ -396,12 +399,12 @@ public class Parser {
}
} catch (Exception weakException) {
throw new UriParserSyntaxException("Error in syntax", weakException);
throw new UriParserSyntaxException("Error in syntax", weakException, UriParserSyntaxException.MessageKeys.TEST);
// exceptionOnStage = 2;
}
} catch (Exception hardException) {
throw new UriParserSyntaxException("Error in syntax", hardException);
throw new UriParserSyntaxException("Error in syntax", hardException, UriParserSyntaxException.MessageKeys.TEST);
}
return ret;

View File

@ -343,7 +343,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
tmp += (tmp.length() != 0 ? "," : "") + name;
}
throw wrap(new UriParserSemanticException("Function of functionimport '" + edmFunctionImport.getName()
+ "' with parameters [" + tmp + "] not found"));
+ "' with parameters [" + tmp + "] not found", UriParserSemanticException.MessageKeys.TEST));
}
uriResource.setFunction(edmFunctionImport.getUnboundFunction(names));
@ -358,7 +358,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastResourcePart == null) {
if (context.contextTypes.size() == 0) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
+ "resource parts"));
+ "resource parts", UriParserSemanticException.MessageKeys.TEST));
}
source = context.contextTypes.peek();
} else {
@ -366,7 +366,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (source.type == null) {
throw wrap(new UriParserSemanticException("Resource part '" + odi + "' can only applied on typed "
+ "resource parts"));
+ "resource parts", UriParserSemanticException.MessageKeys.TEST));
}
}
@ -385,7 +385,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(source.type instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Can not parse'" + odi
+ "'Previous path segment not a structural type."));
+ "'Previous path segment not a structural type.", UriParserSemanticException.MessageKeys.TEST));
}
EdmStructuredType structType = (EdmStructuredType) source.type;
@ -393,7 +393,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmElement property = structType.getProperty(odi);
if (property == null) {
throw wrap(new UriParserSemanticException("Property '" + odi + "' not found in type '"
+ structType.getNamespace() + "." + structType.getName() + "'"));
+ structType.getNamespace() + "." + structType.getName() + "'",
UriParserSemanticException.MessageKeys.TEST));
}
if (property instanceof EdmProperty) {
@ -417,7 +418,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
context.contextUriInfo.addResourcePart(navigationResource);
return null;
} else {
throw wrap(new UriParserSemanticException("Unkown type for property '" + property + "'"));
throw wrap(new UriParserSemanticException("Unkown type for property '" + property + "'",
UriParserSemanticException.MessageKeys.TEST));
}
} else { // with namespace
@ -432,7 +434,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// is entity type cast
if (!(filterEntityType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException(
"Entity typefilter not compatible to previous path segment: " + fullFilterName.toString()));
"Entity typefilter not compatible to previous path segment: " + fullFilterName.toString(),
UriParserSemanticException.MessageKeys.TEST));
}
if (lastResourcePart == null) {
@ -457,7 +460,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnEntry() != null) {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'"));
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TEST));
}
lastPartWithKeys.setEntryTypeFilter(filterEntityType);
return null;
@ -465,7 +469,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnCollection() != null) {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'"));
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TEST));
}
lastPartWithKeys.setCollectionTypeFilter(filterEntityType);
return null;
@ -475,14 +480,14 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterEntityType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'"));
+ getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
}
lastPartTyped.setTypeFilter(filterEntityType);
return null;
} else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterEntityType)
+ "' not typed"));
+ "' not typed", UriParserSemanticException.MessageKeys.TEST));
}
}
}
@ -497,7 +502,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!(filterComplexType.compatibleTo(source.type))) {
throw wrap(new UriParserSemanticException(
"Complex typefilter '" + getName(source.type) + "'not compatible type of previous path segment '"
+ getName(filterComplexType) + "'"));
+ getName(filterComplexType) + "'", UriParserSemanticException.MessageKeys.TEST));
}
// is simple complex type cast
@ -523,7 +528,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnEntry() != null) {
throw wrap(new UriParserSemanticException("Entry typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'"));
+ getName(lastPartWithKeys.getTypeFilterOnEntry()) + "'",
UriParserSemanticException.MessageKeys.TEST));
}
lastPartWithKeys.setEntryTypeFilter(filterComplexType);
return null;
@ -531,7 +537,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartWithKeys.getTypeFilterOnCollection() != null) {
throw wrap(new UriParserSemanticException("Collection typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'"));
+ getName(lastPartWithKeys.getTypeFilterOnCollection()) + "'",
UriParserSemanticException.MessageKeys.TEST));
}
lastPartWithKeys.setCollectionTypeFilter(filterComplexType);
return null;
@ -542,14 +549,14 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (lastPartTyped.getTypeFilter() != null) {
throw wrap(new UriParserSemanticException("Typefilters are not chainable, used '"
+ getName(filterComplexType) + "' behind '"
+ getName(lastPartTyped.getTypeFilter()) + "'"));
+ getName(lastPartTyped.getTypeFilter()) + "'", UriParserSemanticException.MessageKeys.TEST));
}
lastPartTyped.setTypeFilter(filterComplexType);
return null;
} else {
throw wrap(new UriParserSemanticException("Path segment before '" + getName(filterComplexType)
+ "' not typed"));
+ "' not typed", UriParserSemanticException.MessageKeys.TEST));
}
}
}
@ -569,7 +576,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// do a check for bound functions (which requires a parameter list)
if (ctx.vlNVO.size() == 0) {
throw wrap(new UriParserSemanticException("Expected function parameters for '" + fullBindingTypeName.toString()
+ "'"));
+ "'", UriParserSemanticException.MessageKeys.TEST));
}
context.contextReadingFunctionParameters = true;
@ -610,7 +617,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return null;
}
throw wrap(new UriParserSemanticException("Unknown resource path segment:" + fullFilterName.toString()));
throw wrap(new UriParserSemanticException("Unknown resource path segment:" + fullFilterName.toString(),
UriParserSemanticException.MessageKeys.TEST));
}
}
@ -631,7 +639,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResource obj = context.contextUriInfo.getLastResourcePart();
if (!(obj instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("any only allowed on typed path segments"));
throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
}
UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@ -770,7 +779,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
EdmEntityType type = edm.getEntityType(fullName);
if (type == null) {
throw wrap(new UriParserSemanticException("Expected EntityTypeName"));
throw wrap(new UriParserSemanticException("Expected EntityTypeName",
UriParserSemanticException.MessageKeys.TEST));
}
context.contextUriInfo.setEntityTypeCast(type);
@ -855,7 +865,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (ctx.vLV != null) {
UriResourceImpl lastResourcePart = (UriResourceImpl) context.contextUriInfo.getLastResourcePart();
if (!(lastResourcePart instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("any only allowed on typed path segments"));
throw wrap(new UriParserSemanticException("any only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
}
UriContext.LambdaVariables var = new UriContext.LambdaVariables();
@ -957,11 +968,13 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (!((UriResourcePartTyped) pathInfo).isCollection()) {
context.contextUriInfo.addResourcePart(new UriResourceValueImpl());
} else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments"));
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
}
return null;
} else {
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments"));
throw wrap(new UriParserSemanticException("$value only allowed on typed path segments",
UriParserSemanticException.MessageKeys.TEST));
}
} else if (ctx.vC != null) {
@ -969,10 +982,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (((UriResourcePartTyped) pathInfo).isCollection()) {
context.contextUriInfo.addResourcePart(new UriResourceCountImpl());
} else {
throw wrap(new UriParserSemanticException("$count only allowed on collection properties"));
throw wrap(new UriParserSemanticException("$count only allowed on collection properties",
UriParserSemanticException.MessageKeys.TEST));
}
} else {
throw wrap(new UriParserSemanticException("$count only allowed on typed properties"));
throw wrap(new UriParserSemanticException("$count only allowed on typed properties",
UriParserSemanticException.MessageKeys.TEST));
}
} else if (ctx.vR != null) {
if (pathInfo instanceof UriResourcePartTyped) {
@ -980,10 +995,12 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
if (type instanceof EdmEntityType) {
context.contextUriInfo.addResourcePart(new UriResourceRefImpl());
} else {
throw wrap(new UriParserSemanticException("$ref only allowed on endity types"));
throw wrap(new UriParserSemanticException("$ref only allowed on endity types",
UriParserSemanticException.MessageKeys.TEST));
}
} else {
throw wrap(new UriParserSemanticException("$ref only allowed on typed properties"));
throw wrap(new UriParserSemanticException("$ref only allowed on typed properties",
UriParserSemanticException.MessageKeys.TEST));
}
} else if (ctx.vAll != null) {
@ -1393,13 +1410,15 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
try {
expression = (ExpressionImpl) ctx.vVO.accept(this);
} catch (Exception ex) {
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText));
throw wrap(new UriParserSemanticException("Invalid key value: " + valueText,
UriParserSemanticException.MessageKeys.TEST));
}
// get type of last resource part
UriResource last = context.contextUriInfo.getLastResourcePart();
if (!(last instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Paramterslist on untyped resource path segement not allowed"));
throw wrap(new UriParserSemanticException("Paramterslist on untyped resource path segement not allowed",
UriParserSemanticException.MessageKeys.TEST));
}
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@ -1420,14 +1439,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// key.
// for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined"));
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
}
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined"));
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
}
// create the keylist
@ -1445,7 +1466,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
missedKey = item;
} else {
// two of more keys are missing
throw wrap(new UriParserSemanticException("Not enougth referntial contrains defined"));
throw wrap(new UriParserSemanticException("Not enougth referntial contrains defined",
UriParserSemanticException.MessageKeys.TEST));
}
}
}
@ -1479,7 +1501,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// get type of last resource part
if (!(last instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Parameterslist on untyped resource path segement not allowed"));
throw wrap(new UriParserSemanticException("Parameterslist on untyped resource path segement not allowed",
UriParserSemanticException.MessageKeys.TEST));
}
EdmEntityType lastType = (EdmEntityType) ((UriResourcePartTyped) last).getType();
@ -1494,14 +1517,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
// if not, check if the missing key predicates can be satisfied with help of the defined referential constrains
// for using referential constrains the last resource part must be a navigation property
if (!(context.contextUriInfo.getLastResourcePart() instanceof UriResourceNavigationPropertyImpl)) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined"));
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
}
UriResourceNavigationPropertyImpl lastNav = (UriResourceNavigationPropertyImpl) last;
// get the partner of the navigation property
EdmNavigationProperty partner = lastNav.getProperty().getPartner();
if (partner == null) {
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined"));
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
}
// fill missing keys from referential constrains
@ -1528,7 +1553,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return list;
}
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined"));
throw wrap(new UriParserSemanticException("Not enougth keyproperties defined",
UriParserSemanticException.MessageKeys.TEST));
}
return new ArrayList<String>();
}
@ -1542,7 +1568,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
uriParameter.setText(ctx.vCOM.getText());
uriParameter.setExpression((ExpressionImpl) ctx.vCOM.accept(this));
} else {
uriParameter.setAlias(ctx.vALI.getText());
uriParameter.setAlias("@" + ctx.vALI.getText());
}
return uriParameter;
@ -1631,7 +1657,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
((UriResourceWithKeysImpl) pathInfoSegment)
.setKeyPredicates(list);
} else {
throw wrap(new UriParserSemanticException("Key properties not allowed"));
throw wrap(new UriParserSemanticException("Key properties not allowed",
UriParserSemanticException.MessageKeys.TEST));
// throw UriSemanticError.addKrepredicatesNotAllowed();
}
}
@ -1698,7 +1725,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriResource lastResource = context.contextUriInfo.getLastResourcePart();
if (!(lastResource instanceof UriResourcePartTyped)) {
throw wrap(new UriParserSemanticException("Resource path not typed"));
throw wrap(new UriParserSemanticException("Resource path not typed",
UriParserSemanticException.MessageKeys.TEST));
}
UriResourcePartTyped lastType = (UriResourcePartTyped) lastResource;
@ -1803,18 +1831,21 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
prevType = getTypeInformation(last).type;
if (prevType == null) {
throw wrap(new UriParserSemanticException("prev segement not typed"));
throw wrap(new UriParserSemanticException("prev segement not typed",
UriParserSemanticException.MessageKeys.TEST));
}
}
if (!(prevType instanceof EdmStructuredType)) {
throw wrap(new UriParserSemanticException("Previous select item is not a structural type"));
throw wrap(new UriParserSemanticException("Previous select item is not a structural type",
UriParserSemanticException.MessageKeys.TEST));
}
EdmStructuredType structType = (EdmStructuredType) prevType;
EdmElement element = structType.getProperty(odi);
if (element == null) {
throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi));
throw wrap(new UriParserSemanticException("Previous select item has not property: " + odi,
UriParserSemanticException.MessageKeys.TEST));
}
// create new segment
@ -1864,7 +1895,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
return this;
}
} else {
throw wrap(new UriParserSemanticException("Only Simple and Complex properties within select allowed"));
throw wrap(new UriParserSemanticException("Only Simple and Complex properties within select allowed",
UriParserSemanticException.MessageKeys.TEST));
}
} else {
String namespace = ctx.vNS.getText();
@ -1916,14 +1948,16 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
}
} else {
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type"));
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
UriParserSemanticException.MessageKeys.TEST));
}
} else {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) {
throw wrap(new UriParserSemanticException("prev segement typed"));
throw wrap(new UriParserSemanticException("prev segement typed",
UriParserSemanticException.MessageKeys.TEST));
}
EdmType prevType = getTypeInformation(last).type;
@ -1939,7 +1973,7 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
}
}
} else if (prevType instanceof EdmEntityType) {
throw wrap(new UriParserSemanticException("Error"));
throw wrap(new UriParserSemanticException("Error", UriParserSemanticException.MessageKeys.TEST));
/*
* EdmEntityType et = edm.getEntityType(fullName);
* if (et != null) {
@ -1953,7 +1987,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
* }
*/
} else {
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type"));
throw wrap(new UriParserSemanticException("prev segement must be comlex of entity type",
UriParserSemanticException.MessageKeys.TEST));
}
}
@ -1964,7 +1999,8 @@ public class UriParseTreeVisitor extends UriParserBaseVisitor<Object> {
UriInfoImpl uriInfo = (UriInfoImpl) context.contextSelectItem.getResourcePath();
UriResource last = uriInfo.getLastResourcePart();
if (!(last instanceof UriResourceTypedImpl)) {
throw wrap(new UriParserSemanticException("prev segement typed"));
throw wrap(new UriParserSemanticException("prev segement typed",
UriParserSemanticException.MessageKeys.TEST));
}
prevType = getTypeInformation(last).type;
}

View File

@ -18,18 +18,18 @@
*/
package org.apache.olingo.server.core.uri.parser;
public class UriParserException extends Exception {
/**
*
*/
private static final long serialVersionUID = 1L;
import org.apache.olingo.server.api.ODataTranslatedException;
public UriParserException(final String message, final Throwable cause) {
super(message, cause);
public class UriParserException extends ODataTranslatedException {
private static final long serialVersionUID = -6438700016830955949L;
public UriParserException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
}
public UriParserException(final String message) {
super(message, null);
public UriParserException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
}

View File

@ -20,14 +20,18 @@ package org.apache.olingo.server.core.uri.parser;
public class UriParserSemanticException extends UriParserException {
private static final long serialVersionUID = 1L;
public UriParserSemanticException(final String message, final Throwable cause) {
super(message, cause);
private static final long serialVersionUID = 3850285860949809622L;
public static enum MessageKeys implements MessageKey {
TEST
}
public UriParserSemanticException(final String message) {
super(message, null);
public UriParserSemanticException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
}
public UriParserSemanticException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
}

View File

@ -20,17 +20,18 @@ package org.apache.olingo.server.core.uri.parser;
public class UriParserSyntaxException extends UriParserException {
/**
*
*/
private static final long serialVersionUID = 1L;
private static final long serialVersionUID = 5887744747812478226L;
public UriParserSyntaxException(final String message, final Throwable cause) {
super(message, cause);
public static enum MessageKeys implements MessageKey {
TEST
}
public UriParserSyntaxException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
}
public UriParserSyntaxException(final String message) {
super(message, null);
public UriParserSyntaxException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
}

View File

@ -18,17 +18,47 @@
*/
package org.apache.olingo.server.core.uri.validator;
import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeException;
import org.apache.olingo.server.api.ODataTranslatedException;
public class UriValidationException extends Exception {
public class UriValidationException extends ODataTranslatedException {
private static final long serialVersionUID = -3179078078053564742L;
public UriValidationException(final String msg) {
super(msg);
public static enum MessageKeys implements MessageKey {
/** parameter: unsupported query option */
UNSUPPORTED_QUERY_OPTION,
/** parameter: unsupported uri kind */
UNSUPPORTED_URI_KIND,
/** parameter: unsupported uri resource kind */
UNSUPPORTED_URI_RESOURCE_KIND,
/** parameter: unsupported function return type */
UNSUPPORTED_FUNCTION_RETURN_TYPE,
/** parameter: unsupported action return type */
UNSUPPORTED_ACTION_RETURN_TYPE,
/** parameter: unsupported http method */
UNSUPPORTED_HTTP_METHOD,
/** parameter: system query option */
SYSTEM_QUERY_OPTION_NOT_ALLOWED,
/** parameters: system query option, http method */
SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD,
/** parameter: invalid key property */
INVALID_KEY_PROPERTY,
/** parameter: untyped segment name */
LAST_SEGMENT_NOT_TYPED,
/** parameter: untyped segment name */
SECOND_LAST_SEGMENT_NOT_TYPED,
/** parameter: unallowed kind before $value */
UNALLOWED_KIND_BEFORE_VALUE,
/** parameter: unallowed kind before $count */
UNALLOWED_KIND_BEFORE_COUNT,
}
public UriValidationException(String developmentMessage, MessageKey messageKey, String... parameters) {
super(developmentMessage, messageKey, parameters);
}
public UriValidationException(final EdmPrimitiveTypeException e) {
super(e);
public UriValidationException(String developmentMessage, Throwable cause, MessageKey messageKey,
String... parameters) {
super(developmentMessage, cause, messageKey, parameters);
}
}

View File

@ -41,6 +41,7 @@ import org.apache.olingo.server.api.uri.UriResourceKind;
import org.apache.olingo.server.api.uri.UriResourceNavigation;
import org.apache.olingo.server.api.uri.UriResourcePartTyped;
import org.apache.olingo.server.api.uri.UriResourceSingleton;
import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOption;
import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
@ -219,7 +220,8 @@ public class UriValidator {
idx = ColumnIndex.top;
break;
default:
throw new UriValidationException("Unsupported option: " + queryOptionKind);
throw new UriValidationException("Unsupported option: " + queryOptionKind.toString(),
UriValidationException.MessageKeys.UNSUPPORTED_QUERY_OPTION, queryOptionKind.toString());
}
return idx;
@ -251,7 +253,8 @@ public class UriValidator {
idx = RowIndexForUriType.service;
break;
default:
throw new UriValidationException("Unsupported uriInfo kind: " + uriInfo.getKind());
throw new UriValidationException("Unsupported uriInfo kind: " + uriInfo.getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_URI_KIND, uriInfo.getKind().toString());
}
return idx;
@ -300,7 +303,8 @@ public class UriValidator {
idx = rowIndexForValue(uriInfo);
break;
default:
throw new UriValidationException("Unsupported uriResource kind: " + lastPathSegment.getKind());
throw new UriValidationException("Unsupported uriResource kind: " + lastPathSegment.getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_URI_RESOURCE_KIND, lastPathSegment.getKind().toString());
}
return idx;
@ -367,7 +371,8 @@ public class UriValidator {
break;
default:
throw new UriValidationException("Unexpected kind in path segment before $value: "
+ secondLastPathSegment.getKind());
+ secondLastPathSegment.getKind(), UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_VALUE,
secondLastPathSegment.toString());
}
return idx;
}
@ -388,7 +393,8 @@ public class UriValidator {
idx = isCollection ? RowIndexForUriType.propertyPrimitiveCollection : RowIndexForUriType.propertyPrimitive;
break;
default:
throw new UriValidationException("Unsupported function return type: " + functionReturnTypeKind);
throw new UriValidationException("Unsupported function return type: " + functionReturnTypeKind,
UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE, functionReturnTypeKind.toString());
}
return idx;
}
@ -405,7 +411,8 @@ public class UriValidator {
: RowIndexForUriType.reference;
} else {
throw new UriValidationException("secondLastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass());
+ lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
}
return idx;
@ -420,7 +427,8 @@ public class UriValidator {
: RowIndexForUriType.propertyPrimitive;
} else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass());
+ lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
}
return idx;
}
@ -444,7 +452,9 @@ public class UriValidator {
idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex;
break;
default:
throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind());
throw new UriValidationException("Unsupported function return type: " + rt.getType().getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_FUNCTION_RETURN_TYPE,
rt.getType().getKind().toString());
}
return idx;
@ -458,7 +468,8 @@ public class UriValidator {
: RowIndexForUriType.entity;
} else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass());
+ lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
}
return idx;
}
@ -472,7 +483,8 @@ public class UriValidator {
: RowIndexForUriType.propertyComplex;
} else {
throw new UriValidationException("lastPathSegment not a class of UriResourcePartTyped: "
+ lastPathSegment.getClass());
+ lastPathSegment.getClass(), UriValidationException.MessageKeys.LAST_SEGMENT_NOT_TYPED, lastPathSegment
.toString());
}
return idx;
}
@ -496,7 +508,8 @@ public class UriValidator {
idx = rt.isCollection() ? RowIndexForUriType.propertyComplexCollection : RowIndexForUriType.propertyComplex;
break;
default:
throw new UriValidationException("Unsupported action return type: " + rt.getType().getKind());
throw new UriValidationException("Unsupported action return type: " + rt.getType().getKind(),
UriValidationException.MessageKeys.UNSUPPORTED_ACTION_RETURN_TYPE, rt.getType().getKind().toString());
}
return idx;
@ -535,7 +548,8 @@ public class UriValidator {
idx = determineReturnType(functionReturnTypeKind, isCollection);
break;
default:
throw new UriValidationException("Illegal path part kind: " + secondLastPathSegment.getKind());
throw new UriValidationException("Illegal path part kind before $count: " + secondLastPathSegment.getKind(),
UriValidationException.MessageKeys.UNALLOWED_KIND_BEFORE_COUNT, secondLastPathSegment.toString());
}
return idx;
@ -548,7 +562,8 @@ public class UriValidator {
ColumnIndex col = colIndex(option.getKind());
if (!decisionMatrix[row.getIndex()][col.getIndex()]) {
throw new UriValidationException("System query option not allowed: " + option.getName());
throw new UriValidationException("System query option not allowed: " + option.getName(),
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED, option.getName());
}
}
@ -561,7 +576,8 @@ public class UriValidator {
ColumnIndex col = colIndex(option.getKind());
if (!decisionMatrixForHttpMethod[row.getIndex()][col.getIndex()]) {
throw new UriValidationException("System query option " + option.getName() + " not allowed for method "
+ httpMethod);
+ httpMethod, UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, option
.getName(), httpMethod.toString());
}
}
@ -590,7 +606,8 @@ public class UriValidator {
idx = RowIndexForHttpMethod.MERGE;
break;
default:
throw new UriValidationException("HTTP method not supported: " + httpMethod);
throw new UriValidationException("HTTP method not supported: " + httpMethod,
UriValidationException.MessageKeys.UNSUPPORTED_HTTP_METHOD, httpMethod.toString());
}
return idx;
@ -619,26 +636,39 @@ public class UriValidator {
for (UriParameter keyPredicate : keyPredicates) {
String name = keyPredicate.getName();
String alias = keyPredicate.getAlias();
String value = keyPredicate.getText();
if (alias != null) {
value = uriInfo.getValueForAlias(alias);
}
EdmKeyPropertyRef edmKey = edmKeys.get(name);
if (edmKey == null) {
throw new UriValidationException("Unknown key property: " + name);
throw new UriValidationException("Unknown key property: " + name,
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY, name);
}
EdmType edmType = edmKey.getProperty().getType();
EdmPrimitiveType edmPrimitiveType = (EdmPrimitiveType) edmType;
String edmLiteral = edmPrimitiveType.fromUriLiteral(value);
edmPrimitiveType.validate(edmLiteral, edmKey.getProperty().isNullable(), edmKey.getProperty()
.getMaxLength(), edmKey.getProperty().getPrecision(), edmKey.getProperty().getScale(), edmKey
.getProperty().isUnicode());
boolean isValid =
edmPrimitiveType.validate(edmLiteral, edmKey.getProperty().isNullable(), edmKey.getProperty()
.getMaxLength(), edmKey.getProperty().getPrecision(), edmKey.getProperty().getScale(), edmKey
.getProperty().isUnicode());
if (!isValid) {
// TODO: Check exception here
throw new UriValidationException("PrimitiveTypeException",
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY);
}
}
}
}
}
} catch (EdmPrimitiveTypeException e) {
throw new UriValidationException(e);
// TODO: Check exception here
throw new UriValidationException("PrimitiveTypeException", e,
UriValidationException.MessageKeys.INVALID_KEY_PROPERTY);
}
}
}

View File

@ -29,7 +29,9 @@ import java.util.Arrays;
import java.util.Locale;
import org.apache.commons.io.IOUtils;
import org.apache.olingo.commons.api.ODataException;
import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.edm.FullQualifiedName;
import org.apache.olingo.commons.api.edm.constants.ODataServiceVersion;
import org.apache.olingo.commons.api.format.ContentType;
import org.apache.olingo.commons.api.http.HttpContentType;
@ -40,11 +42,14 @@ import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.ODataApplicationException;
import org.apache.olingo.server.api.ODataRequest;
import org.apache.olingo.server.api.ODataResponse;
import org.apache.olingo.server.api.edm.provider.EdmProvider;
import org.apache.olingo.server.api.edm.provider.EntitySet;
import org.apache.olingo.server.api.processor.MetadataProcessor;
import org.apache.olingo.server.api.processor.ServiceDocumentProcessor;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Before;
import org.junit.Ignore;
import org.junit.Test;
public class ODataHandlerTest {
@ -219,6 +224,18 @@ public class ODataHandlerTest {
assertEquals(406, response.getStatusCode());
}
@Test
public void testUnregisteredProcessor() {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("ESAllPrim");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(501, response.getStatusCode());
}
@Test
public void testWithApplicationExceptionInProcessor() throws Exception {
ODataRequest request = new ODataRequest();
@ -227,13 +244,65 @@ public class ODataHandlerTest {
request.setRawODataPath("$metadata");
MetadataProcessor metadataProcessor = mock(MetadataProcessor.class);
doThrow(new ODataApplicationException("msg", 412, Locale.ENGLISH)).when(metadataProcessor).readMetadata(
doThrow(new ODataApplicationException("msg", 425, Locale.ENGLISH)).when(metadataProcessor).readMetadata(
any(ODataRequest.class), any(ODataResponse.class), any(UriInfo.class), any(ContentType.class));
handler.register(metadataProcessor);
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(412, response.getStatusCode());
assertEquals(425, response.getStatusCode());
}
//TODO: Use this test
@Ignore
@Test
public void testUriParserExceptionResultsInRightResponseNotFound() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("NotFound");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(404, response.getStatusCode());
}
//TODO: Use this test
@Ignore
@Test
public void testUriParserExceptionResultsInRightResponseBadRequest() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("ESAllPrim()");
ODataResponse response = handler.process(request);
assertNotNull(response);
assertEquals(404, response.getStatusCode());
}
@Test
public void testUriParserExceptionResultsInRightResponseEdmCause() throws Exception {
ODataRequest request = new ODataRequest();
request.setMethod(HttpMethod.GET);
request.setRawODataPath("EdmException");
OData odata = OData.newInstance();
Edm edm = odata.createEdm(new EdmProvider() {
public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String entitySetName)
throws ODataException {
throw new ODataException("msg");
}
});
ODataHandler localHandler = new ODataHandler(odata, edm);
ODataResponse response = localHandler.process(request);
assertNotNull(response);
assertEquals(500, response.getStatusCode());
// TODO: Check for message in case of EdmException
// System.out.println(IOUtils.toString(response.getContent()));
}
}

View File

@ -148,21 +148,21 @@ public class UriInfoImplTest {
QueryOptionImpl queryOption = new QueryOptionImpl();
queryOptions.add(expand);
queryOptions.add(filter);
queryOptions.add(format);
queryOptions.add(id);
queryOptions.add(inlinecount);
queryOptions.add(orderby);
queryOptions.add(search);
queryOptions.add(select);
queryOptions.add(skip);
queryOptions.add(skipToken);
queryOptions.add(top);
queryOptions.add(customOption0);
queryOptions.add(customOption1);
queryOptions.add(levels);// not stored
queryOptions.add(queryOption);// not stored
queryOptions.add(expand.setName(""));
queryOptions.add(filter.setName(""));
queryOptions.add(format.setName(""));
queryOptions.add(id.setName(""));
queryOptions.add(inlinecount.setName(""));
queryOptions.add(orderby.setName(""));
queryOptions.add(search.setName(""));
queryOptions.add(select.setName(""));
queryOptions.add(skip.setName(""));
queryOptions.add(skipToken.setName(""));
queryOptions.add(top.setName(""));
queryOptions.add(customOption0.setName(""));
queryOptions.add(customOption1.setName(""));
queryOptions.add(levels.setName(""));// not stored
queryOptions.add(queryOption.setName(""));// not stored
uriInfo.setQueryOptions(queryOptions);
assertEquals(expand, uriInfo.getExpandOption());

View File

@ -1067,21 +1067,18 @@ public class TestFullResourcePath {
.isKeyPredicate(2, "KeyAlias2", "'3'")
.isKeyPredicate(3, "KeyAlias3", "'4'");
testUri.run("ESCollAllPrim(null)")
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESCollAllPrim");
testUri.runEx("ESCollAllPrim(null)").isExValidation("");
}
@Test
public void runEsNameParaKeys() throws Exception {
testUri.run(encode("ESAllKey(PropertyString='O''Neil',PropertyBoolean=true,PropertyByte=255,"
+ "PropertySByte=-128,PropertyInt16=-32768,PropertyInt32=-2147483648,"
+ "PropertyInt64=-9223372036854775808,PropertyDecimal=0.1,PropertyDate=2013-09-25,"
+ "PropertyInt64=-9223372036854775808,PropertyDecimal=1,PropertyDate=2013-09-25,"
+ "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00,"
+ "PropertyDuration=duration'P10DT5H34M21.123456789012S',"
+ "PropertyDuration=duration'P50903316DT2H25M4S',"
+ "PropertyGuid=12345678-1234-1234-1234-123456789012,"
+ "PropertyTimeOfDay=12:34:55.123456789012)"))
+ "PropertyTimeOfDay=12:34:55)"))
.isKind(UriInfoKind.resource).goPath()
.first()
.isEntitySet("ESAllKey")
@ -1092,12 +1089,12 @@ public class TestFullResourcePath {
.isKeyPredicate(4, "PropertyInt16", "-32768")
.isKeyPredicate(5, "PropertyInt32", "-2147483648")
.isKeyPredicate(6, "PropertyInt64", "-9223372036854775808")
.isKeyPredicate(7, "PropertyDecimal", "0.1")
.isKeyPredicate(7, "PropertyDecimal", "1")
.isKeyPredicate(8, "PropertyDate", "2013-09-25")
.isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'")
.isKeyPredicate(10, "PropertyDuration", "duration'P50903316DT2H25M4S'")
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55");
}
@Test
@ -3321,7 +3318,7 @@ public class TestFullResourcePath {
.goPath()
.first()
.isFunction("UFCRTETTwoKeyNavParamCTTwoPrim")
.isParameterAlias(0, "ParameterCTTwoPrim", "ParamAlias");
.isParameterAlias(0, "ParameterCTTwoPrim", "@ParamAlias");
testFilter.runOnETTwoKeyNav("PropertyComp"
+ "/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam"
@ -3446,7 +3443,7 @@ public class TestFullResourcePath {
.root().left().goPath()
.first()
.isFunction("UFCRTETTwoKeyNavParam")
.isParameterAlias(0, "ParameterInt16", "Param1Alias")
.isParameterAlias(0, "ParameterInt16", "@Param1Alias")
.n()
.isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
@ -5091,7 +5088,8 @@ public class TestFullResourcePath {
public void testAlias() throws Exception {
testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath()
.isKeyPredicate(0, "PropertyInt16", "1")
.isKeyPredicateAlias(1, "PropertyString", "A")
.isKeyPredicateAlias(1, "PropertyString", "@A")
.isInAliasToValueMap("@A", "'2'")
.goUpUriValidator()
.isCustomParameter(0, "@A", "'2'");

View File

@ -47,14 +47,14 @@ public class TestUriParserImpl {
private final String PropertyDate = "PropertyDate=2013-09-25";
private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00";
private final String PropertyDecimal = "PropertyDecimal=12";
private final String PropertyDuration = "PropertyDuration=duration'P10DT5H34M21.123456789012S'";
private final String PropertyDuration = "PropertyDuration=duration'P50903316DT2H25M4S'";
private final String PropertyGuid = "PropertyGuid=12345678-1234-1234-1234-123456789012";
private final String PropertyInt16 = "PropertyInt16=1";
private final String PropertyInt32 = "PropertyInt32=12";
private final String PropertyInt64 = "PropertyInt64=64";
private final String PropertySByte = "PropertySByte=1";
private final String PropertyString = "PropertyString='ABC'";
private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55.123456789012";
private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55";
private final String allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte
+ "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate
@ -358,9 +358,9 @@ public class TestUriParserImpl {
.isKeyPredicate(7, "PropertyDecimal", "12")
.isKeyPredicate(8, "PropertyDate", "2013-09-25")
.isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
.isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'")
.isKeyPredicate(10, "PropertyDuration", "duration'P50903316DT2H25M4S'")
.isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
.isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55");
}
@Test

View File

@ -597,4 +597,10 @@ public class ResourceValidator implements TestValidator {
return this;
}
public ResourceValidator isInAliasToValueMap(String alias, String value) {
String valueForAlias = uriInfo.getValueForAlias(alias);
assertEquals(value, valueForAlias);
return this;
}
}

View File

@ -71,9 +71,12 @@ public class TestUriValidator implements TestValidator {
uriInfo = null;
try {
uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
new UriValidator().validate(uriInfo, HttpMethod.GET);
fail("Exception expected");
} catch (UriParserException e) {
exception = e;
} catch (UriValidationException e) {
exception = e;
}
return this;
@ -252,4 +255,9 @@ public class TestUriValidator implements TestValidator {
return this;
}
public TestUriValidator isExValidation(String string) {
assertEquals(UriValidationException.class, exception.getClass());
return this;
}
}

View File

@ -331,6 +331,12 @@ public class UriValidatorTest {
parseAndValidate(uri, HttpMethod.GET);
}
@Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongValueTypeForValidateMethod() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString='abc')";
parseAndValidate(uri, HttpMethod.GET);
}
@Test
public void checkValidSystemQueryOption() throws Exception {
String[] uris = constructUri(urisWithValidSystemQueryOptions);