package eu.mondo.utils.test;

import java.io.FileNotFoundException;
import java.io.IOException;
import java.util.Collections;
import java.util.Map;

import org.apache.commons.exec.CommandLine;
import org.apache.commons.exec.DefaultExecutor;
import org.apache.commons.exec.ExecuteException;
import org.apache.commons.exec.environment.EnvironmentUtils;
import org.junit.Test;

import eu.mondo.utils.UnixUtils;

public class UnixUtilsTest {

	@Test
	public void test() throws FileNotFoundException, IOException {
		UnixUtils.exec("ls /", Collections.<String, String> emptyMap(), System.out);
	}

	@Test(expected = ExecuteException.class)
	public void testFail() throws FileNotFoundException, IOException {
		UnixUtils.exec("ls :", Collections.<String, String> emptyMap(), System.out);
	}

	@Test
	public void testEnvironmentVariables() throws IOException {
		final Map<?, ?> executionEnvironment = EnvironmentUtils.getProcEnvironment();
		EnvironmentUtils.addVariableToEnvironment(executionEnvironment, "HELLO=world");

		CommandLine commandLine = new CommandLine("/bin/bash");
		commandLine.addArguments(new String[] { "-c", "echo $HELLO" }, false);
		new DefaultExecutor().execute(commandLine);
	}

}

@@ -769,32 +769,235 @@
  System.out);%0A%09%7D
+%0A%09%0A%09@Test(expected = ExecuteException.class)%0A%09public void testNoSuchScript() throws FileNotFoundException, IOException %7B%0A%09%09UnixUtils.exec(%22./foo%22, Collections.%3CString, String%3E emptyMap(), System.out);%0A%09%7D
 %0A%0A%09@Test%0A%09public

Test more failure cases