@@ -72,6 +72,10 @@ public void resetDefaultsForStaticFields() throws Exception {
72
72
ReflectionTestUtils .setField (Main .class , "objectFilter" , "%" );
73
73
ReflectionTestUtils .setField (Main .class , "typeFilter" , "" );
74
74
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 );
75
79
}
76
80
77
81
@ BeforeMethod
@@ -139,57 +143,59 @@ public void testStopOnWarning() throws Exception {
139
143
public void testExportHRSchemaDefault () throws Exception {
140
144
String [] args = {"-url" , url };
141
145
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 {
144
152
assertThat (out , containsString ("Will try to process schema [HR]" ));
145
153
assertThat (out , containsString ("Start getting of user object list in schema HR for processing" ));
146
154
assertThat (out , containsString ("WARNING: processing of 'PUBLIC DATABASE LINK' will be skipped because HR no access to view it" ));
147
155
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 )));
155
163
156
164
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 |" ));
164
172
165
173
166
174
assertThat (out , containsString ("Written 15 ddls with user objects from total 34 in schema HR" ));
167
175
assertThat (out , containsString ("Skip processing 19 user objects from total 34 in schema HR" ));
168
176
assertThat (out , containsString ("scheme2ddl of schema HR completed" ));
169
177
170
178
171
- assertEqualsFileContent (pwd + "/sequences/locations_seq.sql" , "CREATE SEQUENCE \" HR\" .\" LOCATIONS_SEQ\" " +
179
+ assertEqualsFileContent (dirPath + "/sequences/locations_seq.sql" , "CREATE SEQUENCE \" HR\" .\" LOCATIONS_SEQ\" " +
172
180
" MINVALUE 1 MAXVALUE 9900 INCREMENT BY 100 START WITH 3300 NOCACHE NOORDER NOCYCLE ;" );
173
181
174
182
175
- assertEqualsFileContent (pwd + "/tables/regions.sql" , "CREATE TABLE \" HR\" .\" REGIONS\" \n " +
183
+ assertEqualsFileContent (dirPath + "/tables/regions.sql" , "CREATE TABLE \" HR\" .\" REGIONS\" \n " +
176
184
" (\t \" REGION_ID\" NUMBER CONSTRAINT \" REGION_ID_NN\" NOT NULL ENABLE, \n " +
177
185
"\t \" REGION_NAME\" VARCHAR2(25)\n " +
178
186
" ) ;\n " +
179
187
" ALTER TABLE \" HR\" .\" REGIONS\" ADD CONSTRAINT \" REG_ID_PK\" PRIMARY KEY (\" REGION_ID\" ) ENABLE;\n " +
180
188
" CREATE UNIQUE INDEX \" HR\" .\" REG_ID_PK\" ON \" HR\" .\" REGIONS\" (\" REGION_ID\" ) \n " +
181
189
" ;" );
182
190
183
- assertEqualsFileContent (pwd + "/triggers/secure_employees.sql" ,
191
+ assertEqualsFileContent (dirPath + "/triggers/secure_employees.sql" ,
184
192
"CREATE OR REPLACE TRIGGER \" HR\" .\" SECURE_EMPLOYEES\" \n " +
185
193
" BEFORE INSERT OR UPDATE OR DELETE ON employees\n " +
186
194
"BEGIN\n " +
187
195
" secure_dml;\n " +
188
196
"END secure_employees;\n " +
189
197
"/\n " +
190
198
"ALTER TRIGGER \" HR\" .\" SECURE_EMPLOYEES\" DISABLE;" );
191
-
192
-
193
199
}
194
200
195
201
@@ -240,8 +246,6 @@ public void testProcessForeignSchema() throws Exception {
240
246
241
247
@ Test
242
248
public void testFilterAndReplaceSeqValue () throws Exception {
243
- File tempOutput = FileUtils .getFile (FileUtils .getTempDirectoryPath (),
244
- "scheme2ddl-test-" + UUID .randomUUID ().toString ().substring (0 ,8 ));
245
249
String outputPath = tempOutput .getAbsolutePath ();
246
250
247
251
String [] args = {"-url" , url , "-f" , "LOCATIONS_SEQ" , "-o" , outputPath };
@@ -264,6 +268,16 @@ public void testFilterAndReplaceSeqValue() throws Exception {
264
268
265
269
}
266
270
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
+
267
281
268
282
private static void assertEqualsFileContent (String path , String content ) throws IOException {
269
283
File file = new File (path );
0 commit comments