ProgramUtils { public static int executeCommand( final Logger logger, final String[] command, final File workingDir, final Map<String,String> environmentVars, final String applicationName, final String scopedInstancePath) throws IOException, InterruptedException { ExecutionResult result = executeCommandWithResult( logger, command, workingDir, environmentVars, applicationName, scopedInstancePath); if( ! Utils.isEmptyOrWhitespaces( result.getNormalOutput())) logger.fine( result.getNormalOutput()); if( ! Utils.isEmptyOrWhitespaces( result.getErrorOutput())) logger.warning( result.getErrorOutput()); return result.getExitValue(); } private  ProgramUtils(); static ExecutionResult executeCommandWithResult(
			final Logger logger,
			final String[] command,
			final File workingDir,
			final Map<String,String> environmentVars,
			final String applicationName,
			final String scopedInstancePath); static int executeCommand(
			final Logger logger,
			final String[] command,
			final File workingDir,
			final Map<String,String> environmentVars,
			final String applicationName,
			final String scopedInstancePath); static int executeCommand(
			final Logger logger,
			final List<String> command,
			final File workingDir,
			final Map<String,String> environmentVars,
			final String applicationName,
			final String scopedInstanceName);  }
@Test public void testNonNullMap_Windows() throws Exception { Assume.assumeTrue( TestUtils.isWindows()); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "cmd", "/C", "dir" ), null, new HashMap<String,String>( 0 ), null, null); }
@Test public void testNonNullMap_UnixFamily() throws Exception { Assume.assumeTrue( TestUtils.isUnix()); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "/bin/sh", "-c", "pwd" ), null, new HashMap<String,String>( 0 ), null, null); }
@Test public void testNonEmptyMap_Windows() throws Exception { Assume.assumeTrue( TestUtils.isWindows()); Map<String,String> map = new HashMap<> (); map.put( null, "null key" ); map.put( "null value", null ); map.put( "key", "value" ); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "cmd", "/C", "dir" ), null, map, null, null); }
@Test public void testNonEmptyMap_UnixFamily() throws Exception { Assume.assumeTrue( TestUtils.isUnix()); Map<String,String> map = new HashMap<> (); map.put( null, "null key" ); map.put( "null value", null ); map.put( "key", "value" ); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "/bin/sh", "-c", "pwd" ), null, map, null, null ); }
@Test public void testNullMap_Windows() throws Exception { Assume.assumeTrue( TestUtils.isWindows()); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "cmd", "/C", "dir" ), null, null, null, null); }
@Test public void testNullMap_UnixFamily() throws Exception { Assume.assumeTrue( TestUtils.isUnix()); ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "/bin/sh", "-c", "pwd" ), null, null, null, null); }
@Test public void testExecutionFailure_Windows() throws Exception { Assume.assumeTrue( TestUtils.isWindows()); int exitCode = ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "help" ), null, null, null, null); Assert.assertNotSame( 0, exitCode ); }
@Test public void testExecutionFailure_UnixFamily() throws Exception { Assume.assumeTrue( TestUtils.isUnix()); int exitCode = ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "/bin/sh", "-c", "apt-get-update" ), null, new HashMap<String,String>( 0 ), null, null); Assert.assertNotSame( 0, exitCode ); }
@Test( expected = IOException.class ) public void testInvalidCommand() throws Exception { ProgramUtils.executeCommand( Logger.getLogger( getClass().getName()), Arrays.asList( "whatever" ), null, null, null, null); }