Java Code Examples for io.siddhi.query.compiler.SiddhiCompiler#parseStreamDefinition()

The following examples show how to use io.siddhi.query.compiler.SiddhiCompiler#parseStreamDefinition() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultilevelNestedAnnotations1() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition(
            "@sink(url='http://foo.com/test/{{data}}', " +
                    "   @map(type='xml', " +
                    "@payload('<test><time>{{time}}</time></test>')" +
                    "   )" +
                    ") " +
                    "define stream fooStream (id int, name string);"
    );

    AssertJUnit.assertEquals(
            StreamDefinition
                    .id("fooStream")
                    .attribute("id", Attribute.Type.INT)
                    .attribute("name", Attribute.Type.STRING)
                    .annotation(Annotation.annotation("sink")
                            .element("url", "http://foo.com/test/{{data}}")
                            .annotation(Annotation.annotation("map")
                                    .element("type", "xml")
                                    .annotation(Annotation.annotation("payload")
                                            .element("<test><time>{{time}}</time></test>")))),
            streamDefinition);
}
 
Example 2
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 6 votes vote down vote up
@Test
public void testMultilevelNestedAnnotations3() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition(
            "@sink(url='http://foo.com/test/{{data}}', " +
                    "   @map(type=\"\"\"xml\"\"\", " +
                    "@payload(\"\"\"{ \"time\":{{time}}}\"\"\") " +
                    "   )" +
                    ") " +
                    "define stream fooStream (id int, name string);"
    );

    AssertJUnit.assertEquals(
            StreamDefinition
                    .id("fooStream")
                    .attribute("id", Attribute.Type.INT)
                    .attribute("name", Attribute.Type.STRING)
                    .annotation(Annotation.annotation("sink")
                            .element("url", "http://foo.com/test/{{data}}")
                            .annotation(Annotation.annotation("map")
                                    .element("type", "xml")
                                    .annotation(Annotation.annotation("payload")
                                            .element("{ \"time\":{{time}}}")))),
            streamDefinition);
}
 
Example 3
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test1() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream cseStream ( symbol " +
            "string, price int, volume float )");
    AssertJUnit.assertEquals(StreamDefinition.
                    id("cseStream").
                    attribute("symbol", Attribute.Type.STRING).
                    attribute("price", Attribute.Type.INT).
                    attribute("volume", Attribute.Type.FLOAT).toString(),
            streamDefinition.toString());
}
 
Example 4
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void test2() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream `define` ( `string` " +
            "string, price int, volume float );");
    AssertJUnit.assertEquals(StreamDefinition.
                    id("define").
                    attribute("string", Attribute.Type.STRING).
                    attribute("price", Attribute.Type.INT).
                    attribute("volume", Attribute.Type.FLOAT).toString(),
            streamDefinition.toString());
}
 
Example 5
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatingStreamDefinition() {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " +
            "string, price int, volume float );");
    StreamDefinition api = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING)
            .attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.FLOAT);
    AssertJUnit.assertEquals(api, streamDefinition);
}
 
Example 6
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test(expectedExceptions = SiddhiParserException.class)
    public void testCreatingStreamWithDuplicateAttribute() {
        StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " +
                "string, symbol int, volume float );");
//        StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING).attribute("symbol", Attribute
// .Type.INT).attribute("volume", Attribute.Type.FLOAT);
    }
 
Example 7
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testCreatingStreamDefinition2() {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("define stream StockStream ( symbol " +
            "string, price int, volume double, data Object );");
    StreamDefinition api = StreamDefinition.id("StockStream").attribute("symbol", Attribute.Type.STRING)
            .attribute("price", Attribute.Type.INT).attribute("volume", Attribute.Type.DOUBLE).attribute("data",
                    Attribute.Type.OBJECT);
    AssertJUnit.assertEquals(api, streamDefinition);
}
 
Example 8
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testEqualObjects() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("@Foo(name='bar','Custom')define " +
            "stream cseStream ( symbol string, price int, volume float )");
    AssertJUnit.assertEquals(StreamDefinition.
                    id("cseStream").
                    attribute("symbol", Attribute.Type.STRING).
                    attribute("price", Attribute.Type.INT).
                    attribute("volume", Attribute.Type.FLOAT).annotation(Annotation.annotation("Foo").element
                    ("name", "bar").element("Custom")),
            streamDefinition);
}
 
Example 9
Source File: DefineStreamTestCase.java    From siddhi with Apache License 2.0 5 votes vote down vote up
@Test
public void testMultilevelNestedAnnotations2() throws SiddhiParserException {
    StreamDefinition streamDefinition = SiddhiCompiler.parseStreamDefinition("" +
            "@source(" +
            "   type='http', " +
            "   context='/test', " +
            "   transport='http,https', " +
            "   @map(" +
            "       type='xml', " +
            "       namespace = \"h=uri, a=uri\", " +
            "       @attributes(" +
            "           '//h:time', " +
            "           '//h:data'" +
            "       )" +
            "   )" +
            ") " +
            "define stream fooStream (id int, name string);");

    AssertJUnit.assertEquals(
            StreamDefinition
                    .id("fooStream")
                    .attribute("id", Attribute.Type.INT)
                    .attribute("name", Attribute.Type.STRING)
                    .annotation(Annotation.annotation("source")
                            .element("type", "http")
                            .element("context", "/test")
                            .element("transport", "http,https")
                            .annotation(Annotation.annotation("map")
                                    .element("type", "xml")
                                    .element("namespace", "h=uri, a=uri")
                                    .annotation(Annotation.annotation("attributes")
                                            .element("//h:time")
                                            .element("//h:data")
                                    )
                            )
                    ),
            streamDefinition);
}