Repository: olingo-odata4 Updated Branches: refs/heads/master fa084ac98 -> 2ceacd87f
[OLINGO-587] Fix json title, client and add tests Project: http://git-wip-us.apache.org/repos/asf/olingo-odata4/repo Commit: http://git-wip-us.apache.org/repos/asf/olingo-odata4/commit/2ceacd87 Tree: http://git-wip-us.apache.org/repos/asf/olingo-odata4/tree/2ceacd87 Diff: http://git-wip-us.apache.org/repos/asf/olingo-odata4/diff/2ceacd87 Branch: refs/heads/master Commit: 2ceacd87f7bf6f16d2cb882de11c382b3c26a684 Parents: fa084ac Author: Christian Amend <[email protected]> Authored: Tue Oct 27 17:24:13 2015 +0100 Committer: Christian Amend <[email protected]> Committed: Tue Oct 27 17:24:13 2015 +0100 ---------------------------------------------------------------------- .../client/api/data/ServiceDocumentItem.java | 2 + .../data/JSONServiceDocumentDeserializer.java | 18 +++-- .../core/data/ServiceDocumentItemImpl.java | 79 ++++++++++++++------ .../data/XMLServiceDocumentDeserializer.java | 21 ++++-- .../apache/olingo/commons/api/Constants.java | 2 + .../json/ServiceDocumentJsonSerializer.java | 2 +- .../xml/ServiceDocumentXmlSerializer.java | 1 + .../xml/ServiceDocumentXmlSerializerTest.java | 6 +- .../tecsvc/provider/ContainerProvider.java | 3 + .../serializer/json/ServiceDocumentTest.java | 3 + 10 files changed, 95 insertions(+), 42 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/client-api/src/main/java/org/apache/olingo/client/api/data/ServiceDocumentItem.java ---------------------------------------------------------------------- diff --git a/lib/client-api/src/main/java/org/apache/olingo/client/api/data/ServiceDocumentItem.java b/lib/client-api/src/main/java/org/apache/olingo/client/api/data/ServiceDocumentItem.java index 31cca94..382d101 100644 --- a/lib/client-api/src/main/java/org/apache/olingo/client/api/data/ServiceDocumentItem.java +++ b/lib/client-api/src/main/java/org/apache/olingo/client/api/data/ServiceDocumentItem.java @@ -23,5 +23,7 @@ public interface ServiceDocumentItem { String getName(); String getUrl(); + + String getTitle(); } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java index 717639d..5883aa5 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/JSONServiceDocumentDeserializer.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -74,6 +74,10 @@ public class JSONServiceDocumentDeserializer extends JsonDeserializer { final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl(); item.setName(node.get("name").asText()); + JsonNode titleNode = node.get("title"); + if (titleNode != null) { + item.setTitle(titleNode.asText()); + } item.setUrl(node.get("url").asText()); final String kind = node.has("kind") ? node.get("kind").asText() : null; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentItemImpl.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentItemImpl.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentItemImpl.java index fe6b59b..520e2cf 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentItemImpl.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/ServiceDocumentItemImpl.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -26,6 +26,8 @@ public final class ServiceDocumentItemImpl implements ServiceDocumentItem { private String url; + private String title; + @Override public String getName() { return name; @@ -45,35 +47,66 @@ public final class ServiceDocumentItemImpl implements ServiceDocumentItem { } @Override - public boolean equals(Object o) { - if (this == o) { - return true; - } - if (o == null || getClass() != o.getClass()) { - return false; - } - - ServiceDocumentItemImpl that = (ServiceDocumentItemImpl) o; - - if (name != null ? !name.equals(that.name) : that.name != null) { - return false; - } - return !(url != null ? !url.equals(that.url) : that.url != null); + public String getTitle() { + return title; + } + public void setTitle(String title) { + this.title = title; } @Override public int hashCode() { - int result = name != null ? name.hashCode() : 0; - result = 31 * result + (url != null ? url.hashCode() : 0); + final int prime = 31; + int result = 1; + result = prime * result + ((name == null) ? 0 : name.hashCode()); + result = prime * result + ((title == null) ? 0 : title.hashCode()); + result = prime * result + ((url == null) ? 0 : url.hashCode()); return result; } @Override + public boolean equals(Object obj) { + if (this == obj) { + return true; + } + if (obj == null) { + return false; + } + if (!(obj instanceof ServiceDocumentItemImpl)) { + return false; + } + ServiceDocumentItemImpl other = (ServiceDocumentItemImpl) obj; + if (name == null) { + if (other.name != null) { + return false; + } + } else if (!name.equals(other.name)) { + return false; + } + if (title == null) { + if (other.title != null) { + return false; + } + } else if (!title.equals(other.title)) { + return false; + } + if (url == null) { + if (other.url != null) { + return false; + } + } else if (!url.equals(other.url)) { + return false; + } + return true; + } + + @Override public String toString() { return "ServiceDocumentItemImpl{" + "name='" + name + '\'' + ", url='" + url + '\'' + + ", title='" + title + '\'' + '}'; } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java ---------------------------------------------------------------------- diff --git a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java index 70f76a0..5bb3fe9 100644 --- a/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java +++ b/lib/client-core/src/main/java/org/apache/olingo/client/core/data/XMLServiceDocumentDeserializer.java @@ -1,18 +1,18 @@ /* * Licensed to the Apache Software Foundation (ASF) under one - * or more contributor license agreements. See the NOTICE file + * or more contributor license agreements. See the NOTICE file * distributed with this work for additional information - * regarding copyright ownership. The ASF licenses this file + * 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 - * + * 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 + * KIND, either express or implied. See the License for the * specific language governing permissions and limitations * under the License. */ @@ -61,12 +61,17 @@ public class XMLServiceDocumentDeserializer extends JsonDeserializer { if (token == JsonToken.FIELD_NAME) { if ("href".equals(jp.getCurrentName())) { element.setUrl(jp.nextTextValue()); + } else if ("name".equals(jp.getCurrentName())) { + element.setName(jp.nextTextValue()); } else if ("title".equals(jp.getCurrentName())) { - element.setName(getName(jp)); + element.setTitle(getName(jp)); } } } + if (element.getName() == null) { + element.setName(element.getTitle()); + } return element; } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java ---------------------------------------------------------------------- diff --git a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java index beff60d..88b3d86 100644 --- a/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java +++ b/lib/commons-api/src/main/java/org/apache/olingo/commons/api/Constants.java @@ -104,6 +104,8 @@ public interface Constants { String ATTR_METADATA = "metadata"; String ATTR_HREF = "href"; + + String ATTR_NAME = "name"; String ATTR_REF = "ref"; http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java index a9793b9..9625a4c 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentJsonSerializer.java @@ -81,7 +81,7 @@ public class ServiceDocumentJsonSerializer { private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException { for (EdmEntitySet edmEntitySet : container.getEntitySets()) { if (edmEntitySet.isIncludeInServiceDocument()) { - writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName(), edmEntitySet.getName()); + writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName(), edmEntitySet.getTitle()); } } } http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java index a5490e6..19d132b 100644 --- a/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java +++ b/lib/server-core/src/main/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializer.java @@ -126,6 +126,7 @@ public class ServiceDocumentXmlSerializer { writer.writeStartElement(METADATA, kind, NS_METADATA); } writer.writeAttribute(Constants.ATTR_HREF, name); + writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NAME , name); writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM); if (title != null) { writer.writeCharacters(title); http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java ---------------------------------------------------------------------- diff --git a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java index 1fdb256..846efc5 100644 --- a/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java +++ b/lib/server-core/src/test/java/org/apache/olingo/server/core/serializer/xml/ServiceDocumentXmlSerializerTest.java @@ -87,13 +87,13 @@ public class ServiceDocumentXmlSerializerTest { + "metadata:context=\"http://host/svc/$metadata\">" + "<app:workspace>" + "<atom:title>org.olingo.container</atom:title>" - + "<app:collection href=\"ESAllPrim\">" + + "<app:collection href=\"ESAllPrim\" metadata:name=\"ESAllPrim\">" + "<atom:title>ESAllPrim</atom:title>" + "</app:collection>" - + "<metadata:function-import href=\"FINRTInt16\">" + + "<metadata:function-import href=\"FINRTInt16\" metadata:name=\"FINRTInt16\">" + "<atom:title>FINRTInt16</atom:title>" + "</metadata:function-import>" - + "<metadata:singleton href=\"SI\">" + + "<metadata:singleton href=\"SI\" metadata:name=\"SI\">" + "<atom:title>SI</atom:title>" + "</metadata:singleton>" + "</app:workspace>" http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java ---------------------------------------------------------------------- diff --git a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java index f5fb038..9f91763 100644 --- a/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java +++ b/lib/server-tecsvc/src/main/java/org/apache/olingo/server/tecsvc/provider/ContainerProvider.java @@ -164,6 +164,7 @@ public class ContainerProvider { return new CsdlEntitySet() .setName("ESAllPrim") .setType(EntityTypeProvider.nameETAllPrim) + .setTitle("All PropertyTypes EntitySet") .setNavigationPropertyBindings(Arrays .asList(new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimOne").setTarget("ESTwoPrim"), new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimMany").setTarget("ESTwoPrim"))) @@ -658,6 +659,7 @@ public class ContainerProvider { if (name.equals("FINRTInt16")) { return new CsdlFunctionImport() .setName(name) + .setTitle("Simple FunctionImport") .setFunction(FunctionProvider.nameUFNRTInt16) .setIncludeInServiceDocument(true); @@ -804,6 +806,7 @@ public class ContainerProvider { if (name.equals("SI")) { return new CsdlSingleton() .setName("SI") + .setTitle("Simple Singelton") .setType(EntityTypeProvider.nameETTwoPrim); } else if (name.equals("SINav")) { http://git-wip-us.apache.org/repos/asf/olingo-odata4/blob/2ceacd87/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java ---------------------------------------------------------------------- diff --git a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java index 3b5f58f..2a46711 100644 --- a/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java +++ b/lib/server-test/src/test/java/org/apache/olingo/server/core/serializer/json/ServiceDocumentTest.java @@ -67,17 +67,20 @@ public class ServiceDocumentTest { metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\""))); assertTrue(jsonString.contains("ESAllPrim")); + assertTrue(jsonString.contains("All PropertyTypes EntitySet")); assertTrue(jsonString.contains("ESCollAllPrim")); assertTrue(jsonString.contains("ESKeyNavCont")); assertFalse(jsonString.contains("ESInvisible")); assertTrue(jsonString.contains("FINRTInt16")); + assertTrue(jsonString.contains("Simple FunctionImport")); assertTrue(jsonString.contains("FINRTCollETMixPrimCollCompTwoParam")); assertTrue(jsonString.contains("FICRTCollESKeyNavContParam")); assertFalse(jsonString.contains("FINInvisibleRTInt16")); assertTrue(jsonString.contains("FunctionImport")); assertTrue(jsonString.contains("SI")); + assertTrue(jsonString.contains("Simple Singelton")); assertTrue(jsonString.contains("SINav")); assertTrue(jsonString.contains("SIMedia")); assertTrue(jsonString.contains("Singleton"));
