Skip to content

Commit

Permalink
generate AssertJ compatibility tests
Browse files Browse the repository at this point in the history
  • Loading branch information
bodewig committed May 3, 2020
1 parent 68138c8 commit 24444e6
Show file tree
Hide file tree
Showing 9 changed files with 154 additions and 54 deletions.
3 changes: 3 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,9 @@ install: true
script:
- mvn install -B
- cd compat-tests && ./hamcrest-test.sh 2.6.5-SNAPSHOT 2.2
- cd compat-tests && ./assertj-test.sh 2.6.5-SNAPSHOT 3.9.1
# - cd compat-tests && ./assertj-test.sh 2.6.5-SNAPSHOT 3.13.0
# - cd compat-tests && ./assertj-test.sh 2.6.5-SNAPSHOT 3.15.0
notifications:
email:
- [email protected]
Expand Down
28 changes: 28 additions & 0 deletions compat-tests/TestResources.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
/*
This file is licensed to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xmlunit;

public final class TestResources {
public static final String TEST_RESOURCE_DIR = "../../../test-resources/";

public static final String ANIMAL_FILE = TEST_RESOURCE_DIR + "test1.xml";
public static final String BLAME_FILE = TEST_RESOURCE_DIR + "test.blame.html";
public static final String ANIMAL_XSL = TEST_RESOURCE_DIR + "animal.xsl";
public static final String DOG_FILE = TEST_RESOURCE_DIR + "testAnimal.xml";

public static final String BOOK_DTD = TEST_RESOURCE_DIR + "Book.dtd";
public static final String BOOK_XSD = TEST_RESOURCE_DIR + "Book.xsd";

private TestResources() { }
}
82 changes: 82 additions & 0 deletions compat-tests/assertj-test.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,82 @@
#!/bin/sh
set -e

if [ "$#" -ne 2 ]; then
echo "Usage: assertj-test.sh XMLUNIT_VERSION ASSERTJ_VERSION"
exit 1
fi

XMLUNIT_VERSION=$1
ASSERTJ_VERSION=$2

SCRATCH_DIR=scratch/assertj-${ASSERTJ_VERSION}

rm -rf scratch && mkdir -p ${SCRATCH_DIR}/src/test/java/org/xmlunit/

cat > ${SCRATCH_DIR}/pom.xml <<EOF
<?xml version="1.0"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<parent>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-parent</artifactId>
<version>${XMLUNIT_VERSION}</version>
<relativePath>../../..</relativePath>
</parent>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-compat-tests-assertj-${ASSERTJ_VERSION}</artifactId>
<packaging>jar</packaging>
<name>org.xmlunit:xmlunit-compat-tests-assertj-${ASSERTJ_VERSION}</name>
<description>Verifies the AssertJ assertions are compatible with AssertJ ${ASSERTJ_VERSION}</description>
<url>https://www.xmlunit.org/</url>
<properties>
<automatic.module.name>\${project.groupId}.compat-tests-assertj-${ASSERTJ_VERSION}</automatic.module.name>
<assertj.version>${ASSERTJ_VERSION}</assertj.version>
<maven.compile.source>1.7</maven.compile.source>
<maven.compile.target>1.7</maven.compile.target>
</properties>
<dependencies>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
<version>\${assertj.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>net.bytebuddy</groupId>
<artifactId>byte-buddy</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
</project>
EOF

cp TestResources.java ${SCRATCH_DIR}/src/test/java/org/xmlunit/

cp -r ../xmlunit-assertj/src/test/java/org/xmlunit/assertj ${SCRATCH_DIR}/src/test/java/org/xmlunit

mvn -f ${SCRATCH_DIR}/pom.xml test
31 changes: 1 addition & 30 deletions compat-tests/hamcrest-test.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,36 +74,7 @@ cat > ${SCRATCH_DIR}/pom.xml <<EOF
</project>
EOF

cat > ${SCRATCH_DIR}/src/test/java/org/xmlunit/TestResources.java <<'EOF'
/*
This file is licensed to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
*/
package org.xmlunit;
public final class TestResources {
public static final String TEST_RESOURCE_DIR = "../../../test-resources/";
public static final String ANIMAL_FILE = TEST_RESOURCE_DIR + "test1.xml";
public static final String BLAME_FILE = TEST_RESOURCE_DIR + "test.blame.html";
public static final String ANIMAL_XSL = TEST_RESOURCE_DIR + "animal.xsl";
public static final String DOG_FILE = TEST_RESOURCE_DIR + "testAnimal.xml";
public static final String BOOK_DTD = TEST_RESOURCE_DIR + "Book.dtd";
public static final String BOOK_XSD = TEST_RESOURCE_DIR + "Book.xsd";
private TestResources() { }
}
EOF
cp TestResources.java ${SCRATCH_DIR}/src/test/java/org/xmlunit/

