Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

areSimilar() function support in Java8+ #161

Closed
JuanMorenoDeveloper opened this issue Jul 9, 2019 · 9 comments
Closed

areSimilar() function support in Java8+ #161

JuanMorenoDeveloper opened this issue Jul 9, 2019 · 9 comments

Comments

@JuanMorenoDeveloper
Copy link

JuanMorenoDeveloper commented Jul 9, 2019

Hi Guys

BTW Thank you for this project, It's very good and time saver.

I was using it for testing and I was an issue with the areSimilar() function when I use in Java 11+ (In Java 8 works great).

I isolated the sample code here https://github.com/earth001/jaxp-example. I configure a Travis pipeline where you can find the logs https://travis-ci.org/earth001/jaxp-example/builds/556292262 (Only pass in Java 8).

This is the log (It looks like a problem with newlines):

[INFO] Running com.proitc.JaxpProcessorUnitTest
[ERROR] Tests run: 2, Failures: 1, Errors: 0, Skipped: 0, Time elapsed: 0.602 s <<< FAILURE! - in com.proitc.JaxpProcessorUnitTest
[ERROR] givenTwoXml_whenModifyAttribute_thenGetSimilarXml  Time elapsed: 0.13 s  <<< FAILURE!
java.lang.AssertionError: 
Expecting:
 <<notification id="5">
        
    <to customer="false">jhon@email.com</to>
        
    <from>mary@email.com</from>
    
</notification>>
to be equal to:
 <<notification id="5">
    <to customer="false">jhon@email.com</to>
    <from>mary@email.com</from>
</notification>>
but was not.
	at com.proitc.JaxpProcessorUnitTest.givenTwoXml_whenModifyAttribute_thenGetSimilarXml(JaxpProcessorUnitTest.java:54)
[INFO] 
[INFO] Results:
[INFO] 
[ERROR] Failures: 
[ERROR]   JaxpProcessorUnitTest.givenTwoXml_whenModifyAttribute_thenGetSimilarXml:54 
Expecting:
 <<notification id="5">
        
    <to customer="false">jhon@email.com</to>
        
    <from>mary@email.com</from>
    
</notification>>
to be equal to:
 <<notification id="5">
    <to customer="false">jhon@email.com</to>
    <from>mary@email.com</from>
</notification>>
but was not.

Have you experienced something like this before?

Please let me know if this info is enough or if I could bring something additional.

@JuanMorenoDeveloper
Copy link
Author

I'm not sure but it could be related to https://bugs.openjdk.java.net/browse/JDK-8215543

@bodewig
Copy link
Member

bodewig commented Jul 9, 2019

Yes, it looks quite a bit like the test failure I've fixed with 23336de - it seems to affect any version of Java post Java8.

Back then I didn't find the time to investigate the root cause. but the issue you link is a likely candidate (DefaultComparisonFormatter uses XSLT for an "identity transformation" from DOM to String).

@JuanMorenoDeveloper JuanMorenoDeveloper changed the title areSimilar() function support in Java 11 areSimilar() function support in Java8+ Jul 9, 2019
@JuanMorenoDeveloper
Copy link
Author

Here http://java9.wtf/xml-transformer/ I found more info about the issue.

@bodewig
Copy link
Member

bodewig commented Jul 27, 2019

Interesting.

Unfortunately it only confirms the behavior has changed but I still don't see what XMLUnit could do to make Java9+ behave the way we'd want it to.

@JuanMorenoDeveloper
Copy link
Author

Yes, It's true. In order to use the similar() function, I processed the transformer output with a regex to delete the extra lines, like replaceAll("(?m)^[ \t]*\r?\n", "")

In StackOverflow mentions a similar workaround for the CDATA tags, related to another bug with the JDK (It solved in JDK 14). https://stackoverflow.com/questions/55853220/handling-change-in-newlines-by-xml-transformation-for-cdata-from-java-8-to-java
https://bugs.java.com/bugdatabase/view_bug.do?bug_id=JDK-8223291

@bodewig
Copy link
Member

bodewig commented Jul 27, 2019

It may be a good idea to collect issues like this in the Wiki. Do you think you could add a blurb on some new kind of "know issues" page or something like that?

@JuanMorenoDeveloper
Copy link
Author

Sure, I like the idea.

@JuanMorenoDeveloper
Copy link
Author

I create here https://github.com/xmlunit/xmlunit/wiki/XMLUnit-with-Java-9-and-above. I hope it helps

@bodewig
Copy link
Member

bodewig commented Jul 28, 2019

Many thanks!

When I said "the wiki" I meant the "user guide", sorry for not being clear about it. I've copied your page to https://github.com/xmlunit/user-guide/wiki/XMLUnit-with-Java-9-and-above

bodewig added a commit that referenced this issue Nov 3, 2020
Right now this is a repackaged copy of xmlunit-assertj with the
workarounds for #181 and #161 removed.

This is not the final solution, I'll try to extract common APIs (and
tests) for xmlunit-assertj and xmlunit-assertj3 in order to reduce
code duplication later.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants