Skip to content

Commit

Permalink
Fixed #178 added examples for nested classes
Browse files Browse the repository at this point in the history
  • Loading branch information
baubakg committed Aug 30, 2024
1 parent 571dfeb commit 976aa74
Show file tree
Hide file tree
Showing 8 changed files with 73 additions and 17 deletions.
24 changes: 24 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,26 @@ This works for both Shuffled and Single-Run tests. If we want to run all tests w

You can also add it as a property in your testng definition file.

#### Targeting an Event to a Specific Step
As of version 8.11.2, we can inject an event to a specific step of a Phased Scenario. This is done by:
* Declaring an event by setting the variable `PHASED.EVENTS.NONINTERRUPTIVE`.
* Identifying the step on which an event will occur. This is done by setting the variable `PHASED.EVENTS.TARGET`.

The step should point to a method. For method `step1` in the class `a.b.c.ScenarioA` you can set:
* `a.b.c.ScenarioA.step1`
* `ScenarioA#step1`
* `ScenarioA.step1`

In the case of nested tests, for method `step1` in the class `a.b.c.ScenarioA`, and sub-class `NestedClassB` you need to use the `$` notation. It will look like:
* `a.b.c.ScenarioA$NestedClassB.step1`
* `ScenarioA$NestedClassB#step1`
* `ScenarioA$NestedClassB.step1`

Here is an example of running a specific event for a specific test:

```mvn clean test -DPHASED.EVENTS.NONINTERRUPTIVE=com.adobe.campaign.tests.integro.phased.data.events.MyNonInterruptiveEvent -DPHASED.EVENTS.TARGET=ScenarioA$NestedClassB#step1 ```


### Before- and After-Phase Actions
We have introduced the possibility of defining Before and After Phases. This means that you can state if a method can be invoked before or after the phased tests are executed. These methods are only activated when we are in a Phase, and will not run when executed when we execute the scenarios in Non-Phased mode.

Expand Down Expand Up @@ -568,6 +588,10 @@ For now, we have not come around to deciding how retry should work in the case o

## Release Notes

### 8.11.2
* [#178 Allowing the injection in any step of a scenario](https://github.com/adobe/bridgeService/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.


### 8.11.1
* Renaming ConfigValueHandler to ConfigValueHandlerPhased
* Migrating to Java 11
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ 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),
EVENTS_NONINTERRUPTIVE_TARGET("PHASED.EVENTS.NONINTERRUPTIVE.INJECTINTO", null, false );
EVENT_TARGET("PHASED.EVENTS.TARGET", null, false );

