Search in sources :

Example 6 with ExecuteRequest

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)));
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) Test(org.junit.Test)

Example 7 with ExecuteRequest

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)));
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) Test(org.junit.Test)

Example 8 with ExecuteRequest

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)));
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) Test(org.junit.Test)

Example 9 with ExecuteRequest

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)));
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) Test(org.junit.Test)

Example 10 with ExecuteRequest

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());
}
Also used : ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) Registration(org.eclipse.leshan.server.registration.Registration) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) ExecuteRequest(org.eclipse.leshan.core.request.ExecuteRequest) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) ObserveRequest(org.eclipse.leshan.core.request.ObserveRequest) WriteAttributesRequest(org.eclipse.leshan.core.request.WriteAttributesRequest) Request(org.eclipse.californium.core.coap.Request) DiscoverRequest(org.eclipse.leshan.core.request.DiscoverRequest) Test(org.junit.Test)

Aggregations

ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)12 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)9 Test (org.junit.Test)8 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)5 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)4 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)4 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)3 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)3 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)3 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)3 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)3 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)3 JsonArray (com.eclipsesource.json.JsonArray)2 JsonObject (com.eclipsesource.json.JsonObject)2 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)2 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)2 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)2 Registration (org.eclipse.leshan.server.registration.Registration)2 JsonValue (com.eclipsesource.json.JsonValue)1 Collection (java.util.Collection)1