[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.Assert;
import org.junit.Test; import org.junit.Test;
public final class NavigationITCase extends AbstractBaseTestITCase { public class NavigationITCase extends AbstractBaseTestITCase {
private final ODataClient client = getClient(); private final ODataClient client = getClient();
@ -60,7 +60,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
appendKeySegment(32767).build()).rawExecute(); appendKeySegment(32767).build()).rawExecute();
String zeroLevelResponseBody = StringHelper.asString(zeroLevelResponse); String zeroLevelResponseBody = StringHelper.asString(zeroLevelResponse);
assertTrue(zeroLevelResponseBody.contains("\"@odata.context\":\"$metadata#ESAllPrim/$entity\"")); assertTrue(zeroLevelResponseBody.contains("\"$metadata#ESAllPrim/$entity\""));
// one navigation // one navigation
final InputStream oneLevelResponse = client.getRetrieveRequestFactory().getEntityRequest( final InputStream oneLevelResponse = client.getRetrieveRequestFactory().getEntityRequest(
@ -70,7 +70,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
.rawExecute(); .rawExecute();
String oneLevelResponseBody = StringHelper.asString(oneLevelResponse); String oneLevelResponseBody = StringHelper.asString(oneLevelResponse);
assertTrue(oneLevelResponseBody.contains("\"@odata.context\":\"../$metadata#ESTwoPrim/$entity\"")); assertTrue(oneLevelResponseBody.contains("\"../$metadata#ESTwoPrim/$entity\""));
// two navigation // two navigation
final InputStream twoLevelResponse = client.getRetrieveRequestFactory().getEntityRequest( final InputStream twoLevelResponse = client.getRetrieveRequestFactory().getEntityRequest(
@ -81,7 +81,7 @@ public final class NavigationITCase extends AbstractBaseTestITCase {
.rawExecute(); .rawExecute();
String twoLevelResponseBody = StringHelper.asString(twoLevelResponse); String twoLevelResponseBody = StringHelper.asString(twoLevelResponse);
assertTrue(twoLevelResponseBody.contains("\"@odata.context\":\"../../$metadata#ESTwoPrim/$entity\"")); assertTrue(twoLevelResponseBody.contains("\"../../$metadata#ESTwoPrim/$entity\""));
} }
@Test @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.CircleStreamBuffer;
import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder; import org.apache.olingo.server.core.serializer.utils.ContextURLBuilder;
import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper; import org.apache.olingo.server.core.serializer.utils.ExpandSelectHelper;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ODataXmlSerializer implements ODataSerializer { public class ODataXmlSerializer implements ODataSerializer {
private static final String DATA = "d"; 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_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 String NS_SCHEMA = "http://docs.oasis-open.org/odata/ns/scheme";
private static final Logger log = LoggerFactory.getLogger(ODataXmlSerializer.class);
@Override @Override
public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot) public SerializerResult serviceDocument(final ServiceMetadata metadata, final String serviceRoot)
throws SerializerException { throws SerializerException {
CircleStreamBuffer buffer; CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null; XMLStreamWriter xmlStreamWriter = null;
SerializerException cachedException = null;
try { try {
buffer = new CircleStreamBuffer(); buffer = new CircleStreamBuffer();
xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(), xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
@ -101,26 +97,30 @@ public class ODataXmlSerializer implements ODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build(); return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) { } catch (final XMLStreamException e) {
log.error(e.getMessage(), e); cachedException =
throw new SerializerException("An I/O exception occurred.", e, new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
SerializerException.MessageKeys.IO_EXCEPTION); throw cachedException;
} finally { } finally {
if (xmlStreamWriter != null) { if (xmlStreamWriter != null) {
try { try {
xmlStreamWriter.close(); xmlStreamWriter.close();
} catch (XMLStreamException e) { } catch (XMLStreamException e) {
if (cachedException != null) {
throw cachedException;
} else {
throw new SerializerException("An I/O exception occurred.", e, throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION); SerializerException.MessageKeys.IO_EXCEPTION);
} }
} }
} }
} }
}
@Override @Override
public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException { public SerializerResult metadataDocument(final ServiceMetadata serviceMetadata) throws SerializerException {
CircleStreamBuffer buffer; CircleStreamBuffer buffer;
XMLStreamWriter xmlStreamWriter = null; XMLStreamWriter xmlStreamWriter = null;
SerializerException cachedException = null;
try { try {
buffer = new CircleStreamBuffer(); buffer = new CircleStreamBuffer();
xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(), xmlStreamWriter = XMLOutputFactory.newInstance().createXMLStreamWriter(buffer.getOutputStream(),
@ -132,20 +132,24 @@ public class ODataXmlSerializer implements ODataSerializer {
return SerializerResultImpl.with().content(buffer.getInputStream()).build(); return SerializerResultImpl.with().content(buffer.getInputStream()).build();
} catch (final XMLStreamException e) { } catch (final XMLStreamException e) {
log.error(e.getMessage(), e); cachedException =
throw new SerializerException("An I/O exception occurred.", e, new SerializerException("An I/O exception occurred.", e, SerializerException.MessageKeys.IO_EXCEPTION);
SerializerException.MessageKeys.IO_EXCEPTION); throw cachedException;
} finally { } finally {
if (xmlStreamWriter != null) { if (xmlStreamWriter != null) {
try { try {
xmlStreamWriter.close(); xmlStreamWriter.close();
} catch (XMLStreamException e) { } catch (XMLStreamException e) {
if (cachedException != null) {
throw cachedException;
} else {
throw new SerializerException("An I/O exception occurred.", e, throw new SerializerException("An I/O exception occurred.", e,
SerializerException.MessageKeys.IO_EXCEPTION); SerializerException.MessageKeys.IO_EXCEPTION);
} }
} }
} }
} }
}
@Override @Override
public SerializerResult error(final ODataServerError error) throws SerializerException { public SerializerResult error(final ODataServerError error) throws SerializerException {
@ -168,7 +172,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeErrorDetails(String.valueOf(error.getStatusCode()), error.getMessage(), error.getTarget(), writer); writeErrorDetails(String.valueOf(error.getStatusCode()), error.getMessage(), error.getTarget(), writer);
if (error.getDetails() != null && !error.getDetails().isEmpty()) { if (error.getDetails() != null && !error.getDetails().isEmpty()) {
writer.writeStartElement("details"); writer.writeStartElement("details");
for (ODataErrorDetail inner:error.getDetails()) { for (ODataErrorDetail inner : error.getDetails()) {
writeErrorDetails(inner.getCode(), inner.getMessage(), inner.getTarget(), writer); writeErrorDetails(inner.getCode(), inner.getMessage(), inner.getTarget(), writer);
} }
writer.writeEndElement(); writer.writeEndElement();
@ -355,16 +359,16 @@ public class ODataXmlSerializer implements ODataSerializer {
} else { } else {
String id = entity.getId().toASCIIString(); String id = entity.getId().toASCIIString();
if (id.endsWith("/")) { if (id.endsWith("/")) {
writer.writeAttribute("src", id+"$value"); writer.writeAttribute("src", id + "$value");
} else { } else {
writer.writeAttribute("src", id+"/$value"); writer.writeAttribute("src", id + "/$value");
} }
} }
writer.writeEndElement(); writer.writeEndElement();
} }
// write media links // write media links
for (Link link:entity.getMediaEditLinks()) { for (Link link : entity.getMediaEditLinks()) {
writeLink(writer, link); writeLink(writer, link);
} }
@ -373,7 +377,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writer.writeStartElement(ATOM, "category", NS_ATOM); writer.writeStartElement(ATOM, "category", NS_ATOM);
writer.writeAttribute("scheme", NS_SCHEMA); writer.writeAttribute("scheme", NS_SCHEMA);
writer.writeAttribute("term", "#"+resolvedType.getFullQualifiedName().getFullQualifiedNameAsString()); writer.writeAttribute("term", "#" + resolvedType.getFullQualifiedName().getFullQualifiedNameAsString());
writer.writeEndElement(); writer.writeEndElement();
// In the case media, content is sibiling // In the case media, content is sibiling
@ -389,7 +393,7 @@ public class ODataXmlSerializer implements ODataSerializer {
if (!entityType.hasStream()) { // content if (!entityType.hasStream()) { // content
writer.writeEndElement(); writer.writeEndElement();
} }
writer.writeEndElement(); //entry writer.writeEndElement(); // entry
} }
private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException { private void writerAuthorInfo(final String title, final XMLStreamWriter writer) throws XMLStreamException {
@ -500,7 +504,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeExpandedNavigationProperty(metadata, property, navigationLink, writeExpandedNavigationProperty(metadata, property, navigationLink,
innerOptions == null ? null : innerOptions.getExpandOption(), innerOptions == null ? null : innerOptions.getExpandOption(),
innerOptions == null ? null : innerOptions.getSelectOption(), innerOptions == null ? null : innerOptions.getSelectOption(),
innerOptions == null ? false: innerOptions.isRef(), innerOptions == null ? false : innerOptions.isRef(),
writer); writer);
writer.writeEndElement(); writer.writeEndElement();
writer.writeEndElement(); writer.writeEndElement();
@ -514,7 +518,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeLink(writer, getOrCreateLink(linked, propertyName)); writeLink(writer, getOrCreateLink(linked, propertyName));
} }
} }
for (Link link:linked.getAssociationLinks()) { for (Link link : linked.getAssociationLinks()) {
writeLink(writer, link); writeLink(writer, link);
} }
} }
@ -524,12 +528,12 @@ public class ODataXmlSerializer implements ODataSerializer {
Link link = linked.getNavigationLink(navigationPropertyName); Link link = linked.getNavigationLink(navigationPropertyName);
if (link == null) { if (link == null) {
link = new Link(); 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.setType(Constants.ENTITY_SET_NAVIGATION_LINK_TYPE);
link.setTitle(navigationPropertyName); link.setTitle(navigationPropertyName);
EntityCollection target = new EntityCollection(); EntityCollection target = new EntityCollection();
link.setInlineEntitySet(target); link.setInlineEntitySet(target);
link.setHref(linked.getId().toASCIIString()+"/"+navigationPropertyName); link.setHref(linked.getId().toASCIIString() + "/" + navigationPropertyName);
} }
return link; return link;
} }
@ -537,6 +541,7 @@ public class ODataXmlSerializer implements ODataSerializer {
private void writeLink(final XMLStreamWriter writer, final Link link) throws XMLStreamException { private void writeLink(final XMLStreamWriter writer, final Link link) throws XMLStreamException {
writeLink(writer, link, true); writeLink(writer, link, true);
} }
private void writeLink(final XMLStreamWriter writer, final Link link, final boolean close) private void writeLink(final XMLStreamWriter writer, final Link link, final boolean close)
throws XMLStreamException { throws XMLStreamException {
writer.writeStartElement(ATOM, "link", NS_ATOM); writer.writeStartElement(ATOM, "link", NS_ATOM);
@ -596,7 +601,7 @@ public class ODataXmlSerializer implements ODataSerializer {
} }
private String collectionType(EdmType type) { private String collectionType(EdmType type) {
return "#Collection("+type.getFullQualifiedName().getFullQualifiedNameAsString()+")"; return "#Collection(" + type.getFullQualifiedName().getFullQualifiedNameAsString() + ")";
} }
private String complexType(ServiceMetadata metadata, EdmComplexType baseType, String definedType) private String complexType(ServiceMetadata metadata, EdmComplexType baseType, String definedType)
@ -620,7 +625,7 @@ public class ODataXmlSerializer implements ODataSerializer {
try { try {
if (edmProperty.isPrimitive()) { if (edmProperty.isPrimitive()) {
if (edmProperty.isCollection()) { 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, writePrimitiveCollection((EdmPrimitiveType) edmProperty.getType(), property,
edmProperty.isNullable(), edmProperty.getMaxLength(), edmProperty.isNullable(), edmProperty.getMaxLength(),
edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(), edmProperty.getPrecision(), edmProperty.getScale(), edmProperty.isUnicode(),
@ -636,7 +641,7 @@ public class ODataXmlSerializer implements ODataSerializer {
writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer); writeComplexCollection(metadata, (EdmComplexType) edmProperty.getType(), property, selectedPaths, writer);
} else if (property.isComplex()) { } else if (property.isComplex()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", 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(), writeComplexValue(metadata, (EdmComplexType) edmProperty.getType(), property.asComplex().getValue(),
selectedPaths, writer); selectedPaths, writer);
} else if (property.isEnum()) { } else if (property.isEnum()) {
@ -711,7 +716,7 @@ public class ODataXmlSerializer implements ODataSerializer {
throw new SerializerException("Property type not yet supported!", throw new SerializerException("Property type not yet supported!",
SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName()); SerializerException.MessageKeys.UNSUPPORTED_PROPERTY_TYPE, property.getName());
} else if (property.isEnum()) { } else if (property.isEnum()) {
writer.writeAttribute(METADATA, NS_METADATA, "type", "#"+type.getName()); writer.writeAttribute(METADATA, NS_METADATA, "type", "#" + type.getName());
writePrimitiveValue(type, property.asEnum(), writePrimitiveValue(type, property.asEnum(),
isNullable, maxLength, precision, scale, isUnicode, writer); isNullable, maxLength, precision, scale, isUnicode, writer);
} else { } else {
@ -728,7 +733,7 @@ public class ODataXmlSerializer implements ODataSerializer {
isNullable, maxLength, precision, scale, isUnicode); isNullable, maxLength, precision, scale, isUnicode);
if (value == null) { if (value == null) {
writer.writeAttribute(DATA, NS_DATA, "null", "true"); writer.writeAttribute(DATA, NS_DATA, "null", "true");
} else if(type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) { } else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Boolean)) {
writer.writeCharacters(value); writer.writeCharacters(value);
} else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte) } else if (type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Byte)
|| type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal) || type == EdmPrimitiveTypeFactory.getInstance(EdmPrimitiveTypeKind.Decimal)
@ -785,7 +790,7 @@ public class ODataXmlSerializer implements ODataSerializer {
ContextURLBuilder.create(contextURL).toASCIIString()); ContextURLBuilder.create(contextURL).toASCIIString());
} }
writeMetadataETag(metadata, writer); writeMetadataETag(metadata, writer);
if(property.isNull()) { if (property.isNull()) {
writer.writeAttribute(METADATA, NS_METADATA, "null", "true"); writer.writeAttribute(METADATA, NS_METADATA, "null", "true");
} else { } else {
writePrimitive(type, property, writePrimitive(type, property,
@ -873,7 +878,7 @@ public class ODataXmlSerializer implements ODataSerializer {
ContextURLBuilder.create(contextURL).toASCIIString()); ContextURLBuilder.create(contextURL).toASCIIString());
} }
writeMetadataETag(metadata, writer); writeMetadataETag(metadata, writer);
writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection("+type.getName()+")"); writer.writeAttribute(METADATA, NS_METADATA, "type", "#Collection(" + type.getName() + ")");
writePrimitiveCollection(type, property, writePrimitiveCollection(type, property,
options.isNullable(), options.getMaxLength(), options.getPrecision(), options.getScale(), options.isNullable(), options.getMaxLength(), options.getPrecision(), options.getScale(),
options.isUnicode(), options.isUnicode(),

View File

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