Skip to content

Commit

Permalink
Merge pull request #442 from jamezp/WFARQ-160
Browse files Browse the repository at this point in the history
[WFARQ-160] Enable assumptions for JUnit 5 and TestNG. Add tests for …
  • Loading branch information
jamezp authored Apr 9, 2024
2 parents 93f20ec + 0a536d8 commit bbe2441
Show file tree
Hide file tree
Showing 12 changed files with 455 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -216,9 +216,11 @@ private static class ServerSetupTaskHolder {
private static final Class<?> ASSUMPTION_VIOLATED_EXCEPTION = loadAssumptionFailureClass(
"org.junit.AssumptionViolatedException");

// TODO Support this after adding tests of org.opentest4j.TestAbortedException handling
// private static final Class<?> TEST_ABORTED_EXCEPTION = loadAssumptionFailureClass(
// "org.opentest4j.TestAbortedException");
private static final Class<?> TEST_ABORTED_EXCEPTION = loadAssumptionFailureClass(
"org.opentest4j.TestAbortedException");

private static final Class<?> TESTNG_SKIPPED_EXCEPTION = loadAssumptionFailureClass(
"org.testng.SkipException");

@SuppressWarnings("SameParameterValue")
private static Class<?> loadAssumptionFailureClass(String classname) {
Expand Down Expand Up @@ -295,8 +297,8 @@ public String toString() {

private void rethrowFailedAssumptions(final Throwable t, final String containerName) throws FailedAssumptionException {
rethrowFailedAssumption(t, ASSUMPTION_VIOLATED_EXCEPTION);
// TODO Support this after adding tests of org.opentest4j.TestAbortedException handling
// rethrowFailedAssumption(t, TEST_ABORTED_EXCEPTION);
rethrowFailedAssumption(t, TEST_ABORTED_EXCEPTION);
rethrowFailedAssumption(t, TESTNG_SKIPPED_EXCEPTION);
}

@SuppressWarnings("SameParameterValue")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
@ServerSetup({
ServerSetupAssumptionViolationTestCase.BeforeSetup.class,
ServerSetupAssumptionViolationTestCase.AssumptionViolatedSetup.class,
ServerSetupAssumptionViolationTestCase.BeforeSetup.class
ServerSetupAssumptionViolationTestCase.AfterSetup.class
})
public class ServerSetupAssumptionViolationTestCase extends ServerSetupAssumptionTestBase {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@
@ServerSetup({
ServerSetupUnmanagedAssumptionViolationTestCase.BeforeSetup.class,
ServerSetupUnmanagedAssumptionViolationTestCase.AssumptionViolatedSetup.class,
ServerSetupUnmanagedAssumptionViolationTestCase.BeforeSetup.class
ServerSetupUnmanagedAssumptionViolationTestCase.AfterSetup.class
})
public class ServerSetupUnmanagedAssumptionViolationTestCase extends ServerSetupAssumptionTestBase {

Expand Down
16 changes: 15 additions & 1 deletion integration-tests/junit5-tests/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,11 @@
<artifactId>junit-jupiter</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.platform</groupId>
<artifactId>junit-platform-testkit</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.arquillian</groupId>
<artifactId>wildfly-arquillian-container-managed</artifactId>
Expand Down Expand Up @@ -94,7 +99,7 @@
<goal>test</goal>
</goals>
<configuration>
<groups>!OverrideWebUri</groups>
<excludedGroups>OverrideWebUri,engine-test-kit</excludedGroups>
</configuration>
</execution>
<execution>
Expand All @@ -109,6 +114,15 @@
</systemPropertyVariables>
</configuration>
</execution>
<execution>
<id>engine-test-kit</id>
<goals>
<goal>test</goal>
</goals>
<configuration>
<groups>engine-test-kit</groups>
</configuration>
</execution>
</executions>
</plugin>
</plugins>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;

import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Assumptions;
import org.junit.jupiter.api.Test;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@ServerSetup(AbstractAssumptionTestCase.AssumingServerSetupTask.class)
abstract class AbstractAssumptionTestCase {

public static class AssumingServerSetupTask implements ServerSetupTask {

@Override
public void setup(final ManagementClient managementClient, final String containerId) throws Exception {
Assumptions.abort("Abort on purpose");
}

@Override
public void tearDown(final ManagementClient managementClient, final String containerId) throws Exception {

}
}

@Test
public void failIfExecuted() {
Assertions.fail("This should have been skipped and not executed");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,77 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.wildfly.arquillian.integration.test.junit5.GreeterServlet;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@SuppressWarnings("NewClassNamingConvention")
@ExtendWith(ArquillianExtension.class)
@RunAsClient
public class AssumptionServerSetup extends AbstractAssumptionTestCase {

@Deployment
public static WebArchive create() {
return ShrinkWrap.create(WebArchive.class)
.addClass(GreeterServlet.class);
}

@BeforeAll
public static void failBeforeAll(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@BeforeEach
public void failBefore(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@AfterAll
public static void failAfterAll(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@AfterEach
public void failAfter(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;

import org.junit.jupiter.api.Tag;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.ValueSource;
import org.junit.platform.engine.discovery.DiscoverySelectors;
import org.junit.platform.testkit.engine.EngineTestKit;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@Tag("engine-test-kit")
public class AssumptionTestCase {

@ParameterizedTest
@ValueSource(classes = {
AssumptionServerSetup.class,
InContainerAssumptionServerSetup.class,
UnmanagedAssumptionServerSetup.class
})
public void serverSetup(final Class<?> testClass) {
final var events = EngineTestKit.engine("junit-jupiter")
.selectors(DiscoverySelectors.selectMethod(testClass, "failIfExecuted"))
// .enableImplicitConfigurationParameters(true)
.execute()
.allEvents();

// Should have a single aborted event and no failures.
events.assertStatistics((stats) -> stats.aborted(1L));
events.assertStatistics((stats) -> stats.failed(0L));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;

import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.AfterAll;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.TestInfo;
import org.junit.jupiter.api.extension.ExtendWith;
import org.wildfly.arquillian.integration.test.junit5.GreeterServlet;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@SuppressWarnings("NewClassNamingConvention")
@ExtendWith(ArquillianExtension.class)
public class InContainerAssumptionServerSetup extends AbstractAssumptionTestCase {

@Deployment
public static WebArchive create() {
return ShrinkWrap.create(WebArchive.class)
.addClasses(GreeterServlet.class, ServerSetupTask.class);
}

@BeforeAll
public static void failBeforeAll(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@BeforeEach
public void failBefore(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@AfterAll
public static void failAfterAll(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}

@AfterEach
public void failAfter(final TestInfo testInfo) {
Assertions.fail(() -> String.format("%s.%s should not have executed.", testInfo.getTestClass()
.orElseThrow().getSimpleName(),
testInfo.getTestMethod().orElseThrow().getName()));
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* JBoss, Home of Professional Open Source.
*
* Copyright 2024 Red Hat, Inc., and individual contributors
* as indicated by the @author tags.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.wildfly.arquillian.integration.test.junit5.server.setup;

import org.jboss.arquillian.container.test.api.Deployer;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.wildfly.arquillian.integration.test.junit5.GreeterServlet;

/**
* @author <a href="mailto:[email protected]">James R. Perkins</a>
*/
@SuppressWarnings("NewClassNamingConvention")
@ExtendWith(ArquillianExtension.class)
@RunAsClient
public class UnmanagedAssumptionServerSetup extends AbstractAssumptionTestCase {

@ArquillianResource
private Deployer deployer;

@Deployment(managed = false, name = "unmanaged")
public static WebArchive create() {
return ShrinkWrap.create(WebArchive.class)
.addClass(GreeterServlet.class);
}

@Override
@Test
public void failIfExecuted() {
// Until ARQ-2231 this must happen in the test context
deployer.deploy("unmanaged");
super.failIfExecuted();
}
}
Loading

0 comments on commit bbe2441

Please sign in to comment.