Skip to content

Commit

Permalink
Work on tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jamesagnew committed Oct 3, 2024
1 parent 380c004 commit 312e692
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -1495,8 +1500,6 @@ public void validateResource_withUnknownMetaProfileurl_validatesButLogsWarning()
// setup
IParser parser = myFhirContext.newJsonParser();

myLogbackTestExtension.setUp(Level.WARN);

String obsStr ="""
{
"resourceType": "Observation",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -39,7 +40,7 @@
*/
public class LogbackTestExtension implements BeforeEachCallback, AfterEachCallback {
private final Logger myLogger;
private final Level myLevel;
private Level myLevel;
private ListAppender<ILoggingEvent> myListAppender = null;
private Level mySavedLevel;

Expand Down Expand Up @@ -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.
Expand All @@ -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);
Expand All @@ -118,6 +133,7 @@ public void afterEach(ExtensionContext context) throws Exception {
myListAppender.stop();
if (myLevel != null) {
myLogger.setLevel(mySavedLevel);
myLevel = null;
}
}

Expand Down

0 comments on commit 312e692

Please sign in to comment.