Maven dependency for testing using Jersey test framework

I am trying to test a Restful service using Jersey test framework, I have the following code.

import java.io.UnsupportedEncodingException;
import java.net.URISyntaxException;
import java.net.URLEncoder;
import javax.json.JsonException;
import org.junit.Test;

import com.sun.jersey.api.client.WebResource;
import com.sun.jersey.test.framework.*;
import com.sun.jersey.test.framework.AppDescriptor;
import com.sun.jersey.test.framework.JerseyTest;
import com.sun.jersey.test.framework.WebAppDescriptor;


public class MakeSureTest extends JerseyTest{

    @Override
    protected AppDescriptor configure() {
        return new WebAppDescriptor.Builder().build();
    }

    @Test
    public void testUserFetchesSuccess() throws JsonException,
            URISyntaxException {


        WebResource webResource = client().resource("http://localhost:8080");
        String encodedParam = null;
        try {
            encodedParam = URLEncoder.encode("customertransactions/retrievetransactions/2015/04/25", "UTF-8");
        } catch (UnsupportedEncodingException e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
        VigLinkComission vigLinkComission = webResource.path(encodedParam)
                .get(MyComission.class);
    }

/*  @Test(expected = UniformInterfaceException.class)
    public void testUserNotFound() {
        WebResource webResource = client().resource("http://localhost:8080/");
        JsonObject json = webResource.path("/rest-test-tutorial/user/id/666")
                .get(JsonObject.class);
    }
*/
}

      

I have the following Maven dependencies.

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>

    <groupId>com.mycompany</groupId>
    <artifactId>MyTracker</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <packaging>jar</packaging>

    <name>MyTracker</name>
    <url>http://maven.apache.org</url>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <maven.compiler.source>1.7</maven.compiler.source>
        <maven.compiler.target>1.7</maven.compiler.target>

    </properties>
    <dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>4.11</version>
        </dependency>
        <dependency>
            <groupId>com.yammer.dropwizard</groupId>
            <artifactId>dropwizard-core</artifactId>
            <version>0.6.2</version>
        </dependency>
        <dependency>
            <groupId>net.vz.mongodb.jackson</groupId>
            <artifactId>mongo-jackson-mapper</artifactId>
            <version>1.4.2</version>
        </dependency>
        <dependency>
            <groupId>org.jongo</groupId>
            <artifactId>jongo</artifactId>
            <version>1.1</version>
        </dependency>
        <dependency>
            <groupId>org.joda</groupId>
            <artifactId>joda-money</artifactId>
            <version>0.10.0</version>
        </dependency>
        <dependency>
            <groupId>javax</groupId>
            <artifactId>javaee-api</artifactId>
            <version>7.0</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-core</artifactId>
            <version>1.19</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-external</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-client</artifactId>
            <version>3.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>jaxrs-api</artifactId>
            <version>3.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>org.jboss.resteasy</groupId>
            <artifactId>resteasy-jaxrs</artifactId>
            <version>3.0.2.Final</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.jaxrs</groupId>
            <artifactId>jackson-jaxrs-json-provider</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>com.fasterxml.jackson.module</groupId>
            <artifactId>jackson-module-jaxb-annotations</artifactId>
            <version>2.1.4</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-bundle</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-client</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-http</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.jersey-test-framework</groupId>
            <artifactId>jersey-test-framework-grizzly2</artifactId>
            <version>1.19</version>
        </dependency>

        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-server</artifactId>
            <version>1.17.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-grizzly2</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-core</artifactId>
            <version>1.19</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey</groupId>
            <artifactId>jersey-servlet</artifactId>
            <version>1.17.1</version>
        </dependency>
        <dependency>
            <groupId>com.sun.jersey.test.framework</groupId>
            <artifactId>jersey-test-framework</artifactId>
            <version>1.0.3.1</version>

        </dependency>       
    </dependencies>

</project>

      

However, when I do a Maven clean install from with in eclipse, I see the following compilation error, which by the way is not shown in the eclipse IDE, can anyone please tell me why I am seeing an error in the Maven build? what is still missing from the Maven dependency list to allow me to use the Jersey test framework?

[ERROR] Failed to execute goal org.apache.maven.plugins:maven-compiler-plugin:2.3.2:compile (default-compile) on project MyTracker: Compilation failure: Compilation failure:
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[12,36] error: cannot find symbol
[ERROR] package com.sun.jersey.test.framework
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[14,36] error: cannot find symbol
[ERROR] package com.sun.jersey.test.framework
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[20,11] error: cannot find symbol
[ERROR] class MyTest
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[21,29] error: package WebAppDescriptor does not exist
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[19,1] error: method does not override or implement a method from a supertype
[ERROR] /home/general/workspace/MyTracker/src/main/java/com/mycompany/MyTracker/Test/MyTest.java:[29,28] error: cannot find symbol

      

+3


source to share


1 answer


I suspect your Maven project does not have the correct directory structure.

The corresponding class ( MakeSureTest

) must be in the directory src/test/java

, also in the appropriate package structure.



Try to organize your classes this way and release mvn clean compile

.

+3


source







All Articles