use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testAddHeader.
@Test(description = "Test addHeader function of PushPromise")
public void testAddHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
String headerName = "header1";
String headerValue = "value1";
BString key = new BString(headerName);
BString value = new BString(headerValue);
BValue[] inputArg = { promise, key, value };
BValue[] returnVal = BRunUtil.invoke(result, "testAddHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise http2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertEquals(http2PushPromise.getHeader(headerName), headerValue);
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testGetHeaders.
@Test(description = "Test getHeaders function of PushPromise")
public void testGetHeaders() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header";
String headerValue1 = "value1";
String headerValue2 = "value2";
http2PushPromise.addHeader(headerName, headerValue1);
http2PushPromise.addHeader(headerName, headerValue2);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BString key = new BString(headerName);
BValue[] inputArg = { promise, key };
BValue[] returnVal = BRunUtil.invoke(result, "testGetHeaders", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertEquals(((BStringArray) returnVal[0]).get(0), headerValue1);
Assert.assertEquals(((BStringArray) returnVal[0]).get(1), headerValue2);
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testSetHeader.
@Test(description = "Test setHeader function of PushPromise")
public void testSetHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header1";
String headerValue = "value1";
http2PushPromise.addHeader(headerName, headerValue);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
String targetHeaderValue = "value2";
BString key = new BString(headerName);
BString value = new BString(targetHeaderValue);
BValue[] inputArg = { promise, key, value };
BValue[] returnVal = BRunUtil.invoke(result, "testSetHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertEquals(retrievedHttp2PushPromise.getHeader(headerName), targetHeaderValue);
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testRemoveHeader.
@Test(description = "Test removeHeader function of PushPromise")
public void testRemoveHeader() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String headerName = "header1";
String headerValue = "value1";
http2PushPromise.addHeader(headerName, headerValue);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BString key = new BString(headerName);
BValue[] inputArg = { promise, key };
BValue[] returnVal = BRunUtil.invoke(result, "testRemoveHeader", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertNull(retrievedHttp2PushPromise.getHeader(headerName));
}
use of org.wso2.carbon.apimgt.core.models.Function in project ballerina by ballerina-lang.
the class PushPromiseNativeFunctionTest method testRemoveAllHeaders.
@Test(description = "Test removeAllHeaders function of PushPromise")
public void testRemoveAllHeaders() {
BStruct promise = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, promiseStruct);
Http2PushPromise http2PushPromise = new Http2PushPromise(HttpConstants.HTTP_METHOD_GET, HttpConstants.DEFAULT_BASE_PATH);
String header1Name = "header1";
String header1Value = "value1";
http2PushPromise.addHeader(header1Name, header1Value);
String header2Name = "header2";
String header2Value = "value2";
http2PushPromise.addHeader(header2Name, header2Value);
HttpUtil.populatePushPromiseStruct(promise, http2PushPromise);
BValue[] inputArg = { promise };
BValue[] returnVal = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
Assert.assertFalse(returnVal == null || returnVal.length == 0 || returnVal[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVal[0] instanceof BStruct);
Http2PushPromise retrievedHttp2PushPromise = (Http2PushPromise) ((BStruct) returnVal[0]).getNativeData(HttpConstants.TRANSPORT_PUSH_PROMISE);
Assert.assertNull(retrievedHttp2PushPromise.getHeader(header1Name));
Assert.assertNull(retrievedHttp2PushPromise.getHeader(header2Name));
}
Aggregations