Search in sources :

Example 6 with ObjectLink

use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.

the class WriteTest method can_write_single_instance_objlnk_resource_in_tlv.

@Test
public void can_write_single_instance_objlnk_resource_in_tlv() throws InterruptedException {
    ObjectLink data = new ObjectLink(10245, 1);
    // Write objlnk resource in TLV format
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, data));
    // 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_SINGLE_INSTANCE_RESOURCE_ID));
    LwM2mSingleResource resource = (LwM2mSingleResource) readResponse.getContent();
    // verify read value
    assertEquals(((ObjectLink) resource.getValue()).getObjectId(), 10245);
    assertEquals(((ObjectLink) resource.getValue()).getObjectInstanceId(), 1);
}
Also used : LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) 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 7 with ObjectLink

use of org.eclipse.leshan.core.node.ObjectLink 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());
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) ObjectLink(org.eclipse.leshan.core.node.ObjectLink)

Example 8 with ObjectLink

use of org.eclipse.leshan.core.node.ObjectLink in project leshan by eclipse.

the class LwM2mNodeDecoderTest method assertObj65Instance.

private void assertObj65Instance(LwM2mObjectInstance instance) {
    assertEquals(0, instance.getId());
    // instance 1
    assertEquals(2, instance.getResource(0).getValues().size());
    assertEquals(new ObjectLink(66, 0), instance.getResource(0).getValue(0));
    assertEquals(new ObjectLink(66, 1), instance.getResource(0).getValue(1));
    assertEquals("8613800755500", instance.getResource(1).getValue());
    assertEquals(305419896L, instance.getResource(2).getValue());
}
Also used : ObjectLink(org.eclipse.leshan.core.node.ObjectLink)

Aggregations

ObjectLink (org.eclipse.leshan.core.node.ObjectLink)8 Test (org.junit.Test)5 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)3 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)3 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)3 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)3 LwM2mSingleResource (org.eclipse.leshan.core.node.LwM2mSingleResource)2 ByteBuffer (java.nio.ByteBuffer)1 HashMap (java.util.HashMap)1 LwM2mMultipleResource (org.eclipse.leshan.core.node.LwM2mMultipleResource)1 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)1 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)1 Tlv (org.eclipse.leshan.tlv.Tlv)1