|
1 | 1 | package org.utplsql.cli; |
2 | 2 |
|
3 | 3 | import org.junit.jupiter.api.Test; |
| 4 | +import org.utplsql.cli.config.FileMapperConfig; |
4 | 5 | import org.utplsql.cli.config.ReporterConfig; |
5 | 6 | import org.utplsql.cli.config.RunCommandConfig; |
6 | 7 | import picocli.CommandLine; |
7 | 8 |
|
8 | 9 | import java.util.List; |
9 | 10 |
|
10 | 11 | import static org.hamcrest.MatcherAssert.assertThat; |
11 | | -import static org.hamcrest.Matchers.is; |
| 12 | +import static org.hamcrest.Matchers.*; |
12 | 13 | import static org.junit.jupiter.api.Assertions.*; |
13 | 14 |
|
14 | 15 | public class PicocliRunCommandTest { |
15 | 16 |
|
16 | 17 | private RunCommandConfig parseForConfig( String... args ) throws Exception { |
17 | 18 | Object obj = new UtplsqlPicocliCommand(); |
18 | 19 | CommandLine cline = new CommandLine(obj); |
| 20 | + cline.setTrimQuotes(true); |
19 | 21 | List<CommandLine> parsed = cline.parse(args); |
20 | 22 |
|
21 | 23 | RunPicocliCommand runCmd = parsed.get(1).getCommand(); |
@@ -167,4 +169,49 @@ void multipleReporters() throws Exception { |
167 | 169 | assertEquals("output2.html", reporterConfig.getOutput()); |
168 | 170 | assertTrue(reporterConfig.isScreen()); |
169 | 171 | } |
| 172 | + |
| 173 | + @Test |
| 174 | + void sourceFileMapping() throws Exception { |
| 175 | + RunCommandConfig config = parseForConfig("run", |
| 176 | + TestHelper.getConnectionString(), |
| 177 | + "-source_path=src/test/resources/plsql/source", |
| 178 | + "-owner=app", |
| 179 | + "-regex_expression=\"[a-Z+]\"", |
| 180 | + "-type_mapping=\"sql=PACKAGE BODY/pks=PACKAGE\"", |
| 181 | + "-owner_subexpression=0", |
| 182 | + "-type_subexpression=1", |
| 183 | + "-name_subexpression=3"); |
| 184 | + |
| 185 | + FileMapperConfig sourceMapperConfig = config.getSourceMapping(); |
| 186 | + assertEquals( "src/test/resources/plsql/source", sourceMapperConfig.getPath()); |
| 187 | + assertEquals( "app", sourceMapperConfig.getOwner()); |
| 188 | + assertEquals( "[a-Z+]", sourceMapperConfig.getRegexExpression()); |
| 189 | + assertThat( sourceMapperConfig.getTypeMapping(), hasEntry("PACKAGE BODY", "sql")); |
| 190 | + assertThat( sourceMapperConfig.getTypeMapping(), hasEntry("PACKAGE", "pks")); |
| 191 | + assertEquals( 0, sourceMapperConfig.getOwnerSubexpression()); |
| 192 | + assertEquals( 1, sourceMapperConfig.getTypeSubexpression()); |
| 193 | + assertEquals( 3, sourceMapperConfig.getNameSubexpression()); |
| 194 | + } |
| 195 | + @Test |
| 196 | + void testFileMapping() throws Exception { |
| 197 | + RunCommandConfig config = parseForConfig("run", |
| 198 | + TestHelper.getConnectionString(), |
| 199 | + "-test_path=src/test/resources/plsql/test", |
| 200 | + "-owner=test_app", |
| 201 | + "-regex_expression=\"test_regex\"", |
| 202 | + "-type_mapping=\"tsql=PACKAGE BODY/tsql=FUNCTION\"", |
| 203 | + "-owner_subexpression=4", |
| 204 | + "-type_subexpression=5", |
| 205 | + "-name_subexpression=6"); |
| 206 | + |
| 207 | + FileMapperConfig testMapperConfig = config.getTestMapping(); |
| 208 | + assertEquals( "src/test/resources/plsql/test", testMapperConfig.getPath()); |
| 209 | + assertEquals( "test_app", testMapperConfig.getOwner()); |
| 210 | + assertEquals( "test_regex", testMapperConfig.getRegexExpression()); |
| 211 | + assertThat( testMapperConfig.getTypeMapping(), hasEntry("PACKAGE BODY", "tsql")); |
| 212 | + assertThat( testMapperConfig.getTypeMapping(), hasEntry("FUNCTION", "tsql")); |
| 213 | + assertEquals( 4, testMapperConfig.getOwnerSubexpression()); |
| 214 | + assertEquals( 5, testMapperConfig.getTypeSubexpression()); |
| 215 | + assertEquals( 6, testMapperConfig.getNameSubexpression()); |
| 216 | + } |
170 | 217 | } |
0 commit comments