Search in sources :

Example 26 with Variant

use of jakarta.ws.rs.core.Variant in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method encodingTest.

/*
   * @testName: encodingTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:268; JAXRS:JAVADOC:264; JAXRS:JAVADOC:267;
   * JAXRS:JAVADOC:263; JAXRS:JAVADOC:265; JAXRS:JAVADOC:255; JAXRS:JAVADOC:256;
   * JAXRS:JAVADOC:257;
   * 
   * @test_Strategy: Create a VariantListBuilder instance using
   * Variant.VariantListBuilder.newInstance(); Add one MediaType to it with two
   * encodings; Verify that two variants in the returned List
   */
@Test
public void encodingTest() throws Fault {
    boolean pass = true;
    StringBuffer sb = new StringBuffer();
    List<String> encoding = Arrays.asList("gzip", "compress");
    List<String> lang = new ArrayList<String>();
    MediaType mt1 = new MediaType();
    List<MediaType> types = Arrays.asList(mt1);
    List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt1).encodings("gzip", "compress").add().build();
    String status = verifyVariants(vts, types, encoding, lang, 2);
    if (status.endsWith("false")) {
        pass = false;
    }
    sb.append(status);
    TestUtil.logTrace(sb.toString());
    assertTrue(pass, "At least one assertion faled: " + sb.toString());
}
Also used : Variant(jakarta.ws.rs.core.Variant) ArrayList(java.util.ArrayList) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 27 with Variant

use of jakarta.ws.rs.core.Variant in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method variantsTest.

/*
   * @testName: variantsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:160;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.status(int).variants(List<Variant>).build() verify that correct
   * status code is returned
   */
@Test
public void variantsTest() throws Fault {
    VerificationResult result;
    Response resp = null;
    int status = 200;
    // String type = "text/plain";
    List<String> encoding = Arrays.asList("gzip", "compress");
    List<String> vars = Arrays.asList("accept-language", "accept-encoding");
    MediaType mt = new MediaType("text", "plain");
    List<Variant> vts = getVariantList(encoding, mt);
    resp = Response.status(status).variants(vts).build();
    result = verifyStatus(resp, status);
    result.append(verifyVary(resp, vars));
    logMsg(result);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) Variant(jakarta.ws.rs.core.Variant) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 28 with Variant

use of jakarta.ws.rs.core.Variant in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method fromResponseTest.

/*
   * @testName: fromResponseTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:122; JAXRS:JAVADOC:141; JAXRS:JAVADOC:123;
   * JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.fromResponse(Response).build() verify that correct status code is
   * returned
   */
@Test
public void fromResponseTest() throws Fault {
    VerificationResult result = new VerificationResult();
    int status = 200;
    String content = "Test Only";
    List<String> type = Arrays.asList("text/plain", "text/html");
    List<String> encoding = Arrays.asList("gzip", "compress");
    MediaType mt1 = new MediaType("text", "plain");
    MediaType mt2 = new MediaType("text", "html");
    List<Variant> vts = getVariantList(encoding, mt1, mt2);
    for (int i = 0; i < vts.size(); i++) {
        Variant vt = vts.get(i);
        Response resp1 = Response.ok(content, vt).build();
        Response resp = Response.fromResponse(resp1).build();
        result.append(verifyContent(resp, content));
        result.append(verifyStatus(resp, status));
        result.append(verifyEncoding(resp, encoding));
        result.append(verifyLanguage(resp, getLangList()));
        result.append(verifyContentType(resp, type));
    }
    logMsg(result);
    assertResultTrue(result);
}
Also used : Variant(jakarta.ws.rs.core.Variant) Response(jakarta.ws.rs.core.Response) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 29 with Variant

use of jakarta.ws.rs.core.Variant in project jaxrs-api by eclipse-ee4j.

the class JAXRSClientIT method okTest5.

/*
   * @testName: okTest5
   * 
   * @assertion_ids: JAXRS:JAVADOC:135; JAXRS:JAVADOC:141; JAXRS:JAVADOC:123;
   * JAXRS:JAVADOC:124; JAXRS:JAVADOC:125; JAXRS:JAVADOC:91; JAXRS:JAVADOC:268;
   * JAXRS:JAVADOC:267; JAXRS:JAVADOC:266; JAXRS:JAVADOC:265; JAXRS:JAVADOC:263;
   * JAXRS:JAVADOC:264;
   * 
   * @test_Strategy: Create an instance of Response using Response.ok(String,
   * Variant).build() verify that correct status code is returned
   */
@Test
public void okTest5() throws Fault {
    VerificationResult result = new VerificationResult();
    Response resp = null;
    int status = 200;
    String content = "Test Only";
    List<String> encoding = Arrays.asList("gzip", "compress");
    MediaType mt = new MediaType("text", "plain");
    List<Variant> vts = getVariantList(encoding, mt);
    for (int i = 0; i < vts.size(); i++) {
        Variant vt = vts.get(i);
        resp = Response.ok(content, vt).build();
        result.append(verifyContent(resp, content));
        result.append(verifyStatus(resp, status));
        result.append(verifyEncoding(resp, encoding));
        result.append(verifyLanguage(resp, getLangList()));
        result.append(verifyContentType(resp, Collections.singletonList(mt.toString())));
    }
    logMsg(result.message);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) Variant(jakarta.ws.rs.core.Variant) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Aggregations

Variant (jakarta.ws.rs.core.Variant)29 Test (org.junit.jupiter.api.Test)25 MediaType (jakarta.ws.rs.core.MediaType)21 Locale (java.util.Locale)13 Response (jakarta.ws.rs.core.Response)6 ArrayList (java.util.ArrayList)5 HashMap (java.util.HashMap)3 GET (jakarta.ws.rs.GET)1 Path (jakarta.ws.rs.Path)1 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)1 Invocation (jakarta.ws.rs.client.Invocation)1 Annotation (java.lang.annotation.Annotation)1 LinkedHashSet (java.util.LinkedHashSet)1