-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #442 from jamezp/WFARQ-160
[WFARQ-160] Enable assumptions for JUnit 5 and TestNG. Add tests for …
- Loading branch information
Showing
12 changed files
with
455 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
52 changes: 52 additions & 0 deletions
52
...g/wildfly/arquillian/integration/test/junit5/server/setup/AbstractAssumptionTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"); | ||
} | ||
} |
77 changes: 77 additions & 0 deletions
77
...va/org/wildfly/arquillian/integration/test/junit5/server/setup/AssumptionServerSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
51 changes: 51 additions & 0 deletions
51
.../java/org/wildfly/arquillian/integration/test/junit5/server/setup/AssumptionTestCase.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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)); | ||
} | ||
} |
76 changes: 76 additions & 0 deletions
76
...fly/arquillian/integration/test/junit5/server/setup/InContainerAssumptionServerSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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())); | ||
} | ||
} |
57 changes: 57 additions & 0 deletions
57
...ldfly/arquillian/integration/test/junit5/server/setup/UnmanagedAssumptionServerSetup.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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(); | ||
} | ||
} |
Oops, something went wrong.