use of org.eclipse.leshan.core.request.ExecuteRequest in project leshan by eclipse.
the class ExecuteTest method can_execute_resource.
@Test
public void can_execute_resource() throws InterruptedException {
// execute reboot resource on device
ExecuteResponse response = helper.server.send(helper.getCurrentRegistration(), new ExecuteRequest(3, 0, 4));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.request.ExecuteRequest in project leshan by eclipse.
the class ExecuteTest method cannot_execute_read_only_resource.
@Test
public void cannot_execute_read_only_resource() throws InterruptedException {
// execute manufacturer resource on device
ExecuteResponse response = helper.server.send(helper.getCurrentRegistration(), new ExecuteRequest(3, 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.request.ExecuteRequest in project leshan by eclipse.
the class ExecuteTest method cannot_execute_nonexisting_resource_on_existing_object.
@Test
public void cannot_execute_nonexisting_resource_on_existing_object() throws InterruptedException {
int nonExistingResourceId = 9999;
// execute non existing resource on device
ExecuteResponse response = helper.server.send(helper.getCurrentRegistration(), new ExecuteRequest(3, 0, nonExistingResourceId));
// verify result
assertEquals(ResponseCode.NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.request.ExecuteRequest in project leshan by eclipse.
the class ExecuteTest method cannot_execute_nonexisting_resource_on_non_existing_object.
@Test
public void cannot_execute_nonexisting_resource_on_non_existing_object() throws InterruptedException {
int nonExistingObjectId = 9999;
ExecuteResponse response = helper.server.send(helper.getCurrentRegistration(), new ExecuteRequest(nonExistingObjectId, 0, 0));
// verify result
assertEquals(ResponseCode.NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.request.ExecuteRequest in project leshan by eclipse.
the class CoapRequestBuilderTest method build_execute_request.
@Test
public void build_execute_request() throws Exception {
Registration reg = newRegistration();
// test
CoapRequestBuilder builder = new CoapRequestBuilder(reg.getIdentity(), reg.getRootPath(), reg.getId(), reg.getEndpoint(), model, encoder);
ExecuteRequest request = new ExecuteRequest(3, 0, 12, "params");
builder.visit(request);
// verify
Request coapRequest = builder.getRequest();
assertEquals(CoAP.Code.POST, coapRequest.getCode());
assertEquals("127.0.0.1", coapRequest.getDestinationContext().getPeerAddress().getAddress().getHostAddress());
assertEquals(12354, coapRequest.getDestinationContext().getPeerAddress().getPort());
assertEquals("coap://127.0.0.1:12354/3/0/12", coapRequest.getURI());
assertEquals("params", coapRequest.getPayloadString());
}
Aggregations