Author: cschneider
Date: Mon Aug 26 18:22:14 2013
New Revision: 1517630
URL: http://svn.apache.org/r1517630
Log:
Fix test failure by using xmlunit to compare xml
Modified:
cxf/dosgi/trunk/discovery/local/pom.xml
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
Modified: cxf/dosgi/trunk/discovery/local/pom.xml
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/pom.xml?rev=1517630&r1=1517629&r2=1517630&view=diff
==============================================================================
--- cxf/dosgi/trunk/discovery/local/pom.xml (original)
+++ cxf/dosgi/trunk/discovery/local/pom.xml Mon Aug 26 18:22:14 2013
@@ -56,6 +56,12 @@
<scope>test</scope>
</dependency>
<dependency>
+ <groupId>xmlunit</groupId>
+ <artifactId>xmlunit</artifactId>
+ <version>1.4</version>
+ <scope>test</scope>
+ </dependency>
+ <dependency>
<groupId>org.easymock</groupId>
<artifactId>easymockclassextension</artifactId>
<scope>test</scope>
Modified:
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java?rev=1517630&r1=1517629&r2=1517630&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java
(original)
+++
cxf/dosgi/trunk/discovery/local/src/main/java/org/apache/cxf/dosgi/endpointdesc/EndpointDescriptionBundleParser.java
Mon Aug 26 18:22:14 2013
@@ -88,7 +88,6 @@ public final class EndpointDescriptionBu
}
}
- @SuppressWarnings("unchecked")
Enumeration<URL> urls = b.findEntries(dir, filePattern, false);
return (urls == null) ? Collections.enumeration(new ArrayList<URL>())
: urls;
}
Modified:
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
URL:
http://svn.apache.org/viewvc/cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java?rev=1517630&r1=1517629&r2=1517630&view=diff
==============================================================================
---
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
(original)
+++
cxf/dosgi/trunk/discovery/local/src/test/java/org/apache/cxf/dosgi/endpointdesc/PropertiesMapperTest.java
Mon Aug 26 18:22:14 2013
@@ -18,12 +18,8 @@
*/
package org.apache.cxf.dosgi.endpointdesc;
-import java.io.ByteArrayOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.OutputStream;
+import java.io.ByteArrayInputStream;
import java.net.URL;
-import java.nio.charset.Charset;
import java.util.ArrayList;
import java.util.HashSet;
import java.util.LinkedHashMap;
@@ -32,8 +28,9 @@ import java.util.List;
import java.util.Map;
import java.util.Set;
-import org.apache.cxf.dosgi.discovery.local.util.Utils;
-import org.junit.Assert;
+import org.xml.sax.InputSource;
+
+import org.custommonkey.xmlunit.XMLAssert;
import org.junit.Test;
import org.osgi.xmlns.rsa.v1_0.EndpointDescriptionType;
import org.osgi.xmlns.rsa.v1_0.PropertyType;
@@ -90,41 +87,11 @@ public class PropertiesMapperTest {
EndpointDescriptionType epd = new EndpointDescriptionType();
epd.getProperty().addAll(props);
byte[] epData = new EndpointDescriptionParser().getData(epd);
- String actual = new String(epData, Charset.defaultCharset());
URL edURL = getClass().getResource("/ed2-generated.xml");
- String expected = new String(drainStream(edURL.openStream()));
- Assert.assertEquals(Utils.normXML(expected), Utils.normXML(actual));
+ InputSource expectedXml = new InputSource(edURL.openStream());
+ InputSource actualXml = new InputSource(new
ByteArrayInputStream(epData));
+ XMLAssert.assertXMLEqual(expectedXml, actualXml);
}
-
-
- private static void drainStream(InputStream is, OutputStream os) throws
IOException {
- byte[] bytes = new byte[8192];
-
- int length;
- int offset = 0;
-
- while ((length = is.read(bytes, offset, bytes.length - offset)) != -1)
{
- offset += length;
-
- if (offset == bytes.length) {
- os.write(bytes, 0, bytes.length);
- offset = 0;
- }
- }
- if (offset != 0) {
- os.write(bytes, 0, offset);
- }
- }
-
- private static byte[] drainStream(InputStream is) throws IOException {
- ByteArrayOutputStream baos = new ByteArrayOutputStream();
- try {
- drainStream(is, baos);
- return baos.toByteArray();
- } finally {
- is.close();
- }
- }
}