Search in sources :

Example 1 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest2.

@Test
public void convertFunctionTest2() throws InterruptedException {
    log.info("convert function test 2");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'string') as valueS1, convert(typeS,'float') as valueF1, convert(typeS," + "'double') as valueD1, convert(typeS,'int') as valueI1 , convert(typeS,'long') as valueL1 , convert" + "(typeS,'bool') as valueB1, " + "        convert(typeF,'string') as valueS2, convert(typeF,'float') as valueF2, convert(typeF," + "'double') as valueD2, convert(typeF,'int') as valueI2 , convert(typeF,'long') as valueL2 , convert" + "(typeF,'bool') as valueB2, " + "        convert(typeD,'string') as valueS3, convert(typeD,'float') as valueF3, convert(typeD," + "'double') as valueD3, convert(typeD,'int') as valueI3 , convert(typeD,'long') as valueL3 , convert" + "(typeD,'bool') as valueB3, " + "        convert(typeI,'string') as valueS4, convert(typeI,'float') as valueF4, convert(typeI," + "'double') as valueD4, convert(typeI,'int') as valueI4 , convert(typeI,'long') as valueL4 , convert" + "(typeI,'bool') as valueB4, " + "        convert(typeL,'string') as valueS5, convert(typeL,'float') as valueF5, convert(typeL," + "'double') as valueD5, convert(typeL,'int') as valueI5 , convert(typeL,'long') as valueL5 , convert" + "(typeL,'bool') as valueB5, " + "        convert(typeB,'string') as valueS6, convert(typeB,'float') as valueF6, convert(typeB," + "'double') as valueD6, convert(typeB,'int') as valueI6 , convert(typeB,'long') as valueL6 , convert" + "(typeB,'bool') as valueB6  " + "insert into outputStream ;";
    SiddhiAppRuntime siddhiAppRuntime = siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
    siddhiAppRuntime.addCallback("query1", new QueryCallback() {

        @Override
        public void receive(long timestamp, Event[] inEvents, Event[] removeEvents) {
            EventPrinter.print(timestamp, inEvents, removeEvents);
            count++;
            AssertJUnit.assertTrue(inEvents[0].getData(0) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(1) == null);
            AssertJUnit.assertTrue(inEvents[0].getData(2) == null);
            AssertJUnit.assertTrue(inEvents[0].getData(3) == null);
            AssertJUnit.assertTrue(inEvents[0].getData(4) == null);
            AssertJUnit.assertTrue(inEvents[0].getData(5) instanceof Boolean && !((Boolean) inEvents[0].getData(5)));
            AssertJUnit.assertTrue(inEvents[0].getData(6) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(7) instanceof Float);
            AssertJUnit.assertTrue(inEvents[0].getData(8) instanceof Double);
            AssertJUnit.assertTrue(inEvents[0].getData(9) instanceof Integer);
            AssertJUnit.assertTrue(inEvents[0].getData(10) instanceof Long);
            AssertJUnit.assertTrue(inEvents[0].getData(11) instanceof Boolean && !((Boolean) inEvents[0].getData(11)));
            AssertJUnit.assertTrue(inEvents[0].getData(12) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(13) instanceof Float);
            AssertJUnit.assertTrue(inEvents[0].getData(14) instanceof Double);
            AssertJUnit.assertTrue(inEvents[0].getData(15) instanceof Integer);
            AssertJUnit.assertTrue(inEvents[0].getData(16) instanceof Long);
            AssertJUnit.assertTrue(inEvents[0].getData(17) instanceof Boolean && !((Boolean) inEvents[0].getData(17)));
            AssertJUnit.assertTrue(inEvents[0].getData(18) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(19) instanceof Float);
            AssertJUnit.assertTrue(inEvents[0].getData(20) instanceof Double);
            AssertJUnit.assertTrue(inEvents[0].getData(21) instanceof Integer);
            AssertJUnit.assertTrue(inEvents[0].getData(22) instanceof Long);
            AssertJUnit.assertTrue(inEvents[0].getData(23) instanceof Boolean && !((Boolean) inEvents[0].getData(23)));
            AssertJUnit.assertTrue(inEvents[0].getData(24) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(25) instanceof Float);
            AssertJUnit.assertTrue(inEvents[0].getData(26) instanceof Double);
            AssertJUnit.assertTrue(inEvents[0].getData(27) instanceof Integer);
            AssertJUnit.assertTrue(inEvents[0].getData(28) instanceof Long);
            AssertJUnit.assertTrue(inEvents[0].getData(29) instanceof Boolean && !((Boolean) inEvents[0].getData(29)));
            AssertJUnit.assertTrue(inEvents[0].getData(30) instanceof String);
            AssertJUnit.assertTrue(inEvents[0].getData(31) instanceof Float);
            AssertJUnit.assertTrue(inEvents[0].getData(32) instanceof Double);
            AssertJUnit.assertTrue(inEvents[0].getData(33) instanceof Integer);
            AssertJUnit.assertTrue(inEvents[0].getData(34) instanceof Long);
            AssertJUnit.assertTrue(inEvents[0].getData(35) instanceof Boolean && ((Boolean) inEvents[0].getData(35)));
        }
    });
    InputHandler inputHandler = siddhiAppRuntime.getInputHandler("typeStream");
    siddhiAppRuntime.start();
    inputHandler.send(new Object[] { "WSO2", 2f, 3d, 4, 5L, true });
    Thread.sleep(100);
    AssertJUnit.assertEquals(1, count);
    siddhiAppRuntime.shutdown();
}
Also used : InputHandler(org.wso2.siddhi.core.stream.input.InputHandler) QueryCallback(org.wso2.siddhi.core.query.output.callback.QueryCallback) SiddhiAppRuntime(org.wso2.siddhi.core.SiddhiAppRuntime) Event(org.wso2.siddhi.core.event.Event) SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 2 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionExceptionTest7.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest7() throws InterruptedException {
    log.info("convert function test 7");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL " + "long, typeB bool, typeN double) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'234') as valueS, convert(typeF,'float') as valueF, convert(typeD," + "'double') as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , " + "convert(typeB,'bool') as valueB, convert(typeN,'string') as valueN " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 3 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionExceptionTest8.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest8() throws InterruptedException {
    log.info("convert function test 8");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL " + "long, typeB bool, typeN double) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,123) as valueS, convert(typeF,'float') as valueF, convert(typeD," + "'double') as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , " + "convert(typeB,'bool') as valueB, convert(typeN,'string') as valueN " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 4 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionTest5.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionTest5() throws InterruptedException {
    log.info("convert function test 5");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "" + "" + "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL long, typeB " + "bool) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'string','int') as valueB1 " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Example 5 with Types

