You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@olingo.apache.org by ch...@apache.org on 2014/02/17 16:36:06 UTC
[19/29] [OLINGO-161] Refactored module names
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/EdmTechTestProvider.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/EdmTechTestProvider.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/EdmTechTestProvider.java
deleted file mode 100644
index 4df8654..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/EdmTechTestProvider.java
+++ /dev/null
@@ -1,95 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import java.util.Arrays;
-import java.util.List;
-
-import org.apache.olingo.odata4.commons.api.edm.provider.ComplexType;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntitySet;
-import org.apache.olingo.odata4.commons.api.edm.provider.EntityType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.edm.provider.Property;
-import org.apache.olingo.odata4.commons.api.edm.provider.PropertyRef;
-import org.apache.olingo.odata4.commons.api.exception.ODataException;
-
-
-/**
- * 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 {
-
- 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 (entityContainer == nameContainer) {
- 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);
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ExpandValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ExpandValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ExpandValidator.java
deleted file mode 100644
index a6cb095..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ExpandValidator.java
+++ /dev/null
@@ -1,208 +0,0 @@
-/*******************************************************************************
- *
- * 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.odata4.producer.core.testutil;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import org.apache.olingo.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.exception.ODataApplicationException;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.ExpandItem;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.SelectItem;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.ExceptionVisitExpression;
-import org.apache.olingo.odata4.producer.core.uri.UriInfoImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.ExpandOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.FilterOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.QueryOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SelectOptionImpl;
-
-public class ExpandValidator implements Validator {
- private Edm edm;
- private Validator invokedByValidator;
-
- private int expandItemIndex;
- private ExpandOptionImpl expandOption;
- private ExpandItem expandItem;
-
- // --- Setup ---
-
- public ExpandValidator setGoUpValidator(final Validator parentValidator) {
- invokedByValidator = parentValidator;
- 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 UriResourceValidator goPath() {
- UriInfoImpl uriInfo = (UriInfoImpl) expandItem.getResourceInfo();
-
- if (uriInfo.getKind() != UriInfoKind.resource) {
- fail("goPath() can only be used on UriInfoKind.resource");
- }
-
- return new UriResourceValidator()
- .setUpValidator(this)
- .setEdm(edm)
- .setUriInfoImplPath(uriInfo);
-
- }
-
- public UriResourceValidator goSelectItemPath(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- UriInfoImpl uriInfo = (UriInfoImpl) item.getResourceInfo();
-
- return new UriResourceValidator()
- .setUpValidator(this)
- .setEdm(edm)
- .setUriInfoImplPath(uriInfo);
-
- }
-
-
-
- public ExpandValidator goExpand() {
- ExpandValidator val = new ExpandValidator();
- val.setExpand((ExpandOptionImpl) expandItem.getExpandOption());
- val.setGoUpValidator(this);
- return val;
- }
-
- public ExpandValidator goUpToExpandValidator() {
- return (ExpandValidator) invokedByValidator;
- }
-
- public UriResourceValidator goUpToUriResourceValidator() {
- return (UriResourceValidator) invokedByValidator;
- }
-
- 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.getInlineCountOption();
- 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 isSelectItemAllOp(final int index, FullQualifiedName fqn) {
- SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString());
- return this;
- }
-
-
- public ExpandValidator isFilterText(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 (ExceptionVisitExpression 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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterTreeToText.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterTreeToText.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterTreeToText.java
deleted file mode 100644
index 62409af..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterTreeToText.java
+++ /dev/null
@@ -1,161 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import java.util.List;
-
-import org.apache.olingo.odata4.commons.api.edm.EdmEnumType;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.exception.ODataApplicationException;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoResource;
-import org.apache.olingo.odata4.producer.api.uri.UriResource;
-import org.apache.olingo.odata4.producer.api.uri.UriResourceLambdaAll;
-import org.apache.olingo.odata4.producer.api.uri.UriResourceLambdaAny;
-import org.apache.olingo.odata4.producer.api.uri.UriResourcePartTyped;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.FilterOption;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.ExceptionVisitExpression;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.Expression;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.ExpressionVisitor;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedBinaryOperators;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedConstants;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedMethodCalls;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedUnaryOperators;
-
-public class FilterTreeToText implements ExpressionVisitor<String> {
-
- public static String Serialize(final FilterOption filter)
- throws ExceptionVisitExpression, ODataApplicationException {
-
- Expression expression = filter.getExpression();
- return expression.accept(new FilterTreeToText());
- }
-
- public static String Serialize(final Expression expression)
- throws ExceptionVisitExpression, ODataApplicationException {
-
- return expression.accept(new FilterTreeToText());
- }
-
- @Override
- public String visitBinaryOperator(final SupportedBinaryOperators operator, final String left, final String right)
- throws ExceptionVisitExpression {
-
- return "<" + left + " " + operator.toString() + " " + right + ">";
- }
-
- @Override
- public String visitUnaryOperator(final SupportedUnaryOperators operator, final String operand)
- throws ExceptionVisitExpression {
-
- return "<" + operator + " " + operand.toString() + ">";
- }
-
- @Override
- public String visitMethodCall(final SupportedMethodCalls methodCall, final List<String> parameters)
- throws ExceptionVisitExpression {
-
- 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 ExceptionVisitExpression {
- return "<" + literal + ">";
- }
-
- @Override
- public String visitMember(final UriInfoResource resource) throws ExceptionVisitExpression, 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.getLamdaVariable(), all.getExpression());
- } else if (item instanceof UriResourceLambdaAny) {
- UriResourceLambdaAny any = (UriResourceLambdaAny) item;
- // TODO create enum
- 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 ExceptionVisitExpression {
- return "<" + referenceName + ">";
- }
-
- @Override
- public String visitLambdaExpression(final String functionText, final String string, final Expression expression)
- throws ExceptionVisitExpression, 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 ExceptionVisitExpression, ODataApplicationException {
- String tmp = "";
-
- for (String item : enumValues) {
- if (tmp.length() > 0) {
- tmp += ",";
- }
- tmp += item;
- }
-
- return "<" + type.getNamespace() + "." + type.getName() + "<" + tmp + ">>";
- }
-
- @Override
- public String visitConstant(SupportedConstants kind) throws ExceptionVisitExpression, ODataApplicationException {
- // TODO Auto-generated method stub
- return "<" + kind.toString() + ">";
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterValidator.java
deleted file mode 100644
index 951814b..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/FilterValidator.java
+++ /dev/null
@@ -1,491 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
-
-import java.util.List;
-
-import org.apache.olingo.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.commons.api.exception.ODataApplicationException;
-import org.apache.olingo.odata4.producer.api.uri.UriInfo;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.ExceptionVisitExpression;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.Expression;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.Member;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedBinaryOperators;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedConstants;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.expression.SupportedMethodCalls;
-import org.apache.olingo.odata4.producer.core.uri.Parser;
-import org.apache.olingo.odata4.producer.core.uri.UriInfoImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriParseTreeVisitor;
-import org.apache.olingo.odata4.producer.core.uri.UriParserException;
-import org.apache.olingo.odata4.producer.core.uri.UriParserSemanticException;
-import org.apache.olingo.odata4.producer.core.uri.UriParserSyntaxException;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.FilterOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.OrderByOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.BinaryImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.ConstantImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.EnumerationImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.LiteralImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.MemberImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.MethodCallImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.TypeLiteralImpl;
-
-public class FilterValidator implements Validator {
- private Edm edm;
-
- private Validator invokedByValidator;
- private FilterOptionImpl filter;
-
- private Expression curExpression;
- private Expression rootExpression;
-
- private OrderByOptionImpl orderBy;
-
- private UriParserException exception;
-
- // --- Setup ---
- public FilterValidator setUriResourcePathValidator(final UriResourceValidator uriResourcePathValidator) {
- invokedByValidator = uriResourcePathValidator;
- return this;
- }
-
- public FilterValidator setUriValidator(final UriValidator 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 {
- // TODO change to ESTwoKeyNav
- String uri = "SINav?$filter=" + filter.trim();
- return runUri(uri);
- }
-
- public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException {
- // TODO change to ESTwoKeyNav
- String uri = "SINav?$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, new UriParseTreeVisitor(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, new UriParseTreeVisitor(edm));
- } catch (UriParserException e) {
- this.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, new UriParseTreeVisitor(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, new UriParseTreeVisitor(edm));
- } catch (UriParserException e) {
- this.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 Validator goUp() {
- return invokedByValidator;
- }
-
- public UriResourceValidator goPath() {
- if (!(curExpression instanceof MemberImpl)) {
- fail("Current expression not a member");
- }
-
- MemberImpl member = (MemberImpl) curExpression;
- UriResourceValidator uriValidator = new UriResourceValidator();
- uriValidator.setEdm(edm);
- uriValidator.setUriInfoImplPath((UriInfoImpl) member.getPath());
- uriValidator.setUpValidator(this);
- return uriValidator;
- }
-
- public FilterValidator goParameter(final int parameterIndex) {
- if (curExpression instanceof MethodCallImpl) {
- MethodCallImpl methodCall = (MethodCallImpl) 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 (ExceptionVisitExpression 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();
- }
-
- 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 SupportedMethodCalls methodKind, final int parameterCount) {
- if (!(curExpression instanceof MethodCallImpl)) {
- fail("Current expression is not a methodCall");
- }
-
- MethodCallImpl methodCall = (MethodCallImpl) curExpression;
- assertEquals(methodKind, methodCall.getMethod());
- assertEquals(parameterCount, methodCall.getParameters().size());
-
- return this;
- }
-
-
- public FilterValidator isParameterText(final int parameterIndex, final String parameterText)
- throws ExceptionVisitExpression, ODataApplicationException {
-
- if (!(curExpression instanceof MethodCallImpl)) {
- fail("Current expression is not a method");
- }
-
- MethodCallImpl methodCall = (MethodCallImpl) curExpression;
-
- Expression parameter = methodCall.getParameters().get(parameterIndex);
- String actualParameterText = FilterTreeToText.Serialize(parameter);
- assertEquals(parameterText, actualParameterText);
-
- return this;
- }
-
- public FilterValidator isBinary(final SupportedBinaryOperators 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(FullQualifiedName fullName) {
- if (!(curExpression instanceof TypeLiteralImpl)) {
- fail("Current expression not a typeLiteral");
- }
-
- this.isType(fullName);
-
- return this;
- }
-
- public FilterValidator isMember() {
- if (!(curExpression instanceof MemberImpl)) {
- fail("Current expression not a member");
- }
-
- 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 isConstant(SupportedConstants kind) {
- if (!(curExpression instanceof ConstantImpl)) {
- fail("Current expression not a constant");
- }
-
- assertEquals(kind, ((ConstantImpl) curExpression).getKind());
-
- return this;
- }
-
- public FilterValidator isSortOrder(int index, boolean descending) {
- assertEquals(descending, orderBy.getOrders().get(index).isDescending());
- return this;
- }
-
- public FilterValidator goOrder(int index) {
- curExpression = orderBy.getOrders().get(index).getExpression();
- return this;
- }
-
- public FilterValidator isExSyntax(long errorID) {
- assertEquals(UriParserSyntaxException.class, exception.getClass());
- return this;
- }
-
- public FilterValidator isExSemantic(long errorID) {
- assertEquals(UriParserSemanticException.class, exception.getClass());
- return this;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParseTreeToText.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParseTreeToText.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParseTreeToText.java
deleted file mode 100644
index c7fa306..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParseTreeToText.java
+++ /dev/null
@@ -1,82 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.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/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserTest.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserTest.java
deleted file mode 100644
index 622bce7..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserTest.java
+++ /dev/null
@@ -1,53 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import org.antlr.v4.runtime.DefaultErrorStrategy;
-import org.apache.olingo.odata4.producer.core.uri.Parser;
-import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser;
-
-public class ParserTest extends Parser {
- TestErrorLogger errorCollector1;
- TestErrorLogger errorCollector2;
-
- public ParserTest() {
- errorCollector1 = new TestErrorLogger("Stage 1", 1);
- errorCollector2 = new TestErrorLogger("Stage 2", 1);
- }
-
- @Override
- protected void addStage2ErrorStategy(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(UriParserParser parser) {
- // Log error to console
- parser.removeErrorListeners();
- parser.addErrorListener(errorCollector1);
- }
-
- @Override
- protected void addStage2ErrorListener(UriParserParser parser) {
- // Log error to console
- parser.removeErrorListeners();
- parser.addErrorListener(errorCollector2);
- }
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserValidator.java
deleted file mode 100644
index e29255f..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/ParserValidator.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import static org.junit.Assert.assertEquals;
-
-import java.util.ArrayList;
-import java.util.List;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.BailErrorStrategy;
-import org.antlr.v4.runtime.CommonTokenStream;
-import org.antlr.v4.runtime.DefaultErrorStrategy;
-import org.antlr.v4.runtime.ParserRuleContext;
-import org.antlr.v4.runtime.atn.PredictionMode;
-import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser;
-import org.apache.olingo.odata4.producer.core.uri.antlr.UriParserParser.OdataRelativeUriEOFContext;
-
-// TODO extend to test also exception which can occure while paring
-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;
- }
-
- /**
- * TODO verify
- * 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;
- }
-
- /**
- *
- * TODO verify
- * 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;
- }
-
- /**
- * TODO verify
- * 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;
- }
-
- // --- Helper ---
-
- private OdataRelativeUriEOFContext parseInput(final String input) {
- UriParserParser parser = null;
- UriLexerWithTrace lexer = null;
- OdataRelativeUriEOFContext ret = null;
-
- // Use 2 stage approach to improve performance
- // see https://github.com/antlr/antlr4/issues/192
- // TODO verify this
-
- // stage= 1
- try {
- curException = null;
- exceptions.clear();
-
- // create parser
- lexer = new UriLexerWithTrace(new ANTLRInputStream(input), lexerLogLevel);
- parser = new UriParserParser(new CommonTokenStream(lexer));
-
- // write always a error message in case of syntax errors
- // parser.addErrorListener(new TestErrorHandler<Object>());
- // check error message if whether they are allowed or not
- // parser.addErrorListener(new ErrorCollector());
-
- // bail out of parser at first syntax error. --> proceed in catch block with step 2
- parser.setErrorHandler(new BailErrorStrategy());
-
- // user the faster SLL parsing
- parser.getInterpreter().setPredictionMode(PredictionMode.SLL);
-
- // parse
- if (logLevel > 0) {
- System.out.println("Step 1");
- System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode());
- }
- ret = parser.odataRelativeUriEOF();
-
- } catch (Exception exception) {
- curException = exception;
- try {
- // clear status
- curException = null;
- exceptions.clear();
-
- // create parser
- lexer = new UriLexerWithTrace(new ANTLRInputStream(input), lexerLogLevel);
- parser = new UriParserParser(new CommonTokenStream(lexer));
-
- // write always a error message in case of syntax errors
- // parser.addErrorListener(new ErrorCollector(this));
- // check error message if whether they are allowed or not
- // parser.addErrorListener(new ErrorCollector(this));
-
- // Used default error strategy
- parser.setErrorHandler(new DefaultErrorStrategy());
-
- // User the slower SLL parsing
- parser.getInterpreter().setPredictionMode(PredictionMode.LL);
-
- // parse
- if (logLevel > 1) {
- System.out.println("Step 2");
- System.out.println(" PrectictionMode: " + parser.getInterpreter().getPredictionMode() + ")");
- }
- ret = parser.odataRelativeUriEOF();
-
- } catch (Exception exception1) {
- curException = exception1;
- // exceptionOnStage = 2;
- }
- }
-
- return ret;
- }
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TestErrorLogger.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TestErrorLogger.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TestErrorLogger.java
deleted file mode 100644
index 8e40072..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TestErrorLogger.java
+++ /dev/null
@@ -1,174 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.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;
-
-class TestErrorLogger implements ANTLRErrorListener {
-
- private String prefix;
- private int logLevel = 0;
-
- public TestErrorLogger(String prefix, 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) {
-
- // Collect the exception
- 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) {
-
- /*
- * if (tokenValidator.logLevel > 0) {
- * System.out.println("reportAmbiguity: ");
- * System.out.println(" ambigAlts: " + ambigAlts);
- * System.out.println(" configs: " + configs);
- * System.out.println(" input: " + recognizer.getTokenStream().getText(Interval.of(startIndex, stopIndex)));
- * }
- */
- /*
- * if (!tokenValidator.allowAmbiguity) {
- * printStack(recognizer);
- * fail("reportAmbiguity");
- * }
- */
- }
-
- @Override
- public void reportAttemptingFullContext(final Parser recognizer, final DFA dfa, final int startIndex,
- final int stopIndex,
- final BitSet conflictingAlts, final ATNConfigSet configs) {
- /*
- * // The grammar should be written in order to avoid attempting a full context parse because its negative
- * // impact on the performance, so trace and stop here
- * if (tokenValidator.logLevel > 0) {
- * System.out.println("allowed AttemptingFullContext");
- * }
- *
- * if (!tokenValidator.allowFullContext) {
- * printStack(recognizer);
- * fail("reportAttemptingFullContext");
- * }
- */
- }
-
- @Override
- public void reportContextSensitivity(final Parser recognizer, final DFA dfa, final int startIndex,
- final int stopIndex, final int prediction,
- final ATNConfigSet configs) {
- /*
- * if (tokenValidator.logLevel > 0) {
- * System.out.println("allowed ContextSensitivity");
- * }
- *
- * if (!tokenValidator.allowContextSensitifity) {
- * printStack(recognizer);
- * fail("reportContextSensitivity");
- * }
- */
- }
-
- /*
- * private void printStack(final Parser recognizer) {
- * List<String> stack = ((Parser) recognizer).getRuleInvocationStack();
- * Collections.reverse(stack);
- *
- * System.out.println(" Rule stack: " + stack);
- * }
- */
- 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);
- // TODO check also http://stackoverflow.com/questions/14747952/ll-exact-ambig-detection-interpetation
-
- printStack(recognizer);
-
- if (e != null && e.getOffendingToken() != null) {
-
- // String lexerTokenName = TestSuiteLexer.tokenNames[e.getOffendingToken().getType()];
- String lexerTokenName = "";
- try {
- // TODO check how the Lexer is accessed in the new package structure
- // lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()];
- } catch (ArrayIndexOutOfBoundsException es) {
- lexerTokenName = "token error";
- }
- System.out.println(" line " + line + ":" + charPositionInLine + " at " +
- offendingSymbol + "/" + lexerTokenName + ": " + msg);
- } else {
- System.out.println(" line " + line + ":" + charPositionInLine + " at " + offendingSymbol + ": " + msg);
- }
- }
-
- public static int getDecisionRule(Recognizer<?, ?> recognizer, int decision) {
- if (recognizer == null || decision < 0) {
- return -1;
- }
-
- if (decision >= recognizer.getATN().decisionToState.size()) {
- return -1;
- }
-
- return recognizer.getATN().decisionToState.get(decision).ruleIndex;
-}
-
-public static String getRuleDisplayName(Recognizer<?, ?> recognizer, int ruleIndex) {
- if (recognizer == null || ruleIndex < 0) {
- return Integer.toString(ruleIndex);
- }
-
- String[] ruleNames = recognizer.getRuleNames();
- if (ruleIndex < 0 || ruleIndex >= ruleNames.length) {
- return Integer.toString(ruleIndex);
- }
-
- return ruleNames[ruleIndex];
-}
-
-}
\ No newline at end of file
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TokenValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TokenValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TokenValidator.java
deleted file mode 100644
index 4f452b8..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/TokenValidator.java
+++ /dev/null
@@ -1,194 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.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.odata4.producer.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;
- }
-
-}
http://git-wip-us.apache.org/repos/asf/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriLexerWithTrace.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriLexerWithTrace.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriLexerWithTrace.java
deleted file mode 100644
index 9576ea0..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriLexerWithTrace.java
+++ /dev/null
@@ -1,85 +0,0 @@
-/*******************************************************************************
- * 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.odata4.producer.core.testutil;
-
-import org.antlr.v4.runtime.ANTLRInputStream;
-import org.antlr.v4.runtime.Token;
-import org.apache.olingo.odata4.producer.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;
- }
-}