public static void assertJoin(Thread thread) { assertJoin(thread, 5000); }
public static void assertEndsWith(String suffix, String test) { assertNotNull(test); assertNotNull(suffix); if (!test.endsWith(suffix)) { throw failure("Was expected " + test + " to end with " + suffix); } }
public ShellResponse getResponse() { try { latch.await(60, TimeUnit.SECONDS); return response; } catch (InterruptedException e) { throw AbstractTestCase.failure(e); } } }
@Override protected void setUp() throws Exception { super.setUp(); // List<CRaSHPlugin<?>> plugins = getPlugins(); TestPluginLifeCycle lifeCycle = new TestPluginLifeCycle(plugins.toArray(new CRaSHPlugin[plugins.size()])); // lifeCycle.start(); // this.shell = lifeCycle.createShell(); this.session = (ShellSession)shell; // A bit nasty but will do for tests :-) this.groovyShell = GroovyCompiler.getGroovyShell((ShellSession)shell); this.lifeCycle = lifeCycle; }
final BaseProcessContext ctx = create(command); final AtomicReference<Boolean> interrupted = new AtomicReference<Boolean>(); Thread t = new Thread() { throw AbstractTestCase.failure(e); assertTrue(interruptDoCancel); assertEquals(ShellResponse.Cancelled.class, resp.getClass()); assertTrue(interruptInterrupted); while (true) { Boolean b = interrupted.get(); if (b != null) { assertTrue("Was not expecting thread to be interrupted", b); break;
public static File toExploded(Archive archive, String ext) { File tmp = assertTmpFile(ext); if (tmp.delete()) { ExplodedExporter exporter = archive.as(ExplodedExporter.class); exporter.exportExploded(tmp.getParentFile(), tmp.getName()); tmp.deleteOnExit(); return tmp; } else { throw failure("Could not delete tmp file " + tmp.getAbsolutePath()); } } }
@Override public void run() { context.execute(); ShellResponse response = context.getResponse(); assertInstance(ShellResponse.Cancelled.class, response); } };
@Override protected void setUp() throws Exception { super.setUp(); // TestPluginLifeCycle lifeCycle = new TestPluginLifeCycle(); lifeCycle.start(); // this.lifeCycle = lifeCycle; }
public static File assertTmpFile(String ext) { File tmp; try { tmp = File.createTempFile("crash", ext); } catch (IOException e) { throw failure("Could not create temporary file", e); } return tmp; }
public static File toFile(Archive archive, String ext) { File tmp = assertTmpFile(ext); if (tmp.delete()) { ZipExporter exporter = archive.as(ZipExporter.class); exporter.exportTo(tmp); tmp.deleteOnExit(); return tmp; } else { throw failure("Could not delete tmp file " + tmp.getAbsolutePath()); } }
@Override protected void execute(TestPluginLifeCycle lifeCycle, Wiser wiser) throws IOException, MessagingException, ExecutionException, InterruptedException { Shell shell = lifeCycle.createShell(); lifeCycle.bindClass("produce", Commands.ProduceValue.class); lifeCycle.bindClass("consume", Commands.ConsumeObject.class); Commands.list.clear(); BaseProcessContext process = BaseProcessContext.create(shell, "produce | mail send -s the_subject -b admin@gmail.com | consume").execute(); ShellResponse.Ok ok = assertInstance(ShellResponse.Ok.class, process.getResponse()); Assert.assertEquals(1, wiser.getMessages().size()); WiserMessage msg = wiser.getMessages().get(0); Assert.assertEquals("foo@gmail.com", msg.getEnvelopeSender()); Assert.assertEquals("admin@gmail.com", msg.getEnvelopeReceiver()); Assert.assertEquals("the_subject", msg.getMimeMessage().getSubject()); String data = new String(msg.getData()); String content = (String)msg.getMimeMessage().getContent(); assertTrue(content.contains("<value>abc</value>")); assertTrue(data.contains("Content-Type: text/html;charset=UTF-8")); System.out.println("data = " + data); assertEquals(Arrays.<Object>asList(new Value("abc")), Commands.list); } };
public void cancel() { try { syncB.await(); } catch (Exception e) { throw failure(e); } } });
@Override public void run(String request, ShellProcessContext context) throws Exception { try { syncA.await(); syncB.await(); } catch (Exception e) { throw failure(e); } }
public static <T> T assertInstance(Class<T> expectedType, Object o) { if (expectedType.isInstance(o)) { return expectedType.cast(o); } else { throw failure("Was expecting the object " + o + " to be an instance of " + expectedType.getName()); } }
public static void assertJoin(Thread thread, long timeMillis) { long before = System.currentTimeMillis(); try { thread.join(timeMillis); } catch (InterruptedException e) { throw failure(e); } long after = System.currentTimeMillis(); if (after - before >= timeMillis) { throw failure("Join failed"); } }
public static <T> T assertType(Class<T> expectedType, Object o) { if (o == null) { throw failure("Was expecting the object " + o + " to not be null"); } else if (o.getClass().equals(expectedType)) { return expectedType.cast(o); } else { throw failure("Was expecting the object " + o + " to be an instance of " + expectedType.getName()); } }
public void publish(final Callable<TermEvent> event) { synchronized (lock) { if (closed) { throw AbstractTestCase.failure("closed"); } queue.addLast(event); lock.notifyAll(); } }
@Override public void execute(ShellProcessContext processContext) throws IllegalStateException { try { runnable.run(request, processContext); } catch (Exception e) { throw AbstractTestCase.failure(e); } } @Override
throw AbstractTestCase.failure(e);