cp -r ../xmlunit-matchers/src/test/java/org/xmlunit/bugreports ${SCRATCH_DIR}/src/test/java/org/xmlunit
cp -r ../xmlunit-matchers/src/test/java/org/xmlunit/matchers ${SCRATCH_DIR}/src/test/java/org/xmlunit
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -135,6 +135,11 @@
<artifactId>xmlunit-matchers</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-assertj</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.mockito</groupId>
<artifactId>mockito-core</artifactId>
Expand Down
6 changes: 6 additions & 0 deletions xmlunit-assertj/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,12 @@
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
<artifactId>xmlunit-core</artifactId>
<classifier>tests</classifier>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.assertj</groupId>
<artifactId>assertj-core</artifactId>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import org.junit.Rule;
import org.junit.Test;
import org.xmlunit.TestResources;

import java.io.File;

Expand All @@ -38,8 +39,8 @@ public void testAreNotSimilar_shouldPass() {
@Test
public void testAreNotSimilar_fromFiles_shouldPass() {

File testXml = new File("../test-resources/test1.xml");
File controlXml = new File("../test-resources/test2.xml");
File testXml = new File(TestResources.ANIMAL_FILE);
File controlXml = new File(TestResources.TEST_RESOURCE_DIR + "test2.xml");

assertThat(testXml).and(controlXml).areNotSimilar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import org.w3c.dom.Attr;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.xmlunit.TestResources;
import org.xmlunit.diff.Comparison;
import org.xmlunit.diff.ComparisonController;
import org.xmlunit.diff.ComparisonListener;
Expand Down Expand Up @@ -90,8 +91,8 @@ public void testAreSimilar_fromFiles_shouldFailed() {
thrown.expectAssertionErrorPattern(".*Expecting:.*<(?:.*test2\\.xml)> and <(?:.*test1\\.xml)> to be similar.*");
thrown.expectAssertionError("Expected processing instruction data 'href=\"animal.xsl\" type=\"text/xsl\"' but was 'type=\"text/xsl\" href=\"animal.xsl\"");

File testXml = new File("../test-resources/test1.xml");
File controlXml = new File("../test-resources/test2.xml");
File testXml = new File(TestResources.ANIMAL_FILE);
File controlXml = new File(TestResources.TEST_RESOURCE_DIR + "test2.xml");

assertThat(testXml).and(controlXml).areSimilar();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,10 +16,12 @@
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.xmlunit.TestResources;
import org.xmlunit.validation.Languages;
import org.xmlunit.assertj.util.SetEnglishLocaleRule;

import java.io.File;
import java.util.regex.Pattern;

import javax.xml.transform.stream.StreamSource;
import javax.xml.validation.Schema;
Expand All @@ -38,16 +40,16 @@ public class XmlAssertValidationTest {

@Test
public void testIsValidAgainst_shouldPass() {
StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xsd = new StreamSource(new File("../test-resources/Book.xsd"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));
StreamSource xsd = new StreamSource(new File(TestResources.BOOK_XSD));

assertThat(xml).isValidAgainst(xsd);
}

@Test
public void testIsValidAgainst_withExternallyCreatedSchemaInstance_shouldPass() throws Exception {
StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xsd = new StreamSource(new File("../test-resources/Book.xsd"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));
StreamSource xsd = new StreamSource(new File(TestResources.BOOK_XSD));

SchemaFactory factory = SchemaFactory.newInstance(Languages.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsd);
Expand All @@ -57,16 +59,16 @@ public void testIsValidAgainst_withExternallyCreatedSchemaInstance_shouldPass()

@Test
public void testIsNotValidAgainst_withBrokenXml_shouldPass() {
final StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
final StreamSource xsd = new StreamSource(new File("../test-resources/Book.xsd"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));
StreamSource xsd = new StreamSource(new File(TestResources.BOOK_XSD));

assertThat(xml).isNotValidAgainst(xsd);
}

@Test
public void testIsNotValidAgainst_withBrokenXml_andExternallyCreatedSchemaInstance_shouldPass() throws Exception {
StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
StreamSource xsd = new StreamSource(new File("../test-resources/Book.xsd"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));
StreamSource xsd = new StreamSource(new File(TestResources.BOOK_XSD));

SchemaFactory factory = SchemaFactory.newInstance(Languages.W3C_XML_SCHEMA_NS_URI);
Schema schema = factory.newSchema(xsd);
Expand All @@ -77,21 +79,21 @@ public void testIsNotValidAgainst_withBrokenXml_andExternallyCreatedSchemaInstan
@Test
public void testIsValidAgainst_withBrokenXml_shouldFailed() {

thrown.expectAssertionErrorPattern("^\\nExpecting:\\n <.*\\.\\.\\/test-resources\\/invalidBook.xml>\\nto be valid but found following problems:\\n.*");
thrown.expectAssertionErrorPattern("^\\nExpecting:\\n <.*" + Pattern.quote(TestResources.TEST_RESOURCE_DIR) + "invalidBook.xml>\\nto be valid but found following problems:\\n.*");
thrown.expectAssertionError("1. line=9; column=8; type=ERROR;" +
" message=cvc-complex-type.2.4.b: The content of element 'Book' is not complete." +
" One of '{\"https://www.xmlunit.org/publishing\":Publisher}' is expected.");

StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
StreamSource xsd = new StreamSource(new File("../test-resources/Book.xsd"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));
StreamSource xsd = new StreamSource(new File(TestResources.BOOK_XSD));

assertThat(xml).isValidAgainst(xsd);
}

@Test
public void testIsValidAgainst_withEmptySourcesArray_shouldPass() {

StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));

assertThat(xml).isValidAgainst();
assertThat(xml).isValidAgainst(new Object[0]);
Expand All @@ -104,15 +106,15 @@ public void testIsValidAgainst_withBrokenXmlAndEmptySourcesArray_shouldFailed()
" message=cvc-complex-type.2.4.b: The content of element 'Book' is not complete." +
" One of '{\"https://www.xmlunit.org/publishing\":Publisher}' is expected.");

StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));

assertThat(xml).isValidAgainst();
}

@Test
public void testIsValid_shouldPass() {

StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));

