JAX-RS: Asserting Successful Response With Response.Status.Family

Response.Status.Family introduces a convenient way to assert a HTTP status of being successful (all 2xx status codes) in system tests. Instead of comparing all specific codes, you can rely on the family e.g: Response.Status.Family.SUCCESSFUL:


import javax.ws.rs.client.WebTarget;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import static org.hamcrest.CoreMatchers.is;
import static org.junit.Assert.assertThat;
import org.junit.Test;



    @Test
    public void crud() {
        WebTarget tut = //...
        Response response = tut.request(MediaType.APPLICATION_JSON).get();
        assertThat(response.getStatusInfo().getFamily(), is(Response.Status.Family.SUCCESSFUL));
    }

}


See you at Java EE Workshops at Munich Airport, Terminal 2, particularly in Java EE Testing and Code Quality or Virtual Dedicated Workshops / consulting


NEW online workshop: WebStandards Igniter (online)

Airport MUC workshops: Java EE 7: Bootstrap, Effective, Architectures, Web, React and Angular, Testing and Microservices

Podcast: airhacks.fm and newsletter: airhacks.news

A book about rethinking Java EE Patterns

Comments:

Really useful !!!

Posted by 185.102.40.254 on November 22, 2016 at 02:17 PM CET #

Post a Comment:
  • HTML Syntax: NOT allowed
realworldpatterns.com
Online Workshops
...the last 150 posts
...the last 10 comments
License