From eec30d33870e135a33e24bdc9f3a659b54867cc5 Mon Sep 17 00:00:00 2001
From: samguntersmilecdr <123124187+samguntersmilecdr@users.noreply.github.com>
Date: Fri, 20 Jan 2023 09:30:46 -0500
Subject: [PATCH] removed unneeded mdm logging + test + changelog (#4451)
---
...orage-interceptor-unnecessary-logging.yaml | 5 ++
hapi-fhir-server-mdm/pom.xml | 6 ++
.../interceptor/MdmStorageInterceptor.java | 2 -
.../MdmStorageInterceptorTest.java | 64 +++++++++++++++++++
4 files changed, 75 insertions(+), 2 deletions(-)
create mode 100644 hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3979-mdm-storage-interceptor-unnecessary-logging.yaml
create mode 100644 hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/Interceptor/MdmStorageInterceptorTest.java
diff --git a/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3979-mdm-storage-interceptor-unnecessary-logging.yaml b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3979-mdm-storage-interceptor-unnecessary-logging.yaml
new file mode 100644
index 00000000000..96cd8fe45b3
--- /dev/null
+++ b/hapi-fhir-docs/src/main/resources/ca/uhn/hapi/fhir/changelog/6_4_0/3979-mdm-storage-interceptor-unnecessary-logging.yaml
@@ -0,0 +1,5 @@
+---
+type: fix
+issue: 3979
+title: "Previously, the MdmStorageInterceptor was needlessly logging a warning if theOldResource of an update was null.
+This is now fixed."
diff --git a/hapi-fhir-server-mdm/pom.xml b/hapi-fhir-server-mdm/pom.xml
index 863b448f75e..22674a7191c 100644
--- a/hapi-fhir-server-mdm/pom.xml
+++ b/hapi-fhir-server-mdm/pom.xml
@@ -129,6 +129,12 @@
${project.version}
test
+
+ ca.uhn.hapi.fhir
+ hapi-fhir-test-utilities
+ ${project.version}
+ test
+
diff --git a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmStorageInterceptor.java b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmStorageInterceptor.java
index 1c07ca2cc72..522786f4697 100644
--- a/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmStorageInterceptor.java
+++ b/hapi-fhir-server-mdm/src/main/java/ca/uhn/fhir/mdm/interceptor/MdmStorageInterceptor.java
@@ -116,8 +116,6 @@ public class MdmStorageInterceptor implements IMdmStorageInterceptor {
if (theOldResource != null) {
forbidIfMdmManagedTagIsPresent(theOldResource);
forbidModifyingMdmTag(theUpdatedResource, theOldResource);
- } else {
- ourLog.warn("Null theOldResource for {} {}", theUpdatedResource == null ? "null updated resource" : theUpdatedResource.getIdElement(), theRequestDetails);
}
if (myMdmSettings.isPreventEidUpdates()) {
diff --git a/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/Interceptor/MdmStorageInterceptorTest.java b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/Interceptor/MdmStorageInterceptorTest.java
new file mode 100644
index 00000000000..5567d71d10f
--- /dev/null
+++ b/hapi-fhir-server-mdm/src/test/java/ca/uhn/fhir/mdm/Interceptor/MdmStorageInterceptorTest.java
@@ -0,0 +1,64 @@
+package ca.uhn.fhir.mdm.Interceptor;
+
+import ca.uhn.fhir.mdm.api.IMdmSettings;
+import ca.uhn.fhir.mdm.interceptor.MdmStorageInterceptor;
+import ca.uhn.fhir.model.dstu2.resource.Patient;
+import ca.uhn.fhir.rest.api.server.RequestDetails;
+import ca.uhn.fhir.rest.server.servlet.ServletRequestDetails;
+import ch.qos.logback.classic.Level;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
+import org.mockito.Mock;
+import org.mockito.junit.jupiter.MockitoExtension;
+import org.slf4j.LoggerFactory;
+
+import java.util.List;
+
+import static org.junit.jupiter.api.Assertions.assertEquals;
+
+@ExtendWith(MockitoExtension.class)
+public class MdmStorageInterceptorTest {
+
+ private static final Logger ourLog = (Logger) LoggerFactory.getLogger(MdmStorageInterceptor.class);
+ private ListAppender myListAppender;
+
+ @InjectMocks
+ private MdmStorageInterceptor myMdmStorageInterceptor;
+ @Mock
+ private IMdmSettings myMdmSettings;
+
+ @BeforeEach
+ public void beforeEach(){
+ myListAppender = new ListAppender<>();
+ myListAppender.start();
+ ourLog.addAppender(myListAppender);
+ }
+
+ @AfterEach
+ public void afterEach(){
+ myListAppender.stop();
+ }
+
+ @Test
+ public void testBlockManualGoldenResourceManipulationOnUpdate_nullOldResource_noLogs() {
+ Patient updatedResource = new Patient();
+ RequestDetails requestDetails = new ServletRequestDetails();
+
+ myMdmStorageInterceptor.blockManualGoldenResourceManipulationOnUpdate(null, updatedResource, requestDetails, null);
+
+ List warningLogs = myListAppender
+ .list
+ .stream()
+ .filter(event -> Level.WARN.equals(event.getLevel()))
+ .toList();
+ assertEquals(0, warningLogs.size());
+
+ }
+
+}