Skip to content

Commit

Permalink
In mutational #183 removing the Phased annotation from the motational…
Browse files Browse the repository at this point in the history
… tests
  • Loading branch information
baubakg committed Sep 30, 2024
1 parent c5fa229 commit 2c538ee
Show file tree
Hide file tree
Showing 7 changed files with 150 additions and 14 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import com.adobe.campaign.tests.integro.phased.utils.ClassPathParser;
import org.testng.ITestResult;

import java.lang.reflect.Method;
import java.util.stream.Collectors;

public class MutationManager {
Expand All @@ -34,10 +35,29 @@ public static String fetchScenarioName(ITestResult in_testNGResult) {
* @param in_testResult The test result
* @return true if it is a mutational test
*/
public static boolean isMutational(ITestResult in_testResult) {
public static boolean isMutationalTest(ITestResult in_testResult) {
return in_testResult.getMethod().getRealClass().getTypeName().equals(Mutational.class.getTypeName());
}

/**
* Lets us know if the given class is a mutational class. This means that it is a sub-class of Mutational
* @param in_class a candidate class
* @return true if the class inherits from Mutational
*/
public static boolean isMutationalTest(Class in_class) {

return in_class.getSuperclass() != null ? in_class.getSuperclass().equals(Mutational.class) : false;
}

/**
* Lets us know if the given method is part of a mutational test. This means that it is a sub-class of Mutational
* @param in_method a candidate class
* @return true if the method is part of a class that inherits from Mutational
*/
public static boolean isMutationalTest(Method in_method) {
return isMutationalTest(in_method.getDeclaringClass());
}

public static String fetchScenarioName(String in_classFullName, String in_shuffleGroup) {
return in_classFullName + ClassPathParser.fetchParameterValues(in_shuffleGroup);
}
Expand Down Expand Up @@ -77,4 +97,26 @@ public static Integer[] fetchExecutionIndex(String in_className, String in_phase

return lr_result;
}

/**
* This method lets us know if the steps in a PhasedTest are to be executed in a Shuffled manner. For a test with 3
* steps the test will be executed 6 times in total
*
* @param in_class A test class/scenario
* @return True if the given test scenario is a Shuffled Phased Test scenario
*/
public static boolean isShuffleMode(Class<?> in_class) {
return !PhasedTestManager.isPhasedTestWithEvent(in_class) && !PhasedTestManager.isPhasedTestTargetOfEvent(in_class);
}

/**
* This method lets us know if the steps in a PhasedTest are to be executed consequently in two phases
*
* @param in_class Any class that contains tests
* @return True if the test class is a SingleRun Phase Test scenario
*/
public static boolean isSingleMode(Class<?> in_class) {
return isMutationalTest(in_class) && (PhasedTestManager.isPhasedTestWithEvent(in_class) || PhasedTestManager.isPhasedTestTargetOfEvent(in_class));

}
}
Original file line number Diff line number Diff line change
Expand Up @@ -893,7 +893,7 @@ static boolean isPhaseLimit(Method in_method) {
* @return true if The annotations PhasedTest and PhasedStep are present
*/
public static boolean isPhasedTest(Method in_method) {
return isPhasedTest(in_method.getDeclaringClass());
return isPhasedTest(in_method.getDeclaringClass()) || MutationManager.isMutationalTest(in_method);
}

/**
Expand All @@ -905,7 +905,7 @@ public static boolean isPhasedTest(Method in_method) {
* @return True if the class is a phased test scenario
*/
public static boolean isPhasedTest(Class<?> in_class) {
return in_class.isAnnotationPresent(PhasedTest.class);
return in_class.isAnnotationPresent(PhasedTest.class) || MutationManager.isMutationalTest(in_class);
}

/**
Expand All @@ -925,6 +925,10 @@ static boolean isPhasedTestSingleMode(Method in_method) {
* @return True if the test class is a SingleRun Phase Test scenario
*/
static boolean isPhasedTestSingleMode(Class<?> in_class) {
if (MutationManager.isMutationalTest(in_class)) {
return MutationManager.isSingleMode(in_class);
}

//TODO in 8.11.3 to be removed - make public
//return isPhasedTest(in_class) && (isPhasedTestWithEvent(in_class)
return isPhasedTest(in_class) && (isPhasedTestWithEvent(in_class) || !in_class.getAnnotation(PhasedTest.class).canShuffle()) || isPhasedTestTargetOfEvent(in_class);
Expand Down Expand Up @@ -960,6 +964,9 @@ static boolean isPhasedTestShuffledMode(ITestResult in_testResult) {
* @return True if the given test scenario is a Shuffled Phased Test scenario
*/
static boolean isPhasedTestShuffledMode(Class<?> in_class) {
if (MutationManager.isMutationalTest(in_class)) {
return MutationManager.isShuffleMode(in_class);
}
return isPhasedTest(in_class) && !isPhasedTestWithEvent(in_class) && in_class.getAnnotation(PhasedTest.class)
.canShuffle() && !isPhasedTestTargetOfEvent(in_class);
}
Expand All @@ -974,7 +981,7 @@ static boolean isPhasedTestShuffledMode(Class<?> in_class) {
* @return The identity of the scenario
*/
public static String fetchScenarioName(ITestResult in_testNGResult) {
if (MutationManager.isMutational(in_testNGResult)) {
if (MutationManager.isMutationalTest(in_testNGResult)) {
return MutationManager.fetchScenarioName(in_testNGResult);
}
return in_testNGResult.getMethod().getConstructorOrMethod().getMethod().getDeclaringClass()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,12 @@
*/
package com.adobe.campaign.tests.integro.phased;

import com.adobe.campaign.tests.integro.phased.data.NormalSeries_A;
import com.adobe.campaign.tests.integro.phased.data.PhasedSeries_F_Shuffle;
import com.adobe.campaign.tests.integro.phased.data.PhasedSeries_H_ShuffledClassWithError;
import com.adobe.campaign.tests.integro.phased.mutational.data.nested.MutationalTestParent;
import com.adobe.campaign.tests.integro.phased.mutational.data.simple1.PhasedChild1;
import com.adobe.campaign.tests.integro.phased.mutational.data.simple1.PhasedChild2;
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 org.hamcrest.Matchers;
Expand All @@ -23,10 +25,6 @@

import java.io.File;
import java.lang.reflect.Method;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
Expand Down Expand Up @@ -97,7 +95,7 @@ public void testIsMutational() throws NoSuchMethodException, SecurityException {

ITestResult l_itr = createMutationalMock(expected, "Q");

assertThat("This should be a mutational test", MutationManager.isMutational(l_itr));
assertThat("This should be a mutational test", MutationManager.isMutationalTest(l_itr));
}

@Test
Expand All @@ -109,7 +107,7 @@ public void testIsMutational_negativeNonMutational() throws NoSuchMethodExceptio

ITestResult l_itr = MockTestTools.generateTestResultMock(l_myTestWithOneArg, l_argumentObjects);

assertThat("We should have the correct full name", !MutationManager.isMutational(l_itr));
assertThat("We should have the correct full name", !MutationManager.isMutationalTest(l_itr));
}

@Test
Expand Down Expand Up @@ -145,5 +143,61 @@ public void testExecutionIndex_InterruptiveProducer() {
Matchers.arrayContaining(0, 3));
}

@Test
public void testIfTestIsMutationalSimple() {
Class l_testClass = PhasedChild1.class;

assertThat("This should be a mutational test", MutationManager.isMutationalTest(l_testClass));

assertThat("A mutational test is a phasedTest", PhasedTestManager.isPhasedTest(l_testClass));

Class l_nonMutationalClass = NormalSeries_A.class;
assertThat("This should not be a mutational test", !MutationManager.isMutationalTest(l_nonMutationalClass));



}

@Test
public void testIfTestIsMutationalNested() {
Class l_testClass = MutationalTestParent.MutationalChildTest1.class;

assertThat("This should be a mutational test", MutationManager.isMutationalTest(l_testClass));

assertThat("TA mutational test is a phasedTest", PhasedTestManager.isPhasedTest(l_testClass));

}


@Test
public void testIfTestIsMutationalMethod() throws NoSuchMethodException {
Method l_testMethod = PhasedChild1.class.getMethod("step1", String.class);

assertThat("This should be a mutational test", MutationManager.isMutationalTest(l_testMethod));

assertThat("A mutational test is a phasedTest", PhasedTestManager.isPhasedTest(l_testMethod));


Method l_nonMutationalMethod = NormalSeries_A.class.getMethod("firstTest");
assertThat("This should not be a mutational test", !MutationManager.isMutationalTest(l_nonMutationalMethod));

Method l_nonMutationalMethod2 = Object.class.getMethod("wait");
assertThat("This should not be a mutational test", !MutationManager.isMutationalTest(l_nonMutationalMethod));

}

@Test
public void testIsShuffled_Mutational() throws SecurityException {
Class l_myClass = PhasedChild1.class;

assertThat("We should be in Shuffled mode", PhasedTestManager.isPhasedTestShuffledMode(l_myClass));
assertThat("We should not be in Single mode", !PhasedTestManager.isPhasedTestSingleMode(l_myClass));

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


}
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
import static org.testng.Assert.assertFalse;

@Test
@PhasedTest
public class IE_Shuffled_ErrorAssertion1 extends Mutational {

public void step1(String val) {
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/*
* 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.mutational.data.nested;

import com.adobe.campaign.tests.integro.phased.Mutational;
import com.adobe.campaign.tests.integro.phased.PhasedTestManager;
import org.testng.annotations.Test;

import static org.testng.Assert.assertFalse;

public class MutationalTestParent {
@Test(groups = "nested")
public class MutationalChildTest1 extends Mutational {

public void step1(String val) {
System.out.println("step1 " + val);
PhasedTestManager.produceInStep("A");
}

public void step2(String val) {
System.out.println("step2 " + val);
String l_fetchedValue = PhasedTestManager.consumeFromStep("step1");
assertFalse(true);
PhasedTestManager.produceInStep(l_fetchedValue + "B");

}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.testng.annotations.Test;

//@Test(groups = "aaa", dataProvider = "MUTATIONAL", dataProviderClass = PhasedDataProvider.class)
@PhasedTest
//@PhasedTest
@Test(groups = "aaa")
public class PhasedChild1 extends Mutational {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
import org.testng.annotations.Test;

//@Test(groups = "aaa", dataProvider = "MUTATIONAL", dataProviderClass = PhasedDataProvider.class)
@PhasedTest
//@PhasedTest
@Test(groups = "aaa")
public class PhasedChild2 extends Mutational {

Expand Down

0 comments on commit 2c538ee

Please sign in to comment.