diff --git a/README.md b/README.md index 4c644ee..a743300 100644 --- a/README.md +++ b/README.md @@ -4,24 +4,24 @@ [![javadoc](https://javadoc.io/badge2/com.adobe.campaign.tests.phased/phased-testing-testng/javadoc.svg)](https://javadoc.io/doc/com.adobe.campaign.tests.phased/phased-testing-testng) [![Quality Gate Status](https://sonarcloud.io/api/project_badges/measure?project=adobe_phased-testing&metric=alert_status&branch=main)](https://sonarcloud.io/summary/new_code?id=adobe_phased-testing&branch=main) -Phased Testing has been created to address the issues related to Event Based Testing. Event Based Testing is a notion where tests adapt to external events, and allow you to simulate how your product reacts to an external event. +Mutational Tests (aka Phased Tests) is a framework, built upon TestNG, that allows test scenarios to "mutate". This means that a given scenario can, when needed,change its structure and order, i.e. “mutate”, to address the challenges that are imposed on it. -Examples of events are: -* Upgrades -* Migrations -* Time-Consuming external Data process -* Load surges -* Service shut-downs +The mutational test methods help solve problems such as: +* Software Migration testing +* Software Upgrade testing +* Chaos testing +* End-User testing ## Table of Contents * [Problem Statement](#problem-statement) - * [Interruptive Events](#interruptive-events) - * [Non-Interruptive Events](#non-interruptive-events) + * [Events](#events) + * [Interruptive Events](#interruptive-events) + * [Non-Interruptive Events](#non-interruptive-events) + * [Permutations](#permutations) * [Installation](#installation) * [Maven](#maven) - * [Demo](#demo) - * [Phases](#phases) + * [Demo](#demo) * [Test Execution Modes](#test-execution-modes) * [Default Mode](#default-mode) * [Single Execution Mode](#single-execution-mode) @@ -44,6 +44,11 @@ Examples of events are: * [Before- and After-Phase Actions](#before--and-after-phase-actions) * [Nested Design Pattern](#nested-design-pattern) * [Running a Phased Test](#running-a-phased-test) + * [Execution Modes](#execution-modes) + * [STANDARD Execution Mode](#standard-execution-mode) + * [INTERRUPTIVE Execution Mode](#interruptive-execution-mode) + * [NON-INTERRUPTIVE execution mode](#non-interruptive-execution-mode) + * [PERMUATIONAL Execution Mode](#permuational-execution-mode) * [Run Time Properties](#run-time-properties) * [PHASED.TESTS.PHASE](#phasedtestsphase) * [PHASED.EVENTS.NONINTERRUPTIVE](#phasedeventsnoninterruptive) @@ -58,6 +63,7 @@ Examples of events are: * [Executing a CONSUMER phase based on the PRODUCED Data](#executing-a-consumer-phase-based-on-the-produced-data) * [Execution Order](#execution-order) * [Running Nested Phased Tests](#running-nested-phased-tests) + * [LEGACY PHASES - DEPRECATED](#legacy-phases---deprecated) * [Integrity between Steps and Scenarios](#integrity-between-steps-and-scenarios) * [Phase Contexts - Managing the Scenario Step Executions](#phase-contexts---managing-the-scenario-step-executions) * [On Failure](#on-failure) @@ -75,6 +81,7 @@ Examples of events are: * [Parallel Testing](#parallel-testing) * [Retry Mechanisms](#retry-mechanisms) * [Release Notes](#release-notes) + * [9.0.0 - In-Progress](#900---in-progress) * [8.11.2](#8112) * [8.11.1](#8111) * [8.0.0](#800) @@ -90,13 +97,31 @@ Examples of events are: ## Problem Statement -Phased Testing has been created to address the issues related to Event Based Testing. Event Based Testing is a notion where tests adapt to external events, and allow you to simulate how your product reacts to an external event. We identify two types of events: +Mutational Tests (aka Phased Tests) is a framework, built upon TestNG, that allows test scenarios to "mutate". This means that a given scenario can, when needed,change its structure and order, i.e. “mutate”, to address the challenges that are imposed on it. + +The mutational test methods help solve problems such as: +* Software Migration testing +* Software Upgrade testing +* Chaos testing +* End-User testing + +Mutations are currently of the following types: +* Events: Events taking place during the execution of tests +* Permutations: The user may take a different path than originally intended +* Standard : The normal execution of tests (no mutations) + +![Mutation Tests Possibilities](diagrams/PhasedDiagrams-Mutational Tests.drawio.png) + +Our philosophy is that normal tests should be able to run as they are, but when needed, they should be able to adapt to the situation. A test will be executed as usual on a day-to-day basis, and will test a given functionality. However, when required, it will adapt, and change the way it is executed, in order to help us better test our products. + +### Events +This framework was originally, and was created to address the issues related to Events in a system. Event Based Testing is a notion where tests adapt to external events, and allow you to simulate how your product reacts to an external event. We identify two types of events: * **_Interruptive events_** are cases such as system & application upgrades, system migrations and dependant service upgrades. * **_Non-Interruptive events_** are cases such as system restarts, load injections and other unexpected events. -This library was originally created to help validate system changes such as upgrades and migrations. +The mutational tests allow us to assess the effect of an event on a scenario no matter where along the scenario execution it takes place. -### Interruptive Events +#### Interruptive Events Interruptive events are cases such as system & application upgrades, system migrations and dependant service upgrades. Where the whole system requires a down-time in order to perform these events. This library allows you to define tests in such a way, so that they can be interrupted at any point awaiting an event, and to carry on where they left off. More specifically based on your design the Phased tests will ensure that a scenario will work on an upgraded system no matter where it is interrupted. @@ -105,17 +130,29 @@ This process can be used for validating : * Migrations * Time-Consuming external Data process -Phased Testing, when testing Non-Interruptive events breaks down and reexecutes the tests in the way shown below: +Phased Testing, when testing Interruptive events breaks down and reexecutes the tests in the way shown below: ![The Real Processes](diagrams/PhasedDiagrams-HL-Change-Scenarios.png) If we want to simulate all the use cases for a workflow of a user we will end up with too many duplicate code. This is why we came up with Phased Testing, which allows a scenario to cover all the possible steps in which a workflow can be interrupted. -### Non-Interruptive Events +#### Non-Interruptive Events Non-Interruptive events are cases such as system restarts, load injections and other unexpected events. These events do not require the whole system to restart. A typical use case for non-interruptive event is chaos testing. +This process can be used for validating resilience due to the injection of events during the execution of a scenario. Examples are +* Real-time Upgrades +* Load surges during the execuion of a scenario +* A driverless car that needs to react to a sudden event + +### Permutations +Permutations is the process of detecting all the possible paths a scenario can take. This is done by identifying the dependencies between each step, and creating the possible orders of that scenario. + +Mutationa testing allows us to make sure that all possible permutations of a scenario is checked. + +This is particularily usefull for covering all the possible paths a functional scenario can take. + ## Installation This version runs with the TestNG runner. You can use this library by including it in your project. @@ -126,32 +163,25 @@ The following dependency needs to be added to your pom file: com.adobe.campaign.tests.phased phased-testing-testng - 8.11.1 + 9.0.0 ``` -### Demo +## Demo We have a standard demo that can be accessed through the [Phased Test Demo](https://github.com/baubakg/phased-test-demo). -## Phases -Phases are directives at execution time, where we let the system know, in what way we want our tests to interact with an event. - -We have four test phases: -* **Producer** In this Interruptive mode, the tests will stop before we execute the event. The tests prepare data to be used in the following test phase. The tests will be interr -* **Consumer** In this Interruptive mode, the tests will continue where they left off after the event has finished. The tests consume the data produced in the previous phase. -* **Asynchrounous** In this Non-Interruptive mode, the events are executed in parallel to a step. -* * **Non-Phased** In this state, we have not designated a state, as such, if not unwanted, we execute all tests. +## Wrapping a Secnario around an Event +One of the main features of Phased Testing is the ability to wrap a scenario around an event or a problem. This is done by performing a number of iterations and injecting the event at different stages of the execution of that scenario. -### Test Execution Modes We have three modes of execution of a Phased Test: * Default Mode * Single Mode * Shuffled Mode -#### Default Mode -The steps of each scenario are executed one by one without interruption. +### Default Mode +The steps of each scenario are executed like any other scenario in a linear predicted fashion. -#### Single Execution Mode +### Single Execution Mode Single Execution Mode is used only when a workflow will always be interrupted at a given stage. This is particularly relevant when your scenario will expect a time concuming external process to finish. In this case we execute all steps till the Phase End marker. When in Consumer mode, we execute the rest of the steps. ![The Single Execution Mode](diagrams/PhasedDiagrams-SingleRun-H.png) @@ -182,8 +212,10 @@ public class ShuffledTest { } ``` -#### Shuffled Execution Mode -When in Shuffled mode, we execute all the possible ordered combinations of the steps. +### Shuffled Execution Mode +The concept of “shuffling” involves the multiple re-executions of a scenario, based on a stimulus or a requirement. In the case of Upgrades, the shuffling is based on the possible interruptions a scenario can be subject to whenever an upgrade happens. + +Each re-execution or iteration is identified by what we call a Shuffle Group. The Shuffle Group also acts as a context in which the steps have a relationship and share context variables. The code below will react differently depending on the PHASE/Execution mode it is subject to : @@ -478,9 +510,57 @@ We are able to run tests in phases since each step stores the information needed Managing this data is obviously essential to the Phased Tests. We will discuss this in more detail in the chapter on "Managing Phased Data". +### Execution Modes +We currently have 4 execution modes: +* STANDARD +* INTERRUPTIVE +* NON-INTERRUPTIVE +* PERMUTATIONAL + +The execution mode is set by passing the config value "MUTATIONAL.EXECUTION.MODE" at execution time. + +Some execution modes have a notion of a "behavior" which add more details to the system as to how the tests should be executed. The behavior is set by passing the behavior within parenthesis. + +#### STANDARD Execution Mode +This is the default execution mode. By default, we execute the scenario in the order and manner in which it was defined. + +#### INTERRUPTIVE Execution Mode +The INTERRUPTIVE execution mode simulates the system being subject to an interruptive event. + +The Phased Testing framework was originally devised for Interruptive Events, i.e. you need to stop a system so that you can perform some system change, such as an upgrade, to that system. Once the upgrade is done, we expect that the users can carry on with what they were doing. + +The execution of steps in interruptive events is divided into two phases/behaviors depending on their execution relative to the interruptive event. The phase before the event is called “producer”, because the steps executed before the event produce data used after the event has taken place. Similarly, the phase after the event is called “consumer” because the steps rely on data created in the phase before the execution of the event. + +| NAME | When Passing | Description | +|----------|-----------------------|-----------------------------------------------------------------------------------------------------------------| +| PRODUCER | INTERUPTIVE(PRODUCER) | The tests will stop before we execute the event. The tests prepare data to be used in the following test phase. | +| CONSUMER | INTERUPTIVE(CONSUMER) | The tests will continue where they left off after the event has finished. The tests consume the data produced in the previous phase. | + + +#### NON-INTERRUPTIVE execution mode +A NON-INTERRUPTIVE execution mode is used when we want to inject an event in the middle of the execution of a scenario. Non-Interruptive events allow us to see the effects of parallel events. + +This execution mode is a good way of performing chaos testing. + +This mode is activated by setting the environment variable "MUTATIONAL.EXECUTION.MODE" to "NON-INTERRUPTIVE". + +#### PERMUATIONAL Execution Mode +We have now introduced the PERMUATIONAL execution mode. This execution mode executes a scenario with all possible permutations it can have. This is done by identifying the dependencies between each step, and creating the possible orders of that scenario. + +For example, below you can see a normal scenario being executed in the standard mode: + +![Permutation Standard](diagrams/permutation-normal.png) + +When executed in the PERMUATIONAL mode is is executed in all possible orders: + +![Permutation Permutational](diagrams/permutation-expanded.png) + +This mode is activated by setting the environment variable "MUTATIONAL.EXECUTION.MODE" to "PERMUATIONAL". + ### Run Time Properties We have the following system properties: -* PHASED.TESTS.PHASE +* MUTATIONAL.EXECUTION.MODE +* PHASED.TESTS.PHASE (Deprecated) * PHASED.EVENTS.NONINTERRUPTIVE * PHASED.TESTS.DATABROKER * PHASED.TESTS.STORAGE.PATH @@ -491,7 +571,15 @@ We have the following system properties: * PHASED.TESTS.DETECT.ORDER * PHASED.TESTS.NONPHASED.LEGACY -#### PHASED.TESTS.PHASE +#### MUTATIONAL.EXECUTION.MODE +This property is used to set the execution mode of the Phased Tests. The value can be one of the following: +1. **STANDARD** (Or not setting any mode) : By default we execute all the steps in a mutational test, unless the @PhasedTest has set the attribute **executeInactive** to "false" +2. **INTERRUPTIVE(PRODUCER)** : The tests will stop before we execute the event. The tests prepare data to be used in the following test phase. +3. **INTERRUPTIVE(CONSUMER)** : The tests will continue where they left off after the event has finished. The tests consume the data produced in the previous phase. +4. **NON-INTERRUPTIVE** : The tests will execute in a non-interruptive mode. This means that the tests will be executed in parallel with an event. +5. **PERMUATIONAL** : The tests will execute in all possible orders. + +#### PHASED.TESTS.PHASE (DEPRECATED) We have four phased states: 1. **PRODUCER** : We produce information 2. **CONSUMER** : We consume information @@ -542,7 +630,20 @@ Nested class tests are usually quite tricky in Surefire because dollar sign '$' or -```mvn clean test -Dtest=PhasedTestSeries_NestedContainer\$PhasedScenario1``` + ```mvn clean test -Dtest=PhasedTestSeries_NestedContainer\$PhasedScenario1``` + +### LEGACY PHASES - DEPRECATED +Historically Phased Tests were written for INTERRUPTIVE events so the execution reflected this behavior. As we are now expanding and revising the notion of Mutational Tests, we have need to use the [Execution Modes](#execution-modes) Instead. + +We do however still support the old Phased Tests until version 9.X.2. + +Phases are directives at execution time, where we let the system know, in what way we want our tests to interact with an event. + +We have four test phases: +* **Producer** In this Interruptive mode, the tests will stop before we execute the event. The tests prepare data to be used in the following test phase. +* **Consumer** In this Interruptive mode, the tests will continue where they left off after the event has finished. The tests consume the data produced in the previous phase. +* **Asynchrounous** In this Non-Interruptive mode, the events are executed in parallel to a step. +* * **Non-Phased** In this state, we have not designated a state, as such, if not unwanted, we execute all tests. ## Integrity between Steps and Scenarios ### Phase Contexts - Managing the Scenario Step Executions @@ -636,6 +737,13 @@ For now, we have not come around to deciding how retry should work in the case o ## Release Notes +### 9.0.0 - In-Progress +* **(new feature)** [#204 Introduction of the Execution Mode replacing Phases](https://github.com/adobe/phased-testing/issues/204). We have revised the way we execute scenarios, as we no longer only cater to Upgrade tests. The means you should revise the way you execute Phased Tests by using Execution Modes. For more information please refer to the chapter [Execution Modes](#execution-modes). +* **(new feature)** [#35 Adding the Permutation Execution Mode](https://github.com/adobe/phased-testing/issues/35). We have introduced the Permutation Execution Mode. This mode executes a scenario with all possible permutations it can have. This is done by identifying the dependencies between each step, and creating the possible orders of that scenario. For more information please refer to the chapters [Permutation Execution Mode](#permutation-execution-mode). + +* **New Environment Variables** +* MUTATIONAL.EXECUTION.MODE : This property is used to set the execution mode of the Mutational Tests. The value can be one of the following: STANDARD, INTERRUPTIVE(PRODUCER), INTERRUPTIVE(CONSUMER), NON-INTERRUPTIVE, PERMUATIONAL. This will replace the PHASED.TESTS.PHASE property which will be removed in 9.X.3. + ### 8.11.2 * **(new feature)** [#178 Allowing the injection in any step of a scenario](https://github.com/adobe/phased-testing/issues/178). We can now inject an event into a step in an arbitrary phased test. This is done by setting the syetm property PHASED.EVENTS.TARGET. This way you can inject the event into that step. * **(new feature)** [#198 Adding Post Step Event actions](https://github.com/adobe/phased-testing/issues/198). We allow you to define a 'tearDownEvent' tool to allow you to put the system back to a normal state after the event has finished. Please refer to the chapter [Performing Event Cleanup Actions](#performing-event-cleanup-actions). diff --git a/diagrams/PhasedDiagrams-Mutational Tests.drawio.png b/diagrams/PhasedDiagrams-Mutational Tests.drawio.png new file mode 100644 index 0000000..9a112a7 Binary files /dev/null and b/diagrams/PhasedDiagrams-Mutational Tests.drawio.png differ diff --git a/diagrams/PhasedDiagrams.drawio b/diagrams/PhasedDiagrams.drawio index 820fc0c..d0fbd8b 100644 --- a/diagrams/PhasedDiagrams.drawio +++ b/diagrams/PhasedDiagrams.drawio @@ -1,4 +1,4 @@ - + @@ -19,8 +19,49 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + - + @@ -93,124 +134,8 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -320,7 +245,7 @@ - + @@ -367,7 +292,7 @@ - + @@ -449,7 +374,7 @@ - + @@ -675,139 +600,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -832,73 +624,27 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - - + + + + - + @@ -907,74 +653,74 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -983,13 +729,13 @@ - + - + @@ -1172,129 +918,93 @@ - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1338,17 +1048,17 @@ - + - + - + - + @@ -1358,22 +1068,22 @@ - + - + - + - + - + - + @@ -1384,7 +1094,7 @@ - + @@ -1393,16 +1103,16 @@ - + - + - + - + @@ -1412,22 +1122,22 @@ - + - + - + - + - + - + @@ -1437,28 +1147,28 @@ - + - + - + - + - + @@ -1467,13 +1177,13 @@ - + - + - + @@ -1483,22 +1193,22 @@ - + - + - + - + - + - + @@ -1508,10 +1218,10 @@ - + - + @@ -1521,13 +1231,13 @@ - + - + - + @@ -1537,25 +1247,25 @@ - + - + - + - + - + - + - + @@ -1565,10 +1275,10 @@ - + - + @@ -1578,16 +1288,16 @@ - + - + - + - + @@ -1597,25 +1307,25 @@ - + - + - + - + - + - + - + @@ -1625,10 +1335,10 @@ - + - + @@ -1637,16 +1347,16 @@ - + - + - + - + @@ -1656,25 +1366,25 @@ - + - + - + - + - + - + - + @@ -1685,10 +1395,10 @@ - + - + @@ -1697,58 +1407,58 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + @@ -1757,50 +1467,6 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - @@ -1955,72 +1621,72 @@ - - + + - - + + - + - + - + - + - + - + - + - + - - + + - + - + - + - - - - + + + + @@ -2030,61 +1696,22 @@ - + - + - + - + - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + @@ -2095,7 +1722,7 @@ - + @@ -2136,68 +1763,35 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + - + - + - + - + - + @@ -2209,162 +1803,159 @@ - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - + + - - - - - + + - - + + - - + + - - + + - - + + diff --git a/diagrams/permutation-expanded.png b/diagrams/permutation-expanded.png new file mode 100644 index 0000000..615f540 Binary files /dev/null and b/diagrams/permutation-expanded.png differ diff --git a/diagrams/permutation-normal.png b/diagrams/permutation-normal.png new file mode 100644 index 0000000..2345131 Binary files /dev/null and b/diagrams/permutation-normal.png differ diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/ConfigValueHandlerPhased.java b/src/main/java/com/adobe/campaign/tests/integro/phased/ConfigValueHandlerPhased.java index bf12af8..e5bbfbf 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/ConfigValueHandlerPhased.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/ConfigValueHandlerPhased.java @@ -22,7 +22,8 @@ public enum ConfigValueHandlerPhased { PHASED_TEST_DETECT_ORDER("PHASED.TESTS.DETECT.ORDER", "false", false), PHASED_TEST_NONPHASED_LEGACY( "PHASED.TESTS.NONPHASED.LEGACY", "false", false ), PROP_SCENARIO_EXPORTED_PREFIX("PHASED.TESTS.STORAGE.SCENARIO.PREFIX", "[TC]", false), - EVENT_TARGET("PHASED.EVENTS.TARGET", null, false ); + EVENT_TARGET("PHASED.EVENTS.TARGET", null, false ), + PROP_EXECUTION_MODE("MUTATIONAL.EXECUTION.MODE", "DEFAULT", false); public final String systemName; public final String defaultValue; diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/ExecutionMode.java b/src/main/java/com/adobe/campaign/tests/integro/phased/ExecutionMode.java new file mode 100644 index 0000000..93e16d2 --- /dev/null +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/ExecutionMode.java @@ -0,0 +1,195 @@ +/* + * MIT License + * + * © Copyright 2020 Adobe. All rights reserved. + * + * Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: + * + * The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. + * + * 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; + +import com.adobe.campaign.tests.integro.phased.exceptions.MutationRampUpException; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; + +public enum ExecutionMode { + STANDARD(false, new ArrayList<>()), + //We need to revise this as execution in a suite may not require a precision + NON_INTERRUPTIVE(false, Arrays.asList( "23", "33" )) { + + public boolean isSelected() { + return this.equals(getCurrentMode()) || Phases.ASYNCHRONOUS.isSelected(); + }; + }, + INTERRUPTIVE(false, Arrays.asList( "PRODUCER", "CONSUMER" )) { + public boolean isSelected() { + return this.equals(getCurrentMode()) || Phases.PRODUCER.isSelected() + || Phases.CONSUMER.isSelected(); + }; + public boolean isSelected(String in_executionMode) { + + return this.fetchBehavior().equals(in_executionMode) || (in_executionMode.equals("PRODUCER") && Phases.PRODUCER.isSelected()) + || (in_executionMode.equals("CONSUMER") && Phases.CONSUMER.isSelected()); + }; + }, + PERMUTATIONAL(true, Arrays.asList()); + + boolean hasSplittingEvent; + List behaviorTypes; + + ExecutionMode(boolean in_isInPhase, List in_phaseTypes) { + hasSplittingEvent = in_isInPhase; + behaviorTypes = in_phaseTypes; + } + + /** + * Returns the Phased Test state in which the current test session is being executed + *

+ * Author : gandomi + * + * @return The phase which is currently being executed + */ + public static ExecutionMode getCurrentMode() { + if (ConfigValueHandlerPhased.PROP_EXECUTION_MODE.isSet()) { + return fetchCorrespondingMode(ConfigValueHandlerPhased.PROP_EXECUTION_MODE.fetchValue()); + } + return Phases.getCurrentPhase().fetchRunValues().getExecutionMode(); + } + + /** + * We find a corresponding PhasedTest state given a string. If none are found we return INACTIVE + *

+ * Author : gandomi + * + * @param in_stateValue Returns a Phase given a string representation of its value + * @return A state corresponding to the given Phased State, if none found we return inactive + */ + public static ExecutionMode fetchCorrespondingMode(String in_stateValue) { + for (ExecutionMode lt_ptState : ExecutionMode.values()) { + if (in_stateValue.toUpperCase().startsWith(lt_ptState.toString().toUpperCase())) { + return lt_ptState; + } + } + return STANDARD; + } + + /** + * Provides an array of Phases that contain a splitting Event aka PhasedEvent + *

+ * Author : gandomi + * + * @return An array of Phases that have a Splitting Event + */ + public static ExecutionMode[] fetchPhasesWithEvents() { + return Arrays.stream(ExecutionMode.values()) + .filter(p -> p.hasSplittingEvent) + .toArray(ExecutionMode[]::new); + } + + /** + * Checks if the selected Execution Mode is the given one + * @param in_executionMode A given execution mode to check + * @return + */ + public static boolean is(ExecutionMode in_executionMode) { + return in_executionMode.equals(getCurrentMode()); + } + + public static String getCurrentModeAsString() { + return getCurrentMode().fetchRunValues().toString(); + } + + public RunValues fetchRunValues() { + return new RunValues(getCurrentMode(), getCurrentMode().fetchBehavior()); + } + + public boolean isTypeValid() { + String l_currentType = fetchBehavior(); + if (behaviorTypes.isEmpty()) { + return l_currentType.isEmpty(); + } + return behaviorTypes.contains(l_currentType); + } + + /** + * Checks if the current entry is active. I.e. either producer or consumer + *

+ * Author : gandomi + * + * @return true if we are the active state + */ + public boolean isSelected() { + return this.equals(getCurrentMode()); + } + + /** + * Lets us know if the current phase will include a splitting event + *

+ * Author : gandomi + * + * @return True if the the phase could have a splitting event. + */ + public boolean hasSplittingEvent() { + return this.hasSplittingEvent; + } + + /** + * Activates the given phase + *

+ * Author : gandomi + */ + void activate() { + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(this.name()); + } + + /** + * Activates the given execution type with the given mode + * @param in_executionMode + */ + public void activate(String in_executionMode) { + if (!behaviorTypes.contains(in_executionMode)) { + throw new MutationRampUpException("The given execution mode type is not valid for this execution type. Please use one of the following: " + behaviorTypes.toString()); + } + + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(this.name() + "(" + in_executionMode + ")"); + } + + /** + * Fetches the mode of the current execution type + * @return The mode set at runtime + */ + public String fetchBehavior() { + if (ConfigValueHandlerPhased.PROP_EXECUTION_MODE.isSet()) { + String l_value = ConfigValueHandlerPhased.PROP_EXECUTION_MODE.fetchValue(); + int l_startIndex = l_value.indexOf("("); + int l_endIndex = l_value.indexOf(")"); + + if (l_startIndex != -1 && l_endIndex != -1) { + return l_value.substring(l_startIndex + 1, l_endIndex); + } + return ""; + } else { + return Phases.getCurrentPhase().behavior; + } + + } + + /** + * Checks if the given Type and mode are selected. If the execution type does not expect a mode, we simply ignore + * the given mode. + * + * @param in_executionMode The mode that is expected to be selected + * @return True if the given execution type and mode are selected + */ + public boolean isSelected(String in_executionMode) { + //Ignore the argument if none are expected + return this.behaviorTypes.isEmpty() ? isSelected() : this.fetchBehavior().equals(in_executionMode); + + } + +} diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/MutationListener.java b/src/main/java/com/adobe/campaign/tests/integro/phased/MutationListener.java index 82cae62..768afd3 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/MutationListener.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/MutationListener.java @@ -41,7 +41,7 @@ public void alter(List suites) { IAlterSuiteListener.super.alter(suites); log.debug("{} in alter - current Execution State is : {}", PhasedTestManager.PHASED_TEST_LOG_PREFIX - , Phases.getCurrentPhase()); + , ExecutionMode.getCurrentMode()); // *** Import DataBroker *** String l_phasedDataBrokerClass = null; @@ -51,7 +51,7 @@ public void alter(List suites) { .containsKey(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName)) { l_phasedDataBrokerClass = suites.get(0) .getParameter(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName); - } else if (!Phases.NON_PHASED.isSelected()) { + } else if (!ExecutionMode.STANDARD.isSelected()) { log.info("{} No PhasedDataBroker set. Using the file system path {}/{} instead ", PhasedTestManager.PHASED_TEST_LOG_PREFIX, PhasedTestManager.STD_STORE_DIR, PhasedTestManager.STD_STORE_FILE @@ -69,7 +69,7 @@ public void alter(List suites) { // *** import context for consumer *** //The second condition is there for testing purposes. You can bypass the file by filling the Test - if (Phases.CONSUMER.isSelected() && PhasedTestManager.getPhasedCache().isEmpty()) { + if (ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER") && PhasedTestManager.getPhasedCache().isEmpty()) { PhasedTestManager.importPhaseData(); } @@ -123,7 +123,7 @@ public void transform(ITestAnnotation annotation, Class testClass, Constructor t } if (PhasedTestManager.isPhasedTest(l_currentClass)) { - if (Phases.NON_PHASED.isSelected()) { + if (ExecutionMode.STANDARD.isSelected()) { annotation.setDataProvider( ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.is("true") ? PhasedDataProvider.SINGLE : PhasedDataProvider.DEFAULT); @@ -226,7 +226,7 @@ public List intercept(List list, ITestContext log.info("{} Generating Phased Providers", PhasedTestManager.PHASED_TEST_LOG_PREFIX); //NIA PhasedTestManager.generatePhasedProviders(l_classMethodMap, PhasedTestManager.getStepDependencies(), - Phases.getCurrentPhase()); + ExecutionMode.getCurrentMode().fetchRunValues()); //} //Start by adding the non-phased tests @@ -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); @@ -311,14 +311,14 @@ public void onFinish(ITestContext context) { ITestListener.super.onFinish(context); //Once the tests have finished in producer mode we, need to export the data - if (Phases.PRODUCER.isSelected()) { + if (ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")) { log.info("{} At the end. Exporting data", PhasedTestManager.PHASED_TEST_LOG_PREFIX); PhasedTestManager.exportPhaseData(); } log.debug("{} Purging results - Keeping one method per test class", PhasedTestManager.PHASED_TEST_LOG_PREFIX); - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { PhasedEventManager.stopEventExecutor(); } } diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/MutationManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/MutationManager.java index fa26208..09cb239 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/MutationManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/MutationManager.java @@ -67,26 +67,26 @@ public static String fetchScenarioName(String in_classFullName, String in_shuffl * * @param in_className The name of the scenario * @param in_phaseGroup The phase group in which we are in - * @param in_phase The phase in which we are in + * @param in_runValues The set execution mode and behavior * @return An array of two entries. The first entry is the start index and the second entry is the end index */ - public static Integer[] fetchExecutionIndex(String in_className, String in_phaseGroup, Phases in_phase) { + public static Integer[] fetchExecutionIndex(String in_className, String in_phaseGroup, RunValues in_runValues) { Integer[] lr_result = new Integer[2]; //FetchNr Of Steps int l_nrOfMethods = PhasedTestManager.getMethodMap().keySet().stream().filter(m -> m.startsWith(in_className)) .collect(Collectors.toList()).size(); - Integer[] l_boundaries = in_phase.hasSplittingEvent() ? PhasedTestManager.fetchShuffledStepCount( + Integer[] l_boundaries = in_runValues.getExecutionMode().equals(ExecutionMode.INTERRUPTIVE)? PhasedTestManager.fetchShuffledStepCount( in_phaseGroup) : new Integer[] { 0, l_nrOfMethods }; - switch (in_phase) { - case PRODUCER: + switch (in_runValues.getBehavior()) { + case "PRODUCER": lr_result[0] = 0; lr_result[1] = l_boundaries[0]; break; - case CONSUMER: + case "CONSUMER": lr_result[0] = l_boundaries[0]; lr_result[1] = l_nrOfMethods; break; diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/Mutational.java b/src/main/java/com/adobe/campaign/tests/integro/phased/Mutational.java index 42c1986..960fcee 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/Mutational.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/Mutational.java @@ -34,8 +34,8 @@ public void scenario(String phaseGroup) throws Throwable { Map l_scenarioDependencies = PhasedTestManager.getStepDependencies(); - List l_orderList = Phases.getCurrentPhase() - .equals(Phases.PERMUTATIONAL) ? l_scenarioDependencies.get(l_executingClass.getTypeName()) + List l_orderList = ExecutionMode.is(ExecutionMode.PERMUTATIONAL) ? l_scenarioDependencies.get( + l_executingClass.getTypeName()) .fetchScenarioPermutations().get(phaseGroup) : l_scenarioDependencies.get( l_executingClass.getTypeName()).fetchExecutionOrderList(); @@ -43,7 +43,7 @@ public void scenario(String phaseGroup) throws Throwable { // phaseGroup)[0] : l_orderList.size(); Integer[] l_boundaries = MutationManager.fetchExecutionIndex(l_executingClass.getTypeName(), phaseGroup, - Phases.getCurrentPhase()); + ExecutionMode.getCurrentMode().fetchRunValues()); // System.out.println(nrOfSteps + " - " + phaseGroup); //for (Method stepMethod : l_executingClass.getDeclaredMethods()) { //for (StepDependencies stepOrdering : stepOrder) { @@ -60,7 +60,7 @@ public void scenario(String phaseGroup) throws Throwable { PhasedTestManager.storePhasedContext(ClassPathParser.fetchFullName(stepMethod), phaseGroup); - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { //Check if there is an event declared String lt_event = PhasedEventManager.fetchEvent(stepMethod, phaseGroup); @@ -75,7 +75,7 @@ public void scenario(String phaseGroup) throws Throwable { stepMethod.invoke(ourInstance, phaseGroup); long l_end = System.currentTimeMillis(); - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { //Check if there is an event declared String lt_event = PhasedEventManager.fetchEvent(stepMethod, phaseGroup); if (lt_event != null) { diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestListener.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestListener.java index e9fe24e..2348db4 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestListener.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestListener.java @@ -48,8 +48,12 @@ public class PhasedTestListener @Override public void alter(List suites) { + if (ConfigValueHandlerPhased.PROP_SELECTED_PHASE.isSet()) { + log.warn("IMPORTANT: The property {} is DEPRECATED. Please you the property {} henceforth.", + ConfigValueHandlerPhased.PROP_SELECTED_PHASE.systemName, ConfigValueHandlerPhased.PROP_EXECUTION_MODE.systemName); + } log.debug("{} in alter - current Execution State is : {}", PhasedTestManager.PHASED_TEST_LOG_PREFIX - , Phases.getCurrentPhase()); + , ExecutionMode.getCurrentModeAsString()); // *** Import DataBroker *** String l_phasedDataBrokerClass = null; @@ -59,7 +63,7 @@ public void alter(List suites) { .containsKey(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName)) { l_phasedDataBrokerClass = suites.get(0) .getParameter(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName); - } else if (!Phases.NON_PHASED.isSelected()) { + } else if (!ExecutionMode.STANDARD.isSelected()) { log.info("{} No PhasedDataBroker set. Using the file system path {}/{} instead ", PhasedTestManager.PHASED_TEST_LOG_PREFIX, PhasedTestManager.STD_STORE_DIR, PhasedTestManager.STD_STORE_FILE @@ -77,7 +81,7 @@ public void alter(List suites) { // *** import context for consumer *** //The second condition is there for testing purposes. You can bypass the file by filling the Test - if (Phases.CONSUMER.isSelected() && PhasedTestManager.getPhasedCache().isEmpty()) { + if (ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER") && PhasedTestManager.getPhasedCache().isEmpty()) { PhasedTestManager.importPhaseData(); } @@ -130,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); @@ -151,7 +155,7 @@ public void onTestStart(ITestResult result) { //Managing events //Cases 4 & 5 - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { //Check if there is an event declared String lt_event = PhasedEventManager.fetchEvent(result); @@ -238,7 +242,7 @@ protected void standardPostTestActions(ITestResult result) { PhasedTestManager.scenarioStateStore(result); //Cases 4 & 5 - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { PhasedTestManager.getPhasedCache(); //Check if there is an event declared String lt_event = PhasedEventManager.fetchEvent(result); @@ -264,14 +268,14 @@ public void onTestFailedButWithinSuccessPercentage(ITestResult result) { @Override public void onStart(ITestContext context) { log.info("{} onStart - current Execution State is : {}.", - PhasedTestManager.PHASED_TEST_LOG_PREFIX, Phases.getCurrentPhase()); + PhasedTestManager.PHASED_TEST_LOG_PREFIX, ExecutionMode.getCurrentMode()); } @Override public void onFinish(ITestContext context) { //Once the tests have finished in producer mode we, need to export the data - if (Phases.PRODUCER.isSelected()) { + if (ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")) { log.info("{} At the end. Exporting data", PhasedTestManager.PHASED_TEST_LOG_PREFIX); PhasedTestManager.exportPhaseData(); } @@ -430,7 +434,7 @@ public void transform(ITestAnnotation annotation, Class testClass, Constructor t } if (PhasedTestManager.isPhasedTest(l_currentClass)) { - if (Phases.NON_PHASED.isSelected()) { + if (ExecutionMode.STANDARD.isSelected()) { annotation.setDataProvider( ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.is("true") ? PhasedDataProvider.SINGLE : PhasedDataProvider.DEFAULT); @@ -507,7 +511,7 @@ public List intercept(List list, ITestContext 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()); + PhasedTestManager.generatePhasedProviders(l_classMethodMap, ExecutionMode.getCurrentMode().fetchRunValues()); return list; } else { @@ -519,7 +523,7 @@ public List intercept(List list, ITestContext log.info("{} Generating Phased Providers", PhasedTestManager.PHASED_TEST_LOG_PREFIX); //NIA PhasedTestManager.generatePhasedProviders(l_classMethodMap, l_scenarioDependencies, - Phases.getCurrentPhase()); + ExecutionMode.getCurrentMode().fetchRunValues()); //} //Start by adding the non-phased tests diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java index dfe845e..4094336 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/PhasedTestManager.java @@ -556,7 +556,7 @@ static Properties importPhaseData() { * @return A two-dimensional array of all the data providers attached to the current step/method */ public static Object[][] fetchProvidersShuffled(Method in_method) { - return fetchProvidersShuffled(ClassPathParser.fetchFullName(in_method), Phases.getCurrentPhase()); + return fetchProvidersShuffled(ClassPathParser.fetchFullName(in_method), ExecutionMode.getCurrentMode().fetchRunValues()); } /** @@ -570,7 +570,7 @@ public static Object[][] fetchProvidersShuffled(Method in_method) { */ public static Object[][] fetchProvidersShuffled(ITestNGMethod in_method) { String l_candidateMethod = fetchMappingKeyWithMaxProviders(in_method.getTestClass().getRealClass().getTypeName(), getMethodMap()); - return fetchProvidersShuffled(l_candidateMethod, Phases.getCurrentPhase()); + return fetchProvidersShuffled(l_candidateMethod, ExecutionMode.getCurrentMode().fetchRunValues()); } /** @@ -580,17 +580,16 @@ public static Object[][] fetchProvidersShuffled(ITestNGMethod in_method) { * Author : gandomi * * @param in_methodFullName The full name of the method used for identifying it in the phase context - * @param in_phasedState The phase state for which we should retrieve the parameters. The parameters will be - * different based on the phase. + * @param in_runMode The mode in which the mutational tests are executed * @return A two-dimensional array of all the data providers attached to the current step/method */ - public static Object[][] fetchProvidersShuffled(String in_methodFullName, Phases in_phasedState) { + public static Object[][] fetchProvidersShuffled(String in_methodFullName, RunValues in_runMode) { final MethodMapping l_methodMapping = methodMap.get(in_methodFullName); int l_nrOfProviders = l_methodMapping.nrOfProviders; Object[][] l_objectArrayPhased; - if (in_phasedState.equals(Phases.PERMUTATIONAL)) { + if (in_runMode.getExecutionMode().equals(ExecutionMode.PERMUTATIONAL)) { Map> l_permutations = getStepDependencies().get(l_methodMapping.declaredClass.getTypeName()).fetchScenarioPermutations(); l_nrOfProviders = l_permutations.size(); l_objectArrayPhased = new Object[l_nrOfProviders][1]; @@ -604,16 +603,16 @@ public static Object[][] fetchProvidersShuffled(String in_methodFullName, Phases l_objectArrayPhased= new Object[l_nrOfProviders][1]; for (int rows = 0; rows < l_nrOfProviders; rows++) { - int lt_nrBeforePhase = in_phasedState.equals(Phases.PRODUCER) ? (l_methodMapping.totalClassMethods + int lt_nrBeforePhase = in_runMode.getBehavior().equals("PRODUCER") ? (l_methodMapping.totalClassMethods - rows) : rows; int lt_nrAfterPhase = l_methodMapping.totalClassMethods - lt_nrBeforePhase; - if (in_phasedState.hasSplittingEvent()) { + if (in_runMode.getExecutionMode().equals(ExecutionMode.INTERRUPTIVE)) { l_objectArrayPhased[rows][0] = STD_PHASED_GROUP_PREFIX + lt_nrBeforePhase + "_" + lt_nrAfterPhase; - } else if (Phases.ASYNCHRONOUS.isSelected()) { + } else if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { l_objectArrayPhased[rows][0] = STD_PHASED_GROUP_NIE_PREFIX + (rows + 1); } } @@ -640,21 +639,21 @@ public static Object[][] fetchProvidersShuffled(String in_methodFullName, Phases public static Object[] fetchProvidersSingle(Method in_method) { log.debug("Returning provider for method {}", ClassPathParser.fetchFullName(in_method)); - if (Phases.PRODUCER.isSelected() && isExecutedInProducerMode(in_method)) { + if (ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER") && isExecutedInProducerMode(in_method)) { return new Object[] { STD_PHASED_GROUP_SINGLE }; } - if (Phases.CONSUMER.isSelected() && !isExecutedInProducerMode(in_method)) { + if (ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER") && !isExecutedInProducerMode(in_method)) { return new Object[] { STD_PHASED_GROUP_SINGLE }; } - if (Phases.NON_PHASED.isSelected() && in_method.getDeclaringClass().getAnnotation(PhasedTest.class) + if (ExecutionMode.STANDARD.isSelected() && in_method.getDeclaringClass().getAnnotation(PhasedTest.class) .executeInactive()) { return new Object[] { STD_PHASED_GROUP_SINGLE }; } - if (Phases.ASYNCHRONOUS.isSelected()) { + if (ExecutionMode.NON_INTERRUPTIVE.isSelected()) { return new Object[] { STD_PHASED_GROUP_SINGLE }; } @@ -673,7 +672,7 @@ public static Object[] fetchProvidersSingle(Method in_method) { public static Object[] fetchProvidersStandard(Method in_method) { log.debug("Returning provider for method {}", ClassPathParser.fetchFullName(in_method)); - if (Phases.NON_PHASED.isSelected() && !in_method.getDeclaringClass().getAnnotation(PhasedTest.class) + if (ExecutionMode.STANDARD.isSelected() && !in_method.getDeclaringClass().getAnnotation(PhasedTest.class) .executeInactive()) { return new Object[] { }; } @@ -691,7 +690,7 @@ public static Object[] fetchProvidersStandard(Method in_method) { */ public static Map generatePhasedProviders(Map, List> in_classMethodMap) { - return generatePhasedProviders(in_classMethodMap, Phases.getCurrentPhase()); + return generatePhasedProviders(in_classMethodMap, ExecutionMode.getCurrentMode().fetchRunValues()); } @@ -701,13 +700,13 @@ public static Map generatePhasedProviders(Map, L * Author : gandomi * * @param in_classMethodMap A map of a class and it is methods (A scenario and its steps) - * @param in_phaseState The phase in which we are + * @param in_runValues The execution mode values * @return A map letting us know that for a given method how often it will be executed in the current phase */ public static Map generatePhasedProviders(Map, List> in_classMethodMap, - Phases in_phaseState) { + RunValues in_runValues) { - return generatePhasedProviders(in_classMethodMap, null, in_phaseState); + return generatePhasedProviders(in_classMethodMap, null, in_runValues); } @@ -719,11 +718,11 @@ public static Map generatePhasedProviders(Map, L * * @param in_classMethodMap A map of a class and it is methods (A scenario and its steps) * @param in_scenarioDependencies A map allowing us to detect the test execution order - * @param in_phaseState The phase in which we are + * @param in_runValues The execution mode values * @return A map letting us know that for a given method how often it will be executed in the current phase */ public static Map generatePhasedProviders(Map, List> in_classMethodMap, - Map in_scenarioDependencies, Phases in_phaseState) { + Map in_scenarioDependencies, RunValues in_runValues) { methodMap = new HashMap<>(); for (Entry, List> entry : in_classMethodMap.entrySet().stream().filter(e -> !Modifier.isAbstract(e.getKey().getModifiers())).collect( @@ -735,9 +734,9 @@ public static Map generatePhasedProviders(Map, L .map(ol -> entry.getKey().getTypeName() + "." + ol.getStepName()).collect( Collectors.toList()); - if (in_phaseState.hasSplittingEvent) { + if (in_runValues.getExecutionMode().equals(ExecutionMode.INTERRUPTIVE)) { - if (in_phaseState.equals(Phases.CONSUMER)) { + if (in_runValues.getBehavior().equals("CONSUMER")) { Collections.reverse(lt_methodList); } @@ -1218,7 +1217,7 @@ public static void generateStepFailure(ITestResult in_failedTestResult) { sb.append("[Failed at step : "); sb.append(in_failedTestResult.getMethod().getMethodName()); sb.append(" - "); - sb.append(Phases.getCurrentPhase().toString()); + sb.append(ExecutionMode.getCurrentModeAsString()); sb.append("]"); PhasedTestManager.changeExceptionMessage(l_thrownException, sb.toString()); @@ -1464,23 +1463,22 @@ public static void changeExceptionMessage(Throwable in_exception, String in_newM * phase */ public static boolean hasStepsExecutedInProducer(ITestResult in_testResult) { - return hasStepsExecutedInProducer(in_testResult, Phases.getCurrentPhase()); + return hasStepsExecutedInProducer(in_testResult, Phases.getCurrentPhase().fetchRunValues()); } /** - * Given a phased test method and and its phase group, lets you know if it has ssteps executed in the producer - * phase + * Given a phased test method and and its phase group, lets you know if it has steps executed in the producer phase *

* Author : gandomi * * @param in_testResult A TestNG Test result - * @param in_phase The phase in which we are currently. + * @param in_runValues The execution mode and behavior for the tests being executed * @return true if we are in consumer, and we are not a 0_X phase group that is executed end to end in the consumer * phase */ - public static boolean hasStepsExecutedInProducer(ITestResult in_testResult, Phases in_phase) { - return (in_phase.equals(Phases.CONSUMER) && (fetchNrOfStepsBeforePhaseChange(in_testResult) > 0)); + public static boolean hasStepsExecutedInProducer(ITestResult in_testResult, RunValues in_runValues) { + return (in_runValues.getBehavior().equals("CONSUMER") && (fetchNrOfStepsBeforePhaseChange(in_testResult) > 0)); } /** @@ -1493,8 +1491,7 @@ public static boolean hasStepsExecutedInProducer(ITestResult in_testResult, Phas */ public static Integer fetchNrOfStepsBeforePhaseChange(ITestResult in_testResult) { - if (isPhasedTestShuffledMode(in_testResult) && Phases.getCurrentPhase() - .hasSplittingEvent()) { + if (isPhasedTestShuffledMode(in_testResult) && ExecutionMode.INTERRUPTIVE.isSelected()) { final String in_phaseGroup = in_testResult.getParameters()[0].toString(); @@ -1581,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; @@ -1590,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); } @@ -1613,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; @@ -1634,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() { @@ -1661,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; } @@ -1703,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: @@ -1723,17 +1720,24 @@ 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(); } /** - * Imports the values of a string. + * Imports the values of a string. An import string currently contains: + *

    + *
  • status
  • + *
  • duration
  • + *
  • failedStep
  • + *
  • failedPhase
  • + *
*

* Author : gandomi * * @param in_importString A string that is used to populate the fields of this class. */ public void importFromString(String in_importString) { + //This array will contain the following: [0] status, [1] duration, [2] failedStep, [3] failedPhase String[] l_valueArray = in_importString.split(STD_SCENARIO_CONTEXT_SEPARATOR); if (l_valueArray.length < 2) { @@ -1756,14 +1760,17 @@ 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."); - } + //l_valueArray[3] corresponds to the phase where the failure occurs. If the phase is not set, we will set it to N/A. + 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 ? diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/Phases.java b/src/main/java/com/adobe/campaign/tests/integro/phased/Phases.java index 504f3f6..26b8f91 100644 --- a/src/main/java/com/adobe/campaign/tests/integro/phased/Phases.java +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/Phases.java @@ -11,12 +11,18 @@ import java.util.Arrays; public enum Phases { - PRODUCER(true), CONSUMER(true), NON_PHASED(false), ASYNCHRONOUS(false), PERMUTATIONAL(false); + PRODUCER(true, ExecutionMode.INTERRUPTIVE, "PRODUCER"), CONSUMER(true, ExecutionMode.INTERRUPTIVE, + "CONSUMER"), NON_PHASED(false, ExecutionMode.STANDARD, ""), ASYNCHRONOUS(false, + ExecutionMode.NON_INTERRUPTIVE, ""), PERMUTATIONAL(false, ExecutionMode.PERMUTATIONAL, ""); boolean hasSplittingEvent; + ExecutionMode executionMode; + String behavior; - Phases(boolean in_isInPhase) { + Phases(boolean in_isInPhase, ExecutionMode in_executionMode, String in_behavior) { hasSplittingEvent = in_isInPhase; + executionMode = in_executionMode; + behavior = in_behavior; } /** @@ -27,6 +33,25 @@ public enum Phases { * @return The phase which is currently being executed */ public static Phases getCurrentPhase() { + if (ConfigValueHandlerPhased.PROP_EXECUTION_MODE.isSet()) { + ExecutionMode currentExecutionMode = ExecutionMode.getCurrentMode(); + switch (currentExecutionMode) { + case INTERRUPTIVE: + if (currentExecutionMode.fetchBehavior().equals("PRODUCER")) { + return PRODUCER; + } else { + return CONSUMER; + } + case NON_INTERRUPTIVE: + return ASYNCHRONOUS; + case PERMUTATIONAL: + return PERMUTATIONAL; + default: + return NON_PHASED; + } + } + + return fetchCorrespondingPhase(ConfigValueHandlerPhased.PROP_SELECTED_PHASE.fetchValue()); } @@ -74,7 +99,7 @@ public boolean isSelected() { *

* Author : gandomi * - * @return True if the the phase could have a splitting event. + * @return True if the phase could have a splitting event. */ public boolean hasSplittingEvent() { return this.hasSplittingEvent; @@ -89,4 +114,7 @@ void activate() { ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate(this.name()); } + public RunValues fetchRunValues() { + return new RunValues(executionMode, behavior.isEmpty() ? executionMode.fetchBehavior() : behavior); + } } diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/RunValues.java b/src/main/java/com/adobe/campaign/tests/integro/phased/RunValues.java new file mode 100644 index 0000000..e3d7d09 --- /dev/null +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/RunValues.java @@ -0,0 +1,42 @@ +package com.adobe.campaign.tests.integro.phased; + +public class RunValues { + private ExecutionMode executionMode; + private String behavior; + + RunValues(ExecutionMode executionMode, String behavior) { + this.executionMode = executionMode; + this.behavior = behavior; + } + + public ExecutionMode getExecutionMode() { + return executionMode; + } + + public String getBehavior() { + return behavior; + } + + @Override + public boolean equals(Object o) { + if (this == o) { + return true; + } + if (o == null || getClass() != o.getClass()) { + return false; + } + + RunValues runValues = (RunValues) o; + + if (getExecutionMode() != runValues.getExecutionMode()) { + return false; + } + return getBehavior().equals(runValues.getBehavior()); + } + + @Override + public String toString() { + return executionMode.name() + (!getBehavior().isEmpty() ? "(" + behavior + ")" : ""); + } + +} diff --git a/src/main/java/com/adobe/campaign/tests/integro/phased/exceptions/MutationRampUpException.java b/src/main/java/com/adobe/campaign/tests/integro/phased/exceptions/MutationRampUpException.java new file mode 100644 index 0000000..1b9312d --- /dev/null +++ b/src/main/java/com/adobe/campaign/tests/integro/phased/exceptions/MutationRampUpException.java @@ -0,0 +1,36 @@ +/* + * Copyright 2022 Adobe + * All Rights Reserved. + * + * NOTICE: Adobe permits you to use, modify, and distribute this file in + * accordance with the terms of the Adobe license agreement accompanying + * it. + */ +package com.adobe.campaign.tests.integro.phased.exceptions; + +/** + * Exceptions that are thrown when preparing the tests. Exceptions of this type + * should be thrown before the tests are run + * + * Author : gandomi + * + */ +public class MutationRampUpException extends RuntimeException { + + /** + * + */ + private static final long serialVersionUID = -5305055623086270877L; + + public MutationRampUpException(String in_msg, Throwable e) { + super(in_msg, e); + } + + public MutationRampUpException(String in_msg) { + super(in_msg); + } + + public MutationRampUpException() { + this("Unexpected Expection occurred when raping up the mutation tests."); + } +} diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/ExecutionModeTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/ExecutionModeTests.java new file mode 100644 index 0000000..eb13738 --- /dev/null +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/ExecutionModeTests.java @@ -0,0 +1,237 @@ +/* + * Copyright 2022 Adobe + * All Rights Reserved. + * + * NOTICE: Adobe permits you to use, modify, and distribute this file in + * accordance with the terms of the Adobe license agreement accompanying + * it. + */ +package com.adobe.campaign.tests.integro.phased; + +import com.adobe.campaign.tests.integro.phased.exceptions.MutationRampUpException; +import org.hamcrest.Matchers; +import org.testng.Assert; +import org.testng.annotations.AfterMethod; +import org.testng.annotations.BeforeClass; +import org.testng.annotations.Test; + +import static org.hamcrest.MatcherAssert.assertThat; + +public class ExecutionModeTests { + @BeforeClass + public void cleanCache() { + PhasedTestManager.clearCache(); + ConfigValueHandlerPhased.resetAllValues(); + } + + @AfterMethod + public void clearAllData() { + cleanCache(); + } + + @Test + public void testSetModeNonInterruptive() { + ExecutionMode.NON_INTERRUPTIVE.activate("23"); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected("23")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.ASYNCHRONOUS)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + assertThat("The execution mode should be correct", runMode.getExecutionMode(), + Matchers.equalTo(ExecutionMode.NON_INTERRUPTIVE)); + assertThat("The execution mode should be correct", runMode.getBehavior(), Matchers.equalTo("23")); + + assertThat("The both run values should be the same Phases and ExecutionModes", + runMode.equals(Phases.ASYNCHRONOUS.fetchRunValues())); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("NON_INTERRUPTIVE(23)")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + } + + @Test + public void testSetModeNonInterruptivePhased() { + Phases.ASYNCHRONOUS.activate(); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.ASYNCHRONOUS)); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected()); + + assertThat("The current Mode should be non interruptive", ExecutionMode.getCurrentMode(), Matchers.equalTo(ExecutionMode.NON_INTERRUPTIVE)); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(ExecutionMode.NON_INTERRUPTIVE.name())); + + } + + @Test + public void test_Negative_SetBadMode() { + Assert.assertThrows(MutationRampUpException.class, () -> ExecutionMode.INTERRUPTIVE.activate("23")); + } + + @Test + public void testSetModeInterruptiveProducer() { + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.PRODUCER)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + assertThat("The execution mode should be correct", runMode.getExecutionMode(), + Matchers.equalTo(ExecutionMode.INTERRUPTIVE)); + assertThat("The execution mode should be correct", runMode.getBehavior(), Matchers.equalTo("PRODUCER")); + + assertThat("The both run values should be the same Phases and ExecutionModes", + runMode.equals(Phases.PRODUCER.fetchRunValues())); + + assertThat("The both run values should NOT be the same Phases and ExecutionModes", + !runMode.equals(Phases.CONSUMER.fetchRunValues())); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("INTERRUPTIVE(PRODUCER)")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + + } + + @Test + public void testSetModeInterruptiveProducerPhased() { + Phases.PRODUCER.activate(); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")); + assertThat("This should be the same as Non-interruptive", !ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.PRODUCER)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("INTERRUPTIVE(PRODUCER)")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + + } + + @Test + public void testSetModeInterruptiveConsumer() { + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER")); + assertThat("This should be the same as Non-interruptive", !ExecutionMode.INTERRUPTIVE.isSelected("PRODUCER")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.CONSUMER)); + + assertThat("We should have an execution mode instance", ExecutionMode.getCurrentMode().fetchRunValues(), + Matchers.instanceOf( + RunValues.class)); + assertThat("The execution mode should be correct", + ExecutionMode.getCurrentMode().fetchRunValues().getExecutionMode(), + Matchers.equalTo(ExecutionMode.INTERRUPTIVE)); + assertThat("The execution mode should be correct", + ExecutionMode.getCurrentMode().fetchRunValues().getBehavior(), Matchers.equalTo("CONSUMER")); + + assertThat("The both run values should be the same Phases and ExecutionModes", + ExecutionMode.getCurrentMode().fetchRunValues().equals(Phases.CONSUMER.fetchRunValues())); + assertThat("The both run values should NOT be the same Phases and ExecutionModes", + !ExecutionMode.getCurrentMode().fetchRunValues().equals(Phases.PRODUCER.fetchRunValues())); + + } + + @Test + public void testSetModeInterruptiveConsumerPhased() { + Phases.CONSUMER.activate(); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.INTERRUPTIVE.isSelected("CONSUMER")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.CONSUMER)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("INTERRUPTIVE(CONSUMER)")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + + } + + @Test + public void testDefault() { + assertThat("This should be the same as Non-interruptive", ExecutionMode.STANDARD.isSelected()); + assertThat("Even though we pass a bad value we should not throw an exception. It is simply ignored", + ExecutionMode.STANDARD.isSelected("CONSUMER")); + + assertThat("We should have the correct phase", Phases.getCurrentPhase().equals(Phases.NON_PHASED)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + assertThat("The execution mode should be correct", runMode.getExecutionMode(), + Matchers.equalTo(ExecutionMode.STANDARD)); + assertThat("The execution mode should be correct", runMode.getBehavior(), Matchers.equalTo("")); + + assertThat("is is default selected", Phases.NON_PHASED.isSelected()); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("STANDARD")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + + } + + @Test + public void testMutational() { + ExecutionMode.PERMUTATIONAL.activate(); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.PERMUTATIONAL.isSelected()); + + assertThat("Permutational does not exist in phased", Phases.getCurrentPhase().equals(Phases.PERMUTATIONAL)); + + var runMode = ExecutionMode.getCurrentMode().fetchRunValues(); + assertThat("The execution mode should be correct", runMode.getExecutionMode(), + Matchers.equalTo(ExecutionMode.PERMUTATIONAL)); + assertThat("The execution mode should be correct", runMode.getBehavior(), Matchers.equalTo("")); + + assertThat("The runMode toString should be correct", runMode.toString(), + Matchers.equalTo("PERMUTATIONAL")); + + assertThat("We should properly present the execution mode", ExecutionMode.getCurrentModeAsString(), + Matchers.equalTo(runMode.toString())); + + } + + @Test + public void testIs() { + + assertThat("We should have equals", ExecutionMode.getCurrentMode().equals(ExecutionMode.STANDARD)); + assertThat("We should have equals", ExecutionMode.is(ExecutionMode.STANDARD)); + + } + + @Test + public void testIsPermutational() { + ExecutionMode.PERMUTATIONAL.activate(); + assertThat("We should have equals", ExecutionMode.getCurrentMode().equals(ExecutionMode.PERMUTATIONAL)); + assertThat("We should have equals", ExecutionMode.is(ExecutionMode.PERMUTATIONAL)); + + } + + @Test + public void testIsInterruptive() { + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + assertThat("We should have equals", ExecutionMode.getCurrentMode().equals(ExecutionMode.INTERRUPTIVE)); + assertThat("We should have equals", ExecutionMode.is(ExecutionMode.INTERRUPTIVE)); + + } + +} diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/MutationManagerTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/MutationManagerTests.java index c98feec..beae081 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/MutationManagerTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/MutationManagerTests.java @@ -116,29 +116,38 @@ public void testExecutionIndex_InterruptiveProducer() { //PG 2_1 Class testClass = PhasedChild2.class; - PhasedTestManager.getMethodMap().put(testClass.getTypeName()+".a", new MethodMapping(testClass, 1, 3, 1)); - PhasedTestManager.getMethodMap().put(testClass.getTypeName()+".b", new MethodMapping(testClass, 1, 3, 2)); - PhasedTestManager.getMethodMap().put(testClass.getTypeName()+".c", new MethodMapping(testClass, 1, 3, 3)); - + PhasedTestManager.getMethodMap().put(testClass.getTypeName() + ".a", new MethodMapping(testClass, 1, 3, 1)); + PhasedTestManager.getMethodMap().put(testClass.getTypeName() + ".b", new MethodMapping(testClass, 1, 3, 2)); + PhasedTestManager.getMethodMap().put(testClass.getTypeName() + ".c", new MethodMapping(testClass, 1, 3, 3)); String l_phaseGroup = PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"; //MutationManager. //String l_scenarioName = MutationManager.fetchScenarioName(testClass.getTypeName(), l_phaseGroup); - assertThat("We should have two steps to execute in Producer", MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, Phases.PRODUCER), + assertThat("We should have two steps to execute in Producer", + MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, + 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), + assertThat("We should have one steps to executed in Consumer", + MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, + 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), + assertThat("We should have one steps to executed by default", + MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, + new RunValues(ExecutionMode.STANDARD, "")), Matchers.arrayContaining(0, 3)); - assertThat("We should have one steps to executed in Asynchronous", MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, Phases.ASYNCHRONOUS), + assertThat("We should have one steps to executed in Asynchronous", + MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, + 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), + assertThat("We should have one steps to executed in permutational", + MutationManager.fetchExecutionIndex(testClass.getTypeName(), l_phaseGroup, + new RunValues(ExecutionMode.PERMUTATIONAL, "23")), Matchers.arrayContaining(0, 3)); } diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/MutationalTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/MutationalTests.java index c79da53..4cec4ff 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/MutationalTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/MutationalTests.java @@ -216,7 +216,7 @@ public void testInterruptiveEvent() { TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); - Phases.PRODUCER.activate(); + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); // Define suites XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); @@ -257,7 +257,7 @@ public void testInterruptiveEvent() { TestNG myTestNGC = TestTools.createTestNG(); TestListenerAdapter tlaC = TestTools.fetchTestResultsHandler(myTestNGC); - Phases.CONSUMER.activate(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); // Define suites XmlSuite mySuiteC = TestTools.addSuitToTestNGTest(myTestNGC, "Automated Suite Phased Testing"); @@ -304,7 +304,7 @@ public void testPermutational() { TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); - ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate(Phases.PERMUTATIONAL.name()); + ExecutionMode.PERMUTATIONAL.activate(); // Define suites XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); @@ -337,7 +337,7 @@ public void testPermutationalDemo() { TestNG myTestNG = TestTools.createTestNG(); TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); - ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate(Phases.PERMUTATIONAL.name()); + ExecutionMode.PERMUTATIONAL.activate(); // Define suites XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); @@ -382,7 +382,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled_O final Class l_testClass = TestMutationalShuffled_eventPassedAsExecutionVariable.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.activate("true"); diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java index ac28732..d630bbb 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasedTestManagerTests.java @@ -18,7 +18,6 @@ import com.adobe.campaign.tests.integro.phased.exceptions.PhasedTestException; import com.adobe.campaign.tests.integro.phased.mutational.data.permutational.MultipleProducerConsumer; import com.adobe.campaign.tests.integro.phased.mutational.data.permutational.ShoppingCartDemo; -import com.adobe.campaign.tests.integro.phased.mutational.data.simple1.PhasedChild2; 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.utils.ClassPathParser; @@ -226,7 +225,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")); } @@ -515,7 +514,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(); @@ -625,7 +624,7 @@ public void testCreateDataProviderData() throws NoSuchMethodException { ClassPathParser.fetchFullName(method3))); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - Phases.getCurrentPhase()); + Phases.getCurrentPhase().fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); @@ -684,7 +683,7 @@ public void testCreateDataProviderData_withOwnDataProvider() throws NoSuchMethod ClassPathParser.fetchFullName(method3))); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - Phases.getCurrentPhase()); + Phases.getCurrentPhase().fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); @@ -757,7 +756,7 @@ public void testCreateDataProviderData_withOwnDataProviderOrdered() throws NoSuc ClassPathParser.fetchFullName(method3))); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - Phases.getCurrentPhase()); + Phases.getCurrentPhase().fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); @@ -829,7 +828,7 @@ public void testCreateDataProviderData_modeConsumer() throws SecurityException, ClassPathParser.fetchFullName(method3))); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - Phases.CONSUMER); + Phases.CONSUMER.fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(1)); @@ -839,20 +838,20 @@ public void testCreateDataProviderData_modeConsumer() throws SecurityException, assertThat("The third method should have three entries", l_result.get(ClassPathParser.fetchFullName(method3)).totalClassMethods, equalTo(3)); - Object[][] l_providerA = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), Phases.CONSUMER); + Object[][] l_providerA = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), Phases.CONSUMER.fetchRunValues()); assertThat(l_providerA[0].length, equalTo(1)); assertThat(l_providerA[0][0], equalTo(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3")); - Object[][] l_providerB = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method2), Phases.CONSUMER); + Object[][] l_providerB = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method2), Phases.CONSUMER.fetchRunValues()); assertThat(l_providerB[0].length, equalTo(1)); assertThat(l_providerB[0][0], equalTo(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3")); assertThat(l_providerB[1][0], equalTo(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2")); - Object[][] l_providerC = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method3), Phases.CONSUMER); + Object[][] l_providerC = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method3), Phases.CONSUMER.fetchRunValues()); assertThat(l_providerC[0].length, equalTo(1)); @@ -878,7 +877,7 @@ public void testCreateDataProviderData_forNonInterruptive() throws NoSuchMethodE ClassPathParser.fetchFullName(method3))); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - Phases.getCurrentPhase()); + Phases.getCurrentPhase().fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); @@ -936,7 +935,7 @@ public void testCreateDataProviderData_permutational() throws SecurityException, PhasedTestManager.setStepDependencies(Collections.singletonMap(l_scenario.getScenarioName(), l_scenario)); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - l_currentPhase); + l_currentPhase.fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(3)); @@ -946,7 +945,7 @@ public void testCreateDataProviderData_permutational() throws SecurityException, assertThat("The third method should have three entries", l_result.get(ClassPathParser.fetchFullName(method3)).totalClassMethods, equalTo(3)); - Object[][] l_providerPerm = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), l_currentPhase); + Object[][] l_providerPerm = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), l_currentPhase.fetchRunValues()); assertThat(l_providerPerm.length, equalTo(2)); @@ -978,7 +977,7 @@ public void testCreateDataProviderData_permutationalShoppingCart() throws Securi PhasedTestManager.setStepDependencies(Collections.singletonMap(l_scenario.getScenarioName(), l_scenario)); Map l_result = PhasedTestManager.generatePhasedProviders(l_myMap, - l_currentPhase); + l_currentPhase.fetchRunValues()); assertThat("we need to have the expected key", l_result.containsKey(ClassPathParser.fetchFullName(method1))); assertThat("The first method should have three entries", l_result.get(ClassPathParser.fetchFullName(method1)).nrOfProviders, equalTo(4)); @@ -988,7 +987,7 @@ public void testCreateDataProviderData_permutationalShoppingCart() throws Securi assertThat("The third method should have three entries", l_result.get(ClassPathParser.fetchFullName(method3)).totalClassMethods, equalTo(4)); - Object[][] l_providerPerm = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), l_currentPhase); + Object[][] l_providerPerm = PhasedTestManager.fetchProvidersShuffled(ClassPathParser.fetchFullName(method1), l_currentPhase.fetchRunValues()); assertThat(l_providerPerm.length, equalTo(3)); @@ -2421,7 +2420,7 @@ public void testCreateNewException() throws NoSuchMethodException { assertThat("We should have the correct exception", l_newThrowable.getMessage(), Matchers.startsWith(l_originalMessage)); assertThat("The message should end with the original message", l_newThrowable.getMessage(), - Matchers.endsWith(Phases.getCurrentPhase().toString() + "]")); + Matchers.endsWith(ExecutionMode.getCurrentModeAsString() + "]")); assertThat("We should have the step name in the message", l_newThrowable.getMessage(), Matchers.containsString(l_renamedMethod)); @@ -2453,7 +2452,7 @@ public void testCreateNewExceptionNoMessage() { assertThat("We should have the correct exception", l_newThrowable.getMessage(), Matchers.startsWith("[")); assertThat("The message should end with the original message", l_newThrowable.getMessage(), - Matchers.endsWith(Phases.getCurrentPhase().toString() + "]")); + Matchers.endsWith(ExecutionMode.getCurrentModeAsString() + "]")); assertThat("We should have the step name in the message", l_newThrowable.getMessage(), Matchers.containsString(l_renamedMethod)); @@ -2871,7 +2870,7 @@ public void testDoesTesthaveStepsInProducer() throws NoSuchMethodException, Secu Phases.CONSUMER.activate(); assertThat("This method and phase group should not have steps in the producer", - !PhasedTestManager.hasStepsExecutedInProducer(l_itr, Phases.CONSUMER)); + !PhasedTestManager.hasStepsExecutedInProducer(l_itr, new RunValues(ExecutionMode.INTERRUPTIVE, "CONSUMER"))); Mockito.when(l_itr.getParameters()) .thenReturn(new Object[] { PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_3" }); @@ -2885,14 +2884,14 @@ public void testDoesTesthaveStepsInProducer() throws NoSuchMethodException, Secu .thenReturn(new Object[] { PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_3" }); assertThat("This method and phase group should not have steps in the producer", - !PhasedTestManager.hasStepsExecutedInProducer(l_itr, Phases.PRODUCER)); + !PhasedTestManager.hasStepsExecutedInProducer(l_itr, new RunValues(ExecutionMode.INTERRUPTIVE, "PRODUCER"))); Mockito.when(l_itr.getParameters()) .thenReturn(new Object[] { PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3" }); assertThat( "This method and phase group should not have steps in the producer since we are in Producer", - !PhasedTestManager.hasStepsExecutedInProducer(l_itr, Phases.PRODUCER)); + !PhasedTestManager.hasStepsExecutedInProducer(l_itr, new RunValues(ExecutionMode.INTERRUPTIVE, "PRODUCER"))); //Testing non-phased @@ -2900,14 +2899,14 @@ public void testDoesTesthaveStepsInProducer() throws NoSuchMethodException, Secu .thenReturn(new Object[] { PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_3" }); assertThat("This method and phase group should not have steps in the producer", - !PhasedTestManager.hasStepsExecutedInProducer(l_itr, Phases.NON_PHASED)); + !PhasedTestManager.hasStepsExecutedInProducer(l_itr, new RunValues(ExecutionMode.STANDARD, ""))); Mockito.when(l_itr.getParameters()) .thenReturn(new Object[] { PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3" }); assertThat( "This method and phase group should not have steps in the producer since we are in Producer", - !PhasedTestManager.hasStepsExecutedInProducer(l_itr, Phases.NON_PHASED)); + !PhasedTestManager.hasStepsExecutedInProducer(l_itr, new RunValues(ExecutionMode.STANDARD, ""))); } @@ -3186,9 +3185,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")); @@ -3211,7 +3210,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())); @@ -3227,7 +3226,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)); @@ -3245,7 +3244,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 @@ -3260,7 +3259,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"); @@ -3270,7 +3269,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 @@ -3285,7 +3284,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 @@ -3300,7 +3299,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 diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasesTests.java b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasesTests.java index bb5b696..8253435 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/PhasesTests.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/PhasesTests.java @@ -96,5 +96,65 @@ public void testPhasesFetchWithEvents() { } + @Test + public void testNonInterruptivePhase() { + + Phases.ASYNCHRONOUS.activate(); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", Phases.ASYNCHRONOUS.isSelected()); + + ConfigValueHandlerPhased.resetAllValues(); + + ExecutionMode.NON_INTERRUPTIVE.activate(); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", Phases.ASYNCHRONOUS.isSelected()); + + //ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate(Phases.NON_INTERRUPTIVE.name()+"23"); + } + + @Test + public void testNonInterruptivePhaseWithEvents() { + //assertThat("We should be able to extract the phase value from the string", GeneralTestUtils); + + String l_selectedPhase = ExecutionMode.NON_INTERRUPTIVE.name() + "(23)"; + assertThat("We should detect the correct phase", + ExecutionMode.fetchCorrespondingMode(l_selectedPhase), Matchers.equalTo(ExecutionMode.NON_INTERRUPTIVE)); + + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(l_selectedPhase); + + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.isSelected()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.fetchBehavior(), Matchers.equalTo("23")); + assertThat("We should detect that the given value is corrects", ExecutionMode.getCurrentMode().isTypeValid()); + + + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(ExecutionMode.NON_INTERRUPTIVE.name()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.fetchBehavior(), Matchers.equalTo("")); + assertThat("We should not accept an empty type",!ExecutionMode.getCurrentMode().isTypeValid()); + + + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(ExecutionMode.NON_INTERRUPTIVE.name()); + assertThat("This should be the same as Non-interruptive", ExecutionMode.NON_INTERRUPTIVE.fetchBehavior(), Matchers.equalTo("")); + + ConfigValueHandlerPhased.PROP_EXECUTION_MODE.activate(ExecutionMode.INTERRUPTIVE.name()+"(jhfdhj)"); + assertThat("We should detect that given type is incorrect",!ExecutionMode.getCurrentMode().isTypeValid()); + + ExecutionMode.STANDARD.activate(); + assertThat("This should be the same as Non-phased", ExecutionMode.getCurrentMode().fetchBehavior(), Matchers.equalTo("")); + assertThat("We should accept an empty type", ExecutionMode.getCurrentMode().isTypeValid()); + + ExecutionMode.NON_INTERRUPTIVE.activate("33"); + assertThat("This should be the same as Non-interruptive", ExecutionMode.getCurrentMode().fetchBehavior(), Matchers.equalTo("33")); + + } + + @Test + public void testingBackWardCompatibility() { + Phases.PRODUCER.activate(); + assertThat("We should have the correct phase", !Phases.ASYNCHRONOUS.isSelected()); + } + + } diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhased.java b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhased.java index ab48d69..0d7a350 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhased.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhased.java @@ -2600,7 +2600,7 @@ public void testNonPhasedWithFailure_MERGED() { assertThat("We should have the correct message suffix", context.getFailedTests().getAllResults().iterator().next().getThrowable().getMessage(), - Matchers.endsWith(Phases.getCurrentPhase().toString() + "]")); + Matchers.endsWith(ExecutionMode.getCurrentModeAsString() + "]")); } diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedExecMode.java b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedExecMode.java new file mode 100644 index 0000000..fb02e5e --- /dev/null +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedExecMode.java @@ -0,0 +1,3288 @@ +/* + * Copyright 2022 Adobe + * All Rights Reserved. + * + * NOTICE: Adobe permits you to use, modify, and distribute this file in + * accordance with the terms of the Adobe license agreement accompanying + * it. + */ +package com.adobe.campaign.tests.integro.phased; + +import com.adobe.campaign.tests.integro.phased.data.*; +import com.adobe.campaign.tests.integro.phased.data.dp.PhasedSeries_L_ShuffledDP; +import com.adobe.campaign.tests.integro.phased.data.dp.PhasedSeries_L_ShuffledDPSimple; +import com.adobe.campaign.tests.integro.phased.data.dp.PhasedSeries_L_ShuffledNoArgs; +import com.adobe.campaign.tests.integro.phased.data.dp.PhasedSeries_L_ShuffledWrongArgs; +import com.adobe.campaign.tests.integro.phased.data.nested.PhasedSeries_J_RecipientClass.PhasedSeries_J_ShuffledClassInAClass; +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.GeneralTestUtils; +import com.adobe.campaign.tests.integro.phased.utils.TestTools; +import org.hamcrest.Matchers; +import org.mockito.Mockito; +import org.testng.*; +import org.testng.annotations.BeforeMethod; +import org.testng.annotations.Test; +import org.testng.asserts.SoftAssert; +import org.testng.internal.ConstructorOrMethod; +import org.testng.xml.XmlClass; +import org.testng.xml.XmlPackage; +import org.testng.xml.XmlSuite; +import org.testng.xml.XmlTest; + +import java.io.File; +import java.lang.reflect.Method; +import java.util.*; +import java.util.stream.Collectors; + +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.*; +import static org.testng.Assert.assertThrows; + +public class TestPhasedExecMode { + @BeforeMethod + public void resetVariables() { + + PhasedTestManager.clearCache(); + + ConfigValueHandlerPhased.resetAllValues(); + + PhasedTestManager.deactivateMergedReports(); + PhasedTestManager.deactivateTestSelectionByProducerMode(); + + PhasedTestManager.MergedReportData.resetReport(); + + //Delete temporary cache + File l_newFile = GeneralTestUtils + .createEmptyCacheFile(GeneralTestUtils.createCacheDirectory("phased2"), "newFile.properties"); + + l_newFile.delete(); + + //Delete standard cache file + File l_importCacheFile = new File( + GeneralTestUtils.fetchCacheDirectory(PhasedTestManager.STD_STORE_DIR), + PhasedTestManager.STD_STORE_FILE); + + if (l_importCacheFile.exists()) { + l_importCacheFile.delete(); + } + + PhasedTestManager.MergedReportData.configureMergedReportName(new LinkedHashSet<>(), + new LinkedHashSet<>( + Arrays.asList(PhasedReportElements.DATA_PROVIDERS, PhasedReportElements.PHASE))); + } + + @Test + public void testProducer_ThatTheTestsOnlyExecuteUptoTheLimit() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses( + Arrays.asList(new XmlClass(PhasedSeries_A.class), new XmlClass(NormalSeries_A.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_A.class)).count(), + is(equalTo(2))); + + assertThat("We should have 1 successful methods of normal tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(NormalSeries_A.class)).count(), + is(equalTo(1))); + + } + + /** + * In this case if no shuffle is possible, and we have not set a Phase Event we should execute it as a normal test + *

+ * Author : gandomi + */ + @Test + public void testSINGLE_whereNoPhaseEventHasBeenSet() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Arrays.asList(new XmlClass(PhasedSeries_D_SingleNoPhase.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.activate("false"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("All Tests shuld have been executed", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_D_SingleNoPhase.class)).count(), + is(equalTo(3))); + } + + /** + * This is a corner case for when we declare shuffled, but we also add an event + *

+ * Author : gandomi + */ + @Test + public void testSHUFFLE_wherePhaseEventHasBeenSet() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Arrays.asList(new XmlClass(PhasedTestSingleWithCanShuffleTrue.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("All Tests shuld have been executed", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedTestSingleWithCanShuffleTrue.class)).count(), + is(equalTo(1))); + } + + /** + * In this case when we have not set any value regarding the Phase state we are in the state IANACTIVE. In this case + * the execution of not is defined by the Class Annotation + *

+ * Author : gandomi + */ + @Test + public void testProducer_ThatTheTestsOnlyExecuteUptoTheLimit_NoValueSet() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + // Add classes to test + myTest.setXmlClasses( + Arrays.asList(new XmlClass(PhasedSeries_A.class), new XmlClass(NormalSeries_A.class))); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 3 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_A.class)).count(), + is(equalTo(3))); + + assertThat("We should have 1 successful methods of normal tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(NormalSeries_A.class)).count(), + is(equalTo(1))); + + } + + /** + * In this case when we have not set any value regarding the Phase state we are in the state INACTIVE. In this case + * the execution of not is defined by the Class Annotation + *

