[OLINGO-568] validation for system query option $search

Signed-off-by: Christian Amend <christian.amend@sap.com>
This commit is contained in:
Klaus Straubinger 2015-11-20 12:13:58 +01:00 committed by Christian Amend
parent 63db8b36c4
commit 16a856eaea
3 changed files with 143 additions and 197 deletions

View File

@ -52,6 +52,9 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<JsonNode> {
private static final String STRING_NAME = "String";
private static final String BOOLEAN_NAME = "Boolean";
private static final String NUMBER_NAME = "Number";
private static final String DATE_NAME = "Date";
private static final String TIME_NAME = "TimeOfDay";
private static final String DATETIMEOFFSET_NAME = "DateTimeOffset";
private static final String ENUM_NAME = "enum";
private static final String VALUES_NAME = "values";
private static final String NAME_NAME = "name";
@ -235,6 +238,8 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<JsonNode> {
case FRACTIONALSECONDS:
case TOTALOFFSETMINUTES:
case TOTALSECONDS:
case GEODISTANCE:
case GEOLENGTH:
return NUMBER_NAME;
case CONCAT:
@ -244,14 +249,18 @@ public class ExpressionJsonVisitor implements ExpressionVisitor<JsonNode> {
case TRIM:
return STRING_NAME;
case CAST:
case GEODISTANCE:
case GEOLENGTH:
case DATE:
return DATE_NAME;
case TIME:
return TIME_NAME;
case MAXDATETIME:
case MINDATETIME:
case DATE:
case TIME:
case NOW:
return DATETIMEOFFSET_NAME;
case CAST:
default:
return UNKNOWN_NAME;
}

View File

@ -60,17 +60,17 @@ public class UriValidator {
/* metadata 4 */ { false, true , false, false, false, false, false, false, false, false, false },
/* service 5 */ { false, true , false, false, false, false, false, false, false, false, false },
/* entitySet 6 */ { true , true , true , false, true , true , true , true , true , true , true },
/* entitySetCount 7 */ { true , false, false, false, false, false, true, false, false, false, false },
/* entitySetCount 7 */ { true , false, false, false, false, false, true , false, false, false, false },
/* entity 8 */ { false, true , true , false, false, false, false, true , false, false, false },
/* mediaStream 9 */ { false, false, false, false, false, false, false, false, false, false, false },
/* references 10 */ { true , true , false, true, true , true , true , false, true , true , true },
/* references 10 */ { true , true , false, true , true , true , true , false, true , true , true },
/* reference 11 */ { false, true , false, false, false, false, false, false, false, false, false },
/* propertyComplex 12 */ { false, true , true , false, false, false, false, true , false, false, false },
/* propertyComplexCollection 13 */ { true , true , true , false, true , true , false, true , true , true , true },
/* propertyComplexCollectionCount 14 */ { true , false, false, false, false, false, true, false, false, false, false },
/* propertyComplexCollectionCount 14 */ { true , false, false, false, false, false, false, false, false, false, false },
/* propertyPrimitive 15 */ { false, true , false, false, false, false, false, false, false, false, false },
/* propertyPrimitiveCollection 16 */ { true , true , false, false, true , true , false, false, true , true , true },
/* propertyPrimitiveCollectionCount 17 */ { true , false, false, false, false, false, true, false, false, false, false },
/* propertyPrimitiveCollectionCount 17 */ { true , false, false, false, false, false, false, false, false, false, false },
/* propertyPrimitiveValue 18 */ { false, true , false, false, false, false, false, false, false, false, false },
/* none 19 */ { false, true , false, false, false, false, false, false, false, false, false }
};

View File

@ -27,13 +27,11 @@ import org.apache.olingo.commons.api.edm.Edm;
import org.apache.olingo.commons.api.http.HttpMethod;
import org.apache.olingo.server.api.OData;
import org.apache.olingo.server.api.edmx.EdmxReference;
import org.apache.olingo.server.api.uri.UriInfo;
import org.apache.olingo.server.core.uri.parser.Parser;
import org.apache.olingo.server.core.uri.parser.UriParserException;
import org.apache.olingo.server.core.uri.parser.UriParserSemanticException;
import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
import org.apache.olingo.server.tecsvc.provider.ContainerProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.junit.Test;
@ -41,36 +39,41 @@ public class UriValidatorTest {
private static final String URI_ACTION_NO_RETURN = "AIRT";
private static final String URI_ACTION_PRIM = "AIRTString";
private static final String URI_ACTION_COOL_PRIM = "AIRTCollStringTwoParam";
private static final String URI_ACTION_COLL_PRIM = "AIRTCollStringTwoParam";
private static final String URI_ACTION_CT = "AIRTCTTwoPrimParam";
private static final String URI_ACTION_COLL_CT = "AIRTCollCTTwoPrimParam";
private static final String URI_ACTION_ENTITY = "AIRTESAllPrimParam";
private static final String URI_ACTION_ES = "AIRTCollESAllPrimParam";
// TODO: bound actions
@SuppressWarnings("unused")
private static final String URI_BOUND_ACTION_ENTITY_SET = "ESTwoKeyNav/Namespace1_Alias.BAESTwoKeyNavRTESTwoKeyNav";
@SuppressWarnings("unused")
private static final String URI_BOUND_ACTION_ENTITY = "ESAllPrim/Namespace1_Alias.BAESAllPrimRTETAllPrim";
private static final String URI_ALL = "$all";
private static final String URI_BATCH = "$batch";
private static final String URI_CROSSJOIN = "$crossjoin(ESAllPrim)";
private static final String URI_ENTITY_ID = "/$entity";
private static final String URI_ENTITY_ID = "$entity";
private static final String URI_METADATA = "$metadata";
private static final String URI_SERVICE = "";
private static final String URI_ENTITY_SET = "/ESAllPrim";
private static final String URI_ENTITY_SET_COUNT = "/ESAllPrim/$count";
private static final String URI_ENTITY = "/ESAllPrim(1)";
private static final String URI_MEDIA_STREAM = "/ESMedia(1)/$value";
private static final String URI_REFERENCES = "/ESAllPrim/$ref";
private static final String URI_REFERENCE = "/ESAllPrim(1)/$ref";
private static final String URI_PROPERTY_COMPLEX = "/ESCompComp(1)/PropertyComp";
private static final String URI_ENTITY_SET = "ESAllPrim";
private static final String URI_ENTITY_SET_COUNT = "ESAllPrim/$count";
private static final String URI_ENTITY = "ESAllPrim(1)";
private static final String URI_MEDIA_STREAM = "ESMedia(1)/$value";
private static final String URI_REFERENCES = "ESAllPrim/$ref";
private static final String URI_REFERENCE = "ESAllPrim(1)/$ref";
private static final String URI_PROPERTY_COMPLEX = "ESCompComp(1)/PropertyComp";
private static final String URI_PROPERTY_COMPLEX_COLLECTION =
"/ESCompCollComp(1)/PropertyComp/CollPropertyComp";
"ESCompCollComp(1)/PropertyComp/CollPropertyComp";
private static final String URI_PROPERTY_COMPLEX_COLLECTION_COUNT =
"/ESCompCollComp(1)/PropertyComp/CollPropertyComp/$count";
private static final String URI_PROPERTY_PRIMITIVE = "/ESAllPrim(1)/PropertyString";
private static final String URI_PROPERTY_PRIMITIVE_COLLECTION = "/ESCollAllPrim(1)/CollPropertyString";
"ESCompCollComp(1)/PropertyComp/CollPropertyComp/$count";
private static final String URI_PROPERTY_PRIMITIVE = "ESAllPrim(1)/PropertyString";
private static final String URI_PROPERTY_PRIMITIVE_COLLECTION = "ESCollAllPrim(1)/CollPropertyString";
private static final String URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT =
"/ESCollAllPrim(1)/CollPropertyString/$count";
private static final String URI_PROPERTY_PRIMITIVE_VALUE = "/ESAllPrim(1)/PropertyString/$value";
private static final String URI_SINGLETON = "/SI";
private static final String URI_NAV_ENTITY = "/ESKeyNav(1)/NavPropertyETKeyNavOne";
private static final String URI_NAV_ENTITY_SET = "/ESKeyNav(1)/NavPropertyETKeyNavMany";
"ESCollAllPrim(1)/CollPropertyString/$count";
private static final String URI_PROPERTY_PRIMITIVE_VALUE = "ESAllPrim(1)/PropertyString/$value";
private static final String URI_SINGLETON = "SI";
private static final String URI_NAV_ENTITY = "ESKeyNav(1)/NavPropertyETKeyNavOne";
private static final String URI_NAV_ENTITY_SET = "ESKeyNav(1)/NavPropertyETKeyNavMany";
private static final String URI_FI_ENTITY_SET = "FICRTCollESMedia()";
private static final String URI_FI_ENTITY = "FICRTETTwoKeyNavParam(ParameterInt16=1)";
private static final String URI_FI_ENTITY_SET_KEY = "FICRTCollESMedia()(3)";
@ -81,7 +84,7 @@ public class UriValidatorTest {
private static final String QO_ID = "$id=Products(0)";
private static final String QO_COUNT = "$count=true";
private static final String QO_ORDERBY = "$orderby=true";
// private static final String QO_SEARCH = "$search='bla'";
private static final String QO_SEARCH = "$search=bla";
private static final String QO_SELECT = "$select=*";
private static final String QO_SKIP = "$skip=3";
private static final String QO_SKIPTOKEN = "$skiptoken=123";
@ -89,12 +92,12 @@ public class UriValidatorTest {
private final String[][] urisWithValidSystemQueryOptions = {
{ URI_ALL, QO_FILTER }, { URI_ALL, QO_FORMAT }, { URI_ALL, QO_EXPAND }, { URI_ALL, QO_COUNT },
{ URI_ALL, QO_ORDERBY }, /* { URI_ALL, QO_SEARCH }, */{ URI_ALL, QO_SELECT }, { URI_ALL, QO_SKIP },
{ URI_ALL, QO_ORDERBY }, { URI_ALL, QO_SEARCH }, { URI_ALL, QO_SELECT }, { URI_ALL, QO_SKIP },
{ URI_ALL, QO_SKIPTOKEN }, { URI_ALL, QO_TOP },
{ URI_CROSSJOIN, QO_FILTER }, { URI_CROSSJOIN, QO_FORMAT },
{ URI_CROSSJOIN, QO_EXPAND }, { URI_CROSSJOIN, QO_COUNT }, { URI_CROSSJOIN, QO_ORDERBY },
/* { URI_CROSSJOIN, QO_SEARCH }, */{ URI_CROSSJOIN, QO_SELECT }, { URI_CROSSJOIN, QO_SKIP },
{ URI_CROSSJOIN, QO_SEARCH }, { URI_CROSSJOIN, QO_SELECT }, { URI_CROSSJOIN, QO_SKIP },
{ URI_CROSSJOIN, QO_SKIPTOKEN }, { URI_CROSSJOIN, QO_TOP },
{ URI_ENTITY_ID, QO_ID, QO_FORMAT }, { URI_ENTITY_ID, QO_ID }, { URI_ENTITY_ID, QO_ID, QO_EXPAND },
@ -105,16 +108,16 @@ public class UriValidatorTest {
{ URI_SERVICE, QO_FORMAT },
{ URI_ENTITY_SET, QO_FILTER }, { URI_ENTITY_SET, QO_FORMAT }, { URI_ENTITY_SET, QO_EXPAND },
{ URI_ENTITY_SET, QO_COUNT }, { URI_ENTITY_SET, QO_ORDERBY }, /* { URI_ENTITY_SET, QO_SEARCH }, */
{ URI_ENTITY_SET, QO_COUNT }, { URI_ENTITY_SET, QO_ORDERBY }, { URI_ENTITY_SET, QO_SEARCH },
{ URI_ENTITY_SET, QO_SELECT }, { URI_ENTITY_SET, QO_SKIP }, { URI_ENTITY_SET, QO_SKIPTOKEN },
{ URI_ENTITY_SET, QO_TOP },
{ URI_ENTITY_SET_COUNT, QO_FILTER }, /* { URI_ENTITY_SET_COUNT, QO_SEARCH }, */
{ URI_ENTITY_SET_COUNT, QO_FILTER }, { URI_ENTITY_SET_COUNT, QO_SEARCH },
{ URI_ENTITY, QO_FORMAT }, { URI_ENTITY, QO_EXPAND }, { URI_ENTITY, QO_SELECT },
{ URI_REFERENCES, QO_FILTER }, { URI_REFERENCES, QO_FORMAT }, { URI_REFERENCES, QO_ORDERBY },
/* { URI_REFERENCES, QO_SEARCH }, */{ URI_REFERENCES, QO_SKIP }, { URI_REFERENCES, QO_SKIPTOKEN },
{ URI_REFERENCES, QO_SEARCH }, { URI_REFERENCES, QO_SKIP }, { URI_REFERENCES, QO_SKIPTOKEN },
{ URI_REFERENCES, QO_TOP }, { URI_REFERENCES, QO_ID }, { URI_REFERENCES, QO_COUNT },
{ URI_REFERENCE, QO_FORMAT },
@ -127,7 +130,7 @@ public class UriValidatorTest {
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIP }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIPTOKEN },
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_TOP },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER }, /* { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, */
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER },
{ URI_PROPERTY_PRIMITIVE, QO_FORMAT },
@ -137,7 +140,6 @@ public class UriValidatorTest {
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_TOP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_FILTER },
/* { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SEARCH }, */
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_FORMAT },
@ -147,11 +149,11 @@ public class UriValidatorTest {
{ URI_NAV_ENTITY_SET, QO_FILTER }, { URI_NAV_ENTITY_SET, QO_FORMAT }, { URI_NAV_ENTITY_SET, QO_EXPAND },
{ URI_NAV_ENTITY_SET, QO_COUNT }, { URI_NAV_ENTITY_SET, QO_ORDERBY },
/* { URI_NAV_ENTITY_SET, QO_SEARCH }, */{ URI_NAV_ENTITY_SET, QO_SELECT }, { URI_NAV_ENTITY_SET, QO_SKIP },
{ URI_NAV_ENTITY_SET, QO_SEARCH }, { URI_NAV_ENTITY_SET, QO_SELECT }, { URI_NAV_ENTITY_SET, QO_SKIP },
{ URI_NAV_ENTITY_SET, QO_SKIPTOKEN }, { URI_NAV_ENTITY_SET, QO_TOP },
{ URI_FI_ENTITY_SET, QO_FILTER }, { URI_FI_ENTITY_SET, QO_FORMAT }, { URI_FI_ENTITY_SET, QO_EXPAND },
{ URI_FI_ENTITY_SET, QO_COUNT }, { URI_FI_ENTITY_SET, QO_ORDERBY }, /* { URI_FI_ENTITY_SET, QO_SEARCH }, */
{ URI_FI_ENTITY_SET, QO_COUNT }, { URI_FI_ENTITY_SET, QO_ORDERBY }, { URI_FI_ENTITY_SET, QO_SEARCH },
{ URI_FI_ENTITY_SET, QO_SELECT }, { URI_FI_ENTITY_SET, QO_SKIP }, { URI_FI_ENTITY_SET, QO_SKIPTOKEN },
{ URI_FI_ENTITY_SET, QO_TOP },
@ -161,36 +163,29 @@ public class UriValidatorTest {
{ "FINRTInt16()", QO_FORMAT },
{ "FICRTCollString()", QO_FORMAT },
{ "FICRTCTTwoPrim()", QO_FORMAT },
{ "FICRTCollCTTwoPrim()", QO_FORMAT },
{ "ESTwoKeyNav/olingo.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" },
{ "ESAllPrim/olingo.odata.test1.BAESAllPrimRTETAllPrim" },
{ ContainerProvider.AIRT_COLL_STRING_TWO_PARAM },
{ ContainerProvider.AIRTET_TWO_KEY_TWO_PRIM_PARAM },
{ ContainerProvider.AIRT_STRING }
{ "FICRTCollCTTwoPrim()", QO_FORMAT }
};
private final String[][] urisWithNonValidSystemQueryOptions = {
{ URI_ALL, QO_ID },
{ URI_BATCH, QO_FILTER }, { URI_BATCH, QO_FORMAT }, { URI_BATCH, QO_ID }, { URI_BATCH, QO_EXPAND },
{ URI_BATCH, QO_COUNT }, { URI_BATCH, QO_ORDERBY }, /* { URI_BATCH, QO_SEARCH }, */{ URI_BATCH, QO_SELECT },
{ URI_BATCH, QO_COUNT }, { URI_BATCH, QO_ORDERBY }, { URI_BATCH, QO_SEARCH }, { URI_BATCH, QO_SELECT },
{ URI_BATCH, QO_SKIP }, { URI_BATCH, QO_SKIPTOKEN }, { URI_BATCH, QO_TOP },
{ URI_CROSSJOIN, QO_ID },
{ URI_ENTITY_ID, QO_ID, QO_FILTER },
{ URI_ENTITY_ID, QO_ID, QO_COUNT }, { URI_ENTITY_ID, QO_ORDERBY }, /* { URI_ENTITY_ID, QO_SEARCH }, */
{ URI_ENTITY_ID, QO_ID, QO_COUNT }, { URI_ENTITY_ID, QO_ORDERBY }, { URI_ENTITY_ID, QO_SEARCH },
{ URI_ENTITY_ID, QO_ID, QO_SKIP }, { URI_ENTITY_ID, QO_ID, QO_SKIPTOKEN }, { URI_ENTITY_ID, QO_ID, QO_TOP },
{ URI_METADATA, QO_FILTER }, { URI_METADATA, QO_ID }, { URI_METADATA, QO_EXPAND },
{ URI_METADATA, QO_COUNT }, { URI_METADATA, QO_ORDERBY }, /* { URI_METADATA, QO_SEARCH }, */
{ URI_METADATA, QO_COUNT }, { URI_METADATA, QO_ORDERBY }, { URI_METADATA, QO_SEARCH },
{ URI_METADATA, QO_SELECT }, { URI_METADATA, QO_SKIP }, { URI_METADATA, QO_SKIPTOKEN },
{ URI_METADATA, QO_TOP },
{ URI_SERVICE, QO_FILTER }, { URI_SERVICE, QO_ID }, { URI_SERVICE, QO_EXPAND }, { URI_SERVICE, QO_COUNT },
{ URI_SERVICE, QO_ORDERBY }, /* { URI_SERVICE, QO_SEARCH }, */{ URI_SERVICE, QO_SELECT },
{ URI_SERVICE, QO_ORDERBY }, { URI_SERVICE, QO_SEARCH }, { URI_SERVICE, QO_SELECT },
{ URI_SERVICE, QO_SKIP }, { URI_SERVICE, QO_SKIPTOKEN }, { URI_SERVICE, QO_TOP },
{ URI_ENTITY_SET, QO_ID },
@ -201,63 +196,62 @@ public class UriValidatorTest {
{ URI_ENTITY_SET_COUNT, QO_SELECT }, { URI_ENTITY_SET_COUNT, QO_SKIP }, { URI_ENTITY_SET_COUNT, QO_SKIPTOKEN },
{ URI_ENTITY_SET_COUNT, QO_TOP },
{ URI_ENTITY, QO_FILTER }, { URI_ENTITY, QO_ID }, { URI_ENTITY, QO_COUNT }, /* { URI_ENTITY, QO_ORDERBY }, */
/* { URI_ENTITY, QO_SEARCH }, */{ URI_ENTITY, QO_SKIP }, { URI_ENTITY, QO_SKIPTOKEN }, { URI_ENTITY, QO_TOP },
{ URI_ENTITY, QO_FILTER }, { URI_ENTITY, QO_ID }, { URI_ENTITY, QO_COUNT }, { URI_ENTITY, QO_ORDERBY },
{ URI_ENTITY, QO_SEARCH }, { URI_ENTITY, QO_SKIP }, { URI_ENTITY, QO_SKIPTOKEN }, { URI_ENTITY, QO_TOP },
{ URI_MEDIA_STREAM, QO_FILTER }, { URI_MEDIA_STREAM, QO_FORMAT }, { URI_MEDIA_STREAM, QO_ID },
{ URI_MEDIA_STREAM, QO_EXPAND }, { URI_MEDIA_STREAM, QO_COUNT }, { URI_MEDIA_STREAM, QO_ORDERBY },
/* { URI_MEDIA_STREAM, QO_SEARCH }, */{ URI_MEDIA_STREAM, QO_SELECT }, { URI_MEDIA_STREAM, QO_SKIP },
{ URI_MEDIA_STREAM, QO_SEARCH }, { URI_MEDIA_STREAM, QO_SELECT }, { URI_MEDIA_STREAM, QO_SKIP },
{ URI_MEDIA_STREAM, QO_SKIPTOKEN }, { URI_MEDIA_STREAM, QO_TOP },
{ URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_SELECT },
{ URI_REFERENCE, QO_FILTER }, { URI_REFERENCE, QO_ID }, { URI_REFERENCE, QO_EXPAND },
{ URI_REFERENCE, QO_COUNT }, { URI_REFERENCE, QO_ORDERBY }, /* { URI_REFERENCE, QO_SEARCH }, */
{ URI_REFERENCE, QO_COUNT }, { URI_REFERENCE, QO_ORDERBY }, { URI_REFERENCE, QO_SEARCH },
{ URI_REFERENCE, QO_SELECT }, { URI_REFERENCE, QO_SKIP }, { URI_REFERENCE, QO_SKIPTOKEN },
{ URI_REFERENCE, QO_TOP },
{ URI_PROPERTY_COMPLEX, QO_FILTER }, { URI_PROPERTY_COMPLEX, QO_ID }, { URI_PROPERTY_COMPLEX, QO_COUNT },
{ URI_PROPERTY_COMPLEX, QO_ORDERBY }, /* { URI_PROPERTY_COMPLEX, QO_SEARCH }, */
{ URI_PROPERTY_COMPLEX, QO_ORDERBY }, { URI_PROPERTY_COMPLEX, QO_SEARCH },
{ URI_PROPERTY_COMPLEX, QO_SKIP }, { URI_PROPERTY_COMPLEX, QO_SKIPTOKEN }, { URI_PROPERTY_COMPLEX, QO_TOP },
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_ID },
/* { URI_PROPERTY_COMPLEX_COLLECTION, QO_SEARCH }, */
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_ID }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_SEARCH },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FORMAT },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_ID }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_EXPAND },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_COUNT }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_ORDERBY },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SELECT },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SELECT },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SKIP }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SKIPTOKEN },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_TOP },
{ URI_PROPERTY_PRIMITIVE, QO_FILTER }, { URI_PROPERTY_PRIMITIVE, QO_ID }, { URI_PROPERTY_PRIMITIVE, QO_EXPAND },
{ URI_PROPERTY_PRIMITIVE, QO_COUNT }, { URI_PROPERTY_PRIMITIVE, QO_ORDERBY },
/* { URI_PROPERTY_PRIMITIVE, QO_SEARCH }, */{ URI_PROPERTY_PRIMITIVE, QO_SELECT },
{ URI_PROPERTY_PRIMITIVE, QO_SEARCH }, { URI_PROPERTY_PRIMITIVE, QO_SELECT },
{ URI_PROPERTY_PRIMITIVE, QO_SKIP }, { URI_PROPERTY_PRIMITIVE, QO_SKIPTOKEN },
{ URI_PROPERTY_PRIMITIVE, QO_TOP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ID }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_EXPAND },
/* { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SEARCH }, */{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SELECT },
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SEARCH }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SELECT },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_FORMAT },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_ID }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_EXPAND },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_COUNT },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_ORDERBY },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_ORDERBY }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SEARCH },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIPTOKEN }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_TOP },
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_FILTER }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_ID },
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_EXPAND }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_COUNT },
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_ORDERBY },/* { URI_PROPERTY_PRIMITIVE_VALUE, QO_SEARCH }, */
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_ORDERBY }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_SEARCH },
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_SKIP },
{ URI_PROPERTY_PRIMITIVE_VALUE, QO_SKIPTOKEN }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_TOP },
{ URI_SINGLETON, QO_FILTER }, { URI_SINGLETON, QO_ID }, { URI_SINGLETON, QO_COUNT },
{ URI_SINGLETON, QO_ORDERBY }, /* { URI_SINGLETON, QO_SEARCH }, */{ URI_SINGLETON, QO_SKIP },
{ URI_SINGLETON, QO_ORDERBY }, { URI_SINGLETON, QO_SEARCH }, { URI_SINGLETON, QO_SKIP },
{ URI_SINGLETON, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP },
{ URI_NAV_ENTITY, QO_FILTER }, { URI_NAV_ENTITY, QO_ID }, { URI_NAV_ENTITY, QO_COUNT },
{ URI_NAV_ENTITY, QO_ORDERBY }, /* { URI_NAV_ENTITY, QO_SEARCH }, */{ URI_NAV_ENTITY, QO_SKIP },
{ URI_NAV_ENTITY, QO_ORDERBY }, { URI_NAV_ENTITY, QO_SEARCH }, { URI_NAV_ENTITY, QO_SKIP },
{ URI_NAV_ENTITY, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP },
{ URI_NAV_ENTITY_SET, QO_ID },
@ -265,10 +259,10 @@ public class UriValidatorTest {
{ URI_FI_ENTITY_SET, QO_ID },
{ URI_FI_ENTITY, QO_FILTER }, { URI_FI_ENTITY, QO_ID }, { URI_FI_ENTITY, QO_COUNT },
{ URI_FI_ENTITY, QO_ORDERBY }, /* { URI_FI_ENTITY, QO_SEARCH }, */{ URI_FI_ENTITY, QO_SKIP },
{ URI_FI_ENTITY, QO_ORDERBY }, { URI_FI_ENTITY, QO_SEARCH }, { URI_FI_ENTITY, QO_SKIP },
{ URI_FI_ENTITY, QO_SKIPTOKEN }, { URI_FI_ENTITY, QO_TOP },
{ URI_FI_ENTITY_SET_KEY, QO_FILTER }, { URI_FI_ENTITY_SET_KEY, QO_ID }, { URI_FI_ENTITY_SET_KEY, QO_COUNT },
{ URI_FI_ENTITY_SET_KEY, QO_ORDERBY }, /* { URI_FI_ENTITY_SET_KEY, QO_SEARCH }, */
{ URI_FI_ENTITY_SET_KEY, QO_ORDERBY }, { URI_FI_ENTITY_SET_KEY, QO_SEARCH },
{ URI_FI_ENTITY_SET_KEY, QO_SKIP }, { URI_FI_ENTITY_SET_KEY, QO_SKIPTOKEN }, { URI_FI_ENTITY_SET_KEY, QO_TOP }
};
@ -278,10 +272,10 @@ public class UriValidatorTest {
// PrimReturnType
{ URI_ACTION_PRIM, QO_FORMAT },
// PrimCollectionReturnType
{ URI_ACTION_COOL_PRIM, QO_FILTER }, { URI_ACTION_COOL_PRIM, QO_FORMAT },
{ URI_ACTION_COOL_PRIM, QO_COUNT }, { URI_ACTION_COOL_PRIM, QO_ORDERBY },
{ URI_ACTION_COOL_PRIM, QO_SKIP }, { URI_ACTION_COOL_PRIM, QO_SKIPTOKEN },
{ URI_ACTION_COOL_PRIM, QO_TOP },
{ URI_ACTION_COLL_PRIM, QO_FILTER }, { URI_ACTION_COLL_PRIM, QO_FORMAT },
{ URI_ACTION_COLL_PRIM, QO_COUNT }, { URI_ACTION_COLL_PRIM, QO_ORDERBY },
{ URI_ACTION_COLL_PRIM, QO_SKIP }, { URI_ACTION_COLL_PRIM, QO_SKIPTOKEN },
{ URI_ACTION_COLL_PRIM, QO_TOP },
// ComplexReturnType
{ URI_ACTION_CT, QO_FORMAT }, { URI_ACTION_CT, QO_SELECT }, { URI_ACTION_CT, QO_EXPAND },
// ComplexCollectionReturnType
@ -293,169 +287,93 @@ public class UriValidatorTest {
// EntityReturnType
{ URI_ACTION_ENTITY, QO_FORMAT }, { URI_ACTION_ENTITY, QO_EXPAND }, { URI_ACTION_ENTITY, QO_SELECT },
// EntityCollectionReturnType
{ URI_ACTION_ES, QO_FORMAT }, { URI_ACTION_ES, QO_FILTER }, { URI_ENTITY_SET, URI_ACTION_ES },
{ URI_ACTION_ES, QO_COUNT }, { URI_ACTION_ES, QO_ORDERBY }, /* { URI_ACTION_ES, QO_SEARCH }, */
{ URI_ACTION_ES, QO_FORMAT }, { URI_ACTION_ES, QO_FILTER },
{ URI_ACTION_ES, QO_COUNT }, { URI_ACTION_ES, QO_ORDERBY }, { URI_ACTION_ES, QO_SEARCH },
{ URI_ACTION_ES, QO_SELECT }, { URI_ACTION_ES, QO_SKIP }, { URI_ACTION_ES, QO_SKIPTOKEN },
{ URI_ACTION_ES, QO_TOP },
{ URI_ACTION_ES, QO_TOP }
};
private final String[][] actionsWithNotValidSystemQueryOptions = {
// NoReturnType
{ URI_ACTION_NO_RETURN, QO_FILTER }, { URI_ACTION_NO_RETURN, QO_ID },
{ URI_ACTION_NO_RETURN, QO_EXPAND }, { URI_ACTION_NO_RETURN, QO_COUNT },
{ URI_ACTION_NO_RETURN, QO_ORDERBY },/* { URI_ACTION_NO_RETURN, QO_SEARCH }, */
{ URI_ACTION_NO_RETURN, QO_ORDERBY }, { URI_ACTION_NO_RETURN, QO_SEARCH },
{ URI_ACTION_NO_RETURN, QO_SELECT }, { URI_ACTION_NO_RETURN, QO_SKIP },
{ URI_ACTION_NO_RETURN, QO_SKIPTOKEN }, { URI_ACTION_NO_RETURN, QO_TOP },
// PrimReturnType
{ URI_ACTION_PRIM, QO_FILTER }, { URI_ACTION_PRIM, QO_ID },
{ URI_ACTION_PRIM, QO_EXPAND }, { URI_ACTION_PRIM, QO_COUNT },
{ URI_ACTION_PRIM, QO_ORDERBY },/* { URI_ACTION_PRIM, QO_SEARCH }, */
{ URI_ACTION_PRIM, QO_ORDERBY }, { URI_ACTION_PRIM, QO_SEARCH },
{ URI_ACTION_PRIM, QO_SELECT }, { URI_ACTION_PRIM, QO_SKIP },
{ URI_ACTION_PRIM, QO_SKIPTOKEN }, { URI_ACTION_PRIM, QO_TOP },
// PrimCollectionReturnType
{ URI_ACTION_COOL_PRIM, QO_ID }, { URI_ACTION_COOL_PRIM, QO_EXPAND },
/* { URI_ACTION_COOL_PRIM, QO_SEARCH }, */{ URI_ACTION_COOL_PRIM, QO_SELECT },
{ URI_ACTION_COLL_PRIM, QO_ID }, { URI_ACTION_COLL_PRIM, QO_EXPAND },
{ URI_ACTION_COLL_PRIM, QO_SEARCH }, { URI_ACTION_COLL_PRIM, QO_SELECT },
// ComplexReturnType
{ URI_ACTION_CT, QO_FILTER }, { URI_ACTION_CT, QO_ID }, { URI_ACTION_CT, QO_COUNT },
{ URI_ACTION_CT, QO_ORDERBY }, /* { URI_ACTION_CT, QO_SEARCH }, */
{ URI_ACTION_CT, QO_ORDERBY }, { URI_ACTION_CT, QO_SEARCH },
{ URI_ACTION_CT, QO_SKIP }, { URI_ACTION_CT, QO_SKIPTOKEN }, { URI_ACTION_CT, QO_TOP },
// ComplexCollectionReturnType
{ URI_ACTION_COLL_CT, QO_ID },
/* { URI_ACTION_COLL_CT, QO_SEARCH }, */
{ URI_ACTION_COLL_CT, QO_ID }, { URI_ACTION_COLL_CT, QO_SEARCH },
// EntityReturnType
{ URI_ACTION_ENTITY, QO_FILTER }, { URI_ACTION_ENTITY, QO_ID }, { URI_ACTION_ENTITY, QO_COUNT },
/* { URI_ACTION_ENTITY, QO_ORDERBY }, *//* { URI_ACTION_ENTITY, QO_SEARCH }, */
{ URI_ACTION_ENTITY, QO_ORDERBY }, { URI_ACTION_ENTITY, QO_SEARCH },
{ URI_ACTION_ENTITY, QO_SKIP }, { URI_ACTION_ENTITY, QO_SKIPTOKEN }, { URI_ACTION_ENTITY, QO_TOP },
// EntityCollectionReturnType
{ URI_ACTION_ES, QO_ID },
{ URI_ACTION_ES, QO_ID }
};
private static final Edm edm = OData.newInstance().createServiceMetadata(
new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm();
@Test
public void validatePostOnActionSystemQueryOptions() throws Exception {
for (final String[] uriArray : actionWithValidSystemQueryOptions) {
final String[] uri = constructUri(uriArray);
try {
new UriValidator().validate(
new Parser().parseUri(uri[0], uri[1], null, edm),
HttpMethod.GET);
} catch (final UriParserException e) {
fail("Failed for uri: " + uri[0] + '?' + uri[1]);
} catch (final UriValidationException e) {
fail("Failed for uri: " + uri[0] + '?' + uri[1]);
}
}
}
@Test
public void checkPostOnActionSystemQueryOptionsNotValid() throws Exception {
for (final String[] uriArray : actionsWithNotValidSystemQueryOptions) {
final String[] uri = constructUri(uriArray);
validateWrong(uri[0], uri[1], HttpMethod.POST,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED);
}
}
@Test
public void serviceDocumentMustNotFailForHttpPostPutPatchDelete() throws Exception {
// We must not fail with a nullpointer here as the HTTP method to resource validation happens in the dispatcher
final UriInfo uri = new Parser().parseUri(URI_SERVICE, null, null, edm);
final UriValidator validator = new UriValidator();
validator.validate(uri, HttpMethod.GET);
validator.validate(uri, HttpMethod.POST);
validator.validate(uri, HttpMethod.PUT);
validator.validate(uri, HttpMethod.DELETE);
validator.validate(uri, HttpMethod.PATCH);
validate(URI_SERVICE, null, HttpMethod.GET);
validate(URI_SERVICE, null, HttpMethod.POST);
validate(URI_SERVICE, null, HttpMethod.PUT);
validate(URI_SERVICE, null, HttpMethod.DELETE);
validate(URI_SERVICE, null, HttpMethod.PATCH);
}
@Test
public void validateForHttpMethods() throws Exception {
final UriInfo uri = new Parser().parseUri(URI_ENTITY, null, null, edm);
final UriValidator validator = new UriValidator();
validator.validate(uri, HttpMethod.GET);
validator.validate(uri, HttpMethod.POST);
validator.validate(uri, HttpMethod.PUT);
validator.validate(uri, HttpMethod.DELETE);
validator.validate(uri, HttpMethod.PATCH);
validate(URI_ENTITY, null, HttpMethod.GET);
validate(URI_ENTITY, null, HttpMethod.POST);
validate(URI_ENTITY, null, HttpMethod.PUT);
validate(URI_ENTITY, null, HttpMethod.DELETE);
validate(URI_ENTITY, null, HttpMethod.PATCH);
}
@Test
public void systemQueryOptionsNotAllowedForHttpPostPutPatchDelete() throws Exception {
String[] queryOptions =
{ QO_FILTER, QO_FORMAT, QO_EXPAND, QO_COUNT, QO_ORDERBY, QO_SELECT, QO_SKIP, QO_TOP, QO_SKIPTOKEN };
final UriValidator validator = new UriValidator();
final String[] queryOptions =
{ QO_FILTER, QO_FORMAT, QO_EXPAND, QO_COUNT, QO_ORDERBY, QO_SEARCH, QO_SELECT, QO_SKIP, QO_TOP, QO_SKIPTOKEN };
for (int i = 0; i < queryOptions.length; i++) {
final UriInfo uri = new Parser().parseUri(URI_ENTITY, queryOptions[i], null, edm);
try {
validator.validate(uri, HttpMethod.POST);
fail("UriValidation exception expected for method POST and system query option: " + queryOptions[i]);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
try {
validator.validate(uri, HttpMethod.PUT);
fail("UriValidation exception expected for method PUT and system query option: " + queryOptions[i]);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
try {
validator.validate(uri, HttpMethod.PATCH);
fail("UriValidation exception expected for method PATCH and system query option: " + queryOptions[i]);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
try {
validator.validate(uri, HttpMethod.DELETE);
fail("UriValidation exception expected for method DELETE and system query option: " + queryOptions[i]);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
validateWrong(URI_ENTITY, queryOptions[i], HttpMethod.POST,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_ENTITY, queryOptions[i], HttpMethod.PUT,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_ENTITY, queryOptions[i], HttpMethod.PATCH,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_ENTITY, queryOptions[i], HttpMethod.DELETE,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
}
}
@Test
public void systemQueryOptionIDAllowedForDELETEReferencesOnly() throws Exception {
final UriValidator validator = new UriValidator();
final UriInfo uri = new Parser().parseUri(URI_REFERENCES, QO_ID, null, edm);
validator.validate(uri, HttpMethod.DELETE);
try {
validator.validate(uri, HttpMethod.POST);
fail("UriValidation exception expected for method POST and system query option: " + QO_ID);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
try {
validator.validate(uri, HttpMethod.PUT);
fail("UriValidation exception expected for method PUT and system query option: " + QO_ID);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
try {
validator.validate(uri, HttpMethod.PATCH);
fail("UriValidation exception expected for method PATCH and system query option: " + QO_ID);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
validate(URI_REFERENCES, QO_ID, HttpMethod.DELETE);
final UriInfo newUri = new Parser().parseUri(URI_ENTITY, QO_ID, null, edm);
try {
validator.validate(newUri, HttpMethod.DELETE);
fail("UriValidation exception expected for method DELETE and system query option: " + QO_ID);
} catch (UriValidationException e) {
assertEquals(UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD, e
.getMessageKey());
}
validateWrong(URI_REFERENCES, QO_ID, HttpMethod.POST,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_REFERENCES, QO_ID, HttpMethod.PUT,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_REFERENCES, QO_ID, HttpMethod.PATCH,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
validateWrong(URI_ENTITY, QO_ID, HttpMethod.DELETE,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED_FOR_HTTP_METHOD);
}
@Test
@ -525,15 +443,7 @@ public class UriValidatorTest {
public void checkValidSystemQueryOption() throws Exception {
for (final String[] uriArray : urisWithValidSystemQueryOptions) {
final String[] uri = constructUri(uriArray);
try {
new UriValidator().validate(
new Parser().parseUri(uri[0], uri[1], null, edm),
HttpMethod.GET);
} catch (final UriParserException e) {
fail("Failed for uri: " + uri[0] + '?' + uri[1]);
} catch (final UriValidationException e) {
fail("Failed for uri: " + uri[0] + '?' + uri[1]);
}
validate(uri[0], uri[1], HttpMethod.GET);
}
}
@ -546,6 +456,23 @@ public class UriValidatorTest {
}
}
@Test
public void validatePostOnActionSystemQueryOptions() throws Exception {
for (final String[] uriArray : actionWithValidSystemQueryOptions) {
final String[] uri = constructUri(uriArray);
validate(uri[0], uri[1], HttpMethod.POST);
}
}
@Test
public void checkPostOnActionSystemQueryOptionsNotValid() throws Exception {
for (final String[] uriArray : actionsWithNotValidSystemQueryOptions) {
final String[] uri = constructUri(uriArray);
validateWrong(uri[0], uri[1], HttpMethod.POST,
UriValidationException.MessageKeys.SYSTEM_QUERY_OPTION_NOT_ALLOWED);
}
}
@Test
public void propertyOperations() throws Exception {
validateWrong(URI_PROPERTY_PRIMITIVE_COLLECTION, null, HttpMethod.PATCH,
@ -570,6 +497,16 @@ public class UriValidatorTest {
return new String[] { path, query };
}
private void validate(final String path, final String query, final HttpMethod method) {
try {
new UriValidator().validate(new Parser().parseUri(path, query, null, edm), method);
} catch (final UriParserException e) {
fail("Failed for uri: " + path + '?' + query);
} catch (final UriValidationException e) {
fail("Failed for uri: " + path + '?' + query);
}
}
private void validateWrong(final String path, final String query, final HttpMethod method,
final UriValidationException.MessageKeys expectedMessageKey) {
try {