From 9d507414b17eb8190c2b0ed891beabfa390163db Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 May 2017 13:34:28 -0300 Subject: [PATCH 1/6] Adding get connection method to connectioninfo --- .../io/github/utplsql/cli/ConnectionInfo.java | 7 ++ .../io/github/utplsql/cli/RunCommand.java | 85 +++++++------------ 2 files changed, 38 insertions(+), 54 deletions(-) diff --git a/src/main/java/io/github/utplsql/cli/ConnectionInfo.java b/src/main/java/io/github/utplsql/cli/ConnectionInfo.java index ce540e3..4523537 100644 --- a/src/main/java/io/github/utplsql/cli/ConnectionInfo.java +++ b/src/main/java/io/github/utplsql/cli/ConnectionInfo.java @@ -2,6 +2,9 @@ import com.beust.jcommander.ParameterException; +import java.sql.Connection; +import java.sql.DriverManager; +import java.sql.SQLException; import java.util.regex.Matcher; import java.util.regex.Pattern; @@ -32,6 +35,10 @@ public class ConnectionInfo { public ConnectionInfo() { } + public Connection getConnection() throws SQLException { + return DriverManager.getConnection(getConnectionUrl(), getUser(), getPassword()); + } + public ConnectionInfo parseConnectionString(String connectionString) throws ParameterException { Pattern p = Pattern.compile(CONNSTR_PATTERN); Matcher m = p.matcher(connectionString); diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 8777e2d..fbf2d37 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -3,11 +3,9 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; import io.github.utplsql.api.OutputBuffer; -import io.github.utplsql.api.OutputBufferLines; import io.github.utplsql.api.TestRunner; import io.github.utplsql.api.types.BaseReporter; import io.github.utplsql.api.types.DocumentationReporter; -import io.github.utplsql.api.utPLSQL; import java.sql.Connection; import java.sql.SQLException; @@ -24,15 +22,23 @@ public class RunCommand { @Parameter( required = true, converter = ConnectionStringConverter.class, + arity = 1, description = "user/pass@[[host][:port]/]db") private List connectionInfoList; @Parameter( names = {"-p", "--path"}, description = "run suites/tests by path, format: \n" + - "schema or schema:[suite ...][.test] or schema[.suite ...][.test]") + "-p schema or schema:[suite ...][.test] or schema[.suite ...][.test]") private List testPaths; + @Parameter( + names = {"-f", "--format"}, + variableArity = true, + description = "output reporter format: \n" + + "-f reporter_name [output_file] [console_output]") + private List reporterParams; + public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); } @@ -44,78 +50,49 @@ public String getTestPaths() { return (testPaths == null) ? null : String.join(",", testPaths); } + public List getReporterParams() { + return reporterParams; + } + public void run() throws Exception { - ConnectionInfo ci = getConnectionInfo(); + final ConnectionInfo ci = getConnectionInfo(); System.out.println("Running Tests For: " + ci.toString()); - utPLSQL.init(ci.getConnectionUrl(), ci.getUser(), ci.getPassword()); - String tempTestPaths = getTestPaths(); if (tempTestPaths == null) tempTestPaths = ci.getUser(); - final BaseReporter reporter = createDocumentationReporter(); + final BaseReporter reporter = new DocumentationReporter(); final String testPaths = tempTestPaths; + try (Connection conn = ci.getConnection()) { + reporter.init(conn); + } catch (SQLException e) { + // TODO + e.printStackTrace(); + } + ExecutorService executorService = Executors.newFixedThreadPool(2); executorService.submit(() -> { - Connection conn = null; - try { - conn = utPLSQL.getConnection(); + try (Connection conn = ci.getConnection()){ new TestRunner().run(conn, testPaths, reporter); - - OutputBufferLines outputLines = new OutputBuffer(reporter.getReporterId()) - .fetchAll(conn); - - if (outputLines.getLines().size() > 0) - System.out.println(outputLines.toString()); } catch (SQLException e) { // TODO e.printStackTrace(); - } finally { - if (conn != null) - try { conn.close(); } catch (SQLException ignored) {} } }); -// executorService.submit(() -> { -// Connection conn = null; -// try { -// conn = utPLSQL.getConnection(); -// OutputBufferLines outputLines; -// do { -// outputLines = new OutputBuffer(reporter.getReporterId()) -// .fetchAvailable(conn); -// -// Thread.sleep(500); -// -// if (outputLines.getLines().size() > 0) -// System.out.println(outputLines.toString()); -// } while (!outputLines.isFinished()); -// } catch (SQLException | InterruptedException e) { -// // TODO -// e.printStackTrace(); -// } finally { -// if (conn != null) -// try { conn.close(); } catch (SQLException ignored) {} -// } -// }); + executorService.submit(() -> { + try (Connection conn = ci.getConnection()){ + new OutputBuffer(reporter).printAvailable(conn, System.out); + } catch (SQLException e) { + // TODO + e.printStackTrace(); + } + }); executorService.shutdown(); executorService.awaitTermination(60, TimeUnit.MINUTES); } - private BaseReporter createDocumentationReporter() throws SQLException { - Connection conn = null; - try { - conn = utPLSQL.getConnection(); - BaseReporter reporter = new DocumentationReporter(); - reporter.setReporterId(utPLSQL.newSysGuid(conn)); - return reporter; - } finally { - if (conn != null) - try { conn.close(); } catch (SQLException ignored) {} - } - } - } From 1b328aa3d38bb78efffa23057ff691a309a3b713 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 May 2017 13:34:39 -0300 Subject: [PATCH 2/6] Update jCommander lib --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 72f3b24..f0f5b41 100644 --- a/pom.xml +++ b/pom.xml @@ -20,7 +20,7 @@ com.beust jcommander - 1.60 + 1.69 compile From 0148224cd1fda05b3aeec477a5a0759b6532c146 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 May 2017 14:39:39 -0300 Subject: [PATCH 3/6] Add reporter params --- .../github/utplsql/cli/ReporterOptions.java | 56 +++++++++++ .../io/github/utplsql/cli/RunCommand.java | 35 ++++++- .../java/io/github/utplsql/cli/CliTest.java | 16 --- .../io/github/utplsql/cli/RunCommandTest.java | 99 +++++++++++++++++++ 4 files changed, 185 insertions(+), 21 deletions(-) create mode 100644 src/main/java/io/github/utplsql/cli/ReporterOptions.java delete mode 100644 src/test/java/io/github/utplsql/cli/CliTest.java create mode 100644 src/test/java/io/github/utplsql/cli/RunCommandTest.java diff --git a/src/main/java/io/github/utplsql/cli/ReporterOptions.java b/src/main/java/io/github/utplsql/cli/ReporterOptions.java new file mode 100644 index 0000000..736e362 --- /dev/null +++ b/src/main/java/io/github/utplsql/cli/ReporterOptions.java @@ -0,0 +1,56 @@ +package io.github.utplsql.cli; + +import com.sun.istack.internal.NotNull; + +/** + * Created by Vinicius on 20/05/2017. + */ +public class ReporterOptions { + + private String reporterName; + private String outputFileName; + private boolean outputToScreen; + private boolean forceOutputToScreen; + + public ReporterOptions(String reporterName, String outputFileName, boolean outputToScreen) { + setReporterName(reporterName); + setOutputFileName(outputFileName); + this.outputToScreen = outputToScreen; + this.forceOutputToScreen = false; + } + + public ReporterOptions(String reporterName) { + this(reporterName, null, true); + } + + public String getReporterName() { + return reporterName; + } + + @NotNull + public void setReporterName(String reporterName) { + this.reporterName = reporterName.toUpperCase(); + } + + public String getOutputFileName() { + return outputFileName; + } + + public void setOutputFileName(String outputFileName) { + this.outputFileName = outputFileName; + this.outputToScreen = false; + } + + public boolean outputToFile() { + return outputFileName != null && !outputFileName.isEmpty(); + } + + public boolean outputToScreen() { + return outputToScreen || forceOutputToScreen; + } + + public void forceOutputToScreen(boolean outputToScreen) { + this.forceOutputToScreen = outputToScreen; + } + +} diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index fbf2d37..7b1587e 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -5,10 +5,12 @@ import io.github.utplsql.api.OutputBuffer; import io.github.utplsql.api.TestRunner; import io.github.utplsql.api.types.BaseReporter; +import io.github.utplsql.api.types.CustomTypes; import io.github.utplsql.api.types.DocumentationReporter; import java.sql.Connection; import java.sql.SQLException; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.ExecutorService; import java.util.concurrent.Executors; @@ -24,20 +26,20 @@ public class RunCommand { required = true, converter = ConnectionStringConverter.class, arity = 1, description = "user/pass@[[host][:port]/]db") - private List connectionInfoList; + private List connectionInfoList = new ArrayList<>(); @Parameter( names = {"-p", "--path"}, description = "run suites/tests by path, format: \n" + "-p schema or schema:[suite ...][.test] or schema[.suite ...][.test]") - private List testPaths; + private List testPaths = new ArrayList<>(); @Parameter( names = {"-f", "--format"}, variableArity = true, description = "output reporter format: \n" + "-f reporter_name [output_file] [console_output]") - private List reporterParams; + private List reporterParams = new ArrayList<>(); public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); @@ -50,8 +52,31 @@ public String getTestPaths() { return (testPaths == null) ? null : String.join(",", testPaths); } - public List getReporterParams() { - return reporterParams; + public List getReporterOptionsList() { + List reporterOptionsList = new ArrayList<>(); + ReporterOptions reporterOptions = null; + + for (String p : reporterParams) { + if (reporterOptions == null || !p.startsWith("-")) { + reporterOptions = new ReporterOptions(p); + reporterOptionsList.add(reporterOptions); + } + else + if (p.startsWith("-o=")) { + reporterOptions.setOutputFileName(p.substring(3)); + } + else + if (p.equals("-s")) { + reporterOptions.forceOutputToScreen(true); + } + } + + // If no reporter parameters were passed, use default reporter. + if (reporterOptionsList.isEmpty()) { + reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER.getName())); + } + + return reporterOptionsList; } public void run() throws Exception { diff --git a/src/test/java/io/github/utplsql/cli/CliTest.java b/src/test/java/io/github/utplsql/cli/CliTest.java deleted file mode 100644 index b96e63f..0000000 --- a/src/test/java/io/github/utplsql/cli/CliTest.java +++ /dev/null @@ -1,16 +0,0 @@ -package io.github.utplsql.cli; - -import org.junit.Assert; -import org.junit.Test; - -/** - * Unit test for simple Cli. - */ -public class CliTest { - - @Test - public void dummyTest() { - Assert.assertTrue(true); - } - -} diff --git a/src/test/java/io/github/utplsql/cli/RunCommandTest.java b/src/test/java/io/github/utplsql/cli/RunCommandTest.java new file mode 100644 index 0000000..0378248 --- /dev/null +++ b/src/test/java/io/github/utplsql/cli/RunCommandTest.java @@ -0,0 +1,99 @@ +package io.github.utplsql.cli; + +import com.beust.jcommander.JCommander; +import io.github.utplsql.api.types.CustomTypes; +import org.junit.Assert; +import org.junit.Test; + +import java.util.List; + +/** + * Unit test for run command. + */ +public class RunCommandTest { + + private RunCommand createCommand(String... args) { + RunCommand runCmd = new RunCommand(); + + JCommander.newBuilder() + .addObject(runCmd) + .args(args) + .build(); + + return runCmd; + } + + @Test + public void reporterOptions_Default() { + RunCommand runCmd = createCommand("run", "app/app"); + + List reporterOptionsList = runCmd.getReporterOptionsList(); + + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertNull(reporterOptions1.getOutputFileName()); + Assert.assertFalse(reporterOptions1.outputToFile()); + Assert.assertTrue(reporterOptions1.outputToScreen()); + } + + @Test + public void reporterOptions_OneReporter() { + RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-o=output.txt"); + + List reporterOptionsList = runCmd.getReporterOptionsList(); + + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + Assert.assertTrue(reporterOptions1.outputToFile()); + Assert.assertFalse(reporterOptions1.outputToScreen()); + } + + @Test + public void reporterOptions_OneReporterForceScreen() { + RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-o=output.txt", "-s"); + + List reporterOptionsList = runCmd.getReporterOptionsList(); + + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + Assert.assertTrue(reporterOptions1.outputToFile()); + Assert.assertTrue(reporterOptions1.outputToScreen()); + } + + @Test + public void reporterOptions_OneReporterForceScreenInverse() { + RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-s", "-o=output.txt"); + + List reporterOptionsList = runCmd.getReporterOptionsList(); + + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); + Assert.assertTrue(reporterOptions1.outputToFile()); + Assert.assertTrue(reporterOptions1.outputToScreen()); + } + + @Test + public void reporterOptions_TwoReporters() { + RunCommand runCmd = createCommand("run", "app/app@docker/xe", + "-f=ut_documentation_reporter", + "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); + + List reporterOptionsList = runCmd.getReporterOptionsList(); + + ReporterOptions reporterOptions1 = reporterOptionsList.get(0); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertNull(reporterOptions1.getOutputFileName()); + Assert.assertFalse(reporterOptions1.outputToFile()); + Assert.assertTrue(reporterOptions1.outputToScreen()); + + ReporterOptions reporterOptions2 = reporterOptionsList.get(1); + Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER.getName(), reporterOptions2.getReporterName()); + Assert.assertEquals(reporterOptions2.getOutputFileName(), "coverage.html"); + Assert.assertTrue(reporterOptions2.outputToFile()); + Assert.assertTrue(reporterOptions2.outputToScreen()); + } + +} From 4f1480288ebe5e55e6c87e8f7a2c775f0bd597ae Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Sat, 20 May 2017 20:54:43 -0300 Subject: [PATCH 4/6] Add support for multiple reporters --- .../github/utplsql/cli/ReporterOptions.java | 17 +++-- .../io/github/utplsql/cli/RunCommand.java | 67 +++++++++++++------ .../io/github/utplsql/cli/RunCommandTest.java | 12 ++-- 3 files changed, 64 insertions(+), 32 deletions(-) diff --git a/src/main/java/io/github/utplsql/cli/ReporterOptions.java b/src/main/java/io/github/utplsql/cli/ReporterOptions.java index 736e362..57f252b 100644 --- a/src/main/java/io/github/utplsql/cli/ReporterOptions.java +++ b/src/main/java/io/github/utplsql/cli/ReporterOptions.java @@ -1,6 +1,6 @@ package io.github.utplsql.cli; -import com.sun.istack.internal.NotNull; +import io.github.utplsql.api.types.BaseReporter; /** * Created by Vinicius on 20/05/2017. @@ -12,6 +12,8 @@ public class ReporterOptions { private boolean outputToScreen; private boolean forceOutputToScreen; + private BaseReporter reporterObj = null; + public ReporterOptions(String reporterName, String outputFileName, boolean outputToScreen) { setReporterName(reporterName); setOutputFileName(outputFileName); @@ -23,13 +25,20 @@ public ReporterOptions(String reporterName) { this(reporterName, null, true); } + public BaseReporter getReporterObj() { + return reporterObj; + } + + public void setReporterObj(BaseReporter reporterObj) { + this.reporterObj = reporterObj; + } + public String getReporterName() { - return reporterName; + return reporterName.toUpperCase(); } - @NotNull public void setReporterName(String reporterName) { - this.reporterName = reporterName.toUpperCase(); + this.reporterName = reporterName; } public String getOutputFileName() { diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index 7b1587e..c7bfbc1 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -6,8 +6,10 @@ import io.github.utplsql.api.TestRunner; import io.github.utplsql.api.types.BaseReporter; import io.github.utplsql.api.types.CustomTypes; -import io.github.utplsql.api.types.DocumentationReporter; +import java.io.FileNotFoundException; +import java.io.FileOutputStream; +import java.io.PrintStream; import java.sql.Connection; import java.sql.SQLException; import java.util.ArrayList; @@ -45,11 +47,8 @@ public ConnectionInfo getConnectionInfo() { return connectionInfoList.get(0); } - public String getTestPaths() { -// if (testPaths != null && testPaths.size() > 1) -// throw new RuntimeException("Multiple test paths not supported yet."); - - return (testPaths == null) ? null : String.join(",", testPaths); + public List getTestPaths() { + return testPaths; } public List getReporterOptionsList() { @@ -73,7 +72,7 @@ public List getReporterOptionsList() { // If no reporter parameters were passed, use default reporter. if (reporterOptionsList.isEmpty()) { - reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER.getName())); + reporterOptionsList.add(new ReporterOptions(CustomTypes.UT_DOCUMENTATION_REPORTER)); } return reporterOptionsList; @@ -83,38 +82,62 @@ public void run() throws Exception { final ConnectionInfo ci = getConnectionInfo(); System.out.println("Running Tests For: " + ci.toString()); - String tempTestPaths = getTestPaths(); - if (tempTestPaths == null) tempTestPaths = ci.getUser(); + final List reporterOptionsList = getReporterOptionsList(); + final List reporterList = new ArrayList<>(); + final List testPaths = getTestPaths(); - final BaseReporter reporter = new DocumentationReporter(); - final String testPaths = tempTestPaths; + if (testPaths.isEmpty()) testPaths.add(ci.getUser()); + // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { - reporter.init(conn); + for (ReporterOptions ro : reporterOptionsList) { + BaseReporter reporter = CustomTypes.createReporter(ro.getReporterName()); + reporter.init(conn); + ro.setReporterObj(reporter); + reporterList.add(reporter); + } } catch (SQLException e) { // TODO e.printStackTrace(); } - ExecutorService executorService = Executors.newFixedThreadPool(2); + ExecutorService executorService = Executors.newFixedThreadPool(1 + reporterList.size()); executorService.submit(() -> { try (Connection conn = ci.getConnection()){ - new TestRunner().run(conn, testPaths, reporter); + new TestRunner().run(conn, testPaths, reporterList); } catch (SQLException e) { // TODO e.printStackTrace(); } }); - executorService.submit(() -> { - try (Connection conn = ci.getConnection()){ - new OutputBuffer(reporter).printAvailable(conn, System.out); - } catch (SQLException e) { - // TODO - e.printStackTrace(); - } - }); + + for (ReporterOptions ro : reporterOptionsList) { + executorService.submit(() -> { + List printStreams = new ArrayList<>(); + PrintStream fileOutStream = null; + + try (Connection conn = ci.getConnection()) { + if (ro.outputToScreen()) { + printStreams.add(System.out); + } + + if (ro.outputToFile()) { + fileOutStream = new PrintStream(new FileOutputStream(ro.getOutputFileName())); + printStreams.add(fileOutStream); + } + + new OutputBuffer(ro.getReporterObj()).printAvailable(conn, printStreams); + } catch (SQLException | FileNotFoundException e) { + // TODO + e.printStackTrace(); + } finally { + if (fileOutStream != null) + fileOutStream.close(); + } + }); + } executorService.shutdown(); executorService.awaitTermination(60, TimeUnit.MINUTES); diff --git a/src/test/java/io/github/utplsql/cli/RunCommandTest.java b/src/test/java/io/github/utplsql/cli/RunCommandTest.java index 0378248..6bfe38a 100644 --- a/src/test/java/io/github/utplsql/cli/RunCommandTest.java +++ b/src/test/java/io/github/utplsql/cli/RunCommandTest.java @@ -30,7 +30,7 @@ public void reporterOptions_Default() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); Assert.assertNull(reporterOptions1.getOutputFileName()); Assert.assertFalse(reporterOptions1.outputToFile()); Assert.assertTrue(reporterOptions1.outputToScreen()); @@ -43,7 +43,7 @@ public void reporterOptions_OneReporter() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); Assert.assertTrue(reporterOptions1.outputToFile()); Assert.assertFalse(reporterOptions1.outputToScreen()); @@ -56,7 +56,7 @@ public void reporterOptions_OneReporterForceScreen() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); Assert.assertTrue(reporterOptions1.outputToFile()); Assert.assertTrue(reporterOptions1.outputToScreen()); @@ -69,7 +69,7 @@ public void reporterOptions_OneReporterForceScreenInverse() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); Assert.assertEquals(reporterOptions1.getOutputFileName(), "output.txt"); Assert.assertTrue(reporterOptions1.outputToFile()); Assert.assertTrue(reporterOptions1.outputToScreen()); @@ -84,13 +84,13 @@ public void reporterOptions_TwoReporters() { List reporterOptionsList = runCmd.getReporterOptionsList(); ReporterOptions reporterOptions1 = reporterOptionsList.get(0); - Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER.getName(), reporterOptions1.getReporterName()); + Assert.assertEquals(CustomTypes.UT_DOCUMENTATION_REPORTER, reporterOptions1.getReporterName()); Assert.assertNull(reporterOptions1.getOutputFileName()); Assert.assertFalse(reporterOptions1.outputToFile()); Assert.assertTrue(reporterOptions1.outputToScreen()); ReporterOptions reporterOptions2 = reporterOptionsList.get(1); - Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER.getName(), reporterOptions2.getReporterName()); + Assert.assertEquals(CustomTypes.UT_COVERAGE_HTML_REPORTER, reporterOptions2.getReporterName()); Assert.assertEquals(reporterOptions2.getOutputFileName(), "coverage.html"); Assert.assertTrue(reporterOptions2.outputToFile()); Assert.assertTrue(reporterOptions2.outputToScreen()); From 8a9b66f9dd5790f4086a380a1d81adc152d23872 Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Moreira Date: Mon, 22 May 2017 13:40:09 -0300 Subject: [PATCH 5/6] Api package changes --- .../java/io/github/utplsql/cli/ReporterOptions.java | 8 ++++---- src/main/java/io/github/utplsql/cli/RunCommand.java | 9 +++++---- .../java/io/github/utplsql/cli/RunCommandTest.java | 10 +++++----- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/main/java/io/github/utplsql/cli/ReporterOptions.java b/src/main/java/io/github/utplsql/cli/ReporterOptions.java index 57f252b..61eb930 100644 --- a/src/main/java/io/github/utplsql/cli/ReporterOptions.java +++ b/src/main/java/io/github/utplsql/cli/ReporterOptions.java @@ -1,6 +1,6 @@ package io.github.utplsql.cli; -import io.github.utplsql.api.types.BaseReporter; +import io.github.utplsql.api.reporter.Reporter; /** * Created by Vinicius on 20/05/2017. @@ -12,7 +12,7 @@ public class ReporterOptions { private boolean outputToScreen; private boolean forceOutputToScreen; - private BaseReporter reporterObj = null; + private Reporter reporterObj = null; public ReporterOptions(String reporterName, String outputFileName, boolean outputToScreen) { setReporterName(reporterName); @@ -25,11 +25,11 @@ public ReporterOptions(String reporterName) { this(reporterName, null, true); } - public BaseReporter getReporterObj() { + public Reporter getReporterObj() { return reporterObj; } - public void setReporterObj(BaseReporter reporterObj) { + public void setReporterObj(Reporter reporterObj) { this.reporterObj = reporterObj; } diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index c7bfbc1..c1135de 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -2,10 +2,11 @@ import com.beust.jcommander.Parameter; import com.beust.jcommander.Parameters; +import io.github.utplsql.api.CustomTypes; import io.github.utplsql.api.OutputBuffer; import io.github.utplsql.api.TestRunner; -import io.github.utplsql.api.types.BaseReporter; -import io.github.utplsql.api.types.CustomTypes; +import io.github.utplsql.api.reporter.Reporter; +import io.github.utplsql.api.reporter.ReporterFactory; import java.io.FileNotFoundException; import java.io.FileOutputStream; @@ -83,7 +84,7 @@ public void run() throws Exception { System.out.println("Running Tests For: " + ci.toString()); final List reporterOptionsList = getReporterOptionsList(); - final List reporterList = new ArrayList<>(); + final List reporterList = new ArrayList<>(); final List testPaths = getTestPaths(); if (testPaths.isEmpty()) testPaths.add(ci.getUser()); @@ -91,7 +92,7 @@ public void run() throws Exception { // Do the reporters initialization, so we can use the id to run and gather results. try (Connection conn = ci.getConnection()) { for (ReporterOptions ro : reporterOptionsList) { - BaseReporter reporter = CustomTypes.createReporter(ro.getReporterName()); + Reporter reporter = ReporterFactory.createReporter(ro.getReporterName()); reporter.init(conn); ro.setReporterObj(reporter); reporterList.add(reporter); diff --git a/src/test/java/io/github/utplsql/cli/RunCommandTest.java b/src/test/java/io/github/utplsql/cli/RunCommandTest.java index 6bfe38a..9184234 100644 --- a/src/test/java/io/github/utplsql/cli/RunCommandTest.java +++ b/src/test/java/io/github/utplsql/cli/RunCommandTest.java @@ -1,7 +1,7 @@ package io.github.utplsql.cli; import com.beust.jcommander.JCommander; -import io.github.utplsql.api.types.CustomTypes; +import io.github.utplsql.api.CustomTypes; import org.junit.Assert; import org.junit.Test; @@ -38,7 +38,7 @@ public void reporterOptions_Default() { @Test public void reporterOptions_OneReporter() { - RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-o=output.txt"); + RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -51,7 +51,7 @@ public void reporterOptions_OneReporter() { @Test public void reporterOptions_OneReporterForceScreen() { - RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-o=output.txt", "-s"); + RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-o=output.txt", "-s"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -64,7 +64,7 @@ public void reporterOptions_OneReporterForceScreen() { @Test public void reporterOptions_OneReporterForceScreenInverse() { - RunCommand runCmd = createCommand("run", "app/app@docker/xe", "-f=ut_documentation_reporter", "-s", "-o=output.txt"); + RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-s", "-o=output.txt"); List reporterOptionsList = runCmd.getReporterOptionsList(); @@ -77,7 +77,7 @@ public void reporterOptions_OneReporterForceScreenInverse() { @Test public void reporterOptions_TwoReporters() { - RunCommand runCmd = createCommand("run", "app/app@docker/xe", + RunCommand runCmd = createCommand("run", "app/app", "-f=ut_documentation_reporter", "-f=ut_coverage_html_reporter", "-o=coverage.html", "-s"); From 07275ca52c2ee2d63e35ba067e52565c7846ef7e Mon Sep 17 00:00:00 2001 From: Vinicius Avellar Date: Tue, 23 May 2017 18:22:14 -0300 Subject: [PATCH 6/6] TestRunner api changes --- src/main/java/io/github/utplsql/cli/RunCommand.java | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/src/main/java/io/github/utplsql/cli/RunCommand.java b/src/main/java/io/github/utplsql/cli/RunCommand.java index c1135de..39e2299 100644 --- a/src/main/java/io/github/utplsql/cli/RunCommand.java +++ b/src/main/java/io/github/utplsql/cli/RunCommand.java @@ -106,7 +106,10 @@ public void run() throws Exception { executorService.submit(() -> { try (Connection conn = ci.getConnection()){ - new TestRunner().run(conn, testPaths, reporterList); + new TestRunner() + .addPathList(testPaths) + .addReporterList(reporterList) + .run(conn); } catch (SQLException e) { // TODO e.printStackTrace();