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
Add reporter params
  • Loading branch information
viniciusam committed May 20, 2017
commit 0148224cd1fda05b3aeec477a5a0759b6532c146
56 changes: 56 additions & 0 deletions src/main/java/io/github/utplsql/cli/ReporterOptions.java
Original file line number Diff line number Diff line change
@@ -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;
}

}
35 changes: 30 additions & 5 deletions src/main/java/io/github/utplsql/cli/RunCommand.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -24,20 +26,20 @@ public class RunCommand {
required = true, converter = ConnectionStringConverter.class,
arity = 1,
description = "user/pass@[[host][:port]/]db")
private List<ConnectionInfo> connectionInfoList;
private List<ConnectionInfo> 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<String> testPaths;
private List<String> testPaths = new ArrayList<>();

@Parameter(
names = {"-f", "--format"},
variableArity = true,
description = "output reporter format: \n" +
"-f reporter_name [output_file] [console_output]")
private List<String> reporterParams;
private List<String> reporterParams = new ArrayList<>();

public ConnectionInfo getConnectionInfo() {
return connectionInfoList.get(0);
Expand All @@ -50,8 +52,31 @@ public String getTestPaths() {
return (testPaths == null) ? null : String.join(",", testPaths);
}

public List<String> getReporterParams() {
return reporterParams;
public List<ReporterOptions> getReporterOptionsList() {
List<ReporterOptions> 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 {
Expand Down
16 changes: 0 additions & 16 deletions src/test/java/io/github/utplsql/cli/CliTest.java

This file was deleted.

99 changes: 99 additions & 0 deletions src/test/java/io/github/utplsql/cli/RunCommandTest.java
Original file line number Diff line number Diff line change
@@ -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<ReporterOptions> 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<ReporterOptions> 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<ReporterOptions> 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<ReporterOptions> 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<ReporterOptions> 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());
}

}