@Test public void testExtractRuleSections_invalidRule() throws Exception { String fileContent = MonitoringRunnable.RULE_BEGINNING + " file event id with spaces]"; MonitoringRunnable task = new MonitoringRunnable( this.agentInterface, HANDLERS ); this.agentInterface.setScopedInstance( new Instance( "root" )); List<MonitoringHandlerRun> handlers = task.extractRuleSections( new File( "test" ), fileContent, null ); Assert.assertEquals( 0, handlers.size()); }
List<MonitoringHandlerRun> extractRuleSections( File file, String fileContent, Properties params ) { StringBuilder sb = new StringBuilder(); List<String> sections = new ArrayList<String>(); for( String s : Arrays.asList( fileContent.trim().split( "\n" ))) { s = s.trim(); if( s.length() == 0 || s.startsWith( COMMENT_DELIMITER )) continue; if( s.toLowerCase().startsWith( RULE_BEGINNING )) { addSectionIfNotEmpty(sections, sb.toString()); sb.setLength( 0 ); } sb.append( Utils.expandTemplate(s, params) + "\n" ); } addSectionIfNotEmpty(sections, sb.toString()); List<MonitoringHandlerRun> result = new ArrayList<MonitoringHandlerRun> (); for( String s : sections ) { Matcher m = this.eventPattern.matcher( s ); if( ! m.find()) continue; s = s.substring( m.end()).trim(); MonitoringHandlerRun bean = new MonitoringHandlerRun(); bean.handlerName = m.group( 1 ); bean.eventId = m.group( 2 ); bean.rawRulesText = s; result.add( bean ); } return result; }
MonitoringRunnable implements Runnable { List<MonitoringHandlerRun> extractRuleSections( File file, String fileContent, Properties params ) { StringBuilder sb = new StringBuilder(); List<String> sections = new ArrayList<String>(); for( String s : Arrays.asList( fileContent.trim().split( "\n" ))) { s = s.trim(); if( s.length() == 0 || s.startsWith( COMMENT_DELIMITER )) continue; if( s.toLowerCase().startsWith( RULE_BEGINNING )) { addSectionIfNotEmpty(sections, sb.toString()); sb.setLength( 0 ); } sb.append( Utils.expandTemplate(s, params) + "\n" ); } addSectionIfNotEmpty(sections, sb.toString()); List<MonitoringHandlerRun> result = new ArrayList<MonitoringHandlerRun> (); for( String s : sections ) { Matcher m = this.eventPattern.matcher( s ); if( ! m.find()) continue; s = s.substring( m.end()).trim(); MonitoringHandlerRun bean = new MonitoringHandlerRun(); bean.handlerName = m.group( 1 ); bean.eventId = m.group( 2 ); bean.rawRulesText = s; result.add( bean ); } return result; } }
MonitoringRunnable implements Runnable { List<MonitoringHandlerRun> extractRuleSections( File file, String fileContent, Properties params ) { StringBuilder sb = new StringBuilder(); List<String> sections = new ArrayList<String>(); for( String s : Arrays.asList( fileContent.trim().split( "\n" ))) { s = s.trim(); if( s.length() == 0 || s.startsWith( COMMENT_DELIMITER )) continue; if( s.toLowerCase().startsWith( RULE_BEGINNING )) { addSectionIfNotEmpty(sections, sb.toString()); sb.setLength( 0 ); } sb.append( Utils.expandTemplate(s, params) + "\n" ); } addSectionIfNotEmpty(sections, sb.toString()); List<MonitoringHandlerRun> result = new ArrayList<MonitoringHandlerRun> (); for( String s : sections ) { Matcher m = this.eventPattern.matcher( s ); if( ! m.find()) continue; s = s.substring( m.end()).trim(); MonitoringHandlerRun bean = new MonitoringHandlerRun(); bean.handlerName = m.group( 1 ); bean.eventId = m.group( 2 ); bean.rawRulesText = s; result.add( bean ); } return result; } MonitoringRunnable( AgentMessagingInterface agentInterface, List<IMonitoringHandler> handlers ); }
MonitoringRunnable implements Runnable { List<MonitoringHandlerRun> extractRuleSections( File file, String fileContent, Properties params ) { StringBuilder sb = new StringBuilder(); List<String> sections = new ArrayList<String>(); for( String s : Arrays.asList( fileContent.trim().split( "\n" ))) { s = s.trim(); if( s.length() == 0 || s.startsWith( COMMENT_DELIMITER )) continue; if( s.toLowerCase().startsWith( RULE_BEGINNING )) { addSectionIfNotEmpty(sections, sb.toString()); sb.setLength( 0 ); } sb.append( Utils.expandTemplate(s, params) + "\n" ); } addSectionIfNotEmpty(sections, sb.toString()); List<MonitoringHandlerRun> result = new ArrayList<MonitoringHandlerRun> (); for( String s : sections ) { Matcher m = this.eventPattern.matcher( s ); if( ! m.find()) continue; s = s.substring( m.end()).trim(); MonitoringHandlerRun bean = new MonitoringHandlerRun(); bean.handlerName = m.group( 1 ); bean.eventId = m.group( 2 ); bean.rawRulesText = s; result.add( bean ); } return result; } MonitoringRunnable( AgentMessagingInterface agentInterface, List<IMonitoringHandler> handlers ); @Override void run(); }
MonitoringRunnable implements Runnable { List<MonitoringHandlerRun> extractRuleSections( File file, String fileContent, Properties params ) { StringBuilder sb = new StringBuilder(); List<String> sections = new ArrayList<String>(); for( String s : Arrays.asList( fileContent.trim().split( "\n" ))) { s = s.trim(); if( s.length() == 0 || s.startsWith( COMMENT_DELIMITER )) continue; if( s.toLowerCase().startsWith( RULE_BEGINNING )) { addSectionIfNotEmpty(sections, sb.toString()); sb.setLength( 0 ); } sb.append( Utils.expandTemplate(s, params) + "\n" ); } addSectionIfNotEmpty(sections, sb.toString()); List<MonitoringHandlerRun> result = new ArrayList<MonitoringHandlerRun> (); for( String s : sections ) { Matcher m = this.eventPattern.matcher( s ); if( ! m.find()) continue; s = s.substring( m.end()).trim(); MonitoringHandlerRun bean = new MonitoringHandlerRun(); bean.handlerName = m.group( 1 ); bean.eventId = m.group( 2 ); bean.rawRulesText = s; result.add( bean ); } return result; } MonitoringRunnable( AgentMessagingInterface agentInterface, List<IMonitoringHandler> handlers ); @Override void run();  }