org.jboss.arquillian.test.spi.TestResult Java Examples

The following examples show how to use org.jboss.arquillian.test.spi.TestResult. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: ClassLoaderExceptionTransformer.java    From quarkus with Apache License 2.0 6 votes vote down vote up
public void transform(@Observes(precedence = -1000) Test event) {
    TestResult testResult = testResultInstance.get();
    if (testResult != null) {
        Throwable res = testResult.getThrowable();
        if (res != null) {
            try {
                if (res.getClass().getClassLoader() != null
                        && res.getClass().getClassLoader() != getClass().getClassLoader()) {
                    if (res.getClass() == classLoaderInstance.get().loadClass(res.getClass().getName())) {
                        ByteArrayOutputStream out = new ByteArrayOutputStream();
                        ObjectOutputStream oo = new ObjectOutputStream(out);
                        oo.writeObject(res);
                        res = (Throwable) new ObjectInputStream(new ByteArrayInputStream(out.toByteArray())).readObject();
                        testResult.setThrowable(res);
                    }
                }
            } catch (Exception ignored) {

            }
        }
    }
}
 
Example #2
Source File: VideoTaker.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
public void onStopRecording(@Observes StopRecordVideo event) throws IOException {
    Video video = recorder.get().stopRecording();

    TestResult testResult = event.getVideoMetaData().getTestResult();

    if (testResult != null) {
        Status status = testResult.getStatus();
        appendStatus(video, status);

        resourceRegister.get().addReported(video);

        if ((status.equals(Status.PASSED) && !configuration.get().getTakeOnlyOnFail())
            || (status.equals(Status.FAILED) && configuration.get().getTakeOnlyOnFail())) {
            propertyReportEvent.fire(new PropertyReportEvent(getVideoEntry(video)));
        }
    } else {
        resourceRegister.get().addTaken(video);
    }
}
 
