[OLINGO-640] Minor adjustments to tests and deleted logger
This commit is contained in:
parent
366597070f
commit
db0b9d39de
|
@ -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
|
||||
|
|
|
@ -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,26 +97,30 @@ 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) {
|
||||
if (cachedException != null) {
|
||||
throw cachedException;
|
||||
} else {
|
||||
throw new SerializerException("An I/O exception occurred.", e,
|
||||
SerializerException.MessageKeys.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
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,20 +132,24 @@ 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) {
|
||||
if (cachedException != null) {
|
||||
throw cachedException;
|
||||
} else {
|
||||
throw new SerializerException("An I/O exception occurred.", e,
|
||||
SerializerException.MessageKeys.IO_EXCEPTION);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public SerializerResult error(final ODataServerError error) throws SerializerException {
|
||||
|
@ -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);
|
||||
|
|
|
@ -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 {
|
||||
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())
|
||||
|
@ -107,7 +119,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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,11 +169,13 @@ 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" +
|
||||
|
@ -172,7 +186,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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)
|
||||
|
@ -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/"))
|
||||
|
@ -293,7 +308,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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())
|
||||
|
@ -409,7 +425,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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())
|
||||
|
@ -463,7 +480,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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" +
|
||||
|
@ -522,7 +541,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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" +
|
||||
|
@ -588,7 +609,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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" +
|
||||
|
@ -626,7 +649,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -644,7 +667,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -662,7 +685,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -680,7 +703,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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());
|
||||
.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" +
|
||||
|
@ -721,7 +746,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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()
|
||||
|
@ -862,7 +888,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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()
|
||||
|
@ -916,7 +943,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -938,7 +965,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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" +
|
||||
|
@ -988,7 +1017,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1011,7 +1040,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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())
|
||||
|
@ -1054,7 +1084,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1069,7 +1099,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\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" +
|
||||
|
@ -1163,7 +1195,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1178,7 +1210,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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" +
|
||||
|
@ -1248,7 +1282,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1263,7 +1297,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1298,7 +1332,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\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" +
|
||||
|
@ -1364,7 +1400,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\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" +
|
||||
|
@ -1429,7 +1466,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1449,7 +1486,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1481,7 +1518,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1503,7 +1540,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
|
@ -1531,7 +1568,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.format(new Date(currentTimeMillis)) + "</a:updated>" +
|
||||
" <a:author>\n" +
|
||||
" <a:name />\n" +
|
||||
" </a:author>\n" +
|
||||
|
@ -1558,7 +1595,7 @@ public class ODataXmlSerializerTest {
|
|||
" <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>" +
|
||||
.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
|
||||
|
@ -1743,7 +1780,7 @@ public class ODataXmlSerializerTest {
|
|||
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
|
||||
|
@ -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
|
||||
|
@ -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) { }
|
||||
};
|
||||
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue