[OLINGO-640] Minor adjustments to tests and deleted logger

This commit is contained in:
Christian Amend 2015-08-04 16:23:42 +02:00
parent 366597070f
commit db0b9d39de
3 changed files with 1386 additions and 1303 deletions

View File

@ -38,7 +38,7 @@ import org.apache.olingo.fit.util.StringHelper;
import org.junit.Assert;
import org.junit.Test;
public final class NavigationITCase extends AbstractBaseTestITCase {
public class NavigationITCase extends AbstractBaseTestITCase {
private final ODataClient client = getClient();
@ -60,7 +60,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
appendKeySegment(32767).build()).rawExecute();
String zeroLevelResponseBody = StringHelper.asString(zeroLevelResponse);
assertTrue(zeroLevelResponseBody.contains("\"@odata.context\":\"$metadata#ESAllPrim/$entity\""));
assertTrue(zeroLevelResponseBody.contains("\"$metadata#ESAllPrim/$entity\""));
// one navigation
final InputStream oneLevelResponse = client.getRetrieveRequestFactory().getEntityRequest(
@ -70,7 +70,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
.rawExecute();
String oneLevelResponseBody = StringHelper.asString(oneLevelResponse);
assertTrue(oneLevelResponseBody.contains("\"@odata.context\":\"../$metadata#ESTwoPrim/$entity\""));
assertTrue(oneLevelResponseBody.contains("\"../$metadata#ESTwoPrim/$entity\""));
// two navigation
final InputStream twoLevelResponse = client.getRetrieveRequestFactory().getEntityRequest(
@ -81,7 +81,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
.rawExecute();
String twoLevelResponseBody = StringHelper.asString(twoLevelResponse);
assertTrue(twoLevelResponseBody.contains("\"@odata.context\":\"../../$metadata#ESTwoPrim/$entity\""));
assertTrue(twoLevelResponseBody.contains("\"../../$metadata#ESTwoPrim/$entity\""));
}
@Test

View File

@ -67,8 +67,6 @@ import org.apache.olingo.server.core.serializer.SerializerResultImpl;
import org.apache.olingo.server.core.serializer.utils.CircleStreamBuffer;
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ODataXmlSerializer implements ODataSerializer {
private static final String DATA = "d";
@ -82,14 +80,12 @@ public class ODataXmlSerializer implements ODataSerializer {
private static final String NS_DATA = "http://docs.oasis-open.org/odata/ns/data";
private static final String NS_SCHEMA = "http://docs.oasis-open.org/odata/ns/scheme";
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializer.class);
@Override
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
throws SerializerException {
CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null;
SerializerException cachedException = null;
try {
buffer = new CircleStreamBuffer();
xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
@ -101,16 +97,20 @@ public class ODataXmlSerializer implements ODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
log.error(e.getMessage(), e);
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
if (xmlStreamWriter != null) {
try {
xmlStreamWriter.close();
} catch (XMLStreamException e) {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
if (cachedException != null) {
throw cachedException;
} else {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
}
@ -120,7 +120,7 @@ public class ODataXmlSerializer implements ODataSerializer {
public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null;
SerializerException cachedException = null;
try {
buffer = new CircleStreamBuffer();
xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
@ -132,16 +132,20 @@ public class ODataXmlSerializer implements ODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) {
log.error(e.getMessage(), e);
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
cachedException =
new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
throw cachedException;
} finally {
if (xmlStreamWriter != null) {
try {
xmlStreamWriter.close();
} catch (XMLStreamException e) {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
if (cachedException != null) {
throw cachedException;
} else {
throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION);
}
}
}
}
@ -168,7 +172,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeErrorDetails(String.valueOf(error.getStatusCode()), error.getMessage(), error.getTarget(), writer);
if (error.getDetails() != null && !error.getDetails().isEmpty()) {
writer.writeStartElement("details");
for (ODataErrorDetail inner:error.getDetails()) {
for (ODataErrorDetail inner : error.getDetails()) {
writeErrorDetails(inner.getCode(), inner.getMessage(), inner.getTarget(), writer);
}
writer.writeEndElement();
@ -355,16 +359,16 @@ public class ODataXmlSerializer implements ODataSerializer {
} else {
String id = entity.getId().toASCIIString();
if (id.endsWith("/")) {
writer.writeAttribute("src", id+"$value");
writer.writeAttribute("src", id + "$value");
} else {
writer.writeAttribute("src", id+"/$value");
writer.writeAttribute("src", id + "/$value");
}
}
writer.writeEndElement();
}
// write media links
for (Link link:entity.getMediaEditLinks()) {
for (Link link : entity.getMediaEditLinks()) {
writeLink(writer, link);
}
@ -373,7 +377,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writer.writeStartElement(ATOM, "category", NS_ATOM);
writer.writeAttribute("scheme", NS_SCHEMA);
writer.writeAttribute("term", "#"+resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeAttribute("term", "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement();
// In the case media, content is sibiling
@ -389,7 +393,7 @@ public class ODataXmlSerializer implements ODataSerializer {
if (!entityType.hasStream()) { // content
writer.writeEndElement();
}
writer.writeEndElement(); //entry
writer.writeEndElement(); // entry
}
private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException {
@ -403,7 +407,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writer.writeStartElement(NS_ATOM, "updated");
writer.writeCharacters(new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis())));
.format(new Date(System.currentTimeMillis())));
writer.writeEndElement();
writer.writeStartElement(NS_ATOM, "author");
@ -462,7 +466,7 @@ public class ODataXmlSerializer implements ODataSerializer {
protected void writeProperties(final ServiceMetadata metadata, final EdmStructuredType type,
final List<Property> properties, final SelectOption select, final XMLStreamWriter writer)
throws XMLStreamException, SerializerException {
throws XMLStreamException, SerializerException {
final boolean all = ExpandSelectHelper.isAll(select);
final Set<String> selected = all ? null :
ExpandSelectHelper.getSelectedPropertyNames(select.getSelectItems());
@ -500,7 +504,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(),
innerOptions == null ? false: innerOptions.isRef(),
innerOptions == null ? false : innerOptions.isRef(),
writer);
writer.writeEndElement();
writer.writeEndElement();
@ -514,7 +518,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeLink(writer, getOrCreateLink(linked, propertyName));
}
}
for (Link link:linked.getAssociationLinks()) {
for (Link link : linked.getAssociationLinks()) {
writeLink(writer, link);
}
}
@ -524,12 +528,12 @@ public class ODataXmlSerializer implements ODataSerializer {
Link link = linked.getNavigationLink(navigationPropertyName);
if (link == null) {
link = new Link();
link.setRel("http://docs.oasis-open.org/odata/ns/related/"+navigationPropertyName);
link.setRel("http://docs.oasis-open.org/odata/ns/related/" + navigationPropertyName);
link.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
link.setTitle(navigationPropertyName);
EntityCollection target = new EntityCollection();
link.setInlineEntitySet(target);
link.setHref(linked.getId().toASCIIString()+"/"+navigationPropertyName);
link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
}
return link;
}
@ -537,6 +541,7 @@ public class ODataXmlSerializer implements ODataSerializer {
private void writeLink(final XMLStreamWriter writer, final Link link) throws XMLStreamException {
writeLink(writer, link, true);
}
private void writeLink(final XMLStreamWriter writer, final Link link, final boolean close)
throws XMLStreamException {
writer.writeStartElement(ATOM, "link", NS_ATOM);
@ -596,7 +601,7 @@ public class ODataXmlSerializer implements ODataSerializer {
}
private String collectionType(EdmType type) {
return "#Collection("+type.getFullQualifiedName().getFullQualifiedNameAsString()+")";
return "#Collection(" + type.getFullQualifiedName().getFullQualifiedNameAsString() + ")";
}
private String complexType(ServiceMetadata metadata, EdmComplexType baseType, String definedType)
@ -620,7 +625,7 @@ public class ODataXmlSerializer implements ODataSerializer {
try {
if (edmProperty.isPrimitive()) {
if (edmProperty.isCollection()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection("+edmProperty.getType().getName()+")");
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + edmProperty.getType().getName() + ")");
writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
@ -636,7 +641,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
} else if (property.isComplex()) {
writer.writeAttribute(METADATA, NS_METADATA, "type",
"#"+complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
"#" + complexType(metadata, (EdmComplexType) edmProperty.getType(), property.getType()));
writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, writer);
} else if (property.isEnum()) {
@ -711,7 +716,7 @@ public class ODataXmlSerializer implements ODataSerializer {
throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
} else if (property.isEnum()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", "#"+type.getName());
writer.writeAttribute(METADATA, NS_METADATA, "type", "#" + type.getName());
writePrimitiveValue(type, property.asEnum(),
isNullable, maxLength, precision, scale, isUnicode, writer);
} else {
@ -728,8 +733,8 @@ public class ODataXmlSerializer implements ODataSerializer {
isNullable, maxLength, precision, scale, isUnicode);
if (value == null) {
writer.writeAttribute(DATA, NS_DATA, "null", "true");
} else if(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
writer.writeCharacters(value);
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
writer.writeCharacters(value);
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Double)
@ -785,7 +790,7 @@ public class ODataXmlSerializer implements ODataSerializer {
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
if(property.isNull()) {
if (property.isNull()) {
writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
} else {
writePrimitive(type, property,
@ -873,7 +878,7 @@ public class ODataXmlSerializer implements ODataSerializer {
ContextURLBuilder.create(contextURL).toASCIIString());
}
writeMetadataETag(metadata, writer);
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection("+type.getName()+")");
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + type.getName() + ")");
writePrimitiveCollection(type, property,
options.isNullable(), options.getMaxLength(), options.getPrecision(), options.getScale(),
options.isUnicode(),
@ -980,7 +985,7 @@ public class ODataXmlSerializer implements ODataSerializer {
@Override
public SerializerResult referenceCollection(final ServiceMetadata metadata, final EdmEntitySet edmEntitySet,
final EntityCollection entityCollection, ReferenceCollectionSerializerOptions options)
throws SerializerException {
throws SerializerException {
return entityReferenceCollection(metadata, edmEntitySet.getEntityType(), entityCollection, options);
}

View File

@ -18,8 +18,10 @@
*/
package org.apache.olingo.server.core.serializer.xml;
import java.io.IOException;
import java.io.InputStream;
import java.net.URI;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
@ -63,6 +65,9 @@ import org.apache.olingo.server.core.uri.UriHelperImpl;
import org.apache.olingo.server.tecsvc.MetadataETagSupport;
import org.apache.olingo.server.tecsvc.data.DataProvider;
import org.apache.olingo.server.tecsvc.provider.EdmTechProvider;
import org.custommonkey.xmlunit.Diff;
import org.custommonkey.xmlunit.Difference;
import org.custommonkey.xmlunit.DifferenceListener;
import org.custommonkey.xmlunit.XMLAssert;
import org.custommonkey.xmlunit.XMLUnit;
import org.hamcrest.CoreMatchers;
@ -70,11 +75,17 @@ import org.junit.Assert;
import org.junit.BeforeClass;
import org.junit.Test;
import org.mockito.Mockito;
import org.w3c.dom.Node;
import org.xml.sax.SAXException;
public class ODataXmlSerializerTest {
public class ODataXmlSerializerTest {
private static final ServiceMetadata metadata = new ServiceMetadataImpl(
new EdmTechProvider(), Collections.<EdmxReference> emptyList(), new MetadataETagSupport("WmetadataETag"));
private static final EdmEntityContainer entityContainer = metadata.getEdm().getEntityContainer();
private static final DifferenceListener DIFFERENCE_LISTENER = new CustomDifferenceListener();
private static final int MAX_ALLOWED_UPDATED_DIFFERENCE = 2000;
private static final String UPDATED_FORMAT = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private final DataProvider data = new DataProvider(metadata.getEdm());
private final ODataSerializer serializer = new ODataXmlSerializer();
private final UriHelper helper = new UriHelperImpl();
@ -92,6 +103,7 @@ public class ODataXmlSerializerTest {
public void entitySimple() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@ -106,8 +118,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -149,7 +161,7 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -157,22 +169,24 @@ public class ODataXmlSerializerTest {
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(metadata, edmEntitySet.getEntityType(),
long currentTimeMillis = System.currentTimeMillis();
InputStream content = serializer.entity(metadata, edmEntitySet.getEntityType(),
entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(content);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" "+
" xmlns:d=\"http://docs.oasis-open.org/odata/ns/data\" " +
"m:context=\"$metadata#ESAllPrim/$entity\"\n" +
" m:metadata-etag=\"WmetadataETag\">\n" +
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -210,7 +224,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
"</a:entry>\n" +
"";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test(expected = SerializerException.class)
@ -254,7 +268,7 @@ public class ODataXmlSerializerTest {
InputStream result = serializer.entityCollection(metadata, edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(new URI("http://host:port"))
.entitySet(edmEntitySet).build())
.entitySet(edmEntitySet).build())
.setId("http://host/svc/ESCompAllPrim")
.count(countOption)
.build()).getContent();
@ -277,6 +291,7 @@ public class ODataXmlSerializerTest {
public void entityCollAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCollAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/service/"))
@ -292,8 +307,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCollAllPrim(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -386,13 +401,14 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
public void entityCompAllPrim() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESCompAllPrim");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@ -408,8 +424,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -441,13 +457,14 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
public void entityMixPrimCollComp() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMixPrimCollComp");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@ -462,8 +479,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -507,11 +524,13 @@ public class ODataXmlSerializerTest {
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(metadata, edmEntitySet.getEntityType(),
long currentTimeMillis = System.currentTimeMillis();
InputStream content = serializer.entity(metadata, edmEntitySet.getEntityType(),
entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(content);
final String expectedResult = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -521,8 +540,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMixPrimCollComp(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -573,11 +592,13 @@ public class ODataXmlSerializerTest {
public void entityMedia() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
final Entity entity = data.readAll(edmEntitySet).getEntities().get(0);
final String resultString = IOUtils.toString(serializer.entity(metadata, edmEntitySet.getEntityType(),
long currentTimeMillis = System.currentTimeMillis();
InputStream content = serializer.entity(metadata, edmEntitySet.getEntityType(),
entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(content);
final String expectedResult = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -587,8 +608,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -608,12 +629,14 @@ public class ODataXmlSerializerTest {
public void entitySetMedia() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESMedia");
final EntityCollection entitySet = data.readAll(edmEntitySet);
final String resultString = IOUtils.toString(serializer.entityCollection(metadata,
long currentTimeMillis = System.currentTimeMillis();
InputStream content = serializer.entityCollection(metadata,
edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).build())
.setId("http://host/svc/ESMedia")
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(content);
final String expectedResult = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
@ -625,8 +648,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -643,8 +666,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -661,8 +684,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(3)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -679,8 +702,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESMedia(4)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -702,13 +725,15 @@ public class ODataXmlSerializerTest {
public void primitiveValuesAllNull() throws Exception {
final EdmEntitySet edmEntitySet = entityContainer.getEntitySet("ESAllNullable");
final EntityCollection entitySet = data.readAll(edmEntitySet);
final String resultString = IOUtils.toString(serializer.entityCollection(metadata,
long currentTimeMillis = System.currentTimeMillis();
InputStream content = serializer.entityCollection(metadata,
edmEntitySet.getEntityType(), entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/svc"))
.entitySet(edmEntitySet).build())
.setId("http://host/svc/ESAllNullable")
.build()).getContent());
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().serviceRoot(URI.create("http://host/svc"))
.entitySet(edmEntitySet).build())
.setId("http://host/svc/ESAllNullable")
.build()).getContent();
final String resultString = IOUtils.toString(content);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -720,8 +745,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllNullable(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -831,7 +856,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
" </a:entry>\n" +
"</a:feed>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -843,6 +868,7 @@ public class ODataXmlSerializerTest {
final SelectItem selectItem2 = ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyBoolean");
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
selectItem1, selectItem2, selectItem2));
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
@ -861,8 +887,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -894,6 +920,7 @@ public class ODataXmlSerializerTest {
final EntityCollection entitySet = data.readAll(edmEntitySet);
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString")));
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer
.entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
@ -915,8 +942,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -937,8 +964,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
"<a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
"<a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -956,7 +983,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
" </a:entry>\n" +
"</a:feed>\n";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -967,7 +994,8 @@ public class ODataXmlSerializerTest {
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp", "PropertyString"),
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertyComp", "PropertyComp")));
final String resultString = IOUtils.toString(serializer
long currentTimeMillis = System.currentTimeMillis();
InputStream inputStream = serializer
.entityCollection(metadata, entityType, entitySet,
EntityCollectionSerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
@ -975,7 +1003,8 @@ public class ODataXmlSerializerTest {
.build())
.setId("http://host/svc/ESCompComp")
.select(select)
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(inputStream);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:feed xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -987,8 +1016,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(1)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1010,8 +1039,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESCompComp(2)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1030,7 +1059,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
" </a:entry>\n" +
"</a:feed>\n";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1039,6 +1068,7 @@ public class ODataXmlSerializerTest {
final Entity entity = data.readAll(edmEntitySet).getEntities().get(3);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(
ExpandSelectMock.mockExpandItem(edmEntitySet, "NavPropertyETAllPrimOne")));
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer.entity(metadata, edmEntitySet.getEntityType(), entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet).suffix(Suffix.ENTITY).build())
@ -1053,8 +1083,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1068,8 +1098,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1121,7 +1151,7 @@ public class ODataXmlSerializerTest {
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimMany\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimMany\"\n" +
" href=\"ESTwoPrim(32767)/NavPropertyETAllPrimMany\" />"+
" href=\"ESTwoPrim(32767)/NavPropertyETAllPrimMany\" />" +
" <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETTwoPrim\" />\n" +
" <a:content type=\"application/xml\">\n" +
@ -1132,7 +1162,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
"</a:entry>\n" +
"";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1145,14 +1175,16 @@ public class ODataXmlSerializerTest {
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
long currentTimeMillis = System.currentTimeMillis();
InputStream inputStream = serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(inputStream);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -1162,8 +1194,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1177,8 +1209,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1214,7 +1246,7 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1229,7 +1261,8 @@ public class ODataXmlSerializerTest {
expandItem, expandItem, expandItemAll));
final SelectOption select = ExpandSelectMock.mockSelectOption(Arrays.asList(
ExpandSelectMock.mockSelectItem(edmEntitySet, "PropertySByte")));
final String resultString = IOUtils.toString(serializer
long currentTimeMillis = System.currentTimeMillis();
InputStream inputStream = serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
@ -1237,7 +1270,8 @@ public class ODataXmlSerializerTest {
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(inputStream);
final String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\"\n" +
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -1247,8 +1281,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1262,8 +1296,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1275,7 +1309,7 @@ public class ODataXmlSerializerTest {
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimMany\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimMany\"\n" +
" href=\"ESTwoPrim(32767)/NavPropertyETAllPrimMany\" />"+
" href=\"ESTwoPrim(32767)/NavPropertyETAllPrimMany\" />" +
" <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETTwoPrim\" />\n" +
" <a:content type=\"application/xml\">\n" +
@ -1297,8 +1331,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1306,7 +1340,7 @@ public class ODataXmlSerializerTest {
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimOne\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimOne\"\n" +
" href=\"ESTwoPrim(-365)/NavPropertyETAllPrimOne\" />"+
" href=\"ESTwoPrim(-365)/NavPropertyETAllPrimOne\" />" +
" <a:link\n" +
" rel=\"http://docs.oasis-open.org/odata/ns/related/NavPropertyETAllPrimMany\"\n" +
" type=\"application/atom+xml;type=feed\" title=\"NavPropertyETAllPrimMany\"\n" +
@ -1332,7 +1366,7 @@ public class ODataXmlSerializerTest {
" </a:content>\n" +
"</a:entry>\n" +
"";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1345,7 +1379,8 @@ public class ODataXmlSerializerTest {
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
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
@ -1353,7 +1388,8 @@ public class ODataXmlSerializerTest {
.suffix(Suffix.ENTITY).build())
.expand(expand)
.select(select)
.build()).getContent());
.build()).getContent();
final String resultString = IOUtils.toString(result);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -1363,8 +1399,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1382,7 +1418,7 @@ public class ODataXmlSerializerTest {
" <m:inline>\n" +
" <a:feed />\n" +
" </m:inline>\n" +
" </a:link>"+
" </a:link>" +
" <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETAllPrim\" />\n" +
" <a:content type=\"application/xml\">\n" +
@ -1392,7 +1428,7 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1410,15 +1446,16 @@ public class ODataXmlSerializerTest {
ExpandSelectMock.mockSelectItem(innerEntitySet, "PropertyInt32")));
Mockito.when(expandItemFirst.getSelectOption()).thenReturn(select);
final ExpandOption expand = ExpandSelectMock.mockExpandOption(Arrays.asList(expandItemFirst));
final String resultString = IOUtils.toString(serializer
long currentTimeMillis = System.currentTimeMillis();
InputStream result = serializer
.entity(metadata, entityType, entity,
EntitySerializerOptions.with()
.contextURL(ContextURL.with().entitySet(edmEntitySet)
.selectList(helper.buildContextURLSelectList(entityType, expand, select))
.suffix(Suffix.ENTITY).build())
.expand(expand)
.build()).getContent());
System.out.println(resultString);
.build()).getContent();
final String resultString = IOUtils.toString(result);
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<a:entry xmlns:a=\"http://www.w3.org/2005/Atom\" "
+ "xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
@ -1428,8 +1465,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-365)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1448,8 +1485,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(-32768)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1467,7 +1504,7 @@ public class ODataXmlSerializerTest {
" <m:inline>\n" +
" <a:feed />\n" +
" </m:inline>\n" +
" </a:link>"+
" </a:link>" +
" <a:category scheme=\"http://docs.oasis-open.org/odata/ns/scheme\"\n" +
" term=\"#olingo.odata.test1.ETAllPrim\" />\n" +
" <a:content type=\"application/xml\">\n" +
@ -1480,8 +1517,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESAllPrim(0)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1502,8 +1539,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
@ -1530,8 +1567,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(-32766)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1557,8 +1594,8 @@ public class ODataXmlSerializerTest {
" <a:id>ESTwoPrim(32767)</a:id>\n" +
" <a:title />\n" +
" <a:summary />\n" +
" <a:updated>"+new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(System.currentTimeMillis()))+"</a:updated>" +
" <a:updated>" + new SimpleDateFormat("yyyy-MM-dd'T'HH:mm:ss'Z'")
.format(new Date(currentTimeMillis)) + "</a:updated>" +
" <a:author>\n" +
" <a:name />\n" +
" </a:author>\n" +
@ -1603,7 +1640,7 @@ public class ODataXmlSerializerTest {
" </m:properties>\n" +
" </a:content>\n" +
"</a:entry>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1668,7 +1705,7 @@ public class ODataXmlSerializerTest {
+ "<m:element>Employee2@company.example</m:element>"
+ "<m:element>Employee3@company.example</m:element>"
+ "</m:value>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1693,7 +1730,7 @@ public class ODataXmlSerializerTest {
+ "<d:PropertyInt16 m:type=\"Int16\">111</d:PropertyInt16>"
+ "<d:PropertyString>TEST A</d:PropertyString>"
+ "</m:value>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1727,7 +1764,7 @@ public class ODataXmlSerializerTest {
" <d:PropertyString>TEST 3</d:PropertyString>\n" +
" </m:element>\n" +
"</m:value>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1738,12 +1775,12 @@ public class ODataXmlSerializerTest {
ReferenceSerializerOptions options = ReferenceSerializerOptions.with()
.contextURL(ContextURL.with().suffix(Suffix.REFERENCE).build()).build();
final SerializerResult serializerResult = serializer.reference(metadata, edmEntitySet, entity,options);
final SerializerResult serializerResult = serializer.reference(metadata, edmEntitySet, entity, options);
final String resultString = IOUtils.toString(serializerResult.getContent());
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
"<m:ref xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" m:context=\"$metadata#$ref\" id=\"ESAllPrim(32767)\" />";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1756,7 +1793,7 @@ public class ODataXmlSerializerTest {
final SerializerResult serializerResult = serializer.referenceCollection(metadata,
edmEntitySet,
entityCollection,options);
entityCollection, options);
final String resultString = IOUtils.toString(serializerResult.getContent());
String expected = "<?xml version='1.0' encoding='UTF-8'?>\n" +
@ -1767,7 +1804,7 @@ public class ODataXmlSerializerTest {
" <m:ref id=\"ESAllPrim(-32768)\" />\n" +
" <m:ref id=\"ESAllPrim(0)\" />\n" +
"</a:feed>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
@Test
@ -1780,7 +1817,7 @@ public class ODataXmlSerializerTest {
final SerializerResult serializerResult = serializer.referenceCollection(metadata,
edmEntitySet,
entityCollection,options);
entityCollection, options);
final String resultString = IOUtils.toString(serializerResult.getContent());
@ -1789,6 +1826,47 @@ public class ODataXmlSerializerTest {
" xmlns:m=\"http://docs.oasis-open.org/odata/ns/metadata\"\n" +
" m:context=\"$metadata#Collection($ref)\">\n" +
"</a:feed>";
XMLAssert.assertXMLEqual(expected, resultString);
checkXMLEqual(expected, resultString);
}
private void checkXMLEqual(String resultString, String expected) throws SAXException, IOException {
Diff diff = XMLUnit.compareXML(expected, resultString);
diff.overrideDifferenceListener(DIFFERENCE_LISTENER);
XMLAssert.assertXMLEqual(diff, true);
}
private static class CustomDifferenceListener implements DifferenceListener {
@Override
public int differenceFound(Difference difference) {
final String xpath = "/entry[1]/updated[1]/text()[1]";
if(difference.getControlNodeDetail().getXpathLocation().equals(xpath)) {
String controlValue = difference.getControlNodeDetail().getValue();
String testValue = difference.getTestNodeDetail().getValue();
// allow a difference from two seconds
SimpleDateFormat sdf = new SimpleDateFormat(UPDATED_FORMAT);
try {
long controlTime = sdf.parse(controlValue).getTime();
long testTime = sdf.parse(testValue).getTime();
long diff = controlTime - testTime;
if(diff < 0) {
diff = diff * -1;
}
if(diff < MAX_ALLOWED_UPDATED_DIFFERENCE) {
// allow a difference from 2 seconds
return DifferenceListener.RETURN_IGNORE_DIFFERENCE_NODES_SIMILAR;
}
} catch (ParseException e) {
throw new RuntimeException("Parse exception for updated value (see difference '" + difference + "').");
}
}
//Yes it is a difference so throw an exception
return DifferenceListener.RETURN_ACCEPT_DIFFERENCE;
}
@Override
public void skippedComparison(Node control, Node test) { }
};
}