[OLINGO-587] Fix json title, client and add tests

This commit is contained in:
Christian Amend 2015-10-27 17:24:13 +01:00
parent fa084ac98a
commit 2ceacd87f7
10 changed files with 95 additions and 42 deletions

View File

@ -23,5 +23,7 @@ public interface ServiceDocumentItem {
String getName();
String getUrl();
String getTitle();
}

View File

@ -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;

View File

@ -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 + '\'' +
'}';
}
}

View File

@ -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;
}

View File

@ -104,6 +104,8 @@ public interface Constants {
String ATTR_METADATA = "metadata";
String ATTR_HREF = "href";
String ATTR_NAME = "name";
String ATTR_REF = "ref";

View File

@ -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());
}
}
}

View File

@ -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);

View File

@ -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>"

View File

@ -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")) {

View File

@ -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"));