title: Jax RS & Jersey with Junit; Test case is ignored
body: <p>I can't get Jersey to work with Junit. Can anyone help here? I don't know what else to do.</p>
  
  <p>I'm using my tomcat server, and when I run the project, I right-click the folder and select "run on server." After this is done, I am able to use a post-client in my web browser to use the web service and it works. I just cant get it to interact with JUnit. <strong>It seems that it can't find the url, but I swear it works when I go to the post client.</strong> 
  what I expect the url to be is: </p>
  
  <p><a href="http://localhost:8080/propsub/webapi/new/getit" rel="nofollow noreferrer">http://localhost:8080/propsub/webapi/new/getit</a> </p>
  
  <p>Here are the warnings + output that I get when I try to run my testcase with my tomcast server stopped:</p>
  
  <pre><code>Feb 01, 2018 3:30:31 PM org.glassfish.jersey.test.JerseyTest getDefaultTestContainerFactory
  WARNING: Found multiple TestContainerFactory service providers, using the first found {0}
  Feb 01, 2018 3:30:31 PM org.glassfish.jersey.test.jdkhttp.JdkHttpServerTestContainerFactory$JdkHttpSe    rverTestContainer &lt;init&gt;
  INFO: Creating JdkHttpServerTestContainer configured at the base URI http://localhost:8080/
  Feb 01, 2018 3:30:31 PM org.glassfish.jersey.internal.inject.Providers checkProviderRuntime
  WARNING: A provider com.liron.test.TestCases registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.liron.test.TestCases will be ignored. 
  begin test case
  end : 404 x: 
  </code></pre>
  
  <p>Here is the output when my server is <strong>on</strong>:</p>
  
  <pre><code>Feb 02, 2018 9:49:09 AM org.glassfish.jersey.test.JerseyTest getDefaultTestContainerFactory
  WARNING: Found multiple TestContainerFactory service providers, using the first found {0}
  Feb 02, 2018 9:49:09 AM org.glassfish.jersey.test.jdkhttp.JdkHttpServerTestContainerFactory$JdkHttpServerTestContainer &lt;init&gt;
  INFO: Creating JdkHttpServerTestContainer configured at the base URI http://localhost:8080/
  Feb 02, 2018 9:49:10 AM org.glassfish.jersey.internal.inject.Providers checkProviderRuntime
  WARNING: A provider com.liron.test.TestCases registered in SERVER runtime does not implement any provider interfaces applicable in the SERVER runtime. Due to constraint configuration problems the provider com.liron.test.TestCases will be ignored. 
  </code></pre>
  
  <p>Here is my Junit class:</p>
  
  <pre><code>package com.liron.test;
  
  import static org.junit.Assert.*;
  
  import java.net.URI;
  
  import javax.ws.rs.client.Entity;
  import javax.ws.rs.core.Application;
  import javax.ws.rs.core.Response;
  import javax.ws.rs.ext.Provider;
  import org.glassfish.jersey.server.ResourceConfig;
  import org.glassfish.jersey.test.JerseyTest;
  import org.glassfish.jersey.test.TestProperties;
  import org.junit.Before;
  import org.junit.BeforeClass;
  import org.junit.Test;
  import com.liron.pojo.error.ErrorMsg;
  
  public class TestCases extends JerseyTest{
      @Override
      public Application configure() {
         enable(TestProperties.LOG_TRAFFIC);
          enable(TestProperties.DUMP_ENTITY);
          return new ResourceConfig(TestCases.class);
      }
      @BeforeClass
      public static void setUpBeforeClass() throws Exception{
      }
  
      @Before
      public void setUp() throws Exception{
          super.setUp();
      }
      @Override
      public URI getBaseUri() {
          return URI.create("http://localhost:8080/");
      }
       @Test  
          public void testParseException() {
           System.out.println("begin test case");
           String json = "{\"test\":\"val\".}";
           //Response output = target("propsub/webapi/new/getit").request().buildPost(Entity.json("hey")).invoke();
           //String output = target("/getit").request().post(Entity.json(json), String.class);
           Response output = target("/propsub/webapi/new/getit").request().post(Entity.json("hey"));
            //System.out.println(output.getStatus());
             // assertEquals("should return status 200", "200", output.getStatus());
              //assertNotNull("Should return list", output.getEntity());
             String x = output.readEntity(String.class);
              System.out.println("end : " + output.getStatus() + " x: " + x);
          }
  }
  </code></pre>
  
  <p>Here is the api:</p>
  
  <pre><code>package com.liron.webserv;
  
  import javax.ws.rs.Consumes;
  import javax.ws.rs.GET;
  import javax.ws.rs.POST;
  import javax.ws.rs.Path;
  import javax.ws.rs.Produces;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.Response;
  
  import com.liron.pojo.error.ErrorMsg;
  import com.google.gson.*;
  
  import javax.ws.rs.core.Response.Status;
  import javax.ws.rs.ext.ExceptionMapper;
  import javax.ws.rs.ext.Provider;
  /**
   * Root resource (exposed at "myresource" path)
   */
  @Path("/new")
  public class New {
  
      /**
       * Method handling HTTP GET requests. The returned object will be sent
       * to the client as "text/plain" media type.
       *
       * @return String that will be returned as a text/plain response.
       */
      @Path("/getit")
      @POST
      @Produces(MediaType.APPLICATION_JSON)
      @Consumes(MediaType.APPLICATION_JSON)
      public Response getIt(String s) {
           System.out.println("begin getit");
          return Response.status(Status.NOT_IMPLEMENTED)
                   .entity(new ErrorMsg("414","Testtesttest"))
                   .build();
  
      }
  }
  </code></pre>
  
  <p>Here is the ErrorMsg pojo</p>
  
  <pre><code>package com.liron.pojo.error;
  
  public class ErrorMsg{
  
      String errorCode;
      String errorMessage;
  
      public ErrorMsg(String code, String msg){
          setErrorCode(code);
          setErrorMessage(msg);
      }
      public String getErrorCode(){
          return errorCode;
      }
  
      public void setErrorCode(String errorCode){
          this.errorCode = errorCode;
      }
  
      public String getErrorMessage(){
          return errorMessage;
      }
  
      public void setErrorMessage(String errorMessage){
          this.errorMessage = errorMessage;
      }
  }
  </code></pre>
  
  <p>Application config:</p>
  
  <pre><code>package com.liron.config;
  import java.util.HashMap;
  import java.util.Map;
  
  import javax.ws.rs.ApplicationPath;
  import javax.ws.rs.core.Application;
  
  @ApplicationPath("/api")
  public class ApplicationConfig extends Application {
  
      @Override
      public Map&lt;String, Object&gt; getProperties() {
          System.out.println("begin getProperties");
          Map&lt;String, Object&gt; properties = new HashMap&lt;String, Object&gt;();
          properties.put("jersey.config.server.provider.packages", "com.memorynotfound.rs");
          System.out.println("end getProperties");
          return properties;
      }
  }
  </code></pre>
  
  <p>Here is my pom.xml</p>
  
  <pre><code>&lt;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/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.liron.webserv&lt;/groupId&gt;
      &lt;artifactId&gt;propsub&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;0.0.1-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;propsub&lt;/name&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;propsub&lt;/finalName&gt;
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
                  &lt;inherited&gt;true&lt;/inherited&gt;
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                      &lt;systemProperties&gt;
                      &lt;property&gt;
                          &lt;name&gt;jersey.config.test.container.port&lt;/name&gt;
                          &lt;value&gt;8080&lt;/value&gt;
                      &lt;/property&gt;
                  &lt;/systemProperties&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet-core&lt;/artifactId&gt;
              &lt;!-- use the following artifactId if you don't need servlet 2.x compatibility --&gt;
              &lt;!-- artifactId&gt;jersey-container-servlet&lt;/artifactId --&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.inject&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-hk2&lt;/artifactId&gt;
          &lt;/dependency&gt;
           &lt;dependency&gt; &lt;groupId&gt;org.glassfish.jersey.media&lt;/groupId&gt; 
              &lt;artifactId&gt;jersey-media-json-binding&lt;/artifactId&gt; &lt;/dependency&gt; 
  
          &lt;dependency&gt;
              &lt;groupId&gt;com.google.code.gson&lt;/groupId&gt;
              &lt;artifactId&gt;gson&lt;/artifactId&gt;
              &lt;version&gt;1.4&lt;/version&gt;
          &lt;/dependency&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;net.sf.jt400&lt;/groupId&gt;
              &lt;artifactId&gt;jt400&lt;/artifactId&gt;
              &lt;version&gt;6.7&lt;/version&gt;
          &lt;/dependency&gt;
  
  
           &lt;dependency&gt;
      &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-test-framework-provider-jdk-http&lt;/artifactId&gt;
      &lt;version&gt;2.22.1&lt;/version&gt;
  &lt;/dependency&gt;
          &lt;dependency&gt;
      &lt;groupId&gt;org.glassfish.jersey.test-framework.providers&lt;/groupId&gt;
      &lt;artifactId&gt;jersey-test-framework-provider-inmemory&lt;/artifactId&gt;
      &lt;scope&gt;test&lt;/scope&gt;
   &lt;/dependency&gt;
  
  &lt;/dependencies&gt;
  &lt;properties&gt;
          &lt;jersey.version&gt;2.26&lt;/jersey.version&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
      &lt;/properties&gt;
  &lt;/project&gt;
  </code></pre>
  
  <p>web.xml</p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  &lt;!-- This web.xml file is not required when using Servlet 3.0 container,
       see implementation details http://jersey.java.net/nonav/documentation/latest/jax-rs.html --&gt;
  &lt;web-app version="2.5" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"&gt;
      &lt;servlet&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;com.liron.webserv&lt;/param-value&gt;
          &lt;/init-param&gt;
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/webapi/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>EDIT UPDATE 1</strong>
  New output after changing my test case to include:</p>
  
  <pre><code>public class TestCases extends JerseyTest{
      @Override
      public Application configure() {
          enable(TestProperties.LOG_TRAFFIC);
          enable(TestProperties.DUMP_ENTITY);
          //return new ResourceConfig(TestCases.class);
          return new ApplicationConfig();
         //return new ResourceConfig().register(New.class);
      }
  </code></pre>
  
  <p>output: </p>
  
  <pre><code>begin getProperties
  end getProperties
  Feb 02, 2018 2:33:44 PM org.glassfish.jersey.test.JerseyTest getDefaultTestContainerFactory
  WARNING: Found multiple TestContainerFactory service providers, using the first found {0}
  Feb 02, 2018 2:33:44 PM org.glassfish.jersey.test.jdkhttp.JdkHttpServerTestContainerFactory$JdkHttpServerTestContainer &lt;init&gt;
  INFO: Creating JdkHttpServerTestContainer configured at the base URI http://localhost:8080/
  </code></pre>