Example #3
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeSuiteTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeSuite()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new After(DummyTestCase.class, DummyTestCase.class.getMethod("test")));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordSuiteVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordSuiteVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #4
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeClassTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeClass()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordClassVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordClassVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #5
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Test
public void startBeforeTestTrueTest() throws Exception {

    Mockito.when(configuration.getStartBeforeTest()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #6
Source File: DefaultAnnotationScreenshootingStrategy.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
@Override
public boolean isTakingAction(Event event, TestResult result) {
    if (event instanceof AfterTestLifecycleEvent && !(event instanceof After)) {
        Screenshot screenshotAnnotation = ScreenshotAnnotationScanner.getScreenshotAnnotation(((AfterTestLifecycleEvent) event).getTestMethod());

        if (screenshotAnnotation != null) {
            if (screenshotAnnotation.takeAfterTest()) {
                return true;
            }
            if (result.getStatus() == Status.FAILED && screenshotAnnotation.takeWhenTestFailed()) {
                return true;
            }
        }
    }

    return false;
}
 
Example #7
Source File: ScreenshooterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 6 votes vote down vote up
public boolean decide(org.jboss.arquillian.core.spi.event.Event event, TestResult testResult) {

            boolean taking = false;

            for (final RecorderStrategy<?> recorderStrategy : recorderStrategyRegister.getAll()) {
                if (recorderStrategy instanceof AnnotationScreenshootingStrategy && !hasScreenshotAnnotation(event)) {
                    continue;
                }
                if (testResult == null) {
                    taking = recorderStrategy.isTakingAction(event);
                } else {
                    taking = recorderStrategy.isTakingAction(event, testResult);
                }
            }

            return taking;
        }
 
Example #8
Source File: FurnaceProtocol.java    From furnace with Eclipse Public License 1.0 6 votes vote down vote up
@Override
public ContainerMethodExecutor getExecutor(FurnaceProtocolConfiguration protocolConfiguration,
         ProtocolMetaData metaData, CommandCallback callback)
{
   if (metaData == null)
   {
      return new ContainerMethodExecutor()
      {
         @Override
         public TestResult invoke(TestMethodExecutor arg0)
         {
            return TestResult.skipped();
         }
      };
   }

   Collection<FurnaceHolder> contexts = metaData.getContexts(FurnaceHolder.class);
   if (contexts.size() == 0)
   {
      throw new IllegalArgumentException(
               "No " + Furnace.class.getName() + " found in " + ProtocolMetaData.class.getName() + ". " +
                        "Furnace protocol can not be used");
   }
   return new FurnaceTestMethodExecutor(protocolConfiguration, contexts.iterator().next());
}
 
Example #9
Source File: ModelTestExecutor.java    From keycloak with Apache License 2.0 5 votes vote down vote up
@Override
public void execute(LocalExecutionEvent event) throws Exception {
    Method testMethod = event.getExecutor().getMethod();

    ModelTest annotation = testMethod.getAnnotation(ModelTest.class);

    if (annotation == null) {
        // Not a model test
        super.execute(event);
    } else {
        TestResult result = new TestResult();

        try {
            // Model test - wrap the call inside the
            TestContext ctx = testContext.get();
            KeycloakTestingClient testingClient = ctx.getTestingClient();
            testingClient.server().runModelTest(testMethod.getDeclaringClass().getName(), testMethod.getName());
            
            result.setStatus(TestResult.Status.PASSED);
        } catch (Throwable e) {
            result.setStatus(TestResult.Status.FAILED);
            result.setThrowable(e);
        } finally {
            result.setEnd(System.currentTimeMillis());
        }

        // Need to use reflection this way...
        Field testResultField = Reflections.findDeclaredField(LocalTestExecuter.class, "testResult");
        testResultField.setAccessible(true);
        InstanceProducer<TestResult> thisTestResult = (InstanceProducer<TestResult>) testResultField.get(this);

        thisTestResult.set(result);
    }
}
 
Example #10
Source File: JeeIntegrationBeanTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createTestArchive() {
    // @formatter:off
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(ServiceProviderDiscovery.class,
                                 CallbackHandlerDiscovery.class,
                                 DefaultJoynrRuntimeFactory.class,
                                 JeeIntegrationJoynrTestConfigurationProvider.class,
                                 JoynrIntegrationBean.class,
                                 TestResult.class,
                                 JeeJoynrStatusMetricsAggregator.class,
                                 JeeJoynrServiceLocator.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"));
    // @formatter:on
}
 
Example #11
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void takeOnlyOnFailTestPassedTest() throws Exception {

    Mockito.when(configuration.getTakeOnlyOnFail()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(PropertyReportEvent.class, 0);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #12
Source File: JoynrMessagePersisterInjectionTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> getDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(JoynrMessagePersister.class, TestResult.class, TestMessagePersisterProducer.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"))
                     .addAsManifestResource(new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"));
}
 
Example #13
Source File: JoynrJeeMessageContextTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> getDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(JoynrJeeMessageScoped.class,
                                 JoynrJeeMessageContext.class,
                                 TestResult.class,
                                 MessageScopedBean.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"))
                     .addAsManifestResource(new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"));
}
 
Example #14
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void takeOnlyOnFailTestFailedTest() throws Exception {

    Mockito.when(configuration.getTakeOnlyOnFail()).thenReturn(true);

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException("some exception")));

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 1);
    assertEventFired(StartRecordVideo.class, 1);
    assertEventFired(AfterVideoStart.class, 1);

    assertEventFired(PropertyReportEvent.class, 1);

    assertEventFired(BeforeVideoStop.class, 1);
    assertEventFired(StopRecordVideo.class, 1);
    assertEventFired(AfterVideoStop.class, 1);
}
 
Example #15
Source File: JoynrRawMessageProcessorTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> getDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(JoynrRawMessagingPreprocessor.class,
                                 TestResult.class,
                                 TestRawMessagingProcessorProducer.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"))
                     .addAsManifestResource(new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"));
}
 
Example #16
Source File: JeeIntegrationBeanMqttOnlyTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static JavaArchive createTestArchive() {
    // @formatter:off
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(ServiceProviderDiscovery.class,
                                 CallbackHandlerDiscovery.class,
                                 DefaultJoynrRuntimeFactory.class,
                                 MqttOnlyJoynrConfigurationProvider.class,
                                 JoynrIntegrationBean.class,
                                 TestResult.class,
                                 JeeJoynrStatusMetricsAggregator.class,
                                 JeeJoynrServiceLocator.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"));
    // @formatter:on
}
 
Example #17
Source File: JoynrMqttClientIdProviderTest.java    From joynr with Apache License 2.0 5 votes vote down vote up
@Deployment
public static Archive<?> getDeployment() {
    return ShrinkWrap.create(JavaArchive.class)
                     .addClasses(JoynrMqttClientIdProvider.class,
                                 TestResult.class,
                                 TestMqttClientIdProviderProducer.class)
                     .addAsManifestResource(new File("src/main/resources/META-INF/beans.xml"))
                     .addAsManifestResource(new File("src/main/resources/META-INF/services/javax.enterprise.inject.spi.Extension"));
}
 
Example #18
Source File: RecorderLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Test
public void defaultConfigurationTest() throws Exception {

    // by default, no videos are taken at all

    fire(new VideoExtensionConfigured());

    fire(new BeforeSuite());
    fire(new BeforeClass(DummyTestCase.class));
    fire(new Before(DummyTestCase.class, DummyTestCase.class.getMethod("test")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(DummyTestCase.class, DummyTestCase.class.getMethod("test"), LifecycleMethodExecutor.NO_OP));
    fire(new AfterClass(DummyTestCase.class));
    fire(new AfterSuite());

    assertEventFired(BeforeVideoStart.class, 0);
    assertEventFired(StartRecordVideo.class, 0);
    assertEventFired(StartRecordSuiteVideo.class, 0);
    assertEventFired(AfterVideoStart.class, 0);

    assertEventFired(BeforeVideoStop.class, 0);
    assertEventFired(StopRecordVideo.class, 0);
    assertEventFired(StopRecordSuiteVideo.class, 0);
    assertEventFired(AfterVideoStop.class, 0);
}
 
Example #19
Source File: DefaultVideoStrategy.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTakingAction(Event event, TestResult result) {
    if (event instanceof AfterTestLifecycleEvent && !(event instanceof After)) {
        switch (result.getStatus()) {
            case FAILED:
                return configuration.getTakeOnlyOnFail();
            case PASSED:
                return configuration.getStartBeforeTest() || configuration.getTakeOnlyOnFail();
            case SKIPPED:
            default:
                return false;
        }
    }
    return false;
}
 
Example #20
Source File: DaemonMethodExecutor.java    From thorntail with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see org.jboss.arquillian.container.test.spi.ContainerMethodExecutor#invoke(org.jboss.arquillian.test.spi.TestMethodExecutor)
 */
@Override
public TestResult invoke(final TestMethodExecutor testMethodExecutor) {

    assert testMethodExecutor != null : "Test method executor is required";

    // Build the String request according to the wire protocol
    final StringBuilder builder = new StringBuilder();
    builder.append(WireProtocol.COMMAND_TEST_PREFIX);
    builder.append(testMethodExecutor.getInstance().getClass().getName());
    builder.append(SPACE);
    builder.append(testMethodExecutor.getMethod().getName());
    builder.append(WireProtocol.COMMAND_EOF_DELIMITER);
    final String testCommand = builder.toString();
    final PrintWriter writer = this.context.getWriter();

    // Request
    writer.write(testCommand);
    writer.flush();

    try {
        // Read response
        final ObjectInputStream response = new ObjectInputStream(
                new NoCloseInputStream(context.getSocketInstream()));
        final TestResult testResult = (TestResult) response.readObject();
        response.close();
        return testResult;

    } catch (final IOException ioe) {
        throw new RuntimeException("Could not get test results", ioe);
    } catch (final ClassNotFoundException cnfe) {
        throw new RuntimeException("test result not on the client classpath", cnfe);
    }
}
 
Example #21
Source File: ScreenshooterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
public void afterTest(@Observes(precedence = 50) AfterTestLifecycleEvent event, TestResult result) {
    if (new TakingScreenshotDecider(recorderStrategyRegister.get()).decide(event, result)) {
        ScreenshotMetaData metaData = getMetaData(event);
        metaData.setTestResult(result);
        metaData.setResourceType(getScreenshotType());

        When when = result.getStatus() == TestResult.Status.FAILED ? When.FAILED : When.AFTER;

        DefaultFileNameBuilder nameBuilder = new DefaultFileNameBuilder();
        String screenshotName = nameBuilder
            .withMetaData(metaData)
            .withStage(when)
            .build();

        beforeScreenshotTaken.fire(new BeforeScreenshotTaken(metaData));

        TakeScreenshot takeScreenshooter = new TakeScreenshot(screenshotName, metaData, when, null);
        takeScreenshot.fire(takeScreenshooter);

        metaData.setBlurLevel(resolveBlurLevel(event));
        org.arquillian.extension.recorder.screenshooter.Screenshot screenshot = takeScreenshooter.getScreenshot();
        if(screenshot != null) {
            metaData.setFilename(screenshot.getResource());
        }

        afterScreenshotTaken.fire(new AfterScreenshotTaken(metaData));
    }
}
 
Example #22
Source File: DaemonMethodExecutor.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
/**
 * {@inheritDoc}
 *
 * @see org.jboss.arquillian.container.test.spi.ContainerMethodExecutor#invoke(org.jboss.arquillian.test.spi.TestMethodExecutor)
 */
@Override
public TestResult invoke(final TestMethodExecutor testMethodExecutor) {

    assert testMethodExecutor != null : "Test method executor is required";

    // Build the String request according to the wire protocol
    final StringBuilder builder = new StringBuilder();
    builder.append(WireProtocol.COMMAND_TEST_PREFIX);
    builder.append(testMethodExecutor.getInstance().getClass().getName());
    builder.append(SPACE);
    builder.append(testMethodExecutor.getMethod().getName());
    builder.append(WireProtocol.COMMAND_EOF_DELIMITER);
    final String testCommand = builder.toString();
    final PrintWriter writer = this.context.getWriter();

    // Request
    writer.write(testCommand);
    writer.flush();

    try {
        // Read response
        final ObjectInputStream response = new ObjectInputStream(
                new NoCloseInputStream(context.getSocketInstream()));
        final TestResult testResult = (TestResult) response.readObject();
        response.close();
        return testResult;

    } catch (final IOException ioe) {
        throw new RuntimeException("Could not get test results", ioe);
    } catch (final ClassNotFoundException cnfe) {
        throw new RuntimeException("test result not on the client classpath", cnfe);
    }
}
 
Example #23
Source File: JiraTestExecutionDecider.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
public void on(@Observes AfterTestLifecycleEvent event,
               TestResult testResult,
               GovernorRegistry governorRegistry,
               JiraGovernorConfiguration jiraGovernorConfiguration) {
    int count = 0;
    try {
        final Integer c = lifecycleCountRegister.get(event.getTestMethod());
        count = (c != null ? c.intValue() : 0);
        if (count == 0) { //skip first event - see https://github.com/arquillian/arquillian-governor/pull/16#issuecomment-166590210
            return;
        }
        final ExecutionDecision decision = TestMethodExecutionRegister.resolve(event.getTestMethod(), provides());

        // if we passed some test method annotated with Jira, we may eventually close it

        if (jiraGovernorConfiguration.getClosePassed()) {
            // we decided we run this test method even it has annotation on it
            if (decision.getDecision() == Decision.EXECUTE
                    && (JiraGovernorStrategy.FORCING_EXECUTION_REASON_STRING).equals(decision.getReason())) {

                for (final Map.Entry<Method, List<Annotation>> entry : governorRegistry.get().entrySet()) {
                    if (entry.getKey().toString().equals(event.getTestMethod().toString())) {
                        for (final Annotation annotation : entry.getValue()) {
                            if (annotation.annotationType() == provides()) {
                                closePassedDecider.get().setClosable(annotation, testResult.getStatus() == Status.PASSED);
                                return;
                            }
                        }
                    }
                }
            }
        }
    } finally {
        lifecycleCountRegister.put(event.getTestMethod(), ++count);
    }
}
 
Example #24
Source File: GitHubTestExecutionDecider.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
public void on(@Observes AfterTestLifecycleEvent event,
               TestResult testResult,
               GovernorRegistry governorRegistry,
               GitHubGovernorConfiguration gitHubGovernorConfiguration) {

    int count = 0;
    try {
        final Integer c = lifecycleCountRegister.get(event.getTestMethod());
        count = (c != null ? c.intValue() : 0);
        if (count == 0) { //skip first event - see https://github.com/arquillian/arquillian-governor/pull/16#issuecomment-166590210
            return;
        }

        final ExecutionDecision decision = TestMethodExecutionRegister.resolve(event.getTestMethod(), provides());

        // if we passed some test method annotated with GitHub, we may eventually close it

        if (gitHubGovernorConfiguration.getClosePassed()) {
            // we decided we run this test method even it has annotation on it
            if (decision.getDecision() == Decision.EXECUTE
                    && (GitHubGovernorStrategy.FORCING_EXECUTION_REASON_STRING).equals(decision.getReason())) {

                for (final Map.Entry<Method, List<Annotation>> entry : governorRegistry.get().entrySet()) {
                    if (entry.getKey().toString().equals(event.getTestMethod().toString())) {
                        for (final Annotation annotation : entry.getValue()) {
                            if (annotation.annotationType() == provides()) {
                                closePassedDecider.get().setClosable(annotation, testResult.getStatus() == Status.PASSED);
                                return;
                            }
                        }
                    }
                }
            }
        }
    } finally {
        lifecycleCountRegister.put(event.getTestMethod(), ++count);
    }
}
 
Example #25
Source File: IgnoreObserver.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
private void execute(EventContext<? extends ExecutionEvent> context, String phase) {
    if (shouldPerformExecution(context.getEvent())) {
        context.proceed();
    } else {
        log.info("Ignore test [" + phase + "]: " + toFqn(context.getEvent()));
        testResultProducer.set(TestResult.skipped());
    }
}
 
Example #26
Source File: DefaultScreenshootingStrategy.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTakingAction(Event event, TestResult result) {
    if (event instanceof AfterTestLifecycleEvent && !(event instanceof After)) {
        if (configuration.getTakeAfterTest()) {
            return true;
        }
        if (result.getStatus() == Status.FAILED && configuration.getTakeWhenTestFailed()) {
            return true;
        }
    }
    return false;
}
 
Example #27
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTestStatusFailedTakeAfterTestTrueTakeWhenFailedTrue() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);
    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(true);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException()));

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #28
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTestStatusFailedTakeAfterTestTrueTakeWhenFailedFalse() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);
    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(false);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new RuntimeException()));

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #29
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void afterTestEventTakeAfterTestTrue() throws Exception {

    Mockito.when(configuration.getTakeAfterTest()).thenReturn(true);

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    fire(new Before(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest")));

    bind(TestScoped.class, TestResult.class, TestResult.passed());

    fire(new AfterRules(FakeTestClass.class, FakeTestClass.class.getMethod("fakeTest"),
        LifecycleMethodExecutor.NO_OP));

    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}
 
Example #30
Source File: ScreenshooterLifecycleObserverTestCase.java    From arquillian-recorder with Apache License 2.0 4 votes vote down vote up
@Test
public void takeWhenTestFailedTrueScreenshotMethodTest() throws Exception {

    Mockito.when(configuration.getTakeWhenTestFailed()).thenReturn(false); // false in config

    fire(new ScreenshooterExtensionConfigured());

    initRecorderStrategyRegister();

    // true in annotation
    fire(new Before(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeWhenTestFailedMethod")));

    bind(TestScoped.class, TestResult.class, TestResult.failed(new Throwable()));

    fire(new AfterRules(FakeAnnotatedClass.class, FakeAnnotatedClass.class.getMethod("takeWhenTestFailedMethod"),
        LifecycleMethodExecutor.NO_OP));

    // so we take it
    assertEventFired(BeforeScreenshotTaken.class, 1);
    assertEventFired(TakeScreenshot.class, 1);
    assertEventFired(AfterScreenshotTaken.class, 1);
}