Browse Source

Merge remote-tracking branch 'ce/develop/3.5' into fix/logNode-isStandardForTBEL

pull/7833/head
Sergey Matvienko 4 years ago
parent
commit
175492d6a7
  1. 2
      application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java
  2. 13
      application/src/test/java/org/thingsboard/server/service/resource/sql/BaseTbResourceServiceTest.java
  3. 4
      application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java
  4. 6
      application/src/test/java/org/thingsboard/server/transport/lwm2m/client/LwM2MTestClient.java
  5. 7
      application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/attributes/AbstractMqttV5ClientSparkplugAttributesTest.java
  6. 4
      application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/rpc/AbstractMqttV5RpcSparkplugTest.java
  7. 7
      application/src/test/resources/logback-test.xml
  8. 6
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2mTransportService.java
  9. 4
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java
  10. 30
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/downlink/DefaultLwM2mDownlinkMsgHandler.java
  11. 1
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/DefaultLwM2MOtaUpdateService.java
  12. 48
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2mUplinkMsgHandler.java
  13. 6
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/LwM2mUplinkMsgHandler.java
  14. 16
      common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2MTransportUtil.java
  15. 21
      dao/src/main/java/org/thingsboard/server/dao/entity/DefaultEntityServiceRegistry.java
  16. 122
      dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java
  17. 5
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAdminSettingsServiceTest.java
  18. 22
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAlarmCommentServiceTest.java
  19. 44
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAlarmServiceTest.java
  20. 23
      dao/src/test/java/org/thingsboard/server/dao/service/BaseApiUsageStateServiceTest.java
  21. 26
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetProfileServiceTest.java
  22. 42
      dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java
  23. 25
      dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java
  24. 53
      dao/src/test/java/org/thingsboard/server/dao/service/BaseDashboardServiceTest.java
  25. 26
      dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceCredentialsServiceTest.java
  26. 32
      dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceProfileServiceTest.java
  27. 52
      dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceServiceTest.java
  28. 9
      dao/src/test/java/org/thingsboard/server/dao/service/BaseEdgeEventServiceTest.java
  29. 45
      dao/src/test/java/org/thingsboard/server/dao/service/BaseEdgeServiceTest.java
  30. 2
      dao/src/test/java/org/thingsboard/server/dao/service/BaseEntityServiceRegistryTest.java
  31. 43
      dao/src/test/java/org/thingsboard/server/dao/service/BaseEntityServiceTest.java
  32. 157
      dao/src/test/java/org/thingsboard/server/dao/service/BaseOtaPackageServiceTest.java
  33. 10
      dao/src/test/java/org/thingsboard/server/dao/service/BaseQueueServiceTest.java
  34. 5
      dao/src/test/java/org/thingsboard/server/dao/service/BaseRelationServiceTest.java
  35. 34
      dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java
  36. 14
      dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java
  37. 78
      dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java
  38. 57
      dao/src/test/java/org/thingsboard/server/dao/service/BaseUserServiceTest.java
  39. 27
      dao/src/test/java/org/thingsboard/server/dao/service/BaseWidgetTypeServiceTest.java
  40. 44
      dao/src/test/java/org/thingsboard/server/dao/service/BaseWidgetsBundleServiceTest.java
  41. 6
      dao/src/test/java/org/thingsboard/server/dao/service/event/BaseEventServiceTest.java
  42. 10
      dao/src/test/java/org/thingsboard/server/dao/service/timeseries/BaseTimeseriesServiceTest.java

2
application/src/test/java/org/thingsboard/server/edge/BaseDeviceEdgeTest.java

@ -690,7 +690,7 @@ abstract public class BaseDeviceEdgeTest extends AbstractEdgeTest {
edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build()); edgeImitator.sendUplinkMsg(uplinkMsgBuilder.build());
Assert.assertTrue(edgeImitator.waitForResponses()); Assert.assertTrue(edgeImitator.waitForResponses());
Assert.assertTrue(onUpdateCallback.getSubscribeLatch().await(5, TimeUnit.SECONDS)); Assert.assertTrue(onUpdateCallback.getSubscribeLatch().await(30, TimeUnit.SECONDS));
Assert.assertEquals(JacksonUtil.OBJECT_MAPPER.createObjectNode().put(attrKey, attrValue), Assert.assertEquals(JacksonUtil.OBJECT_MAPPER.createObjectNode().put(attrKey, attrValue),
JacksonUtil.fromBytes(onUpdateCallback.getPayloadBytes())); JacksonUtil.fromBytes(onUpdateCallback.getPayloadBytes()));

13
application/src/test/java/org/thingsboard/server/service/resource/sql/BaseTbResourceServiceTest.java

