use of loghub.RouteParser 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);
}
use of loghub.RouteParser in project LogHub by fbacchella.
the class TestParser method test2.
@Test
public void test2() throws IOException, InterruptedException {
CharStream cs = CharStreams.fromStream(getClass().getClassLoader().getResourceAsStream("test.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());
for (String s : new String[] { "oneref", "main", "groovy" }) {
Assert.assertTrue("pipeline " + s + " not found", conf.pipelines.containsKey(s));
}
Assert.assertEquals("too much pipelines", 6, conf.pipelines.size());
Assert.assertEquals("too much inputs", 1, conf.inputs.size());
Assert.assertEquals("too much outputs", 1, conf.outputs.size());
for (String s : new String[] { "logfile", "plugins" }) {
Assert.assertTrue("property " + s + " not found", conf.properties.containsKey(s));
}
}
use of loghub.RouteParser in project LogHub by fbacchella.
the class Configuration method getTree.
private RouteParser.ConfigurationContext getTree(CharStream cs, ConfigListener conflistener) throws ConfigException {
// Passing the input to the lexer to create tokens
RouteLexer lexer = new RouteLexer(cs);
CommonTokenStream tokens = new CommonTokenStream(lexer);
// Passing the tokens to the parser to create the parse tree.
RouteParser parser = new RouteParser(tokens);
conflistener.parser = parser;
conflistener.stream = cs;
parser.removeErrorListeners();
ConfigErrorListener errListener = new ConfigErrorListener();
parser.addErrorListener(errListener);
RouteParser.ConfigurationContext tree = parser.configuration();
return tree;
}
Aggregations