org.jboss.arquillian.test.spi.event.suite.BeforeClass Java Examples

The following examples show how to use org.jboss.arquillian.test.spi.event.suite.BeforeClass. 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: RedmineGovernorTestCase.java    From arquillian-governor with Apache License 2.0 6 votes vote down vote up
@Test
public void gitHubGovernorTest() {
    fire(new BeforeClass(FakeTestClass.class));

    assertEventFired(BeforeClass.class, 1);
    assertEventFired(DecideMethodExecutions.class, 1);

    final GovernorConfiguration configuration = manager.getContext(ApplicationContext.class).getObjectStore().get(GovernorConfiguration.class);
    assertThat(configuration, is(not(nullValue())));

    final RedmineGovernorConfiguration gitHubConfiguration = manager.getContext(ApplicationContext.class).getObjectStore().get(RedmineGovernorConfiguration.class);
    assertThat(gitHubConfiguration, is(not(nullValue())));

    // for every method and for every Governor annotation of that method
    assertEventFired(ExecutionDecisionEvent.class, 1);

    final ExecutionDecision decision = manager.getContext(ClassContext.class).getObjectStore().get(ExecutionDecision.class);

    assertThat(decision, is(not(nullValue())));
    assertEquals(decision.getDecision(), Decision.EXECUTE);
}
 
Example #2
Source File: AppServerTestEnricher.java    From keycloak with Apache License 2.0 6 votes vote down vote up
public void startAppServer(@Observes(precedence = -1) BeforeClass event) throws MalformedURLException, InterruptedException, IOException {
    // if testClass implements SelfManagedAppContainerLifecycle we skip starting container and let the test to manage the lifecycle itself
    if (SelfManagedAppContainerLifecycle.class.isAssignableFrom(event.getTestClass().getJavaClass())) {
        log.debug("Skipping starting App server. Server should be started by testClass.");
        return;
    }
    if (testContext.isAdapterContainerEnabled() && !testContext.isRelativeAdapterTest()) {
        if (isJBossBased()) {
            prepareServerDir("standalone");
        }
        ContainerController controller = containerConrollerInstance.get();
        if (!controller.isStarted(testContext.getAppServerInfo().getQualifier())) {
            log.info("Starting app server: " + testContext.getAppServerInfo().getQualifier());
            controller.start(testContext.getAppServerInfo().getQualifier());
        }
        if (isFuseAppServer()) {
            FuseUtils.setUpFuse(ContainerConstants.APP_SERVER_PREFIX + CURRENT_APP_SERVER);
        }
    }
}
 
Example #3
Source File: KeycloakContainerEventsController.java    From keycloak with Apache License 2.0 6 votes vote down vote up
@Override
public void execute(BeforeClass event) {
    if (event.getTestClass().isAnnotationPresent(RestartContainer.class)) {

        // stop executing the test - remote container cannot be restarted
        ContainerAssume.assumeNotAuthServerRemote();

        RestartContainer restartContainer = event.getTestClass().getAnnotation(RestartContainer.class);

        beforeOriginalContainerStop(restartContainer);

        container.fire(new StopManualContainers());
        container.fire(new StopSuiteContainers());

        beforeNewContainerStart(restartContainer);

        container.fire(new StartClassContainers());
        container.fire(new StartSuiteContainers());
    }
    super.execute(event);
}
 
Example #4
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 #5
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 #6
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 #7
Source File: GovernorTestClassScanner.java    From arquillian-governor with Apache License 2.0 6 votes vote down vote up
public void onBeforeClass(@Observes BeforeClass event) {
    TestMethodExecutionRegister.setConfigration(governorConfiguration.get());
    TestMethodExecutionRegister.clear();

    if (governorConfiguration.get().getIgnore()) {
        return;
    }

    final Collection<GovernorProvider> governorProviders = serviceLoader.get().all(GovernorProvider.class);

    checkGovernorProviderUniqueness(governorProviders);

    final Map<Method, List<Annotation>> scannedTestMethods = scanTestMethods(event.getTestClass(), Governor.class);

    final GovernorRegistryImpl governorRegistry = new GovernorRegistryImpl();
    governorRegistry.put(scannedTestMethods);
    this.governorRegistry.set(governorRegistry);

    decideMethodExecution.fire(new DecideMethodExecutions());
}
 
