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 3ebf542 commit cc672a6
Show file tree
Hide file tree
Showing 19 changed files with 107 additions and 97 deletions.
14 changes: 9 additions & 5 deletions audit/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-logs</artifactId>
<groupId>com.kumuluz.ee.logs</groupId>
<version>1.5.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand All @@ -31,8 +31,8 @@
</dependency>
<dependency>
<groupId>org.jboss.weld</groupId>
<artifactId>weld-junit4</artifactId>
<version>${weld-junit4.version}</version>
<artifactId>weld-junit5</artifactId>
<version>${weld-junit5.version}</version>
<scope>test</scope>
</dependency>
<dependency>
Expand All @@ -41,8 +41,12 @@
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.jboss.arquillian.junit</groupId>
<artifactId>arquillian-junit-container</artifactId>
<groupId>jakarta.ws.rs</groupId>
<artifactId>jakarta.ws.rs-api</artifactId>
</dependency>
<dependency>
<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 @@ -24,11 +24,11 @@
import com.kumuluz.ee.logs.audit.annotations.AuditObjectParam;
import com.kumuluz.ee.logs.audit.annotations.LogAudit;
import com.kumuluz.ee.logs.audit.types.AuditProperty;
import jakarta.ws.rs.PathParam;
import jakarta.ws.rs.QueryParam;
import jakarta.ws.rs.container.ResourceInfo;
import jakarta.ws.rs.core.UriInfo;

import javax.ws.rs.PathParam;
import javax.ws.rs.QueryParam;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.UriInfo;
import java.lang.reflect.Parameter;
import java.util.Optional;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
*/
package com.kumuluz.ee.logs.audit.annotations;

import javax.enterprise.util.Nonbinding;
import jakarta.enterprise.util.Nonbinding;

/**
* @author Gregor Porocnik
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@
*/
package com.kumuluz.ee.logs.audit.annotations;

import javax.enterprise.util.Nonbinding;
import javax.interceptor.InterceptorBinding;
import jakarta.enterprise.util.Nonbinding;
import jakarta.interceptor.InterceptorBinding;

import java.lang.annotation.ElementType;
import java.lang.annotation.Inherited;
import java.lang.annotation.Retention;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@
import com.kumuluz.ee.logs.audit.loggers.NoOpAuditLogger;
import com.kumuluz.ee.logs.audit.types.AuditProperty;
import com.kumuluz.ee.logs.audit.types.DataAuditAction;
import jakarta.annotation.PostConstruct;
import jakarta.enterprise.context.RequestScoped;

import javax.annotation.PostConstruct;
import javax.enterprise.context.RequestScoped;
import java.lang.reflect.InvocationTargetException;
import java.util.Optional;

