use xmlunit for xml diffs in unit tests

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1825810 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2018-03-04 12:24:44 +00:00
parent 3716f4a556
commit aee50698a4
6 changed files with 34 additions and 11 deletions

View File

@ -35,6 +35,7 @@
<classpathentry exported="true" kind="lib" path="lib/commons-logging-1.2.jar"/>
<classpathentry exported="true" kind="lib" path="lib/commons-collections4-4.1.jar"/>
<classpathentry kind="lib" path="lib/commons-math3-3.6.1.jar"/>
<classpathentry kind="lib" path="lib/xmlunit-core-2.5.1.jar"/>
<classpathentry kind="lib" path="lib/mockito-core-2.13.0.jar"/>
<classpathentry kind="lib" path="lib/byte-buddy-1.7.9.jar"/>
<classpathentry kind="lib" path="lib/byte-buddy-agent-1.7.9.jar"/>

View File

@ -206,6 +206,7 @@ project('ooxml') {
testCompile 'junit:junit:4.12'
testCompile 'org.mockito:mockito-core:2.13.0'
testCompile 'org.xmlunit:xmlunit-core:2.5.1'
testCompile project(path: ':main', configuration: 'tests')
testCompile 'org.openjdk.jmh:jmh-core:1.19'
testCompile 'org.openjdk.jmh:jmh-generator-annprocess:1.19'

View File

@ -164,6 +164,8 @@ under the License.
<property name="main.hamcrest.jar" location="${main.lib}/hamcrest-core-1.3.jar"/>
<property name="main.hamcrest.url" value="${repository.m2}/maven2/org/hamcrest/hamcrest-core/1.3/hamcrest-core-1.3.jar"/>
<property name="main.xmlunit.jar" location="${main.lib}/xmlunit-core-2.5.1.jar"/>
<property name="main.xmlunit.url" value="${repository.m2}/maven2/org/xmlunit/xmlunit-core/2.5.1/xmlunit-core-2.5.1.jar"/>
<property name="main.mockito.jar" location="${main.lib}/mockito-core-2.13.0.jar"/>
<property name="main.mockito.url" value="${repository.m2}/maven2/org/mockito/mockito-core/2.13.0/mockito-core-2.13.0.jar"/>
<property name="main.byte-buddy.jar" location="${main.lib}/byte-buddy-1.7.9.jar"/>
@ -325,6 +327,7 @@ under the License.
<pathelement location="${main.jmh.jar}"/>
<pathelement location="${main.jmhAnnotation.jar}"/>
<pathelement location="${main.hamcrest.jar}"/>
<pathelement location="${main.xmlunit.jar}"/>
<pathelement location="${main.mockito.jar}"/>
<pathelement location="${main.byte-buddy.jar}"/>
<pathelement location="${main.byte-buddy-agent.jar}"/>
@ -632,6 +635,7 @@ under the License.
<available file="${main.jmh.jar}"/>
<available file="${main.jmhAnnotation.jar}"/>
<available file="${main.hamcrest.jar}"/>
<available file="${main.xmlunit.jar}"/>
<available file="${main.mockito.jar}"/>
<available file="${main.byte-buddy.jar}"/>
<available file="${main.byte-buddy-agent.jar}"/>
@ -667,6 +671,7 @@ under the License.
<downloadfile src="${main.jmh.url}" dest="${main.jmh.jar}"/>
<downloadfile src="${main.jmhAnnotation.url}" dest="${main.jmhAnnotation.jar}"/>
<downloadfile src="${main.hamcrest.url}" dest="${main.hamcrest.jar}"/>
<downloadfile src="${main.xmlunit.url}" dest="${main.xmlunit.jar}"/>
<downloadfile src="${main.mockito.url}" dest="${main.mockito.jar}"/>
<downloadfile src="${main.byte-buddy.url}" dest="${main.byte-buddy.jar}"/>
<downloadfile src="${main.byte-buddy-agent.url}" dest="${main.byte-buddy-agent.jar}"/>

Binary file not shown.

View File

@ -65,6 +65,7 @@
<!-- define some of the third-party or plugin-versions globally to use the same in all modules -->
<xmlbeans.version>2.6.0</xmlbeans.version>
<junit.version>4.12</junit.version>
<xmlunit.version>2.5.1</xmlunit.version>
<mockito.version>2.13.0</mockito.version>
<maven.plugin.resources.version>3.0.1</maven.plugin.resources.version>
<maven.plugin.jar.version>3.0.1</maven.plugin.jar.version>
@ -137,6 +138,12 @@
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<version>${xmlunit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>

View File

@ -18,6 +18,7 @@
package org.apache.poi.xddf.usermodel;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import java.io.IOException;
@ -31,26 +32,34 @@ import org.openxmlformats.schemas.drawingml.x2006.main.CTSystemColor;
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetColorVal;
import org.openxmlformats.schemas.drawingml.x2006.main.STSchemeColorVal;
import org.openxmlformats.schemas.drawingml.x2006.main.STSystemColorVal;
import org.xmlunit.builder.DiffBuilder;
import org.xmlunit.builder.Input;
import org.xmlunit.diff.Diff;
public class TestXDDFColor {
private static final String XMLNS = "xmlns:a=\"http://schemas.openxmlformats.org/drawingml/2006/main\"/>";
@Test
public void testSchemeColor() throws IOException {
XMLSlideShow ppt = new XMLSlideShow();
XSLFTheme theme = ppt.createSlide().getTheme();
try (XMLSlideShow ppt = new XMLSlideShow()) {
XSLFTheme theme = ppt.createSlide().getTheme();
XDDFColor color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.ACCENT_2));
// accent2 in theme1.xml is <a:srgbClr val="C0504D"/>
assertEquals("<a:srgbClr val=\"C0504D\" " + XMLNS, color.getColorContainer().toString());
XDDFColor color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.ACCENT_2));
// accent2 in theme1.xml is <a:srgbClr val="C0504D"/>
Diff d1 = DiffBuilder.compare(Input.fromString("<a:srgbClr val=\"C0504D\" " + XMLNS))
.withTest(color.getColorContainer().toString()).build();
assertFalse(d1.toString(), d1.hasDifferences());
color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.LT_1));
assertEquals("<a:sysClr lastClr=\"FFFFFF\" val=\"window\" " + XMLNS, color.getColorContainer().toString());
color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.LT_1));
Diff d2 = DiffBuilder.compare(Input.fromString("<a:sysClr lastClr=\"FFFFFF\" val=\"window\" " + XMLNS))
.withTest(color.getColorContainer().toString()).build();
assertFalse(d2.toString(), d2.hasDifferences());
color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.DK_1));
assertEquals("<a:sysClr lastClr=\"000000\" val=\"windowText\" " + XMLNS, color.getColorContainer().toString());
ppt.close();
color = XDDFColor.forColorContainer(getThemeColor(theme, STSchemeColorVal.DK_1));
Diff d3 = DiffBuilder.compare(Input.fromString("<a:sysClr lastClr=\"000000\" val=\"windowText\" " + XMLNS))
.withTest(color.getColorContainer().toString()).build();
assertFalse(d3.toString(), d3.hasDifferences());
}
}
private CTColor getThemeColor(XSLFTheme theme, STSchemeColorVal.Enum value) {