From d90dac5551a0785bf480de25838c316afde8f77b Mon Sep 17 00:00:00 2001 From: Chintalapudi Guru Ganesh HYD DISYI Date: Mon, 23 Feb 2026 17:26:52 +0530 Subject: [PATCH] Change compId type from int to Integer --- .../de/fva_net/maxs/logger/MaxsLogger.java | 28 +++--- .../java/de/fva_net/maxs/logger/xml/Item.java | 2 +- .../fva_net/maxs/logger/xml/Notification.java | 2 +- .../logger/MaxsLoggerIntegrationTest.java | 95 +++++++++---------- 4 files changed, 61 insertions(+), 66 deletions(-) diff --git a/src/main/java/de/fva_net/maxs/logger/MaxsLogger.java b/src/main/java/de/fva_net/maxs/logger/MaxsLogger.java index ede26aa..1322e98 100644 --- a/src/main/java/de/fva_net/maxs/logger/MaxsLogger.java +++ b/src/main/java/de/fva_net/maxs/logger/MaxsLogger.java @@ -108,13 +108,13 @@ public static void logMessage(final MaxsLoggableRoutine routine, final RexsCompo * @param message the log message * @param messageType the severity of the message */ - public static void logMessage(final MaxsLoggableRoutine routine, final int componentId, final String message, final MaxsMessageType messageType) { + public static void logMessage(final MaxsLoggableRoutine routine, final Integer componentId, final String message, final MaxsMessageType messageType) { // Create the log message final Notification notification = new Notification(); notification.setRoutine(routine != null ? routine.getMaxsId() : null); notification.setMessage(message); notification.setType(messageType); - if (componentId > 0) { + if (componentId != null && componentId > 0) { notification.setCompId(componentId); } @@ -126,9 +126,9 @@ public static void logMessage(final MaxsLoggableRoutine routine, final int compo /** * Logs a new message. * - * @param routine the routine for which the messasge shall be logged - * @param message the log message - * @param messageType the severity of the message + * @param routine the routine for which the messasge shall be logged + * @param message the log message + * @param messageType the severity of the message */ public static void logMessage(final MaxsLoggableRoutine routine, final String message, final MaxsMessageType messageType) { // Create the log message @@ -150,14 +150,16 @@ public static void logMessage(final MaxsLoggableRoutine routine, final String me * @param value the value * @param attribute the attribute name */ - private static void logMissingAttribute(final MaxsLoggableRoutine routine, final int componentId, final Object value, final String attribute) { + private static void logMissingAttribute(final MaxsLoggableRoutine routine, final Integer componentId, final Object value, final String attribute) { final Notification notification = new Notification(); final Item item = new Item(); notification.setRoutine(routine != null ? routine.getMaxsId() : null); notification.setMessage(attribute + " is required to perform the calculation but is missing."); notification.setType(MaxsMessageType.DEBUG_ERROR); - notification.setCompId(componentId); + if (componentId != null) { + notification.setCompId(componentId); + } if (value == null) { item.setValue(Double.NaN); @@ -176,7 +178,9 @@ private static void logMissingAttribute(final MaxsLoggableRoutine routine, final log.error("Unsupported Data Type"); } item.setAttrId(attribute); - item.setCompId(componentId); + if (componentId != null) { + item.setCompId(componentId); + } notification.getData().add(item); // store it in the list and write it to file @@ -192,7 +196,7 @@ private static void logMissingAttribute(final MaxsLoggableRoutine routine, final * @param value the double field * @param attribute the name of the attribute */ - public static void requireNonNull(final MaxsLoggableRoutine routine, final int componentId, final double value, final String attribute) { + public static void requireNonNull(final MaxsLoggableRoutine routine, final Integer componentId, final double value, final String attribute) { if (Double.isNaN(value)) { logMissingAttribute(routine, componentId, value, attribute); } @@ -207,7 +211,7 @@ public static void requireNonNull(final MaxsLoggableRoutine routine, final int c * @param value the value to check for null or "UNKNOWN" * @param attribute the name of the attribute being checked */ - public static void requireNonNull(final MaxsLoggableRoutine routine, final int componentId, final Object value, final String attribute) { + public static void requireNonNull(final MaxsLoggableRoutine routine, final Integer componentId, final Object value, final String attribute) { // Check if the value is null and log the missing attribute if true if (value == null) { logMissingAttribute(routine, componentId, null, attribute); @@ -232,7 +236,7 @@ else if (value instanceof Double d && Double.isNaN(d)) { * @param value the double value to check * @param attribute the name of the attribute */ - public static void requireNonZero(final MaxsLoggableRoutine routine, final int componentId, final double value, final String attribute) { + public static void requireNonZero(final MaxsLoggableRoutine routine, final Integer componentId, final double value, final String attribute) { if (Double.isNaN(value) || Precision.equalsWithRelativeTolerance(value, 0, 1e-7)) { logMissingAttribute(routine, componentId, value, attribute); } @@ -247,7 +251,7 @@ public static void requireNonZero(final MaxsLoggableRoutine routine, final int c * @param attribute the name of the attribute * @param the type of the quantity */ - public static > void requireNonZero(final MaxsLoggableRoutine routine, final int componentId, final Quantity quantity, final String attribute) { + public static > void requireNonZero(final MaxsLoggableRoutine routine, final Integer componentId, final Quantity quantity, final String attribute) { if (quantity == null) { logMissingAttribute(routine, componentId, null, attribute); return; diff --git a/src/main/java/de/fva_net/maxs/logger/xml/Item.java b/src/main/java/de/fva_net/maxs/logger/xml/Item.java index 65ae8e5..83c3b60 100644 --- a/src/main/java/de/fva_net/maxs/logger/xml/Item.java +++ b/src/main/java/de/fva_net/maxs/logger/xml/Item.java @@ -24,7 +24,7 @@ public class Item { * The component ID of the item. */ @XmlAttribute(name = "compId", required = true) - private int compId; + private Integer compId; /** * The value of the item. diff --git a/src/main/java/de/fva_net/maxs/logger/xml/Notification.java b/src/main/java/de/fva_net/maxs/logger/xml/Notification.java index aa19032..bc7866e 100644 --- a/src/main/java/de/fva_net/maxs/logger/xml/Notification.java +++ b/src/main/java/de/fva_net/maxs/logger/xml/Notification.java @@ -22,7 +22,7 @@ public class Notification { * The component ID associated with this notification. */ @XmlAttribute - private int compId; + private Integer compId; /** * The list of items (attributes and values) associated with this notification. diff --git a/src/test/java/de/fva_net/maxs/logger/MaxsLoggerIntegrationTest.java b/src/test/java/de/fva_net/maxs/logger/MaxsLoggerIntegrationTest.java index 79c0c99..80b09de 100644 --- a/src/test/java/de/fva_net/maxs/logger/MaxsLoggerIntegrationTest.java +++ b/src/test/java/de/fva_net/maxs/logger/MaxsLoggerIntegrationTest.java @@ -9,6 +9,7 @@ import java.io.File; import java.nio.file.Path; +import java.util.Optional; import static org.junit.jupiter.api.Assertions.*; @@ -80,12 +81,12 @@ void deactivateFileLogging_deactivatesLogging(@TempDir Path tempDir) { */ @Test void logMessage_withPart_logsMessage() { - MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, 42, "Test message", MaxsMessageType.INFO); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(42, MaxsLogger.getAllNotifications().get(0).getCompId()); - assertEquals("Test message", MaxsLogger.getAllNotifications().get(0).getMessage()); - assertEquals(MaxsMessageType.INFO, MaxsLogger.getAllNotifications().get(0).getType()); - assertEquals("iso21771_2007", MaxsLogger.getAllNotifications().get(0).getRoutine()); + MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, 42, "Test message", MaxsMessageType.INFO); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(42, MaxsLogger.getAllNotifications().get(0).getCompId()); + assertEquals("Test message", MaxsLogger.getAllNotifications().get(0).getMessage()); + assertEquals(MaxsMessageType.INFO, MaxsLogger.getAllNotifications().get(0).getType()); + assertEquals("iso21771_2007", MaxsLogger.getAllNotifications().get(0).getRoutine()); } /** @@ -104,29 +105,19 @@ void logMessage_withString_logsMessage() { * Logs a NaN double value and verifies that a missing attribute notification is created. */ @Test - void requireNonNull_doubleValueIsNaN_logsMissingAttribute() { - MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, Double.NaN, "attr"); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); + void requireNonNull_ValueIsNull_logsMissingAttribute() { + MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, null, "attr"); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); } - /** - * Logs a NaN object double value and verifies that a missing attribute notification is created. - */ - @Test - void requireNonNull_objectDoubleValueIsNaN_logsMissingAttribute() { - MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, Double.valueOf(Double.NaN), "attr"); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); - } - /** * Logs a non-NaN double value and verifies that no notifications are created. */ @Test void requireNonNull_doubleValueIsNotNaN_doesNotLog() { - MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, 1.23, "attr"); - assertEquals(0, MaxsLogger.getAllNotifications().size()); + MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, Optional.of(1.23), "attr"); + assertEquals(0, MaxsLogger.getAllNotifications().size()); } /** @@ -134,7 +125,7 @@ void requireNonNull_doubleValueIsNotNaN_doesNotLog() { */ @Test void requireNonNull_objectDoubleValueIsNotNaN_doesNotLog() { - MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, Double.valueOf(1.0), "attr"); + MaxsLogger.requireNonNull(IsoRoutine.ISO21771_2007, 1, Optional.of(1.0), "attr"); assertEquals(0, MaxsLogger.getAllNotifications().size()); } @@ -172,48 +163,48 @@ void requireNonNull_enumValueIsValid_doesNotLog() { */ @Test void requireNonZero_doubleValueIsNaN_logsMissingAttribute() { - MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, Double.NaN, "attr"); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); - } + MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, Double.NaN, "attr"); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); + } /** * Logs a zero double value and verifies that a missing attribute notification is created. */ @Test void requireNonZero_doubleValueIsZero_logsMissingAttribute() { - MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, 0.0, "attr"); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); - } + MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, 0.0, "attr"); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); + } /** * Logs a non-zero double value and verifies that no notifications are created. */ @Test void requireNonZero_doubleValueIsNonZero_doesNotLog() { - MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, 2.0, "attr"); - assertEquals(0, MaxsLogger.getAllNotifications().size()); - } + MaxsLogger.requireNonZero(IsoRoutine.ISO21771_2007, 3, 2.0, "attr"); + assertEquals(0, MaxsLogger.getAllNotifications().size()); + } /** * Logs a zero int value and verifies that a missing attribute notification is created. */ @Test void requireNonZero_intValueIsZero_logsMissingAttribute() { - MaxsLogger.requireNonZero(IsoRoutine.ISO6336_2019, 4, 0, "intAttr"); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); - } + MaxsLogger.requireNonZero(IsoRoutine.ISO6336_2019, 4, 0, "intAttr"); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(MaxsMessageType.DEBUG_ERROR, MaxsLogger.getAllNotifications().get(0).getType()); + } /** * Logs a non-zero int value and verifies that no notifications are created. */ @Test void requireNonZero_intValueIsNonZero_doesNotLog() { - MaxsLogger.requireNonZero(IsoRoutine.ISO6336_2019, 4, 5, "intAttr"); - assertEquals(0, MaxsLogger.getAllNotifications().size()); - } + MaxsLogger.requireNonZero(IsoRoutine.ISO6336_2019, 4, 5, "intAttr"); + assertEquals(0, MaxsLogger.getAllNotifications().size()); + } /** * Verifies that resetting the logger clears notifications and deactivates logging. @@ -222,13 +213,13 @@ void requireNonZero_intValueIsNonZero_doesNotLog() { void reset_clearsNotificationsAndDeactivatesLogging(@TempDir Path tempDir) { File validFile = new File(tempDir.toFile(), "logfile.maxs"); MaxsLogger.activateFileLogging(validFile); - MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, 5, "msg", MaxsMessageType.INFO); + MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, 5, "msg", MaxsMessageType.INFO); assertTrue(MaxsLogger.isLoggingToFileActivated()); - assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(1, MaxsLogger.getAllNotifications().size()); MaxsLogger.reset(); assertFalse(MaxsLogger.isLoggingToFileActivated()); - assertEquals(0, MaxsLogger.getAllNotifications().size()); - } + assertEquals(0, MaxsLogger.getAllNotifications().size()); + } /** * Sets the application information and verifies the app ID and version. @@ -248,12 +239,12 @@ void setAppInformation_setsAppIdAndVersion() { */ @Test void logMessage_withRexsComponent() { - MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, rexsGear, "Info message", MaxsMessageType.INFO); - assertEquals(1, MaxsLogger.getAllNotifications().size()); - assertEquals(12, MaxsLogger.getAllNotifications().get(0).getCompId()); - assertEquals("Info message", MaxsLogger.getAllNotifications().get(0).getMessage()); - assertEquals(MaxsMessageType.INFO, MaxsLogger.getAllNotifications().get(0).getType()); - assertEquals("iso21771_2007", MaxsLogger.getAllNotifications().get(0).getRoutine()); - assertTrue(MaxsLogger.getAllNotifications().get(0).getMessage().contains("Info")); + MaxsLogger.logMessage(IsoRoutine.ISO21771_2007, rexsGear, "Info message", MaxsMessageType.INFO); + assertEquals(1, MaxsLogger.getAllNotifications().size()); + assertEquals(12, MaxsLogger.getAllNotifications().get(0).getCompId()); + assertEquals("Info message", MaxsLogger.getAllNotifications().get(0).getMessage()); + assertEquals(MaxsMessageType.INFO, MaxsLogger.getAllNotifications().get(0).getType()); + assertEquals("iso21771_2007", MaxsLogger.getAllNotifications().get(0).getRoutine()); + assertTrue(MaxsLogger.getAllNotifications().get(0).getMessage().contains("Info")); } }