use of org.thingsboard.server.extensions.api.device.DeviceAttributes in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicMissingAttributesTest.
@Test
public void basicMissingAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("((typeof nonExistingVal === 'undefined') || nonExistingVal == true) && booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(clientAttributes, new ArrayList<>(), new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
use of org.thingsboard.server.extensions.api.device.DeviceAttributes in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicConflictServerAttributesTest.
@Test
public void basicConflictServerAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("cs.doubleValue == 1.0 && cs.booleanValue == true && ss.doubleValue == 0.0 && ss.booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", true), 42));
List<AttributeKvEntry> serverAttributes = new ArrayList<>();
serverAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 0.0), 42));
serverAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(clientAttributes, serverAttributes, new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
use of org.thingsboard.server.extensions.api.device.DeviceAttributes in project thingsboard by thingsboard.
the class VelocityUtils method createContext.
public static VelocityContext createContext(DeviceMetaData deviceMetaData, FromDeviceMsg payload) {
VelocityContext context = new VelocityContext();
context.put("date", new DateTool());
DeviceAttributes deviceAttributes = deviceMetaData.getDeviceAttributes();
pushAttributes(context, deviceAttributes.getClientSideAttributes(), NashornJsEvaluator.CLIENT_SIDE);
pushAttributes(context, deviceAttributes.getServerSideAttributes(), NashornJsEvaluator.SERVER_SIDE);
pushAttributes(context, deviceAttributes.getServerSidePublicAttributes(), NashornJsEvaluator.SHARED);
switch(payload.getMsgType()) {
case POST_TELEMETRY_REQUEST:
pushTsEntries(context, (TelemetryUploadRequest) payload);
break;
default:
break;
}
context.put("deviceId", deviceMetaData.getDeviceId().getId().toString());
context.put("deviceName", deviceMetaData.getDeviceName());
context.put("deviceType", deviceMetaData.getDeviceType());
return context;
}
use of org.thingsboard.server.extensions.api.device.DeviceAttributes in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicServerAttributesTest.
@Test
public void basicServerAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
List<AttributeKvEntry> serverAttributes = new ArrayList<>();
serverAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
serverAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(new ArrayList<>(), serverAttributes, new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
use of org.thingsboard.server.extensions.api.device.DeviceAttributes in project thingsboard by thingsboard.
the class DeviceAttributesFilterTest method basicClientAttributesTest.
@Test
public void basicClientAttributesTest() {
DeviceAttributesFilter filter = new DeviceAttributesFilter();
filter.init(wrap("doubleValue == 1.0 && booleanValue == false"));
List<AttributeKvEntry> clientAttributes = new ArrayList<>();
clientAttributes.add(new BaseAttributeKvEntry(new DoubleDataEntry("doubleValue", 1.0), 42));
clientAttributes.add(new BaseAttributeKvEntry(new BooleanDataEntry("booleanValue", false), 42));
DeviceAttributes attributes = new DeviceAttributes(clientAttributes, new ArrayList<>(), new ArrayList<>());
Mockito.when(ruleCtx.getDeviceMetaData()).thenReturn(new DeviceMetaData(new DeviceId(UUID.randomUUID()), "A", "A", attributes));
Assert.assertTrue(filter.filter(ruleCtx, null));
filter.stop();
}
Aggregations