use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_manufacturer_resource.
@Test
public void tlv_manufacturer_resource() throws CodecException {
String value = "MyManufacturer";
byte[] content = TlvEncoder.encode(new Tlv[] { new Tlv(TlvType.RESOURCE_VALUE, null, value.getBytes(), 0) }).array();
LwM2mSingleResource resource = (LwM2mSingleResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 0), model);
assertEquals(0, resource.getId());
assertFalse(resource.isMultiInstances());
assertEquals(value, resource.getValue());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method text_manufacturer_resource.
@Test
public void text_manufacturer_resource() throws CodecException {
String value = "MyManufacturer";
LwM2mSingleResource resource = (LwM2mSingleResource) decoder.decode(value.getBytes(StandardCharsets.UTF_8), ContentFormat.TEXT, new LwM2mPath(3, 0, 0), model);
assertEquals(0, resource.getId());
assertFalse(resource.isMultiInstances());
assertEquals(Type.STRING, resource.getType());
assertEquals(value, resource.getValue());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_custom_object_instance.
@Test
public void json_custom_object_instance() throws CodecException {
// json content for instance 0 of device object
StringBuilder b = new StringBuilder();
b.append("{\"e\":[");
b.append("{\"n\":\"0\",\"sv\":\"a string\"},");
b.append("{\"n\":\"1\",\"v\":10.5},");
b.append("{\"n\":\"2\",\"bv\":true}]}");
LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(1024, 0), model);
assertEquals(0, oInstance.getId());
assertEquals("a string", oInstance.getResource(0).getValue());
assertEquals(10.5, oInstance.getResource(1).getValue());
assertEquals(true, oInstance.getResource(2).getValue());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_empty_single_resource.
@Test(expected = CodecException.class)
public void json_empty_single_resource() {
StringBuilder b = new StringBuilder();
b.append("{}");
decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(2, 0, 0), model);
}
use of org.eclipse.leshan.core.node.LwM2mPath 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());
}
Aggregations