assertThat(xml).isValid();
}
Expand All @@ -124,25 +126,26 @@ public void testIsValid_withBrokenXml_shouldPass() {
" message=cvc-complex-type.2.4.b: The content of element 'Book' is not complete." +
" One of '{\"https://www.xmlunit.org/publishing\":Publisher}' is expected.");

StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));

assertThat(xml).isValid();
}

@Test
public void testIsInvalid_withBrokenXml_shouldPass() {

StreamSource xml = new StreamSource(new File("../test-resources/invalidBook.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "invalidBook.xml"));

assertThat(xml).isInvalid();
}

@Test
public void testIsInvalid_shouldField() {

thrown.expectAssertionErrorPattern("^\\nExpecting:\\n <.*\\.\\.\\/test-resources\\/BookXsdGenerated.xml>\\nto be invalid");
thrown.expectAssertionErrorPattern("^\\nExpecting:\\n <.*"
+ Pattern.quote(TestResources.TEST_RESOURCE_DIR) + "BookXsdGenerated.xml>\\nto be invalid");

StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));

assertThat(xml).isInvalid();
}
Expand All @@ -152,7 +155,7 @@ public void testIsValidAgainst_withNullSchemaSources_shouldFailed() {

thrown.expectAssertionError("actual not to be null");

StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));

assertThat(xml).isValidAgainst((Object[]) null);
}
Expand All @@ -162,7 +165,7 @@ public void testIsValidAgainst_withNullSchema_shouldFailed() {

thrown.expectAssertionError("actual not to be null");

StreamSource xml = new StreamSource(new File("../test-resources/BookXsdGenerated.xml"));
StreamSource xml = new StreamSource(new File(TestResources.TEST_RESOURCE_DIR + "BookXsdGenerated.xml"));

assertThat(xml).isValidAgainst((Schema) null);
}
Expand Down

0 comments on commit 24444e6

Please sign in to comment.