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:05 UTC
[18/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/UriResourceValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriResourceValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriResourceValidator.java
deleted file mode 100644
index f06b486..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriResourceValidator.java
+++ /dev/null
@@ -1,562 +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.assertNotNull;
-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.EdmElement;
-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.UriParameter;
-import org.apache.olingo.odata4.producer.api.uri.UriResourceKind;
-import org.apache.olingo.odata4.producer.api.uri.UriResourcePartTyped;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.CustomQueryOption;
-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.UriParseTreeVisitor;
-import org.apache.olingo.odata4.producer.core.uri.UriParserException;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceActionImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceComplexPropertyImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceEntitySetImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceFunctionImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceLambdaAllImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceLambdaAnyImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceNavigationPropertyImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourcePrimitivePropertyImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceSingletonImpl;
-import org.apache.olingo.odata4.producer.core.uri.UriResourceWithKeysImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.CustomQueryOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.ExpandOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SelectOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.ExpressionImpl;
-
-public class UriResourceValidator implements Validator {
- private Edm edm;
- private Validator invokedBy;
- private UriInfo uriInfo = null;
-
- private UriResourceImpl uriPathInfo = null;
- private int uriResourceIndex;
-
- // --- Setup ---
-
- public UriResourceValidator setUpValidator(final Validator uriValidator) {
- invokedBy = uriValidator;
- return this;
- }
-
- public UriResourceValidator setEdm(final Edm edm) {
- this.edm = edm;
- return this;
- }
-
- public UriResourceValidator setUriInfoImplPath(final UriInfoImpl uriInfoPath) {
- uriInfo = uriInfoPath;
- last();
- return this;
- }
-
- // --- Execution ---
-
- public UriResourceValidator run(final String uri) {
- ParserTest testParser = new ParserTest();
- UriInfoImpl uriInfoTmp = null;
- uriPathInfo = null;
- try {
- uriInfoTmp = (UriInfoImpl) testParser.parseUri(uri, new UriParseTreeVisitor(edm));
- } catch (UriParserException e) {
- fail("Exception occured while parsing the URI: " + uri + "\n"
- + " Exception: " + e.getMessage());
- }
-
- if (uriInfoTmp.getKind() != UriInfoKind.resource) {
- fail("Invalid UriInfoKind: " + uriInfoTmp.getKind().toString());
- }
- uriInfo = uriInfoTmp;
-
- first();
- return this;
- }
-
- // --- Navigation ---
-
- public UriValidator goUpUriValidator() {
- return (UriValidator) invokedBy;
- }
-
- public ExpandValidator goUpExpandValidator() {
- return (ExpandValidator) invokedBy;
- }
-
- public FilterValidator goUpFilterValidator() {
- return (FilterValidator) invokedBy;
- }
-
- public FilterValidator goLambdaExpression() {
- if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
- FilterValidator val = new FilterValidator();
- val.setEdm(edm);
- val.setExpression(((UriResourceLambdaAllImpl) uriPathInfo).getExpression());
- return (val);
- } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
- FilterValidator val = new FilterValidator();
- val.setEdm(edm);
- val.setExpression(((UriResourceLambdaAnyImpl) uriPathInfo).getExpression());
- return (val);
- } else {
- fail("invalid resource kind: " + uriPathInfo.getKind().toString());
- }
- return null;
- }
-
- public UriResourceValidator isLambdaVar(final String var) {
- String actualVar = null;
- if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) {
- actualVar = ((UriResourceLambdaAllImpl) uriPathInfo).getLamdaVariable();
- } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) {
- actualVar = ((UriResourceLambdaAnyImpl) uriPathInfo).getLamdaVariable();
- } else {
- fail("invalid resource kind: " + uriPathInfo.getKind().toString());
- }
-
- assertEquals(var, actualVar);
- return this;
- }
-
- public UriResourceValidator goSelectItemPath(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourceInfo();
-
- return new UriResourceValidator()
- .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().setGoUpValidator(this).setExpand(expand);
- }
-
- public UriResourceValidator first() {
- uriResourceIndex = 0;
- uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(0);
- return this;
- }
-
- public UriResourceValidator 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 UriResourceValidator n() {
- uriResourceIndex++;
-
- try {
- uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriResourceIndex);
- } catch (IndexOutOfBoundsException ex) {
- fail("not enough segments");
- }
-
- return this;
- }
-
- public UriResourceValidator at(final int index) {
- uriResourceIndex = index;
- try {
- uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(index);
- } catch (IndexOutOfBoundsException ex) {
- fail("not enough segments");
- }
- return this;
- }
-
- // --- Validation ---
-
- public UriResourceValidator isTypeFilter(final FullQualifiedName expectedType) {
-
- if (uriPathInfo.getKind() != UriResourceKind.complexProperty &&
- uriPathInfo.getKind() != UriResourceKind.singleton &&
- uriPathInfo.getKind() != UriResourceKind.startingTypeFilter) {
- 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 UriResourceValidator 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 UriResourceValidator isType(final FullQualifiedName type, final boolean isFinallyACollection) {
- isType(type);
- assertEquals(isFinallyACollection, ((UriResourcePartTyped) uriPathInfo).isCollection());
- return this;
- }
-
- public UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator isFilterString(final String expectedFilterTreeAsString) {
-
- ExpressionImpl filterTree = (ExpressionImpl) uriInfo.getFilterOption().getExpression();
- try {
- String filterTreeAsString = filterTree.accept(new FilterTreeToText());
- assertEquals(expectedFilterTreeAsString, filterTreeAsString);
- } catch (ExceptionVisitExpression e) {
- fail("isFilterString: Exception " + e.getMessage() + " occured");
- } catch (ODataApplicationException e) {
- fail("isFilterString: Exception " + e.getMessage() + " occured");
- }
-
- return this;
- }
-
-
- public UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator 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 UriResourceValidator isKind(final UriInfoKind kind) {
- assertEquals(kind, uriInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isPrimitiveProperty(final String name,
- final FullQualifiedName type, 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 UriResourceValidator isComplexProperty(final String name, final FullQualifiedName type, 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 UriResourceValidator isNavProperty(final String name, final FullQualifiedName type, 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 UriResourceValidator isUriPathInfoKind(final UriResourceKind infoType) {
- assertNotNull(uriPathInfo);
- assertEquals(infoType, uriPathInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isAction(final String name) {
- assertEquals(UriResourceKind.action, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceActionImpl) uriPathInfo).getAction().getName());
- return this;
- }
-
- public UriResourceValidator isFunction(final String name) {
- assertEquals(UriResourceKind.function, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunction().getName());
- return this;
- }
-
- public UriResourceValidator isFunctionImport(final String name) {
- assertEquals(UriResourceKind.function, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunctionImport().getName());
- return this;
- }
-
- public UriResourceValidator isEntitySet(final String name) {
- assertEquals(UriResourceKind.entitySet, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceEntitySetImpl) uriPathInfo).getEntitySet().getName());
- return this;
- }
-
- public UriResourceValidator isComplex(final String name) {
- assertEquals(UriResourceKind.complexProperty, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceComplexPropertyImpl) uriPathInfo).getProperty().getName());
- return this;
- }
-
- public UriResourceValidator isSingleton(final String name) {
- assertEquals(UriResourceKind.singleton, uriPathInfo.getKind());
- assertEquals(name, ((UriResourceSingletonImpl) uriPathInfo).getSingleton().getName());
- return this;
- }
-
- public UriResourceValidator isValue() {
- assertEquals(UriResourceKind.value, uriPathInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isCount() {
- assertEquals(UriResourceKind.count, uriPathInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isRef() {
- assertEquals(UriResourceKind.ref, uriPathInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isActionImport(final String actionName) {
- assertEquals(UriResourceKind.action, uriPathInfo.getKind());
- assertEquals(actionName, ((UriResourceActionImpl) uriPathInfo).getActionImport().getName());
- return this;
- }
-
- public UriResourceValidator isIt() {
- assertEquals(UriResourceKind.it, uriPathInfo.getKind());
- return this;
- }
-
- public UriResourceValidator isTopText(final String topText) {
- assertEquals(topText, uriInfo.getTopOption().getText());
- return this;
- }
-
- public UriResourceValidator isFormatText(final String formatText) {
- assertEquals(formatText, uriInfo.getFormatOption().getText());
- return this;
- }
-
- public UriResourceValidator isInlineCountText(final String inlineCountText) {
- assertEquals(inlineCountText, uriInfo.getInlineCountOption().getText());
- return this;
- }
-
- public UriResourceValidator isSkipText(final String skipText) {
- assertEquals(skipText, uriInfo.getSkipOption().getText());
- return this;
- }
-
- public UriResourceValidator isSkipTokenText(final String skipTokenText) {
- assertEquals(skipTokenText, uriInfo.getSkipTokenOption().getText());
- return this;
- }
-
- public UriResourceValidator isSelectItemStar(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- assertEquals(true, item.isStar());
- return this;
- }
-
- public UriResourceValidator isSelectItemAllOp(final int index, 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/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriValidator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriValidator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriValidator.java
deleted file mode 100644
index 5e71770..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/UriValidator.java
+++ /dev/null
@@ -1,247 +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.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.provider.FullQualifiedName;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.CustomQueryOption;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.SelectItem;
-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.CustomQueryOptionImpl;
-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.SelectOptionImpl;
-
-public class UriValidator implements Validator {
- private Edm edm;
-
- private UriInfoImpl uriInfo;
- private Exception exception;
-
- // Setup
- public UriValidator setEdm(final Edm edm) {
- this.edm = edm;
- return this;
- }
-
- // Execution
- public UriValidator run(final String uri) {
- Parser parser = new Parser();
- uriInfo = null;
- try {
- // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
- uriInfo = (UriInfoImpl) parser.parseUri(uri, new UriParseTreeVisitor(edm));
- } catch (UriParserException e) {
- fail("Exception occured while parsing the URI: " + uri + "\n"
- + " Exception: " + e.getMessage());
- }
-
- return this;
- }
-
- public UriValidator runEx(final String uri) {
- Parser parser = new Parser();
- uriInfo = null;
- try {
- // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
- uriInfo = (UriInfoImpl) parser.parseUri(uri, new UriParseTreeVisitor(edm));
-
- } catch (UriParserException e) {
- exception = e;
- }
-
- return this;
- }
-
- public UriValidator log(final String uri) {
- ParserTest parserTest = new ParserTest();
- uriInfo = null;
- try {
- // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri);
- uriInfo = (UriInfoImpl) parserTest.parseUri(uri, new UriParseTreeVisitor(edm));
- fail("Exception expected");
- } catch (UriParserException e) {
- fail("Exception occured while parsing the URI: " + uri + "\n"
- + " Exception: " + e.getMessage());
- }
-
- return this;
- }
-
- // Navigation
- public UriResourceValidator goPath() {
- if (uriInfo.getKind() != UriInfoKind.resource) {
- fail("invalid resource kind: " + uriInfo.getKind().toString());
- }
-
- return new UriResourceValidator()
- .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().setGoUpValidator(this).setExpand(expand);
- }
-
-
- public UriResourceValidator goSelectItemPath(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourceInfo();
-
- return new UriResourceValidator()
- .setUpValidator(this)
- .setEdm(edm)
- .setUriInfoImplPath(uriInfo1);
-
- }
-
- // Validation
- public UriValidator isKind(final UriInfoKind kind) {
- assertEquals(kind, uriInfo.getKind());
- return this;
- }
-
- public UriValidator 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 UriValidator isExSyntax(long errorID) {
- assertEquals(UriParserSyntaxException.class, exception.getClass());
- return this;
- }
-
- public UriValidator isExSemantic(long errorID) {
- assertEquals(UriParserSemanticException.class, exception.getClass());
- return this;
- }
-
- public UriValidator isIdText(final String text) {
- assertEquals(text, uriInfo.getIdOption().getText());
- return this;
- }
-
- public UriValidator isExpandText(final String text) {
- assertEquals(text, uriInfo.getExpandOption().getText());
- return this;
- }
-
- public UriValidator isSelectText(final String text) {
- assertEquals(text, uriInfo.getSelectOption().getText());
- return this;
- }
-
- public UriValidator isFormatText(final String text) {
- assertEquals(text, uriInfo.getFormatOption().getText());
- return this;
- }
-
- public UriValidator isFragmentText(final String text) {
- if (uriInfo.getKind() != UriInfoKind.metadata) {
- fail("invalid resource kind: " + uriInfo.getKind().toString());
- }
-
- assertEquals(text, uriInfo.getFragment());
-
- return this;
- }
-
- public UriValidator 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 UriValidator isSelectItemStar(final int index) {
- SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption();
-
- SelectItem item = select.getSelectItems().get(index);
- assertEquals(true, item.isStar());
- return this;
- }
-
- public UriValidator isSelectItemAllOp(final int index, 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/incubator-olingo-odata4/blob/c49ff803/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/Validator.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/Validator.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/Validator.java
deleted file mode 100644
index 11706a6..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/testutil/Validator.java
+++ /dev/null
@@ -1,23 +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;
-
-public interface Validator {
-
-}
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/uri/UriInfoImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriInfoImplTest.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriInfoImplTest.java
deleted file mode 100644
index e602c93..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriInfoImplTest.java
+++ /dev/null
@@ -1,201 +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.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.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.core.edm.provider.EdmProviderImpl;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoAll;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoBatch;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoCrossjoin;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoEntityId;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoKind;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoMetadata;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoResource;
-import org.apache.olingo.odata4.producer.api.uri.UriInfoService;
-import org.apache.olingo.odata4.producer.api.uri.queryoption.CustomQueryOption;
-import org.apache.olingo.odata4.producer.core.testutil.EdmTechProvider;
-import org.apache.olingo.odata4.producer.core.testutil.EdmTechTestProvider;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.CustomQueryOptionImpl;
-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.FormatOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.IdOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.InlineCountOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.LevelsOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.OrderByOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.QueryOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SearchOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SelectOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SkipOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.SkipTokenOptionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.TopOptionImpl;
-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();
- InlineCountOptionImpl inlinecount = new InlineCountOptionImpl();
- 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.getInlineCountOption());
- 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(EdmTechProvider.nameETKeyNav);
- assertNotNull(entityType);
-
- uriInfo.setEntityTypeCast(entityType);
- assertEquals(entityType,uriInfo.getEntityTypeCast());
- }
-}
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/uri/UriParameterImplTest.java
----------------------------------------------------------------------
diff --git a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriParameterImplTest.java b/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriParameterImplTest.java
deleted file mode 100644
index 7b1d0fc..0000000
--- a/odata4-lib/odata4-producer-core/src/test/java/org/apache/olingo/odata4/producer/core/uri/UriParameterImplTest.java
+++ /dev/null
@@ -1,508 +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.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.odata4.commons.api.edm.Edm;
-import org.apache.olingo.odata4.commons.api.edm.EdmAction;
-import org.apache.olingo.odata4.commons.api.edm.EdmActionImport;
-import org.apache.olingo.odata4.commons.api.edm.EdmComplexType;
-import org.apache.olingo.odata4.commons.api.edm.EdmEntityType;
-import org.apache.olingo.odata4.commons.api.edm.EdmFunction;
-import org.apache.olingo.odata4.commons.api.edm.EdmFunctionImport;
-import org.apache.olingo.odata4.commons.api.edm.EdmNavigationProperty;
-import org.apache.olingo.odata4.commons.api.edm.EdmProperty;
-import org.apache.olingo.odata4.commons.api.edm.EdmType;
-import org.apache.olingo.odata4.commons.core.edm.primitivetype.EdmPrimitiveTypeKind;
-import org.apache.olingo.odata4.commons.core.edm.provider.EdmComplexTypeImpl;
-import org.apache.olingo.odata4.commons.core.edm.provider.EdmEntitySetImpl;
-import org.apache.olingo.odata4.commons.core.edm.provider.EdmProviderImpl;
-import org.apache.olingo.odata4.commons.core.edm.provider.EdmSingletonImpl;
-import org.apache.olingo.odata4.producer.api.uri.UriResourceKind;
-import org.apache.olingo.odata4.producer.core.testutil.EdmTechProvider;
-import org.apache.olingo.odata4.producer.core.testutil.EdmTechTestProvider;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.ExpressionImpl;
-import org.apache.olingo.odata4.producer.core.uri.queryoption.expression.LiteralImpl;
-import org.junit.Test;
-
-public class UriParameterImplTest {
- 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.getAction(EdmTechTestProvider.nameUARTETParam, null, null);
- impl.setAction(action);
- assertEquals(action, impl.getAction());
- assertEquals(EdmTechTestProvider.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.getAction(), impl.getAction());
- assertEquals(false, impl.isCollection());
- assertEquals("AIRTPrimParam", impl.toString());
- assertEquals(actionImport.getAction().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.getLamdaVariable());
- assertEquals(EdmPrimitiveTypeKind.Boolean.getEdmPrimitiveTypeInstance(), 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(EdmPrimitiveTypeKind.Boolean.getEdmPrimitiveTypeInstance(), impl.getType());
- assertEquals("any", impl.toString());
- }
-
- @Test
- public void testUriResourceComplexPropertyImpl() {
- UriResourceComplexPropertyImpl impl = new UriResourceComplexPropertyImpl();
- assertEquals(UriResourceKind.complexProperty, impl.getKind());
-
- EdmEntityType entityType = edm.getEntityType(EdmTechProvider.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());
- EdmComplexType complexType = impl.getComplexType(); // must work without cast
-
- EdmComplexTypeImpl complexTypeImplType =
- (EdmComplexTypeImpl) edm.getComplexType(EdmTechProvider.nameCTBasePrimCompNav);
-
- impl.setTypeFilter(complexTypeImplType);
- assertEquals(complexTypeImplType, impl.getTypeFilter());
- assertEquals(complexTypeImplType, impl.getComplexTypeFilter());
- complexType = impl.getComplexTypeFilter(); // must work without cast
-
- }
-
- @Test
- public void testUriResourcePrimitivePropertyImpl() {
- UriResourcePrimitivePropertyImpl impl = new UriResourcePrimitivePropertyImpl();
- assertEquals(UriResourceKind.primitiveProperty, impl.getKind());
-
- EdmEntityType entityType = edm.getEntityType(EdmTechProvider.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());
- EdmEntityType entityType = impl.getEntityType(); // must work without cast
-
- // 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")
- .getFunction(new ArrayList<String>());
- assertNotNull(function);
- impl.setFunction(function);
-
- assertEquals(function, impl.getFunction());
- assertEquals("UFNRTInt16", impl.toString());
- assertEquals(function.getReturnType().getType(), impl.getType());
-
- // 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.getFunction(Arrays.asList("ParameterInt16")));
- assertEquals(true, impl.isCollection());
- impl.setKeyPredicates(new ArrayList<UriParameterImpl>());
- assertEquals(false, impl.isCollection());
-
- assertEquals(parameter, impl.getParameters().get(0));
- }
-
- @Test
- public void testUriResourceImplKeyPred() {
- class Mock extends UriResourceWithKeysImpl {
- EdmType type;
-
- public Mock() {
- super(UriResourceKind.action);
- }
-
- @Override
- public EdmType getType() {
- return type;
- }
-
- public Mock setType(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(EdmTechProvider.nameETTwoKeyNav);
- EdmEntityType entityTypeBaseColl = edm.getEntityType(EdmTechProvider.nameETBaseTwoKeyNav);
- EdmEntityType entityTypeBaseEntry = edm.getEntityType(EdmTechProvider.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
- // TODO remove ???
- 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
- // TODO remove ???
- 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(EdmType type) {
- this.type = type;
- return this;
- }
-
- @Override
- public String toString() {
- return "mock";
- }
-
- }
-
- Mock impl = new Mock();
- EdmEntityType entityType = edm.getEntityType(EdmTechProvider.nameETTwoKeyNav);
- EdmEntityType entityTypeBaseColl = edm.getEntityType(EdmTechProvider.nameETBaseTwoKeyNav);
- EdmEntityType entityTypeBaseEntry = edm.getEntityType(EdmTechProvider.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(EdmTechProvider.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(EdmTechProvider.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(EdmTechProvider.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(EdmTechProvider.nameETBaseTwoKeyNav);
- impl.setSingleton(singleton);
-
- assertEquals("SINav", impl.toString());
- assertEquals(singleton, impl.getSingleton());
-
- assertEquals(singleton.getEntityType(), impl.getType());
- assertEquals(singleton.getEntityType(), impl.getEntityType());
- EdmEntityType entityType = impl.getEntityType(); // must work without cast
-
-
- 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(EdmTechProvider.nameETTwoKeyNav);
- impl.setType(entityType);
- impl.setVariableText("A");
-
- assertEquals("A", impl.toString());
- assertEquals(entityType, impl.getType());
- assertEquals("A", impl.getVariableText());
- assertEquals(false, impl.isCollection());
- impl.setCollection(true);
- assertEquals(true, impl.isCollection());
- }
-
- @Test
- public void testUriResourceStartingTypeFilterImpl () {
- UriResourceStartingTypeFilterImpl impl = new UriResourceStartingTypeFilterImpl();
- assertEquals(UriResourceKind.startingTypeFilter, impl.getKind());
-
- EdmEntityType entityType = edm.getEntityType(EdmTechProvider.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());
-
- }
-}