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
Next Next commit
Package changes
  • Loading branch information
viniciusam committed May 22, 2017
commit 236a95a6baafaf4ceec288e0e80dc876f4a36f3e
16 changes: 16 additions & 0 deletions src/main/java/io/github/utplsql/api/CustomTypes.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
package io.github.utplsql.api;

/**
* Database custom data reporter.
*/
public final class CustomTypes {

// Object names must be upper case.
public static final String UT_REPORTERS = "UT_REPORTERS";
public static final String UT_DOCUMENTATION_REPORTER = "UT_DOCUMENTATION_REPORTER";
public static final String UT_COVERAGE_HTML_REPORTER = "UT_COVERAGE_HTML_REPORTER";
public static final String UT_VARCHAR2_LIST = "UT_VARCHAR2_LIST";

private CustomTypes() {}

}
8 changes: 4 additions & 4 deletions src/main/java/io/github/utplsql/api/OutputBuffer.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package io.github.utplsql.api;

import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.reporter.Reporter;
import oracle.jdbc.OracleTypes;

import java.io.PrintStream;
Expand All @@ -13,21 +13,21 @@
*/
public class OutputBuffer {

private BaseReporter reporter;
private Reporter reporter;

/**
* Creates a new OutputBuffer.
* @param reporter the reporter to be used
*/
public OutputBuffer(BaseReporter reporter) {
public OutputBuffer(Reporter reporter) {
this.reporter = reporter;
}

/**
* Returns the reporter used by this buffer.
* @return the reporter instance
*/
public BaseReporter getReporter() {
public Reporter getReporter() {
return reporter;
}

Expand Down
11 changes: 5 additions & 6 deletions src/main/java/io/github/utplsql/api/TestRunner.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package io.github.utplsql.api;

import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.CustomTypes;
import io.github.utplsql.api.reporter.Reporter;
import oracle.jdbc.OracleConnection;

import java.sql.Array;
Expand All @@ -17,7 +16,7 @@ public class TestRunner {

public TestRunner() {}

public void run(Connection conn, String path, BaseReporter reporter) throws SQLException {
public void run(Connection conn, String path, Reporter reporter) throws SQLException {
validateReporter(conn, reporter);
CallableStatement callableStatement = null;
try {
Expand All @@ -31,8 +30,8 @@ public void run(Connection conn, String path, BaseReporter reporter) throws SQLE
}
}

public void run(Connection conn, List<String> pathList, List<BaseReporter> reporterList) throws SQLException {
for (BaseReporter r : reporterList)
public void run(Connection conn, List<String> pathList, List<Reporter> reporterList) throws SQLException {
for (Reporter r : reporterList)
validateReporter(conn, r);

OracleConnection oraConn = conn.unwrap(OracleConnection.class);
Expand All @@ -57,7 +56,7 @@ public void run(Connection conn, List<String> pathList, List<BaseReporter> repor
* @param reporter the reporter
* @throws SQLException any sql exception
*/
private void validateReporter(Connection conn, BaseReporter reporter) throws SQLException {
private void validateReporter(Connection conn, Reporter reporter) throws SQLException {
if (reporter.getReporterId() == null || reporter.getReporterId().isEmpty())
reporter.init(conn);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.utplsql.api.types;
package io.github.utplsql.api.reporter;

import io.github.utplsql.api.CustomTypes;

import java.sql.SQLException;

/**
* Created by Vinicius on 13/04/2017.
*/
public class CoverageHTMLReporter extends BaseReporter {
public class CoverageHTMLReporter extends Reporter {

@Override
public String getSQLTypeName() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,11 +1,13 @@
package io.github.utplsql.api.types;
package io.github.utplsql.api.reporter;

import io.github.utplsql.api.CustomTypes;

import java.sql.SQLException;

/**
* Created by Vinicius on 13/04/2017.
*/
public class DocumentationReporter extends BaseReporter {
public class DocumentationReporter extends Reporter {

@Override
public String getSQLTypeName() throws SQLException {
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package io.github.utplsql.api.types;
package io.github.utplsql.api.reporter;

import io.github.utplsql.api.DBHelper;

Expand All @@ -8,15 +8,15 @@
/**
* Created by Vinicius on 13/04/2017.
*/
public abstract class BaseReporter implements SQLData {
public abstract class Reporter implements SQLData {

private String selfType;
private String reporterId;
private java.sql.Date startDate;

public BaseReporter() {}
public Reporter() {}

public BaseReporter init(Connection conn) throws SQLException {
public Reporter init(Connection conn) throws SQLException {
setStartDate(new java.sql.Date(Calendar.getInstance().getTimeInMillis()));
setReporterId(DBHelper.newSysGuid(conn));
return this;
Expand Down
20 changes: 20 additions & 0 deletions src/main/java/io/github/utplsql/api/reporter/ReporterFactory.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
package io.github.utplsql.api.reporter;

import io.github.utplsql.api.CustomTypes;

/**
* Created by vinicius.moreira on 22/05/2017.
*/
public final class ReporterFactory {

private ReporterFactory() {}

public static Reporter createReporter(String reporterName) {
switch (reporterName.toUpperCase()) {
case CustomTypes.UT_DOCUMENTATION_REPORTER: return new DocumentationReporter();
case CustomTypes.UT_COVERAGE_HTML_REPORTER: return new CoverageHTMLReporter();
}
throw new RuntimeException("Reporter " + reporterName + " not implemented.");
}

}
24 changes: 0 additions & 24 deletions src/main/java/io/github/utplsql/api/types/CustomTypes.java

This file was deleted.

12 changes: 6 additions & 6 deletions src/test/java/io/github/utplsql/api/OutputBufferTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
package io.github.utplsql.api;

import io.github.utplsql.api.rules.DatabaseRule;
import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.DocumentationReporter;
import io.github.utplsql.api.reporter.Reporter;
import io.github.utplsql.api.reporter.DocumentationReporter;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -23,9 +23,9 @@ public class OutputBufferTest {
@Rule
public final DatabaseRule db = new DatabaseRule();

public BaseReporter createReporter() throws SQLException {
public Reporter createReporter() throws SQLException {
Connection conn = db.newConnection();
BaseReporter reporter = new DocumentationReporter().init(conn);
Reporter reporter = new DocumentationReporter().init(conn);
System.out.println("Reporter ID: " + reporter.getReporterId());
return reporter;
}
Expand All @@ -35,7 +35,7 @@ public void printAvailableLines() {
ExecutorService executorService = Executors.newFixedThreadPool(2);

try {
final BaseReporter reporter = createReporter();
final Reporter reporter = createReporter();

Future<Object> task1 = executorService.submit(() -> {
try {
Expand Down Expand Up @@ -91,7 +91,7 @@ public void printAvailableLines() {
@Test
public void fetchAllLines() {
try {
final BaseReporter reporter = createReporter();
final Reporter reporter = createReporter();
Connection conn = db.newConnection();
new TestRunner().run(conn, "", reporter);

Expand Down
14 changes: 7 additions & 7 deletions src/test/java/io/github/utplsql/api/TestRunnerTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package io.github.utplsql.api;

import io.github.utplsql.api.rules.DatabaseRule;
import io.github.utplsql.api.types.BaseReporter;
import io.github.utplsql.api.types.CoverageHTMLReporter;
import io.github.utplsql.api.types.DocumentationReporter;
import io.github.utplsql.api.reporter.Reporter;
import io.github.utplsql.api.reporter.CoverageHTMLReporter;
import io.github.utplsql.api.reporter.DocumentationReporter;
import org.junit.Assert;
import org.junit.Rule;
import org.junit.Test;
Expand All @@ -25,8 +25,8 @@ public class TestRunnerTest {
public void runWithDocumentationReporter() {
try {
Connection conn = db.newConnection();
BaseReporter reporter = new DocumentationReporter();
new TestRunner().run(conn, "", reporter);
Reporter reporter = new DocumentationReporter();
new TestRunner().run(conn, db.getUser(), reporter);
Assert.assertNotNull(reporter.getReporterId());
} catch (SQLException e) {
Assert.fail(e.getMessage());
Expand All @@ -39,9 +39,9 @@ public void runWithTwoReporters() {
Connection conn = db.newConnection();

List<String> pathList = new ArrayList<>();
pathList.add("app");
pathList.add(db.getUser());

List<BaseReporter> reporterList = new ArrayList<>();
List<Reporter> reporterList = new ArrayList<>();
reporterList.add(new DocumentationReporter().init(conn));
reporterList.add(new CoverageHTMLReporter().init(conn));

Expand Down
4 changes: 4 additions & 0 deletions src/test/java/io/github/utplsql/api/rules/DatabaseRule.java
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,10 @@ public DatabaseRule() {
connectionList = new ArrayList<>();
}

public String getUser() {
return sUser;
}

public synchronized Connection newConnection() throws SQLException {
Connection conn = DriverManager.getConnection("jdbc:oracle:thin:@" + sUrl, sUser, sPass);
connectionList.add(conn);
Expand Down