args.add("-Dij.connection.test=jdbc:derby:wombat;create=true");
args.add("org.apache.derby.tools.ij");
final String[] argArray = args.toArray(new String[0]);
final Process p = execJavaCmd(argArray);
SpawnedProcess spawned = new SpawnedProcess(p, "MPT");
spawned.suppressOutputOnComplete(); // we want to read it ourselves
// The started process is an interactive ij session that will wait
// for user input. Close stdin of the process so that it stops
// waiting and exits.
p.getOutputStream().close();
final int exitCode = spawned.complete(120000L); // 2 minutes
assertTrue(
spawned.getFailMessage("subprocess run failed: "), exitCode == 0);
// The actual message may vary. On Java 6, the names are not quoted,
// whereas newer versions double-quote them. On Windows, the directory
// separator is different. Also, different JVM vendors capitalize
// the "access denied" message differently.
//
// Use a regular expression that matches all known variants.
final String expectedMessageOnConsole =
"(?s).*The file or directory system.nested could not be created " +
"due to a security exception: " +
"java\\.security\\.AccessControlException: [Aa]ccess denied " +
"\\(\"?java\\.io\\.FilePermission\"? \"?system.nested\"? " +
"\"?write\"?\\).*";
final String output = spawned.getFullServerOutput(); // ignore
final String err = spawned.getFullServerError();
assertTrue(err, err.matches(expectedMessageOnConsole));
}