Skip to content

Commit

Permalink
Updated project to Java 21, migrated to Jakarta namespace, updated de…
Browse files Browse the repository at this point in the history
…pendencies to latest versions.
  • Loading branch information
divjad--- committed Nov 29, 2023
1 parent e469579 commit 7363b5d
Show file tree
Hide file tree
Showing 26 changed files with 177 additions and 180 deletions.
26 changes: 6 additions & 20 deletions kumuluzee-arquillian-container/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-testing</artifactId>
<groupId>com.kumuluz.ee.testing</groupId>
<version>1.2.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -14,7 +14,6 @@

<artifactId>kumuluzee-arquillian-container</artifactId>


<dependencies>
<dependency>
<groupId>com.kumuluz.ee</groupId>
Expand All @@ -27,25 +26,17 @@
<optional>true</optional>
</dependency>

<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.container</groupId>
<artifactId>arquillian-container-test-spi</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.protocol</groupId>
<artifactId>arquillian-protocol-servlet</artifactId>
<artifactId>arquillian-protocol-servlet-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-cdi</artifactId>
<artifactId>arquillian-testenricher-cdi-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
<artifactId>arquillian-testenricher-resource</artifactId>
<artifactId>arquillian-testenricher-resource-jakarta</artifactId>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.testenricher</groupId>
Expand All @@ -69,13 +60,8 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<groupId>org.jboss.arquillian.junit5</groupId>
<artifactId>arquillian-junit5-container</artifactId>
<scope>test</scope>
</dependency>
<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@

import java.util.HashMap;
import java.util.Map;
import java.util.logging.Level;
import java.util.logging.Logger;

/**
Expand All @@ -45,7 +46,7 @@
*/
public class KumuluzEEContainer implements DeployableContainer<KumuluzEEContainerConfig> {

private final Logger LOG; // initialized in constructor after logging init
private final Logger log; // initialized in constructor after logging init

private static boolean loggingInitialized = false;

Expand All @@ -57,11 +58,11 @@ private static synchronized void initLogging() {
}
}

private Map<Archive, AbstractDeployment> deployments;
private final Map<Archive, AbstractDeployment> deployments;

public KumuluzEEContainer() {
initLogging();
this.LOG = Logger.getLogger(KumuluzEEContainer.class.getName());
this.log = Logger.getLogger(KumuluzEEContainer.class.getName());
this.deployments = new HashMap<>();
}

