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());
}
Aggregations