+ * Author : gandomi + */ + @Test + public void testInActiveNoExecutions_LEGACY() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_B_NoInActive.class))); + ConfigValueHandlerPhased.PHASED_TEST_NONPHASED_LEGACY.activate("true"); + myTestNG.run(); + + assertThat("We should have no executed methods of phased Tests", + (int) tla.getFailedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_B_NoInActive.class)).count(), + is(equalTo(0))); + + assertThat("We should have no executed methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_B_NoInActive.class)).count(), + is(equalTo(0))); + + } + + /** + * In this case when we have not set any value regarding the Phase state we are in the state INACTIVE. In this case + * the execution of not is defined by the Class Annotation + *

+ * Author : gandomi + */ + @Test + public void testInActiveNoExecutions_Default() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_B_NoInActive.class))); + + myTestNG.run(); + + assertThat("We should have no executed methods of phased Tests", + (int) tla.getFailedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_B_NoInActive.class)).count(), + is(equalTo(0))); + + assertThat("We should have no executed methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_B_NoInActive.class)).count(), + is(equalTo(0))); + + } + + @Test + public void testConsumer_theTestsStartFromTheCorrectPlace() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + // Add class + myTest.setXmlClasses(Arrays.asList(new XmlClass(PhasedSeries_H_SingleClass.class), + new XmlClass(NormalSeries_A.class))); + + ConfigValueHandlerPhased.PROP_SELECTED_PHASE.activate("conSumer"); + + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put("com.adobe.campaign.tests.integro.phased.data.PhasedSeries_H_SingleClass.step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager.storeTestData(PhasedSeries_H_SingleClass.class, + PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + myTestNG.run(); + + assertThat("We should have 1 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(1))); + + assertThat("We should have 1 successful methods of normal tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(NormalSeries_A.class)).count(), + is(equalTo(1))); + + } + + /** + * Related to issue #43 Skip consumer tests if the producer has not been executed. + *

+ * Author : gandomi + */ + @Test + public void testConsumerShuffled_noProducerHasRun() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + // Add class + myTest.setXmlClasses(Arrays.asList(new XmlClass(PhasedSeries_H_ShuffledClass.class), + new XmlClass(NormalSeries_A.class))); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + //Adding otherwise we can have an exception if there is no phasedTest.properties file + PhasedTestManager.produceInStep("just for testing"); + + myTestNG.run(); + + //This is because the Phase group 0-3 should still be executed + assertThat("We should have 3 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_ShuffledClass.class)).count(), + is(equalTo(3))); + + //This is because the Phase groups 1-3 and 2-3 should not be executed + assertThat("We should have no failed methods of phased Tests", + (int) tla.getFailedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_ShuffledClass.class)).count(), + is(equalTo(0))); + + //This is because phase groups 1-3 and 2-3 should not have the necessary context to run + assertThat("We should have 3 skipped methods of phased Tests", + (int) tla.getSkippedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_ShuffledClass.class)).count(), + is(equalTo(3))); + + assertThat("We should have 1 successful methods of normal tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(NormalSeries_A.class)).count(), + is(equalTo(1))); + + } + + /** + * Related to issue #43 Skip consumer tests if the producer has not been executed. + *

