Commit 63988199ab4bda963435132acee7f89d2a0bee77

Authored by mp-loki
1 parent bfd01188

Configured tests to run against postgresql. JpaDeviceCredentialsDao and JpaDeviceDao implemented

Showing 36 changed files with 590 additions and 183 deletions
... ... @@ -57,6 +57,10 @@
57 57 <artifactId>logback-classic</artifactId>
58 58 </dependency>
59 59 <dependency>
  60 + <groupId>org.postgresql</groupId>
  61 + <artifactId>postgresql</artifactId>
  62 + </dependency>
  63 + <dependency>
60 64 <groupId>org.springframework</groupId>
61 65 <artifactId>spring-test</artifactId>
62 66 </dependency>
... ...
... ... @@ -45,6 +45,7 @@ public class ModelConstants {
45 45 * Cassandra user constants.
46 46 */
47 47 public static final String USER_COLUMN_FAMILY_NAME = "user";
  48 + public static final String USER_PG_HIBERNATE_COLUMN_FAMILY_NAME = "tb_user";
48 49 public static final String USER_TENANT_ID_PROPERTY = TENANT_ID_PROPERTY;
49 50 public static final String USER_CUSTOMER_ID_PROPERTY = CUSTOMER_ID_PROPERTY;
50 51 public static final String USER_EMAIL_PROPERTY = "email";
... ...
... ... @@ -21,6 +21,8 @@ import javax.persistence.Entity;
21 21 import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
  24 +
  25 +import lombok.Data;
24 26 import org.thingsboard.server.common.data.id.DeviceCredentialsId;
25 27 import org.thingsboard.server.common.data.id.DeviceId;
26 28 import org.thingsboard.server.common.data.security.DeviceCredentials;
... ... @@ -30,7 +32,8 @@ import org.thingsboard.server.dao.model.ModelConstants;
30 32
31 33 import java.util.UUID;
32 34
33   -//@Entity
  35 +@Data
  36 +@Entity
34 37 @Table(name = ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME)
35 38 public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentials> {
36 39
... ... @@ -68,46 +71,6 @@ public final class DeviceCredentialsEntity implements BaseEntity<DeviceCredentia
68 71 this.credentialsValue = deviceCredentials.getCredentialsValue();
69 72 }
70 73
71   - public UUID getId() {
72   - return id;
73   - }
74   -
75   - public void setId(UUID id) {
76   - this.id = id;
77   - }
78   -
79   - public UUID getDeviceId() {
80   - return deviceId;
81   - }
82   -
83   - public void setDeviceId(UUID deviceId) {
84   - this.deviceId = deviceId;
85   - }
86   -
87   - public DeviceCredentialsType getCredentialsType() {
88   - return credentialsType;
89   - }
90   -
91   - public void setCredentialsType(DeviceCredentialsType credentialsType) {
92   - this.credentialsType = credentialsType;
93   - }
94   -
95   - public String getCredentialsId() {
96   - return credentialsId;
97   - }
98   -
99   - public void setCredentialsId(String credentialsId) {
100   - this.credentialsId = credentialsId;
101   - }
102   -
103   - public String getCredentialsValue() {
104   - return credentialsValue;
105   - }
106   -
107   - public void setCredentialsValue(String credentialsValue) {
108   - this.credentialsValue = credentialsValue;
109   - }
110   -
111 74 @Override
112 75 public int hashCode() {
113 76 final int prime = 31;
... ...
... ... @@ -22,6 +22,9 @@ import javax.persistence.Id;
22 22 import javax.persistence.Table;
23 23 import javax.persistence.Transient;
24 24 import com.fasterxml.jackson.databind.JsonNode;
  25 +import com.fasterxml.jackson.databind.ObjectMapper;
  26 +import lombok.Data;
  27 +import lombok.extern.slf4j.Slf4j;
25 28 import org.thingsboard.server.common.data.Device;
26 29 import org.thingsboard.server.common.data.id.CustomerId;
27 30 import org.thingsboard.server.common.data.id.DeviceId;
... ... @@ -29,9 +32,12 @@ import org.thingsboard.server.common.data.id.TenantId;
29 32 import org.thingsboard.server.dao.model.ModelConstants;
30 33 import org.thingsboard.server.dao.model.SearchTextEntity;
31 34
  35 +import java.io.IOException;
32 36 import java.util.UUID;
33 37
34   -//@Entity
  38 +@Data
  39 +@Slf4j
  40 +@Entity
35 41 @Table(name = ModelConstants.DEVICE_COLUMN_FAMILY_NAME)
36 42 public final class DeviceEntity implements SearchTextEntity<Device> {
37 43
... ... @@ -55,7 +61,7 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
55 61 private String searchText;
56 62
57 63 @Column(name = ModelConstants.DEVICE_ADDITIONAL_INFO_PROPERTY)
58   - private JsonNode additionalInfo;
  64 + private String additionalInfo;
59 65
60 66 public DeviceEntity() {
61 67 super();
... ... @@ -72,49 +78,11 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
72 78 this.customerId = device.getCustomerId().getId();
73 79 }
74 80 this.name = device.getName();
75   - this.additionalInfo = device.getAdditionalInfo();
76   - }
77   -
78   - public UUID getId() {
79   - return id;
80   - }
81   -
82   - public void setId(UUID id) {
83   - this.id = id;
84   - }
85   -
86   - public UUID getTenantId() {
87   - return tenantId;
88   - }
89   -
90   - public void setTenantId(UUID tenantId) {
91   - this.tenantId = tenantId;
92   - }
93   -
94   - public UUID getCustomerId() {
95   - return customerId;
96   - }
97   -
98   - public void setCustomerId(UUID customerId) {
99   - this.customerId = customerId;
100   - }
101   -
102   - public String getName() {
103   - return name;
104   - }
105   -
106   - public void setName(String name) {
107   - this.name = name;
108   - }
109   -
110   - public JsonNode getAdditionalInfo() {
111   - return additionalInfo;
  81 + if (additionalInfo != null) {
  82 + this.additionalInfo = device.getAdditionalInfo().toString();
  83 + }
112 84 }
113 85
114   - public void setAdditionalInfo(JsonNode additionalInfo) {
115   - this.additionalInfo = additionalInfo;
116   - }
117   -
118 86 @Override
119 87 public String getSearchTextSource() {
120 88 return name;
... ... @@ -206,8 +174,16 @@ public final class DeviceEntity implements SearchTextEntity<Device> {
206 174 device.setCustomerId(new CustomerId(customerId));
207 175 }
208 176 device.setName(name);
209   - device.setAdditionalInfo(additionalInfo);
  177 + if (additionalInfo != null) {
  178 + ObjectMapper mapper = new ObjectMapper();
  179 + JsonNode jsonNode = null;
  180 + try {
  181 + jsonNode = mapper.readTree(additionalInfo);
  182 + device.setAdditionalInfo(jsonNode);
  183 + } catch (IOException e) {
  184 + log.error(e.getMessage(), e);
  185 + }
  186 + }
210 187 return device;
211 188 }
212   -
213 189 }
\ No newline at end of file
... ...
... ... @@ -47,16 +47,16 @@ public class EventEntity implements BaseEntity<Event> {
47 47 private static final long serialVersionUID = -5717830061727466727L;
48 48
49 49 @Id
50   - @Column(name = ID_PROPERTY, columnDefinition = "BINARY(16)")
  50 + @Column(name = ID_PROPERTY)
51 51 private UUID id;
52 52
53   - @Column(name = EVENT_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  53 + @Column(name = EVENT_TENANT_ID_PROPERTY)
54 54 private UUID tenantId;
55 55
56 56 @Column(name = EVENT_ENTITY_TYPE_PROPERTY)
57 57 private EntityType entityType;
58 58
59   - @Column(name = EVENT_ENTITY_ID_PROPERTY, columnDefinition = "BINARY(16)")
  59 + @Column(name = EVENT_ENTITY_ID_PROPERTY)
60 60 private UUID entityId;
61 61
62 62 @Column(name = EVENT_TYPE_PROPERTY)
... ...
... ... @@ -44,13 +44,13 @@ public class PluginMetaDataEntity implements SearchTextEntity<PluginMetaData> {
44 44 @Transient
45 45 private static final long serialVersionUID = -6164321050824823149L;
46 46 @Id
47   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  47 + @Column(name = ModelConstants.ID_PROPERTY)
48 48 private UUID id;
49 49
50 50 @Column(name = ModelConstants.PLUGIN_API_TOKEN_PROPERTY)
51 51 private String apiToken;
52 52
53   - @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  53 + @Column(name = ModelConstants.PLUGIN_TENANT_ID_PROPERTY)
54 54 private UUID tenantId;
55 55
56 56 @Column(name = ModelConstants.PLUGIN_NAME_PROPERTY)
... ...
... ... @@ -48,9 +48,9 @@ public class RuleMetaDataEntity implements SearchTextEntity<RuleMetaData> {
48 48 @Transient
49 49 private static final long serialVersionUID = -1506905644259463884L;
50 50 @Id
51   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  51 + @Column(name = ModelConstants.ID_PROPERTY)
52 52 private UUID id;
53   - @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  53 + @Column(name = ModelConstants.RULE_TENANT_ID_PROPERTY)
54 54 private UUID tenantId;
55 55 @Column(name = ModelConstants.RULE_NAME_PROPERTY)
56 56 private String name;
... ...
... ... @@ -45,7 +45,7 @@ public final class TenantEntity implements SearchTextEntity<Tenant> {
45 45 private static final long serialVersionUID = -4330655990232136337L;
46 46
47 47 @Id
48   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  48 + @Column(name = ModelConstants.ID_PROPERTY)
49 49 private UUID id;
50 50
51 51 @Column(name = ModelConstants.TENANT_TITLE_PROPERTY)
... ...
... ... @@ -41,10 +41,10 @@ public final class UserCredentialsEntity implements BaseEntity<UserCredentials>
41 41 private static final long serialVersionUID = -3989724854149114846L;
42 42
43 43 @Id
44   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  44 + @Column(name = ModelConstants.ID_PROPERTY)
45 45 private UUID id;
46 46
47   - @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, columnDefinition = "BINARY(16)", unique = true)
  47 + @Column(name = ModelConstants.USER_CREDENTIALS_USER_ID_PROPERTY, unique = true)
48 48 private UUID userId;
49 49
50 50 @Column(name = ModelConstants.USER_CREDENTIALS_ENABLED_PROPERTY)
... ...
... ... @@ -38,19 +38,19 @@ import java.util.UUID;
38 38 @Slf4j
39 39 @Data
40 40 @Entity
41   -@Table(name = ModelConstants.USER_COLUMN_FAMILY_NAME)
  41 +@Table(name = ModelConstants.USER_PG_HIBERNATE_COLUMN_FAMILY_NAME)
42 42 public class UserEntity implements SearchTextEntity<User> {
43 43 @Transient
44 44 private static final long serialVersionUID = -271106508790582977L;
45 45
46 46 @Id
47   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  47 + @Column(name = ModelConstants.ID_PROPERTY)
48 48 private UUID id;
49 49
50   - @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  50 + @Column(name = ModelConstants.USER_TENANT_ID_PROPERTY)
51 51 private UUID tenantId;
52 52
53   - @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY, columnDefinition = "BINARY(16)")
  53 + @Column(name = ModelConstants.USER_CUSTOMER_ID_PROPERTY)
54 54 private UUID customerId;
55 55
56 56 @Column(name = ModelConstants.USER_AUTHORITY_PROPERTY)
... ...
... ... @@ -46,11 +46,11 @@ public final class WidgetTypeEntity implements BaseEntity<WidgetType> {
46 46 private static final long serialVersionUID = -5436279069884988630L;
47 47
48 48 @Id
49   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  49 + @Column(name = ModelConstants.ID_PROPERTY)
50 50 private UUID id;
51 51
52 52 @PartitionKey(value = 1)
53   - @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  53 + @Column(name = ModelConstants.WIDGET_TYPE_TENANT_ID_PROPERTY)
54 54 private UUID tenantId;
55 55
56 56 @PartitionKey(value = 2)
... ...
... ... @@ -42,10 +42,10 @@ public final class WidgetsBundleEntity implements SearchTextEntity<WidgetsBundle
42 42 private static final long serialVersionUID = 6897035686422298096L;
43 43
44 44 @Id
45   - @Column(name = ModelConstants.ID_PROPERTY, columnDefinition = "BINARY(16)")
  45 + @Column(name = ModelConstants.ID_PROPERTY)
46 46 private UUID id;
47 47
48   - @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY, columnDefinition = "BINARY(16)")
  48 + @Column(name = ModelConstants.WIDGETS_BUNDLE_TENANT_ID_PROPERTY)
49 49 private UUID tenantId;
50 50
51 51 @Column(name = ModelConstants.WIDGETS_BUNDLE_ALIAS_PROPERTY)
... ...
... ... @@ -21,6 +21,7 @@ import com.google.common.util.concurrent.ListeningExecutorService;
21 21 import com.google.common.util.concurrent.MoreExecutors;
22 22 import lombok.extern.slf4j.Slf4j;
23 23 import org.springframework.data.repository.CrudRepository;
  24 +import org.springframework.transaction.annotation.Transactional;
24 25 import org.thingsboard.server.dao.Dao;
25 26 import org.thingsboard.server.dao.DaoUtil;
26 27 import org.thingsboard.server.dao.model.BaseEntity;
... ... @@ -30,6 +31,8 @@ import java.util.List;
30 31 import java.util.UUID;
31 32 import java.util.concurrent.Executors;
32 33
  34 +import static org.springframework.transaction.annotation.Propagation.REQUIRES_NEW;
  35 +
33 36 /**
34 37 * @author Valerii Sosliuk
35 38 */
... ... @@ -47,6 +50,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao<
47 50 }
48 51
49 52 @Override
  53 + @Transactional(propagation = REQUIRES_NEW)
50 54 public D save(D domain) {
51 55 E entity;
52 56 try {
... ... @@ -80,6 +84,7 @@ public abstract class JpaAbstractDao<E extends BaseEntity<D>, D> implements Dao<
80 84 }
81 85
82 86 @Override
  87 + @Transactional(propagation = REQUIRES_NEW)
83 88 public boolean removeById(UUID key) {
84 89 getCrudRepository().delete(key);
85 90 log.debug("Remove request: {}", key);
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.repository.CrudRepository;
  5 +import org.springframework.stereotype.Component;
  6 +import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
  7 +
  8 +import java.util.UUID;
  9 +
  10 +/**
  11 + * Created by Valerii Sosliuk on 5/6/2017.
  12 + */
  13 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  14 +public interface DeviceCredentialsRepository extends CrudRepository<DeviceCredentialsEntity, UUID> {
  15 +
  16 + DeviceCredentialsEntity findByDeviceId(UUID deviceId);
  17 +
  18 + DeviceCredentialsEntity findByCredentialsId(String credentialsId);
  19 +}
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  4 +import org.springframework.data.jpa.repository.Query;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.scheduling.annotation.Async;
  7 +import org.springframework.util.concurrent.ListenableFuture;
  8 +import org.thingsboard.server.dao.model.sql.DeviceEntity;
  9 +
  10 +import java.util.List;
  11 +import java.util.UUID;
  12 +
  13 +/**
  14 + * Created by Valerii Sosliuk on 5/6/2017.
  15 + */
  16 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  17 +public interface DeviceRepository extends CrudRepository<DeviceEntity, UUID> {
  18 +
  19 + @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = ?2 " +
  20 + "AND CUSTOMER_ID = ?3 " +
  21 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  22 + "ORDER BY ID LIMIT ?1")
  23 + List<DeviceEntity> findByTenantIdAndCustomerIdFirstPage(int limit, UUID tenantId, UUID customerId, String searchText);
  24 +
  25 + @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = ?2 " +
  26 + "AND CUSTOMER_ID = ?3 " +
  27 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?4, '%')) " +
  28 + "AND ID > ?5 ORDER BY ID LIMIT ?1")
  29 + List<DeviceEntity> findByTenantIdAndCustomerIdNextPage(int limit, UUID tenantId, UUID customerId, String searchText, UUID idOffset);
  30 +
  31 + @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = ?2 " +
  32 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  33 + "ORDER BY ID LIMIT ?1")
  34 + List<DeviceEntity> findByTenantIdFirstPage(int limit, UUID tenantId, String textSearch);
  35 +
  36 + @Query(nativeQuery = true, value = "SELECT * FROM DEVICE WHERE TENANT_ID = ?2 " +
  37 + "AND LOWER(SEARCH_TEXT) LIKE LOWER(CONCAT(?3, '%')) " +
  38 + "AND ID > ?4 ORDER BY ID LIMIT ?1")
  39 + List<DeviceEntity> findByTenantIdNextPage(int limit, UUID tenantId, String textSearch, UUID idOffset);
  40 +
  41 + DeviceEntity findByTenantIdAndName(UUID tenantId, String name);
  42 +
  43 + List<DeviceEntity> findDevicesByTenantIdAndCustomerIdAndIdIn(UUID tenantId, UUID customerId, List<UUID> deviceIds);
  44 +
  45 + List<DeviceEntity> findDevicesByTenantId(UUID tenantId);
  46 + List<DeviceEntity> findDevicesByTenantIdAndIdIn(UUID tenantId, List<UUID> deviceIds);
  47 +}
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import org.springframework.beans.factory.annotation.Autowired;
  4 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  5 +import org.springframework.data.repository.CrudRepository;
  6 +import org.springframework.stereotype.Component;
  7 +import org.thingsboard.server.common.data.security.DeviceCredentials;
  8 +import org.thingsboard.server.dao.DaoUtil;
  9 +import org.thingsboard.server.dao.device.DeviceCredentialsDao;
  10 +import org.thingsboard.server.dao.model.ModelConstants;
  11 +import org.thingsboard.server.dao.model.sql.DeviceCredentialsEntity;
  12 +import org.thingsboard.server.dao.sql.JpaAbstractDao;
  13 +
  14 +import java.util.UUID;
  15 +
  16 +/**
  17 + * Created by Valerii Sosliuk on 5/6/2017.
  18 + */
  19 +@Component
  20 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  21 +public class JpaDeviceCredentialsDao extends JpaAbstractDao<DeviceCredentialsEntity, DeviceCredentials> implements DeviceCredentialsDao {
  22 +
  23 + @Autowired
  24 + private DeviceCredentialsRepository deviceCredentialsRepository;
  25 +
  26 + @Override
  27 + protected Class<DeviceCredentialsEntity> getEntityClass() {
  28 + return DeviceCredentialsEntity.class;
  29 + }
  30 +
  31 + @Override
  32 + protected String getColumnFamilyName() {
  33 + {
  34 + return ModelConstants.DEVICE_CREDENTIALS_COLUMN_FAMILY_NAME;
  35 + }
  36 + }
  37 +
  38 + @Override
  39 + protected CrudRepository<DeviceCredentialsEntity, UUID> getCrudRepository() {
  40 + return deviceCredentialsRepository;
  41 + }
  42 +
  43 + @Override
  44 + public DeviceCredentials findByDeviceId(UUID deviceId) {
  45 + return DaoUtil.getData(deviceCredentialsRepository.findByDeviceId(deviceId));
  46 + }
  47 +
  48 + @Override
  49 + public DeviceCredentials findByCredentialsId(String credentialsId) {
  50 + return DaoUtil.getData(deviceCredentialsRepository.findByCredentialsId(credentialsId));
  51 + }
  52 +}
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import com.google.common.util.concurrent.ListenableFuture;
  4 +import com.google.common.util.concurrent.ListeningExecutorService;
  5 +import com.google.common.util.concurrent.MoreExecutors;
  6 +import org.springframework.beans.factory.annotation.Autowired;
  7 +import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
  8 +import org.springframework.data.repository.CrudRepository;
  9 +import org.springframework.stereotype.Component;
  10 +import org.thingsboard.server.common.data.Device;
  11 +import org.thingsboard.server.common.data.page.TextPageLink;
  12 +import org.thingsboard.server.dao.DaoUtil;
  13 +import org.thingsboard.server.dao.device.DeviceDao;
  14 +import org.thingsboard.server.dao.model.sql.DeviceEntity;
  15 +import org.thingsboard.server.dao.sql.JpaAbstractSearchTextDao;
  16 +
  17 +import java.util.List;
  18 +import java.util.Optional;
  19 +import java.util.UUID;
  20 +import java.util.concurrent.Executors;
  21 +
  22 +import static org.thingsboard.server.dao.model.ModelConstants.DEVICE_COLUMN_FAMILY_NAME;
  23 +
  24 +/**
  25 + * Created by Valerii Sosliuk on 5/6/2017.
  26 + */
  27 +@Component
  28 +@ConditionalOnProperty(prefix = "sql", value = "enabled", havingValue = "true", matchIfMissing = false)
  29 +public class JpaDeviceDao extends JpaAbstractSearchTextDao<DeviceEntity, Device> implements DeviceDao {
  30 +
  31 + @Autowired
  32 + DeviceRepository deviceRepository;
  33 +
  34 + @Override
  35 + protected Class<DeviceEntity> getEntityClass() {
  36 + return DeviceEntity.class;
  37 + }
  38 +
  39 + @Override
  40 + protected String getColumnFamilyName() {
  41 + return DEVICE_COLUMN_FAMILY_NAME;
  42 + }
  43 +
  44 + @Override
  45 + protected CrudRepository<DeviceEntity, UUID> getCrudRepository() {
  46 + return deviceRepository;
  47 + }
  48 +
  49 + @Override
  50 + public List<Device> findDevicesByTenantId(UUID tenantId, TextPageLink pageLink) {
  51 + if (pageLink.getIdOffset() == null) {
  52 + return DaoUtil.convertDataList(deviceRepository.findByTenantIdFirstPage(
  53 + pageLink.getLimit(), tenantId, pageLink.getTextSearch()));
  54 + } else {
  55 + return DaoUtil.convertDataList(deviceRepository.findByTenantIdNextPage(
  56 + pageLink.getLimit(), tenantId, pageLink.getTextSearch(), pageLink.getIdOffset()));
  57 + }
  58 + }
  59 +
  60 + @Override
  61 + public ListenableFuture<List<Device>> findDevicesByTenantIdAndIdsAsync(UUID tenantId, List<UUID> deviceIds) {
  62 + System.out.println(deviceRepository.findDevicesByTenantIdAndIdIn(tenantId, deviceIds).size());
  63 + ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
  64 + return service.submit(() -> DaoUtil.convertDataList(deviceRepository.findDevicesByTenantIdAndIdIn(tenantId, deviceIds)));
  65 + }
  66 +
  67 + @Override
  68 + public List<Device> findDevicesByTenantIdAndCustomerId(UUID tenantId, UUID customerId, TextPageLink pageLink) {
  69 + if (pageLink.getIdOffset() == null) {
  70 + return DaoUtil.convertDataList(deviceRepository.findByTenantIdAndCustomerIdFirstPage(pageLink.getLimit(),
  71 + tenantId, customerId, pageLink.getTextSearch()));
  72 + } else {
  73 + return DaoUtil.convertDataList(deviceRepository.findByTenantIdAndCustomerIdNextPage(pageLink.getLimit(),
  74 + tenantId, customerId, pageLink.getTextSearch(), pageLink.getIdOffset()));
  75 + }
  76 + }
  77 +
  78 + @Override
  79 + public ListenableFuture<List<Device>> findDevicesByTenantIdCustomerIdAndIdsAsync(UUID tenantId, UUID customerId, List<UUID> deviceIds) {
  80 + ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
  81 + return service.submit(() -> DaoUtil.convertDataList(
  82 + deviceRepository.findDevicesByTenantIdAndCustomerIdAndIdIn(tenantId, customerId, deviceIds)));
  83 + }
  84 +
  85 + @Override
  86 + // Probably findDevice, not findDevices?
  87 + public Optional<Device> findDevicesByTenantIdAndName(UUID tenantId, String name) {
  88 + Device device = DaoUtil.getData(deviceRepository.findByTenantIdAndName(tenantId, name));
  89 + return Optional.ofNullable(device);
  90 + }
  91 +}
... ...
... ... @@ -31,22 +31,22 @@ public interface UserRepository extends CrudRepository<UserEntity, UUID> {
31 31
32 32 UserEntity findByEmail(String email);
33 33
34   - @Query(nativeQuery = true, value = "SELECT * FROM USER WHERE TENANT_ID = ?2 " +
  34 + @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
35 35 "AND CUSTOMER_ID IS NULL AND AUTHORITY = 1 " +
36 36 "ORDER BY ID LIMIT ?1")
37 37 List<UserEntity> findTenantAdminsFirstPage(int limit, UUID tenantId);
38 38
39   - @Query(nativeQuery = true, value = "SELECT * FROM USER WHERE TENANT_ID = ?2 " +
  39 + @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
40 40 "AND CUSTOMER_ID IS NULL AND AUTHORITY = 1 " +
41 41 "AND ID > ?3 ORDER BY ID LIMIT ?1")
42 42 List<UserEntity> findTenantAdminsNextPage(int limit, UUID tenantId, UUID idOffset);
43 43
44   - @Query(nativeQuery = true, value = "SELECT * FROM USER WHERE TENANT_ID = ?2 " +
  44 + @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
45 45 "AND CUSTOMER_ID = ?3 AND AUTHORITY = 2 " +
46 46 "ORDER BY ID LIMIT ?1")
47 47 List<UserEntity> findCustomerUsersFirstPage(int limit, UUID tenantId, UUID customerId);
48 48
49   - @Query(nativeQuery = true, value = "SELECT * FROM USER WHERE TENANT_ID = ?2 " +
  49 + @Query(nativeQuery = true, value = "SELECT * FROM TB_USER WHERE TENANT_ID = ?2 " +
50 50 "AND CUSTOMER_ID = ?3 AND AUTHORITY = 2 " +
51 51 "AND ID > ?4 ORDER BY ID LIMIT ?1")
52 52 List<UserEntity> findCustomerUsersNextPage(int limit, UUID tenantId, UUID customerId, UUID idOffset);
... ...
... ... @@ -16,6 +16,7 @@
16 16 package org.thingsboard.server.dao;
17 17
18 18 import com.github.springtestdbunit.DbUnitTestExecutionListener;
  19 +import com.github.springtestdbunit.annotation.DbUnitConfiguration;
19 20 import org.junit.runner.RunWith;
20 21 import org.springframework.test.context.ContextConfiguration;
21 22 import org.springframework.test.context.TestExecutionListeners;
... ... @@ -29,11 +30,12 @@ import org.springframework.test.context.support.DirtiesContextTestExecutionListe
29 30 * Created by Valerii Sosliuk on 4/22/2017.
30 31 */
31 32 @RunWith(SpringJUnit4ClassRunner.class)
32   -@ContextConfiguration(classes = {JpaDaoConfig.class})
  33 +@ContextConfiguration(classes = {JpaDaoConfig.class, JpaDbunitTestConfig.class})
33 34 @TestPropertySource("classpath:jpa-test.properties")
34 35 @TestExecutionListeners({ DependencyInjectionTestExecutionListener.class,
35 36 DirtiesContextTestExecutionListener.class,
36 37 DbUnitTestExecutionListener.class })
  38 +@DbUnitConfiguration(databaseConnection = "dbUnitDatabaseConnection")
37 39 public class AbstractJpaDaoTest extends AbstractTransactionalJUnit4SpringContextTests {
38 40
39 41 }
... ...
  1 +package org.thingsboard.server.dao;
  2 +
  3 +import com.github.springtestdbunit.bean.DatabaseConfigBean;
  4 +import com.github.springtestdbunit.bean.DatabaseDataSourceConnectionFactoryBean;
  5 +import org.dbunit.DatabaseUnitException;
  6 +import org.dbunit.ext.postgresql.PostgresqlDataTypeFactory;
  7 +import org.springframework.beans.factory.annotation.Autowired;
  8 +import org.springframework.context.annotation.Bean;
  9 +import org.springframework.context.annotation.Configuration;
  10 +
  11 +import javax.sql.DataSource;
  12 +import java.io.IOException;
  13 +import java.sql.SQLException;
  14 +
  15 +/**
  16 + * Created by Valerii Sosliuk on 5/6/2017.
  17 + */
  18 +@Configuration
  19 +public class JpaDbunitTestConfig {
  20 +
  21 + @Autowired
  22 + private DataSource dataSource;
  23 +
  24 + @Bean
  25 + public DatabaseConfigBean databaseConfigBean() {
  26 + DatabaseConfigBean databaseConfigBean = new DatabaseConfigBean();
  27 + databaseConfigBean.setDatatypeFactory(new PostgresqlDataTypeFactory());
  28 + return databaseConfigBean;
  29 + }
  30 +
  31 + @Bean(name = "dbUnitDatabaseConnection")
  32 + public DatabaseDataSourceConnectionFactoryBean dbUnitDatabaseConnection() throws SQLException, DatabaseUnitException, IOException {
  33 + DatabaseDataSourceConnectionFactoryBean databaseDataSourceConnectionFactoryBean = new DatabaseDataSourceConnectionFactoryBean();
  34 + databaseDataSourceConnectionFactoryBean.setDatabaseConfig(databaseConfigBean());
  35 + databaseDataSourceConnectionFactoryBean.setDataSource(dataSource);
  36 + databaseDataSourceConnectionFactoryBean.setSchema("public");
  37 + return databaseDataSourceConnectionFactoryBean;
  38 + }
  39 +}
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import com.github.springtestdbunit.annotation.DatabaseSetup;
  4 +import org.junit.Test;
  5 +import org.springframework.beans.factory.annotation.Autowired;
  6 +import org.thingsboard.server.common.data.security.DeviceCredentials;
  7 +import org.thingsboard.server.dao.AbstractJpaDaoTest;
  8 +import org.thingsboard.server.dao.device.DeviceCredentialsDao;
  9 +
  10 +import java.util.UUID;
  11 +
  12 +import static org.junit.Assert.assertEquals;
  13 +import static org.junit.Assert.assertNotNull;
  14 +
  15 +/**
  16 + * Created by Valerii Sosliuk on 5/6/2017.
  17 + */
  18 +public class JpaDeviceCredentialsDaoTest extends AbstractJpaDaoTest {
  19 +
  20 + @Autowired
  21 + DeviceCredentialsDao deviceCredentialsDao;
  22 +
  23 + @Test
  24 + @DatabaseSetup("classpath:dbunit/device_credentials.xml")
  25 + public void testFindByDeviceId() {
  26 + UUID deviceId = UUID.fromString("958e3a30-3215-11e7-93ae-92361f002671");
  27 + DeviceCredentials deviceCredentials = deviceCredentialsDao.findByDeviceId(deviceId);
  28 + assertNotNull(deviceCredentials);
  29 + assertEquals("958e3314-3215-11e7-93ae-92361f002671", deviceCredentials.getId().getId().toString());
  30 + assertEquals("ID_1", deviceCredentials.getCredentialsId());
  31 + }
  32 +
  33 + @Test
  34 + @DatabaseSetup("classpath:dbunit/device_credentials.xml")
  35 + public void findByCredentialsId() {
  36 + String credentialsId = "ID_2";
  37 + DeviceCredentials deviceCredentials = deviceCredentialsDao.findByCredentialsId(credentialsId);
  38 + assertNotNull(deviceCredentials);
  39 + assertEquals("958e3c74-3215-11e7-93ae-92361f002671", deviceCredentials.getId().getId().toString());
  40 + }
  41 +}
... ...
  1 +package org.thingsboard.server.dao.sql.device;
  2 +
  3 +import com.datastax.driver.core.utils.UUIDs;
  4 +import com.github.springtestdbunit.annotation.DatabaseOperation;
  5 +import com.github.springtestdbunit.annotation.DatabaseSetup;
  6 +import com.github.springtestdbunit.annotation.DatabaseTearDown;
  7 +import com.google.common.util.concurrent.*;
  8 +import org.junit.Test;
  9 +import org.springframework.beans.factory.annotation.Autowired;
  10 +import org.springframework.transaction.annotation.Transactional;
  11 +import org.thingsboard.server.common.data.Device;
  12 +import org.thingsboard.server.common.data.id.CustomerId;
  13 +import org.thingsboard.server.common.data.id.DeviceId;
  14 +import org.thingsboard.server.common.data.id.TenantId;
  15 +import org.thingsboard.server.common.data.page.TextPageLink;
  16 +import org.thingsboard.server.dao.AbstractJpaDaoTest;
  17 +import org.thingsboard.server.dao.device.DeviceDao;
  18 +
  19 +import java.util.ArrayList;
  20 +import java.util.Arrays;
  21 +import java.util.List;
  22 +import java.util.UUID;
  23 +import java.util.concurrent.ExecutionException;
  24 +import java.util.concurrent.Executors;
  25 +
  26 +import static org.junit.Assert.assertEquals;
  27 +import static org.junit.Assert.assertNotNull;
  28 +
  29 +/**
  30 + * Created by Valerii Sosliuk on 5/6/2017.
  31 + */
  32 +@Transactional
  33 +public class JpaDeviceDaoTest extends AbstractJpaDaoTest {
  34 +
  35 + @Autowired
  36 + private DeviceDao deviceDao;
  37 +
  38 + @Test
  39 + @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  40 + @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  41 + public void testFindDevicesByTenantId() {
  42 + UUID tenantId1 = UUIDs.timeBased();
  43 + UUID tenantId2 = UUIDs.timeBased();
  44 + UUID customerId1 = UUIDs.timeBased();
  45 + UUID customerId2 = UUIDs.timeBased();
  46 + createDevices(tenantId1, tenantId2, customerId1, customerId2, 40);
  47 +
  48 + TextPageLink pageLink1 = new TextPageLink(15, "SEARCH_TEXT");
  49 + List<Device> devices1 = deviceDao.findDevicesByTenantId(tenantId1, pageLink1);
  50 + assertEquals(15, devices1.size());
  51 +
  52 + TextPageLink pageLink2 = new TextPageLink(15, "SEARCH_TEXT", devices1.get(14).getId().getId(), null);
  53 + List<Device> devices2 = deviceDao.findDevicesByTenantId(tenantId1, pageLink2);
  54 + assertEquals(5, devices2.size());
  55 + }
  56 +
  57 + @Test
  58 + @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  59 + @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  60 + public void testFindAsync() throws ExecutionException, InterruptedException {
  61 + UUID tenantId = UUIDs.timeBased();
  62 + UUID customerId = UUIDs.timeBased();
  63 + Device device = getDevice(tenantId, customerId);
  64 + deviceDao.save(device);
  65 +
  66 + UUID uuid = device.getId().getId();
  67 + Device entity = deviceDao.findById(uuid);
  68 + assertNotNull(entity);
  69 + assertEquals(uuid, entity.getId().getId());
  70 +
  71 + ListeningExecutorService service = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(10));
  72 + ListenableFuture<Device> future = service.submit(() -> deviceDao.findById(uuid));
  73 + Device asyncDevice = future.get();
  74 + assertNotNull("Async device expected to be not null", asyncDevice);
  75 + }
  76 +
  77 + @Test
  78 + @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  79 + @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  80 + public void testFindDevicesByTenantIdAndIdsAsync() throws ExecutionException, InterruptedException {
  81 + UUID tenantId1 = UUIDs.timeBased();
  82 + UUID customerId1 = UUIDs.timeBased();
  83 + UUID tenantId2 = UUIDs.timeBased();
  84 + UUID customerId2 = UUIDs.timeBased();
  85 +
  86 + List<UUID> deviceIds = new ArrayList<>();
  87 +
  88 + for(int i = 0; i < 5; i++) {
  89 + UUID deviceId1 = UUIDs.timeBased();
  90 + UUID deviceId2 = UUIDs.timeBased();
  91 + deviceDao.save(getDevice(tenantId1, customerId1, deviceId1));
  92 + deviceDao.save(getDevice(tenantId2, customerId2, deviceId2));
  93 + deviceIds.add(deviceId1);
  94 + deviceIds.add(deviceId2);
  95 + }
  96 +
  97 + ListenableFuture<List<Device>> devicesFuture = deviceDao.findDevicesByTenantIdAndIdsAsync(tenantId1, deviceIds);
  98 + List<Device> devices = devicesFuture.get();
  99 + assertEquals(5, devices.size());
  100 + }
  101 +
  102 + @Test
  103 + @DatabaseSetup(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  104 + @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml",type = DatabaseOperation.DELETE_ALL)
  105 + public void testFindDevicesByTenantIdAndCustomerIdAndIdsAsync() throws ExecutionException, InterruptedException {
  106 + UUID tenantId1 = UUIDs.timeBased();
  107 + UUID customerId1 = UUIDs.timeBased();
  108 + UUID tenantId2 = UUIDs.timeBased();
  109 + UUID customerId2 = UUIDs.timeBased();
  110 +
  111 + List<UUID> deviceIds = new ArrayList<>();
  112 +
  113 + for(int i = 0; i < 20; i++) {
  114 + UUID deviceId1 = UUIDs.timeBased();
  115 + UUID deviceId2 = UUIDs.timeBased();
  116 + deviceDao.save(getDevice(tenantId1, customerId1, deviceId1));
  117 + deviceDao.save(getDevice(tenantId2, customerId2, deviceId2));
  118 + deviceIds.add(deviceId1);
  119 + deviceIds.add(deviceId2);
  120 + }
  121 +
  122 + ListenableFuture<List<Device>> devicesFuture = deviceDao.findDevicesByTenantIdCustomerIdAndIdsAsync(tenantId1, customerId1, deviceIds);
  123 + List<Device> devices = devicesFuture.get();
  124 + assertEquals(20, devices.size());
  125 + }
  126 +
  127 + private void createDevices(UUID tenantId1, UUID tenantId2, UUID customerId1, UUID customerId2, int count) {
  128 + for (int i = 0; i < count / 2; i++) {
  129 + deviceDao.save(getDevice(tenantId1, customerId1));
  130 + deviceDao.save(getDevice(tenantId2, customerId2));
  131 + }
  132 + }
  133 +
  134 + private Device getDevice(UUID tenantId, UUID customerID) {
  135 + return getDevice(tenantId, customerID, UUIDs.timeBased());
  136 + }
  137 +
  138 + private Device getDevice(UUID tenantId, UUID customerID, UUID deviceId) {
  139 + Device device = new Device();
  140 + device.setId(new DeviceId(deviceId));
  141 + device.setTenantId(new TenantId(tenantId));
  142 + device.setCustomerId(new CustomerId(customerID));
  143 + device.setName("SEARCH_TEXT");
  144 + return device;
  145 + }
  146 +}
... ...
1 1 package org.thingsboard.server.dao.sql.event;
2 2
3   -import ch.qos.logback.core.net.SyslogOutputStream;
4 3 import com.datastax.driver.core.utils.UUIDs;
5 4 import com.fasterxml.jackson.databind.JsonNode;
6 5 import com.fasterxml.jackson.databind.ObjectMapper;
... ... @@ -18,8 +17,6 @@ import org.thingsboard.server.dao.AbstractJpaDaoTest;
18 17 import org.thingsboard.server.dao.event.EventDao;
19 18
20 19 import java.io.IOException;
21   -import java.text.SimpleDateFormat;
22   -import java.util.Date;
23 20 import java.util.List;
24 21 import java.util.Optional;
25 22 import java.util.UUID;
... ...
... ... @@ -23,7 +23,6 @@ import org.thingsboard.server.common.data.id.PluginId;
23 23 import org.thingsboard.server.common.data.id.TenantId;
24 24 import org.thingsboard.server.common.data.page.TextPageLink;
25 25 import org.thingsboard.server.common.data.plugin.PluginMetaData;
26   -import org.thingsboard.server.common.data.rule.RuleMetaData;
27 26 import org.thingsboard.server.dao.AbstractJpaDaoTest;
28 27 import org.thingsboard.server.dao.plugin.PluginDao;
29 28
... ...
... ... @@ -71,7 +71,6 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
71 71 UUID tenantId = UUIDs.timeBased();
72 72 UUID customerId = UUIDs.timeBased();
73 73 create30Adminsand60Users(tenantId, customerId);
74   - assertEquals(90, userDao.find().size());
75 74 List<User> tenantAdmins1 = userDao.findTenantAdmins(tenantId, new TextPageLink(20));
76 75 assertEquals(20, tenantAdmins1.size());
77 76 List<User> tenantAdmins2 = userDao.findTenantAdmins(tenantId,
... ... @@ -88,7 +87,6 @@ public class JpaUserDaoTest extends AbstractJpaDaoTest {
88 87 UUID tenantId = UUIDs.timeBased();
89 88 UUID customerId = UUIDs.timeBased();
90 89 create30Adminsand60Users(tenantId, customerId);
91   - assertEquals(90, userDao.find().size());
92 90 List<User> customerUsers1 = userDao.findCustomerUsers(tenantId, customerId, new TextPageLink(40));
93 91 assertEquals(40, customerUsers1.size());
94 92 List<User> customerUsers2 = userDao.findCustomerUsers(tenantId, customerId,
... ...
... ... @@ -15,7 +15,6 @@
15 15 */
16 16 package org.thingsboard.server.dao.sql.widget;
17 17
18   -import com.datastax.driver.core.utils.UUIDs;
19 18 import com.github.springtestdbunit.annotation.DatabaseSetup;
20 19 import org.junit.Test;
21 20 import org.springframework.beans.factory.annotation.Autowired;
... ...
... ... @@ -16,7 +16,9 @@
16 16 package org.thingsboard.server.dao.sql.widget;
17 17
18 18 import com.datastax.driver.core.utils.UUIDs;
  19 +import com.github.springtestdbunit.annotation.DatabaseOperation;
19 20 import com.github.springtestdbunit.annotation.DatabaseSetup;
  21 +import com.github.springtestdbunit.annotation.DatabaseTearDown;
20 22 import org.junit.Ignore;
21 23 import org.junit.Test;
22 24 import org.springframework.beans.factory.annotation.Autowired;
... ... @@ -41,13 +43,15 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
41 43 private WidgetsBundleDao widgetsBundleDao;
42 44
43 45 @Test
44   - @DatabaseSetup("classpath:dbunit/widgets_bundle.xml")
  46 + @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml",type= DatabaseOperation.CLEAN_INSERT)
  47 + @DatabaseTearDown(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
45 48 public void testFindAll() {
46 49 assertEquals(7, widgetsBundleDao.find().size());
47 50 }
48 51
49 52 @Test
50   - @DatabaseSetup("classpath:dbunit/widgets_bundle.xml")
  53 + @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml",type= DatabaseOperation.CLEAN_INSERT)
  54 + @DatabaseTearDown(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
51 55 public void testFindWidgetsBundleByTenantIdAndAlias() {
52 56 WidgetsBundle widgetsBundle = widgetsBundleDao.findWidgetsBundleByTenantIdAndAlias(
53 57 UUID.fromString("250aca8e-2825-11e7-93ae-92361f002671"), "WB3");
... ... @@ -55,7 +59,8 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
55 59 }
56 60
57 61 @Test
58   - @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
  62 + @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
  63 + // @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type= DatabaseOperation.DELETE_ALL)
59 64 public void testFindSystemWidgetsBundles() {
60 65 createSystemWidgetBundles(30, "WB_");
61 66 assertEquals(30, widgetsBundleDao.find().size());
... ... @@ -70,7 +75,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
70 75 }
71 76
72 77 @Test
73   - @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
  78 + @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
74 79 public void testFindWidgetsBundlesByTenantId() {
75 80 UUID tenantId1 = UUIDs.timeBased();
76 81 UUID tenantId2 = UUIDs.timeBased();
... ... @@ -97,7 +102,7 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
97 102 }
98 103
99 104 @Test
100   - @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
  105 + @DatabaseSetup(value = "classpath:dbunit/widgets_bundle.xml", type= DatabaseOperation.DELETE_ALL)
101 106 public void testFindAllWidgetsBundlesByTenantId() {
102 107 UUID tenantId1 = UUIDs.timeBased();
103 108 UUID tenantId2 = UUIDs.timeBased();
... ... @@ -129,9 +134,9 @@ public class JpaWidgetsBundleDaoTest extends AbstractJpaDaoTest {
129 134 assertEquals(0, widgetsBundles4.size());
130 135 }
131 136
132   -
133 137 @Test
134 138 @DatabaseSetup("classpath:dbunit/empty_dataset.xml")
  139 + @DatabaseTearDown(value = "classpath:dbunit/empty_dataset.xml", type= DatabaseOperation.DELETE_ALL)
135 140 public void testNonSearchTextNotFound() {
136 141 UUID tenantId = UUIDs.timeBased();
137 142 createWidgetBundles(5, tenantId, "ABC_");
... ...
  1 +<dataset>
  2 + <device_credentials
  3 + id="958e3314-3215-11e7-93ae-92361f002671"
  4 + device_id="958e3a30-3215-11e7-93ae-92361f002671"
  5 + credentials_type="0"
  6 + credentials_id="ID_1"
  7 + credentials_value="ACCESS_TOKEN_1"
  8 + />
  9 + <device_credentials
  10 + id="958e3c74-3215-11e7-93ae-92361f002671"
  11 + device_id="958e3e5e-3215-11e7-93ae-92361f002671"
  12 + credentials_type="0"
  13 + credentials_id="ID_2"
  14 + credentials_value="ACCESS_TOKEN_2"
  15 + />
  16 +</dataset>
\ No newline at end of file
... ...
1 1 <dataset>
2 2 <event
3   - id="uuid'be41c7a2-31f5-11e7-9cfd-2786e6aa2046'"
4   - tenant_id="uuid'be41c7a0-31f5-11e7-9cfd-2786e6aa2046'"
5   - entity_id="uuid'be41c7a1-31f5-11e7-9cfd-2786e6aa2046'"
  3 + id="be41c7a2-31f5-11e7-9cfd-2786e6aa2046"
  4 + tenant_id="be41c7a0-31f5-11e7-9cfd-2786e6aa2046"
  5 + entity_id="be41c7a1-31f5-11e7-9cfd-2786e6aa2046"
6 6 entity_type="1"
7 7 event_type="STATS"
8 8 event_uid="be41c7a3-31f5-11e7-9cfd-2786e6aa2046"
9 9 />
10 10 <event
11   - id="uuid'be41c7a4-31f5-11e7-9cfd-2786e6aa2046'"
12   - tenant_id="uuid'be41c7a0-31f5-11e7-9cfd-2786e6aa2046'"
13   - entity_id="uuid'be41c7a1-31f5-11e7-9cfd-2786e6aa2046'"
  11 + id="be41c7a4-31f5-11e7-9cfd-2786e6aa2046"
  12 + tenant_id="be41c7a0-31f5-11e7-9cfd-2786e6aa2046"
  13 + entity_id="be41c7a1-31f5-11e7-9cfd-2786e6aa2046"
14 14 entity_type="1"
15 15 event_type="STATS"
16 16 event_uid="be41c7a5-31f5-11e7-9cfd-2786e6aa2046"
... ...
1 1 <dataset>
2 2 <rule
3   - id="uuid'8e834e11-2e0a-11e7-83ec-f7f6dbfb4833'"
4   - tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'"
  3 + id="8e834e11-2e0a-11e7-83ec-f7f6dbfb4833"
  4 + tenant_id="8e834e10-2e0a-11e7-83ec-f7f6dbfb4833"
5 5 name="RULE_11"
6 6 weight="1"
7 7 search_text="rule_11"
8 8 plugin_token="token_1"
9 9 />
10 10 <rule
11   - id="uuid'8e834e12-2e0a-11e7-83ec-f7f6dbfb4833'"
12   - tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'"
  11 + id="8e834e12-2e0a-11e7-83ec-f7f6dbfb4833"
  12 + tenant_id="8e834e10-2e0a-11e7-83ec-f7f6dbfb4833"
13 13 name="RULE_12"
14 14 weight="1"
15 15 search_text="rule_12"
16 16 plugin_token="token_1"
17 17 />
18 18 <rule
19   - id="uuid'8e834e13-2e0a-11e7-83ec-f7f6dbfb4833'"
20   - tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'"
  19 + id="8e834e13-2e0a-11e7-83ec-f7f6dbfb4833"
  20 + tenant_id="8e834e10-2e0a-11e7-83ec-f7f6dbfb4833"
21 21 name="RULE_13"
22 22 weight="1"
23 23 search_text="rule_13"
24 24 plugin_token="token_1"
25 25 />
26 26 <rule
27   - id="uuid'8e834e14-2e0a-11e7-83ec-f7f6dbfb4833'"
28   - tenant_id="uuid'8e834e10-2e0a-11e7-83ec-f7f6dbfb4833'"
  27 + id="8e834e14-2e0a-11e7-83ec-f7f6dbfb4833"
  28 + tenant_id="8e834e10-2e0a-11e7-83ec-f7f6dbfb4833"
29 29 name="RULE_14"
30 30 weight="2"
31 31 search_text="rule_14"
... ...
1 1 <dataset>
2 2 <user_credentials
3   - id="uuid'3ed10af0-27d5-11e7-93ae-92361f002671'"
4   - user_id="uuid'44ee8552-27d5-11e7-93ae-92361f002671'"
  3 + id="3ed10af0-27d5-11e7-93ae-92361f002671"
  4 + user_id="44ee8552-27d5-11e7-93ae-92361f002671"
5 5 enabled="true"
6 6 password="password"
7 7 activate_token="ACTIVATE_TOKEN_1"
8 8 reset_token="RESET_TOKEN_1"
9 9 />
10 10 <user_credentials
11   - id="uuid'4b9e010c-27d5-11e7-93ae-92361f002671'"
12   - user_id="uuid'787827e6-27d7-11e7-93ae-92361f002671'"
  11 + id="4b9e010c-27d5-11e7-93ae-92361f002671"
  12 + user_id="787827e6-27d7-11e7-93ae-92361f002671"
13 13 enabled="true"
14 14 password="password"
15 15 activate_token="ACTIVATE_TOKEN_2"
... ...
1 1 <dataset>
2   - <user id="uuid'9cb58ba0-27c1-11e7-93ae-92361f002671'"
3   - tenant_id="uuid'c97ea14e-27c1-11e7-93ae-92361f002671'"
4   - customer_id="uuid'cdf9c79e-27c1-11e7-93ae-92361f002671'"
  2 + <tb_user id="9cb58ba0-27c1-11e7-93ae-92361f002671"
  3 + tenant_id="c97ea14e-27c1-11e7-93ae-92361f002671"
  4 + customer_id="cdf9c79e-27c1-11e7-93ae-92361f002671"
5 5 authority="0"
6 6 email="sysadm@thingsboard.org"
7 7 search_text="SYSADM SEARCH TEXT"
... ... @@ -9,8 +9,8 @@
9 9 last_name="Doe"
10 10 additional_info="{&quot;key&quot;:&quot;value-0&quot;}"
11 11 />
12   - <user id="uuid'1312f328-27c7-11e7-93ae-92361f002671'"
13   - tenant_id="uuid'1e1cd4c8-27c7-11e7-93ae-92361f002671'"
  12 + <tb_user id="1312f328-27c7-11e7-93ae-92361f002671"
  13 + tenant_id="1e1cd4c8-27c7-11e7-93ae-92361f002671"
14 14 authority="1"
15 15 email="tenantadm1@thingsboard.org"
16 16 search_text="TENANTADM1 SEARCH TEXT"
... ... @@ -18,8 +18,8 @@
18 18 last_name="Serif"
19 19 additional_info="{&quot;key&quot;:&quot;value-11&quot;}"
20 20 />
21   - <user id="uuid'2b090dde-27ca-11e7-93ae-92361f002671'"
22   - tenant_id="uuid'1e1cd4c8-27c7-11e7-93ae-92361f002671'"
  21 + <tb_user id="2b090dde-27ca-11e7-93ae-92361f002671"
  22 + tenant_id="1e1cd4c8-27c7-11e7-93ae-92361f002671"
23 23 authority="1"
24 24 email="tenantadm2@thingsboard.org"
25 25 search_text="TENANTADM2 SEARCH TEXT"
... ... @@ -27,9 +27,9 @@
27 27 last_name="Morgan"
28 28 additional_info="{&quot;key&quot;:&quot;value-12&quot;}"
29 29 />
30   - <user id="uuid'cc8c1ca8-27c7-11e7-93ae-92361f002671'"
31   - tenant_id="uuid'd2e27caa-27c7-11e7-93ae-92361f002671'"
32   - customer_id="uuid'd89e128a-27c7-11e7-93ae-92361f002671'"
  30 + <tb_user id="cc8c1ca8-27c7-11e7-93ae-92361f002671"
  31 + tenant_id="d2e27caa-27c7-11e7-93ae-92361f002671"
  32 + customer_id="d89e128a-27c7-11e7-93ae-92361f002671"
33 33 authority="2"
34 34 email="customeruser@thingsboard.org"
35 35 search_text="CUSTOMER USER SEARCH TEXT"
... ... @@ -37,9 +37,9 @@
37 37 last_name="Gordon"
38 38 additional_info="{&quot;key&quot;:&quot;value-2&quot;}"
39 39 />
40   - <user id="uuid'edb2de58-27c7-11e7-93ae-92361f002671'"
41   - tenant_id="uuid'f229675e-27c7-11e7-93ae-92361f002671'"
42   - customer_id="uuid'f7a3d4e4-27c7-11e7-93ae-92361f002671'"
  40 + <tb_user id="edb2de58-27c7-11e7-93ae-92361f002671"
  41 + tenant_id="f229675e-27c7-11e7-93ae-92361f002671"
  42 + customer_id="f7a3d4e4-27c7-11e7-93ae-92361f002671"
43 43 authority="3"
44 44 email="refreshtoken@thingsboard.org"
45 45 search_text="REFRESH TOKEN SEARCH TEXT"
... ...
1 1 <dataset>
2 2 <widget_type
3   - id="uuid'2b7e4c91-2dfe-11e7-94aa-f7f6dbfb4833'"
4   - tenant_id="uuid'2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833'"
  3 + id="2b7e4c91-2dfe-11e7-94aa-f7f6dbfb4833"
  4 + tenant_id="2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"
5 5 bundle_alias="BUNDLE_ALIAS_1"
6 6 alias="ALIAS1"
7 7 name="ALIAS1"
8 8 />
9 9 <widget_type
10   - id="uuid'2b7e4c92-2dfe-11e7-94aa-f7f6dbfb4833'"
11   - tenant_id="uuid'2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833'"
  10 + id="2b7e4c92-2dfe-11e7-94aa-f7f6dbfb4833"
  11 + tenant_id="2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"
12 12 bundle_alias="BUNDLE_ALIAS_1"
13 13 alias="ALIAS2"
14 14 name="ALIAS2"
15 15 />
16 16 <widget_type
17   - id="uuid'2b7e4c93-2dfe-11e7-94aa-f7f6dbfb4833'"
18   - tenant_id="uuid'2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833'"
  17 + id="2b7e4c93-2dfe-11e7-94aa-f7f6dbfb4833"
  18 + tenant_id="2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"
19 19 bundle_alias="BUNDLE_ALIAS_1"
20 20 alias="ALIAS3"
21 21 name="ALIAS3"
22 22 />
23 23 <widget_type
24   - id="uuid'2b7e4c94-2dfe-11e7-94aa-f7f6dbfb4833'"
25   - tenant_id="uuid'2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833'"
  24 + id="2b7e4c94-2dfe-11e7-94aa-f7f6dbfb4833"
  25 + tenant_id="2b7e4c90-2dfe-11e7-94aa-f7f6dbfb4833"
26 26 bundle_alias="BUNDLE_ALIAS_2"
27 27 alias="ALIAS4"
28 28 name="ALIAS4"
... ...
1 1 <dataset>
2 2 <widgets_bundle
3   - id="uuid'250ac7b4-2825-11e7-93ae-92361f002671'"
4   - tenant_id="uuid'250aca8e-2825-11e7-93ae-92361f002671'"
  3 + id="250ac7b4-2825-11e7-93ae-92361f002671"
  4 + tenant_id="250aca8e-2825-11e7-93ae-92361f002671"
5 5 alias="WB1"
6 6 title="Widgets Bundle 1"
7 7 search_text="WB SEARCH TEXT 1"
8 8 />
9 9 <widgets_bundle
10   - id="uuid'3269c18a-2825-11e7-93ae-92361f002671'"
11   - tenant_id="uuid'3269c18a-2825-11e7-93ae-92361f002671'"
  10 + id="3269c18a-2825-11e7-93ae-92361f002671"
  11 + tenant_id="3269c18a-2825-11e7-93ae-92361f002671"
12 12 alias="WB2"
13 13 title="Widgets Bundle 2"
14 14 search_text="WB SEARCH TEXT 2"
15 15 />
16 16 <widgets_bundle
17   - id="uuid'44e6af4e-2825-11e7-93ae-92361f002671'"
18   - tenant_id="uuid'250aca8e-2825-11e7-93ae-92361f002671'"
  17 + id="44e6af4e-2825-11e7-93ae-92361f002671"
  18 + tenant_id="250aca8e-2825-11e7-93ae-92361f002671"
19 19 alias="WB3"
20 20 title="Widgets Bundle 3"
21 21 search_text="WB SEARCH TEXT 3"
22 22 />
23 23 <widgets_bundle
24   - id="uuid'696dc9b4-2830-11e7-93ae-92361f002671'"
  24 + id="696dc9b4-2830-11e7-93ae-92361f002671"
25 25 alias="WB4"
26 26 title="Widgets Bundle 4"
27 27 search_text="SYSTEM BUNDLE 1"
28 28 />
29 29 <widgets_bundle
30   - id="uuid'1a83fc50-2840-11e7-93ae-92361f002671'"
  30 + id="1a83fc50-2840-11e7-93ae-92361f002671"
31 31 alias="WB5"
32 32 title="Widgets Bundle 5"
33 33 search_text="SYSTEM BUNDLE 2"
34 34 />
35 35 <widgets_bundle
36   - id="uuid'6a593dde-2841-11e7-93ae-92361f002671'"
  36 + id="6a593dde-2841-11e7-93ae-92361f002671"
37 37 alias="WB6"
38 38 title="Widgets Bundle 6"
39 39 search_text="SYSTEM BUNDLE 1"
40 40 />
41 41 <widgets_bundle
42   - id="uuid'3beb4b1a-294d-11e7-93ae-92361f002671'"
  42 + id="3beb4b1a-294d-11e7-93ae-92361f002671"
43 43 alias="WB6"
44 44 title="Widgets Bundle 7"
45 45 search_text="ABC DEF"
46 46 />
47   - <!--
48   - <widgets_bundle
49   - id=""
50   - tenant_id=""
51   - alias=""
52   - title=""
53   - search_text=""
54   - />
55   - -->
56 47 </dataset>
\ No newline at end of file
... ...
1 1 cassandra.enabled=false
2 2
3 3 sql.enabled=true
4   -sql.datasource.url=jdbc:h2:mem:thingsboard
5   -sql.datasource.username=sa
6   -sql.datasource.password=
  4 +#sql.datasource.url=jdbc:h2:mem:thingsboard
  5 +#sql.datasource.username=sa
  6 +#sql.datasource.password=
  7 +#spring.jpa.hibernate.ddl-auto=create-drop
7 8
  9 +spring.jpa.show-sql=false
  10 +spring.jpa.hibernate.ddl-auto=create-drop
  11 +
  12 +spring.database.driverClassName=org.postgresql.Driver
  13 +spring.jpa.database-platform=org.hibernate.dialect.PostgreSQLDialect
  14 +spring.datasource.url=jdbc:postgresql://localhost:5432/thingsboard-test
  15 +spring.datasource.username=thingsboard
  16 +spring.datasource.password=thingsboard
  17 +spring.jpa.generate-ddl=true
... ...
... ... @@ -74,6 +74,7 @@
74 74 <h2.version>1.4.194</h2.version>
75 75 <dbunit.version>2.5.3</dbunit.version>
76 76 <spring-test-dbunit.version>1.2.1</spring-test-dbunit.version>
  77 + <postgresql.driver.version>9.4.1211</postgresql.driver.version>
77 78 </properties>
78 79
79 80 <modules>
... ... @@ -420,6 +421,11 @@
420 421 <version>${spring-boot.version}</version>
421 422 </dependency>
422 423 <dependency>
  424 + <groupId>org.postgresql</groupId>
  425 + <artifactId>postgresql</artifactId>
  426 + <version>${postgresql.driver.version}</version>
  427 + </dependency>
  428 + <dependency>
423 429 <groupId>org.springframework</groupId>
424 430 <artifactId>spring-context</artifactId>
425 431 <version>${spring.version}</version>
... ...