ScriptParser { public OALScripts parse() throws IOException { OALScripts scripts = new OALScripts(); CommonTokenStream tokens = new CommonTokenStream(lexer); OALParser parser = new OALParser(tokens); ParseTree tree = parser.root(); ParseTreeWalker walker = new ParseTreeWalker(); walker.walk(new OALListener(scripts, sourcePackage), tree); return scripts; } private  ScriptParser(); static ScriptParser createFromFile(Reader scriptReader, String sourcePackage); static ScriptParser createFromScriptText(String script, String sourcePackage); OALScripts parse(); void close();  }
@Test public void testParse() throws IOException { ScriptParser parser = ScriptParser.createFromScriptText( "Endpoint_avg = from(Endpoint.latency).longAvg(); TEST_SOURCE_PACKAGE ); List<AnalysisResult> results = parser.parse().getMetricsStmts(); Assert.assertEquals(2, results.size()); AnalysisResult endpointAvg = results.get(0); Assert.assertEquals("EndpointAvg", endpointAvg.getMetricsName()); Assert.assertEquals("Endpoint", endpointAvg.getSourceName()); Assert.assertEquals("latency", endpointAvg.getSourceAttribute()); Assert.assertEquals("longAvg", endpointAvg.getAggregationFunctionName()); AnalysisResult serviceAvg = results.get(1); Assert.assertEquals("ServiceAvg", serviceAvg.getMetricsName()); Assert.assertEquals("Service", serviceAvg.getSourceName()); Assert.assertEquals("latency", serviceAvg.getSourceAttribute()); Assert.assertEquals("longAvg", serviceAvg.getAggregationFunctionName()); }