use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class ResponseNativeFunctionNegativeTest method testRemoveHeaderNegative.
@Test
@SuppressWarnings("unchecked")
public void testRemoveHeaderNegative() {
BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inRespStruct);
BStruct entity = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageMime, entityStruct);
String range = "Range";
HttpHeaders httpHeaders = new DefaultHttpHeaders();
httpHeaders.add("Expect", "100-continue");
entity.addNativeData(ENTITY_HEADERS, httpHeaders);
outResponse.addNativeData(MESSAGE_ENTITY, entity);
BString key = new BString(range);
BValue[] inputArg = { outResponse, key };
BValue[] returnVals = BRunUtil.invoke(result, "testRemoveHeader", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
Assert.assertNull(returnHeaders.get("range"));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class ResponseNativeFunctionNegativeTest method testRemoveAllHeadersNegative.
@Test
@SuppressWarnings("unchecked")
public void testRemoveAllHeadersNegative() {
BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inRespStruct);
BValue[] inputArg = { outResponse };
BValue[] returnVals = BRunUtil.invoke(result, "testRemoveAllHeaders", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
Assert.assertNull(returnHeaders.get("Expect"));
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testSetHeader.
@Test
@SuppressWarnings("unchecked")
public void testSetHeader() {
String range = "Range";
String rangeValue = "bytes=500-999; a=4";
BString key = new BString(range);
BString value = new BString(rangeValue);
BValue[] inputArg = { key, value };
BValue[] returnVals = BRunUtil.invoke(result, "testSetHeader", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
Assert.assertEquals(returnHeaders.get(range), rangeValue);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class ResponseNativeFunctionSuccessTest method testAddHeader.
@Test
@SuppressWarnings("unchecked")
public void testAddHeader() {
BStruct outResponse = BCompileUtil.createAndGetStruct(result.getProgFile(), protocolPackageHttp, inResStruct);
String headerName = "header1";
String headerValue = "abc, xyz";
BString key = new BString(headerName);
BString value = new BString(headerValue);
BValue[] inputArg = { outResponse, key, value };
BValue[] returnVals = BRunUtil.invoke(result, "testAddHeader", inputArg);
Assert.assertFalse(returnVals == null || returnVals.length == 0 || returnVals[0] == null, "Invalid Return Values.");
Assert.assertTrue(returnVals[0] instanceof BStruct);
BStruct entityStruct = (BStruct) ((BStruct) returnVals[0]).getNativeData(MESSAGE_ENTITY);
HttpHeaders returnHeaders = (HttpHeaders) entityStruct.getNativeData(ENTITY_HEADERS);
Assert.assertEquals(returnHeaders.get(headerName), headerValue);
}
use of org.apache.flink.shaded.netty4.io.netty.handler.codec.http.HttpHeaders in project ballerina by ballerina-lang.
the class MessageUtils method generateHTTPMessage.
public static HTTPTestRequest generateHTTPMessage(String path, String method, List<Header> headers, String payload) {
HTTPTestRequest carbonMessage = getHttpTestRequest(path, method);
HttpHeaders httpHeaders = carbonMessage.getHeaders();
if (headers != null) {
for (Header header : headers) {
httpHeaders.set(header.getName(), header.getValue());
}
}
if (payload != null) {
carbonMessage.addHttpContent(new DefaultLastHttpContent(Unpooled.wrappedBuffer(payload.getBytes())));
} else {
carbonMessage.addHttpContent(new DefaultLastHttpContent());
}
return carbonMessage;
}
Aggregations