Search in sources :

Example 6 with ExecuteResponse

use of org.eclipse.leshan.core.response.ExecuteResponse in project leshan by eclipse.

the class IntegrationTestHelper method createClient.

public void createClient() {
    // Create objects Enabler
    ObjectsInitializer initializer = new ObjectsInitializer(new LwM2mModel(createObjectModels()));
    initializer.setInstancesForObject(LwM2mId.SECURITY, Security.noSec("coap://" + server.getUnsecuredAddress().getHostString() + ":" + server.getUnsecuredAddress().getPort(), 12345));
    initializer.setInstancesForObject(LwM2mId.SERVER, new Server(12345, LIFETIME, BindingMode.U, false));
    initializer.setInstancesForObject(LwM2mId.DEVICE, new Device("Eclipse Leshan", MODEL_NUMBER, "12345", "U") {

        @Override
        public ExecuteResponse execute(int resourceid, String params) {
            if (resourceid == 4) {
                return ExecuteResponse.success();
            } else {
                return super.execute(resourceid, params);
            }
        }
    });
    List<LwM2mObjectEnabler> objects = initializer.createMandatory();
    objects.addAll(initializer.create(2, 2000));
    // Build Client
    LeshanClientBuilder builder = new LeshanClientBuilder(currentEndpointIdentifier.get());
    builder.setObjects(objects);
    client = builder.build();
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) Server(org.eclipse.leshan.client.object.Server) LeshanServer(org.eclipse.leshan.server.californium.impl.LeshanServer) ObjectsInitializer(org.eclipse.leshan.client.resource.ObjectsInitializer) Device(org.eclipse.leshan.client.object.Device) LeshanClientBuilder(org.eclipse.leshan.client.californium.LeshanClientBuilder) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) LwM2mModel(org.eclipse.leshan.core.model.LwM2mModel)

Example 7 with ExecuteResponse

use of org.eclipse.leshan.core.response.ExecuteResponse in project leshan by eclipse.

the class ExecuteTest method cannot_execute_read_write_resource.

@Test
public void cannot_execute_read_write_resource() throws InterruptedException {
    // execute current time resource on device
    ExecuteResponse response = helper.server.send(helper.getCurrentRegistration(), new ExecuteRequest(3, 0, 13));
    // 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 ExecuteResponse

use of org.eclipse.leshan.core.response.ExecuteResponse 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 9 with ExecuteResponse

use of org.eclipse.leshan.core.response.ExecuteResponse 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 10 with ExecuteResponse

use of org.eclipse.leshan.core.response.ExecuteResponse 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)

Aggregations

ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)13 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)9 Test (org.junit.Test)7 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)4 LwM2mModel (org.eclipse.leshan.core.model.LwM2mModel)3 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)3 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)3 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)3 JsonObject (com.eclipsesource.json.JsonObject)2 LeshanClientBuilder (org.eclipse.leshan.client.californium.LeshanClientBuilder)2 Device (org.eclipse.leshan.client.object.Device)2 Server (org.eclipse.leshan.client.object.Server)2 LwM2mObjectEnabler (org.eclipse.leshan.client.resource.LwM2mObjectEnabler)2 ObjectsInitializer (org.eclipse.leshan.client.resource.ObjectsInitializer)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)2 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)2 DeleteResponse (org.eclipse.leshan.core.response.DeleteResponse)2 DiscoverResponse (org.eclipse.leshan.core.response.DiscoverResponse)2 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)2