use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class GlobalVarServiceTest method testChangingGlobalVarInResourceLevel.
@Test(description = "Test changing global variables in resource level", enabled = false)
public void testChangingGlobalVarInResourceLevel() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
Assert.assertNotNull(response);
// Expected Json message : {"glbVarFloatChange":77.87}
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("glbVarFloatChange").asText(), "77.87");
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class LocksInServicesTest method testThrowErrorInsideLock.
@Test(description = "Test throwing error inside lock statement", enabled = false)
public void testThrowErrorInsideLock() {
Semaphore semaphore = new Semaphore(0);
ExecutorService executor = TestThreadPool.getInstance().getExecutor();
executor.submit(new TestRequestSender(compileResult, semaphore, "/sample3/echo"));
try {
if (!semaphore.tryAcquire(500, TimeUnit.MILLISECONDS)) {
Assert.fail("request execution not finished within 100ms");
}
String path = "/sample3/getMsg";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, cMsg);
Assert.assertNotNull(response, "Response message not found");
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(responseMsgPayload, "modified by second resource", "incorrect response msg");
} catch (InterruptedException e) {
Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
}
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class MultipartDecoderTest method testMultipartsWithEmptyBody.
@Test(description = "Test sending a multipart request without body parts")
public void testMultipartsWithEmptyBody() {
String path = "/test/emptyparts";
List<Header> headers = new ArrayList<>();
String multipartDataBoundary = MimeUtil.getNewMultipartDelimiter();
headers.add(new Header(HttpHeaderNames.CONTENT_TYPE.toString(), "multipart/mixed; boundary=" + multipartDataBoundary));
String multipartBody = "--" + multipartDataBoundary + "\r\n" + "--" + multipartDataBoundary + "--" + "\r\n";
HTTPTestRequest inRequestMsg = MessageUtils.generateHTTPMessage(path, HttpConstants.HTTP_METHOD_POST, headers, multipartBody);
InputStream inputStream = new HttpMessageDataStreamer(inRequestMsg).getInputStream();
String error = null;
try {
MultipartDecoder.decodeBodyParts("multipart/mixed; boundary=" + multipartDataBoundary, inputStream);
} catch (Exception e) {
error = e.getMessage();
}
Assert.assertNotNull(error);
Assert.assertTrue(error.contains("Reached EOF, but there is no closing MIME boundary"));
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class LocksInServicesTest method testServiceLvlPkgLvlVarLockComplex.
@Test(description = "Test locking service level and package level variable complex", enabled = false)
public void testServiceLvlPkgLvlVarLockComplex() {
Semaphore semaphore = new Semaphore(-11);
ExecutorService executor = TestThreadPool.getInstance().getExecutor();
for (int i = 0; i < 4; i++) {
executor.submit(new TestRequestSender(compileResult, semaphore, "/sample2/echo"));
executor.submit(new TestRequestSender(compileResult, semaphore, "/sample2/echo1"));
executor.submit(new TestRequestSender(compileResult, semaphore, "/sample2/echo2"));
}
try {
if (!semaphore.tryAcquire(10, TimeUnit.MINUTES)) {
Assert.fail("request execution not finished within 2s");
}
String path = "/sample2/getResult";
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage(path, "GET");
HTTPCarbonMessage response = Services.invokeNew(compileResult, cMsg);
Assert.assertNotNull(response, "Response message not found");
String responseMsgPayload = StringUtils.getStringFromInputStream(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(responseMsgPayload, "3333333333331224.01455555555555513.026.0777777777777", "incorrect request count");
} catch (InterruptedException e) {
Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
}
}
use of org.wso2.transport.http.netty.message.HttpMessageDataStreamer in project ballerina by ballerina-lang.
the class IdentifierLiteralServiceTest method testUsingIdentifierLiteralsInServiceAndResourceNames.
@Test(description = "Test using identifier literals in service and resource names", enabled = false)
public void testUsingIdentifierLiteralsInServiceAndResourceNames() {
HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/identifierLiteral/resource", "GET");
HTTPCarbonMessage response = Services.invokeNew(application, cMsg);
Assert.assertNotNull(response);
BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
Assert.assertEquals(bJson.value().get("key").asText(), "keyVal");
Assert.assertEquals(bJson.value().get("value").asText(), "valueOfTheString");
}
Aggregations