Search in sources :

Example 1 with READ_CHILDREN_RESOURCES_OPERATION

use of org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION in project wildfly by wildfly.

the class HostExcludesTestCase method testHostExcludes.

@Test
public void testHostExcludes() throws IOException, MgmtOperationException {
    Set<String> availableExtensions = retrieveAvailableExtensions();
    ModelNode op = Util.getEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, null);
    op.get(CHILD_TYPE).set(EXTENSION);
    ModelNode result = DomainTestUtils.executeForResult(op, masterClient);
    Set<String> currentExtensions = new HashSet<>();
    for (Property prop : result.asPropertyList()) {
        currentExtensions.add(prop.getName());
    }
    // Check we are able to retrieve at minimum all the extensions defined for the current server
    if (!availableExtensions.containsAll(currentExtensions)) {
        currentExtensions.removeAll(availableExtensions);
        fail(String.format("The following extensions defined in domain.xml cannot be retrieved by this test %s . " + "It could lead in a false negative test result, check HostExcludesTestCase.retrieveAvailableExtensions method", currentExtensions));
    }
    // Check that the list of all available extensions is in the ExtensionConf.CURRENT configuration
    Set<String> current = ExtensionConf.forName(MAJOR).getExtensions(isEeGalleonPack);
    if (!current.equals(availableExtensions)) {
        Set<String> extensionsAdded = diff.apply(current, availableExtensions);
        Set<String> extensionsRemoved = diff.apply(availableExtensions, current);
        fail(String.format("The following extensions %s have been removed on the current release. Remove them on ExtensionConf.CURRENT object defined in this test. " + "The following extensions %s have been added on the current release. Add them to ExtensionConf.CURRENT object defined in this test.", extensionsAdded, extensionsRemoved));
    }
    // not included in this test.
    if (ExtensionConf.CURRENT.isModified()) {
        op = Util.getReadAttributeOperation(null, "product-version");
        result = DomainTestUtils.executeForResult(op, masterClient);
        if (!result.asString().startsWith(ExtensionConf.CURRENT.getName())) {
            fail(String.format("The ExtensionConf.CURRENT has extensions added or removed but it no longer points to the current release. " + "Modify this test adding new ExtensionConf enums for each previous releases undefined in this test by using the list of extensions added or removed on ExtensionConf.CURRENT." + "Then remove all the extensions from ExtensionConf.CURRENT enum and correct the MAJOR number accordingly to point out to the current release."));
        }
    }
    op = Util.getEmptyOperation(READ_CHILDREN_RESOURCES_OPERATION, null);
    op.get(CHILD_TYPE).set(HOST_EXCLUDE);
    result = DomainTestUtils.executeForResult(op, masterClient);
    Set<String> processedExclusionsIds = new HashSet<>();
    for (Property prop : result.asPropertyList()) {
        String name = prop.getName();
        List<String> excludedExtensions = prop.getValue().get(EXCLUDED_EXTENSIONS).asListOrEmpty().stream().map(p -> p.asString()).collect(Collectors.toList());
        // check duplicated extensions
        Assert.assertTrue(String.format("There are duplicated extensions declared for %s host-exclude", name), excludedExtensions.size() == new HashSet<>(excludedExtensions).size());
        // check we have defined the current host-exclude configuration in the test
        ExtensionConf confPrevRelease = ExtensionConf.forName(name);
        Assert.assertNotNull(String.format("This host-exclude name is not defined in this test: %s", name), confPrevRelease);
        // check that available extensions - excluded extensions = expected extensions in a previous release - removed
        Set<String> expectedExtensions = ExtensionConf.forName(name).getExtensions(isEeGalleonPack);
        expectedExtensions.removeAll(ExtensionConf.forName(MAJOR).getRemovedExtensions());
        Set<String> extensionsUnderTest = new HashSet<>(availableExtensions);
        extensionsUnderTest.removeAll(excludedExtensions);
        if (expectedExtensions.size() > extensionsUnderTest.size()) {
            expectedExtensions.removeAll(extensionsUnderTest);
            fail(String.format("These extensions are expected to be available after applying the %s host-exclude configuration to the extensions supplied by this server release: %s", name, expectedExtensions));
        }
        if (extensionsUnderTest.size() != expectedExtensions.size()) {
            extensionsUnderTest.removeAll(expectedExtensions);
            fail(String.format("These extensions are missing on the %s host-exclude: %s", name, extensionsUnderTest));
        }
        processedExclusionsIds.add(name);
    }
    // Verifies all the exclusions Id added as configurations for this test are defined as host exclusions in the current server release
    for (ExtensionConf extensionConf : ExtensionConf.values()) {
        if (extensionConf != ExtensionConf.CURRENT && !processedExclusionsIds.contains(extensionConf.getName())) {
            Set<String> extensions = extensionConf.getExtensions(isEeGalleonPack);
            extensions.removeAll(ExtensionConf.forName(MAJOR).getRemovedExtensions());
            if (!extensions.equals(availableExtensions)) {
                fail(String.format("The %s exclusion id is not defined as host exclusion for the current release.", extensionConf.getName()));
            }
        }
    }
}
Also used : Arrays(java.util.Arrays) BeforeClass(org.junit.BeforeClass) BiFunction(java.util.function.BiFunction) Logger(org.jboss.logging.Logger) HashMap(java.util.HashMap) DomainTestUtils(org.jboss.as.test.integration.domain.management.util.DomainTestUtils) Resource(org.jboss.modules.Resource) ArrayList(java.util.ArrayList) HashSet(java.util.HashSet) HOST_EXCLUDE(org.jboss.as.controller.descriptions.ModelDescriptionConstants.HOST_EXCLUDE) DirectoryStream(java.nio.file.DirectoryStream) ModuleLoadException(org.jboss.modules.ModuleLoadException) Util(org.jboss.as.controller.operations.common.Util) Map(java.util.Map) Property(org.jboss.dmr.Property) DomainLifecycleUtil(org.jboss.as.test.integration.domain.management.util.DomainLifecycleUtil) MgmtOperationException(org.jboss.as.test.integration.management.util.MgmtOperationException) Assert.fail(org.junit.Assert.fail) Path(java.nio.file.Path) CHILD_TYPE(org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILD_TYPE) WildFlyManagedConfiguration(org.jboss.as.test.integration.domain.management.util.WildFlyManagedConfiguration) AfterClass(org.junit.AfterClass) Iterator(java.util.Iterator) Files(java.nio.file.Files) EXCLUDED_EXTENSIONS(org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXCLUDED_EXTENSIONS) Set(java.util.Set) IOException(java.io.IOException) Test(org.junit.Test) LocalModuleLoader(org.jboss.modules.LocalModuleLoader) EXTENSION(org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION) Collectors(java.util.stream.Collectors) File(java.io.File) DomainClient(org.jboss.as.controller.client.helpers.domain.DomainClient) READ_CHILDREN_RESOURCES_OPERATION(org.jboss.as.controller.descriptions.ModelDescriptionConstants.READ_CHILDREN_RESOURCES_OPERATION) List(java.util.List) Module(org.jboss.modules.Module) Paths(java.nio.file.Paths) ModelNode(org.jboss.dmr.ModelNode) Assert(org.junit.Assert) ModelNode(org.jboss.dmr.ModelNode) Property(org.jboss.dmr.Property) HashSet(java.util.HashSet) Test(org.junit.Test)

Aggregations

File (java.io.File)1 IOException (java.io.IOException)1 DirectoryStream (java.nio.file.DirectoryStream)1 Files (java.nio.file.Files)1 Path (java.nio.file.Path)1 Paths (java.nio.file.Paths)1 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 HashMap (java.util.HashMap)1 HashSet (java.util.HashSet)1 Iterator (java.util.Iterator)1 List (java.util.List)1 Map (java.util.Map)1 Set (java.util.Set)1 BiFunction (java.util.function.BiFunction)1 Collectors (java.util.stream.Collectors)1 DomainClient (org.jboss.as.controller.client.helpers.domain.DomainClient)1 CHILD_TYPE (org.jboss.as.controller.descriptions.ModelDescriptionConstants.CHILD_TYPE)1 EXCLUDED_EXTENSIONS (org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXCLUDED_EXTENSIONS)1 EXTENSION (org.jboss.as.controller.descriptions.ModelDescriptionConstants.EXTENSION)1