Skip to content

Commit

Permalink
WFLY-19573 Adding automated test.
Browse files Browse the repository at this point in the history
Move the test module setup into ServerSetupTask.
Add mgmt ops to add/remove the test extension and subsystem.
Add necessary dependencies to the test.build-compatible-extension module.
Fixes for test execution in bootable jar.
  • Loading branch information
bstansberry authored and manovotn committed Sep 5, 2024
1 parent 4c73b51 commit 111d2e4
Show file tree
Hide file tree
Showing 8 changed files with 388 additions and 0 deletions.
41 changes: 41 additions & 0 deletions testsuite/integration/basic/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -606,6 +606,11 @@
<artifactId>wildfly-naming-client</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly</groupId>
<artifactId>wildfly-weld-common</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-cli</artifactId>
Expand Down Expand Up @@ -782,6 +787,11 @@
<artifactId>wildfly-core-management-subsystem</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.core</groupId>
<artifactId>wildfly-subsystem</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.wildfly.discovery</groupId>
<artifactId>wildfly-discovery-client</artifactId>
Expand Down Expand Up @@ -816,6 +826,11 @@
<artifactId>jakarta.servlet.jsp-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.kohsuke.metainf-services</groupId>
<artifactId>metainf-services</artifactId>
<scope>test</scope>
</dependency>
</dependencies>

<build>
Expand Down Expand Up @@ -921,6 +936,32 @@
<finalName>weldTest</finalName>
<classifier>bootableJar</classifier>
</configuration>
</execution><execution>
<id>create-module-cdidBcExtensionModule</id>
<goals>
<goal>jar</goal>
</goals>
<phase>${bootable-jar-maven-jar-plugin.create.modules.phase}</phase>
<configuration>
<outputDirectory>${project.build.directory}/extraContent/modules/test/build-compatible-extension/main</outputDirectory>
<classesDirectory>${project.build.testOutputDirectory}</classesDirectory>
<includes>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCEDeploymentUnitProcessor.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemModel.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar$1.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemRegistrar$1$1.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/BCEExtension$BCESubsystemSchema.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredExtension.class</include>
<include>**/org/jboss/as/test/integration/weld/extensions/buildcompatible/subsystem/RegisteredBean.class</include>
<include>**/META-INF/services/jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension</include>
<include>**/META-INF/services/org.jboss.as.controller.Extension</include>
<include>**/META-INF/beans.xml</include>
</includes>
<finalName>bce-extension</finalName>
<classifier>bootableJar</classifier>
</configuration>
</execution>
<execution>
<id>create-module-test-alpha</id>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,169 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;

import org.jboss.as.controller.Extension;
import org.jboss.as.controller.ModelVersion;
import org.jboss.as.controller.OperationContext;
import org.jboss.as.controller.OperationFailedException;
import org.jboss.as.controller.PathElement;
import org.jboss.as.controller.PersistentResourceXMLDescription;
import org.jboss.as.controller.PersistentSubsystemSchema;
import org.jboss.as.controller.ResourceDefinition;
import org.jboss.as.controller.ResourceRegistration;
import org.jboss.as.controller.SubsystemModel;
import org.jboss.as.controller.SubsystemRegistration;
import org.jboss.as.controller.SubsystemSchema;
import org.jboss.as.controller.capability.CapabilityServiceSupport;
import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver;
import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver;
import org.jboss.as.controller.registry.ManagementResourceRegistration;
import org.jboss.as.controller.registry.OperationEntry;
import org.jboss.as.controller.xml.VersionedNamespace;
import org.jboss.as.server.AbstractDeploymentChainStep;
import org.jboss.as.server.DeploymentProcessorTarget;
import org.jboss.as.server.deployment.Attachments;
import org.jboss.as.server.deployment.DeploymentPhaseContext;
import org.jboss.as.server.deployment.DeploymentUnit;
import org.jboss.as.server.deployment.DeploymentUnitProcessingException;
import org.jboss.as.server.deployment.DeploymentUnitProcessor;
import org.jboss.as.server.deployment.Phase;
import org.jboss.as.version.Stability;
import org.jboss.as.weld.Capabilities;
import org.jboss.as.weld.WeldCapability;
import org.jboss.dmr.ModelNode;
import org.jboss.staxmapper.IntVersion;
import org.kohsuke.MetaInfServices;
import org.wildfly.subsystem.SubsystemConfiguration;
import org.wildfly.subsystem.SubsystemExtension;
import org.wildfly.subsystem.SubsystemPersistence;
import org.wildfly.subsystem.resource.ManagementResourceRegistrar;
import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext;
import org.wildfly.subsystem.resource.ResourceDescriptor;
import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar;
import org.wildfly.subsystem.resource.operation.ResourceOperationRuntimeHandler;