+ * Author : gandomi + */ + @Test + public void testConsumerSingle_noProducerHasRun() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + // Add class + final Class l_targetTestClass = PhasedSeries_H_SingleClass.class; + myTest.setXmlClasses( + Arrays.asList(new XmlClass(l_targetTestClass), new XmlClass(NormalSeries_A.class))); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + //Adding otherwise we can have an exception if there is no phasedTest.properties file + PhasedTestManager.produceInStep("just for testing"); + + myTestNG.run(); + + //This is because the Phase group 0-3 should still be executed + assertThat("We should have 0 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_targetTestClass)).count(), + is(equalTo(0))); + + //This is because the Phase groups 1-3 and 2-3 should not be executed + assertThat("We should have no failed methods of phased Tests", + (int) tla.getFailedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_targetTestClass)).count(), + is(equalTo(0))); + + //This is because phase groups 1-3 and 2-3 should not have the necessary context to run + assertThat("We should have 1 skipped methods of phased Tests", + (int) tla.getSkippedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_targetTestClass)).count(), + is(equalTo(1))); + + assertThat("We should have 1 successful methods of normal tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(NormalSeries_A.class)).count(), + is(equalTo(1))); + + } + + @Test + public void testFullMonty_SingleRun() { + // ***** PRODUCER **** + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_E_FullMonty.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + myTestNG.run(); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(2))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(2))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + // ***** COSNUMER **** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Phased Tests"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_E_FullMonty.class))); + + myTestNG2.run(); + + assertThat("We should have 1 successful methods of phased Tests", + (int) tla2.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(1))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + } + + @Test + public void testFullMonty_SingleRun_newModel() { + // ***** PRODUCER **** + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + Class l_testClass = PhasedTestSingleWithoutCanShuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + myTestNG.run(); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(2))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(2))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + // ***** COSNUMER **** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Phased Tests"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 1 successful methods of phased Tests", + (int) tla2.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(1))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + } + + // ***** Tests for DataDependencies ****** + + /** + * Here we check that the consuming a producing is taken into account + *

