Skip to content

Commit

Permalink
Fixes #4301 - Cleanup various bits
Browse files Browse the repository at this point in the history
  • Loading branch information
mnriem committed Nov 29, 2024
1 parent 255f2d0 commit d362b92
Show file tree
Hide file tree
Showing 9 changed files with 326 additions and 23 deletions.
72 changes: 54 additions & 18 deletions arquillian/managed/pom.xml
Original file line number Diff line number Diff line change
@@ -1,20 +1,35 @@
<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<project
xmlns="http://maven.apache.org/POM/4.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>cloud.piranha.arquillian</groupId>
<artifactId>project</artifactId>
<version>24.12.0-SNAPSHOT</version>
</parent>

<artifactId>piranha-arquillian-managed</artifactId>
<packaging>jar</packaging>

<name>Piranha - Arquillian - Managed</name>

<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<useModulePath>false</useModulePath>
</configuration>
</plugin>
</plugins>
</build>
<dependencies>
<dependency>
<groupId>me.alexpanov</groupId>
<artifactId>free-port-finder</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
Expand All @@ -26,53 +41,74 @@
</exclusion>
</exclusions>
</dependency>
<dependency>
<groupId>me.alexpanov</groupId>
<artifactId>free-port-finder</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api-base</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
<scope>compile</scope>
<exclusions>
<exclusion>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api-base</artifactId>
</exclusion>
</exclusions>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-cdi-jakarta</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-ejb-jakarta</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-resource-jakarta</artifactId>
<artifactId>arquillian-testenricher-initialcontext</artifactId>
<scope>compile</scope>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-initialcontext</artifactId>
<artifactId>arquillian-testenricher-resource-jakarta</artifactId>
<scope>compile</scope>
</dependency>
<!-- test -->
<dependency>
<groupId>org.jboss.shrinkwrap</groupId>
<artifactId>shrinkwrap-impl-base</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.shrinkwrap.descriptors</groupId>
<artifactId>shrinkwrap-descriptors-api-base</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-engine</artifactId>
<scope>test</scope>
</dependency>
</dependencies>
<distributionManagement>
<site>
Expand Down
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
*/
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);
}
}
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
*/
class ManagedPiranhaContainerExtensionTest {

@Test
void testRegister() {
ExtensionBuilder extensionBuilder = new ExtensionBuilder() {

@Override
public <T> ExtensionBuilder service(Class<T> service, Class<? extends T> impl) {
return this;
}

@Override
public <T> ExtensionBuilder override(Class<T> service, Class<? extends T> oldServiceImpl,
Class<? extends T> newServiceImpl) {
throw new UnsupportedOperationException("Unimplemented method 'override'");
}

@Override
public ExtensionBuilder observer(Class<?> handler) {
throw new UnsupportedOperationException("Unimplemented method 'observer'");
}

@Override
public ExtensionBuilder context(Class<? extends Context> context) {
throw new UnsupportedOperationException("Unimplemented method 'context'");
}
};
ManagedPiranhaContainerExtension extension = new ManagedPiranhaContainerExtension();
extension.register(extensionBuilder);
}
}
Original file line number Diff line number Diff line change
@@ -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 ([email protected])
*/
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());
}
}
6 changes: 6 additions & 0 deletions arquillian/managed/src/test/webapp/test/WEB-INF/web.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="https://jakarta.ee/xml/ns/jakartaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="https://jakarta.ee/xml/ns/jakartaee https://jakarta.ee/xml/ns/jakartaee/web-app_6_0.xsd"
version="6.0">
</web-app>
Loading

0 comments on commit d362b92

Please sign in to comment.