Search in sources :

Example 36 with Response

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

the class JAXRSClientIT method languageTest.

/*
   * @testName: languageTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:149;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.ResponseBuilder.language(String).build() verify that correct
   * status code is returned
   */
@Test
public void languageTest() throws Fault {
    VerificationResult result = new VerificationResult();
    int status = 200;
    List<String> lang = getLangList();
    for (String language : lang) {
        Response resp = Response.status(status).language(language).build();
        result.append(verifyStatus(resp, status));
        result.append(verifyLanguage(resp, lang));
    }
    logMsg(result);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) Test(org.junit.jupiter.api.Test)

Example 37 with Response

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

the class JAXRSClientIT method getHeaderStringTest.

/*
   * @testName: getHeaderStringTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:849;
   * 
   * @test_Strategy: Get a message header as a single string value.
   */
@Test
public void getHeaderStringTest() throws Fault {
    CacheControl ccl = new CacheControl();
    ccl.setNoStore(true);
    NewCookie cookie = new NewCookie("cookie", "eikooc");
    String encoding = "gzip";
    Date date = Calendar.getInstance().getTime();
    Response response = Response.ok().cacheControl(ccl).cookie(cookie).encoding(encoding).expires(date).language(Locale.CANADA_FRENCH).build();
    logMsg("Found following objects:");
    logMsg((Object[]) JaxrsCommonClient.getMetadata(response.getHeaders()));
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CACHE_CONTROL), "no-store", "Cache-Control:no-store has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CACHE_CONTROL), "no-transform", "Cache-Control:no-transform has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.SET_COOKIE), "cookie=eikooc", "Set-Cookie:cookie=eikooc has not been found");
    assertContainsIgnoreCase(response.getHeaderString(HttpHeaders.CONTENT_ENCODING), "gzip", "Content-Encoding:gzip has not been found");
    assertNotNull(response.getHeaderString(HttpHeaders.EXPIRES), "Expires has not been found");
    assertContainsIgnoreCase(langToString(response.getHeaderString("Content-Language")), langToString(Locale.CANADA_FRENCH), "Content-Language:", langToString(Locale.CANADA_FRENCH), "has not been found");
    assertNull(response.getHeaderString("unknown"), "Unknown header has been found", response.getHeaderString("unknown"));
}
Also used : Response(jakarta.ws.rs.core.Response) CacheControl(jakarta.ws.rs.core.CacheControl) Date(java.util.Date) NewCookie(jakarta.ws.rs.core.NewCookie) Test(org.junit.jupiter.api.Test)

Example 38 with Response

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

the class JAXRSClientIT method getFamilyTest.

/* Run test */
/*
   * @testName: getFamilyTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:302;
   * 
   * @test_Strategy: Get the class of status code
   */
@Test
public void getFamilyTest() throws Fault {
    Response response;
    for (int i = 0; i != status_codes.length; i++) {
        response = Response.status(status_codes[i]).build();
        StatusType type = response.getStatusInfo();
        Family family = type.getFamily();
        assertTrue(family == status_family[i], "unexpected family " + family + " differs from " + status_family[i]);
        logMsg("Found expected family", family, "for status", status_codes[i]);
    }
}
Also used : Response(jakarta.ws.rs.core.Response) StatusType(jakarta.ws.rs.core.Response.StatusType) Family(jakarta.ws.rs.core.Response.Status.Family) Test(org.junit.jupiter.api.Test)

Example 39 with Response

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

the class BuilderClientIT method allowStringArrayTruncateDuplicatesTest.

/*
   * @testName: allowStringArrayTruncateDuplicatesTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:875;
   * 
   * @test_Strategy: Set the list of allowed methods for the resource.
   */
@Test
public void allowStringArrayTruncateDuplicatesTest() throws Fault {
    String[] methods = { Request.OPTIONS.name(), Request.OPTIONS.name() };
    ResponseBuilder rb = RuntimeDelegate.getInstance().createResponseBuilder();
    Response response = rb.allow(methods).build();
    Set<String> set = response.getAllowedMethods();
    assertEqualsInt(1, set.size(), "Only one allow method should be present");
    assertEquals(set.iterator().next(), Request.OPTIONS.name(), Request.OPTIONS.name(), "has not been found in allowed methods");
    logMsg(Request.OPTIONS.name(), "has been found in allowed methods");
}
Also used : Response(jakarta.ws.rs.core.Response) ResponseBuilder(jakarta.ws.rs.core.Response.ResponseBuilder) Test(org.junit.jupiter.api.Test)

Example 40 with Response

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

the class JAXRSClientIT method postTest.

// ------------------------------------------------------------------
// ---------------------------POST-----------------------------------
// ------------------------------------------------------------------
/*
   * @testName: postTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:397;
   * 
   * @test_Strategy: Invoke HTTP post method for the current request
   * asynchronously.
   */
@Test
public void postTest() throws Fault {
    AsyncInvoker async = startAsyncInvokerForMethod("post");
    Entity<String> entity = Entity.entity("post", MediaType.WILDCARD_TYPE);
    Future<Response> future = async.post(entity);
    checkFutureOkResponseNoTime(future);
// return future;
}
Also used : Response(jakarta.ws.rs.core.Response) AsyncInvoker(jakarta.ws.rs.client.AsyncInvoker) Test(org.junit.jupiter.api.Test)

Aggregations

Response (jakarta.ws.rs.core.Response)665 Test (org.junit.jupiter.api.Test)551 AsyncInvoker (jakarta.ws.rs.client.AsyncInvoker)78 ClientRequestContext (jakarta.ws.rs.client.ClientRequestContext)71 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)67 Invocation (jakarta.ws.rs.client.Invocation)65 CompletionStageRxInvoker (jakarta.ws.rs.client.CompletionStageRxInvoker)51 Path (jakarta.ws.rs.Path)44 IOException (java.io.IOException)43 SyncInvoker (jakarta.ws.rs.client.SyncInvoker)41 ClientResponseContext (jakarta.ws.rs.client.ClientResponseContext)33 POST (jakarta.ws.rs.POST)27 Client (jakarta.ws.rs.client.Client)25 WebTarget (jakarta.ws.rs.client.WebTarget)24 Link (jakarta.ws.rs.core.Link)23 Status (jakarta.ws.rs.core.Response.Status)23 MediaType (jakarta.ws.rs.core.MediaType)22 Annotation (java.lang.annotation.Annotation)22 Date (java.util.Date)21 GET (jakarta.ws.rs.GET)18