3030 * @since v1.0
3131 */
3232public class GathererControllerTest {
33+
3334 /**
3435 * The JDBC URL of the database to modify
3536 */
@@ -54,42 +55,10 @@ public class GathererControllerTest {
5455 private final ByteArrayOutputStream outContent = new ByteArrayOutputStream ();
5556 private final ByteArrayOutputStream errContent = new ByteArrayOutputStream ();
5657
57- @ org .junit .Before
58- public void setUpStreams () {
59- System .setOut (new PrintStream (outContent ));
60- System .setErr (new PrintStream (errContent ));
61- }
62-
63- @ org .junit .After
64- public void cleanUpStreams () {
65- System .setOut (null );
66- System .setErr (null );
67- }
68-
69- /**
70- * Before running drop the table.
71- */
7258 @ BeforeClass
7359 public static void setUpBaseClass () {
7460 try {
7561 readConfig ();
76- StringBuilder sbSQL = new StringBuilder ();
77- //DROP existing test tables
78- sbSQL .append ("DROP TABLE tblplayers_test;" );
79- sbSQL .append ("DROP TABLE tblplayers_test_two;" );
80-
81- for (String strRealm : GathererController .getRealms ()) {
82- sbSQL .append ("DROP TABLE " + strRealm + ";" );
83- }
84-
85- java .sql .Connection conn = openConnection ();
86- try {
87- Statement stmt = conn .createStatement ();
88- stmt .executeUpdate (sbSQL .toString ());
89- } catch (SQLException e ) {
90-
91- }
92- closeConnection (conn );
9362
9463 } catch (ParserConfigurationException e ) {
9564 e .printStackTrace ();
@@ -98,7 +67,38 @@ public static void setUpBaseClass() {
9867 } catch (SAXException e ) {
9968 e .printStackTrace ();
10069 }
70+ }
10171
72+ /**
73+ * Before running each test, drop tables and pipe output into buffer
74+ */
75+ @ org .junit .Before
76+ public void setUpDB () {
77+ System .setOut (new PrintStream (outContent ));
78+ System .setErr (new PrintStream (errContent ));
79+ StringBuilder sbSQL = new StringBuilder ();
80+ //DROP existing test tables
81+ sbSQL .append ("DROP TABLE tblplayers_test;" );
82+ sbSQL .append ("DROP TABLE tblplayers_test_two;" );
83+
84+ for (String strRealm : GathererController .getRealms ()) {
85+ sbSQL .append ("DROP TABLE " + strRealm + ";" );
86+ }
87+
88+ java .sql .Connection conn = openConnection ();
89+ try {
90+ Statement stmt = conn .createStatement ();
91+ stmt .executeUpdate (sbSQL .toString ());
92+ } catch (SQLException e ) {
93+
94+ }
95+ closeConnection (conn );
96+ }
97+
98+ @ org .junit .After
99+ public void cleanUpStreams () {
100+ System .setOut (null );
101+ System .setErr (null );
102102 }
103103
104104 /**
@@ -113,7 +113,7 @@ public void testRunBasic() throws IOException, SAXException, ParserConfiguration
113113 int startId = 11886902 ;
114114 int endId = 11887010 ;
115115 GathererController gathererController = new GathererController (startId , endId );
116- gathererController .setTableName ("tblplayers_test " );
116+ gathererController .setTableName ("tblplayers_test_3 " );
117117 try {
118118 gathererController .run ();
119119 } catch (Exception e ) {
@@ -161,7 +161,8 @@ public void testRunBasicInvalidParams() {
161161 }
162162
163163 /**
164- * Perform a test run of GathererController with values passed in via constructor.
164+ * Perform a test run of GathererController with values passed in via
165+ * constructor.
165166 */
166167 @ org .junit .Test
167168 public void testRunAdvancedOptions () {
@@ -196,7 +197,8 @@ public void testRunAdvancedOptions() {
196197 }
197198
198199 /**
199- * Invoke a test run in which the single characters table is being split across several tables, one for each realm.
200+ * Invoke a test run in which the single characters table is being split
201+ * across several tables, one for each realm.
200202 *
201203 * Also testing non-verbose mode, debug output (print non-existant records).
202204 */
@@ -205,7 +207,7 @@ public void testRunSplitTables() {
205207 int startId = 1557260 ;
206208 int endId = 1558260 ;
207209
208- GathererController gathererController = new GathererController (startId , endId , false , true , false , true , false , dbHost , dbName , dbUser , dbPassword , 71 , "_test" , true );
210+ GathererController gathererController = new GathererController (startId , endId , false , true , false , false , false , dbHost , dbName , dbUser , dbPassword , 71 , "_test" , true );
209211 try {
210212 gathererController .run ();
211213 } catch (Exception e ) {
@@ -224,7 +226,6 @@ public void testRunSplitTables() {
224226 ArrayList addedIDsMoogle = getAdded (conn , strSQLMoogle );
225227 closeConnection (conn );
226228
227-
228229 //Test for IDs we know exist in cerberus (realm of startID char)
229230 assertTrue (addedIDsCerberus .contains (startId ));
230231 assertTrue (addedIDsCerberus .contains (1557648 ));
@@ -294,7 +295,6 @@ public void testRunMisconfiguredTwo() {
294295 }
295296
296297 //Utility methods
297-
298298 /**
299299 * Open a connection to database.
300300 *
@@ -329,9 +329,10 @@ private static void closeConnection(java.sql.Connection conn) {
329329 /**
330330 * Read configuration from config.xml
331331 *
332- * @throws ParserConfigurationException Indicates a serious configuration error.
333- * @throws IOException Indicates an error reading the file specified.
334- * @throws SAXException Indicates an error parsing XML.
332+ * @throws ParserConfigurationException Indicates a serious configuration
333+ * error.
334+ * @throws IOException Indicates an error reading the file specified.
335+ * @throws SAXException Indicates an error parsing XML.
335336 */
336337 public static void readConfig () throws ParserConfigurationException , IOException , SAXException {
337338 //Set config file location
@@ -357,7 +358,7 @@ public static void readConfig() throws ParserConfigurationException, IOException
357358 /**
358359 * Execute a SQL query and return the results.
359360 *
360- * @param conn the SQL connection to use.
361+ * @param conn the SQL connection to use.
361362 * @param strSQL the SQL statement to execute.
362363 * @return the result set of added rows.
363364 */
@@ -376,9 +377,10 @@ public static ResultSet executeStatement(Connection conn, String strSQL) {
376377 }
377378
378379 /**
379- * Get an array list containing the added IDs returned by executing a SQL statement.
380+ * Get an array list containing the added IDs returned by executing a SQL
381+ * statement.
380382 *
381- * @param conn the SQL connection to use.
383+ * @param conn the SQL connection to use.
382384 * @param strSQL the SQL statement to execute
383385 * @return an array list of the IDs successfully added to DB.
384386 */
@@ -396,4 +398,4 @@ public static ArrayList getAdded(Connection conn, String strSQL) {
396398 }
397399 return addedIDs ;
398400 }
399- }
401+ }
0 commit comments