Search in sources :

Example 6 with DeleteRequest

use of org.eclipse.leshan.core.request.DeleteRequest in project leshan by eclipse.

the class DeleteTest method cannot_delete_single_manadatory_object_instance.

@Test
public void cannot_delete_single_manadatory_object_instance() throws InterruptedException {
    // try to create an instance of object 50
    DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest(3, 0));
    // verify result
    assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) Test(org.junit.Test)

Example 7 with DeleteRequest

use of org.eclipse.leshan.core.request.DeleteRequest in project leshan by eclipse.

the class BootstrapHandler method delete.

public synchronized BootstrapDeleteResponse delete(ServerIdentity identity, BootstrapDeleteRequest deleteRequest) {
    if (bootstrapping) {
        // Only if the request is from the bootstrap server
        if (!isBootstrapServer(identity)) {
            return BootstrapDeleteResponse.badRequest("not from a bootstrap server");
        }
        // The spec say that delete on "/" should delete all the existing Object Instances - except LWM2M
        // Bootstrap Server Account, (see 5.2.5.2 Bootstrap Delete)
        // For now we only remove security and server object.
        // Delete all device management server
        LwM2mObjectEnabler serverObject = objects.get(SERVER);
        for (Integer instanceId : serverObject.getAvailableInstanceIds()) {
            serverObject.delete(identity, new DeleteRequest(SERVER, instanceId));
        }
        // Delete all security instance (except bootstrap one)
        // TODO do not delete bootstrap server (see 5.2.5.2 Bootstrap Delete)
        LwM2mObjectEnabler securityObject = objects.get(SECURITY);
        for (Integer instanceId : securityObject.getAvailableInstanceIds()) {
            securityObject.delete(identity, new DeleteRequest(SECURITY, instanceId));
        }
        return BootstrapDeleteResponse.success();
    } else {
        return BootstrapDeleteResponse.badRequest("no pending bootstrap session");
    }
}
Also used : LwM2mObjectEnabler(org.eclipse.leshan.client.resource.LwM2mObjectEnabler) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) BootstrapDeleteRequest(org.eclipse.leshan.core.request.BootstrapDeleteRequest)

Example 8 with DeleteRequest

use of org.eclipse.leshan.core.request.DeleteRequest 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)));
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 9 with DeleteRequest

use of org.eclipse.leshan.core.request.DeleteRequest in project leshan by eclipse.

the class DeleteTest method cannot_delete_unknown_object_instance.

@Test
public void cannot_delete_unknown_object_instance() throws InterruptedException {
    // try to create an instance of object 50
    DeleteResponse response = helper.server.send(helper.getCurrentRegistration(), new DeleteRequest(2, 0));
    // verify result
    assertEquals(ResponseCode.NOT_FOUND, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) Test(org.junit.Test)

Example 10 with DeleteRequest

use of org.eclipse.leshan.core.request.DeleteRequest 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)));
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) DeleteRequest(org.eclipse.leshan.core.request.DeleteRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Aggregations

DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)11 DeleteResponse (org.eclipse.leshan.core.response.DeleteResponse)7 Test (org.junit.Test)6 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)5 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)4 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)3 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)3 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)3 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)3 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)3 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)3 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)3 JsonArray (com.eclipsesource.json.JsonArray)2 JsonObject (com.eclipsesource.json.JsonObject)2 Registration (org.eclipse.leshan.server.registration.Registration)2 JsonValue (com.eclipsesource.json.JsonValue)1 Collection (java.util.Collection)1 Request (org.eclipse.californium.core.coap.Request)1 ResourceUtil.extractServerIdentity (org.eclipse.leshan.client.californium.impl.ResourceUtil.extractServerIdentity)1 ServerIdentity (org.eclipse.leshan.client.request.ServerIdentity)1