Showing
22 changed files
with
104 additions
and
89 deletions
@@ -249,11 +249,6 @@ | @@ -249,11 +249,6 @@ | ||
249 | <artifactId>spring-test-dbunit</artifactId> | 249 | <artifactId>spring-test-dbunit</artifactId> |
250 | <scope>test</scope> | 250 | <scope>test</scope> |
251 | </dependency> | 251 | </dependency> |
252 | - <dependency> | ||
253 | - <groupId>ru.yandex.qatools.embed</groupId> | ||
254 | - <artifactId>postgresql-embedded</artifactId> | ||
255 | - <scope>test</scope> | ||
256 | - </dependency> | ||
257 | </dependencies> | 252 | </dependencies> |
258 | 253 | ||
259 | <build> | 254 | <build> |
@@ -106,7 +106,7 @@ coap: | @@ -106,7 +106,7 @@ coap: | ||
106 | timeout: "${COAP_TIMEOUT:10000}" | 106 | timeout: "${COAP_TIMEOUT:10000}" |
107 | 107 | ||
108 | database: | 108 | database: |
109 | - type: "${DATABASE_TYPE:cassandra}" # cassandra OR postgres | 109 | + type: "${DATABASE_TYPE:cassandra}" # cassandra OR sql |
110 | 110 | ||
111 | # Cassandra driver configuration parameters | 111 | # Cassandra driver configuration parameters |
112 | cassandra: | 112 | cassandra: |
@@ -18,7 +18,7 @@ package org.thingsboard.server.system; | @@ -18,7 +18,7 @@ package org.thingsboard.server.system; | ||
18 | import org.junit.ClassRule; | 18 | import org.junit.ClassRule; |
19 | import org.junit.extensions.cpsuite.ClasspathSuite; | 19 | import org.junit.extensions.cpsuite.ClasspathSuite; |
20 | import org.junit.runner.RunWith; | 20 | import org.junit.runner.RunWith; |
21 | -import org.thingsboard.server.dao.CustomPostgresUnit; | 21 | +import org.thingsboard.server.dao.CustomSqlUnit; |
22 | 22 | ||
23 | import java.util.Arrays; | 23 | import java.util.Arrays; |
24 | 24 | ||
@@ -30,9 +30,10 @@ import java.util.Arrays; | @@ -30,9 +30,10 @@ import java.util.Arrays; | ||
30 | public class SystemSqlTestSuite { | 30 | public class SystemSqlTestSuite { |
31 | 31 | ||
32 | @ClassRule | 32 | @ClassRule |
33 | - public static CustomPostgresUnit postgresUnit = new CustomPostgresUnit( | ||
34 | - Arrays.asList("postgres/schema.sql", "postgres/system-data.sql"), | ||
35 | - "postgres-embedded-test.properties"); | 33 | + public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
34 | + Arrays.asList("sql/schema.sql", "sql/system-data.sql"), | ||
35 | + "sql-test.properties", | ||
36 | + "sql/drop-all-tables.sql"); | ||
36 | 37 | ||
37 | 38 | ||
38 | } | 39 | } |
@@ -170,8 +170,8 @@ | @@ -170,8 +170,8 @@ | ||
170 | <scope>test</scope> | 170 | <scope>test</scope> |
171 | </dependency> | 171 | </dependency> |
172 | <dependency> | 172 | <dependency> |
173 | - <groupId>ru.yandex.qatools.embed</groupId> | ||
174 | - <artifactId>postgresql-embedded</artifactId> | 173 | + <groupId>org.hsqldb</groupId> |
174 | + <artifactId>hsqldb</artifactId> | ||
175 | <scope>test</scope> | 175 | <scope>test</scope> |
176 | </dependency> | 176 | </dependency> |
177 | </dependencies> | 177 | </dependencies> |
@@ -45,7 +45,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -45,7 +45,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
45 | protected void setSearchText(E entity) {} | 45 | protected void setSearchText(E entity) {} |
46 | 46 | ||
47 | @Override | 47 | @Override |
48 | - @Transactional(propagation = REQUIRES_NEW) | 48 | + @Transactional |
49 | public D save(D domain) { | 49 | public D save(D domain) { |
50 | E entity; | 50 | E entity; |
51 | try { | 51 | try { |
@@ -64,7 +64,6 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -64,7 +64,6 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
64 | } | 64 | } |
65 | 65 | ||
66 | @Override | 66 | @Override |
67 | - @Transactional(propagation = REQUIRES_NEW) | ||
68 | public D findById(UUID key) { | 67 | public D findById(UUID key) { |
69 | log.debug("Get entity by key {}", key); | 68 | log.debug("Get entity by key {}", key); |
70 | E entity = getCrudRepository().findOne(key); | 69 | E entity = getCrudRepository().findOne(key); |
@@ -78,7 +77,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | @@ -78,7 +77,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> | ||
78 | } | 77 | } |
79 | 78 | ||
80 | @Override | 79 | @Override |
81 | - @Transactional(propagation = REQUIRES_NEW) | 80 | + @Transactional |
82 | public boolean removeById(UUID key) { | 81 | public boolean removeById(UUID key) { |
83 | getCrudRepository().delete(key); | 82 | getCrudRepository().delete(key); |
84 | log.debug("Remove request: {}", key); | 83 | log.debug("Remove request: {}", key); |
@@ -73,7 +73,6 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | @@ -73,7 +73,6 @@ public class JpaAlarmDao extends JpaAbstractDao<AlarmEntity, Alarm> implements A | ||
73 | } | 73 | } |
74 | 74 | ||
75 | @Override | 75 | @Override |
76 | - @Transactional(propagation = REQUIRES_NEW) | ||
77 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { | 76 | public ListenableFuture<Alarm> findLatestByOriginatorAndType(TenantId tenantId, EntityId originator, String type) { |
78 | return service.submit(() -> { | 77 | return service.submit(() -> { |
79 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( | 78 | List<AlarmEntity> latest = alarmRepository.findLatestByOriginatorAndType( |
@@ -80,7 +80,5 @@ public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> { | @@ -80,7 +80,5 @@ public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> { | ||
80 | 80 | ||
81 | List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); | 81 | List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds); |
82 | 82 | ||
83 | - List<DeviceEntity> findDevicesByTenantId(UUID tenantId); | ||
84 | - | ||
85 | List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds); | 83 | List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds); |
86 | } | 84 | } |
@@ -30,12 +30,12 @@ import org.thingsboard.server.common.data.page.TimePageLink; | @@ -30,12 +30,12 @@ import org.thingsboard.server.common.data.page.TimePageLink; | ||
30 | import org.thingsboard.server.common.data.relation.EntityRelation; | 30 | import org.thingsboard.server.common.data.relation.EntityRelation; |
31 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; | 31 | import org.thingsboard.server.common.data.relation.RelationTypeGroup; |
32 | import org.thingsboard.server.dao.DaoUtil; | 32 | import org.thingsboard.server.dao.DaoUtil; |
33 | -import org.thingsboard.server.dao.util.SqlDao; | ||
34 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | 33 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
35 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 34 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
36 | import org.thingsboard.server.dao.relation.RelationDao; | 35 | import org.thingsboard.server.dao.relation.RelationDao; |
37 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; | 36 | import org.thingsboard.server.dao.sql.JpaAbstractDaoListeningExecutorService; |
38 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; | 37 | import org.thingsboard.server.dao.sql.JpaAbstractSearchTimeDao; |
38 | +import org.thingsboard.server.dao.util.SqlDao; | ||
39 | 39 | ||
40 | import javax.persistence.criteria.CriteriaBuilder; | 40 | import javax.persistence.criteria.CriteriaBuilder; |
41 | import javax.persistence.criteria.CriteriaQuery; | 41 | import javax.persistence.criteria.CriteriaQuery; |
@@ -17,11 +17,11 @@ package org.thingsboard.server.dao.sql.relation; | @@ -17,11 +17,11 @@ package org.thingsboard.server.dao.sql.relation; | ||
17 | 17 | ||
18 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; | 18 | import org.springframework.data.jpa.repository.JpaSpecificationExecutor; |
19 | import org.springframework.data.repository.CrudRepository; | 19 | import org.springframework.data.repository.CrudRepository; |
20 | -import org.thingsboard.server.dao.util.SqlDao; | 20 | +import org.springframework.transaction.annotation.Transactional; |
21 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; | 21 | import org.thingsboard.server.dao.model.sql.RelationCompositeKey; |
22 | import org.thingsboard.server.dao.model.sql.RelationEntity; | 22 | import org.thingsboard.server.dao.model.sql.RelationEntity; |
23 | +import org.thingsboard.server.dao.util.SqlDao; | ||
23 | 24 | ||
24 | -import javax.transaction.Transactional; | ||
25 | import java.util.List; | 25 | import java.util.List; |
26 | import java.util.UUID; | 26 | import java.util.UUID; |
27 | 27 | ||
@@ -51,5 +51,5 @@ public interface RelationRepository | @@ -51,5 +51,5 @@ public interface RelationRepository | ||
51 | String fromType); | 51 | String fromType); |
52 | 52 | ||
53 | @Transactional | 53 | @Transactional |
54 | - List<RelationEntity> deleteByFromIdAndFromType(UUID fromId, String fromType); | 54 | + void deleteByFromIdAndFromType(UUID fromId, String fromType); |
55 | } | 55 | } |
@@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; | @@ -17,6 +17,6 @@ package org.thingsboard.server.dao.util; | ||
17 | 17 | ||
18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; | 18 | import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty; |
19 | 19 | ||
20 | -@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "postgres") | 20 | +@ConditionalOnProperty(prefix = "database", value = "type", havingValue = "sql") |
21 | public @interface SqlDao { | 21 | public @interface SqlDao { |
22 | } | 22 | } |
dao/src/main/resources/sql/demo-data.sql
renamed from
dao/src/main/resources/postgres/demo-data.sql
dao/src/main/resources/sql/schema.sql
renamed from
dao/src/main/resources/postgres/schema.sql
@@ -17,7 +17,7 @@ | @@ -17,7 +17,7 @@ | ||
17 | 17 | ||
18 | CREATE TABLE IF NOT EXISTS admin_settings ( | 18 | CREATE TABLE IF NOT EXISTS admin_settings ( |
19 | id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY, | 19 | id uuid NOT NULL CONSTRAINT admin_settings_pkey PRIMARY KEY, |
20 | - json_value text, | 20 | + json_value varchar, |
21 | key character varying(255) | 21 | key character varying(255) |
22 | ); | 22 | ); |
23 | 23 | ||
@@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS alarm ( | @@ -25,7 +25,7 @@ CREATE TABLE IF NOT EXISTS alarm ( | ||
25 | id uuid NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY, | 25 | id uuid NOT NULL CONSTRAINT alarm_pkey PRIMARY KEY, |
26 | ack_ts bigint, | 26 | ack_ts bigint, |
27 | clear_ts bigint, | 27 | clear_ts bigint, |
28 | - additional_info text, | 28 | + additional_info varchar, |
29 | end_ts bigint, | 29 | end_ts bigint, |
30 | originator_id uuid, | 30 | originator_id uuid, |
31 | originator_type integer, | 31 | originator_type integer, |
@@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS alarm ( | @@ -39,7 +39,7 @@ CREATE TABLE IF NOT EXISTS alarm ( | ||
39 | 39 | ||
40 | CREATE TABLE IF NOT EXISTS asset ( | 40 | CREATE TABLE IF NOT EXISTS asset ( |
41 | id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, | 41 | id uuid NOT NULL CONSTRAINT asset_pkey PRIMARY KEY, |
42 | - additional_info text, | 42 | + additional_info varchar, |
43 | customer_id uuid, | 43 | customer_id uuid, |
44 | name character varying(255), | 44 | name character varying(255), |
45 | search_text character varying(255), | 45 | search_text character varying(255), |
@@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( | @@ -64,7 +64,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( | ||
64 | id uuid NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY, | 64 | id uuid NOT NULL CONSTRAINT component_descriptor_pkey PRIMARY KEY, |
65 | actions character varying(255), | 65 | actions character varying(255), |
66 | clazz character varying(255), | 66 | clazz character varying(255), |
67 | - configuration_descriptor text, | 67 | + configuration_descriptor varchar, |
68 | name character varying(255), | 68 | name character varying(255), |
69 | scope character varying(255), | 69 | scope character varying(255), |
70 | search_text character varying(255), | 70 | search_text character varying(255), |
@@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( | @@ -73,7 +73,7 @@ CREATE TABLE IF NOT EXISTS component_descriptor ( | ||
73 | 73 | ||
74 | CREATE TABLE IF NOT EXISTS customer ( | 74 | CREATE TABLE IF NOT EXISTS customer ( |
75 | id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY, | 75 | id uuid NOT NULL CONSTRAINT customer_pkey PRIMARY KEY, |
76 | - additional_info text, | 76 | + additional_info varchar, |
77 | address character varying(255), | 77 | address character varying(255), |
78 | address2 character varying(255), | 78 | address2 character varying(255), |
79 | city character varying(255), | 79 | city character varying(255), |
@@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS customer ( | @@ -89,7 +89,7 @@ CREATE TABLE IF NOT EXISTS customer ( | ||
89 | 89 | ||
90 | CREATE TABLE IF NOT EXISTS dashboard ( | 90 | CREATE TABLE IF NOT EXISTS dashboard ( |
91 | id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, | 91 | id uuid NOT NULL CONSTRAINT dashboard_pkey PRIMARY KEY, |
92 | - configuration text, | 92 | + configuration varchar, |
93 | customer_id uuid, | 93 | customer_id uuid, |
94 | search_text character varying(255), | 94 | search_text character varying(255), |
95 | tenant_id uuid, | 95 | tenant_id uuid, |
@@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS dashboard ( | @@ -98,7 +98,7 @@ CREATE TABLE IF NOT EXISTS dashboard ( | ||
98 | 98 | ||
99 | CREATE TABLE IF NOT EXISTS device ( | 99 | CREATE TABLE IF NOT EXISTS device ( |
100 | id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY, | 100 | id uuid NOT NULL CONSTRAINT device_pkey PRIMARY KEY, |
101 | - additional_info text, | 101 | + additional_info varchar, |
102 | customer_id uuid, | 102 | customer_id uuid, |
103 | type character varying(255), | 103 | type character varying(255), |
104 | name character varying(255), | 104 | name character varying(255), |
@@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS device_credentials ( | @@ -116,7 +116,7 @@ CREATE TABLE IF NOT EXISTS device_credentials ( | ||
116 | 116 | ||
117 | CREATE TABLE IF NOT EXISTS event ( | 117 | CREATE TABLE IF NOT EXISTS event ( |
118 | id uuid NOT NULL CONSTRAINT event_pkey PRIMARY KEY, | 118 | id uuid NOT NULL CONSTRAINT event_pkey PRIMARY KEY, |
119 | - body text, | 119 | + body varchar, |
120 | entity_id uuid, | 120 | entity_id uuid, |
121 | entity_type character varying(255), | 121 | entity_type character varying(255), |
122 | event_type character varying(255), | 122 | event_type character varying(255), |
@@ -127,10 +127,10 @@ CREATE TABLE IF NOT EXISTS event ( | @@ -127,10 +127,10 @@ CREATE TABLE IF NOT EXISTS event ( | ||
127 | 127 | ||
128 | CREATE TABLE IF NOT EXISTS plugin ( | 128 | CREATE TABLE IF NOT EXISTS plugin ( |
129 | id uuid NOT NULL CONSTRAINT plugin_pkey PRIMARY KEY, | 129 | id uuid NOT NULL CONSTRAINT plugin_pkey PRIMARY KEY, |
130 | - additional_info text, | 130 | + additional_info varchar, |
131 | api_token character varying(255), | 131 | api_token character varying(255), |
132 | plugin_class character varying(255), | 132 | plugin_class character varying(255), |
133 | - configuration text, | 133 | + configuration varchar, |
134 | name character varying(255), | 134 | name character varying(255), |
135 | public_access boolean, | 135 | public_access boolean, |
136 | search_text character varying(255), | 136 | search_text character varying(255), |
@@ -145,18 +145,18 @@ CREATE TABLE IF NOT EXISTS relation ( | @@ -145,18 +145,18 @@ CREATE TABLE IF NOT EXISTS relation ( | ||
145 | to_type character varying(255), | 145 | to_type character varying(255), |
146 | relation_type_group character varying(255), | 146 | relation_type_group character varying(255), |
147 | relation_type character varying(255), | 147 | relation_type character varying(255), |
148 | - additional_info text, | 148 | + additional_info varchar, |
149 | CONSTRAINT relation_unq_key UNIQUE (from_id, from_type, relation_type_group, relation_type, to_id, to_type) | 149 | CONSTRAINT relation_unq_key UNIQUE (from_id, from_type, relation_type_group, relation_type, to_id, to_type) |
150 | ); | 150 | ); |
151 | 151 | ||
152 | CREATE TABLE IF NOT EXISTS rule ( | 152 | CREATE TABLE IF NOT EXISTS rule ( |
153 | id uuid NOT NULL CONSTRAINT rule_pkey PRIMARY KEY, | 153 | id uuid NOT NULL CONSTRAINT rule_pkey PRIMARY KEY, |
154 | - action text, | ||
155 | - additional_info text, | ||
156 | - filters text, | 154 | + action varchar, |
155 | + additional_info varchar, | ||
156 | + filters varchar, | ||
157 | name character varying(255), | 157 | name character varying(255), |
158 | plugin_token character varying(255), | 158 | plugin_token character varying(255), |
159 | - processor text, | 159 | + processor varchar, |
160 | search_text character varying(255), | 160 | search_text character varying(255), |
161 | state character varying(255), | 161 | state character varying(255), |
162 | tenant_id uuid, | 162 | tenant_id uuid, |
@@ -165,7 +165,7 @@ CREATE TABLE IF NOT EXISTS rule ( | @@ -165,7 +165,7 @@ CREATE TABLE IF NOT EXISTS rule ( | ||
165 | 165 | ||
166 | CREATE TABLE IF NOT EXISTS tb_user ( | 166 | CREATE TABLE IF NOT EXISTS tb_user ( |
167 | id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, | 167 | id uuid NOT NULL CONSTRAINT tb_user_pkey PRIMARY KEY, |
168 | - additional_info text, | 168 | + additional_info varchar, |
169 | authority character varying(255), | 169 | authority character varying(255), |
170 | customer_id uuid, | 170 | customer_id uuid, |
171 | email character varying(255) UNIQUE, | 171 | email character varying(255) UNIQUE, |
@@ -177,7 +177,7 @@ CREATE TABLE IF NOT EXISTS tb_user ( | @@ -177,7 +177,7 @@ CREATE TABLE IF NOT EXISTS tb_user ( | ||
177 | 177 | ||
178 | CREATE TABLE IF NOT EXISTS tenant ( | 178 | CREATE TABLE IF NOT EXISTS tenant ( |
179 | id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY, | 179 | id uuid NOT NULL CONSTRAINT tenant_pkey PRIMARY KEY, |
180 | - additional_info text, | 180 | + additional_info varchar, |
181 | address character varying(255), | 181 | address character varying(255), |
182 | address2 character varying(255), | 182 | address2 character varying(255), |
183 | city character varying(255), | 183 | city character varying(255), |
@@ -228,7 +228,7 @@ CREATE TABLE IF NOT EXISTS widget_type ( | @@ -228,7 +228,7 @@ CREATE TABLE IF NOT EXISTS widget_type ( | ||
228 | id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY, | 228 | id uuid NOT NULL CONSTRAINT widget_type_pkey PRIMARY KEY, |
229 | alias character varying(255), | 229 | alias character varying(255), |
230 | bundle_alias character varying(255), | 230 | bundle_alias character varying(255), |
231 | - descriptor text, | 231 | + descriptor varchar(2000000), |
232 | name character varying(255), | 232 | name character varying(255), |
233 | tenant_id uuid | 233 | tenant_id uuid |
234 | ); | 234 | ); |
@@ -236,7 +236,6 @@ CREATE TABLE IF NOT EXISTS widget_type ( | @@ -236,7 +236,6 @@ CREATE TABLE IF NOT EXISTS widget_type ( | ||
236 | CREATE TABLE IF NOT EXISTS widgets_bundle ( | 236 | CREATE TABLE IF NOT EXISTS widgets_bundle ( |
237 | id uuid NOT NULL CONSTRAINT widgets_bundle_pkey PRIMARY KEY, | 237 | id uuid NOT NULL CONSTRAINT widgets_bundle_pkey PRIMARY KEY, |
238 | alias character varying(255), | 238 | alias character varying(255), |
239 | - image bytea, | ||
240 | search_text character varying(255), | 239 | search_text character varying(255), |
241 | tenant_id uuid, | 240 | tenant_id uuid, |
242 | title character varying(255) | 241 | title character varying(255) |
dao/src/main/resources/sql/system-data.sql
renamed from
dao/src/main/resources/postgres/system-data.sql
dao/src/test/java/org/thingsboard/server/dao/CustomSqlUnit.java
renamed from
dao/src/test/java/org/thingsboard/server/dao/CustomPostgresUnit.java
@@ -19,7 +19,6 @@ import com.google.common.base.Charsets; | @@ -19,7 +19,6 @@ import com.google.common.base.Charsets; | ||
19 | import com.google.common.io.Resources; | 19 | import com.google.common.io.Resources; |
20 | import lombok.extern.slf4j.Slf4j; | 20 | import lombok.extern.slf4j.Slf4j; |
21 | import org.junit.rules.ExternalResource; | 21 | import org.junit.rules.ExternalResource; |
22 | -import ru.yandex.qatools.embed.postgresql.EmbeddedPostgres; | ||
23 | 22 | ||
24 | import java.io.IOException; | 23 | import java.io.IOException; |
25 | import java.io.InputStream; | 24 | import java.io.InputStream; |
@@ -30,58 +29,58 @@ import java.sql.SQLException; | @@ -30,58 +29,58 @@ import java.sql.SQLException; | ||
30 | import java.util.List; | 29 | import java.util.List; |
31 | import java.util.Properties; | 30 | import java.util.Properties; |
32 | 31 | ||
33 | -import static ru.yandex.qatools.embed.postgresql.distribution.Version.Main.V9_6; | ||
34 | 32 | ||
35 | /** | 33 | /** |
36 | * Created by Valerii Sosliuk on 6/24/2017. | 34 | * Created by Valerii Sosliuk on 6/24/2017. |
37 | */ | 35 | */ |
38 | @Slf4j | 36 | @Slf4j |
39 | -public class CustomPostgresUnit extends ExternalResource { | ||
40 | - | ||
41 | - private static final String HOST = "host"; | ||
42 | - private static final String PORT = "port"; | ||
43 | - private static final String DATABASE = "database"; | ||
44 | - private static final String USERNAME = "username"; | ||
45 | - private static final String PASSWORD = "password"; | 37 | +public class CustomSqlUnit extends ExternalResource { |
46 | 38 | ||
47 | private List<String> sqlFiles; | 39 | private List<String> sqlFiles; |
48 | private Properties properties; | 40 | private Properties properties; |
41 | + private String dropAllTablesSqlFile; | ||
49 | 42 | ||
50 | - private EmbeddedPostgres postgres; | ||
51 | - | ||
52 | - public CustomPostgresUnit(List<String> sqlFiles, String configurationFileName) { | 43 | + public CustomSqlUnit(List<String> sqlFiles, String configurationFileName, String dropAllTablesSqlFile) { |
53 | this.sqlFiles = sqlFiles; | 44 | this.sqlFiles = sqlFiles; |
54 | this.properties = loadProperties(configurationFileName); | 45 | this.properties = loadProperties(configurationFileName); |
46 | + this.dropAllTablesSqlFile = dropAllTablesSqlFile; | ||
55 | } | 47 | } |
56 | 48 | ||
57 | @Override | 49 | @Override |
58 | public void before() { | 50 | public void before() { |
59 | - postgres = new EmbeddedPostgres(V9_6); | ||
60 | - load(); | ||
61 | - } | ||
62 | - | ||
63 | - @Override | ||
64 | - public void after() { | ||
65 | - postgres.stop(); | ||
66 | - } | ||
67 | - | ||
68 | - private void load() { | ||
69 | Connection conn = null; | 51 | Connection conn = null; |
70 | try { | 52 | try { |
71 | - String url = postgres.start(properties.getProperty(HOST), | ||
72 | - Integer.parseInt(properties.getProperty(PORT)), | ||
73 | - properties.getProperty(DATABASE), | ||
74 | - properties.getProperty(USERNAME), | ||
75 | - properties.getProperty(PASSWORD)); | ||
76 | - | ||
77 | - conn = DriverManager.getConnection(url); | 53 | + String url = properties.getProperty("spring.datasource.url"); |
54 | + conn = DriverManager.getConnection(url, "sa", ""); | ||
78 | for (String sqlFile : sqlFiles) { | 55 | for (String sqlFile : sqlFiles) { |
79 | URL sqlFileUrl = Resources.getResource(sqlFile); | 56 | URL sqlFileUrl = Resources.getResource(sqlFile); |
80 | String sql = Resources.toString(sqlFileUrl, Charsets.UTF_8); | 57 | String sql = Resources.toString(sqlFileUrl, Charsets.UTF_8); |
81 | conn.createStatement().execute(sql); | 58 | conn.createStatement().execute(sql); |
82 | } | 59 | } |
83 | } catch (IOException | SQLException e) { | 60 | } catch (IOException | SQLException e) { |
84 | - throw new RuntimeException("Unable to start embedded postgres. Reason: " + e.getMessage(), e); | 61 | + throw new RuntimeException("Unable to start embedded hsqldb. Reason: " + e.getMessage(), e); |
62 | + } finally { | ||
63 | + if (conn != null) { | ||
64 | + try { | ||
65 | + conn.close(); | ||
66 | + } catch (SQLException e) { | ||
67 | + log.error(e.getMessage(), e); | ||
68 | + } | ||
69 | + } | ||
70 | + } | ||
71 | + } | ||
72 | + | ||
73 | + @Override | ||
74 | + public void after() { | ||
75 | + Connection conn = null; | ||
76 | + try { | ||
77 | + String url = properties.getProperty("spring.datasource.url"); | ||
78 | + conn = DriverManager.getConnection(url, "sa", ""); | ||
79 | + URL dropAllTableSqlFileUrl = Resources.getResource(dropAllTablesSqlFile); | ||
80 | + String dropAllTablesSql = Resources.toString(dropAllTableSqlFileUrl, Charsets.UTF_8); | ||
81 | + conn.createStatement().execute(dropAllTablesSql); | ||
82 | + } catch (IOException | SQLException e) { | ||
83 | + throw new RuntimeException("Unable to clean up embedded hsqldb. Reason: " + e.getMessage(), e); | ||
85 | } finally { | 84 | } finally { |
86 | if (conn != null) { | 85 | if (conn != null) { |
87 | try { | 86 | try { |
@@ -24,13 +24,14 @@ import java.util.Arrays; | @@ -24,13 +24,14 @@ import java.util.Arrays; | ||
24 | 24 | ||
25 | @RunWith(ClasspathSuite.class) | 25 | @RunWith(ClasspathSuite.class) |
26 | @ClassnameFilters({ | 26 | @ClassnameFilters({ |
27 | - "org.thingsboard.server.dao.sql.*Test" | 27 | + "org.thingsboard.server.dao.sql.*ABTest" |
28 | }) | 28 | }) |
29 | public class JpaDaoTestSuite { | 29 | public class JpaDaoTestSuite { |
30 | 30 | ||
31 | @ClassRule | 31 | @ClassRule |
32 | - public static CustomPostgresUnit postgresUnit = new CustomPostgresUnit( | ||
33 | - Arrays.asList("postgres/schema.sql", "postgres/system-data.sql"), | ||
34 | - "postgres-embedded-test.properties"); | 32 | + public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
33 | + Arrays.asList("sql/schema.sql", "sql/system-data.sql"), | ||
34 | + "sql-test.properties", | ||
35 | + "sql/drop-all-tables.sql"); | ||
35 | 36 | ||
36 | } | 37 | } |
@@ -18,6 +18,7 @@ package org.thingsboard.server.dao; | @@ -18,6 +18,7 @@ package org.thingsboard.server.dao; | ||
18 | import com.github.springtestdbunit.bean.DatabaseConfigBean; | 18 | import com.github.springtestdbunit.bean.DatabaseConfigBean; |
19 | import com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean; | 19 | import com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean; |
20 | import org.dbunit.DatabaseUnitException; | 20 | import org.dbunit.DatabaseUnitException; |
21 | +import org.dbunit.ext.hsqldb.HsqldbDataTypeFactory; | ||
21 | import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; | 22 | import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory; |
22 | import org.springframework.beans.factory.annotation.Autowired; | 23 | import org.springframework.beans.factory.annotation.Autowired; |
23 | import org.springframework.context.annotation.Bean; | 24 | import org.springframework.context.annotation.Bean; |
@@ -41,7 +42,7 @@ public class JpaDbunitTestConfig { | @@ -41,7 +42,7 @@ public class JpaDbunitTestConfig { | ||
41 | @Bean | 42 | @Bean |
42 | public DatabaseConfigBean databaseConfigBean() { | 43 | public DatabaseConfigBean databaseConfigBean() { |
43 | DatabaseConfigBean databaseConfigBean = new DatabaseConfigBean(); | 44 | DatabaseConfigBean databaseConfigBean = new DatabaseConfigBean(); |
44 | - databaseConfigBean.setDatatypeFactory(new PostgresqlDataTypeFactory()); | 45 | + databaseConfigBean.setDatatypeFactory(new HsqldbDataTypeFactory()); |
45 | return databaseConfigBean; | 46 | return databaseConfigBean; |
46 | } | 47 | } |
47 | 48 |
@@ -29,8 +29,9 @@ import java.util.Arrays; | @@ -29,8 +29,9 @@ import java.util.Arrays; | ||
29 | public class SqlDaoServiceTestSuite { | 29 | public class SqlDaoServiceTestSuite { |
30 | 30 | ||
31 | @ClassRule | 31 | @ClassRule |
32 | - public static CustomPostgresUnit postgresUnit = new CustomPostgresUnit( | ||
33 | - Arrays.asList("postgres/schema.sql", "postgres/system-data.sql", "postgres/system-test.sql"), | ||
34 | - "postgres-embedded-test.properties"); | 32 | + public static CustomSqlUnit sqlUnit = new CustomSqlUnit( |
33 | + Arrays.asList("sql/schema.sql", "sql/system-data.sql", "sql/system-test.sql"), | ||
34 | + "sql-test.properties", | ||
35 | + "sql/drop-all-tables.sql"); | ||
35 | 36 | ||
36 | } | 37 | } |
dao/src/test/resources/postgres-embedded-test.properties
deleted
100644 → 0
1 | -database.type=postgres | 1 | +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 | 5 | ||
6 | -spring.datasource.url=jdbc:postgresql://localhost:5433/thingsboard-test | ||
7 | -spring.datasource.username=postgres | ||
8 | -spring.datasource.password=postgres | 6 | +spring.datasource.username=sa |
7 | +spring.datasource.password= | ||
8 | +spring.datasource.url=jdbc:hsqldb:mem:thingsboardTestDb;sql.enforce_size=false |
1 | +TRUNCATE TABLE admin_settings; | ||
2 | +TRUNCATE TABLE alarm; | ||
3 | +TRUNCATE TABLE asset; | ||
4 | +TRUNCATE TABLE attribute_kv; | ||
5 | +TRUNCATE TABLE component_descriptor; | ||
6 | +TRUNCATE TABLE customer; | ||
7 | +TRUNCATE TABLE dashboard; | ||
8 | +TRUNCATE TABLE device; | ||
9 | +TRUNCATE TABLE device_credentials; | ||
10 | +TRUNCATE TABLE event; | ||
11 | +TRUNCATE TABLE plugin; | ||
12 | +TRUNCATE TABLE relation; | ||
13 | +TRUNCATE TABLE rule; | ||
14 | +TRUNCATE TABLE tb_user; | ||
15 | +TRUNCATE TABLE tenant; | ||
16 | +TRUNCATE TABLE ts_kv; | ||
17 | +TRUNCATE TABLE ts_kv_latest; | ||
18 | +TRUNCATE TABLE user_credentials; | ||
19 | +TRUNCATE TABLE widget_type; | ||
20 | +TRUNCATE TABLE widgets_bundle; |
dao/src/test/resources/sql/system-test.sql
renamed from
dao/src/test/resources/postgres/system-test.sql
@@ -71,6 +71,7 @@ | @@ -71,6 +71,7 @@ | ||
71 | <springfox-swagger.version>2.6.1</springfox-swagger.version> | 71 | <springfox-swagger.version>2.6.1</springfox-swagger.version> |
72 | <bouncycastle.version>1.56</bouncycastle.version> | 72 | <bouncycastle.version>1.56</bouncycastle.version> |
73 | <winsw.version>2.0.1</winsw.version> | 73 | <winsw.version>2.0.1</winsw.version> |
74 | + <hsqldb.version>2.4.0</hsqldb.version> | ||
74 | <dbunit.version>2.5.3</dbunit.version> | 75 | <dbunit.version>2.5.3</dbunit.version> |
75 | <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version> | 76 | <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version> |
76 | <postgresql.driver.version>9.4.1211</postgresql.driver.version> | 77 | <postgresql.driver.version>9.4.1211</postgresql.driver.version> |
@@ -747,6 +748,12 @@ | @@ -747,6 +748,12 @@ | ||
747 | <version>${bouncycastle.version}</version> | 748 | <version>${bouncycastle.version}</version> |
748 | </dependency> | 749 | </dependency> |
749 | <dependency> | 750 | <dependency> |
751 | + <groupId>org.hsqldb</groupId> | ||
752 | + <artifactId>hsqldb</artifactId> | ||
753 | + <version>${hsqldb.version}</version> | ||
754 | + <scope>test</scope> | ||
755 | + </dependency> | ||
756 | + <dependency> | ||
750 | <groupId>ru.yandex.qatools.embed</groupId> | 757 | <groupId>ru.yandex.qatools.embed</groupId> |
751 | <artifactId>postgresql-embedded</artifactId> | 758 | <artifactId>postgresql-embedded</artifactId> |
752 | <version>2.2</version> | 759 | <version>2.2</version> |