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