Repository: olingo-odata4 Updated Branches: refs/heads/OLINGO-564 53b10f6b7 -> c37d4da57
http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java index 2213c5a..6763495 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ODataXmlSerializerImpl.java @@ -29,7 +29,7 @@ import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmComplexType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmPrimitiveType; -import org.apache.olingo.server.api.ODataServerError; +import org.apache.olingo.server.api.ClientServerError; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.serializer.ComplexSerializerOptions; import org.apache.olingo.server.api.serializer.EntityCollectionSerializerOptions; @@ -102,7 +102,7 @@ public class ODataXmlSerializerImpl implements ODataSerializer { } @Override - public SerializerResult error(ODataServerError error) throws SerializerException { + public SerializerResult error(ClientServerError error) throws SerializerException { throw new SerializerException("error serialization not implemented for XML format", SerializerException.MessageKeys.NOT_IMPLEMENTED); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java new file mode 100644 index 0000000..c30a719 --- /dev/null +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ClientErrorSerializerTest.java @@ -0,0 +1,136 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one + * or more contributor license agreements. See the NOTICE file + * distributed with this work for additional information + * regarding copyright ownership. The ASF licenses this file + * to you under the Apache License, Version 2.0 (the + * "License"); you may not use this file except in compliance + * with the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, + * software distributed under the License is distributed on an + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + * KIND, either express or implied. See the License for the + * specific language governing permissions and limitations + * under the License. + */ +package org.apache.olingo.server.core.serializer.json; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; + +import java.io.InputStream; +import java.util.ArrayList; +import java.util.List; + +import org.apache.commons.io.IOUtils; +import org.apache.olingo.commons.api.domain.ClientErrorDetail; +import org.apache.olingo.commons.api.format.ODataFormat; +import org.apache.olingo.server.api.OData; +import org.apache.olingo.server.api.ClientServerError; +import org.apache.olingo.server.api.serializer.ODataSerializer; +import org.apache.olingo.server.api.serializer.SerializerException; +import org.junit.Before; +import org.junit.Test; + +import com.fasterxml.jackson.databind.JsonNode; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.node.JsonNodeType; + +public class ClientErrorSerializerTest { + + ODataSerializer ser; + + @Before + public void before() throws Exception { + ser = OData.newInstance().createSerializer(ODataFormat.JSON); + } + + @Test + public void basicODataErrorNoCode() throws Exception { + ClientServerError error = new ClientServerError(); + error.setMessage("ErrorMessage"); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\"}}", jsonString); + } + + @Test + public void basicODataErrorWithCode() throws Exception { + ClientServerError error = new ClientServerError(); + error.setCode("Code").setMessage("ErrorMessage"); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\"}}", jsonString); + } + + @Test + public void basicODataErrorWithCodeAndTarget() throws Exception { + ClientServerError error = new ClientServerError(); + error.setCode("Code").setMessage("ErrorMessage").setTarget("Target"); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString); + } + + @Test(expected = SerializerException.class) + public void nullErrorResultsInException() throws Exception { + ser.error(null); + } + + @Test + public void emptyDetailsList() throws Exception { + ClientServerError error = new ClientServerError(); + error.setMessage("ErrorMessage").setDetails(new ArrayList<ClientErrorDetail>()); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\",\"details\":[]}}", jsonString); + } + + @Test + public void nothingSetAtODataErrorObject() throws Exception { + ClientServerError error = new ClientServerError(); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":null,\"message\":null}}", jsonString); + } + + @Test + public void singleDetailNothingSet() throws Exception { + List<ClientErrorDetail> details = new ArrayList<ClientErrorDetail>(); + details.add(new ClientErrorDetail()); + ClientServerError error = new ClientServerError().setDetails(details); + InputStream stream = ser.error(error).getContent(); + String jsonString = IOUtils.toString(stream); + assertEquals("{\"error\":{\"code\":null,\"message\":null,\"details\":[{\"code\":null,\"message\":null}]}}", + jsonString); + } + + @Test + public void verifiedWithJacksonParser() throws Exception { + List<ClientErrorDetail> details = new ArrayList<ClientErrorDetail>(); + details.add(new ClientErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget")); + ClientServerError error = + new ClientServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details); + InputStream stream = ser.error(error).getContent(); + JsonNode tree = new ObjectMapper().readTree(stream); + assertNotNull(tree); + tree = tree.get("error"); + assertNotNull(tree); + assertEquals("Code", tree.get("code").textValue()); + assertEquals("Message", tree.get("message").textValue()); + assertEquals("Target", tree.get("target").textValue()); + + tree = tree.get("details"); + assertNotNull(tree); + assertEquals(JsonNodeType.ARRAY, tree.getNodeType()); + + tree = tree.get(0); + assertNotNull(tree); + assertEquals("detailCode", tree.get("code").textValue()); + assertEquals("detailMessage", tree.get("message").textValue()); + assertEquals("detailTarget", tree.get("target").textValue()); + } +} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java deleted file mode 100644 index de5a25e..0000000 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/json/ODataErrorSerializerTest.java +++ /dev/null @@ -1,136 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file - * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file - * to you under the Apache License, Version 2.0 (the - * "License"); you may not use this file except in compliance - * with the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, - * software distributed under the License is distributed on an - * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY - * KIND, either express or implied. See the License for the - * specific language governing permissions and limitations - * under the License. - */ -package org.apache.olingo.server.core.serializer.json; - -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; - -import java.io.InputStream; -import java.util.ArrayList; -import java.util.List; - -import org.apache.commons.io.IOUtils; -import org.apache.olingo.commons.api.domain.ODataErrorDetail; -import org.apache.olingo.commons.api.format.ODataFormat; -import org.apache.olingo.server.api.OData; -import org.apache.olingo.server.api.ODataServerError; -import org.apache.olingo.server.api.serializer.ODataSerializer; -import org.apache.olingo.server.api.serializer.SerializerException; -import org.junit.Before; -import org.junit.Test; - -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.node.JsonNodeType; - -public class ODataErrorSerializerTest { - - ODataSerializer ser; - - @Before - public void before() throws Exception { - ser = OData.newInstance().createSerializer(ODataFormat.JSON); - } - - @Test - public void basicODataErrorNoCode() throws Exception { - ODataServerError error = new ODataServerError(); - error.setMessage("ErrorMessage"); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\"}}", jsonString); - } - - @Test - public void basicODataErrorWithCode() throws Exception { - ODataServerError error = new ODataServerError(); - error.setCode("Code").setMessage("ErrorMessage"); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\"}}", jsonString); - } - - @Test - public void basicODataErrorWithCodeAndTarget() throws Exception { - ODataServerError error = new ODataServerError(); - error.setCode("Code").setMessage("ErrorMessage").setTarget("Target"); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":\"Code\",\"message\":\"ErrorMessage\",\"target\":\"Target\"}}", jsonString); - } - - @Test(expected = SerializerException.class) - public void nullErrorResultsInException() throws Exception { - ser.error(null); - } - - @Test - public void emptyDetailsList() throws Exception { - ODataServerError error = new ODataServerError(); - error.setMessage("ErrorMessage").setDetails(new ArrayList<ODataErrorDetail>()); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":\"ErrorMessage\",\"details\":[]}}", jsonString); - } - - @Test - public void nothingSetAtODataErrorObject() throws Exception { - ODataServerError error = new ODataServerError(); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":null}}", jsonString); - } - - @Test - public void singleDetailNothingSet() throws Exception { - List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>(); - details.add(new ODataErrorDetail()); - ODataServerError error = new ODataServerError().setDetails(details); - InputStream stream = ser.error(error).getContent(); - String jsonString = IOUtils.toString(stream); - assertEquals("{\"error\":{\"code\":null,\"message\":null,\"details\":[{\"code\":null,\"message\":null}]}}", - jsonString); - } - - @Test - public void verifiedWithJacksonParser() throws Exception { - List<ODataErrorDetail> details = new ArrayList<ODataErrorDetail>(); - details.add(new ODataErrorDetail().setCode("detailCode").setMessage("detailMessage").setTarget("detailTarget")); - ODataServerError error = - new ODataServerError().setCode("Code").setMessage("Message").setTarget("Target").setDetails(details); - InputStream stream = ser.error(error).getContent(); - JsonNode tree = new ObjectMapper().readTree(stream); - assertNotNull(tree); - tree = tree.get("error"); - assertNotNull(tree); - assertEquals("Code", tree.get("code").textValue()); - assertEquals("Message", tree.get("message").textValue()); - assertEquals("Target", tree.get("target").textValue()); - - tree = tree.get("details"); - assertNotNull(tree); - assertEquals(JsonNodeType.ARRAY, tree.getNodeType()); - - tree = tree.get(0); - assertNotNull(tree); - assertEquals("detailCode", tree.get("code").textValue()); - assertEquals("detailMessage", tree.get("message").textValue()); - assertEquals("detailTarget", tree.get("target").textValue()); - } -} http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java index dcb3bfd..452e529 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/data/DataCreator.java @@ -35,7 +35,7 @@ import org.apache.olingo.commons.api.data.EntityCollection; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataLinkType; +import org.apache.olingo.commons.api.domain.ClientLinkType; public class DataCreator { @@ -628,7 +628,7 @@ public class DataCreator { Link link = entity.getNavigationLink(navigationPropertyName); if (link == null) { link = new Link(); - link.setType(ODataLinkType.ENTITY_NAVIGATION.toString()); + link.setType(ClientLinkType.ENTITY_NAVIGATION.toString()); link.setTitle(navigationPropertyName); entity.getNavigationLinks().add(link); } @@ -639,7 +639,7 @@ public class DataCreator { Link link = entity.getNavigationLink(navigationPropertyName); if (link == null) { link = new Link(); - link.setType(ODataLinkType.ENTITY_SET_NAVIGATION.toString()); + link.setType(ClientLinkType.ENTITY_SET_NAVIGATION.toString()); link.setTitle(navigationPropertyName); EntityCollection target = new EntityCollection(); target.getEntities().addAll(Arrays.asList(targets)); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java index 20eb233..2a51b8d 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/ODataHandlerTest.java @@ -51,7 +51,7 @@ import org.apache.olingo.server.api.OData; import org.apache.olingo.server.api.ODataApplicationException; import org.apache.olingo.server.api.ODataRequest; import org.apache.olingo.server.api.ODataResponse; -import org.apache.olingo.server.api.ODataServerError; +import org.apache.olingo.server.api.ClientServerError; import org.apache.olingo.server.api.ServiceMetadata; import org.apache.olingo.server.api.edmx.EdmxReference; import org.apache.olingo.server.api.processor.ActionComplexCollectionProcessor; @@ -692,7 +692,7 @@ public class ODataHandlerTest { ErrorProcessor errorProcessor = mock(ErrorProcessor.class); dispatch(HttpMethod.POST, "ESAllPrim", "", HttpHeader.CONTENT_TYPE, "some/unsupported", errorProcessor); verifyZeroInteractions(processor); - verify(errorProcessor).processError(any(ODataRequest.class), any(ODataResponse.class), any(ODataServerError.class), + verify(errorProcessor).processError(any(ODataRequest.class), any(ODataResponse.class), any(ClientServerError.class), any(ContentType.class)); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java index 0347941..192f9b7 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataDeserializerDeepInsertTest.java @@ -27,7 +27,7 @@ import java.io.InputStream; import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Link; -import org.apache.olingo.commons.api.domain.ODataLinkType; +import org.apache.olingo.commons.api.domain.ClientLinkType; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.FullQualifiedName; import org.apache.olingo.commons.api.format.ODataFormat; @@ -46,7 +46,7 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe assertNotNull(navigationLink); assertEquals("NavPropertyETTwoPrimOne", navigationLink.getTitle()); - assertEquals(ODataLinkType.ENTITY_NAVIGATION.toString(), navigationLink.getType()); + assertEquals(ClientLinkType.ENTITY_NAVIGATION.toString(), navigationLink.getType()); assertNotNull(navigationLink.getInlineEntity()); assertNull(navigationLink.getInlineEntitySet()); } @@ -68,7 +68,7 @@ public class ODataDeserializerDeepInsertTest extends AbstractODataDeserializerTe assertNotNull(navigationLink); assertEquals("NavPropertyETTwoPrimMany", navigationLink.getTitle()); - assertEquals(ODataLinkType.ENTITY_SET_NAVIGATION.toString(), navigationLink.getType()); + assertEquals(ClientLinkType.ENTITY_SET_NAVIGATION.toString(), navigationLink.getType()); assertNull(navigationLink.getInlineEntity()); assertNotNull(navigationLink.getInlineEntitySet()); assertEquals(1, navigationLink.getInlineEntitySet().getEntities().size()); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/c37d4da5/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java index 8c01c21..7886fbc 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/deserializer/json/ODataJsonDeserializerEntityTest.java @@ -40,7 +40,7 @@ import org.apache.olingo.commons.api.data.Entity; import org.apache.olingo.commons.api.data.Link; import org.apache.olingo.commons.api.data.Property; import org.apache.olingo.commons.api.data.ValueType; -import org.apache.olingo.commons.api.domain.ODataLinkType; +import org.apache.olingo.commons.api.domain.ClientLinkType; import org.apache.olingo.commons.api.edm.Edm; import org.apache.olingo.commons.api.edm.EdmEntityType; import org.apache.olingo.commons.api.edm.EdmProperty; @@ -474,7 +474,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe assertNotNull(bindingToOne); assertEquals("NavPropertyETTwoPrimOne", bindingToOne.getTitle()); assertEquals("ESTwoPrim(2)", bindingToOne.getBindingLink()); - assertEquals(ODataLinkType.ENTITY_BINDING.toString(), bindingToOne.getType()); + assertEquals(ClientLinkType.ENTITY_BINDING.toString(), bindingToOne.getType()); assertTrue(bindingToOne.getBindingLinks().isEmpty()); assertNull(bindingToOne.getHref()); assertNull(bindingToOne.getRel()); @@ -484,7 +484,7 @@ public class ODataJsonDeserializerEntityTest extends AbstractODataDeserializerTe assertEquals("NavPropertyETTwoPrimMany", bindingToMany.getTitle()); assertNotNull(bindingToMany.getBindingLinks()); assertEquals(2, bindingToMany.getBindingLinks().size()); - assertEquals(ODataLinkType.ENTITY_COLLECTION_BINDING.toString(), bindingToMany.getType()); + assertEquals(ClientLinkType.ENTITY_COLLECTION_BINDING.toString(), bindingToMany.getType()); assertNull(bindingToMany.getBindingLink()); assertNull(bindingToMany.getHref()); assertNull(bindingToMany.getRel());
