title: How to test a Jersey REST web service?
body: <p>I have written a Restful Web service and have to test it using JUnit4. I have already written a Client using Jersey Client. But want to know if I can test my service only with junit4. Can someone help me with sample at least. </p>
  
  <p>My rest service has authenticate method that takes user name, password and returns a token. </p>
  
  <p>I have written test case for authenticate method. But I am not sure how to test using url.</p>
  
  <pre><code>public class TestAuthenticate {
      Service service  = new Service();
      String username = "user";
      String password = "password";
      String token;
  
      @Test(expected = Exception.class)
      public final void testAuthenticateInputs() {
          password = "pass";
          service.authenticate(username, password);
      }
  
      @Test(expected = Exception.class)
      public final void testAuthenticateException(){
          username = null;
          String token = service.authenticate(username, password);
          assertNotNull(token);
      }
  
      @Test
      public final void testAuthenticateResult() {
          String token = service.authenticate(username, password);
          assertNotNull(token);
      }
  }
  </code></pre>