Skip to content

Commit

Permalink
DeleteRequest should target object instance only.
Browse files Browse the repository at this point in the history
Signed-off-by: Rokwoon Kim <k862390@gmail.com>
Also-by: Simon Bernard <sbernard@sierrawireless.com>
  • Loading branch information
rkimsb2 authored and sbernard31 committed Jul 11, 2018
1 parent a45b093 commit a7c958a
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public DeleteRequest(int objectId, int objectInstanceId) {
* @exception InvalidRequestException if the path is not valid.
*/
public DeleteRequest(String path) throws InvalidRequestException {
super(newPath(path));
this(newPath(path));
}

private DeleteRequest(LwM2mPath target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ public DiscoverRequest(int objectId, int objectInstanceId, int resourceId) {
* @exception InvalidRequestException if the path is not valid.
*/
public DiscoverRequest(String path) throws InvalidRequestException {
super(newPath(path));
this(newPath(path));
}

private DiscoverRequest(LwM2mPath target) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@

import java.util.Arrays;

import org.eclipse.californium.core.coap.Request;
import org.eclipse.californium.core.coap.Response;
import org.eclipse.leshan.ResponseCode;
import org.eclipse.leshan.core.node.LwM2mObjectInstance;
Expand Down Expand Up @@ -61,10 +62,8 @@ public void stop() {
@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) }))));
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));
Expand All @@ -76,20 +75,18 @@ public void delete_created_object_instance() throws InterruptedException {
}

@Test
public void cannot_delete_resource_of_created_object_instance() throws InterruptedException {
public void cannot_delete_resource() throws InterruptedException {
// create ACL instance
helper.server.send(
helper.getCurrentRegistration(),
new CreateRequest(2, new LwM2mObjectInstance(0, Arrays.asList(new LwM2mResource[] { LwM2mSingleResource
.newIntegerResource(0, 123) }))));
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"));
// try to delete this resource using coap API as lwm2m API does not allow it.
Request delete = Request.newDelete();
delete.getOptions().addUriPath("2").addUriPath("0").addUriPath("0");
Response response = helper.server.coap().send(helper.getCurrentRegistration(), delete);

// verify result
assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
assertEquals(org.eclipse.californium.core.coap.CoAP.ResponseCode.BAD_REQUEST, response.getCode());
}

@Test
Expand Down

0 comments on commit a7c958a

Please sign in to comment.