Search in sources :

Example 76 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbDeviceProfileNodeTest method testConstantKeyFilterSimple.

@Test
public void testConstantKeyFilterSimple() throws Exception {
    init();
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setId(deviceProfileId);
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    Device device = new Device();
    device.setId(deviceId);
    device.setCustomerId(customerId);
    AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "alarmEnabled");
    AttributeKvEntity attributeKvEntity = new AttributeKvEntity();
    attributeKvEntity.setId(compositeKey);
    attributeKvEntity.setBooleanValue(Boolean.TRUE);
    attributeKvEntity.setLastUpdateTs(System.currentTimeMillis());
    AttributeKvEntry entry = attributeKvEntity.toData();
    ListenableFuture<List<AttributeKvEntry>> attrListListenableFuture = Futures.immediateFuture(Collections.singletonList(entry));
    AlarmConditionFilter alarmEnabledFilter = new AlarmConditionFilter();
    alarmEnabledFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.CONSTANT, "alarmEnabled"));
    alarmEnabledFilter.setValue(Boolean.TRUE);
    alarmEnabledFilter.setValueType(EntityKeyValueType.BOOLEAN);
    BooleanFilterPredicate alarmEnabledPredicate = new BooleanFilterPredicate();
    alarmEnabledPredicate.setOperation(BooleanFilterPredicate.BooleanOperation.EQUAL);
    alarmEnabledPredicate.setValue(new FilterPredicateValue<>(Boolean.FALSE, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "alarmEnabled")));
    alarmEnabledFilter.setPredicate(alarmEnabledPredicate);
    AlarmConditionFilter temperatureFilter = new AlarmConditionFilter();
    temperatureFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    temperatureFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate temperaturePredicate = new NumericFilterPredicate();
    temperaturePredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    temperaturePredicate.setValue(new FilterPredicateValue<>(20.0, null, null));
    temperatureFilter.setPredicate(temperaturePredicate);
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setCondition(Arrays.asList(alarmEnabledFilter, temperatureFilter));
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setCondition(alarmCondition);
    DeviceProfileAlarm dpa = new DeviceProfileAlarm();
    dpa.setId("alarmEnabledAlarmID");
    dpa.setAlarmType("alarmEnabledAlarm");
    dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule)));
    deviceProfileData.setAlarms(Collections.singletonList(dpa));
    deviceProfile.setProfileData(deviceProfileData);
    Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile);
    Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "alarmEnabledAlarm")).thenReturn(Futures.immediateFuture(null));
    Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())).thenAnswer(AdditionalAnswers.returnsFirstArg());
    Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
    Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())).thenReturn(attrListListenableFuture);
    TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
    Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(theMsg);
    ObjectNode data = mapper.createObjectNode();
    data.put("temperature", 21);
    TbMsg msg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg);
    verify(ctx).tellSuccess(msg);
    verify(ctx).enqueueForTellNext(theMsg, "Alarm Created");
    verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any());
}
Also used : BooleanFilterPredicate(org.thingsboard.server.common.data.query.BooleanFilterPredicate) AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) List(java.util.List) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Example 77 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbDeviceProfileNodeTest method testInheritTenantAttributeForDuration.

