use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_device_object_instance0_with_root_basename.
@Test
public void json_device_object_instance0_with_root_basename() throws CodecException {
// json content for instance 0 of device object
StringBuilder b = new StringBuilder();
b.append("{\"bn\":\"/\",");
b.append("\"e\":[");
b.append("{\"n\":\"3/0/0\",\"sv\":\"Open Mobile Alliance\"},");
b.append("{\"n\":\"3/0/1\",\"sv\":\"Lightweight M2M Client\"},");
b.append("{\"n\":\"3/0/2\",\"sv\":\"345000123\"},");
b.append("{\"n\":\"3/0/3\",\"sv\":\"1.0\"},");
b.append("{\"n\":\"3/0/6/0\",\"v\":1},");
b.append("{\"n\":\"3/0/6/1\",\"v\":5},");
b.append("{\"n\":\"3/0/7/0\",\"v\":3800},");
b.append("{\"n\":\"3/0/7/1\",\"v\":5000},");
b.append("{\"n\":\"3/0/8/0\",\"v\":125},");
b.append("{\"n\":\"3/0/8/1\",\"v\":900},");
b.append("{\"n\":\"3/0/9\",\"v\":100},");
b.append("{\"n\":\"3/0/10\",\"v\":15},");
b.append("{\"n\":\"3/0/11/0\",\"v\":0},");
b.append("{\"n\":\"3/0/13\",\"v\":1367491215},");
b.append("{\"n\":\"3/0/14\",\"sv\":\"+02:00\"},");
b.append("{\"n\":\"3/0/16\",\"sv\":\"U\"}]}");
LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, 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_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.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_multi_instance_object__missing_instance_tlv.
@Test(expected = CodecException.class)
public void tlv_multi_instance_object__missing_instance_tlv() throws CodecException {
byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(11), 1), new Tlv(TlvType.RESOURCE_VALUE, null, TlvEncoder.encodeInteger(10), 2) }).array();
decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2), model);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_power_source__array_values.
@Test
public void tlv_power_source__array_values() throws CodecException {
byte[] content = new byte[] { 65, 0, 1, 65, 1, 5 };
LwM2mResource resource = (LwM2mResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 6), model);
assertEquals(6, resource.getId());
assertEquals(2, resource.getValues().size());
assertEquals(1L, resource.getValue(0));
assertEquals(5L, resource.getValue(1));
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_invalid_multi_resource_2_instance_with_the_same_id.
@Test(expected = CodecException.class)
public void tlv_invalid_multi_resource_2_instance_with_the_same_id() {
Tlv resInstance1 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(100, 1)), 0);
Tlv resInstance2 = new Tlv(TlvType.RESOURCE_INSTANCE, null, TlvEncoder.encodeObjlnk(new ObjectLink(101, 2)), 0);
Tlv multiResource = new Tlv(TlvType.MULTIPLE_RESOURCE, new Tlv[] { resInstance1, resInstance2 }, null, 22);
byte[] content = TlvEncoder.encode(new Tlv[] { multiResource }).array();
decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 22), model);
}
Aggregations