3
3
import org .junit .jupiter .api .Test ;
4
4
import org .utplsql .api .reporter .DocumentationReporter ;
5
5
import org .utplsql .api .reporter .Reporter ;
6
- import org .utplsql .api .rules .DatabaseRule ;
7
- import org .junit .Rule ;
8
6
9
7
import java .io .File ;
10
8
import java .io .FileOutputStream ;
11
9
import java .io .PrintStream ;
12
- import java .sql .Connection ;
13
10
import java .sql .SQLException ;
14
11
import java .util .ArrayList ;
15
12
import java .util .List ;
19
16
import static org .junit .jupiter .api .Assertions .fail ;
20
17
21
18
/**
22
- * Created by Vinicius on 13/04/2017.
19
+ * Integration-test for OutputBuffers
20
+ *
21
+ * @author viniciusam
22
+ * @author pesse
23
23
*/
24
- public class OutputBufferIT {
25
-
26
- @ Rule
27
- public final DatabaseRule db = new DatabaseRule ();
24
+ public class OutputBufferIT extends AbstractDatabaseTest {
28
25
29
26
public Reporter createReporter () throws SQLException {
30
- Connection conn = db .newConnection ();
31
- Reporter reporter = new DocumentationReporter ().init (conn );
27
+ Reporter reporter = new DocumentationReporter ().init (newConnection ());
32
28
System .out .println ("Reporter ID: " + reporter .getReporterId ());
33
29
return reporter ;
34
30
}
35
31
36
32
@ Test
37
- public void printAvailableLines () {
33
+ public void printAvailableLines () throws SQLException {
38
34
ExecutorService executorService = Executors .newFixedThreadPool (2 );
39
35
40
36
try {
41
37
final Reporter reporter = createReporter ();
42
38
43
39
Future <Object > task1 = executorService .submit (() -> {
44
40
try {
45
- Connection conn = db .newConnection ();
46
41
new TestRunner ()
47
- .addPath (db . getUser ())
42
+ .addPath (getUser ())
48
43
.addReporter (reporter )
49
- .run (conn );
44
+ .run (getConnection () );
50
45
51
46
return Boolean .TRUE ;
52
47
} catch (SQLException e ) {
@@ -58,15 +53,14 @@ public void printAvailableLines() {
58
53
FileOutputStream fileOutStream = null ;
59
54
File outFile = new File ("output.txt" );
60
55
try {
61
- Connection conn = db .newConnection ();
62
56
fileOutStream = new FileOutputStream (outFile );
63
57
64
58
List <PrintStream > printStreams = new ArrayList <>();
65
59
printStreams .add (System .out );
66
60
printStreams .add (new PrintStream (fileOutStream ));
67
61
68
62
new OutputBuffer (reporter )
69
- .printAvailable (conn , printStreams );
63
+ .printAvailable (newConnection () , printStreams );
70
64
71
65
return Boolean .TRUE ;
72
66
} catch (SQLException e ) {
@@ -90,30 +84,23 @@ public void printAvailableLines() {
90
84
91
85
if (res2 instanceof Exception )
92
86
fail ((Exception ) res2 );
93
- } catch (SQLException e ) {
94
- fail (e .getMessage ());
95
87
} catch (InterruptedException | ExecutionException e ) {
96
88
e .printStackTrace ();
97
89
}
98
90
}
99
91
100
92
@ 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 );
117
104
}
118
105
119
106
}
0 commit comments