Skip to content
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
import ca.uhn.test.util.LogbackCaptureTestExtension;
import ch.qos.logback.classic.Level;
import org.hamcrest.MatcherAssert;
import org.hamcrest.Matchers;
import org.hl7.fhir.instance.model.api.IBaseResource;
import org.hl7.fhir.instance.model.api.IIdType;
import org.junit.jupiter.api.BeforeEach;
Expand Down Expand Up @@ -260,10 +259,6 @@ private void stubMatcherCall(String expectedQuery, IBaseResource theTargetResour

@Nested
public class MisconfigurationChecks {


// wipjv check for unsupported params during CdrAuthInterceptor scopes->perms translation.

/**
* in case an unsupported perm snuck through the front door.
* Each scope provides positive perm, so unsupported means we can't vote yes. Abstain.
Expand Down Expand Up @@ -321,7 +316,6 @@ public void noMatcherService_unsupportedPerm_noVerdict() {
}

}
// wipjv how to test the difference between patient/*.rs?code=foo and patient/Observation.rs?code=foo?
// We need the builder to set AppliesTypeEnum, and the use that to build the matcher expression.

private AuthorizationInterceptor.Verdict applyRuleToResource(IBaseResource theResource) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -234,7 +234,7 @@ private <T> T doExecuteInTransaction(ExecutionBuilder theExecutionBuilder, Trans
ExceptionUtils.indexOfThrowable(e, DataIntegrityViolationException.class) != -1 ||
ExceptionUtils.indexOfThrowable(e, ConstraintViolationException.class) != -1 ||
ExceptionUtils.indexOfThrowable(e, ObjectOptimisticLockingFailureException.class) != -1)) {
ourLog.error("Unexpected transaction exception. Will not be retried.", e);
ourLog.debug("Unexpected transaction exception. Will not be retried.", e);
throw e;
} else {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,15 +23,13 @@
import ch.qos.logback.classic.Logger;
import ch.qos.logback.classic.spi.ILoggingEvent;
import ch.qos.logback.core.read.ListAppender;
import org.hamcrest.CustomTypeSafeMatcher;
import org.hamcrest.Matcher;
import org.junit.jupiter.api.extension.AfterEachCallback;
import org.junit.jupiter.api.extension.BeforeEachCallback;
import org.junit.jupiter.api.extension.ExtensionContext;
import org.slf4j.LoggerFactory;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;
import java.util.ArrayList;
import java.util.List;
import java.util.function.Predicate;
Expand Down Expand Up @@ -159,42 +157,11 @@ public static Matcher<ILoggingEvent> eventWithMessageContains(@Nonnull String th
return new LogbackEventMatcher(null, thePartialMessage);
}

/**
* A Hamcrest matcher for junit assertions.
* Matches on level and/or partial message.
*/
public static class LogbackEventMatcher extends CustomTypeSafeMatcher<ILoggingEvent> {
@Nullable
private final Level myLevel;
@Nullable
private final String myString;

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString) {
this("log event", theLevel, thePartialString);
}

public LogbackEventMatcher(String description, @Nullable Level theLevel, @Nullable String thePartialString) {
super(makeDescription(description, theLevel, thePartialString));
myLevel = theLevel;
myString = thePartialString;
}
@Nonnull
private static String makeDescription(String description, Level theLevel, String thePartialString) {
String msg = description;
if (theLevel != null) {
msg = msg + " with level at least " + theLevel;
}
if (thePartialString != null) {
msg = msg + " containing string \"" + thePartialString + "\"";

}
return msg;
}

@Override
protected boolean matchesSafely(ILoggingEvent item) {
return (myLevel == null || item.getLevel().isGreaterOrEqual(myLevel)) &&
(myString == null || item.getFormattedMessage().contains(myString));
}
public static Matcher<ILoggingEvent> eventWithLevelAndMessageAndThrew(@Nonnull Level theLevel,
@Nonnull String thePartialMessage,
@Nonnull String theThrown)
{
return new LogbackEventMatcher(theLevel, thePartialMessage, theThrown);
}

}
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package ca.uhn.test.util;

import ch.qos.logback.classic.Level;
import ch.qos.logback.classic.spi.ILoggingEvent;
import org.hamcrest.CustomTypeSafeMatcher;

import javax.annotation.Nonnull;
import javax.annotation.Nullable;

/**
* A Hamcrest matcher for junit assertions.
* Matches on level, partial message, and/or a portion of the message contained by a throwable, if present.
*/
public class LogbackEventMatcher extends CustomTypeSafeMatcher<ILoggingEvent> {
@Nullable
private final Level myLevel;
@Nullable
private final String myLogMessage;
@Nullable
private final String myThrownMessage;

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString) {
this("log event", theLevel, thePartialString, null);
}

public LogbackEventMatcher(@Nullable Level theLevel, @Nullable String thePartialString, @Nullable String theThrownMessage) {
this("log event", theLevel, thePartialString, theThrownMessage);
}

private LogbackEventMatcher(String description, @Nullable Level theLevel,
@Nullable String thePartialString, @Nullable String theThrownMessage)
{
super(makeDescription(description, theLevel, thePartialString, theThrownMessage));
myLevel = theLevel;
myLogMessage = thePartialString;
myThrownMessage = theThrownMessage;
}

@Nonnull
private static String makeDescription(String description, Level theLevel, String thePartialString, String theThrownMessage) {
String msg = description;
if (theLevel != null) {
msg = msg + " with level at least " + theLevel;
}
if (thePartialString != null) {
msg = msg + " containing string \"" + thePartialString + "\"";

}
if (thePartialString != null) {
msg = msg + " and throwable with error message containing string \"" + theThrownMessage + "\"";

}
return msg;
}

@Override
protected boolean matchesSafely(ILoggingEvent item) {
return (myLevel == null || item.getLevel().isGreaterOrEqual(myLevel)) &&
(myLogMessage == null || item.getFormattedMessage().contains(myLogMessage)) &&
(myThrownMessage == null || item.getThrowableProxy() == null || item.getThrowableProxy().getMessage().contains(myThrownMessage));
}
}