[OLINGO-587] Fix json title, client and add tests
This commit is contained in:
parent
fa084ac98a
commit
2ceacd87f7
|
@ -24,4 +24,6 @@ public interface ServiceDocumentItem {
|
||||||
|
|
||||||
String getUrl();
|
String getUrl();
|
||||||
|
|
||||||
|
String getTitle();
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* 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
|
* 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
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
@ -74,6 +74,10 @@ public class JSONServiceDocumentDeserializer extends JsonDeserializer {
|
||||||
|
|
||||||
final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl();
|
final ServiceDocumentItemImpl item = new ServiceDocumentItemImpl();
|
||||||
item.setName(node.get("name").asText());
|
item.setName(node.get("name").asText());
|
||||||
|
JsonNode titleNode = node.get("title");
|
||||||
|
if (titleNode != null) {
|
||||||
|
item.setTitle(titleNode.asText());
|
||||||
|
}
|
||||||
item.setUrl(node.get("url").asText());
|
item.setUrl(node.get("url").asText());
|
||||||
|
|
||||||
final String kind = node.has("kind") ? node.get("kind").asText() : null;
|
final String kind = node.has("kind") ? node.get("kind").asText() : null;
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* 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
|
* 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
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
@ -26,6 +26,8 @@ public final class ServiceDocumentItemImpl implements ServiceDocumentItem {
|
||||||
|
|
||||||
private String url;
|
private String url;
|
||||||
|
|
||||||
|
private String title;
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public String getName() {
|
public String getName() {
|
||||||
return name;
|
return name;
|
||||||
|
@ -45,35 +47,66 @@ public final class ServiceDocumentItemImpl implements ServiceDocumentItem {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public boolean equals(Object o) {
|
public String getTitle() {
|
||||||
if (this == o) {
|
return title;
|
||||||
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 void setTitle(String title) {
|
||||||
|
this.title = title;
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public int hashCode() {
|
public int hashCode() {
|
||||||
int result = name != null ? name.hashCode() : 0;
|
final int prime = 31;
|
||||||
result = 31 * result + (url != null ? url.hashCode() : 0);
|
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;
|
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
|
@Override
|
||||||
public String toString() {
|
public String toString() {
|
||||||
return "ServiceDocumentItemImpl{" +
|
return "ServiceDocumentItemImpl{" +
|
||||||
"name='" + name + '\'' +
|
"name='" + name + '\'' +
|
||||||
", url='" + url + '\'' +
|
", url='" + url + '\'' +
|
||||||
|
", title='" + title + '\'' +
|
||||||
'}';
|
'}';
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -1,18 +1,18 @@
|
||||||
/*
|
/*
|
||||||
* Licensed to the Apache Software Foundation (ASF) under one
|
* 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
|
* 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
|
* to you under the Apache License, Version 2.0 (the
|
||||||
* "License"); you may not use this file except in compliance
|
* "License"); you may not use this file except in compliance
|
||||||
* with the License. You may obtain a copy of the License at
|
* with the License. You may obtain a copy of the License at
|
||||||
*
|
*
|
||||||
* http://www.apache.org/licenses/LICENSE-2.0
|
* http://www.apache.org/licenses/LICENSE-2.0
|
||||||
*
|
*
|
||||||
* Unless required by applicable law or agreed to in writing,
|
* Unless required by applicable law or agreed to in writing,
|
||||||
* software distributed under the License is distributed on an
|
* software distributed under the License is distributed on an
|
||||||
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
|
* "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
|
* specific language governing permissions and limitations
|
||||||
* under the License.
|
* under the License.
|
||||||
*/
|
*/
|
||||||
|
@ -61,12 +61,17 @@ public class XMLServiceDocumentDeserializer extends JsonDeserializer {
|
||||||
if (token == JsonToken.FIELD_NAME) {
|
if (token == JsonToken.FIELD_NAME) {
|
||||||
if ("href".equals(jp.getCurrentName())) {
|
if ("href".equals(jp.getCurrentName())) {
|
||||||
element.setUrl(jp.nextTextValue());
|
element.setUrl(jp.nextTextValue());
|
||||||
|
} else if ("name".equals(jp.getCurrentName())) {
|
||||||
|
element.setName(jp.nextTextValue());
|
||||||
} else if ("title".equals(jp.getCurrentName())) {
|
} else if ("title".equals(jp.getCurrentName())) {
|
||||||
element.setName(getName(jp));
|
element.setTitle(getName(jp));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (element.getName() == null) {
|
||||||
|
element.setName(element.getTitle());
|
||||||
|
}
|
||||||
return element;
|
return element;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -105,6 +105,8 @@ public interface Constants {
|
||||||
|
|
||||||
String ATTR_HREF = "href";
|
String ATTR_HREF = "href";
|
||||||
|
|
||||||
|
String ATTR_NAME = "name";
|
||||||
|
|
||||||
String ATTR_REF = "ref";
|
String ATTR_REF = "ref";
|
||||||
|
|
||||||
String ATTR_TARGET = "target";
|
String ATTR_TARGET = "target";
|
||||||
|
|
|
@ -81,7 +81,7 @@ public class ServiceDocumentJsonSerializer {
|
||||||
private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
|
private void writeEntitySets(final JsonGenerator gen, final EdmEntityContainer container) throws IOException {
|
||||||
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
|
for (EdmEntitySet edmEntitySet : container.getEntitySets()) {
|
||||||
if (edmEntitySet.isIncludeInServiceDocument()) {
|
if (edmEntitySet.isIncludeInServiceDocument()) {
|
||||||
writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName(), edmEntitySet.getName());
|
writeElement(gen, null, edmEntitySet.getName(), edmEntitySet.getName(), edmEntitySet.getTitle());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -126,6 +126,7 @@ public class ServiceDocumentXmlSerializer {
|
||||||
writer.writeStartElement(METADATA, kind, NS_METADATA);
|
writer.writeStartElement(METADATA, kind, NS_METADATA);
|
||||||
}
|
}
|
||||||
writer.writeAttribute(Constants.ATTR_HREF, name);
|
writer.writeAttribute(Constants.ATTR_HREF, name);
|
||||||
|
writer.writeAttribute(METADATA, NS_METADATA, Constants.ATTR_NAME , name);
|
||||||
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
|
writer.writeStartElement(ATOM, Constants.ATOM_ELEM_TITLE, NS_ATOM);
|
||||||
if (title != null) {
|
if (title != null) {
|
||||||
writer.writeCharacters(title);
|
writer.writeCharacters(title);
|
||||||
|
|
|
@ -87,13 +87,13 @@ public class ServiceDocumentXmlSerializerTest {
|
||||||
+ "metadata:context=\"http://host/svc/$metadata\">"
|
+ "metadata:context=\"http://host/svc/$metadata\">"
|
||||||
+ "<app:workspace>"
|
+ "<app:workspace>"
|
||||||
+ "<atom:title>org.olingo.container</atom:title>"
|
+ "<atom:title>org.olingo.container</atom:title>"
|
||||||
+ "<app:collection href=\"ESAllPrim\">"
|
+ "<app:collection href=\"ESAllPrim\" metadata:name=\"ESAllPrim\">"
|
||||||
+ "<atom:title>ESAllPrim</atom:title>"
|
+ "<atom:title>ESAllPrim</atom:title>"
|
||||||
+ "</app:collection>"
|
+ "</app:collection>"
|
||||||
+ "<metadata:function-import href=\"FINRTInt16\">"
|
+ "<metadata:function-import href=\"FINRTInt16\" metadata:name=\"FINRTInt16\">"
|
||||||
+ "<atom:title>FINRTInt16</atom:title>"
|
+ "<atom:title>FINRTInt16</atom:title>"
|
||||||
+ "</metadata:function-import>"
|
+ "</metadata:function-import>"
|
||||||
+ "<metadata:singleton href=\"SI\">"
|
+ "<metadata:singleton href=\"SI\" metadata:name=\"SI\">"
|
||||||
+ "<atom:title>SI</atom:title>"
|
+ "<atom:title>SI</atom:title>"
|
||||||
+ "</metadata:singleton>"
|
+ "</metadata:singleton>"
|
||||||
+ "</app:workspace>"
|
+ "</app:workspace>"
|
||||||
|
|
|
@ -164,6 +164,7 @@ public class ContainerProvider {
|
||||||
return new CsdlEntitySet()
|
return new CsdlEntitySet()
|
||||||
.setName("ESAllPrim")
|
.setName("ESAllPrim")
|
||||||
.setType(EntityTypeProvider.nameETAllPrim)
|
.setType(EntityTypeProvider.nameETAllPrim)
|
||||||
|
.setTitle("All PropertyTypes EntitySet")
|
||||||
.setNavigationPropertyBindings(Arrays
|
.setNavigationPropertyBindings(Arrays
|
||||||
.asList(new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimOne").setTarget("ESTwoPrim"),
|
.asList(new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimOne").setTarget("ESTwoPrim"),
|
||||||
new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimMany").setTarget("ESTwoPrim")))
|
new CsdlNavigationPropertyBinding().setPath("NavPropertyETTwoPrimMany").setTarget("ESTwoPrim")))
|
||||||
|
@ -658,6 +659,7 @@ public class ContainerProvider {
|
||||||
if (name.equals("FINRTInt16")) {
|
if (name.equals("FINRTInt16")) {
|
||||||
return new CsdlFunctionImport()
|
return new CsdlFunctionImport()
|
||||||
.setName(name)
|
.setName(name)
|
||||||
|
.setTitle("Simple FunctionImport")
|
||||||
.setFunction(FunctionProvider.nameUFNRTInt16)
|
.setFunction(FunctionProvider.nameUFNRTInt16)
|
||||||
.setIncludeInServiceDocument(true);
|
.setIncludeInServiceDocument(true);
|
||||||
|
|
||||||
|
@ -804,6 +806,7 @@ public class ContainerProvider {
|
||||||
if (name.equals("SI")) {
|
if (name.equals("SI")) {
|
||||||
return new CsdlSingleton()
|
return new CsdlSingleton()
|
||||||
.setName("SI")
|
.setName("SI")
|
||||||
|
.setTitle("Simple Singelton")
|
||||||
.setType(EntityTypeProvider.nameETTwoPrim);
|
.setType(EntityTypeProvider.nameETTwoPrim);
|
||||||
|
|
||||||
} else if (name.equals("SINav")) {
|
} else if (name.equals("SINav")) {
|
||||||
|
|
|
@ -67,17 +67,20 @@ public class ServiceDocumentTest {
|
||||||
metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
|
metadata.getServiceMetadataETagSupport().getMetadataETag().replace("\"", "\\\"")));
|
||||||
|
|
||||||
assertTrue(jsonString.contains("ESAllPrim"));
|
assertTrue(jsonString.contains("ESAllPrim"));
|
||||||
|
assertTrue(jsonString.contains("All PropertyTypes EntitySet"));
|
||||||
assertTrue(jsonString.contains("ESCollAllPrim"));
|
assertTrue(jsonString.contains("ESCollAllPrim"));
|
||||||
assertTrue(jsonString.contains("ESKeyNavCont"));
|
assertTrue(jsonString.contains("ESKeyNavCont"));
|
||||||
assertFalse(jsonString.contains("ESInvisible"));
|
assertFalse(jsonString.contains("ESInvisible"));
|
||||||
|
|
||||||
assertTrue(jsonString.contains("FINRTInt16"));
|
assertTrue(jsonString.contains("FINRTInt16"));
|
||||||
|
assertTrue(jsonString.contains("Simple FunctionImport"));
|
||||||
assertTrue(jsonString.contains("FINRTCollETMixPrimCollCompTwoParam"));
|
assertTrue(jsonString.contains("FINRTCollETMixPrimCollCompTwoParam"));
|
||||||
assertTrue(jsonString.contains("FICRTCollESKeyNavContParam"));
|
assertTrue(jsonString.contains("FICRTCollESKeyNavContParam"));
|
||||||
assertFalse(jsonString.contains("FINInvisibleRTInt16"));
|
assertFalse(jsonString.contains("FINInvisibleRTInt16"));
|
||||||
assertTrue(jsonString.contains("FunctionImport"));
|
assertTrue(jsonString.contains("FunctionImport"));
|
||||||
|
|
||||||
assertTrue(jsonString.contains("SI"));
|
assertTrue(jsonString.contains("SI"));
|
||||||
|
assertTrue(jsonString.contains("Simple Singelton"));
|
||||||
assertTrue(jsonString.contains("SINav"));
|
assertTrue(jsonString.contains("SINav"));
|
||||||
assertTrue(jsonString.contains("SIMedia"));
|
assertTrue(jsonString.contains("SIMedia"));
|
||||||
assertTrue(jsonString.contains("Singleton"));
|
assertTrue(jsonString.contains("Singleton"));
|
||||||
|
|
Loading…
Reference in New Issue