Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring 3.2 Test, com.jajway not included as dependency

My tests were failing because of a class not found exception on

import com.jayway.jsonpath.InvalidPathException;

within

org.springframework.test.util.JsonPathExpectationsHelper;

Manually adding the jayway dependency to my maven pom removed this error and my test ran as expected.

Have I found a bug, or do I need to add a different spring jar as well as spring test ?

like image 272
NimChimpsky Avatar asked Dec 22 '12 17:12

NimChimpsky


3 Answers

In my case

Having test code what contained jsonPath usage:

 mockMvc.perform(get("/api/userDetails").header("Authorization", base64ForTestUser).accept(MediaType.APPLICATION_JSON))
                .andExpect(status().isOk())
                .andDo(print())
                .andExpect(jsonPath("userName").value("testUser"));

I was getting

java.lang.NoClassDefFoundError: com/jayway/jsonpath/InvalidPathException

and

java.lang.ClassNotFoundException: com.jayway.jsonpath.InvalidPathException

This error was directly caused by lack of such dependencies

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>0.8.1</version>
    <scope>test</scope>
</dependency>
like image 125
pbaranski Avatar answered Nov 04 '22 18:11

pbaranski


External dependencies (e.g., JUnit, Mockito, Easy Mock, JayWay, etc.) are not included in Spring, so it is necessary to explicitly add them (Ant/Maven/Ivy dependency, or jar files) to the project's classpath.

like image 33
izilotti Avatar answered Nov 04 '22 19:11

izilotti


Adding this dependency worked

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path-assert</artifactId>
    <version>0.8.1</version>
    <scope>test</scope>
</dependency>

If you want to use another version of json-path-assert you can review the following repository:

http://mvnrepository.com/artifact/com.jayway.jsonpath/json-path

like image 2
Harsh Gupta Avatar answered Nov 04 '22 18:11

Harsh Gupta