+ * Author : gandomi + */ + @Test + public void testDataDependencyCheck() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_C_NonAnnotatedDependencies.class))); + + myTestNG.run(); + + assertThat("We should have no successful methods of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_C_NonAnnotatedDependencies.class)).count(), + is(equalTo(3))); + + assertThat("We should have no successful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + } + + /****** SHUFFLED ******/ + + @Test + public void testProducer_SHUFFLED() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("false"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + context.getPassedTests().getAllResults().size(), is(equalTo(tla.getPassedTests().size()))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + //STEP 1 + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 2 + + assertThat("We should have executed step2 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step2 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step2 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 3 + assertThat("We should have executed step3 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step3 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step3 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //Context tests + List l_passedTestNamesContext = context.getPassedTests().getAllResults().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + List l_passsedTestNamesNormal = tla.getPassedTests().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + assertThat("Both lists should have the same values", + l_passedTestNamesContext.containsAll(l_passsedTestNamesNormal)); + } + + @Test + public void testProducer_MERGED_SHUFFLED() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + PhasedTestManager.activateMergedReports(); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the passed", + context.getPassedTests().getAllResults().size(), is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + //STEP 1 + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 2 + + assertThat("We should have executed step2 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step2 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step2 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 3 + assertThat("We should have executed step3 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step3 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step3 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //TRIM + List l_testNames = context.getPassedTests().getAllResults().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + assertThat("The names should have changed", l_testNames, + Matchers.containsInAnyOrder( + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0" + "__" + + Phases.getCurrentPhase().toString())); + } + + //TRIM add assertions duplicate + @Test + public void testConsumer_SHUFFLED() throws NoSuchMethodException, SecurityException { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Shuffled Phased Tests"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + //Fill the cache + final Method l_myTest1 = PhasedSeries_F_Shuffle.class.getMethod("step1", String.class); + final Method l_myTest2 = PhasedSeries_F_Shuffle.class.getMethod("step2", String.class); + + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", "A"); + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", "A"); + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2", "A"); + + PhasedTestManager.storeTestData(l_myTest2, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", "AB"); + PhasedTestManager.storeTestData(l_myTest2, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", "AB"); + + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", true); + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", true); + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2", true); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + context.getPassedTests().getAllResults().size(), is(equalTo(tla.getPassedTests().size()))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Context tests + List l_passedTestNamesContext = context.getPassedTests().getAllResults().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + List l_passsedTestNamesNormal = tla.getPassedTests().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + assertThat("Both lists should have the same values", + l_passedTestNamesContext.containsAll(l_passsedTestNamesNormal)); + } + + //TRIM add assertions duplicate + @Test + public void testConsumer_MERGED_SHUFFLED() throws NoSuchMethodException, SecurityException { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Shuffled Phased Tests"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + PhasedTestManager.activateMergedReports(); + + //Fill the cache + final Method l_myTest1 = PhasedSeries_F_Shuffle.class.getMethod("step1", String.class); + final Method l_myTest2 = PhasedSeries_F_Shuffle.class.getMethod("step2", String.class); + + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", "A"); + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", "A"); + PhasedTestManager.storeTestData(l_myTest1, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2", "A"); + + PhasedTestManager.storeTestData(l_myTest2, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", "AB"); + PhasedTestManager.storeTestData(l_myTest2, PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", "AB"); + + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0", true); + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1", new PhasedTestManager.ScenarioContextData(true, + 5L, PhasedTestManager.ScenarioContextData.NOT_APPLICABLE_STEP_NAME)); + PhasedTestManager.storeTestData(PhasedSeries_F_Shuffle.class, + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2", new PhasedTestManager.ScenarioContextData(true, + 3L, PhasedTestManager.ScenarioContextData.NOT_APPLICABLE_STEP_NAME)); + + //Add the test context + assertThat("The context should still be correct", PhasedTestManager.getScenarioContext().size(),equalTo(3)); + + myTestNG.run(); + + assertThat("The context should still be correct after the run", PhasedTestManager.getScenarioContext().size(),equalTo(4)); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should not include the same value as the Passed", + context.getPassedTests().getAllResults().size(), not(equalTo(tla.getPassedTests().size()))); + + assertThat("The Report should have 3 passed entries", context.getPassedTests().getAllResults().size(), + is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + //Add assert for durations + SoftAssert softAssertion = new SoftAssert(); + for (ITestResult lt_result : context.getPassedTests().getAllResults()) { + String lt_scenarioName = PhasedTestManager.fetchScenarioName(lt_result); + + softAssertion.assertEquals(lt_result.getEndMillis() - lt_result.getStartMillis(), + PhasedTestManager.getScenarioContext() + .get(lt_scenarioName).getDuration(), "We should have the total durations"+lt_scenarioName); + } + softAssertion.assertAll("The durations should include that of the producer"); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Context tests + List l_passedTestNamesContext = context.getPassedTests().getAllResults().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + assertThat("The names should have changed", l_passedTestNamesContext, Matchers.containsInAnyOrder( + + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3" + "__" + + Phases.getCurrentPhase().toString())); + } + + @Test + public void testSHUFFLED_FullMonty() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("false"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + context.getPassedTests().getAllResults().size(), is(equalTo(tla.getPassedTests().size()))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + // ******** CONSUMER ******** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetetive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + ITestContext contextConsumer = tla2.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + contextConsumer.getPassedTests().getAllResults().size(), + is(equalTo(tla2.getPassedTests().size()))); + + assertThat("The Report should also include the same value as the Skipped", + contextConsumer.getSkippedTests().getAllResults().size(), + is(equalTo(tla2.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + contextConsumer.getFailedTests().getAllResults().size(), + is(equalTo(tla2.getFailedTests().size()))); + + } + + @Test + public void testSHUFFLED_MERGED_FullMonty() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Merged Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Merged Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + PhasedTestManager.activateMergedReports(); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + context.getPassedTests().getAllResults().size(), is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + // ******** CONSUMER ******** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Merged Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, + "Test Repetetive Phased Merged Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + ITestContext contextConsumer = tla2.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + contextConsumer.getPassedTests().getAllResults().size(), is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + contextConsumer.getSkippedTests().getAllResults().size(), + is(equalTo(tla2.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + contextConsumer.getFailedTests().getAllResults().size(), + is(equalTo(tla2.getFailedTests().size()))); + + } + + @Test + public void testSHUFFLED_FullMonty_newModel() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Merged Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Merged Phased Tests Producer"); + + final Class l_testClass = PhasedTestShuffledWithoutCanShuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + PhasedTestManager.activateMergedReports(); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + context.getPassedTests().getAllResults().size(), is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + // ******** CONSUMER ******** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Merged Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, + "Test Repetetive Phased Merged Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + ITestContext contextConsumer = tla2.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passed", + contextConsumer.getPassedTests().getAllResults().size(), is(equalTo(3))); + + assertThat("The Report should also include the same value as the Skipped", + contextConsumer.getSkippedTests().getAllResults().size(), + is(equalTo(tla2.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + contextConsumer.getFailedTests().getAllResults().size(), + is(equalTo(tla2.getFailedTests().size()))); + + } + + @Test + public void testInactive_SHUFFLED() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests"); + + final Class l_testClass = PhasedSeries_F_Shuffle.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(3))); + + //STEP 1 + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedDataProvider.DEFAULT))); + + assertThat("We should have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedDataProvider.DEFAULT))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedDataProvider.DEFAULT))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + } + + @Test + public void testProducer_DefaultDataProvider() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_G_DefaultProvider.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_G_DefaultProvider.class)).count(), + is(equalTo(2))); + + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_SINGLE))); + + } + + @Test + public void testProducer_DefaultDataProvider_withoutListener() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_G_DefaultProvider.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_G_DefaultProvider.class)).count(), + is(equalTo(3))); + + assertThat("We should have executed step1 with the phased default group ", + tla.getPassedTests().stream().filter(m -> m.getName().equals("step1")) + .anyMatch(m -> m.getParameters()[0].equals(PhasedDataProvider.DEFAULT))); + + } + + @Test + public void testProducer_SingleRun_DataBrokerParameter() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + Map l_myparameters = new HashMap<>(); + l_myparameters.put(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName, + PhasedDataBrokerTestImplementation.class.getTypeName()); + mySuite.setParameters(l_myparameters); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_E_FullMonty.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(2))); + + //Check that file was retreived + File l_storedFile = PhasedTestManager.getDataBroker().fetch(PhasedTestManager.STD_STORE_FILE); + assertThat("The file should exist", l_storedFile.exists()); + + //Since we also store the test status context in the cache we also have the result of the scenario after the phase. + //I.e. 2 step cache data + 1 scenario state + //There is a comment line in the beginning + assertThat("We should have three +1 lines", + GeneralTestUtils.fetchFileContentDataLines(l_storedFile).size(), Matchers.equalTo(3)); + + } + + /** + * in this example we check the precedence of the Runtime properties over the configuration files + *

+ * Author : gandomi + */ + @Test + public void testProducer_SingleRun_DataBrokerSystemProperty() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + Map l_myparameters = new HashMap<>(); + l_myparameters.put(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName, NormalSeries_A.class.getTypeName()); + mySuite.setParameters(l_myparameters); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_E_FullMonty.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.activate(PhasedDataBrokerTestImplementation.class.getTypeName()); + + myTestNG.run(); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(2))); + + //Check that file was retreived + File l_storedFile = PhasedTestManager.getDataBroker().fetch(PhasedTestManager.STD_STORE_FILE); + assertThat("The file should exist", l_storedFile.exists()); + + //Since we also store the test status context in the cache we also have the result of the scenario after the phase. + //I.e. 2 step cache data + 1 scenario state + //+ 1 line for the comment + assertThat("We should have three +1 lines", + GeneralTestUtils.fetchFileContentDataLines(l_storedFile).size(), Matchers.equalTo(2 + 1)); + + } + + /** + * in this example we check the precedence of the Runtime properties over the configuration files + *

