Thanks to visit codestin.com
Credit goes to github.com

Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Small api changes
  • Loading branch information
viniciusam committed Apr 19, 2017
commit 9811c23c8e384ec83de47595cebd0fc4dd015b13
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ services:
- docker

jdk:
- oraclejdk7
# - oraclejdk7
- oraclejdk8

env:
Expand Down
34 changes: 17 additions & 17 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,23 +30,23 @@
</dependency>
</dependencies>

<build>
<plugins>
<plugin>
<groupId>net.orfjackal.retrolambda</groupId>
<artifactId>retrolambda-maven-plugin</artifactId>
<version>2.5.1</version>
<executions>
<execution>
<goals>
<goal>process-main</goal>
<goal>process-test</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
<!--<build>-->
<!--<plugins>-->
<!--<plugin>-->
<!--<groupId>net.orfjackal.retrolambda</groupId>-->
<!--<artifactId>retrolambda-maven-plugin</artifactId>-->
<!--<version>2.5.1</version>-->
<!--<executions>-->
<!--<execution>-->
<!--<goals>-->
<!--<goal>process-main</goal>-->
<!--<goal>process-test</goal>-->
<!--</goals>-->
<!--</execution>-->
<!--</executions>-->
<!--</plugin>-->
<!--</plugins>-->
<!--</build>-->

<repositories>
<repository>
Expand Down
44 changes: 40 additions & 4 deletions src/main/java/io/github/utplsql/OutputBuffer.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import oracle.jdbc.OracleTypes;

import java.sql.CallableStatement;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
Expand All @@ -11,19 +12,54 @@
/**
* Created by Vinicius on 13/04/2017.
*/
public final class OutputBuffer {
public class OutputBuffer {

private OutputBuffer() {}
private String reporterId;

public static List<String> getAllLines(String reporterId) throws SQLException {
public OutputBuffer(String reporterId) {
this.reporterId = reporterId;
}

public String getReporterId() {
return reporterId;
}

public void setReporterId(String reporterId) {
this.reporterId = reporterId;
}

public List<String> getLines() throws SQLException {
PreparedStatement preparedStatement = null;
ResultSet resultSet = null;
try {
preparedStatement = UTPLSQL.getConnection()
.prepareStatement("SELECT * FROM TABLE(ut_output_buffer.get_lines(?, 1))");

preparedStatement.setString(1, getReporterId());
resultSet = preparedStatement.executeQuery();

List<String> outputLines = new ArrayList<>();
while (resultSet.next()) {
outputLines.add(resultSet.getString(1));
}
return outputLines;
} finally {
if (resultSet != null)
resultSet.close();
if (preparedStatement != null)
preparedStatement.close();
}
}

public List<String> getAllLines() throws SQLException {
CallableStatement callableStatement = null;
ResultSet resultSet = null;
try {
callableStatement = UTPLSQL.getConnection()
.prepareCall("BEGIN ? := ut_output_buffer.get_lines_cursor(?); END;");

callableStatement.registerOutParameter(1, OracleTypes.CURSOR);
callableStatement.setString(2, reporterId);
callableStatement.setString(2, getReporterId());
callableStatement.execute();

resultSet = (ResultSet) callableStatement.getObject(1);
Expand Down
8 changes: 4 additions & 4 deletions src/main/java/io/github/utplsql/TestRunner.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,11 +8,11 @@
/**
* Created by Vinicius Avellar on 12/04/2017.
*/
public final class TestRunner {
public class TestRunner {

private TestRunner() {}
public TestRunner() {}

public static void run() throws SQLException {
public void run() throws SQLException {
CallableStatement callableStatement = null;
try {
callableStatement = UTPLSQL.getConnection()
Expand All @@ -24,7 +24,7 @@ public static void run() throws SQLException {
}
}

public static void run(String path, BaseReporter reporter) throws SQLException {
public void run(String path, BaseReporter reporter) throws SQLException {
if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty()) {
reporter.setReporterId(UTPLSQL.newSysGuid());
}
Expand Down
43 changes: 37 additions & 6 deletions src/test/java/io/github/utplsql/OutputBufferTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,48 @@ public class OutputBufferTest {
@ClassRule
public static final DatabaseRule sInitialization = new DatabaseRule();

private BaseReporter currentReporter = null;

public BaseReporter createReporter() throws SQLException {
BaseReporter reporter = new DocumentationReporter();
reporter.setReporterId(UTPLSQL.newSysGuid());
System.out.println("Reporter ID: " + reporter.getReporterId());
return reporter;
}

@Test
public void getLinesFromOutputBuffer() {
try {
BaseReporter reporter = new DocumentationReporter();
reporter.setReporterId(UTPLSQL.newSysGuid());
TestRunner.run("", reporter);
final BaseReporter reporter = createReporter();
// new TestRunner().run("", reporter);
new Thread(() -> {
try {
new TestRunner().run("", reporter);
} catch (SQLException e) {
e.printStackTrace();
}
}).start();

List<String> outputLines = new OutputBuffer(reporter.getReporterId())
.getLines();

for (int i = 0; i < outputLines.size(); i++) {
System.out.println(outputLines.get(i));
}
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
}

@Test
public void getAllLinesFromOutputBuffer() {
try {
final BaseReporter reporter = createReporter();
new TestRunner().run("", reporter);

List<String> outputLines = OutputBuffer.getAllLines(reporter.getReporterId());
List<String> outputLines = new OutputBuffer(reporter.getReporterId())
.getAllLines();

// Debug
System.out.println("Reporter ID: " + reporter.getReporterId());
for (int i = 0; i < outputLines.size(); i++) {
System.out.println(outputLines.get(i));
}
Expand Down
4 changes: 2 additions & 2 deletions src/test/java/io/github/utplsql/TestRunnerTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ public class TestRunnerTest {
@Test
public void runWithoutParams() {
try {
TestRunner.run();
new TestRunner().run();
} catch (SQLException e) {
Assert.fail(e.getMessage());
}
Expand All @@ -30,7 +30,7 @@ public void runWithoutParams() {
public void runWithDocumentationReporter() {
try {
BaseReporter reporter = new DocumentationReporter();
TestRunner.run("", reporter);
new TestRunner().run("", reporter);
Assert.assertNotNull(reporter.getReporterId());
} catch (SQLException e) {
Assert.fail(e.getMessage());
Expand Down