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);
}
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());
}
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());
}
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);
}
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());
}
Aggregations