Example #8
Source File: GitHubGovernorTestCase.java    From arquillian-governor with Apache License 2.0 6 votes vote down vote up
@Test
public void gitHubGovernorTest() {
    fire(new BeforeClass(FakeTestClass.class));

    assertEventFired(BeforeClass.class, 1);
    assertEventFired(DecideMethodExecutions.class, 1);

    final GovernorConfiguration configuration = manager.getContext(ApplicationContext.class).getObjectStore().get(GovernorConfiguration.class);
    assertThat(configuration, is(not(nullValue())));

    final GitHubGovernorConfiguration gitHubConfiguration = manager.getContext(ApplicationContext.class).getObjectStore().get(GitHubGovernorConfiguration.class);
    assertThat(gitHubConfiguration, is(not(nullValue())));

    // for every method and for every Governor annotation of that method
    assertEventFired(ExecutionDecisionEvent.class, 1);

    final ExecutionDecision decision = manager.getContext(ClassContext.class).getObjectStore().get(ExecutionDecision.class);

    assertThat(decision, is(not(nullValue())));
    assertEquals(decision.getDecision(), Decision.EXECUTE);
}
 
Example #9
Source File: AuthServerTestEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public void initializeTLS(@Observes(precedence = 3) BeforeClass event) throws Exception {
    // TLS for Undertow is configured in KeycloakOnUndertow since it requires
    // SSLContext while initializing HTTPS handlers
    if (!suiteContext.isAuthServerCrossDc() && !suiteContext.isAuthServerCluster()) {
        initializeTLS(suiteContext.getAuthServerInfo());
    }
}
 
Example #10
Source File: AuthServerTestEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public void initializeTestContext(@Observes(precedence = 2) BeforeClass event) throws Exception {
    TestContext testContext = new TestContext(suiteContext, event.getTestClass().getJavaClass());
    testContextProducer.set(testContext);

    if (!isAuthServerRemote() && !isAuthServerQuarkus() && event.getTestClass().isAnnotationPresent(EnableVault.class)) {
        VaultUtils.enableVault(suiteContext, event.getTestClass().getAnnotation(EnableVault.class).providerId());
        restartAuthServer();
        testContext.reconnectAdminClient();
    }
}
 
Example #11
Source File: AppResourceProducer.java    From tomee with Apache License 2.0 5 votes vote down vote up
public void produce(@Observes final BeforeClass bs) {
    try {
        final Assembler a = SystemInstance.get().getComponent(Assembler.class);
        context.set(a.getContainerSystem().getJNDIContext());
        beanManager.set(a.getContainerSystem().getAppContext(a.getDeployedApplications().iterator().next().appId).getBeanManager());
    } catch (final Exception e) {
        // no-op
    }
}
 
Example #12
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public void beforeTestClassCreateSharedTemporaryFolder(@Observes(precedence = -100) BeforeClass beforeClass) throws IOException {
    if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), TemporaryFolder.class)) {
        TemporaryFolder temporaryFolder = new TemporaryFolder();
        temporaryFolder.create();
        scopedTemporaryFolder.get().setSharedTemporaryFolder(temporaryFolder);
    }
}
 
Example #13
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 5 votes vote down vote up
public void beforeTestClassCreateSharedAsciidoctorInstance(@Observes(precedence = -100) BeforeClass beforeClass) {
    if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), AsciidoctorJRuby.class)) {
        scopedAsciidoctor.get().setSharedAsciidoctor(
                AsciidoctorJRuby.Factory.create());
    } else if (isSharedInstanceRequired(beforeClass.getTestClass().getJavaClass(), Asciidoctor.class)) {
        scopedAsciidoctor.get().setSharedAsciidoctor(
                Asciidoctor.Factory.create());
    }
}
 
