http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3fa2b3df/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java index 16ec8ba..5a4ee5b 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/SchemaProvider.java @@ -19,43 +19,39 @@ package org.apache.olingo.server.tecsvc.provider; import java.util.ArrayList; +import java.util.Collections; import java.util.List; -import org.apache.olingo.commons.api.ex.ODataException; import org.apache.olingo.commons.api.edm.provider.CsdlAction; import org.apache.olingo.commons.api.edm.provider.CsdlComplexType; +import org.apache.olingo.commons.api.edm.provider.CsdlEdmProvider; import org.apache.olingo.commons.api.edm.provider.CsdlEntityType; -import org.apache.olingo.commons.api.edm.provider.CsdlEnumType; import org.apache.olingo.commons.api.edm.provider.CsdlFunction; import org.apache.olingo.commons.api.edm.provider.CsdlSchema; -import org.apache.olingo.commons.api.edm.provider.CsdlTypeDefinition; +import org.apache.olingo.commons.api.ex.ODataException; public class SchemaProvider { - private EdmTechProvider prov; - public static final String NAMESPACE = "olingo.odata.test1"; + private final CsdlEdmProvider prov; + public SchemaProvider(final EdmTechProvider prov) { this.prov = prov; } public List<CsdlSchema> getSchemas() throws ODataException { - List<CsdlSchema> schemas = new ArrayList<CsdlSchema>(); CsdlSchema schema = new CsdlSchema(); schema.setNamespace(NAMESPACE); schema.setAlias("Namespace1_Alias"); - schemas.add(schema); // EnumTypes - List<CsdlEnumType> enumTypes = new ArrayList<CsdlEnumType>(); - schema.setEnumTypes(enumTypes); + schema.setEnumTypes(Collections.singletonList( + prov.getEnumType(EnumTypeProvider.nameENString))); // TypeDefinitions - List<CsdlTypeDefinition> typeDefinitions = new ArrayList<CsdlTypeDefinition>(); - schema.setTypeDefinitions(typeDefinitions); - typeDefinitions.add(prov.getTypeDefinition(TypeDefinitionProvider.nameTDString)); - enumTypes.add(prov.getEnumType(EnumTypeProvider.nameENString)); + schema.setTypeDefinitions(Collections.singletonList( + prov.getTypeDefinition(TypeDefinitionProvider.nameTDString))); // EntityTypes List<CsdlEntityType> entityTypes = new ArrayList<CsdlEntityType>(); @@ -89,24 +85,24 @@ public class SchemaProvider { entityTypes.add(prov.getEntityType(EntityTypeProvider.nameETAbstractBase)); // ComplexTypes - List<CsdlComplexType> complexType = new ArrayList<CsdlComplexType>(); - schema.setComplexTypes(complexType); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTPrim)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTAllPrim)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCollAllPrim)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoPrim)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixPrimCollComp)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTMixEnumDef)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTBase)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBase)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompComp)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompCollComp)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTPrimComp)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTNavFiveProp)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBasePrimCompNav)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTCompNav)); - complexType.add(prov.getComplexType(ComplexTypeProvider.nameCTNavCont)); + List<CsdlComplexType> complexTypes = new ArrayList<CsdlComplexType>(); + schema.setComplexTypes(complexTypes); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTPrim)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTAllPrim)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTCollAllPrim)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoPrim)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTMixPrimCollComp)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTMixEnumDef)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTBase)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBase)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTCompComp)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTCompCollComp)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTPrimComp)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTNavFiveProp)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTBasePrimCompNav)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTTwoBasePrimCompNav)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTCompNav)); + complexTypes.add(prov.getComplexType(ComplexTypeProvider.nameCTNavCont)); // Actions List<CsdlAction> actions = new ArrayList<CsdlAction>(); @@ -158,6 +154,7 @@ public class SchemaProvider { functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETMixPrimCollCompTwoParam)); functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTCollCTNavFiveProp)); functions.addAll(prov.getFunctions(FunctionProvider.nameUFCRTCollETKeyNavContParam)); + functions.addAll(prov.getFunctions(FunctionProvider.nameUFNRTByteNineParam)); functions.addAll(prov.getFunctions(FunctionProvider.nameBFCESTwoKeyNavRTESTwoKeyNav)); functions.addAll(prov.getFunctions(FunctionProvider.nameBFCStringRTESTwoKeyNav)); @@ -195,7 +192,7 @@ public class SchemaProvider { // EntityContainer schema.setEntityContainer(prov.getEntityContainer()); - return schemas; + return Collections.singletonList(schema); } }
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3fa2b3df/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerFunctionParametersTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerFunctionParametersTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerFunctionParametersTest.java new file mode 100644 index 0000000..7460e2a --- /dev/null +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerFunctionParametersTest.java @@ -0,0 +1,121 @@ +/* + * 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.deserializer.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + +import java.util.List; + +import org.apache.olingo.commons.api.data.Parameter; +import org.apache.olingo.commons.api.data.Property; +import org.apache.olingo.commons.api.edm.FullQualifiedName; +import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.deserializer.DeserializerException; +import org.apache.olingo.server.api.deserializer.DeserializerException.MessageKeys; +import org.apache.olingo.server.core.deserializer.AbstractODataDeserializerTest; +import org.junit.Test; + +public class ODataJsonDeserializerFunctionParametersTest extends AbstractODataDeserializerTest { + + @Test + public void empty() throws Exception { + final Parameter parameter = deserialize("{}", "UFCRTETTwoKeyNavParamCTTwoPrim", "ParameterCTTwoPrim"); + assertNotNull(parameter); + assertTrue(parameter.isComplex()); + } + + @Test + public void primitive() throws Exception { + final Parameter parameter = deserialize("'test'", "UFCRTCollStringTwoParam", "ParameterString"); + assertNotNull(parameter); + assertTrue(parameter.isPrimitive()); + assertFalse(parameter.isCollection()); + assertEquals("test", parameter.getValue()); + } + + @Test + public void complex() throws Exception { + final Parameter parameter = deserialize("{ \"PropertyString\": \"Yes\", \"PropertyInt16\": 42 }", + "UFCRTETTwoKeyNavParamCTTwoPrim", "ParameterCTTwoPrim"); + assertNotNull(parameter); + assertTrue(parameter.isComplex()); + assertFalse(parameter.isCollection()); + final List<Property> complexValues = parameter.asComplex().getValue(); + assertEquals((short) 42, complexValues.get(0).getValue()); + assertEquals("Yes", complexValues.get(1).getValue()); + } + + @Test + public void ignoreODataAnnotations() throws Exception { + final Parameter parameter = deserialize("{\"[email protected]\":\"Edm.Int16\",\"PropertyInt16\":42," + + "\"PropertyString\":\"Test\"}", + "UFCRTETTwoKeyNavParamCTTwoPrim", "ParameterCTTwoPrim"); + assertNotNull(parameter); + assertTrue(parameter.isComplex()); + assertFalse(parameter.isCollection()); + final List<Property> complexValues = parameter.asComplex().getValue(); + assertEquals((short) 42, complexValues.get(0).getValue()); + assertEquals("Test", complexValues.get(1).getValue()); + } + + @Test + public void parameterWithNullLiteral() throws Exception { + final Parameter parameter = deserialize(null, "UFCRTCollCTTwoPrimTwoParam", "ParameterString"); + assertNotNull(parameter); + assertEquals(null, parameter.getValue()); + + expectException(null, "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + } + + @Test + public void noContent() throws Exception { + expectException("", "UFCRTETTwoKeyNavParamCTTwoPrim", "ParameterCTTwoPrim", MessageKeys.JSON_SYNTAX_EXCEPTION); + } + + @Test + public void wrongType() throws Exception { + expectException("null", "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + expectException("\"42\"", "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + expectException("'42'", "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + expectException("123456", "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + expectException("[42]", "UFCRTStringTwoParam", "ParameterInt16", MessageKeys.INVALID_VALUE_FOR_PROPERTY); + } + + private Parameter deserialize(final String input, final String functionName, final String parameterName) + throws DeserializerException { + return OData.newInstance().createFixedFormatDeserializer() + .parameter(input, + edm.getUnboundFunctions(new FullQualifiedName(NAMESPACE, functionName)).get(0) + .getParameter(parameterName)); + } + + private void expectException(final String input, final String functionName, final String parameterName, + final DeserializerException.MessageKeys messageKey) { + try { + deserialize(input, functionName, parameterName); + fail("Expected exception not thrown."); + } catch (final DeserializerException e) { + assertEquals(messageKey, e.getMessageKey()); + } + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3fa2b3df/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java index 2a46711..12a5edc 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java @@ -80,7 +80,7 @@ public class ServiceDocumentTest { assertTrue(jsonString.contains("FunctionImport")); assertTrue(jsonString.contains("SI")); - assertTrue(jsonString.contains("Simple Singelton")); + assertTrue(jsonString.contains("Simple Singleton")); assertTrue(jsonString.contains("SINav")); assertTrue(jsonString.contains("SIMedia")); assertTrue(jsonString.contains("Singleton")); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3fa2b3df/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java index dc90901..20bdade 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java @@ -18,27 +18,27 @@ */ package org.apache.olingo.server.core.uri; +import static org.junit.Assert.assertArrayEquals; import static org.junit.Assert.assertEquals; import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; -import java.util.ArrayList; +import java.util.Arrays; import java.util.Collections; -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.ex.ODataRuntimeException; import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.edmx.EdmxReference; -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.UriInfo; 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.api.uri.UriResourceAction; +import org.apache.olingo.server.api.uri.UriResourceEntitySet; +import org.apache.olingo.server.api.uri.queryoption.AliasQueryOption; +import org.apache.olingo.server.api.uri.queryoption.QueryOption; +import org.apache.olingo.server.core.uri.queryoption.AliasQueryOptionImpl; 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; @@ -47,7 +47,6 @@ 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; @@ -63,56 +62,39 @@ public class UriInfoImplTest { new EdmTechProvider(), Collections.<EdmxReference> emptyList()).getEdm(); @Test - public void testKind() { - UriInfoImpl uriInfo = new UriInfoImpl().setKind(UriInfoKind.all); + public void kind() { + final UriInfo 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); - + public void casts() { + final UriInfo uriInfo = new UriInfoImpl(); + + assertEquals(uriInfo, uriInfo.asUriInfoAll()); + assertEquals(uriInfo, uriInfo.asUriInfoBatch()); + assertEquals(uriInfo, uriInfo.asUriInfoCrossjoin()); + assertEquals(uriInfo, uriInfo.asUriInfoEntityId()); + assertEquals(uriInfo, uriInfo.asUriInfoMetadata()); + assertEquals(uriInfo, uriInfo.asUriInfoResource()); + assertEquals(uriInfo, uriInfo.asUriInfoService()); } @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)); - + public void entityNames() { + final UriInfo uriInfo = new UriInfoImpl() + .addEntitySetName("A") + .addEntitySetName("B"); + assertArrayEquals(new String[] { "A", "B" }, uriInfo.getEntitySetNames().toArray()); } @Test - public void testResourceParts() { + public void resourceParts() { UriInfoImpl uriInfo = new UriInfoImpl(); - UriResourceActionImpl action = new UriResourceActionImpl(); - UriResourceEntitySetImpl entitySet0 = new UriResourceEntitySetImpl(); - UriResourceEntitySetImpl entitySet1 = new UriResourceEntitySetImpl(); + final UriResourceAction action = new UriResourceActionImpl(); + final UriResourceEntitySet entitySet0 = new UriResourceEntitySetImpl(); + final UriResourceEntitySet entitySet1 = new UriResourceEntitySetImpl(); uriInfo.addResourcePart(action); uriInfo.addResourcePart(entitySet0); @@ -129,53 +111,52 @@ public class UriInfoImplTest { @Test(expected = ODataRuntimeException.class) public void doubleSystemQueryOptions() { new UriInfoImpl() - .setSystemQueryOption(new FormatOptionImpl()) - .setSystemQueryOption(new FormatOptionImpl()); + .setSystemQueryOption(new FormatOptionImpl()) + .setSystemQueryOption(new FormatOptionImpl()); } @Test - public void testCustomQueryOption() { - UriInfoImpl uriInfo = new UriInfoImpl(); - - List<QueryOptionImpl> queryOptions = new ArrayList<QueryOptionImpl>(); - - ExpandOptionImpl expand = new ExpandOptionImpl(); - FilterOptionImpl filter = new FilterOptionImpl(); - FormatOptionImpl format = new FormatOptionImpl(); - IdOptionImpl id = new IdOptionImpl(); - CountOptionImpl inlinecount = new CountOptionImpl(); - OrderByOptionImpl orderby = new OrderByOptionImpl(); - SearchOptionImpl search = new SearchOptionImpl(); - SelectOptionImpl select = new SelectOptionImpl(); - SkipOptionImpl skip = new SkipOptionImpl(); - SkipTokenOptionImpl skipToken = new SkipTokenOptionImpl(); - TopOptionImpl top = new TopOptionImpl(); - LevelsOptionImpl levels = new LevelsOptionImpl(); - - CustomQueryOptionImpl customOption0 = new CustomQueryOptionImpl(); - customOption0.setText("A"); - CustomQueryOptionImpl customOption1 = new CustomQueryOptionImpl(); - customOption1.setText("B"); - - QueryOptionImpl queryOption = new CustomQueryOptionImpl(); - - queryOptions.add(expand.setName("")); - queryOptions.add(filter.setName("")); - queryOptions.add(format.setName("")); - queryOptions.add(id.setName("")); - queryOptions.add(inlinecount.setName("")); - queryOptions.add(orderby.setName("")); - queryOptions.add(search.setName("")); - queryOptions.add(select.setName("")); - queryOptions.add(skip.setName("")); - queryOptions.add(skipToken.setName("")); - queryOptions.add(top.setName("")); - queryOptions.add(customOption0.setName("")); - queryOptions.add(customOption1.setName("")); - queryOptions.add(levels.setName(""));// not stored - queryOptions.add(queryOption.setName(""));// not stored - uriInfo.setQueryOptions(queryOptions); - + public void customQueryOption() { + final QueryOption expand = new ExpandOptionImpl().setName(""); + final QueryOption filter = new FilterOptionImpl().setName(""); + final QueryOption format = new FormatOptionImpl().setName(""); + final QueryOption id = new IdOptionImpl().setName(""); + final QueryOption inlinecount = new CountOptionImpl().setName(""); + final QueryOption orderby = new OrderByOptionImpl().setName(""); + final QueryOption search = new SearchOptionImpl().setName(""); + final QueryOption select = new SelectOptionImpl().setName(""); + final QueryOption skip = new SkipOptionImpl().setName(""); + final QueryOption skipToken = new SkipTokenOptionImpl().setName(""); + final QueryOption top = new TopOptionImpl().setName(""); + final QueryOption levels = new LevelsOptionImpl().setName(""); + + final QueryOption customOption0 = new CustomQueryOptionImpl().setName("").setText("A"); + final QueryOption customOption1 = new CustomQueryOptionImpl().setName("").setText("B"); + + final QueryOption initialQueryOption = new CustomQueryOptionImpl(); + + final QueryOption alias = new AliasQueryOptionImpl().setName("alias").setText("C"); + + final UriInfo uriInfo = new UriInfoImpl() + .setQueryOptions(Arrays.asList( + expand, + filter, + format, + id, + inlinecount, + orderby, + search, + select, + skip, + skipToken, + top, + customOption0, + customOption1, + levels, + initialQueryOption, + alias)); + + assertEquals(12, uriInfo.getSystemQueryOptions().size()); assertEquals(expand, uriInfo.getExpandOption()); assertEquals(filter, uriInfo.getFilterOption()); assertEquals(format, uriInfo.getFormatOption()); @@ -188,25 +169,44 @@ public class UriInfoImplTest { assertEquals(skipToken, uriInfo.getSkipTokenOption()); assertEquals(top, uriInfo.getTopOption()); - List<CustomQueryOption> customQueryOptions = uriInfo.getCustomQueryOptions(); - assertEquals(customOption0, customQueryOptions.get(0)); - assertEquals(customOption1, customQueryOptions.get(1)); + assertArrayEquals(new QueryOption[] { alias }, uriInfo.getAliases().toArray()); + assertEquals("C", uriInfo.getValueForAlias("alias")); + + assertArrayEquals(new QueryOption[] { customOption0, customOption1, initialQueryOption }, + uriInfo.getCustomQueryOptions().toArray()); } @Test - public void testFragment() { - UriInfoImpl uriInfo = new UriInfoImpl(); - uriInfo.setFragment("F"); + public void fragment() { + final UriInfo uriInfo = new UriInfoImpl().setFragment("F"); assertEquals("F", uriInfo.getFragment()); } @Test - public void testEntityTypeCast() { - UriInfoImpl uriInfo = new UriInfoImpl(); - EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); + public void entityTypeCast() { + final EdmEntityType entityType = edm.getEntityType(EntityTypeProvider.nameETKeyNav); assertNotNull(entityType); - uriInfo.setEntityTypeCast(entityType); + final UriInfo uriInfo = new UriInfoImpl() + .setEntityTypeCast(entityType); assertEquals(entityType, uriInfo.getEntityTypeCast()); } + + @Test + public void alias() { + final UriInfo uriInfo = new UriInfoImpl() + .addAlias((AliasQueryOption) new AliasQueryOptionImpl().setName("A").setText("notUsed")) + .addAlias((AliasQueryOption) new AliasQueryOptionImpl().setName("A").setText("X")) + .addAlias((AliasQueryOption) new AliasQueryOptionImpl().setName("B").setText("Y")) + .addAlias((AliasQueryOption) new AliasQueryOptionImpl().setName("C").setText("Z")); + + assertEquals(3, uriInfo.getAliases().size()); + assertEquals("X", uriInfo.getValueForAlias("A")); + assertEquals("Y", uriInfo.getValueForAlias("B")); + assertEquals("Z", uriInfo.getValueForAlias("C")); + assertNull(uriInfo.getValueForAlias("D")); + + assertTrue(uriInfo.getSystemQueryOptions().isEmpty()); + assertTrue(uriInfo.getCustomQueryOptions().isEmpty()); + } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/3fa2b3df/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java index fc48b9d..e0f5738 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/antlr/TestFullResourcePath.java @@ -5527,13 +5527,11 @@ public class TestFullResourcePath { } @Test - public void testAlias() throws Exception { + public void alias() throws Exception { testUri.run("ESTwoKeyNav(PropertyInt16=1,PropertyString=@A)", "@A='2'").goPath() .isKeyPredicate(0, "PropertyInt16", "1") .isKeyPredicateAlias(1, "PropertyString", "@A") - .isInAliasToValueMap("@A", "'2'") - .goUpUriValidator() - .isCustomParameter(0, "@A", "'2'"); + .isInAliasToValueMap("@A", "'2'"); } @Test @@ -5833,6 +5831,11 @@ public class TestFullResourcePath { + "(ParameterComp=@p1) eq 0&@p1={\"PropertyInt16\":[{\"Prop1\":123,\"Prop2\":\"Test\",\"Prop3\":[1,2,3]}," + "{\"Prop1\":{\"Prop1\":[\"Prop\\\":{]\"]}}],\"ProperyString\":\"1\"}"); + testUri.run("FINRTByteNineParam(ParameterEnum=null,ParameterDef='x',ParameterComp=@c," + + "ParameterETTwoPrim=@c,CollParameterByte=@e,CollParameterEnum=@e,CollParameterDef=@e," + + "CollParameterComp=@e,CollParameterETTwoPrim=@e)", + "@c={}&@e=[]"); + testUri.runEx("ESTwoKeyNav/olingo.odata.test1.BFCESTwoKeyNavRTStringParam" + "(ParameterComp=@p1)", "@p1={\"PropertyInt16\":1,\"ProperyString\":'1'}") .isExSyntax(UriParserSyntaxException.MessageKeys.SYNTAX);
