Skip to content

Commit 0e5b5eb

Browse files
committed
Convert the RunCommand-properties into the new Config-Objects first
1 parent 2c682e9 commit 0e5b5eb

File tree

4 files changed

+152
-6
lines changed

4 files changed

+152
-6
lines changed

src/main/java/org/utplsql/cli/RunCommand.java

Lines changed: 87 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,11 @@
1010
import org.utplsql.api.exception.DatabaseNotCompatibleException;
1111
import org.utplsql.api.exception.SomeTestsFailedException;
1212
import org.utplsql.api.exception.UtPLSQLNotInstalledException;
13+
import org.utplsql.api.reporter.CoreReporters;
1314
import org.utplsql.api.reporter.Reporter;
1415
import org.utplsql.api.reporter.ReporterFactory;
16+
import org.utplsql.cli.config.ReporterConfig;
17+
import org.utplsql.cli.config.TestRunnerConfig;
1518
import org.utplsql.cli.exception.DatabaseConnectionFailed;
1619

1720
import javax.sql.DataSource;
@@ -36,10 +39,10 @@ public class RunCommand implements ICommand {
3639

3740
@Parameter(
3841
required = true,
39-
converter = ConnectionInfo.ConnectionStringConverter.class,
42+
//converter = ConnectionInfo.ConnectionStringConverter.class,
4043
arity = 1,
4144
description = ConnectionInfo.COMMANDLINE_PARAM_DESCRIPTION)
42-
private List<ConnectionInfo> connectionInfoList = new ArrayList<>();
45+
private String connectionInfo = "";
4346

4447
@Parameter(
4548
names = {"-p", "--path"},
@@ -100,12 +103,16 @@ public class RunCommand implements ICommand {
100103
private String excludeObjects = null;
101104

102105

106+
private ConnectionInfo connectionInfoObj;
103107
private CompatibilityProxy compatibilityProxy;
104108
private ReporterFactory reporterFactory;
105109
private ReporterManager reporterManager;
106110

107111
public ConnectionInfo getConnectionInfo() {
108-
return connectionInfoList.get(0);
112+
if ( connectionInfoObj == null )
113+
connectionInfoObj = new ConnectionInfo(connectionInfo);
114+
115+
return connectionInfoObj;
109116
}
110117

111118
public List<String> getTestPaths() {
@@ -326,4 +333,81 @@ private ReporterManager getReporterManager() {
326333
public List<ReporterOptions> getReporterOptionsList() {
327334
return getReporterManager().getReporterOptionsList();
328335
}
336+
337+
private List<ReporterConfig> getReporterConfigs() {
338+
List<ReporterConfig> reporterConfigs = new ArrayList<>(5);
339+
340+
String reporterName = null;
341+
String outputFile = null;
342+
Boolean forceToScreen = null;
343+
for (String p : reporterParams) {
344+
if (!p.startsWith("-")) {
345+
if ( reporterName != null ) {
346+
reporterConfigs.add(new ReporterConfig(reporterName, outputFile, forceToScreen));
347+
reporterName = null;
348+
outputFile = null;
349+
forceToScreen = null;
350+
}
351+
reporterName = p;
352+
}
353+
else if (p.startsWith("-o="))
354+
outputFile = p.substring(3);
355+
else if (p.equals("-s"))
356+
forceToScreen = true;
357+
}
358+
359+
if ( reporterName != null )
360+
reporterConfigs.add(new ReporterConfig(reporterName, outputFile, forceToScreen));
361+
362+
return reporterConfigs;
363+
}
364+
365+
private String[] getSplitList( String delimitedList ) {
366+
if ( delimitedList != null && !delimitedList.isEmpty() )
367+
return delimitedList.split(",");
368+
else
369+
return null;
370+
}
371+
372+
public TestRunnerConfig getConfig() {
373+
final List<Reporter> reporterList;
374+
List<ReporterOptions> reporterOptionsList = new ArrayList<>();
375+
ReporterOptions reporterOptions = null;
376+
377+
List<ReporterConfig> reporterConfigs = getReporterConfigs();
378+
379+
// If no reporter parameters were passed, use default reporter.
380+
if (reporterOptionsList.isEmpty()) {
381+
reporterOptionsList.add(new ReporterOptions(CoreReporters.UT_DOCUMENTATION_REPORTER.name()));
382+
}
383+
final List<String> testPaths = getTestPaths();
384+
385+
final File baseDir = new File("").getAbsoluteFile();
386+
final FileMapperOptions[] sourceMappingOptions = {null};
387+
final FileMapperOptions[] testMappingOptions = {null};
388+
389+
final int[] returnCode = {0};
390+
391+
sourceMappingOptions[0] = getFileMapperOptionsByParamListItem(this.sourcePathParams, baseDir);
392+
testMappingOptions[0] = getFileMapperOptionsByParamListItem(this.testPathParams, baseDir);
393+
394+
String[] testPathArr = new String[testPaths.size()];
395+
testPathArr = testPaths.toArray(testPathArr);
396+
397+
ReporterConfig[] reporterConfigArr = new ReporterConfig[reporterConfigs.size()];
398+
reporterConfigArr = reporterConfigs.toArray(reporterConfigArr);
399+
400+
return new TestRunnerConfig(
401+
connectionInfo,
402+
testPathArr,
403+
reporterConfigArr,
404+
colorConsole,
405+
failureExitCode,
406+
skipCompatibilityCheck,
407+
getSplitList(includeObjects),
408+
getSplitList(excludeObjects),
409+
null,
410+
null
411+
);
412+
}
329413
}

src/main/java/org/utplsql/cli/config/ReporterConfig.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ public class ReporterConfig {
99
private boolean screen = false;
1010

1111
@ConstructorProperties({"name", "output", "screen"})
12-
public ReporterConfig( String name, String output, boolean screen ) {
12+
public ReporterConfig( String name, String output, Boolean screen ) {
1313
this.name = name;
1414
this.output = output;
15-
this.screen = screen;
15+
if ( screen != null ) this.screen = screen;
1616
}
1717

1818
public String getName() {

src/test/java/org/utplsql/cli/YmlConfigTest.java

Lines changed: 37 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
package org.utplsql.cli;
22

3+
import com.beust.jcommander.JCommander;
34
import com.fasterxml.jackson.databind.ObjectMapper;
45
import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
56
import org.apache.commons.lang3.builder.ReflectionToStringBuilder;
@@ -10,6 +11,10 @@
1011
import java.io.File;
1112
import java.io.IOException;
1213

14+
import static org.junit.jupiter.api.Assertions.assertEquals;
15+
import static org.junit.jupiter.api.Assertions.assertNull;
16+
import static org.junit.jupiter.api.Assertions.assertTrue;
17+
1318
public class YmlConfigTest {
1419

1520
@Test
@@ -21,7 +26,38 @@ public void letsPlayAround() throws IOException {
2126

2227
TestRunnerConfig config = mapper.readValue(new File(testConfigFile), TestRunnerConfig.class);
2328

24-
System.out.println(ReflectionToStringBuilder.toString(config,ToStringStyle.MULTI_LINE_STYLE));
29+
System.out.println(ReflectionToStringBuilder.toString(config, ToStringStyle.MULTI_LINE_STYLE));
30+
}
31+
32+
@Test
33+
public void configTest() {
34+
JCommander jc = new JCommander();
35+
jc.setProgramName("utplsql");
36+
37+
CommandProvider cmdProvider = new CommandProvider();
38+
39+
cmdProvider.commands().forEach(cmd -> jc.addCommand(cmd.getCommand(), cmd));
40+
41+
jc.parse("run", TestHelper.getConnectionString(),
42+
"-f=ut_coverage_html_reporter", "-o=test.html",
43+
"-f=ut_documentation_reporter", "-s",
44+
"-exclude=app.award_bonus,app.betwnstr");
45+
46+
RunCommand cmd = (RunCommand) cmdProvider.getCommand(jc.getParsedCommand());
47+
48+
TestRunnerConfig config = cmd.getConfig();
49+
50+
assertEquals(TestHelper.getConnectionString(), config.getConnectString());
51+
assertEquals(2, config.getReporters().length);
52+
assertEquals("ut_coverage_html_reporter", config.getReporters()[0].getName());
53+
assertEquals("test.html", config.getReporters()[0].getOutput());
54+
assertEquals(false, config.getReporters()[0].isScreen());
55+
assertEquals("ut_documentation_reporter", config.getReporters()[1].getName());
56+
assertNull(config.getReporters()[1].getOutput());
57+
assertEquals(true, config.getReporters()[1].isScreen());
58+
assertEquals("app.award_bonus", config.getExcludePackages()[0]);
59+
assertEquals("app.betwnstr", config.getExcludePackages()[1]);
60+
2561
}
2662

2763

src/test/resources/test

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
utPLSQL-cli/bin/utplsql run test_runner/pass@db_url \
2+
-p=hr,app \
3+
-f=ut_documentation_reporter \
4+
-f=ut_coverage_html_reporter \
5+
-o=coverage.html \
6+
-f=ut_sonar_test_reporter \
7+
-o=sonar.txt \
8+
-s \
9+
-c \
10+
--failure-exit-code=2 \
11+
-scc \
12+
-include=app.betwnstr,mypackage \
13+
-exclude=mypackage.blugg,stuff \
14+
-source_path=sources \
15+
-regex_expression="/(\w+)/(\w+)/(\w+)\..{3}$" \
16+
-type_mapping="packages_bodies=PACKAGE BODY/types_bodies=TYPE BODY/triggers=TRIGGER/procedures=PROCEDURE/functions=FUNCTION" \
17+
-owner_subexpression=2 \
18+
-name_subexpression=3 \
19+
-type_subexpression=4 \
20+
-test_path=tests -regex_expression="/(\w+)/(\w+)/(\w+)\..{3}$" \
21+
-type_mapping="body=PACKAGE BODY/type_body=TYPE BODY/trigger=TRIGGER" \
22+
-owner_subexpression=2 \
23+
-name_subexpression=3 \
24+
-type_subexpression=4 \
25+
-f=ut_coverage_html_reporter -o=coverage.html \
26+
-f=ut_sonar_test_reporter -o=test_results.xml

0 commit comments

Comments
 (0)