Search in sources :

Example 1 with LwM2mMultipleResource

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);
}
Also used : LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) HashMap(java.util.HashMap) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) ObjectLink(org.eclipse.leshan.core.node.ObjectLink) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 2 with LwM2mMultipleResource

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());
}
Also used : LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 3 with LwM2mMultipleResource

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());
}
Also used : LwM2mMultipleResource(org.eclipse.leshan.core.node.LwM2mMultipleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Tlv(org.eclipse.leshan.tlv.Tlv) Test(org.junit.Test)

Aggregations

LwM2mMultipleResource (org.eclipse.leshan.core.node.LwM2mMultipleResource)3 Test (org.junit.Test)3 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)2 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)2 HashMap (java.util.HashMap)1 ObjectLink (org.eclipse.leshan.core.node.ObjectLink)1 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)1 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)1 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)1 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)1 Tlv (org.eclipse.leshan.tlv.Tlv)1