@Test
public void testInheritTenantAttributeForDuration() throws Exception {
    init();
    DeviceProfile deviceProfile = new DeviceProfile();
    deviceProfile.setId(deviceProfileId);
    DeviceProfileData deviceProfileData = new DeviceProfileData();
    Device device = new Device();
    device.setId(deviceId);
    device.setCustomerId(customerId);
    AttributeKvCompositeKey compositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "greaterAttribute");
    AttributeKvEntity attributeKvEntity = new AttributeKvEntity();
    attributeKvEntity.setId(compositeKey);
    attributeKvEntity.setLongValue(30L);
    attributeKvEntity.setLastUpdateTs(0L);
    AttributeKvCompositeKey alarmDelayCompositeKey = new AttributeKvCompositeKey(EntityType.TENANT, deviceId.getId(), "SERVER_SCOPE", "alarm_delay");
    AttributeKvEntity alarmDelayAttributeKvEntity = new AttributeKvEntity();
    alarmDelayAttributeKvEntity.setId(alarmDelayCompositeKey);
    long alarmDelayInSeconds = 5L;
    alarmDelayAttributeKvEntity.setLongValue(alarmDelayInSeconds);
    alarmDelayAttributeKvEntity.setLastUpdateTs(0L);
    AttributeKvEntry entry = attributeKvEntity.toData();
    AttributeKvEntry alarmDelayAttributeKvEntry = alarmDelayAttributeKvEntity.toData();
    ListenableFuture<Optional<AttributeKvEntry>> optionalDurationAttribute = Futures.immediateFuture(Optional.of(alarmDelayAttributeKvEntry));
    ListenableFuture<List<AttributeKvEntry>> listNoDurationAttribute = Futures.immediateFuture(Collections.singletonList(entry));
    ListenableFuture<Optional<AttributeKvEntry>> emptyOptional = Futures.immediateFuture(Optional.empty());
    AlarmConditionFilter highTempFilter = new AlarmConditionFilter();
    highTempFilter.setKey(new AlarmConditionFilterKey(AlarmConditionKeyType.TIME_SERIES, "temperature"));
    highTempFilter.setValueType(EntityKeyValueType.NUMERIC);
    NumericFilterPredicate highTemperaturePredicate = new NumericFilterPredicate();
    highTemperaturePredicate.setOperation(NumericFilterPredicate.NumericOperation.GREATER);
    highTemperaturePredicate.setValue(new FilterPredicateValue<>(0.0, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "greaterAttribute", false)));
    highTempFilter.setPredicate(highTemperaturePredicate);
    AlarmCondition alarmCondition = new AlarmCondition();
    alarmCondition.setCondition(Collections.singletonList(highTempFilter));
    FilterPredicateValue<Long> filterPredicateValue = new FilterPredicateValue<>(10L, null, new DynamicValue<>(DynamicValueSourceType.CURRENT_DEVICE, "alarm_delay", true));
    DurationAlarmConditionSpec durationSpec = new DurationAlarmConditionSpec();
    durationSpec.setUnit(TimeUnit.SECONDS);
    durationSpec.setPredicate(filterPredicateValue);
    alarmCondition.setSpec(durationSpec);
    AlarmRule alarmRule = new AlarmRule();
    alarmRule.setCondition(alarmCondition);
    DeviceProfileAlarm dpa = new DeviceProfileAlarm();
    dpa.setId("highTemperatureAlarmID");
    dpa.setAlarmType("highTemperatureAlarm");
    dpa.setCreateRules(new TreeMap<>(Collections.singletonMap(AlarmSeverity.CRITICAL, alarmRule)));
    deviceProfileData.setAlarms(Collections.singletonList(dpa));
    deviceProfile.setProfileData(deviceProfileData);
    Mockito.when(cache.get(tenantId, deviceId)).thenReturn(deviceProfile);
    Mockito.when(timeseriesService.findLatest(tenantId, deviceId, Collections.singleton("temperature"))).thenReturn(Futures.immediateFuture(Collections.emptyList()));
    Mockito.when(alarmService.findLatestByOriginatorAndType(tenantId, deviceId, "highTemperatureAlarm")).thenReturn(Futures.immediateFuture(null));
    Mockito.when(alarmService.createOrUpdateAlarm(Mockito.any())).thenAnswer(AdditionalAnswers.returnsFirstArg());
    Mockito.when(ctx.getAttributesService()).thenReturn(attributesService);
    Mockito.when(attributesService.find(eq(tenantId), eq(tenantId), Mockito.anyString(), Mockito.anyString())).thenReturn(optionalDurationAttribute);
    Mockito.when(ctx.getDeviceService().findDeviceById(tenantId, deviceId)).thenReturn(device);
    Mockito.when(attributesService.find(eq(tenantId), eq(customerId), eq(DataConstants.SERVER_SCOPE), Mockito.anyString())).thenReturn(emptyOptional);
    Mockito.when(attributesService.find(eq(tenantId), eq(deviceId), Mockito.anyString(), Mockito.anySet())).thenReturn(listNoDurationAttribute);
    TbMsg theMsg = TbMsg.newMsg("ALARM", deviceId, new TbMsgMetaData(), "");
    Mockito.when(ctx.newMsg(Mockito.anyString(), Mockito.anyString(), Mockito.any(), Mockito.any(), Mockito.any(), Mockito.anyString())).thenReturn(theMsg);
    ObjectNode data = mapper.createObjectNode();
    data.put("temperature", 150);
    TbMsg msg = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg);
    verify(ctx).tellSuccess(msg);
    int halfOfAlarmDelay = new BigDecimal(alarmDelayInSeconds).multiply(BigDecimal.valueOf(1000)).divide(BigDecimal.valueOf(2), 3, RoundingMode.HALF_EVEN).intValueExact();
    Thread.sleep(halfOfAlarmDelay);
    verify(ctx, Mockito.never()).tellNext(theMsg, "Alarm Created");
    Thread.sleep(halfOfAlarmDelay);
    TbMsg msg2 = TbMsg.newMsg(SessionMsgType.POST_TELEMETRY_REQUEST.name(), deviceId, new TbMsgMetaData(), TbMsgDataType.JSON, mapper.writeValueAsString(data), null, null);
    node.onMsg(ctx, msg2);
    verify(ctx).tellSuccess(msg2);
    verify(ctx).enqueueForTellNext(theMsg, "Alarm Created");
    verify(ctx, Mockito.never()).tellFailure(Mockito.any(), Mockito.any());
}
Also used : AttributeKvEntry(org.thingsboard.server.common.data.kv.AttributeKvEntry) AttributeKvEntity(org.thingsboard.server.dao.model.sql.AttributeKvEntity) AlarmRule(org.thingsboard.server.common.data.device.profile.AlarmRule) FilterPredicateValue(org.thingsboard.server.common.data.query.FilterPredicateValue) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) DeviceProfile(org.thingsboard.server.common.data.DeviceProfile) List(java.util.List) DeviceProfileData(org.thingsboard.server.common.data.device.profile.DeviceProfileData) AlarmConditionFilterKey(org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey) AttributeKvCompositeKey(org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey) TbMsg(org.thingsboard.server.common.msg.TbMsg) Optional(java.util.Optional) ObjectNode(com.fasterxml.jackson.databind.node.ObjectNode) NumericFilterPredicate(org.thingsboard.server.common.data.query.NumericFilterPredicate) Device(org.thingsboard.server.common.data.Device) AlarmConditionFilter(org.thingsboard.server.common.data.device.profile.AlarmConditionFilter) BigDecimal(java.math.BigDecimal) AlarmCondition(org.thingsboard.server.common.data.device.profile.AlarmCondition) DurationAlarmConditionSpec(org.thingsboard.server.common.data.device.profile.DurationAlarmConditionSpec) DeviceProfileAlarm(org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm) DynamicValue(org.thingsboard.server.common.data.query.DynamicValue) Test(org.junit.Test)

