Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

updating RegressionTest generateAnswers for when two classes are used for test .dat & answer files #821

Merged
Merged
Show file tree
Hide file tree
Changes from 3 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
7 changes: 6 additions & 1 deletion src/test/java/emissary/test/core/junit5/RegressionTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -301,7 +301,12 @@ protected void generateAnswerFiles(final String resource) throws Exception {
tweakFinalLogEventsBeforeSerialisation(resource, finalLogEvents);

// Generate the full XML (setup & answers from before & after)
RegressionTestUtil.writeAnswerXml(resource, initialIbdo, finalIbdo, finalResults, finalLogEvents, getEncoders());
if (super.answerFileClassRef == null) {
RegressionTestUtil.writeAnswerXml(resource, initialIbdo, finalIbdo, finalResults, finalLogEvents, getEncoders());
} else {
RegressionTestUtil.writeAnswerXml(resource, initialIbdo, finalIbdo, finalResults, finalLogEvents, getEncoders(),
super.answerFileClassRef);
}
}

@Override
Expand Down
29 changes: 28 additions & 1 deletion src/test/java/emissary/test/core/junit5/RegressionTestUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.concurrent.atomic.AtomicReference;
import javax.annotation.Nullable;

import static emissary.core.constants.IbdoXmlElementNames.ANSWERS;
Expand Down Expand Up @@ -95,6 +96,8 @@ public final class RegressionTestUtil {
*/
private static final Path TEST_RESX = getTestResx();

private static AtomicReference<Class<?>> answerFileClassRef = null;
drivenflywheel marked this conversation as resolved.
Show resolved Hide resolved

private RegressionTestUtil() {}

/**
Expand Down Expand Up @@ -200,7 +203,14 @@ public static Path getXmlPath(final String resource) {
return null;
}

final String xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX;
String xmlPath;
if (answerFileClassRef == null) {
xmlPath = resource.substring(0, datPos) + ResourceReader.XML_SUFFIX;
} else {
String ansPath = answerFileClassRef.get().getName().replace(".", "/");
int testNamePos = resource.lastIndexOf("/");
xmlPath = ansPath + resource.substring(testNamePos, datPos) + ResourceReader.XML_SUFFIX;
}
return TEST_RESX.resolve(xmlPath);
}

Expand Down Expand Up @@ -240,6 +250,23 @@ public static void writeAnswerXml(final String resource, final IBaseDataObject i
writeXml(resource, xmlContent);
}

/**
* Generate the relevant XML and write to disk. Used when answer file class and data file class are not the same.
*
* @param resource referencing the DAT file
* @param initialIbdo for 'setup' section
* @param finalIbdo for 'answers' section
* @param encoders for encoding ibdo into XML
* @param results for 'answers' section
* @param answerFileClassRef test class for answer files
*/
public static void writeAnswerXml(final String resource, final IBaseDataObject initialIbdo, final IBaseDataObject finalIbdo,
final List<IBaseDataObject> results, final List<SimplifiedLogEvent> logEvents, final ElementEncoders encoders,
final AtomicReference<Class<?>> answerFileClassRef) {
RegressionTestUtil.answerFileClassRef = answerFileClassRef;
writeAnswerXml(resource, initialIbdo, finalIbdo, results, logEvents, encoders);
}

/**
* Helper method to write XML for a given DAT file.
*
Expand Down
2 changes: 1 addition & 1 deletion src/test/java/emissary/test/core/junit5/UnitTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -145,7 +145,7 @@ public static Stream<? extends Arguments> getMyTestParameterFiles(Class<?> clz)

/**
* Specifies a non-default source of test answer files
*
*
* @param ansClz Class that provides the test answer files.
*/
protected synchronized void useAlternateAnswerFileSource(Class<?> ansClz) {
Expand Down