Skip to content

Commit b8ff97f

Browse files
committed
Merge branch 'coverall'
2 parents eea9c24 + 2ace1f8 commit b8ff97f

File tree

11 files changed

+653
-99
lines changed

11 files changed

+653
-99
lines changed

src/main/java/com/googlecode/scheme2ddl/Main.java

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static void processSchemas(ConfigurableApplicationContext context) {
138138
if (isLaunchedByDBA)
139139
schemaList = new ArrayList<String>(listFromContext);
140140
else {
141-
log.warn("Ignore 'schemaList' from advanced config, becouse oracle user is not connected as sys dba");
141+
log.warn("Ignore 'schemaList' from advanced config, because oracle user is not connected as sys dba");
142142
schemaList = extactSchemaListFromUserName(context);
143143
}
144144
}
@@ -171,13 +171,6 @@ private static List<String> extactSchemaListFromUserName(ConfigurableApplication
171171
return list;
172172
}
173173

174-
private static void fillSchemaListFromUserName(ConfigurableApplicationContext context) {
175-
OracleDataSource dataSource = (OracleDataSource) context.getBean("dataSource");
176-
String schemaName = dataSource.getUser().split(" ")[0];
177-
schemaList = new ArrayList<String>();
178-
schemaList.add(schemaName);
179-
}
180-
181174
/**
182175
* @param context
183176
* @return existing bean 'schemaList', if this exists, or create and register new bean

src/main/java/com/googlecode/scheme2ddl/TypeNamesUtil.java

Lines changed: 0 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -28,19 +28,5 @@ public static String map2TypeForDBMS(String type) {
2828
return type.replace(" ", "_");
2929
}
3030

31-
/**
32-
* Oracle types in user_table without underscore, for example PACKAGE BODY
33-
* but in DBMS_METADATA with underscore PACKAGE_BODY
34-
* @param type - type name from DBMS_METADATA representation
35-
*
36-
* @return type name for using in advanced config
37-
*/
38-
public static String map2TypeForConfig(String type) {
39-
if (type.equals("DB_LINK"))
40-
return "DATABASE LINK";
41-
if (type.equals("PROCOBJ"))
42-
return "JOB";
43-
return type.replace("_", " ");
44-
}
4531

4632
}

src/main/java/com/googlecode/scheme2ddl/UserObjectJobRunner.java

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -65,13 +65,6 @@ int start(ConfigurableApplicationContext context, boolean launchedByDBA, String
6565
}
6666
}
6767