Example 78 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbRestApiCallNodeTest method deleteRequestWithoutBody.

@Test
public void deleteRequestWithoutBody() throws IOException, InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final String path = "/path/to/delete";
    setupServer("*", new HttpRequestHandler() {

        @Override
        public void handle(HttpRequest request, HttpResponse response, HttpContext context) throws HttpException, IOException {
            try {
                assertEquals("Request path matches", request.getRequestLine().getUri(), path);
                assertFalse("Content-Type not included", request.containsHeader("Content-Type"));
                assertTrue("Custom header included", request.containsHeader("Foo"));
                assertEquals("Custom header value", "Bar", request.getFirstHeader("Foo").getValue());
                response.setStatusCode(200);
                new Thread(new Runnable() {

                    @Override
                    public void run() {
                        try {
                            Thread.sleep(1000L);
                        } catch (InterruptedException e) {
                        // ignore
                        } finally {
                            latch.countDown();
                        }
                    }
                }).start();
            } catch (Exception e) {
                System.out.println("Exception handling request: " + e.toString());
                e.printStackTrace();
                latch.countDown();
            }
        }
    });
    TbRestApiCallNodeConfiguration config = new TbRestApiCallNodeConfiguration().defaultConfiguration();
    config.setRequestMethod("DELETE");
    config.setHeaders(Collections.singletonMap("Foo", "Bar"));
    config.setIgnoreRequestBody(true);
    config.setRestEndpointUrlPattern(String.format("http://localhost:%d%s", server.getLocalPort(), path));
    initWithConfig(config);
    TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, "{}", ruleChainId, ruleNodeId);
    restNode.onMsg(ctx, msg);
    assertTrue("Server handled request", latch.await(10, TimeUnit.SECONDS));
    ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
    ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class);
    ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture());
    assertEquals("USER", typeCaptor.getValue());
    assertEquals(originator, originatorCaptor.getValue());
    assertNotSame(metaData, metadataCaptor.getValue());
    assertEquals("{}", dataCaptor.getValue());
}
Also used : HttpRequest(org.apache.http.HttpRequest) HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpContext(org.apache.http.protocol.HttpContext) HttpResponse(org.apache.http.HttpResponse) IOException(java.io.IOException) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) CountDownLatch(java.util.concurrent.CountDownLatch) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) IOException(java.io.IOException) HttpException(org.apache.http.HttpException) EntityId(org.thingsboard.server.common.data.id.EntityId) HttpException(org.apache.http.HttpException) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Example 79 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbTransformMsgNodeTest method metadataCanBeUpdated.

