Search in sources :

Example 21 with Variant

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

the class JAXRSClientIT method checkMediaTypeForEqualTest1.

private static boolean checkMediaTypeForEqualTest1(StringBuffer sb, MediaType type) {
    String encoding = "ISO8859-15";
    Locale lang1 = new Locale("en", "US");
    Locale lang2 = null;
    Boolean pass = true;
    Variant vt1 = new Variant(type, lang1, encoding);
    Variant vt2 = new Variant(type, lang2, encoding);
    if (vt1.equals(vt2)) {
        pass = false;
        sb.append("Equals Test1 Failed" + newline);
    }
    if (vt1.hashCode() == vt2.hashCode()) {
        sb.append("hasCode Test1 Failed: vt1.hashCode()=" + vt1.hashCode() + newline);
        sb.append("                      vt2.hashCode()=" + vt2.hashCode() + newline);
        pass = false;
    }
    return pass;
}
Also used : Locale(java.util.Locale) Variant(jakarta.ws.rs.core.Variant)

Example 22 with Variant

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

the class JAXRSClientIT method constructorMediaStringStringStringStringTest.

/*
     * @testName: constructorMediaStringStringStringStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:902;
     * 
     * @test_Strategy: Create a Variant(MediaType, String, String, String, String)
     */
@Test
public void constructorMediaStringStringStringStringTest() throws Fault {
    Variant vt = null;
    String[] encodings = { null, "CP1250", "UTF8", "ISO8859-2" };
    Locale[] langs = { null, Locale.CANADA, Locale.FRENCH };
    for (String encoding : encodings) for (Locale lang : langs) {
        vt = new Variant(MediaType.APPLICATION_XHTML_XML_TYPE, lang == null ? null : lang.getLanguage(), lang == null ? null : lang.getCountry(), lang == null ? null : lang.getVariant(), encoding);
        verifyVariant(vt, MediaType.APPLICATION_XHTML_XML_TYPE.getType(), MediaType.APPLICATION_XHTML_XML_TYPE.getSubtype(), lang, encoding);
    }
}
Also used : Variant(jakarta.ws.rs.core.Variant) Locale(java.util.Locale) Test(org.junit.jupiter.api.Test)

Example 23 with Variant

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

the class JAXRSClientIT method verifyVariants.

// ////////////////////////////////////////////////////////////////////////
private static void verifyVariants(List<Variant> vts, List<MediaType> mts, List<String> langs, List<String> encodings) throws Fault {
    StringBuffer sb = new StringBuffer();
    boolean pass = true;
    for (Variant vt : vts) {
        if (mts != null) {
            MediaType mt = vt.getMediaType();
            if (mt != null && !mts.contains(mt)) {
                pass = false;
                sb.append("MediaType is not found: " + mt + newline);
            }
        }
        if (langs != null) {
            if (!langs.contains(vt.getLanguage().toString())) {
                sb.append("Language not found: " + vt.getLanguage() + "." + newline);
            }
        }
        if (encodings != null) {
            if (!encodings.contains(vt.getEncoding())) {
                pass = false;
                sb.append("Encoding not found: " + vt.getEncoding() + newline);
            }
        }
    }
    int m = 1;
    int e = 1;
    int l = 1;
    if (mts != null) {
        m = mts.size();
    }
    if (encodings != null) {
        e = encodings.size();
    }
    if (langs != null) {
        l = langs.size();
    }
    if (vts.size() != m * e * l) {
        pass = false;
        sb.append("Number of Variants is incorrect, expecting " + m + "*" + e + "*" + l + ", got " + vts.size() + newline);
    }
    if (!pass) {
        sb.append("Expected language: ");
        if (langs != null) {
            for (String lang : langs) {
                sb.append(lang + ", ");
            }
            sb.append(newline);
        }
        sb.append("Expected encodings: ");
        if (encodings != null) {
            for (String encoding : encodings) {
                sb.append(encoding + ", ");
            }
            sb.append(newline);
        }
        sb.append("Expected MediaType: ");
        for (MediaType mt : mts) {
            sb.append(mt.toString() + ", ");
        }
        sb.append(newline);
        throw new Fault("at least one assertion failed: " + sb.toString());
    }
}
Also used : Variant(jakarta.ws.rs.core.Variant) MediaType(jakarta.ws.rs.core.MediaType)

Example 24 with Variant

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

the class JAXRSClientIT method getLanguageStringTest.

/*
     * @testName: getLanguageStringTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:899;
     * 
     * @test_Strategy: Get the string representation of the variant language
     */
@Test
public void getLanguageStringTest() throws Fault {
    Locale[] langs = { null, Locale.CHINA, Locale.PRC, Locale.CANADA_FRENCH, Locale.GERMAN };
    for (Locale lang : langs) {
        Variant v = new Variant(MediaType.TEXT_PLAIN_TYPE, lang, (String) null);
        if (lang != null)
            assertTrue(v.getLanguageString().contains(lang.getLanguage()), "Created variant contained " + v.getLanguageString() + "but was expected " + lang.getLanguage());
        else
            assertTrue(v.getLanguageString() == null, "#getLanguageString was " + v.getLanguageString() + " expected was null");
    }
    logMsg("#getLanguageString returned exected language string");
}
Also used : Locale(java.util.Locale) Variant(jakarta.ws.rs.core.Variant) Test(org.junit.jupiter.api.Test)

Example 25 with Variant

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

the class JAXRSClientIT method complexTest.

/*
   * @testName: complexTest
   * 
   * @assertion_ids: JAXRS:SPEC:33.7; JAXRS:SPEC:33.8; JAXRS:JAVADOC:268;
   * JAXRS:JAVADOC:264; JAXRS:JAVADOC:267; JAXRS:JAVADOC:263; JAXRS:JAVADOC:265;
   * JAXRS:JAVADOC:266; JAXRS:JAVADOC:255; JAXRS:JAVADOC:256; JAXRS:JAVADOC:257;
   * 
   * @test_Strategy: Create a VariantListBuilder instance using
   * Variant.VariantListBuilder.newInstance(); Add two MediaType to it with three
   * language and two encodings; Verify that 12 variants in the returned List
   */
@Test
public void complexTest() throws Fault {
    boolean pass = true;
    StringBuffer sb = new StringBuffer();
    List<String> encoding = Arrays.asList("gzip", "compress");
    MediaType mt1 = new MediaType();
    MediaType mt2 = new MediaType("application", "atom+xml");
    List<MediaType> types = Arrays.asList(mt1, mt2);
    List<Variant> vts = getVariantList(encoding, mt1, mt2);
    String status = verifyVariants(vts, types, encoding, getLangList(), 12);
    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) 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