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);
}
}
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);
}
}
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());
}
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);
}
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();
}
Aggregations