Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions src/test/java/com/yetanalytics/ConfigParserTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
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;
Expand Down Expand Up @@ -473,6 +474,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"})
public void lookupInjectionMissingObjectHonorsRequiredOption() {
InjectionHandler ih = new InjectionHandler() {
@Override
Expand Down Expand Up @@ -500,6 +502,7 @@ public Optional<CachedObject> resolveLookup(ObjectLookup lookup, InjectionContex
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"})
public void lookupInjectionMissingValueHonorsRequiredButNotNullable() {
CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity");
InjectionHandler ih = new InjectionHandler() {
Expand Down Expand Up @@ -535,6 +538,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"})
public void lookupInjectionPresentNullAbortsByDefaultAndRendersWhenNullable() {
CachedObject matchedObject = new CachedObject(7, "object-7", "Predator", "SimEntity");
InjectionHandler ih = new InjectionHandler() {
Expand Down Expand Up @@ -576,6 +580,7 @@ public ValueResolution handleLookup(CachedObject object, Target attrTarget, Inje
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"})
public void queryAndThisMissingValuesHonorRequiredOption() {
InjectionHandler ih = new InjectionHandler() {
@Override
Expand Down
14 changes: 14 additions & 0 deletions src/test/java/com/yetanalytics/extension/SuppressTestLogging.java
Original file line number Diff line number Diff line change
@@ -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();
}
Original file line number Diff line number Diff line change
@@ -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<String, Level> 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<String, Level>();
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<SuppressTestLogging> getAnnotation(ExtensionContext context) {
return context.getTestMethod().map(method -> method.getAnnotation(SuppressTestLogging.class));
}

}
7 changes: 5 additions & 2 deletions src/test/java/com/yetanalytics/hlaxapi/XapiClientTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@

import org.junit.jupiter.api.Test;

import com.yetanalytics.extension.SuppressTestLogging;
import com.yetanalytics.hlaxapi.config.XapiConfig;
import com.yetanalytics.hlaxapi.config.model.LrsConfig;
import com.yetanalytics.hlaxapi.exception.StatementValidationException;
Expand Down Expand Up @@ -57,7 +58,6 @@ class XapiClientTest {
}
""";


@Test
void buffersStatementFromJsonString() throws Exception {
XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator());
Expand All @@ -68,13 +68,14 @@ void buffersStatementFromJsonString() throws Exception {
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"})
void rejectsInvalidStatementJson() {
XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator());

assertThrows(StatementValidationException.class, () -> xapiClient.sendStatement("{"));
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"})
void rejectsInvalidStatementXApi() {
XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator());

Expand All @@ -101,6 +102,7 @@ void clearBufferPostsBufferedStatementsAndClearsBuffer() throws Exception {
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"})
void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Exception {
XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator());
FakeStatementClient fakeClient = new FakeStatementClient();
Expand All @@ -116,6 +118,7 @@ void clearBufferKeepsStatementsWhenClientErrorsBeforeMaxRetries() throws Excepti
}

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.XapiClient"})
void clearBufferClearsStatementsAfterMaxRetries() throws Exception {
XapiClient xapiClient = new XapiClient(config(4, 1), new StatementValidator());
FakeStatementClient fakeClient = new FakeStatementClient();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,21 +7,24 @@
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;
import com.yetanalytics.hlaxapi.SimulationConfig;
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 org.junit.jupiter.api.Test;
import org.portico.impl.hla1516e.types.encoding.HLA1516eEncoderFactory;

class XapiValueGeneratorTest {

Expand Down Expand Up @@ -215,6 +218,7 @@ private record XapiValidationTestEntry (String statement, InjectionContext ic, b
);

@Test
@SuppressTestLogging({"com.yetanalytics.hlaxapi.TriggerProcessor"})
void validationInjectionTests() {
SimulationConfig simConfig = new SimulationConfig(null, null, null, null,
"config/HlaFedereplFOM.xml");
Expand Down
Loading