68-
private JobParameters getJobParameters(String schemaName, boolean launchedByDBA) {
69-
JobParametersBuilder parametersBuilder = new JobParametersBuilder();
70-
parametersBuilder.addString("schemaName", schemaName.toUpperCase());
71-
parametersBuilder.addString("launchedByDBA", Boolean.toString(launchedByDBA));
72-
return parametersBuilder.toJobParameters();
73-
}
74-
7568
private void writeJobExecutionStatus(JobExecution jobExecution, JobParameters jobParameters) {
7669
StepExecution step = jobExecution.getStepExecutions().toArray(new StepExecution[]{})[0];
7770
String schemaName = jobParameters.getString("schemaName");

src/main/java/com/googlecode/scheme2ddl/dao/UserObjectDaoImpl.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -310,7 +310,7 @@ public String findRefGroupDDL(String type, final String name) {
310310
+ " GROUP BY rname";
311311

312312
public Object doInConnection(Connection connection) throws SQLException, DataAccessException {
313-
System.out.println(query);
313+
//todo sl4j logger.debug( "query: \n {} ", query);
314314
applyTransformParameters(connection);
315315
PreparedStatement ps = connection.prepareStatement(query);
316316

Lines changed: 117 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,117 @@
1+
package com.googlecode.scheme2ddl;
2+
3+
import org.apache.commons.io.FileUtils;
4+
import org.springframework.beans.factory.annotation.Autowired;
5+
import org.springframework.beans.factory.annotation.Value;
6+
import org.springframework.boot.test.context.SpringBootTest;
7+
import org.springframework.jdbc.CannotGetJdbcConnectionException;
8+
import org.springframework.jdbc.core.JdbcTemplate;
9+
import org.springframework.test.context.testng.AbstractTestNGSpringContextTests;
10+
import org.springframework.test.util.ReflectionTestUtils;
11+
import org.testng.SkipException;
12+
import org.testng.annotations.AfterMethod;
13+
import org.testng.annotations.BeforeClass;
14+
import org.testng.annotations.BeforeMethod;
15+
16+
import java.io.ByteArrayOutputStream;
17+
import java.io.File;
18+
import java.io.IOException;
19+
import java.io.PrintStream;
20+
import java.util.UUID;
21+
22+
import static org.testng.Assert.assertEquals;
23+
import static org.testng.Assert.assertTrue;
24+
25+
/**
26+
* Created by Anton Reshetnikov on 12 Dec 2016.
27+
*/
28+
@SpringBootTest(classes = ConfigurationIT.class, properties = "test-default.properties")
29+
public abstract class BaseIT extends AbstractTestNGSpringContextTests {
30+
31+
@Value("${hrUrl}")
32+
protected String url;
33+
34+
@Value("${dbaUrl}")
35+
protected String dbaUrl;
36+
37+
@Value("${dbaAsSysdbaUrl}")
38+
protected String dbaAsSysdbaUrl;
39+
40+
41+
@Autowired
42+
protected JdbcTemplate dbaJdbcTemplate;
43+
44+
protected final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
45+
protected final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
46+
47+
protected final PrintStream outOriginal = System.out;
48+
protected final PrintStream errorOriginal = System.err;
49+
50+
51+
protected File tempOutput;
52+
53+
54+
@BeforeClass
55+
public void setUp() {
56+
try {
57+
dbaJdbcTemplate.execute("ALTER USER HR ACCOUNT UNLOCK IDENTIFIED BY pass");
58+
}
59+
catch (CannotGetJdbcConnectionException e){
60+
logger.warn("Ignore all test due", e);
61+
throw new SkipException("Ignore all test due " + e.getMessage());
62+
}
63+
64+
}
65+
66+
@BeforeMethod
67+
public void resetDefaultsForStaticFields() throws Exception {
68+
ReflectionTestUtils.setField(Main.class, "justPrintUsage", false);
69+
ReflectionTestUtils.setField(Main.class, "justPrintVersion", false);
70+
ReflectionTestUtils.setField(Main.class, "justTestConnection", false);
71+
ReflectionTestUtils.setField(Main.class, "dbUrl", null);
72+
ReflectionTestUtils.setField(Main.class, "objectFilter", "%");
73+
ReflectionTestUtils.setField(Main.class, "typeFilter", "");
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);
79+
ReflectionTestUtils.setField(Main.class, "customConfigLocation", null);
80+
ReflectionTestUtils.setField(Main.class, "parallelCount", 4);
81+
ReflectionTestUtils.setField(Main.class, "outputPath", null);
82+
}
83+
84+
@BeforeMethod
85+
public void setUpStreams() {
86+
System.setOut(new PrintStream(outContent));
87+
System.setErr(new PrintStream(errContent));
88+
}
89+
90+
@AfterMethod
91+
public void cleanUpStreams() throws IOException {
92+
System.setOut(outOriginal);
93+
System.setErr(errorOriginal);
94+
outContent.reset();
95+
errContent.reset();
96+
}
97+
98+
@BeforeMethod
99+
public void setUpTempOutputDir(){
100+
tempOutput = FileUtils.getFile(FileUtils.getTempDirectoryPath(),
101+
"scheme2ddl-test-tmp-output",
102+
UUID.randomUUID().toString().substring(0,8));
103+
}
104+
105+
@AfterMethod
106+
public void cleanUpTempOutput() throws IOException {
107+
FileUtils.deleteDirectory(tempOutput);
108+
}
109+
110+
protected static void assertEqualsFileContent(String path, String content) throws IOException {
111+
File file = new File(path);
112+
assertTrue(file.exists(), "file doesn't exists " + file );
113+
String fileContent = FileUtils.readFileToString(file, "UTF-8");
114+
assertEquals(fileContent.trim().replace("\r", ""), content.replace("\r", ""));
115+
116+
}
117+
}

0 commit comments

Comments
 (0)