use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method text_encode_single_resource.
@Test
public void text_encode_single_resource() {
byte[] encoded = encoder.encode(LwM2mSingleResource.newFloatResource(15, 56.4D), ContentFormat.TEXT, new LwM2mPath("/323/0/15"), model);
Assert.assertEquals("56.4", new String(encoded, StandardCharsets.UTF_8));
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method tlv_encode_device_object_instance_as_resources_array__undefined_instance_id.
@Test
public void tlv_encode_device_object_instance_as_resources_array__undefined_instance_id() {
LwM2mObjectInstance oInstance = new LwM2mObjectInstance(LwM2mObjectInstance.UNDEFINED, getDeviceResources());
byte[] encoded = encoder.encode(oInstance, ContentFormat.TLV, new LwM2mPath("/3"), model);
Assert.assertArrayEquals(ENCODED_DEVICE_WITHOUT_INSTANCE, encoded);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_instance_tlv.
@Test
public void tlv_device_object_instance0_from_instance_tlv() throws CodecException {
LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(ENCODED_DEVICE_WITH_INSTANCE, ContentFormat.TLV, new LwM2mPath(3, 0), model);
assertDeviceInstance(oInstance);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_unknown_object__missing_instance_tlv.
@Test
public void tlv_unknown_object__missing_instance_tlv() throws CodecException {
byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, "value1".getBytes(), 1), new Tlv(TlvType.RESOURCE_VALUE, null, "value1".getBytes(), 2) }).array();
LwM2mObject obj = (LwM2mObject) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(10234), model);
assertEquals(1, obj.getInstances().size());
assertEquals(2, obj.getInstance(0).getResources().size());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_timestamped_instances.
@Test
public void json_timestamped_instances() throws CodecException {
// json content for instance 0 of device object
StringBuilder b = new StringBuilder();
b.append("{\"e\":[");
b.append("{\"n\":\"1\",\"v\":22.9,\"t\":-30},");
b.append("{\"n\":\"1\",\"v\":22.4,\"t\":-5},");
b.append("{\"n\":\"0\",\"sv\":\"a string\",\"t\":-5},");
b.append("{\"n\":\"1\",\"v\":24.1,\"t\":-50}],");
b.append("\"bt\":25462634}");
List<TimestampedLwM2mNode> timestampedResources = decoder.decodeTimestampedData(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(1024, 0), model);
assertEquals(3, timestampedResources.size());
assertEquals(Long.valueOf(25462634L - 5), timestampedResources.get(0).getTimestamp());
assertEquals("a string", ((LwM2mObjectInstance) timestampedResources.get(0).getNode()).getResource(0).getValue());
assertEquals(22.4d, ((LwM2mObjectInstance) timestampedResources.get(0).getNode()).getResource(1).getValue());
assertEquals(Long.valueOf(25462634L - 30), timestampedResources.get(1).getTimestamp());
assertEquals(22.9d, ((LwM2mObjectInstance) timestampedResources.get(1).getNode()).getResource(1).getValue());
assertEquals(Long.valueOf(25462634 - 50), timestampedResources.get(2).getTimestamp());
assertEquals(24.1d, ((LwM2mObjectInstance) timestampedResources.get(2).getNode()).getResource(1).getValue());
}
Aggregations