Skip to content

Commit

Permalink
Add support for Priority in Configuration Methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Martin Aldrin committed Oct 25, 2021
1 parent 49dbdc9 commit cd9cbf2
Show file tree
Hide file tree
Showing 18 changed files with 219 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the valude (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -99,4 +99,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -77,4 +77,11 @@
* @return the value (default 0)
*/
long timeOut() default 0;

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int priority() default 0;
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,4 +40,11 @@ public interface ITestOrConfiguration extends IParameterizable {
String getDescription();

void setDescription(String description);

/**
* The scheduling priority. Lower priorities will be scheduled first.
*
* @return the value (default 0)
*/
int getPriority();
}
Original file line number Diff line number Diff line change
Expand Up @@ -327,7 +327,7 @@ public int getPriority() {

@Override
public void setPriority(int priority) {
// ignored
m_method.setPriority(priority);
}

@Override
Expand All @@ -337,7 +337,7 @@ public int getInterceptedPriority() {

@Override
public void setInterceptedPriority(int priority) {
// ignored
m_method.setInterceptedPriority(priority);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -409,6 +409,7 @@ private void init() {
m_inheritGroupsFromTestClass = annotation.getInheritGroups();
setEnabled(annotation.getEnabled());
setDescription(annotation.getDescription());
setPriority(annotation.getPriority());
}

if (annotation != null && annotation.isFakeConfiguration()) {
Expand Down Expand Up @@ -503,6 +504,7 @@ public ConfigurationMethod clone() {
clone.setDescription(getDescription());
clone.setEnabled(getEnabled());
clone.setParameterInvocationCount(getParameterInvocationCount());
clone.setPriority(getPriority());
clone.m_inheritGroupsFromTestClass = inheritGroupsFromTestClass();

return clone;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -197,6 +197,7 @@ private static void finishInitialize(
result.setGroups(bs.getGroups());
result.setInheritGroups(bs.getInheritGroups());
result.setTimeOut(bs.getTimeOut());
result.setPriority(bs.getPriority());
}

public static List<Class<? extends IAnnotation>> getAllAnnotations() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,6 +109,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterSuite.class) {
AfterSuite bs = (AfterSuite) a;
Expand Down Expand Up @@ -136,6 +137,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeTest.class) {
BeforeTest bs = (BeforeTest) a;
Expand Down Expand Up @@ -163,6 +165,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterTest.class) {
AfterTest bs = (AfterTest) a;
Expand Down Expand Up @@ -190,6 +193,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeGroups.class) {
BeforeGroups bs = (BeforeGroups) a;
Expand Down Expand Up @@ -218,6 +222,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterGroups.class) {
AfterGroups bs = (AfterGroups) a;
Expand Down Expand Up @@ -246,6 +251,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeClass.class) {
BeforeClass bs = (BeforeClass) a;
Expand Down Expand Up @@ -273,6 +279,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IAfterClass.class) {
AfterClass bs = (AfterClass) a;
Expand Down Expand Up @@ -300,6 +307,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
false,
bs.timeOut(),
bs.priority(),
new String[0]);
} else if (annotationClass == IBeforeMethod.class) {
BeforeMethod bs = (BeforeMethod) a;
Expand Down Expand Up @@ -327,6 +335,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
bs.firstTimeOnly(),
false,
bs.timeOut(),
bs.priority(),
bs.onlyForGroups());
} else if (annotationClass == IAfterMethod.class) {
AfterMethod bs = (AfterMethod) a;
Expand Down Expand Up @@ -354,6 +363,7 @@ private IAnnotation maybeCreateNewConfigurationTag(Annotation a, Class<?> annota
false,
bs.lastTimeOnly(),
bs.timeOut(),
bs.priority(),
bs.onlyForGroups());
}

Expand Down Expand Up @@ -383,6 +393,7 @@ private IAnnotation createConfigurationTag(
boolean firstTimeOnly,
boolean lastTimeOnly,
long timeOut,
int priority,
String[] groupFilters) {
ConfigurationAnnotation result = new ConfigurationAnnotation();
result.setIsBeforeGroups(isBeforeGroups);
Expand Down Expand Up @@ -410,6 +421,7 @@ private IAnnotation createConfigurationTag(
result.setFirstTimeOnly(firstTimeOnly);
result.setLastTimeOnly(lastTimeOnly);
result.setTimeOut(timeOut);
result.setPriority(priority);

return result;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,7 @@ public void setDescription(String description) {
m_description = description;
}

@Override
public int getPriority() {
return m_priority;
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
package test;

import java.util.ArrayList;
import java.util.List;
import org.testng.annotations.AfterClass;
import org.testng.annotations.AfterMethod;
import org.testng.annotations.AfterSuite;
import org.testng.annotations.BeforeClass;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeSuite;
import org.testng.annotations.Test;

public class ConfigurationMethodPrioritySampleTest {
public static List<String> logs = new ArrayList<>();

@BeforeSuite(priority = 100)
public void beforeSuiteA() {
logs.add("beforeSuiteA");
}

@BeforeSuite(priority = 1)
public void beforeSuiteB() {
logs.add("beforeSuiteB");
}

@BeforeClass(priority = 100)
public void beforeClassA() {
logs.add("beforeClassA");
}

@BeforeClass(priority = 1)
public void beforeClassB() {
logs.add("beforeClassB");
}

@BeforeMethod(priority = 100)
public void beforeMethodA() {
logs.add("beforeMethodA");
}

@BeforeMethod(priority = 1)
public void beforeMethodB() {
logs.add("beforeMethodB");
}

@Test(priority = 100)
public void testA() {
logs.add("TestA");
}

@Test(priority = 0)
public void testB() {
logs.add("TestB");
}

@AfterSuite(priority = 100)
public void afterSuiteA() {
logs.add("afterSuiteA");
}

@AfterSuite(priority = 1)
public void afterSuiteB() {
logs.add("afterSuiteB");
}

@AfterClass(priority = 100)
public void afterClassA() {
logs.add("afterClassA");
}

@AfterClass(priority = 1)
public void afterClassB() {
logs.add("afterClassB");
}

@AfterMethod(priority = 100)
public void afterMethodA() {
logs.add("afterMethodA");
}

@AfterMethod(priority = 1)
public void afterMethodB() {
logs.add("afterMethodB");
}
}
Loading

0 comments on commit cd9cbf2

Please sign in to comment.