InstancesMngrImpl implements IInstancesMngr { @Override public void removeInstance( ManagedApplication ma, Instance instance ) throws UnauthorizedActionException, IOException { removeInstance( ma, instance, true ); } InstancesMngrImpl(
			IMessagingMngr messagingMngr,
			INotificationMngr notificationMngr,
			ITargetsMngr targetsMngr,
			IRandomMngr randomMngr,
			ITargetConfigurator targetConfigurator ); void setTargetHandlerResolver( ITargetHandlerResolver targetHandlerResolver ); void setRuleBasedHandler( IAutonomicMngr autonomicMngr ); void setDmDomain( String dmDomain ); @Override void addInstance( ManagedApplication ma, Instance parentInstance, Instance instance ); @Override void instanceWasUpdated( Instance instance, ManagedApplication ma ); @Override void removeInstance( ManagedApplication ma, Instance instance ); @Override void removeInstance( ManagedApplication ma, Instance instance, boolean immediate ); @Override void restoreInstanceStates( ManagedApplication ma, TargetHandler targetHandler ); @Override void resynchronizeAgents( ManagedApplication ma ); @Override void changeInstanceState( ManagedApplication ma, Instance instance, InstanceStatus newStatus ); @Override void deployAndStartAll( ManagedApplication ma, Instance instance ); @Override void stopAll( ManagedApplication ma, Instance instance ); @Override void undeployAll( ManagedApplication ma, Instance instance );  }
@Test( expected = UnauthorizedActionException.class ) public void testRemoveInstanceImmediately() throws Exception { INotificationMngr notificationMngr = Mockito.mock( INotificationMngr.class ); IRandomMngr randomMngr = Mockito.mock( IRandomMngr.class ); ITargetConfigurator targetConfigurator = Mockito.mock( ITargetConfigurator.class ); IMessagingMngr messagingMngr = Mockito.mock( IMessagingMngr.class ); ITargetsMngr targetsMngr = Mockito.mock( ITargetsMngr.class ); IConfigurationMngr configurationMngr = new ConfigurationMngrImpl(); configurationMngr.setWorkingDirectory( this.folder.newFolder()); IInstancesMngr mngr = new InstancesMngrImpl( messagingMngr, notificationMngr, targetsMngr, randomMngr, targetConfigurator ); TestApplication app = new TestApplication(); app.setDirectory( this.folder.newFolder()); ManagedApplication ma = new ManagedApplication( app ); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); mngr.removeInstance( ma, app.getMySqlVm(), true ); }
@Test public void testRemoveInstanceNotImmediately() throws Exception { INotificationMngr notificationMngr = Mockito.mock( INotificationMngr.class ); IRandomMngr randomMngr = Mockito.mock( IRandomMngr.class ); ITargetConfigurator targetConfigurator = Mockito.mock( ITargetConfigurator.class ); IMessagingMngr messagingMngr = Mockito.mock( IMessagingMngr.class ); ITargetsMngr targetsMngr = Mockito.mock( ITargetsMngr.class ); IConfigurationMngr configurationMngr = new ConfigurationMngrImpl(); configurationMngr.setWorkingDirectory( this.folder.newFolder()); IInstancesMngr mngr = new InstancesMngrImpl( messagingMngr, notificationMngr, targetsMngr, randomMngr, targetConfigurator ); TestApplication app = new TestApplication(); app.setDirectory( this.folder.newFolder()); ManagedApplication ma = new ManagedApplication( app ); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); mngr.removeInstance( ma, app.getMySqlVm(), false ); Assert.assertEquals( app.getMySqlVm(), InstanceHelpers.findInstanceByPath( app, "/" + app.getMySqlVm().getName())); Assert.assertEquals( "true", app.getMySqlVm().data.get( Instance.DELETE_WHEN_NOT_DEPLOYED )); }