Search in sources :

Example 11 with Variant

use of javax.ws.rs.core.Variant in project jersey by jersey.

the class ResponseTest method fromResponseTest.

/*
     * Create an instance of Response using
     * Response.fromResponse(Response).build()
     * verify that correct status code is returned
     */
@Test
public void fromResponseTest() {
    int status = 200;
    String content = "Test Only";
    List<String> type = Arrays.asList("text/plain", "text/html");
    List<String> encoding = Arrays.asList("gzip", "compress");
    List<String> lang = Arrays.asList("en-US", "en-GB", "zh-CN");
    MediaType mt1 = new MediaType("text", "plain");
    MediaType mt2 = new MediaType("text", "html");
    List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt1, mt2).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).encodings((String[]) encoding.toArray()).add().build();
    String tmp;
    for (Variant vt : vts) {
        Response resp1 = Response.ok(content, vt).build();
        Response resp = Response.fromResponse(resp1).build();
        tmp = verifyResponse(resp, content, status, encoding, lang, type, null, null, null);
        if (tmp.endsWith("false")) {
            System.out.println("### " + tmp);
            fail();
        }
    }
}
Also used : Locale(java.util.Locale) Variant(javax.ws.rs.core.Variant) Response(javax.ws.rs.core.Response) MediaType(javax.ws.rs.core.MediaType) Test(org.junit.Test)

Aggregations

Variant (javax.ws.rs.core.Variant)11 Test (org.junit.Test)6 Locale (java.util.Locale)5 Response (javax.ws.rs.core.Response)5 MediaType (javax.ws.rs.core.MediaType)4 LinkedList (java.util.LinkedList)1 List (java.util.List)1 ConstraintViolationException (javax.validation.ConstraintViolationException)1 GET (javax.ws.rs.GET)1 MapPropertiesDelegate (org.glassfish.jersey.internal.MapPropertiesDelegate)1