use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.
the class WriteTest method write_string_resource.
private void write_string_resource(ContentFormat format) throws InterruptedException {
// write resource
String expectedvalue = "stringvalue";
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_ID, expectedvalue));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read resource to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TEST_OBJECT_ID, 0, STRING_RESOURCE_ID));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertEquals(expectedvalue, resource.getValue());
}
use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.
the class DeleteTest method cannot_delete_resource_of_created_object_instance.
@Test
public void cannot_delete_resource_of_created_object_instance() throws InterruptedException {
// create ACL instance
helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mObjectInstance(0, Arrays.asList(new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }))));
// try to delete this instance
DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest("/2/0/0"));
// verify result
assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.
the class DeleteTest method delete_created_object_instance.
@Test
public void delete_created_object_instance() throws InterruptedException {
// create ACL instance
helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mObjectInstance(0, Arrays.asList(new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(0, 123) }))));
// try to delete this instance
DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest(2, 0));
// verify result
assertEquals(ResponseCode.DELETED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.node.LwM2mResource 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());
}
use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_power_source__multiple_resource.
@Test
public void tlv_power_source__multiple_resource() throws CodecException {
// this content (a single TLV of type 'multiple_resource' containing the values)
// is probably not compliant with the spec but it should be supported by the server
byte[] content = new byte[] { -122, 6, 65, 0, 1, 65, 1, 5 };
LwM2mResource resource = (LwM2mResource) decoder.decode(content, ContentFormat.TLV, new LwM2mPath(3, 0, 6), model);
assertEquals(6, resource.getId());
assertEquals(2, resource.getValues().size());
assertEquals(1L, resource.getValue(0));
assertEquals(5L, resource.getValue(1));
}
Aggregations