Skip to content

Commit

Permalink
#204 Extracted the Phases from the PhasedTestManager
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Nov 20, 2024
1 parent a091787 commit f731084
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -282,7 +282,7 @@ public void onTestStart(ITestResult result) {
+ " due to failure in step " + PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedStep() + " in Phase "
+ PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase().name();
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase();

log.info(skipMessageSKIPFAILURE);
result.setStatus(ITestResult.SKIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,7 +134,7 @@ public void onTestStart(ITestResult result) {
+ " due to failure in step " + PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedStep() + " in Phase "
+ PhasedTestManager.getScenarioContext()
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase().name();
.get(PhasedTestManager.fetchScenarioName(result)).getFailedInPhase();

log.info(skipMessageSKIPFAILURE);
result.setStatus(ITestResult.SKIP);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1578,7 +1578,7 @@ protected static class ScenarioContextData {
private boolean passed;
private long duration;
private String failedStep;
private Phases failedInPhase;
private String failedInPhase;
private String currentStep;
private int stepNr;

Expand All @@ -1587,7 +1587,7 @@ protected static class ScenarioContextData {
passed = true;
duration = 0;
failedStep = NOT_APPLICABLE_STEP_NAME;
setFailedInPhase(Phases.NON_PHASED);
setFailedInPhase("N/A");
setCurrentStep(NOT_APPLICABLE_STEP_NAME);
}

Expand All @@ -1610,7 +1610,7 @@ protected ScenarioContextData(String in_importString) {
* @param in_phase The Phase in which the error happened
* @param in_currentStep The current step in which we are
*/
protected ScenarioContextData(boolean in_passed, long in_duration, String in_failedStep, Phases in_phase,
protected ScenarioContextData(boolean in_passed, long in_duration, String in_failedStep, String in_phase,
String in_currentStep) {
this.passed = in_passed;
this.duration = in_duration;
Expand All @@ -1631,7 +1631,7 @@ public ScenarioContextData(boolean in_passed, long in_duration, String in_failed
this.passed = in_passed;
this.duration = in_duration;
this.failedStep = in_failedStep;
this.setFailedInPhase(Phases.getCurrentPhase());
this.setFailedInPhase(ExecutionMode.getCurrentMode().fetchBehavior());
}

public boolean isPassed() {
Expand All @@ -1658,11 +1658,11 @@ public void setFailedStep(String failedStep) {
this.failedStep = failedStep;
}

public Phases getFailedInPhase() {
public String getFailedInPhase() {
return failedInPhase;
}

public void setFailedInPhase(Phases failedInPhase) {
public void setFailedInPhase(String failedInPhase) {
this.failedInPhase = failedInPhase;
}

Expand Down Expand Up @@ -1700,7 +1700,7 @@ public void synchronizeState(String in_scenarioName, int in_stepRessult, long st
switch (in_stepRessult) {
case ITestResult.FAILURE:
failedStep = in_scenarioName;
setFailedInPhase(Phases.getCurrentPhase());
setFailedInPhase(ExecutionMode.getCurrentMode().fetchBehavior());
case ITestResult.SKIP:
passed = false;
default:
Expand All @@ -1720,7 +1720,7 @@ public void synchronizeState(String in_scenarioName, int in_stepRessult, long st
*/
public String exportToString() {
return this.passed + ";" + this.duration + ";" + this.failedStep + ";"
+ this.getFailedInPhase().name();
+ this.getFailedInPhase();
}

/**
Expand Down Expand Up @@ -1753,14 +1753,16 @@ public void importFromString(String in_importString) {
this.failedStep =
!l_valueArray[2].trim().isEmpty() ? l_valueArray[2] : NOT_APPLICABLE_STEP_NAME;

try {
this.setFailedInPhase(!l_valueArray[3].trim().isEmpty() ? Phases.valueOf(
l_valueArray[3]) : Phases.NON_PHASED);
} catch (IllegalArgumentException exc) {
throw new IllegalArgumentException(
"The given import string " + in_importString
+ " does not allow us to deduce the Phase.");
}
var importedPhase = !l_valueArray[3].trim().isEmpty() ?
l_valueArray[3] : "N/A";

if (importedPhase.equals("N/A") || ExecutionMode.INTERRUPTIVE.behaviorTypes.contains(importedPhase)) {
this.setFailedInPhase(importedPhase);
} else {
throw new IllegalArgumentException(
"The given import string " + in_importString
+ " does not allow us to deduce the Phase.");
}

//TODO include the StepNr ?

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -127,32 +127,27 @@ public void testExecutionIndex_InterruptiveProducer() {

assertThat("We should have two steps to execute in Producer",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
Phases.PRODUCER.fetchRunValues()),
new RunValues(ExecutionMode.INTERRUPTIVE, "PRODUCER")),
Matchers.arrayContaining(0, 2));

assertThat("We should have one steps to executed in Consumer",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
Phases.CONSUMER.fetchRunValues()),
new RunValues(ExecutionMode.INTERRUPTIVE, "CONSUMER")),
Matchers.arrayContaining(2, 3));

assertThat("We should have one steps to executed by default",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
Phases.NON_PHASED.fetchRunValues()),
Matchers.arrayContaining(0, 3));

assertThat("We should have one steps to executed by default",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
ExecutionMode.DEFAULT.fetchRunValues()),
new RunValues(ExecutionMode.DEFAULT, "")),
Matchers.arrayContaining(0, 3));

assertThat("We should have one steps to executed in Asynchronous",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
Phases.ASYNCHRONOUS.fetchRunValues()),
new RunValues(ExecutionMode.NON_INTERRUPTIVE, "23")),
Matchers.arrayContaining(0, 3));

assertThat("We should have one steps to executed in permutational",
MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup,
Phases.PERMUTATIONAL.fetchRunValues()),
new RunValues(ExecutionMode.PERMUTATIONAL, "23")),
Matchers.arrayContaining(0, 3));
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -226,7 +226,7 @@ public void exportingData() throws IOException {
assertThat("We should find our scenario", prop.containsKey(l_storedScenarioContext));

assertThat("We should find our scenario", prop.get(l_storedScenarioContext),
Matchers.equalTo("true;0;NA;NON_PHASED"));
Matchers.equalTo("true;0;NA;N/A"));

}

Expand Down Expand Up @@ -515,7 +515,7 @@ public void dataBrokerPhasedTestManagerInitializing_negativeNotAClass()
public void importingData() {
String l_stepId = PhasedTestManager.produceInStep("Hello");
String l_scenarioId = PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, "A",
new PhasedTestManager.ScenarioContextData(false,3,"abc",Phases.PRODUCER,"zdf" ));
new PhasedTestManager.ScenarioContextData(false,3,"abc","PRODUCER","zdf" ));

File l_phasedTestFile = PhasedTestManager.exportPhaseData();
PhasedTestManager.clearCache();
Expand Down Expand Up @@ -3186,9 +3186,9 @@ public void testScenarioContextDataToString() {
l_scenarioContext.setFailedStep("abc");

assertThat("The toString method should correctly export the data", l_scenarioContext.exportToString(),
Matchers.equalTo("false;2;abc;NON_PHASED"));
Matchers.equalTo("false;2;abc;N/A"));

l_scenarioContext.setFailedInPhase(Phases.CONSUMER);
l_scenarioContext.setFailedInPhase("CONSUMER");

assertThat("The toString method should correctly export the data", l_scenarioContext.exportToString(),
Matchers.equalTo("false;2;abc;CONSUMER"));
Expand All @@ -3211,7 +3211,7 @@ public void testScenarioContextDataToString() {

@Test
public void testScenarioContextData_StringConstructor() {
PhasedTestManager.ScenarioContextData l_scenarioContext = new PhasedTestManager.ScenarioContextData(false,2,"abc",Phases.PRODUCER,"efg" );
PhasedTestManager.ScenarioContextData l_scenarioContext = new PhasedTestManager.ScenarioContextData(false,2,"abc","PRODUCER","efg" );

assertThat("The toString method should correctly export the data", l_scenarioContext.exportToString(),
Matchers.equalTo("false;2;abc;"+Phases.PRODUCER.name()));
Expand All @@ -3227,7 +3227,7 @@ public void testScenarioContextData_StringConstructor() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo(l_scenarioContext.getFailedStep()));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.PRODUCER));
l_scenarioContextImported.getFailedInPhase(), equalTo("PRODUCER"));

assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getCurrentStep(), equalTo(PhasedTestManager.ScenarioContextData.NOT_APPLICABLE_STEP_NAME));
Expand All @@ -3245,7 +3245,7 @@ public void testScenarioContextData_import1_emptyFailedTest() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo("NA"));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.NON_PHASED));
l_scenarioContextImported.getFailedInPhase(), equalTo("N/A"));
}

@Test
Expand All @@ -3260,7 +3260,7 @@ public void testScenarioContextData_import2_passed() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo("NA"));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.NON_PHASED));
l_scenarioContextImported.getFailedInPhase(), equalTo("N/A"));

l_scenarioContextImported.importFromString("true;2");

Expand All @@ -3270,7 +3270,7 @@ public void testScenarioContextData_import2_passed() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo("NA"));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.NON_PHASED));
l_scenarioContextImported.getFailedInPhase(), equalTo("N/A"));
}

@Test
Expand All @@ -3285,7 +3285,7 @@ public void testScenarioContextData_import3_failed() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo("sd"));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.NON_PHASED));
l_scenarioContextImported.getFailedInPhase(), equalTo("N/A"));
}

@Test
Expand All @@ -3300,7 +3300,7 @@ public void testScenarioContextData_import4_failed() {
assertThat("The failedStep should be correctly imported", l_scenarioContextImported.getFailedStep(),
Matchers.equalTo(PhasedTestManager.ScenarioContextData.NOT_APPLICABLE_STEP_NAME));
assertThat("The phased in which the failure occurred should be the producer phase",
l_scenarioContextImported.getFailedInPhase(), equalTo(Phases.NON_PHASED));
l_scenarioContextImported.getFailedInPhase(), equalTo("N/A"));
}

@Test
Expand Down

0 comments on commit f731084

Please sign in to comment.