Search in sources :

Example 6 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingChangedGlobalVarInAnotherResourceInAnotherService.

@Test(description = "Test accessing changed global var in another resource in different service", enabled = false)
public void testAccessingChangedGlobalVarInAnotherResourceInAnotherService() {
    HTTPTestRequest cMsgChange = MessageUtils.generateHTTPMessage("/globalvar/change-resource-level", "GET");
    Services.invokeNew(result, cMsgChange);
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar-second/get-changed-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");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 7 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testDefiningGlobalVarInService.

@Test(description = "Test defining global variables in services", enabled = false)
public void testDefiningGlobalVarInService() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/defined", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"glbVarInt":800, "glbVarString":"value", "glbVarFloat":99.34323}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("glbVarInt").asText(), "800");
    Assert.assertEquals(bJson.value().get("glbVarString").asText(), "value");
    Assert.assertEquals(bJson.value().get("glbVarFloat").asText(), "99.34323");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 8 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class GlobalVarServiceTest method testAccessingGlobalVarInServiceLevel.

@Test(description = "Test accessing global variables in service level", enabled = false)
public void testAccessingGlobalVarInServiceLevel() {
    HTTPTestRequest cMsg = MessageUtils.generateHTTPMessage("/globalvar/access-service-level", "GET");
    HTTPCarbonMessage response = Services.invokeNew(result, cMsg);
    Assert.assertNotNull(response);
    // Expected Json message : {"serviceVarFloat":99.34323}
    BJSON bJson = new BJSON(new HttpMessageDataStreamer(response).getInputStream());
    Assert.assertEquals(bJson.value().get("serviceVarFloat").asText(), "99.34323");
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) BJSON(org.ballerinalang.model.values.BJSON) Test(org.testng.annotations.Test)

Example 9 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class LocksInServicesTest method testServiceLvlVarLockComplex.

@Test(description = "Test locking service level variable complex", enabled = false)
public void testServiceLvlVarLockComplex() {
    Semaphore semaphore = new Semaphore(-11);
    ExecutorService executor = TestThreadPool.getInstance().getExecutor();
    for (int i = 0; i < 4; i++) {
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo1"));
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample1/echo2"));
    }
    try {
        if (!semaphore.tryAcquire(10, TimeUnit.MINUTES)) {
            Assert.fail("request execution not finished within 2s");
        }
        String path = "/sample1/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);
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ExecutorService(java.util.concurrent.ExecutorService) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Example 10 with HTTPTestRequest

use of org.ballerinalang.test.services.testutils.HTTPTestRequest in project ballerina by ballerina-lang.

the class LocksInServicesTest method testServiceLvlVarLockBasic.

@Test(description = "Test locking service level variable basic", enabled = false)
public void testServiceLvlVarLockBasic() {
    Semaphore semaphore = new Semaphore(-9999);
    ExecutorService executor = TestThreadPool.getInstance().getExecutor();
    for (int i = 0; i < 10000; i++) {
        executor.submit(new TestRequestSender(compileResult, semaphore, "/sample/echo"));
    }
    try {
        if (!semaphore.tryAcquire(20, TimeUnit.MINUTES)) {
            Assert.fail("request execution not finished within 2s");
        }
        String path = "/sample/getCount";
        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, "count - 10000", "incorrect request count");
    } catch (InterruptedException e) {
        Assert.fail("thread interrupted before request execution finished - " + e.getMessage(), e);
    }
}
Also used : HTTPCarbonMessage(org.wso2.transport.http.netty.message.HTTPCarbonMessage) HttpMessageDataStreamer(org.wso2.transport.http.netty.message.HttpMessageDataStreamer) ExecutorService(java.util.concurrent.ExecutorService) HTTPTestRequest(org.ballerinalang.test.services.testutils.HTTPTestRequest) Semaphore(java.util.concurrent.Semaphore) Test(org.testng.annotations.Test)

Aggregations

HTTPTestRequest (org.ballerinalang.test.services.testutils.HTTPTestRequest)243 Test (org.testng.annotations.Test)241 HTTPCarbonMessage (org.wso2.transport.http.netty.message.HTTPCarbonMessage)233 HttpMessageDataStreamer (org.wso2.transport.http.netty.message.HttpMessageDataStreamer)172 BJSON (org.ballerinalang.model.values.BJSON)108 BString (org.ballerinalang.model.values.BString)32 ArrayList (java.util.ArrayList)26 BStruct (org.ballerinalang.model.values.BStruct)16 Header (org.wso2.carbon.messaging.Header)15 InputStream (java.io.InputStream)4 ExecutorService (java.util.concurrent.ExecutorService)4 Semaphore (java.util.concurrent.Semaphore)4 DefaultLastHttpContent (io.netty.handler.codec.http.DefaultLastHttpContent)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 IOException (java.io.IOException)2 MimeTypeParseException (javax.activation.MimeTypeParseException)2 BValue (org.ballerinalang.model.values.BValue)2 BXMLItem (org.ballerinalang.model.values.BXMLItem)2 RequestCacheControlStruct (org.ballerinalang.net.http.caching.RequestCacheControlStruct)2 StringDataSource (org.ballerinalang.runtime.message.StringDataSource)2