diff --git a/subsystem/pom.xml b/subsystem/pom.xml index a70efc4..6b19612 100644 --- a/subsystem/pom.xml +++ b/subsystem/pom.xml @@ -40,6 +40,11 @@ wildfly-server provided + + org.wildfly.core + wildfly-subsystem + provided + org.wildfly wildfly-ee diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptions.java b/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptions.java index 97f9482..2289bf3 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptions.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/NamedVertxOptions.java @@ -11,6 +11,8 @@ */ public class NamedVertxOptions { + public static final NamedVertxOptions DEFAULT = new NamedVertxOptions("", new VertxOptions()); + /** The name of the configured VertxOptions **/ private final String name; diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxProxyService.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxProxyService.java index 826f0fe..67a76d4 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxProxyService.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxProxyService.java @@ -16,7 +16,6 @@ import org.jboss.msc.service.StopContext; import org.wildfly.extension.vertx.logging.VertxLogger; -import java.util.Objects; import java.util.concurrent.CompletableFuture; import java.util.function.Consumer; import java.util.function.Supplier; @@ -36,10 +35,14 @@ public class VertxProxyService implements Service, VertxConstants { final Consumer vertxProxytConsumer; static void installService(OperationContext context, String optionName) { - Objects.requireNonNull(optionName, "optionName cannot be null."); CapabilityServiceBuilder vertxServiceBuilder = context.getCapabilityServiceTarget().addService(); Consumer vertxProxytConsumer = vertxServiceBuilder.provides(VERTX_RUNTIME_CAPABILITY); - Supplier optionsSupplier = vertxServiceBuilder.requiresCapability(VERTX_OPTIONS_CAPABILITY.getName(), NamedVertxOptions.class, optionName); + final Supplier optionsSupplier; + if (optionName == null) { + optionsSupplier = () -> NamedVertxOptions.DEFAULT; + } else { + optionsSupplier = vertxServiceBuilder.requiresCapability(VERTX_OPTIONS_CAPABILITY.getName(), NamedVertxOptions.class, optionName); + } VertxProxyService vertxProxyService = new VertxProxyService(optionName, optionsSupplier, vertxProxytConsumer); vertxServiceBuilder.setInstance(vertxProxyService); vertxServiceBuilder.setInitialMode(ServiceController.Mode.ACTIVE); diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxResourceDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxResourceDefinition.java index 9b7463f..8399810 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxResourceDefinition.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxResourceDefinition.java @@ -52,10 +52,8 @@ static class VertxResourceAdd extends AbstractAddStepHandler { @Override protected void performRuntime(OperationContext context, ModelNode operation, Resource resource) throws OperationFailedException { - String optionName = operation.hasDefined(ATTR_OPTION_NAME) ? VertxAttributes.OPTION_NAME.resolveModelAttribute(context, operation).asString() : null; - if (optionName != null) { - VertxProxyService.installService(context, optionName); - } + final String optionName = operation.hasDefined(ATTR_OPTION_NAME) ? VertxAttributes.OPTION_NAME.resolveModelAttribute(context, operation).asString() : null; + VertxProxyService.installService(context, optionName); } } diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java index 4433b96..2408d78 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemDefinition.java @@ -25,9 +25,11 @@ */ public class VertxSubsystemDefinition extends SimpleResourceDefinition { + static final VertxSubsystemDefinition INSTANCE = new VertxSubsystemDefinition(); + VertxSubsystemDefinition() { super(new SimpleResourceDefinition.Parameters(VertxSubsystemExtension.SUBSYSTEM_PATH, - VertxSubsystemExtension.getResourceDescriptionResolver(VertxSubsystemExtension.SUBSYSTEM_NAME)) + VertxSubsystemRegistrar.RESOLVER) .setAddHandler(new VertxSubsystemAdd()) .setRemoveHandler(ReloadRequiredRemoveStepHandler.INSTANCE) ); diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemExtension.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemExtension.java index 5d450b4..489858f 100644 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemExtension.java +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemExtension.java @@ -5,31 +5,24 @@ package org.wildfly.extension.vertx; -import org.jboss.as.controller.Extension; -import org.jboss.as.controller.ExtensionContext; import org.jboss.as.controller.ModelVersion; import org.jboss.as.controller.PathElement; -import org.jboss.as.controller.SubsystemRegistration; +import org.jboss.as.controller.SubsystemModel; import org.jboss.as.controller.descriptions.StandardResourceDescriptionResolver; -import org.jboss.as.controller.operations.common.GenericSubsystemDescribeHandler; -import org.jboss.as.controller.parsing.ExtensionParsingContext; -import org.jboss.as.controller.registry.ManagementResourceRegistration; import org.jboss.as.version.Stability; +import org.wildfly.subsystem.SubsystemConfiguration; +import org.wildfly.subsystem.SubsystemExtension; +import org.wildfly.subsystem.SubsystemPersistence; import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; import static org.wildfly.extension.vertx.VertxConstants.EXTENSION_STABILITY; -import static org.wildfly.extension.vertx.logging.VertxLogger.VERTX_LOGGER; /** * @author Lin Gao */ -public class VertxSubsystemExtension implements Extension { - public static final String EXTENSION_NAME = "org.wildfly.extension.vertx"; +public class VertxSubsystemExtension extends SubsystemExtension { public static final String SUBSYSTEM_NAME = "vertx"; - protected static final ModelVersion VERSION_1_0_0 = ModelVersion.create(1, 0, 0); - private static final ModelVersion CURRENT_MODEL_VERSION = VERSION_1_0_0; - protected static final PathElement SUBSYSTEM_PATH = PathElement.pathElement(SUBSYSTEM, SUBSYSTEM_NAME); private static final String RESOURCE_NAME = VertxSubsystemExtension.class.getPackage().getName() + ".LocalDescriptions"; @@ -44,23 +37,34 @@ static StandardResourceDescriptionResolver getResourceDescriptionResolver(final return new StandardResourceDescriptionResolver(prefix.toString(), RESOURCE_NAME, VertxSubsystemExtension.class.getClassLoader(), true, false); } + public VertxSubsystemExtension() { + super(SubsystemConfiguration.of(SUBSYSTEM_NAME, VertxSubsystemModel.CURRENT, VertxSubsystemRegistrar::new), + SubsystemPersistence.of(VertxSubsystemSchema.CURRENT)); + } + @Override public Stability getStability() { return EXTENSION_STABILITY; } - @Override - public void initialize(ExtensionContext context) { - VERTX_LOGGER.debug("Activating WildFly Vertx Extension."); - final SubsystemRegistration subsystem = context.registerSubsystem(SUBSYSTEM_NAME, CURRENT_MODEL_VERSION); - final ManagementResourceRegistration registration = subsystem.registerSubsystemModel(new VertxSubsystemDefinition()); - registration.registerOperationHandler(GenericSubsystemDescribeHandler.DEFINITION, GenericSubsystemDescribeHandler.INSTANCE); - subsystem.registerXMLElementWriter(VertxSubsystemParser_1_0::new); - } + /** + * Model for the vertx subsystem. + */ + enum VertxSubsystemModel implements SubsystemModel { + VERSION_1_0_0(1, 0, 0), + ; - @Override - public void initializeParsers(ExtensionParsingContext context) { - context.setSubsystemXmlMapping(SUBSYSTEM_NAME, VertxSubsystemParser_1_0.NAMESPACE, VertxSubsystemParser_1_0::new); + static final VertxSubsystemModel CURRENT = VERSION_1_0_0; + private final ModelVersion version; + + VertxSubsystemModel(int major, int minor, int micro) { + this.version = ModelVersion.create(major, minor, micro); + } + + @Override + public ModelVersion getVersion() { + return version; + } } } diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemParser_1_0.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemParser_1_0.java deleted file mode 100644 index a0ef871..0000000 --- a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemParser_1_0.java +++ /dev/null @@ -1,57 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ - -package org.wildfly.extension.vertx; - -import org.jboss.as.controller.AttributeDefinition; -import org.jboss.as.controller.PersistentResourceXMLDescription; -import org.jboss.as.controller.PersistentResourceXMLParser; - -import static org.jboss.as.controller.PersistentResourceXMLDescription.builder; -import static org.jboss.as.controller.PersistentResourceXMLDescription.decorator; -import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTIONS; - -/** - * Parser used to parse the Vertx Subsystem. - * - * @author Lin Gao - */ -public class VertxSubsystemParser_1_0 extends PersistentResourceXMLParser { - /** - * The name space used for the {@code subsystem} element - */ - static final String NAMESPACE = "urn:wildfly:vertx:1.0"; - - private static final PersistentResourceXMLDescription xmlDescription; - static { - xmlDescription = builder(VertxSubsystemExtension.SUBSYSTEM_PATH, NAMESPACE) - .addChild( - builder(VertxResourceDefinition.INSTANCE.getPathElement()) - .addAttributes(VertxAttributes.getSimpleAttributes().toArray(new AttributeDefinition[0])) - ) - .addChild( - decorator(ELEMENT_VERTX_OPTIONS) - .addChild( - builder(VertxOptionFileResourceDefinition.INSTANCE.getPathElement()) - .addAttributes(VertxOptionsAttributes.getVertxOptionsFileAttributes().toArray(new AttributeDefinition[0])) - ) - .addChild( - builder(VertxOptionsResourceDefinition.INSTANCE.getPathElement()) - .addAttributes(VertxOptionsAttributes.getVertxOptionsAttributes().toArray(new AttributeDefinition[0])) - ) - .addChild( - builder(AddressResolverResourceDefinition.INSTANCE.getPathElement()) - .addAttributes(AddressResolverResourceDefinition.getVertxAddressResolverOptionsAttrs().toArray(new AttributeDefinition[0])) - ) - ) - .build(); - } - - @Override - public PersistentResourceXMLDescription getParserDescription() { - return xmlDescription; - } - -} diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemRegistrar.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemRegistrar.java new file mode 100644 index 0000000..6966b8e --- /dev/null +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemRegistrar.java @@ -0,0 +1,28 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.extension.vertx; + +import org.jboss.as.controller.SubsystemRegistration; +import org.jboss.as.controller.descriptions.ParentResourceDescriptionResolver; +import org.jboss.as.controller.descriptions.SubsystemResourceDescriptionResolver; +import org.jboss.as.controller.registry.ManagementResourceRegistration; +import org.wildfly.subsystem.resource.ManagementResourceRegistrationContext; +import org.wildfly.subsystem.resource.SubsystemResourceDefinitionRegistrar; + +import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME; + +/** + * @author Lin Gao + */ +public class VertxSubsystemRegistrar implements SubsystemResourceDefinitionRegistrar { + static final ParentResourceDescriptionResolver RESOLVER = new SubsystemResourceDescriptionResolver(SUBSYSTEM_NAME, + VertxSubsystemRegistrar.class); + + @Override + public ManagementResourceRegistration register(SubsystemRegistration parent, + ManagementResourceRegistrationContext managementResourceRegistrationContext) { + return parent.registerSubsystemModel(VertxSubsystemDefinition.INSTANCE); + } +} diff --git a/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java new file mode 100644 index 0000000..b84c8b8 --- /dev/null +++ b/subsystem/src/main/java/org/wildfly/extension/vertx/VertxSubsystemSchema.java @@ -0,0 +1,66 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.extension.vertx; + +import org.jboss.as.controller.AttributeDefinition; +import org.jboss.as.controller.PersistentResourceXMLDescription; +import org.jboss.as.controller.PersistentSubsystemSchema; +import org.jboss.as.controller.SubsystemSchema; +import org.jboss.as.controller.xml.VersionedNamespace; +import org.jboss.as.version.Stability; +import org.jboss.staxmapper.IntVersion; + +import static org.jboss.as.controller.PersistentResourceXMLDescription.builder; +import static org.jboss.as.controller.PersistentResourceXMLDescription.decorator; +import static org.wildfly.extension.vertx.VertxConstants.ELEMENT_VERTX_OPTIONS; +import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME; +import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_PATH; + +/** + * @author Lin Gao + */ +enum VertxSubsystemSchema implements PersistentSubsystemSchema { + VERSION_1_0_PREVIEW(1, 0,Stability.PREVIEW), + ; + + static final VertxSubsystemSchema CURRENT = VERSION_1_0_PREVIEW; + + private final VersionedNamespace namespace; + + VertxSubsystemSchema(int major, int minor, Stability stability) { + this.namespace = SubsystemSchema.createSubsystemURN(SUBSYSTEM_NAME, stability, + new IntVersion(major, minor)); + } + + @Override + public VersionedNamespace getNamespace() { + return namespace; + } + + @Override + public PersistentResourceXMLDescription getXMLDescription() { + return builder(SUBSYSTEM_PATH, namespace) + .addChild( + builder(VertxResourceDefinition.INSTANCE.getPathElement()) + .addAttributes(VertxAttributes.getSimpleAttributes().toArray(new AttributeDefinition[0])) + ) + .addChild( + decorator(ELEMENT_VERTX_OPTIONS) + .addChild( + builder(VertxOptionFileResourceDefinition.INSTANCE.getPathElement()) + .addAttributes(VertxOptionsAttributes.getVertxOptionsFileAttributes().toArray(new AttributeDefinition[0])) + ) + .addChild( + builder(VertxOptionsResourceDefinition.INSTANCE.getPathElement()) + .addAttributes(VertxOptionsAttributes.getVertxOptionsAttributes().toArray(new AttributeDefinition[0])) + ) + .addChild( + builder(AddressResolverResourceDefinition.INSTANCE.getPathElement()) + .addAttributes(AddressResolverResourceDefinition.getVertxAddressResolverOptionsAttrs().toArray(new AttributeDefinition[0])) + ) + ) + .build(); + } +} diff --git a/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd b/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd index e5d248f..a4f9fa4 100644 --- a/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd +++ b/subsystem/src/main/resources/schema/wildfly-vertx_1_0_0.xsd @@ -3,8 +3,8 @@ ~ SPDX-License-Identifier: Apache-2.0 --> diff --git a/subsystem/src/test/java/org/wildfly/extension/vertx/SubsystemTestCase.java b/subsystem/src/test/java/org/wildfly/extension/vertx/SubsystemTestCase.java new file mode 100644 index 0000000..4a7fc85 --- /dev/null +++ b/subsystem/src/test/java/org/wildfly/extension/vertx/SubsystemTestCase.java @@ -0,0 +1,53 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.extension.vertx; + +import org.jboss.as.controller.capability.registry.RuntimeCapabilityRegistry; +import org.jboss.as.controller.extension.ExtensionRegistry; +import org.jboss.as.controller.registry.ManagementResourceRegistration; +import org.jboss.as.controller.registry.Resource; +import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; +import org.jboss.as.subsystem.test.AdditionalInitialization; +import org.jboss.as.version.Stability; + +import java.io.IOException; + +import static org.wildfly.extension.vertx.VertxSubsystemExtension.SUBSYSTEM_NAME; + +/** + * Standard subsystem test. + * + * @author Lin Gao + */ +public class SubsystemTestCase extends AbstractSubsystemBaseTest { + + public SubsystemTestCase() { + super(SUBSYSTEM_NAME, new VertxSubsystemExtension(), Stability.PREVIEW); + } + + @Override + protected String getSubsystemXml() throws IOException { + // test configuration put in standalone.xml + return readResource("vertx-options-full.xml"); + } + + @Override + protected String getSubsystemXsdPath() { + return "schema/wildfly-vertx_1_0_0.xsd"; + } + + protected AdditionalInitialization createAdditionalInitialization() { + return new AdditionalInitialization.ManagementAdditionalInitialization(Stability.PREVIEW) { + + @Override + protected void initializeExtraSubystemsAndModel(ExtensionRegistry extensionRegistry, Resource rootResource, + ManagementResourceRegistration rootRegistration, RuntimeCapabilityRegistry capabilityRegistry) { + super.initializeExtraSubystemsAndModel(extensionRegistry, rootResource, rootRegistration, capabilityRegistry); + registerCapabilities(capabilityRegistry, "org.wildfly.weld"); + } + }; + } + +} diff --git a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemBaseParsingTestCase.java b/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemBaseParsingTestCase.java deleted file mode 100644 index 9fa0aa2..0000000 --- a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemBaseParsingTestCase.java +++ /dev/null @@ -1,49 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.extension.vertx; - -import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; -import org.junit.Test; - -import java.io.IOException; - -/** - * This is the bare-bones test example that tests subsystem - * It does same things that {@link VertxSubsystemParsingTestCase} does but most of internals are already done in AbstractSubsystemBaseTest - * If you need more control over what happens in tests look at {@link VertxSubsystemParsingTestCase} - * - * @author Lin Gao - */ -public class VertxSubsystemBaseParsingTestCase extends AbstractSubsystemBaseTest { - - public VertxSubsystemBaseParsingTestCase() { - super(VertxSubsystemExtension.SUBSYSTEM_NAME, new VertxSubsystemExtension()); - } - - @Override - protected String getSubsystemXsdPath() throws Exception { - return "schema/wildfly-vertx_1_0_0.xsd"; - } - - @Override - protected String[] getSubsystemTemplatePaths() throws IOException { - return new String[]{ - "/subsystem-templates/vertx.xml" - }; - } - - @Override - protected String getSubsystemXml() throws IOException { - return "" + - ""; - } - - @Test - @Override - public void testSubsystem() throws Exception { - standardSubsystemTest(null, false); - } - -} diff --git a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemOptionsTestCase.java b/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemOptionsTestCase.java deleted file mode 100644 index 1759cdf..0000000 --- a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemOptionsTestCase.java +++ /dev/null @@ -1,37 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.extension.vertx; - -import java.io.IOException; - -import org.jboss.as.subsystem.test.AbstractSubsystemBaseTest; -import org.junit.Test; - -/** - * @author Lin Gao - */ -public class VertxSubsystemOptionsTestCase extends AbstractSubsystemBaseTest { - - public VertxSubsystemOptionsTestCase() { - super(VertxSubsystemExtension.SUBSYSTEM_NAME, new VertxSubsystemExtension()); - } - - @Override - protected String getSubsystemXml() throws IOException { - return readResource("vertx-options-full.xml"); - } - - @Override - protected String getSubsystemXsdPath() throws Exception { - return "schema/wildfly-vertx_1_0_0.xsd"; - } - - @Test - @Override - public void testSubsystem() throws Exception { - standardSubsystemTest(null, false); - } - -} diff --git a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemParsingTestCase.java b/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemParsingTestCase.java deleted file mode 100644 index 7cc3316..0000000 --- a/subsystem/src/test/java/org/wildfly/extension/vertx/VertxSubsystemParsingTestCase.java +++ /dev/null @@ -1,115 +0,0 @@ -/* - * Copyright The WildFly Authors - * SPDX-License-Identifier: Apache-2.0 - */ -package org.wildfly.extension.vertx; - -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.ADD; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.OP_ADDR; -import static org.jboss.as.controller.descriptions.ModelDescriptionConstants.SUBSYSTEM; - -import java.util.List; - -import org.jboss.as.controller.PathAddress; -import org.jboss.as.controller.PathElement; -import org.jboss.as.subsystem.test.AbstractSubsystemTest; -import org.jboss.as.subsystem.test.KernelServices; -import org.jboss.dmr.ModelNode; -import org.junit.Assert; -import org.junit.Test; - - -/** - * Tests all management expects for subsystem, parsing, marshaling, model definition and other - * Here is an example that allows you a fine grained controler over what is tested and how. So it can give you ideas what can be done and tested. - * If you have no need for advanced testing of subsystem you look at {@link VertxSubsystemBaseParsingTestCase} that testes same stuff but most of the code - * is hidden inside of test harness - * - * @author Lin Gao - */ -public class VertxSubsystemParsingTestCase extends AbstractSubsystemTest { - - public VertxSubsystemParsingTestCase() { - super(VertxSubsystemExtension.SUBSYSTEM_NAME, new VertxSubsystemExtension()); - } - - /** - * Tests that the xml is parsed into the correct operations - */ - @Test - public void testParseSubsystem() throws Exception { - //Parse the subsystem xml into operations - String subsystemXml = - "" + - ""; - List operations = super.parse(subsystemXml); - - ///Check that we have the expected number of operations - Assert.assertEquals(1, operations.size()); - - //Check that each operation has the correct content - ModelNode addSubsystem = operations.get(0); - Assert.assertEquals(ADD, addSubsystem.get(OP).asString()); - PathAddress addr = PathAddress.pathAddress(addSubsystem.get(OP_ADDR)); - Assert.assertEquals(1, addr.size()); - PathElement element = addr.getElement(0); - Assert.assertEquals(SUBSYSTEM, element.getKey()); - Assert.assertEquals(VertxSubsystemExtension.SUBSYSTEM_NAME, element.getValue()); - } - - /** - * Test that the model created from the xml looks as expected - */ - @Test - public void testInstallIntoController() throws Exception { - //Parse the subsystem xml and install into the controller - String subsystemXml = - "" + - ""; - KernelServices services = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build(); - - //Read the whole model and make sure it looks as expected - ModelNode model = services.readWholeModel(); - Assert.assertTrue(model.get(SUBSYSTEM).hasDefined(VertxSubsystemExtension.SUBSYSTEM_NAME)); - } - - /** - * Starts a controller with a given subsystem xml and then checks that a second - * controller started with the xml marshalled from the first one results in the same model - */ - @Test - public void testParseAndMarshalModel() throws Exception { - //Parse the subsystem xml and install into the first controller - String subsystemXml = - "" + - ""; - KernelServices servicesA = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build(); - //Get the model and the persisted xml from the first controller - ModelNode modelA = servicesA.readWholeModel(); - String marshalled = servicesA.getPersistedSubsystemXml(); - - //Install the persisted xml from the first controller into a second controller - KernelServices servicesB = super.createKernelServicesBuilder(null).setSubsystemXml(marshalled).build(); - ModelNode modelB = servicesB.readWholeModel(); - - //Make sure the models from the two controllers are identical - super.compare(modelA, modelB); - } - - /** - * Tests that the subsystem can be removed - */ - @Test - public void testSubsystemRemoval() throws Exception { - //Parse the subsystem xml and install into the first controller - String subsystemXml = - "" + - ""; - KernelServices services = super.createKernelServicesBuilder(null).setSubsystemXml(subsystemXml).build(); - //Checks that the subsystem was removed from the model - super.assertRemoveSubsystemResources(services); - - //TODO Chek that any services that were installed were removed here - } -} diff --git a/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml b/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml index 24a75bd..b5f0de2 100644 --- a/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml +++ b/subsystem/src/test/resources/org/wildfly/extension/vertx/vertx-options-full.xml @@ -3,7 +3,7 @@ ~ SPDX-License-Identifier: Apache-2.0 --> - + diff --git a/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/VertxInjectionTestCase.java b/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/VertxInjectionTestCase.java new file mode 100644 index 0000000..4a65795 --- /dev/null +++ b/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/VertxInjectionTestCase.java @@ -0,0 +1,56 @@ +/* + * Copyright The WildFly Authors + * SPDX-License-Identifier: Apache-2.0 + */ +package org.wildfly.extension.vertx.test.basic; + +import org.jboss.arquillian.container.test.api.Deployment; +import org.jboss.arquillian.container.test.api.RunAsClient; +import org.jboss.arquillian.junit.Arquillian; +import org.jboss.arquillian.test.api.ArquillianResource; +import org.jboss.as.arquillian.api.ContainerResource; +import org.jboss.as.arquillian.container.ManagementClient; +import org.jboss.as.test.integration.common.HttpRequest; +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.Ignore; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.wildfly.extension.vertx.test.shared.ejb.EchoService; +import org.wildfly.extension.vertx.test.shared.rest.RestApp; +import org.wildfly.extension.vertx.test.shared.rest.ServiceEndpoint; + +import java.net.URL; +import java.util.concurrent.TimeUnit; + +/** + * Test injection in servlet, ejb, REST resource endpoints. + * + * @author Lin Gao + */ +@RunWith(Arquillian.class) +@RunAsClient +@Ignore("io.netty.netty-transport needs to be added as dependency to module: io.smallrye.reactive.mutiny.vertx-core") +public class VertxInjectionTestCase { + @ArquillianResource + private URL url; + + @ContainerResource + private ManagementClient managementClient; + + @Deployment + public static WebArchive createDeployment() { + final WebArchive war = ShrinkWrap.create(WebArchive.class, "test-injection.war"); + war.addClasses(EchoService.class, RestApp.class, ServiceEndpoint.class); + war.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml"); + return war; + } + + @Test + public void testInjection() throws Exception { + String res = HttpRequest.get(url.toExternalForm() + "rest/echo/Hello", 4, TimeUnit.SECONDS); + Assert.assertEquals("Hello", res); + } +} diff --git a/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/management/VertxOptionsManagementTestCase.java b/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/management/VertxOptionsManagementTestCase.java index 57e0c80..b3463ce 100644 --- a/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/management/VertxOptionsManagementTestCase.java +++ b/testsuite/integration/basic/src/test/java/org/wildfly/extension/vertx/test/basic/management/VertxOptionsManagementTestCase.java @@ -29,7 +29,7 @@ import static org.wildfly.extension.vertx.test.shared.ManagementClientUtils.vertxOptionOperation; /** - * Test vertx eventbus message in async ejb on basic set up. + * Test vertx subsystem management operations. * * @author Lin Gao */ diff --git a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/ejb/EchoService.java b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/ejb/EchoService.java index 79f9d99..38fb8bc 100644 --- a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/ejb/EchoService.java +++ b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/ejb/EchoService.java @@ -7,16 +7,23 @@ import java.util.concurrent.CompletableFuture; import java.util.concurrent.Future; +import io.smallrye.common.annotation.Identifier; import io.vertx.core.Vertx; import io.vertx.core.eventbus.MessageConsumer; import jakarta.annotation.PostConstruct; import jakarta.annotation.PreDestroy; import jakarta.ejb.Asynchronous; import jakarta.ejb.Stateless; +import jakarta.enterprise.inject.Any; import jakarta.inject.Inject; +import static org.wildfly.extension.vertx.VertxConstants.CDI_QUALIFIER; + @Stateless public class EchoService { + + @Any + @Identifier(CDI_QUALIFIER) @Inject private Vertx vertx; diff --git a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AbstractVertxServlet.java b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AbstractVertxServlet.java index 0345964..6db64c2 100644 --- a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AbstractVertxServlet.java +++ b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AbstractVertxServlet.java @@ -6,7 +6,9 @@ import java.io.IOException; +import io.smallrye.common.annotation.Identifier; import io.vertx.core.Vertx; +import jakarta.enterprise.inject.Any; import jakarta.inject.Inject; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; @@ -14,6 +16,8 @@ import jakarta.servlet.http.HttpServletRequest; import jakarta.servlet.http.HttpServletResponse; +import static org.wildfly.extension.vertx.VertxConstants.CDI_QUALIFIER; + /** * An abstract servlet class which communicates with a Vert.x eventbus address. * @@ -21,6 +25,8 @@ */ public abstract class AbstractVertxServlet extends HttpServlet { + @Any + @Identifier(CDI_QUALIFIER) @Inject private Vertx vertx; diff --git a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AsyncServlet.java b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AsyncServlet.java index d7a09a3..598d083 100644 --- a/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AsyncServlet.java +++ b/testsuite/shared/src/main/java/org/wildfly/extension/vertx/test/shared/servlet/AsyncServlet.java @@ -4,9 +4,11 @@ */ package org.wildfly.extension.vertx.test.shared.servlet; +import io.smallrye.common.annotation.Identifier; import io.vertx.core.Vertx; import io.vertx.core.eventbus.MessageConsumer; +import jakarta.enterprise.inject.Any; import jakarta.inject.Inject; import jakarta.servlet.AsyncContext; import jakarta.servlet.ServletException; @@ -17,6 +19,8 @@ import java.io.IOException; import java.io.PrintWriter; +import static org.wildfly.extension.vertx.VertxConstants.CDI_QUALIFIER; + /** * AsyncServlet which requests a response from `echo` Vert.x EventBus address. * @@ -25,6 +29,8 @@ @WebServlet(value = "/async", asyncSupported = true) public class AsyncServlet extends HttpServlet { + @Any + @Identifier(CDI_QUALIFIER) @Inject private Vertx vertx;