Search in sources :

Example 16 with Variant

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

the class JAXRSClientIT method languageTest.

/*
   * @testName: languageTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:268; JAXRS:JAVADOC:264; JAXRS:JAVADOC:267;
   * JAXRS:JAVADOC:263; JAXRS:JAVADOC:266; 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 three
   * languages; Verify that three Variant in the returned List
   */
@Test
public void languageTest() throws Fault {
    boolean pass = true;
    StringBuffer sb = new StringBuffer();
    List<String> encoding = new ArrayList<String>();
    MediaType mt1 = new MediaType();
    List<MediaType> types = Arrays.asList(mt1);
    List<Variant> vts = Variant.VariantListBuilder.newInstance().mediaTypes(mt1).languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).add().build();
    int size = vts.size();
    sb.append("size================== " + size + newline);
    String status = verifyVariants(vts, types, encoding, getLangList(), 3);
    if (status.endsWith("false")) {
        pass = false;
    }
    sb.append(status);
    assertTrue(pass, "At least one assertion faled: " + sb.toString());
    TestUtil.logTrace(sb.toString());
}
Also used : Variant(jakarta.ws.rs.core.Variant) Locale(java.util.Locale) ArrayList(java.util.ArrayList) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 17 with Variant

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

the class JAXRSClientIT method contentLanguageTest.

/*
   * @testName: contentLanguageTest
   * 
   * @assertion_ids: JAXRS:SPEC:3.6; JAXRS:JAVADOC:78;
   * 
   * @test_Strategy: Client invokes PUT request on root resource at /HeadersTest
   * with Language Header set; Verify that HttpHeaders got the property set by
   * the request
   */
@Test
public void contentLanguageTest() throws Fault {
    setProperty(Property.REQUEST_HEADERS, buildAccept(MediaType.TEXT_PLAIN_TYPE));
    Variant variant = new Variant(MediaType.WILDCARD_TYPE, "en-US", null);
    Entity<String> entity = Entity.entity("anything", variant);
    setRequestContentEntity(entity);
    setProperty(Property.REQUEST, buildRequest(Request.PUT, ""));
    setProperty(Property.SEARCH_STRING_IGNORE_CASE, "Content-Language|en-US");
    invoke();
}
Also used : Variant(jakarta.ws.rs.core.Variant) Test(org.junit.jupiter.api.Test)

Example 18 with Variant

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

the class JAXRSClientIT method variantTest.

/*
   * @testName: variantTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:159;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.status(int).variant(Variant).build() verify that correct status
   * code is returned
   */
@Test
public void variantTest() throws Fault {
    VerificationResult result = new VerificationResult();
    Response resp = null;
    int status = 200;
    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.status(status).variant(vt).build();
        verifyStatus(resp, status);
        verifyEncoding(resp, encoding);
        verifyLanguage(resp, getLangList());
    }
    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 19 with Variant

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

the class JAXRSClientIT method equalsTest3.

/*
     * @testName: equalsTest3
     * 
     * @assertion_ids: JAXRS:JAVADOC:262; JAXRS:JAVADOC:254; JAXRS:JAVADOC:258;
     * 
     * @test_Strategy: Create two Variants with the same properties. Verify
     * Variant.equals and Variant.hasCode methods work properly using those two
     * Variant objects.
     */
@Test
public void equalsTest3() throws Fault {
    StringBuffer sb = new StringBuffer();
    Boolean pass = true;
    String type = "application";
    String subtype = "x-www-form-urlencoded";
    Map<String, String> params = new HashMap<String, String>();
    String encoding = null;
    Locale lang = null;
    MediaType mt4 = new MediaType(type, subtype, params);
    Variant vt1 = new Variant(mt4, lang, encoding);
    Variant vt2 = new Variant(mt4, lang, encoding);
    if (!vt1.equals(vt2)) {
        pass = false;
        sb.append("Equals Test3 Failed" + newline);
    }
    if (vt1.hashCode() != vt2.hashCode()) {
        sb.append("hasCode Test3 Failed: vt1.hashCode()=" + vt1.hashCode() + newline);
        sb.append("                      vt2.hashCode()=" + vt2.hashCode() + newline);
        pass = false;
    }
    assertTrue(pass, "At least one assertion failed: " + sb.toString());
}
Also used : Locale(java.util.Locale) Variant(jakarta.ws.rs.core.Variant) HashMap(java.util.HashMap) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 20 with Variant

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

the class JAXRSClientIT method languagesTest.

/*
     * @testName: languagesTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:259;
     * 
     * @test_Strategy: Call Variant.languages(Locale ...) with three Locales,
     * Verify that three Variant instances created properly
     */
@Test
public void languagesTest() throws Fault {
    List<String> encodingS = null;
    List<MediaType> mts = null;
    List<Variant> vts = Variant.languages(new Locale("en", "US"), new Locale("en", "GB"), new Locale("zh", "CN")).add().build();
    verifyVariants(vts, mts, getLangList(), encodingS);
}
Also used : Variant(jakarta.ws.rs.core.Variant) Locale(java.util.Locale) 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