Commit ea5f4d78f0ba7ba793a1e8a75ab67f86beba07e1

Authored by Volodymyr Babak
1 parent 2b8a8fb8

Fixed device api sql test

... ... @@ -235,7 +235,6 @@ spring:
235 235 enabled: "true"
236 236 jpa:
237 237 show-sql: "false"
238   - generate-ddl: "true"
239 238 database-platform: "org.hibernate.dialect.PostgreSQLDialect"
240 239 hibernate:
241 240 ddl-auto: "validate"
... ...
... ... @@ -22,5 +22,5 @@ import org.thingsboard.server.system.BaseHttpDeviceApiTest;
22 22 * Created by Valerii Sosliuk on 6/27/2017.
23 23 */
24 24 @DaoSqlTest
25   -public class DeviceApiSqlTest extends BaseHttpDeviceApiTest{
  25 +public class DeviceApiSqlTest extends BaseHttpDeviceApiTest {
26 26 }
... ...
... ... @@ -37,21 +37,22 @@ import java.util.Properties;
37 37 public class CustomSqlUnit extends ExternalResource {
38 38
39 39 private List<String> sqlFiles;
40   - private Properties properties;
41 40 private String dropAllTablesSqlFile;
  41 + private String dbUrl;
  42 + private String dbUserName;
  43 + private String dbPassword;
42 44
43 45 public CustomSqlUnit(List<String> sqlFiles, String configurationFileName, String dropAllTablesSqlFile) {
44 46 this.sqlFiles = sqlFiles;
45   - this.properties = loadProperties(configurationFileName);
46 47 this.dropAllTablesSqlFile = dropAllTablesSqlFile;
  48 + loadProperties(configurationFileName);
47 49 }
48 50
49 51 @Override
50 52 public void before() {
51 53 Connection conn = null;
52 54 try {
53   - String url = properties.getProperty("spring.datasource.url");
54   - conn = DriverManager.getConnection(url, "sa", "");
  55 + conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
55 56 for (String sqlFile : sqlFiles) {
56 57 URL sqlFileUrl = Resources.getResource(sqlFile);
57 58 String sql = Resources.toString(sqlFileUrl, Charsets.UTF_8);
... ... @@ -74,8 +75,7 @@ public class CustomSqlUnit extends ExternalResource {
74 75 public void after() {
75 76 Connection conn = null;
76 77 try {
77   - String url = properties.getProperty("spring.datasource.url");
78   - conn = DriverManager.getConnection(url, "sa", "");
  78 + conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
79 79 URL dropAllTableSqlFileUrl = Resources.getResource(dropAllTablesSqlFile);
80 80 String dropAllTablesSql = Resources.toString(dropAllTableSqlFileUrl, Charsets.UTF_8);
81 81 conn.createStatement().execute(dropAllTablesSql);
... ... @@ -92,13 +92,16 @@ public class CustomSqlUnit extends ExternalResource {
92 92 }
93 93 }
94 94
95   - private Properties loadProperties(String fileName) {
  95 + private void loadProperties(String fileName) {
96 96 final Properties properties = new Properties();
97 97 try (final InputStream stream = this.getClass().getClassLoader().getResourceAsStream(fileName)) {
98 98 properties.load(stream);
99   - return properties;
  99 + this.dbUrl = properties.getProperty("spring.datasource.url");
  100 + this.dbUserName = properties.getProperty("spring.datasource.username");
  101 + this.dbPassword = properties.getProperty("spring.datasource.password");
100 102 } catch (IOException e) {
101 103 throw new RuntimeException(e.getMessage(), e);
102 104 }
  105 +
103 106 }
104 107 }
... ...
... ... @@ -2,7 +2,9 @@ database.type=sql
2 2
3 3 spring.jpa.show-sql=false
4 4 spring.jpa.hibernate.ddl-auto=validate
  5 +spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
5 6
6 7 spring.datasource.username=sa
7 8 spring.datasource.password=
8   -spring.datasource.url=jdbc:hsqldb:mem:thingsboardTestDb;sql.enforce_size=false
  9 +spring.datasource.url=jdbc:hsqldb:mem:testDb;sql.enforce_size=false
  10 +spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver
\ No newline at end of file
... ...