@Test public void testEvalCondition() throws Exception { RestHandler handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag = 0" ); Map<String,String> map = new HashMap<String,String> (); Assert.assertFalse( handler.evalCondition( map )); map.put( "undefined", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); map.put( "lag", "0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag >= 0" ); map.put( "lag", "1.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag == 0" ); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "yes" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag > 0" ); map.put( "lag", "1.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag <= 0" ); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag < 0" ); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertTrue( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "yes" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag == yes" ); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "yes" ); Assert.assertTrue( handler.evalCondition( map )); handler = new RestHandler(); handler.setAgentId( APP_NAME, SCOPED_INSTANCE_PATH ); handler.reset( null, EVENT_NAME, "check url that lag = yes" ); map.put( "lag", "1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "-1.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "0.0" ); Assert.assertFalse( handler.evalCondition( map )); map.clear(); map.put( "lag", "yes" ); Assert.assertTrue( handler.evalCondition( map )); }
boolean evalCondition( Map<String,String> map ) { boolean result = false; String value = map.get( this.conditionParameter ); if( value != null ) { try { Double doubleValue = Double.parseDouble( value ); Double thresholdValue = Double.parseDouble( this.conditionThreshold ); int comparison = doubleValue.compareTo( thresholdValue ); if( ">".equals( this.conditionOperator )) result = comparison > 0; else if( ">=".equals( this.conditionOperator )) result = comparison >= 0; else if( "<".equals( this.conditionOperator )) result = comparison < 0; else if( "<=".equals( this.conditionOperator )) result = comparison <= 0; else result = comparison == 0; } catch( NumberFormatException e ) { if( "==".equals( this.conditionOperator ) || "=".equals( this.conditionOperator )) result = Objects.equals( value, this.conditionThreshold ); else this.logger.fine( "Invalid double. " + e.getMessage()); } } return result; }
RestHandler implements IMonitoringHandler { boolean evalCondition( Map<String,String> map ) { boolean result = false; String value = map.get( this.conditionParameter ); if( value != null ) { try { Double doubleValue = Double.parseDouble( value ); Double thresholdValue = Double.parseDouble( this.conditionThreshold ); int comparison = doubleValue.compareTo( thresholdValue ); if( ">".equals( this.conditionOperator )) result = comparison > 0; else if( ">=".equals( this.conditionOperator )) result = comparison >= 0; else if( "<".equals( this.conditionOperator )) result = comparison < 0; else if( "<=".equals( this.conditionOperator )) result = comparison <= 0; else result = comparison == 0; } catch( NumberFormatException e ) { if( "==".equals( this.conditionOperator ) || "=".equals( this.conditionOperator )) result = Objects.equals( value, this.conditionThreshold ); else this.logger.fine( "Invalid double. " + e.getMessage()); } } return result; } }
RestHandler implements IMonitoringHandler { boolean evalCondition( Map<String,String> map ) { boolean result = false; String value = map.get( this.conditionParameter ); if( value != null ) { try { Double doubleValue = Double.parseDouble( value ); Double thresholdValue = Double.parseDouble( this.conditionThreshold ); int comparison = doubleValue.compareTo( thresholdValue ); if( ">".equals( this.conditionOperator )) result = comparison > 0; else if( ">=".equals( this.conditionOperator )) result = comparison >= 0; else if( "<".equals( this.conditionOperator )) result = comparison < 0; else if( "<=".equals( this.conditionOperator )) result = comparison <= 0; else result = comparison == 0; } catch( NumberFormatException e ) { if( "==".equals( this.conditionOperator ) || "=".equals( this.conditionOperator )) result = Objects.equals( value, this.conditionThreshold ); else this.logger.fine( "Invalid double. " + e.getMessage()); } } return result; }  }
RestHandler implements IMonitoringHandler { boolean evalCondition( Map<String,String> map ) { boolean result = false; String value = map.get( this.conditionParameter ); if( value != null ) { try { Double doubleValue = Double.parseDouble( value ); Double thresholdValue = Double.parseDouble( this.conditionThreshold ); int comparison = doubleValue.compareTo( thresholdValue ); if( ">".equals( this.conditionOperator )) result = comparison > 0; else if( ">=".equals( this.conditionOperator )) result = comparison >= 0; else if( "<".equals( this.conditionOperator )) result = comparison < 0; else if( "<=".equals( this.conditionOperator )) result = comparison <= 0; else result = comparison == 0; } catch( NumberFormatException e ) { if( "==".equals( this.conditionOperator ) || "=".equals( this.conditionOperator )) result = Objects.equals( value, this.conditionThreshold ); else this.logger.fine( "Invalid double. " + e.getMessage()); } } return result; }  @Override String getName(); @Override void setAgentId( String applicationName, String scopedInstancePath ); @Override void reset( Instance associatedInstance, String eventId, String rawRulesText ); @Override MsgNotifAutonomic process(); }
RestHandler implements IMonitoringHandler { boolean evalCondition( Map<String,String> map ) { boolean result = false; String value = map.get( this.conditionParameter ); if( value != null ) { try { Double doubleValue = Double.parseDouble( value ); Double thresholdValue = Double.parseDouble( this.conditionThreshold ); int comparison = doubleValue.compareTo( thresholdValue ); if( ">".equals( this.conditionOperator )) result = comparison > 0; else if( ">=".equals( this.conditionOperator )) result = comparison >= 0; else if( "<".equals( this.conditionOperator )) result = comparison < 0; else if( "<=".equals( this.conditionOperator )) result = comparison <= 0; else result = comparison == 0; } catch( NumberFormatException e ) { if( "==".equals( this.conditionOperator ) || "=".equals( this.conditionOperator )) result = Objects.equals( value, this.conditionThreshold ); else this.logger.fine( "Invalid double. " + e.getMessage()); } } return result; }  @Override String getName(); @Override void setAgentId( String applicationName, String scopedInstancePath ); @Override void reset( Instance associatedInstance, String eventId, String rawRulesText ); @Override MsgNotifAutonomic process();  }