Skip to content

Commit

Permalink
bug: indentify the bug with XMLDocument comparison
Browse files Browse the repository at this point in the history
  • Loading branch information
volodya-lombrozo committed May 3, 2024
1 parent e6d3e28 commit 9bb9266
Show file tree
Hide file tree
Showing 8 changed files with 142 additions and 0 deletions.
20 changes: 20 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,26 @@ OF THE POSSIBILITY OF SUCH DAMAGE.
<source>8</source>
</configuration>
</plugin>
<plugin>
<artifactId>maven-invoker-plugin</artifactId>
<configuration>
<!--
@todo #1:90min Enable Groovy Integration Test
The Groovy integration test is disabled because it fails.
The problem is that the XMLDocument#equals method is
indentation-aware, but it shouldn't be.
We need to fix it and enable the test.
-->
<pomExcludes>groovy/pom.xml</pomExcludes>
</configuration>
<dependencies>
<dependency>
<groupId>${project.groupId}</groupId>
<artifactId>${project.artifactId}</artifactId>
<version>${project.version}</version>
</dependency>
</dependencies>
</plugin>
</plugins>
</build>
<profiles>
Expand Down
12 changes: 12 additions & 0 deletions src/it/groovy/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
# Groovy Integration Test

This module contains integration tests for `jcabi-xml` usage in Groovy scripts.

To run the tests, execute the following command:

```shell
mvn clean integration-test invoker:run -Dinvoker.test=groovy -DskipTests
```

The testing Groovy code you can find in the [verify.groovy](verify.groovy)
script.
4 changes: 4 additions & 0 deletions src/it/groovy/first.xmir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<program>
<indentation/>
</program>
1 change: 1 addition & 0 deletions src/it/groovy/invoker.properties
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
invoker.goals = clean
48 changes: 48 additions & 0 deletions src/it/groovy/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,48 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--
Copyright (c) 2012-2022, jcabi.com
All rights reserved.
Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions
are met: 1) Redistributions of source code must retain the above
copyright notice, this list of conditions and the following
disclaimer. 2) Redistributions in binary form must reproduce the above
copyright notice, this list of conditions and the following
disclaimer in the documentation and/or other materials provided
with the distribution. 3) Neither the name of the jcabi.com nor
the names of its contributors may be used to endorse or promote
products derived from this software without specific prior written
permission.
THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
"AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
(INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
OF THE POSSIBILITY OF SUCH DAMAGE.
-->
<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>com.jcabi</groupId>
<artifactId>jcabi</artifactId>
<version>1.39.0</version>
</parent>
<groupId>com.jcabi.xml</groupId>
<artifactId>groovy</artifactId>
<version>1.0-SNAPSHOT</version>
<dependencies>
<dependency>
<groupId>@project.groupId@</groupId>
<artifactId>@project.artifactId@</artifactId>
<version>@project.version@</version>
</dependency>
</dependencies>
</project>
4 changes: 4 additions & 0 deletions src/it/groovy/same.xmir
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<?xml version="1.0" encoding="UTF-8"?>
<program>
<indentation/>
</program>
38 changes: 38 additions & 0 deletions src/it/groovy/verify.groovy
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/*
* Copyright (c) 2012-2022, jcabi.com
* All rights reserved.
*
* Redistribution and use in source and binary forms, with or without
* modification, are permitted provided that the following conditions
* are met: 1) Redistributions of source code must retain the above
* copyright notice, this list of conditions and the following
* disclaimer. 2) Redistributions in binary form must reproduce the above
* copyright notice, this list of conditions and the following
* disclaimer in the documentation and/or other materials provided
* with the distribution. 3) Neither the name of the jcabi.com nor
* the names of its contributors may be used to endorse or promote
* products derived from this software without specific prior written
* permission.
*
* THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
* "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT
* NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
* FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
* THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
* INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
* (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
* SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
* STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
* ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
* OF THE POSSIBILITY OF SUCH DAMAGE.
*/
import com.jcabi.xml.XMLDocument

def log = new File(basedir, 'build.log')
def fist = new XMLDocument(new File(basedir, 'first.xmir'))
def same = new XMLDocument(new File(basedir, 'same.xmir'))

assert fist == same

assert log.text.contains("BUILD SUCCESS")
15 changes: 15 additions & 0 deletions src/test/java/com/jcabi/xml/XMLDocumentTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hamcrest.core.IsEqual;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.w3c.dom.Document;
import org.w3c.dom.Element;
Expand Down Expand Up @@ -381,6 +382,20 @@ void comparesToAnotherDocument() {
);
}

@Test
@Disabled
void comparesDocumentsWithDifferentIndentations() {
// @todo #1:90min Implement comparison of XML documents with different indentations.
// The current implementation of XMLDocument does not ignore different indentations
// when comparing two XML documents. We need to implement a comparison that ignores
// different indentations. Don't forget to remove the @Disabled annotation from this test.
MatcherAssert.assertThat(
"Different indentations should be ignored",
new XMLDocument("<program>\n <indentation/></program>"),
Matchers.equalTo(new XMLDocument("<program>\n <indentation/></program>"))
);
}

@Test
void preservesXmlNamespaces() {
final String xml = "<a xmlns='http://www.w3.org/1999/xhtml'><b/></a>";
Expand Down

0 comments on commit 9bb9266

Please sign in to comment.