3

I added the following dependency list in pom.xml for my Rest assured project with maven:

<dependency>
    <groupId>com.jayway.restassured</groupId>
    <artifactId>rest-assured</artifactId>
    <version>2.1.0</version>
    <scope>test</scope>
</dependency>

Now I am trying to run following sample code:

import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*;
import static org.hamcrest.Matchers.*;
import java.util.*;
import org.testng.Assert;
import org.testng.annotations.*;

public class TestNGTest1 {

    private Collection collection;

    @Test
    public void testGetSingleUserProgrammatic() {
        Response res = get("/service/single-user");            
        assertEquals(200, res.getStatusCode());
        String json = res.asString();
        JsonPath jp = new JsonPath(json);
        assertEquals("test@hascode.com", jp.get("email"));
        assertEquals("Tim", jp.get("firstName"));
        assertEquals("Testerman", jp.get("lastName"));
        assertEquals("1", jp.get("id"));
    }
}

But this is throwing error while doing mvn test

Error is:

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GBAppAuomation: Compilation failure: Compilation failure:
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,2] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol

Corresponding symbols are get etc, which rest assured uses.

As asked here is complete error message::

Here is the complete error message::   **

[INFO] --- maven-compiler-plugin:2.3.2:testCompile (default-testCompile) @ GBAppAuomation ---
[INFO] Compiling 1 source file to /home/jay/temp/GB_MVN_Proj/GBAppAuomation/target/test-classes
[INFO] -------------------------------------------------------------
[ERROR] COMPILATION ERROR : 
[INFO] -------------------------------------------------------------
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,1] error: cannot find symbol
[ERROR]  class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,17] error: cannot find symbol
[ERROR]  class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol
[ERROR]  class TestNGTest1
/home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,20] error: cannot find symbol
[INFO] 4 errors 
[INFO] -------------------------------------------------------------
[INFO] ------------------------------------------------------------------------
[INFO] BUILD FAILURE
[INFO] ------------------------------------------------------------------------
[INFO] Total time: 3.384s
[INFO] Finished at: Sat Jan 04 15:26:57 IST 2014
[INFO] Final Memory: 16M/202M
[INFO] ------------------------------------------------------------------------
[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:testCompile (default-testCompile) on project GBAppAuomation: Compilation failure: Compilation failure:
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,1] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[50,17] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,2] error: cannot find symbol
[ERROR] class TestNGTest1
[ERROR] /home/jay/temp/GB_MVN_Proj/GBAppAuomation/src/test/java/com/glassbeam/app/TestNGTest1.java:[53,20] error: cannot find symbol
Vadim Kotov
  • 8,084
  • 8
  • 48
  • 62
undefined
  • 3,464
  • 11
  • 48
  • 90

2 Answers2

1

The problem seems to be related with dependencies.

Were there any compilation errors in the IDE?

Because the interface Response from the line below (probably line 50 from the error)

Response res = get("/service/single-user");

belongs to package com.jayway.restassured.response, whereas the only imports in the class related to restassured are

import static com.jayway.restassured.RestAssured.*;
import static com.jayway.restassured.matcher.RestAssuredMatchers.*; 

And the JsonPath class from (probably line 53 from the error)

JsonPath jp = new JsonPath(json);

belongs to package com.jayway.jsonpath and also not imported. This package should be also included into the POM as a dependency:

<dependency>
    <groupId>com.jayway.jsonpath</groupId>
    <artifactId>json-path</artifactId>
    <version>0.9.1</version>
</dependency>
Vlad.Bachurin
  • 1,340
  • 1
  • 14
  • 22
  • Thanks, issue fixed.. imported packages: import static com.jayway.restassured.RestAssured.expect; import static com.jayway.restassured.RestAssured.get; import static com.jayway.restassured.RestAssured.given; + added ur ones.. Everything is working fine now.. only place I am stuck is http://stackoverflow.com/questions/20931722/how-to-test-rest-api-which-require-authentication-using-rest-assured . – undefined Jan 05 '14 at 17:30
0

Please pay attention to the groupId. There are two of them available. The one you need for the Restassured jars is: io.rest-assured.

Currently, this is the latest version :

<dependency>
<groupId>io.rest-assured</groupId>
<artifactId>rest-assured</artifactId>
<version>3.0.3</version>
<scope>test</scope>
</dependency>

If a newer version becomes available, all you need to do is to change the version number in the dependency from 3.0.3 to the new one.

For your information, there is no longer a need to add a standalone JsonPath dependency as it is now fully embedded in the rest-assured artifact as given as above