Search in sources :

Example 31 with Variant

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));
}
Also used : Variant(javax.ws.rs.core.Variant) Locale(java.util.Locale) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 32 with Variant

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));
}
Also used : Variant(javax.ws.rs.core.Variant) ArrayList(java.util.ArrayList)

Example 33 with Variant

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));
}
Also used : Variant(javax.ws.rs.core.Variant) Locale(java.util.Locale) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 34 with Variant

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);
}
Also used : Locale(java.util.Locale) Variant(javax.ws.rs.core.Variant) Test(org.junit.Test)

Example 35 with Variant

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);
}
Also used : Locale(java.util.Locale) Variant(javax.ws.rs.core.Variant) Test(org.junit.Test)

Aggregations

Variant (javax.ws.rs.core.Variant)282 Produces (javax.ws.rs.Produces)191 Header (org.kie.server.remote.rest.common.Header)184 Path (javax.ws.rs.Path)183 ApiOperation (io.swagger.annotations.ApiOperation)181 ApiResponses (io.swagger.annotations.ApiResponses)175 RestUtils.createCorrectVariant (org.kie.server.remote.rest.common.util.RestUtils.createCorrectVariant)175 RestUtils.getVariant (org.kie.server.remote.rest.common.util.RestUtils.getVariant)170 RestUtils.buildConversationIdHeader (org.kie.server.remote.rest.common.util.RestUtils.buildConversationIdHeader)168 GET (javax.ws.rs.GET)106 DeploymentNotFoundException (org.jbpm.services.api.DeploymentNotFoundException)75 ProcessInstanceNotFoundException (org.jbpm.services.api.ProcessInstanceNotFoundException)72 TaskNotFoundException (org.jbpm.services.api.TaskNotFoundException)70 Consumes (javax.ws.rs.Consumes)52 PermissionDeniedException (org.jbpm.services.task.exception.PermissionDeniedException)41 Test (org.junit.Test)40 PUT (javax.ws.rs.PUT)39 Locale (java.util.Locale)35 POST (javax.ws.rs.POST)33 MediaType (javax.ws.rs.core.MediaType)33