diff --git a/arquillian/managed/pom.xml b/arquillian/managed/pom.xml index 246354f93d..844f225817 100644 --- a/arquillian/managed/pom.xml +++ b/arquillian/managed/pom.xml @@ -1,20 +1,35 @@ - + 4.0.0 - cloud.piranha.arquillian project 24.12.0-SNAPSHOT - piranha-arquillian-managed jar - Piranha - Arquillian - Managed - + + + + org.apache.maven.plugins + maven-surefire-plugin + + false + + + + + + me.alexpanov + free-port-finder + compile + org.jboss.arquillian.container arquillian-container-spi @@ -26,15 +41,10 @@ - - me.alexpanov - free-port-finder - compile - - org.jboss.arquillian.container arquillian-container-test-spi + compile org.jboss.shrinkwrap.descriptors @@ -42,10 +52,10 @@ - org.jboss.arquillian.protocol arquillian-protocol-servlet-jakarta + compile org.jboss.shrinkwrap.descriptors @@ -53,26 +63,52 @@ - org.jboss.arquillian.testenricher arquillian-testenricher-cdi-jakarta + compile - org.jboss.arquillian.testenricher arquillian-testenricher-ejb-jakarta + compile - org.jboss.arquillian.testenricher - arquillian-testenricher-resource-jakarta + arquillian-testenricher-initialcontext + compile - org.jboss.arquillian.testenricher - arquillian-testenricher-initialcontext + arquillian-testenricher-resource-jakarta + compile + + + org.jboss.shrinkwrap + shrinkwrap-impl-base + test + + + org.jboss.shrinkwrap.descriptors + shrinkwrap-descriptors-api-base + test + + + org.junit.jupiter + junit-jupiter-api + test + + + org.junit.jupiter + junit-jupiter-params + test + + + org.junit.jupiter + junit-jupiter-engine + test + diff --git a/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfigurationTest.java b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfigurationTest.java new file mode 100644 index 0000000000..1af331b027 --- /dev/null +++ b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerConfigurationTest.java @@ -0,0 +1,151 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package cloud.piranha.arquillian.managed; + +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * The JUnit tests for the ManagedPiranhaContainerConfiguration class. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +class ManagedPiranhaContainerConfigurationTest { + + @Test + void testGetHttpPortDefault() { + System.clearProperty("piranha.httpPort"); + ManagedPiranhaContainerConfiguration configuration = new ManagedPiranhaContainerConfiguration(); + int port = configuration.getHttpPort(); + assertTrue(port > 0, "The port should be a positive integer"); + System.clearProperty("piranha.httpPort"); + } + + @Test + void testGetHttpPortSet() { + System.setProperty("piranha.httpPort", "8080"); + ManagedPiranhaContainerConfiguration configuration = new ManagedPiranhaContainerConfiguration(); + int port = configuration.getHttpPort(); + assertEquals(8080, port, "The port should be 8080"); + System.clearProperty("piranha.httpPort"); + } + + @Test + void testGetHttpPortInvalid() { + System.setProperty("piranha.httpPort", "invalid"); + assertThrows(NumberFormatException.class, () -> { + ManagedPiranhaContainerConfiguration configuration = new ManagedPiranhaContainerConfiguration(); + configuration.getHttpPort(); + }, "A NumberFormatException should be thrown for invalid port"); + System.clearProperty("piranha.httpPort"); + } + + @Test + void testGetDistribution() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertEquals("coreprofile", config.getDistribution()); + } + + @Test + void testSetDistribution() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setDistribution("webprofile"); + assertEquals("webprofile", config.getDistribution()); + } + + @Test + void testGetHttpPort() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertTrue(config.getHttpPort() > 0); + } + + @Test + void testSetHttpPort() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setHttpPort(8080); + assertEquals(8080, config.getHttpPort()); + } + + @Test + void testGetJvmArguments() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertEquals("", config.getJvmArguments()); + } + + @Test + void testSetJvmArguments() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setJvmArguments("-Xmx512m"); + assertEquals("-Xmx512m", config.getJvmArguments()); + } + + @Test + void testGetProtocol() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertEquals("Servlet 6.0", config.getProtocol()); + } + + @Test + void testSetProtocol() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setProtocol("Servlet 5.0"); + assertEquals("Servlet 5.0", config.getProtocol()); + } + + @Test + void testIsDebug() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertFalse(config.isDebug()); + } + + @Test + void testSetDebug() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setDebug(true); + assertTrue(config.isDebug()); + } + + @Test + void testIsSuspend() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertFalse(config.isSuspend()); + } + + @Test + void testSetSuspend() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + config.setSuspend(true); + assertTrue(config.isSuspend()); + } + + @Test + void testValidate() { + ManagedPiranhaContainerConfiguration config = new ManagedPiranhaContainerConfiguration(); + assertDoesNotThrow(config::validate); + } +} diff --git a/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerExtensionTest.java b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerExtensionTest.java new file mode 100644 index 0000000000..79c085b5d8 --- /dev/null +++ b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerExtensionTest.java @@ -0,0 +1,69 @@ +/* + * Copyright (c) 2002-2024 Manorrock.com. All Rights Reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions are met: + * + * 1. Redistributions of source code must retain the above copyright notice, + * this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. Neither the name of the copyright holder nor the names of its + * contributors may be used to endorse or promote products derived from + * this software without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" + * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE + * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR + * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF + * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS + * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN + * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) + * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE + * POSSIBILITY OF SUCH DAMAGE. + */ +package cloud.piranha.arquillian.managed; + +import org.jboss.arquillian.core.spi.LoadableExtension.ExtensionBuilder; +import org.jboss.arquillian.core.spi.context.Context; +import org.junit.jupiter.api.Test; + +/** + * The JUnit tests for the ManagedPiranhaContainerExtension class. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +class ManagedPiranhaContainerExtensionTest { + + @Test + void testRegister() { + ExtensionBuilder extensionBuilder = new ExtensionBuilder() { + + @Override + public ExtensionBuilder service(Class service, Class impl) { + return this; + } + + @Override + public ExtensionBuilder override(Class service, Class oldServiceImpl, + Class newServiceImpl) { + throw new UnsupportedOperationException("Unimplemented method 'override'"); + } + + @Override + public ExtensionBuilder observer(Class handler) { + throw new UnsupportedOperationException("Unimplemented method 'observer'"); + } + + @Override + public ExtensionBuilder context(Class context) { + throw new UnsupportedOperationException("Unimplemented method 'context'"); + } + }; + ManagedPiranhaContainerExtension extension = new ManagedPiranhaContainerExtension(); + extension.register(extensionBuilder); + } +} diff --git a/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerTest.java b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerTest.java new file mode 100644 index 0000000000..e55300b258 --- /dev/null +++ b/arquillian/managed/src/test/java/cloud/piranha/arquillian/managed/ManagedPiranhaContainerTest.java @@ -0,0 +1,40 @@ +package cloud.piranha.arquillian.managed; + +import java.io.File; +import org.jboss.arquillian.container.spi.client.container.DeploymentException; +import org.jboss.arquillian.container.spi.client.protocol.ProtocolDescription; +import org.jboss.shrinkwrap.api.ShrinkWrap; +import org.jboss.shrinkwrap.api.spec.WebArchive; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Disabled; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.*; + +/** + * The JUnit tests for the ManagedPiranhaContainer class. + * + * @author Manfred Riem (mriem@manorrock.com) + */ +class ManagedPiranhaContainerTest { + + /** + * Test getContainerConfiguration method. + */ + @Test + void testGetConfigurationClass() { + ManagedPiranhaContainer container = new ManagedPiranhaContainer(); + assertEquals(ManagedPiranhaContainerConfiguration.class, container.getConfigurationClass()); + } + + /** + * TEst getDefaulProtocol method. + */ + @Test + void testGetDefaultProtocol() { + ManagedPiranhaContainer container = new ManagedPiranhaContainer(); + container.setup(new ManagedPiranhaContainerConfiguration()); + ProtocolDescription protocolDescription = container.getDefaultProtocol(); + assertEquals("Servlet 6.0", protocolDescription.getName()); + } +} diff --git a/arquillian/managed/src/test/webapp/test/WEB-INF/web.xml b/arquillian/managed/src/test/webapp/test/WEB-INF/web.xml new file mode 100644 index 0000000000..0bf2fcbaf7 --- /dev/null +++ b/arquillian/managed/src/test/webapp/test/WEB-INF/web.xml @@ -0,0 +1,6 @@ + + + \ No newline at end of file diff --git a/extension/bytesstreamhandler/src/main/java/module-info.java b/extension/bytesstreamhandler/src/main/java/module-info.java index 3dca29cd89..ac6b767e46 100644 --- a/extension/bytesstreamhandler/src/main/java/module-info.java +++ b/extension/bytesstreamhandler/src/main/java/module-info.java @@ -35,6 +35,6 @@ exports cloud.piranha.extension.bytesstreamhandler; opens cloud.piranha.extension.bytesstreamhandler; - requires cloud.piranha.core.api; + requires transitive cloud.piranha.core.api; requires cloud.piranha.resource.impl; } diff --git a/extension/coreprofile/src/main/java/module-info.java b/extension/coreprofile/src/main/java/module-info.java index 73296ce7d0..4d5c22efbe 100644 --- a/extension/coreprofile/src/main/java/module-info.java +++ b/extension/coreprofile/src/main/java/module-info.java @@ -47,7 +47,7 @@ exports cloud.piranha.extension.coreprofile; opens cloud.piranha.extension.coreprofile; - requires cloud.piranha.core.api; + requires transitive cloud.piranha.core.api; requires cloud.piranha.extension.annotationscan; requires cloud.piranha.extension.annotationscan.classfile; requires cloud.piranha.extension.herring; diff --git a/extension/default-datasource/src/main/java/module-info.java b/extension/default-datasource/src/main/java/module-info.java index d6ddce9cf9..31d1f9d2c7 100644 --- a/extension/default-datasource/src/main/java/module-info.java +++ b/extension/default-datasource/src/main/java/module-info.java @@ -41,8 +41,8 @@ exports cloud.piranha.extension.datasource; opens cloud.piranha.extension.datasource; - requires cloud.piranha.core.api; - requires java.sql; + requires transitive cloud.piranha.core.api; + requires transitive java.sql; requires java.naming; requires jakarta.cdi; requires jakarta.transaction;