@Test
public void metadataCanBeUpdated() throws TbNodeException, ScriptException {
    initWithScript();
    TbMsgMetaData metaData = new TbMsgMetaData();
    metaData.putValue("temp", "7");
    String rawJson = "{\"passed\": 5}";
    RuleChainId ruleChainId = new RuleChainId(Uuids.timeBased());
    RuleNodeId ruleNodeId = new RuleNodeId(Uuids.timeBased());
    TbMsg msg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId);
    TbMsg transformedMsg = TbMsg.newMsg("USER", null, metaData, TbMsgDataType.JSON, "{new}", ruleChainId, ruleNodeId);
    when(scriptEngine.executeUpdateAsync(msg)).thenReturn(Futures.immediateFuture(Collections.singletonList(transformedMsg)));
    node.onMsg(ctx, msg);
    verify(ctx).getDbCallbackExecutor();
    ArgumentCaptor<TbMsg> captor = ArgumentCaptor.forClass(TbMsg.class);
    verify(ctx).tellSuccess(captor.capture());
    TbMsg actualMsg = captor.getValue();
    assertEquals(transformedMsg, actualMsg);
}
Also used : RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbMsg(org.thingsboard.server.common.msg.TbMsg) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) Test(org.junit.Test)

Example 80 with TbMsgMetaData

use of org.thingsboard.server.common.msg.TbMsgMetaData in project thingsboard by thingsboard.

the class TbAlarmNodeTest method testCreateAlarmWithDynamicSeverityFromMetadata.

