CommandsExecutor { AbstractCommandExecution findExecutor( AbstractCommandInstruction instr ) { AbstractCommandExecution result = null; if( RenameCommandInstruction.class.equals( instr.getClass())) result = new RenameCommandExecution((RenameCommandInstruction) instr); else if( ReplicateCommandInstruction.class.equals( instr.getClass())) result = new ReplicateCommandExecution((ReplicateCommandInstruction) instr, this.manager ); else if( AssociateTargetCommandInstruction.class.equals( instr.getClass())) result = new AssociateTargetCommandExecution((AssociateTargetCommandInstruction) instr, this.manager ); else if( BulkCommandInstructions.class.equals( instr.getClass())) result = new BulkCommandExecution((BulkCommandInstructions) instr, this.manager ); else if( ChangeStateCommandInstruction.class.equals( instr.getClass())) result = new ChangeStateCommandExecution((ChangeStateCommandInstruction) instr, this.manager ); else if( CreateInstanceCommandInstruction.class.equals( instr.getClass())) result = new CreateInstanceCommandExecution((CreateInstanceCommandInstruction) instr, this.manager ); else if( EmailCommandInstruction.class.equals( instr.getClass())) result = new EmailCommandExecution((EmailCommandInstruction) instr, this.manager ); else if( WriteCommandInstruction.class.equals( instr.getClass())) result = new WriteCommandExecution((WriteCommandInstruction) instr); else if( AppendCommandInstruction.class.equals( instr.getClass())) result = new AppendCommandExecution((AppendCommandInstruction) instr); else if( ExecuteCommandInstruction.class.equals( instr.getClass())) result = new ExecuteCommandExecution((ExecuteCommandInstruction) instr, this.manager ); return result; } CommandsExecutor( Manager manager, Application app, File commandsFile );  CommandsExecutor(
			Manager manager,
			Application app,
			File commandsFile,
			CommandExecutionContext executionContext ); void execute(); boolean wereInstructionSkipped();  }
@Test public void testFindExecutor_bulkCommand() { CommandsParser parser = new CommandsParser( this.app, "deploy and start all /tomcat-vm" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( BulkCommandInstructions.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( BulkCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_changeStateCommand() { CommandsParser parser = new CommandsParser( this.app, "change status of /tomcat-vm to DEPLOYED and STARTED" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( ChangeStateCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( ChangeStateCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_defineCommand() { CommandsParser parser = new CommandsParser( this.app, "define key = value" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( DefineVariableCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertNull( executor.findExecutor( instr )); }
@Test public void testFindExecutor_emailCommand() { CommandsParser parser = new CommandsParser( this.app, "email toto with this message" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( EmailCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( EmailCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_writeCommand() { CommandsParser parser = new CommandsParser( this.app, "write this into that" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( WriteCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( WriteCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_appendCommand() { CommandsParser parser = new CommandsParser( this.app, "append this into that" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( AppendCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( AppendCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_executeCommand() { CommandsParser parser = new CommandsParser( this.app, "execute this" ); Assert.assertEquals( 1, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( ExecuteCommandInstruction.class, instr.getClass()); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( ExecuteCommandExecution.class, executor.findExecutor( instr ).getClass()); }
@Test public void testFindExecutor_executeCommand_disabled() { CommandsParser parser = new CommandsParser( this.app, "append this into /that" ); Assert.assertEquals( 0, parser.getParsingErrors().size()); Assert.assertEquals( 1, parser.getInstructions().size()); AbstractCommandInstruction instr = parser.getInstructions().get( 0 ); Assert.assertEquals( AppendCommandInstruction.class, instr.getClass()); Assert.assertFalse( instr.isDisabled()); instr.setDisabled( true ); CommandsExecutor executor = new CommandsExecutor( this.manager, null, new File( "whatever" )); Assert.assertEquals( AppendCommandExecution.class, executor.findExecutor( instr ).getClass()); }