Example #14
Source File: AppServerTestEnricher.java    From keycloak with Apache License 2.0 5 votes vote down vote up
public void updateTestContextWithAppServerInfo(@Observes(precedence = 1) BeforeClass event) {
    testContext = testContextInstance.get();

    Set<String> appServerQualifiers = getAppServerQualifiers(testContext.getTestClass());
    if (appServerQualifiers.isEmpty()) { // no adapter test
        log.info("\n\n" + testContext);
        return;
    }

    String appServerQualifier = null;
    for (String qualifier : appServerQualifiers) {
        if (qualifier.contains(";")) {// cluster adapter test
            final List<String> appServers = Arrays.asList(qualifier.split("\\s*;\\s*"));
            List<ContainerInfo> appServerBackendsInfo = testContext.getSuiteContext().getContainers().stream()
                .filter(ci -> appServers.contains(ci.getQualifier()))
                .map(this::updateWithAppServerInfo)
                .collect(Collectors.toList());
            testContext.setAppServerBackendsInfo(appServerBackendsInfo);
        } else {// non-cluster adapter test
            for (ContainerInfo container : testContext.getSuiteContext().getContainers()) {
                if (container.getQualifier().equals(qualifier)) {
                    testContext.setAppServerInfo(updateWithAppServerInfo(container));
                    appServerQualifier = qualifier;
                    break;
                }
                //TODO add warning if there are two or more matching containers.
            }
        }
    }
    // validate app server
    if (appServerQualifier != null && testContext.getAppServerInfo() == null) {
        throw new RuntimeException(String.format("No app server container matching '%s' was activated. Check if defined and enabled in arquillian.xml.", appServerQualifier));
    }
    log.info("\n\n" + testContext);
}
 
Example #15
Source File: ReporterLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
public void observeBeforeClass(@Observes(precedence = Integer.MAX_VALUE) BeforeClass event) {
    TestClassReport testClassReport = new TestClassReport();
    testClassReport.setTestClassName(event.getTestClass().getName());
    testClassReport.setRunAsClient(event.getTestClass().isAnnotationPresent(RunAsClient.class));
    testClassReport.setReportMessage(ReportMessageParser.parseTestClassReportMessage(event.getTestClass().getJavaClass()));

    reporter.get().getLastTestSuiteReport().getTestClassReports().add(testClassReport);
    reporter.get().setTestClassReport(testClassReport);
}
 
Example #16
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 #17
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 #18
Source File: JiraGovernorTestCase.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
@Test
public void jiraGovernorTest() {
    fire(new BeforeClass(FakeTestClass.class));

    assertEventFired(BeforeClass.class, 1);
    assertEventFired(DecideMethodExecutions.class, 1);

    final GovernorRegistry governorRegistry = manager.getContext(ClassContext.class).getObjectStore().get(GovernorRegistry.class);
    assertThat(governorRegistry, is(not(nullValue())));

    final GovernorConfiguration configuration = manager.getContext(ApplicationContext.class).getObjectStore().get(GovernorConfiguration.class);
    assertThat(configuration, is(not(nullValue())));

    final JiraGovernorConfiguration jiraConfiguration = manager.getContext(ApplicationContext.class).getObjectStore().get(JiraGovernorConfiguration.class);
    assertThat(jiraConfiguration, is(not(nullValue())));

    final List<Method> jiraMethods = governorRegistry.getMethodsForAnnotation(Jira.class);
    assertEquals(1, jiraMethods.size());

    // for every method and for every Governor annotation of that method
    assertEventFired(ExecutionDecisionEvent.class, 1);

    final ExecutionDecision decision = manager.getContext(ClassContext.class).getObjectStore().get(ExecutionDecision.class);

    assertThat(decision, is(not(nullValue())));
    assertEquals(decision.getDecision(), Decision.EXECUTE);
}
 
Example #19
Source File: GitHubGovernorTestCase.java    From arquillian-governor with Apache License 2.0 5 votes vote down vote up
@org.junit.BeforeClass
public static void setupClass() throws Exception {
    REPOSITORY_USERNAME = resolveRepositoryUser();
    REPOSITORY_NAME = resolveRepository();
    TOKEN = resolveToken();
    USERNAME = resolvUsername();
    PASSWORD = resolvePassword();
}
 
Example #20
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 #21
Source File: DefaultVideoStrategy.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
@Override
public boolean isTakingAction(Event event) {
    if (event instanceof BeforeSuite
            || event instanceof AfterSuite) {
        return configuration.getStartBeforeSuite();
    } else if (event instanceof BeforeClass
            || event instanceof AfterClass) {
        return configuration.getStartBeforeClass();
    } else if (event instanceof Before) {
        return configuration.getStartBeforeTest()
            || configuration.getTakeOnlyOnFail();
    }

    return false;
}
 
