@Test( expected = UnauthorizedActionException.class ) public void testUpdateTarget_whenTargetDoesNotExist() throws Exception { this.mngr.updateTarget( "inexisting", "prop: ok\nhandler: h" ); }
@Override public void updateTarget( String targetId, String newTargetContent ) throws IOException, UnauthorizedActionException { TargetValidator tv = new TargetValidator( newTargetContent ); tv.validate(); RoboconfErrorHelpers.filterErrors( tv.getErrors(), ErrorCode.REC_TARGET_NO_ID, ErrorCode.REC_TARGET_CONFLICTING_ID ); if( RoboconfErrorHelpers.containsCriticalErrors( tv.getErrors())) throw new IOException( "There are errors in the target definition." ); File targetFile = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME ); if( targetFile == null ) throw new UnauthorizedActionException( "Target " + targetId + " does not exist." ); Utils.writeStringInto( newTargetContent, targetFile ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void updateTarget( String targetId, String newTargetContent ) throws IOException, UnauthorizedActionException { TargetValidator tv = new TargetValidator( newTargetContent ); tv.validate(); RoboconfErrorHelpers.filterErrors( tv.getErrors(), ErrorCode.REC_TARGET_NO_ID, ErrorCode.REC_TARGET_CONFLICTING_ID ); if( RoboconfErrorHelpers.containsCriticalErrors( tv.getErrors())) throw new IOException( "There are errors in the target definition." ); File targetFile = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME ); if( targetFile == null ) throw new UnauthorizedActionException( "Target " + targetId + " does not exist." ); Utils.writeStringInto( newTargetContent, targetFile ); } }
TargetsMngrImpl implements ITargetsMngr { @Override public void updateTarget( String targetId, String newTargetContent ) throws IOException, UnauthorizedActionException { TargetValidator tv = new TargetValidator( newTargetContent ); tv.validate(); RoboconfErrorHelpers.filterErrors( tv.getErrors(), ErrorCode.REC_TARGET_NO_ID, ErrorCode.REC_TARGET_CONFLICTING_ID ); if( RoboconfErrorHelpers.containsCriticalErrors( tv.getErrors())) throw new IOException( "There are errors in the target definition." ); File targetFile = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME ); if( targetFile == null ) throw new UnauthorizedActionException( "Target " + targetId + " does not exist." ); Utils.writeStringInto( newTargetContent, targetFile ); } TargetsMngrImpl( IConfigurationMngr configurationMngr ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void updateTarget( String targetId, String newTargetContent ) throws IOException, UnauthorizedActionException { TargetValidator tv = new TargetValidator( newTargetContent ); tv.validate(); RoboconfErrorHelpers.filterErrors( tv.getErrors(), ErrorCode.REC_TARGET_NO_ID, ErrorCode.REC_TARGET_CONFLICTING_ID ); if( RoboconfErrorHelpers.containsCriticalErrors( tv.getErrors())) throw new IOException( "There are errors in the target definition." ); File targetFile = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME ); if( targetFile == null ) throw new UnauthorizedActionException( "Target " + targetId + " does not exist." ); Utils.writeStringInto( newTargetContent, targetFile ); } 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 ); }
TargetsMngrImpl implements ITargetsMngr { @Override public void updateTarget( String targetId, String newTargetContent ) throws IOException, UnauthorizedActionException { TargetValidator tv = new TargetValidator( newTargetContent ); tv.validate(); RoboconfErrorHelpers.filterErrors( tv.getErrors(), ErrorCode.REC_TARGET_NO_ID, ErrorCode.REC_TARGET_CONFLICTING_ID ); if( RoboconfErrorHelpers.containsCriticalErrors( tv.getErrors())) throw new IOException( "There are errors in the target definition." ); File targetFile = findTargetFile( targetId, Constants.TARGET_PROPERTIES_FILE_NAME ); if( targetFile == null ) throw new UnauthorizedActionException( "Target " + targetId + " does not exist." ); Utils.writeStringInto( newTargetContent, targetFile ); } 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 );  }