Search in sources :

Example 1 with ObjectWrapped

use of loghub.configuration.ConfigListener.ObjectWrapped in project LogHub by fbacchella.

the class TestParser method testType.

@Test
public void testType() throws IOException {
    CharStream cs = CharStreams.fromStream(getClass().getClassLoader().getResourceAsStream("types.conf"), CharsetUtil.UTF_8);
    RouteLexer lexer = new RouteLexer(cs);
    CommonTokenStream tokens = new CommonTokenStream(lexer);
    RouteParser parser = new RouteParser(tokens);
    parser.removeErrorListeners();
    ConfigErrorListener errListener = new ConfigErrorListener();
    parser.addErrorListener(errListener);
    // begin parsing at init rule
    loghub.RouteParser.ConfigurationContext tree = parser.configuration();
    ConfigListener conf = new ConfigListener();
    ParseTreeWalker walker = new ParseTreeWalker();
    walker.walk(conf, tree);
    Assert.assertEquals("stack not empty :" + conf.stack, 0, conf.stack.size());
    ConfigListener.PipenodesList main = conf.pipelines.get("main");
    ObjectDescription p = (ObjectDescription) main.processors.get(0);
    Assert.assertTrue(((ObjectWrapped) p.beans.get("string")).wrapped instanceof String);
    Assert.assertTrue(((ObjectWrapped) p.beans.get("boolean")).wrapped instanceof Boolean);
    Assert.assertTrue(((ObjectWrapped) p.beans.get("int")).wrapped instanceof Integer);
    Assert.assertTrue(((ObjectWrapped) p.beans.get("double")).wrapped instanceof Double);
    Assert.assertArrayEquals(new Object[] { "0", 1, 1.0, true }, (Object[]) ((ObjectWrapped) p.beans.get("array")).wrapped);
}
Also used : CommonTokenStream(org.antlr.v4.runtime.CommonTokenStream) RouteLexer(loghub.RouteLexer) RouteParser(loghub.RouteParser) ObjectWrapped(loghub.configuration.ConfigListener.ObjectWrapped) CharStream(org.antlr.v4.runtime.CharStream) ObjectDescription(loghub.configuration.ConfigListener.ObjectDescription) ParseTreeWalker(org.antlr.v4.runtime.tree.ParseTreeWalker) Test(org.junit.Test)

Aggregations

RouteLexer (loghub.RouteLexer)1 RouteParser (loghub.RouteParser)1 ObjectDescription (loghub.configuration.ConfigListener.ObjectDescription)1 ObjectWrapped (loghub.configuration.ConfigListener.ObjectWrapped)1 CharStream (org.antlr.v4.runtime.CharStream)1 CommonTokenStream (org.antlr.v4.runtime.CommonTokenStream)1 ParseTreeWalker (org.antlr.v4.runtime.tree.ParseTreeWalker)1 Test (org.junit.Test)1