From 728bf23d5111ea75e0062b5e4f532393f408b283 Mon Sep 17 00:00:00 2001 From: Cliff Casey Date: Mon, 20 Jul 2026 17:10:47 -0400 Subject: [PATCH 1/2] chatty test log exceptions suppressed --- .../com/yetanalytics/ConfigParserTest.java | 28 +++++++++++++++ .../com/yetanalytics/TestLoggingUtils.java | 35 +++++++++++++++++++ .../yetanalytics/hlaxapi/XapiClientTest.java | 28 ++++++++++++++- .../injection/XapiValueGeneratorTest.java | 26 ++++++++++++++ 4 files changed, 116 insertions(+), 1 deletion(-) create mode 100644 src/test/java/com/yetanalytics/TestLoggingUtils.java diff --git a/src/test/java/com/yetanalytics/ConfigParserTest.java b/src/test/java/com/yetanalytics/ConfigParserTest.java index 1a67e15..0831684 100644 --- a/src/test/java/com/yetanalytics/ConfigParserTest.java +++ b/src/test/java/com/yetanalytics/ConfigParserTest.java @@ -16,11 +16,17 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; +import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.io.TempDir; import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; @@ -51,12 +57,30 @@ import hla.rti1516e.ParameterHandleValueMap; import hla.rti1516e.encoding.ByteWrapper; +import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; +import static com.yetanalytics.TestLoggingUtils.suppressLogs; + public class ConfigParserTest { private static final Logger logger = LogManager.getLogger(ConfigParserTest.class); final static String CONFIG_STATEMENT_RESULT = "{\"actor\":{\"objectType\":\"Agent\",\"name\":\"c5988e0e-c521-4ff7-ba83-df1a63eb72bf\",\"account\":{\"homePage\":\"https://homepage.system.io\",\"name\":\"Mr. c5988e0e-c521-4ff7-ba83-df1a63eb72bf\"}},\"context\":{\"extensions\":{\"https://yetanalytics.com/extensions/from-x\":4,\"https://yetanalytics.com/extensions/from-y\":12}},\"result\":{\"response\":\"[5, 13]\"}}"; + private Map originalLevels; + @BeforeEach + public void silenceLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS + originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.TriggerProcessor")); + } + } + @AfterEach + public void resetLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + setLogLevelsByClass(originalLevels); + } + } + @Test public void parsesConfigFile() throws IOException { XapiConfig config = ConfigParser.fromFile("src/test/resources/config-test.json").parse(); @@ -473,6 +497,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test + @Tag("SuppressLogs") public void lookupInjectionMissingObjectHonorsRequiredOption() { InjectionHandler ih = new InjectionHandler() { @Override @@ -500,6 +525,7 @@ public Optional resolveLookup(ObjectLookup lookup, InjectionContex } @Test + @Tag("SuppressLogs") public void lookupInjectionMissingValueHonorsRequiredButNotNullable() { CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity"); InjectionHandler ih = new InjectionHandler() { @@ -535,6 +561,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test + @Tag("SuppressLogs") public void lookupInjectionPresentNullAbortsByDefaultAndRendersWhenNullable() { CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity"); InjectionHandler ih = new InjectionHandler() { @@ -576,6 +603,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test + @Tag("SuppressLogs") public void queryAndThisMissingValuesHonorRequiredOption() { InjectionHandler ih = new InjectionHandler() { @Override diff --git a/src/test/java/com/yetanalytics/TestLoggingUtils.java b/src/test/java/com/yetanalytics/TestLoggingUtils.java new file mode 100644 index 0000000..9eba4db --- /dev/null +++ b/src/test/java/com/yetanalytics/TestLoggingUtils.java @@ -0,0 +1,35 @@ +package com.yetanalytics; + +import java.util.HashMap; +import java.util.Map; +import java.util.Set; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.Configurator; + +public class TestLoggingUtils { + + public static Map suppressLogs(String targetClass) { + return suppressLogs(Set.of(targetClass)); + } + + public static Map suppressLogs(Set targetClasses) { + LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + Configuration config = ctx.getConfiguration(); + Map originalLevels = new HashMap(); + for(String targetClass : targetClasses){ + Level originalLevel = config.getLoggerConfig(targetClass).getLevel(); + originalLevels.put(targetClass, originalLevel); + Configurator.setLevel(targetClass, Level.OFF); + } + return originalLevels; + } + + public static void setLogLevelsByClass(Map levels) { + Configurator.setLevel(levels); + } + +} diff --git a/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java b/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java index df939bd..a14446c 100644 --- a/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java +++ b/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java @@ -8,9 +8,16 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; +import java.util.Map; +import java.util.Set; import java.util.UUID; +import org.apache.logging.log4j.Level; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import com.yetanalytics.hlaxapi.config.XapiConfig; import com.yetanalytics.hlaxapi.config.model.LrsConfig; @@ -20,6 +27,8 @@ import com.yetanalytics.xapi.exception.StatementClientException; import com.yetanalytics.xapi.model.Statement; import com.yetanalytics.xapi.util.StatementValidator; +import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; +import static com.yetanalytics.TestLoggingUtils.suppressLogs; class XapiClientTest { @@ -57,6 +66,20 @@ class XapiClientTest { } """; + private Map originalLevels; + @BeforeEach + public void silenceLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS + originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.XapiClient")); + } + } + @AfterEach + public void resetLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + setLogLevelsByClass(originalLevels); + } + } @Test void buffersStatementFromJsonString() throws Exception { @@ -68,13 +91,14 @@ void buffersStatementFromJsonString() throws Exception { } @Test + @Tag("SuppressLogs") void rejectsInvalidStatementJson() { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); - assertThrows(StatementValidationException.class, () -> xapiClient.sendStatement("{")); } @Test + @Tag("SuppressLogs") void rejectsInvalidStatementXApi() { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); @@ -101,6 +125,7 @@ void clearBufferPostsBufferedStatementsAndClearsBuffer() throws Exception { } @Test + @Tag("SuppressLogs") void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Exception { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); FakeStatementClient fakeClient = new FakeStatementClient(); @@ -116,6 +141,7 @@ void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Excepti } @Test + @Tag("SuppressLogs") void clearBufferClearsStatementsAfterMaxRetries() throws Exception { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); FakeStatementClient fakeClient = new FakeStatementClient(); diff --git a/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java b/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java index 6d76ab6..381d91b 100644 --- a/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java +++ b/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java @@ -20,11 +20,36 @@ import com.yetanalytics.xapi.util.StatementValidator.StatementValidationResult; import java.util.List; +import java.util.Map; +import java.util.Set; + +import org.apache.logging.log4j.Level; +import org.junit.jupiter.api.AfterEach; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.TestInfo; import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; +import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; +import static com.yetanalytics.TestLoggingUtils.suppressLogs; class XapiValueGeneratorTest { + private Map originalLevels; + @BeforeEach + public void silenceLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS + originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.TriggerProcessor")); + } + } + @AfterEach + public void resetLogs(TestInfo testInfo) { + if (testInfo.getTags().contains("SuppressLogs")) { + setLogLevelsByClass(originalLevels); + } + } + @Test void usesPresetUriForObjectIdPaths() { InjectionContext ctx = new InjectionContext() {}; @@ -215,6 +240,7 @@ private record XapiValidationTestEntry (String statement, InjectionContext ic, b ); @Test + @Tag("SuppressLogs") void validationInjectionTests() { SimulationConfig simConfig = new SimulationConfig(null, null, null, null, "config/HlaFedereplFOM.xml"); From 9f7219a409eda67e331ee7099a4c14acff15aa60 Mon Sep 17 00:00:00 2001 From: Cliff Casey Date: Mon, 20 Jul 2026 23:08:20 -0400 Subject: [PATCH 2/2] much better way to organize this --- .../com/yetanalytics/ConfigParserTest.java | 33 ++----------- .../com/yetanalytics/TestLoggingUtils.java | 35 -------------- .../extension/SuppressTestLogging.java | 14 ++++++ .../SuppressTestLoggingExtension.java | 48 +++++++++++++++++++ .../yetanalytics/hlaxapi/XapiClientTest.java | 33 ++----------- .../injection/XapiValueGeneratorTest.java | 38 ++++----------- 6 files changed, 80 insertions(+), 121 deletions(-) delete mode 100644 src/test/java/com/yetanalytics/TestLoggingUtils.java create mode 100644 src/test/java/com/yetanalytics/extension/SuppressTestLogging.java create mode 100644 src/test/java/com/yetanalytics/extension/SuppressTestLoggingExtension.java diff --git a/src/test/java/com/yetanalytics/ConfigParserTest.java b/src/test/java/com/yetanalytics/ConfigParserTest.java index 0831684..2b2a5df 100644 --- a/src/test/java/com/yetanalytics/ConfigParserTest.java +++ b/src/test/java/com/yetanalytics/ConfigParserTest.java @@ -16,20 +16,15 @@ import java.util.List; import java.util.Map; import java.util.Optional; -import java.util.Set; import java.util.concurrent.atomic.AtomicInteger; -import org.apache.logging.log4j.Level; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; import org.junit.jupiter.api.io.TempDir; import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; +import com.yetanalytics.extension.SuppressTestLogging; import com.yetanalytics.hlaxapi.FOMXML; import com.yetanalytics.hlaxapi.HLADecoderRegistry; import com.yetanalytics.hlaxapi.HLAEncodingTestSupport; @@ -57,30 +52,12 @@ import hla.rti1516e.ParameterHandleValueMap; import hla.rti1516e.encoding.ByteWrapper; -import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; -import static com.yetanalytics.TestLoggingUtils.suppressLogs; - public class ConfigParserTest { private static final Logger logger = LogManager.getLogger(ConfigParserTest.class); final static String CONFIG_STATEMENT_RESULT = "{\"actor\":{\"objectType\":\"Agent\",\"name\":\"c5988e0e-c521-4ff7-ba83-df1a63eb72bf\",\"account\":{\"homePage\":\"https://homepage.system.io\",\"name\":\"Mr. c5988e0e-c521-4ff7-ba83-df1a63eb72bf\"}},\"context\":{\"extensions\":{\"https://yetanalytics.com/extensions/from-x\":4,\"https://yetanalytics.com/extensions/from-y\":12}},\"result\":{\"response\":\"[5, 13]\"}}"; - private Map originalLevels; - @BeforeEach - public void silenceLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS - originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.TriggerProcessor")); - } - } - @AfterEach - public void resetLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - setLogLevelsByClass(originalLevels); - } - } - @Test public void parsesConfigFile() throws IOException { XapiConfig config = ConfigParser.fromFile("src/test/resources/config-test.json").parse(); @@ -497,7 +474,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"}) public void lookupInjectionMissingObjectHonorsRequiredOption() { InjectionHandler ih = new InjectionHandler() { @Override @@ -525,7 +502,7 @@ public Optional resolveLookup(ObjectLookup lookup, InjectionContex } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"}) public void lookupInjectionMissingValueHonorsRequiredButNotNullable() { CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity"); InjectionHandler ih = new InjectionHandler() { @@ -561,7 +538,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"}) public void lookupInjectionPresentNullAbortsByDefaultAndRendersWhenNullable() { CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity"); InjectionHandler ih = new InjectionHandler() { @@ -603,7 +580,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"}) public void queryAndThisMissingValuesHonorRequiredOption() { InjectionHandler ih = new InjectionHandler() { @Override diff --git a/src/test/java/com/yetanalytics/TestLoggingUtils.java b/src/test/java/com/yetanalytics/TestLoggingUtils.java deleted file mode 100644 index 9eba4db..0000000 --- a/src/test/java/com/yetanalytics/TestLoggingUtils.java +++ /dev/null @@ -1,35 +0,0 @@ -package com.yetanalytics; - -import java.util.HashMap; -import java.util.Map; -import java.util.Set; - -import org.apache.logging.log4j.Level; -import org.apache.logging.log4j.LogManager; -import org.apache.logging.log4j.core.LoggerContext; -import org.apache.logging.log4j.core.config.Configuration; -import org.apache.logging.log4j.core.config.Configurator; - -public class TestLoggingUtils { - - public static Map suppressLogs(String targetClass) { - return suppressLogs(Set.of(targetClass)); - } - - public static Map suppressLogs(Set targetClasses) { - LoggerContext ctx = (LoggerContext) LogManager.getContext(false); - Configuration config = ctx.getConfiguration(); - Map originalLevels = new HashMap(); - for(String targetClass : targetClasses){ - Level originalLevel = config.getLoggerConfig(targetClass).getLevel(); - originalLevels.put(targetClass, originalLevel); - Configurator.setLevel(targetClass, Level.OFF); - } - return originalLevels; - } - - public static void setLogLevelsByClass(Map levels) { - Configurator.setLevel(levels); - } - -} diff --git a/src/test/java/com/yetanalytics/extension/SuppressTestLogging.java b/src/test/java/com/yetanalytics/extension/SuppressTestLogging.java new file mode 100644 index 0000000..5f784ef --- /dev/null +++ b/src/test/java/com/yetanalytics/extension/SuppressTestLogging.java @@ -0,0 +1,14 @@ +package com.yetanalytics.extension; + +import java.lang.annotation.ElementType; +import java.lang.annotation.Retention; +import java.lang.annotation.RetentionPolicy; +import java.lang.annotation.Target; +import org.junit.jupiter.api.extension.ExtendWith; + +@Target(ElementType.METHOD) +@Retention(RetentionPolicy.RUNTIME) +@ExtendWith(SuppressTestLoggingExtension.class) +public @interface SuppressTestLogging { + String[] value(); +} diff --git a/src/test/java/com/yetanalytics/extension/SuppressTestLoggingExtension.java b/src/test/java/com/yetanalytics/extension/SuppressTestLoggingExtension.java new file mode 100644 index 0000000..bae382b --- /dev/null +++ b/src/test/java/com/yetanalytics/extension/SuppressTestLoggingExtension.java @@ -0,0 +1,48 @@ +package com.yetanalytics.extension; + +import java.util.HashMap; +import java.util.Map; +import java.util.Optional; + +import org.apache.logging.log4j.Level; +import org.apache.logging.log4j.LogManager; +import org.apache.logging.log4j.core.LoggerContext; +import org.apache.logging.log4j.core.config.Configuration; +import org.apache.logging.log4j.core.config.Configurator; +import org.junit.jupiter.api.extension.AfterTestExecutionCallback; +import org.junit.jupiter.api.extension.BeforeTestExecutionCallback; +import org.junit.jupiter.api.extension.ExtensionContext; + +public class SuppressTestLoggingExtension implements BeforeTestExecutionCallback, AfterTestExecutionCallback { + + private Map originalLevels; + + @Override + public void beforeTestExecution(ExtensionContext context) throws Exception { + // If a Test has this annotation, get any declared classes and store their current log level + // in originalLevels and then turn them off + LoggerContext ctx = (LoggerContext) LogManager.getContext(false); + Configuration config = ctx.getConfiguration(); + originalLevels = new HashMap(); + getAnnotation(context).ifPresent(annotation -> { + String[] targetClasses = annotation.value(); + for(int i = 0; i < targetClasses.length; i++) { + String targetClass = targetClasses[i]; + Level originalLevel = config.getLoggerConfig(targetClass).getLevel(); + originalLevels.put(targetClass, originalLevel); + Configurator.setLevel(targetClass, Level.OFF); + } + }); + } + + @Override + public void afterTestExecution(ExtensionContext context) throws Exception { + // Return everything to normal + Configurator.setLevel(originalLevels); + } + + private Optional getAnnotation(ExtensionContext context) { + return context.getTestMethod().map(method -> method.getAnnotation(SuppressTestLogging.class)); + } + +} diff --git a/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java b/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java index a14446c..4b242e2 100644 --- a/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java +++ b/src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java @@ -8,17 +8,11 @@ import java.lang.reflect.Method; import java.util.ArrayList; import java.util.List; -import java.util.Map; -import java.util.Set; import java.util.UUID; -import org.apache.logging.log4j.Level; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; +import com.yetanalytics.extension.SuppressTestLogging; import com.yetanalytics.hlaxapi.config.XapiConfig; import com.yetanalytics.hlaxapi.config.model.LrsConfig; import com.yetanalytics.hlaxapi.exception.StatementValidationException; @@ -27,8 +21,6 @@ import com.yetanalytics.xapi.exception.StatementClientException; import com.yetanalytics.xapi.model.Statement; import com.yetanalytics.xapi.util.StatementValidator; -import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; -import static com.yetanalytics.TestLoggingUtils.suppressLogs; class XapiClientTest { @@ -66,21 +58,6 @@ class XapiClientTest { } """; - private Map originalLevels; - @BeforeEach - public void silenceLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS - originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.XapiClient")); - } - } - @AfterEach - public void resetLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - setLogLevelsByClass(originalLevels); - } - } - @Test void buffersStatementFromJsonString() throws Exception { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); @@ -91,14 +68,14 @@ void buffersStatementFromJsonString() throws Exception { } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"}) void rejectsInvalidStatementJson() { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); assertThrows(StatementValidationException.class, () -> xapiClient.sendStatement("{")); } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"}) void rejectsInvalidStatementXApi() { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); @@ -125,7 +102,7 @@ void clearBufferPostsBufferedStatementsAndClearsBuffer() throws Exception { } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"}) void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Exception { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); FakeStatementClient fakeClient = new FakeStatementClient(); @@ -141,7 +118,7 @@ void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Excepti } @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"}) void clearBufferClearsStatementsAfterMaxRetries() throws Exception { XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator()); FakeStatementClient fakeClient = new FakeStatementClient(); diff --git a/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java b/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java index 381d91b..80fda73 100644 --- a/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java +++ b/src/test/java/com/yetanalytics/hlaxapi/injection/XapiValueGeneratorTest.java @@ -7,6 +7,12 @@ import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertTrue; +import java.util.List; + +import org.junit.jupiter.api.Test; +import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; + +import com.yetanalytics.extension.SuppressTestLogging; import com.yetanalytics.hlaxapi.FOMXML; import com.yetanalytics.hlaxapi.HLADecoderRegistry; import com.yetanalytics.hlaxapi.InjectionHandler; @@ -14,42 +20,14 @@ import com.yetanalytics.hlaxapi.TriggerProcessor; import com.yetanalytics.hlaxapi.TriggerProcessor.TriggerProcessingResult; import com.yetanalytics.hlaxapi.config.model.StatementTrigger; -import com.yetanalytics.hlaxapi.config.model.Target; import com.yetanalytics.hlaxapi.config.model.StatementTrigger.Type; +import com.yetanalytics.hlaxapi.config.model.Target; import com.yetanalytics.xapi.util.StatementValidator; import com.yetanalytics.xapi.util.StatementValidator.StatementValidationResult; -import java.util.List; -import java.util.Map; -import java.util.Set; - -import org.apache.logging.log4j.Level; -import org.junit.jupiter.api.AfterEach; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Tag; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.TestInfo; -import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory; -import static com.yetanalytics.TestLoggingUtils.setLogLevelsByClass; -import static com.yetanalytics.TestLoggingUtils.suppressLogs; class XapiValueGeneratorTest { - private Map originalLevels; - @BeforeEach - public void silenceLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - // TURNS OFF ERROR LOGGING DURING TEST RUNS. REMOVE TO ENABLE LOGS - originalLevels = suppressLogs(Set.of("com.yetanalytics.hlaxapi.TriggerProcessor")); - } - } - @AfterEach - public void resetLogs(TestInfo testInfo) { - if (testInfo.getTags().contains("SuppressLogs")) { - setLogLevelsByClass(originalLevels); - } - } - @Test void usesPresetUriForObjectIdPaths() { InjectionContext ctx = new InjectionContext() {}; @@ -240,7 +218,7 @@ private record XapiValidationTestEntry (String statement, InjectionContext ic, b ); @Test - @Tag("SuppressLogs") + @SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"}) void validationInjectionTests() { SimulationConfig simConfig = new SimulationConfig(null, null, null, null, "config/HlaFedereplFOM.xml");