use of org.eclipse.leshan.core.node.LwM2mObject 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.LwM2mObject 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.LwM2mObject in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_empty_object.
@Test
public void tlv_empty_object() {
byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
LwM2mObject obj = (LwM2mObject) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
assertNotNull(obj);
assertEquals(2, obj.getId());
assertTrue(obj.getInstances().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mObject in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_empty_object.
@Test
public void json_empty_object() {
// Completely empty
StringBuilder b = new StringBuilder();
b.append("{}");
LwM2mObject obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2), model);
assertNotNull(obj);
assertEquals(2, obj.getId());
assertTrue(obj.getInstances().isEmpty());
// with empty resource list
b = new StringBuilder();
b.append("{\"e\":[]}");
obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2), model);
assertNotNull(obj);
assertEquals(2, obj.getId());
assertTrue(obj.getInstances().isEmpty());
// with empty resources list and base name
b = new StringBuilder();
b.append("{\"bn\":\"2\", \"e\":[]}");
obj = (LwM2mObject) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2), model);
assertNotNull(obj);
assertEquals(2, obj.getId());
assertTrue(obj.getInstances().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mObject in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_acl_object_multi_instance.
@Test
public void tlv_acl_object_multi_instance() throws Exception {
LwM2mObject oObject = ((LwM2mObject) decoder.decode(ENCODED_ACL, ContentFormat.TLV, new LwM2mPath(2), model));
assertAclInstances(oObject);
}
Aggregations