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)));
}
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");
}
}
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)));
}
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)));
}
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)));
}
Aggregations