AgentUtils { public static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent ) throws IOException { File dir = InstanceHelpers.findInstanceDirectoryOnAgent( instance ); Utils.createDirectory( dir ); if( fileNameToFileContent != null ) { for( Map.Entry<String,byte[]> entry : fileNameToFileContent.entrySet()) { File f = new File( dir, entry.getKey()); Utils.createDirectory( f.getParentFile()); ByteArrayInputStream in = new ByteArrayInputStream( entry.getValue()); Utils.copyStream( in, f ); } } } private  AgentUtils(); static boolean isValidIP( String ip ); static void copyInstanceResources( Instance instance, Map<String,byte[]> fileNameToFileContent ); static void executeScriptResources( File scriptsDir ); static void deleteInstanceResources( Instance instance ); static void changeRoboconfLogLevel( String logLevel, String etcDir ); static Map<String,byte[]> collectLogs( String karafData ); static String findIpAddress( String networkInterface ); static void injectConfigurations(
			String karafEtc,
			String applicationName,
			String scopedInstancePath,
			String domain,
			String ipAddress ); static final String INJECTED_CONFIGS_DIR; }
@Test( expected = IOException.class ) public void testInstanceResources_exception_rootDir() throws Exception { TestApplicationTemplate app = new TestApplicationTemplate(); File dir = InstanceHelpers.findInstanceDirectoryOnAgent( app.getTomcat()); Utils.deleteFilesRecursively( dir ); Assert.assertFalse( dir.exists()); Assert.assertTrue( dir.createNewFile()); Assert.assertTrue( dir.exists()); try { AgentUtils.copyInstanceResources( app.getTomcat(), null ); } finally { Utils.deleteFilesRecursively( dir ); } }
@Test( expected = IOException.class ) public void testInstanceResources_exception_subDir() throws Exception { TestApplicationTemplate app = new TestApplicationTemplate(); Map<String,byte[]> fileNameToFileContent = new HashMap<> (); fileNameToFileContent.put( "dir1/dir2/f3.txt", "I am file 3".getBytes( "UTF-8" )); File dir = InstanceHelpers.findInstanceDirectoryOnAgent( app.getTomcat()); Utils.deleteFilesRecursively( dir ); Assert.assertFalse( dir.exists()); Assert.assertTrue( dir.mkdirs()); Assert.assertTrue( new File( dir, "dir1" ).createNewFile()); try { AgentUtils.copyInstanceResources( app.getTomcat(), fileNameToFileContent ); } finally { Utils.deleteFilesRecursively( dir ); } }