@ -19,10 +19,8 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.rules.ExpectedException;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityInfo;
import org.thingsboard.server.common.data.ResourceType; import org.thingsboard.server.common.data.ResourceType;
@ -46,6 +44,7 @@ import java.util.Base64;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
@DaoSqlTest @DaoSqlTest
@ -116,10 +115,6 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
.andExpect(status().isOk()); .andExpect(status().isOk());
} }
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testSaveResourceWithMaxSumDataSizeOutOfLimit() throws Exception { public void testSaveResourceWithMaxSumDataSizeOutOfLimit() throws Exception {
loginSysAdmin(); loginSysAdmin();
@ -138,9 +133,9 @@ public class BaseTbResourceServiceTest extends AbstractControllerTest {
Assert.assertEquals(1, resourceService.sumDataSizeByTenantId(tenantId)); Assert.assertEquals(1, resourceService.sumDataSizeByTenantId(tenantId));
try { try {
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> createResource("test1", 1 + DEFAULT_FILE_NAME))
thrown.expectMessage(String.format("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit)); .isInstanceOf(DataValidationException.class)
createResource("test1", 1 + DEFAULT_FILE_NAME); .hasMessageContaining("Failed to create the tb resource, files size limit is exhausted %d bytes!", limit);
} finally { } finally {
defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(0).build()); defaultTenantProfile.getProfileData().setConfiguration(DefaultTenantProfileConfiguration.builder().maxResourcesInBytes(0).build());
loginSysAdmin(); loginSysAdmin();

4
application/src/test/java/org/thingsboard/server/transport/lwm2m/AbstractLwM2MIntegrationTest.java

@ -70,7 +70,7 @@ import org.thingsboard.server.service.telemetry.cmd.v2.LatestValueCmd;
import org.thingsboard.server.transport.AbstractTransportIntegrationTest; import org.thingsboard.server.transport.AbstractTransportIntegrationTest;
import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient; import org.thingsboard.server.transport.lwm2m.client.LwM2MTestClient;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
import java.io.IOException; import java.io.IOException;
import java.net.ServerSocket; import java.net.ServerSocket;
@ -108,7 +108,7 @@ import static org.thingsboard.server.transport.lwm2m.Lwm2mTestHelper.LwM2MProfil
public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportIntegrationTest { public abstract class AbstractLwM2MIntegrationTest extends AbstractTransportIntegrationTest {
@SpyBean @SpyBean
DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest; LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
@Autowired @Autowired
private LwM2mClientContext clientContextTest; private LwM2mClientContext clientContextTest;

6
application/src/test/java/org/thingsboard/server/transport/lwm2m/client/LwM2MTestClient.java

@ -45,7 +45,7 @@ import org.junit.Assert;
import org.mockito.Mockito; import org.mockito.Mockito;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient; import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClient;
import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext; import org.thingsboard.server.transport.lwm2m.server.client.LwM2mClientContext;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
import java.io.IOException; import java.io.IOException;
@ -109,12 +109,12 @@ public class LwM2MTestClient {
private LwM2MLocationParams locationParams; private LwM2MLocationParams locationParams;
private LwM2mTemperatureSensor lwM2MTemperatureSensor; private LwM2mTemperatureSensor lwM2MTemperatureSensor;
private Set<LwM2MClientState> clientStates; private Set<LwM2MClientState> clientStates;
private DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest; private LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandlerTest;
private LwM2mClientContext clientContext; private LwM2mClientContext clientContext;
public void init(Security security, Configuration coapConfig, int port, boolean isRpc, boolean isBootstrap, public void init(Security security, Configuration coapConfig, int port, boolean isRpc, boolean isBootstrap,
int shortServerId, int shortServerIdBs, Security securityBs, int shortServerId, int shortServerIdBs, Security securityBs,
DefaultLwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler, LwM2mUplinkMsgHandler defaultLwM2mUplinkMsgHandler,
LwM2mClientContext clientContext) throws InvalidDDFFileException, IOException { LwM2mClientContext clientContext) throws InvalidDDFFileException, IOException {
Assert.assertNull("client already initialized", leshanClient); Assert.assertNull("client already initialized", leshanClient);
this.defaultLwM2mUplinkMsgHandlerTest = defaultLwM2mUplinkMsgHandler; this.defaultLwM2mUplinkMsgHandlerTest = defaultLwM2mUplinkMsgHandler;

7
application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/attributes/AbstractMqttV5ClientSparkplugAttributesTest.java

@ -20,6 +20,7 @@ import io.netty.handler.codec.mqtt.MqttQoS;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.msg.session.FeatureType;
import org.thingsboard.server.transport.mqtt.sparkplug.AbstractMqttV5ClientSparkplugTest; import org.thingsboard.server.transport.mqtt.sparkplug.AbstractMqttV5ClientSparkplugTest;
import org.thingsboard.server.transport.mqtt.util.sparkplug.MetricDataType; import org.thingsboard.server.transport.mqtt.util.sparkplug.MetricDataType;
import org.thingsboard.server.transport.mqtt.util.sparkplug.SparkplugMessageType; import org.thingsboard.server.transport.mqtt.util.sparkplug.SparkplugMessageType;
@ -50,6 +51,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
String SHARED_ATTRIBUTES_PAYLOAD = "{\"" + keyNodeRebirth + "\":" + value + "}"; String SHARED_ATTRIBUTES_PAYLOAD = "{\"" + keyNodeRebirth + "\":" + value + "}";
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
doPostAsync("/api/plugins/telemetry/DEVICE/" + savedGateway.getId().getId() + "/attributes/SHARED_SCOPE", SHARED_ATTRIBUTES_PAYLOAD, String.class, status().isOk()); doPostAsync("/api/plugins/telemetry/DEVICE/" + savedGateway.getId().getId() + "/attributes/SHARED_SCOPE", SHARED_ATTRIBUTES_PAYLOAD, String.class, status().isOk());
await(alias + SparkplugMessageType.NBIRTH.name()) await(alias + SparkplugMessageType.NBIRTH.name())
.atMost(40, TimeUnit.SECONDS) .atMost(40, TimeUnit.SECONDS)
@ -75,6 +77,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
connectionWithNBirth(metricDataType, metricKey, metricValue); connectionWithNBirth(metricDataType, metricKey, metricValue);
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
// Boolean <-> String // Boolean <-> String
boolean expectedValue = true; boolean expectedValue = true;
@ -138,6 +141,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
connectionWithNBirth(metricDataType, metricKey, metricValue); connectionWithNBirth(metricDataType, metricKey, metricValue);
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
// Long <-> String // Long <-> String
String valueStr = "123"; String valueStr = "123";
@ -189,6 +193,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
connectionWithNBirth(metricDataType, metricKey, metricValue); connectionWithNBirth(metricDataType, metricKey, metricValue);
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
// Float <-> String // Float <-> String
String valueStr = "123.345"; String valueStr = "123.345";
@ -240,6 +245,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
connectionWithNBirth(metricDataType, metricKey, metricValue); connectionWithNBirth(metricDataType, metricKey, metricValue);
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
// Double <-> String // Double <-> String
String valueStr = "123345456"; String valueStr = "123345456";
@ -291,6 +297,7 @@ public abstract class AbstractMqttV5ClientSparkplugAttributesTest extends Abstra
connectionWithNBirth(metricDataType, metricKey, metricValue); connectionWithNBirth(metricDataType, metricKey, metricValue);
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.ATTRIBUTES, 1);
// String <-> Long // String <-> Long
long valueLong = 123345456L; long valueLong = 123345456L;

4
application/src/test/java/org/thingsboard/server/transport/mqtt/sparkplug/rpc/AbstractMqttV5RpcSparkplugTest.java

@ -20,6 +20,7 @@ import lombok.extern.slf4j.Slf4j;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.msg.session.FeatureType;
import org.thingsboard.server.transport.mqtt.sparkplug.AbstractMqttV5ClientSparkplugTest; import org.thingsboard.server.transport.mqtt.sparkplug.AbstractMqttV5ClientSparkplugTest;
import org.thingsboard.server.transport.mqtt.util.sparkplug.SparkplugMessageType; import org.thingsboard.server.transport.mqtt.util.sparkplug.SparkplugMessageType;
@ -45,6 +46,7 @@ public abstract class AbstractMqttV5RpcSparkplugTest extends AbstractMqttV5Clie
connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32()); connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32());
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.RPC, 1);
String expected = "{\"result\":\"Success: " + SparkplugMessageType.NCMD.name() + "\"}"; String expected = "{\"result\":\"Success: " + SparkplugMessageType.NCMD.name() + "\"}";
String actual = sendRPCSparkplug(NCMD.name(), sparkplugRpcRequest, savedGateway); String actual = sendRPCSparkplug(NCMD.name(), sparkplugRpcRequest, savedGateway);
await(alias + SparkplugMessageType.NCMD.name()) await(alias + SparkplugMessageType.NCMD.name())
@ -79,6 +81,7 @@ public abstract class AbstractMqttV5RpcSparkplugTest extends AbstractMqttV5Clie
connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32()); connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32());
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.RPC, 1);
String invalidateTypeMessageName = "RCMD"; String invalidateTypeMessageName = "RCMD";
String expected = "{\"result\":\"" + INVALID_ARGUMENTS + "\",\"error\":\"Failed to convert device RPC command to MQTT msg: " + String expected = "{\"result\":\"" + INVALID_ARGUMENTS + "\",\"error\":\"Failed to convert device RPC command to MQTT msg: " +
invalidateTypeMessageName + "{\\\"metricName\\\":\\\"" + metricBirthName_Int32 + "\\\",\\\"value\\\":" + metricBirthValue_Int32 + "}\"}"; invalidateTypeMessageName + "{\\\"metricName\\\":\\\"" + metricBirthName_Int32 + "\\\",\\\"value\\\":" + metricBirthValue_Int32 + "}\"}";
@ -92,6 +95,7 @@ public abstract class AbstractMqttV5RpcSparkplugTest extends AbstractMqttV5Clie
connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32()); connectionWithNBirth(metricBirthDataType_Int32, metricBirthName_Int32, nextInt32());
Assert.assertTrue("Connection node is failed", client.isConnected()); Assert.assertTrue("Connection node is failed", client.isConnected());
client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE); client.subscribeAndWait(NAMESPACE + "/" + groupId + "/" + NCMD.name() + "/" + edgeNode + "/#", MqttQoS.AT_MOST_ONCE);
awaitForDeviceActorToReceiveSubscription(savedGateway.getId(), FeatureType.RPC, 1);
String metricNameBad = metricBirthName_Int32 + "_Bad"; String metricNameBad = metricBirthName_Int32 + "_Bad";
String sparkplugRpcRequestBad = "{\"metricName\":\"" + metricNameBad + "\",\"value\":" + metricBirthValue_Int32 + "}"; String sparkplugRpcRequestBad = "{\"metricName\":\"" + metricNameBad + "\",\"value\":" + metricBirthValue_Int32 + "}";
String expected = "{\"result\":\"BAD_REQUEST_PARAMS\",\"error\":\"Failed send To Node Rpc Request: " + String expected = "{\"result\":\"BAD_REQUEST_PARAMS\",\"error\":\"Failed send To Node Rpc Request: " +

7
application/src/test/resources/logback-test.xml

@ -21,6 +21,13 @@
<!-- mute TelemetryEdgeSqlTest that causes a lot of randomly generated errors --> <!-- mute TelemetryEdgeSqlTest that causes a lot of randomly generated errors -->
<logger name="org.thingsboard.server.service.edge.rpc.EdgeGrpcSession" level="OFF"/> <logger name="org.thingsboard.server.service.edge.rpc.EdgeGrpcSession" level="OFF"/>
<!-- LwM2m lifecycle debug for the test scope -->
<logger name="org.thingsboard.server.transport.lwm2m.server.downlink.DefaultLwM2mDownlinkMsgHandler" level="TRACE"/>
<logger name="org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler" level="TRACE"/>
<logger name="org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaUpdateService" level="TRACE"/>
<logger name="org.thingsboard.server.transport.lwm2m.server" level="INFO"/>
<logger name="org.eclipse.californium.core" level="INFO"/>
<root level="WARN"> <root level="WARN">
<appender-ref ref="console"/> <appender-ref ref="console"/>
</root> </root>

6
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/DefaultLwM2mTransportService.java

@ -25,6 +25,7 @@ import org.eclipse.leshan.core.node.codec.DefaultLwM2mEncoder;
import org.eclipse.leshan.server.californium.LeshanServer; import org.eclipse.leshan.server.californium.LeshanServer;
import org.eclipse.leshan.server.californium.LeshanServerBuilder; import org.eclipse.leshan.server.californium.LeshanServerBuilder;
import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore; import org.eclipse.leshan.server.californium.registration.CaliforniumRegistrationStore;
import org.springframework.context.annotation.DependsOn;
import org.springframework.stereotype.Component; import org.springframework.stereotype.Component;
import org.thingsboard.server.cache.ota.OtaPackageDataCache; import org.thingsboard.server.cache.ota.OtaPackageDataCache;
import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.DataConstants;
@ -35,7 +36,7 @@ import org.thingsboard.server.transport.lwm2m.config.LwM2MTransportServerConfig;
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MAuthorizer; import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MAuthorizer;
import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MDtlsCertificateVerifier; import org.thingsboard.server.transport.lwm2m.secure.TbLwM2MDtlsCertificateVerifier;
import org.thingsboard.server.transport.lwm2m.server.store.TbSecurityStore; import org.thingsboard.server.transport.lwm2m.server.store.TbSecurityStore;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl; import org.thingsboard.server.transport.lwm2m.utils.LwM2mValueConverterImpl;
import javax.annotation.PreDestroy; import javax.annotation.PreDestroy;
@ -56,6 +57,7 @@ import static org.thingsboard.server.transport.lwm2m.server.ota.DefaultLwM2MOtaU
@Slf4j @Slf4j
@Component @Component
@DependsOn({"lwM2mDownlinkMsgHandler", "lwM2mUplinkMsgHandler"})
@TbLwM2mTransportComponent @TbLwM2mTransportComponent
@RequiredArgsConstructor @RequiredArgsConstructor
public class DefaultLwM2mTransportService implements LwM2MTransportService { public class DefaultLwM2mTransportService implements LwM2MTransportService {
@ -66,7 +68,7 @@ public class DefaultLwM2mTransportService implements LwM2MTransportService {
private final LwM2mTransportContext context; private final LwM2mTransportContext context;
private final LwM2MTransportServerConfig config; private final LwM2MTransportServerConfig config;
private final OtaPackageDataCache otaPackageDataCache; private final OtaPackageDataCache otaPackageDataCache;
private final DefaultLwM2mUplinkMsgHandler handler; private final LwM2mUplinkMsgHandler handler;
private final CaliforniumRegistrationStore registrationStore; private final CaliforniumRegistrationStore registrationStore;
private final TbSecurityStore securityStore; private final TbSecurityStore securityStore;
private final TbLwM2MDtlsCertificateVerifier certificateVerifier; private final TbLwM2MDtlsCertificateVerifier certificateVerifier;

4
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/client/LwM2mClientContextImpl.java

@ -42,7 +42,7 @@ import org.thingsboard.server.transport.lwm2m.server.ota.LwM2MOtaUpdateService;
import org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager; import org.thingsboard.server.transport.lwm2m.server.session.LwM2MSessionManager;
import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MClientStore; import org.thingsboard.server.transport.lwm2m.server.store.TbLwM2MClientStore;
import org.thingsboard.server.transport.lwm2m.server.store.TbMainSecurityStore; import org.thingsboard.server.transport.lwm2m.server.store.TbMainSecurityStore;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
import org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil; import org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil;
import java.util.Arrays; import java.util.Arrays;
@ -75,7 +75,7 @@ public class LwM2mClientContextImpl implements LwM2mClientContext {
@Autowired @Autowired
@Lazy @Lazy
private DefaultLwM2mUplinkMsgHandler defaultLwM2MUplinkMsgHandler; private LwM2mUplinkMsgHandler defaultLwM2MUplinkMsgHandler;
@Autowired @Autowired
@Lazy @Lazy
private LwM2MOtaUpdateService otaUpdateService; private LwM2MOtaUpdateService otaUpdateService;

30
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/downlink/DefaultLwM2mDownlinkMsgHandler.java

@ -85,6 +85,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.RejectedExecutionException;
import java.util.function.Function; import java.util.function.Function;
import java.util.function.Predicate; import java.util.function.Predicate;
import java.util.stream.Collectors; import java.util.stream.Collectors;
@ -103,7 +104,7 @@ import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.ge
import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.validateVersionedId; import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.validateVersionedId;
@Slf4j @Slf4j
@Service @Service("lwM2mDownlinkMsgHandler")
@TbLwM2mTransportComponent @TbLwM2mTransportComponent
@RequiredArgsConstructor @RequiredArgsConstructor
public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mDownlinkMsgHandler { public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mDownlinkMsgHandler {
@ -124,6 +125,7 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
@PreDestroy @PreDestroy
public void destroy() { public void destroy() {
log.trace("Destroying {}", getClass().getSimpleName());
super.destroy(); super.destroy();
} }
@ -521,16 +523,22 @@ public class DefaultLwM2mDownlinkMsgHandler extends LwM2MExecutorAwareService im
private <R extends DownlinkRequest<T>, T extends LwM2mResponse> void handleDownlinkError(LwM2mClient client, R request, DownlinkRequestCallback<R, T> callback, Exception e) { private <R extends DownlinkRequest<T>, T extends LwM2mResponse> void handleDownlinkError(LwM2mClient client, R request, DownlinkRequestCallback<R, T> callback, Exception e) {
log.trace("[{}] Received downlink error: {}.", client.getEndpoint(), e); log.trace("[{}] Received downlink error: {}.", client.getEndpoint(), e);
client.updateLastUplinkTime(); try {
executor.submit(() -> { client.updateLastUplinkTime();
if (e instanceof TimeoutException || e instanceof ClientSleepingException) { executor.submit(() -> {
log.trace("[{}] Received {}, client is probably sleeping", client.getEndpoint(), e.getClass().getSimpleName()); if (e instanceof TimeoutException || e instanceof ClientSleepingException) {
clientContext.asleep(client); log.trace("[{}] Received {}, client is probably sleeping", client.getEndpoint(), e.getClass().getSimpleName());
} else { clientContext.asleep(client);
log.trace("[{}] Received {}", client.getEndpoint(), e.getClass().getSimpleName()); } else {
} log.trace("[{}] Received {}", client.getEndpoint(), e.getClass().getSimpleName());
callback.onError(toString(request), e); }
}); callback.onError(toString(request), e);
});
} catch (RejectedExecutionException ree) {
log.warn("[{}] Can not handle downlink error. Executor already down", client.getEndpoint(), ree);
} catch (Exception exception) {
log.warn("[{}] Can not handle downlink error", client.getEndpoint(), exception);
}
} }
private WriteRequest getWriteRequestSingleResource(ResourceModel.Type type, ContentFormat contentFormat, int objectId, int instanceId, int resourceId, Object value) { private WriteRequest getWriteRequestSingleResource(ResourceModel.Type type, ContentFormat contentFormat, int objectId, int instanceId, int resourceId, Object value) {

1
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/ota/DefaultLwM2MOtaUpdateService.java

@ -146,6 +146,7 @@ public class DefaultLwM2MOtaUpdateService extends LwM2MExecutorAwareService impl
@PreDestroy @PreDestroy
public void destroy() { public void destroy() {
log.trace("Destroying {}", getClass().getSimpleName());
super.destroy(); super.destroy();
} }

48
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/DefaultLwM2mUplinkMsgHandler.java

@ -20,6 +20,8 @@ import com.google.gson.GsonBuilder;
import com.google.gson.JsonElement; import com.google.gson.JsonElement;
import com.google.gson.JsonObject; import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken; import com.google.gson.reflect.TypeToken;
import lombok.Getter;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.eclipse.leshan.core.ResponseCode; import org.eclipse.leshan.core.ResponseCode;
import org.eclipse.leshan.core.model.ObjectModel; import org.eclipse.leshan.core.model.ObjectModel;
@ -32,6 +34,7 @@ import org.eclipse.leshan.core.node.LwM2mPath;
import org.eclipse.leshan.core.node.LwM2mResource; import org.eclipse.leshan.core.node.LwM2mResource;
import org.eclipse.leshan.core.node.LwM2mResourceInstance; import org.eclipse.leshan.core.node.LwM2mResourceInstance;
import org.eclipse.leshan.core.node.LwM2mSingleResource; import org.eclipse.leshan.core.node.LwM2mSingleResource;
import org.eclipse.leshan.core.node.codec.LwM2mValueConverter;
import org.eclipse.leshan.core.observation.Observation; import org.eclipse.leshan.core.observation.Observation;
import org.eclipse.leshan.core.request.*; import org.eclipse.leshan.core.request.*;
import org.eclipse.leshan.core.request.WriteRequest.Mode; import org.eclipse.leshan.core.request.WriteRequest.Mode;
@ -122,69 +125,41 @@ import static org.thingsboard.server.transport.lwm2m.utils.LwM2MTransportUtil.fr
@Slf4j @Slf4j
@Service @Service("lwM2mUplinkMsgHandler")
@TbLwM2mTransportComponent @TbLwM2mTransportComponent
@RequiredArgsConstructor
public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mUplinkMsgHandler { public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService implements LwM2mUplinkMsgHandler {
public LwM2mValueConverterImpl converter; @Getter
private final LwM2mValueConverter converter = LwM2mValueConverterImpl.getInstance();;
private final TransportService transportService; private final TransportService transportService;
private final LwM2mTransportContext context; private final LwM2mTransportContext context;
@Lazy
private final LwM2MAttributesService attributesService; private final LwM2MAttributesService attributesService;
private final LwM2MSessionManager sessionManager; private final LwM2MSessionManager sessionManager;
@Lazy
private final LwM2MOtaUpdateService otaService; private final LwM2MOtaUpdateService otaService;
private final LwM2MTransportServerConfig config; private final LwM2MTransportServerConfig config;
private final LwM2MTelemetryLogService logService; private final LwM2MTelemetryLogService logService;
private final LwM2mTransportServerHelper helper; private final LwM2mTransportServerHelper helper;
private final TbLwM2MDtlsSessionStore sessionStore; private final TbLwM2MDtlsSessionStore sessionStore;
private final LwM2mClientContext clientContext; private final LwM2mClientContext clientContext;
private final LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler; private final LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler; //Do not use Lazy because we need live executor to handle msgs
private final LwM2mVersionedModelProvider modelProvider; private final LwM2mVersionedModelProvider modelProvider;
private final RegistrationStore registrationStore; private final RegistrationStore registrationStore;
private final TbLwM2mSecurityStore securityStore; private final TbLwM2mSecurityStore securityStore;
private final LwM2MModelConfigService modelConfigService; private final LwM2MModelConfigService modelConfigService;
public DefaultLwM2mUplinkMsgHandler(TransportService transportService,
LwM2MTransportServerConfig config,
LwM2mTransportServerHelper helper,
LwM2mClientContext clientContext,
LwM2MTelemetryLogService logService,
LwM2MSessionManager sessionManager,
@Lazy LwM2MOtaUpdateService otaService,
@Lazy LwM2MAttributesService attributesService,
@Lazy LwM2mDownlinkMsgHandler defaultLwM2MDownlinkMsgHandler,
LwM2mTransportContext context,
TbLwM2MDtlsSessionStore sessionStore,
LwM2mVersionedModelProvider modelProvider,
RegistrationStore registrationStore,
TbLwM2mSecurityStore securityStore,
LwM2MModelConfigService modelConfigService) {
this.transportService = transportService;
this.sessionManager = sessionManager;
this.attributesService = attributesService;
this.otaService = otaService;
this.config = config;
this.helper = helper;
this.clientContext = clientContext;
this.logService = logService;
this.defaultLwM2MDownlinkMsgHandler = defaultLwM2MDownlinkMsgHandler;
this.context = context;
this.sessionStore = sessionStore;
this.modelProvider = modelProvider;
this.registrationStore = registrationStore;
this.securityStore = securityStore;
this.modelConfigService = modelConfigService;
}
@PostConstruct @PostConstruct
public void init() { public void init() {
super.init(); super.init();
this.context.getScheduler().scheduleAtFixedRate(this::reportActivity, new Random().nextInt((int) config.getSessionReportTimeout()), config.getSessionReportTimeout(), TimeUnit.MILLISECONDS); this.context.getScheduler().scheduleAtFixedRate(this::reportActivity, new Random().nextInt((int) config.getSessionReportTimeout()), config.getSessionReportTimeout(), TimeUnit.MILLISECONDS);
this.converter = LwM2mValueConverterImpl.getInstance();
} }
@PreDestroy @PreDestroy
public void destroy() { public void destroy() {
log.trace("Destroying {}", getClass().getSimpleName());
super.destroy(); super.destroy();
} }
@ -955,6 +930,7 @@ public class DefaultLwM2mUplinkMsgHandler extends LwM2MExecutorAwareService impl
* *
* @param lwM2MClient - LwM2M Client * @param lwM2MClient - LwM2M Client
*/ */
@Override
public void initAttributes(LwM2mClient lwM2MClient, boolean logFailedUpdateOfNonChangedValue) { public void initAttributes(LwM2mClient lwM2MClient, boolean logFailedUpdateOfNonChangedValue) {
Map<String, String> keyNamesMap = this.getNamesFromProfileForSharedAttributes(lwM2MClient); Map<String, String> keyNamesMap = this.getNamesFromProfileForSharedAttributes(lwM2MClient);
if (!keyNamesMap.isEmpty()) { if (!keyNamesMap.isEmpty()) {

6
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/server/uplink/LwM2mUplinkMsgHandler.java

@ -15,6 +15,7 @@
*/ */
package org.thingsboard.server.transport.lwm2m.server.uplink; package org.thingsboard.server.transport.lwm2m.server.uplink;
import org.eclipse.leshan.core.node.codec.LwM2mValueConverter;
import org.eclipse.leshan.core.observation.Observation; import org.eclipse.leshan.core.observation.Observation;
import org.eclipse.leshan.core.request.CreateRequest; import org.eclipse.leshan.core.request.CreateRequest;
import org.eclipse.leshan.core.request.SendRequest; import org.eclipse.leshan.core.request.SendRequest;
@ -69,5 +70,10 @@ public interface LwM2mUplinkMsgHandler {
void onToTransportUpdateCredentials(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToTransportUpdateCredentialsProto updateCredentials); void onToTransportUpdateCredentials(TransportProtos.SessionInfoProto sessionInfo, TransportProtos.ToTransportUpdateCredentialsProto updateCredentials);
void initAttributes(LwM2mClient lwM2MClient, boolean logFailedUpdateOfNonChangedValue);
LwM2MTransportServerConfig getConfig(); LwM2MTransportServerConfig getConfig();
LwM2mValueConverter getConverter();
} }

16
common/transport/lwm2m/src/main/java/org/thingsboard/server/transport/lwm2m/utils/LwM2MTransportUtil.java

@ -52,7 +52,7 @@ import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdate
import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState; import org.thingsboard.server.transport.lwm2m.server.ota.firmware.FirmwareUpdateState;
import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult; import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateResult;
import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState; import org.thingsboard.server.transport.lwm2m.server.ota.software.SoftwareUpdateState;
import org.thingsboard.server.transport.lwm2m.server.uplink.DefaultLwM2mUplinkMsgHandler; import org.thingsboard.server.transport.lwm2m.server.uplink.LwM2mUplinkMsgHandler;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -289,12 +289,12 @@ public class LwM2MTransportUtil {
* Attribute pmax = new Attribute(MAXIMUM_PERIOD, "60"); * Attribute pmax = new Attribute(MAXIMUM_PERIOD, "60");
* Attribute [] attrs = {gt, st}; * Attribute [] attrs = {gt, st};
*/ */
public static SimpleDownlinkRequest createWriteAttributeRequest(String target, Object params, DefaultLwM2mUplinkMsgHandler serviceImpl) { public static SimpleDownlinkRequest createWriteAttributeRequest(String target, Object params, LwM2mUplinkMsgHandler serviceImpl) {
AttributeSet attrSet = new AttributeSet(createWriteAttributes(params, serviceImpl, target)); AttributeSet attrSet = new AttributeSet(createWriteAttributes(params, serviceImpl, target));
return attrSet.getAttributes().size() > 0 ? new WriteAttributesRequest(target, attrSet) : null; return attrSet.getAttributes().size() > 0 ? new WriteAttributesRequest(target, attrSet) : null;
} }
private static Attribute[] createWriteAttributes(Object params, DefaultLwM2mUplinkMsgHandler serviceImpl, String target) { private static Attribute[] createWriteAttributes(Object params, LwM2mUplinkMsgHandler serviceImpl, String target) {
List<Attribute> attributeLists = new ArrayList<>(); List<Attribute> attributeLists = new ArrayList<>();
Map<String, Object> map = JacksonUtil.convertValue(params, new TypeReference<>() { Map<String, Object> map = JacksonUtil.convertValue(params, new TypeReference<>() {
}); });
@ -366,19 +366,19 @@ public class LwM2MTransportUtil {
return newValues; return newValues;
} }
public static Object convertWriteAttributes(String type, Object value, DefaultLwM2mUplinkMsgHandler serviceImpl, String target) { public static Object convertWriteAttributes(String type, Object value, LwM2mUplinkMsgHandler serviceImpl, String target) {
switch (type) { switch (type) {
/** Integer [0:255]; */ /** Integer [0:255]; */
case DIMENSION: case DIMENSION:
Long dim = (Long) serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target)); Long dim = (Long) serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
return dim >= 0 && dim <= 255 ? dim : null; return dim >= 0 && dim <= 255 ? dim : null;
/**String;*/ /**String;*/
case OBJECT_VERSION: case OBJECT_VERSION:
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), STRING, new LwM2mPath(target)); return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), STRING, new LwM2mPath(target));
/**INTEGER */ /**INTEGER */
case MINIMUM_PERIOD: case MINIMUM_PERIOD:
case MAXIMUM_PERIOD: case MAXIMUM_PERIOD:
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target)); return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), INTEGER, new LwM2mPath(target));
/**Float; */ /**Float; */
case GREATER_THAN: case GREATER_THAN:
case LESSER_THAN: case LESSER_THAN:
@ -386,7 +386,7 @@ public class LwM2MTransportUtil {
if (value.getClass().getSimpleName().equals("String")) { if (value.getClass().getSimpleName().equals("String")) {
value = Double.valueOf((String) value); value = Double.valueOf((String) value);
} }
return serviceImpl.converter.convertValue(value, equalsResourceTypeGetSimpleName(value), FLOAT, new LwM2mPath(target)); return serviceImpl.getConverter().convertValue(value, equalsResourceTypeGetSimpleName(value), FLOAT, new LwM2mPath(target));
default: default:
return null; return null;
} }

21
dao/src/main/java/org/thingsboard/server/dao/entity/DefaultEntityServiceRegistry.java

@ -15,27 +15,31 @@
*/ */
package org.thingsboard.server.dao.entity; package org.thingsboard.server.dao.entity;
import lombok.RequiredArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.context.ApplicationContext; import org.springframework.context.ApplicationContext;
import org.springframework.context.event.ContextRefreshedEvent;
import org.springframework.context.event.EventListener;
import org.springframework.core.Ordered;
import org.springframework.core.annotation.Order;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import javax.annotation.PostConstruct;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
@Service @Service
@RequiredArgsConstructor
@Slf4j
public class DefaultEntityServiceRegistry implements EntityServiceRegistry { public class DefaultEntityServiceRegistry implements EntityServiceRegistry {
private final ApplicationContext applicationContext; private final ApplicationContext applicationContext;
private final Map<EntityType, EntityDaoService> entityDaoServicesMap; private final Map<EntityType, EntityDaoService> entityDaoServicesMap = new HashMap<>();
public DefaultEntityServiceRegistry(ApplicationContext applicationContext) { @EventListener(ContextRefreshedEvent.class)
this.applicationContext = applicationContext; @Order(Ordered.HIGHEST_PRECEDENCE)
this.entityDaoServicesMap = new HashMap<>();
}
@PostConstruct
public void init() { public void init() {
log.debug("Initializing EntityServiceRegistry on ContextRefreshedEvent");
applicationContext.getBeansOfType(EntityDaoService.class).values().forEach(entityDaoService -> { applicationContext.getBeansOfType(EntityDaoService.class).values().forEach(entityDaoService -> {
EntityType entityType = entityDaoService.getEntityType(); EntityType entityType = entityDaoService.getEntityType();
entityDaoServicesMap.put(entityType, entityDaoService); entityDaoServicesMap.put(entityType, entityDaoService);
@ -43,6 +47,7 @@ public class DefaultEntityServiceRegistry implements EntityServiceRegistry {
entityDaoServicesMap.put(EntityType.RULE_NODE, entityDaoService); entityDaoServicesMap.put(EntityType.RULE_NODE, entityDaoService);
} }
}); });
log.debug("Initialized EntityServiceRegistry total [{}] entries", entityDaoServicesMap.size());
} }
@Override @Override

122
dao/src/test/java/org/thingsboard/server/dao/service/AbstractServiceTest.java

@ -18,6 +18,8 @@ package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Before;
import org.junit.runner.RunWith; import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Bean;
@ -47,44 +49,17 @@ import org.thingsboard.server.common.data.id.HasId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.ota.OtaPackageType; import org.thingsboard.server.common.data.ota.OtaPackageType;
import org.thingsboard.server.dao.alarm.AlarmCommentService;
import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.asset.AssetProfileService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.audit.AuditLogLevelFilter; import org.thingsboard.server.dao.audit.AuditLogLevelFilter;
import org.thingsboard.server.dao.audit.AuditLogLevelMask; import org.thingsboard.server.dao.audit.AuditLogLevelMask;
import org.thingsboard.server.dao.audit.AuditLogLevelProperties; import org.thingsboard.server.dao.audit.AuditLogLevelProperties;
import org.thingsboard.server.dao.component.ComponentDescriptorService;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.edge.EdgeEventService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entity.EntityService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.event.EventService;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.relation.RelationService;
import org.thingsboard.server.dao.resource.ResourceService;
import org.thingsboard.server.dao.rpc.RpcService;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.settings.AdminSettingsService;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import org.thingsboard.server.dao.tenant.TenantService; import org.thingsboard.server.dao.tenant.TenantService;
import org.thingsboard.server.dao.timeseries.TimeseriesService;
import org.thingsboard.server.dao.usagerecord.ApiUsageStateService;
import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.widget.WidgetTypeService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.io.IOException; import java.io.IOException;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.Comparator; import java.util.Comparator;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import java.util.UUID;
import static org.junit.Assert.assertNotNull; import static org.junit.Assert.assertNotNull;
@ -100,91 +75,20 @@ public abstract class AbstractServiceTest {
public static final TenantId SYSTEM_TENANT_ID = TenantId.SYS_TENANT_ID; public static final TenantId SYSTEM_TENANT_ID = TenantId.SYS_TENANT_ID;
@Autowired
protected UserService userService;
@Autowired
protected ApiUsageStateService apiUsageStateService;
@Autowired
protected AdminSettingsService adminSettingsService;
@Autowired @Autowired
protected TenantService tenantService; protected TenantService tenantService;
@Autowired protected TenantId tenantId;
protected CustomerService customerService;
@Autowired
protected DeviceService deviceService;
@Autowired
protected AssetService assetService;
@Autowired
protected EntityViewService entityViewService;
@Autowired
protected EntityService entityService;
@Autowired
protected DeviceCredentialsService deviceCredentialsService;
@Autowired
protected WidgetsBundleService widgetsBundleService;
@Autowired
protected WidgetTypeService widgetTypeService;
@Autowired
protected DashboardService dashboardService;
@Autowired
protected TimeseriesService tsService;
@Autowired
protected EventService eventService;
@Autowired
protected RelationService relationService;
@Autowired
protected AlarmService alarmService;
@Autowired
protected AlarmCommentService alarmCommentService;
@Autowired
protected RuleChainService ruleChainService;
@Autowired
protected EdgeService edgeService;
@Autowired
protected EdgeEventService edgeEventService;
@Autowired @Before
private ComponentDescriptorService componentDescriptorService; public void beforeAbstractService() {
tenantId = createTenant();
@Autowired }
protected TenantProfileService tenantProfileService;
@Autowired
protected DeviceProfileService deviceProfileService;
@Autowired
protected AssetProfileService assetProfileService;
@Autowired
protected ResourceService resourceService;
@Autowired
protected OtaPackageService otaPackageService;
@Autowired
protected RpcService rpcService;
@Autowired @After
protected QueueService queueService; public void afterAbstractService() {
tenantService.deleteTenants();
}
public class IdComparator<D extends HasId> implements Comparator<D> { public class IdComparator<D extends HasId> implements Comparator<D> {
@Override @Override
@ -270,7 +174,7 @@ public abstract class AbstractServiceTest {
public TenantId createTenant() { public TenantId createTenant() {
Tenant tenant = new Tenant(); Tenant tenant = new Tenant();
tenant.setTitle("My tenant " + Uuids.timeBased()); tenant.setTitle("My tenant " + UUID.randomUUID());
Tenant savedTenant = tenantService.saveTenant(tenant); Tenant savedTenant = tenantService.saveTenant(tenant);
assertNotNull(savedTenant); assertNotNull(savedTenant);
return savedTenant.getId(); return savedTenant.getId();

5
dao/src/test/java/org/thingsboard/server/dao/service/BaseAdminSettingsServiceTest.java

@ -20,11 +20,16 @@ import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.AdminSettings; import org.thingsboard.server.common.data.AdminSettings;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.settings.AdminSettingsService;
public abstract class BaseAdminSettingsServiceTest extends AbstractServiceTest { public abstract class BaseAdminSettingsServiceTest extends AbstractServiceTest {
@Autowired
AdminSettingsService adminSettingsService;
@Test @Test
public void testFindAdminSettingsByKey() { public void testFindAdminSettingsByKey() {
AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(SYSTEM_TENANT_ID, "general"); AdminSettings adminSettings = adminSettingsService.findAdminSettingsByKey(SYSTEM_TENANT_ID, "general");

22
dao/src/test/java/org/thingsboard/server/dao/service/BaseAlarmCommentServiceTest.java

@ -20,21 +20,22 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils; import org.testcontainers.shaded.org.apache.commons.lang3.RandomStringUtils;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.alarm.Alarm; import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmComment; import org.thingsboard.server.common.data.alarm.AlarmComment;
import org.thingsboard.server.common.data.alarm.AlarmCommentInfo; import org.thingsboard.server.common.data.alarm.AlarmCommentInfo;
import org.thingsboard.server.common.data.alarm.AlarmSeverity; import org.thingsboard.server.common.data.alarm.AlarmSeverity;
import org.thingsboard.server.common.data.alarm.AlarmStatus;
import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.id.UserId; import org.thingsboard.server.common.data.id.UserId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.dao.alarm.AlarmCommentService;
import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.user.UserService;
import java.util.UUID; import java.util.UUID;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
@ -43,19 +44,19 @@ import static org.thingsboard.server.common.data.alarm.AlarmCommentType.OTHER;
public abstract class BaseAlarmCommentServiceTest extends AbstractServiceTest { public abstract class BaseAlarmCommentServiceTest extends AbstractServiceTest {
@Autowired
AlarmService alarmService;
@Autowired
AlarmCommentService alarmCommentService;
@Autowired
UserService userService;
public static final String TEST_ALARM = "TEST_ALARM"; public static final String TEST_ALARM = "TEST_ALARM";
private TenantId tenantId;
private Alarm alarm; private Alarm alarm;
private User user; private User user;
@Before @Before
public void before() { public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
alarm = Alarm.builder().tenantId(tenantId).originator(new AssetId(Uuids.timeBased())) alarm = Alarm.builder().tenantId(tenantId).originator(new AssetId(Uuids.timeBased()))
.type(TEST_ALARM) .type(TEST_ALARM)
.severity(AlarmSeverity.CRITICAL) .severity(AlarmSeverity.CRITICAL)
@ -74,7 +75,6 @@ public abstract class BaseAlarmCommentServiceTest extends AbstractServiceTest {
@After @After
public void after() { public void after() {
alarmService.deleteAlarm(tenantId, alarm.getId()); alarmService.deleteAlarm(tenantId, alarm.getId());
tenantService.deleteTenant(tenantId);
} }

44
dao/src/test/java/org/thingsboard/server/dao/service/BaseAlarmServiceTest.java

@ -16,14 +16,12 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.User; import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.alarm.Alarm; import org.thingsboard.server.common.data.alarm.Alarm;
import org.thingsboard.server.common.data.alarm.AlarmCreateOrUpdateActiveRequest; import org.thingsboard.server.common.data.alarm.AlarmCreateOrUpdateActiveRequest;
@ -36,9 +34,7 @@ import org.thingsboard.server.common.data.alarm.AlarmStatus;
import org.thingsboard.server.common.data.alarm.AlarmUpdateRequest; import org.thingsboard.server.common.data.alarm.AlarmUpdateRequest;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.page.SortOrder; import org.thingsboard.server.common.data.page.SortOrder;
import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.common.data.query.AlarmData; import org.thingsboard.server.common.data.query.AlarmData;
@ -52,7 +48,12 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.dao.alarm.AlarmApiCallResult; import org.thingsboard.server.dao.alarm.AlarmApiCallResult;
import org.thingsboard.server.dao.alarm.AlarmOperationResult; import org.thingsboard.server.dao.alarm.AlarmService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.relation.RelationService;
import org.thingsboard.server.dao.user.UserService;
import java.util.Arrays; import java.util.Arrays;
import java.util.Collections; import java.util.Collections;
@ -61,29 +62,24 @@ import java.util.concurrent.ExecutionException;
public abstract class BaseAlarmServiceTest extends AbstractServiceTest { public abstract class BaseAlarmServiceTest extends AbstractServiceTest {
public static final String TEST_ALARM = "TEST_ALARM"; @Autowired
AlarmService alarmService;
@Autowired
AssetService assetService;
@Autowired
CustomerService customerService;
@Autowired
DeviceService deviceService;
@Autowired
RelationService relationService;
@Autowired
UserService userService;
public static final String TEST_ALARM = "TEST_ALARM";
private static final String TEST_TENANT_EMAIL = "testtenant@thingsboard.org"; private static final String TEST_TENANT_EMAIL = "testtenant@thingsboard.org";
private static final String TEST_TENANT_FIRST_NAME = "testtenantfirstname"; private static final String TEST_TENANT_FIRST_NAME = "testtenantfirstname";
private static final String TEST_TENANT_LAST_NAME = "testtenantlastname"; private static final String TEST_TENANT_LAST_NAME = "testtenantlastname";
private TenantId tenantId;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveAndFetchAlarm() throws ExecutionException, InterruptedException { public void testSaveAndFetchAlarm() throws ExecutionException, InterruptedException {
AssetId parentId = new AssetId(Uuids.timeBased()); AssetId parentId = new AssetId(Uuids.timeBased());

23
dao/src/test/java/org/thingsboard/server/dao/service/BaseApiUsageStateServiceTest.java

@ -15,33 +15,18 @@
*/ */
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.ApiUsageStateValue; import org.thingsboard.server.common.data.ApiUsageStateValue;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.ApiUsageState; import org.thingsboard.server.common.data.ApiUsageState;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.dao.usagerecord.ApiUsageStateService;
public abstract class BaseApiUsageStateServiceTest extends AbstractServiceTest { public abstract class BaseApiUsageStateServiceTest extends AbstractServiceTest {
private TenantId tenantId; @Autowired
ApiUsageStateService apiUsageStateService;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testFindApiUsageStateByTenantId() { public void testFindApiUsageStateByTenantId() {

26
dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetProfileServiceTest.java

@ -19,19 +19,18 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.ThingsBoardThreadFactory; import org.thingsboard.common.util.ThingsBoardThreadFactory;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.asset.AssetProfile; import org.thingsboard.server.common.data.asset.AssetProfile;
import org.thingsboard.server.common.data.asset.AssetProfileInfo; import org.thingsboard.server.common.data.asset.AssetProfileInfo;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.asset.AssetProfileService;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,21 +45,10 @@ public abstract class BaseAssetProfileServiceTest extends AbstractServiceTest {
private IdComparator<AssetProfile> idComparator = new IdComparator<>(); private IdComparator<AssetProfile> idComparator = new IdComparator<>();
private IdComparator<AssetProfileInfo> assetProfileInfoIdComparator = new IdComparator<>(); private IdComparator<AssetProfileInfo> assetProfileInfoIdComparator = new IdComparator<>();
private TenantId tenantId; @Autowired
AssetProfileService assetProfileService;
@Before @Autowired
public void before() { AssetService assetService;
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveAssetProfile() { public void testSaveAssetProfile() {

42
dao/src/test/java/org/thingsboard/server/dao/service/BaseAssetServiceTest.java

@ -16,11 +16,10 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntitySubtype;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
@ -31,6 +30,8 @@ import org.thingsboard.server.common.data.id.CustomerId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import java.util.ArrayList; import java.util.ArrayList;
@ -41,23 +42,12 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
public abstract class BaseAssetServiceTest extends AbstractServiceTest { public abstract class BaseAssetServiceTest extends AbstractServiceTest {
private IdComparator<Asset> idComparator = new IdComparator<>(); @Autowired
AssetService assetService;
private TenantId tenantId; @Autowired
CustomerService customerService;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After private IdComparator<Asset> idComparator = new IdComparator<>();
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveAsset() { public void testSaveAsset() {
@ -220,12 +210,6 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindAssetsByTenantId() { public void testFindAssetsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Asset> assets = new ArrayList<>(); List<Asset> assets = new ArrayList<>();
for (int i=0;i<178;i++) { for (int i=0;i<178;i++) {
Asset asset = new Asset(); Asset asset = new Asset();
@ -257,8 +241,6 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
pageData = assetService.findAssetsByTenantId(tenantId, pageLink); pageData = assetService.findAssetsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -419,12 +401,6 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindAssetsByTenantIdAndCustomerId() { public void testFindAssetsByTenantIdAndCustomerId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -463,8 +439,6 @@ public abstract class BaseAssetServiceTest extends AbstractServiceTest {
pageData = assetService.findAssetInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink); pageData = assetService.findAssetInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

25
dao/src/test/java/org/thingsboard/server/dao/service/BaseCustomerServiceTest.java

@ -25,6 +25,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.ThingsBoardExecutors; import org.thingsboard.common.util.ThingsBoardExecutors;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
@ -32,6 +33,7 @@ import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import java.util.ArrayList; import java.util.ArrayList;
@ -41,28 +43,22 @@ import java.util.concurrent.TimeUnit;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
public abstract class BaseCustomerServiceTest extends AbstractServiceTest { public abstract class BaseCustomerServiceTest extends AbstractServiceTest {
@Autowired
CustomerService customerService;
static final int TIMEOUT = 30; static final int TIMEOUT = 30;
ListeningExecutorService executor; ListeningExecutorService executor;
private TenantId tenantId;
@Before @Before
public void before() { public void before() {
executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(8, getClass())); executor = MoreExecutors.listeningDecorator(ThingsBoardExecutors.newWorkStealingPool(8, getClass()));
}
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After @After
public void after() { public void after() {
executor.shutdownNow(); executor.shutdownNow();
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -152,11 +148,6 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindCustomersByTenantId() throws Exception { public void testFindCustomersByTenantId() throws Exception {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<ListenableFuture<Customer>> futures = new ArrayList<>(135); List<ListenableFuture<Customer>> futures = new ArrayList<>(135);
for (int i = 0; i < 135; i++) { for (int i = 0; i < 135; i++) {
@ -187,8 +178,6 @@ public abstract class BaseCustomerServiceTest extends AbstractServiceTest {
pageData = customerService.findCustomersByTenantId(tenantId, pageLink); pageData = customerService.findCustomersByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

53
dao/src/test/java/org/thingsboard/server/dao/service/BaseDashboardServiceTest.java

@ -16,11 +16,10 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Dashboard; import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.DashboardInfo; import org.thingsboard.server.common.data.DashboardInfo;
@ -33,6 +32,9 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.page.SortOrder; import org.thingsboard.server.common.data.page.SortOrder;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import java.io.IOException; import java.io.IOException;
@ -42,24 +44,15 @@ import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
public abstract class BaseDashboardServiceTest extends AbstractServiceTest { public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
private IdComparator<DashboardInfo> idComparator = new IdComparator<>();
private TenantId tenantId;
@Before @Autowired
public void before() { CustomerService customerService;
Tenant tenant = new Tenant(); @Autowired
tenant.setTitle("My tenant"); DashboardService dashboardService;
Tenant savedTenant = tenantService.saveTenant(tenant); @Autowired
Assert.assertNotNull(savedTenant); EdgeService edgeService;
tenantId = savedTenant.getId();
}
@After private IdComparator<DashboardInfo> idComparator = new IdComparator<>();
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveDashboard() throws IOException { public void testSaveDashboard() throws IOException {
@ -176,12 +169,6 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindDashboardsByTenantId() { public void testFindDashboardsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<DashboardInfo> dashboards = new ArrayList<>(); List<DashboardInfo> dashboards = new ArrayList<>();
for (int i=0;i<165;i++) { for (int i=0;i<165;i++) {
Dashboard dashboard = new Dashboard(); Dashboard dashboard = new Dashboard();
@ -212,18 +199,10 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink); pageData = dashboardService.findDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
public void testFindMobileDashboardsByTenantId() { public void testFindMobileDashboardsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<DashboardInfo> mobileDashboards = new ArrayList<>(); List<DashboardInfo> mobileDashboards = new ArrayList<>();
for (int i=0;i<165;i++) { for (int i=0;i<165;i++) {
Dashboard dashboard = new Dashboard(); Dashboard dashboard = new Dashboard();
@ -272,8 +251,6 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
pageData = dashboardService.findMobileDashboardsByTenantId(tenantId, pageLink); pageData = dashboardService.findMobileDashboardsByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -353,12 +330,6 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindDashboardsByTenantIdAndCustomerId() throws ExecutionException, InterruptedException { public void testFindDashboardsByTenantIdAndCustomerId() throws ExecutionException, InterruptedException {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -396,8 +367,6 @@ public abstract class BaseDashboardServiceTest extends AbstractServiceTest {
pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink); pageData = dashboardService.findDashboardsByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

26
dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceCredentialsServiceTest.java

@ -16,37 +16,25 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.DeviceCredentialsId; import org.thingsboard.server.common.data.id.DeviceCredentialsId;
import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceId;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTest { public abstract class BaseDeviceCredentialsServiceTest extends AbstractServiceTest {
private TenantId tenantId; @Autowired
DeviceCredentialsService deviceCredentialsService;
@Before @Autowired
public void before() { DeviceService deviceService;
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testCreateDeviceCredentials() { public void testCreateDeviceCredentials() {

32
dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceProfileServiceTest.java

@ -19,24 +19,24 @@ import com.google.common.util.concurrent.Futures;
import com.google.common.util.concurrent.ListenableFuture; import com.google.common.util.concurrent.ListenableFuture;
import com.google.common.util.concurrent.ListeningExecutorService; import com.google.common.util.concurrent.ListeningExecutorService;
import com.google.common.util.concurrent.MoreExecutors; import com.google.common.util.concurrent.MoreExecutors;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Ignore; import org.junit.Ignore;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.ThingsBoardThreadFactory; import org.thingsboard.common.util.ThingsBoardThreadFactory;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceProfileInfo; import org.thingsboard.server.common.data.DeviceProfileInfo;
import org.thingsboard.server.common.data.DeviceTransportType; import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.OtaPackage; import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.ota.ChecksumAlgorithm; import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.ota.OtaPackageService;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,7 +44,6 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import java.util.concurrent.ExecutionException; import java.util.concurrent.ExecutionException;
import java.util.concurrent.Executors; import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
@ -52,25 +51,16 @@ import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
public abstract class BaseDeviceProfileServiceTest extends AbstractServiceTest { public abstract class BaseDeviceProfileServiceTest extends AbstractServiceTest {
@Autowired
DeviceProfileService deviceProfileService;
@Autowired
DeviceService deviceService;
@Autowired
OtaPackageService otaPackageService;
private IdComparator<DeviceProfile> idComparator = new IdComparator<>(); private IdComparator<DeviceProfile> idComparator = new IdComparator<>();
private IdComparator<DeviceProfileInfo> deviceProfileInfoIdComparator = new IdComparator<>(); private IdComparator<DeviceProfileInfo> deviceProfileInfoIdComparator = new IdComparator<>();
private TenantId tenantId;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveDeviceProfile() { public void testSaveDeviceProfile() {
DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile"); DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");

52
dao/src/test/java/org/thingsboard/server/dao/service/BaseDeviceServiceTest.java

@ -19,10 +19,9 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.junit.rules.ExpectedException; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceInfo; import org.thingsboard.server.common.data.DeviceInfo;
@ -40,26 +39,43 @@ import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.security.DeviceCredentials; import org.thingsboard.server.common.data.security.DeviceCredentials;
import org.thingsboard.server.common.data.security.DeviceCredentialsType; import org.thingsboard.server.common.data.security.DeviceCredentialsType;
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.device.DeviceCredentialsService;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID; import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
public abstract class BaseDeviceServiceTest extends AbstractServiceTest { public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
private IdComparator<Device> idComparator = new IdComparator<>(); @Autowired
CustomerService customerService;
@Autowired
DeviceCredentialsService deviceCredentialsService;
@Autowired
DeviceProfileService deviceProfileService;
@Autowired
DeviceService deviceService;
@Autowired
OtaPackageService otaPackageService;
@Autowired
TenantProfileService tenantProfileService;
private TenantId tenantId; private IdComparator<Device> idComparator = new IdComparator<>();
private TenantId anotherTenantId; private TenantId anotherTenantId;
@Before @Before
public void before() { public void before() {
tenantId = createTenant();
anotherTenantId = createTenant(); anotherTenantId = createTenant();
} }
@ -72,10 +88,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
tenantProfileService.deleteTenantProfiles(anotherTenantId); tenantProfileService.deleteTenantProfiles(anotherTenantId);
} }
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@Test @Test
public void testSaveDevicesWithoutMaxDeviceLimit() { public void testSaveDevicesWithoutMaxDeviceLimit() {
Device device = this.saveDevice(tenantId, "My device"); Device device = this.saveDevice(tenantId, "My device");
@ -244,9 +256,9 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
savedDevice.setFirmwareId(savedFirmware.getId()); savedDevice.setFirmwareId(savedFirmware.getId());
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> deviceService.saveDevice(savedDevice))
thrown.expectMessage("Can't assign firmware with different deviceProfile!"); .isInstanceOf(DataValidationException.class)
deviceService.saveDevice(savedDevice); .hasMessageContaining("Can't assign firmware with different deviceProfile!");
} }
@Test @Test
@ -389,12 +401,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindDevicesByTenantId() { public void testFindDevicesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Device> devices = new ArrayList<>(); List<Device> devices = new ArrayList<>();
for (int i = 0; i < 178; i++) { for (int i = 0; i < 178; i++) {
Device device = new Device(); Device device = new Device();
@ -426,8 +432,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
pageData = deviceService.findDevicesByTenantId(tenantId, pageLink); pageData = deviceService.findDevicesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -588,12 +592,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindDevicesByTenantIdAndCustomerId() { public void testFindDevicesByTenantIdAndCustomerId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -632,8 +630,6 @@ public abstract class BaseDeviceServiceTest extends AbstractServiceTest {
pageData = deviceService.findDeviceInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink); pageData = deviceService.findDeviceInfosByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

9
dao/src/test/java/org/thingsboard/server/dao/service/BaseEdgeEventServiceTest.java

@ -21,6 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.edge.EdgeEvent; import org.thingsboard.server.common.data.edge.EdgeEvent;
import org.thingsboard.server.common.data.edge.EdgeEventActionType; import org.thingsboard.server.common.data.edge.EdgeEventActionType;
import org.thingsboard.server.common.data.edge.EdgeEventType; import org.thingsboard.server.common.data.edge.EdgeEventType;
@ -32,20 +33,20 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.SortOrder; import org.thingsboard.server.common.data.page.SortOrder;
import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.dao.edge.EdgeEventService;
import java.io.IOException; import java.io.IOException;
import java.text.ParseException; import java.text.ParseException;
import java.time.LocalDateTime;
import java.time.Month;
import java.time.ZoneOffset;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.TimeUnit;
import static org.apache.commons.lang3.time.DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT; import static org.apache.commons.lang3.time.DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT;
public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest { public abstract class BaseEdgeEventServiceTest extends AbstractServiceTest {
@Autowired
EdgeEventService edgeEventService;
long timeBeforeStartTime; long timeBeforeStartTime;
long startTime; long startTime;
long eventTime; long eventTime;

45
dao/src/test/java/org/thingsboard/server/dao/service/BaseEdgeServiceTest.java

@ -17,11 +17,10 @@ package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.databind.node.ObjectNode; import com.fasterxml.jackson.databind.node.ObjectNode;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.EntitySubtype; import org.thingsboard.server.common.data.EntitySubtype;
@ -36,7 +35,10 @@ import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData; import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.rule.RuleNode; import org.thingsboard.server.common.data.rule.RuleNode;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.rule.RuleChainService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -47,23 +49,14 @@ import static org.thingsboard.server.dao.model.ModelConstants.NULL_UUID;
public abstract class BaseEdgeServiceTest extends AbstractServiceTest { public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
private IdComparator<Edge> idComparator = new IdComparator<>(); @Autowired
CustomerService customerService;
private TenantId tenantId; @Autowired
EdgeService edgeService;
@Before @Autowired
public void before() { RuleChainService ruleChainService;
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After private IdComparator<Edge> idComparator = new IdComparator<>();
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveEdge() { public void testSaveEdge() {
@ -204,12 +197,6 @@ public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindEdgesByTenantId() { public void testFindEdgesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<Edge> edges = new ArrayList<>(); List<Edge> edges = new ArrayList<>();
for (int i = 0; i < 178; i++) { for (int i = 0; i < 178; i++) {
Edge edge = constructEdge(tenantId, "Edge " + i, "default"); Edge edge = constructEdge(tenantId, "Edge " + i, "default");
@ -238,8 +225,6 @@ public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
pageData = edgeService.findEdgesByTenantId(tenantId, pageLink); pageData = edgeService.findEdgesByTenantId(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -388,12 +373,6 @@ public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindEdgesByTenantIdAndCustomerId() { public void testFindEdgesByTenantIdAndCustomerId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -429,8 +408,6 @@ public abstract class BaseEdgeServiceTest extends AbstractServiceTest {
pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink); pageData = edgeService.findEdgesByTenantIdAndCustomerId(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

2
dao/src/test/java/org/thingsboard/server/dao/service/BaseEntityServiceRegistryTest.java

@ -28,7 +28,7 @@ import org.thingsboard.server.dao.rule.RuleChainService;
public abstract class BaseEntityServiceRegistryTest extends AbstractServiceTest { public abstract class BaseEntityServiceRegistryTest extends AbstractServiceTest {
@Autowired @Autowired
private EntityServiceRegistry entityServiceRegistry; EntityServiceRegistry entityServiceRegistry;
@Test @Test
public void givenAllEntityTypes_whenGetServiceByEntityTypeCalled_thenAllBeansExists() { public void givenAllEntityTypes_whenGetServiceByEntityTypeCalled_thenAllBeansExists() {

43
dao/src/test/java/org/thingsboard/server/dao/service/BaseEntityServiceTest.java

@ -21,9 +21,7 @@ import com.google.common.util.concurrent.ListenableFuture;
import lombok.extern.slf4j.Slf4j; import lombok.extern.slf4j.Slf4j;
import org.apache.commons.lang3.RandomUtils; import org.apache.commons.lang3.RandomUtils;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.jdbc.core.ResultSetExtractor; import org.springframework.jdbc.core.ResultSetExtractor;
@ -31,7 +29,6 @@ import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.Edge;
import org.thingsboard.server.common.data.id.CustomerId; import org.thingsboard.server.common.data.id.CustomerId;
@ -73,8 +70,13 @@ import org.thingsboard.server.common.data.relation.EntityRelation;
import org.thingsboard.server.common.data.relation.EntitySearchDirection; import org.thingsboard.server.common.data.relation.EntitySearchDirection;
import org.thingsboard.server.common.data.relation.RelationEntityTypeFilter; import org.thingsboard.server.common.data.relation.RelationEntityTypeFilter;
import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.attributes.AttributesService; import org.thingsboard.server.dao.attributes.AttributesService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entity.EntityService;
import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity; import org.thingsboard.server.dao.model.sqlts.ts.TsKvEntity;
import org.thingsboard.server.dao.relation.RelationService;
import org.thingsboard.server.dao.sql.relation.RelationRepository; import org.thingsboard.server.dao.sql.relation.RelationRepository;
import org.thingsboard.server.dao.timeseries.TimeseriesService; import org.thingsboard.server.dao.timeseries.TimeseriesService;
@ -100,30 +102,21 @@ public abstract class BaseEntityServiceTest extends AbstractServiceTest {
static final int ENTITY_COUNT = 5; static final int ENTITY_COUNT = 5;
@Autowired @Autowired
private AttributesService attributesService; AssetService assetService;
@Autowired @Autowired
private TimeseriesService timeseriesService; AttributesService attributesService;
private TenantId tenantId;
@Autowired @Autowired
private RelationRepository relationRepository; DeviceService deviceService;
@Autowired
@Before EdgeService edgeService;
public void before() { @Autowired
Tenant tenant = new Tenant(); EntityService entityService;
tenant.setTitle("My tenant"); @Autowired
Tenant savedTenant = tenantService.saveTenant(tenant); RelationRepository relationRepository;
Assert.assertNotNull(savedTenant); @Autowired
tenantId = savedTenant.getId(); RelationService relationService;
} @Autowired
TimeseriesService timeseriesService;
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testCountEntitiesByQuery() throws InterruptedException { public void testCountEntitiesByQuery() throws InterruptedException {

157
dao/src/test/java/org/thingsboard/server/dao/service/BaseOtaPackageServiceTest.java

@ -19,16 +19,14 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
import org.junit.rules.ExpectedException; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Device; import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile; import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.OtaPackage; import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.OtaPackageInfo; import org.thingsboard.server.common.data.OtaPackageInfo;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.TenantProfile; import org.thingsboard.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.id.DeviceProfileId; import org.thingsboard.server.common.data.id.DeviceProfileId;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
@ -36,7 +34,11 @@ import org.thingsboard.server.common.data.ota.ChecksumAlgorithm;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration; import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileConfiguration;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
@ -44,6 +46,7 @@ import java.util.Collections;
import java.util.List; import java.util.List;
import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE; import static org.thingsboard.server.common.data.ota.OtaPackageType.FIRMWARE;
public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest { public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
@ -60,28 +63,25 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
private final IdComparator<OtaPackageInfo> idComparator = new IdComparator<>(); private final IdComparator<OtaPackageInfo> idComparator = new IdComparator<>();
private TenantId tenantId;
private DeviceProfileId deviceProfileId; private DeviceProfileId deviceProfileId;
@Autowired
DeviceProfileService deviceProfileService;
@Autowired
DeviceService deviceService;
@Autowired
OtaPackageService otaPackageService;
@Autowired
TenantProfileService tenantProfileService;
@Before @Before
public void before() { public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile"); DeviceProfile deviceProfile = this.createDeviceProfile(tenantId, "Device Profile");
DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile); DeviceProfile savedDeviceProfile = deviceProfileService.saveDeviceProfile(deviceProfile);
Assert.assertNotNull(savedDeviceProfile); Assert.assertNotNull(savedDeviceProfile);
deviceProfileId = savedDeviceProfile.getId(); deviceProfileId = savedDeviceProfile.getId();
} }
@SuppressWarnings("deprecation")
@Rule
public ExpectedException thrown = ExpectedException.none();
@After @After
public void after() { public void after() {
tenantService.deleteTenant(tenantId); tenantService.deleteTenant(tenantId);
@ -99,9 +99,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
createAndSaveFirmware(tenantId, "1"); createAndSaveFirmware(tenantId, "1");
Assert.assertEquals(1, otaPackageService.sumDataSizeByTenantId(tenantId)); Assert.assertEquals(1, otaPackageService.sumDataSizeByTenantId(tenantId));
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> createAndSaveFirmware(tenantId, "2"))
thrown.expectMessage(String.format("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE)); .isInstanceOf(DataValidationException.class)
createAndSaveFirmware(tenantId, "2"); .hasMessageContaining("Failed to create the ota package, files size limit is exhausted %d bytes!", DATA_SIZE);
} }
@Test @Test
@ -243,9 +243,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage should be assigned to tenant!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage should be assigned to tenant!");
} }
@Test @Test
@ -261,9 +261,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("Type should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("Type should be specified!");
} }
@Test @Test
@ -279,9 +279,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage title should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage title should be specified!");
} }
@Test @Test
@ -297,9 +297,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage file name should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage file name should be specified!");
} }
@Test @Test
@ -315,9 +315,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage content type should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage content type should be specified!");
} }
@Test @Test
@ -333,9 +333,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM); firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage data should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage data should be specified!");
} }
@Test @Test
@ -352,9 +352,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage is referencing to non-existent tenant!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage is referencing to non-existent tenant!");
} }
@Test @Test
@ -371,9 +371,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksum(CHECKSUM); firmware.setChecksum(CHECKSUM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage is referencing to non-existent device profile!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage is referencing to non-existent device profile!");
} }
@Test @Test
@ -389,9 +389,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM); firmware.setChecksumAlgorithm(CHECKSUM_ALGORITHM);
firmware.setData(DATA); firmware.setData(DATA);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(firmware))
thrown.expectMessage("OtaPackage checksum should be specified!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackage(firmware); .hasMessageContaining("OtaPackage checksum should be specified!");
} }
@Test @Test
@ -411,17 +411,17 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
newFirmwareInfo.setTitle(TITLE); newFirmwareInfo.setTitle(TITLE);
newFirmwareInfo.setVersion(VERSION); newFirmwareInfo.setVersion(VERSION);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false))
thrown.expectMessage("OtaPackage with such title and version already exists!"); .isInstanceOf(DataValidationException.class)
otaPackageService.saveOtaPackageInfo(newFirmwareInfo, false); .hasMessageContaining("OtaPackage with such title and version already exists!");
} }
@Test @Test
public void testSaveFirmwareWithExistingTitleAndVersion() { public void testSaveFirmwareWithExistingTitleAndVersion() {
createAndSaveFirmware(tenantId, VERSION); createAndSaveFirmware(tenantId, VERSION);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> createAndSaveFirmware(tenantId, VERSION))
thrown.expectMessage("OtaPackage with such title and version already exists!"); .isInstanceOf(DataValidationException.class)
createAndSaveFirmware(tenantId, VERSION); .hasMessageContaining("OtaPackage with such title and version already exists!");
} }
@Test @Test
@ -436,9 +436,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
Device savedDevice = deviceService.saveDevice(device); Device savedDevice = deviceService.saveDevice(device);
try { try {
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()))
thrown.expectMessage("The otaPackage referenced by the devices cannot be deleted!"); .isInstanceOf(DataValidationException.class)
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); .hasMessageContaining("The otaPackage referenced by the devices cannot be deleted!");
} finally { } finally {
deviceService.deleteDevice(tenantId, savedDevice.getId()); deviceService.deleteDevice(tenantId, savedDevice.getId());
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
@ -448,12 +448,12 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
@Test @Test
public void testUpdateDeviceProfileId() { public void testUpdateDeviceProfileId() {
OtaPackage savedFirmware = createAndSaveFirmware(tenantId, VERSION); OtaPackage savedFirmware = createAndSaveFirmware(tenantId, VERSION);
savedFirmware.setDeviceProfileId(null);
try { try {
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackage(savedFirmware))
thrown.expectMessage("Updating otaPackage deviceProfile is prohibited!"); .isInstanceOf(DataValidationException.class)
savedFirmware.setDeviceProfileId(null); .hasMessageContaining("Updating otaPackage deviceProfile is prohibited!");
otaPackageService.saveOtaPackage(savedFirmware);
} finally { } finally {
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId());
} }
@ -482,9 +482,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
deviceProfileService.saveDeviceProfile(savedDeviceProfile); deviceProfileService.saveDeviceProfile(savedDeviceProfile);
try { try {
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()))
thrown.expectMessage("The otaPackage referenced by the device profile cannot be deleted!"); .isInstanceOf(DataValidationException.class)
otaPackageService.deleteOtaPackage(tenantId, savedFirmware.getId()); .hasMessageContaining("The otaPackage referenced by the device profile cannot be deleted!");
} finally { } finally {
deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId()); deviceProfileService.deleteDeviceProfile(tenantId, savedDeviceProfile.getId());
} }
@ -636,12 +636,18 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmwareInfo.setType(FIRMWARE); firmwareInfo.setType(FIRMWARE);
firmwareInfo.setTitle(TITLE); firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(VERSION); firmwareInfo.setVersion(VERSION);
firmwareInfo.setUrl(" "); firmwareInfo.setUrl(" ");
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
thrown.expectMessage("Ota package URL should be specified!"); .as("firmwareInfo url set whitespaces")
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); .isInstanceOf(DataValidationException.class)
.hasMessageContaining("Ota package URL should be specified!");
firmwareInfo.setUrl(""); firmwareInfo.setUrl("");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
.as("firmwareInfo url is empty")
.isInstanceOf(DataValidationException.class)
.hasMessageContaining("Ota package URL should be specified!");
} }
@Test @Test
@ -655,12 +661,10 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmwareInfo.setTenantId(tenantId); firmwareInfo.setTenantId(tenantId);
OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, true); OtaPackageInfo savedFirmwareInfo = otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
thrown.expect(DataValidationException.class);
thrown.expectMessage("Updating otaPackage URL is prohibited!");
savedFirmwareInfo.setUrl("https://newurl.com"); savedFirmwareInfo.setUrl("https://newurl.com");
otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(savedFirmwareInfo, true))
.isInstanceOf(DataValidationException.class)
.hasMessageContaining("Updating otaPackage URL is prohibited!");
} }
@Test @Test
@ -673,10 +677,9 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmwareInfo.setUrl(URL); firmwareInfo.setUrl(URL);
firmwareInfo.setTenantId(tenantId); firmwareInfo.setTenantId(tenantId);
thrown.expect(DataValidationException.class); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
thrown.expectMessage("title length must be equal or less than 255"); .isInstanceOf(DataValidationException.class)
.hasMessageContaining("title length must be equal or less than 255");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true);
} }
@Test @Test
@ -687,11 +690,11 @@ public abstract class BaseOtaPackageServiceTest extends AbstractServiceTest {
firmwareInfo.setUrl(URL); firmwareInfo.setUrl(URL);
firmwareInfo.setTenantId(tenantId); firmwareInfo.setTenantId(tenantId);
firmwareInfo.setTitle(TITLE); firmwareInfo.setTitle(TITLE);
firmwareInfo.setVersion(StringUtils.random(257)); firmwareInfo.setVersion(StringUtils.random(257));
thrown.expectMessage("version length must be equal or less than 255");
otaPackageService.saveOtaPackageInfo(firmwareInfo, true); assertThatThrownBy(() -> otaPackageService.saveOtaPackageInfo(firmwareInfo, true))
.isInstanceOf(DataValidationException.class)
.hasMessageContaining("version length must be equal or less than 255");
} }
private OtaPackage createAndSaveFirmware(TenantId tenantId, String version) { private OtaPackage createAndSaveFirmware(TenantId tenantId, String version) {

10
dao/src/test/java/org/thingsboard/server/dao/service/BaseQueueServiceTest.java

@ -20,6 +20,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.TenantProfile; import org.thingsboard.server.common.data.TenantProfile;
@ -35,6 +36,8 @@ import org.thingsboard.server.common.data.queue.SubmitStrategyType;
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; import org.thingsboard.server.common.data.tenant.profile.TenantProfileData;
import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration; import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.queue.QueueService;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -42,6 +45,11 @@ import java.util.List;
public abstract class BaseQueueServiceTest extends AbstractServiceTest { public abstract class BaseQueueServiceTest extends AbstractServiceTest {
@Autowired
TenantProfileService tenantProfileService;
@Autowired
QueueService queueService;
private IdComparator<Queue> idComparator = new IdComparator<>(); private IdComparator<Queue> idComparator = new IdComparator<>();
private TenantId tenantId; private TenantId tenantId;
@ -83,7 +91,7 @@ public abstract class BaseQueueServiceTest extends AbstractServiceTest {
Tenant tenant = new Tenant(); Tenant tenant = new Tenant();
tenant.setTitle("My tenant"); tenant.setTitle("My tenant");
tenant.setTenantProfileId(tenantProfileId); tenant.setTenantProfileId(tenantProfileId); //custom profile
Tenant savedTenant = tenantService.saveTenant(tenant); Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant); Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId(); tenantId = savedTenant.getId();

5
dao/src/test/java/org/thingsboard/server/dao/service/BaseRelationServiceTest.java

@ -23,6 +23,7 @@ import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EntityType; import org.thingsboard.server.common.data.EntityType;
import org.thingsboard.server.common.data.id.AssetId; import org.thingsboard.server.common.data.id.AssetId;
import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceId;
@ -33,6 +34,7 @@ import org.thingsboard.server.common.data.relation.RelationEntityTypeFilter;
import org.thingsboard.server.common.data.relation.RelationTypeGroup; import org.thingsboard.server.common.data.relation.RelationTypeGroup;
import org.thingsboard.server.common.data.relation.RelationsSearchParameters; import org.thingsboard.server.common.data.relation.RelationsSearchParameters;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.relation.RelationService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -42,6 +44,9 @@ import java.util.concurrent.ExecutionException;
public abstract class BaseRelationServiceTest extends AbstractServiceTest { public abstract class BaseRelationServiceTest extends AbstractServiceTest {
@Autowired
RelationService relationService;
@Before @Before
public void before() { public void before() {
} }

34
dao/src/test/java/org/thingsboard/server/dao/service/BaseRuleChainServiceTest.java

@ -17,11 +17,10 @@ package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.edge.Edge; import org.thingsboard.server.common.data.edge.Edge;
@ -34,7 +33,9 @@ import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainMetaData; import org.thingsboard.server.common.data.rule.RuleChainMetaData;
import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.rule.RuleNode; import org.thingsboard.server.common.data.rule.RuleNode;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.rule.RuleChainService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -46,25 +47,14 @@ import java.util.List;
*/ */
public abstract class BaseRuleChainServiceTest extends AbstractServiceTest { public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
@Autowired
EdgeService edgeService;
@Autowired
RuleChainService ruleChainService;
private IdComparator<RuleChain> idComparator = new IdComparator<>(); private IdComparator<RuleChain> idComparator = new IdComparator<>();
private IdComparator<RuleNode> ruleNodeIdComparator = new IdComparator<>(); private IdComparator<RuleNode> ruleNodeIdComparator = new IdComparator<>();
private TenantId tenantId;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveRuleChain() throws IOException { public void testSaveRuleChain() throws IOException {
RuleChain ruleChain = new RuleChain(); RuleChain ruleChain = new RuleChain();
@ -133,12 +123,6 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindRuleChainsByTenantId() { public void testFindRuleChainsByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<RuleChain> ruleChains = new ArrayList<>(); List<RuleChain> ruleChains = new ArrayList<>();
for (int i = 0; i < 165; i++) { for (int i = 0; i < 165; i++) {
RuleChain ruleChain = new RuleChain(); RuleChain ruleChain = new RuleChain();
@ -169,8 +153,6 @@ public abstract class BaseRuleChainServiceTest extends AbstractServiceTest {
pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink); pageData = ruleChainService.findTenantRuleChainsByType(tenantId, RuleChainType.CORE, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test

14
dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantProfileServiceTest.java

@ -18,8 +18,10 @@ package org.thingsboard.server.dao.service;
import com.fasterxml.jackson.databind.node.NullNode; import com.fasterxml.jackson.databind.node.NullNode;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.DataConstants; import org.thingsboard.server.common.data.DataConstants;
import org.thingsboard.server.common.data.EntityInfo; import org.thingsboard.server.common.data.EntityInfo;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
@ -36,6 +38,7 @@ import org.thingsboard.server.common.data.tenant.profile.DefaultTenantProfileCon
import org.thingsboard.server.common.data.tenant.profile.TenantProfileData; import org.thingsboard.server.common.data.tenant.profile.TenantProfileData;
import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration; import org.thingsboard.server.common.data.tenant.profile.TenantProfileQueueConfiguration;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -44,9 +47,20 @@ import java.util.stream.Collectors;
public abstract class BaseTenantProfileServiceTest extends AbstractServiceTest { public abstract class BaseTenantProfileServiceTest extends AbstractServiceTest {
@Autowired
TenantProfileService tenantProfileService;
private IdComparator<TenantProfile> idComparator = new IdComparator<>(); private IdComparator<TenantProfile> idComparator = new IdComparator<>();
private IdComparator<EntityInfo> tenantProfileInfoIdComparator = new IdComparator<>(); private IdComparator<EntityInfo> tenantProfileInfoIdComparator = new IdComparator<>();
@Before
public void before() {
//this test requires no Tenants in the database
tenantId = null;
tenantService.deleteTenants();
tenantProfileService.deleteTenantProfiles(TenantId.SYS_TENANT_ID);
}
@After @After
public void after() { public void after() {
tenantProfileService.deleteTenantProfiles(TenantId.SYS_TENANT_ID); tenantProfileService.deleteTenantProfiles(TenantId.SYS_TENANT_ID);

78
dao/src/test/java/org/thingsboard/server/dao/service/BaseTenantServiceTest.java

@ -23,24 +23,7 @@ import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.mock.mockito.SpyBean; import org.springframework.boot.test.mock.mockito.SpyBean;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.cache.TbTransactionalCache; import org.thingsboard.server.cache.TbTransactionalCache;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.*;
import org.thingsboard.server.common.data.Dashboard;
import org.thingsboard.server.common.data.DashboardInfo;
import org.thingsboard.server.common.data.Device;
import org.thingsboard.server.common.data.DeviceProfile;
import org.thingsboard.server.common.data.DeviceProfileType;
import org.thingsboard.server.common.data.DeviceTransportType;
import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.OtaPackage;
import org.thingsboard.server.common.data.OtaPackageInfo;
import org.thingsboard.server.common.data.ResourceType;
import org.thingsboard.server.common.data.StringUtils;
import org.thingsboard.server.common.data.TbResource;
import org.thingsboard.server.common.data.TbResourceInfo;
import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.TenantInfo;
import org.thingsboard.server.common.data.TenantProfile;
import org.thingsboard.server.common.data.User;
import org.thingsboard.server.common.data.asset.Asset; import org.thingsboard.server.common.data.asset.Asset;
import org.thingsboard.server.common.data.device.profile.DeviceProfileData; import org.thingsboard.server.common.data.device.profile.DeviceProfileData;
import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration; import org.thingsboard.server.common.data.device.profile.MqttDeviceProfileTransportConfiguration;
@ -54,8 +37,23 @@ import org.thingsboard.server.common.data.rule.RuleChain;
import org.thingsboard.server.common.data.rule.RuleChainType; import org.thingsboard.server.common.data.rule.RuleChainType;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.asset.AssetService;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.dashboard.DashboardService;
import org.thingsboard.server.dao.device.DeviceProfileService;
import org.thingsboard.server.dao.device.DeviceService;
import org.thingsboard.server.dao.edge.EdgeService;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.ota.OtaPackageService;
import org.thingsboard.server.dao.resource.ResourceService;
import org.thingsboard.server.dao.rpc.RpcService;
import org.thingsboard.server.dao.rule.RuleChainService;
import org.thingsboard.server.dao.tenant.TenantDao; import org.thingsboard.server.dao.tenant.TenantDao;
import org.thingsboard.server.dao.tenant.TenantProfileService;
import org.thingsboard.server.dao.usagerecord.ApiUsageStateService;
import org.thingsboard.server.dao.user.UserService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -69,16 +67,45 @@ import static org.mockito.Mockito.verify;
public abstract class BaseTenantServiceTest extends AbstractServiceTest { public abstract class BaseTenantServiceTest extends AbstractServiceTest {
private IdComparator<Tenant> idComparator = new IdComparator<>();
@SpyBean @SpyBean
protected TenantDao tenantDao; TenantDao tenantDao;
@Autowired @Autowired
protected TbTransactionalCache<TenantId, Tenant> cache; ApiUsageStateService apiUsageStateService;
@Autowired
AssetService assetService;
@Autowired
CustomerService customerService;
@Autowired
DashboardService dashboardService;
@Autowired
DeviceProfileService deviceProfileService;
@Autowired
DeviceService deviceService;
@Autowired
EdgeService edgeService;
@Autowired
EntityViewService entityViewService;
@Autowired
OtaPackageService otaPackageService;
@Autowired @Autowired
protected TbTransactionalCache<TenantId, Boolean> existsTenantCache; ResourceService resourceService;
@Autowired
RpcService rpcService;
@Autowired
RuleChainService ruleChainService;
@Autowired
TbTransactionalCache<TenantId, Boolean> existsTenantCache;
@Autowired
TbTransactionalCache<TenantId, Tenant> cache;
@Autowired
TenantProfileService tenantProfileService;
@Autowired
UserService userService;
@Autowired
WidgetsBundleService widgetsBundleService;
private final IdComparator<Tenant> idComparator = new IdComparator<>();
@Test @Test
public void testSaveTenant() { public void testSaveTenant() {
@ -150,6 +177,7 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindTenants() { public void testFindTenants() {
tenantService.deleteTenants();
List<Tenant> tenants = new ArrayList<>(); List<Tenant> tenants = new ArrayList<>();
PageLink pageLink = new PageLink(17); PageLink pageLink = new PageLink(17);
PageData<Tenant> pageData = tenantService.findTenants(pageLink); PageData<Tenant> pageData = tenantService.findTenants(pageLink);
@ -264,7 +292,7 @@ public abstract class BaseTenantServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindTenantInfos() { public void testFindTenantInfos() {
tenantService.deleteTenants();
List<TenantInfo> tenants = new ArrayList<>(); List<TenantInfo> tenants = new ArrayList<>();
PageLink pageLink = new PageLink(17); PageLink pageLink = new PageLink(17);
PageData<TenantInfo> pageData = tenantService.findTenantInfos(pageLink); PageData<TenantInfo> pageData = tenantService.findTenantInfos(pageLink);

57
dao/src/test/java/org/thingsboard/server/dao/service/BaseUserServiceTest.java

@ -15,11 +15,11 @@
*/ */
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.common.util.JacksonUtil; import org.thingsboard.common.util.JacksonUtil;
import org.thingsboard.server.common.data.Customer; import org.thingsboard.server.common.data.Customer;
import org.thingsboard.server.common.data.StringUtils; import org.thingsboard.server.common.data.StringUtils;
@ -33,7 +33,9 @@ import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.security.Authority; import org.thingsboard.server.common.data.security.Authority;
import org.thingsboard.server.common.data.security.UserCredentials; import org.thingsboard.server.common.data.security.UserCredentials;
import org.thingsboard.server.common.data.security.UserSettings; import org.thingsboard.server.common.data.security.UserSettings;
import org.thingsboard.server.dao.customer.CustomerService;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.user.UserService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -41,19 +43,17 @@ import java.util.List;
public abstract class BaseUserServiceTest extends AbstractServiceTest { public abstract class BaseUserServiceTest extends AbstractServiceTest {
@Autowired
CustomerService customerService;
@Autowired
UserService userService;
private IdComparator<User> idComparator = new IdComparator<>(); private IdComparator<User> idComparator = new IdComparator<>();
private TenantId tenantId;
private UserSettings userSettings; private UserSettings userSettings;
@Before @Before
public void before() { public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
User tenantAdmin = new User(); User tenantAdmin = new User();
tenantAdmin.setAuthority(Authority.TENANT_ADMIN); tenantAdmin.setAuthority(Authority.TENANT_ADMIN);
tenantAdmin.setTenantId(tenantId); tenantAdmin.setTenantId(tenantId);
@ -75,11 +75,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
userSettings = createUserSettings(customerUser.getId()); userSettings = createUserSettings(customerUser.getId());
} }
@After
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testFindUserByEmail() { public void testFindUserByEmail() {
User user = userService.findUserByEmail(SYSTEM_TENANT_ID, "sysadmin@thingsboard.org"); User user = userService.findUserByEmail(SYSTEM_TENANT_ID, "sysadmin@thingsboard.org");
@ -209,17 +204,13 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
Assert.assertEquals(1, users.size()); Assert.assertEquals(1, users.size());
Assert.assertEquals(tenantAdminUser, users.get(0)); Assert.assertEquals(tenantAdminUser, users.get(0));
Tenant tenant = new Tenant(); TenantId secondTenantId = createTenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<User> tenantAdmins = new ArrayList<>(); List<User> tenantAdmins = new ArrayList<>();
for (int i = 0; i < 124; i++) { for (int i = 0; i < 124; i++) {
User user = new User(); User user = new User();
user.setAuthority(Authority.TENANT_ADMIN); user.setAuthority(Authority.TENANT_ADMIN);
user.setTenantId(tenantId); user.setTenantId(secondTenantId);
user.setEmail("testTenant" + i + "@thingsboard.org"); user.setEmail("testTenant" + i + "@thingsboard.org");
tenantAdmins.add(userService.saveUser(user)); tenantAdmins.add(userService.saveUser(user));
} }
@ -227,7 +218,7 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
List<User> loadedTenantAdmins = new ArrayList<>(); List<User> loadedTenantAdmins = new ArrayList<>();
PageLink pageLink = new PageLink(33); PageLink pageLink = new PageLink(33);
do { do {
pageData = userService.findTenantAdmins(tenantId, pageLink); pageData = userService.findTenantAdmins(secondTenantId, pageLink);
loadedTenantAdmins.addAll(pageData.getData()); loadedTenantAdmins.addAll(pageData.getData());
if (pageData.hasNext()) { if (pageData.hasNext()) {
pageLink = pageLink.nextPageLink(); pageLink = pageLink.nextPageLink();
@ -239,10 +230,10 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
Assert.assertEquals(tenantAdmins, loadedTenantAdmins); Assert.assertEquals(tenantAdmins, loadedTenantAdmins);
tenantService.deleteTenant(tenantId); tenantService.deleteTenant(secondTenantId);
pageLink = new PageLink(33); pageLink = new PageLink(33);
pageData = userService.findTenantAdmins(tenantId, pageLink); pageData = userService.findTenantAdmins(secondTenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
@ -250,12 +241,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindTenantAdminsByEmail() { public void testFindTenantAdminsByEmail() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
String email1 = "testEmail1"; String email1 = "testEmail1";
List<User> tenantAdminsEmail1 = new ArrayList<>(); List<User> tenantAdminsEmail1 = new ArrayList<>();
@ -332,8 +317,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
pageData = userService.findTenantAdmins(tenantId, pageLink); pageData = userService.findTenantAdmins(tenantId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size()); Assert.assertEquals(0, pageData.getData().size());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -346,12 +329,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
Assert.assertEquals(1, users.size()); Assert.assertEquals(1, users.size());
Assert.assertEquals(customerUser, users.get(0)); Assert.assertEquals(customerUser, users.get(0));
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -394,12 +371,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindCustomerUsersByEmail() { public void testFindCustomerUsersByEmail() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
Customer customer = new Customer(); Customer customer = new Customer();
customer.setTitle("Test customer"); customer.setTitle("Test customer");
customer.setTenantId(tenantId); customer.setTenantId(tenantId);
@ -485,8 +456,6 @@ public abstract class BaseUserServiceTest extends AbstractServiceTest {
pageData = userService.findCustomerUsers(tenantId, customerId, pageLink); pageData = userService.findCustomerUsers(tenantId, customerId, pageLink);
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertEquals(0, pageData.getData().size()); Assert.assertEquals(0, pageData.getData().size());
tenantService.deleteTenant(tenantId);
} }
private UserSettings createUserSettings(UserId userId) { private UserSettings createUserSettings(UserId userId) {

27
dao/src/test/java/org/thingsboard/server/dao/service/BaseWidgetTypeServiceTest.java

@ -18,18 +18,18 @@ package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.thingsboard.server.common.data.Tenant; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.widget.WidgetType; import org.thingsboard.server.common.data.widget.WidgetType;
import org.thingsboard.server.common.data.widget.WidgetTypeDetails; import org.thingsboard.server.common.data.widget.WidgetTypeDetails;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.widget.WidgetTypeService;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -38,23 +38,12 @@ import java.util.List;
public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest { public abstract class BaseWidgetTypeServiceTest extends AbstractServiceTest {
private IdComparator<WidgetType> idComparator = new IdComparator<>(); @Autowired
WidgetsBundleService widgetsBundleService;
private TenantId tenantId; @Autowired
WidgetTypeService widgetTypeService;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After private IdComparator<WidgetType> idComparator = new IdComparator<>();
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveWidgetType() throws IOException { public void testSaveWidgetType() throws IOException {

44
dao/src/test/java/org/thingsboard/server/dao/service/BaseWidgetsBundleServiceTest.java

@ -16,18 +16,17 @@
package org.thingsboard.server.dao.service; package org.thingsboard.server.dao.service;
import com.datastax.oss.driver.api.core.uuid.Uuids; import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Assertions;
import org.thingsboard.server.common.data.Tenant; import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.id.TenantId; import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.PageLink; import org.thingsboard.server.common.data.page.PageLink;
import org.thingsboard.server.common.data.widget.WidgetsBundle; import org.thingsboard.server.common.data.widget.WidgetsBundle;
import org.thingsboard.server.dao.exception.DataValidationException; import org.thingsboard.server.dao.exception.DataValidationException;
import org.thingsboard.server.dao.model.ModelConstants; import org.thingsboard.server.dao.model.ModelConstants;
import org.thingsboard.server.dao.widget.WidgetsBundleService;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
@ -36,23 +35,10 @@ import java.util.List;
public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest { public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
private IdComparator<WidgetsBundle> idComparator = new IdComparator<>(); @Autowired
WidgetsBundleService widgetsBundleService;
private TenantId tenantId;
@Before
public void before() {
Tenant tenant = new Tenant();
tenant.setTitle("My tenant");
Tenant savedTenant = tenantService.saveTenant(tenant);
Assert.assertNotNull(savedTenant);
tenantId = savedTenant.getId();
}
@After private IdComparator<WidgetsBundle> idComparator = new IdComparator<>();
public void after() {
tenantService.deleteTenant(tenantId);
}
@Test @Test
public void testSaveWidgetsBundle() throws IOException { public void testSaveWidgetsBundle() throws IOException {
@ -249,11 +235,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
@Test @Test
public void testFindTenantWidgetsBundlesByTenantId() { public void testFindTenantWidgetsBundlesByTenantId() {
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
List<WidgetsBundle> widgetsBundles = new ArrayList<>(); List<WidgetsBundle> widgetsBundles = new ArrayList<>();
for (int i=0;i<127;i++) { for (int i=0;i<127;i++) {
@ -286,7 +267,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
Assert.assertFalse(pageData.hasNext()); Assert.assertFalse(pageData.hasNext());
Assert.assertTrue(pageData.getData().isEmpty()); Assert.assertTrue(pageData.getData().isEmpty());
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -294,11 +274,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId); List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId);
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
TenantId systemTenantId = TenantId.fromUUID(ModelConstants.NULL_UUID); TenantId systemTenantId = TenantId.fromUUID(ModelConstants.NULL_UUID);
List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>(); List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
@ -371,8 +346,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
Collections.sort(loadedWidgetsBundles, idComparator); Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles); Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
tenantService.deleteTenant(tenantId);
} }
@Test @Test
@ -380,11 +353,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId); List<WidgetsBundle> systemWidgetsBundles = widgetsBundleService.findSystemWidgetsBundles(tenantId);
Tenant tenant = new Tenant();
tenant.setTitle("Test tenant");
tenant = tenantService.saveTenant(tenant);
TenantId tenantId = tenant.getId();
TenantId systemTenantId = TenantId.fromUUID(ModelConstants.NULL_UUID); TenantId systemTenantId = TenantId.fromUUID(ModelConstants.NULL_UUID);
List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>(); List<WidgetsBundle> createdWidgetsBundles = new ArrayList<>();
@ -432,8 +400,6 @@ public abstract class BaseWidgetsBundleServiceTest extends AbstractServiceTest {
Collections.sort(loadedWidgetsBundles, idComparator); Collections.sort(loadedWidgetsBundles, idComparator);
Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles); Assert.assertEquals(systemWidgetsBundles, loadedWidgetsBundles);
tenantService.deleteTenant(tenantId);
} }
} }

6
dao/src/test/java/org/thingsboard/server/dao/service/event/BaseEventServiceTest.java

@ -19,6 +19,7 @@ import com.datastax.oss.driver.api.core.uuid.Uuids;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EventInfo; import org.thingsboard.server.common.data.EventInfo;
import org.thingsboard.server.common.data.event.Event; import org.thingsboard.server.common.data.event.Event;
import org.thingsboard.server.common.data.event.EventType; import org.thingsboard.server.common.data.event.EventType;
@ -31,6 +32,7 @@ import org.thingsboard.server.common.data.id.TenantId;
import org.thingsboard.server.common.data.page.PageData; import org.thingsboard.server.common.data.page.PageData;
import org.thingsboard.server.common.data.page.SortOrder; import org.thingsboard.server.common.data.page.SortOrder;
import org.thingsboard.server.common.data.page.TimePageLink; import org.thingsboard.server.common.data.page.TimePageLink;
import org.thingsboard.server.dao.event.EventService;
import org.thingsboard.server.dao.service.AbstractServiceTest; import org.thingsboard.server.dao.service.AbstractServiceTest;
import java.text.ParseException; import java.text.ParseException;
@ -39,6 +41,10 @@ import java.util.List;
import static org.apache.commons.lang3.time.DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT; import static org.apache.commons.lang3.time.DateFormatUtils.ISO_DATETIME_TIME_ZONE_FORMAT;
public abstract class BaseEventServiceTest extends AbstractServiceTest { public abstract class BaseEventServiceTest extends AbstractServiceTest {
@Autowired
EventService eventService;
long timeBeforeStartTime; long timeBeforeStartTime;
long startTime; long startTime;
long eventTime; long eventTime;

10
dao/src/test/java/org/thingsboard/server/dao/service/timeseries/BaseTimeseriesServiceTest.java

@ -21,6 +21,7 @@ import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.thingsboard.server.common.data.EntityView; import org.thingsboard.server.common.data.EntityView;
import org.thingsboard.server.common.data.Tenant; import org.thingsboard.server.common.data.Tenant;
import org.thingsboard.server.common.data.id.DeviceId; import org.thingsboard.server.common.data.id.DeviceId;
@ -39,7 +40,9 @@ import org.thingsboard.server.common.data.kv.ReadTsKvQueryResult;
import org.thingsboard.server.common.data.kv.StringDataEntry; import org.thingsboard.server.common.data.kv.StringDataEntry;
import org.thingsboard.server.common.data.kv.TsKvEntry; import org.thingsboard.server.common.data.kv.TsKvEntry;
import org.thingsboard.server.common.data.objects.TelemetryEntityView; import org.thingsboard.server.common.data.objects.TelemetryEntityView;
import org.thingsboard.server.dao.entityview.EntityViewService;
import org.thingsboard.server.dao.service.AbstractServiceTest; import org.thingsboard.server.dao.service.AbstractServiceTest;
import org.thingsboard.server.dao.timeseries.TimeseriesService;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
@ -59,6 +62,13 @@ import static org.junit.Assert.assertNotNull;
@Slf4j @Slf4j
public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest { public abstract class BaseTimeseriesServiceTest extends AbstractServiceTest {
@Autowired
TimeseriesService tsService;
@Autowired
EntityViewService entityViewService;
static final int MAX_TIMEOUT = 30; static final int MAX_TIMEOUT = 30;
private static final String STRING_KEY = "stringKey"; private static final String STRING_KEY = "stringKey";

Loading…
Cancel
Save