Skip to content

Commit 5520562

Browse files
committed
Some more tests around FileMapping
Also fixed a bug - the Object types are the actual key which should be translated into Key-Values later
1 parent ce849fc commit 5520562

File tree

2 files changed

+51
-4
lines changed

2 files changed

+51
-4
lines changed

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ FileMapperConfig toFileMapperConfig() {
147147
if ( mapping.typeMapping != null && !mapping.typeMapping.isEmpty()) {
148148
for ( String keyVal : mapping.typeMapping.split("/")) {
149149
String[] values = keyVal.split("=");
150-
typeMap.put(values[0], values[1]);
150+
typeMap.put(values[1], values[0]);
151151
}
152152
}
153153

@@ -157,8 +157,8 @@ FileMapperConfig toFileMapperConfig() {
157157
mapping.regexExpression,
158158
typeMap,
159159
mapping.ownerSubExpression,
160-
mapping.typeSubExpression,
161-
mapping.nameSubExpression
160+
mapping.nameSubExpression,
161+
mapping.typeSubExpression
162162
);
163163
}
164164
}

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

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

33
import org.junit.jupiter.api.Test;
4+
import org.utplsql.cli.config.FileMapperConfig;
45
import org.utplsql.cli.config.ReporterConfig;
56
import org.utplsql.cli.config.RunCommandConfig;
67
import picocli.CommandLine;
78

89
import java.util.List;
910

1011
import static org.hamcrest.MatcherAssert.assertThat;
11-
import static org.hamcrest.Matchers.is;
12+
import static org.hamcrest.Matchers.*;
1213
import static org.junit.jupiter.api.Assertions.*;
1314

1415
public class PicocliRunCommandTest {
1516

1617
private RunCommandConfig parseForConfig( String... args ) throws Exception {
1718
Object obj = new UtplsqlPicocliCommand();
1819
CommandLine cline = new CommandLine(obj);
20+
cline.setTrimQuotes(true);
1921
List<CommandLine> parsed = cline.parse(args);
2022

2123
RunPicocliCommand runCmd = parsed.get(1).getCommand();
@@ -167,4 +169,49 @@ void multipleReporters() throws Exception {
167169
assertEquals("output2.html", reporterConfig.getOutput());
168170
assertTrue(reporterConfig.isScreen());
169171
}
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+
}
170217
}

0 commit comments

Comments
 (0)