Browse Source

Fixed device api sql test

pull/197/head
Volodymyr Babak 9 years ago
parent
commit
ea5f4d78f0
  1. 1
      application/src/main/resources/thingsboard.yml
  2. 2
      application/src/test/java/org/thingsboard/server/system/sql/DeviceApiSqlTest.java
  3. 19
      dao/src/test/java/org/thingsboard/server/dao/CustomSqlUnit.java
  4. 4
      dao/src/test/resources/sql-test.properties

1
application/src/main/resources/thingsboard.yml

@ -235,7 +235,6 @@ spring:
enabled: "true" enabled: "true"
jpa: jpa:
show-sql: "false" show-sql: "false"
generate-ddl: "true"
database-platform: "org.hibernate.dialect.PostgreSQLDialect" database-platform: "org.hibernate.dialect.PostgreSQLDialect"
hibernate: hibernate:
ddl-auto: "validate" ddl-auto: "validate"

2
application/src/test/java/org/thingsboard/server/system/sql/DeviceApiSqlTest.java

@ -22,5 +22,5 @@ import org.thingsboard.server.system.BaseHttpDeviceApiTest;
* Created by Valerii Sosliuk on 6/27/2017. * Created by Valerii Sosliuk on 6/27/2017.
*/ */
@DaoSqlTest @DaoSqlTest
public class DeviceApiSqlTest extends BaseHttpDeviceApiTest{ public class DeviceApiSqlTest extends BaseHttpDeviceApiTest {
} }

19
dao/src/test/java/org/thingsboard/server/dao/CustomSqlUnit.java

@ -37,21 +37,22 @@ import java.util.Properties;
public class CustomSqlUnit extends ExternalResource { public class CustomSqlUnit extends ExternalResource {
private List<String> sqlFiles; private List<String> sqlFiles;
private Properties properties;
private String dropAllTablesSqlFile; private String dropAllTablesSqlFile;
private String dbUrl;
private String dbUserName;
private String dbPassword;
public CustomSqlUnit(List<String> sqlFiles, String configurationFileName, String dropAllTablesSqlFile) { public CustomSqlUnit(List<String> sqlFiles, String configurationFileName, String dropAllTablesSqlFile) {
this.sqlFiles = sqlFiles; this.sqlFiles = sqlFiles;
this.properties = loadProperties(configurationFileName);
this.dropAllTablesSqlFile = dropAllTablesSqlFile; this.dropAllTablesSqlFile = dropAllTablesSqlFile;
loadProperties(configurationFileName);
} }
@Override @Override
public void before() { public void before() {
Connection conn = null; Connection conn = null;
try { try {
String url = properties.getProperty("spring.datasource.url"); conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
conn = DriverManager.getConnection(url, "sa", "");
for (String sqlFile : sqlFiles) { for (String sqlFile : sqlFiles) {
URL sqlFileUrl = Resources.getResource(sqlFile); URL sqlFileUrl = Resources.getResource(sqlFile);
String sql = Resources.toString(sqlFileUrl, Charsets.UTF_8); String sql = Resources.toString(sqlFileUrl, Charsets.UTF_8);
@ -74,8 +75,7 @@ public class CustomSqlUnit extends ExternalResource {
public void after() { public void after() {
Connection conn = null; Connection conn = null;
try { try {
String url = properties.getProperty("spring.datasource.url"); conn = DriverManager.getConnection(dbUrl, dbUserName, dbPassword);
conn = DriverManager.getConnection(url, "sa", "");
URL dropAllTableSqlFileUrl = Resources.getResource(dropAllTablesSqlFile); URL dropAllTableSqlFileUrl = Resources.getResource(dropAllTablesSqlFile);
String dropAllTablesSql = Resources.toString(dropAllTableSqlFileUrl, Charsets.UTF_8); String dropAllTablesSql = Resources.toString(dropAllTableSqlFileUrl, Charsets.UTF_8);
conn.createStatement().execute(dropAllTablesSql); conn.createStatement().execute(dropAllTablesSql);
@ -92,13 +92,16 @@ public class CustomSqlUnit extends ExternalResource {
} }
} }
private Properties loadProperties(String fileName) { private void loadProperties(String fileName) {
final Properties properties = new Properties(); final Properties properties = new Properties();
try (final InputStream stream = this.getClass().getClassLoader().getResourceAsStream(fileName)) { try (final InputStream stream = this.getClass().getClassLoader().getResourceAsStream(fileName)) {
properties.load(stream); properties.load(stream);
return properties; this.dbUrl = properties.getProperty("spring.datasource.url");
this.dbUserName = properties.getProperty("spring.datasource.username");
this.dbPassword = properties.getProperty("spring.datasource.password");
} catch (IOException e) { } catch (IOException e) {
throw new RuntimeException(e.getMessage(), e); throw new RuntimeException(e.getMessage(), e);
} }
} }
} }

4
dao/src/test/resources/sql-test.properties

@ -2,7 +2,9 @@ database.type=sql
spring.jpa.show-sql=false spring.jpa.show-sql=false
spring.jpa.hibernate.ddl-auto=validate spring.jpa.hibernate.ddl-auto=validate
spring.jpa.database-platform=org.hibernate.dialect.HSQLDialect
spring.datasource.username=sa spring.datasource.username=sa
spring.datasource.password= spring.datasource.password=
spring.datasource.url=jdbc:hsqldb:mem:thingsboardTestDb;sql.enforce_size=false spring.datasource.url=jdbc:hsqldb:mem:testDb;sql.enforce_size=false
spring.datasource.driverClassName=org.hsqldb.jdbc.JDBCDriver
Loading…
Cancel
Save