Skip to content

Commit 2f06f30

Browse files
committed
[more tests] test with default config from path
1 parent 04cd84f commit 2f06f30

File tree

1 file changed

+37
-23
lines changed

1 file changed

+37
-23
lines changed

src/test/java/com/googlecode/scheme2ddl/MainIT.java

Lines changed: 37 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,10 @@ public void resetDefaultsForStaticFields() throws Exception {
7272
ReflectionTestUtils.setField(Main.class, "objectFilter", "%");
7373
ReflectionTestUtils.setField(Main.class, "typeFilter", "");
7474
ReflectionTestUtils.setField(Main.class, "typeFilterMode", "include");
75+
ReflectionTestUtils.setField(Main.class, "isLaunchedByDBA", false);
76+
ReflectionTestUtils.setField(Main.class, "schemas", null);
77+
ReflectionTestUtils.setField(Main.class, "schemaList", null);
78+
ReflectionTestUtils.setField(Main.class, "replaceSequenceValues", false);
7579
}
7680

7781
@BeforeMethod
@@ -139,57 +143,59 @@ public void testStopOnWarning() throws Exception {
139143
public void testExportHRSchemaDefault() throws Exception {
140144
String[] args = {"-url", url};
141145
Main.main(args);
142-
String out = outContent.toString();
143-
String pwd = FileUtils.getFile(new File("output")).getAbsolutePath();
146+
assertHRSchemaDefault(
147+
FileUtils.getFile(new File("output")).getAbsolutePath(),
148+
outContent.toString());
149+
}
150+
151+
private static void assertHRSchemaDefault(String dirPath, String out) throws IOException {
144152
assertThat(out, containsString("Will try to process schema [HR]"));
145153
assertThat(out, containsString("Start getting of user object list in schema HR for processing"));
146154
assertThat(out, containsString("WARNING: processing of 'PUBLIC DATABASE LINK' will be skipped because HR no access to view it"));
147155
assertThat(out, containsString("Found 34 items for processing in schema HR"));
148-
assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %s/sequences/locations_seq.sql", pwd)));
149-
assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %s/sequences/employees_seq.sql", pwd)));
150-
assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %s/triggers/update_job_history.sql", pwd)));
151-
assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %s/procedures/add_job_history.sql", pwd)));
152-
assertThat(out, containsString(String.format("Saved table hr.locations to file %s/tables/locations.sql", pwd)));
153-
assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %s/procedures/secure_dml.sql", pwd)));
154-
assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %s/views/emp_details_view.sql", pwd)));
156+
assertThat(out, containsString(String.format("Saved sequence hr.locations_seq to file %s/sequences/locations_seq.sql", dirPath)));
157+
assertThat(out, containsString(String.format("Saved sequence hr.employees_seq to file %s/sequences/employees_seq.sql", dirPath)));
158+
assertThat(out, containsString(String.format("Saved trigger hr.update_job_history to file %s/triggers/update_job_history.sql", dirPath)));
159+
assertThat(out, containsString(String.format("Saved procedure hr.add_job_history to file %s/procedures/add_job_history.sql", dirPath)));
160+
assertThat(out, containsString(String.format("Saved table hr.locations to file %s/tables/locations.sql", dirPath)));
161+
assertThat(out, containsString(String.format("Saved procedure hr.secure_dml to file %s/procedures/secure_dml.sql", dirPath)));
162+
assertThat(out, containsString(String.format("Saved view hr.emp_details_view to file %s/views/emp_details_view.sql", dirPath)));
155163

156164

157-
assertThat(out, containsString(
158-
"-------------------------------------------------------\n" +
159-
" R E P O R T S K I P P E D O B J E C T S \n" +
160-
"-------------------------------------------------------\n" +
161-
"| skip rule | object type | count |\n" +
162-
"-------------------------------------------------------\n" +
163-
"| config | INDEX | 19 |"));
165+
assertThat(out, containsString(
166+
"-------------------------------------------------------\n" +
167+
" R E P O R T S K I P P E D O B J E C T S \n" +
168+
"-------------------------------------------------------\n" +
169+
"| skip rule | object type | count |\n" +
170+
"-------------------------------------------------------\n" +
171+
"| config | INDEX | 19 |"));
164172

165173

166174
assertThat(out, containsString("Written 15 ddls with user objects from total 34 in schema HR"));
167175
assertThat(out, containsString("Skip processing 19 user objects from total 34 in schema HR"));
168176
assertThat(out, containsString("scheme2ddl of schema HR completed"));
169177

170178

171-
assertEqualsFileContent(pwd + "/sequences/locations_seq.sql", "CREATE SEQUENCE \"HR\".\"LOCATIONS_SEQ\"" +
179+
assertEqualsFileContent(dirPath + "/sequences/locations_seq.sql", "CREATE SEQUENCE \"HR\".\"LOCATIONS_SEQ\"" +
172180
" MINVALUE 1 MAXVALUE 9900 INCREMENT BY 100 START WITH 3300 NOCACHE NOORDER NOCYCLE ;");
173181

174182

175-
assertEqualsFileContent(pwd + "/tables/regions.sql", "CREATE TABLE \"HR\".\"REGIONS\" \n" +
183+
assertEqualsFileContent(dirPath + "/tables/regions.sql", "CREATE TABLE \"HR\".\"REGIONS\" \n" +
176184
" (\t\"REGION_ID\" NUMBER CONSTRAINT \"REGION_ID_NN\" NOT NULL ENABLE, \n" +
177185
"\t\"REGION_NAME\" VARCHAR2(25)\n" +
178186
" ) ;\n" +
179187
" ALTER TABLE \"HR\".\"REGIONS\" ADD CONSTRAINT \"REG_ID_PK\" PRIMARY KEY (\"REGION_ID\") ENABLE;\n" +
180188
" CREATE UNIQUE INDEX \"HR\".\"REG_ID_PK\" ON \"HR\".\"REGIONS\" (\"REGION_ID\") \n" +
181189
" ;");
182190

183-
assertEqualsFileContent(pwd + "/triggers/secure_employees.sql",
191+
assertEqualsFileContent(dirPath + "/triggers/secure_employees.sql",
184192
"CREATE OR REPLACE TRIGGER \"HR\".\"SECURE_EMPLOYEES\" \n" +
185193
" BEFORE INSERT OR UPDATE OR DELETE ON employees\n" +
186194
"BEGIN\n" +
187195
" secure_dml;\n" +
188196
"END secure_employees;\n" +
189197
"/\n" +
190198
"ALTER TRIGGER \"HR\".\"SECURE_EMPLOYEES\" DISABLE;");
191-
192-
193199
}
194200

195201

@@ -240,8 +246,6 @@ public void testProcessForeignSchema() throws Exception {
240246

241247
@Test
242248
public void testFilterAndReplaceSeqValue() throws Exception {
243-
File tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(),
244-
"scheme2ddl-test-" + UUID.randomUUID().toString().substring(0,8));
245249
String outputPath = tempOutput.getAbsolutePath();
246250

247251
String[] args = {"-url", url, "-f", "LOCATIONS_SEQ", "-o", outputPath};
@@ -264,6 +268,16 @@ public void testFilterAndReplaceSeqValue() throws Exception {
264268

265269
}
266270

271+
@Test
272+
public void testRunWithCustomConfig() throws Exception {
273+
String outputPath = tempOutput.getAbsolutePath();
274+
String[] args = {"-url", url, "-c", "src/main/resources/scheme2ddl.config.xml", "-o", outputPath};
275+
Main.main(args);
276+
assertHRSchemaDefault(
277+
outputPath,
278+
outContent.toString());
279+
}
280+
267281

268282
private static void assertEqualsFileContent(String path, String content) throws IOException {
269283
File file = new File(path);

0 commit comments

Comments
 (0)