Search in sources :

Example 1 with Variant

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

the class JAXRSClientIT method entityVariantAnnotationsTest.

/*
   * @testName: entityVariantAnnotationsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:497; JAXRS:JAVADOC:500; JAXRS:JAVADOC:501;
   * JAXRS:JAVADOC:502; JAXRS:JAVADOC:503; JAXRS:JAVADOC:504; JAXRS:JAVADOC:505;
   * 
   * @test_Strategy: Create an entity using a supplied content media type.
   */
@Test
public void entityVariantAnnotationsTest() throws Fault {
    Entity<?> entity;
    Object[] pairs = getEntities();
    MediaType[] media = getMediaTypes(MediaType.class);
    Annotation[] annotations = AnnotatedClass.class.getAnnotations();
    for (int i = 0; i != pairs.length; i++) for (int j = 0; j != media.length; j++) for (int k = 0; k != LANGUAGES.length; k++) for (int l = 0; l != ENCODINGS.length; l++) {
        Variant variant = new Variant(media[j], LANGUAGES[k], ENCODINGS[l]);
        entity = Entity.entity(pairs[i], variant, annotations);
        logMsg(pairs[i], media[j], LANGUAGES[k], ENCODINGS[l]);
        assertEntity(entity, ENTITY_VALUES[i]);
        assertMediaType(entity, media[j].toString());
        assertLanguages(entity, LANGUAGES[k]);
        assertEncoding(entity, ENCODINGS[l]);
        assertVariant(entity, variant);
        assertAnnotations(entity, annotations);
    }
}
Also used : Variant(jakarta.ws.rs.core.Variant) MediaType(jakarta.ws.rs.core.MediaType) Annotation(java.lang.annotation.Annotation) Test(org.junit.jupiter.api.Test)

Example 2 with Variant

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

the class JAXRSClientIT method entityVariantTest.

/*
   * @testName: entityVariantTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:496; JAXRS:JAVADOC:501; JAXRS:JAVADOC:502;
   * JAXRS:JAVADOC:503; JAXRS:JAVADOC:504; JAXRS:JAVADOC:505;
   * 
   * @test_Strategy: Create an entity using a supplied content media type.
   */
@Test
public void entityVariantTest() throws Fault {
    Entity<?> entity;
    Object[] pairs = getEntities();
    MediaType[] media = getMediaTypes(MediaType.class);
    for (int i = 0; i != pairs.length; i++) for (int j = 0; j != media.length; j++) for (int k = 0; k != LANGUAGES.length; k++) for (int l = 0; l != ENCODINGS.length; l++) {
        Variant variant = new Variant(media[j], LANGUAGES[k], ENCODINGS[l]);
        entity = Entity.entity(pairs[i], variant);
        assertEntity(entity, ENTITY_VALUES[i]);
        assertMediaType(entity, media[j].toString());
        assertLanguages(entity, LANGUAGES[k]);
        assertEncoding(entity, ENCODINGS[l]);
        assertVariant(entity, variant);
    }
}
Also used : Variant(jakarta.ws.rs.core.Variant) MediaType(jakarta.ws.rs.core.MediaType) Test(org.junit.jupiter.api.Test)

Example 3 with Variant

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

the class JAXRSClientIT method getLanguageTest.

/*
   * @testName: getLanguageTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:441; JAXRS:JAVADOC:455; JAXRS:JAVADOC:456;
   * JAXRS:SPEC:85; JAXRS:JAVADOC:427;
   * 
   * @test_Strategy: Get the language of the entity. Returns: the language of
   * the entity or null if not specified
   * 
   * ClientRequestFilter.abortWith
   */
@Test
public void getLanguageTest() throws Fault {
    ContextProvider provider = new ContextProvider() {

        @Override
        protected void checkFilterContext(ClientRequestContext context) throws Fault {
            Locale lang = context.getLanguage();
            String entity = lang == null ? "NULL" : lang.toString();
            Response r = Response.ok(entity).build();
            context.abortWith(r);
        }
    };
    Locale locale = Locale.TRADITIONAL_CHINESE;
    Variant variant = new Variant(MediaType.TEXT_XML_TYPE, locale, null);
    Entity<String> entity = Entity.entity("TEST", variant);
    Invocation invocation = buildBuilder(provider).buildPost(entity);
    Response response = invoke(invocation);
    String body = response.readEntity(String.class).toLowerCase().replace('-', '_');
    assertContains(body, locale.toString().toLowerCase());
}
Also used : ClientRequestContext(jakarta.ws.rs.client.ClientRequestContext) Locale(java.util.Locale) Response(jakarta.ws.rs.core.Response) Variant(jakarta.ws.rs.core.Variant) Invocation(jakarta.ws.rs.client.Invocation) Test(org.junit.jupiter.api.Test)

Example 4 with Variant

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

the class JAXRSClientIT method notAcceptableTest.

/*
   * @testName: notAcceptableTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:127; 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.notAcceptable(vts).build() verify that correct status code is
   * returned
   */
@Test
public void notAcceptableTest() throws Fault {
    VerificationResult result;
    Response resp = null;
    int status = 406;
    List<String> encoding = Arrays.asList("gzip", "compress");
    MediaType mt = new MediaType("text", "plain");
    List<Variant> vts = getVariantList(encoding, mt);
    resp = Response.notAcceptable(vts).build();
    result = verifyStatus(resp, status);
    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 5 with Variant

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

the class RequestTest method selectVariantTestResponse.

@GET
@Path("/SelectVariantTestResponse")
public Response selectVariantTestResponse(@Context Request req) {
    List<Variant> list = Variant.encodings("CP1250", "UTF-8").languages(Locale.ENGLISH).mediaTypes(MediaType.APPLICATION_JSON_TYPE).add().build();
    Variant selectedVariant = req.selectVariant(list);
    if (null == selectedVariant)
        return Response.notAcceptable(list).build();
    return Response.ok("entity").build();
}
Also used : Variant(jakarta.ws.rs.core.Variant) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

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