use of org.wso2.ballerinalang.compiler.semantics.analyzer.Types in project siddhi by wso2.

the class ConvertFunctionTestCase method convertFunctionExceptionTest10.

@Test(expectedExceptions = SiddhiAppCreationException.class)
public void convertFunctionExceptionTest10() throws InterruptedException {
    log.info("convert function test 10");
    SiddhiManager siddhiManager = new SiddhiManager();
    String cseEventStream = "define stream typeStream (typeS string, typeF float, typeD double, typeI int, typeL " + "long, typeB bool, typeN double) ;";
    String query = "" + "@info(name = 'query1') " + "from typeStream " + "select convert(typeS,'invalidType') as valueS, convert(typeF,'float') as valueF, convert" + "(typeD," + "'double') as valueD , convert(typeI,'int') as valueI , convert(typeL,'long') as valueL , " + "convert(typeB,'bool') as valueB, convert(typeN,'string') as valueN " + "insert into outputStream ;";
    siddhiManager.createSiddhiAppRuntime(cseEventStream + query);
}
Also used : SiddhiManager(org.wso2.siddhi.core.SiddhiManager) Test(org.testng.annotations.Test)

Aggregations

ArrayList (java.util.ArrayList)20 Test (org.testng.annotations.Test)15 BType (org.wso2.ballerinalang.compiler.semantics.model.types.BType)13 SiddhiManager (org.wso2.siddhi.core.SiddhiManager)12 HashMap (java.util.HashMap)11 Map (java.util.Map)11 APIManagementException (org.wso2.carbon.apimgt.api.APIManagementException)10 List (java.util.List)8 JsonObject (com.google.gson.JsonObject)5 Test (org.junit.Test)5 SiddhiAppRuntime (org.wso2.siddhi.core.SiddhiAppRuntime)5 Arrays (java.util.Arrays)4 Collectors (java.util.stream.Collectors)4 JSONObject (org.json.simple.JSONObject)4 BSymbol (org.wso2.ballerinalang.compiler.semantics.model.symbols.BSymbol)4 BLangPackage (org.wso2.ballerinalang.compiler.tree.BLangPackage)4 JsonElement (com.google.gson.JsonElement)3 Paths (java.nio.file.Paths)3 TokenStream (org.antlr.v4.runtime.TokenStream)3 StringUtils (org.apache.commons.lang3.StringUtils)3