use of org.eclipse.leshan.core.node.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_device_object_instance0.
@Test
public void json_device_object_instance0() throws CodecException {
// json content for instance 0 of device object
StringBuilder b = new StringBuilder();
b.append("{\"e\":[");
b.append("{\"n\":\"0\",\"sv\":\"Open Mobile Alliance\"},");
b.append("{\"n\":\"1\",\"sv\":\"Lightweight M2M Client\"},");
b.append("{\"n\":\"2\",\"sv\":\"345000123\"},");
b.append("{\"n\":\"3\",\"sv\":\"1.0\"},");
b.append("{\"n\":\"6/0\",\"v\":1},");
b.append("{\"n\":\"6/1\",\"v\":5},");
b.append("{\"n\":\"7/0\",\"v\":3800},");
b.append("{\"n\":\"7/1\",\"v\":5000},");
b.append("{\"n\":\"8/0\",\"v\":125},");
b.append("{\"n\":\"8/1\",\"v\":900},");
b.append("{\"n\":\"9\",\"v\":100},");
b.append("{\"n\":\"10\",\"v\":15},");
b.append("{\"n\":\"11/0\",\"v\":0},");
b.append("{\"n\":\"13\",\"v\":1367491215},");
b.append("{\"n\":\"14\",\"sv\":\"+02:00\"},");
b.append("{\"n\":\"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.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeDecoderTest method assertObj66Instance.
private void assertObj66Instance(LwM2mObject oObject) {
assertEquals(66, oObject.getId());
assertEquals(2, oObject.getInstances().size());
// instance 1
LwM2mObjectInstance oInstance0 = oObject.getInstance(0);
assertEquals("myService 1", oInstance0.getResource(0).getValue());
assertEquals("Internet.15.234", oInstance0.getResource(1).getValue());
assertEquals(new ObjectLink(67, 0), oInstance0.getResource(2).getValue());
// instance 2
LwM2mObjectInstance oInstance2 = oObject.getInstance(1);
assertEquals("myService 2", oInstance2.getResource(0).getValue());
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_empty_instance.
@Test
public void tlv_empty_instance() {
byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
LwM2mObjectInstance instance = (LwM2mObjectInstance) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(2, 0), model);
assertNotNull(instance);
assertEquals(0, instance.getId());
assertTrue(instance.getResources().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_empty_instance.
@Test
public void json_empty_instance() {
// Completely empty
StringBuilder b = new StringBuilder();
b.append("{}");
LwM2mObjectInstance instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
assertNotNull(instance);
assertEquals(0, instance.getId());
assertTrue(instance.getResources().isEmpty());
// with empty resource list
b = new StringBuilder();
b.append("{\"e\":[]}");
instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
assertNotNull(instance);
assertEquals(0, instance.getId());
assertTrue(instance.getResources().isEmpty());
// with empty resources list and base name
b = new StringBuilder();
b.append("{\"bn\":\"2/0\", \"e\":[]}");
instance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0), model);
assertNotNull(instance);
assertEquals(0, instance.getId());
assertTrue(instance.getResources().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mObjectInstance in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_resources_tlv__instance_expected.
@Test
public void tlv_device_object_instance0_from_resources_tlv__instance_expected() throws CodecException {
LwM2mObjectInstance oInstance = decoder.decode(ENCODED_DEVICE_WITHOUT_INSTANCE, ContentFormat.TLV, new LwM2mPath(3), model, LwM2mObjectInstance.class);
assertDeviceInstance(oInstance);
}
Aggregations