Search in sources :

Example 56 with ResponseBuilder

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

the class BuilderClientIT method statusTest1.

/*
   * @testName: statusTest1
   *
   * @assertion_ids: JAXRS:JAVADOC:131; JAXRS:JAVADOC:153; JAXRS:JAVADOC:141;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:125; JAXRS:JAVADOC:124;
   *
   * @test_Strategy: Create an instance of ResponseBuilder Response.ok();
   * Setting status using ResponseBuilder.status(int); verify that correct
   * status code is returned
   */
@Test
public void statusTest1() throws Fault {
    VerificationResult result = new VerificationResult();
    Response resp = null;
    ResponseBuilder respb = null;
    for (int status : status_codes) {
        respb = Response.ok();
        respb = respb.status(status);
        resp = respb.build();
        result.append(verifyStatus(resp, status));
    }
    logMsg(result);
    assertTrue(result.pass);
}
Also used : Response(jakarta.ws.rs.core.Response) VerificationResult(ee.jakarta.tck.ws.rs.api.rs.core.responseclient.VerificationResult) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 57 with ResponseBuilder

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

the class BuilderClientIT method variantsTest.

/*
   * @testName: variantsTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:884;
   * 
   * @test_Strategy: Add a Vary header that lists the available variants.
   */
@Test
public void variantsTest() throws Fault {
    List<String> encoding = Arrays.asList("gzip", "compress");
    List<String> vars = Arrays.asList(HttpHeaders.ACCEPT_LANGUAGE, HttpHeaders.ACCEPT_ENCODING);
    MediaType mt = MediaType.APPLICATION_JSON_TYPE;
    ResponseBuilder rb = Response.ok();
    rb = rb.variants(getVariantList(encoding, mt).toArray(new Variant[0]));
    Response response = rb.build();
    VerificationResult result = new VerificationResult();
    result.append(verifyVary(response, vars));
    logMsg(result.message);
    assertTrue(result.pass);
}
Also used : Response(jakarta.ws.rs.core.Response) VerificationResult(ee.jakarta.tck.ws.rs.api.rs.core.responseclient.VerificationResult) MediaType(jakarta.ws.rs.core.MediaType) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 58 with ResponseBuilder

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

the class BuilderClientIT method allowStringSetNullRemovesAllTest.

/*
   * @testName: allowStringSetNullRemovesAllTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:876;
   * 
   * @test_Strategy: if null any existing allowed method list will be removed.
   */
@Test
public void allowStringSetNullRemovesAllTest() throws Fault {
    Set<String> methods = new TreeSet<String>();
    methods.add(Request.OPTIONS.name());
    methods.add(Request.TRACE.name());
    ResponseBuilder rb = RuntimeDelegate.getInstance().createResponseBuilder();
    Response response = rb.allow(methods).allow((Set<String>) null).build();
    Set<String> set = response.getAllowedMethods();
    assertEqualsInt(0, set.size(), "No one allow method should be present");
    logMsg("Allowed methods has been removed by null value as expected");
}
Also used : Response(jakarta.ws.rs.core.Response) TreeSet(java.util.TreeSet) Set(java.util.Set) TreeSet(java.util.TreeSet) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 59 with ResponseBuilder

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

the class Resource method getHeaders.

@POST
@Path("getheaders")
public Response getHeaders(String header) {
    ResponseBuilder builder = createResponseWithHeader();
    for (int i = 0; i != 5; i++) builder = builder.header(header + i, header);
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) POST(jakarta.ws.rs.POST)

Example 60 with ResponseBuilder

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

the class Resource method getHeaderStringByOperation.

@GET
@Path("getheaderstringoperation")
public Response getHeaderStringByOperation() {
    ResponseBuilder builder = createResponseWithHeader();
    Response response = builder.build();
    return response;
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Path(jakarta.ws.rs.Path) GET(jakarta.ws.rs.GET)

Aggregations

ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)80 Response (jakarta.ws.rs.core.Response)69 Path (jakarta.ws.rs.Path)41 Test (org.junit.jupiter.api.Test)34 POST (jakarta.ws.rs.POST)27 GET (jakarta.ws.rs.GET)14 Date (java.util.Date)6 ByteArrayInputStream (java.io.ByteArrayInputStream)4 Annotation (java.lang.annotation.Annotation)4 VerificationResult (ee.jakarta.tck.ws.rs.api.rs.core.responseclient.VerificationResult)3 StringBean (ee.jakarta.tck.ws.rs.common.provider.StringBean)3 NewCookie (jakarta.ws.rs.core.NewCookie)3 RuntimeDelegate (jakarta.ws.rs.ext.RuntimeDelegate)3 IOException (java.io.IOException)3 StringBeanWithAnnotation (ee.jakarta.tck.ws.rs.common.provider.StringBeanWithAnnotation)2 Produces (jakarta.ws.rs.Produces)2 WebApplicationException (jakarta.ws.rs.WebApplicationException)2 EntityTag (jakarta.ws.rs.core.EntityTag)2 Link (jakarta.ws.rs.core.Link)2 InputStreamReader (java.io.InputStreamReader)2