Expand Down Expand Up @@ -95,7 +96,7 @@ public void stop() {

@Override
public ProtocolDescription getDefaultProtocol() {
return new ProtocolDescription("Servlet 3.0");
return new ProtocolDescription("Servlet 5.0");
}

@Override
Expand All @@ -122,7 +123,7 @@ public void undeploy(Archive<?> archive) throws DeploymentException {

@Override
public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
LOG.info("Deploying " + archive.getName());
log.info("Deploying " + archive.getName());

KumuluzEEContainerConfig containerConfig = KumuluzEEContainerConfig.getInstance();

Expand All @@ -131,12 +132,12 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
switch (containerConfig.getPackaging()) {
case KumuluzEEContainerConfig.PACKAGING_UBER_JAR:
Archive<?> uberJar = ArchiveUtils.generateUberJar(archive);
LOG.fine("UberJar: " + uberJar.toString(true));
log.log(Level.FINE, "UberJar: {0}", uberJar.toString(true));
deployment = new UberJarDeployment(uberJar);
break;
case KumuluzEEContainerConfig.PACKAGING_EXPLODED:
Archive<?> exploded = ArchiveUtils.generateExploded(archive);
LOG.fine("Exploded structure: " + exploded.toString(true));
log.log(Level.FINE, "Exploded structure: {0}", exploded.toString(true));
deployment = new ExplodedDeployment(exploded);
break;
default:
Expand All @@ -153,5 +154,4 @@ public ProtocolMetaData deploy(Archive<?> archive) throws DeploymentException {
metaData.addContext(context);
return metaData;
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -51,8 +51,8 @@ public static void main(String[] args) {

EeApplication app = new EeApplication();

KumuluzServer server = app.getServer();
if (server instanceof ServletServer) {
KumuluzServer ser = app.getServer();
if (ser instanceof ServletServer server) {
// print metadata (gets intercepted by parent process)
// print port
Integer port = EeConfig.getInstance().getServer().getHttp().getPort();
Expand All @@ -61,11 +61,11 @@ public static void main(String[] args) {
metadataSb.append(MSG_METADATA_PREFIX).append(port).append('\t');

// print information about the servlets
List<ServletWrapper> servlets = ((ServletServer) server).getRegisteredServlets();
List<ServletWrapper> servlets = server.getRegisteredServlets();
for (ServletWrapper s : servlets) {
metadataSb.append(s.getName()).append(':').append(s.getContextPath()).append('\t');
}
System.out.println(metadataSb.toString());
System.out.println(metadataSb);
}

System.out.println(MSG_SERVER_STARTED);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,11 +20,11 @@
*/
package com.kumuluz.ee.testing.arquillian.assets;

import javax.servlet.ServletContext;
import javax.servlet.ServletContextEvent;
import javax.servlet.ServletContextListener;
import javax.servlet.ServletRegistration;
import javax.servlet.annotation.WebListener;
import jakarta.servlet.ServletContext;
import jakarta.servlet.ServletContextEvent;
import jakarta.servlet.ServletContextListener;
import jakarta.servlet.ServletRegistration;
import jakarta.servlet.annotation.WebListener;

/**
* Adds Arquillian Servlet mapping to the web container.
Expand Down Expand Up @@ -57,6 +57,7 @@ public void contextDestroyed(ServletContextEvent servletContextEvent) {

private boolean isClassPresent(String classname) {
try {
System.out.println("Checking for class: " + classname);
Class.forName(classname);
return true;
} catch (ClassNotFoundException e) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ public abstract class AbstractDeployment {

private Process process;

public AbstractDeployment(Archive<?> archive) {
protected AbstractDeployment(Archive<?> archive) {
this.archive = archive;
this.containerConfig = KumuluzEEContainerConfig.getInstance();
this.shouldDelete = this.containerConfig.shouldDeleteTemporaryFiles();
Expand Down Expand Up @@ -96,7 +96,7 @@ public HTTPContext start() throws DeploymentException {

Path javaPath;

if (!this.containerConfig.getJavaPath().equals("")) {
if (!this.containerConfig.getJavaPath().isEmpty()) {
// java binary is specified in container configuration
javaPath = Paths.get(this.containerConfig.getJavaPath());

Expand Down Expand Up @@ -171,10 +171,8 @@ public void stop() {
}

// clean up tmp files
if (shouldDelete) {
if (tmpDir.toFile().exists()) {
deleteDirectory(tmpDir.toFile());
}
if (shouldDelete && tmpDir.toFile().exists()) {
deleteDirectory(tmpDir.toFile());
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,10 @@ public class ArchiveUtils {

private static final Logger LOG = Logger.getLogger(ArchiveUtils.class.getName());

private ArchiveUtils() {
throw new IllegalStateException("Utility class");
}

/**
* These classes are added to the root of the archive
*/
Expand Down Expand Up @@ -192,10 +196,9 @@ private static void fixArchiveAssets(Archive<?> a, String parentDir) {
Archive<?> tmp = ShrinkWrap.create(JavaArchive.class);
List<ArchivePath> pathsToDelete = new ArrayList<>();
for (Node child : n.getChildren()) {
Asset childAsset = child.getAsset();
if (childAsset instanceof ArchiveAsset && child.getPath().get().endsWith(".jar")) {
Asset asset = child.getAsset();
if (asset instanceof ArchiveAsset archiveAsset && child.getPath().get().endsWith(".jar")) {
LOG.fine("Converting archive " + child.getPath().get() + " to ByteArrayAsset");
ArchiveAsset archiveAsset = (ArchiveAsset) childAsset;
ByteArrayAsset bas = new ByteArrayAsset(archiveAsset.openStream());
pathsToDelete.add(child.getPath());
tmp.add(bas, child.getPath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,10 @@ public class RequiredLibraries {

private static final Logger LOG = Logger.getLogger(RequiredLibraries.class.getName());

private RequiredLibraries() {
throw new IllegalStateException("Utility class");
}

private static final String[] LIBS_DEFAULT = {
"com.kumuluz.ee:kumuluzee-core:",
"com.kumuluz.ee:kumuluzee-servlet-jetty:",
Expand Down Expand Up @@ -125,21 +129,15 @@ public static Archive<?>[] getRequiredLibraries(List<String> deploymentLibs) {
* @return A list of dependencies.
*/
private static List<String> getIncludedLibraries(String includeRequiredLibraries) {
switch (includeRequiredLibraries) {
case KumuluzEEContainerConfig.INCLUDE_LIBS_FALSE:
case KumuluzEEContainerConfig.INCLUDE_LIBS_FROM_POM:
return Collections.emptyList();
case KumuluzEEContainerConfig.INCLUDE_LIBS_DEFAULT:
return Arrays.asList(LIBS_DEFAULT);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_0:
return Arrays.asList(LIBS_MP1_0);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_1:
return Arrays.asList(LIBS_MP1_1);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_2:
return Arrays.asList(LIBS_MP1_2);
default:
throw new RuntimeException("Could not determine includeRequiredLibraries parameter: " +
includeRequiredLibraries);
}
return switch (includeRequiredLibraries) {
case KumuluzEEContainerConfig.INCLUDE_LIBS_FALSE, KumuluzEEContainerConfig.INCLUDE_LIBS_FROM_POM ->
Collections.emptyList();
case KumuluzEEContainerConfig.INCLUDE_LIBS_DEFAULT -> Arrays.asList(LIBS_DEFAULT);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_0 -> Arrays.asList(LIBS_MP1_0);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_1 -> Arrays.asList(LIBS_MP1_1);
case KumuluzEEContainerConfig.INCLUDE_LIBS_MP1_2 -> Arrays.asList(LIBS_MP1_2);
default -> throw new RuntimeException("Could not determine includeRequiredLibraries parameter: " +
includeRequiredLibraries);
};
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,20 +23,20 @@
import com.kumuluz.ee.common.exceptions.KumuluzServerException;
import org.jboss.arquillian.container.test.api.Deployment;
import org.jboss.arquillian.container.test.api.ShouldThrowException;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.asset.EmptyAsset;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Starts two deployments and tests for "Address is already in use" exception.
*
* @author Urban Malc
* @since 1.1.0
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class AddressAlreadyInUseTest {

@Deployment(name = "deployment1", order = 1)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,11 @@

import com.kumuluz.ee.testing.arquillian.provider.SimplePojo;
import org.jboss.arquillian.container.test.api.RunAsClient;
import org.jboss.arquillian.junit.Arquillian;
import org.jboss.arquillian.junit5.ArquillianExtension;
import org.jboss.arquillian.test.api.ArquillianResource;
import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

/**
* Tests injection of {@link ArquillianResource}.
Expand All @@ -35,7 +35,7 @@
* @since 1.0.0
*/
@SuppressWarnings("ArquillianDeploymentAbsent")
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
@RunAsClient
public class ArquillianResourceTest {

Expand All @@ -44,7 +44,7 @@ public class ArquillianResourceTest {

@Test
public void arquillianResourceTest() {
Assert.assertNotNull(simplePojo);
Assert.assertEquals(42, simplePojo.getNumber());
Assertions.assertNotNull(simplePojo);
Assertions.assertEquals(42, simplePojo.getNumber());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,11 +23,11 @@
import com.kumuluz.ee.testing.arquillian.assets.AutoDiscoveredServlet;
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.junit5.ArquillianExtension;
import org.jboss.shrinkwrap.api.ShrinkWrap;
import org.jboss.shrinkwrap.api.spec.JavaArchive;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import static io.restassured.RestAssured.when;
import static org.hamcrest.Matchers.is;
Expand All @@ -38,7 +38,7 @@
* @author Urban Malc
* @since 1.0.0
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class AutoDiscoveredServletTest {

@Deployment(testable = false)
Expand Down
Loading

0 comments on commit 7363b5d

Please sign in to comment.