Search in sources :

Example 1 with LwM2mSingleResource

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

the class WriteTest method can_write_single_instance_objlnk_resource_in_text.

@Test
public void can_write_single_instance_objlnk_resource_in_text() throws InterruptedException {
    // Write objlnk resource in TEXT format
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TEXT, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, new ObjectLink(10245, 0)));
    // 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(ContentFormat.TEXT, 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(), 0);
}
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 2 with LwM2mSingleResource

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

Example 3 with LwM2mSingleResource

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

Example 4 with LwM2mSingleResource

use of org.eclipse.leshan.core.node.LwM2mSingleResource 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 5 with LwM2mSingleResource

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

the class LwM2mNodeDecoderTest method text_battery_resource.

@Test
public void text_battery_resource() throws CodecException {
    LwM2mSingleResource resource = (LwM2mSingleResource) decoder.decode("100".getBytes(StandardCharsets.UTF_8), ContentFormat.TEXT, new LwM2mPath(3, 0, 9), model);
    assertEquals(9, resource.getId());
    assertFalse(resource.isMultiInstances());
    assertEquals(Type.INTEGER, resource.getType());
    assertEquals(100, ((Number) resource.getValue()).intValue());
}
Also used : LwM2mSingleResource(org.eclipse.leshan.core.node.LwM2mSingleResource) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Aggregations

LwM2mSingleResource (org.eclipse.leshan.core.node.LwM2mSingleResource)5 Test (org.junit.Test)5 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)3 ObjectLink (org.eclipse.leshan.core.node.ObjectLink)2 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)2 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)2 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)2 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)2 Tlv (org.eclipse.leshan.tlv.Tlv)1