Commit d1da8490617561331954ed9304ee4648a783223e
Committed by
Andrew Shvayka
1 parent
47e82b3c
Correction of tests for DeviceProfile
Showing
1 changed file
with
35 additions
and
21 deletions
@@ -50,11 +50,9 @@ import org.thingsboard.server.common.data.kv.AttributeKvEntry; | @@ -50,11 +50,9 @@ import org.thingsboard.server.common.data.kv.AttributeKvEntry; | ||
50 | import org.thingsboard.server.common.data.query.BooleanFilterPredicate; | 50 | import org.thingsboard.server.common.data.query.BooleanFilterPredicate; |
51 | import org.thingsboard.server.common.data.query.DynamicValue; | 51 | import org.thingsboard.server.common.data.query.DynamicValue; |
52 | import org.thingsboard.server.common.data.query.DynamicValueSourceType; | 52 | import org.thingsboard.server.common.data.query.DynamicValueSourceType; |
53 | -import org.thingsboard.server.common.data.query.EntityKey; | ||
54 | import org.thingsboard.server.common.data.query.EntityKeyType; | 53 | import org.thingsboard.server.common.data.query.EntityKeyType; |
55 | import org.thingsboard.server.common.data.query.EntityKeyValueType; | 54 | import org.thingsboard.server.common.data.query.EntityKeyValueType; |
56 | import org.thingsboard.server.common.data.query.FilterPredicateValue; | 55 | import org.thingsboard.server.common.data.query.FilterPredicateValue; |
57 | -import org.thingsboard.server.common.data.query.KeyFilter; | ||
58 | import org.thingsboard.server.common.data.query.NumericFilterPredicate; | 56 | import org.thingsboard.server.common.data.query.NumericFilterPredicate; |
59 | import org.thingsboard.server.common.msg.TbMsg; | 57 | import org.thingsboard.server.common.msg.TbMsg; |
60 | import org.thingsboard.server.common.msg.TbMsgDataType; | 58 | import org.thingsboard.server.common.msg.TbMsgDataType; |
@@ -74,7 +72,6 @@ import java.util.TreeMap; | @@ -74,7 +72,6 @@ import java.util.TreeMap; | ||
74 | import java.util.UUID; | 72 | import java.util.UUID; |
75 | 73 | ||
76 | import static org.mockito.ArgumentMatchers.eq; | 74 | import static org.mockito.ArgumentMatchers.eq; |
77 | -import static org.mockito.Mockito.mock; | ||
78 | import static org.mockito.Mockito.verify; | 75 | import static org.mockito.Mockito.verify; |
79 | 76 | ||
80 | @RunWith(MockitoJUnitRunner.class) | 77 | @RunWith(MockitoJUnitRunner.class) |
@@ -386,10 +383,6 @@ public class TbDeviceProfileNodeTest { | @@ -386,10 +383,6 @@ public class TbDeviceProfileNodeTest { | ||
386 | deviceProfile.setId(deviceProfileId); | 383 | deviceProfile.setId(deviceProfileId); |
387 | DeviceProfileData deviceProfileData = new DeviceProfileData(); | 384 | DeviceProfileData deviceProfileData = new DeviceProfileData(); |
388 | 385 | ||
389 | - Device device = new Device(); | ||
390 | - device.setId(deviceId); | ||
391 | - device.setCustomerId(customerId); | ||
392 | - | ||
393 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( | 386 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( |
394 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "greaterAttribute" | 387 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "greaterAttribute" |
395 | ); | 388 | ); |
@@ -464,7 +457,7 @@ public class TbDeviceProfileNodeTest { | @@ -464,7 +457,7 @@ public class TbDeviceProfileNodeTest { | ||
464 | device.setCustomerId(customerId); | 457 | device.setCustomerId(customerId); |
465 | 458 | ||
466 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( | 459 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( |
467 | - EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "lessAttribute" | 460 | + EntityType.CUSTOMER, deviceId.getId(), "SERVER_SCOPE", "lessAttribute" |
468 | ); | 461 | ); |
469 | 462 | ||
470 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); | 463 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); |
@@ -474,7 +467,7 @@ public class TbDeviceProfileNodeTest { | @@ -474,7 +467,7 @@ public class TbDeviceProfileNodeTest { | ||
474 | 467 | ||
475 | AttributeKvEntry entry = attributeKvEntity.toData(); | 468 | AttributeKvEntry entry = attributeKvEntity.toData(); |
476 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = | 469 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = |
477 | - Futures.immediateFuture(Collections.singletonList(entry)); | 470 | + Futures.immediateFuture(Collections.emptyList()); |
478 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = | 471 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = |
479 | Futures.immediateFuture(Optional.of(entry)); | 472 | Futures.immediateFuture(Optional.of(entry)); |
480 | 473 | ||
@@ -538,10 +531,6 @@ public class TbDeviceProfileNodeTest { | @@ -538,10 +531,6 @@ public class TbDeviceProfileNodeTest { | ||
538 | DeviceProfile deviceProfile = new DeviceProfile(); | 531 | DeviceProfile deviceProfile = new DeviceProfile(); |
539 | DeviceProfileData deviceProfileData = new DeviceProfileData(); | 532 | DeviceProfileData deviceProfileData = new DeviceProfileData(); |
540 | 533 | ||
541 | - Device device = new Device(); | ||
542 | - device.setId(deviceId); | ||
543 | - device.setCustomerId(customerId); | ||
544 | - | ||
545 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( | 534 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( |
546 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "lessAttribute" | 535 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "lessAttribute" |
547 | ); | 536 | ); |
@@ -553,7 +542,7 @@ public class TbDeviceProfileNodeTest { | @@ -553,7 +542,7 @@ public class TbDeviceProfileNodeTest { | ||
553 | 542 | ||
554 | AttributeKvEntry entry = attributeKvEntity.toData(); | 543 | AttributeKvEntry entry = attributeKvEntity.toData(); |
555 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = | 544 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = |
556 | - Futures.immediateFuture(Collections.singletonList(entry)); | 545 | + Futures.immediateFuture(Collections.emptyList()); |
557 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = | 546 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = |
558 | Futures.immediateFuture(Optional.of(entry)); | 547 | Futures.immediateFuture(Optional.of(entry)); |
559 | 548 | ||
@@ -620,6 +609,10 @@ public class TbDeviceProfileNodeTest { | @@ -620,6 +609,10 @@ public class TbDeviceProfileNodeTest { | ||
620 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "tenantAttribute" | 609 | EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "tenantAttribute" |
621 | ); | 610 | ); |
622 | 611 | ||
612 | + Device device = new Device(); | ||
613 | + device.setId(deviceId); | ||
614 | + device.setCustomerId(customerId); | ||
615 | + | ||
623 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); | 616 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); |
624 | attributeKvEntity.setId(compositeKey); | 617 | attributeKvEntity.setId(compositeKey); |
625 | attributeKvEntity.setLongValue(100L); | 618 | attributeKvEntity.setLongValue(100L); |
@@ -627,7 +620,11 @@ public class TbDeviceProfileNodeTest { | @@ -627,7 +620,11 @@ public class TbDeviceProfileNodeTest { | ||
627 | 620 | ||
628 | AttributeKvEntry entry = attributeKvEntity.toData(); | 621 | AttributeKvEntry entry = attributeKvEntity.toData(); |
629 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = | 622 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = |
630 | - Futures.immediateFuture(Collections.singletonList(entry)); | 623 | + Futures.immediateFuture(Collections.emptyList()); |
624 | + ListenableFuture<Optional<AttributeKvEntry>> emptyOptionalFuture = | ||
625 | + Futures.immediateFuture(Optional.empty()); | ||
626 | + ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = | ||
627 | + Futures.immediateFuture(Optional.of(entry)); | ||
631 | 628 | ||
632 | AlarmConditionFilter lowTempFilter = new AlarmConditionFilter(); | 629 | AlarmConditionFilter lowTempFilter = new AlarmConditionFilter(); |
633 | lowTempFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature")); | 630 | lowTempFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature")); |
@@ -661,8 +658,14 @@ public class TbDeviceProfileNodeTest { | @@ -661,8 +658,14 @@ public class TbDeviceProfileNodeTest { | ||
661 | Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())) | 658 | Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())) |
662 | .thenAnswer(AdditionalAnswers.returnsFirstArg()); | 659 | .thenAnswer(AdditionalAnswers.returnsFirstArg()); |
663 | Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); | 660 | Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); |
661 | + Mockito.when(ctx.getDeviceService().findDeviceById(tenantId, deviceId)) | ||
662 | + .thenReturn(device); | ||
664 | Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) | 663 | Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) |
665 | .thenReturn(listListenableFutureWithLess); | 664 | .thenReturn(listListenableFutureWithLess); |
665 | + Mockito.when(attributesService.find(eq(tenantId), eq(customerId), Mockito.anyString(), Mockito.anyString())) | ||
666 | + .thenReturn(emptyOptionalFuture); | ||
667 | + Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())) | ||
668 | + .thenReturn(optionalListenableFutureWithLess); | ||
666 | 669 | ||
667 | TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); | 670 | TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); |
668 | Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())) | 671 | Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.anyString())) |
@@ -677,6 +680,7 @@ public class TbDeviceProfileNodeTest { | @@ -677,6 +680,7 @@ public class TbDeviceProfileNodeTest { | ||
677 | verify(ctx).tellSuccess(msg); | 680 | verify(ctx).tellSuccess(msg); |
678 | verify(ctx).tellNext(theMsg, "Alarm Created"); | 681 | verify(ctx).tellNext(theMsg, "Alarm Created"); |
679 | verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any()); | 682 | verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any()); |
683 | + | ||
680 | } | 684 | } |
681 | 685 | ||
682 | 686 | ||
@@ -688,9 +692,13 @@ public class TbDeviceProfileNodeTest { | @@ -688,9 +692,13 @@ public class TbDeviceProfileNodeTest { | ||
688 | DeviceProfileData deviceProfileData = new DeviceProfileData(); | 692 | DeviceProfileData deviceProfileData = new DeviceProfileData(); |
689 | 693 | ||
690 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( | 694 | AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey( |
691 | - EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "customerAttribute" | 695 | + EntityType.DEVICE, deviceId.getId(), EntityKeyType.SERVER_ATTRIBUTE.name(), "tenantAttribute" |
692 | ); | 696 | ); |
693 | 697 | ||
698 | + Device device = new Device(); | ||
699 | + device.setId(deviceId); | ||
700 | + device.setCustomerId(customerId); | ||
701 | + | ||
694 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); | 702 | AttributeKvEntity attributeKvEntity = new AttributeKvEntity(); |
695 | attributeKvEntity.setId(compositeKey); | 703 | attributeKvEntity.setId(compositeKey); |
696 | attributeKvEntity.setLongValue(100L); | 704 | attributeKvEntity.setLongValue(100L); |
@@ -698,7 +706,9 @@ public class TbDeviceProfileNodeTest { | @@ -698,7 +706,9 @@ public class TbDeviceProfileNodeTest { | ||
698 | 706 | ||
699 | AttributeKvEntry entry = attributeKvEntity.toData(); | 707 | AttributeKvEntry entry = attributeKvEntity.toData(); |
700 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = | 708 | ListenableFuture<List<AttributeKvEntry>> listListenableFutureWithLess = |
701 | - Futures.immediateFuture(Collections.singletonList(entry)); | 709 | + Futures.immediateFuture(Collections.emptyList()); |
710 | + ListenableFuture<Optional<AttributeKvEntry>> emptyOptionalFuture = | ||
711 | + Futures.immediateFuture(Optional.empty()); | ||
702 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = | 712 | ListenableFuture<Optional<AttributeKvEntry>> optionalListenableFutureWithLess = |
703 | Futures.immediateFuture(Optional.of(entry)); | 713 | Futures.immediateFuture(Optional.of(entry)); |
704 | 714 | ||
@@ -711,7 +721,7 @@ public class TbDeviceProfileNodeTest { | @@ -711,7 +721,7 @@ public class TbDeviceProfileNodeTest { | ||
711 | new FilterPredicateValue<>( | 721 | new FilterPredicateValue<>( |
712 | 0.0, | 722 | 0.0, |
713 | null, | 723 | null, |
714 | - new DynamicValue<>(DynamicValueSourceType.CURRENT_CUSTOMER, "customerAttribute", true)) | 724 | + new DynamicValue<>(DynamicValueSourceType.CURRENT_CUSTOMER, "tenantAttribute", true)) |
715 | ); | 725 | ); |
716 | lowTempFilter.setPredicate(lowTempPredicate); | 726 | lowTempFilter.setPredicate(lowTempPredicate); |
717 | AlarmCondition alarmCondition = new AlarmCondition(); | 727 | AlarmCondition alarmCondition = new AlarmCondition(); |
@@ -720,7 +730,7 @@ public class TbDeviceProfileNodeTest { | @@ -720,7 +730,7 @@ public class TbDeviceProfileNodeTest { | ||
720 | alarmRule.setCondition(alarmCondition); | 730 | alarmRule.setCondition(alarmCondition); |
721 | DeviceProfileAlarm dpa = new DeviceProfileAlarm(); | 731 | DeviceProfileAlarm dpa = new DeviceProfileAlarm(); |
722 | dpa.setId("lesstempID"); | 732 | dpa.setId("lesstempID"); |
723 | - dpa.setAlarmType("lessTemperatureAlarm"); | 733 | + dpa.setAlarmType("greaterTemperatureAlarm"); |
724 | dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule))); | 734 | dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule))); |
725 | 735 | ||
726 | deviceProfileData.setAlarms(Collections.singletonList(dpa)); | 736 | deviceProfileData.setAlarms(Collections.singletonList(dpa)); |
@@ -729,14 +739,18 @@ public class TbDeviceProfileNodeTest { | @@ -729,14 +739,18 @@ public class TbDeviceProfileNodeTest { | ||
729 | Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile); | 739 | Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile); |
730 | Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))) | 740 | Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))) |
731 | .thenReturn(Futures.immediateFuture(Collections.emptyList())); | 741 | .thenReturn(Futures.immediateFuture(Collections.emptyList())); |
732 | - Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "lessTemperatureAlarm")) | 742 | + Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "greaterTemperatureAlarm")) |
733 | .thenReturn(Futures.immediateFuture(null)); | 743 | .thenReturn(Futures.immediateFuture(null)); |
734 | Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())) | 744 | Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())) |
735 | .thenAnswer(AdditionalAnswers.returnsFirstArg()); | 745 | .thenAnswer(AdditionalAnswers.returnsFirstArg()); |
736 | Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); | 746 | Mockito.when(ctx.getAttributesService()).thenReturn(attributesService); |
747 | + Mockito.when(ctx.getDeviceService().findDeviceById(tenantId, deviceId)) | ||
748 | + .thenReturn(device); | ||
737 | Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) | 749 | Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())) |
738 | .thenReturn(listListenableFutureWithLess); | 750 | .thenReturn(listListenableFutureWithLess); |
739 | - Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())) | 751 | + Mockito.when(attributesService.find(eq(tenantId), eq(customerId), Mockito.anyString(), Mockito.anyString())) |
752 | + .thenReturn(emptyOptionalFuture); | ||
753 | + Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())) | ||
740 | .thenReturn(optionalListenableFutureWithLess); | 754 | .thenReturn(optionalListenableFutureWithLess); |
741 | 755 | ||
742 | TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); | 756 | TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), ""); |