@MetaInfServices(Extension.class)
public class BCEExtension extends SubsystemExtension<BCEExtension.BCESubsystemSchema> {

public BCEExtension() {
super(SubsystemConfiguration.of(BCESubsystemRegistrar.NAME, BCESubsystemModel.CURRENT,
BCESubsystemRegistrar::new), SubsystemPersistence.of(BCESubsystemSchema.CURRENT));
}

/**
* Model for the 'bce' subsystem.
*/
public enum BCESubsystemModel implements SubsystemModel {
VERSION_1_0_0(1, 0, 0),
;

static final BCESubsystemModel CURRENT = VERSION_1_0_0;

private final ModelVersion version;

BCESubsystemModel(int major, int minor, int micro) {
this.version = ModelVersion.create(major, minor, micro);
}

@Override
public ModelVersion getVersion() {
return this.version;
}
}

/**
* Schema for the 'bce' subsystem.
*/
public enum BCESubsystemSchema implements PersistentSubsystemSchema<BCESubsystemSchema> {

VERSION_1_0(1, 0, Stability.DEFAULT),
;

static final BCESubsystemSchema CURRENT = VERSION_1_0;

private final VersionedNamespace<IntVersion, BCESubsystemSchema> namespace;

BCESubsystemSchema(int major, int minor, Stability stability) {
this.namespace = SubsystemSchema.createSubsystemURN(BCESubsystemRegistrar.NAME, stability, new IntVersion(major, minor));
}

@Override
public VersionedNamespace<IntVersion, BCESubsystemSchema> getNamespace() {
return this.namespace;
}

@Override
public Stability getStability() {
return Stability.DEFAULT;
}

@Override
public PersistentResourceXMLDescription getXMLDescription() {
PersistentResourceXMLDescription.Factory factory = PersistentResourceXMLDescription.factory(this);
return factory.builder(BCESubsystemRegistrar.PATH).build();
}
}

/**
* Registrar for the 'bce' subsystem root resource.
*/
private static final class BCESubsystemRegistrar implements SubsystemResourceDefinitionRegistrar {

static final String NAME = "bce";
static final PathElement PATH = SubsystemResourceDefinitionRegistrar.pathElement(NAME);
static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(NAME, BCESubsystemRegistrar.class);

@Override
public ManagementResourceRegistration register(SubsystemRegistration parent, ManagementResourceRegistrationContext context) {
ManagementResourceRegistration registration = parent.registerSubsystemModel(ResourceDefinition.builder(ResourceRegistration.of(PATH), RESOLVER).build());
ResourceDescriptor descriptor = ResourceDescriptor.builder(RESOLVER)
.withAddOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES)
.withRemoveOperationRestartFlag(OperationEntry.Flag.RESTART_ALL_SERVICES)
.withRuntimeHandler(new ResourceOperationRuntimeHandler() {
@Override
public void addRuntime(OperationContext context, ModelNode model) {
if (context.isBooting()) {
context.addStep(new AbstractDeploymentChainStep() {
@Override
protected void execute(DeploymentProcessorTarget processorTarget) {
processorTarget.addDeploymentProcessor(NAME, Phase.INSTALL, Phase.INSTALL_WELD_DEPLOYMENT, new BCEDeploymentUnitProcessor());

}
}, OperationContext.Stage.RUNTIME);
} else {
context.reloadRequired();
}
}

@Override
public void removeRuntime(OperationContext context, ModelNode model) throws OperationFailedException {
context.reloadRequired();
}
})
.build();
ManagementResourceRegistrar.of(descriptor).register(registration);
return registration;
}
}

private static final class BCEDeploymentUnitProcessor implements DeploymentUnitProcessor {

@Override
public void deploy(DeploymentPhaseContext phaseContext) throws DeploymentUnitProcessingException {
final DeploymentUnit deploymentUnit = phaseContext.getDeploymentUnit();
try {
final WeldCapability weldCapability = deploymentUnit.getAttachment(Attachments.CAPABILITY_SERVICE_SUPPORT)
.getCapabilityRuntimeAPI(Capabilities.WELD_CAPABILITY_NAME, WeldCapability.class);
weldCapability.registerBuildCompatibleExtension(RegisteredExtension.class, deploymentUnit);
} catch (CapabilityServiceSupport.NoSuchCapabilityException e) {
throw new RuntimeException(e);
}
}
}


}
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;

