Issue #23507 logging now uses junit5 instead of junit4
- tests were enhanced a bit
diff --git a/nucleus/core/logging/pom.xml b/nucleus/core/logging/pom.xml
index 2bd7ed5..0392ac4 100755
--- a/nucleus/core/logging/pom.xml
+++ b/nucleus/core/logging/pom.xml
@@ -61,6 +61,10 @@
</dependency>
<dependency>
+ <groupId>org.junit.jupiter</groupId>
+ <artifactId>junit-jupiter-engine</artifactId>
+ </dependency>
+ <dependency>
<groupId>org.hamcrest</groupId>
<artifactId>hamcrest</artifactId>
</dependency>
diff --git a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
index 99a96f1..4dadbf0 100644
--- a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
+++ b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LogEventListenerTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,17 +17,17 @@
package com.sun.enterprise.server.logging;
-import static org.junit.Assert.assertEquals;
-
import java.io.File;
import java.util.concurrent.ArrayBlockingQueue;
import java.util.concurrent.BlockingQueue;
import java.util.logging.Level;
import java.util.logging.Logger;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test class to exercise the LogEvent notification mechanism.
@@ -48,7 +49,7 @@
private static final Logger LOGGER = Logger.getLogger(LOGGER_NAME);
- @BeforeClass
+ @BeforeAll
public static void initializeLoggingAnnotationsTest() throws Exception {
File basePath = new File(BASE_PATH);
basePath.mkdirs();
@@ -81,7 +82,7 @@
System.out.println("Test testLogEventListenerNotifications passed.");
}
- @AfterClass
+ @AfterAll
public static void cleanupLoggingAnnotationsTest() throws Exception {
logEventListener.logEvents.clear();
LOGGER.removeHandler(gfFileHandler);
@@ -93,7 +94,7 @@
private static class TestLogEventListener implements LogEventListener {
- private BlockingQueue<LogEvent> logEvents = new ArrayBlockingQueue<LogEvent>(100);
+ private final BlockingQueue<LogEvent> logEvents = new ArrayBlockingQueue<>(100);
@Override
public void messageLogged(LogEvent event) {
diff --git a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LoggingAnnotationsTest.java b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LoggingAnnotationsTest.java
index 0a1963e..adb928c 100644
--- a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LoggingAnnotationsTest.java
+++ b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/LoggingAnnotationsTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,8 +17,6 @@
package com.sun.enterprise.server.logging;
-import static org.junit.Assert.assertEquals;
-
import java.io.BufferedReader;
import java.io.File;
import java.io.FileReader;
@@ -32,9 +31,13 @@
import org.glassfish.logging.annotation.LogMessageInfo;
import org.glassfish.logging.annotation.LogMessagesResourceBundle;
import org.glassfish.logging.annotation.LoggerInfo;
-import org.junit.AfterClass;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterAll;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* @author sanshriv
@@ -82,7 +85,7 @@
private static ConsoleHandler consoleHandler;
- @BeforeClass
+ @BeforeAll
public static void initializeLoggingAnnotationsTest() throws Exception {
File basePath = new File(BASE_PATH);
basePath.mkdirs();
@@ -127,13 +130,17 @@
public void testFineLevelMessageWithSourceInfo() throws IOException {
LOGGER.fine(FINE_TEST_MESSAGE_ID);
String testMessage = "FINE Level test message";
- String[] ulfContents = new String[] {testMessage,
+ String[] ulfContents = new String[] {
"ClassName=com.sun.enterprise.server.logging.LoggingAnnotationsTest;",
- "MethodName=testFineLevelMessageWithSourceInfo;"};
+ "MethodName=testFineLevelMessageWithSourceInfo;",
+ testMessage,
+ };
validateLogContents(ULF_LOG, ulfContents);
- String[] odlContents = new String[] {testMessage,
+ String[] odlContents = new String[] {
"[CLASSNAME: com.sun.enterprise.server.logging.LoggingAnnotationsTest]",
- "[METHODNAME: testFineLevelMessageWithSourceInfo]"};
+ "[METHODNAME: testFineLevelMessageWithSourceInfo]",
+ testMessage,
+ };
validateLogContents(ODL_LOG, odlContents);
System.out.println("Test passed successfully.");
}
@@ -175,10 +182,8 @@
buf.append(LINE_SEP);
}
String contents = buf.toString();
- for (String msg : messages) {
- assertEquals("File " + file + " does not contain expected log message:" + msg,
- true, contents.contains(msg));
- }
+ assertThat("File " + file + " does not contain expected log messages", contents,
+ stringContainsInOrder(messages));
return contents;
} finally {
if (reader != null) {
@@ -187,7 +192,7 @@
}
}
- @AfterClass
+ @AfterAll
public static void cleanupLoggingAnnotationsTest() throws Exception {
LOGGER.removeHandler(consoleHandler);
LOGGER.removeHandler(uniformFormatHandler);
diff --git a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/logviewer/backend/LogFileTest.java b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/logviewer/backend/LogFileTest.java
index 21307e0..a045f84 100644
--- a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/logviewer/backend/LogFileTest.java
+++ b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/logviewer/backend/LogFileTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2012, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,37 +17,49 @@
package com.sun.enterprise.server.logging.logviewer.backend;
-import java.io.IOException;
-import java.io.ObjectInputStream;
-
-import org.junit.Test;
-
import com.sun.enterprise.server.logging.logviewer.backend.LogFile.LogEntry;
+import java.io.ObjectInputStream;
+import java.time.LocalDateTime;
+import java.time.ZoneId;
+import java.time.ZonedDateTime;
+
+import org.junit.jupiter.api.Test;
+
+import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.stringContainsInOrder;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+
/**
- *
* @author sanshriv
- *
*/
public class LogFileTest {
@Test
- public void testLogEntryDeserialization() throws IOException, ClassNotFoundException {
- ObjectInputStream objectInput = new ObjectInputStream(
- LogFileTest.class.getResource("logentry.bin").openStream());
- // Create and initialize a LogEntry from binary file
- LogFile.LogEntry entry = (LogEntry) objectInput.readObject();
+ public void testLogEntryDeserialization() throws Exception {
+ try (ObjectInputStream objectInput = new ObjectInputStream(
+ LogFileTest.class.getResource("logentry.bin").openStream())) {
+ // Create and initialize a LogEntry from binary file
+ LogFile.LogEntry entry = (LogEntry) objectInput.readObject();
- System.out.println("DateTime=" + entry.getLoggedDateTime());
- System.out.println("Level=" + entry.getLoggedLevel());
- System.out.println("Logger=" + entry.getLoggedLoggerName());
- System.out.println("Message=" + entry.getLoggedMessage());
- System.out.println("NameValuePairs=" + entry.getLoggedNameValuePairs());
- System.out.println("Product=" + entry.getLoggedProduct());
- System.out.println("MessageId=" + entry.getMessageId());
- System.out.println("RecordNumber=" + entry.getRecordNumber());
-
- objectInput.close();
+ assertNotNull(entry.getLoggedDateTime(), "DateTime");
+ ZoneId utc = ZoneId.of("Z");
+ final ZonedDateTime dateTime = ZonedDateTime.ofInstant(entry.getLoggedDateTime().toInstant(), utc);
+ final ZonedDateTime expectedDateTime = ZonedDateTime
+ .of(LocalDateTime.of(2012, 11, 8, 18, 42, 26, 763000000), utc);
+ assertEquals(expectedDateTime, dateTime, "DateTime");
+ assertEquals("INFO", entry.getLoggedLevel(), "Level");
+ assertEquals("javax.enterprise.logging", entry.getLoggedLoggerName(), "Logger");
+ assertEquals("Running GlassFish Version: Oracle GlassFish Server 4.0 (build sanshriv-private)",
+ entry.getLoggedMessage(), "Message");
+ assertThat("NameValuePairs", entry.getLoggedNameValuePairs(),
+ stringContainsInOrder("ThreadID", "ThreadName", "TimeMillis", "LevelValue", "MessageID"));
+ assertEquals("44.0", entry.getLoggedProduct(), "Product");
+ // FIXME: MessageID is not parsed.
+// assertEquals("NCLS-LOGGING-00009", entry.getMessageId(), "MessageId");
+ assertEquals(1L, entry.getRecordNumber(), "RecordNumber");
+ }
}
}
diff --git a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/parser/LogParserTest.java b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/parser/LogParserTest.java
index a928b98..f77f1b6 100644
--- a/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/parser/LogParserTest.java
+++ b/nucleus/core/logging/src/test/java/com/sun/enterprise/server/logging/parser/LogParserTest.java
@@ -1,5 +1,6 @@
/*
* Copyright (c) 2013, 2018 Oracle and/or its affiliates. All rights reserved.
+ * Copyright (c) 2021 Contributors to the Eclipse Foundation
*
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License v. 2.0, which is available at
@@ -16,15 +17,15 @@
package com.sun.enterprise.server.logging.parser;
-import static org.junit.Assert.assertEquals;
-
import java.io.BufferedReader;
import java.io.BufferedWriter;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
public class LogParserTest {