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

XmlExpectationsHelper.assertXmlEqual missing "regardless of order" case [SPR-15156] #19722

Closed
spring-projects-issues opened this issue Jan 17, 2017 · 5 comments
Assignees
Labels
in: test Issues in the test module type: bug A general bug
Milestone

Comments

@spring-projects-issues
Copy link
Collaborator

spring-projects-issues commented Jan 17, 2017

Matthew Depue opened SPR-15156 and commented

XmlExpectationsHelper.assertXmlEqual does not work "regardless of order" as stated in the JavaDoc and as was supported in 4.x.

#18615 shows an example of using the XMLUnit DiffBuilder with a NodeMatcher that seems to have not made it into the current code. However, my local fix uses ElementSelectors.byNameAndText instead of just ElementSelectors.byName.

public void assertXmlEqual(String expected, String actual) throws Exception {
		Diff diffSimilar = DiffBuilder.compare(expected).withTest(actual)
				.withNodeMatcher(new DefaultNodeMatcher(ElementSelectors.byNameAndText))
				.ignoreWhitespace().ignoreComments()
				.checkForSimilar()
				.build();
		if (diffSimilar.hasDifferences()) {
			AssertionErrors.fail("Body content " + diffSimilar.toString());
		}
	}

There is also a unit test missing, something along the lines of the attached file is needed.


Affects: 5.0 M4

Attachments:

Issue Links:

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 13, 2017

Brian Clozel commented

Hi Matthew Depue - quick question: did you copy that XmlExpectationsHelperTests class from somewhere, or is it adapted from another test class in the framework? Thanks!

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 13, 2017

Brian Clozel commented

Thanks Matthew Depue!

I've changed the author tag to reflect that.
This should be available in the next 5.0.0.BUILD-SNAPSHOT.

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 13, 2017

Phil Webb commented

I think this change has made XML Unit a hard dependency. See https://build.spring.io/browse/BOOT-PUB-5267.

java.lang.NoClassDefFoundError: org/xmlunit/diff/NodeMatcher
	at org.springframework.test.web.servlet.result.ContentResultMatchers.<init>(ContentResultMatchers.java:56)
	at org.springframework.test.web.servlet.result.MockMvcResultMatchers.content(MockMvcResultMatchers.java:156)
	at org.springframework.boot.test.context.SpringBootContextLoaderMockMvcTests.testMockHttpEndpoint(SpringBootContextLoaderMockMvcTests.java:71)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:50)
	at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:12)
	at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:47)
	at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:17)
	at org.springframework.test.context.junit4.statements.RunBeforeTestExecutionCallbacks.evaluate(RunBeforeTestExecutionCallbacks.java:73)
	at org.springframework.test.context.junit4.statements.RunAfterTestExecutionCallbacks.evaluate(RunAfterTestExecutionCallbacks.java:83)
	at org.junit.internal.runners.statements.RunBefores.evaluate(RunBefores.java:26)
	at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:75)
	at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:86)
	at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:84)
	at org.junit.runners.ParentRunner.runLeaf(ParentRunner.java:325)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:250)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:97)
	at org.junit.runners.ParentRunner$3.run(ParentRunner.java:290)
	at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:71)
	at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:288)
	at org.junit.runners.ParentRunner.access$000(ParentRunner.java:58)
	at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:268)
	at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
	at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:70)
	at org.junit.runners.ParentRunner.run(ParentRunner.java:363)
	at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:189)
	at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:86)
	at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:678)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
	at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: java.lang.ClassNotFoundException: org.xmlunit.diff.NodeMatcher
	at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
	at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
	at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
	... 35 more

@spring-projects-issues
Copy link
Collaborator Author

spring-projects-issues commented Feb 14, 2017

Phil Webb commented

Hopefully fixed in commit fd5681c5

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: test Issues in the test module type: bug A general bug
Projects
None yet
Development

No branches or pull requests

2 participants