@ -15,7 +15,6 @@
* /
package org.thingsboard.rule.engine.profile ;
import com.fasterxml.jackson.databind.ObjectMapper ;
import com.fasterxml.jackson.databind.node.ObjectNode ;
import com.google.common.util.concurrent.Futures ;
import com.google.common.util.concurrent.ListenableFuture ;
@ -24,6 +23,7 @@ import org.junit.runner.RunWith;
import org.mockito.Mock ;
import org.mockito.Mockito ;
import org.mockito.junit.MockitoJUnitRunner ;
import org.thingsboard.common.util.JacksonUtil ;
import org.thingsboard.rule.engine.api.RuleEngineAlarmService ;
import org.thingsboard.rule.engine.api.RuleEngineDeviceProfileCache ;
import org.thingsboard.rule.engine.api.TbContext ;
@ -90,8 +90,6 @@ import static org.mockito.Mockito.when;
@RunWith ( MockitoJUnitRunner . class )
public class TbDeviceProfileNodeTest {
private static final ObjectMapper mapper = new ObjectMapper ( ) ;
private TbDeviceProfileNode node ;
@Mock
@ -122,10 +120,10 @@ public class TbDeviceProfileNodeTest {
deviceProfile . setProfileData ( deviceProfileData ) ;
Mockito . when ( cache . get ( tenantId , deviceId ) ) . thenReturn ( deviceProfile ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 42 ) ;
TbMsg msg = TbMsg . newMsg ( "123456789" , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
verify ( ctx , Mockito . never ( ) ) . tellFailure ( Mockito . any ( ) , Mockito . any ( ) ) ;
@ -141,10 +139,10 @@ public class TbDeviceProfileNodeTest {
deviceProfile . setProfileData ( deviceProfileData ) ;
Mockito . when ( cache . get ( tenantId , deviceId ) ) . thenReturn ( deviceProfile ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 42 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
verify ( ctx , Mockito . never ( ) ) . tellFailure ( Mockito . any ( ) , Mockito . any ( ) ) ;
@ -198,10 +196,10 @@ public class TbDeviceProfileNodeTest {
TbMsg theMsg = TbMsg . newMsg ( "ALARM" , deviceId , new TbMsgMetaData ( ) , "" ) ;
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) ) . thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 42 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
verify ( ctx ) . enqueueForTellNext ( theMsg , "Alarm Created" ) ;
@ -214,7 +212,7 @@ public class TbDeviceProfileNodeTest {
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
verify ( ctx ) . enqueueForTellNext ( theMsg2 , "Alarm Updated" ) ;
@ -292,10 +290,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 21 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -379,10 +377,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 21 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -448,10 +446,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -542,10 +540,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -560,7 +558,7 @@ public class TbDeviceProfileNodeTest {
Thread . sleep ( halfOfAlarmDelay ) ;
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
@ -666,10 +664,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 150 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -684,7 +682,7 @@ public class TbDeviceProfileNodeTest {
Thread . sleep ( halfOfAlarmDelay ) ;
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
@ -775,10 +773,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 150 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -787,7 +785,7 @@ public class TbDeviceProfileNodeTest {
data . put ( "temperature" , 151 ) ;
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
@ -891,10 +889,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 150 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -903,7 +901,7 @@ public class TbDeviceProfileNodeTest {
data . put ( "temperature" , 151 ) ;
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
@ -987,10 +985,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1005,7 +1003,7 @@ public class TbDeviceProfileNodeTest {
Thread . sleep ( halfOfAlarmDelay ) ;
TbMsg msg2 = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg2 ) ;
verify ( ctx ) . tellSuccess ( msg2 ) ;
@ -1085,10 +1083,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1167,10 +1165,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
// Mockito.reset(ctx);
@ -1261,10 +1259,10 @@ public class TbDeviceProfileNodeTest {
TbMsg theMsg = TbMsg . newMsg ( "ALARM" , deviceId , new TbMsgMetaData ( ) , "" ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 35 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1341,10 +1339,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 25 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1414,10 +1412,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 40 ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1497,10 +1495,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 150L ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1582,10 +1580,10 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . newMsg ( Mockito . any ( ) , Mockito . anyString ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . any ( ) , Mockito . anyString ( ) ) )
. thenReturn ( theMsg ) ;
ObjectNode data = mapper . create ObjectNode( ) ;
ObjectNode data = JacksonUtil . new ObjectNode( ) ;
data . put ( "temperature" , 150L ) ;
TbMsg msg = TbMsg . newMsg ( SessionMsgType . POST_TELEMETRY_REQUEST . name ( ) , deviceId , new TbMsgMetaData ( ) ,
TbMsgDataType . JSON , mapper . writeValueAs String( data ) , null , null ) ;
TbMsgDataType . JSON , JacksonUtil . to String( data ) , null , null ) ;
node . onMsg ( ctx , msg ) ;
verify ( ctx ) . tellSuccess ( msg ) ;
@ -1600,7 +1598,7 @@ public class TbDeviceProfileNodeTest {
Mockito . when ( ctx . getAlarmService ( ) ) . thenReturn ( alarmService ) ;
Mockito . when ( ctx . getDeviceService ( ) ) . thenReturn ( deviceService ) ;
Mockito . when ( ctx . getAttributesService ( ) ) . thenReturn ( attributesService ) ;
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration ( mapper . create ObjectNode( ) ) ;
TbNodeConfiguration nodeConfiguration = new TbNodeConfiguration ( JacksonUtil . new ObjectNode( ) ) ;
node = new TbDeviceProfileNode ( ) ;
node . init ( ctx , nodeConfiguration ) ;
}