Search in sources :

Example 6 with CacheControl

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

the class JAXRSClientIT method cacheControlTest.

/*
   * @testName: cacheControlTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:139; JAXRS:JAVADOC:141; JAXRS:JAVADOC:142;
   * JAXRS:JAVADOC:123; JAXRS:JAVADOC:124; JAXRS:JAVADOC:125;
   * 
   * @test_Strategy: Create an instance of Response using
   * Response.ResponseBuilder.cacheControl(String).build() verify that correct
   * status code is returned
   */
@Test
public void cacheControlTest() throws Fault {
    VerificationResult result;
    int status = 200;
    boolean nostore = true;
    CacheControl ccl4 = new CacheControl();
    ccl4.setNoStore(nostore);
    List<String> ccl = Arrays.asList("no-store", "no-transform");
    Response resp = Response.status(status).cacheControl(ccl4).build();
    result = verifyStatus(resp, status);
    result.append(verifyCacheControl(resp, ccl));
    logMsg(result);
    assertResultTrue(result);
}
Also used : Response(jakarta.ws.rs.core.Response) CacheControl(jakarta.ws.rs.core.CacheControl) Test(org.junit.jupiter.api.Test)

Example 7 with CacheControl

use of jakarta.ws.rs.core.CacheControl 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 8 with CacheControl

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

the class JAXRSClientIT method getHeadersTest.

/*
   * @testName: getHeadersTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:848;
   * 
   * @test_Strategy: Get view of the response headers and their object values.
   */
@Test
public void getHeadersTest() throws Fault {
    CacheControl ccl = new CacheControl();
    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()));
    MultivaluedMap<String, Object> headers = response.getHeaders();
    String header = null;
    header = headers.getFirst(HttpHeaders.CACHE_CONTROL).toString();
    assertContainsIgnoreCase(header, "no-transform", "Cache-Control:no-transform has not been found");
    header = headers.getFirst(HttpHeaders.SET_COOKIE).toString();
    assertContainsIgnoreCase(header, "cookie=eikooc", "Set-Cookie:cookie=eikooc has not been found");
    header = headers.getFirst(HttpHeaders.CONTENT_ENCODING).toString();
    assertContainsIgnoreCase(header, "gzip", "Content-Encoding:gzip has not been found");
    header = headers.getFirst(HttpHeaders.EXPIRES).toString();
    assertNotNull(header, "Expires has not been found");
    header = headers.getFirst(HttpHeaders.CONTENT_LANGUAGE).toString();
    assertContainsIgnoreCase(langToString(header), langToString(Locale.CANADA_FRENCH), "Content-Language:", langToString(Locale.CANADA_FRENCH), "has not been found");
    Object noHeader = headers.getFirst("unknown");
    assertNull(noHeader, "Unknown header has been found", header);
}
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 9 with CacheControl

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

the class JAXRSClientIT method checkCreatedHeaderDelegateCacheControlTest.

/*
   * @testName: checkCreatedHeaderDelegateCacheControlTest
   * 
   * @assertion_ids: JAXRS:JAVADOC:287; JAXRS:JAVADOC:294; JAXRS:JAVADOC:296;
   * 
   * @test_Strategy: Check that
   * RuntimeDelegate.createHeaderDelegate<CacheControl> makes no exception and
   * is not null
   * 
   */
@Test
public void checkCreatedHeaderDelegateCacheControlTest() throws Fault {
    HeaderDelegate<CacheControl> hdcc = delegate.createHeaderDelegate(CacheControl.class);
    assertTrue(hdcc != null, "HeaderDelegate<CacheControl> has not been created");
    CacheControl control = new CacheControl();
    control.setMaxAge(1000);
    control.setSMaxAge(500);
    control.setNoTransform(false);
    control.setPrivate(true);
    String toString = hdcc.toString(control);
    CacheControl serialized = hdcc.fromString(toString);
    assertTrue(serialized.getMaxAge() == 1000 && serialized.getSMaxAge() == 500 && !serialized.isNoTransform() && serialized.isPrivate(), "HeaderDelegate<CacheControl> fromString(),toString() failed");
}
Also used : CacheControl(jakarta.ws.rs.core.CacheControl) Test(org.junit.jupiter.api.Test)

Example 10 with CacheControl

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

the class JAXRSClientIT method valueOfTest.

/*
     * @testName: valueOfTest
     * 
     * @assertion_ids: JAXRS:JAVADOC:47;
     * 
     * @test_Strategy: Client instantiate one CacheControl instance using
     * Constructor CacheControl.valueOf(String). verify valueOf method work
     * correctly.
     */
@Test
public void valueOfTest() throws Fault {
    boolean pass = true;
    StringBuffer sb = new StringBuffer();
    String value_to_parse = "private, no-cache, no-store, no-transform, proxy-revalidate, max-age=200";
    CacheControl ccl8 = CacheControl.valueOf(value_to_parse);
    String value = ccl8.toString().toLowerCase();
    sb.append(value + newline);
    if (!value.contains("private")) {
        pass = false;
        sb.append("ToString test failed in Private" + newline);
    }
    if (!value.contains("no-cache")) {
        pass = false;
        sb.append("ToString test failed in no-cache" + newline);
    }
    if (!value.contains("no-store")) {
        pass = false;
        sb.append("ToString test failed in no-store" + newline);
    }
    if (!value.contains("no-transform")) {
        pass = false;
        sb.append("ToString test failed in no-transform" + newline);
    }
    if (!value.contains("proxy-revalidate")) {
        pass = false;
        sb.append("ToString test failed in proxy-revalidate" + newline);
    }
    if (!value.contains("max-age=200")) {
        pass = false;
        sb.append("ToString test failed in max-age=200" + newline);
    }
    if (value.contains("s-maxage")) {
        pass = false;
        sb.append("ToString test failed in s-maxage" + newline);
    }
    if (value.contains("must-revalidate")) {
        pass = false;
        sb.append("ToString test failed in must-revalidate" + newline);
    }
    assertTrue(pass, "At least one assertion failed: " + sb);
    TestUtil.logTrace("Test passed. " + sb.toString());
}
Also used : CacheControl(jakarta.ws.rs.core.CacheControl) Test(org.junit.jupiter.api.Test)

Aggregations

CacheControl (jakarta.ws.rs.core.CacheControl)19 Test (org.junit.jupiter.api.Test)18 NewCookie (jakarta.ws.rs.core.NewCookie)3 Response (jakarta.ws.rs.core.Response)3 Date (java.util.Date)3 POST (jakarta.ws.rs.POST)1 Path (jakarta.ws.rs.Path)1 Invocation (jakarta.ws.rs.client.Invocation)1 ResponseBuilder (jakarta.ws.rs.core.Response.ResponseBuilder)1 HashMap (java.util.HashMap)1