Commit ea5f4d78f0ba7ba793a1e8a75ab67f86beba07e1

Authored by Volodymyr Babak
1 parent 2b8a8fb8

Fixed device api sql test

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