@Test
public void testCreateAlarmWithDynamicSeverityFromMetadata() throws Exception {
    TbCreateAlarmNodeConfiguration config = new TbCreateAlarmNodeConfiguration();
    config.setPropagate(true);
    config.setSeverity("${alarmSeverity}");
    config.setAlarmType("SomeType");
    config.setAlarmDetailsBuildJs("DETAILS");
    config.setDynamicSeverity(true);
    ObjectMapper mapper = new ObjectMapper();
    TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration(mapper.valueToTree(config));
    when(ctx.createJsScriptEngine("DETAILS")).thenReturn(detailsJs);
    when(ctx.getTenantId()).thenReturn(tenantId);
    when(ctx.getAlarmService()).thenReturn(alarmService);
    when(ctx.getDbCallbackExecutor()).thenReturn(dbExecutor);
    node = new TbCreateAlarmNode();
    node.init(ctx, nodeConfiguration);
    metaData.putValue("alarmSeverity", "WARNING");
    TbMsg msg = TbMsg.newMsg("USER", originator, metaData, TbMsgDataType.JSON, rawJson, ruleChainId, ruleNodeId);
    long ts = msg.getTs();
    when(detailsJs.executeJsonAsync(msg)).thenReturn(Futures.immediateFuture(null));
    when(alarmService.findLatestByOriginatorAndType(tenantId, originator, "SomeType")).thenReturn(Futures.immediateFuture(null));
    doAnswer((Answer<Alarm>) invocationOnMock -> (Alarm) (invocationOnMock.getArguments())[0]).when(alarmService).createOrUpdateAlarm(any(Alarm.class));
    node.onMsg(ctx, msg);
    verify(ctx).enqueue(any(), successCaptor.capture(), failureCaptor.capture());
    successCaptor.getValue().run();
    verify(ctx).tellNext(any(), eq("Created"));
    ArgumentCaptor<TbMsg> msgCaptor = ArgumentCaptor.forClass(TbMsg.class);
    ArgumentCaptor<String> typeCaptor = ArgumentCaptor.forClass(String.class);
    ArgumentCaptor<EntityId> originatorCaptor = ArgumentCaptor.forClass(EntityId.class);
    ArgumentCaptor<TbMsgMetaData> metadataCaptor = ArgumentCaptor.forClass(TbMsgMetaData.class);
    ArgumentCaptor<String> dataCaptor = ArgumentCaptor.forClass(String.class);
    verify(ctx).transformMsg(msgCaptor.capture(), typeCaptor.capture(), originatorCaptor.capture(), metadataCaptor.capture(), dataCaptor.capture());
    assertEquals("ALARM", typeCaptor.getValue());
    assertEquals(originator, originatorCaptor.getValue());
    assertEquals(Boolean.TRUE.toString(), metadataCaptor.getValue().getValue(IS_NEW_ALARM));
    assertNotSame(metaData, metadataCaptor.getValue());
    Alarm actualAlarm = new ObjectMapper().readValue(dataCaptor.getValue().getBytes(), Alarm.class);
    Alarm expectedAlarm = Alarm.builder().startTs(ts).endTs(ts).tenantId(tenantId).originator(originator).status(ACTIVE_UNACK).severity(WARNING).propagate(true).type("SomeType").details(null).build();
    assertEquals(expectedAlarm, actualAlarm);
}
Also used : CRITICAL(org.thingsboard.server.common.data.alarm.AlarmSeverity.CRITICAL) RuleEngineAlarmService(org.thingsboard.rule.engine.api.RuleEngineAlarmService) ArgumentMatchers.nullable(org.mockito.ArgumentMatchers.nullable) Assert.assertNotSame(org.junit.Assert.assertNotSame) RuleNodeId(org.thingsboard.server.common.data.id.RuleNodeId) TenantId(org.thingsboard.server.common.data.id.TenantId) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) ACTIVE_UNACK(org.thingsboard.server.common.data.alarm.AlarmStatus.ACTIVE_UNACK) TbNodeException(org.thingsboard.rule.engine.api.TbNodeException) Mockito.verifyNoMoreInteractions(org.mockito.Mockito.verifyNoMoreInteractions) Uuids(com.datastax.oss.driver.api.core.uuid.Uuids) Mockito.doAnswer(org.mockito.Mockito.doAnswer) JsonNode(com.fasterxml.jackson.databind.JsonNode) ScriptException(javax.script.ScriptException) DeviceId(org.thingsboard.server.common.data.id.DeviceId) IS_NEW_ALARM(org.thingsboard.server.common.data.DataConstants.IS_NEW_ALARM) Alarm(org.thingsboard.server.common.data.alarm.Alarm) TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) Mockito.atMost(org.mockito.Mockito.atMost) WARNING(org.thingsboard.server.common.data.alarm.AlarmSeverity.WARNING) RuleChainId(org.thingsboard.server.common.data.id.RuleChainId) MockitoJUnitRunner(org.mockito.junit.MockitoJUnitRunner) Mockito.eq(org.mockito.Mockito.eq) NotImplementedException(org.apache.commons.lang3.NotImplementedException) ArgumentMatchers.any(org.mockito.ArgumentMatchers.any) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) TbMsg(org.thingsboard.server.common.msg.TbMsg) Mock(org.mockito.Mock) IS_CLEARED_ALARM(org.thingsboard.server.common.data.DataConstants.IS_CLEARED_ALARM) RunWith(org.junit.runner.RunWith) Callable(java.util.concurrent.Callable) TbContext(org.thingsboard.rule.engine.api.TbContext) Captor(org.mockito.Captor) Answer(org.mockito.stubbing.Answer) ArgumentCaptor(org.mockito.ArgumentCaptor) ListeningExecutor(org.thingsboard.common.util.ListeningExecutor) EntityId(org.thingsboard.server.common.data.id.EntityId) ScriptEngine(org.thingsboard.rule.engine.api.ScriptEngine) CLEARED_UNACK(org.thingsboard.server.common.data.alarm.AlarmStatus.CLEARED_UNACK) Mockito.anyLong(org.mockito.Mockito.anyLong) Mockito.same(org.mockito.Mockito.same) IS_EXISTING_ALARM(org.thingsboard.server.common.data.DataConstants.IS_EXISTING_ALARM) Before(org.junit.Before) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Assert.assertTrue(org.junit.Assert.assertTrue) Test(org.junit.Test) IOException(java.io.IOException) Mockito.times(org.mockito.Mockito.times) Mockito.when(org.mockito.Mockito.when) Mockito.verify(org.mockito.Mockito.verify) CLEARED_ACK(org.thingsboard.server.common.data.alarm.AlarmStatus.CLEARED_ACK) Consumer(java.util.function.Consumer) Futures(com.google.common.util.concurrent.Futures) AlarmId(org.thingsboard.server.common.data.id.AlarmId) TbMsgDataType(org.thingsboard.server.common.msg.TbMsgDataType) Assert.assertEquals(org.junit.Assert.assertEquals) TbMsgMetaData(org.thingsboard.server.common.msg.TbMsgMetaData) TbNodeConfiguration(org.thingsboard.rule.engine.api.TbNodeConfiguration) EntityId(org.thingsboard.server.common.data.id.EntityId) Alarm(org.thingsboard.server.common.data.alarm.Alarm) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) TbMsg(org.thingsboard.server.common.msg.TbMsg) Test(org.junit.Test)

