0

I am writing a Junit test case which is running successfully. I want a assert to check if response content is not null.

enter image description here

I am able to see the content in response object, but not getting how to print this content or put a assert on this to check for null.

After adding json-path jar I am getting this error on line no 132, it gets terminated:

Any help would be really appreciated.

enter image description here

Samuel Liew
  • 76,741
  • 107
  • 159
  • 260
CoderBeginner
  • 717
  • 1
  • 12
  • 39
  • Use JSONPath to extract values out of a JSON string and assert on them https://www.baeldung.com/guide-to-jayway-jsonpath – A G May 12 '20 at 11:19
  • I am using Spring3 with ant project, downloaded the json-path jar, but it is giving me a noclassdeffound error. I think it doesn't support Spring 3 – CoderBeginner May 12 '20 at 12:00
  • No classDefFound has nothing to do with Spring. I suggest look at the packaging. JsonPath JAR needs to be in the classpath when you run your program. If you have this program on public git, I could take a look at it – A G May 12 '20 at 12:10
  • I cannot share the project on public git. But i have added the screenshot of the error I am getting. If you can please look into it and provide me a solution – CoderBeginner May 12 '20 at 12:30
  • Ah ... that helps.. As you can see from the Error the NoClassDefFound Error is for SLF4J's LoggerFactory. Do you have that in your classpath? BTW you could consider moving to maven with Spring-boot. That could ease up a lot of these packaging issues that you are bound to get with Ant. – A G May 12 '20 at 19:24

1 Answers1

0

from the documentation of mvcResult.getResponse() where getResponse() says: the response, never null. So, i think you can use the follwoing:

assertNotNull(mvcResult.getResponse());

after that you can use whatever you want like:

assertEquals("your return", mvcResult.getResponse().getContentAsString());