[OLINGO-206] JUnit

This commit is contained in:
Stephan Klevenz 2014-04-29 17:38:10 +02:00
parent 73858b9b3d
commit 7dfb6761bd
1 changed files with 51 additions and 35 deletions

View File

@ -66,7 +66,7 @@ public class UriValidatorTest {
private static final String QO_EXPAND = "$expand=*";
private static final String QO_ID = "$id=Products(0)";
private static final String QO_COUNT = "$count";
// private static final String QO_ORDERBY = "$orderby=true";
private static final String QO_ORDERBY = "$orderby=true";
// private static final String QO_SEARCH = "$search='bla'";
private static final String QO_SELECT = "$select=*";
private static final String QO_SKIP = "$skip=3";
@ -76,11 +76,11 @@ public class UriValidatorTest {
private 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_LEVELS },
{ URI_CROSSJOIN, QO_FILTER, }, { URI_CROSSJOIN, QO_FORMAT },
{ URI_CROSSJOIN, QO_EXPAND }, { URI_CROSSJOIN, QO_COUNT }, /* { URI_CROSSJOIN, QO_ORDERBY }, */
{ 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_SKIPTOKEN }, { URI_CROSSJOIN, QO_LEVELS }, { URI_CROSSJOIN, QO_TOP },
@ -92,7 +92,7 @@ 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_LEVELS },
{ URI_ENTITY_SET, QO_TOP },
@ -103,7 +103,7 @@ public class UriValidatorTest {
{ URI_MEDIA_STREAM, QO_FORMAT },
{ URI_REFERENCES, QO_FILTER }, { URI_REFERENCES, QO_FORMAT }, /* { URI_REFERENCES, QO_ORDERBY }, */
{ 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_TOP },
@ -116,13 +116,14 @@ public class UriValidatorTest {
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_EXPAND }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_COUNT },
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIP }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIPTOKEN },
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_LEVELS }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_TOP },
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_ORDERBY },
{ URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER }, /* { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, */
{ URI_PROPERTY_PRIMITIVE, QO_FORMAT },
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FILTER }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FORMAT },
/* { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ORDERBY }, */{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SKIP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ORDERBY }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SKIP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SKIPTOKEN }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_TOP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_FILTER },
@ -137,7 +138,7 @@ public class UriValidatorTest {
{ URI_NAV_ENTITY, QO_LEVELS },
{ 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_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_SKIPTOKEN }, { URI_NAV_ENTITY_SET, QO_LEVELS }, { URI_NAV_ENTITY_SET, QO_TOP },
@ -161,30 +162,30 @@ public class UriValidatorTest {
{ URI_ALL, QO_ID, }, { URI_ALL, QO_TOP },
{ 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_LEVELS }, { 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_LEVELS }, { 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_LEVELS }, { URI_SERVICE, QO_TOP },
{ URI_ENTITY_SET, QO_ID },
{ URI_ENTITY_SET_COUNT, QO_FORMAT }, { URI_ENTITY_SET_COUNT, QO_ID },
{ URI_ENTITY_SET_COUNT, QO_EXPAND }, { URI_ENTITY_SET_COUNT, QO_COUNT },
/* { URI_ENTITY_SET_COUNT, QO_ORDERBY }, */
{ URI_ENTITY_SET_COUNT, QO_ORDERBY },
{ URI_ENTITY_SET_COUNT, QO_SELECT }, { URI_ENTITY_SET_COUNT, QO_SKIP }, { URI_ENTITY_SET_COUNT, QO_SKIPTOKEN },
{ URI_ENTITY_SET_COUNT, QO_LEVELS }, { URI_ENTITY_SET_COUNT, QO_TOP },
@ -192,7 +193,7 @@ public class UriValidatorTest {
/* { 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_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_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_SKIPTOKEN },
{ URI_MEDIA_STREAM, QO_LEVELS }, { URI_MEDIA_STREAM, QO_TOP },
@ -200,26 +201,26 @@ public class UriValidatorTest {
{ URI_REFERENCES, QO_SELECT }, { URI_REFERENCES, QO_LEVELS },
{ 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_LEVELS }, { 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_ORDERBY }, */
{ URI_PROPERTY_COMPLEX_COLLECTION, QO_ID, },
/* { URI_PROPERTY_COMPLEX_COLLECTION, QO_SEARCH }, */{ URI_PROPERTY_COMPLEX_COLLECTION, QO_SELECT },
{ 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_COUNT }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_ORDERBY },
{ 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_LEVELS }, { 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_COUNT }, { URI_PROPERTY_PRIMITIVE, QO_ORDERBY },
/* { URI_PROPERTY_PRIMITIVE, QO_SEARCH }, */{ URI_PROPERTY_PRIMITIVE, QO_SELECT },
{ URI_PROPERTY_PRIMITIVE, QO_SKIP }, { URI_PROPERTY_PRIMITIVE, QO_SKIPTOKEN },
{ URI_PROPERTY_PRIMITIVE, QO_LEVELS }, { URI_PROPERTY_PRIMITIVE, QO_TOP },
@ -231,24 +232,24 @@ public class UriValidatorTest {
{ 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_SELECT }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIP },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIPTOKEN },
{ URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_LEVELS }, { 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_LEVELS },
{ 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 },
@ -268,17 +269,32 @@ public class UriValidatorTest {
public void validateSelect() throws Exception {
String[] uris = { "/ESAllPrim(1)?$select=PropertyString" };
for (String uri : uris) {
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
}
@Test(expected = UriValidationException.class)
public void validateForHttpMethodsFail() throws Exception {
String uri = URI_ENTITY;
parseAndValidate(uri, "xyz");
}
@Test
// @Ignore("uri parser doen't support orderby yet")
public
void validateOrderBy() throws Exception {
public void validateForHttpMethods() throws Exception {
String uri = URI_ENTITY;
parseAndValidate(uri, "GET");
parseAndValidate(uri, "POST");
parseAndValidate(uri, "PUT");
parseAndValidate(uri, "DELETE");
parseAndValidate(uri, "PATCH");
parseAndValidate(uri, "MERGE");
}
@Test
public void validateOrderBy() throws Exception {
String[] uris = { "/ESAllPrim?$orderby=PropertyString" };
for (String uri : uris) {
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
}
@ -286,25 +302,25 @@ public class UriValidatorTest {
@Ignore("uri parser doen't support orderby yet")
public void validateOrderByInvalid() throws Exception {
String uri = "/ESAllPrim(1)?$orderBy=XXXX";
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
@Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongKey() throws Exception {
String uri = "ESTwoKeyNav(xxx=1, yyy='abc')";
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
@Test
public void validateKeyPredicates() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16=1, PropertyString='abc')";
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
@Test(expected = UriValidationException.class)
public void validateKeyPredicatesWrongValueType() throws Exception {
String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString=1)";
parseAndValidate(uri);
parseAndValidate(uri, "GET");
}
@Test
@ -313,7 +329,7 @@ public class UriValidatorTest {
for (String uri : uris) {
try {
parseAndValidate(uri);
parseAndValidate(uri, "GET");
} catch (Exception e) {
throw new Exception("Faild for uri: " + uri, e);
}
@ -326,7 +342,7 @@ public class UriValidatorTest {
for (String uri : uris) {
try {
parseAndValidate(uri);
parseAndValidate(uri, "GET");
fail("Validation Exception not thrown: " + uri);
} catch (UriValidationException e) {
assertTrue(e instanceof UriValidationException);
@ -352,11 +368,11 @@ public class UriValidatorTest {
return uris.toArray(new String[0]);
}
private void parseAndValidate(final String uri) throws UriParserException, UriValidationException {
private void parseAndValidate(final String uri, String method) throws UriParserException, UriValidationException {
UriInfo uriInfo = parser.parseUri(uri.trim(), edm);
UriValidator validator = new UriValidator();
validator.validate(uriInfo, "GET");
validator.validate(uriInfo, method);
}
}