1414 */
1515public class TestManager extends ResourceManager {
1616
17+ public final static String FORMAT_JUNIT = "junit" ;
18+
19+ /**
20+ * The "none" format means that the XML will be returned from the ml-unit-test endpoint without any additional
21+ * formatting applied to it.
22+ */
23+ public final static String FORMAT_NONE = "" ;
24+
1725 private ServiceResponseUnmarshaller unitTestXmlParser ;
1826
1927 public TestManager (DatabaseClient client ) {
@@ -59,9 +67,21 @@ public List<String> listSuites() {
5967 * @return
6068 */
6169 public TestSuiteResult run (TestModule testModule ) {
62- RequestParameters params = new RequestParameters ();
63- params .add ("func" , "run" );
64- params .add ("suite" , testModule .getSuite ());
70+ return run (testModule , true , true );
71+ }
72+
73+ /**
74+ *
75+ * Run a single test module. This is intended to be used in a parameterized JUnit test, where each test
76+ * module is intended to correspond to a separate JUnit test.
77+ *
78+ * @param testModule
79+ * @param runTeardown
80+ * @param runSuiteTeardown
81+ * @return
82+ */
83+ public TestSuiteResult run (TestModule testModule , boolean runTeardown , boolean runSuiteTeardown ) {
84+ RequestParameters params = buildRequestParameters (testModule .getSuite (), FORMAT_NONE , runTeardown , runSuiteTeardown );
6585
6686 String test = testModule .getTest ();
6787 if (test != null ) {
@@ -76,10 +96,20 @@ public TestSuiteResult run(TestModule testModule) {
7696 * @return a JUnitTestSuite for every suite found in the modules database
7797 */
7898 public List <JUnitTestSuite > runAllSuites () {
99+ return runAllSuites (true , true );
100+ }
101+
102+ /**
103+ *
104+ * @param runTeardown
105+ * @param runSuiteTeardown
106+ * @return a JUnitTestSuite for every suite found in the modules database
107+ */
108+ public List <JUnitTestSuite > runAllSuites (boolean runTeardown , boolean runSuiteTeardown ) {
79109 List <String > suiteNames = listSuites ();
80110 List <JUnitTestSuite > suites = new ArrayList <>();
81111 for (String suiteName : suiteNames ) {
82- suites .add (runSuite (suiteName ));
112+ suites .add (runSuite (suiteName , runTeardown , runSuiteTeardown ));
83113 }
84114 return suites ;
85115 }
@@ -93,14 +123,19 @@ public JUnitTestSuite runSuite(String suite) {
93123 }
94124
95125 public JUnitTestSuite runSuite (String suite , boolean runTeardown , boolean runSuiteTeardown ) {
126+ RequestParameters params = buildRequestParameters (suite , FORMAT_JUNIT , runTeardown , runSuiteTeardown );
127+ String xml = getServices ().post (params , (AbstractWriteHandle ) null , new StringHandle ()).get ();
128+ return unitTestXmlParser .parseJUnitTestSuiteResult (xml );
129+ }
130+
131+ protected RequestParameters buildRequestParameters (String suite , String format , boolean runTeardown , boolean runSuiteTeardown ) {
96132 RequestParameters params = new RequestParameters ();
97133 params .add ("func" , "run" );
98134 params .add ("suite" , suite );
99- params .add ("format" , "junit" );
135+ params .add ("format" , format );
100136 params .add ("runsuiteteardown" , String .valueOf (runSuiteTeardown ));
101137 params .add ("runteardown" , String .valueOf (runTeardown ));
102- String xml = getServices ().post (params , (AbstractWriteHandle ) null , new StringHandle ()).get ();
103- return unitTestXmlParser .parseJUnitTestSuiteResult (xml );
138+ return params ;
104139 }
105140
106141 public void setUnitTestXmlParser (ServiceResponseUnmarshaller unitTestXmlParser ) {
0 commit comments