DefaultTbClusterService.getRuleEngineProfileForEntityOrElseNull - Added unit tests
This commit is contained in:
parent
a2e4cb9a7d
commit
b7c505efcd
@ -216,7 +216,7 @@ public class DefaultTbClusterService implements TbClusterService {
|
|||||||
toRuleEngineMsgs.incrementAndGet();
|
toRuleEngineMsgs.incrementAndGet();
|
||||||
}
|
}
|
||||||
|
|
||||||
private HasRuleEngineProfile getRuleEngineProfileForEntityOrElseNull(TenantId tenantId, EntityId entityId, TbMsg tbMsg) {
|
HasRuleEngineProfile getRuleEngineProfileForEntityOrElseNull(TenantId tenantId, EntityId entityId, TbMsg tbMsg) {
|
||||||
if (entityId.getEntityType().equals(EntityType.DEVICE)) {
|
if (entityId.getEntityType().equals(EntityType.DEVICE)) {
|
||||||
if (TbMsgType.ENTITY_DELETED.equals(tbMsg.getInternalType())) {
|
if (TbMsgType.ENTITY_DELETED.equals(tbMsg.getInternalType())) {
|
||||||
try {
|
try {
|
||||||
|
|||||||
@ -23,11 +23,20 @@ import org.springframework.boot.test.mock.mockito.MockBean;
|
|||||||
import org.springframework.boot.test.mock.mockito.SpyBean;
|
import org.springframework.boot.test.mock.mockito.SpyBean;
|
||||||
import org.springframework.test.context.ContextConfiguration;
|
import org.springframework.test.context.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringRunner;
|
import org.springframework.test.context.junit4.SpringRunner;
|
||||||
|
import org.thingsboard.common.util.JacksonUtil;
|
||||||
import org.thingsboard.server.cluster.TbClusterService;
|
import org.thingsboard.server.cluster.TbClusterService;
|
||||||
import org.thingsboard.server.common.data.DataConstants;
|
import org.thingsboard.server.common.data.DataConstants;
|
||||||
|
import org.thingsboard.server.common.data.Device;
|
||||||
|
import org.thingsboard.server.common.data.asset.Asset;
|
||||||
|
import org.thingsboard.server.common.data.id.AssetId;
|
||||||
|
import org.thingsboard.server.common.data.id.AssetProfileId;
|
||||||
|
import org.thingsboard.server.common.data.id.DeviceId;
|
||||||
|
import org.thingsboard.server.common.data.id.DeviceProfileId;
|
||||||
import org.thingsboard.server.common.data.id.QueueId;
|
import org.thingsboard.server.common.data.id.QueueId;
|
||||||
import org.thingsboard.server.common.data.id.TenantId;
|
import org.thingsboard.server.common.data.id.TenantId;
|
||||||
|
import org.thingsboard.server.common.data.msg.TbMsgType;
|
||||||
import org.thingsboard.server.common.data.queue.Queue;
|
import org.thingsboard.server.common.data.queue.Queue;
|
||||||
|
import org.thingsboard.server.common.msg.TbMsg;
|
||||||
import org.thingsboard.server.common.msg.queue.ServiceType;
|
import org.thingsboard.server.common.msg.queue.ServiceType;
|
||||||
import org.thingsboard.server.dao.edge.EdgeService;
|
import org.thingsboard.server.dao.edge.EdgeService;
|
||||||
import org.thingsboard.server.gen.transport.TransportProtos;
|
import org.thingsboard.server.gen.transport.TransportProtos;
|
||||||
@ -249,4 +258,44 @@ public class DefaultTbClusterServiceTest {
|
|||||||
queue.setPartitions(10);
|
queue.setPartitions(10);
|
||||||
return queue;
|
return queue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRuleEngineProfileForUpdatedAndDeletedDevice() {
|
||||||
|
DeviceId deviceId = new DeviceId(UUID.randomUUID());
|
||||||
|
TenantId tenantId = new TenantId(UUID.randomUUID());
|
||||||
|
DeviceProfileId deviceProfileId = new DeviceProfileId(UUID.randomUUID());
|
||||||
|
|
||||||
|
Device device = new Device(deviceId);
|
||||||
|
device.setDeviceProfileId(deviceProfileId);
|
||||||
|
|
||||||
|
// device updated
|
||||||
|
TbMsg tbMsg = TbMsg.builder().internalType(TbMsgType.ENTITY_UPDATED).build();
|
||||||
|
((DefaultTbClusterService) clusterService).getRuleEngineProfileForEntityOrElseNull(tenantId, deviceId, tbMsg);
|
||||||
|
verify(deviceProfileCache, times(1)).get(tenantId, deviceId);
|
||||||
|
|
||||||
|
// device deleted
|
||||||
|
tbMsg = TbMsg.builder().internalType(TbMsgType.ENTITY_DELETED).data(JacksonUtil.toString(device)).build();
|
||||||
|
((DefaultTbClusterService) clusterService).getRuleEngineProfileForEntityOrElseNull(tenantId, deviceId, tbMsg);
|
||||||
|
verify(deviceProfileCache, times(1)).get(tenantId, deviceProfileId);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetRuleEngineProfileForUpdatedAndDeletedAsset() {
|
||||||
|
AssetId assetId = new AssetId(UUID.randomUUID());
|
||||||
|
TenantId tenantId = new TenantId(UUID.randomUUID());
|
||||||
|
AssetProfileId assetProfileId = new AssetProfileId(UUID.randomUUID());
|
||||||
|
|
||||||
|
Asset asset = new Asset(assetId);
|
||||||
|
asset.setAssetProfileId(assetProfileId);
|
||||||
|
|
||||||
|
// asset updated
|
||||||
|
TbMsg tbMsg = TbMsg.builder().internalType(TbMsgType.ENTITY_UPDATED).build();
|
||||||
|
((DefaultTbClusterService) clusterService).getRuleEngineProfileForEntityOrElseNull(tenantId, assetId, tbMsg);
|
||||||
|
verify(assetProfileCache, times(1)).get(tenantId, assetId);
|
||||||
|
|
||||||
|
// asset deleted
|
||||||
|
tbMsg = TbMsg.builder().internalType(TbMsgType.ENTITY_DELETED).data(JacksonUtil.toString(asset)).build();
|
||||||
|
((DefaultTbClusterService) clusterService).getRuleEngineProfileForEntityOrElseNull(tenantId, assetId, tbMsg);
|
||||||
|
verify(assetProfileCache, times(1)).get(tenantId, assetProfileId);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
Loading…
x
Reference in New Issue
Block a user