use of javax.ws.rs.core.Variant in project cxf by apache.
the class RequestImplTest method testMultipleVariantsBestMatch.
@Test
public void testMultipleVariantsBestMatch() {
metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en-us");
metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "gzip;q=1.0, compress");
List<Variant> list = new ArrayList<>();
list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "gzip"));
Variant var2 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "gzip");
list.add(var2);
Variant var3 = new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), null);
list.add(var3);
assertSame(var2, new RequestImpl(m).selectVariant(list));
list.clear();
list.add(var3);
assertSame(var3, new RequestImpl(m).selectVariant(list));
}
use of javax.ws.rs.core.Variant in project cxf by apache.
the class RequestImplTest method assertSameVariant.
private void assertSameVariant(MediaType mt, Locale lang, String enc) {
Variant var = new Variant(mt, lang, enc);
List<Variant> list = new ArrayList<>();
list.add(var);
assertSame(var, new RequestImpl(m).selectVariant(list));
}
use of javax.ws.rs.core.Variant in project cxf by apache.
the class RequestImplTest method testMultipleNonMatchingVariants.
@Test
public void testMultipleNonMatchingVariants() {
metadata.putSingle(HttpHeaders.ACCEPT, "application/xml");
metadata.putSingle(HttpHeaders.ACCEPT_LANGUAGE, "en");
metadata.putSingle(HttpHeaders.ACCEPT_ENCODING, "utf-8");
List<Variant> list = new ArrayList<>();
list.add(new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en"), "utf-8"));
list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("es"), "utf-8"));
list.add(new Variant(MediaType.APPLICATION_XML_TYPE, new Locale("en"), "abc"));
assertNull(new RequestImpl(m).selectVariant(list));
}
use of javax.ws.rs.core.Variant in project cxf by apache.
the class ResponseBuilderImplTest method testVariant.
@Test
public void testVariant() throws Exception {
MetadataMap<String, Object> m = new MetadataMap<>();
m.putSingle("Content-Type", MediaType.TEXT_XML_TYPE);
m.putSingle("Content-Language", new Locale("en"));
m.putSingle("Content-Encoding", "gzip");
Variant v = new Variant(MediaType.TEXT_XML_TYPE, new Locale("en"), "gzip");
checkBuild(Response.ok().variant(v).build(), 200, null, m);
}
use of javax.ws.rs.core.Variant in project cxf by apache.
the class ResponseBuilderImplTest method testVariantsArray.
@Test
public void testVariantsArray() throws Exception {
MetadataMap<String, Object> m = new MetadataMap<>();
m.add("Content-Type", MediaType.APPLICATION_JSON_TYPE);
m.add("Content-Language", new Locale("en_uk"));
m.add("Content-Language", new Locale("en_gb"));
m.add("Vary", "Accept");
m.add("Vary", "Accept-Language");
Variant json = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_uk"), null);
Variant xml = new Variant(MediaType.APPLICATION_JSON_TYPE, new Locale("en_gb"), null);
checkBuild(Response.ok().variants(json, xml).build(), 200, null, m);
}
Aggregations