Testing a JAX-RS Web Service?

前端 未结 10 1238
[愿得一人]
[愿得一人] 2020-12-04 08:36

I\'m currently looking for ways to create automated tests for a JAX-RS (Java API for RESTful Web Services) based web service.

I basically need a way to send it cert

10条回答
  •  独厮守ぢ
    2020-12-04 09:32

    Keep it simple. Have a look at https://github.com/valid4j/http-matchers which can be imported from Maven Central.

        
            org.valid4j
            http-matchers
            1.0
        
    

    Usage example:

    // Statically import the library entry point:
    import static org.valid4j.matchers.http.HttpResponseMatchers.*;
    
    // Invoke your web service using plain JAX-RS. E.g:
    Client client = ClientBuilder.newClient();
    Response response = client.target("http://example.org/hello").request("text/plain").get();
    
    // Verify the response
    assertThat(response, hasStatus(Status.OK));
    assertThat(response, hasHeader("Content-Encoding", equalTo("gzip")));
    assertThat(response, hasEntity(equalTo("content")));
    // etc...
    

提交回复
热议问题