import jakarta.enterprise.context.Dependent;

@Dependent
public class DummyBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;

// no bean defining annotation, processed via RegisteredExtension
public class RegisteredBean {
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;

import jakarta.enterprise.inject.build.compatible.spi.BuildCompatibleExtension;
import jakarta.enterprise.inject.build.compatible.spi.Discovery;
import jakarta.enterprise.inject.build.compatible.spi.ScannedClasses;

public class RegisteredExtension implements BuildCompatibleExtension {

@Discovery
public void discovery(ScannedClasses sc) {
sc.add(RegisteredBean.class.getName());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
/*
* Copyright The WildFly Authors
* SPDX-License-Identifier: Apache-2.0
*/

package org.jboss.as.test.integration.weld.extensions.buildcompatible.subsystem;

import jakarta.inject.Inject;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.as.arquillian.api.ServerSetup;
import org.jboss.as.arquillian.api.ServerSetupTask;
import org.jboss.as.arquillian.container.ManagementClient;
import org.jboss.as.controller.PathAddress;
import org.jboss.as.controller.operations.common.Util;
import org.jboss.as.test.module.util.TestModule;
import org.jboss.as.test.shared.ServerReload;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.WebArchive;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;

import java.io.File;
import java.net.URL;

@RunWith(Arquillian.class)
@ServerSetup(SubsystemBceRegistrationTest.SetupTask.class)
public class SubsystemBceRegistrationTest {

@Deployment
public static WebArchive getDeployment() throws Exception {
return ShrinkWrap.create(WebArchive.class)
.addClasses(SubsystemBceRegistrationTest.class, DummyBean.class, TestModule.class, RegisteredBean.class)
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
}

@Inject
DummyBean dummyBean;

@Inject
RegisteredBean registeredBean;

@Test
public void testBceRegisteredAndExecuted() {
// check plain WAR deployment
Assert.assertNotNull(dummyBean);

// verify BCE was executed; if so, RegisteredBean would now be resolvable
Assert.assertNotNull(registeredBean);
}

public static class SetupTask implements ServerSetupTask {
private static final String MODULE_NAME = "build-compatible-extension";
private static TestModule testModule;

@Override
public void setup(ManagementClient managementClient, String containerId) throws Exception {
URL url = BCEExtension.class.getResource(MODULE_NAME + "-module.xml");
File moduleXmlFile = new File(url.toURI());
testModule = new TestModule("test." + MODULE_NAME, moduleXmlFile);
testModule.addResource("bce-extension.jar")
.addClasses(BCEExtension.class, RegisteredExtension.class, RegisteredBean.class)
.addAsManifestResource(EmptyAsset.INSTANCE, "beans.xml")
.addAsServiceProvider(org.jboss.as.controller.Extension.class, BCEExtension.class);
testModule.create();

managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME)));
managementClient.getControllerClient().execute(Util.createAddOperation(PathAddress.pathAddress("subsystem", "bce")));

ServerReload.executeReloadAndWaitForCompletion(managementClient);
}

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

managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("subsystem", "bce")));
managementClient.getControllerClient().execute(Util.createRemoveOperation(PathAddress.pathAddress("extension", "test." + MODULE_NAME)));

testModule.remove();

ServerReload.executeReloadAndWaitForCompletion(managementClient);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?xml version="1.0" encoding="UTF-8"?>

<!--
~ Copyright The WildFly Authors
~ SPDX-License-Identifier: Apache-2.0
-->

<module xmlns="urn:jboss:module:1.9" name="test.build-compatible-extension">

<resources>
<resource-root path="bce-extension.jar"/>
<!-- Insert resources here -->
</resources>

<dependencies>
<module name="jakarta.enterprise.api"/>
<module name="jakarta.inject.api"/>
<module name="org.jboss.staxmapper"/>
<module name="org.jboss.as.controller"/>
<module name="org.jboss.as.server"/>
<module name="org.jboss.as.weld.common"/>
<module name="org.jboss.as.version"/>
<module name="org.jboss.logging"/>
<module name="org.wildfly.subsystem"/>
</dependencies>
</module>
Loading

0 comments on commit 111d2e4

Please sign in to comment.