diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java deleted file mode 100644 index 8713348b1..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java +++ /dev/null @@ -1,133 +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.server.core.serializer.json; - -import static org.junit.Assert.assertFalse; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; -import static org.mockito.Mockito.when; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmSingleton; -import org.apache.olingo.server.api.ODataServer; -import org.apache.olingo.server.api.serializer.ODataFormat; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.junit.Before; -import org.junit.Test; - -public class ServiceDocumentTest { - - private Edm edm; - - @Before - public void before() { - - EdmEntitySet edmEntitySet1 = mock(EdmEntitySet.class); - when(edmEntitySet1.getName()).thenReturn("entitySetName1"); - when(edmEntitySet1.isIncludeInServiceDocument()).thenReturn(true); - - EdmEntitySet edmEntitySet2 = mock(EdmEntitySet.class); - when(edmEntitySet2.getName()).thenReturn("entitySetName2"); - when(edmEntitySet2.isIncludeInServiceDocument()).thenReturn(true); - - EdmEntitySet edmEntitySet3 = mock(EdmEntitySet.class); - when(edmEntitySet3.getName()).thenReturn("entitySetName3"); - when(edmEntitySet3.isIncludeInServiceDocument()).thenReturn(false); - - List entitySets = new ArrayList(); - entitySets.add(edmEntitySet1); - entitySets.add(edmEntitySet2); - entitySets.add(edmEntitySet3); - - EdmFunctionImport functionImport1 = mock(EdmFunctionImport.class); - when(functionImport1.getName()).thenReturn("functionImport1"); - when(functionImport1.isIncludeInServiceDocument()).thenReturn(true); - - EdmFunctionImport functionImport2 = mock(EdmFunctionImport.class); - when(functionImport2.getName()).thenReturn("functionImport2"); - when(functionImport2.isIncludeInServiceDocument()).thenReturn(true); - - EdmFunctionImport functionImport3 = mock(EdmFunctionImport.class); - when(functionImport3.getName()).thenReturn("functionImport3"); - when(functionImport3.isIncludeInServiceDocument()).thenReturn(false); - - List functionImports = new ArrayList(); - functionImports.add(functionImport1); - functionImports.add(functionImport2); - functionImports.add(functionImport3); - - EdmSingleton singleton1 = mock(EdmSingleton.class); - when(singleton1.getName()).thenReturn("singleton1"); - - EdmSingleton singleton2 = mock(EdmSingleton.class); - when(singleton2.getName()).thenReturn("singleton2"); - - EdmSingleton singleton3 = mock(EdmSingleton.class); - when(singleton3.getName()).thenReturn("singleton3"); - - List singletons = new ArrayList(); - singletons.add(singleton1); - singletons.add(singleton2); - singletons.add(singleton3); - - EdmEntityContainer edmEntityContainer = mock(EdmEntityContainer.class); - when(edmEntityContainer.getEntitySets()).thenReturn(entitySets); - when(edmEntityContainer.getFunctionImports()).thenReturn(functionImports); - when(edmEntityContainer.getSingletons()).thenReturn(singletons); - - edm = mock(Edm.class); - when(edm.getEntityContainer(null)).thenReturn(edmEntityContainer); - } - - @Test - public void writeServiceDocumentJson() throws Exception { - String serviceRoot = "http://localhost:8080/odata.svc"; - - ODataServer server = ODataServer.newInstance(); - assertNotNull(server); - - ODataSerializer serializer = server.getSerializer(ODataFormat.JSON); - assertNotNull(serializer); - - InputStream result = serializer.serviceDocument(edm, serviceRoot); - assertNotNull(result); - String jsonString = IOUtils.toString(result); - - assertTrue(jsonString.contains("entitySetName1")); - assertTrue(jsonString.contains("entitySetName2")); - assertFalse(jsonString.contains("entitySetName3")); - - assertTrue(jsonString.contains("functionImport1")); - assertTrue(jsonString.contains("functionImport2")); - assertFalse(jsonString.contains("functionImport3")); - - assertTrue(jsonString.contains("singleton1")); - assertTrue(jsonString.contains("singleton2")); - assertTrue(jsonString.contains("singleton3")); - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java deleted file mode 100644 index 17ac95709..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java +++ /dev/null @@ -1,254 +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.server.core.serializer.xml; - -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertTrue; -import static org.mockito.Mockito.mock; - -import java.io.IOException; -import java.io.InputStream; -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.ODataRuntimeException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.edm.Target; -import org.apache.olingo.server.api.ODataServer; -import org.apache.olingo.server.api.edm.provider.Action; -import org.apache.olingo.server.api.edm.provider.ActionImport; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EdmProvider; -import org.apache.olingo.server.api.edm.provider.EntityContainer; -import org.apache.olingo.server.api.edm.provider.EntitySet; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.EnumMember; -import org.apache.olingo.server.api.edm.provider.EnumType; -import org.apache.olingo.server.api.edm.provider.Function; -import org.apache.olingo.server.api.edm.provider.FunctionImport; -import org.apache.olingo.server.api.edm.provider.NavigationProperty; -import org.apache.olingo.server.api.edm.provider.NavigationPropertyBinding; -import org.apache.olingo.server.api.edm.provider.Parameter; -import org.apache.olingo.server.api.edm.provider.Property; -import org.apache.olingo.server.api.edm.provider.ReturnType; -import org.apache.olingo.server.api.edm.provider.Schema; -import org.apache.olingo.server.api.edm.provider.Singleton; -import org.apache.olingo.server.api.edm.provider.TypeDefinition; -import org.apache.olingo.server.api.serializer.ODataFormat; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.junit.Test; - -public class MetadataDocumentTest { - - @Test(expected = ODataRuntimeException.class) - public void metadataOnJsonResultsInException() { - ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.JSON); - serializer.metadataDocument(mock(Edm.class)); - } - - @Test - public void writeMetadataWithEmptyMockedEdm() { - ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML); - Edm edm = mock(Edm.class); - serializer.metadataDocument(edm); - } - - @Test - public void writeMetadataWithLocalTestEdm() throws Exception { - ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML); - Edm edm = new EdmProviderImpl(new TestMetadataProvider()); - InputStream metadata = serializer.metadataDocument(edm); - assertNotNull(metadata); - - String metadataString = IOUtils.toString(metadata); - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString.contains("")); - - assertTrue(metadataString.contains("")); - - assertTrue(metadataString - .contains("" + - "" + - "")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString.contains("")); - - assertTrue(metadataString - .contains("")); - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString.contains("")); - - assertTrue(metadataString - .contains("")); - - assertTrue(metadataString.contains("")); - } - - @Test - public void writeMetadataWithTechnicalScenario() { - ODataSerializer serializer = ODataServer.newInstance().getSerializer(ODataFormat.XML); - EdmProviderImpl edm = new EdmProviderImpl(new EdmTechProvider()); - InputStream metadata = serializer.metadataDocument(edm); - assertNotNull(metadata); - // The technical scenario is too big to verify. We are content for now to make sure we can serialize it. - // System.out.println(StringUtils.inputStreamToString(metadata, false)); - } - - private class TestMetadataProvider extends EdmProvider { - - @Override - public List getSchemas() throws ODataException { - Property p1 = new Property().setName("P1").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()); - String ns = "namespace"; - NavigationProperty n1 = new NavigationProperty().setName("N1") - .setType(new FullQualifiedName(ns, "ETBaseName")).setNullable(true).setPartner("N1"); - Property p2 = new Property().setName("P2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()); - NavigationProperty n2 = new NavigationProperty().setName("N2") - .setType(new FullQualifiedName(ns, "ETDerivedName")).setNullable(true).setPartner("N2"); - Schema schema = new Schema().setNamespace(ns).setAlias("alias"); - List complexTypes = new ArrayList(); - schema.setComplexTypes(complexTypes); - ComplexType ctBase = - new ComplexType().setName("CTBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties( - Arrays.asList(n1)); - complexTypes.add(ctBase); - ComplexType ctDerived = - new ComplexType().setName("CTDerivedName").setBaseType(new FullQualifiedName(ns, "CTBaseName")) - .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2)); - complexTypes.add(ctDerived); - - List entityTypes = new ArrayList(); - schema.setEntityTypes(entityTypes); - EntityType etBase = - new EntityType().setName("ETBaseName").setProperties(Arrays.asList(p1)).setNavigationProperties( - Arrays.asList(n1)); - entityTypes.add(etBase); - EntityType etDerived = - new EntityType().setName("ETDerivedName").setBaseType(new FullQualifiedName(ns, "ETBaseName")) - .setProperties(Arrays.asList(p2)).setNavigationProperties(Arrays.asList(n2)); - entityTypes.add(etDerived); - - List actions = new ArrayList(); - schema.setActions(actions); - // TODO:EntitySetPath - actions.add((new Action().setName("ActionWOParameter"))); - List parameters = new ArrayList(); - parameters.add(new Parameter().setName("param").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())); - parameters.add(new Parameter().setName("param2").setType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName()) - .setCollection(true)); - actions.add(new Action().setName("ActionName").setBound(true).setParameters(parameters).setReturnType( - new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName")))); - - List functions = new ArrayList(); - schema.setFunctions(functions); - functions.add((new Function().setName("FunctionWOParameter") - .setReturnType(new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName"))))); - functions.add(new Function().setName("FunctionName").setBound(true).setParameters(parameters).setReturnType( - new ReturnType().setType(new FullQualifiedName(ns, "CTBaseName")))); - - List enumTypes = new ArrayList(); - schema.setEnumTypes(enumTypes); - List members = new ArrayList(); - members.add(new EnumMember().setName("member").setValue("1")); - enumTypes.add(new EnumType().setName("EnumName").setFlags(true).setMembers(members)); - - List typeDefinitions = new ArrayList(); - schema.setTypeDefinitions(typeDefinitions); - typeDefinitions.add(new TypeDefinition().setName("typeDef") - .setUnderlyingType(EdmPrimitiveTypeKind.Int16.getFullQualifiedName())); - - EntityContainer container = new EntityContainer().setName("container"); - schema.setEntityContainer(container); - - List actionImports = new ArrayList(); - container.setActionImports(actionImports); - actionImports.add(new ActionImport().setName("actionImport").setAction( - new FullQualifiedName(ns, "ActionWOParameter")).setEntitySet( - new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName"))); - - List functionImports = new ArrayList(); - container.setFunctionImports(functionImports); - functionImports.add(new FunctionImport().setName("actionImport").setFunction( - new FullQualifiedName(ns, "FunctionName")).setEntitySet( - new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName"))); - - List entitySets = new ArrayList(); - container.setEntitySets(entitySets); - List nPB = new ArrayList(); - nPB.add(new NavigationPropertyBinding().setPath("N1").setTarget( - new Target().setEntityContainer(new FullQualifiedName(ns, "container")).setTargetName("EntitySetName"))); - entitySets.add(new EntitySet().setName("EntitySetName").setType(new FullQualifiedName(ns, "ETBaseName")) - .setNavigationPropertyBindings(nPB)); - - List singletons = new ArrayList(); - container.setSingletons(singletons); - singletons.add(new Singleton().setName("SingletonName").setType(new FullQualifiedName(ns, "ETBaseName")) - .setNavigationPropertyBindings(nPB)); - - List schemas = new ArrayList(); - schemas.add(schema); - return schemas; - } - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java deleted file mode 100644 index f54ad5799..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java +++ /dev/null @@ -1,151 +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.server.core.uri; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.olingo.server.core.uri.parser.RawUri; -import org.apache.olingo.server.core.uri.parser.UriDecoder; -import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; -import org.junit.Test; - -public class RawUriTest { - - private RawUri runRawParser(final String uri, final int scipSegments) throws UriParserSyntaxException { - return UriDecoder.decodeUri(uri, scipSegments); - } - - @Test - public void testOption() throws Exception { - RawUri rawUri; - rawUri = runRawParser("?", 0); - checkOptionCount(rawUri, 0); - - rawUri = runRawParser("?a", 0); - checkOption(rawUri, 0, "a", ""); - - rawUri = runRawParser("?a=b", 0); - checkOption(rawUri, 0, "a", "b"); - - rawUri = runRawParser("?=", 0); - checkOption(rawUri, 0, "", ""); - - rawUri = runRawParser("?=b", 0); - checkOption(rawUri, 0, "", "b"); - - rawUri = runRawParser("?a&c", 0); - checkOption(rawUri, 0, "a", ""); - checkOption(rawUri, 1, "c", ""); - - rawUri = runRawParser("?a=b&c", 0); - checkOption(rawUri, 0, "a", "b"); - checkOption(rawUri, 1, "c", ""); - - rawUri = runRawParser("?a=b&c=d", 0); - checkOption(rawUri, 0, "a", "b"); - checkOption(rawUri, 1, "c", "d"); - - rawUri = runRawParser("?=&=", 0); - checkOption(rawUri, 0, "", ""); - checkOption(rawUri, 1, "", ""); - - rawUri = runRawParser("?=&c=d", 0); - checkOption(rawUri, 0, "", ""); - checkOption(rawUri, 1, "c", "d"); - } - - private void checkOption(final RawUri rawUri, final int index, final String name, final String value) { - RawUri.QueryOption option = rawUri.queryOptionListDecoded.get(index); - - assertEquals(name, option.name); - assertEquals(value, option.value); - - } - - private void checkOptionCount(final RawUri rawUri, final int count) { - assertEquals(count, rawUri.queryOptionListDecoded.size()); - } - - @Test - public void testPath() throws Exception { - RawUri rawUri; - - rawUri = runRawParser("http://test.org", 0); - checkPath(rawUri, "", new ArrayList()); - - rawUri = runRawParser("http://test.org/", 0); - checkPath(rawUri, "/", Arrays.asList("")); - - rawUri = runRawParser("http://test.org/entitySet", 0); - checkPath(rawUri, "/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 0); - checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); - - rawUri = runRawParser("http://test.org/nonServiceSegment/entitySet", 1); - checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("", 0); - checkPath(rawUri, "", new ArrayList()); - - rawUri = runRawParser("/", 0); - checkPath(rawUri, "/", Arrays.asList("")); - - rawUri = runRawParser("/entitySet", 0); - checkPath(rawUri, "/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("entitySet", 0); - checkPath(rawUri, "entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("nonServiceSegment/entitySet", 0); - checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); - - rawUri = runRawParser("nonServiceSegment/entitySet", 1); - checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("http://test.org/a?abc=xx+yz", 0); - } - - @Test - public void testSplitt() { - UriDecoder.splitt("", '/'); - UriDecoder.splitt("/", '/'); - UriDecoder.splitt("a", '/'); - UriDecoder.splitt("a/", '/'); - UriDecoder.splitt("/a", '/'); - UriDecoder.splitt("a/a", '/'); - } - - private void checkPath(final RawUri rawUri, final String path, final List list) { - assertEquals(path, rawUri.path); - - assertEquals(list.size(), rawUri.pathSegmentListDecoded.size()); - - int i = 0; - while (i < list.size()) { - assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i)); - i++; - } - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java deleted file mode 100644 index a71762c41..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/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.server.core.uri; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.server.api.uri.UriInfoAll; -import org.apache.olingo.server.api.uri.UriInfoBatch; -import org.apache.olingo.server.api.uri.UriInfoCrossjoin; -import org.apache.olingo.server.api.uri.UriInfoEntityId; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriInfoMetadata; -import org.apache.olingo.server.api.uri.UriInfoResource; -import org.apache.olingo.server.api.uri.UriInfoService; -import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.queryoption.CountOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.FormatOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.IdOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.LevelsOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SearchOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SkipOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SkipTokenOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.TopOptionImpl; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; -import org.junit.Test; - -public class UriInfoImplTest { - - Edm edm = new EdmProviderImpl(new EdmTechTestProvider()); - - @Test - public void testKind() { - UriInfoImpl uriInfo = new UriInfoImpl().setKind(UriInfoKind.all); - assertEquals(UriInfoKind.all, uriInfo.getKind()); - } - - @Test - public void testCasts() { - UriInfoImpl uriInfo = new UriInfoImpl(); - - UriInfoAll all = uriInfo.asUriInfoAll(); - assertEquals(uriInfo, all); - - UriInfoBatch batch = uriInfo.asUriInfoBatch(); - assertEquals(uriInfo, batch); - - UriInfoCrossjoin crossjoin = uriInfo.asUriInfoCrossjoin(); - assertEquals(uriInfo, crossjoin); - - UriInfoEntityId entityID = uriInfo.asUriInfoEntityId(); - assertEquals(uriInfo, entityID); - - UriInfoMetadata metadata = uriInfo.asUriInfoMetadata(); - assertEquals(uriInfo, metadata); - - UriInfoResource resource = uriInfo.asUriInfoResource(); - assertEquals(uriInfo, resource); - - UriInfoService service = uriInfo.asUriInfoService(); - assertEquals(uriInfo, service); - - } - - @Test - public void testEntityNames() { - UriInfoImpl uriInfo = new UriInfoImpl(); - uriInfo.addEntitySetName("A"); - uriInfo.addEntitySetName("B"); - - assertEquals("A", uriInfo.getEntitySetNames().get(0)); - assertEquals("B", uriInfo.getEntitySetNames().get(1)); - - } - - @Test - public void testResourceParts() { - UriInfoImpl uriInfo = new UriInfoImpl(); - - UriResourceActionImpl action = new UriResourceActionImpl(); - UriResourceEntitySetImpl entitySet0 = new UriResourceEntitySetImpl(); - UriResourceEntitySetImpl entitySet1 = new UriResourceEntitySetImpl(); - - uriInfo.addResourcePart(action); - uriInfo.addResourcePart(entitySet0); - - assertEquals(action, uriInfo.getUriResourceParts().get(0)); - assertEquals(entitySet0, uriInfo.getUriResourceParts().get(1)); - - assertEquals(entitySet0, uriInfo.getLastResourcePart()); - - uriInfo.addResourcePart(entitySet1); - assertEquals(entitySet1, uriInfo.getLastResourcePart()); - } - - @Test - public void testCustomQueryOption() { - UriInfoImpl uriInfo = new UriInfoImpl(); - - List queryOptions = new ArrayList(); - - ExpandOptionImpl expand = new ExpandOptionImpl(); - FilterOptionImpl filter = new FilterOptionImpl(); - FormatOptionImpl format = new FormatOptionImpl(); - IdOptionImpl id = new IdOptionImpl(); - CountOptionImpl inlinecount = new CountOptionImpl(); - OrderByOptionImpl orderby = new OrderByOptionImpl(); - SearchOptionImpl search = new SearchOptionImpl(); - SelectOptionImpl select = new SelectOptionImpl(); - SkipOptionImpl skip = new SkipOptionImpl(); - SkipTokenOptionImpl skipToken = new SkipTokenOptionImpl(); - TopOptionImpl top = new TopOptionImpl(); - LevelsOptionImpl levels = new LevelsOptionImpl(); - - CustomQueryOptionImpl customOption0 = new CustomQueryOptionImpl(); - customOption0.setText("A"); - CustomQueryOptionImpl customOption1 = new CustomQueryOptionImpl(); - customOption1.setText("B"); - - QueryOptionImpl queryOption = new QueryOptionImpl(); - - queryOptions.add(expand); - queryOptions.add(filter); - queryOptions.add(format); - queryOptions.add(id); - queryOptions.add(inlinecount); - queryOptions.add(orderby); - queryOptions.add(search); - queryOptions.add(select); - queryOptions.add(skip); - queryOptions.add(skipToken); - queryOptions.add(top); - queryOptions.add(customOption0); - queryOptions.add(customOption1); - queryOptions.add(levels);// not stored - queryOptions.add(queryOption);// not stored - uriInfo.setQueryOptions(queryOptions); - - assertEquals(expand, uriInfo.getExpandOption()); - assertEquals(filter, uriInfo.getFilterOption()); - assertEquals(format, uriInfo.getFormatOption()); - assertEquals(id, uriInfo.getIdOption()); - assertEquals(inlinecount, uriInfo.getCountOption()); - assertEquals(orderby, uriInfo.getOrderByOption()); - assertEquals(search, uriInfo.getSearchOption()); - assertEquals(select, uriInfo.getSelectOption()); - assertEquals(skip, uriInfo.getSkipOption()); - assertEquals(skipToken, uriInfo.getSkipTokenOption()); - assertEquals(top, uriInfo.getTopOption()); - - List customQueryOptions = uriInfo.getCustomQueryOptions(); - assertEquals(customOption0, customQueryOptions.get(0)); - assertEquals(customOption1, customQueryOptions.get(1)); - } - - @Test - public void testFragment() { - UriInfoImpl uriInfo = new UriInfoImpl(); - uriInfo.setFragment("F"); - assertEquals("F", uriInfo.getFragment()); - } - - @Test - public void testEntityTypeCast() { - UriInfoImpl uriInfo = new UriInfoImpl(); - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); - assertNotNull(entityType); - - uriInfo.setEntityTypeCast(entityType); - assertEquals(entityType, uriInfo.getEntityTypeCast()); - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.java deleted file mode 100644 index d6beef0d2..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/UriResourceImplTest.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.server.core.uri; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmActionImport; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.commons.api.edm.EdmFunctionImport; -import org.apache.olingo.commons.api.edm.EdmNavigationProperty; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.core.edm.primitivetype.EdmPrimitiveTypeFactory; -import org.apache.olingo.server.api.uri.UriResourceKind; -import org.apache.olingo.server.core.edm.provider.EdmComplexTypeImpl; -import org.apache.olingo.server.core.edm.provider.EdmEntitySetImpl; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.edm.provider.EdmSingletonImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.apache.olingo.server.tecsvc.provider.ActionProvider; -import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; -import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; -import org.junit.Test; - -public class UriResourceImplTest { - - Edm edm = new EdmProviderImpl(new EdmTechTestProvider()); - - @Test - public void testUriParameterImpl() { - UriParameterImpl impl = new UriParameterImpl(); - ExpressionImpl expression = new LiteralImpl().setText("Expression"); - - impl.setText("Text"); - impl.setName("A"); - impl.setAlias("@A"); - impl.setExpression(expression); - - assertEquals("Text", impl.getText()); - assertEquals("A", impl.getName()); - assertEquals("@A", impl.getAlias()); - assertEquals(expression, impl.getExression()); - } - - @Test - public void testUriResourceActionImpl() { - UriResourceActionImpl impl = new UriResourceActionImpl(); - assertEquals(UriResourceKind.action, impl.getKind()); - assertEquals("", impl.toString()); - - // action - EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTETParam); - impl.setAction(action); - assertEquals(action, impl.getAction()); - assertEquals(ActionProvider.nameUARTETParam.getName(), impl.toString()); - - // action import - impl = new UriResourceActionImpl(); - EdmActionImport actionImport = edm.getEntityContainer(null).getActionImport("AIRTPrimParam"); - impl.setActionImport(actionImport); - assertEquals(actionImport, impl.getActionImport()); - assertEquals(actionImport.getUnboundAction(), impl.getAction()); - assertEquals(false, impl.isCollection()); - assertEquals("AIRTPrimParam", impl.toString()); - assertEquals(actionImport.getUnboundAction().getReturnType().getType(), impl.getType()); - } - - @Test - public void testUriResourceLambdaAllImpl() { - UriResourceLambdaAllImpl impl = new UriResourceLambdaAllImpl(); - assertEquals(UriResourceKind.lambdaAll, impl.getKind()); - - ExpressionImpl expression = new LiteralImpl().setText("Expression"); - impl.setExpression(expression); - impl.setLamdaVariable("A"); - - assertEquals(false, impl.isCollection()); - assertEquals(expression, impl.getExpression()); - assertEquals("A", impl.getLambdaVariable()); - assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType()); - assertEquals("all", impl.toString()); - } - - @Test - public void testUriResourceLambdaAnyImpl() { - UriResourceLambdaAnyImpl impl = new UriResourceLambdaAnyImpl(); - assertEquals(UriResourceKind.lambdaAny, impl.getKind()); - - ExpressionImpl expression = new LiteralImpl().setText("Expression"); - impl.setExpression(expression); - impl.setLamdaVariable("A"); - - assertEquals(false, impl.isCollection()); - assertEquals(expression, impl.getExpression()); - assertEquals("A", impl.getLamdaVariable()); - assertEquals(EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean), impl.getType()); - assertEquals("any", impl.toString()); - } - - @Test - public void testUriResourceComplexPropertyImpl() { - UriResourceComplexPropertyImpl impl = new UriResourceComplexPropertyImpl(); - assertEquals(UriResourceKind.complexProperty, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); - EdmProperty property = (EdmProperty) entityType.getProperty("PropertyComplex"); - impl.setProperty(property); - - assertEquals(property, impl.getProperty()); - assertEquals(property.getName(), impl.toString()); - assertEquals(false, impl.isCollection()); - assertEquals(property.getType(), impl.getType()); - assertEquals(property.getType(), impl.getComplexType()); - impl.getComplexType(); - - EdmComplexTypeImpl complexTypeImplType = - (EdmComplexTypeImpl) edm.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav); - - impl.setTypeFilter(complexTypeImplType); - assertEquals(complexTypeImplType, impl.getTypeFilter()); - assertEquals(complexTypeImplType, impl.getComplexTypeFilter()); - impl.getComplexTypeFilter(); - - } - - @Test - public void testUriResourcePrimitivePropertyImpl() { - UriResourcePrimitivePropertyImpl impl = new UriResourcePrimitivePropertyImpl(); - assertEquals(UriResourceKind.primitiveProperty, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); - EdmProperty property = (EdmProperty) entityType.getProperty("PropertyInt16"); - impl.setProperty(property); - - assertEquals(property, impl.getProperty()); - assertEquals(property.getName(), impl.toString()); - assertEquals(false, impl.isCollection()); - assertEquals(property.getType(), impl.getType()); - } - - @Test - public void testUriResourceCountImpl() { - UriResourceCountImpl impl = new UriResourceCountImpl(); - assertEquals(UriResourceKind.count, impl.getKind()); - assertEquals("$count", impl.toString()); - } - - @Test - public void testUriResourceEntitySetImpl() { - UriResourceEntitySetImpl impl = new UriResourceEntitySetImpl(); - assertEquals(UriResourceKind.entitySet, impl.getKind()); - - EdmEntitySetImpl entitySet = (EdmEntitySetImpl) edm.getEntityContainer(null).getEntitySet("ESAllPrim"); - impl.setEntitSet(entitySet); - - assertEquals("ESAllPrim", impl.toString()); - assertEquals(entitySet, impl.getEntitySet()); - - assertEquals(entitySet.getEntityType(), impl.getType()); - assertEquals(entitySet.getEntityType(), impl.getEntityType()); - impl.getEntityType(); - - // is Collection - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(new ArrayList()); - assertEquals(false, impl.isCollection()); - } - - @Test - public void testUriResourceFunctionImpl() { - UriResourceFunctionImpl impl = new UriResourceFunctionImpl(); - assertEquals(UriResourceKind.function, impl.getKind()); - assertEquals("", impl.toString()); - - // function - EdmFunction function = (EdmFunction) edm.getEntityContainer(null).getFunctionImport("FINRTInt16") - .getUnboundFunction(new ArrayList()); - assertNotNull(function); - impl.setFunction(function); - - assertEquals(function, impl.getFunction()); - assertEquals("UFNRTInt16", impl.toString()); - assertEquals(function.getReturnType().getType(), impl.getType()); - assertEquals(false, impl.isParameterListFilled()); - - // function import - impl = new UriResourceFunctionImpl(); - EdmFunctionImport functionImport = edm.getEntityContainer(null).getFunctionImport("FINRTInt16"); - impl.setFunctionImport(functionImport, new ArrayList()); - assertEquals(functionImport, impl.getFunctionImport()); - assertEquals("FINRTInt16", impl.toString()); - - // function collection - impl = new UriResourceFunctionImpl(); - functionImport = edm.getEntityContainer(null).getFunctionImport("FICRTESTwoKeyNavParam"); - assertNotNull(function); - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - impl.setFunctionImport(functionImport, Arrays.asList(parameter)); - assertEquals("FICRTESTwoKeyNavParam", impl.toString()); - - impl.setFunction(functionImport.getUnboundFunction(Arrays.asList("ParameterInt16"))); - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(new ArrayList()); - assertEquals(false, impl.isCollection()); - - assertEquals(parameter, impl.getParameters().get(0)); - assertEquals(true, impl.isParameterListFilled()); - } - - @Test - public void testUriResourceImplKeyPred() { - class Mock extends UriResourceWithKeysImpl { - - EdmType type; - - public Mock() { - super(UriResourceKind.action); - } - - @Override - public EdmType getType() { - return type; - } - - public Mock setType(final EdmType type) { - this.type = type; - return this; - } - - @Override - public boolean isCollection() { - return false; - } - - @Override - public String toString() { - return "mock"; - } - } - - Mock impl = new Mock(); - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - EdmEntityType entityTypeBaseEntry = edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - impl.setType(entityType); - assertEquals(entityType, impl.getType()); - assertEquals("mock", impl.toString(false)); - assertEquals("mock", impl.toString(true)); - - // set both - impl.setCollectionTypeFilter(entityTypeBaseColl); - assertEquals(entityTypeBaseColl, impl.getTypeFilterOnCollection()); - assertEquals("mock", impl.toString(false)); - assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true)); - impl.setEntryTypeFilter(entityTypeBaseEntry); - assertEquals(entityTypeBaseEntry, impl.getTypeFilterOnEntry()); - assertEquals("mock", impl.toString(false)); - assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav/()com.sap.odata.test1.ETTwoBaseTwoKeyNav", - impl.toString(true)); - - // set entry - impl = new Mock(); - impl.setType(entityType); - impl.setEntryTypeFilter(entityTypeBaseEntry); - assertEquals(entityTypeBaseEntry, impl.getTypeFilterOnEntry()); - assertEquals("mock", impl.toString(false)); - assertEquals("mock/com.sap.odata.test1.ETTwoBaseTwoKeyNav", impl.toString(true)); - - // set collection - impl = new Mock(); - impl.setType(entityType); - impl.setCollectionTypeFilter(entityTypeBaseColl); - assertEquals(entityTypeBaseColl, impl.getTypeFilterOnCollection()); - assertEquals("mock", impl.toString(false)); - assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true)); - - impl = new Mock(); - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - List keyPredicates = new ArrayList(); - keyPredicates.add(parameter); - - impl.setKeyPredicates(keyPredicates); - assertNotNull(null, impl.getKeyPredicates()); - - } - - @Test - public void testUriResourceImplTyped() { - class Mock extends UriResourceTypedImpl { - - EdmType type; - - public Mock() { - super(UriResourceKind.action); - } - - @Override - public EdmType getType() { - return type; - } - - @Override - public boolean isCollection() { - return false; - } - - public Mock setType(final EdmType type) { - this.type = type; - return this; - } - - @Override - public String toString() { - return "mock"; - } - - } - - Mock impl = new Mock(); - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - edm.getEntityType(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - impl.setType(entityType); - assertEquals("mock", impl.toString()); - assertEquals("mock", impl.toString(true)); - assertEquals("mock", impl.toString(false)); - - impl.setTypeFilter(entityTypeBaseColl); - assertEquals(entityTypeBaseColl, impl.getTypeFilter()); - assertEquals("mock", impl.toString()); - assertEquals("mock/com.sap.odata.test1.ETBaseTwoKeyNav", impl.toString(true)); - assertEquals("mock", impl.toString(false)); - // - } - - @Test - public void testUriResourceItImpl() { - UriResourceItImpl impl = new UriResourceItImpl(); - assertEquals(UriResourceKind.it, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - assertEquals("$it", impl.toString()); - - impl.setType(entityType); - assertEquals(entityType, impl.getType()); - - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - List keyPredicates = new ArrayList(); - keyPredicates.add(parameter); - - assertEquals(false, impl.isCollection()); - impl.setCollection(true); - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(keyPredicates); - assertEquals(false, impl.isCollection()); - } - - @Test - public void testUriResourceNavigationPropertyImpl() { - UriResourceNavigationPropertyImpl impl = new UriResourceNavigationPropertyImpl(); - assertEquals(UriResourceKind.navigationProperty, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - EdmNavigationProperty property = (EdmNavigationProperty) entityType.getProperty("NavPropertyETKeyNavMany"); - assertNotNull(property); - - impl.setNavigationProperty(property); - assertEquals(property, impl.getProperty()); - - assertEquals("NavPropertyETKeyNavMany", impl.toString()); - assertEquals(property.getType(), impl.getType()); - - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - List keyPredicates = new ArrayList(); - keyPredicates.add(parameter); - - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(keyPredicates); - assertEquals(false, impl.isCollection()); - } - - @Test - public void testUriResourceRefImpl() { - UriResourceRefImpl impl = new UriResourceRefImpl(); - assertEquals(UriResourceKind.ref, impl.getKind()); - assertEquals("$ref", impl.toString()); - } - - @Test - public void testUriResourceRootImpl() { - UriResourceRootImpl impl = new UriResourceRootImpl(); - assertEquals(UriResourceKind.root, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - assertEquals("$root", impl.toString()); - - impl.setType(entityType); - assertEquals(entityType, impl.getType()); - - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - List keyPredicates = new ArrayList(); - keyPredicates.add(parameter); - - assertEquals(false, impl.isCollection()); - impl.setCollection(true); - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(keyPredicates); - assertEquals(false, impl.isCollection()); - } - - @Test - public void testUriResourceSingletonImpl() { - UriResourceSingletonImpl impl = new UriResourceSingletonImpl(); - assertEquals(UriResourceKind.singleton, impl.getKind()); - - EdmSingletonImpl singleton = (EdmSingletonImpl) edm.getEntityContainer(null).getSingleton("SINav"); - EdmEntityType entityTypeBaseColl = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - impl.setSingleton(singleton); - - assertEquals("SINav", impl.toString()); - assertEquals(singleton, impl.getSingleton()); - - assertEquals(singleton.getEntityType(), impl.getType()); - assertEquals(singleton.getEntityType(), impl.getEntityType()); - impl.getEntityType(); - - impl.setTypeFilter(entityTypeBaseColl); - assertEquals(entityTypeBaseColl, impl.getEntityTypeFilter()); - - // is Collection - assertEquals(false, impl.isCollection()); - } - - @Test - public void testUriResourceValueImpl() { - UriResourceValueImpl impl = new UriResourceValueImpl(); - assertEquals(UriResourceKind.value, impl.getKind()); - assertEquals("$value", impl.toString()); - } - - @Test - public void testUriResourceLambdaVarImpl() { - UriResourceLambdaVarImpl impl = new UriResourceLambdaVarImpl(); - assertEquals(UriResourceKind.lambdaVariable, impl.getKind()); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - impl.setType(entityType); - impl.setVariableText("A"); - - assertEquals("A", impl.toString()); - assertEquals(entityType, impl.getType()); - assertEquals("A", impl.getVariableName()); - assertEquals(false, impl.isCollection()); - impl.setCollection(true); - assertEquals(true, impl.isCollection()); - } - - @Test - public void testUriResourceStartingTypeFilterImpl() { - UriResourceStartingTypeFilterImpl impl = new UriResourceStartingTypeFilterImpl(); - - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETTwoKeyNav); - - impl.setType(entityType); - assertEquals("com.sap.odata.test1.ETTwoKeyNav", impl.toString()); - assertEquals(entityType, impl.getType()); - - UriParameterImpl parameter = new UriParameterImpl().setName("ParameterInt16"); - List keyPredicates = new ArrayList(); - keyPredicates.add(parameter); - - assertEquals(false, impl.isCollection()); - impl.setCollection(true); - assertEquals(true, impl.isCollection()); - impl.setKeyPredicates(keyPredicates); - assertEquals(false, impl.isCollection()); - - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java deleted file mode 100644 index 00772a566..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java +++ /dev/null @@ -1,5110 +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.server.core.uri.antlr; - -import java.io.UnsupportedEncodingException; -import java.util.Arrays; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.core.Encoder; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriResourceKind; -import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.apache.olingo.server.core.uri.testutil.FilterValidator; -import org.apache.olingo.server.core.uri.testutil.ResourceValidator; -import org.apache.olingo.server.core.uri.testutil.TestUriValidator; -import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; -import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; -import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider; -import org.apache.olingo.server.tecsvc.provider.PropertyProvider; -import org.junit.Test; - -public class TestFullResourcePath { - Edm edm = null; - TestUriValidator testUri = null; - ResourceValidator testRes = null; - FilterValidator testFilter = null; - - public TestFullResourcePath() { - edm = new EdmProviderImpl(new EdmTechTestProvider()); - testUri = new TestUriValidator().setEdm(edm); - testRes = new ResourceValidator().setEdm(edm); - testFilter = new FilterValidator().setEdm(edm); - } - - @Test - public void test() throws UriParserException { - - } - - @Test - public void testFunctionBound_varOverloading() { - // on ESTwoKeyNav - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // with string parameter - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')").goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // with string parameter - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()").goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav); - } - - @Test - public void runBfuncBnCpropCastRtEs() { - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESBaseTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESBaseTwoKeyNav"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESBaseTwoKeyNav()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESBaseTwoKeyNav") - .isType(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isUriPathInfoKind(UriResourceKind.count); - - } - - @Test - public void runBfuncBnCpropCollRtEs() { - testUri.run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isUriPathInfoKind(UriResourceKind.complexProperty) - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .n() - .isFunction("BFCCollCTPrimCompRTESAllPrim"); - - testUri - .run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isUriPathInfoKind(UriResourceKind.complexProperty) - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .n() - .isFunction("BFCCollCTPrimCompRTESAllPrim") - .isType(EntityTypeProvider.nameETAllPrim, true) - .n() - .isUriPathInfoKind(UriResourceKind.count); - } - - @Test - public void runBfuncBnCpropRtEs() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')" - + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isUriPathInfoKind(UriResourceKind.complexProperty) - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESTwoKeyNav"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')" - + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isUriPathInfoKind(UriResourceKind.complexProperty) - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .n() - .isUriPathInfoKind(UriResourceKind.count); - - } - - @Test - public void runBfuncBnEntityRtEs() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isFunction("BFCETTwoKeyNavRTESTwoKeyNav"); - } - - @Test - public void runBfuncBnEntityCastRtEs() { - testUri - .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isFunction("BFCETBaseTwoKeyNavRTESTwoKeyNav"); - - testUri - .run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='(''2'')')" - + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'(''2'')'") - .n() - .isFunction("BFCETBaseTwoKeyNavRTESTwoKeyNav"); - } - - @Test - public void runBfuncBnEsCastRtEs() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/com.sap.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/com.sap.odata.test1.BFCESBaseTwoKeyNavRTESBaseTwoKey()" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isFunction("BFCESBaseTwoKeyNavRTESBaseTwoKey") - .isType(EntityTypeProvider.nameETBaseTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav" - + "/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - } - - @Test - public void runBfuncBnEsRtCprop() { - testUri.run("ESAllPrim/com.sap.odata.test1.BFCESAllPrimRTCTAllPrim()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .n() - .isFunction("BFCESAllPrimRTCTAllPrim") - .isType(ComplexTypeProvider.nameCTAllPrim); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()/com.sap.odata.test1.CTBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTCTTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim, false) - .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase); - } - - @Test - public void runBfuncBnEsRtCpropColl() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTCollCTTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim, true); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTCollCTTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim, true) - .n() - .isUriPathInfoKind(UriResourceKind.count); - } - - @Test - public void runBfuncBnEsRtEntityPpNp() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()/NavPropertyETKeyNavOne") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTTwoKeyNav") - .n() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()/NavPropertyETKeyNavOne/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTTwoKeyNav") - .n() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .n() - .isUriPathInfoKind(UriResourceKind.ref); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/NavPropertyETMediaOne/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isNavProperty("NavPropertyETMediaOne", EntityTypeProvider.nameETMedia, false) - .n() - .isValue(); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavOne/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavOne/PropertyComplex/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp) - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTAllPrim); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavOne/PropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/PropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - } - - @Test - public void runBfuncBnEsRtEntyPpNpCast() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTTwoKeyNav()" - + "/NavPropertyETTwoKeyNavOne/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTTwoKeyNav") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri - .run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()(PropertyInt16=1,PropertyString='2')" - + "/NavPropertyETTwoKeyNavOne/com.sap.odata.test1.ETTwoBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - } - - @Test - public void runBfuncBnEsRtEntityPpCp() { - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTNavFiveProp); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTNavFiveProp) - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyComplex/PropertyInt16/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isComplex("PropertyComplex") - .isType(ComplexTypeProvider.nameCTNavFiveProp) - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .n() - .isValue(); - - } - - @Test - public void runBfuncBnEsRtEntyPpCpCast() { - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isComplex("PropertyComplexTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim) - .isTypeFilter(ComplexTypeProvider.nameCTTwoBase); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNavParam(ParameterString='1')" - + "/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')" - + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNavParam") - .isParameter(0, "ParameterString", "'1'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isComplex("PropertyComplexTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim) - .isTypeFilter(ComplexTypeProvider.nameCTTwoBase); - } - - @Test - public void runBfuncBnEsRtEntityPpSp() { - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESKeyNavRTETKeyNav()/PropertyInt16/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESKeyNavRTETKeyNav") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .n() - .isValue(); - - } - - @Test - public void runBfuncBnEsRtEs() { - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isParameter(0, "ParameterString", "'2'") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - testUri.run("ESKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='3')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isParameter(0, "ParameterString", "'3'") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .n() - .isCount(); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()(PropertyInt16=1,PropertyString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'"); - - } - - @Test - public void runBfuncBnEsRtEsBa() { - - testUri.run("ESKeyNav(PropertyInt16=1)/CollPropertyComplex" - + "/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()/com.sap.odata.test1.BAESAllPrimRTETAllPrim") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp) - .n() - .isFunction("BFCCollCTPrimCompRTESAllPrim") - .n() - .isAction("BAESAllPrimRTETAllPrim"); - - } - - @Test - public void runBfuncBnEsRtPrim() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTString"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTString") - .isType(PropertyProvider.nameString) - .n() - .isValue(); - } - - @Test - public void runbfuncBnEsRtPrimColl() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTCollString") - .isType(PropertyProvider.nameString, true); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isFunction("BFCESTwoKeyNavRTCollString") - .isType(PropertyProvider.nameString, true) - .n() - .isCount(); - } - - @Test - public void runBfuncBnPpropCollRtEs() { - testUri.run("ESKeyNav(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .n() - .isFunction("BFCCollStringRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true); - - testUri.run("ESKeyNav(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .n() - .isFunction("BFCCollStringRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .n() - .isCount(); - } - - @Test - public void runBfuncBnPpropRtEs() { - - testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .n() - .isFunction("BFCStringRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true); - - testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .n() - .isFunction("BFCStringRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .n() - .isCount(); - - testUri.run("ESKeyNav(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .n() - .isFunction("BFCStringRTESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .n() - .isRef(); - } - - @Test - public void runBfuncBnSingleRtEs() { - - testUri.run("SINav/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isFunction("BFCSINavRTESTwoKeyNav"); - } - - @Test - public void runBfuncBnSingleCastRtEs() { - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTESBaseTwoKey()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isFunction("BFCETBaseTwoKeyNavRTESBaseTwoKey"); - } - - @Test - public void runActionBound_on_EntityEntry() { - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.BAETTwoKeyNavRTETTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isAction("BAETTwoKeyNavRTETTwoKeyNav"); - - testUri.run("ESKeyNav(PropertyInt16=1)/com.sap.odata.test1.BAETTwoKeyNavRTETTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isAction("BAETTwoKeyNavRTETTwoKeyNav"); - } - - @Test - public void runActionBound_on_EntityCollection() { - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .n() - .isAction("BAESTwoKeyNavRTESTwoKeyNav"); - } - - @Test - public void runFunctionBound_on_var_Types() { - - // on primitive - testUri.run("ESAllPrim(1)/PropertyString/com.sap.odata.test1.BFCStringRTESTwoKeyNav()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETAllPrim, false) - .at(1) - .isUriPathInfoKind(UriResourceKind.primitiveProperty) - .isType(PropertyProvider.nameString); - - // on collection of primitive - testUri.run("ESCollAllPrim(1)/CollPropertyString/com.sap.odata.test1.BFCCollStringRTESTwoKeyNav()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETCollAllPrim, false) - .at(1) - .isUriPathInfoKind(UriResourceKind.primitiveProperty) - .isType(PropertyProvider.nameString); - - // on complex - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')" - + "/PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNav()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .at(1) - .isUriPathInfoKind(UriResourceKind.complexProperty) - .at(2) - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // on collection of complex - testUri.run("ESKeyNav(1)/CollPropertyComplex/com.sap.odata.test1.BFCCollCTPrimCompRTESAllPrim()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .at(1) - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .at(2) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETAllPrim); - - // on entity - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')" - + "/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // on collection of entity - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .goPath() - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1).isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav); - } - - @Test - public void runActionBound_on_EntityCast() { - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/com.sap.odata.test1.BAETBaseTwoKeyNavRTETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isAction("BAETBaseTwoKeyNavRTETBaseTwoKeyNav"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav/com.sap.odata.test1.BAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav) - .n() - .isAction("BAETTwoBaseTwoKeyNavRTETBaseTwoKeyNav"); - } - - @Test - public void runCrossjoin() { - testUri.run("$crossjoin(ESKeyNav)") - .isKind(UriInfoKind.crossjoin) - .isCrossJoinEntityList(Arrays.asList("ESKeyNav")); - - testUri.run("$crossjoin(ESKeyNav, ESTwoKeyNav)") - .isKind(UriInfoKind.crossjoin) - .isCrossJoinEntityList(Arrays.asList("ESKeyNav", "ESTwoKeyNav")); - } - - @Test - public void runCrossjoinError() { - testUri.runEx("$crossjoin").isExSyntax(0); - testUri.runEx("$crossjoin/error").isExSyntax(0); - testUri.runEx("$crossjoin()").isExSyntax(0); - // testUri.runEx("$crossjoin(ESKeyNav, ESTwoKeyNav)/invalid").isExSyntax(0); - } - - @Test - public void runEntityId() { - testUri.run("$entity?$id=ESKeyNav(1)") - .isKind(UriInfoKind.entityId) - .isIdText("ESKeyNav(1)"); - testUri.run("$entity/com.sap.odata.test1.ETKeyNav?$id=ESKeyNav(1)") - .isKind(UriInfoKind.entityId) - .isEntityType(EntityTypeProvider.nameETKeyNav) - .isIdText("ESKeyNav(1)"); - } - - @Test - public void runEntityIdError() { - // TODO planned: move to validator - // testUri.runEx("$entity").isExSyntax(0); - // testUri.runEx("$entity?$idfalse=ESKeyNav(1)").isExSyntax(0); - // testUri.runEx("$entity/com.sap.odata.test1.invalidType?$id=ESKeyNav(1)").isExSemantic(0); - // testUri.runEx("$entity/invalid?$id=ESKeyNav(1)").isExSyntax(0); - } - - @Test - public void runEsName() { - testUri.run("ESAllPrim") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .isType(EntityTypeProvider.nameETAllPrim, true); - - testUri.run("ESAllPrim/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .isType(EntityTypeProvider.nameETAllPrim, true) - .n() - .isCount(); - } - - @Test - public void runEsNameError() { - - testUri.runEx("ESAllPrim/$count/$ref").isExSemantic(0); - testUri.runEx("ESAllPrim/$ref/$count").isExSemantic(0); - testUri.runEx("ESAllPrim/$ref/invalid").isExSemantic(0); - testUri.runEx("ESAllPrim/$count/invalid").isExSemantic(0); - testUri.runEx("ESAllPrim(1)/whatever").isExSemantic(0); - // testUri.runEx("ESAllPrim(PropertyInt16='1')").isExSemantic(0); - testUri.runEx("ESAllPrim(PropertyInt16)").isExSemantic(0); - testUri.runEx("ESAllPrim(PropertyInt16=)").isExSyntax(0); - testUri.runEx("ESAllPrim(PropertyInt16=1,Invalid='1')").isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim").isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETAllKey") - .isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim('1')/com.sap.odata.test1.ETAllKey") - .isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim(1)/com.sap.odata.test1.ETBaseTwoKeyTwoPrim" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim") - .isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETBaseTwoKeyTwoPrim" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyTwoPrim(1)") - .isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim/com.sap.odata.test1.ETAllKey") - .isExSemantic(0); - - testUri.runEx("ETBaseTwoKeyTwoPrim()") - .isExSemantic(0); - - testUri.runEx("ESAllNullable(1)/CollPropertyString/$value") - .isExSemantic(0); - - testUri.runEx("ETMixPrimCollComp(1)/ComplexProperty/$value").isExSemantic(0); - } - - @Test - public void runEsNameCast() { - testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim, true) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(-32768)/com.sap.odata.test1.ETTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim, false) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase) - .isKeyPredicate(0, "PropertyInt16", "-32768") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase(-32768)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim, false) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase) - .isKeyPredicate(0, "PropertyInt16", "-32768"); - - testUri.run("ESTwoPrim/Namespace1_Alias.ETTwoBase(-32768)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim, false) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase) - .isKeyPredicate(0, "PropertyInt16", "-32768"); - - } - - @Test - public void runEsNamePpSpCast() { - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplex/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - } - - @Test - public void runEsNameKey() { - testUri.run("ESCollAllPrim(1)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESCollAllPrim"); - - testUri.run("ESCollAllPrim(PropertyInt16=1)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESCollAllPrim"); - - testUri.run("ESFourKeyAlias(PropertyInt16=1,KeyAlias1=2,KeyAlias2='3',KeyAlias3='4')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESFourKeyAlias") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "KeyAlias1", "2") - .isKeyPredicate(2, "KeyAlias2", "'3'") - .isKeyPredicate(3, "KeyAlias3", "'4'"); - - testUri.run("ESCollAllPrim(null)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESCollAllPrim"); - } - - @Test - public void runEsNameParaKeys() throws UnsupportedEncodingException { - testUri.run(encode("ESAllKey(PropertyString='O''Neil',PropertyBoolean=true,PropertyByte=255," - + "PropertySByte=-128,PropertyInt16=-32768,PropertyInt32=-2147483648," - + "PropertyInt64=-9223372036854775808,PropertyDecimal=0.1,PropertyDate=2013-09-25," - + "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00," - + "PropertyDuration=duration'P10DT5H34M21.123456789012S'," - + "PropertyGuid=12345678-1234-1234-1234-123456789012," - + "PropertyTimeOfDay=12:34:55.123456789012)")) - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllKey") - .isKeyPredicate(0, "PropertyString", "'O''Neil'") - .isKeyPredicate(1, "PropertyBoolean", "true") - .isKeyPredicate(2, "PropertyByte", "255") - .isKeyPredicate(3, "PropertySByte", "-128") - .isKeyPredicate(4, "PropertyInt16", "-32768") - .isKeyPredicate(5, "PropertyInt32", "-2147483648") - .isKeyPredicate(6, "PropertyInt64", "-9223372036854775808") - .isKeyPredicate(7, "PropertyDecimal", "0.1") - .isKeyPredicate(8, "PropertyDate", "2013-09-25") - .isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00") - .isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'") - .isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012") - .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012"); - } - - @Test - public void runEsNameKeyCast() { - /* - * testUri.runEx("ESTwoPrim(1)/com.sap.odata.test1.ETBase(1)") - * .isExSemantic(0); - * - * testUri.runEx("ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase(1)") - * .isExSemantic(0); - * - * testUri.runEx("ESBase/com.sap.odata.test1.ETTwoPrim(1)") - * .isExSemantic(0); - */ - - testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isKeyPredicate(0, "PropertyInt16", "1") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBase); - - testUri.run("ESTwoPrim(1)/com.sap.odata.test1.ETTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isKeyPredicate(0, "PropertyInt16", "1") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(1)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isKeyPredicate(0, "PropertyInt16", "1") - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase(1)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isKeyPredicate(0, "PropertyInt16", "1") - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETBase(1)/com.sap.odata.test1.ETTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isKeyPredicate(0, "PropertyInt16", "1") - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase); - - testUri.run("ESTwoPrim/com.sap.odata.test1.ETTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBase); - } - - @Test - public void runEsNameParaKeysCast() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=1,PropertyString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'"); - } - - @Test - public void run_EsNamePpCp() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isComplex("PropertyComplex"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplex/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isComplex("PropertyComplex") - .n() - .isComplex("PropertyComplex"); - } - - @Test - public void runEsNamePpCpColl() { - testUri.run("ESMixPrimCollComp(5)/CollPropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESMixPrimCollComp") - .isKeyPredicate(0, "PropertyInt16", "5") - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTTwoPrim, true); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/CollPropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/CollPropertyComplex/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .n() - .isCount(); - } - - @Test - public void runEsNamePpCpCast() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex"); - - testUri - .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplex/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isComplex("PropertyComplex") - .n() - .isComplex("PropertyComplex"); - - testUri - .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplexTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim) - .isTypeFilter(ComplexTypeProvider.nameCTBase); - - testUri - .run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplexTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim) - .isTypeFilter(ComplexTypeProvider.nameCTTwoBase); - } - - @Test - public void runNsNamePpNp() { - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true); - - testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2"); - - testUri.run("ESKeyNav(PropertyInt16=1)/NavPropertyETKeyNavMany(PropertyInt16=2)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2"); - - testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .n() - .isComplex("PropertyComplex"); - - testUri.run("ESKeyNav(1)/NavPropertyETKeyNavMany(2)/NavPropertyETKeyNavOne") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .n() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')" - + "/NavPropertyETKeyNavMany(4)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "4"); - - testUri.run("ESKeyNav(1)/PropertyComplex/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isComplex("PropertyComplex") - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='(3)')" - + "/PropertyComplex/PropertyComplex/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'(3)'") - .n() - .isComplex("PropertyComplex") - .n() - .isComplex("PropertyComplex") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav(1)/NavPropertyETMediaMany(2)/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETMediaMany", EntityTypeProvider.nameETMedia, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .n() - .isValue(); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')" - + "/NavPropertyETKeyNavOne/NavPropertyETMediaOne/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .n() - .isNavProperty("NavPropertyETMediaOne", EntityTypeProvider.nameETMedia, false) - .n() - .isValue(); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')" - + "/NavPropertyETKeyNavOne/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .n() - .isRef(); - } - - @Test - public void runEsNamePpNpCast() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/NavPropertyETKeyNavMany(3)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "3"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETTwoBaseTwoKeyNav(PropertyInt16=3,PropertyString='4')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESTwoKeyNav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "3") - .isKeyPredicate(1, "PropertyString", "'4'") - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')" - + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=4,PropertyString='5')" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav/NavPropertyETBaseTwoKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "4") - .isKeyPredicate(1, "PropertyString", "'5'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETBaseTwoKeyNavMany", EntityTypeProvider.nameETBaseTwoKeyNav, true); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/" - + "NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=4,PropertyString='5')/" - + "NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "4") - .isKeyPredicate(1, "PropertyString", "'5'") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - } - - @Test - public void runEsNamePpNpRc() { - // checks for using referential constrains to fill missing keys - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany('2')").goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicateRef(0, "PropertyInt16", "PropertyInt16") - .isKeyPredicate(1, "PropertyString", "'2'"); - - testUri.run("ESKeyNav(PropertyInt16=1)/NavPropertyETTwoKeyNavMany(PropertyString='2')").goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicateRef(0, "PropertyInt16", "PropertyInt16") - .isKeyPredicate(1, "PropertyString", "'2'"); - - } - - @Test - public void runEsNamePpSp() { - testUri.run("ESAllPrim(1)/PropertyByte") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false); - - testUri.run("ESAllPrim(1)/PropertyByte/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false) - .n() - .isValue(); - - testUri.run("ESMixPrimCollComp(1)/PropertyComplex/PropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESMixPrimCollComp") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isComplex("PropertyComplex") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - } - - @Test - public void runEsNamePpSpColl() { - testUri.run("ESCollAllPrim(1)/CollPropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESCollAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/CollPropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true); - - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=2,PropertyString='3')/CollPropertyString/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .n() - .isCount(); - - } - - @Test - public void runEsNameRef() { - testUri.run("ESAllPrim/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .n() - .isRef(); - - testUri.run("ESAllPrim(-32768)/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESAllPrim") - .isKeyPredicate(0, "PropertyInt16", "-32768") - .n() - .isRef(); - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n() - .isRef(); - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='2')/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isRef(); - } - - @Test - public void runFunctionImpBf() { - - testUri.run("FICRTString()/com.sap.odata.test1.BFCStringRTESTwoKeyNav()"); - } - - @Test - public void runFunctionImpCastBf() { - - testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav" - + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isFunction("BFCETBaseTwoKeyNavRTETTwoKeyNav"); - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')" - + "/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isFunction("BFCETBaseTwoKeyNavRTETTwoKeyNav"); - } - - @Test - public void runFunctionImpEntity() { - - testUri.run("FICRTETKeyNav()") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETKeyNav") - .isFunction("UFCRTETKeyNav") - .isType(EntityTypeProvider.nameETKeyNav); - - testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=2,PropertyString='3')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'"); - - testUri.run("FICRTETMedia()/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETMedia") - .isFunction("UFCRTETMedia") - .n() - .isValue(); - - testUri.run("FICRTETKeyNav()/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETKeyNav") - .isFunction("UFCRTETKeyNav") - .n() - .isRef(); - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/$ref") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .n() - .isRef(); - - testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("FICRTETTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=2,PropertyString='3')" - + "/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'"); - } - - @Test - public void runFunctionImpEs() { - /**/ - testUri.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESMixPrimCollCompTwoParam") - .isFunction("UFCRTESMixPrimCollCompTwoParam") - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'") - .isType(EntityTypeProvider.nameETMixPrimCollComp); - - testUri.run("FINRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FINRTESMixPrimCollCompTwoParam") - .isFunction("UFNRTESMixPrimCollCompTwoParam") - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'") - .isType(EntityTypeProvider.nameETMixPrimCollComp); - - testUri.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESMixPrimCollCompTwoParam") - .isFunction("UFCRTESMixPrimCollCompTwoParam") - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'") - .isType(EntityTypeProvider.nameETMixPrimCollComp) - .n() - .isCount(); - } - - @Test - public void runFunctionImpError() { - testUri.runEx("FICRTCollCTTwoPrimParam()").isExSemantic(0); - testUri.runEx("FICRTCollCTTwoPrimParam(invalidParam=2)").isExSemantic(0); - } - - @Test - public void runFunctionImpEsAlias() { - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)?@parameterAlias=1"); - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@parameterAlias)/$count?@parameterAlias=1"); - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=@invalidAlias)?@validAlias=1"); - } - - @Test - public void runFunctionImpEsCast() { - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)/com.sap.odata.test1.ETBaseTwoKeyNav/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isCount(); - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'"); - - testUri.run("FICRTESTwoKeyNavParam(ParameterInt16=1)" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')" - + "/com.sap.odata.test1.ETTwoBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath() - .first() - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .isTypeFilterOnEntry(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - } - - @Test - public void runSingletonEntityValue() { - testUri.run("SIMedia/$value") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SIMedia") - .n().isValue(); - } - - @Test - public void runSingletonPpNpCast() { - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany(1)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1"); - - } - - @Test - public void runSingletonPpCpCast() { - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex"); - - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplex/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplex") - .n() - .isComplex("PropertyComplex"); - - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplexTwoPrim/com.sap.odata.test1.CTBase") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isComplex("PropertyComplexTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim) - .isTypeFilter(ComplexTypeProvider.nameCTBase); - - } - - @Test - public void runSingletonPpSpCast() { - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/CollPropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilter(EntityTypeProvider.nameETBaseTwoKeyNav) - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .isType(PropertyProvider.nameString, true); - - } - - @Test - public void runSingletonEntityPpNp() { - testUri.run("SINav/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("SINav/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='2')") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'"); - - } - - @Test - public void runSingletonEntityPpCp() { - testUri.run("SINav/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isComplex("PropertyComplex"); - - testUri.run("SINav/PropertyComplex/PropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isComplex("PropertyComplex") - .n() - .isComplex("PropertyComplex"); - - } - - @Test - public void runSingletonEntityPpCpColl() { - testUri.run("SINav/CollPropertyComplex") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true); - - testUri.run("SINav/CollPropertyComplex/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isComplex("CollPropertyComplex") - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .n() - .isCount(); - } - - @Test - public void runSingletonEntityPpSp() { - testUri.run("SINav/PropertyString") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - } - - @Test - public void runSingletonEntityPpSpColl() { - testUri.run("SINav/CollPropertyString") - - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true); - testUri.run("SINav/CollPropertyString/$count") - .isKind(UriInfoKind.resource).goPath() - .first() - .isSingleton("SINav") - .n() - .isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .n() - .isCount(); - } - - @Test - public void runExpand() { - - testUri.run("ESKeyNav(1)?$expand=*") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .isSegmentStar(0); - - testUri.run("ESKeyNav(1)?$expand=*/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .isSegmentStar(0) - .isSegmentRef(1); - - testUri.run("ESKeyNav(1)?$expand=*/$ref,NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .isSegmentStar(0).isSegmentRef(1) - .next() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESKeyNav(1)?$expand=*($levels=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .isSegmentStar(0) - .isLevelText("3"); - - testUri.run("ESKeyNav(1)?$expand=*($levels=max)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .isSegmentStar(0) - .isLevelText("max"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef(); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$ref") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav, false) - .n().isRef(); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($filter=PropertyInt16 eq 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator().isFilterSerialized("< eq <1>>"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($orderby=PropertyInt16)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isSortOrder(0, false) - .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isSkipText("1"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isTopText("2"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($count=true)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isInlineCountText("true"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1;$top=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isSkipText("1") - .isTopText("3"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref($skip=1%3b$top=3)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .isSkipText("1") - .isTopText("3"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isCount(); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne/$count") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav, false) - .n().isCount(); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$count($filter=PropertyInt16 gt 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .n().isCount() - .goUpExpandValidator() - .isFilterSerialized("< gt <1>>"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($filter=PropertyInt16 eq 1)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isFilterSerialized("< eq <1>>"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($orderby=PropertyInt16)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSortOrder(0, false) - .goOrder(0).goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSkipText("1"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isTopText("2"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($count=true)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isInlineCountText("true"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($select=PropertyString)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSelectText("PropertyString") - .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($expand=NavPropertyETTwoKeyNavOne)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .goExpand() - .goPath().first() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($expand=NavPropertyETKeyNavMany)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .goExpand() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne($levels=5)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav, false) - .goUpExpandValidator() - .isLevelText("5"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($select=PropertyString)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSelectText("PropertyString") - .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavOne($levels=max)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav, false) - .goUpExpandValidator() - .isLevelText("max"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1;$top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSkipText("1") - .isTopText("2"); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany($skip=1%3b$top=2)") - .isKind(UriInfoKind.resource).goPath().goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true) - .goUpExpandValidator() - .isSkipText("1") - .isTopText("2"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')?$expand=NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath() - .first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'Hugo'") - .goExpand() - .first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESTwoKeyNav?" - + "$expand=com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath().first() - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='Hugo')?" - + "$expand=com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETKeyNavMany") - .isKind(UriInfoKind.resource).goPath().first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'Hugo'") - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?" - + "$expand=com.sap.odata.test1.ETBaseTwoKeyNav/NavPropertyETTwoKeyNavMany") - .isKind(UriInfoKind.resource).goPath().first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$expand=com.sap.odata.test1.ETBaseTwoKeyNav" - + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETTwoBaseTwoKeyNav") - .isKind(UriInfoKind.resource).goPath().first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav?$expand=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplexNav/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath().first() - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isComplex("PropertyComplexNav") - .isType(ComplexTypeProvider.nameCTBasePrimCompNav) - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - testUri.run("ESTwoKeyNav?$expand=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyComplexNav" - + "/com.sap.odata.test1.CTTwoBasePrimCompNav/NavPropertyETTwoKeyNavOne") - .isKind(UriInfoKind.resource).goPath().first() - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n() - .isComplex("PropertyComplexNav") - .isType(ComplexTypeProvider.nameCTBasePrimCompNav) - .n() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - testUri.run("ESKeyNav(1)?$expand=NavPropertyETKeyNavMany/$ref,NavPropertyETTwoKeyNavMany($skip=2;$top=1)") - .isKind(UriInfoKind.resource).goPath().first() - .goExpand().first() - .goPath() - .first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .n().isRef() - .goUpExpandValidator() - .next() - .goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .goUpExpandValidator() - .isSkipText("2") - .isTopText("1"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$expand=com.sap.odata.test1.ETBaseTwoKeyNav" - + "/NavPropertyETTwoKeyNavMany/com.sap.odata.test1.ETTwoBaseTwoKeyNav($select=PropertyString)") - .isKind(UriInfoKind.resource).goPath() - .first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .goExpand().first() - .isExpandStartType(EntityTypeProvider.nameETBaseTwoKeyNav) - .goPath().first() - // .isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(EntityTypeProvider.nameETTwoKeyNav) - // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnCollection(EntityTypeProvider.nameETTwoBaseTwoKeyNav) - .goUpExpandValidator() - .goSelectItem(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($expand=NavPropertyETKeyNavMany(" - + "$expand=NavPropertyETKeyNavOne))") - .isKind(UriInfoKind.resource) - .goPath().first() - .goExpand().first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav) - .goUpExpandValidator() - .goExpand().first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, true) - .isType(EntityTypeProvider.nameETKeyNav) - .goUpExpandValidator() - .goExpand().first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')?$select=com.sap.odata.test1.ETBaseTwoKeyNav" - + "/PropertyInt16") - .isKind(UriInfoKind.resource).goPath() - .first() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav) - .goSelectItem(0) - .first() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($select=PropertyInt16)") - .isKind(UriInfoKind.resource) - .goPath().first() - .goExpand().first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav) - .goUpExpandValidator() - .isSelectText("PropertyInt16") - .goSelectItem(0).isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESKeyNav?$expand=NavPropertyETKeyNavOne($select=PropertyComplex/PropertyInt16)") - .isKind(UriInfoKind.resource) - .goPath().first() - .goExpand().first() - .goPath().first() - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav) - .goUpExpandValidator() - .isSelectText("PropertyComplex/PropertyInt16"); - } - - @Test - public void runTop() { - // top - testUri.run("ESKeyNav?$top=1") - .isKind(UriInfoKind.resource).goPath() - .isEntitySet("ESKeyNav") - .isTopText("1"); - - testUri.run("ESKeyNav?$top=0") - .isKind(UriInfoKind.resource).goPath() - .isEntitySet("ESKeyNav") - .isTopText("0"); - - testUri.run("ESKeyNav?$top=-3") - .isKind(UriInfoKind.resource).goPath() - .isEntitySet("ESKeyNav") - .isTopText("-3"); - } - - @Test - public void runFormat() { - // format - testUri.run("ESKeyNav(1)?$format=atom") - .isKind(UriInfoKind.resource).goPath() - .isFormatText("atom"); - testUri.run("ESKeyNav(1)?$format=json") - .isKind(UriInfoKind.resource).goPath() - .isFormatText("json"); - testUri.run("ESKeyNav(1)?$format=xml") - .isKind(UriInfoKind.resource).goPath() - .isFormatText("xml"); - testUri.run("ESKeyNav(1)?$format=IANA_content_type/must_contain_a_slash") - .isKind(UriInfoKind.resource).goPath() - .isFormatText("IANA_content_type/must_contain_a_slash"); - testUri.run("ESKeyNav(1)?$format=Test_all_valid_signsSpecified_for_format_signs%26-._~$@%27/Aa123%26-._~$@%27") - .isKind(UriInfoKind.resource).goPath() - .isFormatText("Test_all_valid_signsSpecified_for_format_signs&-._~$@'/Aa123&-._~$@'"); - } - - @Test - public void runCount() { - // count - testUri.run("ESAllPrim?$count=true") - .isKind(UriInfoKind.resource).goPath() - .isInlineCountText("true"); - testUri.run("ESAllPrim?$count=false") - .isKind(UriInfoKind.resource).goPath() - .isInlineCountText("false"); - - // TODO planned: move to validator - // testUri.runEx("ESAllPrim?$count=foo").isExSyntax(0); - } - - @Test - public void skip() { - // skip - testUri.run("ESAllPrim?$skip=3") - .isKind(UriInfoKind.resource).goPath() - .isSkipText("3"); - testUri.run("ESAllPrim?$skip=0") - .isKind(UriInfoKind.resource).goPath() - .isSkipText("0"); - testUri.run("ESAllPrim?$skip=-3") - .isKind(UriInfoKind.resource).goPath() - .isSkipText("-3"); - } - - @Test - public void skiptoken() { - - testUri.run("ESAllPrim?$skiptoken=foo") - .isKind(UriInfoKind.resource).goPath() - .isSkipTokenText("foo"); - } - - @Test - public void misc() { - - testUri.run("") - .isKind(UriInfoKind.service); - testUri.run("/") - .isKind(UriInfoKind.service); - - testUri.run("$all") - .isKind(UriInfoKind.all); - - testUri.run("$metadata") - .isKind(UriInfoKind.metadata); - - testUri.run("$batch") - .isKind(UriInfoKind.batch); - - testUri.run("$crossjoin(ESKeyNav)") - .isKind(UriInfoKind.crossjoin) - .isCrossJoinEntityList(Arrays.asList("ESKeyNav")); - - testUri.run("ESKeyNav") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav"); - testUri.run("ESKeyNav(1)") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1"); - - testUri.run("SINav") - .isKind(UriInfoKind.resource) - .goPath().first() - .isSingleton("SINav"); - - testUri.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource) - .goPath() - .isFunctionImport("FICRTESMixPrimCollCompTwoParam") - .isType(EntityTypeProvider.nameETMixPrimCollComp) - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'"); - - testUri.run("FICRTETKeyNav()") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTETKeyNav") - .isType(EntityTypeProvider.nameETKeyNav); - - testUri.run("FICRTCollCTTwoPrim()") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTCollCTTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim); - - testUri.run("FICRTCTAllPrimTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTCTAllPrimTwoParam") - .isType(ComplexTypeProvider.nameCTAllPrim) - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'"); - - testUri.run("FICRTCollStringTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTCollStringTwoParam") - .isType(PropertyProvider.nameString) - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'"); - - testUri.run("FICRTStringTwoParam(ParameterInt16=1)") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTStringTwoParam") - .isFunction("UFCRTStringTwoParam") - .isType(PropertyProvider.nameString) - .isParameter(0, "ParameterInt16", "1"); - - testUri.run("FICRTStringTwoParam(ParameterInt16=1,ParameterString='2')") - .isKind(UriInfoKind.resource) - .goPath().first() - .isFunctionImport("FICRTStringTwoParam") - .isFunction("UFCRTStringTwoParam") - .isType(PropertyProvider.nameString) - .isParameter(0, "ParameterInt16", "1"); - - testUri.run("AIRTETParam") - .isKind(UriInfoKind.resource) - .goPath().first() - .isActionImport("AIRTETParam"); - - testUri.run("AIRTPrimParam") - .isKind(UriInfoKind.resource) - .goPath().first() - .isActionImport("AIRTPrimParam"); - - testUri.run("ESKeyNav/$count") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .n().isCount(); - - testUri.run("ESKeyNav/$ref") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .n().isRef(); - - testUri.run("ESKeyNav/$count") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .n().isCount(); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .n().isFunction("BFCESTwoKeyNavRTESTwoKeyNav"); - - testUri.run("ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESAllPrim") - .n().isAction("BAESAllPrimRTETAllPrim"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .n().isFunction("BFCESTwoKeyNavRTESTwoKeyNav"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav/$count") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .n() - .isCount(); - - testUri.run("ESTwoKeyNav/$ref") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .n() - .isRef(); - - testUri.run("ESKeyNav(1)") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1"); - - testUri.run("ESKeyNav(1)/$ref") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isRef(); - - testUri.run("ESMedia(1)/$value") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESMedia") - .n() - .isValue(); - - testUri.run("ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESAllPrim") - .n().isAction("BAESAllPrimRTETAllPrim"); - - testUri.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav()") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .n().isFunction("BFCESTwoKeyNavRTESTwoKeyNav"); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/$ref") - .isKind(UriInfoKind.resource) - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n().isRef(); - - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBaseTwoKeyNav/$value") - .goPath().first() - .isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .n().isValue(); - - } - - @Test - public void testFilter() throws UriParserException { - - testFilter.runOnETTwoKeyNav("PropertyString") - .is("") - .isType(PropertyProvider.nameString); - - testFilter.runOnETTwoKeyNav("PropertyComplex/PropertyInt16") - .is("") - .isType(PropertyProvider.nameInt16); - - testFilter.runOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyDate") - .is("") - .isType(PropertyProvider.nameDate); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne") - .is("") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/PropertyString") - .is("") - .isType(PropertyProvider.nameString); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/PropertyComplex") - .is("") - .isType(ComplexTypeProvider.nameCTPrimComp); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/PropertyComplex/PropertyComplex") - .is("") - .isType(ComplexTypeProvider.nameCTAllPrim); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/PropertyComplex/PropertyInt16") - .is("") - .isType(PropertyProvider.nameInt16); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/PropertyComplex/PropertyInt16 eq 1") - .is("< eq <1>>") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isLiteral("1"); - - testFilter.runOnETTwoKeyNav("NavPropertyETKeyNavMany(1)/NavPropertyETTwoKeyNavMany(PropertyString='2')/" - + "PropertyString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left() - .isType(PropertyProvider.nameString) - .isMember().goPath() - .first() - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .n() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicateRef(0, "PropertyInt16", "PropertyInt16") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().right(); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate eq 2013-11-12") - .is("< eq <2013-11-12>>") - .root().left() - .isType(PropertyProvider.nameDate) - .isMember().isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath() - // .first().isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(EntityTypeProvider.nameETTwoKeyNav).isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - // .n().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .first().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .goUpFilterValidator() - .root().right() - .isLiteral("2013-11-12"); - - testFilter.runOnCTTwoPrim("com.sap.odata.test1.CTBase/AdditionalPropString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left() - .isType(PropertyProvider.nameString) - .isMember().isMemberStartType(ComplexTypeProvider.nameCTBase).goPath() - // .first().isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(EntityTypeProvider.nameCTTwoPrim).isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase) - // .n().isPrimitiveProperty("AdditionalPropString", PropertyProvider.nameString, false) - .first().isPrimitiveProperty("AdditionalPropString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().right() - .isLiteral("'SomeString'"); - - testFilter - .runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate eq 2013-11-12") - .is("< eq <2013-11-12>>") - .root().left() - .isType(PropertyProvider.nameDate) - .root().right() - .isLiteral("2013-11-12"); - - testFilter - .runOnETTwoKeyNav("PropertyComplexTwoPrim/com.sap.odata.test1.CTTwoBase/AdditionalPropString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left() - .isType(PropertyProvider.nameString) - .root().right() - .isLiteral("'SomeString'"); - - testFilter.runOnETTwoKeyNavEx("invalid").isExSemantic(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplex/invalid").isExSemantic(0); - testFilter.runOnETTwoKeyNavEx("concat('a','b')/invalid").isExSyntax(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplex/concat('a','b')").isExSyntax(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplexAllPrim/PropertyInt16 eq '1'").isExSemantic(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplexAllPrim/PropertyDate eq 1").isExSemantic(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplexAllPrim/PropertyString eq 1").isExSemantic(0); - testFilter.runOnETTwoKeyNavEx("PropertyComplexAllPrim/PropertyDate eq 1").isExSemantic(0); - - testFilter.runOnETAllPrim("PropertySByte eq PropertySByte") - .is("< eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - - testFilter.runOnETAllPrim("PropertySByte ne PropertySByte") - .is("< ne >") - .isBinary(BinaryOperatorKind.NE) - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - - testFilter.runOnETAllPrim("PropertySByte add PropertySByte") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - - testFilter.runOnETAllPrim("PropertyByte add PropertyByte") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyInt16 add PropertyInt16") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isType(PropertyProvider.nameInt16); - testFilter.runOnETAllPrim("PropertyInt32 add PropertyInt32") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameInt32) - .root().right() - .isType(PropertyProvider.nameInt32); - - testFilter.runOnETAllPrim("PropertyInt64 add PropertyInt64") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertySingle add PropertySingle") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameSingle) - .root().right() - .isType(PropertyProvider.nameSingle); - testFilter.runOnETAllPrim("PropertyDouble add PropertyDouble") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameDouble) - .root().right() - .isType(PropertyProvider.nameDouble); - testFilter.runOnETAllPrim("PropertyDecimal add PropertyDecimal") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertySByte add PropertyDecimal") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertySByte add PropertyInt32") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertySByte add PropertyInt64") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertyDateTimeOffset add PropertyDuration") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameDateTimeOffset) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertyDuration add PropertyDuration") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameDuration) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertyDate add PropertyDuration") - .is("< add >") - .root().left() - .isType(PropertyProvider.nameDate) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertySByte sub PropertySByte") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - testFilter.runOnETAllPrim("PropertyByte sub PropertyByte") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyInt16 sub PropertyInt16") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isType(PropertyProvider.nameInt16); - testFilter.runOnETAllPrim("PropertyInt32 sub PropertyInt32") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameInt32) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyInt64 sub PropertyInt64") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertySingle sub PropertySingle") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameSingle) - .root().right() - .isType(PropertyProvider.nameSingle); - testFilter.runOnETAllPrim("PropertyDouble sub PropertyDouble") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDouble) - .root().right() - .isType(PropertyProvider.nameDouble); - testFilter.runOnETAllPrim("PropertyDecimal sub PropertyDecimal") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyDecimal sub PropertyInt32") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyDecimal sub PropertyInt64") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertyDecimal sub PropertyByte") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyDateTimeOffset sub PropertyDuration") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDateTimeOffset) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertyDuration sub PropertyDuration") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDuration) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertyDateTimeOffset sub PropertyDateTimeOffset") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDateTimeOffset) - .root().right() - .isType(PropertyProvider.nameDateTimeOffset); - testFilter.runOnETAllPrim("PropertyDate sub PropertyDuration") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDate) - .root().right() - .isType(PropertyProvider.nameDuration); - testFilter.runOnETAllPrim("PropertyDate sub PropertyDate") - .is("< sub >") - .root().left() - .isType(PropertyProvider.nameDate) - .root().right() - .isType(PropertyProvider.nameDate); - testFilter.runOnETAllPrim("PropertySByte mul PropertySByte") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - testFilter.runOnETAllPrim("PropertyByte mul PropertyByte") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyInt16 mul PropertyInt16") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isType(PropertyProvider.nameInt16); - testFilter.runOnETAllPrim("PropertyInt32 mul PropertyInt32") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt32) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyInt64 mul PropertyInt64") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertySingle mul PropertySingle") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameSingle) - .root().right() - .isType(PropertyProvider.nameSingle); - testFilter.runOnETAllPrim("PropertyDouble mul PropertyDouble") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameDouble) - .root().right() - .isType(PropertyProvider.nameDouble); - testFilter.runOnETAllPrim("PropertyDecimal mul PropertyDecimal") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyInt64 mul PropertyInt32") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyInt64 mul PropertySByte") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameSByte); - testFilter.runOnETAllPrim("PropertyInt64 mul PropertyDecimal") - .is("< mul >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertySByte div PropertySByte") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - testFilter.runOnETAllPrim("PropertyByte div PropertyByte") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyInt16 div PropertyInt16") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isType(PropertyProvider.nameInt16); - testFilter.runOnETAllPrim("PropertyInt32 div PropertyInt32") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameInt32) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyInt64 div PropertyInt64") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertySingle div PropertySingle") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameSingle) - .root().right() - .isType(PropertyProvider.nameSingle); - testFilter.runOnETAllPrim("PropertyDouble div PropertyDouble") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameDouble) - .root().right() - .isType(PropertyProvider.nameDouble); - testFilter.runOnETAllPrim("PropertyDecimal div PropertyDecimal") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyByte div PropertyInt32") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyByte div PropertyDecimal") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyByte div PropertySByte") - .is("< div >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameSByte); - - testFilter.runOnETAllPrim("PropertyByte div 0") - .is("< div <0>>"); - - testFilter.runOnETAllPrim("0 div 0") - .is("<<0> div <0>>"); - - testFilter.runOnETAllPrim("PropertySByte mod PropertySByte") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameSByte) - .root().right() - .isType(PropertyProvider.nameSByte); - testFilter.runOnETAllPrim("PropertyByte mod PropertyByte") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameByte) - .root().right() - .isType(PropertyProvider.nameByte); - testFilter.runOnETAllPrim("PropertyInt16 mod PropertyInt16") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameInt16) - .root().right() - .isType(PropertyProvider.nameInt16); - testFilter.runOnETAllPrim("PropertyInt32 mod PropertyInt32") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameInt32) - .root().right() - .isType(PropertyProvider.nameInt32); - testFilter.runOnETAllPrim("PropertyInt64 mod PropertyInt64") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameInt64) - .root().right() - .isType(PropertyProvider.nameInt64); - testFilter.runOnETAllPrim("PropertySingle mod PropertySingle") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameSingle) - .root().right() - .isType(PropertyProvider.nameSingle); - testFilter.runOnETAllPrim("PropertyDouble mod PropertyDouble") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameDouble) - .root().right() - .isType(PropertyProvider.nameDouble); - testFilter.runOnETAllPrim("PropertyDecimal mod PropertyDecimal") - .is("< mod >") - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - - // - testFilter.runOnETAllPrim("PropertyDecimal ge PropertyDecimal") - .is("< ge >") - .isBinary(BinaryOperatorKind.GE) - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyDecimal lt PropertyDecimal") - .is("< lt >") - .isBinary(BinaryOperatorKind.LT) - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyDecimal le PropertyDecimal") - .is("< le >") - .isBinary(BinaryOperatorKind.LE) - .root().left() - .isType(PropertyProvider.nameDecimal) - .root().right() - .isType(PropertyProvider.nameDecimal); - - testFilter.runOnETAllPrim("PropertyDecimal sub NaN") - .right().isLiteral("NaN").isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyDecimal sub -INF") - .right().isLiteral("-INF").isType(PropertyProvider.nameDecimal); - testFilter.runOnETAllPrim("PropertyDecimal sub INF") - .right().isLiteral("INF").isType(PropertyProvider.nameDecimal); - } - - @Test - public void testFilterProperties() throws UriParserException { - testFilter.runOnETAllPrim("PropertyByte mod 0") - .is("< mod <0>>"); - - testFilter.runOnETAllPrim("com.sap.odata.test1.UFCRTETTwoKeyNavParamCTTwoPrim(ParameterCTTwoPrim=@ParamAlias)") - .is("") - .goPath() - .first() - .isFunction("UFCRTETTwoKeyNavParamCTTwoPrim") - .isParameterAlias(0, "ParameterCTTwoPrim", "ParamAlias"); - - testFilter.runOnETTwoKeyNav("PropertyComplex" - + "/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam" - + "(ParameterString=PropertyComplex/PropertyComplex/PropertyString)(PropertyInt16=1,PropertyString='2')" - + "/PropertyString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left().goPath() - .first() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESTwoKeyNavParam") - .isParameter(0, "ParameterString", "PropertyComplex/PropertyComplex/PropertyString") - .goParameter(0) - .isMember() - .goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .goUpToResourceValidator() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTETTwoKeyNavParam" - + "(ParameterString=null)/PropertyString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left().goPath() - .first() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTETTwoKeyNavParam") - .goParameter(0) - .isNull() - .goUpToResourceValidator() - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavMany/com.sap.odata.test1.BFCESTwoKeyNavRTString()" - + " eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left().goPath() - .first() - .isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n() - .isFunction("BFCESTwoKeyNavRTString"); - - testFilter.runOnETTwoKeyNav("$it/com.sap.odata.test1.BFESTwoKeyNavRTESTwoKeyNav()/PropertyString eq 'SomeString'") - .is("<<$it/BFESTwoKeyNavRTESTwoKeyNav/PropertyString> eq <'SomeString'>>") - .root().left().goPath() - .first() - .isIt() - .n() - .isFunction("BFESTwoKeyNavRTESTwoKeyNav") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.BFESTwoKeyNavRTESTwoKeyNav()/PropertyString eq 'SomeString'") - .is("< eq <'SomeString'>>") - .root().left().goPath() - .first() - .isFunction("BFESTwoKeyNavRTESTwoKeyNav") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("NavPropertyETTwoKeyNavOne/com.sap.odata.test1.BFCETTwoKeyNavRTETTwoKeyNav()" - + "/PropertyComplex/PropertyComplex/PropertyString eq 'Walldorf'") - .is("< " - + "eq <'Walldorf'>>") - .root().left().goPath() - .first() - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n() - .isFunction("BFCETTwoKeyNavRTETTwoKeyNav") - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("PropertyComplex/com.sap.odata.test1.BFCCTPrimCompRTESTwoKeyNavParam" - + "(ParameterString='1')" - + "/com.sap.odata.test1.ETBaseTwoKeyNav(PropertyInt16=2,PropertyString='3')" - + "/PropertyString eq 'SomeString'") - .is("< " - + "eq <'SomeString'>>") - .root().left().goPath() - .first() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isFunction("BFCCTPrimCompRTESTwoKeyNavParam") - .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .isKeyPredicate(0, "PropertyInt16", "2") - .isKeyPredicate(1, "PropertyString", "'3'") - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNavSingle("$it/com.sap.odata.test1.BFCETTwoKeyNavRTCTTwoPrim()/com.sap.odata.test1.CTBase" - + "/PropertyString eq 'SomeString'") - .is("<<$it/BFCETTwoKeyNavRTCTTwoPrim/com.sap.odata.test1.CTBase/PropertyString> eq <'SomeString'>>") - .root().left().goPath() - .first() - .isIt() - .n() - .isFunction("BFCETTwoKeyNavRTCTTwoPrim") - .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase) - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.UFCRTETTwoKeyNavParam(ParameterInt16=1)/PropertyInt16 eq 2") - .is("< eq <2>>") - .root().left().goPath() - .first() - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.UFCRTETTwoKeyNavParam(ParameterInt16=@Param1Alias)" - + "/PropertyInt16 eq 2") - .root().left().goPath() - .first() - .isFunction("UFCRTETTwoKeyNavParam") - .isParameterAlias(0, "ParameterInt16", "Param1Alias") - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.UFCRTETTwoKeyNavParam(ParameterInt16=1)" - + "/PropertyComplex/PropertyComplex/PropertyString eq 'SomeString'") - .root().left().goPath() - .first() - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "1") - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("com.sap.odata.test1.UFCRTETTwoKeyNavParam(ParameterInt16=PropertyInt16)" - + "/PropertyComplex/PropertyComplex/PropertyString eq 'SomeString'") - .root().left().goPath() - .first() - .isFunction("UFCRTETTwoKeyNavParam") - .isParameter(0, "ParameterInt16", "PropertyInt16") - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n() - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - } - - @Test - public void testFilterPMethods() throws ExpressionVisitException, ODataApplicationException, UriParserException { - - testFilter.runOnETKeyNav("indexof(PropertyString,'47') eq 5") - .is("<,<'47'>)> eq <5>>") - .root().left() - .isMethod(MethodKind.INDEXOF, 2) - .isParameterText(0, "") - .isParameterText(1, "<'47'>"); - - testFilter.runOnETKeyNav("tolower(PropertyString) eq 'foo'") - .is("<)> eq <'foo'>>") - .root().left() - .isMethod(MethodKind.TOLOWER, 1) - .isParameterText(0, ""); - - testFilter.runOnETKeyNav("toupper(PropertyString) eq 'FOO'") - .is("<)> eq <'FOO'>>") - .root().left() - .isMethod(MethodKind.TOUPPER, 1) - .isParameterText(0, ""); - - testFilter.runOnETKeyNav("trim(PropertyString) eq 'fooba'") - .is("<)> eq <'fooba'>>") - .root().left() - .isMethod(MethodKind.TRIM, 1) - .isParameterText(0, ""); - - testFilter.runOnETKeyNav("substring(PropertyString,4) eq 'foo'") - .is("<,<4>)> eq <'foo'>>") - .root().left() - .isMethod(MethodKind.SUBSTRING, 2) - .isParameterText(0, "") - .isParameterText(1, "<4>"); - - testFilter.runOnETKeyNav("substring(PropertyString,4) eq 'foo'") - .is("<,<4>)> eq <'foo'>>") - .root().left() - .isMethod(MethodKind.SUBSTRING, 2) - .isParameterText(0, "") - .isParameterText(1, "<4>"); - - testFilter.runOnETKeyNav("substring(PropertyString,2,4) eq 'foo'") - .is("<,<2>,<4>)> eq <'foo'>>") - .root().left() - .isMethod(MethodKind.SUBSTRING, 3) - .isParameterText(0, "") - .isParameterText(1, "<2>") - .isParameterText(2, "<4>"); - - testFilter.runOnETKeyNav("concat(PropertyString,PropertyComplexTwoPrim/PropertyString) eq 'foo'") - .is("<,)> eq <'foo'>>") - .root().left() - .isMethod(MethodKind.CONCAT, 2) - .isParameterText(0, "") - .isParameterText(1, ""); - - testFilter.runOnETKeyNav("concat(PropertyString,'bar') eq 'foobar'") - .is("<,<'bar'>)> eq <'foobar'>>") - .root().left() - .isMethod(MethodKind.CONCAT, 2) - .isParameterText(0, "") - .isParameterText(1, "<'bar'>"); - - testFilter.runOnETKeyNav("concat(PropertyString,'bar') eq 'foobar'") - .is("<,<'bar'>)> eq <'foobar'>>") - .root().left() - .isMethod(MethodKind.CONCAT, 2) - .isParameterText(0, "") - .isParameterText(1, "<'bar'>"); - - testFilter.runOnETKeyNav("concat(PropertyString, cast(PropertyComplexAllPrim/PropertyInt16,Edm.String))") - .is(",,)>)>") - .isMethod(MethodKind.CONCAT, 2) - .isParameterText(0, "") - .isParameterText(1, ",)>") - .goParameter(1) - .isMethod(MethodKind.CAST, 2) - .isParameterText(0, "") - .isParameterText(1, ""); - - testFilter.runOnETKeyNav("length(PropertyString) eq 32") - .is("<)> eq <32>>") - .root().left() - .isMethod(MethodKind.LENGTH, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("year(PropertyDate) eq 2013") - .is("<)> eq <2013>>") - .root().left() - .isMethod(MethodKind.YEAR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("year(2013-09-25) eq 2013") - .is("<)> eq <2013>>") - .root().left() - .isMethod(MethodKind.YEAR, 1) - .isParameterText(0, "<2013-09-25>"); - - testFilter.runOnETAllPrim("year(PropertyDateTimeOffset) eq 2013") - .is("<)> eq <2013>>") - .root().left() - .isMethod(MethodKind.YEAR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("year(2013-09-25T12:34:56.123456789012-10:24) eq 2013") - .is("<)> eq <2013>>") - .root().left() - .isMethod(MethodKind.YEAR, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("month(PropertyDate) eq 9") - .is("<)> eq <9>>") - .root().left() - .isMethod(MethodKind.MONTH, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("month(2013-09-25) eq 9") - .is("<)> eq <9>>") - .root().left() - .isMethod(MethodKind.MONTH, 1) - .isParameterText(0, "<2013-09-25>"); - - testFilter.runOnETAllPrim("month(PropertyDateTimeOffset) eq 9") - .is("<)> eq <9>>") - .root().left() - .isMethod(MethodKind.MONTH, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("month(2013-09-25T12:34:56.123456789012-10:24) eq 9") - .is("<)> eq <9>>") - .root().left() - .isMethod(MethodKind.MONTH, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("day(PropertyDate) eq 25") - .is("<)> eq <25>>") - .root().left() - .isMethod(MethodKind.DAY, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("day(2013-09-25) eq 25") - .is("<)> eq <25>>") - .root().left() - .isMethod(MethodKind.DAY, 1) - .isParameterText(0, "<2013-09-25>"); - - testFilter.runOnETAllPrim("day(PropertyDateTimeOffset) eq 25") - .is("<)> eq <25>>") - .root().left() - .isMethod(MethodKind.DAY, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("day(2013-09-25T12:34:56.123456789012-10:24) eq 25") - .is("<)> eq <25>>") - .root().left() - .isMethod(MethodKind.DAY, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("hour(PropertyDateTimeOffset) eq 2") - .is("<)> eq <2>>") - .root().left() - .isMethod(MethodKind.HOUR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("hour(PropertyDateTimeOffset) eq 2") - .is("<)> eq <2>>") - .root().left() - .isMethod(MethodKind.HOUR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("hour(2013-09-25T12:34:56.123456789012-10:24) eq 2") - .is("<)> eq <2>>") - .root().left() - .isMethod(MethodKind.HOUR, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("hour(PropertyTimeOfDay) eq 2") - .is("<)> eq <2>>") - .root().left() - .isMethod(MethodKind.HOUR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("hour(12:34:55.123456789012) eq 12") - .is("<)> eq <12>>") - .root().left() - .isMethod(MethodKind.HOUR, 1) - .isParameterText(0, "<12:34:55.123456789012>"); - - testFilter.runOnETAllPrim("minute(PropertyDateTimeOffset) eq 34") - .is("<)> eq <34>>") - .root().left() - .isMethod(MethodKind.MINUTE, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("minute(2013-09-25T12:34:56.123456789012-10:24) eq 34") - .is("<)> eq <34>>") - .root().left() - .isMethod(MethodKind.MINUTE, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("minute(PropertyTimeOfDay) eq 34") - .is("<)> eq <34>>") - .root().left() - .isMethod(MethodKind.MINUTE, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("minute(12:34:55.123456789012) eq 34") - .is("<)> eq <34>>") - .root().left() - .isMethod(MethodKind.MINUTE, 1) - .isParameterText(0, "<12:34:55.123456789012>"); - - testFilter.runOnETAllPrim("second(PropertyDateTimeOffset) eq 56") - .is("<)> eq <56>>") - .root().left() - .isMethod(MethodKind.SECOND, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("second(2013-09-25T12:34:56.123456789012-10:24) eq 56") - .is("<)> eq <56>>") - .root().left() - .isMethod(MethodKind.SECOND, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("second(PropertyTimeOfDay) eq 56") - .is("<)> eq <56>>") - .root().left() - .isMethod(MethodKind.SECOND, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("second(12:34:55.123456789012) eq 56") - .is("<)> eq <56>>") - .root().left() - .isMethod(MethodKind.SECOND, 1) - .isParameterText(0, "<12:34:55.123456789012>"); - - testFilter.runOnETAllPrim("fractionalseconds(PropertyDateTimeOffset) eq 123456789012") - .is("<)> eq <123456789012>>") - .root().left() - .isMethod(MethodKind.FRACTIONALSECONDS, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("fractionalseconds(2013-09-25T12:34:56.123456789012-10:24) eq 123456789012") - .is("<)> eq <123456789012>>") - .root().left() - .isMethod(MethodKind.FRACTIONALSECONDS, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("fractionalseconds(PropertyTimeOfDay) eq 123456789012") - .is("<)> eq <123456789012>>") - .root().left() - .isMethod(MethodKind.FRACTIONALSECONDS, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("fractionalseconds(12:34:55.123456789012) eq 123456789012") - .is("<)> eq <123456789012>>") - .root().left() - .isMethod(MethodKind.FRACTIONALSECONDS, 1) - .isParameterText(0, "<12:34:55.123456789012>"); - - testFilter.runOnETAllPrim("totalseconds(PropertyDuration) eq 4711") - .is("<)> eq <4711>>") - .root().left() - .isMethod(MethodKind.TOTALSECONDS, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("totalseconds(duration'P10DT5H34M21.123456789012S') eq 4711") - .is("<)> eq <4711>>") - .root().left() - .isMethod(MethodKind.TOTALSECONDS, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("date(PropertyDateTimeOffset) eq 2013-09-25") - .is("<)> eq <2013-09-25>>") - .root().left() - .isMethod(MethodKind.DATE, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("date(2013-09-25T12:34:56.123456789012-10:24) eq 2013-09-25") - .is("<)> eq <2013-09-25>>") - .root().left() - .isMethod(MethodKind.DATE, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("time(PropertyDateTimeOffset) eq 12:34:55.123456789012") - .is("<)> eq <12:34:55.123456789012>>") - .root().left() - .isMethod(MethodKind.TIME, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("time(2013-09-25T12:34:56.123456789012-10:24) eq 12:34:55.123456789012") - .is("<)> eq <12:34:55.123456789012>>") - .root().left() - .isMethod(MethodKind.TIME, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("round(PropertyDouble) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.ROUND, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("round(17.45e1) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.ROUND, 1) - .isParameterText(0, "<17.45e1>"); - - testFilter.runOnETAllPrim("round(PropertyDecimal) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.ROUND, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("round(17.45) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.ROUND, 1) - .isParameterText(0, "<17.45>"); - - testFilter.runOnETAllPrim("floor(PropertyDouble) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.FLOOR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("floor(17.45e1) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.FLOOR, 1) - .isParameterText(0, "<17.45e1>"); - - testFilter.runOnETAllPrim("floor(PropertyDecimal) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.FLOOR, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("floor(17.45) eq 17") - .is("<)> eq <17>>") - .root().left() - .isMethod(MethodKind.FLOOR, 1) - .isParameterText(0, "<17.45>"); - - testFilter.runOnETAllPrim("ceiling(PropertyDouble) eq 18") - .is("<)> eq <18>>") - .root().left() - .isMethod(MethodKind.CEILING, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("ceiling(17.55e1) eq 18") - .is("<)> eq <18>>") - .root().left() - .isMethod(MethodKind.CEILING, 1) - .isParameterText(0, "<17.55e1>"); - - testFilter.runOnETAllPrim("ceiling(PropertyDecimal) eq 18") - .is("<)> eq <18>>") - .root().left() - .isMethod(MethodKind.CEILING, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("ceiling(17.55) eq 18") - .is("<)> eq <18>>") - .root().left() - .isMethod(MethodKind.CEILING, 1) - .isParameterText(0, "<17.55>"); - - testFilter.runOnETAllPrim("totaloffsetminutes(PropertyDateTimeOffset) eq 4711") - .is("<)> eq <4711>>") - .root().left() - .isMethod(MethodKind.TOTALOFFSETMINUTES, 1) - .isParameterText(0, ""); - - testFilter.runOnETAllPrim("totaloffsetminutes(2013-09-25T12:34:56.123456789012-10:24) eq 4711") - .is("<)> eq <4711>>") - .root().left() - .isMethod(MethodKind.TOTALOFFSETMINUTES, 1) - .isParameterText(0, "<2013-09-25T12:34:56.123456789012-10:24>"); - - testFilter.runOnETAllPrim("mindatetime()") - .is("") - .isMethod(MethodKind.MINDATETIME, 0); - - testFilter.runOnETAllPrim("mindatetime() eq 2013-09-25T12:34:56.123456789012-10:24") - .is("< eq <2013-09-25T12:34:56.123456789012-10:24>>") - .root().left() - .isMethod(MethodKind.MINDATETIME, 0); - - testFilter.runOnETAllPrim("maxdatetime()") - .is("") - .isMethod(MethodKind.MAXDATETIME, 0); - - testFilter.runOnETAllPrim("maxdatetime() eq 2013-09-25T12:34:56.123456789012-10:24") - .is("< eq <2013-09-25T12:34:56.123456789012-10:24>>") - .root().left() - .isMethod(MethodKind.MAXDATETIME, 0); - - testFilter.runOnETAllPrim("now()") - .is("") - .isMethod(MethodKind.NOW, 0); - - testFilter.runOnETAllPrim("now() eq 2013-09-25T12:34:56.123456789012-10:24") - .is("< eq <2013-09-25T12:34:56.123456789012-10:24>>") - .root().left() - .isMethod(MethodKind.NOW, 0); - - testFilter.runOnETTwoKeyNav("$it/PropertyString eq 'SomeString'") - .is("<<$it/PropertyString> eq <'SomeString'>>") - .root().left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnCTTwoPrim("$it/PropertyString eq 'SomeString'") - .is("<<$it/PropertyString> eq <'SomeString'>>") - .root().left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(ComplexTypeProvider.nameCTTwoPrim, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOnString("$it eq 'Walldorf'") - .is("<<$it> eq <'Walldorf'>>") - .root().left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(PropertyProvider.nameString, false); - - testFilter.runOnString("endswith($it,'sap.com')") - .is(",<'sap.com'>)>") - .isMethod(MethodKind.ENDSWITH, 2) - .isParameterText(0, "<$it>") - .isParameterText(1, "<'sap.com'>") - .goParameter(0) - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(PropertyProvider.nameString, false); - - testFilter.runOnString("endswith($it,'sap.com') eq false") - .is("<,<'sap.com'>)> eq >") - .root().left() - .isMethod(MethodKind.ENDSWITH, 2) - .isParameterText(0, "<$it>") - .isParameterText(1, "<'sap.com'>") - .goParameter(0) - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(PropertyProvider.nameString, false); - - testFilter.runOnETTwoKeyNav("endswith($it/CollPropertyString,'sap.com')") - .is(",<'sap.com'>)>") - .isMethod(MethodKind.ENDSWITH, 2) - .isParameterText(0, "<$it/CollPropertyString>") - .isParameterText(1, "<'sap.com'>") - .goParameter(0) - .goPath() - .first().isUriPathInfoKind(UriResourceKind.it) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .n().isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true); - - testFilter.runOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyInt16 eq $root" - + "/ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyInt16") - .is("< eq <$root/ESTwoKeyNav/PropertyInt16>>") - .root().left() - .goPath() - .first().isComplex("PropertyComplex").isType(ComplexTypeProvider.nameCTPrimComp, false) - .n().isComplex("PropertyComplex").isType(ComplexTypeProvider.nameCTAllPrim, false) - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .root().right() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.root) - .n().isEntitySet("ESTwoKeyNav") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'2'") - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOnETKeyNav("cast(com.sap.odata.test1.ETBaseTwoKeyNav)") - .is(")>") - .root() - .isMethod(MethodKind.CAST, 1) - .isParameterText(0, "") - .goParameter(0) - .isTypedLiteral(EntityTypeProvider.nameETBaseTwoKeyNav); - - testFilter.runOnETKeyNav("cast(PropertyComplexTwoPrim,com.sap.odata.test1.CTBase)") - .is(",)>") - .root() - .isMethod(MethodKind.CAST, 2) - .isParameterText(0, "") - .isParameterText(1, "") - .goParameter(0).goPath().first() - .isComplex("PropertyComplexTwoPrim").isType(ComplexTypeProvider.nameCTTwoPrim, false) - .goUpFilterValidator() - .root() - .goParameter(1) - .isTypedLiteral(ComplexTypeProvider.nameCTBase); - - testFilter.runOnETKeyNav("cast($it,com.sap.odata.test1.CTBase)") - .is(",)>") - .root() - .isMethod(MethodKind.CAST, 2) - .isParameterText(0, "<$it>") - .isParameterText(1, "") - .goParameter(0).goPath().first() - .isIt().isType(EntityTypeProvider.nameETKeyNav, false) - .goUpFilterValidator() - .root() - .goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTBase); - - testFilter.runOnETKeyNav("cast($it,com.sap.odata.test1.CTBase) eq cast($it,com.sap.odata.test1.CTBase)" - ) - .is("<,)> eq ,)>>") - .root().left() - .isMethod(MethodKind.CAST, 2) - .isParameterText(0, "<$it>") - .isParameterText(1, "") - .goParameter(0).goPath().first() - .isIt().isType(EntityTypeProvider.nameETKeyNav, false) - .goUpFilterValidator() - .root().left() - .goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTBase) - .root().right() - .isMethod(MethodKind.CAST, 2) - .isParameterText(0, "<$it>") - .isParameterText(1, "") - .goParameter(0).goPath().first() - .isIt().isType(EntityTypeProvider.nameETKeyNav, false) - .goUpFilterValidator() - .root().right() - .goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTBase); - - testFilter.runOnInt32("cast(Edm.Int32)") - .is(")>") - .isMethod(MethodKind.CAST, 1) - .goParameter(0).isTypedLiteral(PropertyProvider.nameInt32); - - testFilter.runOnDateTimeOffset("cast(Edm.DateTimeOffset)") - .is(")>") - .isMethod(MethodKind.CAST, 1) - .goParameter(0).isTypedLiteral(PropertyProvider.nameDateTimeOffset); - - testFilter.runOnDuration("cast(Edm.Duration)") - .is(")>") - .isMethod(MethodKind.CAST, 1) - .goParameter(0).isTypedLiteral(PropertyProvider.nameDuration); - - testFilter.runOnTimeOfDay("cast(Edm.TimeOfDay)") - .is(")>") - .isMethod(MethodKind.CAST, 1) - .goParameter(0).isTypedLiteral(PropertyProvider.nameTimeOfDay); - - testFilter.runOnETKeyNav("cast(CollPropertyInt16,Edm.Int32)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath().first() - .isPrimitiveProperty("CollPropertyInt16", PropertyProvider.nameInt16, true) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(PropertyProvider.nameInt32); - - testFilter.runOnETTwoKeyNav( - "cast(PropertyComplex/PropertyComplex/PropertyDateTimeOffset,Edm.DateTimeOffset)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath() - .first().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n().isPrimitiveProperty("PropertyDateTimeOffset", PropertyProvider.nameDateTimeOffset, false) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(PropertyProvider.nameDateTimeOffset); - - testFilter.runOnETTwoKeyNav("cast(PropertyComplex/PropertyComplex/PropertyDuration,Edm.Duration)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath() - .first().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n().isPrimitiveProperty("PropertyDuration", PropertyProvider.nameDuration, false) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(PropertyProvider.nameDuration); - - testFilter.runOnETTwoKeyNav("cast(PropertyComplex/PropertyComplex/PropertyTimeOfDay,Edm.TimeOfDay)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath() - .first().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n().isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .n().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(PropertyProvider.nameTimeOfDay); - - testFilter.runOnETKeyNav("cast(PropertyComplexAllPrim,com.sap.odata.test1.CTTwoPrim)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath() - .first().isComplexProperty("PropertyComplexAllPrim", ComplexTypeProvider.nameCTAllPrim, false) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoPrim); - - // testFilter.runOnETKeyNav(" Xcast(PropertyComplexTwoPrim,com.sap.odata.test1.CTAllPrim)"); - - testFilter.runOnETKeyNav("cast(NavPropertyETKeyNavOne,com.sap.odata.test1.ETKeyPrimNav)") - .is(",)>") - .isMethod(MethodKind.CAST, 2) - .goParameter(0).goPath() - .first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .goUpFilterValidator().root() - .goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyPrimNav); - - testFilter.runOnETKeyNavEx("cast(NavPropertyETKeyPrimNavOne,com.sap.odata.test1.ETKeyNav)").isExSemantic(0); - testFilter.runOnETKeyNav("any()") - .isMember().goPath().first().isUriPathInfoKind(UriResourceKind.lambdaAny); - - } - - @Test - public void runLamdbaFunctions() throws ExpressionVisitException, ODataApplicationException, UriParserException { - - testFilter.runOnETKeyNav("any(d:d/PropertyInt16 eq 1)") - .is("< eq <1>>>>") - .root().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETKeyNav, false) - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyString eq 'SomeString')") - .is(" eq <'SomeString'>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // TODO planned: lambda does not check if the previous path segment is a collection - // testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavOne/any(d:d/PropertyString eq 'SomeString')"); - - testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any()") - .is(">"); - - testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavOne/CollPropertyString/any(d:d eq 'SomeString')") - .is(" eq <'SomeString'>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(PropertyProvider.nameString, false); - - testFilter.runOnETKeyNav(" NavPropertyETTwoKeyNavOne/com.sap.odata.test1.BFCETTwoKeyNavRTESTwoKeyNav()" - + "/any(d:d/PropertyComplex/PropertyInt16 eq 6)") - .is(" eq <6>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .n().isFunction("BFCETTwoKeyNavRTESTwoKeyNav") - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyInt16 eq 1 or d/any" - + "(e:e/CollPropertyString eq 'SomeString'))") - .is(" eq <1>> or " - + " eq <'SomeString'>>>>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().isBinary(BinaryOperatorKind.OR) - .root().left() - .isBinary(BinaryOperatorKind.EQ) - .left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .root().right() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("CollPropertyString", PropertyProvider.nameString, true); - - testFilter.runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyInt16 eq 1 or d/CollPropertyString/any" - + "(e:e eq 'SomeString'))") - .is(" eq <1>> or " - + " eq <'SomeString'>>>>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().isBinary(BinaryOperatorKind.OR) - .root().left() - .isBinary(BinaryOperatorKind.EQ) - .left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .root().right() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isType(PropertyProvider.nameString, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(PropertyProvider.nameString, false); - - testFilter - .runOnETKeyNav("NavPropertyETTwoKeyNavMany/any(d:d/PropertyString eq 'SomeString' and d/CollPropertyString/any" - + "(e:e eq d/PropertyString))") - .is(" eq <'SomeString'>> and " - + " eq >>>>>>") - .root().goPath() - .first().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().isBinary(BinaryOperatorKind.AND) - .root().left() - .isBinary(BinaryOperatorKind.EQ) - .left() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().right() - .goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .n().isType(PropertyProvider.nameString, true) - .n().isUriPathInfoKind(UriResourceKind.lambdaAny) - .goLambdaExpression() - .root().left().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .isType(PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().right().goPath() - .first().isUriPathInfoKind(UriResourceKind.lambdaVariable) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - } - - @Test - public void runIsOf() throws ExpressionVisitException, ODataApplicationException, UriParserException { - - testFilter.runOnETKeyNav("isof(com.sap.odata.test1.ETTwoKeyNav)") - .is(")>") - .root() - .isMethod(MethodKind.ISOF, 1) - .goParameter(0).isTypedLiteral(EntityTypeProvider.nameETTwoKeyNav); - - testFilter.runOnETKeyNav("isof(com.sap.odata.test1.ETBaseTwoKeyNav) eq true") - .is("<)> eq >") - .root().isBinary(BinaryOperatorKind.EQ) - .left() - .isMethod(MethodKind.ISOF, 1) - .goParameter(0).isTypedLiteral(EntityTypeProvider.nameETBaseTwoKeyNav); - - testFilter - .runOnETKeyNav("isof(com.sap.odata.test1.ETBaseTwoKeyNav) eq true and PropertyComplex/PropertyInt16 eq 1") - .is("<<)> eq > and < eq <1>>>") - .root().isBinary(BinaryOperatorKind.AND) - .left().isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.ISOF, 1) - .goParameter(0).isTypedLiteral(EntityTypeProvider.nameETBaseTwoKeyNav); - - testFilter.runOnETKeyNav("isof(NavPropertyETKeyNavOne, com.sap.odata.test1.ETKeyNav) eq true") - .is("<,)> eq >") - .root().isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .goUpFilterValidator() - .root().left().goParameter(1).isTypedLiteral(EntityTypeProvider.nameETKeyNav); - - testFilter.runOnETKeyNav("isof(PropertyComplexTwoPrim,com.sap.odata.test1.CTTwoPrim)") - .is(",)>") - .root().isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isComplex("PropertyComplexTwoPrim").goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoPrim); - - testFilter.runOnETKeyNav("isof(PropertyComplexTwoPrim,com.sap.odata.test1.CTTwoBase)") - .is(",)>") - .root().isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isComplex("PropertyComplexTwoPrim").goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoBase); - - testFilter.runOnETKeyNav("isof(PropertyComplexTwoPrim,com.sap.odata.test1.CTTwoPrim) eq true") - .is("<,)> eq >") - .root().left().isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isComplex("PropertyComplexTwoPrim").goUpFilterValidator() - .root().left().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoPrim); - - testFilter.runOnETKeyNav("isof($it,com.sap.odata.test1.CTTwoPrim)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isIt().goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoPrim); - - testFilter.runOnETKeyNav("isof($it,com.sap.odata.test1.CTTwoBase) eq false") - .is("<,)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath().isIt().goUpFilterValidator() - .root().left().goParameter(1).isTypedLiteral(ComplexTypeProvider.nameCTTwoBase); - - testFilter.runOnETKeyNav("isof(PropertyComplex/PropertyInt16,Edm.Int32)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameInt32); - - testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyDateTimeOffset,Edm.DateTimeOffset)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDateTimeOffset", PropertyProvider.nameDateTimeOffset, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameDateTimeOffset); - - testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyTimeOfDay,Edm.TimeOfDay)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameTimeOfDay); - - testFilter.runOnETTwoKeyNav(" isof(PropertyComplex/PropertyComplex/PropertyDuration,Edm.Duration)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDuration", PropertyProvider.nameDuration, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameDuration); - - testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyString,Edm.String)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameString); - - testFilter.runOnETTwoKeyNav("isof(PropertyComplex/PropertyComplex/PropertyString,Edm.Guid)") - .is(",)>") - .root() - .isMethod(MethodKind.ISOF, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().goParameter(1).isTypedLiteral(PropertyProvider.nameGuid); - } - - @Test - public void testHas() throws ExpressionVisitException, ODataApplicationException, UriParserException { - - testFilter.runOnETTwoKeyNav("PropertyEnumString has com.sap.odata.test1.ENString'String1'") - .is("< has >>") - .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); - - testFilter.runOnETTwoKeyNav("PropertyComplexEnum/PropertyEnumString has com.sap.odata.test1.ENString'String2'") - .is("< has >>") - .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath() - .first().isComplex("PropertyComplexEnum") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); - - testFilter.runOnETTwoKeyNav( - "PropertyComplexEnum/PropertyEnumString has com.sap.odata.test1.ENString'String2' eq true") - .is("<< has >> eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left() - .isBinary(BinaryOperatorKind.HAS) - .root().left().left().goPath() - .first().isComplex("PropertyComplexEnum") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().left().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); - - testFilter.runOnETTwoKeyNav("PropertyEnumString has com.sap.odata.test1.ENString'String3'") - .is("< has >>") - .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String3")); - - testFilter.runOnETTwoKeyNav("PropertyEnumString has com.sap.odata.test1.ENString'String,String3'") - .is("< has >>") - .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String", "String3")); - - testFilter.runOnETTwoKeyNav("PropertyEnumString has null") - .is("< has >") - .root() - .isBinary(BinaryOperatorKind.HAS) - .root().left().goPath() - .first().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() - .root().right().isNull(); - - testFilter.runOnETTwoKeyNav("endswith(PropertyComplex/PropertyComplex/PropertyString,'dorf')") - .is(",<'dorf'>)>") - .isMethod(MethodKind.ENDSWITH, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().goParameter(1).isLiteral("'dorf'"); - - testFilter.runOnETTwoKeyNav("endswith(PropertyComplex/PropertyComplex/PropertyString,'dorf') eq true") - .is("<,<'dorf'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.ENDSWITH, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().left().goParameter(1).isLiteral("'dorf'"); - - testFilter.runOnETTwoKeyNav("endswith('Walldorf','dorf')") - .is(",<'dorf'>)>") - .isMethod(MethodKind.ENDSWITH, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().goParameter(1).isLiteral("'dorf'"); - - testFilter.runOnETTwoKeyNav("endswith('Walldorf','dorf') eq true") - .is("<,<'dorf'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.ENDSWITH, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().left().goParameter(1).isLiteral("'dorf'"); - - testFilter.runOnETKeyNav("startswith(PropertyComplexAllPrim/PropertyString,'Wall')") - .is(",<'Wall'>)>") - .isMethod(MethodKind.STARTSWITH, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplexAllPrim") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETKeyNav("startswith(PropertyComplexAllPrim/PropertyString,'Wall') eq true") - .is("<,<'Wall'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.STARTSWITH, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplexAllPrim") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().left().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETKeyNav("startswith('Walldorf','Wall')") - .is(",<'Wall'>)>") - .isMethod(MethodKind.STARTSWITH, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETKeyNav("startswith('Walldorf','Wall') eq true") - .is("<,<'Wall'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.STARTSWITH, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().left().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETTwoKeyNav("contains(PropertyComplex/PropertyComplex/PropertyString,'Wall')") - .is(",<'Wall'>)>") - .isMethod(MethodKind.CONTAINS, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETTwoKeyNav("contains(PropertyComplex/PropertyComplex/PropertyString,'Wall') eq true") - .is("<,<'Wall'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.CONTAINS, 2) - .goParameter(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .root().left().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETTwoKeyNav("contains('Walldorf','Wall')") - .is(",<'Wall'>)>") - .isMethod(MethodKind.CONTAINS, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETTwoKeyNav("contains('Walldorf','Wall') eq true") - .is("<,<'Wall'>)> eq >") - .isBinary(BinaryOperatorKind.EQ) - .left().isMethod(MethodKind.CONTAINS, 2) - .goParameter(0).isLiteral("'Walldorf'") - .root().left().goParameter(1).isLiteral("'Wall'"); - - testFilter.runOnETAllPrim("com.sap.odata.test1.UFCRTCTTwoPrimParam(ParameterInt16=null,ParameterString=null)") - .goPath() - .isFunction("UFCRTCTTwoPrimParam") - .isParameter(0, "ParameterInt16", "null") - .isParameter(1, "ParameterString", "null"); - - testFilter.runOnETAllPrim("PropertyBoolean eq true") - .is("< eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyBoolean", PropertyProvider.nameBoolean, false) - .goUpFilterValidator() - .root().right().isTrue(); - - testFilter.runOnETAllPrim("PropertyBoolean eq 2") - .is("< eq <2>>"); - - testFilter.runOnETAllPrim("PropertyDecimal eq 1.25") - .is("< eq <1.25>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyDecimal", PropertyProvider.nameDecimal, false) - .goUpFilterValidator() - .root().right().isLiteral("1.25"); - - testFilter.runOnETAllPrim("PropertyDouble eq 1.5") - .is("< eq <1.5>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyDouble", PropertyProvider.nameDouble, false) - .goUpFilterValidator() - .root().right().isLiteral("1.5"); - - testFilter.runOnETAllPrim("PropertySingle eq 1.5") - .is("< eq <1.5>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertySingle", PropertyProvider.nameSingle, false) - .goUpFilterValidator() - .root().right().isLiteral("1.5"); - - testFilter.runOnETAllPrim("PropertySByte eq -128") - .is("< eq <-128>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertySByte", PropertyProvider.nameSByte, false) - .goUpFilterValidator() - .root().right().isLiteral("-128"); - - testFilter.runOnETAllPrim("PropertyByte eq 255") - .is("< eq <255>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyByte", - PropertyProvider.nameByte, false).goUpFilterValidator() - .root().right().isLiteral("255"); - - testFilter.runOnETAllPrim("PropertyInt16 eq 32767") - .is("< eq <32767>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .root().right().isLiteral("32767"); - - testFilter.runOnETAllPrim("PropertyInt32 eq 2147483647") - .is("< eq <2147483647>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyInt32", PropertyProvider.nameInt32, false) - .goUpFilterValidator() - .root().right().isLiteral("2147483647"); - - testFilter.runOnETAllPrim("PropertyInt64 eq 9223372036854775807") - .is("< eq <9223372036854775807>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyInt64", PropertyProvider.nameInt64, false) - .goUpFilterValidator() - .root().right().isLiteral("9223372036854775807"); - - testFilter.runOnETAllPrim("PropertyDate eq 2013-09-25") - .is("< eq <2013-09-25>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .goUpFilterValidator() - .root().right().isLiteral("2013-09-25"); - - testFilter.runOnETAllPrim("PropertyDateTimeOffset eq 2013-09-25T12:34:56.123456789012-10:24") - .is("< eq <2013-09-25T12:34:56.123456789012-10:24>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath() - .isPrimitiveProperty("PropertyDateTimeOffset", PropertyProvider.nameDateTimeOffset, false) - .goUpFilterValidator() - .root().right().isLiteral("2013-09-25T12:34:56.123456789012-10:24"); - - testFilter.runOnETAllPrim("PropertyDuration eq duration'P10DT5H34M21.123456789012S'") - .is("< eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyDuration", PropertyProvider.nameDuration, false) - .goUpFilterValidator() - .root().right().isLiteral("duration'P10DT5H34M21.123456789012S'"); - - testFilter.runOnETAllPrim("PropertyGuid eq 005056A5-09B1-1ED3-89BD-FB81372CCB33") - .is("< eq <005056A5-09B1-1ED3-89BD-FB81372CCB33>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyGuid", PropertyProvider.nameGuid, false) - .goUpFilterValidator() - .root().right().isLiteral("005056A5-09B1-1ED3-89BD-FB81372CCB33"); - - testFilter.runOnETAllPrim("PropertyString eq 'somestring'") - .is("< eq <'somestring'>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .root().right().isLiteral("'somestring'"); - - testFilter.runOnETAllPrim("PropertyTimeOfDay eq 12:34:55.12345678901") - .is("< eq <12:34:55.12345678901>>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) - .goUpFilterValidator() - .root().right().isLiteral("12:34:55.12345678901"); - - testFilter.runOnETTwoKeyNav("PropertyEnumString eq com.sap.odata.test1.ENString'String1'") - .is("< eq >>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); - - testFilter.runOnETTwoKeyNav("PropertyEnumString eq com.sap.odata.test1.ENString'String2'") - .is("< eq >>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString) - .goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String2")); - - testFilter.runOnETTwoKeyNav("PropertyComplexEnum/PropertyEnumString eq com.sap.odata.test1.ENString'String3'") - .is("< eq >>") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath() - .first().isComplex("PropertyComplexEnum") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() - .root().right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String3")); - - testFilter.runOnETTwoKeyNav("PropertyComplexEnum/PropertyEnumString eq PropertyComplexEnum/PropertyEnumString") - .is("< eq >") - .isBinary(BinaryOperatorKind.EQ) - .root().left().goPath() - .first().isComplex("PropertyComplexEnum") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator() - .root().right().goPath() - .first().isComplex("PropertyComplexEnum") - .n().isComplex("PropertyEnumString").isType(EnumTypeProvider.nameENString).goUpFilterValidator(); - - } - - @Test - public void testOrderby() throws UriParserException, UnsupportedEncodingException { - - testFilter.runOrderByOnETTwoKeyNav("com.sap.odata.test1.UFCRTETAllPrimTwoParam(" - + "ParameterString=@ParamStringAlias,ParameterInt16=@ParamInt16Alias)/PropertyString eq 'SomeString'") - .isSortOrder(0, false) - .goOrder(0).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isFunction("UFCRTETAllPrimTwoParam").goUpFilterValidator() - .goOrder(0).right().isLiteral("'SomeString'"); - - testFilter.runOrderByOnETTwoKeyNav("com.sap.odata.test1.UFCRTETAllPrimTwoParam(" - + "ParameterString=@ParamStringAlias,ParameterInt16=@ParamInt16Alias)/PropertyString eq 'SomeString' asc") - .isSortOrder(0, false) - .goOrder(0).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isFunction("UFCRTETAllPrimTwoParam").goUpFilterValidator() - .goOrder(0).right().isLiteral("'SomeString'"); - - testFilter.runOrderByOnETTwoKeyNav("com.sap.odata.test1.UFCRTETAllPrimTwoParam(" - + "ParameterString=@ParamStringAlias,ParameterInt16=@ParamInt16Alias)/PropertyString eq 'SomeString' desc") - .isSortOrder(0, true) - .goOrder(0).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isFunction("UFCRTETAllPrimTwoParam").goUpFilterValidator() - .goOrder(0).right().isLiteral("'SomeString'"); - - testFilter.runOrderByOnETTwoKeyNav("com.sap.odata.test1.UFCRTETAllPrimTwoParam(" - + "ParameterString=@ParamStringAlias,ParameterInt16=@ParamInt16Alias)/PropertyString eq 'SomeString' desc" - + ", PropertyString eq '1'") - .isSortOrder(0, true) - .goOrder(0).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isFunction("UFCRTETAllPrimTwoParam").goUpFilterValidator() - .goOrder(0).right().isLiteral("'SomeString'") - .isSortOrder(1, false) - .goOrder(1).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .goOrder(1).right().isLiteral("'1'"); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyDate eq " - + "$root/ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplex/PropertyComplex/PropertyDate") - .isSortOrder(0, false) - .goOrder(0).isBinary(BinaryOperatorKind.EQ).left().goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .goUpFilterValidator() - .goOrder(0).right().goPath() - .first().isUriPathInfoKind(UriResourceKind.root) - .n().isEntitySet("ESTwoKeyNav") - .n().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false); - - testFilter.runOrderByOnETTwoKeyNav("PropertyString") - .isSortOrder(0, false) - .goOrder(0).goPath() - .first().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyDate") - .isSortOrder(0, false) - .goOrder(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyDate " - + "eq 2013-11-12 desc, PropertyString eq 'SomeString' desc") - .isSortOrder(0, true) - .goOrder(0).isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false).goUpFilterValidator() - .goOrder(0).right().isLiteral("2013-11-12") - .isSortOrder(1, true) - .goOrder(1).left().goPath().first().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .goOrder(1).right().isLiteral("'SomeString'"); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex") - .isSortOrder(0, false) - .goOrder(0).goPath() - .first().isComplex("PropertyComplex"); - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex/PropertyComplex") - .isSortOrder(0, false) - .goOrder(0).goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex"); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex desc, PropertyComplex/PropertyInt16 eq 1") - .isSortOrder(0, true) - .goOrder(0).goPath() - .first().isComplex("PropertyComplex").goUpFilterValidator() - .isSortOrder(1, false) - .goOrder(1).isBinary(BinaryOperatorKind.EQ) - .left().goPath() - .first().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false).goUpFilterValidator() - .goOrder(1).right().isLiteral("1"); - - testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavOne") - .isSortOrder(0, false).goOrder(0).goPath() - .first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavOne/PropertyString") - .isSortOrder(0, false).goOrder(0).goPath() - .first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavOne/PropertyComplex") - .isSortOrder(0, false).goOrder(0).goPath() - .first().isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .n().isComplex("PropertyComplex"); - - testFilter.runOrderByOnETTwoKeyNav("PropertyComplex/PropertyComplex/PropertyInt16 eq 1") - .isSortOrder(0, false).goOrder(0).left().goPath() - .first().isComplex("PropertyComplex") - .n().isComplex("PropertyComplex") - .n().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavMany(1)/NavPropertyETTwoKeyNavMany(PropertyString='2')" - + "/PropertyString eq 'SomeString'") - .isSortOrder(0, false).goOrder(0).left().goPath() - .first().isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .n().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOrderByOnETTwoKeyNav("NavPropertyETKeyNavMany(1)/NavPropertyETTwoKeyNavMany(PropertyString='2')" - + "/PropertyString eq 'SomeString1' desc,PropertyString eq 'SomeString2' asc") - .isSortOrder(0, true).goOrder(0).left().goPath() - .first().isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .n().isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .n().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false).goUpFilterValidator() - .isSortOrder(1, false).goOrder(1).left().goPath() - .first().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testFilter.runOrderByOnETAllPrim("PropertyBoolean eq true") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyBoolean", PropertyProvider.nameBoolean, false) - .goUpFilterValidator() - .goOrder(0).right().isTrue(); - - testFilter.runOrderByOnETAllPrim("PropertyBoolean eq true desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyBoolean", PropertyProvider.nameBoolean, false) - .goUpFilterValidator() - .goOrder(0).right().isTrue(); - - testFilter.runOrderByOnETAllPrim(encode("PropertyDouble eq 3.5E+38")) - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDouble", PropertyProvider.nameDouble, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("3.5E+38"); - - testFilter.runOrderByOnETAllPrim(encode("PropertyDouble eq 3.5E+38 desc")).isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDouble", PropertyProvider.nameDouble, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("3.5E+38"); - - testFilter.runOrderByOnETAllPrim("PropertySingle eq 1.5") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertySingle", PropertyProvider.nameSingle, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("1.5"); - - testFilter.runOrderByOnETAllPrim("PropertySingle eq 1.5 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertySingle", PropertyProvider.nameSingle, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("1.5"); - - testFilter.runOrderByOnETAllPrim("PropertySByte eq -128") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertySByte", PropertyProvider.nameSByte, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("-128"); - - testFilter.runOrderByOnETAllPrim("PropertySByte eq -128 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertySByte", PropertyProvider.nameSByte, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("-128"); - - testFilter.runOrderByOnETAllPrim("PropertyByte eq 255") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("255"); - - testFilter.runOrderByOnETAllPrim("PropertyByte eq 255 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyByte", PropertyProvider.nameByte, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("255"); - - testFilter.runOrderByOnETAllPrim("PropertyInt16 eq 32767") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("32767"); - - testFilter.runOrderByOnETAllPrim("PropertyInt16 eq 32767 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("32767"); - - testFilter.runOrderByOnETAllPrim("PropertyInt32 eq 2147483647") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt32", PropertyProvider.nameInt32, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2147483647"); - - testFilter.runOrderByOnETAllPrim("PropertyInt32 eq 2147483647 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt32", PropertyProvider.nameInt32, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2147483647"); - - testFilter.runOrderByOnETAllPrim("PropertyInt64 eq 9223372036854775807") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt64", PropertyProvider.nameInt64, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("9223372036854775807"); - - testFilter.runOrderByOnETAllPrim("PropertyInt64 eq 9223372036854775807 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyInt64", PropertyProvider.nameInt64, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("9223372036854775807"); - - testFilter.runOrderByOnETAllPrim("PropertyBinary eq binary'0FAB7B'") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyBinary", PropertyProvider.nameBinary, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("binary'0FAB7B'"); - - testFilter.runOrderByOnETAllPrim("PropertyBinary eq binary'0FAB7B' desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyBinary", PropertyProvider.nameBinary, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("binary'0FAB7B'"); - - testFilter.runOrderByOnETAllPrim("PropertyDate eq 2013-09-25") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2013-09-25"); - - testFilter.runOrderByOnETAllPrim("PropertyDate eq 2013-09-25 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDate", PropertyProvider.nameDate, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2013-09-25"); - - testFilter.runOrderByOnETAllPrim("PropertyDateTimeOffset eq 2013-09-25T12:34:56.123456789012-10:24") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDateTimeOffset", PropertyProvider.nameDateTimeOffset, - false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2013-09-25T12:34:56.123456789012-10:24"); - - testFilter.runOrderByOnETAllPrim("PropertyDateTimeOffset eq 2013-09-25T12:34:56.123456789012-10:24 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDateTimeOffset", PropertyProvider.nameDateTimeOffset, - false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("2013-09-25T12:34:56.123456789012-10:24"); - - testFilter.runOrderByOnETAllPrim("PropertyDuration eq duration'P10DT5H34M21.123456789012S'") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDuration", PropertyProvider.nameDuration, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("duration'P10DT5H34M21.123456789012S'"); - - testFilter.runOrderByOnETAllPrim("PropertyDuration eq duration'P10DT5H34M21.123456789012S' desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyDuration", PropertyProvider.nameDuration, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("duration'P10DT5H34M21.123456789012S'"); - - testFilter.runOrderByOnETAllPrim("PropertyGuid eq 005056A5-09B1-1ED3-89BD-FB81372CCB33") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyGuid", PropertyProvider.nameGuid, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("005056A5-09B1-1ED3-89BD-FB81372CCB33"); - - testFilter.runOrderByOnETAllPrim("PropertyGuid eq 005056A5-09B1-1ED3-89BD-FB81372CCB33 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyGuid", PropertyProvider.nameGuid, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("005056A5-09B1-1ED3-89BD-FB81372CCB33"); - - testFilter.runOrderByOnETAllPrim("PropertyString eq 'somestring'") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("'somestring'"); - - testFilter.runOrderByOnETAllPrim("PropertyString eq 'somestring' desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("'somestring'"); - - testFilter.runOrderByOnETAllPrim("PropertyTimeOfDay eq 12:34:55.123456789012") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("12:34:55.123456789012"); - - testFilter.runOrderByOnETAllPrim("PropertyTimeOfDay eq 12:34:55.123456789012 desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isPrimitiveProperty("PropertyTimeOfDay", PropertyProvider.nameTimeOfDay, false) - .goUpFilterValidator() - .goOrder(0).right().isLiteral("12:34:55.123456789012"); - - testFilter.runOrderByOnETTwoKeyNav("PropertyEnumString eq com.sap.odata.test1.ENString'String1'") - .isSortOrder(0, false) - .goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator() - .goOrder(0).right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); - - testFilter.runOrderByOnETTwoKeyNav("PropertyEnumString eq com.sap.odata.test1.ENString'String1' desc") - .isSortOrder(0, true) - .goOrder(0).left().goPath().isComplex("PropertyEnumString").goUpFilterValidator() - .goOrder(0).right().isEnum(EnumTypeProvider.nameENString, Arrays.asList("String1")); - - testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 1").isExSyntax(0); - testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16, PropertyInt32 PropertyDuration").isExSyntax(0); - testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 PropertyInt32, PropertyDuration desc").isExSyntax(0); - testFilter.runOrderByOnETTwoKeyNavEx("PropertyInt16 asc, PropertyInt32 PropertyDuration desc").isExSyntax(0); - } - - public void testSearch() { - - testUri.run("ESTwoKeyNav?$search=abc"); - testUri.run("ESTwoKeyNav?$search=NOT abc"); - - testUri.run("ESTwoKeyNav?$search=abc AND def"); - testUri.run("ESTwoKeyNav?$search=abc OR def"); - testUri.run("ESTwoKeyNav?$search=abc def"); - - testUri.run("ESTwoKeyNav?$search=abc AND def AND ghi"); - testUri.run("ESTwoKeyNav?$search=abc AND def OR ghi"); - testUri.run("ESTwoKeyNav?$search=abc AND def ghi"); - - testUri.run("ESTwoKeyNav?$search=abc OR def AND ghi"); - testUri.run("ESTwoKeyNav?$search=abc OR def OR ghi"); - testUri.run("ESTwoKeyNav?$search=abc OR def ghi"); - - testUri.run("ESTwoKeyNav?$search=abc def AND ghi"); - testUri.run("ESTwoKeyNav?$search=abc def OR ghi"); - testUri.run("ESTwoKeyNav?$search=abc def ghi"); - - // mixed not - testUri.run("ESTwoKeyNav?$search= abc def AND ghi"); - testUri.run("ESTwoKeyNav?$search=NOT abc NOT def OR NOT ghi"); - testUri.run("ESTwoKeyNav?$search= abc def NOT ghi"); - - // parenthesis - testUri.run("ESTwoKeyNav?$search= (abc)"); - testUri.run("ESTwoKeyNav?$search= (abc AND def)"); - testUri.run("ESTwoKeyNav?$search= (abc AND def) OR ghi "); - testUri.run("ESTwoKeyNav?$search= (abc AND def) ghi "); - testUri.run("ESTwoKeyNav?$search= abc AND (def OR ghi)"); - testUri.run("ESTwoKeyNav?$search= abc AND (def ghi)"); - } - - @Test - public void testErrors() { - testUri.runEx("FICRTString(wrong1='ABC')/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0); - testUri.runEx("FICRTString(wrong1='ABC', wrong2=1)/com.sap.odata.test1.BFCStringRTESTwoKeyNav()").isExSemantic(0); - - // type filter for entity incompatible - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/com.sap.odata.test1.ETBase").isExSemantic(0); - - // type filter for entity double on entry - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')" - + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0); - // type filter for entity double on collection - testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav") - .isExSemantic(0); - // type filter for entity double on non key pred - testUri.runEx("SINav/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.ETBaseTwoKeyNav").isExSemantic(0); - - // type filter for complex incompatible - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim" - + "/com.sap.odata.test1.CTCollAllPrim").isExSemantic(0); - - // type filter for complex double on entry - testUri.runEx("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')" - + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0); - - // type filter for complex double on collection - testUri.runEx("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')" - + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0); - - // type filter for complex double on non key pred - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim" - + "/com.sap.odata.test1.CTBase/com.sap.odata.test1.CTBase").isExSemantic(0); - - testUri.runEx("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav").isExSemantic(0); - - // $ref - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim/$ref").isExSemantic(0); - testUri.runEx("ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyComplexTwoPrim/$count").isExSemantic(0); - - } - - @Test - public void testAlias() { - testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)?@A='2'").goPath() - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicateAlias(1, "PropertyString", "A") - .goUpUriValidator() - .isCustomParameter(0, "@A", "'2'"); - - } - - public static String encode(final String decoded) throws UnsupportedEncodingException { - return Encoder.encode(decoded); - - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java deleted file mode 100644 index e8aa9cecd..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestLexer.java +++ /dev/null @@ -1,248 +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.server.core.uri.antlr; - -import org.antlr.v4.runtime.Lexer; -import org.apache.olingo.server.core.uri.testutil.TokenValidator; -import org.junit.Test; - -public class TestLexer { - - private TokenValidator test = null; - - private static final String cPCT_ENCODED = "%45%46%47" + "%22" + "%5C";// last two chars are not in - // cPCT_ENCODED_UNESCAPED - private static final String cUNRESERVED = "ABCabc123-._~"; - private static final String cOTHER_DELIMS = "!()*+,;"; - private static final String cSUB_DELIMS = "$&'=" + cOTHER_DELIMS; - - private static final String cPCHAR = cUNRESERVED + cPCT_ENCODED + cSUB_DELIMS + ":@"; - - public TestLexer() { - test = new TokenValidator(); - } - - @Test - public void test() { - - // test.log(1).run("ESAllPrim?$orderby=PropertyDouble eq 3.5E+38"); - } - - // ;------------------------------------------------------------------------------ - // ; 0. URI - // ;------------------------------------------------------------------------------ - - @Test - public void testUriTokens() { - test.globalMode(UriLexer.MODE_QUERY); - test.run("#").isText("#").isType(UriLexer.FRAGMENT); - test.run("$count").isText("$count").isType(UriLexer.COUNT); - test.run("$ref").isText("$ref").isType(UriLexer.REF); - test.run("$value").isText("$value").isType(UriLexer.VALUE); - } - - // ;------------------------------------------------------------------------------ - // ; 2. Query Options - // ;------------------------------------------------------------------------------ - @Test - public void testQueryOptionsTokens() { - - test.globalMode(UriLexer.MODE_QUERY); - test.run("$skip=1").isAllText("$skip=1").isType(UriLexer.SKIP); - test.run("$skip=2").isAllText("$skip=2").isType(UriLexer.SKIP); - test.run("$skip=123").isAllText("$skip=123").isType(UriLexer.SKIP); - - test.run("$top=1").isAllText("$top=1").isType(UriLexer.TOP); - test.run("$top=2").isAllText("$top=2").isType(UriLexer.TOP); - test.run("$top=123").isAllText("$top=123").isType(UriLexer.TOP); - - test.run("$levels=1").isAllText("$levels=1").isType(UriLexer.LEVELS); - test.run("$levels=2").isAllText("$levels=2").isType(UriLexer.LEVELS); - test.run("$levels=123").isAllText("$levels=123").isType(UriLexer.LEVELS); - test.run("$levels=max").isAllText("$levels=max").isType(UriLexer.LEVELS); - - test.run("$format=atom").isAllText("$format=atom").isType(UriLexer.FORMAT); - test.run("$format=json").isAllText("$format=json").isType(UriLexer.FORMAT); - test.run("$format=xml").isAllText("$format=xml").isType(UriLexer.FORMAT); - test.run("$format=abc/def").isAllText("$format=abc/def").isType(UriLexer.FORMAT); - - test.run("$id=123").isAllText("$id=123").isType(UriLexer.ID); - test.run("$id=ABC").isAllText("$id=ABC").isType(UriLexer.ID); - - test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN); - test.run("$skiptoken=ABC").isAllText("$skiptoken=ABC").isType(UriLexer.SKIPTOKEN); - - test.run("$search=\"ABC\"").isAllText("$search=\"ABC\"").isType(UriLexer.SEARCH); - test.run("$search=ABC").isAllText("$search=ABC").isType(UriLexer.SEARCH); - test.run("$search=\"A%20B%20C\"").isAllText("$search=\"A%20B%20C\"").isType(UriLexer.SEARCH); - } - - // ;------------------------------------------------------------------------------ - // ; 4. Expressions - // ;------------------------------------------------------------------------------ - @Test - public void testQueryExpressions() { - test.globalMode(Lexer.DEFAULT_MODE); - - test.run("$it").isText("$it").isType(UriLexer.IT); - - test.run("$filter=contains(").at(2).isText("contains(").isType(UriLexer.CONTAINS_WORD); - - test.run("$filter=containsabc").at(2).isText("containsabc") - .isType(UriLexer.ODATAIDENTIFIER); // test that this is a ODI - - test.run("$filter=startswith(").at(2).isText("startswith(").isType(UriLexer.STARTSWITH_WORD); - test.run("$filter=endswith(").at(2).isText("endswith(").isType(UriLexer.ENDSWITH_WORD); - test.run("$filter=length(").at(2).isText("length(").isType(UriLexer.LENGTH_WORD); - test.run("$filter=indexof(").at(2).isText("indexof(").isType(UriLexer.INDEXOF_WORD); - test.run("$filter=substring(").at(2).isText("substring(").isType(UriLexer.SUBSTRING_WORD); - test.run("$filter=tolower(").at(2).isText("tolower(").isType(UriLexer.TOLOWER_WORD); - test.run("$filter=toupper(").at(2).isText("toupper(").isType(UriLexer.TOUPPER_WORD); - test.run("$filter=trim(").at(2).isText("trim(").isType(UriLexer.TRIM_WORD); - test.run("$filter=concat(").at(2).isText("concat(").isType(UriLexer.CONCAT_WORD); - - } - - // ;------------------------------------------------------------------------------ - // ; 7. Literal Data Values - // ;------------------------------------------------------------------------------ - - @Test - public void testLiteralDataValues() { - test.globalMode(Lexer.DEFAULT_MODE); - // null - test.run("null").isInput().isType(UriLexer.NULLVALUE); - - // binary - test.run("binary'ABCD'").isInput().isType(UriLexer.BINARY); - test.run("BiNaRy'ABCD'").isInput().isType(UriLexer.BINARY); - - // boolean - test.run("true").isInput().isType(UriLexer.TRUE); - test.run("false").isInput().isType(UriLexer.FALSE); - test.run("TrUe").isInput().isType(UriLexer.BOOLEAN); - test.run("FaLsE").isInput().isType(UriLexer.BOOLEAN); - - // Lexer rule INT - test.run("123").isInput().isType(UriLexer.INT); - test.run("123456789").isInput().isType(UriLexer.INT); - test.run("+123").isInput().isType(UriLexer.INT); - test.run("+123456789").isInput().isType(UriLexer.INT); - test.run("-123").isInput().isType(UriLexer.INT); - test.run("-123456789").isInput().isType(UriLexer.INT); - - // Lexer rule DECIMAL - test.run("0.1").isInput().isType(UriLexer.DECIMAL); - test.run("1.1").isInput().isType(UriLexer.DECIMAL); - test.run("+0.1").isInput().isType(UriLexer.DECIMAL); - test.run("+1.1").isInput().isType(UriLexer.DECIMAL); - test.run("-0.1").isInput().isType(UriLexer.DECIMAL); - test.run("-1.1").isInput().isType(UriLexer.DECIMAL); - - // Lexer rule EXP - test.run("1.1e+1").isInput().isType(UriLexer.DECIMAL); - test.run("1.1e-1").isInput().isType(UriLexer.DECIMAL); - - test.run("NaN").isInput().isType(UriLexer.NANINFINITY); - test.run("-INF").isInput().isType(UriLexer.NANINFINITY); - test.run("INF").isInput().isType(UriLexer.NANINFINITY); - - // Lexer rule GUID - test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID); - test.run("1234ABCD-12AB-23CD-45EF-123456780ABC").isInput().isType(UriLexer.GUID); - - // Lexer rule DATE - test.run("2013-11-15").isInput().isType(UriLexer.DATE); - - // Lexer rule DATETIMEOFFSET - test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET); - test.run("2013-11-15T13:35:10Z").isInput().isType(UriLexer.DATETIMEOFFSET); - test.run("2013-11-15T13:35:10.1234Z").isInput().isType(UriLexer.DATETIMEOFFSET); - - test.run("2013-11-15T13:35:10.1234+01:30").isInput().isType(UriLexer.DATETIMEOFFSET); - test.run("2013-11-15T13:35:10.1234-01:12").isInput().isType(UriLexer.DATETIMEOFFSET); - - test.run("2013-11-15T13:35Z").isInput().isType(UriLexer.DATETIMEOFFSET); - - // Lexer rule DURATION - test.run("duration'PT67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT67.89S'").isInput().isType(UriLexer.DURATION); - - test.run("duration'PT5M'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT5M67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT5M67.89S'").isInput().isType(UriLexer.DURATION); - - test.run("duration'PT4H'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT4H67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT4H67.89S'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT4H5M'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT4H5M67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'PT4H5M67.89S'").isInput().isType(UriLexer.DURATION); - - test.run("duration'P3D'"); - test.run("duration'P3DT67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT67.89S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT5M'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT5M67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT5M67.89S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H67.89S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H5M'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H5M67S'").isInput().isType(UriLexer.DURATION); - test.run("duration'P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION); - - test.run("DuRaTiOn'P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION); - test.run("DuRaTiOn'-P3DT4H5M67.89S'").isInput().isType(UriLexer.DURATION); - - test.run("20:00").isInput().isType(UriLexer.TIMEOFDAY); - test.run("20:15:01").isInput().isType(UriLexer.TIMEOFDAY); - test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY); - - test.run("20:15:01.02").isInput().isType(UriLexer.TIMEOFDAY); - - // String - test.run("'ABC'").isText("'ABC'").isType(UriLexer.STRING); - test.run("'A%20C'").isInput().isType(UriLexer.STRING); - test.run("'%20%20%20ABC'").isInput().isType(UriLexer.STRING); - - } - - @Test - public void testDelims() { - String reserved = "/"; - test.globalMode(UriLexer.MODE_QUERY); - // Test lexer rule UNRESERVED - test.run("$format=A/" + cUNRESERVED).isAllInput().isType(UriLexer.FORMAT); - test.run("$format=A/" + cUNRESERVED + reserved).isType(UriLexer.FORMAT).at(4).isText(cUNRESERVED); - // Test lexer rule PCT_ENCODED - test.run("$format=A/" + cPCT_ENCODED).isAllInput().isType(UriLexer.FORMAT); - test.run("$format=A/" + cPCT_ENCODED + reserved).isType(UriLexer.FORMAT).at(4).isText(cPCT_ENCODED); - // Test lexer rule SUB_DELIMS - test.run("$format=A/" + cSUB_DELIMS).isAllInput().isType(UriLexer.FORMAT); - test.run("$format=A/" + cSUB_DELIMS + reserved).isType(UriLexer.FORMAT).at(4).isText("$"); - // Test lexer rule PCHAR rest - test.run("$format=A/:@").isAllText("$format=A/:@").isType(UriLexer.FORMAT); - test.run("$format=A/:@" + reserved).isType(UriLexer.FORMAT).at(4).isText(":@"); - // Test lexer rule PCHAR all - test.run("$format=" + cPCHAR + "/" + cPCHAR).isAllInput().isType(UriLexer.FORMAT); - - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java deleted file mode 100644 index f928ad2bb..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/antlr/TestUriParserImpl.java +++ /dev/null @@ -1,1144 +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.server.core.uri.antlr; - -import java.io.UnsupportedEncodingException; -import java.net.URLEncoder; -import java.util.Arrays; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriResourceKind; -import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.apache.olingo.server.core.uri.testutil.FilterValidator; -import org.apache.olingo.server.core.uri.testutil.ResourceValidator; -import org.apache.olingo.server.core.uri.testutil.TestUriValidator; -import org.apache.olingo.server.tecsvc.provider.ComplexTypeProvider; -import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; -import org.apache.olingo.server.tecsvc.provider.PropertyProvider; -import org.junit.Test; - -public class TestUriParserImpl { - Edm edm = null; - private final String PropertyBoolean = "PropertyBoolean=true"; - private final String PropertyByte = "PropertyByte=1"; - - private final String PropertyDate = "PropertyDate=2013-09-25"; - private final String PropertyDateTimeOffset = "PropertyDateTimeOffset=2002-10-10T12:00:00-05:00"; - private final String PropertyDecimal = "PropertyDecimal=12"; - private final String PropertyDuration = "PropertyDuration=duration'P10DT5H34M21.123456789012S'"; - private final String PropertyGuid = "PropertyGuid=12345678-1234-1234-1234-123456789012"; - private final String PropertyInt16 = "PropertyInt16=1"; - private final String PropertyInt32 = "PropertyInt32=12"; - private final String PropertyInt64 = "PropertyInt64=64"; - private final String PropertySByte = "PropertySByte=1"; - private final String PropertyString = "PropertyString='ABC'"; - private final String PropertyTimeOfDay = "PropertyTimeOfDay=12:34:55.123456789012"; - - private final String allKeys = PropertyString + "," + PropertyInt16 + "," + PropertyBoolean + "," + PropertyByte - + "," + PropertySByte + "," + PropertyInt32 + "," + PropertyInt64 + "," + PropertyDecimal + "," + PropertyDate - + "," + PropertyDateTimeOffset + "," + PropertyDuration + "," + PropertyGuid + "," + PropertyTimeOfDay; - - TestUriValidator testUri = null; - ResourceValidator testRes = null; - FilterValidator testFilter = null; - - public TestUriParserImpl() { - edm = new EdmProviderImpl(new EdmTechTestProvider()); - testUri = new TestUriValidator().setEdm(edm); - testRes = new ResourceValidator().setEdm(edm); - testFilter = new FilterValidator().setEdm(edm); - } - - @Test - public void test() throws UriParserException, UnsupportedEncodingException { - - } - - @Test - public void testBoundFunctionImport_VarParameters() { - - // no input - testRes.run("ESKeyNav(1)/com.sap.odata.test1.BFCETKeyNavRTETKeyNav()") - .at(0).isUriPathInfoKind(UriResourceKind.entitySet) - .at(1).isUriPathInfoKind(UriResourceKind.function); - - // one input - testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTESTwoKeyNav(ParameterString='ABC')") - .at(0).isUriPathInfoKind(UriResourceKind.entitySet) - .at(1).isUriPathInfoKind(UriResourceKind.function) - .isParameter(0, "ParameterString", "'ABC'"); - - // two input - testRes.run("FICRTESMixPrimCollCompTwoParam(ParameterInt16=1,ParameterString='2')") - .at(0) - .isUriPathInfoKind(UriResourceKind.function) - .isParameter(0, "ParameterInt16", "1") - .isParameter(1, "ParameterString", "'2'"); - } - - @Test - public void testFunctionBound_varReturnType() { - - String esTwoKeyNav = "ESTwoKeyNav(PropertyInt16=1,PropertyString='ABC')"; - - // returning primitive - testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTString()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(PropertyProvider.nameString, false); - - // returning collection of primitive - testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollString()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(PropertyProvider.nameString, true); - - // returning single complex - testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCTTwoPrim()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(ComplexTypeProvider.nameCTTwoPrim, false); - - // returning collection of complex - testRes.run("ESTwoKeyNav/com.sap.odata.test1.BFCESTwoKeyNavRTCollCTTwoPrim()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(ComplexTypeProvider.nameCTTwoPrim, true); - - // returning single entity - testRes.run( - esTwoKeyNav + "/com.sap.odata.test1.ETBaseTwoKeyNav/com.sap.odata.test1.BFCETBaseTwoKeyNavRTETTwoKeyNav()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav, false); - - // returning collection of entity (aka entitySet) - testRes.run(esTwoKeyNav + "/com.sap.odata.test1.BFCSINavRTESTwoKeyNav()") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .at(1) - .isUriPathInfoKind(UriResourceKind.function) - .isType(EntityTypeProvider.nameETTwoKeyNav, true); - } - - @Test - public void runActionImport_VarReturnType() { - - testRes.run("AIRTPrimParam").isKind(UriInfoKind.resource) - .first() - .isActionImport("AIRTPrimParam") - .isAction("UARTPrimParam") - .isType(PropertyProvider.nameString, false); - - testRes.run("AIRTPrimCollParam").isKind(UriInfoKind.resource) - .first() - .isActionImport("AIRTPrimCollParam") - .isAction("UARTPrimCollParam") - .isType(PropertyProvider.nameString, true); - - testRes.run("AIRTCompParam").isKind(UriInfoKind.resource) - .first() - .isActionImport("AIRTCompParam") - .isAction("UARTCompParam") - .isType(ComplexTypeProvider.nameCTTwoPrim, false); - - testRes.run("AIRTCompCollParam").isKind(UriInfoKind.resource) - .first() - .isActionImport("AIRTCompCollParam") - .isAction("UARTCompCollParam") - .isType(ComplexTypeProvider.nameCTTwoPrim, true); - - testRes.run("AIRTETParam").isKind(UriInfoKind.resource) - .first() - .isActionImport("AIRTETParam") - .isAction("UARTETParam") - .isType(EntityTypeProvider.nameETTwoKeyTwoPrim, false); - - testUri.runEx("AIRTPrimParam/invalidElement").isExSemantic(0); - } - - @Test - public void runCount() { - - // count entity set - testRes.run("ESAllPrim/$count") - .at(0) - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETAllPrim, true) - .at(1) - .isUriPathInfoKind(UriResourceKind.count); - - // count on collection of complex - testRes.run("ESKeyNav(1)/CollPropertyComplex/$count") - .at(0) - .isType(EntityTypeProvider.nameETKeyNav) - .at(1) - .isType(ComplexTypeProvider.nameCTPrimComp, true) - .at(2) - .isUriPathInfoKind(UriResourceKind.count); - - // count on collection of primitive - testRes.run("ESCollAllPrim(1)/CollPropertyString/$count") - .at(1) - .isType(PropertyProvider.nameString, true) - .at(2) - .isUriPathInfoKind(UriResourceKind.count); - } - - @Test - public void runCrossJoin() { - testUri.run("$crossjoin(ESAllKey)") - .isKind(UriInfoKind.crossjoin) - .isCrossJoinEntityList(Arrays.asList("ESAllKey")); - - testUri.run("$crossjoin(ESAllKey,ESTwoPrim)") - .isKind(UriInfoKind.crossjoin) - .isCrossJoinEntityList(Arrays.asList("ESAllKey", "ESTwoPrim")); - } - - @Test(expected = Exception.class) - public void testEntityFailOnValidation1() { - // simple entity set; with qualifiedentityTypeName; with filter - testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$filter=PropertyInt16 eq 123&$id=ESAllKey") - .isIdText("ESAllKey") - .goFilter().is("< eq <123>>"); - } - - @Test(expected = Exception.class) - public void testEntityFailOnValidation2() { - // simple entity set; with qualifiedentityTypeName; with 2xformat(before and after), expand, filter - testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?" - + "$format=xml&$expand=*&abc=123&$id=ESBase&xyz=987&$filter=PropertyInt16 eq 123&$format=atom&$select=*") - .isFormatText("atom") - .isCustomParameter(0, "abc", "123") - .isIdText("ESBase") - .isCustomParameter(1, "xyz", "987") - .isSelectItemStar(0); - } - - @Test - public void testEntity() { - - // simple entity set - testUri.run("$entity?$id=ESAllPrim").isKind(UriInfoKind.entityId) - .isKind(UriInfoKind.entityId) - .isIdText("ESAllPrim"); - - // simple entity set; $format before $id - testUri.run("$entity?$format=xml&$id=ETAllPrim").isKind(UriInfoKind.entityId) - .isFormatText("xml") - .isIdText("ETAllPrim"); - - testUri.run("$entity?$format=xml&abc=123&$id=ESAllKey").isKind(UriInfoKind.entityId) - .isFormatText("xml") - .isCustomParameter(0, "abc", "123") - .isIdText("ESAllKey"); - - // simple entity set; $format after $id - testUri.run("$entity?$id=ETAllPrim&$format=xml").isKind(UriInfoKind.entityId) - .isIdText("ETAllPrim") - .isFormatText("xml"); - - // simple entity set; $format and custom parameter after $id - testUri.run("$entity?$id=ETAllPrim&$format=xml&abc=123").isKind(UriInfoKind.entityId) - .isIdText("ETAllPrim") - .isFormatText("xml") - .isCustomParameter(0, "abc", "123"); - - // simple entity set; $format before $id and custom parameter after $id - testUri.run("$entity?$format=xml&$id=ETAllPrim&abc=123").isKind(UriInfoKind.entityId) - .isFormatText("xml") - .isIdText("ETAllPrim") - .isCustomParameter(0, "abc", "123"); - - // simple entity set; with qualifiedentityTypeName - testUri.run("$entity/com.sap.odata.test1.ETTwoPrim?$id=ESBase") - .isEntityType(EntityTypeProvider.nameETTwoPrim) - .isIdText("ESBase"); - - // simple entity set; with qualifiedentityTypeName; - testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim") - .isEntityType(EntityTypeProvider.nameETBase) - .isKind(UriInfoKind.entityId) - .isIdText("ESTwoPrim"); - - // simple entity set; with qualifiedentityTypeName; with format - testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$format=atom") - .isKind(UriInfoKind.entityId) - .isEntityType(EntityTypeProvider.nameETBase) - .isIdText("ESTwoPrim") - .isFormatText("atom"); - - // simple entity set; with qualifiedentityTypeName; with select - testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$select=*") - .isKind(UriInfoKind.entityId) - .isEntityType(EntityTypeProvider.nameETBase) - .isIdText("ESTwoPrim") - .isSelectItemStar(0); - - // simple entity set; with qualifiedentityTypeName; with expand - testUri.run("$entity/com.sap.odata.test1.ETBase?$id=ESTwoPrim&$expand=*") - .isKind(UriInfoKind.entityId) - .isEntityType(EntityTypeProvider.nameETBase) - .isIdText("ESTwoPrim") - .isExpandText("*") - .goExpand().first().isSegmentStar(0); - - } - - @Test - public void testEntitySet() throws UnsupportedEncodingException { - - // plain entity set - testRes.run("ESAllPrim") - .isEntitySet("ESAllPrim") - .isType(EntityTypeProvider.nameETAllPrim); - - // with one key; simple key notation - testRes.run("ESAllPrim(1)") - .isEntitySet("ESAllPrim") - .isType(EntityTypeProvider.nameETAllPrim) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // with one key; name value key notation - testRes.run("ESAllPrim(PropertyInt16=1)") - .isEntitySet("ESAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1"); - - // with two keys - testRes.run("ESTwoKeyTwoPrim(PropertyInt16=1, PropertyString='ABC')") - .isEntitySet("ESTwoKeyTwoPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'ABC'"); - - // with all keys - testRes.run("ESAllKey(" + encode(allKeys) + ")") - .isEntitySet("ESAllKey") - .isKeyPredicate(0, "PropertyString", "'ABC'") - .isKeyPredicate(1, "PropertyInt16", "1") - .isKeyPredicate(2, "PropertyBoolean", "true") - .isKeyPredicate(3, "PropertyByte", "1") - .isKeyPredicate(4, "PropertySByte", "1") - .isKeyPredicate(5, "PropertyInt32", "12") - .isKeyPredicate(6, "PropertyInt64", "64") - .isKeyPredicate(7, "PropertyDecimal", "12") - .isKeyPredicate(8, "PropertyDate", "2013-09-25") - .isKeyPredicate(9, "PropertyDateTimeOffset", "2002-10-10T12:00:00-05:00") - .isKeyPredicate(10, "PropertyDuration", "duration'P10DT5H34M21.123456789012S'") - .isKeyPredicate(11, "PropertyGuid", "12345678-1234-1234-1234-123456789012") - .isKeyPredicate(12, "PropertyTimeOfDay", "12:34:55.123456789012"); - } - - @Test - public void testEntitySet_NavigationPropperty() { - - // plain entity set ... - - // with navigation property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne") - .at(0) - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // with navigation property -> property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/PropertyString") - .at(0) - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .at(2) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property -> navigation property -> navigation property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne") - .at(0) - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .isType(EntityTypeProvider.nameETTwoKeyNav) - .at(2) - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav); - - // with navigation property(key) - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)") - .at(0) - .isEntitySet("ESKeyNav") - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // with navigation property(key) -> property - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/PropertyString").at(0) - .at(0) - .isEntitySet("ESKeyNav") - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(2) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property(key) -> navigation property - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavOne") - .isEntitySet("ESKeyNav") - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(2) - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - // with navigation property(key) -> navigation property(key) - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavMany(1)") - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav) - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(2) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // with navigation property(key) -> navigation property -> property - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavOne/PropertyString") - .at(0) - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav) - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(2) - .isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .isType(EntityTypeProvider.nameETKeyNav) - .at(3) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property(key) -> navigation property(key) -> property - testRes.run("ESKeyNav(1)/NavPropertyETKeyNavMany(1)/NavPropertyETKeyNavMany(1)/PropertyString") - .at(0) - .isEntitySet("ESKeyNav") - .isType(EntityTypeProvider.nameETKeyNav) - .at(1) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(2) - .isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(3) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - } - - @Test - public void testEntitySet_Property() { - - // plain entity set ... - - // with property - testRes.run("ESAllPrim(1)/PropertyString") - .at(0) - .isEntitySet("ESAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with complex property - testRes.run("ESCompAllPrim(1)/PropertyComplex") - .at(0) - .isEntitySet("ESCompAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false); - - // with two properties - testRes.run("ESCompAllPrim(1)/PropertyComplex/PropertyString") - .at(0) - .isEntitySet("ESCompAllPrim") - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false) - .at(2) - .isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - } - - @Test - public void testEntitySet_TypeFilter() { - - // filter - testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase") - .at(0) - .isEntitySet("ESTwoPrim") - .isType(EntityTypeProvider.nameETTwoPrim, true) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase) - .isTypeFilterOnEntry(null); - - // filter before key predicate - testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)") - .at(0) - .isEntitySet("ESTwoPrim") - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoPrim) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase) - .isTypeFilterOnEntry(null) - .at(0) - .isType(EntityTypeProvider.nameETTwoPrim, false) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // filter before key predicate; property of sub type - testRes.run("ESTwoPrim/com.sap.odata.test1.ETBase(PropertyInt16=1)/AdditionalPropertyString_5") - .at(0) - .isEntitySet("ESTwoPrim") - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoPrim) - .isTypeFilterOnCollection(EntityTypeProvider.nameETBase) - .isTypeFilterOnEntry(null) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isType(PropertyProvider.nameString) - .isPrimitiveProperty("AdditionalPropertyString_5", PropertyProvider.nameString, false); - - // filter after key predicate - testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase") - .at(0) - .isEntitySet("ESTwoPrim") - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoPrim, false) - .isTypeFilterOnCollection(null) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBase) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // filter after key predicate; property of sub type - testRes.run("ESTwoPrim(PropertyInt16=1)/com.sap.odata.test1.ETBase/AdditionalPropertyString_5") - .at(0) - .isEntitySet("ESTwoPrim") - .isUriPathInfoKind(UriResourceKind.entitySet) - .isType(EntityTypeProvider.nameETTwoPrim) - .isTypeFilterOnCollection(null) - .isTypeFilterOnEntry(EntityTypeProvider.nameETBase) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(1) - .isPrimitiveProperty("AdditionalPropertyString_5", PropertyProvider.nameString, false) - .isType(PropertyProvider.nameString); - - } - - @Test - public void testFilterComplexMixedPriority() throws UriParserException { - testFilter.runESabc("a or c and e ").isCompr("< or < and >>"); - testFilter.runESabc("a or c and e eq f").isCompr("< or < and < eq >>>"); - testFilter.runESabc("a or c eq d and e ").isCompr("< or << eq > and >>"); - testFilter.runESabc("a or c eq d and e eq f").isCompr("< or << eq > and < eq >>>"); - testFilter.runESabc("a eq b or c and e ").isCompr("<< eq > or < and >>"); - testFilter.runESabc("a eq b or c and e eq f").isCompr("<< eq > or < and < eq >>>"); - testFilter.runESabc("a eq b or c eq d and e ").isCompr("<< eq > or << eq > and >>"); - testFilter.runESabc("a eq b or c eq d and e eq f").isCompr("<< eq > or << eq > and < eq >>>"); - } - - @Test - public void testFilterSimpleSameBinaryBinaryBinaryPriority() throws UriParserException { - - testFilter.runESabc("1 add 2 add 3 add 4").isCompr("<<< <1> add <2>> add <3>> add <4>>"); - testFilter.runESabc("1 add 2 add 3 div 4").isCompr("<< <1> add <2>> add <<3> div <4>>>"); - testFilter.runESabc("1 add 2 div 3 add 4").isCompr("<< <1> add <<2> div <3>>> add <4>>"); - testFilter.runESabc("1 add 2 div 3 div 4").isCompr("< <1> add <<<2> div <3>> div <4>>>"); - testFilter.runESabc("1 div 2 add 3 add 4").isCompr("<<< <1> div <2>> add <3>> add <4>>"); - testFilter.runESabc("1 div 2 add 3 div 4").isCompr("<< <1> div <2>> add <<3> div <4>>>"); - testFilter.runESabc("1 div 2 div 3 add 4").isCompr("<<< <1> div <2>> div <3>> add <4>>"); - testFilter.runESabc("1 div 2 div 3 div 4").isCompr("<<< <1> div <2>> div <3>> div <4>>"); - - } - - @Test - public void testFunctionImport_VarParameters() { - - // no input - testRes.run("FINRTInt16()") - .isFunctionImport("FINRTInt16") - .isFunction("UFNRTInt16") - .isType(PropertyProvider.nameInt16); - - // one input - testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)") - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav); - - // two input - testRes.run("FICRTStringTwoParam(ParameterString='ABC',ParameterInt16=1)") - .isFunctionImport("FICRTStringTwoParam") - .isFunction("UFCRTStringTwoParam") - .isType(PropertyProvider.nameString); - } - - @Test - public void testFunctionImport_VarRetruning() { - // returning primitive - testRes.run("FINRTInt16()") - .isFunctionImport("FINRTInt16") - .isFunction("UFNRTInt16") - .isType(PropertyProvider.nameInt16, false); - - // returning collection of primitive - testRes.run("FICRTCollStringTwoParam(ParameterString='ABC',ParameterInt16=1)") - .isFunctionImport("FICRTCollStringTwoParam") - .isFunction("UFCRTCollStringTwoParam") - .isType(PropertyProvider.nameString, true); - - // returning single complex - testRes.run("FICRTCTAllPrimTwoParam(ParameterString='ABC',ParameterInt16=1)") - .isFunctionImport("FICRTCTAllPrimTwoParam") - .isFunction("UFCRTCTAllPrimTwoParam") - .isType(ComplexTypeProvider.nameCTAllPrim, false); - - // returning collection of complex - testRes.run("FICRTCollCTTwoPrim()") - .isFunctionImport("FICRTCollCTTwoPrim") - .isFunction("UFCRTCollCTTwoPrim") - .isType(ComplexTypeProvider.nameCTTwoPrim, true); - - // returning single entity - testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)") - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav, false); - - // returning collection of entity (aka entitySet) - testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)") - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav, true); - } - - @Test - public void testFunctionImportChain() { - - // test chain; returning single complex - testRes.run("FICRTCTAllPrimTwoParam(ParameterString='ABC',ParameterInt16=1)/PropertyInt16") - .at(0) - .isFunctionImport("FICRTCTAllPrimTwoParam") - .isFunction("UFCRTCTAllPrimTwoParam") - .isType(ComplexTypeProvider.nameCTAllPrim, false) - .isParameter(0, "ParameterString", "'ABC'") - .isParameter(1, "ParameterInt16", "1") - .at(1) - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - // test chains; returning single entity - testRes.run("FICRTETTwoKeyNavParam(ParameterInt16=1)/PropertyInt16") - .at(0) - .isFunctionImport("FICRTETTwoKeyNavParam") - .isFunction("UFCRTETTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isParameter(0, "ParameterInt16", "1") - .at(1) - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - // test chains; returning collection of entity (aka entitySet) - testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=1,PropertyString='ABC')") - .at(0) - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isParameter(0, "ParameterInt16", "1") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'ABC'"); - - // test chains; returning collection of entity (aka entitySet) - testRes.run("FICRTESTwoKeyNavParam(ParameterInt16=1)(PropertyInt16=1,PropertyString='ABC')/PropertyInt16") - .at(0) - .isFunctionImport("FICRTESTwoKeyNavParam") - .isFunction("UFCRTESTwoKeyNavParam") - .isType(EntityTypeProvider.nameETTwoKeyNav, false) - .isParameter(0, "ParameterInt16", "1") - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'ABC'") - .at(1) - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - } - - @Test - public void testMetaData() { - - // Parsing the fragment may be used if a uri has to be parsed on the consumer side. - // On the producer side this feature is currently not supported, so the context fragment - // part is only available as text. - - testUri.run("$metadata") - .isKind(UriInfoKind.metadata); - - testUri.run("$metadata?$format=atom") - .isKind(UriInfoKind.metadata) - .isFormatText("atom"); - - // with context (client usage) - - testUri.run("$metadata#$ref") - .isKind(UriInfoKind.metadata) - .isFragmentText("$ref"); - - testUri.run("$metadata?$format=atom#$ref") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("$ref"); - - testUri.run("$metadata?$format=atom#Collection($ref)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("Collection($ref)"); - - testUri.run("$metadata?$format=atom#Collection(Edm.EntityType)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("Collection(Edm.EntityType)"); - - testUri.run("$metadata?$format=atom#Collection(Edm.ComplexType)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("Collection(Edm.ComplexType)"); - - testUri.run("$metadata?$format=atom#SINav") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav"); - - testUri.run("$metadata?$format=atom#SINav/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/PropertyInt16"); - - testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/NavPropertyETKeyNavOne"); - - testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/NavPropertyETKeyNavMany(1)"); - - testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavOne/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/NavPropertyETKeyNavOne/PropertyInt16"); - - testUri.run("$metadata?$format=atom#SINav/NavPropertyETKeyNavMany(1)/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/NavPropertyETKeyNavMany(1)/PropertyInt16"); - - testUri.run("$metadata?$format=atom#SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16"); - - testUri.run("$metadata?$format=atom#SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("SINav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16"); - - testUri.run("$metadata?$format=atom#com.sap.odata.test1.ETAllKey") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("com.sap.odata.test1.ETAllKey"); - - testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedEntity") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESTwoPrim/$deletedEntity"); - - testUri.run("$metadata?$format=atom#ESTwoPrim/$link") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESTwoPrim/$link"); - - testUri.run("$metadata?$format=atom#ESTwoPrim/$deletedLink") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESTwoPrim/$deletedLink"); - - testUri.run("$metadata?$format=atom#ESKeyNav") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav"); - - testUri.run("$metadata?$format=atom#ESKeyNav/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/PropertyInt16"); - - testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne"); - - testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)"); - - testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/NavPropertyETKeyNavOne/PropertyInt16"); - - testUri.run("$metadata?$format=atom#ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/NavPropertyETKeyNavMany(1)/PropertyInt16"); - - testUri.run("$metadata?$format=atom#ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavOne/PropertyInt16"); - - testUri.run( - "$metadata?$format=atom#ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/com.sap.odata.test1.ETTwoPrim/NavPropertyETKeyNavMany(1)/PropertyInt16"); - - testUri.run("$metadata?$format=atom#ESKeyNav(PropertyInt16,PropertyString)") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav(PropertyInt16,PropertyString)"); - - testUri.run("$metadata?$format=atom#ESKeyNav/$entity") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/$entity"); - - testUri.run("$metadata?$format=atom#ESKeyNav/$delta") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/$delta"); - - testUri.run("$metadata?$format=atom#ESKeyNav/(PropertyInt16,PropertyString)/$delta") - .isKind(UriInfoKind.metadata) - .isFormatText("atom") - .isFragmentText("ESKeyNav/(PropertyInt16,PropertyString)/$delta"); - - } - - @Test - public void testRef() { - testUri.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/$ref"); - } - - @Test - public void testSingleton() { - // plain singleton - testRes.run("SINav") - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav); - } - - @Test - public void testNavigationProperty() { - - // plain entity set ... - - // with navigation property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false); - - // with navigation property -> property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/PropertyString") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .at(2).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property -> navigation property -> navigation property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavOne/NavPropertyETKeyNavOne") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavOne", EntityTypeProvider.nameETTwoKeyNav, false) - .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - // with navigation property(key) - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'"); - - // with navigation property(key) -> property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')/PropertyString") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'") - .at(2).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property(key) -> navigation property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')/NavPropertyETKeyNavOne") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'") - .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false); - - // with navigation property(key) -> navigation property(key) - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')" - + "/NavPropertyETKeyNavMany(1)") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'") - .at(2).isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1"); - - // with navigation property(key) -> navigation property -> property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')" - + "/NavPropertyETKeyNavOne/PropertyString") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'") - .at(2).isNavProperty("NavPropertyETKeyNavOne", EntityTypeProvider.nameETKeyNav, false) - .at(3).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - // with navigation property(key) -> navigation property(key) -> property - testRes.run("ESKeyNav(1)/NavPropertyETTwoKeyNavMany(PropertyInt16=1,PropertyString='1')" - + "/NavPropertyETKeyNavMany(1)/PropertyString") - .at(0).isEntitySet("ESKeyNav") - .at(1).isNavProperty("NavPropertyETTwoKeyNavMany", EntityTypeProvider.nameETTwoKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .isKeyPredicate(1, "PropertyString", "'1'") - .at(2).isNavProperty("NavPropertyETKeyNavMany", EntityTypeProvider.nameETKeyNav, false) - .isKeyPredicate(0, "PropertyInt16", "1") - .at(3).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - } - - @Test - public void testSingleton_Property() { - - // plain singleton ... - - // with property - testRes.run("SINav/PropertyInt16") - .at(0) - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .at(1) - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - // with complex property - testRes.run("SINav/PropertyComplex") - .at(0) - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .at(1) - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false); - - // with two properties - testRes.run("SINav/PropertyComplex/PropertyInt16") - .at(0) - .isSingleton("SINav") - .isType(EntityTypeProvider.nameETTwoKeyNav) - .at(1) - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .at(2) - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - } - - @Test - public void testValue() { - testUri.run("ESAllPrim(1)/PropertyString/$value"); - } - - @Test(expected = Exception.class) - public void testMemberStartingWithCastFailOnValidation1() { - // on EntityType entry - testUri.run("ESTwoKeyNav(ParameterInt16=1,PropertyString='ABC')?" - + "$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate") - .goFilter().root().isMember() - .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath() - // .at(0) - // .isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(EntityTypeProvider.nameETTwoKeyNav, false) - // .isTypeFilterOnEntry(EntityTypeProvider.nameETBaseTwoKeyNav) - .at(0).isType(PropertyProvider.nameDate); - } - - @Test(expected = Exception.class) - public void testMemberStartingWithCastFailOnValidation2() { - testUri.run("FICRTCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?" - + "$filter=com.sap.odata.test1.CTBase/AdditionalPropString") - .goFilter().root().isMember() - .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath() - // .at(0) - // .isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(ComplexTypeProvider.nameCTTwoPrim, false) - // .isTypeFilterOnEntry(ComplexTypeProvider.nameCTBase) - .at(0).isType(PropertyProvider.nameString); - } - - @Test - public void testMemberStartingWithCast() { - - // on EntityType collection - testUri.run("ESTwoKeyNav?$filter=com.sap.odata.test1.ETBaseTwoKeyNav/PropertyDate") - .goFilter().root().isMember() - .isMemberStartType(EntityTypeProvider.nameETBaseTwoKeyNav).goPath() - // .at(0) - // .isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(EntityTypeProvider.nameETTwoKeyNav, true) - // .isTypeFilterOnCollection(EntityTypeProvider.nameETBaseTwoKeyNav) - .at(0).isType(PropertyProvider.nameDate); - - // on Complex collection - testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')?" - + "$filter=com.sap.odata.test1.CTBase/AdditionalPropString") - .goFilter().root().isMember() - .isMemberStartType(ComplexTypeProvider.nameCTBase).goPath() - // .at(0) - // .isUriPathInfoKind(UriResourceKind.startingTypeFilter) - // .isType(ComplexTypeProvider.nameCTTwoPrim, true) - // .isTypeFilterOnCollection(ComplexTypeProvider.nameCTBase) - .at(0).isType(PropertyProvider.nameString); - - } - - @Test - public void testComplexTypeCastFollowingAsCollection() { - testUri.run("FICRTCollCTTwoPrimParam(ParameterInt16=1,ParameterString='2')/com.sap.odata.test1.CTBase"); - } - - @Test - public void testLambda() { - testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/all( l : true )") - .goFilter().is(">>"); - - testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/any( l : true )") - .goFilter().is(">>"); - testUri.run("ESTwoKeyNav?$filter=CollPropertyComplex/any( )") - .goFilter().is(">"); - - testUri.run("ESTwoKeyNav?$filter=all( l : true )") - .goFilter().is("<>>"); - testUri.run("ESTwoKeyNav?$filter=any( l : true )") - .goFilter().is("<>>"); - testUri.run("ESTwoKeyNav?$filter=any( )") - .goFilter().is("<>"); - } - - @Test - public void testCustomQueryOption() { - testUri.run("ESTwoKeyNav?custom") - .isCustomParameter(0, "custom", ""); - testUri.run("ESTwoKeyNav?custom=ABC") - .isCustomParameter(0, "custom", "ABC"); - } - - @Test - public void testGeo() throws UriParserException { - // TODO sync - testFilter.runOnETAllPrim("geo.distance(PropertySByte,PropertySByte)") - .is(",)>") - .isMethod(MethodKind.GEODISTANCE, 2); - testFilter.runOnETAllPrim("geo.length(PropertySByte)") - .is(")>") - .isMethod(MethodKind.GEOLENGTH, 1); - testFilter.runOnETAllPrim("geo.intersects(PropertySByte,PropertySByte)") - .is(",)>") - .isMethod(MethodKind.GEOINTERSECTS, 2); - } - - @Test - public void testSelect() { - testUri.run("ESTwoKeyNav?$select=*") - .isSelectItemStar(0); - - testUri.run("ESTwoKeyNav?$select=com.sap.odata.test1.*") - .isSelectItemAllOp(0, new FullQualifiedName("com.sap.odata.test1", "*")); - - testUri.run("ESTwoKeyNav?$select=PropertyString") - .goSelectItemPath(0).isPrimitiveProperty("PropertyString", PropertyProvider.nameString, false); - - testUri.run("ESTwoKeyNav?$select=PropertyComplex") - .goSelectItemPath(0).isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false); - - testUri.run("ESTwoKeyNav?$select=PropertyComplex/PropertyInt16") - .goSelectItemPath(0) - .first() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isPrimitiveProperty("PropertyInt16", PropertyProvider.nameInt16, false); - - testUri.run("ESTwoKeyNav?$select=PropertyComplex/PropertyComplex") - .goSelectItemPath(0) - .first() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTPrimComp, false) - .n() - .isComplexProperty("PropertyComplex", ComplexTypeProvider.nameCTAllPrim, false); - - testUri.run("ESTwoKeyNav?$select=com.sap.odata.test1.ETBaseTwoKeyNav") - .isSelectStartType(0, EntityTypeProvider.nameETBaseTwoKeyNav); - - testUri.run("ESTwoKeyNav/PropertyComplexNav?$select=com.sap.odata.test1.CTTwoBasePrimCompNav") - .isSelectStartType(0, ComplexTypeProvider.nameCTTwoBasePrimCompNav); - - testUri.run("ESTwoKeyNav?$select=PropertyComplexNav/com.sap.odata.test1.CTTwoBasePrimCompNav") - .goSelectItemPath(0) - .first() - .isComplexProperty("PropertyComplexNav", ComplexTypeProvider.nameCTBasePrimCompNav, false) - .n() - .isTypeFilterOnCollection(ComplexTypeProvider.nameCTTwoBasePrimCompNav); - ; - - } - - public static String encode(final String decoded) throws UnsupportedEncodingException { - - return URLEncoder.encode(decoded, "UTF-8"); - - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java deleted file mode 100644 index 7dcf5a5f1..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/QueryOptionTest.java +++ /dev/null @@ -1,303 +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.server.core.uri.queryoption; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfoResource; -import org.apache.olingo.server.api.uri.queryoption.SystemQueryOptionKind; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.AliasImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.junit.Test; - -//TOOD add getKind check to all -public class QueryOptionTest { - - Edm edm = new EdmProviderImpl(new EdmTechTestProvider()); - - @Test - public void testAliasQueryOption() { - AliasQueryOptionImpl option = new AliasQueryOptionImpl(); - - ExpressionImpl expression = new LiteralImpl(); - - option.setAliasValue(expression); - assertEquals(expression, option.getValue()); - } - - @Test - public void testExandItemImpl() { - ExpandItemImpl option = new ExpandItemImpl(); - - // input options - ExpandOptionImpl expand = new ExpandOptionImpl(); - FilterOptionImpl filter = new FilterOptionImpl(); - CountOptionImpl inlinecount = new CountOptionImpl(); - OrderByOptionImpl orderby = new OrderByOptionImpl(); - SearchOptionImpl search = new SearchOptionImpl(); - SelectOptionImpl select = new SelectOptionImpl(); - SkipOptionImpl skip = new SkipOptionImpl(); - TopOptionImpl top = new TopOptionImpl(); - LevelsOptionImpl levels = new LevelsOptionImpl(); - - option.setSystemQueryOption(expand); - option.setSystemQueryOption(filter); - option.setSystemQueryOption(inlinecount); - option.setSystemQueryOption(orderby); - option.setSystemQueryOption(search); - option.setSystemQueryOption(select); - option.setSystemQueryOption(skip); - option.setSystemQueryOption(top); - option.setSystemQueryOption(levels); - - assertEquals(expand, option.getExpandOption()); - assertEquals(filter, option.getFilterOption()); - assertEquals(inlinecount, option.getCountOption()); - assertEquals(orderby, option.getOrderByOption()); - assertEquals(search, option.getSearchOption()); - assertEquals(select, option.getSelectOption()); - assertEquals(skip, option.getSkipOption()); - assertEquals(top, option.getTopOption()); - assertEquals(levels, option.getLevelsOption()); - - // just for completeness - option = new ExpandItemImpl(); - option.setSystemQueryOption(new IdOptionImpl()); - - option = new ExpandItemImpl(); - List list = new ArrayList(); - list.add(expand); - list.add(filter); - option.setSystemQueryOptions(list); - assertEquals(expand, option.getExpandOption()); - assertEquals(filter, option.getFilterOption()); - - option = new ExpandItemImpl(); - assertEquals(false, option.isRef()); - option.setIsRef(true); - assertEquals(true, option.isRef()); - - option = new ExpandItemImpl(); - assertEquals(false, option.isStar()); - option.setIsStar(true); - assertEquals(true, option.isStar()); - - option = new ExpandItemImpl(); - UriInfoResource resource = new UriInfoImpl().asUriInfoResource(); - option.setResourcePath(resource); - assertEquals(resource, option.getResourcePath()); - - } - - @Test - public void testExpandOptionImpl() { - ExpandOptionImpl option = new ExpandOptionImpl(); - assertEquals(SystemQueryOptionKind.EXPAND, option.getKind()); - - ExpandItemImpl item1 = new ExpandItemImpl(); - ExpandItemImpl item2 = new ExpandItemImpl(); - option.addExpandItem(item1); - option.addExpandItem(item2); - assertEquals(item1, option.getExpandItems().get(0)); - assertEquals(item2, option.getExpandItems().get(1)); - } - - @Test - public void testFilterOptionImpl() { - FilterOptionImpl option = new FilterOptionImpl(); - assertEquals(SystemQueryOptionKind.FILTER, option.getKind()); - - AliasImpl expression = new AliasImpl(); - - option.setExpression(expression); - assertEquals(expression, option.getExpression()); - } - - @Test - public void testFormatOptionImpl() { - FormatOptionImpl option = new FormatOptionImpl(); - assertEquals(SystemQueryOptionKind.FORMAT, option.getKind()); - - option.setFormat("A"); - - assertEquals("A", option.getFormat()); - } - - @Test - public void testIdOptionImpl() { - IdOptionImpl option = new IdOptionImpl(); - assertEquals(SystemQueryOptionKind.ID, option.getKind()); - - option.setValue("A"); - - assertEquals("A", option.getValue()); - } - - @Test - public void testInlineCountImpl() { - CountOptionImpl option = new CountOptionImpl(); - assertEquals(SystemQueryOptionKind.COUNT, option.getKind()); - - assertEquals(false, option.getValue()); - option.setValue(true); - assertEquals(true, option.getValue()); - } - - @Test - public void testLevelsExpandOptionImpl() { - LevelsOptionImpl option = new LevelsOptionImpl(); - assertEquals(SystemQueryOptionKind.LEVELS, option.getKind()); - - assertEquals(0, option.getValue()); - option.setValue(1); - assertEquals(1, option.getValue()); - - option = new LevelsOptionImpl(); - option.setMax(); - assertEquals(true, option.isMax()); - } - - @Test - public void testOrderByItemImpl() { - OrderByItemImpl option = new OrderByItemImpl(); - - AliasImpl expression = new AliasImpl(); - option.setExpression(expression); - assertEquals(expression, option.getExpression()); - - assertEquals(false, option.isDescending()); - option.setDescending(true); - assertEquals(true, option.isDescending()); - } - - @Test - public void testOrderByOptionImpl() { - OrderByOptionImpl option = new OrderByOptionImpl(); - - OrderByItemImpl order0 = new OrderByItemImpl(); - OrderByItemImpl order1 = new OrderByItemImpl(); - option.addOrder(order0); - option.addOrder(order1); - - assertEquals(order0, option.getOrders().get(0)); - assertEquals(order1, option.getOrders().get(1)); - } - - @Test - public void testQueryOptionImpl() { - QueryOptionImpl option = new AliasQueryOptionImpl(); - - option.setName("A"); - option.setText("B"); - assertEquals("A", option.getName()); - assertEquals("B", option.getText()); - } - - @Test - public void testSearchOptionImpl() { - SearchOptionImpl option = new SearchOptionImpl(); - assertEquals(SystemQueryOptionKind.SEARCH, option.getKind()); - // TODO $search is not supported yet - } - - @Test - public void testSelectItemImpl() { - SelectItemImpl option = new SelectItemImpl(); - - // no typed collection else case ( e.g. if not path is added) - option = new SelectItemImpl(); - - option = new SelectItemImpl(); - assertEquals(false, option.isStar()); - option.setStar(true); - assertEquals(true, option.isStar()); - - option = new SelectItemImpl(); - assertEquals(false, option.isAllOperationsInSchema()); - FullQualifiedName fqName = new FullQualifiedName("Namespace", "Name"); - option.addAllOperationsInSchema(fqName); - assertEquals(true, option.isAllOperationsInSchema()); - assertEquals(fqName, option.getAllOperationsInSchemaNameSpace()); - - } - - @Test - public void testSelectOptionImpl() { - SelectOptionImpl option = new SelectOptionImpl(); - assertEquals(SystemQueryOptionKind.SELECT, option.getKind()); - - SelectItemImpl item0 = new SelectItemImpl(); - SelectItemImpl item1 = new SelectItemImpl(); - - ArrayList list = new ArrayList(); - list.add(item0); - list.add(item1); - option.setSelectItems(list); - - assertEquals(item0, option.getSelectItems().get(0)); - assertEquals(item1, option.getSelectItems().get(1)); - - } - - @Test - public void testSkipOptionImpl() { - SkipOptionImpl option = new SkipOptionImpl(); - assertEquals(SystemQueryOptionKind.SKIP, option.getKind()); - - option.setValue(10); - assertEquals(10, option.getValue()); - } - - @Test - public void testSkipTokenOptionImpl() { - SkipTokenOptionImpl option = new SkipTokenOptionImpl(); - assertEquals(SystemQueryOptionKind.SKIPTOKEN, option.getKind()); - - option.setValue("A"); - assertEquals("A", option.getValue()); - } - - @Test - public void testSystemQueryOptionImpl() { - SystemQueryOptionImpl option = new SystemQueryOptionImpl(); - - option.setKind(SystemQueryOptionKind.EXPAND); - assertEquals(SystemQueryOptionKind.EXPAND, option.getKind()); - - assertEquals("$expand", option.getName()); - } - - @Test - public void testTopOptionImpl() { - TopOptionImpl option = new TopOptionImpl(); - assertEquals(SystemQueryOptionKind.TOP, option.getKind()); - - option.setValue(11); - assertEquals(11, option.getValue()); - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java deleted file mode 100644 index de63b4694..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/queryoption/expression/ExpressionTest.java +++ /dev/null @@ -1,239 +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.server.core.uri.queryoption.expression; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.util.Arrays; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmAction; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmFunction; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriInfoResource; -import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; -import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.UriResourceActionImpl; -import org.apache.olingo.server.core.uri.UriResourceFunctionImpl; -import org.apache.olingo.server.core.uri.testutil.EdmTechTestProvider; -import org.apache.olingo.server.core.uri.testutil.FilterTreeToText; -import org.apache.olingo.server.tecsvc.provider.ActionProvider; -import org.apache.olingo.server.tecsvc.provider.EntityTypeProvider; -import org.apache.olingo.server.tecsvc.provider.EnumTypeProvider; -import org.apache.olingo.server.tecsvc.provider.FunctionProvider; -import org.junit.Test; - -public class ExpressionTest { - Edm edm = new EdmProviderImpl(new EdmTechTestProvider()); - - @Test - public void testSupportedOperators() { - assertEquals(UnaryOperatorKind.MINUS, UnaryOperatorKind.get("-")); - assertEquals(null, UnaryOperatorKind.get("XXX")); - - assertEquals(BinaryOperatorKind.MOD, BinaryOperatorKind.get("mod")); - assertEquals(null, BinaryOperatorKind.get("XXX")); - - assertEquals(MethodKind.CONCAT, MethodKind.get("concat")); - assertEquals(null, MethodKind.get("XXX")); - } - - @Test - public void testAliasExpression() throws ExpressionVisitException, ODataApplicationException { - AliasImpl expression = new AliasImpl(); - - expression.setParameter("Test"); - - assertEquals("Test", expression.getParameterName()); - - String output = expression.accept(new FilterTreeToText()); - assertEquals("", output); - - } - - @Test - public void testBinaryExpression() throws ExpressionVisitException, ODataApplicationException { - BinaryImpl expression = new BinaryImpl(); - - ExpressionImpl expressionLeft = new LiteralImpl().setText("A"); - ExpressionImpl expressionRight = new LiteralImpl().setText("B"); - - expression.setLeftOperand(expressionLeft); - expression.setRightOperand(expressionRight); - expression.setOperator(BinaryOperatorKind.SUB); - - assertEquals(expressionLeft, expression.getLeftOperand()); - assertEquals(expressionRight, expression.getRightOperand()); - assertEquals(BinaryOperatorKind.SUB, expression.getOperator()); - - String output = expression.accept(new FilterTreeToText()); - assertEquals("< sub >", output); - } - - @Test - public void testEnumerationExpression() throws ExpressionVisitException, ODataApplicationException { - EnumerationImpl expression = new EnumerationImpl(); - EdmEnumType type = (EdmEnumType) edm.getEnumType(EnumTypeProvider.nameENString); - assertNotNull(type); - expression.setType(type); - - assertEquals(type, expression.getType()); - - expression.addValue("A"); - expression.addValue("B"); - assertEquals("A", expression.getValues().get(0)); - assertEquals("B", expression.getValues().get(1)); - assertEquals(">", expression.accept(new FilterTreeToText())); - } - - @Test - public void testLambdaRefExpression() throws ExpressionVisitException, ODataApplicationException { - LambdaRefImpl expression = new LambdaRefImpl(); - expression.setVariableText("A"); - assertEquals("A", expression.getVariableName()); - - assertEquals("", expression.accept(new FilterTreeToText())); - - } - - @Test - public void testLiteralExpresion() throws ExpressionVisitException, ODataApplicationException { - LiteralImpl expression = new LiteralImpl(); - expression.setText("A"); - assertEquals("A", expression.getText()); - - assertEquals("", expression.accept(new FilterTreeToText())); - } - - @Test - public void testMemberExpression() throws ExpressionVisitException, ODataApplicationException { - MemberImpl expression = new MemberImpl(); - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); - - // UriResourceImplTyped - EdmAction action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam); - UriInfoResource uriInfo = new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceActionImpl().setAction(action)).asUriInfoResource(); - expression.setResourcePath(uriInfo); - assertEquals(action.getReturnType().getType(), expression.getType()); - - // check accept and path - assertEquals(uriInfo, expression.getResourcePath()); - assertEquals("", expression.accept(new FilterTreeToText())); - - // UriResourceImplTyped check collection = false case - assertEquals(false, expression.isCollection()); - - // UriResourceImplTyped check collection = true case - action = edm.getUnboundAction(ActionProvider.nameUARTPrimCollParam); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceActionImpl().setAction(action)) - .asUriInfoResource()); - assertEquals(true, expression.isCollection()); - - // UriResourceImplTyped with filter - action = edm.getUnboundAction(ActionProvider.nameUARTPrimParam); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceActionImpl().setAction(action).setTypeFilter(entityType)) - .asUriInfoResource()); - assertEquals(entityType, expression.getType()); - - // UriResourceImplKeyPred - EdmFunction function = edm.getUnboundFunction(FunctionProvider.nameUFCRTETKeyNav, null); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceFunctionImpl().setFunction(function)) - .asUriInfoResource()); - assertEquals(function.getReturnType().getType(), expression.getType()); - - // UriResourceImplKeyPred typeFilter on entry - EdmEntityType entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceFunctionImpl().setFunction(function).setEntryTypeFilter(entityBaseType)) - .asUriInfoResource()); - assertEquals(entityBaseType, expression.getType()); - - // UriResourceImplKeyPred typeFilter on entry - entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.resource).addResourcePart( - new UriResourceFunctionImpl().setFunction(function).setCollectionTypeFilter(entityBaseType)) - .asUriInfoResource()); - assertEquals(entityBaseType, expression.getType()); - - // no typed - entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - function = edm.getUnboundFunction(FunctionProvider.nameUFCRTESTwoKeyNavParam, Arrays.asList("ParameterInt16")); - expression.setResourcePath(new UriInfoImpl().setKind(UriInfoKind.all)); - assertEquals(null, expression.getType()); - - // no typed collection else case - assertEquals(false, expression.isCollection()); - } - - @Test - public void testMethodCallExpression() throws ExpressionVisitException, ODataApplicationException { - MethodImpl expression = new MethodImpl(); - expression.setMethod(MethodKind.CONCAT); - - ExpressionImpl p0 = new LiteralImpl().setText("A"); - ExpressionImpl p1 = new LiteralImpl().setText("B"); - expression.addParameter(p0); - expression.addParameter(p1); - - assertEquals(MethodKind.CONCAT, expression.getMethod()); - assertEquals(",)>", expression.accept(new FilterTreeToText())); - - assertEquals(p0, expression.getParameters().get(0)); - assertEquals(p1, expression.getParameters().get(1)); - } - - @Test - public void testTypeLiteralExpression() throws ExpressionVisitException, ODataApplicationException { - TypeLiteralImpl expression = new TypeLiteralImpl(); - EdmEntityType entityBaseType = edm.getEntityType(EntityTypeProvider.nameETBaseTwoKeyNav); - expression.setType(entityBaseType); - - assertEquals(entityBaseType, expression.getType()); - assertEquals("", expression.accept(new FilterTreeToText())); - } - - @Test - public void testUnaryExpression() throws ExpressionVisitException, ODataApplicationException { - UnaryImpl expression = new UnaryImpl(); - expression.setOperator(UnaryOperatorKind.MINUS); - - ExpressionImpl operand = new LiteralImpl().setText("A"); - expression.setOperand(operand); - - assertEquals(UnaryOperatorKind.MINUS, expression.getOperator()); - assertEquals(operand, expression.getOperand()); - - assertEquals("<- >", expression.accept(new FilterTreeToText())); - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java deleted file mode 100644 index 8f0d507d7..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/EdmTechTestProvider.java +++ /dev/null @@ -1,100 +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.server.core.uri.testutil; - -import java.util.Arrays; -import java.util.List; - -import org.apache.olingo.commons.api.ODataException; -import org.apache.olingo.commons.api.edm.EdmPrimitiveTypeKind; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.edm.provider.ComplexType; -import org.apache.olingo.server.api.edm.provider.EntitySet; -import org.apache.olingo.server.api.edm.provider.EntityType; -import org.apache.olingo.server.api.edm.provider.Property; -import org.apache.olingo.server.api.edm.provider.PropertyRef; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; - -/** - * Implement the EdmTechProvider and - *
  • adds a entity type ETabc with properties a,b,c,d,e,f
  • - *
  • adds a complex type CTabc with properties a,b,c,d,e,f
  • - *
  • adds a abc entity set of type ETabc
  • - */ -public class EdmTechTestProvider extends EdmTechProvider { - - private static final FullQualifiedName nameInt16 = EdmPrimitiveTypeKind.Int16.getFullQualifiedName(); - public static final String nameSpace = "com.sap.odata.test1"; - public static final FullQualifiedName nameContainer = new FullQualifiedName(nameSpace, "Container"); - - Property propertyAInt16 = new Property().setName("a").setType(nameInt16); - Property propertyBInt16 = new Property().setName("b").setType(nameInt16); - Property propertyCInt16 = new Property().setName("c").setType(nameInt16); - Property propertyDInt16 = new Property().setName("d").setType(nameInt16); - Property propertyEInt16 = new Property().setName("e").setType(nameInt16); - Property propertyFInt16 = new Property().setName("f").setType(nameInt16); - - public static final FullQualifiedName nameCTabc = new FullQualifiedName(nameSpace, "CTabc"); - public static final FullQualifiedName nameETabc = new FullQualifiedName(nameSpace, "ETabc"); - - @Override - public ComplexType getComplexType(final FullQualifiedName complexTypeName) throws ODataException { - if (complexTypeName.equals(nameCTabc)) { - return new ComplexType() - .setName("CTabc") - .setProperties(Arrays.asList( - propertyAInt16, propertyBInt16, propertyCInt16, - propertyDInt16, propertyEInt16, propertyFInt16 - )); - - } - - return super.getComplexType(complexTypeName); - } - - @Override - public EntitySet getEntitySet(final FullQualifiedName entityContainer, final String name) throws ODataException { - if (nameContainer.equals(entityContainer)) { - if (name.equals("ESabc")) { - return new EntitySet() - .setName("ESabc") - .setType(nameETabc); - } - } - - return super.getEntitySet(entityContainer, name); - } - - @Override - public EntityType getEntityType(final FullQualifiedName entityTypeName) throws ODataException { - List 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); - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java deleted file mode 100644 index fde13c851..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ExpandValidator.java +++ /dev/null @@ -1,230 +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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.queryoption.ExpandItem; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.QueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl; - -public class ExpandValidator implements TestValidator { - private Edm edm; - private TestValidator invokedByValidator; - - private int expandItemIndex; - private ExpandOptionImpl expandOption; - private ExpandItem expandItem; - - // --- Setup --- - - public ExpandValidator setUpValidator(final TestValidator validator) { - invokedByValidator = validator; - return this; - } - - public ExpandValidator setExpand(final ExpandOptionImpl expand) { - expandOption = expand; - first(); - return this; - } - - public ExpandValidator setEdm(final Edm edm) { - this.edm = edm; - return this; - } - - // --- Navigation --- - - public ExpandValidator goUpToExpandValidator() { - return (ExpandValidator) invokedByValidator; - } - - public ResourceValidator goUpToUriResourceValidator() { - return (ResourceValidator) invokedByValidator; - } - - public ResourceValidator goPath() { - UriInfoImpl uriInfo = (UriInfoImpl) expandItem.getResourcePath(); - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("goPath() can only be used on UriInfoKind.resource"); - } - - return new ResourceValidator() - .setUpValidator(this) - .setEdm(edm) - .setUriInfoImplPath(uriInfo); - - } - - public FilterValidator goOrder(final int index) { - OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption(); - - return new FilterValidator() - .setValidator(this) - .setEdm(edm) - .setExpression(orderBy.getOrders().get(index).getExpression()); - } - - public ResourceValidator goSelectItem(final int index) { - SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - UriInfoImpl uriInfo = (UriInfoImpl) item.getResourcePath(); - - return new ResourceValidator() - .setUpValidator(this) - .setEdm(edm) - .setUriInfoImplPath(uriInfo); - - } - - public ExpandValidator goExpand() { - ExpandValidator val = new ExpandValidator() - .setExpand((ExpandOptionImpl) expandItem.getExpandOption()) - .setUpValidator(this); - return val; - } - - public ExpandValidator first() { - expandItemIndex = 0; - expandItem = expandOption.getExpandItems().get(expandItemIndex); - return this; - } - - public ExpandValidator next() { - expandItemIndex++; - - try { - expandItem = expandOption.getExpandItems().get(expandItemIndex); - } catch (IndexOutOfBoundsException ex) { - fail("not enought segments"); - } - return this; - - } - - public ExpandValidator isSegmentStar(final int index) { - assertEquals(true, expandItem.isStar()); - return this; - } - - public ExpandValidator isSegmentRef(final int index) { - assertEquals(true, expandItem.isRef()); - return this; - } - - public ExpandValidator isLevelText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getLevelsOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isSkipText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getSkipOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isTopText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getTopOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isInlineCountText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getCountOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isSelectText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getSelectOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isSelectItemStar(final int index) { - SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(true, item.isStar()); - return this; - } - - public ExpandValidator isSelectItemAllOperations(final int index, final FullQualifiedName fqn) { - SelectOptionImpl select = (SelectOptionImpl) expandItem.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString()); - return this; - } - - public ExpandValidator isFilterOptionText(final String text) { - QueryOptionImpl option = (QueryOptionImpl) expandItem.getFilterOption(); - assertEquals(text, option.getText()); - return this; - } - - public ExpandValidator isFilterSerialized(final String serialized) { - FilterOptionImpl filter = (FilterOptionImpl) expandItem.getFilterOption(); - - try { - String tmp = FilterTreeToText.Serialize(filter); - assertEquals(serialized, tmp); - } catch (ExpressionVisitException e) { - fail("Exception occured while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } catch (ODataApplicationException e) { - fail("Exception occured while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } - - return this; - } - - public ExpandValidator isSortOrder(final int index, final boolean descending) { - OrderByOptionImpl orderBy = (OrderByOptionImpl) expandItem.getOrderByOption(); - assertEquals(descending, orderBy.getOrders().get(index).isDescending()); - return this; - } - - public ExpandValidator isExpandStartType(final FullQualifiedName fullName) { - EdmType actualType = expandItem.getStartTypeFilter(); - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(fullName, actualName); - return this; - - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java deleted file mode 100644 index 06056e015..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterTreeToText.java +++ /dev/null @@ -1,154 +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.server.core.uri.testutil; - -import java.util.List; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.EdmEnumType; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.server.api.uri.UriInfoResource; -import org.apache.olingo.server.api.uri.UriResource; -import org.apache.olingo.server.api.uri.UriResourceLambdaAll; -import org.apache.olingo.server.api.uri.UriResourceLambdaAny; -import org.apache.olingo.server.api.uri.UriResourcePartTyped; -import org.apache.olingo.server.api.uri.queryoption.FilterOption; -import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; -import org.apache.olingo.server.api.uri.queryoption.expression.Expression; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitor; -import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; -import org.apache.olingo.server.api.uri.queryoption.expression.UnaryOperatorKind; - -public class FilterTreeToText implements ExpressionVisitor { - - public static String Serialize(final FilterOption filter) - throws ExpressionVisitException, ODataApplicationException { - - Expression expression = filter.getExpression(); - return expression.accept(new FilterTreeToText()); - } - - public static String Serialize(final Expression expression) - throws ExpressionVisitException, ODataApplicationException { - - return expression.accept(new FilterTreeToText()); - } - - @Override - public String visitBinaryOperator(final BinaryOperatorKind operator, final String left, final String right) - throws ExpressionVisitException { - - return "<" + left + " " + operator.toString() + " " + right + ">"; - } - - @Override - public String visitUnaryOperator(final UnaryOperatorKind operator, final String operand) - throws ExpressionVisitException { - - return "<" + operator + " " + operand.toString() + ">"; - } - - @Override - public String visitMethodCall(final MethodKind methodCall, final List parameters) - throws ExpressionVisitException { - - String text = "<" + methodCall + "("; - int i = 0; - while (i < parameters.size()) { - if (i > 0) { - text += ","; - } - text += parameters.get(i); - i++; - } - return text + ")>"; - } - - @Override - public String visitLiteral(final String literal) throws ExpressionVisitException { - return "<" + literal + ">"; - } - - @Override - public String visitMember(final UriInfoResource resource) throws ExpressionVisitException, ODataApplicationException { - String ret = ""; - - UriInfoResource path = resource; - - for (UriResource item : path.getUriResourceParts()) { - String tmp = ""; - if (item instanceof UriResourceLambdaAll) { - UriResourceLambdaAll all = (UriResourceLambdaAll) item; - tmp = visitLambdaExpression("ALL", all.getLambdaVariable(), all.getExpression()); - } else if (item instanceof UriResourceLambdaAny) { - UriResourceLambdaAny any = (UriResourceLambdaAny) item; - tmp = visitLambdaExpression("ANY", any.getLamdaVariable(), any.getExpression()); - } else if (item instanceof UriResourcePartTyped) { - UriResourcePartTyped typed = (UriResourcePartTyped) item; - tmp = typed.toString(true); - } - - if (ret.length() != 0) { - ret += "/"; - } - ret += tmp; - - } - return "<" + ret + ">"; - } - - @Override - public String visitAlias(final String referenceName) throws ExpressionVisitException { - return "<" + referenceName + ">"; - } - - @Override - public String visitLambdaExpression(final String functionText, final String string, final Expression expression) - throws ExpressionVisitException, ODataApplicationException { - - return "<" + functionText + ";" + ((expression == null) ? "" : expression.accept(this)) + ">"; - } - - @Override - public String visitTypeLiteral(final EdmType type) { - return "<" + type.getNamespace() + "." + type.getName() + ">"; - } - - @Override - public String visitLambdaReference(final String variableText) { - return "<" + variableText + ">"; - } - - @Override - public String visitEnum(final EdmEnumType type, final List enumValues) - throws ExpressionVisitException, ODataApplicationException { - String tmp = ""; - - for (String item : enumValues) { - if (tmp.length() > 0) { - tmp += ","; - } - tmp += item; - } - - return "<" + type.getNamespace() + "." + type.getName() + "<" + tmp + ">>"; - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java deleted file mode 100644 index 58e429f77..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/FilterValidator.java +++ /dev/null @@ -1,534 +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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfo; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.queryoption.expression.BinaryOperatorKind; -import org.apache.olingo.server.api.uri.queryoption.expression.Expression; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.api.uri.queryoption.expression.Member; -import org.apache.olingo.server.api.uri.queryoption.expression.MethodKind; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.parser.Parser; -import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.core.uri.parser.UriParserSemanticException; -import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; -import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.OrderByOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.BinaryImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.EnumerationImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.LiteralImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.MemberImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.MethodImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.TypeLiteralImpl; - -public class FilterValidator implements TestValidator { - private Edm edm; - - private TestValidator invokedByValidator; - private FilterOptionImpl filter; - - private Expression curExpression; - private Expression rootExpression; - - private OrderByOptionImpl orderBy; - - private UriParserException exception; - - // --- Setup --- - public FilterValidator setUriResourcePathValidator(final ResourceValidator uriResourcePathValidator) { - invokedByValidator = uriResourcePathValidator; - return this; - } - - public FilterValidator setUriValidator(final TestUriValidator uriValidator) { - invokedByValidator = uriValidator; - return this; - } - - public FilterValidator setValidator(final TestValidator uriValidator) { - invokedByValidator = uriValidator; - return this; - } - - public FilterValidator setEdm(final Edm edm) { - this.edm = edm; - return this; - } - - public FilterValidator setFilter(final FilterOptionImpl filter) { - this.filter = filter; - - if (filter.getExpression() == null) { - fail("FilterValidator: no filter found"); - } - setExpression(filter.getExpression()); - return this; - } - - public FilterValidator setOrderBy(final OrderByOptionImpl orderBy) { - this.orderBy = orderBy; - - return this; - } - - public FilterValidator setExpression(final Expression expression) { - rootExpression = curExpression = expression; - return this; - } - - // --- Execution --- - - public FilterValidator runOrderByOnETAllPrim(final String orderBy) throws UriParserException { - String uri = "ESAllPrim?$orderby=" + orderBy.trim(); - return runUriOrderBy(uri); - } - - public FilterValidator runOrderByOnETTwoKeyNav(final String orderBy) throws UriParserException { - String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim(); - return runUriOrderBy(uri); - } - - public FilterValidator runOrderByOnETTwoKeyNavEx(final String orderBy) throws UriParserException { - String uri = "ESTwoKeyNav?$orderby=" + orderBy.trim(); - return runUriOrderByEx(uri); - } - - public FilterValidator runOnETTwoKeyNav(final String filter) throws UriParserException { - String uri = "ESTwoKeyNav?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnETTwoKeyNavSingle(final String filter) throws UriParserException { - String uri = "SINav?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnETTwoKeyNavEx(final String filter) throws UriParserException { - String uri = "ESTwoKeyNav?$filter=" + filter.trim(); - return runUriEx(uri); - } - - public FilterValidator runOnETAllPrim(final String filter) throws UriParserException { - String uri = "ESAllPrim(1)?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnETKeyNav(final String filter) throws UriParserException { - String uri = "ESKeyNav(1)?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnETKeyNavEx(final String filter) throws UriParserException { - String uri = "ESKeyNav(1)?$filter=" + filter.trim(); - return runUriEx(uri); - } - - public FilterValidator runOnCTTwoPrim(final String filter) throws UriParserException { - String uri = "SINav/PropertyComplexTwoPrim?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnString(final String filter) throws UriParserException { - String uri = "SINav/PropertyString?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnInt32(final String filter) throws UriParserException { - String uri = "ESCollAllPrim(1)/CollPropertyInt32?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnDateTimeOffset(final String filter) throws UriParserException { - String uri = "ESCollAllPrim(1)/CollPropertyDateTimeOffset?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnDuration(final String filter) throws UriParserException { - String uri = "ESCollAllPrim(1)/CollPropertyDuration?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runOnTimeOfDay(final String filter) throws UriParserException { - String uri = "ESCollAllPrim(1)/CollPropertyTimeOfDay?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runESabc(final String filter) throws UriParserException { - String uri = "ESabc?$filter=" + filter.trim(); - return runUri(uri); - } - - public FilterValidator runUri(final String uri) throws UriParserException { - Parser parser = new Parser(); - UriInfo uriInfo = null; - - uriInfo = parser.parseUri(uri, edm); - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - - setFilter((FilterOptionImpl) uriInfo.getFilterOption()); - curExpression = filter.getExpression(); - return this; - } - - public FilterValidator runUriEx(final String uri) { - Parser parser = new Parser(); - UriInfo uriInfo = null; - - try { - uriInfo = parser.parseUri(uri, edm); - } catch (UriParserException e) { - exception = e; - return this; - } - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - - setFilter((FilterOptionImpl) uriInfo.getFilterOption()); - curExpression = filter.getExpression(); - return this; - } - - public FilterValidator runUriOrderBy(final String uri) throws UriParserException { - Parser parser = new Parser(); - UriInfo uriInfo = null; - - uriInfo = parser.parseUri(uri, edm); - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - - setOrderBy((OrderByOptionImpl) uriInfo.getOrderByOption()); - return this; - } - - public FilterValidator runUriOrderByEx(final String uri) { - Parser parser = new Parser(); - UriInfo uriInfo = null; - - try { - uriInfo = parser.parseUri(uri, edm); - } catch (UriParserException e) { - exception = e; - return this; - } - - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("Filtervalidator can only be used on resourcePaths"); - } - - setOrderBy((OrderByOptionImpl) uriInfo.getOrderByOption()); - return this; - } - - // --- Navigation --- - - public ExpandValidator goUpToExpandValidator() { - return (ExpandValidator) invokedByValidator; - } - - public ResourceValidator goUpToResourceValidator() { - return (ResourceValidator) invokedByValidator; - } - - public ResourceValidator goPath() { - if (!(curExpression instanceof MemberImpl)) { - fail("Current expression not a member"); - } - - MemberImpl member = (MemberImpl) curExpression; - - return new ResourceValidator() - .setEdm(edm) - .setUriInfoImplPath((UriInfoImpl) member.getResourcePath()) - .setUpValidator(this); - - } - - public FilterValidator goParameter(final int parameterIndex) { - if (curExpression instanceof MethodImpl) { - MethodImpl methodCall = (MethodImpl) curExpression; - curExpression = methodCall.getParameters().get(parameterIndex); - } else { - fail("Current expression not a methodCall"); - } - return this; - } - - // --- Validation --- - - /** - * Validates the serialized filterTree against a given filterString - * The given expected filterString is compressed before to allow better readable code in the unit tests - * @param toBeCompr - * @return - */ - public FilterValidator isCompr(final String toBeCompr) { - return is(compress(toBeCompr)); - } - - public FilterValidator is(final String expectedFilterAsString) { - try { - String actualFilterAsText = FilterTreeToText.Serialize((FilterOptionImpl) filter); - assertEquals(expectedFilterAsString, actualFilterAsText); - } catch (ExpressionVisitException e) { - fail("Exception occured while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } catch (ODataApplicationException e) { - fail("Exception occured while converting the filterTree into text" + "\n" - + " Exception: " + e.getMessage()); - } - - return this; - } - - // --- Helper --- - - private String compress(final String expected) { - String ret = expected.replaceAll("\\s+", " "); - ret = ret.replaceAll("< ", "<"); - ret = ret.replaceAll(" >", ">"); - return ret; - } - - public FilterValidator isType(final FullQualifiedName fullName) { - EdmType actualType = null; - - if (curExpression instanceof MemberImpl) { - Member member = (Member) curExpression; - actualType = member.getType(); - } else if (curExpression instanceof TypeLiteralImpl) { - TypeLiteralImpl typeLiteral = (TypeLiteralImpl) curExpression; - actualType = typeLiteral.getType(); - } else if (curExpression instanceof LiteralImpl) { - LiteralImpl typeLiteral = (LiteralImpl) curExpression; - actualType = typeLiteral.getType(); - } - - if (actualType == null) { - fail("Current expression not typed"); - } - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(fullName, actualName); - return this; - } - - public FilterValidator left() { - if (!(curExpression instanceof BinaryImpl)) { - fail("Current expression not a binary operator"); - } - - curExpression = ((BinaryImpl) curExpression).getLeftOperand(); - - return this; - } - - public FilterValidator root() { - if (filter != null) { - curExpression = filter.getExpression(); - } else { - curExpression = rootExpression; - } - - return this; - } - - public FilterValidator right() { - if (!(curExpression instanceof BinaryImpl)) { - fail("Current expression is not a binary operator"); - } - - curExpression = ((BinaryImpl) curExpression).getRightOperand(); - - return this; - - } - - public FilterValidator isLiteral(final String literalText) { - if (!(curExpression instanceof LiteralImpl)) { - fail("Current expression is not a literal"); - } - - String actualLiteralText = ((LiteralImpl) curExpression).getText(); - assertEquals(literalText, actualLiteralText); - - return this; - } - - public FilterValidator isMethod(final MethodKind methodKind, final int parameterCount) { - if (!(curExpression instanceof MethodImpl)) { - fail("Current expression is not a methodCall"); - } - - MethodImpl methodCall = (MethodImpl) curExpression; - assertEquals(methodKind, methodCall.getMethod()); - assertEquals(parameterCount, methodCall.getParameters().size()); - - return this; - } - - public FilterValidator isParameterText(final int parameterIndex, final String parameterText) - throws ExpressionVisitException, ODataApplicationException { - - if (!(curExpression instanceof MethodImpl)) { - fail("Current expression is not a method"); - } - - MethodImpl methodCall = (MethodImpl) curExpression; - - Expression parameter = methodCall.getParameters().get(parameterIndex); - String actualParameterText = FilterTreeToText.Serialize(parameter); - assertEquals(parameterText, actualParameterText); - - return this; - } - - public FilterValidator isBinary(final BinaryOperatorKind binaryOperator) { - if (!(curExpression instanceof BinaryImpl)) { - fail("Current expression is not a binary operator"); - } - - BinaryImpl binary = (BinaryImpl) curExpression; - assertEquals(binaryOperator, binary.getOperator()); - - return this; - } - - public FilterValidator isTypedLiteral(final FullQualifiedName fullName) { - if (!(curExpression instanceof TypeLiteralImpl)) { - fail("Current expression not a typeLiteral"); - } - - isType(fullName); - - return this; - } - - public FilterValidator isMember() { - if (!(curExpression instanceof MemberImpl)) { - fail("Current expression not a member"); - } - - return this; - } - - public FilterValidator isMemberStartType(final FullQualifiedName fullName) { - if (!(curExpression instanceof MemberImpl)) { - fail("Current expression not a member"); - } - - MemberImpl member = (MemberImpl) curExpression; - EdmType actualType = member.getStartTypeFilter(); - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(fullName, actualName); - return this; - } - - public FilterValidator isEnum(final FullQualifiedName nameenstring, final List enumValues) { - if (!(curExpression instanceof EnumerationImpl)) { - fail("Current expression not a enumeration"); - } - - EnumerationImpl enumeration = (EnumerationImpl) curExpression; - - FullQualifiedName actualName = - new FullQualifiedName(enumeration.getType().getNamespace(), enumeration.getType().getName()); - - // check name - assertEquals(nameenstring.toString(), actualName.toString()); - - // check values - int i = 0; - for (String item : enumValues) { - assertEquals(item, enumeration.getValues().get(i)); - i++; - } - - return this; - } - - public FilterValidator isSortOrder(final int index, final boolean descending) { - assertEquals(descending, orderBy.getOrders().get(index).isDescending()); - return this; - } - - public FilterValidator goOrder(final int index) { - curExpression = orderBy.getOrders().get(index).getExpression(); - return this; - } - - public FilterValidator isExSyntax(final long errorID) { - assertEquals(UriParserSyntaxException.class, exception.getClass()); - return this; - } - - public FilterValidator isExSemantic(final long errorID) { - assertEquals(UriParserSemanticException.class, exception.getClass()); - return this; - } - - public FilterValidator isNull() { - if (!(curExpression instanceof LiteralImpl)) { - fail("Current expression is not a literal"); - } - - String actualLiteralText = ((LiteralImpl) curExpression).getText(); - assertEquals("null", actualLiteralText); - return this; - } - - public FilterValidator isTrue() { - if (!(curExpression instanceof LiteralImpl)) { - fail("Current expression is not a literal"); - } - - String actualLiteralText = ((LiteralImpl) curExpression).getText(); - assertEquals("true", actualLiteralText); - return this; - } - - public FilterValidator isFalse() { - if (!(curExpression instanceof LiteralImpl)) { - fail("Current expression is not a literal"); - } - - String actualLiteralText = ((LiteralImpl) curExpression).getText(); - assertEquals("false", actualLiteralText); - return this; - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParseTreeToText.java deleted file mode 100644 index f6a308607..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/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.server.core.uri.testutil; - -import java.util.Arrays; -import java.util.List; - -import org.antlr.v4.runtime.Token; -import org.antlr.v4.runtime.misc.NotNull; -import org.antlr.v4.runtime.misc.Nullable; -import org.antlr.v4.runtime.misc.Utils; -import org.antlr.v4.runtime.tree.ErrorNode; -import org.antlr.v4.runtime.tree.RuleNode; -import org.antlr.v4.runtime.tree.TerminalNode; -import org.antlr.v4.runtime.tree.Tree; - -public class ParseTreeToText { - - public static String getTreeAsText(final Tree contextTree, final String[] ruleNames) { - return toStringTree(contextTree, Arrays.asList(ruleNames)); - } - - private static String toStringTree(final Tree t, @Nullable final List 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 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(); - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java deleted file mode 100644 index 3f73b97f0..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserValidator.java +++ /dev/null @@ -1,162 +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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; - -import java.util.ArrayList; -import java.util.List; - -import org.antlr.v4.runtime.ParserRuleContext; -import org.apache.olingo.server.core.uri.antlr.UriParserParser; - -public class ParserValidator { - - private String input = null; - private ParserRuleContext root; - - int logLevel = 0; - private int lexerLogLevel = 0; - - boolean allowFullContext; - boolean allowContextSensitifity; - boolean allowAmbiguity; - - List exceptions = new ArrayList(); - private Exception curException = null; - - // --- Setup --- - - public ParserValidator log(final int logLevel) { - this.logLevel = logLevel; - return this; - } - - public ParserValidator lexerLog(final int logLevel) { - lexerLogLevel = logLevel; - return this; - } - - /** - * Used in fast LL Parsing: - * Don't stop the parsing process when the slower full context parsing (with prediction mode SLL) is - * required - * @return - */ - public ParserValidator aFC() { - allowFullContext = true; - return this; - } - - /** - * Used in fast LL Parsing: - * Allows ContextSensitifity Errors which occur often when using the slower full context parsing - * and indicate that there is a context sensitivity ( which may not be an error). - * @return - */ - public ParserValidator aCS() { - allowContextSensitifity = true; - return this; - } - - /** - * Used in fast LL Parsing: - * Allows ambiguities - * @return - */ - public ParserValidator aAM() { - allowAmbiguity = true; - return this; - } - - // --- Execution --- - - public ParserValidator run(final String uri) { - input = uri; - - // just run a short lexer step. E.g. to print the tokens - if (lexerLogLevel > 0) { - (new TokenValidator()).log(lexerLogLevel).run(input); - } - - /**/// root = parseInput(uri); - - // if LOG > 0 - Write serialized tree - if (logLevel > 0) { - if (root != null) { - System.out.println(ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames())); - } else { - System.out.println("root == null"); - } - } - - // reset for next test - allowFullContext = false; - allowContextSensitifity = false; - allowAmbiguity = false; - logLevel = 0; - - return this; - } - - // --- Navigation --- - - public ParserValidator exFirst() { - try { - // curWeakException = exceptions.get(0); - } catch (IndexOutOfBoundsException ex) { - // curWeakException = null; - } - return this; - - } - - public ParserValidator exLast() { - // curWeakException = exceptions.get(exceptions.size() - 1); - return this; - } - - public ParserValidator exAt(final int index) { - try { - // curWeakException = exceptions.get(index); - } catch (IndexOutOfBoundsException ex) { - // curWeakException = null; - } - return this; - } - - // --- Validation --- - - public ParserValidator isText(final String expected) { - - assertEquals(null, curException); - assertEquals(0, exceptions.size()); - - String actualTreeAsText = ParseTreeToText.getTreeAsText(root, new UriParserParser(null).getRuleNames()); - - assertEquals(expected, actualTreeAsText); - return this; - } - - public ParserValidator isExeptionType(final Class exClass) { - assertEquals(exClass, curException.getClass()); - return this; - } - -} \ No newline at end of file diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java deleted file mode 100644 index 524a38a17..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ParserWithLogging.java +++ /dev/null @@ -1,56 +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.server.core.uri.testutil; - -import org.antlr.v4.runtime.DefaultErrorStrategy; -import org.antlr.v4.runtime.DiagnosticErrorListener; -import org.apache.olingo.server.core.uri.antlr.UriParserParser; -import org.apache.olingo.server.core.uri.parser.Parser; - -public class ParserWithLogging extends Parser { - TestErrorLogger errorCollector1; - TestErrorLogger errorCollector2; - - public ParserWithLogging() { - errorCollector1 = new TestErrorLogger("Stage 1", 1); - errorCollector2 = new TestErrorLogger("Stage 2", 1); - } - - @Override - protected void addStage2ErrorStategy(final UriParserParser parser) { - // Don't throw an at first syntax error, so the error listener will be called - parser.setErrorHandler(new DefaultErrorStrategy()); - } - - @Override - protected void addStage1ErrorListener(final UriParserParser parser) { - // Log error to console - parser.removeErrorListeners(); - parser.addErrorListener(errorCollector1); - parser.addErrorListener(new DiagnosticErrorListener()); - } - - @Override - protected void addStage2ErrorListener(final UriParserParser parser) { - // Log error to console - parser.removeErrorListeners(); - parser.addErrorListener(errorCollector2); - parser.addErrorListener(new DiagnosticErrorListener()); - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java deleted file mode 100644 index 143871a1f..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/ResourceValidator.java +++ /dev/null @@ -1,599 +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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.apache.olingo.commons.api.ODataApplicationException; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmElement; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfo; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.UriParameter; -import org.apache.olingo.server.api.uri.UriResourceKind; -import org.apache.olingo.server.api.uri.UriResourcePartTyped; -import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.expression.ExpressionVisitException; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.UriResourceActionImpl; -import org.apache.olingo.server.core.uri.UriResourceComplexPropertyImpl; -import org.apache.olingo.server.core.uri.UriResourceEntitySetImpl; -import org.apache.olingo.server.core.uri.UriResourceFunctionImpl; -import org.apache.olingo.server.core.uri.UriResourceImpl; -import org.apache.olingo.server.core.uri.UriResourceLambdaAllImpl; -import org.apache.olingo.server.core.uri.UriResourceLambdaAnyImpl; -import org.apache.olingo.server.core.uri.UriResourceNavigationPropertyImpl; -import org.apache.olingo.server.core.uri.UriResourcePrimitivePropertyImpl; -import org.apache.olingo.server.core.uri.UriResourceSingletonImpl; -import org.apache.olingo.server.core.uri.UriResourceWithKeysImpl; -import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.expression.ExpressionImpl; -import org.apache.olingo.server.core.uri.validator.UriValidator; - -public class ResourceValidator implements TestValidator { - private Edm edm; - private TestValidator invokedBy; - private UriInfo uriInfo = null; - - private UriResourceImpl uriPathInfo = null; - private int uriResourceIndex; - - // --- Setup --- - - public ResourceValidator setUpValidator(final TestValidator uriValidator) { - invokedBy = uriValidator; - return this; - } - - public ResourceValidator setEdm(final Edm edm) { - this.edm = edm; - return this; - } - - public ResourceValidator setUriInfoImplPath(final UriInfoImpl uriInfoPath) { - uriInfo = uriInfoPath; - last(); - return this; - } - - // --- Execution --- - - public ResourceValidator run(final String uri) { - ParserWithLogging testParser = new ParserWithLogging(); - - UriInfoImpl uriInfoTmp = null; - uriPathInfo = null; - try { - uriInfoTmp = (UriInfoImpl) testParser.parseUri(uri, edm); - - UriValidator uriValidator = new UriValidator(); - uriValidator.validate(uriInfoTmp, "GET"); - } catch (Exception e) { - fail("Exception occured while parsing the URI: " + uri + "\n" - + " Message: " + e.getMessage()); - } - - if (uriInfoTmp.getKind() != UriInfoKind.resource) { - fail("Invalid UriInfoKind: " + uriInfoTmp.getKind().toString()); - } - uriInfo = uriInfoTmp; - - first(); - return this; - } - - // --- Navigation --- - - public TestUriValidator goUpUriValidator() { - return (TestUriValidator) invokedBy; - } - - public ExpandValidator goUpExpandValidator() { - return (ExpandValidator) invokedBy; - } - - public FilterValidator goUpFilterValidator() { - return (FilterValidator) invokedBy; - } - - public FilterValidator goParameter(final int index) { - assertEquals(UriResourceKind.function, uriPathInfo.getKind()); - UriResourceFunctionImpl function = (UriResourceFunctionImpl) uriPathInfo; - - return new FilterValidator() - .setEdm(edm) - .setExpression(function.getParameters().get(index).getExression()) - .setValidator(this); - } - - public FilterValidator goLambdaExpression() { - if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) { - return new FilterValidator() - .setEdm(edm) - .setExpression(((UriResourceLambdaAllImpl) uriPathInfo).getExpression()); - - } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) { - return new FilterValidator() - .setEdm(edm) - .setExpression(((UriResourceLambdaAnyImpl) uriPathInfo).getExpression()); - } else { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - return null; - } - - public ResourceValidator goSelectItem(final int index) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath(); - - return new ResourceValidator() - .setUpValidator(this) - .setEdm(edm) - .setUriInfoImplPath(uriInfo1); - - } - - public ExpandValidator goExpand() { - ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption(); - if (expand == null) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - return new ExpandValidator().setUpValidator(this).setExpand(expand); - } - - public ResourceValidator first() { - uriResourceIndex = 0; - uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(0); - return this; - } - - public ResourceValidator last() { - uriResourceIndex = 0; - - try { - uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriInfo.getUriResourceParts().size() - 1); - uriResourceIndex = uriInfo.getUriResourceParts().size() - 1; - } catch (IndexOutOfBoundsException ex) { - fail("not enough segments"); - } - - return this; - } - - public ResourceValidator n() { - uriResourceIndex++; - - try { - uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(uriResourceIndex); - } catch (IndexOutOfBoundsException ex) { - fail("not enough segments"); - } - - return this; - } - - public ResourceValidator at(final int index) { - uriResourceIndex = index; - try { - uriPathInfo = (UriResourceImpl) uriInfo.getUriResourceParts().get(index); - } catch (IndexOutOfBoundsException ex) { - fail("not enough segments"); - } - return this; - } - - // --- Validation --- - - public ResourceValidator isLambdaVar(final String var) { - String actualVar = null; - if (uriPathInfo.getKind() == UriResourceKind.lambdaAll) { - actualVar = ((UriResourceLambdaAllImpl) uriPathInfo).getLambdaVariable(); - } else if (uriPathInfo.getKind() == UriResourceKind.lambdaAny) { - actualVar = ((UriResourceLambdaAnyImpl) uriPathInfo).getLamdaVariable(); - } else { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - assertEquals(var, actualVar); - return this; - } - - public ResourceValidator isTypeFilter(final FullQualifiedName expectedType) { - - if (uriPathInfo.getKind() != UriResourceKind.complexProperty && - uriPathInfo.getKind() != UriResourceKind.singleton) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - EdmType actualType = null; - if (uriPathInfo instanceof UriResourceComplexPropertyImpl) { - actualType = ((UriResourceComplexPropertyImpl) uriPathInfo).getComplexTypeFilter(); - } else if (uriPathInfo instanceof UriResourceSingletonImpl) { - actualType = ((UriResourceSingletonImpl) uriPathInfo).getEntityTypeFilter(); - } - - if (actualType == null) { - fail("type information not set"); - } - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - - assertEquals(expectedType.toString(), actualName.toString()); - return this; - } - - public ResourceValidator isType(final FullQualifiedName type) { - if (!(uriPathInfo instanceof UriResourcePartTyped)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo; - - EdmType actualType = uriPathInfoTyped.getType(); - if (actualType == null) { - fail("type information not set"); - } - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - - assertEquals(type.toString(), actualName.toString()); - - return this; - } - - public ResourceValidator isType(final FullQualifiedName type, final boolean isFinallyACollection) { - isType(type); - assertEquals(isFinallyACollection, ((UriResourcePartTyped) uriPathInfo).isCollection()); - return this; - } - - public ResourceValidator isTypeFilterOnEntry(final FullQualifiedName type) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo; - - // input parameter type may be null in order to assert that the singleTypeFilter is not set - EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnEntry(); - if (type == null) { - assertEquals(type, actualType); - } else { - assertEquals(type.toString(), new FullQualifiedName(actualType.getNamespace(), actualType.getName()).toString()); - } - - return this; - } - - public ResourceValidator isTypeFilterOnCollection(final FullQualifiedName expectedType) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - UriResourceWithKeysImpl uriPathInfoKeyPred = (UriResourceWithKeysImpl) uriPathInfo; - - // input parameter type may be null in order to assert that the collectionTypeFilter is not set - EdmType actualType = uriPathInfoKeyPred.getTypeFilterOnCollection(); - if (expectedType == null) { - assertEquals(expectedType, actualType); - } else { - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(expectedType.toString(), actualName.toString()); - } - - return this; - } - - // other functions - public ResourceValidator checkCustomParameter(final int index, final String name, final String value) { - if (uriInfo == null) { - fail("hasQueryParameter: uriInfo == null"); - } - - List list = uriInfo.getCustomQueryOptions(); - if (list.size() <= index) { - fail("not enough queryParameters"); - } - - CustomQueryOptionImpl option = (CustomQueryOptionImpl) list.get(index); - assertEquals(name, option.getName()); - assertEquals(value, option.getText()); - return this; - } - - // TODO remove - /* - * public ResourceValidator isCollection(final boolean isCollection) { - * if (!(uriPathInfo instanceof UriResourcePartTyped)) { - * fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - * } - * UriResourcePartTyped uriPathInfoTyped = (UriResourcePartTyped) uriPathInfo; - * - * EdmType type = uriPathInfoTyped.getType(); - * if (type == null) { - * fail("isCollection: type == null"); - * } - * assertEquals(isCollection, uriPathInfoTyped.isCollection()); - * return this; - * } - */ - - public ResourceValidator isFilterString(final String expectedFilterTreeAsString) { - - ExpressionImpl filterTree = (ExpressionImpl) uriInfo.getFilterOption().getExpression(); - try { - String filterTreeAsString = filterTree.accept(new FilterTreeToText()); - assertEquals(expectedFilterTreeAsString, filterTreeAsString); - } catch (ExpressionVisitException e) { - fail("isFilterString: Exception " + e.getMessage() + " occured"); - } catch (ODataApplicationException e) { - fail("isFilterString: Exception " + e.getMessage() + " occured"); - } - - return this; - } - - public ResourceValidator isKeyPredicateRef(final int index, final String name, final String refencedProperty) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; - List keyPredicates = info.getKeyPredicates(); - assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(refencedProperty, keyPredicates.get(index).getRefencedProperty()); - return this; - - } - - public ResourceValidator isKeyPredicateAlias(final int index, final String name, final String alias) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; - List keyPredicates = info.getKeyPredicates(); - assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(alias, keyPredicates.get(index).getAlias()); - return this; - - } - - public ResourceValidator isKeyPredicate(final int index, final String name, final String text) { - if (!(uriPathInfo instanceof UriResourceWithKeysImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceWithKeysImpl info = (UriResourceWithKeysImpl) uriPathInfo; - List keyPredicates = info.getKeyPredicates(); - assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(text, keyPredicates.get(index).getText()); - return this; - - } - - public ResourceValidator isParameter(final int index, final String name, final String text) { - if (!(uriPathInfo instanceof UriResourceFunctionImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo; - List keyPredicates = info.getParameters(); - assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(text, keyPredicates.get(index).getText()); - return this; - - } - - public ResourceValidator isParameterAlias(final int index, final String name, final String alias) { - if (!(uriPathInfo instanceof UriResourceFunctionImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceFunctionImpl info = (UriResourceFunctionImpl) uriPathInfo; - List keyPredicates = info.getParameters(); - assertEquals(name, keyPredicates.get(index).getName()); - assertEquals(alias, keyPredicates.get(index).getAlias()); - return this; - - } - - public ResourceValidator isKind(final UriInfoKind kind) { - assertEquals(kind, uriInfo.getKind()); - return this; - } - - public ResourceValidator isPrimitiveProperty(final String name, - final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourcePrimitivePropertyImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourcePrimitivePropertyImpl uriPathInfoProp = (UriResourcePrimitivePropertyImpl) uriPathInfo; - - EdmElement property = uriPathInfoProp.getProperty(); - - assertEquals(name, property.getName()); - assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName())); - assertEquals(isCollection, property.isCollection()); - return this; - } - - public ResourceValidator - isComplexProperty(final String name, final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourceComplexPropertyImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceComplexPropertyImpl uriPathInfoProp = (UriResourceComplexPropertyImpl) uriPathInfo; - - EdmElement property = uriPathInfoProp.getProperty(); - - assertEquals(name, property.getName()); - assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName())); - assertEquals(isCollection, property.isCollection()); - return this; - } - - public ResourceValidator isNavProperty(final String name, final FullQualifiedName type, final boolean isCollection) { - if (!(uriPathInfo instanceof UriResourceNavigationPropertyImpl)) { - fail("invalid resource kind: " + uriPathInfo.getKind().toString()); - } - - UriResourceNavigationPropertyImpl uriPathInfoProp = (UriResourceNavigationPropertyImpl) uriPathInfo; - - EdmElement property = uriPathInfoProp.getProperty(); - - assertEquals(name, property.getName()); - assertEquals(type, new FullQualifiedName(property.getType().getNamespace(), property.getType().getName())); - assertEquals(isCollection, uriPathInfoProp.isCollection()); - return this; - } - - public ResourceValidator isUriPathInfoKind(final UriResourceKind infoType) { - assertNotNull(uriPathInfo); - assertEquals(infoType, uriPathInfo.getKind()); - return this; - } - - public ResourceValidator isAction(final String name) { - assertEquals(UriResourceKind.action, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceActionImpl) uriPathInfo).getAction().getName()); - return this; - } - - public ResourceValidator isFunction(final String name) { - assertEquals(UriResourceKind.function, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunction().getName()); - return this; - } - - public ResourceValidator isFunctionImport(final String name) { - assertEquals(UriResourceKind.function, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceFunctionImpl) uriPathInfo).getFunctionImport().getName()); - return this; - } - - public ResourceValidator isEntitySet(final String name) { - assertEquals(UriResourceKind.entitySet, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceEntitySetImpl) uriPathInfo).getEntitySet().getName()); - return this; - } - - public ResourceValidator isComplex(final String name) { - assertEquals(UriResourceKind.complexProperty, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceComplexPropertyImpl) uriPathInfo).getProperty().getName()); - return this; - } - - public ResourceValidator isSingleton(final String name) { - assertEquals(UriResourceKind.singleton, uriPathInfo.getKind()); - assertEquals(name, ((UriResourceSingletonImpl) uriPathInfo).getSingleton().getName()); - return this; - } - - public ResourceValidator isValue() { - assertEquals(UriResourceKind.value, uriPathInfo.getKind()); - return this; - } - - public ResourceValidator isCount() { - assertEquals(UriResourceKind.count, uriPathInfo.getKind()); - return this; - } - - public ResourceValidator isRef() { - assertEquals(UriResourceKind.ref, uriPathInfo.getKind()); - return this; - } - - public ResourceValidator isActionImport(final String actionName) { - assertEquals(UriResourceKind.action, uriPathInfo.getKind()); - assertEquals(actionName, ((UriResourceActionImpl) uriPathInfo).getActionImport().getName()); - return this; - } - - public ResourceValidator isIt() { - assertEquals(UriResourceKind.it, uriPathInfo.getKind()); - return this; - } - - public ResourceValidator isTopText(final String topText) { - assertEquals(topText, uriInfo.getTopOption().getText()); - return this; - } - - public ResourceValidator isFormatText(final String formatText) { - assertEquals(formatText, uriInfo.getFormatOption().getText()); - return this; - } - - public ResourceValidator isInlineCountText(final String inlineCountText) { - assertEquals(inlineCountText, uriInfo.getCountOption().getText()); - return this; - } - - public ResourceValidator isSkipText(final String skipText) { - assertEquals(skipText, uriInfo.getSkipOption().getText()); - return this; - } - - public ResourceValidator isSkipTokenText(final String skipTokenText) { - assertEquals(skipTokenText, uriInfo.getSkipTokenOption().getText()); - return this; - } - - public ResourceValidator isSelectItemStar(final int index) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(true, item.isStar()); - return this; - } - - public ResourceValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString()); - return this; - } - - public ResourceValidator isSelectStartType(final int index, final FullQualifiedName fullName) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - - EdmType actualType = item.getStartTypeFilter(); - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(fullName, actualName); - return this; - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java deleted file mode 100644 index 0153036dc..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestErrorLogger.java +++ /dev/null @@ -1,105 +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.server.core.uri.testutil; - -import java.util.BitSet; -import java.util.Collections; -import java.util.List; - -import org.antlr.v4.runtime.ANTLRErrorListener; -import org.antlr.v4.runtime.Parser; -import org.antlr.v4.runtime.RecognitionException; -import org.antlr.v4.runtime.Recognizer; -import org.antlr.v4.runtime.atn.ATNConfigSet; -import org.antlr.v4.runtime.dfa.DFA; -import org.apache.olingo.server.core.uri.antlr.UriLexer; - -class TestErrorLogger implements ANTLRErrorListener { - - private String prefix; - private int logLevel = 0; - - public TestErrorLogger(final String prefix, final int logLevel) { - this.prefix = prefix; - this.logLevel = logLevel; - } - - @Override - public void syntaxError(final Recognizer recognizer, final Object offendingSymbol, final int line, - final int charPositionInLine, - final String msg, final RecognitionException e) { - - if (logLevel > 0) { - System.out.println("\n" + prefix + " -- SyntaxError"); - trace(recognizer, offendingSymbol, line, charPositionInLine, msg, e); - } - - } - - @Override - public void reportAmbiguity(final Parser recognizer, final DFA dfa, final int startIndex, final int stopIndex, - final boolean exact, - final BitSet ambigAlts, final ATNConfigSet configs) { - - } - - @Override - public void reportAttemptingFullContext(final Parser recognizer, final DFA dfa, final int startIndex, - final int stopIndex, - final BitSet conflictingAlts, final ATNConfigSet configs) { - - } - - @Override - public void reportContextSensitivity(final Parser recognizer, final DFA dfa, final int startIndex, - final int stopIndex, final int prediction, - final ATNConfigSet configs) { - - } - - private void printStack(final Recognizer recognizer) { - List stack = ((Parser) recognizer).getRuleInvocationStack(); - Collections.reverse(stack); - System.out.println(" rule stack: " + stack); - } - - public void trace(final Recognizer recognizer, final Object offendingSymbol, - final int line, final int charPositionInLine, final String msg, final RecognitionException e) { - - System.out.println("Error message: " + msg); - - printStack(recognizer); - - System.out.println(" line/char :" + line + " / " + charPositionInLine); - System.out.println(" sym :" + offendingSymbol); - if (e != null && e.getOffendingToken() != null) { - - String lexerTokenName = ""; - try { - lexerTokenName = UriLexer.tokenNames[e.getOffendingToken().getType()]; - } catch (ArrayIndexOutOfBoundsException es) { - lexerTokenName = "token error"; - } - - System.out.println(" tokenname:" + lexerTokenName); - } - - } - -} \ No newline at end of file diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java deleted file mode 100644 index 35687f699..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestUriValidator.java +++ /dev/null @@ -1,258 +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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.fail; - -import java.util.List; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmType; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.uri.UriInfoKind; -import org.apache.olingo.server.api.uri.queryoption.CustomQueryOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.core.uri.UriInfoImpl; -import org.apache.olingo.server.core.uri.parser.Parser; -import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.core.uri.parser.UriParserSemanticException; -import org.apache.olingo.server.core.uri.parser.UriParserSyntaxException; -import org.apache.olingo.server.core.uri.queryoption.CustomQueryOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.ExpandOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.FilterOptionImpl; -import org.apache.olingo.server.core.uri.queryoption.SelectOptionImpl; -import org.apache.olingo.server.core.uri.validator.UriValidator; - -public class TestUriValidator implements TestValidator { - private Edm edm; - - private UriInfoImpl uriInfo; - private Exception exception; - - // Setup - public TestUriValidator setEdm(final Edm edm) { - this.edm = edm; - return this; - } - - // Execution - public TestUriValidator run(final String uri) { - Parser parser = new Parser(); - UriValidator validator = new UriValidator(); - - uriInfo = null; - try { - uriInfo = (UriInfoImpl) parser.parseUri(uri, edm); - validator.validate(uriInfo, "GET"); - } catch (Exception e) { - throw new RuntimeException(e); - } - - return this; - } - - public TestUriValidator runEx(final String uri) { - Parser parser = new Parser(); - uriInfo = null; - try { - uriInfo = (UriInfoImpl) parser.parseUri(uri, edm); - fail("Exception expected"); - } catch (UriParserException e) { - exception = e; - } - - return this; - } - - public TestUriValidator log(final String uri) { - ParserWithLogging parserTest = new ParserWithLogging(); - parserTest.setLogLevel(1); - uriInfo = null; - try { - // uriInfoTmp = new UriParserImpl(edm).ParseUri(uri); - uriInfo = (UriInfoImpl) parserTest.parseUri(uri, edm); - } catch (UriParserException e) { - fail("Exception occured while parsing the URI: " + uri + "\n" - + " Exception: " + e.getMessage()); - } - - return this; - } - - // Navigation - public ResourceValidator goPath() { - if (uriInfo.getKind() != UriInfoKind.resource) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - return new ResourceValidator() - .setUpValidator(this) - .setEdm(edm) - .setUriInfoImplPath(uriInfo); - } - - public FilterValidator goFilter() { - FilterOptionImpl filter = (FilterOptionImpl) uriInfo.getFilterOption(); - if (filter == null) { - fail("no filter found"); - } - return new FilterValidator().setUriValidator(this).setFilter(filter); - - } - - public ExpandValidator goExpand() { - ExpandOptionImpl expand = (ExpandOptionImpl) uriInfo.getExpandOption(); - if (expand == null) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - return new ExpandValidator().setUpValidator(this).setExpand(expand); - } - - public ResourceValidator goSelectItemPath(final int index) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - UriInfoImpl uriInfo1 = (UriInfoImpl) item.getResourcePath(); - - return new ResourceValidator() - .setUpValidator(this) - .setEdm(edm) - .setUriInfoImplPath(uriInfo1); - - } - - public TestUriValidator isSelectStartType(final int index, final FullQualifiedName fullName) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - SelectItem item = select.getSelectItems().get(index); - EdmType actualType = item.getStartTypeFilter(); - - FullQualifiedName actualName = new FullQualifiedName(actualType.getNamespace(), actualType.getName()); - assertEquals(fullName, actualName); - return this; - - } - - // Validation - public TestUriValidator isKind(final UriInfoKind kind) { - assertEquals(kind, uriInfo.getKind()); - return this; - } - - public TestUriValidator isCustomParameter(final int index, final String name, final String value) { - if (uriInfo == null) { - fail("hasQueryParameter: uriInfo == null"); - } - - List 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 entitySets) { - if (uriInfo.getKind() != UriInfoKind.crossjoin) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - int i = 0; - for (String entitySet : entitySets) { - assertEquals(entitySet, uriInfo.getEntitySetNames().get(i)); - i++; - } - - } - - public TestUriValidator isExSyntax(final long errorID) { - assertEquals(UriParserSyntaxException.class, exception.getClass()); - return this; - } - - public TestUriValidator isExSemantic(final long errorID) { - assertEquals(UriParserSemanticException.class, exception.getClass()); - return this; - } - - public TestUriValidator isIdText(final String text) { - assertEquals(text, uriInfo.getIdOption().getText()); - return this; - } - - public TestUriValidator isExpandText(final String text) { - assertEquals(text, uriInfo.getExpandOption().getText()); - return this; - } - - public TestUriValidator isSelectText(final String text) { - assertEquals(text, uriInfo.getSelectOption().getText()); - return this; - } - - public TestUriValidator isFormatText(final String text) { - assertEquals(text, uriInfo.getFormatOption().getText()); - return this; - } - - public TestUriValidator isFragmentText(final String text) { - if (uriInfo.getKind() != UriInfoKind.metadata) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - assertEquals(text, uriInfo.getFragment()); - - return this; - } - - public TestUriValidator isEntityType(final FullQualifiedName fullName) { - if (uriInfo.getKind() != UriInfoKind.entityId) { - fail("invalid resource kind: " + uriInfo.getKind().toString()); - } - - assertEquals(fullName.toString(), fullName(uriInfo.getEntityTypeCast())); - return this; - } - - private String fullName(final EdmEntityType type) { - return type.getNamespace() + "." + type.getName(); - } - - public TestUriValidator isSelectItemStar(final int index) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(true, item.isStar()); - return this; - } - - public TestUriValidator isSelectItemAllOp(final int index, final FullQualifiedName fqn) { - SelectOptionImpl select = (SelectOptionImpl) uriInfo.getSelectOption(); - - SelectItem item = select.getSelectItems().get(index); - assertEquals(fqn.toString(), item.getAllOperationsInSchemaNameSpace().toString()); - return this; - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.java deleted file mode 100644 index 7e64f86a5..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TestValidator.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.server.core.uri.testutil; - -public interface TestValidator { - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/TokenValidator.java deleted file mode 100644 index 4a94bb3e7..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/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.server.core.uri.testutil; - -import static org.junit.Assert.assertEquals; - -import java.util.List; - -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.Token; -import org.apache.olingo.server.core.uri.antlr.UriLexer; - -//TODO extend to test also exception which can occure while paring -public class TokenValidator { - - private String input = null; - - private List 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 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; - } - -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/testutil/UriLexerWithTrace.java deleted file mode 100644 index 9005080dc..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/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.server.core.uri.testutil; - -import org.antlr.v4.runtime.ANTLRInputStream; -import org.antlr.v4.runtime.Token; -import org.apache.olingo.server.core.uri.antlr.UriLexer; - -public class UriLexerWithTrace extends UriLexer { - int logLevel = 0; - - public UriLexerWithTrace(final ANTLRInputStream antlrInputStream, final int logLevel) { - super(antlrInputStream); - this.logLevel = logLevel; - } - - public UriLexerWithTrace(final ANTLRInputStream antlrInputStream, final int logLevel, final int mode) { - super(antlrInputStream); - super.mode(mode); - this.logLevel = logLevel; - } - - @Override - public void emit(final Token token) { - if (logLevel > 1) { - String out = String.format("%1$-" + 20 + "s", token.getText()); - - int tokenType = token.getType(); - if (tokenType == -1) { - out += "-1/EOF"; - } else { - out += UriLexer.tokenNames[tokenType]; - } - System.out.println("Lexer.emit(...):" + out); - } - - super.emit(token); - } - - @Override - public void pushMode(final int m) { - - String out = UriLexer.modeNames[_mode] + "-->"; - - super.pushMode(m); - - out += UriLexer.modeNames[_mode]; - - if (logLevel > 1) { - System.out.println(out + " "); - } - } - - @Override - public int popMode() { - - String out = UriLexer.modeNames[_mode] + "-->"; - - int m = super.popMode(); - - out += UriLexer.modeNames[_mode]; - - if (logLevel > 1) { - System.out.println(out + " "); - } - - return m; - } -} diff --git a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java b/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java deleted file mode 100644 index 9787fab84..000000000 --- a/lib/server-tecsvc/src/test/java/org/apache/olingo/server/core/uri/validator/UriValidatorTest.java +++ /dev/null @@ -1,378 +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.server.core.uri.validator; - -import static org.junit.Assert.assertTrue; -import static org.junit.Assert.fail; - -import java.util.ArrayList; - -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.server.api.uri.UriInfo; -import org.apache.olingo.server.core.edm.provider.EdmProviderImpl; -import org.apache.olingo.server.core.uri.parser.Parser; -import org.apache.olingo.server.core.uri.parser.UriParserException; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.junit.Before; -import org.junit.Ignore; -import org.junit.Test; - -public class UriValidatorTest { - - private static final String URI_ALL = "$all"; - private static final String URI_BATCH = "$batch"; - private static final String URI_CROSSJOIN = "$crossjoin(ESAllPrim)"; - private static final String URI_ENTITY_ID = "/$entity"; - private static final String URI_METADATA = "$metadata"; - private static final String URI_SERVICE = ""; - private static final String URI_ENTITY_SET = "/ESAllPrim"; - private static final String URI_ENTITY_SET_COUNT = "/ESAllPrim/$count"; - private static final String URI_ENTITY = "/ESAllPrim(1)"; - private static final String URI_MEDIA_STREAM = "/ESMedia(1)/$value"; - private static final String URI_REFERENCES = "/ESAllPrim/$ref"; - private static final String URI_REFERENCE = "/ESAllPrim(1)/$ref"; - private static final String URI_PROPERTY_COMPLEX = "/ESCompComp(1)/PropertyComplex"; - private static final String URI_PROPERTY_COMPLEX_COLLECTION = - "/ESCompCollComp(1)/PropertyComplex/CollPropertyComplex"; - private static final String URI_PROPERTY_COMPLEX_COLLECTION_COUNT = - "/ESCompCollComp(1)/PropertyComplex/CollPropertyComplex/$count"; - private static final String URI_PROPERTY_PRIMITIVE = "/ESAllPrim(1)/PropertyString"; - private static final String URI_PROPERTY_PRIMITIVE_COLLECTION = "/ESCollAllPrim/CollPropertyString"; - private static final String URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT = - "/ESCollAllPrim/CollPropertyString/$count"; - private static final String URI_PROPERTY_PRIMITIVE_VALUE = "/ESAllPrim(1)/PropertyString/$value"; - private static final String URI_SINGLETON = "/SI"; - private static final String URI_NAV_ENTITY = "/ESKeyNav/NavPropertyETKeyNavOne"; - private static final String URI_NAV_ENTITY_SET = "/ESKeyNav/NavPropertyETKeyNavMany"; - - private static final String QO_FILTER = "$filter='1' eq '1'"; - private static final String QO_FORMAT = "$format=bla"; - private static final String QO_EXPAND = "$expand=*"; - private static final String QO_ID = "$id=Products(0)"; - private static final String QO_COUNT = "$count"; - private static final String QO_ORDERBY = "$orderby=true"; -// private static final String QO_SEARCH = "$search='bla'"; - private static final String QO_SELECT = "$select=*"; - private static final String QO_SKIP = "$skip=3"; - private static final String QO_SKIPTOKEN = "$skiptoken=123"; - private static final String QO_LEVELS = "$expand=*($levels=1)"; - private static final String QO_TOP = "$top=1"; - - private String[][] urisWithValidSystemQueryOptions = { - { URI_ALL, QO_FILTER, }, { URI_ALL, QO_FORMAT }, { URI_ALL, QO_EXPAND }, { URI_ALL, QO_COUNT }, - { URI_ALL, QO_ORDERBY }, /* { URI_ALL, QO_SEARCH }, */{ URI_ALL, QO_SELECT }, { URI_ALL, QO_SKIP }, - { URI_ALL, QO_SKIPTOKEN }, { URI_ALL, QO_LEVELS }, - - { URI_CROSSJOIN, QO_FILTER, }, { URI_CROSSJOIN, QO_FORMAT }, - { URI_CROSSJOIN, QO_EXPAND }, { URI_CROSSJOIN, QO_COUNT }, { URI_CROSSJOIN, QO_ORDERBY }, - /* { URI_CROSSJOIN, QO_SEARCH }, */{ URI_CROSSJOIN, QO_SELECT }, { URI_CROSSJOIN, QO_SKIP }, - { URI_CROSSJOIN, QO_SKIPTOKEN }, { URI_CROSSJOIN, QO_LEVELS }, { URI_CROSSJOIN, QO_TOP }, - - { URI_ENTITY_ID, QO_ID, QO_FORMAT }, { URI_ENTITY_ID, QO_ID, }, { URI_ENTITY_ID, QO_ID, QO_EXPAND }, - { URI_ENTITY_ID, QO_ID, QO_SELECT }, { URI_ENTITY_ID, QO_ID, QO_LEVELS }, - - { URI_METADATA, QO_FORMAT }, - - { URI_SERVICE, QO_FORMAT }, - - { URI_ENTITY_SET, QO_FILTER, }, { URI_ENTITY_SET, QO_FORMAT }, { URI_ENTITY_SET, QO_EXPAND }, - { URI_ENTITY_SET, QO_COUNT }, { URI_ENTITY_SET, QO_ORDERBY }, /* { URI_ENTITY_SET, QO_SEARCH }, */ - { URI_ENTITY_SET, QO_SELECT }, - { URI_ENTITY_SET, QO_SKIP }, { URI_ENTITY_SET, QO_SKIPTOKEN }, { URI_ENTITY_SET, QO_LEVELS }, - { URI_ENTITY_SET, QO_TOP }, - - { URI_ENTITY_SET_COUNT, QO_FILTER }, /* { URI_ENTITY_SET_COUNT, QO_SEARCH }, */ - - { URI_ENTITY, QO_FORMAT }, { URI_ENTITY, QO_EXPAND }, { URI_ENTITY, QO_SELECT }, { URI_ENTITY, QO_LEVELS }, - - { URI_MEDIA_STREAM, QO_FORMAT }, - - { URI_REFERENCES, QO_FILTER }, { URI_REFERENCES, QO_FORMAT }, { URI_REFERENCES, QO_ORDERBY }, - /* { URI_REFERENCES, QO_SEARCH }, */{ URI_REFERENCES, QO_SKIP }, { URI_REFERENCES, QO_SKIPTOKEN }, - { URI_REFERENCES, QO_TOP }, - - { URI_REFERENCE, QO_FORMAT }, - - { URI_PROPERTY_COMPLEX, QO_FORMAT }, { URI_PROPERTY_COMPLEX, QO_SELECT }, { URI_PROPERTY_COMPLEX, QO_EXPAND }, - { URI_PROPERTY_COMPLEX, QO_LEVELS }, - - { URI_PROPERTY_COMPLEX_COLLECTION, QO_FILTER }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_FORMAT }, - { URI_PROPERTY_COMPLEX_COLLECTION, QO_EXPAND }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_COUNT }, - { URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIP }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_SKIPTOKEN }, - { URI_PROPERTY_COMPLEX_COLLECTION, QO_LEVELS }, { URI_PROPERTY_COMPLEX_COLLECTION, QO_TOP }, - { URI_PROPERTY_COMPLEX_COLLECTION, QO_ORDERBY }, - - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FILTER }, /* { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SEARCH }, */ - - { URI_PROPERTY_PRIMITIVE, QO_FORMAT }, - - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FILTER }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_FORMAT }, - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ORDERBY }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SKIP }, - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SKIPTOKEN }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_TOP }, - - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_FILTER }, - /* { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SEARCH }, */ - - { URI_PROPERTY_PRIMITIVE_VALUE, QO_FORMAT }, - - { URI_SINGLETON, QO_FORMAT }, { URI_SINGLETON, QO_EXPAND }, { URI_SINGLETON, QO_SELECT }, - { URI_SINGLETON, QO_LEVELS }, - - { URI_NAV_ENTITY, QO_FORMAT }, { URI_NAV_ENTITY, QO_EXPAND }, { URI_NAV_ENTITY, QO_SELECT }, - { URI_NAV_ENTITY, QO_LEVELS }, - - { URI_NAV_ENTITY_SET, QO_FILTER, }, { URI_NAV_ENTITY_SET, QO_FORMAT }, { URI_NAV_ENTITY_SET, QO_EXPAND }, - { URI_NAV_ENTITY_SET, QO_COUNT }, { URI_NAV_ENTITY_SET, QO_ORDERBY }, - /* { URI_NAV_ENTITY_SET, QO_SEARCH }, */{ URI_NAV_ENTITY_SET, QO_SELECT }, { URI_NAV_ENTITY_SET, QO_SKIP }, - { URI_NAV_ENTITY_SET, QO_SKIPTOKEN }, { URI_NAV_ENTITY_SET, QO_LEVELS }, { URI_NAV_ENTITY_SET, QO_TOP }, - - { "FINRTInt16()" }, - { "FICRTETKeyNav()" }, - { "FICRTESTwoKeyNavParam(ParameterInt16=1)" }, - { "FICRTCollString()" }, - { "FICRTCTTwoPrim()" }, - { "FICRTCollCTTwoPrim()" }, - { "FICRTETMedia()" }, - - { "ESTwoKeyNav/com.sap.odata.test1.BAESTwoKeyNavRTESTwoKeyNav" }, - { "ESAllPrim/com.sap.odata.test1.BAESAllPrimRTETAllPrim" }, - { "AIRTPrimCollParam" }, - { "AIRTETParam" }, - { "AIRTPrimParam" }, - - }; - - private String[][] urisWithNonValidSystemQueryOptions = { - { URI_ALL, QO_ID, }, { URI_ALL, QO_TOP }, - - { URI_BATCH, QO_FILTER, }, { URI_BATCH, QO_FORMAT }, { URI_BATCH, QO_ID, }, { URI_BATCH, QO_EXPAND }, - { URI_BATCH, QO_COUNT }, { URI_BATCH, QO_ORDERBY }, /* { URI_BATCH, QO_SEARCH }, */{ URI_BATCH, QO_SELECT }, - { URI_BATCH, QO_SKIP }, { URI_BATCH, QO_SKIPTOKEN }, { URI_BATCH, QO_LEVELS }, { URI_BATCH, QO_TOP }, - - { URI_CROSSJOIN, QO_ID, }, - - { URI_ENTITY_ID, QO_ID, QO_FILTER, }, - { URI_ENTITY_ID, QO_ID, QO_COUNT }, { URI_ENTITY_ID, QO_ORDERBY }, /* { URI_ENTITY_ID, QO_SEARCH }, */ - - { URI_ENTITY_ID, QO_ID, QO_SKIP }, { URI_ENTITY_ID, QO_ID, QO_SKIPTOKEN }, { URI_ENTITY_ID, QO_ID, QO_TOP }, - - { URI_METADATA, QO_FILTER, }, { URI_METADATA, QO_ID, }, { URI_METADATA, QO_EXPAND }, - { URI_METADATA, QO_COUNT }, { URI_METADATA, QO_ORDERBY }, /* { URI_METADATA, QO_SEARCH }, */ - { URI_METADATA, QO_SELECT }, { URI_METADATA, QO_SKIP }, { URI_METADATA, QO_SKIPTOKEN }, - { URI_METADATA, QO_LEVELS }, { URI_METADATA, QO_TOP }, - - { URI_SERVICE, QO_FILTER }, { URI_SERVICE, QO_ID }, { URI_SERVICE, QO_EXPAND }, { URI_SERVICE, QO_COUNT }, - { URI_SERVICE, QO_ORDERBY }, /* { URI_SERVICE, QO_SEARCH }, */{ URI_SERVICE, QO_SELECT }, - { URI_SERVICE, QO_SKIP }, { URI_SERVICE, QO_SKIPTOKEN }, { URI_SERVICE, QO_LEVELS }, { URI_SERVICE, QO_TOP }, - - { URI_ENTITY_SET, QO_ID }, - - { URI_ENTITY_SET_COUNT, QO_FORMAT }, { URI_ENTITY_SET_COUNT, QO_ID }, - { URI_ENTITY_SET_COUNT, QO_EXPAND }, { URI_ENTITY_SET_COUNT, QO_COUNT }, - { URI_ENTITY_SET_COUNT, QO_ORDERBY }, - { URI_ENTITY_SET_COUNT, QO_SELECT }, { URI_ENTITY_SET_COUNT, QO_SKIP }, { URI_ENTITY_SET_COUNT, QO_SKIPTOKEN }, - { URI_ENTITY_SET_COUNT, QO_LEVELS }, { URI_ENTITY_SET_COUNT, QO_TOP }, - - { URI_ENTITY, QO_FILTER }, { URI_ENTITY, QO_ID }, { URI_ENTITY, QO_COUNT }, /* { URI_ENTITY, QO_ORDERBY }, */ - /* { URI_ENTITY, QO_SEARCH }, */{ URI_ENTITY, QO_SKIP }, { URI_ENTITY, QO_SKIPTOKEN }, { URI_ENTITY, QO_TOP }, - - { URI_MEDIA_STREAM, QO_FILTER }, { URI_MEDIA_STREAM, QO_ID, }, { URI_MEDIA_STREAM, QO_EXPAND }, - { URI_MEDIA_STREAM, QO_COUNT }, { URI_MEDIA_STREAM, QO_ORDERBY }, /* { URI_MEDIA_STREAM, QO_SEARCH }, */ - { URI_MEDIA_STREAM, QO_SELECT }, { URI_MEDIA_STREAM, QO_SKIP }, { URI_MEDIA_STREAM, QO_SKIPTOKEN }, - { URI_MEDIA_STREAM, QO_LEVELS }, { URI_MEDIA_STREAM, QO_TOP }, - - { URI_REFERENCES, QO_ID, }, { URI_REFERENCES, QO_EXPAND }, { URI_REFERENCES, QO_COUNT }, - { URI_REFERENCES, QO_SELECT }, { URI_REFERENCES, QO_LEVELS }, - - { URI_REFERENCE, QO_FILTER }, { URI_REFERENCE, QO_ID, }, { URI_REFERENCE, QO_EXPAND }, - { URI_REFERENCE, QO_COUNT }, { URI_REFERENCE, QO_ORDERBY }, /* { URI_REFERENCE, QO_SEARCH }, */ - { URI_REFERENCE, QO_SELECT }, { URI_REFERENCE, QO_SKIP }, { URI_REFERENCE, QO_SKIPTOKEN }, - { URI_REFERENCE, QO_LEVELS }, { URI_REFERENCE, QO_TOP }, - - { URI_PROPERTY_COMPLEX, QO_FILTER }, { URI_PROPERTY_COMPLEX, QO_ID, }, { URI_PROPERTY_COMPLEX, QO_COUNT }, - { URI_PROPERTY_COMPLEX, QO_ORDERBY }, /* { URI_PROPERTY_COMPLEX, QO_SEARCH }, */ - { URI_PROPERTY_COMPLEX, QO_SKIP }, { URI_PROPERTY_COMPLEX, QO_SKIPTOKEN }, { URI_PROPERTY_COMPLEX, QO_TOP }, - - { URI_PROPERTY_COMPLEX_COLLECTION, QO_ID, }, - /* { URI_PROPERTY_COMPLEX_COLLECTION, QO_SEARCH }, */{ URI_PROPERTY_COMPLEX_COLLECTION, QO_SELECT }, - - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_FORMAT }, - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_ID, }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_EXPAND }, - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_COUNT }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_ORDERBY }, - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SELECT }, - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SKIP }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_SKIPTOKEN }, - { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_LEVELS }, { URI_PROPERTY_COMPLEX_COLLECTION_COUNT, QO_TOP }, - - { URI_PROPERTY_PRIMITIVE, QO_FILTER }, { URI_PROPERTY_PRIMITIVE, QO_ID, }, { URI_PROPERTY_PRIMITIVE, QO_EXPAND }, - { URI_PROPERTY_PRIMITIVE, QO_COUNT }, { URI_PROPERTY_PRIMITIVE, QO_ORDERBY }, - /* { URI_PROPERTY_PRIMITIVE, QO_SEARCH }, */{ URI_PROPERTY_PRIMITIVE, QO_SELECT }, - { URI_PROPERTY_PRIMITIVE, QO_SKIP }, { URI_PROPERTY_PRIMITIVE, QO_SKIPTOKEN }, - { URI_PROPERTY_PRIMITIVE, QO_LEVELS }, { URI_PROPERTY_PRIMITIVE, QO_TOP }, - - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_ID, }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_EXPAND }, - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_COUNT }, /* { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SEARCH }, */ - { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_COLLECTION, QO_LEVELS }, - - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_FORMAT }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_ID, }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_EXPAND }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_COUNT }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_ORDERBY }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIP }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_SKIPTOKEN }, - { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_LEVELS }, { URI_PROPERTY_PRIMITIVE_COLLECTION_COUNT, QO_TOP }, - - { URI_PROPERTY_PRIMITIVE_VALUE, QO_FILTER }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_ID, }, - { URI_PROPERTY_PRIMITIVE_VALUE, QO_EXPAND }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_COUNT }, - { URI_PROPERTY_PRIMITIVE_VALUE, QO_ORDERBY },/* { URI_PROPERTY_PRIMITIVE_VALUE, QO_SEARCH }, */ - { URI_PROPERTY_PRIMITIVE_VALUE, QO_SELECT }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_SKIP }, - { URI_PROPERTY_PRIMITIVE_VALUE, QO_SKIPTOKEN }, { URI_PROPERTY_PRIMITIVE_VALUE, QO_LEVELS }, - { URI_PROPERTY_PRIMITIVE_VALUE, QO_TOP }, - - { URI_SINGLETON, QO_FILTER }, { URI_SINGLETON, QO_ID }, { URI_SINGLETON, QO_COUNT }, - { URI_SINGLETON, QO_ORDERBY }, /* { URI_SINGLETON, QO_SEARCH }, */{ URI_SINGLETON, QO_SKIP }, - { URI_SINGLETON, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP }, - - { URI_NAV_ENTITY, QO_FILTER }, { URI_NAV_ENTITY, QO_ID }, { URI_NAV_ENTITY, QO_COUNT }, - { URI_NAV_ENTITY, QO_ORDERBY }, /* { URI_NAV_ENTITY, QO_SEARCH }, */{ URI_NAV_ENTITY, QO_SKIP }, - { URI_NAV_ENTITY, QO_SKIPTOKEN }, { URI_SINGLETON, QO_TOP }, - - { URI_NAV_ENTITY_SET, QO_ID }, - - }; - - private Parser parser; - private Edm edm; - - @Before - public void before() { - parser = new Parser(); - edm = new EdmProviderImpl(new EdmTechProvider()); - } - - @Test - public void validateSelect() throws Exception { - String[] uris = { "/ESAllPrim(1)?$select=PropertyString" }; - for (String uri : uris) { - parseAndValidate(uri, "GET"); - } - } - - @Test(expected = UriValidationException.class) - public void validateForHttpMethodsFail() throws Exception { - String uri = URI_ENTITY; - parseAndValidate(uri, "xyz"); - } - - @Test - public void validateForHttpMethods() throws Exception { - String uri = URI_ENTITY; - parseAndValidate(uri, "GET"); - parseAndValidate(uri, "POST"); - parseAndValidate(uri, "PUT"); - parseAndValidate(uri, "DELETE"); - parseAndValidate(uri, "PATCH"); - parseAndValidate(uri, "MERGE"); - } - - @Test - public void validateOrderBy() throws Exception { - String[] uris = { "/ESAllPrim?$orderby=PropertyString" }; - for (String uri : uris) { - parseAndValidate(uri, "GET"); - } - } - - @Test(expected = UriValidationException.class) - @Ignore("uri parser doen't support orderby yet") - public void validateOrderByInvalid() throws Exception { - String uri = "/ESAllPrim(1)?$orderBy=XXXX"; - parseAndValidate(uri, "GET"); - } - - @Test(expected = UriValidationException.class) - public void validateKeyPredicatesWrongKey() throws Exception { - String uri = "ESTwoKeyNav(xxx=1, yyy='abc')"; - parseAndValidate(uri, "GET"); - } - - @Test - public void validateKeyPredicates() throws Exception { - String uri = "ESTwoKeyNav(PropertyInt16=1, PropertyString='abc')"; - parseAndValidate(uri, "GET"); - } - - @Test(expected = UriValidationException.class) - public void validateKeyPredicatesWrongValueType() throws Exception { - String uri = "ESTwoKeyNav(PropertyInt16='abc', PropertyString=1)"; - parseAndValidate(uri, "GET"); - } - - @Test - public void checkValidSystemQueryOption() throws Exception { - String[] uris = constructUri(urisWithValidSystemQueryOptions); - - for (String uri : uris) { - try { - parseAndValidate(uri, "GET"); - } catch (Exception e) { - throw new Exception("Faild for uri: " + uri, e); - } - } - } - - @Test - public void checkNonValidSystemQueryOption() throws Exception { - String[] uris = constructUri(urisWithNonValidSystemQueryOptions); - - for (String uri : uris) { - try { - parseAndValidate(uri, "GET"); - fail("Validation Exception not thrown: " + uri); - } catch (UriValidationException e) { - assertTrue(e instanceof UriValidationException); - } - } - } - - private String[] constructUri(final String[][] uriParameterMatrix) { - ArrayList uris = new ArrayList(); - for (String[] uriParameter : uriParameterMatrix) { - String uri = uriParameter[0]; - if (uriParameter.length > 1) { - uri += "?"; - } - for (int i = 1; i < uriParameter.length; i++) { - uri += uriParameter[i]; - if (i < (uriParameter.length - 1)) { - uri += "&"; - } - } - uris.add(uri); - } - return uris.toArray(new String[0]); - } - - private void parseAndValidate(final String uri, String method) throws UriParserException, UriValidationException { - UriInfo uriInfo = parser.parseUri(uri.trim(), edm); - UriValidator validator = new UriValidator(); - - validator.validate(uriInfo, method); - } - -}