use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class ReadTest method cannot_read_non_existent_instance.
@Test
public void cannot_read_non_existent_instance() throws InterruptedException {
// read 2nd Device resource
ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 1));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class ReadTest method cannot_read_non_readable_resource.
@Test
public void cannot_read_non_readable_resource() throws InterruptedException {
// read device reboot resource
ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 4));
// verify result
assertEquals(METHOD_NOT_ALLOWED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class RegistrationTest method deregister_cancel_multiple_pending_request.
@Test
public void deregister_cancel_multiple_pending_request() throws InterruptedException {
// Check client is not registered
helper.assertClientNotRegisterered();
// Start it and wait for registration
helper.client.start();
helper.waitForRegistration(1);
// Check client is well registered
helper.assertClientRegisterered();
assertArrayEquals(Link.parse("</>;rt=\"oma.lwm2m\",</1/0>,</2>,</3/0>,</2000/0>".getBytes()), helper.getCurrentRegistration().getObjectLinks());
// Stop client with out de-registration
helper.client.stop(false);
// Send multiple reads which should be retransmitted.
List<Callback<ReadResponse>> callbacks = new ArrayList<>();
for (int index = 0; index < 4; ++index) {
Callback<ReadResponse> callback = new Callback<>();
helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1), callback, callback);
callbacks.add(callback);
}
// Restart client (de-registration/re-registration)
helper.client.start();
// Check the request was cancelled.
int index = 0;
for (Callback<ReadResponse> callback : callbacks) {
boolean timedout = !callback.waitForResponse(1000);
assertFalse("Response or Error expected, no timeout, call " + index, timedout);
assertTrue("Response or Error expected, call " + index, callback.isCalled().get());
assertNull("No response expected, call " + index, callback.getResponse());
assertNotNull("Exception expected, call " + index, callback.getException());
++index;
}
}
use of org.eclipse.leshan.core.response.ReadResponse 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);
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method write_boolean_resource.
private void write_boolean_resource(ContentFormat format) throws InterruptedException {
// write resource
boolean expectedvalue = true;
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, BOOLEAN_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, BOOLEAN_RESOURCE_ID));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertEquals(expectedvalue, resource.getValue());
}
Aggregations