@Test public void testExecute_success_noDefaultTarget() throws Exception { String instancePath = InstanceHelpers.computeInstancePath( this.app.getTomcatVm()); String line = "replicate /" + this.app.getTomcatVm().getName() + " as toto"; ReplicateCommandExecution executor = buildExecutor( line ); Mockito.verifyZeroInteractions( this.instancesMngr ); Mockito.verifyZeroInteractions( this.targetsMngr ); executor.execute(); Mockito.verify( this.instancesMngr, Mockito.times( 1 )).addInstance( this.ma, null, new Instance( "toto" )); Mockito.verify( this.targetsMngr, Mockito.times( 1 )).findTargetId( this.app, instancePath, true ); Mockito.verify( this.targetsMngr, Mockito.times( 0 )).findTargetId( this.app, null ); Mockito.verify( this.targetsMngr, Mockito.times( 0 )).associateTargetWith( Mockito.anyString(), Mockito.any( Application.class ), Mockito.anyString()); }
@Override public void execute() throws CommandException { Instance rootInstance = resolveInstance( this.instr, this.instr.getReplicatedInstancePath(), true ); ManagedApplication ma = resolveManagedApplication( this.manager, this.instr ); CreateInstanceCommandExecution.verify( this.executionContext, rootInstance.getComponent()); try { Instance copy = InstanceHelpers.replicateInstance( rootInstance ); copy.setName( this.instr.getNewInstanceName()); this.manager.instancesMngr().addInstance( ma, null, copy ); String targetId = this.manager.targetsMngr().findTargetId( ma.getApplication(), "/" + rootInstance.getName(), true ); if( targetId != null ) this.manager.targetsMngr().associateTargetWith( targetId, ma.getApplication(), "/" + copy.getName()); CreateInstanceCommandExecution.update( this.executionContext, copy ); } catch( Exception e ) { throw new CommandException( e ); } }
ReplicateCommandExecution extends AbstractCommandExecution { @Override public void execute() throws CommandException { Instance rootInstance = resolveInstance( this.instr, this.instr.getReplicatedInstancePath(), true ); ManagedApplication ma = resolveManagedApplication( this.manager, this.instr ); CreateInstanceCommandExecution.verify( this.executionContext, rootInstance.getComponent()); try { Instance copy = InstanceHelpers.replicateInstance( rootInstance ); copy.setName( this.instr.getNewInstanceName()); this.manager.instancesMngr().addInstance( ma, null, copy ); String targetId = this.manager.targetsMngr().findTargetId( ma.getApplication(), "/" + rootInstance.getName(), true ); if( targetId != null ) this.manager.targetsMngr().associateTargetWith( targetId, ma.getApplication(), "/" + copy.getName()); CreateInstanceCommandExecution.update( this.executionContext, copy ); } catch( Exception e ) { throw new CommandException( e ); } } }
ReplicateCommandExecution extends AbstractCommandExecution { @Override public void execute() throws CommandException { Instance rootInstance = resolveInstance( this.instr, this.instr.getReplicatedInstancePath(), true ); ManagedApplication ma = resolveManagedApplication( this.manager, this.instr ); CreateInstanceCommandExecution.verify( this.executionContext, rootInstance.getComponent()); try { Instance copy = InstanceHelpers.replicateInstance( rootInstance ); copy.setName( this.instr.getNewInstanceName()); this.manager.instancesMngr().addInstance( ma, null, copy ); String targetId = this.manager.targetsMngr().findTargetId( ma.getApplication(), "/" + rootInstance.getName(), true ); if( targetId != null ) this.manager.targetsMngr().associateTargetWith( targetId, ma.getApplication(), "/" + copy.getName()); CreateInstanceCommandExecution.update( this.executionContext, copy ); } catch( Exception e ) { throw new CommandException( e ); } } ReplicateCommandExecution( ReplicateCommandInstruction instr, Manager manager ); }
ReplicateCommandExecution extends AbstractCommandExecution { @Override public void execute() throws CommandException { Instance rootInstance = resolveInstance( this.instr, this.instr.getReplicatedInstancePath(), true ); ManagedApplication ma = resolveManagedApplication( this.manager, this.instr ); CreateInstanceCommandExecution.verify( this.executionContext, rootInstance.getComponent()); try { Instance copy = InstanceHelpers.replicateInstance( rootInstance ); copy.setName( this.instr.getNewInstanceName()); this.manager.instancesMngr().addInstance( ma, null, copy ); String targetId = this.manager.targetsMngr().findTargetId( ma.getApplication(), "/" + rootInstance.getName(), true ); if( targetId != null ) this.manager.targetsMngr().associateTargetWith( targetId, ma.getApplication(), "/" + copy.getName()); CreateInstanceCommandExecution.update( this.executionContext, copy ); } catch( Exception e ) { throw new CommandException( e ); } } ReplicateCommandExecution( ReplicateCommandInstruction instr, Manager manager ); @Override void execute(); }
ReplicateCommandExecution extends AbstractCommandExecution { @Override public void execute() throws CommandException { Instance rootInstance = resolveInstance( this.instr, this.instr.getReplicatedInstancePath(), true ); ManagedApplication ma = resolveManagedApplication( this.manager, this.instr ); CreateInstanceCommandExecution.verify( this.executionContext, rootInstance.getComponent()); try { Instance copy = InstanceHelpers.replicateInstance( rootInstance ); copy.setName( this.instr.getNewInstanceName()); this.manager.instancesMngr().addInstance( ma, null, copy ); String targetId = this.manager.targetsMngr().findTargetId( ma.getApplication(), "/" + rootInstance.getName(), true ); if( targetId != null ) this.manager.targetsMngr().associateTargetWith( targetId, ma.getApplication(), "/" + copy.getName()); CreateInstanceCommandExecution.update( this.executionContext, copy ); } catch( Exception e ) { throw new CommandException( e ); } } ReplicateCommandExecution( ReplicateCommandInstruction instr, Manager manager ); @Override void execute();  }