Return-Path: X-Original-To: apmail-olingo-commits-archive@minotaur.apache.org Delivered-To: apmail-olingo-commits-archive@minotaur.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id 4753117DF3 for ; Tue, 17 Feb 2015 09:53:19 +0000 (UTC) Received: (qmail 29007 invoked by uid 500); 17 Feb 2015 09:53:16 -0000 Delivered-To: apmail-olingo-commits-archive@olingo.apache.org Received: (qmail 28912 invoked by uid 500); 17 Feb 2015 09:53:16 -0000 Mailing-List: contact commits-help@olingo.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@olingo.apache.org Delivered-To: mailing list commits@olingo.apache.org Received: (qmail 28704 invoked by uid 99); 17 Feb 2015 09:53:15 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 17 Feb 2015 09:53:15 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id B7DE5E0823; Tue, 17 Feb 2015 09:53:15 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: mibo@apache.org To: commits@olingo.apache.org Date: Tue, 17 Feb 2015 09:53:21 -0000 Message-Id: In-Reply-To: <73789f0782374dfead1a5a785f04e6ff@git.apache.org> References: <73789f0782374dfead1a5a785f04e6ff@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [07/35] olingo-odata4 git commit: [OLINGO-575] Removed V4 server code http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java deleted file mode 100644 index 038c668..0000000 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ODataJsonSerializerTest.java +++ /dev/null @@ -1,681 +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 java.io.InputStream; -import java.net.URI; -import java.util.Arrays; -import java.util.Collections; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.data.ContextURL; -import org.apache.olingo.commons.api.data.ContextURL.Suffix; -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.EntitySet; -import org.apache.olingo.commons.api.data.Property; -import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.edm.Edm; -import org.apache.olingo.commons.api.edm.EdmComplexType; -import org.apache.olingo.commons.api.edm.EdmEntityContainer; -import org.apache.olingo.commons.api.edm.EdmEntitySet; -import org.apache.olingo.commons.api.edm.EdmEntityType; -import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.commons.api.edm.EdmProperty; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.commons.core.data.PropertyImpl; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.edmx.EdmxReference; -import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; -import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.apache.olingo.server.api.serializer.EntitySerializerOptions; -import org.apache.olingo.server.api.serializer.PrimitiveSerializerOptions; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.api.uri.UriHelper; -import org.apache.olingo.server.api.uri.queryoption.CountOption; -import org.apache.olingo.server.api.uri.queryoption.ExpandItem; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; -import org.apache.olingo.server.core.serializer.ExpandSelectMock; -import org.apache.olingo.server.core.uri.UriHelperImpl; -import org.apache.olingo.server.tecsvc.data.DataProvider; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.hamcrest.CoreMatchers; -import org.junit.Assert; -import org.junit.Test; -import org.mockito.Mockito; - -public class ODataJsonSerializerTest { - - private static final Edm edm = OData.newInstance().createServiceMetadata( - new EdmTechProvider(), Collections. emptyList()).getEdm(); - private static final EdmEntityContainer entityContainer = edm.getEntityContainer( - new FullQualifiedName("olingo.odata.test1", "Container")); - private final DataProvider data = new DataProvider(); - private final ODataSerializer serializer = new ODataJsonSerializer(ODataFormat.JSON); - private final UriHelper helper = new UriHelperImpl(); - - @Test - public void entitySimple() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{" - + "\"@odata.context\":\"$metadata#ESAllPrim/$entity\"," - + "\"PropertyInt16\":32767," - + "\"PropertyString\":\"First Resource - positive values\"," - + "\"PropertyBoolean\":true," - + "\"PropertyByte\":255," - + "\"PropertySByte\":127," - + "\"PropertyInt32\":2147483647," - + "\"PropertyInt64\":9223372036854775807," - + "\"PropertySingle\":1.79E20," - + "\"PropertyDouble\":-1.79E19," - + "\"PropertyDecimal\":34," - + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," - + "\"PropertyDate\":\"2012-12-03\"," - + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," - + "\"PropertyDuration\":\"PT6S\"," - + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," - + "\"PropertyTimeOfDay\":\"03:26:05\"" - + "}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityAllPrimAllNull() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0))); - final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build())); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESAllPrim/$entity\"," - + "\"PropertyInt16\":32767," - + "\"PropertyString\":null,\"PropertyBoolean\":null," - + "\"PropertyByte\":null,\"PropertySByte\":null," - + "\"PropertyInt32\":null,\"PropertyInt64\":null," - + "\"PropertySingle\":null,\"PropertyDouble\":null,\"PropertyDecimal\":null," - + "\"PropertyBinary\":null," - + "\"PropertyDate\":null,\"PropertyDateTimeOffset\":null,\"PropertyDuration\":null," - + "\"PropertyGuid\":null,\"PropertyTimeOfDay\":null}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test(expected = SerializerException.class) - public void entityAllPrimKeyNull() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - entity.getProperties().clear(); - serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - } - - @Test - public void entityWrongData() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - entity.getProperties().get(0).setValue(ValueType.PRIMITIVE, false); - try { - serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - Assert.fail("Expected exception not thrown!"); - } catch (final SerializerException e) { - Assert.assertEquals(SerializerException.MessageKeys.WRONG_PROPERTY_VALUE, e.getMessageKey()); - final String message = e.getLocalizedMessage(); - Assert.assertThat(message, CoreMatchers.containsString("PropertyInt16")); - Assert.assertThat(message, CoreMatchers.containsString("false")); - } - } - - @Test - public void entitySetAllPrim() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - EntitySet entitySet = data.readAll(edmEntitySet); - entitySet.setCount(entitySet.getEntities().size()); - entitySet.setNext(URI.create("/next")); - CountOption countOption = Mockito.mock(CountOption.class); - Mockito.when(countOption.getValue()).thenReturn(true); - InputStream result = serializer.entityCollection(edmEntitySet.getEntityType(), entitySet, - EntityCollectionSerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).build()) - .count(countOption) - .build()); - final String resultString = IOUtils.toString(result); - - Assert.assertThat(resultString, CoreMatchers.startsWith("{" - + "\"@odata.context\":\"$metadata#ESAllPrim\"," - + "\"@odata.count\":3,\"value\":[")); - Assert.assertThat(resultString, CoreMatchers.endsWith("]," - + "\"@odata.nextLink\":\"/next\"}")); - - int count = 0; - int index = -1; - while ((index = resultString.indexOf("PropertyInt16\":", ++index)) > 0) { - count++; - } - Assert.assertEquals(3, count); - } - - @Test - public void entityCollAllPrim() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/")) - .entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{" - + "\"@odata.context\":\"http://host/service/$metadata#ESCollAllPrim/$entity\"," - + "\"PropertyInt16\":1," - + "\"CollPropertyString\":" - + "[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]," - + "\"CollPropertyBoolean\":[true,false,true]," - + "\"CollPropertyByte\":[50,200,249]," - + "\"CollPropertySByte\":[-120,120,126]," - + "\"CollPropertyInt16\":[1000,2000,30112]," - + "\"CollPropertyInt32\":[23232323,11223355,10000001]," - + "\"CollPropertyInt64\":[929292929292,333333333333,444444444444]," - + "\"CollPropertySingle\":[1790.0,26600.0,3210.0]," - + "\"CollPropertyDouble\":[-17900.0,-2.78E7,3210.0]," - + "\"CollPropertyDecimal\":[12,-2,1234]," - + "\"CollPropertyBinary\":[\"q83v\",\"ASNF\",\"VGeJ\"]," - + "\"CollPropertyDate\":[\"1958-12-03\",\"1999-08-05\",\"2013-06-25\"]," - + "\"CollPropertyDateTimeOffset\":[\"2015-08-12T03:08:34Z\",\"1970-03-28T12:11:10Z\"," - + "\"1948-02-17T09:09:09Z\"]," - + "\"CollPropertyDuration\":[\"PT13S\",\"PT5H28M0S\",\"PT1H0S\"]," - + "\"CollPropertyGuid\":[\"ffffff67-89ab-cdef-0123-456789aaaaaa\",\"eeeeee67-89ab-cdef-0123-456789bbbbbb\"," - + "\"cccccc67-89ab-cdef-0123-456789cccccc\"]," - + "\"CollPropertyTimeOfDay\":[\"04:14:13\",\"23:59:59\",\"01:12:33\"]" - + "}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityCompAllPrim() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{" - + "\"@odata.context\":\"$metadata#ESCompAllPrim/$entity\"," - + "\"PropertyInt16\":32767," - + "\"PropertyComp\":{" - + "\"PropertyString\":\"First Resource - first\"," - + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," - + "\"PropertyBoolean\":true," - + "\"PropertyByte\":255," - + "\"PropertyDate\":\"2012-10-03\"," - + "\"PropertyDateTimeOffset\":\"2012-10-03T07:16:23.1234567Z\"," - + "\"PropertyDecimal\":34.27," - + "\"PropertySingle\":1.79E20," - + "\"PropertyDouble\":-1.79E19," - + "\"PropertyDuration\":\"PT6S\"," - + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," - + "\"PropertyInt16\":32767," - + "\"PropertyInt32\":2147483647," - + "\"PropertyInt64\":9223372036854775807," - + "\"PropertySByte\":127," - + "\"PropertyTimeOfDay\":\"01:00:01\"" - + "}}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityMixPrimCollComp() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{" - + "\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\"," - + "\"PropertyInt16\":32767," - + "\"CollPropertyString\":" - + "[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]," - + "\"PropertyComp\":{\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}," - + "\"CollPropertyComp\":[" - + "{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," - + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," - + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityMixPrimCollCompAllNull() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); - Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - entity.getProperties().retainAll(Arrays.asList(entity.getProperties().get(0))); - final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build())); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESMixPrimCollComp/$entity\"," - + "\"PropertyInt16\":32767," - + "\"CollPropertyString\":null,\"PropertyComp\":null,\"CollPropertyComp\":null}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityTwoPrimNoMetadata() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA) - .entity(edmEntitySet.getEntityType(), entity, null); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entitySetTwoPrimNoMetadata() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EntitySet entitySet = data.readAll(edmEntitySet); - InputStream result = new ODataJsonSerializer(ODataFormat.JSON_NO_METADATA) - .entityCollection(edmEntitySet.getEntityType(), entitySet, - EntityCollectionSerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{\"value\":[" - + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," - + "{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}," - + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," - + "{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}]}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entityMedia() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia"); - Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - entity.setMediaETag("theMediaETag"); - final String resultString = IOUtils.toString(serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .build())); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia/$entity\"," - + "\"@odata.mediaEtag\":\"theMediaETag\",\"@odata.mediaContentType\":\"image/svg+xml\"," - + "\"PropertyInt16\":1}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void entitySetMedia() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia"); - final EntitySet entitySet = data.readAll(edmEntitySet); - final String resultString = IOUtils.toString(serializer.entityCollection(edmEntitySet.getEntityType(), entitySet, - EntityCollectionSerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).build()).build())); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESMedia\",\"value\":[" - + "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":1}," - + "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":2}," - + "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":3}," - + "{\"@odata.mediaContentType\":\"image/svg+xml\",\"PropertyInt16\":4}]}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void select() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyDate"); - final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyBoolean"); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - selectItem1, selectItem2, selectItem2)); - InputStream result = serializer - .entity(entityType, entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, null, select)) - .suffix(Suffix.ENTITY).build()) - .select(select) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyBoolean,PropertyDate)/$entity\"," - + "\"PropertyBoolean\":true,\"PropertyDate\":\"2012-12-03\"}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void selectAll() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyString"); - SelectItem selectItem2 = Mockito.mock(SelectItem.class); - Mockito.when(selectItem2.isStar()).thenReturn(true); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2)); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .select(select) - .build()); - final String resultString = IOUtils.toString(result); - final String expectedResult = "{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," - + "\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}"; - Assert.assertEquals(expectedResult, resultString); - } - - @Test - public void selectComplex() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final EntitySet entitySet = data.readAll(edmEntitySet); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"))); - InputStream result = serializer - .entityCollection(entityType, entitySet, - EntityCollectionSerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, null, select)) - .build()) - .select(select) - .build()); - final String resultString = IOUtils.toString(result); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCompComp(PropertyComp/PropertyComp/PropertyString)\"," - + "\"value\":[" - + "{\"PropertyComp\":{\"PropertyComp\":{\"PropertyString\":\"String 1\"}}}," - + "{\"PropertyComp\":{\"PropertyComp\":{\"PropertyString\":\"String 2\"}}}]}", - resultString); - } - - @Test - public void selectComplexTwice() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompComp"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final EntitySet entitySet = data.readAll(edmEntitySet); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"), - ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp"))); - final String resultString = IOUtils.toString(serializer - .entityCollection(entityType, entitySet, - EntityCollectionSerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, null, select)) - .build()) - .select(select) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCompComp(PropertyComp/PropertyComp)\"," - + "\"value\":[" - + "{\"PropertyComp\":{\"PropertyComp\":{\"PropertyInt16\":123,\"PropertyString\":\"String 1\"}}}," - + "{\"PropertyComp\":{\"PropertyComp\":{\"PropertyInt16\":987,\"PropertyString\":\"String 2\"}}}]}", - resultString); - } - - @Test - public void expand() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(3); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList( - ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne"))); - InputStream result = serializer.entity(edmEntitySet.getEntityType(), entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build()) - .expand(expand) - .build()); - final String resultString = IOUtils.toString(result); - Assert.assertEquals("{\"@odata.context\":\"$metadata#ESTwoPrim/$entity\"," - + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," - + "\"NavPropertyETAllPrimOne\":{" - + "\"PropertyInt16\":32767," - + "\"PropertyString\":\"First Resource - positive values\"," - + "\"PropertyBoolean\":true," - + "\"PropertyByte\":255," - + "\"PropertySByte\":127," - + "\"PropertyInt32\":2147483647," - + "\"PropertyInt64\":9223372036854775807," - + "\"PropertySingle\":1.79E20," - + "\"PropertyDouble\":-1.79E19," - + "\"PropertyDecimal\":34," - + "\"PropertyBinary\":\"ASNFZ4mrze8=\"," - + "\"PropertyDate\":\"2012-12-03\"," - + "\"PropertyDateTimeOffset\":\"2012-12-03T07:16:23Z\"," - + "\"PropertyDuration\":\"PT6S\"," - + "\"PropertyGuid\":\"01234567-89ab-cdef-0123-456789abcdef\"," - + "\"PropertyTimeOfDay\":\"03:26:05\"}}", - resultString); - } - - @Test - public void expandSelect() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(3); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(entityContainer.getEntitySet("ESAllPrim"), "PropertyDate"))); - ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne"); - Mockito.when(expandItem.getSelectOption()).thenReturn(select); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); - final String resultString = IOUtils.toString(serializer - .entity(entityType, entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, expand, select)) - .suffix(Suffix.ENTITY).build()) - .expand(expand) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimOne(PropertyDate))/$entity\"," - + "\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"," - + "\"NavPropertyETAllPrimOne\":{\"PropertyDate\":\"2012-12-03\"}}", - resultString); - } - - @Test - public void expandAll() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(0); - final ExpandItem expandItem = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETTwoPrimOne"); - ExpandItem expandItemAll = Mockito.mock(ExpandItem.class); - Mockito.when(expandItemAll.isStar()).thenReturn(true); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList( - expandItem, expandItem, expandItemAll)); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte"))); - final String resultString = IOUtils.toString(serializer - .entity(entityType, entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, expand, select)) - .suffix(Suffix.ENTITY).build()) - .expand(expand) - .select(select) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertySByte)/$entity\"," - + "\"PropertySByte\":127," - + "\"NavPropertyETTwoPrimOne\":{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}," - + "\"NavPropertyETTwoPrimMany\":[{\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"}]}", - resultString); - } - - @Test - public void expandNoData() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(1); - ExpandItem expandItemAll = Mockito.mock(ExpandItem.class); - Mockito.when(expandItemAll.isStar()).thenReturn(true); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemAll)); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyTimeOfDay"))); - final String resultString = IOUtils.toString(serializer - .entity(entityType, entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, expand, select)) - .suffix(Suffix.ENTITY).build()) - .expand(expand) - .select(select) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(PropertyTimeOfDay)/$entity\"," - + "\"PropertyTimeOfDay\":\"23:49:14\"," - + "\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}", - resultString); - } - - @Test - public void expandTwoLevels() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EdmEntityType entityType = edmEntitySet.getEntityType(); - final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final Entity entity = data.readAll(edmEntitySet).getEntities().get(1); - ExpandItem expandItemSecond = Mockito.mock(ExpandItem.class); - Mockito.when(expandItemSecond.isStar()).thenReturn(true); - final ExpandOption expandInner = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemSecond)); - ExpandItem expandItemFirst = ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimMany"); - Mockito.when(expandItemFirst.getExpandOption()).thenReturn(expandInner); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32"))); - Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst)); - final String resultString = IOUtils.toString(serializer - .entity(entityType, entity, - EntitySerializerOptions.with() - .contextURL(ContextURL.with().entitySet(edmEntitySet) - .selectList(helper.buildContextURLSelectList(entityType, expand, select)) - .suffix(Suffix.ENTITY).build()) - .expand(expand) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESTwoPrim(NavPropertyETAllPrimMany(PropertyInt32))/$entity\"," - + "\"PropertyInt16\":-365,\"PropertyString\":\"Test String2\"," - + "\"NavPropertyETAllPrimMany\":[" - + "{\"PropertyInt32\":-2147483648,\"NavPropertyETTwoPrimOne\":null,\"NavPropertyETTwoPrimMany\":[]}," - + "{\"PropertyInt32\":0,\"NavPropertyETTwoPrimOne\":null," - + "\"NavPropertyETTwoPrimMany\":[" - + "{\"PropertyInt16\":32766,\"PropertyString\":\"Test String1\"}," - + "{\"PropertyInt16\":-32766,\"PropertyString\":null}," - + "{\"PropertyInt16\":32767,\"PropertyString\":\"Test String4\"}]}]}", - resultString); - } - - @Test - public void primitiveProperty() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); - final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); - final String resultString = IOUtils.toString(serializer - .primitive((EdmPrimitiveType) edmProperty.getType(), property, - PrimitiveSerializerOptions.with() - .contextURL(ContextURL.with() - .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) - .build()) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESAllPrim(32767)/PropertyString\"," - + "\"value\":\"First Resource - positive values\"}", - resultString); - } - - @Test(expected = SerializerException.class) - public void primitivePropertyNull() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyString"); - final Property property = new PropertyImpl("Edm.String", edmProperty.getName(), ValueType.PRIMITIVE, null); - serializer.primitive((EdmPrimitiveType) edmProperty.getType(), property, - PrimitiveSerializerOptions.with() - .contextURL(ContextURL.with() - .entitySet(edmEntitySet).keyPath("4242").navOrPropertyPath(edmProperty.getName()) - .build()) - .build()); - } - - @Test - public void primitiveCollectionProperty() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim"); - final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyString"); - final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); - - final String resultString = IOUtils.toString(serializer - .primitiveCollection((EdmPrimitiveType) edmProperty.getType(), property, - PrimitiveSerializerOptions.with() - .contextURL(ContextURL.with() - .entitySet(edmEntitySet).keyPath("1").navOrPropertyPath(edmProperty.getName()) - .build()) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESCollAllPrim(1)/CollPropertyString\"," - + "\"value\":[\"Employee1@company.example\",\"Employee2@company.example\",\"Employee3@company.example\"]}", - resultString); - } - - @Test - public void complexProperty() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); - final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("PropertyComp"); - final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty("PropertyComp"); - - final String resultString = IOUtils.toString(serializer - .complex((EdmComplexType) edmProperty.getType(), property, - ComplexSerializerOptions.with() - .contextURL(ContextURL.with() - .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) - .build()) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/PropertyComp\"," - + "\"PropertyInt16\":111,\"PropertyString\":\"TEST A\"}", - resultString); - } - - @Test - public void complexCollectionProperty() throws Exception { - final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp"); - final EdmProperty edmProperty = (EdmProperty) edmEntitySet.getEntityType().getProperty("CollPropertyComp"); - final Property property = data.readAll(edmEntitySet).getEntities().get(0).getProperty(edmProperty.getName()); - - final String resultString = IOUtils.toString(serializer - .complexCollection((EdmComplexType) edmProperty.getType(), property, - ComplexSerializerOptions.with() - .contextURL(ContextURL.with() - .entitySet(edmEntitySet).keyPath("32767").navOrPropertyPath(edmProperty.getName()) - .build()) - .build())); - Assert.assertEquals("{" - + "\"@odata.context\":\"$metadata#ESMixPrimCollComp(32767)/CollPropertyComp\"," - + "\"value\":[{\"PropertyInt16\":123,\"PropertyString\":\"TEST 1\"}," - + "{\"PropertyInt16\":456,\"PropertyString\":\"TEST 2\"}," - + "{\"PropertyInt16\":789,\"PropertyString\":\"TEST 3\"}]}", - resultString); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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 deleted file mode 100644 index de03327..0000000 --- a/lib/server-test/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 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.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.junit.Before; -import org.junit.Test; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -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; - -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"; - - OData server = OData.newInstance(); - assertNotNull(server); - - ODataSerializer serializer = server.createSerializer(ODataFormat.JSON); - assertNotNull(serializer); - - InputStream result = serializer.serviceDocument(edm, serviceRoot); - assertNotNull(result); - String jsonString = IOUtils.toString(result); - - assertTrue(jsonString.contains("entitySetName1")); - assertTrue(jsonString.contains("entitySetName2")); - assertFalse(jsonString.contains("entitySetName3")); - - assertTrue(jsonString.contains("functionImport1")); - assertTrue(jsonString.contains("functionImport2")); - assertFalse(jsonString.contains("functionImport3")); - - assertTrue(jsonString.contains("singleton1")); - assertTrue(jsonString.contains("singleton2")); - assertTrue(jsonString.contains("singleton3")); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java deleted file mode 100644 index 5397856..0000000 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/utils/ContextURLHelperTest.java +++ /dev/null @@ -1,215 +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.utils; - -import static org.junit.Assert.assertEquals; - -import java.util.Arrays; -import java.util.Collections; - -import org.apache.olingo.commons.api.data.ContextURL; -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.EdmProperty; -import org.apache.olingo.commons.api.edm.FullQualifiedName; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.edmx.EdmxReference; -import org.apache.olingo.server.api.uri.UriParameter; -import org.apache.olingo.server.api.uri.queryoption.ExpandItem; -import org.apache.olingo.server.api.uri.queryoption.ExpandOption; -import org.apache.olingo.server.api.uri.queryoption.SelectItem; -import org.apache.olingo.server.api.uri.queryoption.SelectOption; -import org.apache.olingo.server.core.serializer.ExpandSelectMock; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.junit.Test; -import org.mockito.Mockito; - -public class ContextURLHelperTest { - - private static final Edm edm = OData.newInstance().createServiceMetadata( - new EdmTechProvider(), Collections.emptyList()).getEdm(); - private static final EdmEntityContainer entityContainer = edm.getEntityContainer( - new FullQualifiedName("olingo.odata.test1", "Container")); - - @Test - public void buildSelect() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESAllPrim"); - final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyString"); - final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16"); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - selectItem1, selectItem2, selectItem2)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESAllPrim(PropertyInt16,PropertyString)", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildSelectAll() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESAllPrim"); - final SelectItem selectItem1 = ExpandSelectMock.mockSelectItem(entitySet, "PropertyGuid"); - SelectItem selectItem2 = Mockito.mock(SelectItem.class); - Mockito.when(selectItem2.isStar()).thenReturn(true); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem1, selectItem2)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESAllPrim(*)", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildSelectComplex() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESCompMixPrimCollComp"); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(entitySet, - "PropertyMixedPrimCollComp", "PropertyComp", "PropertyString"), - ExpandSelectMock.mockSelectItem(entitySet, - "PropertyMixedPrimCollComp", "PropertyComp", "PropertyInt16"), - ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyString"), - ExpandSelectMock.mockSelectItem(entitySet, "PropertyMixedPrimCollComp", "CollPropertyComp"), - ExpandSelectMock.mockSelectItem(entitySet, "PropertyInt16"))); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), null, select)).build(); - assertEquals("$metadata#ESCompMixPrimCollComp(" - + "PropertyInt16," - + "PropertyMixedPrimCollComp/CollPropertyString," - + "PropertyMixedPrimCollComp/PropertyComp/PropertyInt16," - + "PropertyMixedPrimCollComp/PropertyComp/PropertyString," - + "PropertyMixedPrimCollComp/CollPropertyComp)", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandAll() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - ExpandItem expandItem = Mockito.mock(ExpandItem.class); - Mockito.when(expandItem.isStar()).thenReturn(true); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); - assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandNoSelect() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList( - ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne"))); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); - assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandSelect() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - final ExpandItem expandItem1 = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne"); - final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim"); - ExpandItem expandItem2 = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimMany"); - final SelectOption innerSelect = ExpandSelectMock.mockSelectOption(Arrays.asList( - ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32"))); - Mockito.when(expandItem2.getSelectOption()).thenReturn(innerSelect); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList( - expandItem1, expandItem2)); - final SelectItem selectItem = ExpandSelectMock.mockSelectItem(entitySet, "PropertyString"); - final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(selectItem)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, select)).build(); - assertEquals("$metadata#ESTwoPrim(PropertyString,NavPropertyETAllPrimMany(PropertyInt32))", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandTwoLevels() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim"); - final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList( - ExpandSelectMock.mockExpandItem(innerEntitySet, "NavPropertyETTwoPrimOne"))); - ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne"); - Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); - assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandTwoLevelsInnerAll() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - ExpandItem expandItemInner = Mockito.mock(ExpandItem.class); - Mockito.when(expandItemInner.isStar()).thenReturn(true); - final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemInner)); - ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne"); - Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); - assertEquals("$metadata#ESTwoPrim", ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildExpandSelectTwoLevels() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EdmEntitySet innerEntitySet = entityContainer.getEntitySet("ESAllPrim"); - ExpandItem expandItemInner = ExpandSelectMock.mockExpandItem(innerEntitySet, "NavPropertyETTwoPrimOne"); - SelectItem innerSelectItem = Mockito.mock(SelectItem.class); - Mockito.when(innerSelectItem.isStar()).thenReturn(true); - final SelectOption innerSelect = ExpandSelectMock.mockSelectOption(Arrays.asList(innerSelectItem)); - Mockito.when(expandItemInner.getSelectOption()).thenReturn(innerSelect); - final ExpandOption innerExpand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemInner)); - ExpandItem expandItem = ExpandSelectMock.mockExpandItem(entitySet, "NavPropertyETAllPrimOne"); - Mockito.when(expandItem.getExpandOption()).thenReturn(innerExpand); - final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItem)); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .selectList(ContextURLHelper.buildSelectList(entitySet.getEntityType(), expand, null)).build(); - assertEquals("$metadata#ESTwoPrim(NavPropertyETAllPrimOne(NavPropertyETTwoPrimOne(*)))", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildSingleKey() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoPrim"); - final EdmProperty edmProperty = entitySet.getEntityType().getStructuralProperty("PropertyInt16"); - UriParameter key = Mockito.mock(UriParameter.class); - Mockito.when(key.getName()).thenReturn(edmProperty.getName()); - Mockito.when(key.getText()).thenReturn("42"); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .keyPath(ContextURLHelper.buildKeyPredicate(Arrays.asList(key))) - .navOrPropertyPath(edmProperty.getName()).build(); - assertEquals("$metadata#ESTwoPrim(42)/PropertyInt16", - ContextURLBuilder.create(contextURL).toASCIIString()); - } - - @Test - public void buildCompoundKey() throws Exception { - final EdmEntitySet entitySet = entityContainer.getEntitySet("ESTwoKeyNav"); - final EdmProperty edmProperty = entitySet.getEntityType().getStructuralProperty("PropertyInt16"); - UriParameter key1 = Mockito.mock(UriParameter.class); - Mockito.when(key1.getName()).thenReturn(edmProperty.getName()); - Mockito.when(key1.getText()).thenReturn("1"); - UriParameter key2 = Mockito.mock(UriParameter.class); - Mockito.when(key2.getName()).thenReturn("PropertyString"); - Mockito.when(key2.getText()).thenReturn("'2'"); - final ContextURL contextURL = ContextURL.with().entitySet(entitySet) - .keyPath(ContextURLHelper.buildKeyPredicate(Arrays.asList(key1, key2))) - .navOrPropertyPath(edmProperty.getName()).build(); - assertEquals("$metadata#ESTwoKeyNav(PropertyInt16=1,PropertyString='2')/PropertyInt16", - ContextURLBuilder.create(contextURL).toASCIIString()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java deleted file mode 100644 index c438d00..0000000 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/xml/MetadataDocumentTest.java +++ /dev/null @@ -1,158 +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.hamcrest.CoreMatchers.containsString; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertThat; - -import java.net.URI; -import java.util.Arrays; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.ServiceMetadata; -import org.apache.olingo.server.api.edmx.EdmxReference; -import org.apache.olingo.server.api.edmx.EdmxReferenceInclude; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.junit.Test; - -public class MetadataDocumentTest { - - private static final String CORE_VOCABULARY = - "http://docs.oasis-open.org/odata/odata/v4.0/cs02/vocabularies/Org.OData.Core.V1.xml"; - - @Test - public void writeMetadataWithTechnicalScenario() throws Exception { - final OData odata = OData.newInstance(); - final List references = getEdmxReferences(); - final ServiceMetadata serviceMetadata = odata.createServiceMetadata( - new EdmTechProvider(references), references); - - final String metadata = IOUtils.toString( - odata.createSerializer(ODataFormat.XML).metadataDocument(serviceMetadata)); - assertNotNull(metadata); - - assertThat(metadata, - containsString("" - + "" - + "")); - - assertThat(metadata, - containsString("")); - - assertThat(metadata, - containsString("")); - - assertThat(metadata, - containsString("" - + "" - + "" - + "" - + "" - + "" - + "")); - - assertThat(metadata, - containsString("" - + "" - + "")); - - assertThat(metadata, - containsString("" - + "")); - - assertThat(metadata, - containsString("" - + "")); - - // TODO: TypeDefinition - // assertThat(metadata, containsString("")); - - assertThat(metadata, containsString("" - + "" - + "")); - - assertThat(metadata, - containsString("" - + "" - + "")); - - assertThat(metadata, - containsString("" - + "")); - - assertThat(metadata, - containsString("" - + "" - + "")); - - assertThat(metadata, containsString("")); - - assertThat(metadata, - containsString("")); - - assertThat(metadata, - containsString("" - + "" - + "")); - - assertThat(metadata, - containsString("")); - - assertThat(metadata, - containsString("")); - - assertThat(metadata, containsString("")); - - // BaseTypeCheck - assertThat(metadata, containsString("")); - assertThat(metadata, containsString("")); - assertThat(metadata, - containsString("")); - - // TypeDefCheck - assertThat(metadata, - containsString("")); - assertThat(metadata, containsString("")); - } - - /** - * - * - * - * - * - * - * @return default emdx reference - */ - private List getEdmxReferences() { - EdmxReference reference = new EdmxReference(URI.create(CORE_VOCABULARY)); - reference.addInclude(new EdmxReferenceInclude("Org.OData.Core.V1", "Core")); - return Arrays.asList(reference); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/RawUriTest.java deleted file mode 100644 index 5e991b0..0000000 --- a/lib/server-test/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 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; - -import java.util.Arrays; -import java.util.Collections; -import java.util.List; - -import static org.junit.Assert.assertEquals; - -public class RawUriTest { - - private RawUri runRawParser(final String path, final String query, final int skipSegments) - throws UriParserSyntaxException { - return UriDecoder.decodeUri(path, query, null, skipSegments); - } - - @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("", null, 0); - checkPath(rawUri, "", Collections. emptyList()); - - rawUri = runRawParser("/", null, 0); - checkPath(rawUri, "/", Collections. emptyList()); - - rawUri = runRawParser("/entitySet", null, 0); - checkPath(rawUri, "/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("//entitySet", null, 0); - checkPath(rawUri, "//entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("entitySet", null, 0); - checkPath(rawUri, "entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("/nonServiceSegment/entitySet", null, 0); - checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); - - rawUri = runRawParser("/nonServiceSegment/entitySet", null, 1); - checkPath(rawUri, "/nonServiceSegment/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("nonServiceSegment/entitySet", null, 0); - checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("nonServiceSegment", "entitySet")); - - rawUri = runRawParser("nonServiceSegment/entitySet", null, 1); - checkPath(rawUri, "nonServiceSegment/entitySet", Arrays.asList("entitySet")); - - rawUri = runRawParser("non//Service/Segment///entitySet/", null, 3); - checkPath(rawUri, "non//Service/Segment///entitySet/", Arrays.asList("entitySet")); - - rawUri = runRawParser("/a", "abc=xx+yz", 0); - checkPath(rawUri, "/a", Arrays.asList("a")); - } - - @Test - public void testSplit() { - UriDecoder.split("", '/'); - UriDecoder.split("/", '/'); - UriDecoder.split("a", '/'); - UriDecoder.split("a/", '/'); - UriDecoder.split("/a", '/'); - UriDecoder.split("a/a", '/'); - } - - private void checkPath(final RawUri rawUri, final String path, final List list) { - assertEquals(path, rawUri.path); - - assertEquals(list.size(), rawUri.pathSegmentListDecoded.size()); - - for (int i = 0; i < list.size(); i++) { - assertEquals(list.get(i), rawUri.pathSegmentListDecoded.get(i)); - } - } - - @Test(expected = UriParserSyntaxException.class) - public void wrongPercentEncoding() throws Exception { - runRawParser("%wrong", null, 0); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.java deleted file mode 100644 index fe44305..0000000 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriHelperTest.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; - -import java.util.Collections; - -import org.apache.olingo.commons.api.data.Entity; -import org.apache.olingo.commons.api.data.ValueType; -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.FullQualifiedName; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.edmx.EdmxReference; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.apache.olingo.server.api.uri.UriHelper; -import org.apache.olingo.server.tecsvc.data.DataProvider; -import org.apache.olingo.server.tecsvc.provider.EdmTechProvider; -import org.junit.Assert; -import org.junit.Test; - -public class UriHelperTest { - - private static final Edm edm = OData.newInstance().createServiceMetadata( - new EdmTechProvider(), Collections. emptyList()).getEdm(); - private static final EdmEntityContainer container = edm.getEntityContainer( - new FullQualifiedName("olingo.odata.test1", "Container")); - private static final UriHelper helper = new UriHelperImpl(); - private final DataProvider data = new DataProvider(); - - @Test - public void canonicalURL() throws Exception { - final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim"); - final Entity entity = data.readAll(entitySet).getEntities().get(0); - Assert.assertEquals("ESAllPrim(32767)", helper.buildCanonicalURL(entitySet, entity)); - } - - @Test - public void canonicalURLLong() throws Exception { - final EdmEntitySet entitySet = container.getEntitySet("ESAllKey"); - final Entity entity = data.readAll(entitySet).getEntities().get(0); - Assert.assertEquals("ESAllKey(" - + "PropertyString='First'," - + "PropertyBoolean=true," - + "PropertyByte=255," - + "PropertySByte=127," - + "PropertyInt16=32767," - + "PropertyInt32=2147483647," - + "PropertyInt64=9223372036854775807," - + "PropertyDecimal=34," - + "PropertyDate=2012-12-03," - + "PropertyDateTimeOffset=2012-12-03T07%3A16%3A23Z," - + "PropertyDuration=duration'PT6S'," - + "PropertyGuid=01234567-89ab-cdef-0123-456789abcdef," - + "PropertyTimeOfDay=02%3A48%3A21)", - helper.buildCanonicalURL(entitySet, entity)); - } - - @Test(expected = SerializerException.class) - public void canonicalURLWrong() throws Exception { - final EdmEntitySet entitySet = container.getEntitySet("ESAllPrim"); - Entity entity = data.readAll(entitySet).getEntities().get(0); - entity.getProperty("PropertyInt16").setValue(ValueType.PRIMITIVE, "wrong"); - helper.buildCanonicalURL(entitySet, entity); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/f7a7b484/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 deleted file mode 100644 index d4e8ebd..0000000 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/uri/UriInfoImplTest.java +++ /dev/null @@ -1,209 +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 org.apache.olingo.commons.api.ODataRuntimeException; -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; - -import java.util.ArrayList; -import java.util.List; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -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(expected = ODataRuntimeException.class) - public void doubleSystemQueryOptions() { - new UriInfoImpl() - .setSystemQueryOption(new FormatOptionImpl()) - .setSystemQueryOption(new FormatOptionImpl()); - } - - @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.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); - - 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()); - } -}