33import org .junit .jupiter .api .Test ;
44import org .utplsql .api .reporter .DocumentationReporter ;
55import org .utplsql .api .reporter .Reporter ;
6- import org .utplsql .api .rules .DatabaseRule ;
7- import org .junit .Rule ;
86
97import java .io .File ;
108import java .io .FileOutputStream ;
119import java .io .PrintStream ;
12- import java .sql .Connection ;
1310import java .sql .SQLException ;
1411import java .util .ArrayList ;
1512import java .util .List ;
1916import static org .junit .jupiter .api .Assertions .fail ;
2017
2118/**
22- * Created by Vinicius on 13/04/2017.
19+ * Integration-test for OutputBuffers
20+ *
21+ * @author viniciusam
22+ * @author pesse
2323 */
24- public class OutputBufferIT {
25-
26- @ Rule
27- public final DatabaseRule db = new DatabaseRule ();
24+ public class OutputBufferIT extends AbstractDatabaseTest {
2825
2926 public Reporter createReporter () throws SQLException {
30- Connection conn = db .newConnection ();
31- Reporter reporter = new DocumentationReporter ().init (conn );
27+ Reporter reporter = new DocumentationReporter ().init (newConnection ());
3228 System .out .println ("Reporter ID: " + reporter .getReporterId ());
3329 return reporter ;
3430 }
3531
3632 @ Test
37- public void printAvailableLines () {
33+ public void printAvailableLines () throws SQLException {
3834 ExecutorService executorService = Executors .newFixedThreadPool (2 );
3935
4036 try {
4137 final Reporter reporter = createReporter ();
4238
4339 Future <Object > task1 = executorService .submit (() -> {
4440 try {
45- Connection conn = db .newConnection ();
4641 new TestRunner ()
47- .addPath (db . getUser ())
42+ .addPath (getUser ())
4843 .addReporter (reporter )
49- .run (conn );
44+ .run (getConnection () );
5045
5146 return Boolean .TRUE ;
5247 } catch (SQLException e ) {
@@ -58,15 +53,14 @@ public void printAvailableLines() {
5853 FileOutputStream fileOutStream = null ;
5954 File outFile = new File ("output.txt" );
6055 try {
61- Connection conn = db .newConnection ();
6256 fileOutStream = new FileOutputStream (outFile );
6357
6458 List <PrintStream > printStreams = new ArrayList <>();
6559 printStreams .add (System .out );
6660 printStreams .add (new PrintStream (fileOutStream ));
6761
6862 new OutputBuffer (reporter )
69- .printAvailable (conn , printStreams );
63+ .printAvailable (newConnection () , printStreams );
7064
7165 return Boolean .TRUE ;
7266 } catch (SQLException e ) {
@@ -90,30 +84,23 @@ public void printAvailableLines() {
9084
9185 if (res2 instanceof Exception )
9286 fail ((Exception ) res2 );
93- } catch (SQLException e ) {
94- fail (e .getMessage ());
9587 } catch (InterruptedException | ExecutionException e ) {
9688 e .printStackTrace ();
9789 }
9890 }
9991
10092 @ Test
101- public void fetchAllLines () {
102- try {
103- final Reporter reporter = createReporter ();
104- Connection conn = db .newConnection ();
105- new TestRunner ()
106- .addPath (db .getUser ())
107- .addReporter (reporter )
108- .run (conn );
109-
110- List <String > outputLines = new OutputBuffer (reporter )
111- .fetchAll (conn );
112-
113- assertTrue (outputLines .size () > 0 );
114- } catch (SQLException e ) {
115- fail (e );
116- }
93+ public void fetchAllLines () throws SQLException {
94+ final Reporter reporter = createReporter ();
95+ new TestRunner ()
96+ .addPath (getUser ())
97+ .addReporter (reporter )
98+ .run (getConnection ());
99+
100+ List <String > outputLines = new OutputBuffer (reporter )
101+ .fetchAll (getConnection ());
102+
103+ assertTrue (outputLines .size () > 0 );
117104 }
118105
119106}
0 commit comments