Skip to content

Commit

Permalink
Merge pull request wildfly#17650 from bstansberry/WFLY-19025
Browse files Browse the repository at this point in the history
[WFLY-19025] Update LayersTestCase(s) to reflect WFCORE-6456
  • Loading branch information
bstansberry authored Mar 5, 2024
2 parents bfbf053 + 6da43fb commit da23e3c
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,15 +6,13 @@

import java.util.Set;

import org.jboss.as.test.layers.LayersTest;
import org.jboss.as.test.shared.LayersTestBase;
import org.jboss.as.test.shared.util.AssumeTestGroupUtil;
import org.junit.Test;

public class LayersTestCase extends LayersTestBase {

@Override
public void test() throws Exception {
public void testUnreferencedModules() throws Exception {
// For WildFly Preview testing, ignore this test. The testing in the layers-expansion
// testsuite module covers this.
// In this module the test-standalone-reference installation will be
Expand All @@ -23,15 +21,20 @@ public void test() throws Exception {
// testing those is out of scope for this module.
AssumeTestGroupUtil.assumeNotWildFlyPreview();

super.test();
super.testUnreferencedModules();
}

@Test
public void testLayers() throws Exception {
// Since we don't run 'test()' with WFP, which among other things
// checks the execution of the layers, do it directly
AssumeTestGroupUtil.assumeWildFlyPreview();
LayersTest.testExecution(root);
@Override
public void testLayersModuleUse() throws Exception {
// For WildFly Preview testing, ignore this test. The testing in the layers-expansion
// testsuite module covers this.
// In this module the test-standalone-reference installation will be
// provisioned with a lot of MP, etc modules, as that's what wildfly-preview FP does.
// But the test-all-layers installation will not include the expansion layers as
// testing those is out of scope for this module.
AssumeTestGroupUtil.assumeNotWildFlyPreview();

super.testLayersModuleUse();
}

protected Set<String> getExpectedUnreferenced() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -329,51 +329,104 @@ protected static Set<String> concatArrays(String[] first, String[]... others) {
* A HashMap to configure a banned module.
* They key is the banned module name, the value is an optional List with the installation names that are allowed to
* provision the banned module. This installations will be ignored.
*
* <p>
* Notice the allowed installation names does not distinguish between different parent names, e.g test-all-layers here means
* allowing root/test-all-layers and servletRoot/test-all-layers.
*/
private static final HashMap<String, List<String>> BANNED_MODULES_CONF = new HashMap<>(){{
put("org.jboss.as.security", Arrays.asList("test-all-layers-jpa-distributed", "test-all-layers", "legacy-security", "test-standalone-reference"));
}};

public static String root;
public static String defaultConfigsRoot;
protected static String root;
private static String defaultConfigsRoot;
private static LayersTest.ScanContext scanContext;

@BeforeClass
public static void setUp() {
root = System.getProperty("layers.install.root");
defaultConfigsRoot = System.getProperty("std.default.install.root");
scanContext = new LayersTest.ScanContext(root);
}

@AfterClass
public static void cleanUp() {
Boolean delete = Boolean.getBoolean("layers.delete.installations");
boolean delete = Boolean.getBoolean("layers.delete.installations");
if(delete) {
File[] installations = new File(root).listFiles(File::isDirectory);
for(File f : installations) {
LayersTest.recursiveDelete(f.toPath());
if (installations != null) {
for (File f : installations) {
LayersTest.recursiveDelete(f.toPath());
}
}
installations = new File(defaultConfigsRoot).listFiles(File::isDirectory);
for(File f : installations) {
LayersTest.recursiveDelete(f.toPath());
if (installations != null) {
for (File f : installations) {
LayersTest.recursiveDelete(f.toPath());
}
}
}
}

/**
* Checks that the installations found in the given {@code layers.install.root} directory can all be started
* without errors, i.e. with the {@code WFLYSRV0025} log message in the server's stdout stream.
* <p>
* The @{code test-standalone-reference} installation is not tested as that kind of installation is heavily
* tested elsewhere.
*
* @throws Exception on failure
*/
@Test
public void testLayersBoot() throws Exception {
LayersTest.testLayersBoot(root);
}

/**
* Checks that all modules that were provisioned in the @{code test-standalone-reference} installation are also
* provisioned in @{test-all-layers}, except those included in the {@link #getExpectedUnusedInAllLayers()} set.
* The goals of this test are to check for new modules that should be provided by layers but currently are not
* and to encourage inclusion of existing modules not used in a layer to have an associated layer.
*
* @throws Exception on failure
*/
@Test
public void testLayersModuleUse() throws Exception {
LayersTest.testLayersModuleUse(getExpectedUnusedInAllLayers(), scanContext);
}

/**
* Checks that all modules in the @{code test-standalone-reference} installation are referenced from
* the installation root module or extension modules configured in standalone.xml, except those
* included in the {@link #getExpectedUnreferenced()} set. The goal of this test is to prevent the
* accumulation of 'orphaned' modules that are not usable.
*
* @throws Exception on failure
*/
@Test
public void test() throws Exception {
LayersTest.test(root, getExpectedUnreferenced(), getExpectedUnusedInAllLayers());
public void testUnreferencedModules() throws Exception {
LayersTest.testUnreferencedModules(getExpectedUnreferenced(), scanContext);
}

/**
* Checks that none of the installations found in the given {@code layers.install.root} directory include modules
* marked as 'banned'.
*
* @throws Exception on failure
*/
@Test
public void checkBannedModules() throws Exception {
final HashMap<String, String> results = LayersTest.checkBannedModules(root, BANNED_MODULES_CONF);
Assert.assertTrue("The following banned modules were provisioned " + results.toString(), results.isEmpty());
}

/**
* Checks that the installation found in the given {@code std.default.install.root} directory can be started
* without errors, i.e. with the {@code WFLYSRV0025} log message in the server's stdout stream.
*
* @throws Exception on failure
*/
@Test
public void testDefaultConfigs() throws Exception {
LayersTest.testExecution(defaultConfigsRoot);
LayersTest.testLayersBoot(defaultConfigsRoot);
}
}

0 comments on commit da23e3c

Please sign in to comment.