You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by sk...@apache.org on 2014/05/13 14:55:57 UTC
[1/5] [OLINGO-266] server-test module introduced
Repository: olingo-odata4
Updated Branches:
refs/heads/olingo-266-ref a98d3b4ab -> 7916df52e
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java
new file mode 100644
index 0000000..9005080
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java
@@ -0,0 +1,85 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.Token;
+import org.apache.olingo.server.core.uri.antlr.UriLexer;
+
+public class UriLexerWithTrace extends UriLexer {
+ int logLevel = 0;
+
+ public UriLexerWithTrace(final ANTLRInputStream antlrInputStream, final int logLevel) {
+ super(antlrInputStream);
+ this.logLevel = logLevel;
+ }
+
+ public UriLexerWithTrace(final ANTLRInputStream antlrInputStream, final int logLevel, final int mode) {
+ super(antlrInputStream);
+ super.mode(mode);
+ this.logLevel = logLevel;
+ }
+
+ @Override
+ public void emit(final Token token) {
+ if (logLevel > 1) {
+ String out = String.format("%1$-" + 20 + "s", token.getText());
+
+ int tokenType = token.getType();
+ if (tokenType == -1) {
+ out += "-1/EOF";
+ } else {
+ out += UriLexer.tokenNames[tokenType];
+ }
+ System.out.println("Lexer.emit(...):" + out);
+ }
+
+ super.emit(token);
+ }
+
+ @Override
+ public void pushMode(final int m) {
+
+ String out = UriLexer.modeNames[_mode] + "-->";
+
+ super.pushMode(m);
+
+ out += UriLexer.modeNames[_mode];
+
+ if (logLevel > 1) {
+ System.out.println(out + " ");
+ }
+ }
+
+ @Override
+ public int popMode() {
+
+ String out = UriLexer.modeNames[_mode] + "-->";
+
+ int m = super.popMode();
+
+ out += UriLexer.modeNames[_mode];
+
+ if (logLevel > 1) {
+ System.out.println(out + " ");
+ }
+
+ return m;
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
new file mode 100644
index 0000000..9787fab
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java
@@ -0,0 +1,378 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.validator;
+
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.parser.Parser;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
+import org.junit.Before;
+import org.junit.Ignore;
+import org.junit.Test;
+
+public class UriValidatorTest {
+
+ 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_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)/PropertyComplex";
+ private static final String URI_PROPERTY_COMPLEX_COLLECTION =
+ "/ESCompCollComp(1)/PropertyComplex/CollPropertyComplex";
+ private static final String URI_PROPERTY_COMPLEX_COLLECTION_COUNT =
+ "/ESCompCollComp(1)/PropertyComplex/CollPropertyComplex/$count";
+ private static final String URI_PROPERTY_PRIMITIVE = "/ESAllPrim(1)/PropertyString";
+ private static final String URI_PROPERTY_PRIMITIVE_COLLECTION = "/ESCollAllPrim/CollPropertyString";
+ private static final String URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT =
+ "/ESCollAllPrim/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/NavPropertyETKeyNavOne";
+ private static final String URI_NAV_ENTITY_SET = "/ESKeyNav/NavPropertyETKeyNavMany";
+
+ private static final String QO_FILTER = "$filter='1' eq '1'";
+ private static final String QO_FORMAT = "$format=bla";
+ 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_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";
+ private static final String QO_LEVELS = "$expand=*($levels=1)";
+ private static final String QO_TOP = "$top=1";
+
+ 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_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_SEARCH }, */{ URI_CROSSJOIN, QO_SELECT }, { URI_CROSSJOIN, QO_SKIP },
+ { URI_CROSSJOIN, QO_SKIPTOKEN }, { URI_CROSSJOIN, QO_LEVELS }, { URI_CROSSJOIN, QO_TOP },
+
+ { URI_ENTITY_ID, QO_ID, QO_FORMAT }, { URI_ENTITY_ID, QO_ID, }, { URI_ENTITY_ID, QO_ID, QO_EXPAND },
+ { URI_ENTITY_ID, QO_ID, QO_SELECT }, { URI_ENTITY_ID, QO_ID, QO_LEVELS },
+
+ { URI_METADATA, QO_FORMAT },
+
+ { 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_SELECT },
+ { URI_ENTITY_SET, QO_SKIP }, { URI_ENTITY_SET, QO_SKIPTOKEN }, { URI_ENTITY_SET, QO_LEVELS },
+ { URI_ENTITY_SET, QO_TOP },
+
+ { 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_ENTITY, QO_LEVELS },
+
+ { URI_MEDIA_STREAM, QO_FORMAT },
+
+ { 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 },
+
+ { URI_REFERENCE, QO_FORMAT },
+
+ { URI_PROPERTY_COMPLEX, QO_FORMAT }, { URI_PROPERTY_COMPLEX, QO_SELECT }, { URI_PROPERTY_COMPLEX, QO_EXPAND },
+ { URI_PROPERTY_COMPLEX, QO_LEVELS },
+
+ { URI_PROPERTY_COMPLEX_COLLECTION, QO_FILTER }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_FORMAT },
+ { 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_SKIPTOKEN }, { 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 },
+
+ { URI_SINGLETON, QO_FORMAT }, { URI_SINGLETON, QO_EXPAND }, { URI_SINGLETON, QO_SELECT },
+ { URI_SINGLETON, QO_LEVELS },
+
+ { URI_NAV_ENTITY, QO_FORMAT }, { URI_NAV_ENTITY, QO_EXPAND }, { URI_NAV_ENTITY, QO_SELECT },
+ { 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_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 },
+
+ { "FINRTInt16()" },
+ { "FICRTETKeyNav()" },
+ { "FICRTESTwoKeyNavParam(ParameterInt16=1)" },
+ { "FICRTCollString()" },
+ { "FICRTCTTwoPrim()" },
+ { "FICRTCollCTTwoPrim()" },
+ { "FICRTETMedia()" },
+
+ { "ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" },
+ { "ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim" },
+ { "AIRTPrimCollParam" },
+ { "AIRTETParam" },
+ { "AIRTPrimParam" },
+
+ };
+
+ private String[][] urisWithNonValidSystemQueryOptions = {
+ { 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_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_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_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_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_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 },
+
+ { 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_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_SKIPTOKEN },
+ { URI_MEDIA_STREAM, QO_LEVELS }, { URI_MEDIA_STREAM, QO_TOP },
+
+ { URI_REFERENCES, QO_ID, }, { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT },
+ { 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_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_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_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_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_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 },
+
+ { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ID, }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_EXPAND },
+ { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_COUNT }, /* { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SEARCH }, */
+ { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_LEVELS },
+
+ { 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_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_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_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_SKIPTOKEN }, { URI_SINGLETON, QO_TOP },
+
+ { URI_NAV_ENTITY_SET, QO_ID },
+
+ };
+
+ private Parser parser;
+ private Edm edm;
+
+ @Before
+ public void before() {
+ parser = new Parser();
+ edm = new EdmProviderImpl(new EdmTechProvider());
+ }
+
+ @Test
+ public void validateSelect() throws Exception {
+ String[] uris = { "/ESAllPrim(1)?$select=PropertyString" };
+ for (String uri : uris) {
+ parseAndValidate(uri, "GET");
+ }
+ }
+
+ @Test(expected = UriValidationException.class)
+ public void validateForHttpMethodsFail() throws Exception {
+ String uri = URI_ENTITY;
+ parseAndValidate(uri, "xyz");
+ }
+
+ @Test
+ 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, "GET");
+ }
+ }
+
+ @Test(expected = UriValidationException.class)
+ @Ignore("uri parser doen't support orderby yet")
+ public void validateOrderByInvalid() throws Exception {
+ String uri = "/ESAllPrim(1)?$orderBy=XXXX";
+ parseAndValidate(uri, "GET");
+ }
+
+ @Test(expected = UriValidationException.class)
+ public void validateKeyPredicatesWrongKey() throws Exception {
+ String uri = "ESTwoKeyNav(xxx=1, yyy='abc')";
+ parseAndValidate(uri, "GET");
+ }
+
+ @Test
+ public void validateKeyPredicates() throws Exception {
+ String uri = "ESTwoKeyNav(PropertyInt16=1, PropertyString='abc')";
+ parseAndValidate(uri, "GET");
+ }
+
+ @Test(expected = UriValidationException.class)
+ public void validateKeyPredicatesWrongValueType() throws Exception {
+ String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString=1)";
+ parseAndValidate(uri, "GET");
+ }
+
+ @Test
+ public void checkValidSystemQueryOption() throws Exception {
+ String[] uris = constructUri(urisWithValidSystemQueryOptions);
+
+ for (String uri : uris) {
+ try {
+ parseAndValidate(uri, "GET");
+ } catch (Exception e) {
+ throw new Exception("Faild for uri: " + uri, e);
+ }
+ }
+ }
+
+ @Test
+ public void checkNonValidSystemQueryOption() throws Exception {
+ String[] uris = constructUri(urisWithNonValidSystemQueryOptions);
+
+ for (String uri : uris) {
+ try {
+ parseAndValidate(uri, "GET");
+ fail("Validation Exception not thrown: " + uri);
+ } catch (UriValidationException e) {
+ assertTrue(e instanceof UriValidationException);
+ }
+ }
+ }
+
+ private String[] constructUri(final String[][] uriParameterMatrix) {
+ ArrayList<String> uris = new ArrayList<String>();
+ for (String[] uriParameter : uriParameterMatrix) {
+ String uri = uriParameter[0];
+ if (uriParameter.length > 1) {
+ uri += "?";
+ }
+ for (int i = 1; i < uriParameter.length; i++) {
+ uri += uriParameter[i];
+ if (i < (uriParameter.length - 1)) {
+ uri += "&";
+ }
+ }
+ uris.add(uri);
+ }
+ return uris.toArray(new String[0]);
+ }
+
+ 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, method);
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/resources/simplelogger.properties
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/resources/simplelogger.properties b/lib/server-test/src/test/resources/simplelogger.properties
new file mode 100644
index 0000000..2a3350c
--- /dev/null
+++ b/lib/server-test/src/test/resources/simplelogger.properties
@@ -0,0 +1,20 @@
+#
+# Licensed to the Apache Software Foundation (ASF) under one
+# or more contributor license agreements. See the NOTICE file
+# distributed with this work for additional information
+# regarding copyright ownership. The ASF licenses this file
+# to you under the Apache License, Version 2.0 (the
+# "License"); you may not use this file except in compliance
+# with the License. You may obtain a copy of the License at
+#
+# http://www.apache.org/licenses/LICENSE-2.0
+#
+# Unless required by applicable law or agreed to in writing,
+# software distributed under the License is distributed on an
+# "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+# KIND, either express or implied. See the License for the
+# specific language governing permissions and limitations
+# under the License.
+#
+org.slf4j.simpleLogger.defaultLogLevel=debug
+org.slf4j.simpleLogger.logFile=System.out
\ No newline at end of file
[2/5] [OLINGO-266] server-test module introduced
Posted by sk...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
new file mode 100644
index 0000000..fde13c8
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java
@@ -0,0 +1,230 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.queryoption.ExpandItem;
+import org.apache.olingo.server.api.uri.queryoption.SelectItem;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
+
+public class ExpandValidator implements TestValidator {
+ private Edm edm;
+ private TestValidator invokedByValidator;
+
+ private int expandItemIndex;
+ private ExpandOptionImpl expandOption;
+ private ExpandItem expandItem;
+
+ // --- Setup ---
+
+ public ExpandValidator setUpValidator(final TestValidator validator) {
+ invokedByValidator = validator;
+ return this;
+ }
+
+ public ExpandValidator setExpand(final ExpandOptionImpl expand) {
+ expandOption = expand;
+ first();
+ return this;
+ }
+
+ public ExpandValidator setEdm(final Edm edm) {
+ this.edm = edm;
+ return this;
+ }
+
+ // --- Navigation ---
+
+ public ExpandValidator goUpToExpandValidator() {
+ return (ExpandValidator) invokedByValidator;
+ }
+
+ public ResourceValidator goUpToUriResourceValidator() {
+ return (ResourceValidator) invokedByValidator;
+ }
+
+ public ResourceValidator goPath() {
+ UriInfoImpl uriInfo = (UriInfoImpl) expandItem.getResourcePath();
+
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("goPath() can only be used on UriInfoKind.resource");
+ }
+
+ return new ResourceValidator()
+ .setUpValidator(this)
+ .setEdm(edm)
+ .setUriInfoImplPath(uriInfo);
+
+ }
+
+ public FilterValidator goOrder(final int index) {
+ OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption();
+
+ return new FilterValidator()
+ .setValidator(this)
+ .setEdm(edm)
+ .setExpression(orderBy.getOrders().get(index).getExpression());
+ }
+
+ public ResourceValidator goSelectItem(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ UriInfoImpl uriInfo = (UriInfoImpl) item.getResourcePath();
+
+ return new ResourceValidator()
+ .setUpValidator(this)
+ .setEdm(edm)
+ .setUriInfoImplPath(uriInfo);
+
+ }
+
+ public ExpandValidator goExpand() {
+ ExpandValidator val = new ExpandValidator()
+ .setExpand((ExpandOptionImpl) expandItem.getExpandOption())
+ .setUpValidator(this);
+ return val;
+ }
+
+ public ExpandValidator first() {
+ expandItemIndex = 0;
+ expandItem = expandOption.getExpandItems().get(expandItemIndex);
+ return this;
+ }
+
+ public ExpandValidator next() {
+ expandItemIndex++;
+
+ try {
+ expandItem = expandOption.getExpandItems().get(expandItemIndex);
+ } catch (IndexOutOfBoundsException ex) {
+ fail("not enought segments");
+ }
+ return this;
+
+ }
+
+ public ExpandValidator isSegmentStar(final int index) {
+ assertEquals(true, expandItem.isStar());
+ return this;
+ }
+
+ public ExpandValidator isSegmentRef(final int index) {
+ assertEquals(true, expandItem.isRef());
+ return this;
+ }
+
+ public ExpandValidator isLevelText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getLevelsOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isSkipText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getSkipOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isTopText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getTopOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isInlineCountText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getCountOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isSelectText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getSelectOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isSelectItemStar(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(true, item.isStar());
+ return this;
+ }
+
+ public ExpandValidator isSelectItemAllOperations(final int index, final FullQualifiedName fqn) {
+ SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
+ return this;
+ }
+
+ public ExpandValidator isFilterOptionText(final String text) {
+ QueryOptionImpl option = (QueryOptionImpl) expandItem.getFilterOption();
+ assertEquals(text, option.getText());
+ return this;
+ }
+
+ public ExpandValidator isFilterSerialized(final String serialized) {
+ FilterOptionImpl filter = (FilterOptionImpl) expandItem.getFilterOption();
+
+ try {
+ String tmp = FilterTreeToText.Serialize(filter);
+ assertEquals(serialized, tmp);
+ } catch (ExpressionVisitException e) {
+ fail("Exception occured while converting the filterTree into text" + "\n"
+ + " Exception: " + e.getMessage());
+ } catch (ODataApplicationException e) {
+ fail("Exception occured while converting the filterTree into text" + "\n"
+ + " Exception: " + e.getMessage());
+ }
+
+ return this;
+ }
+
+ public ExpandValidator isSortOrder(final int index, final boolean descending) {
+ OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption();
+ assertEquals(descending, orderBy.getOrders().get(index).isDescending());
+ return this;
+ }
+
+ public ExpandValidator isExpandStartType(final FullQualifiedName fullName) {
+ EdmType actualType = expandItem.getStartTypeFilter();
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(fullName, actualName);
+ return this;
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java
new file mode 100644
index 0000000..06056e0
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java
@@ -0,0 +1,154 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriResource;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAll;
+import org.apache.olingo.server.api.uri.UriResourceLambdaAny;
+import org.apache.olingo.server.api.uri.UriResourcePartTyped;
+import org.apache.olingo.server.api.uri.queryoption.FilterOption;
+import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitor;
+import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind;
+
+public class FilterTreeToText implements ExpressionVisitor<String> {
+
+ public static String Serialize(final FilterOption filter)
+ throws ExpressionVisitException, ODataApplicationException {
+
+ Expression expression = filter.getExpression();
+ return expression.accept(new FilterTreeToText());
+ }
+
+ public static String Serialize(final Expression expression)
+ throws ExpressionVisitException, ODataApplicationException {
+
+ return expression.accept(new FilterTreeToText());
+ }
+
+ @Override
+ public String visitBinaryOperator(final BinaryOperatorKind operator, final String left, final String right)
+ throws ExpressionVisitException {
+
+ return "<" + left + " " + operator.toString() + " " + right + ">";
+ }
+
+ @Override
+ public String visitUnaryOperator(final UnaryOperatorKind operator, final String operand)
+ throws ExpressionVisitException {
+
+ return "<" + operator + " " + operand.toString() + ">";
+ }
+
+ @Override
+ public String visitMethodCall(final MethodKind methodCall, final List<String> parameters)
+ throws ExpressionVisitException {
+
+ String text = "<" + methodCall + "(";
+ int i = 0;
+ while (i < parameters.size()) {
+ if (i > 0) {
+ text += ",";
+ }
+ text += parameters.get(i);
+ i++;
+ }
+ return text + ")>";
+ }
+
+ @Override
+ public String visitLiteral(final String literal) throws ExpressionVisitException {
+ return "<" + literal + ">";
+ }
+
+ @Override
+ public String visitMember(final UriInfoResource resource) throws ExpressionVisitException, ODataApplicationException {
+ String ret = "";
+
+ UriInfoResource path = resource;
+
+ for (UriResource item : path.getUriResourceParts()) {
+ String tmp = "";
+ if (item instanceof UriResourceLambdaAll) {
+ UriResourceLambdaAll all = (UriResourceLambdaAll) item;
+ tmp = visitLambdaExpression("ALL", all.getLambdaVariable(), all.getExpression());
+ } else if (item instanceof UriResourceLambdaAny) {
+ UriResourceLambdaAny any = (UriResourceLambdaAny) item;
+ tmp = visitLambdaExpression("ANY", any.getLamdaVariable(), any.getExpression());
+ } else if (item instanceof UriResourcePartTyped) {
+ UriResourcePartTyped typed = (UriResourcePartTyped) item;
+ tmp = typed.toString(true);
+ }
+
+ if (ret.length() != 0) {
+ ret += "/";
+ }
+ ret += tmp;
+
+ }
+ return "<" + ret + ">";
+ }
+
+ @Override
+ public String visitAlias(final String referenceName) throws ExpressionVisitException {
+ return "<" + referenceName + ">";
+ }
+
+ @Override
+ public String visitLambdaExpression(final String functionText, final String string, final Expression expression)
+ throws ExpressionVisitException, ODataApplicationException {
+
+ return "<" + functionText + ";" + ((expression == null) ? "" : expression.accept(this)) + ">";
+ }
+
+ @Override
+ public String visitTypeLiteral(final EdmType type) {
+ return "<" + type.getNamespace() + "." + type.getName() + ">";
+ }
+
+ @Override
+ public String visitLambdaReference(final String variableText) {
+ return "<" + variableText + ">";
+ }
+
+ @Override
+ public String visitEnum(final EdmEnumType type, final List<String> enumValues)
+ throws ExpressionVisitException, ODataApplicationException {
+ String tmp = "";
+
+ for (String item : enumValues) {
+ if (tmp.length() > 0) {
+ tmp += ",";
+ }
+ tmp += item;
+ }
+
+ return "<" + type.getNamespace() + "." + type.getName() + "<" + tmp + ">>";
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
new file mode 100644
index 0000000..58e429f
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java
@@ -0,0 +1,534 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.Expression;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.api.uri.queryoption.expression.Member;
+import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+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.queryoption.FilterOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.BinaryImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.EnumerationImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.TypeLiteralImpl;
+
+public class FilterValidator implements TestValidator {
+ private Edm edm;
+
+ private TestValidator invokedByValidator;
+ private FilterOptionImpl filter;
+
+ private Expression curExpression;
+ private Expression rootExpression;
+
+ private OrderByOptionImpl orderBy;
+
+ private UriParserException exception;
+
+ // --- Setup ---
+ public FilterValidator setUriResourcePathValidator(final ResourceValidator uriResourcePathValidator) {
+ invokedByValidator = uriResourcePathValidator;
+ return this;
+ }
+
+ public FilterValidator setUriValidator(final TestUriValidator uriValidator) {
+ invokedByValidator = uriValidator;
+ return this;
+ }
+
+ public FilterValidator setValidator(final TestValidator uriValidator) {
+ invokedByValidator = uriValidator;
+ return this;
+ }
+
+ public FilterValidator setEdm(final Edm edm) {
+ this.edm = edm;
+ return this;
+ }
+
+ public FilterValidator setFilter(final FilterOptionImpl filter) {
+ this.filter = filter;
+
+ if (filter.getExpression() == null) {
+ fail("FilterValidator: no filter found");
+ }
+ setExpression(filter.getExpression());
+ return this;
+ }
+
+ public FilterValidator setOrderBy(final OrderByOptionImpl orderBy) {
+ this.orderBy = orderBy;
+
+ return this;
+ }
+
+ public FilterValidator setExpression(final Expression expression) {
+ rootExpression = curExpression = expression;
+ return this;
+ }
+
+ // --- Execution ---
+
+ public FilterValidator runOrderByOnETAllPrim(final String orderBy) throws UriParserException {
+ String uri = "ESAllPrim?$orderby=" + orderBy.trim();
+ return runUriOrderBy(uri);
+ }
+
+ public FilterValidator runOrderByOnETTwoKeyNav(final String orderBy) throws UriParserException {
+ String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim();
+ return runUriOrderBy(uri);
+ }
+
+ public FilterValidator runOrderByOnETTwoKeyNavEx(final String orderBy) throws UriParserException {
+ String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim();
+ return runUriOrderByEx(uri);
+ }
+
+ public FilterValidator runOnETTwoKeyNav(final String filter) throws UriParserException {
+ String uri = "ESTwoKeyNav?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnETTwoKeyNavSingle(final String filter) throws UriParserException {
+ String uri = "SINav?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException {
+ String uri = "ESTwoKeyNav?$filter=" + filter.trim();
+ return runUriEx(uri);
+ }
+
+ public FilterValidator runOnETAllPrim(final String filter) throws UriParserException {
+ String uri = "ESAllPrim(1)?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnETKeyNav(final String filter) throws UriParserException {
+ String uri = "ESKeyNav(1)?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnETKeyNavEx(final String filter) throws UriParserException {
+ String uri = "ESKeyNav(1)?$filter=" + filter.trim();
+ return runUriEx(uri);
+ }
+
+ public FilterValidator runOnCTTwoPrim(final String filter) throws UriParserException {
+ String uri = "SINav/PropertyComplexTwoPrim?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnString(final String filter) throws UriParserException {
+ String uri = "SINav/PropertyString?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnInt32(final String filter) throws UriParserException {
+ String uri = "ESCollAllPrim(1)/CollPropertyInt32?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnDateTimeOffset(final String filter) throws UriParserException {
+ String uri = "ESCollAllPrim(1)/CollPropertyDateTimeOffset?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnDuration(final String filter) throws UriParserException {
+ String uri = "ESCollAllPrim(1)/CollPropertyDuration?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runOnTimeOfDay(final String filter) throws UriParserException {
+ String uri = "ESCollAllPrim(1)/CollPropertyTimeOfDay?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runESabc(final String filter) throws UriParserException {
+ String uri = "ESabc?$filter=" + filter.trim();
+ return runUri(uri);
+ }
+
+ public FilterValidator runUri(final String uri) throws UriParserException {
+ Parser parser = new Parser();
+ UriInfo uriInfo = null;
+
+ uriInfo = parser.parseUri(uri, edm);
+
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("Filtervalidator can only be used on resourcePaths");
+ }
+
+ setFilter((FilterOptionImpl) uriInfo.getFilterOption());
+ curExpression = filter.getExpression();
+ return this;
+ }
+
+ public FilterValidator runUriEx(final String uri) {
+ Parser parser = new Parser();
+ UriInfo uriInfo = null;
+
+ try {
+ uriInfo = parser.parseUri(uri, edm);
+ } catch (UriParserException e) {
+ exception = e;
+ return this;
+ }
+
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("Filtervalidator can only be used on resourcePaths");
+ }
+
+ setFilter((FilterOptionImpl) uriInfo.getFilterOption());
+ curExpression = filter.getExpression();
+ return this;
+ }
+
+ public FilterValidator runUriOrderBy(final String uri) throws UriParserException {
+ Parser parser = new Parser();
+ UriInfo uriInfo = null;
+
+ uriInfo = parser.parseUri(uri, edm);
+
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("Filtervalidator can only be used on resourcePaths");
+ }
+
+ setOrderBy((OrderByOptionImpl) uriInfo.getOrderByOption());
+ return this;
+ }
+
+ public FilterValidator runUriOrderByEx(final String uri) {
+ Parser parser = new Parser();
+ UriInfo uriInfo = null;
+
+ try {
+ uriInfo = parser.parseUri(uri, edm);
+ } catch (UriParserException e) {
+ exception = e;
+ return this;
+ }
+
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("Filtervalidator can only be used on resourcePaths");
+ }
+
+ setOrderBy((OrderByOptionImpl) uriInfo.getOrderByOption());
+ return this;
+ }
+
+ // --- Navigation ---
+
+ public ExpandValidator goUpToExpandValidator() {
+ return (ExpandValidator) invokedByValidator;
+ }
+
+ public ResourceValidator goUpToResourceValidator() {
+ return (ResourceValidator) invokedByValidator;
+ }
+
+ public ResourceValidator goPath() {
+ if (!(curExpression instanceof MemberImpl)) {
+ fail("Current expression not a member");
+ }
+
+ MemberImpl member = (MemberImpl) curExpression;
+
+ return new ResourceValidator()
+ .setEdm(edm)
+ .setUriInfoImplPath((UriInfoImpl) member.getResourcePath())
+ .setUpValidator(this);
+
+ }
+
+ public FilterValidator goParameter(final int parameterIndex) {
+ if (curExpression instanceof MethodImpl) {
+ MethodImpl methodCall = (MethodImpl) curExpression;
+ curExpression = methodCall.getParameters().get(parameterIndex);
+ } else {
+ fail("Current expression not a methodCall");
+ }
+ return this;
+ }
+
+ // --- Validation ---
+
+ /**
+ * Validates the serialized filterTree against a given filterString
+ * The given expected filterString is compressed before to allow better readable code in the unit tests
+ * @param toBeCompr
+ * @return
+ */
+ public FilterValidator isCompr(final String toBeCompr) {
+ return is(compress(toBeCompr));
+ }
+
+ public FilterValidator is(final String expectedFilterAsString) {
+ try {
+ String actualFilterAsText = FilterTreeToText.Serialize((FilterOptionImpl) filter);
+ assertEquals(expectedFilterAsString, actualFilterAsText);
+ } catch (ExpressionVisitException e) {
+ fail("Exception occured while converting the filterTree into text" + "\n"
+ + " Exception: " + e.getMessage());
+ } catch (ODataApplicationException e) {
+ fail("Exception occured while converting the filterTree into text" + "\n"
+ + " Exception: " + e.getMessage());
+ }
+
+ return this;
+ }
+
+ // --- Helper ---
+
+ private String compress(final String expected) {
+ String ret = expected.replaceAll("\\s+", " ");
+ ret = ret.replaceAll("< ", "<");
+ ret = ret.replaceAll(" >", ">");
+ return ret;
+ }
+
+ public FilterValidator isType(final FullQualifiedName fullName) {
+ EdmType actualType = null;
+
+ if (curExpression instanceof MemberImpl) {
+ Member member = (Member) curExpression;
+ actualType = member.getType();
+ } else if (curExpression instanceof TypeLiteralImpl) {
+ TypeLiteralImpl typeLiteral = (TypeLiteralImpl) curExpression;
+ actualType = typeLiteral.getType();
+ } else if (curExpression instanceof LiteralImpl) {
+ LiteralImpl typeLiteral = (LiteralImpl) curExpression;
+ actualType = typeLiteral.getType();
+ }
+
+ if (actualType == null) {
+ fail("Current expression not typed");
+ }
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(fullName, actualName);
+ return this;
+ }
+
+ public FilterValidator left() {
+ if (!(curExpression instanceof BinaryImpl)) {
+ fail("Current expression not a binary operator");
+ }
+
+ curExpression = ((BinaryImpl) curExpression).getLeftOperand();
+
+ return this;
+ }
+
+ public FilterValidator root() {
+ if (filter != null) {
+ curExpression = filter.getExpression();
+ } else {
+ curExpression = rootExpression;
+ }
+
+ return this;
+ }
+
+ public FilterValidator right() {
+ if (!(curExpression instanceof BinaryImpl)) {
+ fail("Current expression is not a binary operator");
+ }
+
+ curExpression = ((BinaryImpl) curExpression).getRightOperand();
+
+ return this;
+
+ }
+
+ public FilterValidator isLiteral(final String literalText) {
+ if (!(curExpression instanceof LiteralImpl)) {
+ fail("Current expression is not a literal");
+ }
+
+ String actualLiteralText = ((LiteralImpl) curExpression).getText();
+ assertEquals(literalText, actualLiteralText);
+
+ return this;
+ }
+
+ public FilterValidator isMethod(final MethodKind methodKind, final int parameterCount) {
+ if (!(curExpression instanceof MethodImpl)) {
+ fail("Current expression is not a methodCall");
+ }
+
+ MethodImpl methodCall = (MethodImpl) curExpression;
+ assertEquals(methodKind, methodCall.getMethod());
+ assertEquals(parameterCount, methodCall.getParameters().size());
+
+ return this;
+ }
+
+ public FilterValidator isParameterText(final int parameterIndex, final String parameterText)
+ throws ExpressionVisitException, ODataApplicationException {
+
+ if (!(curExpression instanceof MethodImpl)) {
+ fail("Current expression is not a method");
+ }
+
+ MethodImpl methodCall = (MethodImpl) curExpression;
+
+ Expression parameter = methodCall.getParameters().get(parameterIndex);
+ String actualParameterText = FilterTreeToText.Serialize(parameter);
+ assertEquals(parameterText, actualParameterText);
+
+ return this;
+ }
+
+ public FilterValidator isBinary(final BinaryOperatorKind binaryOperator) {
+ if (!(curExpression instanceof BinaryImpl)) {
+ fail("Current expression is not a binary operator");
+ }
+
+ BinaryImpl binary = (BinaryImpl) curExpression;
+ assertEquals(binaryOperator, binary.getOperator());
+
+ return this;
+ }
+
+ public FilterValidator isTypedLiteral(final FullQualifiedName fullName) {
+ if (!(curExpression instanceof TypeLiteralImpl)) {
+ fail("Current expression not a typeLiteral");
+ }
+
+ isType(fullName);
+
+ return this;
+ }
+
+ public FilterValidator isMember() {
+ if (!(curExpression instanceof MemberImpl)) {
+ fail("Current expression not a member");
+ }
+
+ return this;
+ }
+
+ public FilterValidator isMemberStartType(final FullQualifiedName fullName) {
+ if (!(curExpression instanceof MemberImpl)) {
+ fail("Current expression not a member");
+ }
+
+ MemberImpl member = (MemberImpl) curExpression;
+ EdmType actualType = member.getStartTypeFilter();
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(fullName, actualName);
+ return this;
+ }
+
+ public FilterValidator isEnum(final FullQualifiedName nameenstring, final List<String> enumValues) {
+ if (!(curExpression instanceof EnumerationImpl)) {
+ fail("Current expression not a enumeration");
+ }
+
+ EnumerationImpl enumeration = (EnumerationImpl) curExpression;
+
+ FullQualifiedName actualName =
+ new FullQualifiedName(enumeration.getType().getNamespace(), enumeration.getType().getName());
+
+ // check name
+ assertEquals(nameenstring.toString(), actualName.toString());
+
+ // check values
+ int i = 0;
+ for (String item : enumValues) {
+ assertEquals(item, enumeration.getValues().get(i));
+ i++;
+ }
+
+ return this;
+ }
+
+ public FilterValidator isSortOrder(final int index, final boolean descending) {
+ assertEquals(descending, orderBy.getOrders().get(index).isDescending());
+ return this;
+ }
+
+ public FilterValidator goOrder(final int index) {
+ curExpression = orderBy.getOrders().get(index).getExpression();
+ return this;
+ }
+
+ public FilterValidator isExSyntax(final long errorID) {
+ assertEquals(UriParserSyntaxException.class, exception.getClass());
+ return this;
+ }
+
+ public FilterValidator isExSemantic(final long errorID) {
+ assertEquals(UriParserSemanticException.class, exception.getClass());
+ return this;
+ }
+
+ public FilterValidator isNull() {
+ if (!(curExpression instanceof LiteralImpl)) {
+ fail("Current expression is not a literal");
+ }
+
+ String actualLiteralText = ((LiteralImpl) curExpression).getText();
+ assertEquals("null", actualLiteralText);
+ return this;
+ }
+
+ public FilterValidator isTrue() {
+ if (!(curExpression instanceof LiteralImpl)) {
+ fail("Current expression is not a literal");
+ }
+
+ String actualLiteralText = ((LiteralImpl) curExpression).getText();
+ assertEquals("true", actualLiteralText);
+ return this;
+ }
+
+ public FilterValidator isFalse() {
+ if (!(curExpression instanceof LiteralImpl)) {
+ fail("Current expression is not a literal");
+ }
+
+ String actualLiteralText = ((LiteralImpl) curExpression).getText();
+ assertEquals("false", actualLiteralText);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java
new file mode 100644
index 0000000..f6a3086
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java
@@ -0,0 +1,82 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.antlr.v4.runtime.Token;
+import org.antlr.v4.runtime.misc.NotNull;
+import org.antlr.v4.runtime.misc.Nullable;
+import org.antlr.v4.runtime.misc.Utils;
+import org.antlr.v4.runtime.tree.ErrorNode;
+import org.antlr.v4.runtime.tree.RuleNode;
+import org.antlr.v4.runtime.tree.TerminalNode;
+import org.antlr.v4.runtime.tree.Tree;
+
+public class ParseTreeToText {
+
+ public static String getTreeAsText(final Tree contextTree, final String[] ruleNames) {
+ return toStringTree(contextTree, Arrays.asList(ruleNames));
+ }
+
+ private static String toStringTree(final Tree t, @Nullable final List<String> ruleNames) {
+
+ if (t.getChildCount() == 0) {
+ return Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
+ }
+
+ StringBuilder buf = new StringBuilder();
+ String s = Utils.escapeWhitespace(getNodeText(t, ruleNames), false);
+ buf.append(s);
+ buf.append("(");
+
+ for (int i = 0; i < t.getChildCount(); i++) {
+ if (i > 0) {
+ buf.append(' ');
+ }
+ buf.append(toStringTree(t.getChild(i), ruleNames));
+ }
+ buf.append(")");
+ return buf.toString();
+ }
+
+ private static String getNodeText(@NotNull final Tree t, @Nullable final List<String> ruleNames) {
+ if (ruleNames != null) {
+ if (t instanceof RuleNode) {
+ int ruleIndex = ((RuleNode) t).getRuleContext().getRuleIndex();
+ return ruleNames.get(ruleIndex);
+ } else if (t instanceof ErrorNode) {
+ return t.toString();
+ } else if (t instanceof TerminalNode) {
+ Token symbol = ((TerminalNode) t).getSymbol();
+ if (symbol != null) {
+ String s = symbol.getText();
+ return s;
+ }
+ }
+ }
+ // no recog for rule names
+ Object payload = t.getPayload();
+ if (payload instanceof Token) {
+ return ((Token) payload).getText();
+ }
+ return t.getPayload().toString();
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
new file mode 100644
index 0000000..3f73b97
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java
@@ -0,0 +1,162 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.antlr.v4.runtime.ParserRuleContext;
+import org.apache.olingo.server.core.uri.antlr.UriParserParser;
+
+public class ParserValidator {
+
+ private String input = null;
+ private ParserRuleContext root;
+
+ int logLevel = 0;
+ private int lexerLogLevel = 0;
+
+ boolean allowFullContext;
+ boolean allowContextSensitifity;
+ boolean allowAmbiguity;
+
+ List<Exception> exceptions = new ArrayList<Exception>();
+ private Exception curException = null;
+
+ // --- Setup ---
+
+ public ParserValidator log(final int logLevel) {
+ this.logLevel = logLevel;
+ return this;
+ }
+
+ public ParserValidator lexerLog(final int logLevel) {
+ lexerLogLevel = logLevel;
+ return this;
+ }
+
+ /**
+ * Used in fast LL Parsing:
+ * Don't stop the parsing process when the slower full context parsing (with prediction mode SLL) is
+ * required
+ * @return
+ */
+ public ParserValidator aFC() {
+ allowFullContext = true;
+ return this;
+ }
+
+ /**
+ * Used in fast LL Parsing:
+ * Allows ContextSensitifity Errors which occur often when using the slower full context parsing
+ * and indicate that there is a context sensitivity ( which may not be an error).
+ * @return
+ */
+ public ParserValidator aCS() {
+ allowContextSensitifity = true;
+ return this;
+ }
+
+ /**
+ * Used in fast LL Parsing:
+ * Allows ambiguities
+ * @return
+ */
+ public ParserValidator aAM() {
+ allowAmbiguity = true;
+ return this;
+ }
+
+ // --- Execution ---
+
+ public ParserValidator run(final String uri) {
+ input = uri;
+
+ // just run a short lexer step. E.g. to print the tokens
+ if (lexerLogLevel > 0) {
+ (new TokenValidator()).log(lexerLogLevel).run(input);
+ }
+
+ /**/// root = parseInput(uri);
+
+ // if LOG > 0 - Write serialized tree
+ if (logLevel > 0) {
+ if (root != null) {
+ System.out.println(ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames()));
+ } else {
+ System.out.println("root == null");
+ }
+ }
+
+ // reset for next test
+ allowFullContext = false;
+ allowContextSensitifity = false;
+ allowAmbiguity = false;
+ logLevel = 0;
+
+ return this;
+ }
+
+ // --- Navigation ---
+
+ public ParserValidator exFirst() {
+ try {
+ // curWeakException = exceptions.get(0);
+ } catch (IndexOutOfBoundsException ex) {
+ // curWeakException = null;
+ }
+ return this;
+
+ }
+
+ public ParserValidator exLast() {
+ // curWeakException = exceptions.get(exceptions.size() - 1);
+ return this;
+ }
+
+ public ParserValidator exAt(final int index) {
+ try {
+ // curWeakException = exceptions.get(index);
+ } catch (IndexOutOfBoundsException ex) {
+ // curWeakException = null;
+ }
+ return this;
+ }
+
+ // --- Validation ---
+
+ public ParserValidator isText(final String expected) {
+
+ assertEquals(null, curException);
+ assertEquals(0, exceptions.size());
+
+ String actualTreeAsText = ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames());
+
+ assertEquals(expected, actualTreeAsText);
+ return this;
+ }
+
+ public ParserValidator isExeptionType(final Class<?> exClass) {
+ assertEquals(exClass, curException.getClass());
+ return this;
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java
new file mode 100644
index 0000000..524a38a
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java
@@ -0,0 +1,56 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import org.antlr.v4.runtime.DefaultErrorStrategy;
+import org.antlr.v4.runtime.DiagnosticErrorListener;
+import org.apache.olingo.server.core.uri.antlr.UriParserParser;
+import org.apache.olingo.server.core.uri.parser.Parser;
+
+public class ParserWithLogging extends Parser {
+ TestErrorLogger errorCollector1;
+ TestErrorLogger errorCollector2;
+
+ public ParserWithLogging() {
+ errorCollector1 = new TestErrorLogger("Stage 1", 1);
+ errorCollector2 = new TestErrorLogger("Stage 2", 1);
+ }
+
+ @Override
+ protected void addStage2ErrorStategy(final UriParserParser parser) {
+ // Don't throw an at first syntax error, so the error listener will be called
+ parser.setErrorHandler(new DefaultErrorStrategy());
+ }
+
+ @Override
+ protected void addStage1ErrorListener(final UriParserParser parser) {
+ // Log error to console
+ parser.removeErrorListeners();
+ parser.addErrorListener(errorCollector1);
+ parser.addErrorListener(new DiagnosticErrorListener());
+ }
+
+ @Override
+ protected void addStage2ErrorListener(final UriParserParser parser) {
+ // Log error to console
+ parser.removeErrorListeners();
+ parser.addErrorListener(errorCollector2);
+ parser.addErrorListener(new DiagnosticErrorListener());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
new file mode 100644
index 0000000..143871a
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java
@@ -0,0 +1,599 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmElement;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfo;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriParameter;
+import org.apache.olingo.server.api.uri.UriResourceKind;
+import org.apache.olingo.server.api.uri.UriResourcePartTyped;
+import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectItem;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.UriResourceActionImpl;
+import org.apache.olingo.server.core.uri.UriResourceComplexPropertyImpl;
+import org.apache.olingo.server.core.uri.UriResourceEntitySetImpl;
+import org.apache.olingo.server.core.uri.UriResourceFunctionImpl;
+import org.apache.olingo.server.core.uri.UriResourceImpl;
+import org.apache.olingo.server.core.uri.UriResourceLambdaAllImpl;
+import org.apache.olingo.server.core.uri.UriResourceLambdaAnyImpl;
+import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl;
+import org.apache.olingo.server.core.uri.UriResourcePrimitivePropertyImpl;
+import org.apache.olingo.server.core.uri.UriResourceSingletonImpl;
+import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl;
+import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
+import org.apache.olingo.server.core.uri.validator.UriValidator;
+
+public class ResourceValidator implements TestValidator {
+ private Edm edm;
+ private TestValidator invokedBy;
+ private UriInfo uriInfo = null;
+
+ private UriResourceImpl uriPathInfo = null;
+ private int uriResourceIndex;
+
+ // --- Setup ---
+
+ public ResourceValidator setUpValidator(final TestValidator uriValidator) {
+ invokedBy = uriValidator;
+ return this;
+ }
+
+ public ResourceValidator setEdm(final Edm edm) {
+ this.edm = edm;
+ return this;
+ }
+
+ public ResourceValidator setUriInfoImplPath(final UriInfoImpl uriInfoPath) {
+ uriInfo = uriInfoPath;
+ last();
+ return this;
+ }
+
+ // --- Execution ---
+
+ public ResourceValidator run(final String uri) {
+ ParserWithLogging testParser = new ParserWithLogging();
+
+ UriInfoImpl uriInfoTmp = null;
+ uriPathInfo = null;
+ try {
+ uriInfoTmp = (UriInfoImpl) testParser.parseUri(uri, edm);
+
+ UriValidator uriValidator = new UriValidator();
+ uriValidator.validate(uriInfoTmp, "GET");
+ } catch (Exception e) {
+ fail("Exception occured while parsing the URI: " + uri + "\n"
+ + " Message: " + e.getMessage());
+ }
+
+ if (uriInfoTmp.getKind() != UriInfoKind.resource) {
+ fail("Invalid UriInfoKind: " + uriInfoTmp.getKind().toString());
+ }
+ uriInfo = uriInfoTmp;
+
+ first();
+ return this;
+ }
+
+ // --- Navigation ---
+
+ public TestUriValidator goUpUriValidator() {
+ return (TestUriValidator) invokedBy;
+ }
+
+ public ExpandValidator goUpExpandValidator() {
+ return (ExpandValidator) invokedBy;
+ }
+
+ public FilterValidator goUpFilterValidator() {
+ return (FilterValidator) invokedBy;
+ }
+
+ public FilterValidator goParameter(final int index) {
+ assertEquals(UriResourceKind.function, uriPathInfo.getKind());
+ UriResourceFunctionImpl function = (UriResourceFunctionImpl) uriPathInfo;
+
+ return new FilterValidator()
+ .setEdm(edm)
+ .setExpression(function.getParameters().get(index).getExression())
+ .setValidator(this);
+ }
+
+ public FilterValidator goLambdaExpression() {
+ if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
+ return new FilterValidator()
+ .setEdm(edm)
+ .setExpression(((UriResourceLambdaAllImpl) uriPathInfo).getExpression());
+
+ } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
+ return new FilterValidator()
+ .setEdm(edm)
+ .setExpression(((UriResourceLambdaAnyImpl) uriPathInfo).getExpression());
+ } else {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+ return null;
+ }
+
+ public ResourceValidator goSelectItem(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
+
+ return new ResourceValidator()
+ .setUpValidator(this)
+ .setEdm(edm)
+ .setUriInfoImplPath(uriInfo1);
+
+ }
+
+ public ExpandValidator goExpand() {
+ ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
+ if (expand == null) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ return new ExpandValidator().setUpValidator(this).setExpand(expand);
+ }
+
+ public ResourceValidator first() {
+ uriResourceIndex = 0;
+ uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(0);
+ return this;
+ }
+
+ public ResourceValidator last() {
+ uriResourceIndex = 0;
+
+ try {
+ uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1);
+ uriResourceIndex = uriInfo.getUriResourceParts().size() - 1;
+ } catch (IndexOutOfBoundsException ex) {
+ fail("not enough segments");
+ }
+
+ return this;
+ }
+
+ public ResourceValidator n() {
+ uriResourceIndex++;
+
+ try {
+ uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriResourceIndex);
+ } catch (IndexOutOfBoundsException ex) {
+ fail("not enough segments");
+ }
+
+ return this;
+ }
+
+ public ResourceValidator at(final int index) {
+ uriResourceIndex = index;
+ try {
+ uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(index);
+ } catch (IndexOutOfBoundsException ex) {
+ fail("not enough segments");
+ }
+ return this;
+ }
+
+ // --- Validation ---
+
+ public ResourceValidator isLambdaVar(final String var) {
+ String actualVar = null;
+ if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
+ actualVar = ((UriResourceLambdaAllImpl) uriPathInfo).getLambdaVariable();
+ } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
+ actualVar = ((UriResourceLambdaAnyImpl) uriPathInfo).getLamdaVariable();
+ } else {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ assertEquals(var, actualVar);
+ return this;
+ }
+
+ public ResourceValidator isTypeFilter(final FullQualifiedName expectedType) {
+
+ if (uriPathInfo.getKind() != UriResourceKind.complexProperty &&
+ uriPathInfo.getKind() != UriResourceKind.singleton) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ EdmType actualType = null;
+ if (uriPathInfo instanceof UriResourceComplexPropertyImpl) {
+ actualType = ((UriResourceComplexPropertyImpl) uriPathInfo).getComplexTypeFilter();
+ } else if (uriPathInfo instanceof UriResourceSingletonImpl) {
+ actualType = ((UriResourceSingletonImpl) uriPathInfo).getEntityTypeFilter();
+ }
+
+ if (actualType == null) {
+ fail("type information not set");
+ }
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+
+ assertEquals(expectedType.toString(), actualName.toString());
+ return this;
+ }
+
+ public ResourceValidator isType(final FullQualifiedName type) {
+ if (!(uriPathInfo instanceof UriResourcePartTyped)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+ UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo;
+
+ EdmType actualType = uriPathInfoTyped.getType();
+ if (actualType == null) {
+ fail("type information not set");
+ }
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+
+ assertEquals(type.toString(), actualName.toString());
+
+ return this;
+ }
+
+ public ResourceValidator isType(final FullQualifiedName type, final boolean isFinallyACollection) {
+ isType(type);
+ assertEquals(isFinallyACollection, ((UriResourcePartTyped) uriPathInfo).isCollection());
+ return this;
+ }
+
+ public ResourceValidator isTypeFilterOnEntry(final FullQualifiedName type) {
+ if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo;
+
+ // input parameter type may be null in order to assert that the singleTypeFilter is not set
+ EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnEntry();
+ if (type == null) {
+ assertEquals(type, actualType);
+ } else {
+ assertEquals(type.toString(), new FullQualifiedName(actualType.getNamespace(), actualType.getName()).toString());
+ }
+
+ return this;
+ }
+
+ public ResourceValidator isTypeFilterOnCollection(final FullQualifiedName expectedType) {
+ if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+ UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo;
+
+ // input parameter type may be null in order to assert that the collectionTypeFilter is not set
+ EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnCollection();
+ if (expectedType == null) {
+ assertEquals(expectedType, actualType);
+ } else {
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(expectedType.toString(), actualName.toString());
+ }
+
+ return this;
+ }
+
+ // other functions
+ public ResourceValidator checkCustomParameter(final int index, final String name, final String value) {
+ if (uriInfo == null) {
+ fail("hasQueryParameter: uriInfo == null");
+ }
+
+ List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
+ if (list.size() <= index) {
+ fail("not enough queryParameters");
+ }
+
+ CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
+ assertEquals(name, option.getName());
+ assertEquals(value, option.getText());
+ return this;
+ }
+
+ // TODO remove
+ /*
+ * public ResourceValidator isCollection(final boolean isCollection) {
+ * if (!(uriPathInfo instanceof UriResourcePartTyped)) {
+ * fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ * }
+ * UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo;
+ *
+ * EdmType type = uriPathInfoTyped.getType();
+ * if (type == null) {
+ * fail("isCollection: type == null");
+ * }
+ * assertEquals(isCollection, uriPathInfoTyped.isCollection());
+ * return this;
+ * }
+ */
+
+ public ResourceValidator isFilterString(final String expectedFilterTreeAsString) {
+
+ ExpressionImpl filterTree = (ExpressionImpl) uriInfo.getFilterOption().getExpression();
+ try {
+ String filterTreeAsString = filterTree.accept(new FilterTreeToText());
+ assertEquals(expectedFilterTreeAsString, filterTreeAsString);
+ } catch (ExpressionVisitException e) {
+ fail("isFilterString: Exception " + e.getMessage() + " occured");
+ } catch (ODataApplicationException e) {
+ fail("isFilterString: Exception " + e.getMessage() + " occured");
+ }
+
+ return this;
+ }
+
+ public ResourceValidator isKeyPredicateRef(final int index, final String name, final String refencedProperty) {
+ if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo;
+ List<UriParameter> keyPredicates = info.getKeyPredicates();
+ assertEquals(name, keyPredicates.get(index).getName());
+ assertEquals(refencedProperty, keyPredicates.get(index).getRefencedProperty());
+ return this;
+
+ }
+
+ public ResourceValidator isKeyPredicateAlias(final int index, final String name, final String alias) {
+ if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo;
+ List<UriParameter> keyPredicates = info.getKeyPredicates();
+ assertEquals(name, keyPredicates.get(index).getName());
+ assertEquals(alias, keyPredicates.get(index).getAlias());
+ return this;
+
+ }
+
+ public ResourceValidator isKeyPredicate(final int index, final String name, final String text) {
+ if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo;
+ List<UriParameter> keyPredicates = info.getKeyPredicates();
+ assertEquals(name, keyPredicates.get(index).getName());
+ assertEquals(text, keyPredicates.get(index).getText());
+ return this;
+
+ }
+
+ public ResourceValidator isParameter(final int index, final String name, final String text) {
+ if (!(uriPathInfo instanceof UriResourceFunctionImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo;
+ List<UriParameter> keyPredicates = info.getParameters();
+ assertEquals(name, keyPredicates.get(index).getName());
+ assertEquals(text, keyPredicates.get(index).getText());
+ return this;
+
+ }
+
+ public ResourceValidator isParameterAlias(final int index, final String name, final String alias) {
+ if (!(uriPathInfo instanceof UriResourceFunctionImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo;
+ List<UriParameter> keyPredicates = info.getParameters();
+ assertEquals(name, keyPredicates.get(index).getName());
+ assertEquals(alias, keyPredicates.get(index).getAlias());
+ return this;
+
+ }
+
+ public ResourceValidator isKind(final UriInfoKind kind) {
+ assertEquals(kind, uriInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isPrimitiveProperty(final String name,
+ final FullQualifiedName type, final boolean isCollection) {
+ if (!(uriPathInfo instanceof UriResourcePrimitivePropertyImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourcePrimitivePropertyImpl uriPathInfoProp = (UriResourcePrimitivePropertyImpl) uriPathInfo;
+
+ EdmElement property = uriPathInfoProp.getProperty();
+
+ assertEquals(name, property.getName());
+ assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
+ assertEquals(isCollection, property.isCollection());
+ return this;
+ }
+
+ public ResourceValidator
+ isComplexProperty(final String name, final FullQualifiedName type, final boolean isCollection) {
+ if (!(uriPathInfo instanceof UriResourceComplexPropertyImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceComplexPropertyImpl uriPathInfoProp = (UriResourceComplexPropertyImpl) uriPathInfo;
+
+ EdmElement property = uriPathInfoProp.getProperty();
+
+ assertEquals(name, property.getName());
+ assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
+ assertEquals(isCollection, property.isCollection());
+ return this;
+ }
+
+ public ResourceValidator isNavProperty(final String name, final FullQualifiedName type, final boolean isCollection) {
+ if (!(uriPathInfo instanceof UriResourceNavigationPropertyImpl)) {
+ fail("invalid resource kind: " + uriPathInfo.getKind().toString());
+ }
+
+ UriResourceNavigationPropertyImpl uriPathInfoProp = (UriResourceNavigationPropertyImpl) uriPathInfo;
+
+ EdmElement property = uriPathInfoProp.getProperty();
+
+ assertEquals(name, property.getName());
+ assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName()));
+ assertEquals(isCollection, uriPathInfoProp.isCollection());
+ return this;
+ }
+
+ public ResourceValidator isUriPathInfoKind(final UriResourceKind infoType) {
+ assertNotNull(uriPathInfo);
+ assertEquals(infoType, uriPathInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isAction(final String name) {
+ assertEquals(UriResourceKind.action, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceActionImpl) uriPathInfo).getAction().getName());
+ return this;
+ }
+
+ public ResourceValidator isFunction(final String name) {
+ assertEquals(UriResourceKind.function, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunction().getName());
+ return this;
+ }
+
+ public ResourceValidator isFunctionImport(final String name) {
+ assertEquals(UriResourceKind.function, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunctionImport().getName());
+ return this;
+ }
+
+ public ResourceValidator isEntitySet(final String name) {
+ assertEquals(UriResourceKind.entitySet, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceEntitySetImpl) uriPathInfo).getEntitySet().getName());
+ return this;
+ }
+
+ public ResourceValidator isComplex(final String name) {
+ assertEquals(UriResourceKind.complexProperty, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceComplexPropertyImpl) uriPathInfo).getProperty().getName());
+ return this;
+ }
+
+ public ResourceValidator isSingleton(final String name) {
+ assertEquals(UriResourceKind.singleton, uriPathInfo.getKind());
+ assertEquals(name, ((UriResourceSingletonImpl) uriPathInfo).getSingleton().getName());
+ return this;
+ }
+
+ public ResourceValidator isValue() {
+ assertEquals(UriResourceKind.value, uriPathInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isCount() {
+ assertEquals(UriResourceKind.count, uriPathInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isRef() {
+ assertEquals(UriResourceKind.ref, uriPathInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isActionImport(final String actionName) {
+ assertEquals(UriResourceKind.action, uriPathInfo.getKind());
+ assertEquals(actionName, ((UriResourceActionImpl) uriPathInfo).getActionImport().getName());
+ return this;
+ }
+
+ public ResourceValidator isIt() {
+ assertEquals(UriResourceKind.it, uriPathInfo.getKind());
+ return this;
+ }
+
+ public ResourceValidator isTopText(final String topText) {
+ assertEquals(topText, uriInfo.getTopOption().getText());
+ return this;
+ }
+
+ public ResourceValidator isFormatText(final String formatText) {
+ assertEquals(formatText, uriInfo.getFormatOption().getText());
+ return this;
+ }
+
+ public ResourceValidator isInlineCountText(final String inlineCountText) {
+ assertEquals(inlineCountText, uriInfo.getCountOption().getText());
+ return this;
+ }
+
+ public ResourceValidator isSkipText(final String skipText) {
+ assertEquals(skipText, uriInfo.getSkipOption().getText());
+ return this;
+ }
+
+ public ResourceValidator isSkipTokenText(final String skipTokenText) {
+ assertEquals(skipTokenText, uriInfo.getSkipTokenOption().getText());
+ return this;
+ }
+
+ public ResourceValidator isSelectItemStar(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(true, item.isStar());
+ return this;
+ }
+
+ public ResourceValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
+ return this;
+ }
+
+ public ResourceValidator isSelectStartType(final int index, final FullQualifiedName fullName) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+ SelectItem item = select.getSelectItems().get(index);
+
+ EdmType actualType = item.getStartTypeFilter();
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(fullName, actualName);
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java
new file mode 100644
index 0000000..0153036
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java
@@ -0,0 +1,105 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import java.util.BitSet;
+import java.util.Collections;
+import java.util.List;
+
+import org.antlr.v4.runtime.ANTLRErrorListener;
+import org.antlr.v4.runtime.Parser;
+import org.antlr.v4.runtime.RecognitionException;
+import org.antlr.v4.runtime.Recognizer;
+import org.antlr.v4.runtime.atn.ATNConfigSet;
+import org.antlr.v4.runtime.dfa.DFA;
+import org.apache.olingo.server.core.uri.antlr.UriLexer;
+
+class TestErrorLogger implements ANTLRErrorListener {
+
+ private String prefix;
+ private int logLevel = 0;
+
+ public TestErrorLogger(final String prefix, final int logLevel) {
+ this.prefix = prefix;
+ this.logLevel = logLevel;
+ }
+
+ @Override
+ public void syntaxError(final Recognizer<?, ?> recognizer, final Object offendingSymbol, final int line,
+ final int charPositionInLine,
+ final String msg, final RecognitionException e) {
+
+ if (logLevel > 0) {
+ System.out.println("\n" + prefix + " -- SyntaxError");
+ trace(recognizer, offendingSymbol, line, charPositionInLine, msg, e);
+ }
+
+ }
+
+ @Override
+ public void reportAmbiguity(final Parser recognizer, final DFA dfa, final int startIndex, final int stopIndex,
+ final boolean exact,
+ final BitSet ambigAlts, final ATNConfigSet configs) {
+
+ }
+
+ @Override
+ public void reportAttemptingFullContext(final Parser recognizer, final DFA dfa, final int startIndex,
+ final int stopIndex,
+ final BitSet conflictingAlts, final ATNConfigSet configs) {
+
+ }
+
+ @Override
+ public void reportContextSensitivity(final Parser recognizer, final DFA dfa, final int startIndex,
+ final int stopIndex, final int prediction,
+ final ATNConfigSet configs) {
+
+ }
+
+ private void printStack(final Recognizer<?, ?> recognizer) {
+ List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
+ Collections.reverse(stack);
+ System.out.println(" rule stack: " + stack);
+ }
+
+ public void trace(final Recognizer<?, ?> recognizer, final Object offendingSymbol,
+ final int line, final int charPositionInLine, final String msg, final RecognitionException e) {
+
+ System.out.println("Error message: " + msg);
+
+ printStack(recognizer);
+
+ System.out.println(" line/char :" + line + " / " + charPositionInLine);
+ System.out.println(" sym :" + offendingSymbol);
+ if (e != null && e.getOffendingToken() != null) {
+
+ String lexerTokenName = "";
+ try {
+ lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
+ } catch (ArrayIndexOutOfBoundsException es) {
+ lexerTokenName = "token error";
+ }
+
+ System.out.println(" tokenname:" + lexerTokenName);
+ }
+
+ }
+
+}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
new file mode 100644
index 0000000..35687f6
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java
@@ -0,0 +1,258 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.fail;
+
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
+import org.apache.olingo.server.api.uri.queryoption.SelectItem;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+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.queryoption.CustomQueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
+import org.apache.olingo.server.core.uri.validator.UriValidator;
+
+public class TestUriValidator implements TestValidator {
+ private Edm edm;
+
+ private UriInfoImpl uriInfo;
+ private Exception exception;
+
+ // Setup
+ public TestUriValidator setEdm(final Edm edm) {
+ this.edm = edm;
+ return this;
+ }
+
+ // Execution
+ public TestUriValidator run(final String uri) {
+ Parser parser = new Parser();
+ UriValidator validator = new UriValidator();
+
+ uriInfo = null;
+ try {
+ uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+ validator.validate(uriInfo, "GET");
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+
+ return this;
+ }
+
+ public TestUriValidator runEx(final String uri) {
+ Parser parser = new Parser();
+ uriInfo = null;
+ try {
+ uriInfo = (UriInfoImpl) parser.parseUri(uri, edm);
+ fail("Exception expected");
+ } catch (UriParserException e) {
+ exception = e;
+ }
+
+ return this;
+ }
+
+ public TestUriValidator log(final String uri) {
+ ParserWithLogging parserTest = new ParserWithLogging();
+ parserTest.setLogLevel(1);
+ uriInfo = null;
+ try {
+ // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
+ uriInfo = (UriInfoImpl) parserTest.parseUri(uri, edm);
+ } catch (UriParserException e) {
+ fail("Exception occured while parsing the URI: " + uri + "\n"
+ + " Exception: " + e.getMessage());
+ }
+
+ return this;
+ }
+
+ // Navigation
+ public ResourceValidator goPath() {
+ if (uriInfo.getKind() != UriInfoKind.resource) {
+ fail("invalid resource kind: " + uriInfo.getKind().toString());
+ }
+
+ return new ResourceValidator()
+ .setUpValidator(this)
+ .setEdm(edm)
+ .setUriInfoImplPath(uriInfo);
+ }
+
+ public FilterValidator goFilter() {
+ FilterOptionImpl filter = (FilterOptionImpl) uriInfo.getFilterOption();
+ if (filter == null) {
+ fail("no filter found");
+ }
+ return new FilterValidator().setUriValidator(this).setFilter(filter);
+
+ }
+
+ public ExpandValidator goExpand() {
+ ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption();
+ if (expand == null) {
+ fail("invalid resource kind: " + uriInfo.getKind().toString());
+ }
+
+ return new ExpandValidator().setUpValidator(this).setExpand(expand);
+ }
+
+ public ResourceValidator goSelectItemPath(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath();
+
+ return new ResourceValidator()
+ .setUpValidator(this)
+ .setEdm(edm)
+ .setUriInfoImplPath(uriInfo1);
+
+ }
+
+ public TestUriValidator isSelectStartType(final int index, final FullQualifiedName fullName) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+ SelectItem item = select.getSelectItems().get(index);
+ EdmType actualType = item.getStartTypeFilter();
+
+ FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName());
+ assertEquals(fullName, actualName);
+ return this;
+
+ }
+
+ // Validation
+ public TestUriValidator isKind(final UriInfoKind kind) {
+ assertEquals(kind, uriInfo.getKind());
+ return this;
+ }
+
+ public TestUriValidator isCustomParameter(final int index, final String name, final String value) {
+ if (uriInfo == null) {
+ fail("hasQueryParameter: uriInfo == null");
+ }
+
+ List<CustomQueryOption> list = uriInfo.getCustomQueryOptions();
+ if (list.size() <= index) {
+ fail("not enought queryParameters");
+ }
+
+ CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index);
+ assertEquals(name, option.getName());
+ assertEquals(value, option.getText());
+ return this;
+ }
+
+ public void isCrossJoinEntityList(final List<String> entitySets) {
+ if (uriInfo.getKind() != UriInfoKind.crossjoin) {
+ fail("invalid resource kind: " + uriInfo.getKind().toString());
+ }
+
+ int i = 0;
+ for (String entitySet : entitySets) {
+ assertEquals(entitySet, uriInfo.getEntitySetNames().get(i));
+ i++;
+ }
+
+ }
+
+ public TestUriValidator isExSyntax(final long errorID) {
+ assertEquals(UriParserSyntaxException.class, exception.getClass());
+ return this;
+ }
+
+ public TestUriValidator isExSemantic(final long errorID) {
+ assertEquals(UriParserSemanticException.class, exception.getClass());
+ return this;
+ }
+
+ public TestUriValidator isIdText(final String text) {
+ assertEquals(text, uriInfo.getIdOption().getText());
+ return this;
+ }
+
+ public TestUriValidator isExpandText(final String text) {
+ assertEquals(text, uriInfo.getExpandOption().getText());
+ return this;
+ }
+
+ public TestUriValidator isSelectText(final String text) {
+ assertEquals(text, uriInfo.getSelectOption().getText());
+ return this;
+ }
+
+ public TestUriValidator isFormatText(final String text) {
+ assertEquals(text, uriInfo.getFormatOption().getText());
+ return this;
+ }
+
+ public TestUriValidator isFragmentText(final String text) {
+ if (uriInfo.getKind() != UriInfoKind.metadata) {
+ fail("invalid resource kind: " + uriInfo.getKind().toString());
+ }
+
+ assertEquals(text, uriInfo.getFragment());
+
+ return this;
+ }
+
+ public TestUriValidator isEntityType(final FullQualifiedName fullName) {
+ if (uriInfo.getKind() != UriInfoKind.entityId) {
+ fail("invalid resource kind: " + uriInfo.getKind().toString());
+ }
+
+ assertEquals(fullName.toString(), fullName(uriInfo.getEntityTypeCast()));
+ return this;
+ }
+
+ private String fullName(final EdmEntityType type) {
+ return type.getNamespace() + "." + type.getName();
+ }
+
+ public TestUriValidator isSelectItemStar(final int index) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(true, item.isStar());
+ return this;
+ }
+
+ public TestUriValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) {
+ SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
+
+ SelectItem item = select.getSelectItems().get(index);
+ assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
+ return this;
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
new file mode 100644
index 0000000..7e64f86
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java
@@ -0,0 +1,23 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+public interface TestValidator {
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java
new file mode 100644
index 0000000..4a94bb3
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java
@@ -0,0 +1,194 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.List;
+
+import org.antlr.v4.runtime.ANTLRInputStream;
+import org.antlr.v4.runtime.Token;
+import org.apache.olingo.server.core.uri.antlr.UriLexer;
+
+//TODO extend to test also exception which can occure while paring
+public class TokenValidator {
+
+ private String input = null;
+
+ private List<? extends Token> tokens = null;
+ private Token curToken = null;
+ private Exception curException = null;
+
+ private int startMode;
+ private int logLevel = 0;
+
+ // --- Setup ---
+
+ public TokenValidator log(final int logLevel) {
+ this.logLevel = logLevel;
+ return this;
+ }
+
+ // --- Execution ---
+
+ public TokenValidator run(final String uri) {
+ input = uri;
+
+ tokens = parseInput(uri);
+ if (logLevel > 0) {
+ showTokens();
+ }
+
+ first();
+ exFirst();
+ logLevel = 0;
+
+ return this;
+ }
+
+ // --- Navigation ---
+
+ // navigate within the tokenlist
+ public TokenValidator first() {
+ try {
+ curToken = tokens.get(0);
+ } catch (IndexOutOfBoundsException ex) {
+ curToken = null;
+ }
+ return this;
+ }
+
+ public TokenValidator last() {
+ curToken = tokens.get(tokens.size() - 1);
+ return this;
+ }
+
+ public TokenValidator at(final int index) {
+ try {
+ curToken = tokens.get(index);
+ } catch (IndexOutOfBoundsException ex) {
+ curToken = null;
+ }
+ return this;
+ }
+
+ public TokenValidator exLast() {
+ // curException = exceptions.get(exceptions.size() - 1);
+ return this;
+ }
+
+ // navigate within the exception list
+ public TokenValidator exFirst() {
+ try {
+ // curException = exceptions.get(0);
+ } catch (IndexOutOfBoundsException ex) {
+ curException = null;
+ }
+ return this;
+
+ }
+
+ public TokenValidator exAt(final int index) {
+ try {
+ // curException = exceptions.get(index);
+ } catch (IndexOutOfBoundsException ex) {
+ curException = null;
+ }
+ return this;
+ }
+
+ // --- Validation ---
+
+ public TokenValidator isText(final String expected) {
+ assertEquals(expected, curToken.getText());
+ return this;
+ }
+
+ public TokenValidator isAllText(final String expected) {
+ String actual = "";
+
+ for (Token curToken : tokens) {
+ actual += curToken.getText();
+ }
+ assertEquals(expected, actual);
+ return this;
+ }
+
+ public TokenValidator isAllInput() {
+ String actual = "";
+
+ for (Token curToken : tokens) {
+ actual += curToken.getText();
+ }
+ assertEquals(input, actual);
+ return this;
+ }
+
+ public TokenValidator isInput() {
+ assertEquals(input, curToken.getText());
+ return this;
+ }
+
+ public TokenValidator isType(final int expected) {
+ assertEquals(UriLexer.tokenNames[expected], UriLexer.tokenNames[curToken.getType()]);
+ return this;
+ }
+
+ public TokenValidator isExType(final Class<?> exClass) {
+ assertEquals(exClass, curException.getClass());
+ return this;
+ }
+
+ public void globalMode(final int mode) {
+ startMode = mode;
+ }
+
+ // --- Helper ---
+
+ private List<? extends Token> parseInput(final String input) {
+ ANTLRInputStream inputStream = new ANTLRInputStream(input);
+
+ UriLexer lexer = new UriLexerWithTrace(inputStream, logLevel, startMode);
+ // lexer.addErrorListener(new ErrorCollector(this));
+ return lexer.getAllTokens();
+ }
+
+ public TokenValidator showTokens() {
+ boolean first = true;
+ System.out.println("input: " + input);
+ String nL = "\n";
+ String out = "[" + nL;
+ for (Token token : tokens) {
+ if (!first) {
+ out += ",";
+ first = false;
+ }
+ int index = token.getType();
+ if (index != -1) {
+ out += "\"" + token.getText() + "\"" + " " + UriLexer.tokenNames[index] + nL;
+ } else {
+ out += "\"" + token.getText() + "\"" + " " + index + nL;
+ }
+ }
+ out += ']';
+ System.out.println("tokens: " + out);
+ return this;
+ }
+
+}
[3/5] [OLINGO-266] server-test module introduced
Posted by sk...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java
new file mode 100644
index 0000000..e8aa9ce
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java
@@ -0,0 +1,248 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.antlr;
+
+import org.antlr.v4.runtime.Lexer;
+import org.apache.olingo.server.core.uri.testutil.TokenValidator;
+import org.junit.Test;
+
+public class TestLexer {
+
+ private TokenValidator test = null;
+
+ private static final String cPCT_ENCODED = "%45%46%47" + "%22" + "%5C";// last two chars are not in
+ // cPCT_ENCODED_UNESCAPED
+ private static final String cUNRESERVED = "ABCabc123-._~";
+ private static final String cOTHER_DELIMS = "!()*+,;";
+ private static final String cSUB_DELIMS = "$&'=" + cOTHER_DELIMS;
+
+ private static final String cPCHAR = cUNRESERVED + cPCT_ENCODED + cSUB_DELIMS + ":@";
+
+ public TestLexer() {
+ test = new TokenValidator();
+ }
+
+ @Test
+ public void test() {
+
+ // test.log(1).run("ESAllPrim?$orderby=PropertyDouble eq 3.5E+38");
+ }
+
+ // ;------------------------------------------------------------------------------
+ // ; 0. URI
+ // ;------------------------------------------------------------------------------
+
+ @Test
+ public void testUriTokens() {
+ test.globalMode(UriLexer.MODE_QUERY);
+ test.run("#").isText("#").isType(UriLexer.FRAGMENT);
+ test.run("$count").isText("$count").isType(UriLexer.COUNT);
+ test.run("$ref").isText("$ref").isType(UriLexer.REF);
+ test.run("$value").isText("$value").isType(UriLexer.VALUE);
+ }
+
+ // ;------------------------------------------------------------------------------
+ // ; 2. Query Options
+ // ;------------------------------------------------------------------------------
+ @Test
+ public void testQueryOptionsTokens() {
+
+ test.globalMode(UriLexer.MODE_QUERY);
+ test.run("$skip=1").isAllText("$skip=1").isType(UriLexer.SKIP);
+ test.run("$skip=2").isAllText("$skip=2").isType(UriLexer.SKIP);
+ test.run("$skip=123").isAllText("$skip=123").isType(UriLexer.SKIP);
+
+ test.run("$top=1").isAllText("$top=1").isType(UriLexer.TOP);
+ test.run("$top=2").isAllText("$top=2").isType(UriLexer.TOP);
+ test.run("$top=123").isAllText("$top=123").isType(UriLexer.TOP);
+
+ test.run("$levels=1").isAllText("$levels=1").isType(UriLexer.LEVELS);
+ test.run("$levels=2").isAllText("$levels=2").isType(UriLexer.LEVELS);
+ test.run("$levels=123").isAllText("$levels=123").isType(UriLexer.LEVELS);
+ test.run("$levels=max").isAllText("$levels=max").isType(UriLexer.LEVELS);
+
+ test.run("$format=atom").isAllText("$format=atom").isType(UriLexer.FORMAT);
+ test.run("$format=json").isAllText("$format=json").isType(UriLexer.FORMAT);
+ test.run("$format=xml").isAllText("$format=xml").isType(UriLexer.FORMAT);
+ test.run("$format=abc/def").isAllText("$format=abc/def").isType(UriLexer.FORMAT);
+
+ test.run("$id=123").isAllText("$id=123").isType(UriLexer.ID);
+ test.run("$id=ABC").isAllText("$id=ABC").isType(UriLexer.ID);
+
+ test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
+ test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN);
+
+ test.run("$search=\"ABC\"").isAllText("$search=\"ABC\"").isType(UriLexer.SEARCH);
+ test.run("$search=ABC").isAllText("$search=ABC").isType(UriLexer.SEARCH);
+ test.run("$search=\"A%20B%20C\"").isAllText("$search=\"A%20B%20C\"").isType(UriLexer.SEARCH);
+ }
+
+ // ;------------------------------------------------------------------------------
+ // ; 4. Expressions
+ // ;------------------------------------------------------------------------------
+ @Test
+ public void testQueryExpressions() {
+ test.globalMode(Lexer.DEFAULT_MODE);
+
+ test.run("$it").isText("$it").isType(UriLexer.IT);
+
+ test.run("$filter=contains(").at(2).isText("contains(").isType(UriLexer.CONTAINS_WORD);
+
+ test.run("$filter=containsabc").at(2).isText("containsabc")
+ .isType(UriLexer.ODATAIDENTIFIER); // test that this is a ODI
+
+ test.run("$filter=startswith(").at(2).isText("startswith(").isType(UriLexer.STARTSWITH_WORD);
+ test.run("$filter=endswith(").at(2).isText("endswith(").isType(UriLexer.ENDSWITH_WORD);
+ test.run("$filter=length(").at(2).isText("length(").isType(UriLexer.LENGTH_WORD);
+ test.run("$filter=indexof(").at(2).isText("indexof(").isType(UriLexer.INDEXOF_WORD);
+ test.run("$filter=substring(").at(2).isText("substring(").isType(UriLexer.SUBSTRING_WORD);
+ test.run("$filter=tolower(").at(2).isText("tolower(").isType(UriLexer.TOLOWER_WORD);
+ test.run("$filter=toupper(").at(2).isText("toupper(").isType(UriLexer.TOUPPER_WORD);
+ test.run("$filter=trim(").at(2).isText("trim(").isType(UriLexer.TRIM_WORD);
+ test.run("$filter=concat(").at(2).isText("concat(").isType(UriLexer.CONCAT_WORD);
+
+ }
+
+ // ;------------------------------------------------------------------------------
+ // ; 7. Literal Data Values
+ // ;------------------------------------------------------------------------------
+
+ @Test
+ public void testLiteralDataValues() {
+ test.globalMode(Lexer.DEFAULT_MODE);
+ // null
+ test.run("null").isInput().isType(UriLexer.NULLVALUE);
+
+ // binary
+ test.run("binary'ABCD'").isInput().isType(UriLexer.BINARY);
+ test.run("BiNaRy'ABCD'").isInput().isType(UriLexer.BINARY);
+
+ // boolean
+ test.run("true").isInput().isType(UriLexer.TRUE);
+ test.run("false").isInput().isType(UriLexer.FALSE);
+ test.run("TrUe").isInput().isType(UriLexer.BOOLEAN);
+ test.run("FaLsE").isInput().isType(UriLexer.BOOLEAN);
+
+ // Lexer rule INT
+ test.run("123").isInput().isType(UriLexer.INT);
+ test.run("123456789").isInput().isType(UriLexer.INT);
+ test.run("+123").isInput().isType(UriLexer.INT);
+ test.run("+123456789").isInput().isType(UriLexer.INT);
+ test.run("-123").isInput().isType(UriLexer.INT);
+ test.run("-123456789").isInput().isType(UriLexer.INT);
+
+ // Lexer rule DECIMAL
+ test.run("0.1").isInput().isType(UriLexer.DECIMAL);
+ test.run("1.1").isInput().isType(UriLexer.DECIMAL);
+ test.run("+0.1").isInput().isType(UriLexer.DECIMAL);
+ test.run("+1.1").isInput().isType(UriLexer.DECIMAL);
+ test.run("-0.1").isInput().isType(UriLexer.DECIMAL);
+ test.run("-1.1").isInput().isType(UriLexer.DECIMAL);
+
+ // Lexer rule EXP
+ test.run("1.1e+1").isInput().isType(UriLexer.DECIMAL);
+ test.run("1.1e-1").isInput().isType(UriLexer.DECIMAL);
+
+ test.run("NaN").isInput().isType(UriLexer.NANINFINITY);
+ test.run("-INF").isInput().isType(UriLexer.NANINFINITY);
+ test.run("INF").isInput().isType(UriLexer.NANINFINITY);
+
+ // Lexer rule GUID
+ test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID);
+ test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID);
+
+ // Lexer rule DATE
+ test.run("2013-11-15").isInput().isType(UriLexer.DATE);
+
+ // Lexer rule DATETIMEOFFSET
+ test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET);
+ test.run("2013-11-15T13:35:10Z").isInput().isType(UriLexer.DATETIMEOFFSET);
+ test.run("2013-11-15T13:35:10.1234Z").isInput().isType(UriLexer.DATETIMEOFFSET);
+
+ test.run("2013-11-15T13:35:10.1234+01:30").isInput().isType(UriLexer.DATETIMEOFFSET);
+ test.run("2013-11-15T13:35:10.1234-01:12").isInput().isType(UriLexer.DATETIMEOFFSET);
+
+ test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET);
+
+ // Lexer rule DURATION
+ test.run("duration'PT67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT67.89S'").isInput().isType(UriLexer.DURATION);
+
+ test.run("duration'PT5M'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT5M67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT5M67.89S'").isInput().isType(UriLexer.DURATION);
+
+ test.run("duration'PT4H'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT4H67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT4H67.89S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT4H5M'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT4H5M67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'PT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
+
+ test.run("duration'P3D'");
+ test.run("duration'P3DT67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT67.89S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT5M'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT5M67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT5M67.89S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H67.89S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H5M'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H5M67S'").isInput().isType(UriLexer.DURATION);
+ test.run("duration'P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
+
+ test.run("DuRaTiOn'P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
+ test.run("DuRaTiOn'-P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION);
+
+ test.run("20:00").isInput().isType(UriLexer.TIMEOFDAY);
+ test.run("20:15:01").isInput().isType(UriLexer.TIMEOFDAY);
+ test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY);
+
+ test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY);
+
+ // String
+ test.run("'ABC'").isText("'ABC'").isType(UriLexer.STRING);
+ test.run("'A%20C'").isInput().isType(UriLexer.STRING);
+ test.run("'%20%20%20ABC'").isInput().isType(UriLexer.STRING);
+
+ }
+
+ @Test
+ public void testDelims() {
+ String reserved = "/";
+ test.globalMode(UriLexer.MODE_QUERY);
+ // Test lexer rule UNRESERVED
+ test.run("$format=A/" + cUNRESERVED).isAllInput().isType(UriLexer.FORMAT);
+ test.run("$format=A/" + cUNRESERVED + reserved).isType(UriLexer.FORMAT).at(4).isText(cUNRESERVED);
+ // Test lexer rule PCT_ENCODED
+ test.run("$format=A/" + cPCT_ENCODED).isAllInput().isType(UriLexer.FORMAT);
+ test.run("$format=A/" + cPCT_ENCODED + reserved).isType(UriLexer.FORMAT).at(4).isText(cPCT_ENCODED);
+ // Test lexer rule SUB_DELIMS
+ test.run("$format=A/" + cSUB_DELIMS).isAllInput().isType(UriLexer.FORMAT);
+ test.run("$format=A/" + cSUB_DELIMS + reserved).isType(UriLexer.FORMAT).at(4).isText("$");
+ // Test lexer rule PCHAR rest
+ test.run("$format=A/:@").isAllText("$format=A/:@").isType(UriLexer.FORMAT);
+ test.run("$format=A/:@" + reserved).isType(UriLexer.FORMAT).at(4).isText(":@");
+ // Test lexer rule PCHAR all
+ test.run("$format=" + cPCHAR + "/" + cPCHAR).isAllInput().isType(UriLexer.FORMAT);
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
new file mode 100644
index 0000000..f928ad2
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java
@@ -0,0 +1,1144 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.antlr;
+
+import java.io.UnsupportedEncodingException;
+import java.net.URLEncoder;
+import java.util.Arrays;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriResourceKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.apache.olingo.server.core.uri.testutil.FilterValidator;
+import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
+import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
+import org.junit.Test;
+
+public class TestUriParserImpl {
+ Edm edm = null;
+ private final String PropertyBoolean = "PropertyBoolean=true";
+ private final String PropertyByte = "PropertyByte=1";
+
+ 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 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 allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte
+ + "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate
+ + "," + PropertyDateTimeOffset + "," + PropertyDuration + "," + PropertyGuid + "," + PropertyTimeOfDay;
+
+ TestUriValidator testUri = null;
+ ResourceValidator testRes = null;
+ FilterValidator testFilter = null;
+
+ public TestUriParserImpl() {
+ edm = new EdmProviderImpl(new EdmTechTestProvider());
+ testUri = new TestUriValidator().setEdm(edm);
+ testRes = new ResourceValidator().setEdm(edm);
+ testFilter = new FilterValidator().setEdm(edm);
+ }
+
+ @Test
+ public void test() throws UriParserException, UnsupportedEncodingException {
+
+ }
+
+ @Test
+ public void testBoundFunctionImport_VarParameters() {
+
+ // no input
+ testRes.run("ESKeyNav(1)/com.sap.odata.test1.BFCETKeyNavRTETKeyNav()")
+ .at(0).isUriPathInfoKind(UriResourceKind.entitySet)
+ .at(1).isUriPathInfoKind(UriResourceKind.function);
+
+ // one input
+ testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')")
+ .at(0).isUriPathInfoKind(UriResourceKind.entitySet)
+ .at(1).isUriPathInfoKind(UriResourceKind.function)
+ .isParameter(0, "ParameterString", "'ABC'");
+
+ // two input
+ testRes.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isParameter(0, "ParameterInt16", "1")
+ .isParameter(1, "ParameterString", "'2'");
+ }
+
+ @Test
+ public void testFunctionBound_varReturnType() {
+
+ String esTwoKeyNav = "ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')";
+
+ // returning primitive
+ testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(PropertyProvider.nameString, false);
+
+ // returning collection of primitive
+ testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(PropertyProvider.nameString, true);
+
+ // returning single complex
+ testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(ComplexTypeProvider.nameCTTwoPrim, false);
+
+ // returning collection of complex
+ testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true);
+
+ // returning single entity
+ testRes.run(
+ esTwoKeyNav + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false);
+
+ // returning collection of entity (aka entitySet)
+ testRes.run(esTwoKeyNav + "/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true);
+ }
+
+ @Test
+ public void runActionImport_VarReturnType() {
+
+ testRes.run("AIRTPrimParam").isKind(UriInfoKind.resource)
+ .first()
+ .isActionImport("AIRTPrimParam")
+ .isAction("UARTPrimParam")
+ .isType(PropertyProvider.nameString, false);
+
+ testRes.run("AIRTPrimCollParam").isKind(UriInfoKind.resource)
+ .first()
+ .isActionImport("AIRTPrimCollParam")
+ .isAction("UARTPrimCollParam")
+ .isType(PropertyProvider.nameString, true);
+
+ testRes.run("AIRTCompParam").isKind(UriInfoKind.resource)
+ .first()
+ .isActionImport("AIRTCompParam")
+ .isAction("UARTCompParam")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, false);
+
+ testRes.run("AIRTCompCollParam").isKind(UriInfoKind.resource)
+ .first()
+ .isActionImport("AIRTCompCollParam")
+ .isAction("UARTCompCollParam")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true);
+
+ testRes.run("AIRTETParam").isKind(UriInfoKind.resource)
+ .first()
+ .isActionImport("AIRTETParam")
+ .isAction("UARTETParam")
+ .isType(EntityTypeProvider.nameETTwoKeyTwoPrim, false);
+
+ testUri.runEx("AIRTPrimParam/invalidElement").isExSemantic(0);
+ }
+
+ @Test
+ public void runCount() {
+
+ // count entity set
+ testRes.run("ESAllPrim/$count")
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETAllPrim, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.count);
+
+ // count on collection of complex
+ testRes.run("ESKeyNav(1)/CollPropertyComplex/$count")
+ .at(0)
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .at(1)
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .at(2)
+ .isUriPathInfoKind(UriResourceKind.count);
+
+ // count on collection of primitive
+ testRes.run("ESCollAllPrim(1)/CollPropertyString/$count")
+ .at(1)
+ .isType(PropertyProvider.nameString, true)
+ .at(2)
+ .isUriPathInfoKind(UriResourceKind.count);
+ }
+
+ @Test
+ public void runCrossJoin() {
+ testUri.run("$crossjoin(ESAllKey)")
+ .isKind(UriInfoKind.crossjoin)
+ .isCrossJoinEntityList(Arrays.asList("ESAllKey"));
+
+ testUri.run("$crossjoin(ESAllKey,ESTwoPrim)")
+ .isKind(UriInfoKind.crossjoin)
+ .isCrossJoinEntityList(Arrays.asList("ESAllKey", "ESTwoPrim"));
+ }
+
+ @Test(expected = Exception.class)
+ public void testEntityFailOnValidation1() {
+ // simple entity set; with qualifiedentityTypeName; with filter
+ testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$filter=PropertyInt16 eq 123&$id=ESAllKey")
+ .isIdText("ESAllKey")
+ .goFilter().is("<<PropertyInt16> eq <123>>");
+ }
+
+ @Test(expected = Exception.class)
+ public void testEntityFailOnValidation2() {
+ // simple entity set; with qualifiedentityTypeName; with 2xformat(before and after), expand, filter
+ testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?"
+ + "$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 123&$format=atom&$select=*")
+ .isFormatText("atom")
+ .isCustomParameter(0, "abc", "123")
+ .isIdText("ESBase")
+ .isCustomParameter(1, "xyz", "987")
+ .isSelectItemStar(0);
+ }
+
+ @Test
+ public void testEntity() {
+
+ // simple entity set
+ testUri.run("$entity?$id=ESAllPrim").isKind(UriInfoKind.entityId)
+ .isKind(UriInfoKind.entityId)
+ .isIdText("ESAllPrim");
+
+ // simple entity set; $format before $id
+ testUri.run("$entity?$format=xml&$id=ETAllPrim").isKind(UriInfoKind.entityId)
+ .isFormatText("xml")
+ .isIdText("ETAllPrim");
+
+ testUri.run("$entity?$format=xml&abc=123&$id=ESAllKey").isKind(UriInfoKind.entityId)
+ .isFormatText("xml")
+ .isCustomParameter(0, "abc", "123")
+ .isIdText("ESAllKey");
+
+ // simple entity set; $format after $id
+ testUri.run("$entity?$id=ETAllPrim&$format=xml").isKind(UriInfoKind.entityId)
+ .isIdText("ETAllPrim")
+ .isFormatText("xml");
+
+ // simple entity set; $format and custom parameter after $id
+ testUri.run("$entity?$id=ETAllPrim&$format=xml&abc=123").isKind(UriInfoKind.entityId)
+ .isIdText("ETAllPrim")
+ .isFormatText("xml")
+ .isCustomParameter(0, "abc", "123");
+
+ // simple entity set; $format before $id and custom parameter after $id
+ testUri.run("$entity?$format=xml&$id=ETAllPrim&abc=123").isKind(UriInfoKind.entityId)
+ .isFormatText("xml")
+ .isIdText("ETAllPrim")
+ .isCustomParameter(0, "abc", "123");
+
+ // simple entity set; with qualifiedentityTypeName
+ testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$id=ESBase")
+ .isEntityType(EntityTypeProvider.nameETTwoPrim)
+ .isIdText("ESBase");
+
+ // simple entity set; with qualifiedentityTypeName;
+ testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim")
+ .isEntityType(EntityTypeProvider.nameETBase)
+ .isKind(UriInfoKind.entityId)
+ .isIdText("ESTwoPrim");
+
+ // simple entity set; with qualifiedentityTypeName; with format
+ testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$format=atom")
+ .isKind(UriInfoKind.entityId)
+ .isEntityType(EntityTypeProvider.nameETBase)
+ .isIdText("ESTwoPrim")
+ .isFormatText("atom");
+
+ // simple entity set; with qualifiedentityTypeName; with select
+ testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$select=*")
+ .isKind(UriInfoKind.entityId)
+ .isEntityType(EntityTypeProvider.nameETBase)
+ .isIdText("ESTwoPrim")
+ .isSelectItemStar(0);
+
+ // simple entity set; with qualifiedentityTypeName; with expand
+ testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$expand=*")
+ .isKind(UriInfoKind.entityId)
+ .isEntityType(EntityTypeProvider.nameETBase)
+ .isIdText("ESTwoPrim")
+ .isExpandText("*")
+ .goExpand().first().isSegmentStar(0);
+
+ }
+
+ @Test
+ public void testEntitySet() throws UnsupportedEncodingException {
+
+ // plain entity set
+ testRes.run("ESAllPrim")
+ .isEntitySet("ESAllPrim")
+ .isType(EntityTypeProvider.nameETAllPrim);
+
+ // with one key; simple key notation
+ testRes.run("ESAllPrim(1)")
+ .isEntitySet("ESAllPrim")
+ .isType(EntityTypeProvider.nameETAllPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // with one key; name value key notation
+ testRes.run("ESAllPrim(PropertyInt16=1)")
+ .isEntitySet("ESAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // with two keys
+ testRes.run("ESTwoKeyTwoPrim(PropertyInt16=1, PropertyString='ABC')")
+ .isEntitySet("ESTwoKeyTwoPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'ABC'");
+
+ // with all keys
+ testRes.run("ESAllKey(" + encode(allKeys) + ")")
+ .isEntitySet("ESAllKey")
+ .isKeyPredicate(0, "PropertyString", "'ABC'")
+ .isKeyPredicate(1, "PropertyInt16", "1")
+ .isKeyPredicate(2, "PropertyBoolean", "true")
+ .isKeyPredicate(3, "PropertyByte", "1")
+ .isKeyPredicate(4, "PropertySByte", "1")
+ .isKeyPredicate(5, "PropertyInt32", "12")
+ .isKeyPredicate(6, "PropertyInt64", "64")
+ .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(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
+ .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
+ }
+
+ @Test
+ public void testEntitySet_NavigationPropperty() {
+
+ // plain entity set ...
+
+ // with navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // with navigation property -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/PropertyString")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(2)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property -> navigation property -> navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .at(2)
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .isType(EntityTypeProvider.nameETKeyNav);
+
+ // with navigation property(key)
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // with navigation property(key) -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/PropertyString").at(0)
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(2)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property(key) -> navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavOne")
+ .isEntitySet("ESKeyNav")
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(2)
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false);
+
+ // with navigation property(key) -> navigation property(key)
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavMany(1)")
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(2)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // with navigation property(key) -> navigation property -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavOne/PropertyString")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(2)
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .at(3)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property(key) -> navigation property(key) -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavMany(1)/PropertyString")
+ .at(0)
+ .isEntitySet("ESKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav)
+ .at(1)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(2)
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(3)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ }
+
+ @Test
+ public void testEntitySet_Property() {
+
+ // plain entity set ...
+
+ // with property
+ testRes.run("ESAllPrim(1)/PropertyString")
+ .at(0)
+ .isEntitySet("ESAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with complex property
+ testRes.run("ESCompAllPrim(1)/PropertyComplex")
+ .at(0)
+ .isEntitySet("ESCompAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false);
+
+ // with two properties
+ testRes.run("ESCompAllPrim(1)/PropertyComplex/PropertyString")
+ .at(0)
+ .isEntitySet("ESCompAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false)
+ .at(2)
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+ }
+
+ @Test
+ public void testEntitySet_TypeFilter() {
+
+ // filter
+ testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase")
+ .at(0)
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim, true)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase)
+ .isTypeFilterOnEntry(null);
+
+ // filter before key predicate
+ testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)")
+ .at(0)
+ .isEntitySet("ESTwoPrim")
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase)
+ .isTypeFilterOnEntry(null)
+ .at(0)
+ .isType(EntityTypeProvider.nameETTwoPrim, false)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // filter before key predicate; property of sub type
+ testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)/AdditionalPropertyString_5")
+ .at(0)
+ .isEntitySet("ESTwoPrim")
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase)
+ .isTypeFilterOnEntry(null)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isType(PropertyProvider.nameString)
+ .isPrimitiveProperty("AdditionalPropertyString_5", PropertyProvider.nameString, false);
+
+ // filter after key predicate
+ testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase")
+ .at(0)
+ .isEntitySet("ESTwoPrim")
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoPrim, false)
+ .isTypeFilterOnCollection(null)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBase)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // filter after key predicate; property of sub type
+ testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase/AdditionalPropertyString_5")
+ .at(0)
+ .isEntitySet("ESTwoPrim")
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isTypeFilterOnCollection(null)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBase)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(1)
+ .isPrimitiveProperty("AdditionalPropertyString_5", PropertyProvider.nameString, false)
+ .isType(PropertyProvider.nameString);
+
+ }
+
+ @Test
+ public void testFilterComplexMixedPriority() throws UriParserException {
+ testFilter.runESabc("a or c and e ").isCompr("< <a> or < <c> and <e> >>");
+ testFilter.runESabc("a or c and e eq f").isCompr("< <a> or < <c> and <<e> eq <f>>>>");
+ testFilter.runESabc("a or c eq d and e ").isCompr("< <a> or <<<c> eq <d>> and <e> >>");
+ testFilter.runESabc("a or c eq d and e eq f").isCompr("< <a> or <<<c> eq <d>> and <<e> eq <f>>>>");
+ testFilter.runESabc("a eq b or c and e ").isCompr("<<<a> eq <b>> or < <c> and <e> >>");
+ testFilter.runESabc("a eq b or c and e eq f").isCompr("<<<a> eq <b>> or < <c> and <<e> eq <f>>>>");
+ testFilter.runESabc("a eq b or c eq d and e ").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and <e> >>");
+ testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<<<a> eq <b>> or <<<c> eq <d>> and <<e> eq <f>>>>");
+ }
+
+ @Test
+ public void testFilterSimpleSameBinaryBinaryBinaryPriority() throws UriParserException {
+
+ testFilter.runESabc("1 add 2 add 3 add 4").isCompr("<<< <1> add <2>> add <3>> add <4>>");
+ testFilter.runESabc("1 add 2 add 3 div 4").isCompr("<< <1> add <2>> add <<3> div <4>>>");
+ testFilter.runESabc("1 add 2 div 3 add 4").isCompr("<< <1> add <<2> div <3>>> add <4>>");
+ testFilter.runESabc("1 add 2 div 3 div 4").isCompr("< <1> add <<<2> div <3>> div <4>>>");
+ testFilter.runESabc("1 div 2 add 3 add 4").isCompr("<<< <1> div <2>> add <3>> add <4>>");
+ testFilter.runESabc("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>");
+ testFilter.runESabc("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>");
+ testFilter.runESabc("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>");
+
+ }
+
+ @Test
+ public void testFunctionImport_VarParameters() {
+
+ // no input
+ testRes.run("FINRTInt16()")
+ .isFunctionImport("FINRTInt16")
+ .isFunction("UFNRTInt16")
+ .isType(PropertyProvider.nameInt16);
+
+ // one input
+ testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)")
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // two input
+ testRes.run("FICRTStringTwoParam(ParameterString='ABC',ParameterInt16=1)")
+ .isFunctionImport("FICRTStringTwoParam")
+ .isFunction("UFCRTStringTwoParam")
+ .isType(PropertyProvider.nameString);
+ }
+
+ @Test
+ public void testFunctionImport_VarRetruning() {
+ // returning primitive
+ testRes.run("FINRTInt16()")
+ .isFunctionImport("FINRTInt16")
+ .isFunction("UFNRTInt16")
+ .isType(PropertyProvider.nameInt16, false);
+
+ // returning collection of primitive
+ testRes.run("FICRTCollStringTwoParam(ParameterString='ABC',ParameterInt16=1)")
+ .isFunctionImport("FICRTCollStringTwoParam")
+ .isFunction("UFCRTCollStringTwoParam")
+ .isType(PropertyProvider.nameString, true);
+
+ // returning single complex
+ testRes.run("FICRTCTAllPrimTwoParam(ParameterString='ABC',ParameterInt16=1)")
+ .isFunctionImport("FICRTCTAllPrimTwoParam")
+ .isFunction("UFCRTCTAllPrimTwoParam")
+ .isType(ComplexTypeProvider.nameCTAllPrim, false);
+
+ // returning collection of complex
+ testRes.run("FICRTCollCTTwoPrim()")
+ .isFunctionImport("FICRTCollCTTwoPrim")
+ .isFunction("UFCRTCollCTTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true);
+
+ // returning single entity
+ testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)")
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false);
+
+ // returning collection of entity (aka entitySet)
+ testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)")
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true);
+ }
+
+ @Test
+ public void testFunctionImportChain() {
+
+ // test chain; returning single complex
+ testRes.run("FICRTCTAllPrimTwoParam(ParameterString='ABC',ParameterInt16=1)/PropertyInt16")
+ .at(0)
+ .isFunctionImport("FICRTCTAllPrimTwoParam")
+ .isFunction("UFCRTCTAllPrimTwoParam")
+ .isType(ComplexTypeProvider.nameCTAllPrim, false)
+ .isParameter(0, "ParameterString", "'ABC'")
+ .isParameter(1, "ParameterInt16", "1")
+ .at(1)
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ // test chains; returning single entity
+ testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/PropertyInt16")
+ .at(0)
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isParameter(0, "ParameterInt16", "1")
+ .at(1)
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ // test chains; returning collection of entity (aka entitySet)
+ testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=1,PropertyString='ABC')")
+ .at(0)
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isParameter(0, "ParameterInt16", "1")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'ABC'");
+
+ // test chains; returning collection of entity (aka entitySet)
+ testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=1,PropertyString='ABC')/PropertyInt16")
+ .at(0)
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isParameter(0, "ParameterInt16", "1")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'ABC'")
+ .at(1)
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ }
+
+ @Test
+ public void testMetaData() {
+
+ // Parsing the fragment may be used if a uri has to be parsed on the consumer side.
+ // On the producer side this feature is currently not supported, so the context fragment
+ // part is only available as text.
+
+ testUri.run("$metadata")
+ .isKind(UriInfoKind.metadata);
+
+ testUri.run("$metadata?$format=atom")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom");
+
+ // with context (client usage)
+
+ testUri.run("$metadata#$ref")
+ .isKind(UriInfoKind.metadata)
+ .isFragmentText("$ref");
+
+ testUri.run("$metadata?$format=atom#$ref")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("$ref");
+
+ testUri.run("$metadata?$format=atom#Collection($ref)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("Collection($ref)");
+
+ testUri.run("$metadata?$format=atom#Collection(Edm.EntityType)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("Collection(Edm.EntityType)");
+
+ testUri.run("$metadata?$format=atom#Collection(Edm.ComplexType)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("Collection(Edm.ComplexType)");
+
+ testUri.run("$metadata?$format=atom#SINav")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav");
+
+ testUri.run("$metadata?$format=atom#SINav/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/NavPropertyETKeyNavOne");
+
+ testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/NavPropertyETKeyNavMany(1)");
+
+ testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/NavPropertyETKeyNavOne/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#com.sap.odata.test1.ETAllKey")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("com.sap.odata.test1.ETAllKey");
+
+ testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedEntity")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESTwoPrim/$deletedEntity");
+
+ testUri.run("$metadata?$format=atom#ESTwoPrim/$link")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESTwoPrim/$link");
+
+ testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedLink")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESTwoPrim/$deletedLink");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16");
+
+ testUri.run(
+ "$metadata?$format=atom#ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav(PropertyInt16,PropertyString)")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav(PropertyInt16,PropertyString)");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/$entity")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/$entity");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/$delta")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/$delta");
+
+ testUri.run("$metadata?$format=atom#ESKeyNav/(PropertyInt16,PropertyString)/$delta")
+ .isKind(UriInfoKind.metadata)
+ .isFormatText("atom")
+ .isFragmentText("ESKeyNav/(PropertyInt16,PropertyString)/$delta");
+
+ }
+
+ @Test
+ public void testRef() {
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/$ref");
+ }
+
+ @Test
+ public void testSingleton() {
+ // plain singleton
+ testRes.run("SINav")
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+ }
+
+ @Test
+ public void testNavigationProperty() {
+
+ // plain entity set ...
+
+ // with navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
+
+ // with navigation property -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/PropertyString")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(2).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property -> navigation property -> navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false);
+
+ // with navigation property(key)
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'");
+
+ // with navigation property(key) -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')/PropertyString")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'")
+ .at(2).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property(key) -> navigation property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')/NavPropertyETKeyNavOne")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'")
+ .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false);
+
+ // with navigation property(key) -> navigation property(key)
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')"
+ + "/NavPropertyETKeyNavMany(1)")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'")
+ .at(2).isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ // with navigation property(key) -> navigation property -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')"
+ + "/NavPropertyETKeyNavOne/PropertyString")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'")
+ .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .at(3).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ // with navigation property(key) -> navigation property(key) -> property
+ testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')"
+ + "/NavPropertyETKeyNavMany(1)/PropertyString")
+ .at(0).isEntitySet("ESKeyNav")
+ .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'1'")
+ .at(2).isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .at(3).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+ }
+
+ @Test
+ public void testSingleton_Property() {
+
+ // plain singleton ...
+
+ // with property
+ testRes.run("SINav/PropertyInt16")
+ .at(0)
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .at(1)
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ // with complex property
+ testRes.run("SINav/PropertyComplex")
+ .at(0)
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .at(1)
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false);
+
+ // with two properties
+ testRes.run("SINav/PropertyComplex/PropertyInt16")
+ .at(0)
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .at(1)
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false)
+ .at(2)
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ }
+
+ @Test
+ public void testValue() {
+ testUri.run("ESAllPrim(1)/PropertyString/$value");
+ }
+
+ @Test(expected = Exception.class)
+ public void testMemberStartingWithCastFailOnValidation1() {
+ // on EntityType entry
+ testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')?"
+ + "$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
+ .goFilter().root().isMember()
+ .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
+ // .at(0)
+ // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
+ // .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .at(0).isType(PropertyProvider.nameDate);
+ }
+
+ @Test(expected = Exception.class)
+ public void testMemberStartingWithCastFailOnValidation2() {
+ testUri.run("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?"
+ + "$filter=com.sap.odata.test1.CTBase/AdditionalPropString")
+ .goFilter().root().isMember()
+ .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath()
+ // .at(0)
+ // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
+ // .isType(ComplexTypeProvider.nameCTTwoPrim, false)
+ // .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase)
+ .at(0).isType(PropertyProvider.nameString);
+ }
+
+ @Test
+ public void testMemberStartingWithCast() {
+
+ // on EntityType collection
+ testUri.run("ESTwoKeyNav?$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
+ .goFilter().root().isMember()
+ .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath()
+ // .at(0)
+ // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
+ // .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .at(0).isType(PropertyProvider.nameDate);
+
+ // on Complex collection
+ testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?"
+ + "$filter=com.sap.odata.test1.CTBase/AdditionalPropString")
+ .goFilter().root().isMember()
+ .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath()
+ // .at(0)
+ // .isUriPathInfoKind(UriResourceKind.startingTypeFilter)
+ // .isType(ComplexTypeProvider.nameCTTwoPrim, true)
+ // .isTypeFilterOnCollection(ComplexTypeProvider.nameCTBase)
+ .at(0).isType(PropertyProvider.nameString);
+
+ }
+
+ @Test
+ public void testComplexTypeCastFollowingAsCollection() {
+ testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')/com.sap.odata.test1.CTBase");
+ }
+
+ @Test
+ public void testLambda() {
+ testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/all( l : true )")
+ .goFilter().is("<CollPropertyComplex/<ALL;<true>>>");
+
+ testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/any( l : true )")
+ .goFilter().is("<CollPropertyComplex/<ANY;<true>>>");
+ testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/any( )")
+ .goFilter().is("<CollPropertyComplex/<ANY;>>");
+
+ testUri.run("ESTwoKeyNav?$filter=all( l : true )")
+ .goFilter().is("<<ALL;<true>>>");
+ testUri.run("ESTwoKeyNav?$filter=any( l : true )")
+ .goFilter().is("<<ANY;<true>>>");
+ testUri.run("ESTwoKeyNav?$filter=any( )")
+ .goFilter().is("<<ANY;>>");
+ }
+
+ @Test
+ public void testCustomQueryOption() {
+ testUri.run("ESTwoKeyNav?custom")
+ .isCustomParameter(0, "custom", "");
+ testUri.run("ESTwoKeyNav?custom=ABC")
+ .isCustomParameter(0, "custom", "ABC");
+ }
+
+ @Test
+ public void testGeo() throws UriParserException {
+ // TODO sync
+ testFilter.runOnETAllPrim("geo.distance(PropertySByte,PropertySByte)")
+ .is("<geo.distance(<PropertySByte>,<PropertySByte>)>")
+ .isMethod(MethodKind.GEODISTANCE, 2);
+ testFilter.runOnETAllPrim("geo.length(PropertySByte)")
+ .is("<geo.length(<PropertySByte>)>")
+ .isMethod(MethodKind.GEOLENGTH, 1);
+ testFilter.runOnETAllPrim("geo.intersects(PropertySByte,PropertySByte)")
+ .is("<geo.intersects(<PropertySByte>,<PropertySByte>)>")
+ .isMethod(MethodKind.GEOINTERSECTS, 2);
+ }
+
+ @Test
+ public void testSelect() {
+ testUri.run("ESTwoKeyNav?$select=*")
+ .isSelectItemStar(0);
+
+ testUri.run("ESTwoKeyNav?$select=com.sap.odata.test1.*")
+ .isSelectItemAllOp(0, new FullQualifiedName("com.sap.odata.test1", "*"));
+
+ testUri.run("ESTwoKeyNav?$select=PropertyString")
+ .goSelectItemPath(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ testUri.run("ESTwoKeyNav?$select=PropertyComplex")
+ .goSelectItemPath(0).isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false);
+
+ testUri.run("ESTwoKeyNav?$select=PropertyComplex/PropertyInt16")
+ .goSelectItemPath(0)
+ .first()
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESTwoKeyNav?$select=PropertyComplex/PropertyComplex")
+ .goSelectItemPath(0)
+ .first()
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false);
+
+ testUri.run("ESTwoKeyNav?$select=com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri.run("ESTwoKeyNav/PropertyComplexNav?$select=com.sap.odata.test1.CTTwoBasePrimCompNav")
+ .isSelectStartType(0, ComplexTypeProvider.nameCTTwoBasePrimCompNav);
+
+ testUri.run("ESTwoKeyNav?$select=PropertyComplexNav/com.sap.odata.test1.CTTwoBasePrimCompNav")
+ .goSelectItemPath(0)
+ .first()
+ .isComplexProperty("PropertyComplexNav", ComplexTypeProvider.nameCTBasePrimCompNav, false)
+ .n()
+ .isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav);
+ ;
+
+ }
+
+ public static String encode(final String decoded) throws UnsupportedEncodingException {
+
+ return URLEncoder.encode(decoded, "UTF-8");
+
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java
new file mode 100644
index 0000000..7dcf5a5
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java
@@ -0,0 +1,303 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.queryoption;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.AliasImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.junit.Test;
+
+//TOOD add getKind check to all
+public class QueryOptionTest {
+
+ Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
+
+ @Test
+ public void testAliasQueryOption() {
+ AliasQueryOptionImpl option = new AliasQueryOptionImpl();
+
+ ExpressionImpl expression = new LiteralImpl();
+
+ option.setAliasValue(expression);
+ assertEquals(expression, option.getValue());
+ }
+
+ @Test
+ public void testExandItemImpl() {
+ ExpandItemImpl option = new ExpandItemImpl();
+
+ // input options
+ ExpandOptionImpl expand = new ExpandOptionImpl();
+ FilterOptionImpl filter = new FilterOptionImpl();
+ CountOptionImpl inlinecount = new CountOptionImpl();
+ OrderByOptionImpl orderby = new OrderByOptionImpl();
+ SearchOptionImpl search = new SearchOptionImpl();
+ SelectOptionImpl select = new SelectOptionImpl();
+ SkipOptionImpl skip = new SkipOptionImpl();
+ TopOptionImpl top = new TopOptionImpl();
+ LevelsOptionImpl levels = new LevelsOptionImpl();
+
+ option.setSystemQueryOption(expand);
+ option.setSystemQueryOption(filter);
+ option.setSystemQueryOption(inlinecount);
+ option.setSystemQueryOption(orderby);
+ option.setSystemQueryOption(search);
+ option.setSystemQueryOption(select);
+ option.setSystemQueryOption(skip);
+ option.setSystemQueryOption(top);
+ option.setSystemQueryOption(levels);
+
+ assertEquals(expand, option.getExpandOption());
+ assertEquals(filter, option.getFilterOption());
+ assertEquals(inlinecount, option.getCountOption());
+ assertEquals(orderby, option.getOrderByOption());
+ assertEquals(search, option.getSearchOption());
+ assertEquals(select, option.getSelectOption());
+ assertEquals(skip, option.getSkipOption());
+ assertEquals(top, option.getTopOption());
+ assertEquals(levels, option.getLevelsOption());
+
+ // just for completeness
+ option = new ExpandItemImpl();
+ option.setSystemQueryOption(new IdOptionImpl());
+
+ option = new ExpandItemImpl();
+ List<SystemQueryOptionImpl> list = new ArrayList<SystemQueryOptionImpl>();
+ list.add(expand);
+ list.add(filter);
+ option.setSystemQueryOptions(list);
+ assertEquals(expand, option.getExpandOption());
+ assertEquals(filter, option.getFilterOption());
+
+ option = new ExpandItemImpl();
+ assertEquals(false, option.isRef());
+ option.setIsRef(true);
+ assertEquals(true, option.isRef());
+
+ option = new ExpandItemImpl();
+ assertEquals(false, option.isStar());
+ option.setIsStar(true);
+ assertEquals(true, option.isStar());
+
+ option = new ExpandItemImpl();
+ UriInfoResource resource = new UriInfoImpl().asUriInfoResource();
+ option.setResourcePath(resource);
+ assertEquals(resource, option.getResourcePath());
+
+ }
+
+ @Test
+ public void testExpandOptionImpl() {
+ ExpandOptionImpl option = new ExpandOptionImpl();
+ assertEquals(SystemQueryOptionKind.EXPAND, option.getKind());
+
+ ExpandItemImpl item1 = new ExpandItemImpl();
+ ExpandItemImpl item2 = new ExpandItemImpl();
+ option.addExpandItem(item1);
+ option.addExpandItem(item2);
+ assertEquals(item1, option.getExpandItems().get(0));
+ assertEquals(item2, option.getExpandItems().get(1));
+ }
+
+ @Test
+ public void testFilterOptionImpl() {
+ FilterOptionImpl option = new FilterOptionImpl();
+ assertEquals(SystemQueryOptionKind.FILTER, option.getKind());
+
+ AliasImpl expression = new AliasImpl();
+
+ option.setExpression(expression);
+ assertEquals(expression, option.getExpression());
+ }
+
+ @Test
+ public void testFormatOptionImpl() {
+ FormatOptionImpl option = new FormatOptionImpl();
+ assertEquals(SystemQueryOptionKind.FORMAT, option.getKind());
+
+ option.setFormat("A");
+
+ assertEquals("A", option.getFormat());
+ }
+
+ @Test
+ public void testIdOptionImpl() {
+ IdOptionImpl option = new IdOptionImpl();
+ assertEquals(SystemQueryOptionKind.ID, option.getKind());
+
+ option.setValue("A");
+
+ assertEquals("A", option.getValue());
+ }
+
+ @Test
+ public void testInlineCountImpl() {
+ CountOptionImpl option = new CountOptionImpl();
+ assertEquals(SystemQueryOptionKind.COUNT, option.getKind());
+
+ assertEquals(false, option.getValue());
+ option.setValue(true);
+ assertEquals(true, option.getValue());
+ }
+
+ @Test
+ public void testLevelsExpandOptionImpl() {
+ LevelsOptionImpl option = new LevelsOptionImpl();
+ assertEquals(SystemQueryOptionKind.LEVELS, option.getKind());
+
+ assertEquals(0, option.getValue());
+ option.setValue(1);
+ assertEquals(1, option.getValue());
+
+ option = new LevelsOptionImpl();
+ option.setMax();
+ assertEquals(true, option.isMax());
+ }
+
+ @Test
+ public void testOrderByItemImpl() {
+ OrderByItemImpl option = new OrderByItemImpl();
+
+ AliasImpl expression = new AliasImpl();
+ option.setExpression(expression);
+ assertEquals(expression, option.getExpression());
+
+ assertEquals(false, option.isDescending());
+ option.setDescending(true);
+ assertEquals(true, option.isDescending());
+ }
+
+ @Test
+ public void testOrderByOptionImpl() {
+ OrderByOptionImpl option = new OrderByOptionImpl();
+
+ OrderByItemImpl order0 = new OrderByItemImpl();
+ OrderByItemImpl order1 = new OrderByItemImpl();
+ option.addOrder(order0);
+ option.addOrder(order1);
+
+ assertEquals(order0, option.getOrders().get(0));
+ assertEquals(order1, option.getOrders().get(1));
+ }
+
+ @Test
+ public void testQueryOptionImpl() {
+ QueryOptionImpl option = new AliasQueryOptionImpl();
+
+ option.setName("A");
+ option.setText("B");
+ assertEquals("A", option.getName());
+ assertEquals("B", option.getText());
+ }
+
+ @Test
+ public void testSearchOptionImpl() {
+ SearchOptionImpl option = new SearchOptionImpl();
+ assertEquals(SystemQueryOptionKind.SEARCH, option.getKind());
+ // TODO $search is not supported yet
+ }
+
+ @Test
+ public void testSelectItemImpl() {
+ SelectItemImpl option = new SelectItemImpl();
+
+ // no typed collection else case ( e.g. if not path is added)
+ option = new SelectItemImpl();
+
+ option = new SelectItemImpl();
+ assertEquals(false, option.isStar());
+ option.setStar(true);
+ assertEquals(true, option.isStar());
+
+ option = new SelectItemImpl();
+ assertEquals(false, option.isAllOperationsInSchema());
+ FullQualifiedName fqName = new FullQualifiedName("Namespace", "Name");
+ option.addAllOperationsInSchema(fqName);
+ assertEquals(true, option.isAllOperationsInSchema());
+ assertEquals(fqName, option.getAllOperationsInSchemaNameSpace());
+
+ }
+
+ @Test
+ public void testSelectOptionImpl() {
+ SelectOptionImpl option = new SelectOptionImpl();
+ assertEquals(SystemQueryOptionKind.SELECT, option.getKind());
+
+ SelectItemImpl item0 = new SelectItemImpl();
+ SelectItemImpl item1 = new SelectItemImpl();
+
+ ArrayList<SelectItemImpl> list = new ArrayList<SelectItemImpl>();
+ list.add(item0);
+ list.add(item1);
+ option.setSelectItems(list);
+
+ assertEquals(item0, option.getSelectItems().get(0));
+ assertEquals(item1, option.getSelectItems().get(1));
+
+ }
+
+ @Test
+ public void testSkipOptionImpl() {
+ SkipOptionImpl option = new SkipOptionImpl();
+ assertEquals(SystemQueryOptionKind.SKIP, option.getKind());
+
+ option.setValue(10);
+ assertEquals(10, option.getValue());
+ }
+
+ @Test
+ public void testSkipTokenOptionImpl() {
+ SkipTokenOptionImpl option = new SkipTokenOptionImpl();
+ assertEquals(SystemQueryOptionKind.SKIPTOKEN, option.getKind());
+
+ option.setValue("A");
+ assertEquals("A", option.getValue());
+ }
+
+ @Test
+ public void testSystemQueryOptionImpl() {
+ SystemQueryOptionImpl option = new SystemQueryOptionImpl();
+
+ option.setKind(SystemQueryOptionKind.EXPAND);
+ assertEquals(SystemQueryOptionKind.EXPAND, option.getKind());
+
+ assertEquals("$expand", option.getName());
+ }
+
+ @Test
+ public void testTopOptionImpl() {
+ TopOptionImpl option = new TopOptionImpl();
+ assertEquals(SystemQueryOptionKind.TOP, option.getKind());
+
+ option.setValue(11);
+ assertEquals(11, option.getValue());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
new file mode 100644
index 0000000..de63b46
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java
@@ -0,0 +1,239 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.queryoption.expression;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.Arrays;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmEnumType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.UriInfoImpl;
+import org.apache.olingo.server.core.uri.UriResourceActionImpl;
+import org.apache.olingo.server.core.uri.UriResourceFunctionImpl;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.apache.olingo.server.core.uri.testutil.FilterTreeToText;
+import org.apache.olingo.server.tecsvc.provider.ActionProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.FunctionProvider;
+import org.junit.Test;
+
+public class ExpressionTest {
+ Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
+
+ @Test
+ public void testSupportedOperators() {
+ assertEquals(UnaryOperatorKind.MINUS, UnaryOperatorKind.get("-"));
+ assertEquals(null, UnaryOperatorKind.get("XXX"));
+
+ assertEquals(BinaryOperatorKind.MOD, BinaryOperatorKind.get("mod"));
+ assertEquals(null, BinaryOperatorKind.get("XXX"));
+
+ assertEquals(MethodKind.CONCAT, MethodKind.get("concat"));
+ assertEquals(null, MethodKind.get("XXX"));
+ }
+
+ @Test
+ public void testAliasExpression() throws ExpressionVisitException, ODataApplicationException {
+ AliasImpl expression = new AliasImpl();
+
+ expression.setParameter("Test");
+
+ assertEquals("Test", expression.getParameterName());
+
+ String output = expression.accept(new FilterTreeToText());
+ assertEquals("<Test>", output);
+
+ }
+
+ @Test
+ public void testBinaryExpression() throws ExpressionVisitException, ODataApplicationException {
+ BinaryImpl expression = new BinaryImpl();
+
+ ExpressionImpl expressionLeft = new LiteralImpl().setText("A");
+ ExpressionImpl expressionRight = new LiteralImpl().setText("B");
+
+ expression.setLeftOperand(expressionLeft);
+ expression.setRightOperand(expressionRight);
+ expression.setOperator(BinaryOperatorKind.SUB);
+
+ assertEquals(expressionLeft, expression.getLeftOperand());
+ assertEquals(expressionRight, expression.getRightOperand());
+ assertEquals(BinaryOperatorKind.SUB, expression.getOperator());
+
+ String output = expression.accept(new FilterTreeToText());
+ assertEquals("<<A> sub <B>>", output);
+ }
+
+ @Test
+ public void testEnumerationExpression() throws ExpressionVisitException, ODataApplicationException {
+ EnumerationImpl expression = new EnumerationImpl();
+ EdmEnumType type = (EdmEnumType) edm.getEnumType(EnumTypeProvider.nameENString);
+ assertNotNull(type);
+ expression.setType(type);
+
+ assertEquals(type, expression.getType());
+
+ expression.addValue("A");
+ expression.addValue("B");
+ assertEquals("A", expression.getValues().get(0));
+ assertEquals("B", expression.getValues().get(1));
+ assertEquals("<com.sap.odata.test1.ENString<A,B>>", expression.accept(new FilterTreeToText()));
+ }
+
+ @Test
+ public void testLambdaRefExpression() throws ExpressionVisitException, ODataApplicationException {
+ LambdaRefImpl expression = new LambdaRefImpl();
+ expression.setVariableText("A");
+ assertEquals("A", expression.getVariableName());
+
+ assertEquals("<A>", expression.accept(new FilterTreeToText()));
+
+ }
+
+ @Test
+ public void testLiteralExpresion() throws ExpressionVisitException, ODataApplicationException {
+ LiteralImpl expression = new LiteralImpl();
+ expression.setText("A");
+ assertEquals("A", expression.getText());
+
+ assertEquals("<A>", expression.accept(new FilterTreeToText()));
+ }
+
+ @Test
+ public void testMemberExpression() throws ExpressionVisitException, ODataApplicationException {
+ MemberImpl expression = new MemberImpl();
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
+
+ // UriResourceImplTyped
+ EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam);
+ UriInfoResource uriInfo = new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceActionImpl().setAction(action)).asUriInfoResource();
+ expression.setResourcePath(uriInfo);
+ assertEquals(action.getReturnType().getType(), expression.getType());
+
+ // check accept and path
+ assertEquals(uriInfo, expression.getResourcePath());
+ assertEquals("<UARTPrimParam>", expression.accept(new FilterTreeToText()));
+
+ // UriResourceImplTyped check collection = false case
+ assertEquals(false, expression.isCollection());
+
+ // UriResourceImplTyped check collection = true case
+ action = edm.getUnboundAction(ActionProvider.nameUARTPrimCollParam);
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceActionImpl().setAction(action))
+ .asUriInfoResource());
+ assertEquals(true, expression.isCollection());
+
+ // UriResourceImplTyped with filter
+ action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam);
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceActionImpl().setAction(action).setTypeFilter(entityType))
+ .asUriInfoResource());
+ assertEquals(entityType, expression.getType());
+
+ // UriResourceImplKeyPred
+ EdmFunction function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null);
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceFunctionImpl().setFunction(function))
+ .asUriInfoResource());
+ assertEquals(function.getReturnType().getType(), expression.getType());
+
+ // UriResourceImplKeyPred typeFilter on entry
+ EdmEntityType entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16"));
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceFunctionImpl().setFunction(function).setEntryTypeFilter(entityBaseType))
+ .asUriInfoResource());
+ assertEquals(entityBaseType, expression.getType());
+
+ // UriResourceImplKeyPred typeFilter on entry
+ entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16"));
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart(
+ new UriResourceFunctionImpl().setFunction(function).setCollectionTypeFilter(entityBaseType))
+ .asUriInfoResource());
+ assertEquals(entityBaseType, expression.getType());
+
+ // no typed
+ entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16"));
+ expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.all));
+ assertEquals(null, expression.getType());
+
+ // no typed collection else case
+ assertEquals(false, expression.isCollection());
+ }
+
+ @Test
+ public void testMethodCallExpression() throws ExpressionVisitException, ODataApplicationException {
+ MethodImpl expression = new MethodImpl();
+ expression.setMethod(MethodKind.CONCAT);
+
+ ExpressionImpl p0 = new LiteralImpl().setText("A");
+ ExpressionImpl p1 = new LiteralImpl().setText("B");
+ expression.addParameter(p0);
+ expression.addParameter(p1);
+
+ assertEquals(MethodKind.CONCAT, expression.getMethod());
+ assertEquals("<concat(<A>,<B>)>", expression.accept(new FilterTreeToText()));
+
+ assertEquals(p0, expression.getParameters().get(0));
+ assertEquals(p1, expression.getParameters().get(1));
+ }
+
+ @Test
+ public void testTypeLiteralExpression() throws ExpressionVisitException, ODataApplicationException {
+ TypeLiteralImpl expression = new TypeLiteralImpl();
+ EdmEntityType entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ expression.setType(entityBaseType);
+
+ assertEquals(entityBaseType, expression.getType());
+ assertEquals("<com.sap.odata.test1.ETBaseTwoKeyNav>", expression.accept(new FilterTreeToText()));
+ }
+
+ @Test
+ public void testUnaryExpression() throws ExpressionVisitException, ODataApplicationException {
+ UnaryImpl expression = new UnaryImpl();
+ expression.setOperator(UnaryOperatorKind.MINUS);
+
+ ExpressionImpl operand = new LiteralImpl().setText("A");
+ expression.setOperand(operand);
+
+ assertEquals(UnaryOperatorKind.MINUS, expression.getOperator());
+ assertEquals(operand, expression.getOperand());
+
+ assertEquals("<- <A>>", expression.accept(new FilterTreeToText()));
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
new file mode 100644
index 0000000..8f0d507
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java
@@ -0,0 +1,100 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.testutil;
+
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.server.api.edm.provider.ComplexType;
+import org.apache.olingo.server.api.edm.provider.EntitySet;
+import org.apache.olingo.server.api.edm.provider.EntityType;
+import org.apache.olingo.server.api.edm.provider.Property;
+import org.apache.olingo.server.api.edm.provider.PropertyRef;
+import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
+
+/**
+ * Implement the EdmTechProvider and
+ * <li>adds a entity type <b>ETabc with</b> properties a,b,c,d,e,f</li>
+ * <li>adds a complex type <b>CTabc</b> with properties a,b,c,d,e,f</li>
+ * <li>adds a <b>abc</b> entity set of type <b>ETabc</b></li>
+ */
+public class EdmTechTestProvider extends EdmTechProvider {
+
+ private static final FullQualifiedName nameInt16 = EdmPrimitiveTypeKind.Int16.getFullQualifiedName();
+ public static final String nameSpace = "com.sap.odata.test1";
+ public static final FullQualifiedName nameContainer = new FullQualifiedName(nameSpace, "Container");
+
+ Property propertyAInt16 = new Property().setName("a").setType(nameInt16);
+ Property propertyBInt16 = new Property().setName("b").setType(nameInt16);
+ Property propertyCInt16 = new Property().setName("c").setType(nameInt16);
+ Property propertyDInt16 = new Property().setName("d").setType(nameInt16);
+ Property propertyEInt16 = new Property().setName("e").setType(nameInt16);
+ Property propertyFInt16 = new Property().setName("f").setType(nameInt16);
+
+ public static final FullQualifiedName nameCTabc = new FullQualifiedName(nameSpace, "CTabc");
+ public static final FullQualifiedName nameETabc = new FullQualifiedName(nameSpace, "ETabc");
+
+ @Override
+ public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException {
+ if (complexTypeName.equals(nameCTabc)) {
+ return new ComplexType()
+ .setName("CTabc")
+ .setProperties(Arrays.asList(
+ propertyAInt16, propertyBInt16, propertyCInt16,
+ propertyDInt16, propertyEInt16, propertyFInt16
+ ));
+
+ }
+
+ return super.getComplexType(complexTypeName);
+ }
+
+ @Override
+ public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String name) throws ODataException {
+ if (nameContainer.equals(entityContainer)) {
+ if (name.equals("ESabc")) {
+ return new EntitySet()
+ .setName("ESabc")
+ .setType(nameETabc);
+ }
+ }
+
+ return super.getEntitySet(entityContainer, name);
+ }
+
+ @Override
+ public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException {
+ List<PropertyRef> oneKeyPropertyInt16 = Arrays.asList(new PropertyRef().setPropertyName("a"));
+
+ if (entityTypeName.equals(nameETabc)) {
+ return new EntityType()
+ .setName("ETabc")
+ .setProperties(Arrays.asList(
+ propertyAInt16, propertyBInt16, propertyCInt16,
+ propertyDInt16, propertyEInt16, propertyFInt16))
+ .setKey(oneKeyPropertyInt16);
+ }
+
+ return super.getEntityType(entityTypeName);
+ }
+
+}
[4/5] [OLINGO-266] server-test module introduced
Posted by sk...@apache.org.
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
new file mode 100644
index 0000000..00772a5
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java
@@ -0,0 +1,5110 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri.antlr;
+
+import java.io.UnsupportedEncodingException;
+import java.util.Arrays;
+
+import org.apache.olingo.commons.api.ODataApplicationException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.core.Encoder;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriResourceKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind;
+import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException;
+import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.parser.UriParserException;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.apache.olingo.server.core.uri.testutil.FilterValidator;
+import org.apache.olingo.server.core.uri.testutil.ResourceValidator;
+import org.apache.olingo.server.core.uri.testutil.TestUriValidator;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.PropertyProvider;
+import org.junit.Test;
+
+public class TestFullResourcePath {
+ Edm edm = null;
+ TestUriValidator testUri = null;
+ ResourceValidator testRes = null;
+ FilterValidator testFilter = null;
+
+ public TestFullResourcePath() {
+ edm = new EdmProviderImpl(new EdmTechTestProvider());
+ testUri = new TestUriValidator().setEdm(edm);
+ testRes = new ResourceValidator().setEdm(edm);
+ testFilter = new FilterValidator().setEdm(edm);
+ }
+
+ @Test
+ public void test() throws UriParserException {
+
+ }
+
+ @Test
+ public void testFunctionBound_varOverloading() {
+ // on ESTwoKeyNav
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // with string parameter
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')").goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // with string parameter
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+ }
+
+ @Test
+ public void runBfuncBnCpropCastRtEs() {
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESBaseTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isFunction("BFCCTPrimCompRTESBaseTwoKeyNav");
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESBaseTwoKeyNav()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isFunction("BFCCTPrimCompRTESBaseTwoKeyNav")
+ .isType(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isUriPathInfoKind(UriResourceKind.count);
+
+ }
+
+ @Test
+ public void runBfuncBnCpropCollRtEs() {
+ testUri.run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isUriPathInfoKind(UriResourceKind.complexProperty)
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .n()
+ .isFunction("BFCCollCTPrimCompRTESAllPrim");
+
+ testUri
+ .run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isUriPathInfoKind(UriResourceKind.complexProperty)
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .n()
+ .isFunction("BFCCollCTPrimCompRTESAllPrim")
+ .isType(EntityTypeProvider.nameETAllPrim, true)
+ .n()
+ .isUriPathInfoKind(UriResourceKind.count);
+ }
+
+ @Test
+ public void runBfuncBnCpropRtEs() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isUriPathInfoKind(UriResourceKind.complexProperty)
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isFunction("BFCCTPrimCompRTESTwoKeyNav");
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isUriPathInfoKind(UriResourceKind.complexProperty)
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, false)
+ .n()
+ .isFunction("BFCCTPrimCompRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .n()
+ .isUriPathInfoKind(UriResourceKind.count);
+
+ }
+
+ @Test
+ public void runBfuncBnEntityRtEs() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isFunction("BFCETTwoKeyNavRTESTwoKeyNav");
+ }
+
+ @Test
+ public void runBfuncBnEntityCastRtEs() {
+ testUri
+ .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isFunction("BFCETBaseTwoKeyNavRTESTwoKeyNav");
+
+ testUri
+ .run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='(''2'')')"
+ + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'(''2'')'")
+ .n()
+ .isFunction("BFCETBaseTwoKeyNavRTESTwoKeyNav");
+ }
+
+ @Test
+ public void runBfuncBnEsCastRtEs() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/com.sap.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey");
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/com.sap.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey")
+ .isType(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ testUri.run("ESTwoKeyNav"
+ + "/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+ }
+
+ @Test
+ public void runBfuncBnEsRtCprop() {
+ testUri.run("ESAllPrim/com.sap.odata.test1.BFCESAllPrimRTCTAllPrim()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .n()
+ .isFunction("BFCESAllPrimRTCTAllPrim")
+ .isType(ComplexTypeProvider.nameCTAllPrim);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()/com.sap.odata.test1.CTBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTCTTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, false)
+ .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase);
+ }
+
+ @Test
+ public void runBfuncBnEsRtCpropColl() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTCollCTTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTCollCTTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true)
+ .n()
+ .isUriPathInfoKind(UriResourceKind.count);
+ }
+
+ @Test
+ public void runBfuncBnEsRtEntityPpNp() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()/NavPropertyETKeyNavOne")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTTwoKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()/NavPropertyETKeyNavOne/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTTwoKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .n()
+ .isUriPathInfoKind(UriResourceKind.ref);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/NavPropertyETMediaOne/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETMediaOne", EntityTypeProvider.nameETMedia, false)
+ .n()
+ .isValue();
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavOne")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavOne/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavOne/PropertyComplex/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp)
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTAllPrim);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavOne/PropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/PropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+ }
+
+ @Test
+ public void runBfuncBnEsRtEntyPpNpCast() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()"
+ + "/NavPropertyETTwoKeyNavOne/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTTwoKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri
+ .run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()(PropertyInt16=1,PropertyString='2')"
+ + "/NavPropertyETTwoKeyNavOne/com.sap.odata.test1.ETTwoBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ }
+
+ @Test
+ public void runBfuncBnEsRtEntityPpCp() {
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTNavFiveProp);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTNavFiveProp)
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex/PropertyInt16/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isComplex("PropertyComplex")
+ .isType(ComplexTypeProvider.nameCTNavFiveProp)
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false)
+ .n()
+ .isValue();
+
+ }
+
+ @Test
+ public void runBfuncBnEsRtEntyPpCpCast() {
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isComplex("PropertyComplexTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim)
+ .isTypeFilter(ComplexTypeProvider.nameCTTwoBase);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')"
+ + "/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')"
+ + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNavParam")
+ .isParameter(0, "ParameterString", "'1'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isComplex("PropertyComplexTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim)
+ .isTypeFilter(ComplexTypeProvider.nameCTTwoBase);
+ }
+
+ @Test
+ public void runBfuncBnEsRtEntityPpSp() {
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyInt16/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESKeyNavRTETKeyNav")
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false)
+ .n()
+ .isValue();
+
+ }
+
+ @Test
+ public void runBfuncBnEsRtEs() {
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isParameter(0, "ParameterString", "'2'")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ testUri.run("ESKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='3')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isParameter(0, "ParameterString", "'3'")
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .n()
+ .isCount();
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()(PropertyInt16=1,PropertyString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'");
+
+ }
+
+ @Test
+ public void runBfuncBnEsRtEsBa() {
+
+ testUri.run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex"
+ + "/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()/com.sap.odata.test1.BAESAllPrimRTETAllPrim")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp)
+ .n()
+ .isFunction("BFCCollCTPrimCompRTESAllPrim")
+ .n()
+ .isAction("BAESAllPrimRTETAllPrim");
+
+ }
+
+ @Test
+ public void runBfuncBnEsRtPrim() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTString");
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTString")
+ .isType(PropertyProvider.nameString)
+ .n()
+ .isValue();
+ }
+
+ @Test
+ public void runbfuncBnEsRtPrimColl() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTCollString")
+ .isType(PropertyProvider.nameString, true);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isFunction("BFCESTwoKeyNavRTCollString")
+ .isType(PropertyProvider.nameString, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runBfuncBnPpropCollRtEs() {
+ testUri.run("ESKeyNav(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true)
+ .n()
+ .isFunction("BFCCollStringRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true);
+
+ testUri.run("ESKeyNav(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true)
+ .n()
+ .isFunction("BFCCollStringRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runBfuncBnPpropRtEs() {
+
+ testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false)
+ .n()
+ .isFunction("BFCStringRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true);
+
+ testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false)
+ .n()
+ .isFunction("BFCStringRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .n()
+ .isCount();
+
+ testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false)
+ .n()
+ .isFunction("BFCStringRTESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .n()
+ .isRef();
+ }
+
+ @Test
+ public void runBfuncBnSingleRtEs() {
+
+ testUri.run("SINav/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isFunction("BFCSINavRTESTwoKeyNav");
+ }
+
+ @Test
+ public void runBfuncBnSingleCastRtEs() {
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESBaseTwoKey()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isFunction("BFCETBaseTwoKeyNavRTESBaseTwoKey");
+ }
+
+ @Test
+ public void runActionBound_on_EntityEntry() {
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.BAETTwoKeyNavRTETTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isAction("BAETTwoKeyNavRTETTwoKeyNav");
+
+ testUri.run("ESKeyNav(PropertyInt16=1)/com.sap.odata.test1.BAETTwoKeyNavRTETTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isAction("BAETTwoKeyNavRTETTwoKeyNav");
+ }
+
+ @Test
+ public void runActionBound_on_EntityCollection() {
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .n()
+ .isAction("BAESTwoKeyNavRTESTwoKeyNav");
+ }
+
+ @Test
+ public void runFunctionBound_on_var_Types() {
+
+ // on primitive
+ testUri.run("ESAllPrim(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETAllPrim, false)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.primitiveProperty)
+ .isType(PropertyProvider.nameString);
+
+ // on collection of primitive
+ testUri.run("ESCollAllPrim(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETCollAllPrim, false)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.primitiveProperty)
+ .isType(PropertyProvider.nameString);
+
+ // on complex
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')"
+ + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.complexProperty)
+ .at(2)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // on collection of complex
+ testUri.run("ESKeyNav(1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .at(1)
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .at(2)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETAllPrim);
+
+ // on entity
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')"
+ + "/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .at(1)
+ .isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+
+ // on collection of entity
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()")
+ .goPath()
+ .at(0)
+ .isUriPathInfoKind(UriResourceKind.entitySet)
+ .isType(EntityTypeProvider.nameETTwoKeyNav, true)
+ .at(1).isUriPathInfoKind(UriResourceKind.function)
+ .isType(EntityTypeProvider.nameETTwoKeyNav);
+ }
+
+ @Test
+ public void runActionBound_on_EntityCast() {
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/com.sap.odata.test1.BAETBaseTwoKeyNavRTETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isAction("BAETBaseTwoKeyNavRTETBaseTwoKeyNav");
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav/com.sap.odata.test1.BAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav)
+ .n()
+ .isAction("BAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav");
+ }
+
+ @Test
+ public void runCrossjoin() {
+ testUri.run("$crossjoin(ESKeyNav)")
+ .isKind(UriInfoKind.crossjoin)
+ .isCrossJoinEntityList(Arrays.asList("ESKeyNav"));
+
+ testUri.run("$crossjoin(ESKeyNav, ESTwoKeyNav)")
+ .isKind(UriInfoKind.crossjoin)
+ .isCrossJoinEntityList(Arrays.asList("ESKeyNav", "ESTwoKeyNav"));
+ }
+
+ @Test
+ public void runCrossjoinError() {
+ testUri.runEx("$crossjoin").isExSyntax(0);
+ testUri.runEx("$crossjoin/error").isExSyntax(0);
+ testUri.runEx("$crossjoin()").isExSyntax(0);
+ // testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid").isExSyntax(0);
+ }
+
+ @Test
+ public void runEntityId() {
+ testUri.run("$entity?$id=ESKeyNav(1)")
+ .isKind(UriInfoKind.entityId)
+ .isIdText("ESKeyNav(1)");
+ testUri.run("$entity/com.sap.odata.test1.ETKeyNav?$id=ESKeyNav(1)")
+ .isKind(UriInfoKind.entityId)
+ .isEntityType(EntityTypeProvider.nameETKeyNav)
+ .isIdText("ESKeyNav(1)");
+ }
+
+ @Test
+ public void runEntityIdError() {
+ // TODO planned: move to validator
+ // testUri.runEx("$entity").isExSyntax(0);
+ // testUri.runEx("$entity?$idfalse=ESKeyNav(1)").isExSyntax(0);
+ // testUri.runEx("$entity/com.sap.odata.test1.invalidType?$id=ESKeyNav(1)").isExSemantic(0);
+ // testUri.runEx("$entity/invalid?$id=ESKeyNav(1)").isExSyntax(0);
+ }
+
+ @Test
+ public void runEsName() {
+ testUri.run("ESAllPrim")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .isType(EntityTypeProvider.nameETAllPrim, true);
+
+ testUri.run("ESAllPrim/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .isType(EntityTypeProvider.nameETAllPrim, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runEsNameError() {
+
+ testUri.runEx("ESAllPrim/$count/$ref").isExSemantic(0);
+ testUri.runEx("ESAllPrim/$ref/$count").isExSemantic(0);
+ testUri.runEx("ESAllPrim/$ref/invalid").isExSemantic(0);
+ testUri.runEx("ESAllPrim/$count/invalid").isExSemantic(0);
+ testUri.runEx("ESAllPrim(1)/whatever").isExSemantic(0);
+ // testUri.runEx("ESAllPrim(PropertyInt16='1')").isExSemantic(0);
+ testUri.runEx("ESAllPrim(PropertyInt16)").isExSemantic(0);
+ testUri.runEx("ESAllPrim(PropertyInt16=)").isExSyntax(0);
+ testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')").isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim").isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETAllKey")
+ .isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim('1')/com.sap.odata.test1.ETAllKey")
+ .isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim")
+ .isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)")
+ .isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETAllKey")
+ .isExSemantic(0);
+
+ testUri.runEx("ETBaseTwoKeyTwoPrim()")
+ .isExSemantic(0);
+
+ testUri.runEx("ESAllNullable(1)/CollPropertyString/$value")
+ .isExSemantic(0);
+
+ testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value").isExSemantic(0);
+ }
+
+ @Test
+ public void runEsNameCast() {
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim, true)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(-32768)/com.sap.odata.test1.ETTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim, false)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase)
+ .isKeyPredicate(0, "PropertyInt16", "-32768")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase(-32768)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim, false)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase)
+ .isKeyPredicate(0, "PropertyInt16", "-32768");
+
+ testUri.run("ESTwoPrim/Namespace1_Alias.ETTwoBase(-32768)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim, false)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase)
+ .isKeyPredicate(0, "PropertyInt16", "-32768");
+
+ }
+
+ @Test
+ public void runEsNamePpSpCast() {
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false);
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplex/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+ }
+
+ @Test
+ public void runEsNameKey() {
+ testUri.run("ESCollAllPrim(1)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESCollAllPrim");
+
+ testUri.run("ESCollAllPrim(PropertyInt16=1)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESCollAllPrim");
+
+ testUri.run("ESFourKeyAlias(PropertyInt16=1,KeyAlias1=2,KeyAlias2='3',KeyAlias3='4')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESFourKeyAlias")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "KeyAlias1", "2")
+ .isKeyPredicate(2, "KeyAlias2", "'3'")
+ .isKeyPredicate(3, "KeyAlias3", "'4'");
+
+ testUri.run("ESCollAllPrim(null)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESCollAllPrim");
+ }
+
+ @Test
+ public void runEsNameParaKeys() throws UnsupportedEncodingException {
+ 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,"
+ + "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00,"
+ + "PropertyDuration=duration'P10DT5H34M21.123456789012S',"
+ + "PropertyGuid=12345678-1234-1234-1234-123456789012,"
+ + "PropertyTimeOfDay=12:34:55.123456789012)"))
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllKey")
+ .isKeyPredicate(0, "PropertyString", "'O''Neil'")
+ .isKeyPredicate(1, "PropertyBoolean", "true")
+ .isKeyPredicate(2, "PropertyByte", "255")
+ .isKeyPredicate(3, "PropertySByte", "-128")
+ .isKeyPredicate(4, "PropertyInt16", "-32768")
+ .isKeyPredicate(5, "PropertyInt32", "-2147483648")
+ .isKeyPredicate(6, "PropertyInt64", "-9223372036854775808")
+ .isKeyPredicate(7, "PropertyDecimal", "0.1")
+ .isKeyPredicate(8, "PropertyDate", "2013-09-25")
+ .isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00")
+ .isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'")
+ .isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012")
+ .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012");
+ }
+
+ @Test
+ public void runEsNameKeyCast() {
+ /*
+ * testUri.runEx("ESTwoPrim(1)/com.sap.odata.test1.ETBase(1)")
+ * .isExSemantic(0);
+ *
+ * testUri.runEx("ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)")
+ * .isExSemantic(0);
+ *
+ * testUri.runEx("ESBase/com.sap.odata.test1.ETTwoPrim(1)")
+ * .isExSemantic(0);
+ */
+
+ testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBase);
+
+ testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(1)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase(1)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBase);
+
+ testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoPrim")
+ .isType(EntityTypeProvider.nameETTwoPrim)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase);
+ }
+
+ @Test
+ public void runEsNameParaKeysCast() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'");
+ }
+
+ @Test
+ public void run_EsNamePpCp() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplex/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isComplex("PropertyComplex");
+ }
+
+ @Test
+ public void runEsNamePpCpColl() {
+ testUri.run("ESMixPrimCollComp(5)/CollPropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESMixPrimCollComp")
+ .isKeyPredicate(0, "PropertyInt16", "5")
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTTwoPrim, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/CollPropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/CollPropertyComplex/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runEsNamePpCpCast() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri
+ .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplex/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri
+ .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplexTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim)
+ .isTypeFilter(ComplexTypeProvider.nameCTBase);
+
+ testUri
+ .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplexTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim)
+ .isTypeFilter(ComplexTypeProvider.nameCTTwoBase);
+ }
+
+ @Test
+ public void runNsNamePpNp() {
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2");
+
+ testUri.run("ESKeyNav(PropertyInt16=1)/NavPropertyETKeyNavMany(PropertyInt16=2)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2");
+
+ testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/NavPropertyETKeyNavOne")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')"
+ + "/NavPropertyETKeyNavMany(4)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "4");
+
+ testUri.run("ESKeyNav(1)/PropertyComplex/NavPropertyETTwoKeyNavOne")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='(3)')"
+ + "/PropertyComplex/PropertyComplex/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'(3)'")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETMediaMany(2)/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETMediaMany", EntityTypeProvider.nameETMedia, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .n()
+ .isValue();
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')"
+ + "/NavPropertyETKeyNavOne/NavPropertyETMediaOne/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .n()
+ .isNavProperty("NavPropertyETMediaOne", EntityTypeProvider.nameETMedia, false)
+ .n()
+ .isValue();
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')"
+ + "/NavPropertyETKeyNavOne/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .n()
+ .isRef();
+ }
+
+ @Test
+ public void runEsNamePpNpCast() {
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/NavPropertyETKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/NavPropertyETKeyNavMany(3)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "3");
+
+ testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETTwoBaseTwoKeyNav(PropertyInt16=3,PropertyString='4')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESTwoKeyNav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "3")
+ .isKeyPredicate(1, "PropertyString", "'4'")
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')"
+ + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=4,PropertyString='5')"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav/NavPropertyETBaseTwoKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "4")
+ .isKeyPredicate(1, "PropertyString", "'5'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETBaseTwoKeyNavMany", EntityTypeProvider.nameETBaseTwoKeyNav, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/"
+ + "NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=4,PropertyString='5')/"
+ + "NavPropertyETKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "4")
+ .isKeyPredicate(1, "PropertyString", "'5'")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
+ }
+
+ @Test
+ public void runEsNamePpNpRc() {
+ // checks for using referential constrains to fill missing keys
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany('2')").goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicateRef(0, "PropertyInt16", "PropertyInt16")
+ .isKeyPredicate(1, "PropertyString", "'2'");
+
+ testUri.run("ESKeyNav(PropertyInt16=1)/NavPropertyETTwoKeyNavMany(PropertyString='2')").goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicateRef(0, "PropertyInt16", "PropertyInt16")
+ .isKeyPredicate(1, "PropertyString", "'2'");
+
+ }
+
+ @Test
+ public void runEsNamePpSp() {
+ testUri.run("ESAllPrim(1)/PropertyByte")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false);
+
+ testUri.run("ESAllPrim(1)/PropertyByte/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false)
+ .n()
+ .isValue();
+
+ testUri.run("ESMixPrimCollComp(1)/PropertyComplex/PropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESMixPrimCollComp")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+ }
+
+ @Test
+ public void runEsNamePpSpColl() {
+ testUri.run("ESCollAllPrim(1)/CollPropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESCollAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/CollPropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true);
+
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/CollPropertyString/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true)
+ .n()
+ .isCount();
+
+ }
+
+ @Test
+ public void runEsNameRef() {
+ testUri.run("ESAllPrim/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .n()
+ .isRef();
+
+ testUri.run("ESAllPrim(-32768)/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESAllPrim")
+ .isKeyPredicate(0, "PropertyInt16", "-32768")
+ .n()
+ .isRef();
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true)
+ .n()
+ .isRef();
+ testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='2')/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isEntitySet("ESKeyNav")
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'")
+ .n()
+ .isRef();
+ }
+
+ @Test
+ public void runFunctionImpBf() {
+
+ testUri.run("FICRTString()/com.sap.odata.test1.BFCStringRTESTwoKeyNav()");
+ }
+
+ @Test
+ public void runFunctionImpCastBf() {
+
+ testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav"
+ + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isFunction("BFCETBaseTwoKeyNavRTETTwoKeyNav");
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')"
+ + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .n()
+ .isFunction("BFCETBaseTwoKeyNavRTETTwoKeyNav");
+ }
+
+ @Test
+ public void runFunctionImpEntity() {
+
+ testUri.run("FICRTETKeyNav()")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETKeyNav")
+ .isFunction("UFCRTETKeyNav")
+ .isType(EntityTypeProvider.nameETKeyNav);
+
+ testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=2,PropertyString='3')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'");
+
+ testUri.run("FICRTETMedia()/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETMedia")
+ .isFunction("UFCRTETMedia")
+ .n()
+ .isValue();
+
+ testUri.run("FICRTETKeyNav()/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETKeyNav")
+ .isFunction("UFCRTETKeyNav")
+ .n()
+ .isRef();
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/$ref")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .n()
+ .isRef();
+
+ testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=2,PropertyString='3')"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTETTwoKeyNavParam")
+ .isFunction("UFCRTETTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'");
+ }
+
+ @Test
+ public void runFunctionImpEs() {
+ /**/
+ testUri.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESMixPrimCollCompTwoParam")
+ .isFunction("UFCRTESMixPrimCollCompTwoParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isParameter(1, "ParameterString", "'2'")
+ .isType(EntityTypeProvider.nameETMixPrimCollComp);
+
+ testUri.run("FINRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FINRTESMixPrimCollCompTwoParam")
+ .isFunction("UFNRTESMixPrimCollCompTwoParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isParameter(1, "ParameterString", "'2'")
+ .isType(EntityTypeProvider.nameETMixPrimCollComp);
+
+ testUri.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESMixPrimCollCompTwoParam")
+ .isFunction("UFCRTESMixPrimCollCompTwoParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isParameter(1, "ParameterString", "'2'")
+ .isType(EntityTypeProvider.nameETMixPrimCollComp)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runFunctionImpError() {
+ testUri.runEx("FICRTCollCTTwoPrimParam()").isExSemantic(0);
+ testUri.runEx("FICRTCollCTTwoPrimParam(invalidParam=2)").isExSemantic(0);
+ }
+
+ @Test
+ public void runFunctionImpEsAlias() {
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)?@parameterAlias=1");
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)/$count?@parameterAlias=1");
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@invalidAlias)?@validAlias=1");
+ }
+
+ @Test
+ public void runFunctionImpEsCast() {
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav);
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isCount();
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'");
+
+ testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)"
+ + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')"
+ + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isFunctionImport("FICRTESTwoKeyNavParam")
+ .isFunction("UFCRTESTwoKeyNavParam")
+ .isParameter(0, "ParameterInt16", "1")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .isKeyPredicate(0, "PropertyInt16", "2")
+ .isKeyPredicate(1, "PropertyString", "'3'")
+ .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ }
+
+ @Test
+ public void runSingletonEntityValue() {
+ testUri.run("SIMedia/$value")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SIMedia")
+ .n().isValue();
+ }
+
+ @Test
+ public void runSingletonPpNpCast() {
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
+
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany(1)")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1");
+
+ }
+
+ @Test
+ public void runSingletonPpCpCast() {
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplexTwoPrim/com.sap.odata.test1.CTBase")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isComplex("PropertyComplexTwoPrim")
+ .isType(ComplexTypeProvider.nameCTTwoPrim)
+ .isTypeFilter(ComplexTypeProvider.nameCTBase);
+
+ }
+
+ @Test
+ public void runSingletonPpSpCast() {
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyInt16")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/CollPropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .isType(EntityTypeProvider.nameETTwoKeyNav)
+ .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav)
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true)
+ .isType(PropertyProvider.nameString, true);
+
+ }
+
+ @Test
+ public void runSingletonEntityPpNp() {
+ testUri.run("SINav/NavPropertyETKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
+
+ testUri.run("SINav/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='2')")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false)
+ .isKeyPredicate(0, "PropertyInt16", "1")
+ .isKeyPredicate(1, "PropertyString", "'2'");
+
+ }
+
+ @Test
+ public void runSingletonEntityPpCp() {
+ testUri.run("SINav/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isComplex("PropertyComplex");
+
+ testUri.run("SINav/PropertyComplex/PropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isComplex("PropertyComplex")
+ .n()
+ .isComplex("PropertyComplex");
+
+ }
+
+ @Test
+ public void runSingletonEntityPpCpColl() {
+ testUri.run("SINav/CollPropertyComplex")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true);
+
+ testUri.run("SINav/CollPropertyComplex/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isComplex("CollPropertyComplex")
+ .isType(ComplexTypeProvider.nameCTPrimComp, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runSingletonEntityPpSp() {
+ testUri.run("SINav/PropertyString")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false);
+ }
+
+ @Test
+ public void runSingletonEntityPpSpColl() {
+ testUri.run("SINav/CollPropertyString")
+
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true);
+ testUri.run("SINav/CollPropertyString/$count")
+ .isKind(UriInfoKind.resource).goPath()
+ .first()
+ .isSingleton("SINav")
+ .n()
+ .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true)
+ .n()
+ .isCount();
+ }
+
+ @Test
+ public void runExpand() {
+
+ testUri.run("ESKeyNav(1)?$expand=*")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .isSegmentStar(0);
+
+ testUri.run("ESKeyNav(1)?$expand=*/$ref")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .isSegmentStar(0)
+ .isSegmentRef(1);
+
+ testUri.run("ESKeyNav(1)?$expand=*/$ref,NavPropertyETKeyNavMany")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .isSegmentStar(0).isSegmentRef(1)
+ .next()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true);
+
+ testUri.run("ESKeyNav(1)?$expand=*($levels=3)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .isSegmentStar(0)
+ .isLevelText("3");
+
+ testUri.run("ESKeyNav(1)?$expand=*($levels=max)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .isSegmentStar(0)
+ .isLevelText("max");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef();
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$ref")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .isType(EntityTypeProvider.nameETKeyNav, false)
+ .n().isRef();
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($filter=PropertyInt16 eq 1)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator().isFilterSerialized("<<PropertyInt16> eq <1>>");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($orderby=PropertyInt16)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isSortOrder(0, false)
+ .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isSkipText("1");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($top=2)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isTopText("2");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($count=true)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isInlineCountText("true");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1;$top=3)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isSkipText("1")
+ .isTopText("3");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1%3b$top=3)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isRef()
+ .goUpExpandValidator()
+ .isSkipText("1")
+ .isTopText("3");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isCount();
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$count")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false)
+ .isType(EntityTypeProvider.nameETKeyNav, false)
+ .n().isCount();
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count($filter=PropertyInt16 gt 1)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .n().isCount()
+ .goUpExpandValidator()
+ .isFilterSerialized("<<PropertyInt16> gt <1>>");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($filter=PropertyInt16 eq 1)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .goUpExpandValidator()
+ .isFilterSerialized("<<PropertyInt16> eq <1>>");
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($orderby=PropertyInt16)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true)
+ .isType(EntityTypeProvider.nameETKeyNav, true)
+ .goUpExpandValidator()
+ .isSortOrder(0, false)
+ .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false);
+
+ testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1)")
+ .isKind(UriInfoKind.resource).goPath().goExpand()
+ .first()
+ .goPath().first()
+ .isNavProperty("NavPropertyETKeyNavMa
<TRUNCATED>
[5/5] git commit: [OLINGO-266] server-test module introduced
Posted by sk...@apache.org.
[OLINGO-266] server-test module introduced
Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo
Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/7916df52
Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/7916df52
Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/7916df52
Branch: refs/heads/olingo-266-ref
Commit: 7916df52e6bf8be25449d76495da1b84994bd529
Parents: a98d3b4
Author: Stephan Klevenz <st...@sap.com>
Authored: Tue May 13 14:49:26 2014 +0200
Committer: Stephan Klevenz <st...@sap.com>
Committed: Tue May 13 14:49:26 2014 +0200
----------------------------------------------------------------------
lib/pom.xml | 1 +
lib/server-tecsvc/pom.xml | 43 +-
lib/server-test/pom.xml | 86 +
.../serializer/json/ServiceDocumentTest.java | 133 +
.../serializer/xml/MetadataDocumentTest.java | 254 +
.../olingo/server/core/uri/RawUriTest.java | 151 +
.../olingo/server/core/uri/UriInfoImplTest.java | 201 +
.../server/core/uri/UriResourceImplTest.java | 508 ++
.../core/uri/antlr/TestFullResourcePath.java | 5110 ++++++++++++++++++
.../olingo/server/core/uri/antlr/TestLexer.java | 248 +
.../core/uri/antlr/TestUriParserImpl.java | 1144 ++++
.../core/uri/queryoption/QueryOptionTest.java | 303 ++
.../queryoption/expression/ExpressionTest.java | 239 +
.../core/uri/testutil/EdmTechTestProvider.java | 100 +
.../core/uri/testutil/ExpandValidator.java | 230 +
.../core/uri/testutil/FilterTreeToText.java | 154 +
.../core/uri/testutil/FilterValidator.java | 534 ++
.../core/uri/testutil/ParseTreeToText.java | 82 +
.../core/uri/testutil/ParserValidator.java | 162 +
.../core/uri/testutil/ParserWithLogging.java | 56 +
.../core/uri/testutil/ResourceValidator.java | 599 ++
.../core/uri/testutil/TestErrorLogger.java | 105 +
.../core/uri/testutil/TestUriValidator.java | 258 +
.../server/core/uri/testutil/TestValidator.java | 23 +
.../core/uri/testutil/TokenValidator.java | 194 +
.../core/uri/testutil/UriLexerWithTrace.java | 85 +
.../core/uri/validator/UriValidatorTest.java | 378 ++
.../src/test/resources/simplelogger.properties | 20 +
28 files changed, 11399 insertions(+), 2 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/pom.xml
----------------------------------------------------------------------
diff --git a/lib/pom.xml b/lib/pom.xml
index 2cea272..3afb6f6 100644
--- a/lib/pom.xml
+++ b/lib/pom.xml
@@ -43,5 +43,6 @@
<module>server-api</module>
<module>server-core</module>
<module>server-tecsvc</module>
+ <module>server-test</module>
</modules>
</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-tecsvc/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-tecsvc/pom.xml b/lib/server-tecsvc/pom.xml
index 717ad60..cd345a4 100644
--- a/lib/server-tecsvc/pom.xml
+++ b/lib/server-tecsvc/pom.xml
@@ -34,6 +34,45 @@
<relativePath>..</relativePath>
</parent>
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-jar-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>make-a-jar</id>
+ <phase>compile</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-install-plugin</artifactId>
+ <executions>
+ <execution>
+ <phase>install</phase>
+ <goals>
+ <goal>install-file</goal>
+ </goals>
+ <configuration>
+ <packaging>jar</packaging>
+ <artifactId>${project.artifactId}</artifactId>
+ <groupId>${project.groupId}</groupId>
+ <version>${project.version}</version>
+ <file>
+ ${project.build.directory}/${project.artifactId}-${project.version}.jar
+ </file>
+ </configuration>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
<dependencies>
<dependency>
<groupId>javax.servlet</groupId>
@@ -53,7 +92,7 @@
<version>${project.version}</version>
<scope>runtime</scope>
</dependency>
-
+
<dependency>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
@@ -64,7 +103,7 @@
<artifactId>slf4j-simple</artifactId>
<scope>runtime</scope>
</dependency>
-
+
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/pom.xml
----------------------------------------------------------------------
diff --git a/lib/server-test/pom.xml b/lib/server-test/pom.xml
new file mode 100644
index 0000000..865f75d
--- /dev/null
+++ b/lib/server-test/pom.xml
@@ -0,0 +1,86 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!--
+
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+
+-->
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
+ xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
+ <modelVersion>4.0.0</modelVersion>
+
+ <artifactId>olingo-server-test</artifactId>
+ <packaging>jar</packaging>
+ <name>${project.artifactId}</name>
+
+ <parent>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-lib</artifactId>
+ <version>0.1.0-SNAPSHOT</version>
+ <relativePath>..</relativePath>
+ </parent>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-server-core</artifactId>
+ <version>${project.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.apache.olingo</groupId>
+ <artifactId>olingo-server-tecsvc</artifactId>
+ <version>${project.version}</version>
+<!-- <type>jar</type> -->
+ </dependency>
+ <dependency>
+ <groupId>junit</groupId>
+ <artifactId>junit</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-all</artifactId>
+ </dependency>
+ <dependency>
+ <groupId>commons-logging</groupId>
+ <artifactId>commons-logging</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>org.slf4j</groupId>
+ <artifactId>slf4j-simple</artifactId>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
+ <groupId>commons-io</groupId>
+ <artifactId>commons-io</artifactId>
+ <scope>test</scope>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-deploy-plugin</artifactId>
+ <configuration>
+ <skip>false</skip>
+ </configuration>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
new file mode 100644
index 0000000..8713348
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java
@@ -0,0 +1,133 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer.json;
+
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityContainer;
+import org.apache.olingo.commons.api.edm.EdmEntitySet;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmSingleton;
+import org.apache.olingo.server.api.ODataServer;
+import org.apache.olingo.server.api.serializer.ODataFormat;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.junit.Before;
+import org.junit.Test;
+
+public class ServiceDocumentTest {
+
+ private Edm edm;
+
+ @Before
+ public void before() {
+
+ EdmEntitySet edmEntitySet1 = mock(EdmEntitySet.class);
+ when(edmEntitySet1.getName()).thenReturn("entitySetName1");
+ when(edmEntitySet1.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmEntitySet edmEntitySet2 = mock(EdmEntitySet.class);
+ when(edmEntitySet2.getName()).thenReturn("entitySetName2");
+ when(edmEntitySet2.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmEntitySet edmEntitySet3 = mock(EdmEntitySet.class);
+ when(edmEntitySet3.getName()).thenReturn("entitySetName3");
+ when(edmEntitySet3.isIncludeInServiceDocument()).thenReturn(false);
+
+ List<EdmEntitySet> entitySets = new ArrayList<EdmEntitySet>();
+ entitySets.add(edmEntitySet1);
+ entitySets.add(edmEntitySet2);
+ entitySets.add(edmEntitySet3);
+
+ EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class);
+ when(functionImport1.getName()).thenReturn("functionImport1");
+ when(functionImport1.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmFunctionImport functionImport2 = mock(EdmFunctionImport.class);
+ when(functionImport2.getName()).thenReturn("functionImport2");
+ when(functionImport2.isIncludeInServiceDocument()).thenReturn(true);
+
+ EdmFunctionImport functionImport3 = mock(EdmFunctionImport.class);
+ when(functionImport3.getName()).thenReturn("functionImport3");
+ when(functionImport3.isIncludeInServiceDocument()).thenReturn(false);
+
+ List<EdmFunctionImport> functionImports = new ArrayList<EdmFunctionImport>();
+ functionImports.add(functionImport1);
+ functionImports.add(functionImport2);
+ functionImports.add(functionImport3);
+
+ EdmSingleton singleton1 = mock(EdmSingleton.class);
+ when(singleton1.getName()).thenReturn("singleton1");
+
+ EdmSingleton singleton2 = mock(EdmSingleton.class);
+ when(singleton2.getName()).thenReturn("singleton2");
+
+ EdmSingleton singleton3 = mock(EdmSingleton.class);
+ when(singleton3.getName()).thenReturn("singleton3");
+
+ List<EdmSingleton> singletons = new ArrayList<EdmSingleton>();
+ singletons.add(singleton1);
+ singletons.add(singleton2);
+ singletons.add(singleton3);
+
+ EdmEntityContainer edmEntityContainer = mock(EdmEntityContainer.class);
+ when(edmEntityContainer.getEntitySets()).thenReturn(entitySets);
+ when(edmEntityContainer.getFunctionImports()).thenReturn(functionImports);
+ when(edmEntityContainer.getSingletons()).thenReturn(singletons);
+
+ edm = mock(Edm.class);
+ when(edm.getEntityContainer(null)).thenReturn(edmEntityContainer);
+ }
+
+ @Test
+ public void writeServiceDocumentJson() throws Exception {
+ String serviceRoot = "http://localhost:8080/odata.svc";
+
+ ODataServer server = ODataServer.newInstance();
+ assertNotNull(server);
+
+ ODataSerializer serializer = server.getSerializer(ODataFormat.JSON);
+ assertNotNull(serializer);
+
+ InputStream result = serializer.serviceDocument(edm, serviceRoot);
+ assertNotNull(result);
+ String jsonString = IOUtils.toString(result);
+
+ assertTrue(jsonString.contains("entitySetName1"));
+ assertTrue(jsonString.contains("entitySetName2"));
+ assertFalse(jsonString.contains("entitySetName3"));
+
+ assertTrue(jsonString.contains("functionImport1"));
+ assertTrue(jsonString.contains("functionImport2"));
+ assertFalse(jsonString.contains("functionImport3"));
+
+ assertTrue(jsonString.contains("singleton1"));
+ assertTrue(jsonString.contains("singleton2"));
+ assertTrue(jsonString.contains("singleton3"));
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
new file mode 100644
index 0000000..17ac957
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java
@@ -0,0 +1,254 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.serializer.xml;
+
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.commons.io.IOUtils;
+import org.apache.olingo.commons.api.ODataException;
+import org.apache.olingo.commons.api.ODataRuntimeException;
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.FullQualifiedName;
+import org.apache.olingo.commons.api.edm.Target;
+import org.apache.olingo.server.api.ODataServer;
+import org.apache.olingo.server.api.edm.provider.Action;
+import org.apache.olingo.server.api.edm.provider.ActionImport;
+import org.apache.olingo.server.api.edm.provider.ComplexType;
+import org.apache.olingo.server.api.edm.provider.EdmProvider;
+import org.apache.olingo.server.api.edm.provider.EntityContainer;
+import org.apache.olingo.server.api.edm.provider.EntitySet;
+import org.apache.olingo.server.api.edm.provider.EntityType;
+import org.apache.olingo.server.api.edm.provider.EnumMember;
+import org.apache.olingo.server.api.edm.provider.EnumType;
+import org.apache.olingo.server.api.edm.provider.Function;
+import org.apache.olingo.server.api.edm.provider.FunctionImport;
+import org.apache.olingo.server.api.edm.provider.NavigationProperty;
+import org.apache.olingo.server.api.edm.provider.NavigationPropertyBinding;
+import org.apache.olingo.server.api.edm.provider.Parameter;
+import org.apache.olingo.server.api.edm.provider.Property;
+import org.apache.olingo.server.api.edm.provider.ReturnType;
+import org.apache.olingo.server.api.edm.provider.Schema;
+import org.apache.olingo.server.api.edm.provider.Singleton;
+import org.apache.olingo.server.api.edm.provider.TypeDefinition;
+import org.apache.olingo.server.api.serializer.ODataFormat;
+import org.apache.olingo.server.api.serializer.ODataSerializer;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
+import org.junit.Test;
+
+public class MetadataDocumentTest {
+
+ @Test(expected = ODataRuntimeException.class)
+ public void metadataOnJsonResultsInException() {
+ ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.JSON);
+ serializer.metadataDocument(mock(Edm.class));
+ }
+
+ @Test
+ public void writeMetadataWithEmptyMockedEdm() {
+ ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML);
+ Edm edm = mock(Edm.class);
+ serializer.metadataDocument(edm);
+ }
+
+ @Test
+ public void writeMetadataWithLocalTestEdm() throws Exception {
+ ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML);
+ Edm edm = new EdmProviderImpl(new TestMetadataProvider());
+ InputStream metadata = serializer.metadataDocument(edm);
+ assertNotNull(metadata);
+
+ String metadataString = IOUtils.toString(metadata);
+ assertTrue(metadataString
+ .contains("<edmx:Edmx Version=\"4.0\" xmlns:edmx=\"http://docs.oasis-open.org/odata/ns/edmx\">"));
+
+ assertTrue(metadataString
+ .contains("<Schema xmlns=\"http://docs.oasis-open.org/odata/ns/edm\" " +
+ "Namespace=\"namespace\" Alias=\"alias\">"));
+
+ assertTrue(metadataString
+ .contains("<EntityType Name=\"ETBaseName\"><Property Name=\"P1\" Type=\"Edm.Int16\"/><NavigationProperty " +
+ "Name=\"N1\" Type=\"namespace.ETBaseName\" Nullable=\"true\" Partner=\"N1\"/></EntityType>"));
+
+ assertTrue(metadataString
+ .contains("<EntityType Name=\"ETDerivedName\" BaseType=\"namespace.ETBaseName\"><Property Name=\"P2\" " +
+ "Type=\"Edm.Int16\"/><NavigationProperty Name=\"N2\" Type=\"namespace.ETDerivedName\" Nullable=\"true\" " +
+ "Partner=\"N2\"/></EntityType>"));
+
+ assertTrue(metadataString
+ .contains("<ComplexType Name=\"CTBaseName\"><Property Name=\"P1\" Type=\"Edm.Int16\"/><NavigationProperty " +
+ "Name=\"N1\" Type=\"namespace.ETBaseName\" Nullable=\"true\" Partner=\"N1\"/></ComplexType>"));
+
+ assertTrue(metadataString
+ .contains("<ComplexType Name=\"CTDerivedName\" BaseType=\"namespace.CTBaseName\"><Property Name=\"P2\" " +
+ "Type=\"Edm.Int16\"/><NavigationProperty Name=\"N2\" Type=\"namespace.ETDerivedName\" Nullable=\"true\" " +
+ "Partner=\"N2\"/></ComplexType>"));
+
+ assertTrue(metadataString.contains("<TypeDefinition Name=\"typeDef\" Type=\"Edm.Int16\"/>"));
+
+ assertTrue(metadataString.contains("<Action Name=\"ActionWOParameter\" IsBound=\"false\"/>"));
+
+ assertTrue(metadataString
+ .contains("<Action Name=\"ActionName\" IsBound=\"true\"><Parameter Name=\"param\" Type=\"Edm.Int16\"/>" +
+ "<Parameter Name=\"param2\" Type=\"Collection(Edm.Int16)\"/><ReturnType Type=\"namespace.CTBaseName\"/>" +
+ "</Action>"));
+
+ assertTrue(metadataString
+ .contains("<Function Name=\"FunctionWOParameter\" IsBound=\"false\" IsComposable=\"false\"><ReturnType " +
+ "Type=\"namespace.CTBaseName\"/></Function>"));
+
+ assertTrue(metadataString
+ .contains("<Function Name=\"FunctionName\" IsBound=\"true\" IsComposable=\"false\"><Parameter Name=\"param\" " +
+ "Type=\"Edm.Int16\"/><Parameter Name=\"param2\" Type=\"Collection(Edm.Int16)\"/><ReturnType " +
+ "Type=\"namespace.CTBaseName\"/></Function>"));
+
+ assertTrue(metadataString.contains("<EntityContainer Name=\"container\">"));
+
+ assertTrue(metadataString
+ .contains("<EntitySet Name=\"EntitySetName\" EntityType=\"namespace.ETBaseName\"><NavigationPropertyBinding " +
+ "Path=\"N1\" Target=\"namespace.container/EntitySetName\"/></EntitySet>"));
+ assertTrue(metadataString
+ .contains("<Singleton Name=\"SingletonName\" EntityType=\"namespace.ETBaseName\"><NavigationPropertyBinding " +
+ "Path=\"N1\" Target=\"namespace.container/EntitySetName\"/></Singleton>"));
+
+ assertTrue(metadataString.contains("<ActionImport Name=\"actionImport\" Action=\"namespace.ActionWOParameter\"/>"));
+
+ assertTrue(metadataString
+ .contains("<FunctionImport Name=\"actionImport\" Function=\"namespace.FunctionName\" " +
+ "EntitySet=\"namespace.EntitySetName\" IncludeInServiceDocument=\"false\"/>"));
+
+ assertTrue(metadataString.contains("</EntityContainer></Schema></edmx:DataServices></edmx:Edmx>"));
+ }
+
+ @Test
+ public void writeMetadataWithTechnicalScenario() {
+ ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML);
+ EdmProviderImpl edm = new EdmProviderImpl(new EdmTechProvider());
+ InputStream metadata = serializer.metadataDocument(edm);
+ assertNotNull(metadata);
+ // The technical scenario is too big to verify. We are content for now to make sure we can serialize it.
+ // System.out.println(StringUtils.inputStreamToString(metadata, false));
+ }
+
+ private class TestMetadataProvider extends EdmProvider {
+
+ @Override
+ public List<Schema> getSchemas() throws ODataException {
+ Property p1 = new Property().setName("P1").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName());
+ String ns = "namespace";
+ NavigationProperty n1 = new NavigationProperty().setName("N1")
+ .setType(new FullQualifiedName(ns, "ETBaseName")).setNullable(true).setPartner("N1");
+ Property p2 = new Property().setName("P2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName());
+ NavigationProperty n2 = new NavigationProperty().setName("N2")
+ .setType(new FullQualifiedName(ns, "ETDerivedName")).setNullable(true).setPartner("N2");
+ Schema schema = new Schema().setNamespace(ns).setAlias("alias");
+ List<ComplexType> complexTypes = new ArrayList<ComplexType>();
+ schema.setComplexTypes(complexTypes);
+ ComplexType ctBase =
+ new ComplexType().setName("CTBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties(
+ Arrays.asList(n1));
+ complexTypes.add(ctBase);
+ ComplexType ctDerived =
+ new ComplexType().setName("CTDerivedName").setBaseType(new FullQualifiedName(ns, "CTBaseName"))
+ .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2));
+ complexTypes.add(ctDerived);
+
+ List<EntityType> entityTypes = new ArrayList<EntityType>();
+ schema.setEntityTypes(entityTypes);
+ EntityType etBase =
+ new EntityType().setName("ETBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties(
+ Arrays.asList(n1));
+ entityTypes.add(etBase);
+ EntityType etDerived =
+ new EntityType().setName("ETDerivedName").setBaseType(new FullQualifiedName(ns, "ETBaseName"))
+ .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2));
+ entityTypes.add(etDerived);
+
+ List<Action> actions = new ArrayList<Action>();
+ schema.setActions(actions);
+ // TODO:EntitySetPath
+ actions.add((new Action().setName("ActionWOParameter")));
+ List<Parameter> parameters = new ArrayList<Parameter>();
+ parameters.add(new Parameter().setName("param").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()));
+ parameters.add(new Parameter().setName("param2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())
+ .setCollection(true));
+ actions.add(new Action().setName("ActionName").setBound(true).setParameters(parameters).setReturnType(
+ new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName"))));
+
+ List<Function> functions = new ArrayList<Function>();
+ schema.setFunctions(functions);
+ functions.add((new Function().setName("FunctionWOParameter")
+ .setReturnType(new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName")))));
+ functions.add(new Function().setName("FunctionName").setBound(true).setParameters(parameters).setReturnType(
+ new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName"))));
+
+ List<EnumType> enumTypes = new ArrayList<EnumType>();
+ schema.setEnumTypes(enumTypes);
+ List<EnumMember> members = new ArrayList<EnumMember>();
+ members.add(new EnumMember().setName("member").setValue("1"));
+ enumTypes.add(new EnumType().setName("EnumName").setFlags(true).setMembers(members));
+
+ List<TypeDefinition> typeDefinitions = new ArrayList<TypeDefinition>();
+ schema.setTypeDefinitions(typeDefinitions);
+ typeDefinitions.add(new TypeDefinition().setName("typeDef")
+ .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()));
+
+ EntityContainer container = new EntityContainer().setName("container");
+ schema.setEntityContainer(container);
+
+ List<ActionImport> actionImports = new ArrayList<ActionImport>();
+ container.setActionImports(actionImports);
+ actionImports.add(new ActionImport().setName("actionImport").setAction(
+ new FullQualifiedName(ns, "ActionWOParameter")).setEntitySet(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+
+ List<FunctionImport> functionImports = new ArrayList<FunctionImport>();
+ container.setFunctionImports(functionImports);
+ functionImports.add(new FunctionImport().setName("actionImport").setFunction(
+ new FullQualifiedName(ns, "FunctionName")).setEntitySet(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+
+ List<EntitySet> entitySets = new ArrayList<EntitySet>();
+ container.setEntitySets(entitySets);
+ List<NavigationPropertyBinding> nPB = new ArrayList<NavigationPropertyBinding>();
+ nPB.add(new NavigationPropertyBinding().setPath("N1").setTarget(
+ new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName")));
+ entitySets.add(new EntitySet().setName("EntitySetName").setType(new FullQualifiedName(ns, "ETBaseName"))
+ .setNavigationPropertyBindings(nPB));
+
+ List<Singleton> singletons = new ArrayList<Singleton>();
+ container.setSingletons(singletons);
+ singletons.add(new Singleton().setName("SingletonName").setType(new FullQualifiedName(ns, "ETBaseName"))
+ .setNavigationPropertyBindings(nPB));
+
+ List<Schema> schemas = new ArrayList<Schema>();
+ schemas.add(schema);
+ return schemas;
+ }
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
new file mode 100644
index 0000000..f54ad57
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java
@@ -0,0 +1,151 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.server.core.uri.parser.RawUri;
+import org.apache.olingo.server.core.uri.parser.UriDecoder;
+import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException;
+import org.junit.Test;
+
+public class RawUriTest {
+
+ private RawUri runRawParser(final String uri, final int scipSegments) throws UriParserSyntaxException {
+ return UriDecoder.decodeUri(uri, scipSegments);
+ }
+
+ @Test
+ public void testOption() throws Exception {
+ RawUri rawUri;
+ rawUri = runRawParser("?", 0);
+ checkOptionCount(rawUri, 0);
+
+ rawUri = runRawParser("?a", 0);
+ checkOption(rawUri, 0, "a", "");
+
+ rawUri = runRawParser("?a=b", 0);
+ checkOption(rawUri, 0, "a", "b");
+
+ rawUri = runRawParser("?=", 0);
+ checkOption(rawUri, 0, "", "");
+
+ rawUri = runRawParser("?=b", 0);
+ checkOption(rawUri, 0, "", "b");
+
+ rawUri = runRawParser("?a&c", 0);
+ checkOption(rawUri, 0, "a", "");
+ checkOption(rawUri, 1, "c", "");
+
+ rawUri = runRawParser("?a=b&c", 0);
+ checkOption(rawUri, 0, "a", "b");
+ checkOption(rawUri, 1, "c", "");
+
+ rawUri = runRawParser("?a=b&c=d", 0);
+ checkOption(rawUri, 0, "a", "b");
+ checkOption(rawUri, 1, "c", "d");
+
+ rawUri = runRawParser("?=&=", 0);
+ checkOption(rawUri, 0, "", "");
+ checkOption(rawUri, 1, "", "");
+
+ rawUri = runRawParser("?=&c=d", 0);
+ checkOption(rawUri, 0, "", "");
+ checkOption(rawUri, 1, "c", "d");
+ }
+
+ private void checkOption(final RawUri rawUri, final int index, final String name, final String value) {
+ RawUri.QueryOption option = rawUri.queryOptionListDecoded.get(index);
+
+ assertEquals(name, option.name);
+ assertEquals(value, option.value);
+
+ }
+
+ private void checkOptionCount(final RawUri rawUri, final int count) {
+ assertEquals(count, rawUri.queryOptionListDecoded.size());
+ }
+
+ @Test
+ public void testPath() throws Exception {
+ RawUri rawUri;
+
+ rawUri = runRawParser("http://test.org", 0);
+ checkPath(rawUri, "", new ArrayList<String>());
+
+ rawUri = runRawParser("http://test.org/", 0);
+ checkPath(rawUri, "/", Arrays.asList(""));
+
+ rawUri = runRawParser("http://test.org/entitySet", 0);
+ checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
+
+ rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 0);
+ checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
+
+ rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 1);
+ checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet"));
+
+ rawUri = runRawParser("", 0);
+ checkPath(rawUri, "", new ArrayList<String>());
+
+ rawUri = runRawParser("/", 0);
+ checkPath(rawUri, "/", Arrays.asList(""));
+
+ rawUri = runRawParser("/entitySet", 0);
+ checkPath(rawUri, "/entitySet", Arrays.asList("entitySet"));
+
+ rawUri = runRawParser("entitySet", 0);
+ checkPath(rawUri, "entitySet", Arrays.asList("entitySet"));
+
+ rawUri = runRawParser("nonServiceSegment/entitySet", 0);
+ checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet"));
+
+ rawUri = runRawParser("nonServiceSegment/entitySet", 1);
+ checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet"));
+
+ rawUri = runRawParser("http://test.org/a?abc=xx+yz", 0);
+ }
+
+ @Test
+ public void testSplitt() {
+ UriDecoder.splitt("", '/');
+ UriDecoder.splitt("/", '/');
+ UriDecoder.splitt("a", '/');
+ UriDecoder.splitt("a/", '/');
+ UriDecoder.splitt("/a", '/');
+ UriDecoder.splitt("a/a", '/');
+ }
+
+ private void checkPath(final RawUri rawUri, final String path, final List<String> list) {
+ assertEquals(path, rawUri.path);
+
+ assertEquals(list.size(), rawUri.pathSegmentListDecoded.size());
+
+ int i = 0;
+ while (i < list.size()) {
+ assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i));
+ i++;
+ }
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java
new file mode 100644
index 0000000..a71762c
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.server.api.uri.UriInfoAll;
+import org.apache.olingo.server.api.uri.UriInfoBatch;
+import org.apache.olingo.server.api.uri.UriInfoCrossjoin;
+import org.apache.olingo.server.api.uri.UriInfoEntityId;
+import org.apache.olingo.server.api.uri.UriInfoKind;
+import org.apache.olingo.server.api.uri.UriInfoMetadata;
+import org.apache.olingo.server.api.uri.UriInfoResource;
+import org.apache.olingo.server.api.uri.UriInfoService;
+import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.uri.queryoption.CountOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.FormatOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.IdOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.LevelsOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SearchOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SkipOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.SkipTokenOptionImpl;
+import org.apache.olingo.server.core.uri.queryoption.TopOptionImpl;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+import org.junit.Test;
+
+public class UriInfoImplTest {
+
+ Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
+
+ @Test
+ public void testKind() {
+ UriInfoImpl uriInfo = new UriInfoImpl().setKind(UriInfoKind.all);
+ assertEquals(UriInfoKind.all, uriInfo.getKind());
+ }
+
+ @Test
+ public void testCasts() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+
+ UriInfoAll all = uriInfo.asUriInfoAll();
+ assertEquals(uriInfo, all);
+
+ UriInfoBatch batch = uriInfo.asUriInfoBatch();
+ assertEquals(uriInfo, batch);
+
+ UriInfoCrossjoin crossjoin = uriInfo.asUriInfoCrossjoin();
+ assertEquals(uriInfo, crossjoin);
+
+ UriInfoEntityId entityID = uriInfo.asUriInfoEntityId();
+ assertEquals(uriInfo, entityID);
+
+ UriInfoMetadata metadata = uriInfo.asUriInfoMetadata();
+ assertEquals(uriInfo, metadata);
+
+ UriInfoResource resource = uriInfo.asUriInfoResource();
+ assertEquals(uriInfo, resource);
+
+ UriInfoService service = uriInfo.asUriInfoService();
+ assertEquals(uriInfo, service);
+
+ }
+
+ @Test
+ public void testEntityNames() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+ uriInfo.addEntitySetName("A");
+ uriInfo.addEntitySetName("B");
+
+ assertEquals("A", uriInfo.getEntitySetNames().get(0));
+ assertEquals("B", uriInfo.getEntitySetNames().get(1));
+
+ }
+
+ @Test
+ public void testResourceParts() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+
+ UriResourceActionImpl action = new UriResourceActionImpl();
+ UriResourceEntitySetImpl entitySet0 = new UriResourceEntitySetImpl();
+ UriResourceEntitySetImpl entitySet1 = new UriResourceEntitySetImpl();
+
+ uriInfo.addResourcePart(action);
+ uriInfo.addResourcePart(entitySet0);
+
+ assertEquals(action, uriInfo.getUriResourceParts().get(0));
+ assertEquals(entitySet0, uriInfo.getUriResourceParts().get(1));
+
+ assertEquals(entitySet0, uriInfo.getLastResourcePart());
+
+ uriInfo.addResourcePart(entitySet1);
+ assertEquals(entitySet1, uriInfo.getLastResourcePart());
+ }
+
+ @Test
+ public void testCustomQueryOption() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+
+ List<QueryOptionImpl> queryOptions = new ArrayList<QueryOptionImpl>();
+
+ ExpandOptionImpl expand = new ExpandOptionImpl();
+ FilterOptionImpl filter = new FilterOptionImpl();
+ FormatOptionImpl format = new FormatOptionImpl();
+ IdOptionImpl id = new IdOptionImpl();
+ CountOptionImpl inlinecount = new CountOptionImpl();
+ OrderByOptionImpl orderby = new OrderByOptionImpl();
+ SearchOptionImpl search = new SearchOptionImpl();
+ SelectOptionImpl select = new SelectOptionImpl();
+ SkipOptionImpl skip = new SkipOptionImpl();
+ SkipTokenOptionImpl skipToken = new SkipTokenOptionImpl();
+ TopOptionImpl top = new TopOptionImpl();
+ LevelsOptionImpl levels = new LevelsOptionImpl();
+
+ CustomQueryOptionImpl customOption0 = new CustomQueryOptionImpl();
+ customOption0.setText("A");
+ CustomQueryOptionImpl customOption1 = new CustomQueryOptionImpl();
+ customOption1.setText("B");
+
+ 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
+ uriInfo.setQueryOptions(queryOptions);
+
+ assertEquals(expand, uriInfo.getExpandOption());
+ assertEquals(filter, uriInfo.getFilterOption());
+ assertEquals(format, uriInfo.getFormatOption());
+ assertEquals(id, uriInfo.getIdOption());
+ assertEquals(inlinecount, uriInfo.getCountOption());
+ assertEquals(orderby, uriInfo.getOrderByOption());
+ assertEquals(search, uriInfo.getSearchOption());
+ assertEquals(select, uriInfo.getSelectOption());
+ assertEquals(skip, uriInfo.getSkipOption());
+ assertEquals(skipToken, uriInfo.getSkipTokenOption());
+ assertEquals(top, uriInfo.getTopOption());
+
+ List<CustomQueryOption> customQueryOptions = uriInfo.getCustomQueryOptions();
+ assertEquals(customOption0, customQueryOptions.get(0));
+ assertEquals(customOption1, customQueryOptions.get(1));
+ }
+
+ @Test
+ public void testFragment() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+ uriInfo.setFragment("F");
+ assertEquals("F", uriInfo.getFragment());
+ }
+
+ @Test
+ public void testEntityTypeCast() {
+ UriInfoImpl uriInfo = new UriInfoImpl();
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
+ assertNotNull(entityType);
+
+ uriInfo.setEntityTypeCast(entityType);
+ assertEquals(entityType, uriInfo.getEntityTypeCast());
+ }
+}
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/7916df52/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
----------------------------------------------------------------------
diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
new file mode 100644
index 0000000..d6beef0
--- /dev/null
+++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java
@@ -0,0 +1,508 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ */
+package org.apache.olingo.server.core.uri;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+
+import org.apache.olingo.commons.api.edm.Edm;
+import org.apache.olingo.commons.api.edm.EdmAction;
+import org.apache.olingo.commons.api.edm.EdmActionImport;
+import org.apache.olingo.commons.api.edm.EdmEntityType;
+import org.apache.olingo.commons.api.edm.EdmFunction;
+import org.apache.olingo.commons.api.edm.EdmFunctionImport;
+import org.apache.olingo.commons.api.edm.EdmNavigationProperty;
+import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind;
+import org.apache.olingo.commons.api.edm.EdmProperty;
+import org.apache.olingo.commons.api.edm.EdmType;
+import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory;
+import org.apache.olingo.server.api.uri.UriResourceKind;
+import org.apache.olingo.server.core.edm.provider.EdmComplexTypeImpl;
+import org.apache.olingo.server.core.edm.provider.EdmEntitySetImpl;
+import org.apache.olingo.server.core.edm.provider.EdmProviderImpl;
+import org.apache.olingo.server.core.edm.provider.EdmSingletonImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl;
+import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl;
+import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider;
+import org.apache.olingo.server.tecsvc.provider.ActionProvider;
+import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider;
+import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider;
+import org.junit.Test;
+
+public class UriResourceImplTest {
+
+ Edm edm = new EdmProviderImpl(new EdmTechTestProvider());
+
+ @Test
+ public void testUriParameterImpl() {
+ UriParameterImpl impl = new UriParameterImpl();
+ ExpressionImpl expression = new LiteralImpl().setText("Expression");
+
+ impl.setText("Text");
+ impl.setName("A");
+ impl.setAlias("@A");
+ impl.setExpression(expression);
+
+ assertEquals("Text", impl.getText());
+ assertEquals("A", impl.getName());
+ assertEquals("@A", impl.getAlias());
+ assertEquals(expression, impl.getExression());
+ }
+
+ @Test
+ public void testUriResourceActionImpl() {
+ UriResourceActionImpl impl = new UriResourceActionImpl();
+ assertEquals(UriResourceKind.action, impl.getKind());
+ assertEquals("", impl.toString());
+
+ // action
+ EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTETParam);
+ impl.setAction(action);
+ assertEquals(action, impl.getAction());
+ assertEquals(ActionProvider.nameUARTETParam.getName(), impl.toString());
+
+ // action import
+ impl = new UriResourceActionImpl();
+ EdmActionImport actionImport = edm.getEntityContainer(null).getActionImport("AIRTPrimParam");
+ impl.setActionImport(actionImport);
+ assertEquals(actionImport, impl.getActionImport());
+ assertEquals(actionImport.getUnboundAction(), impl.getAction());
+ assertEquals(false, impl.isCollection());
+ assertEquals("AIRTPrimParam", impl.toString());
+ assertEquals(actionImport.getUnboundAction().getReturnType().getType(), impl.getType());
+ }
+
+ @Test
+ public void testUriResourceLambdaAllImpl() {
+ UriResourceLambdaAllImpl impl = new UriResourceLambdaAllImpl();
+ assertEquals(UriResourceKind.lambdaAll, impl.getKind());
+
+ ExpressionImpl expression = new LiteralImpl().setText("Expression");
+ impl.setExpression(expression);
+ impl.setLamdaVariable("A");
+
+ assertEquals(false, impl.isCollection());
+ assertEquals(expression, impl.getExpression());
+ assertEquals("A", impl.getLambdaVariable());
+ assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
+ assertEquals("all", impl.toString());
+ }
+
+ @Test
+ public void testUriResourceLambdaAnyImpl() {
+ UriResourceLambdaAnyImpl impl = new UriResourceLambdaAnyImpl();
+ assertEquals(UriResourceKind.lambdaAny, impl.getKind());
+
+ ExpressionImpl expression = new LiteralImpl().setText("Expression");
+ impl.setExpression(expression);
+ impl.setLamdaVariable("A");
+
+ assertEquals(false, impl.isCollection());
+ assertEquals(expression, impl.getExpression());
+ assertEquals("A", impl.getLamdaVariable());
+ assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType());
+ assertEquals("any", impl.toString());
+ }
+
+ @Test
+ public void testUriResourceComplexPropertyImpl() {
+ UriResourceComplexPropertyImpl impl = new UriResourceComplexPropertyImpl();
+ assertEquals(UriResourceKind.complexProperty, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
+ EdmProperty property = (EdmProperty) entityType.getProperty("PropertyComplex");
+ impl.setProperty(property);
+
+ assertEquals(property, impl.getProperty());
+ assertEquals(property.getName(), impl.toString());
+ assertEquals(false, impl.isCollection());
+ assertEquals(property.getType(), impl.getType());
+ assertEquals(property.getType(), impl.getComplexType());
+ impl.getComplexType();
+
+ EdmComplexTypeImpl complexTypeImplType =
+ (EdmComplexTypeImpl) edm.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav);
+
+ impl.setTypeFilter(complexTypeImplType);
+ assertEquals(complexTypeImplType, impl.getTypeFilter());
+ assertEquals(complexTypeImplType, impl.getComplexTypeFilter());
+ impl.getComplexTypeFilter();
+
+ }
+
+ @Test
+ public void testUriResourcePrimitivePropertyImpl() {
+ UriResourcePrimitivePropertyImpl impl = new UriResourcePrimitivePropertyImpl();
+ assertEquals(UriResourceKind.primitiveProperty, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav);
+ EdmProperty property = (EdmProperty) entityType.getProperty("PropertyInt16");
+ impl.setProperty(property);
+
+ assertEquals(property, impl.getProperty());
+ assertEquals(property.getName(), impl.toString());
+ assertEquals(false, impl.isCollection());
+ assertEquals(property.getType(), impl.getType());
+ }
+
+ @Test
+ public void testUriResourceCountImpl() {
+ UriResourceCountImpl impl = new UriResourceCountImpl();
+ assertEquals(UriResourceKind.count, impl.getKind());
+ assertEquals("$count", impl.toString());
+ }
+
+ @Test
+ public void testUriResourceEntitySetImpl() {
+ UriResourceEntitySetImpl impl = new UriResourceEntitySetImpl();
+ assertEquals(UriResourceKind.entitySet, impl.getKind());
+
+ EdmEntitySetImpl entitySet = (EdmEntitySetImpl) edm.getEntityContainer(null).getEntitySet("ESAllPrim");
+ impl.setEntitSet(entitySet);
+
+ assertEquals("ESAllPrim", impl.toString());
+ assertEquals(entitySet, impl.getEntitySet());
+
+ assertEquals(entitySet.getEntityType(), impl.getType());
+ assertEquals(entitySet.getEntityType(), impl.getEntityType());
+ impl.getEntityType();
+
+ // is Collection
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(new ArrayList<UriParameterImpl>());
+ assertEquals(false, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceFunctionImpl() {
+ UriResourceFunctionImpl impl = new UriResourceFunctionImpl();
+ assertEquals(UriResourceKind.function, impl.getKind());
+ assertEquals("", impl.toString());
+
+ // function
+ EdmFunction function = (EdmFunction) edm.getEntityContainer(null).getFunctionImport("FINRTInt16")
+ .getUnboundFunction(new ArrayList<String>());
+ assertNotNull(function);
+ impl.setFunction(function);
+
+ assertEquals(function, impl.getFunction());
+ assertEquals("UFNRTInt16", impl.toString());
+ assertEquals(function.getReturnType().getType(), impl.getType());
+ assertEquals(false, impl.isParameterListFilled());
+
+ // function import
+ impl = new UriResourceFunctionImpl();
+ EdmFunctionImport functionImport = edm.getEntityContainer(null).getFunctionImport("FINRTInt16");
+ impl.setFunctionImport(functionImport, new ArrayList<UriParameterImpl>());
+ assertEquals(functionImport, impl.getFunctionImport());
+ assertEquals("FINRTInt16", impl.toString());
+
+ // function collection
+ impl = new UriResourceFunctionImpl();
+ functionImport = edm.getEntityContainer(null).getFunctionImport("FICRTESTwoKeyNavParam");
+ assertNotNull(function);
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ impl.setFunctionImport(functionImport, Arrays.asList(parameter));
+ assertEquals("FICRTESTwoKeyNavParam", impl.toString());
+
+ impl.setFunction(functionImport.getUnboundFunction(Arrays.asList("ParameterInt16")));
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(new ArrayList<UriParameterImpl>());
+ assertEquals(false, impl.isCollection());
+
+ assertEquals(parameter, impl.getParameters().get(0));
+ assertEquals(true, impl.isParameterListFilled());
+ }
+
+ @Test
+ public void testUriResourceImplKeyPred() {
+ class Mock extends UriResourceWithKeysImpl {
+
+ EdmType type;
+
+ public Mock() {
+ super(UriResourceKind.action);
+ }
+
+ @Override
+ public EdmType getType() {
+ return type;
+ }
+
+ public Mock setType(final EdmType type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ @Override
+ public String toString() {
+ return "mock";
+ }
+ }
+
+ Mock impl = new Mock();
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ EdmEntityType entityTypeBaseEntry = edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ impl.setType(entityType);
+ assertEquals(entityType, impl.getType());
+ assertEquals("mock", impl.toString(false));
+ assertEquals("mock", impl.toString(true));
+
+ // set both
+ impl.setCollectionTypeFilter(entityTypeBaseColl);
+ assertEquals(entityTypeBaseColl, impl.getTypeFilterOnCollection());
+ assertEquals("mock", impl.toString(false));
+ assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true));
+ impl.setEntryTypeFilter(entityTypeBaseEntry);
+ assertEquals(entityTypeBaseEntry, impl.getTypeFilterOnEntry());
+ assertEquals("mock", impl.toString(false));
+ assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav/()com.sap.odata.test1.ETTwoBaseTwoKeyNav",
+ impl.toString(true));
+
+ // set entry
+ impl = new Mock();
+ impl.setType(entityType);
+ impl.setEntryTypeFilter(entityTypeBaseEntry);
+ assertEquals(entityTypeBaseEntry, impl.getTypeFilterOnEntry());
+ assertEquals("mock", impl.toString(false));
+ assertEquals("mock/com.sap.odata.test1.ETTwoBaseTwoKeyNav", impl.toString(true));
+
+ // set collection
+ impl = new Mock();
+ impl.setType(entityType);
+ impl.setCollectionTypeFilter(entityTypeBaseColl);
+ assertEquals(entityTypeBaseColl, impl.getTypeFilterOnCollection());
+ assertEquals("mock", impl.toString(false));
+ assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true));
+
+ impl = new Mock();
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
+ keyPredicates.add(parameter);
+
+ impl.setKeyPredicates(keyPredicates);
+ assertNotNull(null, impl.getKeyPredicates());
+
+ }
+
+ @Test
+ public void testUriResourceImplTyped() {
+ class Mock extends UriResourceTypedImpl {
+
+ EdmType type;
+
+ public Mock() {
+ super(UriResourceKind.action);
+ }
+
+ @Override
+ public EdmType getType() {
+ return type;
+ }
+
+ @Override
+ public boolean isCollection() {
+ return false;
+ }
+
+ public Mock setType(final EdmType type) {
+ this.type = type;
+ return this;
+ }
+
+ @Override
+ public String toString() {
+ return "mock";
+ }
+
+ }
+
+ Mock impl = new Mock();
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav);
+
+ impl.setType(entityType);
+ assertEquals("mock", impl.toString());
+ assertEquals("mock", impl.toString(true));
+ assertEquals("mock", impl.toString(false));
+
+ impl.setTypeFilter(entityTypeBaseColl);
+ assertEquals(entityTypeBaseColl, impl.getTypeFilter());
+ assertEquals("mock", impl.toString());
+ assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true));
+ assertEquals("mock", impl.toString(false));
+ //
+ }
+
+ @Test
+ public void testUriResourceItImpl() {
+ UriResourceItImpl impl = new UriResourceItImpl();
+ assertEquals(UriResourceKind.it, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ assertEquals("$it", impl.toString());
+
+ impl.setType(entityType);
+ assertEquals(entityType, impl.getType());
+
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
+ keyPredicates.add(parameter);
+
+ assertEquals(false, impl.isCollection());
+ impl.setCollection(true);
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(keyPredicates);
+ assertEquals(false, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceNavigationPropertyImpl() {
+ UriResourceNavigationPropertyImpl impl = new UriResourceNavigationPropertyImpl();
+ assertEquals(UriResourceKind.navigationProperty, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ EdmNavigationProperty property = (EdmNavigationProperty) entityType.getProperty("NavPropertyETKeyNavMany");
+ assertNotNull(property);
+
+ impl.setNavigationProperty(property);
+ assertEquals(property, impl.getProperty());
+
+ assertEquals("NavPropertyETKeyNavMany", impl.toString());
+ assertEquals(property.getType(), impl.getType());
+
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
+ keyPredicates.add(parameter);
+
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(keyPredicates);
+ assertEquals(false, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceRefImpl() {
+ UriResourceRefImpl impl = new UriResourceRefImpl();
+ assertEquals(UriResourceKind.ref, impl.getKind());
+ assertEquals("$ref", impl.toString());
+ }
+
+ @Test
+ public void testUriResourceRootImpl() {
+ UriResourceRootImpl impl = new UriResourceRootImpl();
+ assertEquals(UriResourceKind.root, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ assertEquals("$root", impl.toString());
+
+ impl.setType(entityType);
+ assertEquals(entityType, impl.getType());
+
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
+ keyPredicates.add(parameter);
+
+ assertEquals(false, impl.isCollection());
+ impl.setCollection(true);
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(keyPredicates);
+ assertEquals(false, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceSingletonImpl() {
+ UriResourceSingletonImpl impl = new UriResourceSingletonImpl();
+ assertEquals(UriResourceKind.singleton, impl.getKind());
+
+ EdmSingletonImpl singleton = (EdmSingletonImpl) edm.getEntityContainer(null).getSingleton("SINav");
+ EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav);
+ impl.setSingleton(singleton);
+
+ assertEquals("SINav", impl.toString());
+ assertEquals(singleton, impl.getSingleton());
+
+ assertEquals(singleton.getEntityType(), impl.getType());
+ assertEquals(singleton.getEntityType(), impl.getEntityType());
+ impl.getEntityType();
+
+ impl.setTypeFilter(entityTypeBaseColl);
+ assertEquals(entityTypeBaseColl, impl.getEntityTypeFilter());
+
+ // is Collection
+ assertEquals(false, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceValueImpl() {
+ UriResourceValueImpl impl = new UriResourceValueImpl();
+ assertEquals(UriResourceKind.value, impl.getKind());
+ assertEquals("$value", impl.toString());
+ }
+
+ @Test
+ public void testUriResourceLambdaVarImpl() {
+ UriResourceLambdaVarImpl impl = new UriResourceLambdaVarImpl();
+ assertEquals(UriResourceKind.lambdaVariable, impl.getKind());
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+ impl.setType(entityType);
+ impl.setVariableText("A");
+
+ assertEquals("A", impl.toString());
+ assertEquals(entityType, impl.getType());
+ assertEquals("A", impl.getVariableName());
+ assertEquals(false, impl.isCollection());
+ impl.setCollection(true);
+ assertEquals(true, impl.isCollection());
+ }
+
+ @Test
+ public void testUriResourceStartingTypeFilterImpl() {
+ UriResourceStartingTypeFilterImpl impl = new UriResourceStartingTypeFilterImpl();
+
+ EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav);
+
+ impl.setType(entityType);
+ assertEquals("com.sap.odata.test1.ETTwoKeyNav", impl.toString());
+ assertEquals(entityType, impl.getType());
+
+ UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16");
+ List<UriParameterImpl> keyPredicates = new ArrayList<UriParameterImpl>();
+ keyPredicates.add(parameter);
+
+ assertEquals(false, impl.isCollection());
+ impl.setCollection(true);
+ assertEquals(true, impl.isCollection());
+ impl.setKeyPredicates(keyPredicates);
+ assertEquals(false, impl.isCollection());
+
+ }
+}