public final String systemName;
public final String defaultValue;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static String fetchApplicableEvent(Method in_method) {
}
else if (in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses().length > 0) {
return in_method.getDeclaringClass().getDeclaredAnnotation(PhasedTest.class).eventClasses()[0];
} else if (ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.isSet()) {
} else if (ConfigValueHandlerPhased.EVENT_TARGET.isSet()) {
return PhasedTestManager.isPhasedTestTargetOfEvent(in_method) ? ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue() : null;
} else if (ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.isSet()) {
return ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.fetchValue();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1673,11 +1673,11 @@ public static int asynchronousExtractIndex(ITestResult in_testResult) {
* @return true if the property PHASED.EVENTS.NONINTERRUPTIVE.INJECTINTO points to a method in the class
*/
public static boolean isPhasedTestTargetOfEvent(Class in_class) {
if (!ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.isSet()) {
if (!ConfigValueHandlerPhased.EVENT_TARGET.isSet()) {
return false;
}
return ClassPathParser.elementsCorrespond(in_class,
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.fetchValue());
ConfigValueHandlerPhased.EVENT_TARGET.fetchValue());
}

/**
Expand All @@ -1687,12 +1687,12 @@ public static boolean isPhasedTestTargetOfEvent(Class in_class) {
* @return true if the property PHASED.EVENTS.NONINTERRUPTIVE.INJECTINTO points to the method
*/
public static boolean isPhasedTestTargetOfEvent(Method in_method) {
if (!ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.isSet()) {
if (!ConfigValueHandlerPhased.EVENT_TARGET.isSet()) {
return false;
}

return ClassPathParser.elementsCorrespond(in_method,
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.fetchValue());
ConfigValueHandlerPhased.EVENT_TARGET.fetchValue());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -129,7 +129,6 @@ public static File fetchClassFile(Class in_class) {
* @return if the element corresponds to the class
*/
public static boolean elementsCorrespond(Class in_class, String in_selectedElementName) {

return in_class.getTypeName().endsWith(extractElements(in_selectedElementName)[0]);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1300,7 +1300,7 @@ public void testIsShuffled_butIsSingleSinceAcynhcronousTargetted() throws NoSuch
assertThat("We should not be in Single mode", !PhasedTestManager.isPhasedTestSingleMode(l_myClass));

//Activate target event
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getTypeName()+".step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getTypeName()+".step1");
assertThat("We should not be in Shuffled mode", !PhasedTestManager.isPhasedTestShuffledMode(l_myClass));
assertThat("We should be in Single mode", PhasedTestManager.isPhasedTestSingleMode(l_myClass));

Expand All @@ -1315,15 +1315,15 @@ public void testIsTargetOfEvent() throws NoSuchMethodException, SecurityExceptio
assertThat("We should be the target of an event", !PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

//Simple
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getTypeName()+".step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getTypeName()+".step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

//Simple with #
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getSimpleName()+"#step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getSimpleName()+"#step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

//Simple with .
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getSimpleName()+".step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getSimpleName()+".step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

}
Expand All @@ -1339,15 +1339,15 @@ public void testIsTargetOfEventMethodLevel() throws NoSuchMethodException, Secur
assertThat("We should be the target of an event", !PhasedTestManager.isPhasedTestTargetOfEvent(l_targetMethod));

//Simple
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getTypeName()+".step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getTypeName()+".step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

//Simple with #
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getSimpleName()+"#step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getSimpleName()+"#step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

//Simple with .
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(l_myClass.getSimpleName()+".step1");
ConfigValueHandlerPhased.EVENT_TARGET.activate(l_myClass.getSimpleName()+".step1");
assertThat("We should be the target of an event", PhasedTestManager.isPhasedTestTargetOfEvent(l_myClass));

}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -337,7 +337,7 @@ public void testExtractEvent_SUFFLED_definitionOnAnnotation() throws NoSuchMetho
public void testExtractEventForTargettedEvent() throws NoSuchMethodException {
Method l_targettedMethodWithoutEvent = PhasedSeries_F_Shuffle.class.getMethod("step2", String.class);
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName());
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(ClassPathParser.fetchFullName(l_targettedMethodWithoutEvent));
ConfigValueHandlerPhased.EVENT_TARGET.activate(ClassPathParser.fetchFullName(l_targettedMethodWithoutEvent));

assertThat("We should correctly extract the event from the method",
PhasedEventManager.fetchApplicableEvent(l_targettedMethodWithoutEvent),
Expand Down Expand Up @@ -683,7 +683,7 @@ public void testNonInterruptive_ParellelConfiguredAsExecutionVariableTargetted_S

Phases.ASYNCHRONOUS.activate();
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE.activate(MyNonInterruptiveEvent.class.getTypeName());
ConfigValueHandlerPhased.EVENTS_NONINTERRUPTIVE_TARGET.activate(PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class.getTypeName()+"#step3");
ConfigValueHandlerPhased.EVENT_TARGET.activate(PhasedTestShuffledWithoutCanShuffleNested.PhasedTestShuffledWithoutCanShuffleNestedInner.class.getTypeName()+"#step3");

myTestNG.run();

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
import com.adobe.campaign.tests.integro.phased.PhasedTestManagerTests;
import com.adobe.campaign.tests.integro.phased.data.PhasedSeries_H_SingleClass;
import com.adobe.campaign.tests.integro.phased.data.events.TestSINGLEWithEvent_eventAsExecProperty;
import com.adobe.campaign.tests.integro.phased.data.nested.PhasedSeries_N_NestedContainer;
import com.adobe.campaign.tests.integro.phased.data.permutational.SimpleProducerConsumerNestedContainer;
import org.hamcrest.Matchers;
import org.mockito.Mockito;
Expand Down Expand Up @@ -190,7 +191,7 @@ public void testElementsCorrespondSimple() throws NoSuchMethodException {
assertThat("The class should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_class, l_selectedMethodName));

final Method l_method = TestSINGLEWithEvent_eventAsExecProperty.class.getMethod("step1", String.class);
final Method l_method = l_class.getMethod("step1", String.class);
assertThat("The method should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_method, l_selectedMethodName));

Expand All @@ -213,6 +214,38 @@ public void testElementsCorrespondSimple() throws NoSuchMethodException {
ClassPathParser.elementsCorrespond(l_method, l_selectedMethodName3));
}

@Test
public void testElementsCorrespondNested() throws NoSuchMethodException {
//Case 1: The method corresponds
String l_selectedMethodName = "com.adobe.campaign.tests.integro.phased.data.nested.PhasedSeries_N_NestedContainer$PhasedSeries_N_ShuffledClassWithError.step2";

Class l_class = PhasedSeries_N_NestedContainer.PhasedSeries_N_ShuffledClassWithError.class;
assertThat("The class should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_class, l_selectedMethodName));

final Method l_method = l_class.getMethod("step2", String.class);
assertThat("The method should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_method, l_selectedMethodName));

//Case 2 With #
String l_selectedMethodName2 = "PhasedSeries_N_NestedContainer$PhasedSeries_N_ShuffledClassWithError.step2";

assertThat("The class should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_class, l_selectedMethodName2));

assertThat("The method should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_method, l_selectedMethodName2));

//Case 3 Full with #
String l_selectedMethodName3 = "com.adobe.campaign.tests.integro.phased.data.nested.PhasedSeries_N_NestedContainer$PhasedSeries_N_ShuffledClassWithError#step2";;

assertThat("The class should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_class, l_selectedMethodName3));

assertThat("The method should correspond to the selected method",
ClassPathParser.elementsCorrespond(l_method, l_selectedMethodName3));
}

@Test
public void testExtractClassFromElementSelection() throws NoSuchMethodException, ClassNotFoundException {
//Case 1: The method corresponds
Expand Down

0 comments on commit 976aa74

Please sign in to comment.