Search in sources :

Example 76 with Function

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);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 77 with Function

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);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 78 with Function

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);
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 79 with Function

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));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BString(org.ballerinalang.model.values.BString) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Example 80 with Function

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));
}
Also used : BStruct(org.ballerinalang.model.values.BStruct) Http2PushPromise(org.wso2.transport.http.netty.message.Http2PushPromise) BValue(org.ballerinalang.model.values.BValue) BString(org.ballerinalang.model.values.BString) Test(org.testng.annotations.Test)

Aggregations

Test (org.testng.annotations.Test)94 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)49 HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)44 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)39 ArrayList (java.util.ArrayList)37 BLangFunction (org.wso2.ballerinalang.compiler.tree.BLangFunction)35 BString (org.ballerinalang.model.values.BString)30 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)29 BLangEndpoint (org.wso2.ballerinalang.compiler.tree.BLangEndpoint)26 BLangVariable (org.wso2.ballerinalang.compiler.tree.BLangVariable)25 BInvokableSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BInvokableSymbol)20 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)20 BJSON (org.ballerinalang.model.values.BJSON)19 BLangExpression (org.wso2.ballerinalang.compiler.tree.expressions.BLangExpression)19 List (java.util.List)18 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)18 BLangStruct (org.wso2.ballerinalang.compiler.tree.BLangStruct)16 BStructSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BStructSymbol)15 BPackageSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BPackageSymbol)14 BLangSimpleVarRef (org.wso2.ballerinalang.compiler.tree.expressions.BLangSimpleVarRef)14