Example #22
Source File: VideoLifecycleObserver.java    From arquillian-recorder with Apache License 2.0 5 votes vote down vote up
public void beforeClass(@Observes BeforeClass event) {
    if (strategy.get().isTakingAction(event)) {
        VideoMetaData classMetaData = getClassMetaData(event);
        VideoType videoType = getVideoType();

        beforeVideoStart.fire(new BeforeVideoStart(videoType, classMetaData));

        startRecordClassVideo.fire(new StartRecordClassVideo(videoType, classMetaData));

        afterVideoStart.fire(new AfterVideoStart(videoType, classMetaData));
    }
}
 
Example #23
Source File: JiraGovernorTestCase.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
@org.junit.BeforeClass
public static void setupClass() throws Exception {
    JIRA_SERVER_ADDRESS = resolveJiraServerAddress();
    USERNAME = getUsername();
    PASSWORD = getPassword();
}
 
Example #24
Source File: KeycloakContainerFeaturesController.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void handleEnableFeaturesAnnotationBeforeClass(@Observes(precedence = 1) BeforeClass event) throws Exception {
    checkAnnotatedElementForFeatureAnnotations(event.getTestClass().getJavaClass(), State.BEFORE);
}
 
Example #25
Source File: RedmineGovernorTestCase.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
@org.junit.BeforeClass
public static void setupClass() throws Exception {
    redmineServer = resolveServer();
    apiKey = resolveApiKey();
}
 
Example #26
Source File: AuthServerTestEnricher.java    From keycloak with Apache License 2.0 4 votes vote down vote up
public void initializeOAuthClient(@Observes(precedence = 4) BeforeClass event) {
    // TODO workaround. Check if can be removed
    OAuthClient.updateURLs(suiteContext.getAuthServerInfo().getContextRoot().toString());
    OAuthClient oAuthClient = new OAuthClient();
    oAuthClientProducer.set(oAuthClient);
}
 
Example #27
Source File: ArquillianSuiteExtension.java    From appengine-tck with Apache License 2.0 4 votes vote down vote up
public void overrideBefore(@Observes EventContext<BeforeClass> event) {
    // Setup the Suite level scenario as if it came from the TestClass
    event.proceed();
    classDeploymentScenario.set(suiteDeploymentScenario);
}
 
Example #28
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public void beforeTestClassCreateClasspathResources(@Observes BeforeClass beforeClass) {
    ClasspathResources classpathResources = new ClasspathResources(beforeClass.getTestClass().getJavaClass());
    classpathResourcesInstanceProducer.set(classpathResources);
}
 
Example #29
Source File: AsciidoctorTestObserver.java    From asciidoctorj with Apache License 2.0 4 votes vote down vote up
public void beforeTestClassCreateScopedResourceHolder(@Observes(precedence = 100) BeforeClass beforeClass) {
    scopedAsciidoctor.set(new ScopedAsciidoctor());
    scopedTemporaryFolder.set(new ScopedTemporaryFolder());
}
 
Example #30
Source File: GovernorTestCase.java    From arquillian-governor with Apache License 2.0 4 votes vote down vote up
@Test
public void governorRegistryTestCase() {
    fire(new BeforeClass(FakeTestClass.class));

    assertEventFired(BeforeClass.class, 1);
    assertEventFired(DecideMethodExecutions.class, 1);

    final GovernorRegistry governorRegistry = manager.getContext(ApplicationContext.class).getObjectStore().get(GovernorRegistry.class);

    final GovernorConfiguration configuration = manager.getContext(ApplicationContext.class).getObjectStore().get(GovernorConfiguration.class);

    assertThat(configuration, is(not(nullValue())));

    assertThat(governorRegistry, is(not(nullValue())));

    final List<Method> fakeGovernorMethods = governorRegistry.getMethodsForAnnotation(FakeGovernor.class);
    assertEquals(2, fakeGovernorMethods.size());

    final List<Method> dumymGovernorMethods = governorRegistry.getMethodsForAnnotation(DummyGovernor.class);
    assertEquals(1, dumymGovernorMethods.size());

    // for every method and for every Governor annotation of that method
    assertEventFired(ExecutionDecisionEvent.class, 3);
}