PluginFile implements PluginInterface { SortedSet<Action> findActions( String actionName, Properties properties ) { Pattern pattern = Pattern.compile( actionName + "\\.(\\d)+\\.(.*)", Pattern.CASE_INSENSITIVE ); SortedSet<Action> result = new TreeSet<Action>( new ActionComparator()); for( Map.Entry<Object,Object> entry : properties.entrySet()) { String key = String.valueOf( entry.getKey()).toLowerCase(); Matcher m = pattern.matcher( key ); if( ! m.matches()) continue; int position = Integer.parseInt( m.group( 1 )); ActionType actionType = ActionType.which( m.group( 2 )); String parameter = String.valueOf( entry.getValue()); result.add( new Action( position, actionType, parameter )); } return result; }  @Override String getPluginName(); @Override void setNames( String applicationName, String rootInstanceName ); @Override void initialize( Instance instance ); @Override void deploy( Instance instance ); @Override void start( Instance instance ); @Override void update( Instance instance, Import importChanged, InstanceStatus statusChanged ); @Override void stop( Instance instance ); @Override void undeploy( Instance instance ); static final String PLUGIN_NAME; }
@Test public void testFindActions() { Properties properties = new Properties(); properties.setProperty( "deploy.1.download", "http: properties.setProperty( "deploy.0.ignore", "oops" ); properties.setProperty( "DeploY.2.copy", "/tmp/roboconf_tmp_file -> /home/toto/file.txt" ); properties.setProperty( "start.1.delete", "/tmp/roboconf_tmp_file" ); properties.setProperty( "deploy.-50.hop", "invalid" ); properties.setProperty( "deploy.to.server", "invalid" ); properties.setProperty( "", "" ); PluginFile plugin = new PluginFile(); Set<Action> actions = plugin.findActions( "deploy", properties ); Assert.assertEquals( 3, actions.size()); List<ActionType> orderedActions = new ArrayList<ActionType> (); Map<ActionType,Action> typeToAction = new HashMap<ActionType,Action> (); for( Action action : actions ) { orderedActions.add( action.actionType ); typeToAction.put( action.actionType, action ); } Assert.assertEquals( ActionType.NOTHING, orderedActions.get( 0 )); Assert.assertEquals( ActionType.DOWNLOAD, orderedActions.get( 1 )); Assert.assertEquals( ActionType.COPY, orderedActions.get( 2 )); Action action = typeToAction.get( ActionType.NOTHING ); Assert.assertEquals( "oops", action.parameter ); Assert.assertEquals( 0, action.position ); action = typeToAction.get( ActionType.DOWNLOAD ); Assert.assertEquals( "http: Assert.assertEquals( 1, action.position ); action = typeToAction.get( ActionType.COPY ); Assert.assertEquals( "/tmp/roboconf_tmp_file -> /home/toto/file.txt", action.parameter ); Assert.assertEquals( 2, action.position ); actions = plugin.findActions( "STARt", properties ); Assert.assertEquals( 1, actions.size()); action = actions.iterator().next(); Assert.assertEquals( "/tmp/roboconf_tmp_file", action.parameter ); Assert.assertEquals( 1, action.position ); Assert.assertEquals( ActionType.DELETE, action.actionType ); }