TargetsMngrImpl implements ITargetsMngr { @Override public void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ) throws IOException, UnauthorizedActionException { if( instancePathOrComponentName != null && ! instancePathOrComponentName.startsWith( "@" )) { Instance instance = InstanceHelpers.findInstanceByPath( app, instancePathOrComponentName ); if( instance != null ) { if( instance.getStatus() != InstanceStatus.NOT_DEPLOYED ) throw new UnauthorizedActionException( "Operation not allowed: " + app + " :: " + instancePathOrComponentName + " should be not deployed." ); if( ! InstanceHelpers.isTarget( instance )) throw new IllegalArgumentException( "Only scoped instances can be associated with targets. Path in error: " + instancePathOrComponentName ); } } saveAssociation( app, null, instancePathOrComponentName, false ); } TargetsMngrImpl( IConfigurationMngr configurationMngr ); @Override String createTarget( String targetContent ); @Override String createTarget( File targetPropertiesFile, ApplicationTemplate creator ); @Override void updateTarget( String targetId, String newTargetContent ); @Override void deleteTarget( String targetId ); @Override void associateTargetWith( String targetId, AbstractApplication app, String instancePathOrComponentName ); @Override void dissociateTargetFrom( AbstractApplication app, String instancePathOrComponentName ); @Override void copyOriginalMapping( Application app ); @Override void applicationWasDeleted( AbstractApplication app ); @Override TargetProperties findTargetProperties( AbstractApplication app, String instancePath ); @Override TargetProperties findTargetProperties( String targetId ); @Override String findTargetId( AbstractApplication app, String instancePath, boolean strict ); @Override String findTargetId( AbstractApplication app, String instancePath ); @Override Map<String,byte[]> findScriptResourcesForAgent( String targetId ); @Override Map<String,byte[]> findScriptResourcesForAgent( AbstractApplication app, Instance scopedInstance ); @Override File findScriptForDm( AbstractApplication app, Instance scopedInstance ); @Override List<TargetWrapperDescriptor> listAllTargets(); @Override TargetWrapperDescriptor findTargetById( String targetId ); @Override List<TargetWrapperDescriptor> listPossibleTargets( AbstractApplication app ); @Override void addHint( String targetId, AbstractApplication app ); @Override void removeHint( String targetId, AbstractApplication app ); @Override TargetProperties lockAndGetTarget( Application app, Instance scopedInstance ); @Override void unlockTarget( Application app, Instance scopedInstance ); @Override List<TargetUsageItem> findUsageStatistics( String targetId );  }
@Test( expected = IllegalArgumentException.class ) public void testDissociateTargetFrom_nonScopedInstance() throws Exception { TestApplication app = new TestApplication(); String mySqlPath = InstanceHelpers.computeInstancePath( app.getMySql()); this.mngr.dissociateTargetFrom( app, mySqlPath ); }
@Test public void testDisssociationWithInvalidTargetId() throws Exception { TestApplication app = new TestApplication(); String mySqlPath = InstanceHelpers.computeInstancePath( app.getMySqlVm()); this.mngr.dissociateTargetFrom( app, mySqlPath ); }
@Test public void testDisssociationWithInvalidInstancePath() throws Exception { TestApplication app = new TestApplication(); this.mngr.dissociateTargetFrom( app, "/vm/invalid" ); }
@Test( expected = UnauthorizedActionException.class ) public void testDisssociations_onADeployedInstance() throws Exception { TestApplication app = new TestApplication(); String instancePath = InstanceHelpers.computeInstancePath( app.getMySqlVm()); app.getMySqlVm().setStatus( InstanceStatus.DEPLOYED_STARTED ); this.mngr.dissociateTargetFrom( app, instancePath ); }