Search in sources :

Example 6 with RequestCacheControlStruct

use of org.ballerinalang.net.http.caching.RequestCacheControlStruct in project ballerina by ballerina-lang.

the class HttpCachingClientTest method testIsServingStaleProhibited.

@Test(description = "Test for the isServingStaleProhibited() function which determines whether serving stale " + "responses is prohibited.", enabled = false)
public void testIsServingStaleProhibited() {
    RequestCacheControlStruct requestCacheControl = new RequestCacheControlStruct(compileResult.getProgFile().getPackageInfo(PROTOCOL_PACKAGE_HTTP).getStructInfo(REQUEST_CACHE_CONTROL));
    ResponseCacheControlStruct responseCacheControl = new ResponseCacheControlStruct(compileResult.getProgFile().getPackageInfo(PROTOCOL_PACKAGE_HTTP).getStructInfo(RESPONSE_CACHE_CONTROL));
    BValue[] inputArgs = { requestCacheControl.getStruct(), responseCacheControl.getStruct() };
    BValue[] returns;
    // No prohibitive directives set
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertFalse(((BBoolean) returns[0]).booleanValue());
    // Setting no-store in request
    requestCacheControl.setNoStore(true);
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertTrue(((BBoolean) returns[0]).booleanValue());
    // Setting no-cache in request
    requestCacheControl.setNoStore(false).setNoCache(true);
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertTrue(((BBoolean) returns[0]).booleanValue());
    // Setting must-revalidate in response
    requestCacheControl.setNoCache(false);
    responseCacheControl.setMustRevalidate(true);
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertTrue(((BBoolean) returns[0]).booleanValue());
    // Setting must-revalidate in response
    responseCacheControl.setMustRevalidate(false).setSMaxAge(10);
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertTrue(((BBoolean) returns[0]).booleanValue());
    // Setting must-revalidate in response
    responseCacheControl.setSMaxAge(-1).setProxyRevalidate(true);
    returns = BRunUtil.invoke(compileResult, "isServingStaleProhibited", inputArgs);
    Assert.assertTrue(((BBoolean) returns[0]).booleanValue());
}
Also used : BValue(org.ballerinalang.model.values.BValue) RequestCacheControlStruct(org.ballerinalang.net.http.caching.RequestCacheControlStruct) ResponseCacheControlStruct(org.ballerinalang.net.http.caching.ResponseCacheControlStruct) Test(org.testng.annotations.Test)

Aggregations

BValue (org.ballerinalang.model.values.BValue)6 RequestCacheControlStruct (org.ballerinalang.net.http.caching.RequestCacheControlStruct)6 BStruct (org.ballerinalang.model.values.BStruct)5 BString (org.ballerinalang.model.values.BString)4 Test (org.testng.annotations.Test)4 HashMap (java.util.HashMap)2 Map (java.util.Map)2 BallerinaConnectorException (org.ballerinalang.connector.api.BallerinaConnectorException)2 ResponseCacheControlStruct (org.ballerinalang.net.http.caching.ResponseCacheControlStruct)2 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)2 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)2 DefaultHttpHeaders (io.netty.handler.codec.http.DefaultHttpHeaders)1 HttpHeaders (io.netty.handler.codec.http.HttpHeaders)1 IOException (java.io.IOException)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 List (java.util.List)1 Semaphore (java.util.concurrent.Semaphore)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1 BLangVMErrors (org.ballerinalang.bre.bvm.BLangVMErrors)1 CallableUnitCallback (org.ballerinalang.bre.bvm.CallableUnitCallback)1