public void testClassNotFound() throws Exception { CommandRunner runner = new CommandRunner("java BadClass", null); runner.run(); assertHasRegexp("java.lang.NoClassDefFoundError", runner.getError()); assertEquals("", runner.getOutput()); assertTrue(0 != runner.getExitCode()); }
private boolean loadTomcatParameters() { InitialContext initCtx = null; try { initCtx = new InitialContext(); NamingContext envCtx = (NamingContext) initCtx.lookup("java:comp/env"); try { CommandRunner.setServerSettingFromTomcatConfig( "app_output_dir", (String) envCtx.lookup("app_output_dir")); } catch (NamingException e) { File rootFolder = new File(ApplicationSettings.WEBAPP_ROOT_DIRECTORY); String appHome = rootFolder.getParentFile().getParentFile().getParent(); CommandRunner.setServerSettingFromTomcatConfig("app_output_dir", appHome); } try { CommandRunner.setServerSettingFromTomcatConfig( "is_test_version", (String) envCtx.lookup("is_test_version")); } catch (NameNotFoundException e) { // Absent is_test_version variable in context.xml CommandRunner.setServerSettingFromTomcatConfig("is_test_version", "false"); } CommandRunner.setServerSettingFromTomcatConfig( "backend_url", (String) envCtx.lookup("backend_url")); return true; } catch (Throwable e) { e .printStackTrace(); // To change body of catch statement use File | Settings | File // Templates. return false; } }
@Test public void testExceptionedCommandYieldsExceptionedTest() throws Exception { commandList.add(command1); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandResult1.getStatus()).thenReturn(CommandResult.EXCEPTION); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.EXCEPTION, testResult.getStatus()); }
public static void run( BRJS brjs, CommandList commandList, LogLevelAccessor logLevelAccessor, String args[]) throws CommandOperationException { ConsoleWriter out = brjs.getConsoleWriter(); if (!CommandRunner.extractCommandFromArgs(args).equals(new VersionCommand().getCommandName())) { out.println(brjs.versionInfo().toString()); out.println(""); } doRunCommand(brjs, args, out); }
@Test public void testSuccessThenFailureYieldsFailedTest() throws Exception { commandList.add(command1); commandList.add(command2); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandRunner.runCommand(command2, lineBuffer, lineWriter)).thenReturn(commandResult2); when(commandResult1.getStatus()).thenReturn(CommandResult.SUCCESS); when(commandResult2.getStatus()).thenReturn(CommandResult.FAILURE); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.FAILURE, testResult.getStatus()); }
@Test public void testCommandsAreNotRunAfterException() throws Exception { commandList.add(command1); commandList.add(command2); when(commandRunner.runCommand(command1, lineBuffer, lineWriter)).thenReturn(commandResult1); when(commandResult1.getStatus()).thenReturn(CommandResult.EXCEPTION); when(commandResult2.getStatus()).thenReturn(CommandResult.SUCCESS); TestResult testResult = singleTestRunner.runTest(lineBuffer, lineWriter, parsedTestUnit); assertEquals(TestResult.EXCEPTION, testResult.getStatus()); verify(commandRunner, never()).runCommand(command2, lineBuffer, lineWriter); }
public void testExpandTar() throws Exception { fileSystem.makeDirs(new File("/dummy/path/45.expanded")); expect(fileSystem.getTemporaryDirectory("expanded_tar_")) .andReturn(new File("/dummy/path/45.expanded")); expect( mockcmd.runCommand( "tar", ImmutableList.of("-xf", "/dummy/path/45.tar"), "/dummy/path/45.expanded")) .andReturn(""); control.replay(); File expanded = Utils.expandTar(new File("/dummy/path/45.tar")); assertEquals(new File("/dummy/path/45.expanded"), expanded); control.verify(); }
public void testBasics() throws Exception { CommandRunner runner = new CommandRunner("java -cp ./classes fitnesse.testutil.Echo", "echo this!"); runner.run(); assertHasRegexp("echo this!", runner.getOutput()); assertEquals("", runner.getError()); assertEquals(false, runner.hasExceptions()); assertEquals(0, runner.getExitCode()); }
/** * Confirms that the expandToDirectory()-method calls the proper expand methods for known archive * types. * * @throws Exception */ public void testExpandToDirectory() throws Exception { String filePath = "/foo/bar.tar"; File file = new File(filePath); expect(fileSystem.getTemporaryDirectory(EasyMock.<String>anyObject())) .andReturn(new File("/test")); fileSystem.makeDirs(EasyMock.<File>anyObject()); EasyMock.expectLastCall().once(); expect( mockcmd.runCommand( EasyMock.<String>anyObject(), EasyMock.<List<String>>anyObject(), EasyMock.<String>anyObject())) .andReturn(null); control.replay(); // Run the .expandToDirectory method. File directory = Utils.expandToDirectory(file); assertNotNull(directory); assertEquals("/test", directory.toString()); control.verify(); }