Expand Down Expand Up @@ -80,7 +80,8 @@ public void init() {
this.auditLogger = (AuditLogger) clazz.getDeclaredConstructor().newInstance();
return;
}
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException | ClassNotFoundException e) {
} catch (NoSuchMethodException | InvocationTargetException | IllegalAccessException | InstantiationException |
ClassNotFoundException e) {
LOG.warn("Unable to create instance of provided class {}", auditLoggerClass.get());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@
import com.kumuluz.ee.logs.audit.annotations.AuditProperty;
import com.kumuluz.ee.logs.audit.annotations.LogAudit;
import com.kumuluz.ee.logs.audit.cdi.AuditLog;
import jakarta.annotation.Priority;
import jakarta.inject.Inject;
import jakarta.interceptor.AroundInvoke;
import jakarta.interceptor.Interceptor;
import jakarta.interceptor.InvocationContext;
import jakarta.ws.rs.Path;

import javax.annotation.Priority;
import javax.inject.Inject;
import javax.interceptor.AroundInvoke;
import javax.interceptor.Interceptor;
import javax.interceptor.InvocationContext;
import javax.ws.rs.Path;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.util.Set;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,18 @@
import com.kumuluz.ee.logs.audit.cdi.AuditLog;
import com.kumuluz.ee.logs.audit.types.AuditProperty;
import com.kumuluz.ee.logs.audit.types.DataAuditAction;
import jakarta.annotation.Priority;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.inject.Inject;
import jakarta.ws.rs.*;
import jakarta.ws.rs.container.ContainerRequestContext;
import jakarta.ws.rs.container.ContainerResponseContext;
import jakarta.ws.rs.container.ContainerResponseFilter;
import jakarta.ws.rs.container.ResourceInfo;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.UriInfo;
import jakarta.ws.rs.ext.Provider;

import javax.annotation.Priority;
import javax.enterprise.context.ApplicationScoped;
import javax.inject.Inject;
import javax.ws.rs.*;
import javax.ws.rs.container.ContainerRequestContext;
import javax.ws.rs.container.ContainerResponseContext;
import javax.ws.rs.container.ContainerResponseFilter;
import javax.ws.rs.container.ResourceInfo;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.UriInfo;
import javax.ws.rs.ext.Provider;
import java.lang.reflect.Method;
import java.lang.reflect.Parameter;
import java.net.URI;
Expand Down
22 changes: 11 additions & 11 deletions audit/src/test/java/com/kumuluz/ee/logs/audit/cdi/AuditLogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,15 @@
import com.kumuluz.ee.logs.audit.types.DataAuditAction;
import com.kumuluz.ee.logs.messages.LogMessage;
import org.jboss.arquillian.container.test.api.Deployment;
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.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import javax.inject.Inject;
import java.util.LinkedList;
Expand All @@ -49,12 +49,12 @@

import static com.kumuluz.ee.logs.audit.cdi.AuditLog.CONFIG_AUDIT_LOG_ENABLE;
import static com.kumuluz.ee.logs.audit.cdi.AuditLog.CONFIG_AUDIT_LOG_LOGGER_CLASS;
import static org.junit.Assert.*;
import static org.junit.jupiter.api.Assertions.*;

/**
* @author Gregor Porocnik
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class AuditLogTest {

@Deployment
Expand All @@ -78,7 +78,7 @@ public static WebArchive createDeployment() {
@Inject
private AuditLog auditLog;

@Before
@BeforeAll
public void before() {
System.setProperty(CONFIG_AUDIT_LOG_LOGGER_CLASS, KumuluzAuditLogger.class.getName());
TestLogger.setMessages(new LinkedList<>());
Expand Down Expand Up @@ -106,7 +106,7 @@ public void shouldLogAuditWithGenericApi() {
}

@Test
public void shouldLogAudit() {
void shouldLogAudit() {

auditLog.log("exampleMethodName", "exampleObjectType", "exampleAction", "id", new AuditProperty("propName", "propValue"));
auditLog.flush();
Expand All @@ -123,7 +123,7 @@ public void shouldLogAudit() {
}

@Test
public void shouldLogNullWithNullParams() {
void shouldLogNullWithNullParams() {

auditLog.log(null, null, (DataAuditAction) null, null, null);
auditLog.flush();
Expand All @@ -139,7 +139,7 @@ public void shouldLogNullWithNullParams() {
}

@Test
public void disabledAuditShouldNotLog() {
void disabledAuditShouldNotLog() {

System.setProperty(CONFIG_AUDIT_LOG_ENABLE, "false");

Expand All @@ -154,7 +154,7 @@ public void disabledAuditShouldNotLog() {
}

@Test
public void shouldLogAuditWithCustomAuditLogger() {
void shouldLogAuditWithCustomAuditLogger() {

System.setProperty(CONFIG_AUDIT_LOG_LOGGER_CLASS, TestAuditLogger.class.getName());

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,39 +27,38 @@
import com.kumuluz.ee.logs.audit.test.loggers.TestLogConfigurator;
import com.kumuluz.ee.logs.audit.test.loggers.TestLogger;
import com.kumuluz.ee.logs.messages.LogMessage;
import org.jboss.arquillian.container.test.api.BeforeDeployment;
import org.jboss.arquillian.container.test.api.Deployment;
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.jboss.shrinkwrap.api.spec.WebArchive;
import org.jboss.shrinkwrap.resolver.api.maven.Maven;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;

import java.io.IOException;
import java.net.HttpURLConnection;
import java.net.URI;
import java.net.URL;
import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.ResourceBundle;

import static com.kumuluz.ee.logs.audit.cdi.AuditLog.CONFIG_AUDIT_LOG_ENABLE;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;

/**
* @author Gregor Porocnik
*/
@RunWith(Arquillian.class)
@ExtendWith(ArquillianExtension.class)
public class AuditResourceTest {


@Deployment
public static WebArchive createDeployment() {

ResourceBundle versionsBundle = ResourceBundle.getBundle("META-INF/kumuluzee/logs/audit/versions");

WebArchive jar = ShrinkWrap
Expand All @@ -70,28 +69,28 @@ public static WebArchive createDeployment() {
.addAsResource("META-INF/services/com.kumuluz.ee.logs.LogCommons")
.addAsResource("META-INF/services/com.kumuluz.ee.logs.LogConfigurator")
.addAsWebInfResource(EmptyAsset.INSTANCE, "beans.xml");
jar.merge(Maven.resolver().resolve("com.kumuluz.ee.logs:kumuluzee-logs-common:"+ versionsBundle.getString("kumuluzee-logs-common-version")).withoutTransitivity().asSingle(JavaArchive.class));
jar.merge(Maven.resolver().resolve("com.kumuluz.ee.logs:kumuluzee-logs-common:" + versionsBundle.getString("kumuluzee-logs-common-version")).withoutTransitivity().asSingle(JavaArchive.class));

return jar;
}

@Before
@BeforeDeployment
public void before() {
System.setProperty(CONFIG_AUDIT_LOG_ENABLE, "true");
TestLogger.setMessages(new LinkedList<>());
}

@Test
public void shouldLogClassAnnotatedAuditGetResourceWithParams() throws IOException {
URL url = new URL("http://localhost:8080/resourceName/parentInputParamIds/inputParamId?obj=1234");
void shouldLogClassAnnotatedAuditGetResourceWithParams() throws IOException {
URL url = URI.create("http://localhost:8080/resourceName/parentInputParamIds/inputParamId?obj=1234").toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("GET");
connection.connect();

assertEquals(200, connection.getResponseCode());

List<LogMessage> messages = TestLogger.getMessages();
messages.stream().forEach(this::debugMsg);
messages.forEach(this::debugMsg);

assertEquals(1, messages.size());
LogMessage logMessage = messages.get(0);
Expand All @@ -107,12 +106,11 @@ public void shouldLogClassAnnotatedAuditGetResourceWithParams() throws IOExcepti
assertEquals("resPropVal2", fields.get("resPropName2"));
//resource parameters not annotated with auditObjectParam are not included
assertNull(fields.get("parentId"));

}

@Test
public void shouldLogClassAnnotatedAuditPostResourceWithParams() throws IOException {
URL url = new URL("http://localhost:8080/resourceName?obj=4321");
void shouldLogClassAnnotatedAuditPostResourceWithParams() throws IOException {
URL url = URI.create(("http://localhost:8080/resourceName?obj=4321")).toURL();
HttpURLConnection connection = (HttpURLConnection) url.openConnection();
connection.setRequestMethod("POST");
connection.connect();
Expand All @@ -133,7 +131,6 @@ public void shouldLogClassAnnotatedAuditPostResourceWithParams() throws IOExcept
//assert class anotated properties since method does not have AuditLog annotation
assertEquals("resPropVal1", fields.get("resPropName1"));
assertEquals("resPropVal2", fields.get("resPropName2"));

}

private void debugMsg(LogMessage logMessage) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@
import com.kumuluz.ee.logs.audit.annotations.AuditObjectParam;
import com.kumuluz.ee.logs.audit.annotations.AuditProperty;
import com.kumuluz.ee.logs.audit.annotations.LogAudit;
import jakarta.enterprise.context.ApplicationScoped;

import javax.enterprise.context.ApplicationScoped;
import java.util.UUID;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,12 +23,12 @@
import com.kumuluz.ee.logs.audit.annotations.AuditObjectParam;
import com.kumuluz.ee.logs.audit.annotations.AuditProperty;
import com.kumuluz.ee.logs.audit.annotations.LogAudit;
import jakarta.enterprise.context.ApplicationScoped;
import jakarta.ws.rs.*;
import jakarta.ws.rs.core.Context;
import jakarta.ws.rs.core.Response;
import jakarta.ws.rs.core.UriInfo;

import javax.enterprise.context.ApplicationScoped;
import javax.ws.rs.*;
import javax.ws.rs.core.Context;
import javax.ws.rs.core.Response;
import javax.ws.rs.core.UriInfo;
import java.util.UUID;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,9 +21,9 @@
package com.kumuluz.ee.logs.audit.test.beans;

import com.kumuluz.ee.logs.audit.filters.AuditLogFilter;
import jakarta.ws.rs.ApplicationPath;
import jakarta.ws.rs.core.Application;

import javax.ws.rs.ApplicationPath;
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;

Expand Down
2 changes: 1 addition & 1 deletion common/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<parent>
<artifactId>kumuluzee-logs</artifactId>
<groupId>com.kumuluz.ee.logs</groupId>
<version>1.5.0-SNAPSHOT</version>
<version>2.0.0-SNAPSHOT</version>
</parent>
<modelVersion>4.0.0</modelVersion>

Expand Down
Loading

0 comments on commit cc672a6

Please sign in to comment.