diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderIT.java similarity index 97% rename from hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderTest.java rename to hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderIT.java index f0ab98a7cd97..541f4f6cb284 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/expunge/ResourceTableFKProviderIT.java @@ -33,8 +33,8 @@ JpaConstants.HAPI_INCLUDE_PARTITION_IDS_IN_PKS + "=true" }) @DirtiesContext(classMode = DirtiesContext.ClassMode.AFTER_CLASS) -class ResourceTableFKProviderTest extends BaseJpaR4Test { - private static final Logger ourLog = LoggerFactory.getLogger(ResourceTableFKProviderTest.class); +class ResourceTableFKProviderIT extends BaseJpaR4Test { + private static final Logger ourLog = LoggerFactory.getLogger(ResourceTableFKProviderIT.class); @PersistenceContext(type = PersistenceContextType.TRANSACTION) protected EntityManager myEntityManager; diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java index 3de4d680d9d2..70c6c8b471f5 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/dao/r4/FhirResourceDaoR4ValidateTest.java @@ -32,6 +32,7 @@ import ca.uhn.fhir.util.OperationOutcomeUtil; import ca.uhn.fhir.util.StopWatch; import ca.uhn.fhir.validation.IValidatorModule; +import ca.uhn.test.util.LogbackTestExtension; import ca.uhn.test.util.LogbackTestExtensionAssert; import ch.qos.logback.classic.Level; import org.apache.commons.io.IOUtils; @@ -85,6 +86,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Nested; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.CsvSource; import org.springframework.beans.factory.annotation.Autowired; @@ -128,6 +130,9 @@ public class FhirResourceDaoR4ValidateTest extends BaseJpaR4Test { @Autowired private InMemoryTerminologyServerValidationSupport myInMemoryTerminologyServerValidationSupport; + @RegisterExtension + public LogbackTestExtension myLogbackTestExtension = new LogbackTestExtension(); + @AfterEach public void after() { FhirInstanceValidator val = AopTestUtils.getTargetObject(myValidatorModule); @@ -1495,8 +1500,6 @@ public void validateResource_withUnknownMetaProfileurl_validatesButLogsWarning() // setup IParser parser = myFhirContext.newJsonParser(); - myLogbackTestExtension.setUp(Level.WARN); - String obsStr =""" { "resourceType": "Observation", diff --git a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/subscription/async/AsyncSubscriptionMessageSubmissionIT.java b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/subscription/async/AsyncSubscriptionMessageSubmissionIT.java index 923657ae47a0..4eadff8ed7d7 100644 --- a/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/subscription/async/AsyncSubscriptionMessageSubmissionIT.java +++ b/hapi-fhir-jpaserver-test-r4/src/test/java/ca/uhn/fhir/jpa/subscription/async/AsyncSubscriptionMessageSubmissionIT.java @@ -17,6 +17,7 @@ import ca.uhn.fhir.jpa.subscription.submit.interceptor.SynchronousSubscriptionMatcherInterceptor; import ca.uhn.fhir.jpa.test.util.StoppableSubscriptionDeliveringRestHookSubscriber; import ca.uhn.fhir.rest.api.server.SystemRequestDetails; +import ca.uhn.test.util.LogbackTestExtension; import ch.qos.logback.classic.Level; import ch.qos.logback.classic.spi.ILoggingEvent; import com.fasterxml.jackson.core.JsonProcessingException; @@ -28,6 +29,7 @@ import org.junit.jupiter.api.AfterEach; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.extension.RegisterExtension; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; @@ -66,6 +68,9 @@ public class AsyncSubscriptionMessageSubmissionIT extends BaseSubscriptionsR4Tes @Autowired private IResourceModifiedDao myResourceModifiedDao; + @RegisterExtension + public LogbackTestExtension myLogbackTestExtension = new LogbackTestExtension(AsyncResourceModifiedSubmitterSvc.class.getName(), Level.DEBUG); + @AfterEach public void cleanupStoppableSubscriptionDeliveringRestHookSubscriber() { myStoppableSubscriptionDeliveringRestHookSubscriber.setCountDownLatch(null); @@ -93,8 +98,6 @@ public void testSpringInjects_BeanOfTypeSubscriptionMatchingInterceptor_whenBean @Test public void runDeliveryPass_withManyResources_isBatchedAndKeepsResourceUsageDown() throws JsonProcessingException, InterruptedException { // setup - myLogbackTestExtension.setUp(Level.DEBUG); - String resourceType = "Patient"; int factor = 5; int numberOfResourcesToCreate = factor * AsyncResourceModifiedSubmitterSvc.MAX_LIMIT; diff --git a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaR4Test.java b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaR4Test.java index 036ebc64dc1c..07c5ec73a5b3 100644 --- a/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaR4Test.java +++ b/hapi-fhir-jpaserver-test-utilities/src/main/java/ca/uhn/fhir/jpa/test/BaseJpaR4Test.java @@ -563,9 +563,6 @@ public abstract class BaseJpaR4Test extends BaseJpaTest implements ITestDataBuil @RegisterExtension private final PreventDanglingInterceptorsExtension myPreventDanglingInterceptorsExtension = new PreventDanglingInterceptorsExtension(()-> myInterceptorRegistry); - @RegisterExtension - public LogbackTestExtension myLogbackTestExtension = new LogbackTestExtension(); - @AfterEach() @Order(0) public void afterCleanupDao() { diff --git a/hapi-fhir-test-utilities/src/main/java/ca/uhn/test/util/LogbackTestExtension.java b/hapi-fhir-test-utilities/src/main/java/ca/uhn/test/util/LogbackTestExtension.java index 40ae0c21d6ad..71fb42ec035d 100644 --- a/hapi-fhir-test-utilities/src/main/java/ca/uhn/test/util/LogbackTestExtension.java +++ b/hapi-fhir-test-utilities/src/main/java/ca/uhn/test/util/LogbackTestExtension.java @@ -24,6 +24,7 @@ import ch.qos.logback.classic.spi.ILoggingEvent; import ch.qos.logback.core.read.ListAppender; import jakarta.annotation.Nonnull; +import org.apache.commons.lang3.Validate; import org.junit.jupiter.api.extension.AfterEachCallback; import org.junit.jupiter.api.extension.BeforeEachCallback; import org.junit.jupiter.api.extension.ExtensionContext; @@ -39,7 +40,7 @@ */ public class LogbackTestExtension implements BeforeEachCallback, AfterEachCallback { private final Logger myLogger; - private final Level myLevel; + private Level myLevel; private ListAppender myListAppender = null; private Level mySavedLevel; @@ -77,6 +78,13 @@ public LogbackTestExtension(org.slf4j.Logger theLogger) { this((Logger) theLogger); } + /** + * Sets the root logger to the given level + */ + public LogbackTestExtension(Level theLevel) { + this(org.slf4j.Logger.ROOT_LOGGER_NAME, theLevel); + } + /** * Returns a copy to avoid concurrent modification errors. * @return A copy of the log events so far. @@ -102,10 +110,17 @@ public void setUp() { setUp(myLevel); } + /** + * @deprecated Just use the constructor here + */ + @Deprecated public void setUp(Level theLevel) { - myListAppender = new ListAppender<>(); - myListAppender.start(); - myLogger.addAppender(myListAppender); + myLevel = theLevel; + if (myListAppender == null) { + myListAppender = new ListAppender<>(); + myListAppender.start(); + myLogger.addAppender(myListAppender); + } if (theLevel != null) { mySavedLevel = myLogger.getLevel(); myLogger.setLevel(theLevel); @@ -118,6 +133,7 @@ public void afterEach(ExtensionContext context) throws Exception { myListAppender.stop(); if (myLevel != null) { myLogger.setLevel(mySavedLevel); + myLevel = null; } }