Skip to content

Commit

Permalink
Moved the exceptions to a dedicated package. RenamedPhasedTestConfigV…
Browse files Browse the repository at this point in the history
…alueHandler to ConfigValueHandlerPhased
  • Loading branch information
baubakg committed Sep 14, 2023
1 parent cb17bce commit 1806063
Show file tree
Hide file tree
Showing 28 changed files with 119 additions and 120 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,9 @@
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.PhasedTestManager;
import com.adobe.campaign.tests.integro.phased.Phases;

import java.util.Arrays;

public enum PhasedTestConfigValueHandler {
public enum ConfigValueHandlerPhased {
PROP_SELECTED_PHASE("PHASED.TESTS.PHASE", Phases.NON_PHASED.name(), false),
EVENTS_NONINTERRUPTIVE("PHASED.EVENTS.NONINTERRUPTIVE",null, false),
PROP_PHASED_TEST_DATABROKER("PHASED.TESTS.DATABROKER", null, false),
Expand All @@ -33,7 +30,7 @@ public enum PhasedTestConfigValueHandler {
public final String defaultValue;
public final boolean requiredValue;

PhasedTestConfigValueHandler(String in_propertyName, String in_defaultValue, boolean in_requiredValue) {
ConfigValueHandlerPhased(String in_propertyName, String in_defaultValue, boolean in_requiredValue) {
systemName =in_propertyName;
defaultValue=in_defaultValue;
requiredValue=in_requiredValue;
Expand Down Expand Up @@ -66,7 +63,7 @@ public void reset() {
* Resets all of the values
*/
public static void resetAllValues() {
Arrays.stream(values()).forEach(PhasedTestConfigValueHandler::reset);
Arrays.stream(values()).forEach(ConfigValueHandlerPhased::reset);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,7 @@
*/
package com.adobe.campaign.tests.integro.phased;

import java.util.Date;
import java.util.Map;
import java.util.TreeMap;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestingEventException;

public abstract class NonInterruptiveEvent implements Runnable {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException;
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
Expand Down Expand Up @@ -44,8 +46,8 @@ public static String fetchApplicableEvent(Method in_method) {
return in_method.getDeclaredAnnotation(PhaseEvent.class).eventClasses()[0];
} else if (PhasedTestManager.isPhasedTest(in_method) && (in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses().length > 0)) {
return in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses()[0];
} else if (PhasedTestConfigValueHandler.EVENTS_NONINTERRUPTIVE.isSet()) {
return PhasedTestConfigValueHandler.EVENTS_NONINTERRUPTIVE.fetchValue();
} else if (ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.isSet()) {
return ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue();
}
return null;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,13 @@
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException;
import com.adobe.campaign.tests.integro.phased.internal.PhaseProcessorFactory;
import com.adobe.campaign.tests.integro.phased.permutational.ScenarioStepDependencies;
import com.adobe.campaign.tests.integro.phased.permutational.ScenarioStepDependencyFactory;
import com.adobe.campaign.tests.integro.phased.permutational.StepDependencies;
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import com.adobe.campaign.tests.integro.phased.PhasedTestConfigValueHandler;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import org.testng.*;
Expand Down Expand Up @@ -55,12 +56,12 @@ public void alter(List<XmlSuite> suites) {

// *** Import DataBroker ***
String l_phasedDataBrokerClass = null;
if (PhasedTestConfigValueHandler.PROP_PHASED_TEST_DATABROKER.isSet()) {
l_phasedDataBrokerClass = PhasedTestConfigValueHandler.PROP_PHASED_TEST_DATABROKER.fetchValue();
if (ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.isSet()) {
l_phasedDataBrokerClass = ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.fetchValue();
} else if (suites.get(0).getAllParameters()
.containsKey(PhasedTestConfigValueHandler.PROP_PHASED_TEST_DATABROKER.systemName)) {
.containsKey(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName)) {
l_phasedDataBrokerClass = suites.get(0)
.getParameter(PhasedTestConfigValueHandler.PROP_PHASED_TEST_DATABROKER.systemName);
.getParameter(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName);
} else if (!Phases.NON_PHASED.isSelected()) {
log.info("{} No PhasedDataBroker set. Using the file system path {}/{} instead ",
PhasedTestManager.PHASED_TEST_LOG_PREFIX, PhasedTestManager.STD_STORE_DIR,
Expand Down Expand Up @@ -434,7 +435,7 @@ public void transform(ITestAnnotation annotation, Class testClass, Constructor t
if (PhasedTestManager.isPhasedTest(l_currentClass)) {
if (Phases.NON_PHASED.isSelected()) {
annotation.setDataProvider(
PhasedTestConfigValueHandler.PHASED_TEST_NONPHASED_LEGACY.is("true") ? PhasedDataProvider.SINGLE : PhasedDataProvider.DEFAULT);
ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.is("true") ? PhasedDataProvider.SINGLE : PhasedDataProvider.DEFAULT);

} else {
annotation.setDataProvider(PhasedTestManager.isPhasedTestShuffledMode(
Expand Down Expand Up @@ -462,7 +463,7 @@ public List<IMethodInstance> intercept(List<IMethodInstance> list, ITestContext
Map<Class<?>, List<String>> l_classMethodMap = new HashMap<>();
Set<Class> l_phasedClasses = new HashSet<>();

if (PhasedTestConfigValueHandler.PROP_DISABLE_RETRY.is("true")) {
if (ConfigValueHandlerPhased.PROP_DISABLE_RETRY.is("true")) {
log.debug("{} Disabling Retry for phased Tests.", PhasedTestManager.PHASED_TEST_LOG_PREFIX);
list.stream().filter(l -> PhasedTestManager.isPhasedTest(l.getMethod().getRealClass())).forEach(i -> i.getMethod().setRetryAnalyzerClass(DisabledRetryAnalyzer.class));
}
Expand Down Expand Up @@ -506,7 +507,7 @@ public List<IMethodInstance> intercept(List<IMethodInstance> list, ITestContext
}

//If the property PHASED.TESTS.DETECT.ORDER not set, we follow the standard TestNG order
if (PhasedTestConfigValueHandler.PHASED_TEST_DETECT_ORDER.is("false")) {
if (ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.is("false")) {
log.info("{} Generating Phased Providers", PhasedTestManager.PHASED_TEST_LOG_PREFIX);
//NIA
PhasedTestManager.generatePhasedProviders(l_classMethodMap, Phases.getCurrentPhase());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException;
import com.adobe.campaign.tests.integro.phased.permutational.ScenarioStepDependencies;
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import com.adobe.campaign.tests.integro.phased.utils.GeneralTestUtils;
Expand Down Expand Up @@ -44,7 +46,7 @@ private PhasedTestManager() {
private static final Logger log = LogManager.getLogger();

public static final String DEFAULT_CACHE_DIR = "phased_output";
public static final String STD_CACHE_DIR = PhasedTestConfigValueHandler.PROP_OUTPUT_DIR.fetchValue();
public static final String STD_CACHE_DIR = ConfigValueHandlerPhased.PROP_OUTPUT_DIR.fetchValue();
public static final String STD_STORE_DIR = "phased_tests";
public static final String STD_STORE_FILE = "phaseData.properties";

Expand Down Expand Up @@ -80,7 +82,7 @@ public enum ScenarioState {

static Boolean selectTestsByProducerMode = Boolean.FALSE;

static final String SCENARIO_CONTEXT_PREFIX = PhasedTestConfigValueHandler.PROP_SCENARIO_EXPORTED_PREFIX.fetchValue();
static final String SCENARIO_CONTEXT_PREFIX = ConfigValueHandlerPhased.PROP_SCENARIO_EXPORTED_PREFIX.fetchValue();

public static class MergedReportData {

Expand Down Expand Up @@ -406,8 +408,8 @@ public static File exportPhaseData() {
public static File fetchExportFile() {
File l_exportCacheFile;

if (PhasedTestConfigValueHandler.PROP_PHASED_DATA_PATH.isSet() ) {
return new File(PhasedTestConfigValueHandler.PROP_PHASED_DATA_PATH.fetchValue());
if (ConfigValueHandlerPhased.PROP_PHASED_DATA_PATH.isSet() ) {
return new File(ConfigValueHandlerPhased.PROP_PHASED_DATA_PATH.fetchValue());
} else {
return new File(GeneralTestUtils.fetchCacheDirectory(STD_STORE_DIR), STD_STORE_FILE);
}
Expand Down Expand Up @@ -494,13 +496,13 @@ static Properties importPhaseData() {

if (dataBroker == null) {

if (PhasedTestConfigValueHandler.PROP_PHASED_DATA_PATH.isSet()) {
l_importCacheFile = new File(PhasedTestConfigValueHandler.PROP_PHASED_DATA_PATH.fetchValue());
if (ConfigValueHandlerPhased.PROP_PHASED_DATA_PATH.isSet()) {
l_importCacheFile = new File(ConfigValueHandlerPhased.PROP_PHASED_DATA_PATH.fetchValue());

} else {
l_importCacheFile = new File(GeneralTestUtils.fetchCacheDirectory(STD_STORE_DIR), STD_STORE_FILE);
log.warn("{} The system property {} not set. Fetching Phased Test data from {}.",
PHASED_TEST_LOG_PREFIX, PhasedTestConfigValueHandler.PROP_PHASED_DATA_PATH.systemName, l_importCacheFile.getPath());
PHASED_TEST_LOG_PREFIX, ConfigValueHandlerPhased.PROP_PHASED_DATA_PATH.systemName, l_importCacheFile.getPath());
}
} else {
log.info("{} Fetching cache through DataBroker.", PHASED_TEST_LOG_PREFIX);
Expand Down Expand Up @@ -1441,11 +1443,11 @@ public static String fetchClassFromScenarioContext(String in_scenario) {
*/
static void applyMergeReportChoice() {
//Activating merge results if the value is set in the system properties
if (PhasedTestConfigValueHandler.PROP_MERGE_STEP_RESULTS.is("true")) {
if (ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.is("true")) {
activateMergedReports();
}

if (PhasedTestConfigValueHandler.PROP_MERGE_STEP_RESULTS.is("false")) {
if (ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.is("false")) {
deactivateMergedReports();
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ public enum Phases {
*
*/
public static Phases getCurrentPhase() {
return fetchCorrespondingPhase(PhasedTestConfigValueHandler.PROP_SELECTED_PHASE.fetchValue());
return fetchCorrespondingPhase(ConfigValueHandlerPhased.PROP_SELECTED_PHASE.fetchValue());
}

/**
Expand Down Expand Up @@ -88,7 +88,7 @@ public boolean hasSplittingEvent() {
*
*/
void activate() {
PhasedTestConfigValueHandler.PROP_SELECTED_PHASE.activate(this.name());
ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate(this.name());
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.adobe.campaign.tests.integro.phased;
package com.adobe.campaign.tests.integro.phased.exceptions;

/**
* Exceptions that are thrown when preparing the tests. Exceptions of this type
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
/**
*
*/
package com.adobe.campaign.tests.integro.phased;
package com.adobe.campaign.tests.integro.phased.exceptions;

/**
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
*/
package com.adobe.campaign.tests.integro.phased;
package com.adobe.campaign.tests.integro.phased.exceptions;

public class PhasedTestingEventException extends RuntimeException {
public PhasedTestingEventException(String message) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
*/
package com.adobe.campaign.tests.integro.phased.internal;

import com.adobe.campaign.tests.integro.phased.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.Phases;
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import java.lang.annotation.Annotation;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,9 +11,9 @@
*/
package com.adobe.campaign.tests.integro.phased.permutational;

import com.adobe.campaign.tests.integro.phased.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestConfigurationException;
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import com.adobe.campaign.tests.integro.phased.PhasedTestConfigValueHandler;
import com.adobe.campaign.tests.integro.phased.ConfigValueHandlerPhased;
import com.github.javaparser.StaticJavaParser;
import com.github.javaparser.ast.body.MethodDeclaration;
import com.github.javaparser.ast.expr.MethodCallExpr;
Expand Down Expand Up @@ -50,7 +50,7 @@ public static ScenarioStepDependencies listMethodCalls(Class in_class) {
} catch (FileNotFoundException e) {
throw new PhasedTestConfigurationException(
"The class " + in_class.getTypeName() + " could not be found in the given directory "
+ PhasedTestConfigValueHandler.PHASED_TEST_SOURCE_LOCATION
+ ConfigValueHandlerPhased.PHASED_TEST_SOURCE_LOCATION
+ "you can configure this by setting the execution property PHASED.TESTS.CODE.ROOT", e);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import java.util.Arrays;
import java.util.stream.Collectors;

import com.adobe.campaign.tests.integro.phased.PhasedTestConfigValueHandler;
import com.adobe.campaign.tests.integro.phased.ConfigValueHandlerPhased;
import org.testng.ITestResult;

public final class ClassPathParser {
Expand Down Expand Up @@ -107,7 +107,7 @@ public static File fetchClassFile(String className) {
className = className.substring(0,className.lastIndexOf('$'));
}

final String l_rootPath = (new File("")).getAbsolutePath() + PhasedTestConfigValueHandler.PHASED_TEST_SOURCE_LOCATION.fetchValue();
final String l_rootPath = (new File("")).getAbsolutePath() + ConfigValueHandlerPhased.PHASED_TEST_SOURCE_LOCATION.fetchValue();
final String l_filePath = l_rootPath + "/" + className.replace('.', '/') + ".java";
return new File(l_filePath);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class NestedClassDesignTests {
public void resetVariables() {

PhasedTestManager.clearCache();
PhasedTestConfigValueHandler.resetAllValues();
ConfigValueHandlerPhased.resetAllValues();

PhasedTestManager.deactivateMergedReports();
PhasedTestManager.MergedReportData.resetReport();
Expand Down Expand Up @@ -201,7 +201,7 @@ public void testNested_HelloWorld_MultiNestedClasses() {
// Add package to test

Phases.PRODUCER.activate();
PhasedTestConfigValueHandler.PROP_MERGE_STEP_RESULTS.activate("true");
ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true");

myTestNG.run();

Expand Down Expand Up @@ -290,7 +290,7 @@ public void testNested_HelloWorld_Negative_MultiNestedClasses() {
// Add package to test

Phases.PRODUCER.activate();
PhasedTestConfigValueHandler.PROP_MERGE_STEP_RESULTS.activate("true");
ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true");

myTestNG.run();

Expand Down Expand Up @@ -342,7 +342,7 @@ public void testNested_Negative_SelectionByGroup() {

// Add package to test
Phases.PRODUCER.activate();
PhasedTestConfigValueHandler.PROP_MERGE_STEP_RESULTS.activate("true");
ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true");

myTestNG.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ public class OrderingStepsTests {
public void resetVariables() {

PhasedTestManager.clearCache();
PhasedTestConfigValueHandler.resetAllValues();
ConfigValueHandlerPhased.resetAllValues();

PhasedTestManager.deactivateMergedReports();
PhasedTestManager.deactivateTestSelectionByProducerMode();
Expand Down Expand Up @@ -68,7 +68,7 @@ public void resetVariables() {

@Test
public void testNonPhased() {
PhasedTestConfigValueHandler.PHASED_TEST_DETECT_ORDER.activate("true");
ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.activate("true");
//Activate Merge
PhasedTestManager.activateMergedReports();

Expand Down Expand Up @@ -115,7 +115,7 @@ public void testNonPhased() {

@Test
public void testPhasedProducer() {
PhasedTestConfigValueHandler.PHASED_TEST_DETECT_ORDER.activate("true");
ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.activate("true");
//Activate Merge
PhasedTestManager.activateMergedReports();

Expand Down Expand Up @@ -165,7 +165,7 @@ public void testPhasedProducer() {

@Test
public void testPhasedFullMonty() {
PhasedTestConfigValueHandler.PHASED_TEST_DETECT_ORDER.activate("true");
ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.activate("true");
//Activate Merge
PhasedTestManager.activateMergedReports();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.samples.PhasedReportElementsSample;
import com.adobe.campaign.tests.integro.phased.PhasedTestConfigValueHandler;
import com.adobe.campaign.tests.integro.phased.utils.TestTools;
import java.util.ArrayList;
import java.util.HashMap;
Expand All @@ -38,18 +37,18 @@ public class PhasedReportElementsTest implements IConfigurable, IHookable {
@BeforeMethod
@AfterMethod
public void cleanup() {
PhasedTestConfigValueHandler.resetAllValues();
ConfigValueHandlerPhased.resetAllValues();
}

@Override
public void run(IConfigureCallBack callBack, ITestResult testResult) {
PhasedTestConfigValueHandler.PROP_SELECTED_PHASE.activate("PRODUCER");
ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate("PRODUCER");
callBack.runConfigurationMethod(testResult);
}

@Override
public void run(IHookCallBack callBack, ITestResult testResult) {
PhasedTestConfigValueHandler.PROP_SELECTED_PHASE.activate("PRODUCER");
ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate("PRODUCER");
callBack.runTestMethod(testResult);
}

Expand Down
Loading

0 comments on commit 1806063

Please sign in to comment.