+ * Author : gandomi + */ + @Test + public void testProducer_SingleRun_DataBroker_Negative() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + Map l_myparameters = new HashMap<>(); + l_myparameters.put(ConfigValueHandlerPhased.PROP_PHASED_TEST_DATABROKER.systemName, NormalSeries_A.class.getTypeName()); + mySuite.setParameters(l_myparameters); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_E_FullMonty.class))); + + assertThrows(TestNGException.class, myTestNG::run); + + assertThat("We should have no successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(0))); + + assertThat("We should have no failed methods of phased Tests", + (int) tla.getFailedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(0))); + + assertThat("We should have no skipped methods of phased Tests", + (int) tla.getSkippedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_E_FullMonty.class)).count(), + is(equalTo(0))); + + } + + /************ Class Level Tests **************/ + + @Test + public void testProducer_classLevel() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_H_SingleClass.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(2))); + } + + @Test + public void testProducer_classLevel_MERGED() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_H_SingleClass.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(2))); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the passed", + context.getPassedTests().getAllResults().size(), is(equalTo(1))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(0))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(0))); + } + + @Test + public void testSINGLE_ClassLevelFullMonty() { + // ***** PRODUCER **** + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + final Class l_testClass = PhasedSeries_H_SingleClass.class; + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + myTestNG.run(); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(2))); + + assertThat("We should have 2 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(2))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + // ***** COSNUMER **** + + //Clear data + PhasedTestManager.clearCache(); + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Phased Tests"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 1 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(1))); + + assertThat("We should have no unsuccesful methods of phased Tests", + tla.getFailedTests().size() + tla.getSkippedTests().size(), is(equalTo(0))); + + } + + @Test + public void testSHUFFLED_ClassLevelFullMonty() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_H_ShuffledClass.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + // ******** CONSUMER ******** + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetetive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + } + + @Test(description = "Shuffling with an error") + public void testSHUFFLED_ClassLevelFullMonty_Negative() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, + "Automated Suite Phased Testing - Producer"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_H_ShuffledClassWithError.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 3 successful methods of phased Tests", tla.getPassedTests().size(), + is(equalTo(3))); + + //Global + assertThat("We should have 3 failed tests", tla.getFailedTests().size(), equalTo(2)); + + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(1)); + + //STEP 1 + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 2 + + assertThat("We should have executed step2 with the phased group 0", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step2 with the phased group 1", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step2 with the phased group 2", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 3 + assertThat("We should have executed step3 with the phased group 0", + tla.getSkippedTests().stream().filter(m -> m.getName().startsWith("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + // ******** CONSUMER ******** + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, + "Automated Suite Phased Testing - Consumer"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetitive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + //Global + + assertThat("We should have 1 successful methods of phased Tests", tla2.getPassedTests().size(), + is(equalTo(1))); + + assertThat("We should have 2 failed tests", tla2.getFailedTests().size(), equalTo(2)); + assertThat("We should have three skipped tests", tla2.getSkippedTests().size(), equalTo(3)); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getFailedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getFailedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have NO executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + } + + @Test(description = "Shuffling with an error") + public void testSHUFFLED_MERGED_ClassLevelFullMonty_Negative() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, + "Automated Suite Phased Testing - With Failures - Merged - Producer"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_H_ShuffledClassWithError.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true"); + + myTestNG.run(); + + assertThat("We should have 3 successful methods of phased Tests", tla.getPassedTests().size(), + is(equalTo(3))); + + //Global + assertThat("We should have 2 failed tests", tla.getFailedTests().size(), equalTo(2)); + assertThat("We should have one skipped tests", tla.getSkippedTests().size(), equalTo(1)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should only have one Passed test", + context.getPassedTests().getAllResults().size(), is(equalTo(1))); + + assertThat("The Report should not contain Skipped tests", + context.getSkippedTests().getAllResults().size(), is(equalTo(0))); + + assertThat("The Report should contain 2 tests marked as Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(2))); + + //Check duration + // assertThat("The duration should be the sum of all the tests", assertion); + + //STEP 1 + assertThat("We should have executed step1 with the phased group 0", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step1 with the phased group 1", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step1 with the phased group 2", + tla.getPassedTests().stream().filter(m -> m.getName().startsWith("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 2 + + assertThat("We should have executed step2 with the phased group 0", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step2 with the phased group 1", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step2 with the phased group 2", + tla.getFailedTests().stream().filter(m -> m.getName().startsWith("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + //STEP 3 + assertThat("We should have executed step3 with the phased group 0", + tla.getSkippedTests().stream().filter(m -> m.getName().startsWith("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + // ******** CONSUMER ******** + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, + "Automated Suite Phased Testing - Consumer"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetetive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + //Global + + assertThat("We should have 1 successful methods of phased Tests", tla2.getPassedTests().size(), + is(equalTo(1))); + + assertThat("We should have 2 failed tests", tla2.getFailedTests().size(), equalTo(2)); + assertThat("We should have three skipped tests", tla2.getSkippedTests().size(), equalTo(3)); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getFailedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getFailedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have NO executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getSkippedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + ITestContext contextConsumer = tla2.getTestContexts().get(0); + + assertThat("The Report should have no Passed tests", + contextConsumer.getPassedTests().getAllResults().size(), is(equalTo(0))); + + assertThat("The Report should have 1 Skipped test", + contextConsumer.getSkippedTests().getAllResults().size(), is(equalTo(1))); + + assertThat("The Report should contain 2 tests marked as Failed", + contextConsumer.getFailedTests().getAllResults().size(), is(equalTo(2))); + + } + + @Test + public void test_WithoutDataProvider() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_K_ShuffledClass_noproviders.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + // ******** CONSUMER ******** + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetetive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + } + + @Test + public void testNonPhased_WithoutDataProvider() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_K_ShuffledClass_noproviders.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + myTestNG.run(); + + assertThat("We should have 3 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(3))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report should also include the same value as the Passsed", + context.getPassedTests().getAllResults().size(), is(equalTo(tla.getPassedTests().size()))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + } + + @Test + public void testNonPhased_MERGED() { + //Activate Merge + PhasedTestManager.activateMergedReports(); + + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_K_ShuffledClass_noproviders.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + myTestNG.run(); + + assertThat("We should have 3 successful method of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(3))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report NOW only have one passed test", + context.getPassedTests().getAllResults().size(), is(equalTo(1))); + + assertThat("The Report should also include the same value as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(tla.getSkippedTests().size()))); + + assertThat("The Report should also include the same value as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(tla.getFailedTests().size()))); + + } + + @Test + public void testNonPhasedWithFailure_MERGED() { + //Activate Merge + PhasedTestManager.activateMergedReports(); + + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_H_ShuffledClassWithError.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + myTestNG.run(); + + assertThat("We should have 3 successful method of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(1))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(1)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(1)); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("The Report NOW only have one passed test", + context.getPassedTests().getAllResults().size(), is(equalTo(0))); + + assertThat("The Report should have no tests marked as the Skipped", + context.getSkippedTests().getAllResults().size(), is(equalTo(0))); + + assertThat("The Report should test marked as the Failed", + context.getFailedTests().getAllResults().size(), is(equalTo(1))); + + assertThat("We should have the correct message suffix", + context.getFailedTests().getAllResults().iterator().next().getThrowable().getMessage(), + Matchers.endsWith(ExecutionMode.getCurrentModeAsString() + "]")); + + } + + /******** GROUP Testing ********/ + + @Test + public void testProducer_classGroupLevel() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, + "Automated Suite Phased Testing - Groups "); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests - Groups"); + + //Define packages + List l_packages = new ArrayList<>(); + l_packages.add(new XmlPackage("com.adobe.campaign.tests.integro.phased.data")); + myTest.setXmlPackages(l_packages); + + myTest.addIncludedGroup("UPGRADE"); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 2 successful methods of phased Tests", tla.getPassedTests().size(), + is(equalTo(2))); + } + + @Test + public void testProducer_produceWithKey() { + + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing Produce"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Simple Phased Tests - produce"); + + myTest.setXmlClasses(Collections.singletonList(new XmlClass(PhasedSeries_I_SingleClassProduceTest.class))); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + final Properties phaseContext = PhasedTestManager.importPhaseData(); + assertThat("The phase cache should have stored the correct value", + phaseContext.containsKey(PhasedSeries_I_SingleClassProduceTest.class.getTypeName() + "(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")" + + PhasedTestManager.STD_KEY_CLASS_SEPARATOR + "MyVal")); + + assertThat("We should have no failed methods of phased Tests", tla.getFailedTests().size(), + is(equalTo(0))); + + assertThat("We should have 1 successful method of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_I_SingleClassProduceTest.class)).count(), + is(equalTo(1))); + } + + @Test + public void testProducer_produceWithKeyCascaded() { + + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, + "Automated Suite Phased Testing - Produce with Key"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, + "Test Repetetive Phased Tests Producer - Produce with Key"); + + final Class l_testClass = PhasedSeries_I_ShuffledProduceKey.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + } + + /* ************* Test The listener **************/ + + /* + * Testing the AppendShuffledGroupMethod + *

+ * Author : gandomi + */ + @Test + public void testAppendShuffledGroupName() throws NoSuchMethodException, SecurityException { + final Method l_myTestNoArgs = PhasedSeries_H_SingleClass.class.getMethod("step2", String.class); + + ITestResult l_itr = Mockito.mock(ITestResult.class); + ITestNGMethod l_itrMethod = Mockito.mock(ITestNGMethod.class); + ConstructorOrMethod l_com = Mockito.mock(ConstructorOrMethod.class); + + //TODO replace, since this is invalid in later versions of Mockito + //Mockito.when(l_itr.getMethod()).thenThrow(NoSuchFieldException.class); + Mockito.when(l_itr.getMethod()).thenAnswer(invocation -> { + throw new NoSuchFieldException("Mocked Exception"); + }); + Mockito.when(l_itr.getParameters()).thenReturn(new Object[] { "A" }); + Mockito.when(l_itrMethod.getConstructorOrMethod()).thenReturn(l_com); + Mockito.when(l_com.getMethod()).thenReturn(l_myTestNoArgs); + + PhasedTestListener ptl = new PhasedTestListener(); + assertThrows(PhasedTestException.class, () -> ptl.appendShuffleGroupToName(l_itr)); + + } + + @Test + public void testAppendShuffledGroupName2() throws NoSuchMethodException, SecurityException { + final Method l_myTestNoArgs = PhasedSeries_H_SingleClass.class.getMethod("step2", String.class); + + ITestResult l_itr = Mockito.mock(ITestResult.class); + ITestNGMethod l_itrMethod = Mockito.mock(ITestNGMethod.class); + ConstructorOrMethod l_com = Mockito.mock(ConstructorOrMethod.class); + + //TODO replace, since this is invalid in later versions of Mockito + //Mockito.when(l_itr.getMethod()).thenThrow(IllegalAccessException.class); + Mockito.when(l_itr.getMethod()).thenAnswer(invocation -> { + throw new IllegalAccessException("Mocked Exception"); + }); + Mockito.when(l_itr.getParameters()).thenReturn(new Object[] { "A" }); + Mockito.when(l_itrMethod.getConstructorOrMethod()).thenReturn(l_com); + Mockito.when(l_com.getMethod()).thenReturn(l_myTestNoArgs); + + PhasedTestListener ptl = new PhasedTestListener(); + assertThrows(PhasedTestException.class, () -> ptl.appendShuffleGroupToName(l_itr)); + + } + + @Test + public void testSHUFFLED_ClassInAClass() { + // ******** PRODUCER ******** + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_J_ShuffledClassInAClass.class; + myTest.setXmlClasses( + Arrays.asList(new XmlClass(l_testClass), new XmlClass(PhasedSeries_H_ShuffledClass.class))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", tla.getPassedTests().size(), + is(equalTo(12))); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + + // ******** CONSUMER ******** + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + TestNG myTestNG2 = TestTools.createTestNG(); + TestListenerAdapter tla2 = TestTools.fetchTestResultsHandler(myTestNG2); + + // Define suites + XmlSuite mySuite2 = TestTools.addSuitToTestNGTest(myTestNG2, "Automated Suite Phased Testing"); + + // Add listeners + mySuite2.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite2, "Test Repetetive Phased Tests Consumer"); + + myTest2.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + myTestNG2.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla2.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)) + .count(), + is(equalTo(6))); + + //STEP 1 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step1 with the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should NOT have executed step1 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step1 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step1")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 2 + + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should NOT have executed step2 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step2 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step2 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step2")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //STEP 3 + assertThat("We should have no executions for the phased group 0", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).noneMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "3_0"))); + + assertThat("We should have executed step3 with the phased group 1", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_1"))); + + assertThat("We should have executed step3 with the phased group 2", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_2"))); + + assertThat("We should have executed step3 with the phased group 3", + tla2.getPassedTests().stream().filter(m -> m.getName().equals("step3")).anyMatch( + m -> m.getParameters()[0].equals(PhasedTestManager.STD_PHASED_GROUP_PREFIX + "0_3"))); + + //Global + assertThat("We should have no failed tests", tla2.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla2.getSkippedTests().size(), equalTo(0)); + + } + + /************* Multi Data Provider ******************/ + @Test + public void testMultiDataProvider() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing multi dp"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_L_ShuffledDP.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + } + + @Test + public void testMultiDataProviderInClass() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing multi dp"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_L_ShuffledDPSimple.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + myTestNG.run(); + + assertThat("We should have 6 successful methods of phased Tests", + (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(6))); + + //Global + assertThat("We should have no failed tests", tla.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", tla.getSkippedTests().size(), equalTo(0)); + } + + @Test + public void testMultiDataProviderInClass_MERGED() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing multi dp"); + + // Add listeners + mySuite.addListener("com.adobe.campaign.tests.integro.phased.PhasedTestListener"); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_L_ShuffledDPSimple.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + ConfigValueHandlerPhased.PROP_MERGE_STEP_RESULTS.activate("true"); + + myTestNG.run(); + + ITestContext context = tla.getTestContexts().get(0); + + assertThat("We should have 6 successful methods of phased Tests", + (int) context.getPassedTests().getAllResults().stream() + .filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), + is(equalTo(4))); + + //Global + assertThat("We should have no failed tests", context.getFailedTests().size(), equalTo(0)); + assertThat("We should have no skipped tests", context.getSkippedTests().size(), equalTo(0)); + + List l_passedTestNamesContext = context.getPassedTests().getAllResults().stream() + .map(m -> m.getMethod().getMethodName()).collect(Collectors.toList()); + + assertThat("The names should have changed", l_passedTestNamesContext, + + Matchers.containsInAnyOrder( + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_0" + "__" + "M" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "2_0" + "__" + "Z" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_1" + "__" + "M" + "__" + + Phases.getCurrentPhase().toString(), + PhasedTestManager.STD_PHASED_GROUP_PREFIX + "1_1" + "__" + "Z" + "__" + + Phases.getCurrentPhase().toString())); + } + + //Related to issue #27 errors when we have no arguments + @Test + public void testInsufficientArguments_Negative() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing multi dp"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_L_ShuffledNoArgs.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + assertThrows(PhasedTestConfigurationException.class, myTestNG::run); + + } + + //Related to issue #28 errors when we have the wrong number of arguments + @Test + public void testInsufficientArguments_NegativeWrongArgs() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing multi dp"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + final Class l_testClass = PhasedSeries_L_ShuffledWrongArgs.class; + myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); + + // Add package to test + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + + assertThrows(PhasedTestConfigurationException.class, myTestNG::run); + + } + + // ************** Testing issue #9 regarding the feature "select tests by produced data " + + @Test + public void testConsumer_selectionBasedOnProducer_Deactivated() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put(PhasedSeries_H_SingleClass.class.getTypeName() + ".step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager + .storeTestData(PhasedSeries_H_SingleClass.class, PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + assertThat("We should not be in the SELECT_BY_PRODUCER mode", + !PhasedTestManager.isTestsSelectedByProducerMode()); + + myTestNG.run(); + + assertThat("We should not be in the SELECT_BY_PRODUCER mode", + !PhasedTestManager.isTestsSelectedByProducerMode()); + + assertThat( + "Since we have not passed the test group PHASED_PRODUCED_TESTS, we should have no successful methods of phased Tests", + (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(0))); + } + + /** + * Starting from here we use the properties file as a test selector. + *

+ * Author : gandomi + */ + @Test + public void testConsumer_selectionBasedOnProducerFile() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + //This activates the selection + myTest.addIncludedGroup(PhasedTestManager.STD_GROUP_SELECT_TESTS_BY_PRODUCER); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put(PhasedSeries_H_SingleClass.class.getTypeName() + ".step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager + .storeTestData(PhasedSeries_H_SingleClass.class, PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + assertThat("We should not be in the SELECT_BY_PRODUCER mode", + !PhasedTestManager.isTestsSelectedByProducerMode()); + + myTestNG.run(); + + assertThat("We should be in the SELECT_BY_PRODUCER mode", PhasedTestManager.isTestsSelectedByProducerMode()); + + assertThat("The number of tests should not have changed", + tla.getTestContexts().get(0).getSuite().getXmlSuite().getTests().size(), equalTo(1)); + + assertThat("We should have 1 successful methods of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(1))); + + } + + /** + * Starting from here we use the properties file as a test selector. + * + * In this case we are in producer mode. + *

+ * Author : gandomi + */ + @Test + public void testConsumer_selectionBasedOnProducerFile_NegativeInProducer() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Phased Tests"); + + //This activates the selection + myTest.addIncludedGroup(PhasedTestManager.STD_GROUP_SELECT_TESTS_BY_PRODUCER); + + ExecutionMode.INTERRUPTIVE.activate("PRODUCER"); + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put(PhasedSeries_H_SingleClass.class.getTypeName() + ".step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager + .storeTestData(PhasedSeries_H_SingleClass.class, PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + assertThat("We should not be in the SELECT_BY_PRODUCER mode", + !PhasedTestManager.isTestsSelectedByProducerMode()); + + myTestNG.run(); + + assertThat("We should be in the SELECT_BY_PRODUCER mode", PhasedTestManager.isTestsSelectedByProducerMode()); + + assertThat("The number of tests should not have changed", + tla.getTestContexts().get(0).getSuite().getXmlSuite().getTests().size(), equalTo(1)); + + assertThat("We should have 1 successful methods of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(1))); + + } + + /** + * In this test the same phased test is select by direct group selection and by selection through producer what we + * want is that this test should only be executed once + */ + @Test + public void testSelectedByProducer_groupSelected() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Create an instance of XmlTest and assign a name for it. + XmlTest myTest = TestTools.attachTestToSuite(mySuite, "Test Repetetive Phased Tests Producer"); + + //Define packages + List l_packages = new ArrayList<>(); + l_packages.add(new XmlPackage("com.adobe.campaign.tests.integro.phased.data")); + myTest.setXmlPackages(l_packages); + + myTest.addIncludedGroup("PROPERTIES_SELECT"); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + //Fill producer data + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put(PhasedSeries_H_SingleClass.class.getTypeName() + ".step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager + .storeTestData(PhasedSeries_H_SingleClass.class, PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + myTestNG.run(); + + assertThat("We should have 1 successful methods of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(1))); + } + + /** + * Testing how the feature of selection by properties works if we have many tests. In this example we have two + * tests. The first one executes a normal test. The second one has the execute by producer activated + */ + @Test + public void testSelectByProperties_multiTest() { + // Rampup + TestNG myTestNG = TestTools.createTestNG(); + TestListenerAdapter tla = TestTools.fetchTestResultsHandler(myTestNG); + + // Define suites + XmlSuite mySuite = TestTools.addSuitToTestNGTest(myTestNG, "Automated Suite Phased Testing"); + + // Add listeners + mySuite.addListener(PhasedTestListener.class.getTypeName()); + + // Test1 - include a simple test + XmlTest myTest1 = TestTools.attachTestToSuite(mySuite, "Two tests in suite #1. Normal test"); + + //Define packages + List l_packages = new ArrayList<>(); + l_packages.add(new XmlPackage("com.adobe.campaign.tests.integro.phased.data")); + myTest1.setXmlPackages(l_packages); + + myTest1.addIncludedGroup("PROPERTIES_TEST2"); + + //Test 2 - Include the phased test to be selected from producer + + XmlTest myTest2 = TestTools.attachTestToSuite(mySuite, "Two tests in suite. Contains phased test."); + + //This activates the selection for selection by Producerr + myTest2.addIncludedGroup(PhasedTestManager.STD_GROUP_SELECT_TESTS_BY_PRODUCER); + + ExecutionMode.INTERRUPTIVE.activate("CONSUMER"); + + //Fill producer data + Properties phasedCache = PhasedTestManager.phasedCache; + phasedCache.put(PhasedSeries_H_SingleClass.class.getTypeName() + ".step2(" + + PhasedTestManager.STD_PHASED_GROUP_SINGLE + ")", "AB"); + + PhasedTestManager + .storeTestData(PhasedSeries_H_SingleClass.class, PhasedTestManager.STD_PHASED_GROUP_SINGLE, true); + + myTestNG.run(); + + assertThat("We should have a total of 2 successful methods", tla.getPassedTests().size(), is(equalTo(2))); + + assertThat("We should have 1 successful methods of phased Tests", (int) tla.getPassedTests().stream() + .filter(m -> m.getInstance().getClass().equals(PhasedSeries_H_SingleClass.class)).count(), + is(equalTo(1))); + } +} diff --git a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java index c7b7789..abe5b21 100644 --- a/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java +++ b/src/test/java/com/adobe/campaign/tests/integro/phased/TestPhasedNonInterruptive.java @@ -13,9 +13,14 @@ import com.adobe.campaign.tests.integro.phased.data.events.*; 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.*; +import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser; +import com.adobe.campaign.tests.integro.phased.utils.GeneralTestUtils; +import com.adobe.campaign.tests.integro.phased.utils.MockTestTools; +import com.adobe.campaign.tests.integro.phased.utils.TestTools; import org.hamcrest.Matchers; -import org.testng.*; +import org.testng.ITestResult; +import org.testng.TestListenerAdapter; +import org.testng.TestNG; import org.testng.annotations.AfterMethod; import org.testng.annotations.BeforeMethod; import org.testng.annotations.Test; @@ -25,7 +30,10 @@ import java.io.File; import java.lang.reflect.Method; -import java.util.*; +import java.util.Arrays; +import java.util.Collections; +import java.util.Date; +import java.util.LinkedHashSet; import java.util.stream.Collectors; import static org.hamcrest.MatcherAssert.assertThat; @@ -420,12 +428,12 @@ public void testNonInterruptive_ParellelHardCoded_SINGLE() { final Class l_testClass = TestSINGLEWithEvent_eventAsAnnotation.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); myTestNG.run(); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), equalTo(Phases.ASYNCHRONOUS)); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), - not(equalTo(Phases.NON_PHASED))); + assertThat("The correct phase must have been selected", ExecutionMode.NON_INTERRUPTIVE.isSelected("33")); + assertThat("The correct phase must have been selected", ExecutionMode.getCurrentMode(), + not(equalTo(ExecutionMode.STANDARD))); assertThat("We should have 3 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -490,13 +498,13 @@ public void testNonInterruptive_ParellelConfigured_SINGLELegacy() { final Class l_testClass = TestSINGLEWithEvent_eventAsExecProperty.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); myTestNG.run(); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), equalTo(Phases.ASYNCHRONOUS)); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), - not(equalTo(Phases.NON_PHASED))); + assertThat("The correct phase must have been selected", ExecutionMode.getCurrentMode(), equalTo(ExecutionMode.NON_INTERRUPTIVE)); + assertThat("The correct phase must have been selected", ExecutionMode.getCurrentMode(), + not(equalTo(ExecutionMode.STANDARD))); assertThat("We should have 3 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -562,13 +570,13 @@ public void testNonInterruptive_ParellelConfigured_SINGLE() { final Class l_testClass = TestSINGLEWithEvent_eventAsExecProperty.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); myTestNG.run(); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), equalTo(Phases.ASYNCHRONOUS)); - assertThat("The correct phase must have been selected", Phases.getCurrentPhase(), - not(equalTo(Phases.NON_PHASED))); + assertThat("The correct phase must have been selected", ExecutionMode.getCurrentMode(), equalTo(ExecutionMode.NON_INTERRUPTIVE)); + assertThat("The correct phase must have been selected", ExecutionMode.getCurrentMode(), + not(equalTo(ExecutionMode.STANDARD))); assertThat("We should have 3 successful methods of phased Tests", (int) tla.getPassedTests().stream().filter(m -> m.getInstance().getClass().equals(l_testClass)).count(), @@ -633,7 +641,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_ShuffledLe final Class l_testClass = TestShuffled_eventPassedAsExecutionVariable.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); myTestNG.run(); @@ -674,7 +682,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled() final Class l_testClass = PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); myTestNG.run(); @@ -716,7 +724,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariableTargetted_S final Class l_testClass = PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); ConfigValueHandlerPhased.EVENT_TARGET.activate(PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class.getTypeName()+"#step3"); @@ -759,7 +767,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariable_Shuffled_O final Class l_testClass = TestOrderedShuffled_eventPassedAsExecutionVariable.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); ConfigValueHandlerPhased.PHASED_TEST_DETECT_ORDER.activate("true"); @@ -799,7 +807,7 @@ public void testNonInterruptive_ParellelConfigured_Shuffled_AfterPhase() { final Class l_testClass = TestShuffled_eventConfiguredAfter.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName()); assertThat("The after phase should not yet have been updated", TestShuffled_eventConfiguredAfter.originalValue, Matchers.equalTo(0)); @@ -844,7 +852,7 @@ public void testNonInterruptive_ParellelConfiguredOnPhaseTestAnnotation_Shuffled final Class l_testClass = TestShuffled_eventDefinedOnPhasedTestAnnotation.class; myTest.setXmlClasses(Collections.singletonList(new XmlClass(l_testClass))); - Phases.ASYNCHRONOUS.activate(); + ExecutionMode.NON_INTERRUPTIVE.activate("33"); myTestNG.run();