use of org.eclipse.leshan.core.node.LwM2mMultipleResource in project leshan by eclipse.
the class WriteTest method can_write_multi_instance_objlnk_resource_in_tlv.
@Test
public void can_write_multi_instance_objlnk_resource_in_tlv() throws InterruptedException {
Map<Integer, ObjectLink> neighbourCellReport = new HashMap<>();
neighbourCellReport.put(0, new ObjectLink(10245, 1));
neighbourCellReport.put(1, new ObjectLink(10242, 2));
neighbourCellReport.put(2, new ObjectLink(10244, 3));
// Write objlnk resource in TLV format
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID, neighbourCellReport, Type.OBJLNK));
// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// Reading back the written OBJLNK value
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_MULTI_INSTANCE_RESOURCE_ID));
LwM2mMultipleResource resource = (LwM2mMultipleResource) readResponse.getContent();
// verify read value
assertEquals(((ObjectLink) resource.getValue(0)).getObjectId(), 10245);
assertEquals(((ObjectLink) resource.getValue(0)).getObjectInstanceId(), 1);
assertEquals(((ObjectLink) resource.getValue(1)).getObjectId(), 10242);
assertEquals(((ObjectLink) resource.getValue(1)).getObjectInstanceId(), 2);
assertEquals(((ObjectLink) resource.getValue(2)).getObjectId(), 10244);
assertEquals(((ObjectLink) resource.getValue(2)).getObjectInstanceId(), 3);
}
use of org.eclipse.leshan.core.node.LwM2mMultipleResource in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_empty_multi_resource.
@Test
public void json_empty_multi_resource() {
// Completely empty
StringBuilder b = new StringBuilder();
b.append("{}");
LwM2mResource resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
// with empty resource list
b = new StringBuilder();
b.append("{\"e\":[]}");
resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
// with empty resources list and base name
b = new StringBuilder();
b.append("{\"bn\":\"3/0/6\", \"e\":[]}");
resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mMultipleResource in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_empty_multi_resource.
@Test
public void tlv_empty_multi_resource() {
byte[] content = TlvEncoder.encode(new Tlv[] {}).array();
LwM2mResource resource = (LwM2mResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
}
Aggregations