Aggregations

TbMsgMetaData (org.thingsboard.server.common.msg.TbMsgMetaData)89 TbMsg (org.thingsboard.server.common.msg.TbMsg)56 Test (org.junit.Test)49 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)26 Device (org.thingsboard.server.common.data.Device)17 DeviceProfile (org.thingsboard.server.common.data.DeviceProfile)17 List (java.util.List)16 DeviceProfileData (org.thingsboard.server.common.data.device.profile.DeviceProfileData)16 DeviceId (org.thingsboard.server.common.data.id.DeviceId)15 EntityId (org.thingsboard.server.common.data.id.EntityId)15 AlarmCondition (org.thingsboard.server.common.data.device.profile.AlarmCondition)14 AlarmConditionFilter (org.thingsboard.server.common.data.device.profile.AlarmConditionFilter)14 AlarmConditionFilterKey (org.thingsboard.server.common.data.device.profile.AlarmConditionFilterKey)14 AlarmRule (org.thingsboard.server.common.data.device.profile.AlarmRule)14 DeviceProfileAlarm (org.thingsboard.server.common.data.device.profile.DeviceProfileAlarm)14 AttributeKvEntry (org.thingsboard.server.common.data.kv.AttributeKvEntry)14 NumericFilterPredicate (org.thingsboard.server.common.data.query.NumericFilterPredicate)14 JsonNode (com.fasterxml.jackson.databind.JsonNode)13 DynamicValue (org.thingsboard.server.common.data.query.DynamicValue)13 AttributeKvCompositeKey (org.thingsboard.server.dao.model.sql.AttributeKvCompositeKey)13