use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method tlv_encode_device_object_instance_as_instance.
@Test
public void tlv_encode_device_object_instance_as_instance() {
LwM2mObjectInstance oInstance = new LwM2mObjectInstance(0, getDeviceResources());
byte[] encoded = encoder.encode(oInstance, ContentFormat.TLV, new LwM2mPath("/3"), model);
Assert.assertArrayEquals(ENCODED_DEVICE_WITH_INSTANCE, encoded);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method tlv_encode_device_object.
@Test
public void tlv_encode_device_object() {
LwM2mObject object = new LwM2mObject(3, new LwM2mObjectInstance(0, getDeviceResources()));
byte[] encoded = encoder.encode(object, ContentFormat.TLV, new LwM2mPath("/3"), model);
// encoded as an array of resource TLVs
Assert.assertArrayEquals(ENCODED_DEVICE_WITH_INSTANCE, encoded);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method json_encode_timestamped_Object.
@Test
public void json_encode_timestamped_Object() throws CodecException {
List<TimestampedLwM2mNode> data = new ArrayList<>();
LwM2mObject objectAt210 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.9)));
LwM2mObject objectAt220 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.4), LwM2mSingleResource.newStringResource(0, "a string")), new LwM2mObjectInstance(1, LwM2mSingleResource.newFloatResource(1, 23)));
LwM2mObject objetAt230 = new LwM2mObject(1204, new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 24.1)));
data.add(new TimestampedLwM2mNode(210L, objectAt210));
data.add(new TimestampedLwM2mNode(220L, objectAt220));
data.add(new TimestampedLwM2mNode(230L, objetAt230));
byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024), model);
StringBuilder b = new StringBuilder();
b.append("{\"bn\":\"/1024\",\"e\":[");
b.append("{\"n\":\"0/1\",\"v\":22.9,\"t\":210},");
b.append("{\"n\":\"0/0\",\"sv\":\"a string\",\"t\":220},");
b.append("{\"n\":\"0/1\",\"v\":22.4,\"t\":220},");
b.append("{\"n\":\"1/1\",\"v\":23,\"t\":220},");
b.append("{\"n\":\"0/1\",\"v\":24.1,\"t\":230}]}");
String expected = b.toString();
Assert.assertEquals(expected, new String(encoded));
}
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.
@Test
public void tlv_encode_device_object_instance_as_resources_array() {
LwM2mObjectInstance oInstance = new LwM2mObjectInstance(0, getDeviceResources());
byte[] encoded = encoder.encode(oInstance, ContentFormat.TLV, new LwM2mPath("/3/0"), model);
Assert.assertArrayEquals(ENCODED_DEVICE_WITHOUT_INSTANCE, encoded);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeEncoderTest method json_encode_timestamped_resources.
@Test
public void json_encode_timestamped_resources() throws CodecException {
List<TimestampedLwM2mNode> data = new ArrayList<>();
data.add(new TimestampedLwM2mNode(500L, LwM2mSingleResource.newFloatResource(1, 22.9)));
data.add(new TimestampedLwM2mNode(510L, LwM2mSingleResource.newFloatResource(1, 22.4)));
data.add(new TimestampedLwM2mNode(520L, LwM2mSingleResource.newFloatResource(1, 24.1)));
byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024, 0, 1), model);
StringBuilder b = new StringBuilder();
b.append("{\"bn\":\"/1024/0/1\",\"e\":[");
b.append("{\"n\":\"\",\"v\":22.9,\"t\":500},");
b.append("{\"n\":\"\",\"v\":22.4,\"t\":510},");
b.append("{\"n\":\"\",\"v\":24.1,\"t\":520}]}");
String expected = b.toString();
Assert.assertEquals(expected, new String(encoded));
}
Aggregations