Search in sources :

Example 6 with DeleteResponse

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

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

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

Example 9 with DeleteResponse

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

the class ResponseSerDes method deserialize.

public static LwM2mResponse deserialize(JsonObject o) {
    String sCode = o.getString("code", null);
    if (sCode == null)
        throw new IllegalStateException("Invalid response missing code attribute");
    ResponseCode code = ResponseCode.fromName(sCode);
    String errorMessage = o.getString("errorMessage", null);
    String kind = o.getString("kind", null);
    switch(kind) {
        case "observe":
            {
                // TODO ser Observation
                LwM2mNode content = LwM2mNodeSerDes.deserialize((JsonObject) o.get("content"));
                return new ObserveResponse(code, content, null, null, errorMessage);
            }
        case "delete":
            return new DeleteResponse(code, errorMessage);
        case "discover":
            String objectLinks = o.getString("objectLinks", "");
            return new DiscoverResponse(code, Link.parse(objectLinks.getBytes()), errorMessage);
        case "create":
            {
                String location = o.getString("location", null);
                return new CreateResponse(code, location, errorMessage);
            }
        case "execute":
            return new ExecuteResponse(code, errorMessage);
        case "writeAttributes":
            {
                return new WriteAttributesResponse(code, errorMessage);
            }
        case "write":
            {
                return new WriteResponse(code, errorMessage);
            }
        case "read":
            {
                LwM2mNode content = LwM2mNodeSerDes.deserialize((JsonObject) o.get("content"));
                return new ReadResponse(code, content, errorMessage);
            }
        default:
            throw new IllegalStateException("Invalid response missing kind attribute");
    }
}
Also used : ResponseCode(org.eclipse.leshan.ResponseCode) CreateResponse(org.eclipse.leshan.core.response.CreateResponse) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) JsonObject(com.eclipsesource.json.JsonObject) WriteAttributesResponse(org.eclipse.leshan.core.response.WriteAttributesResponse) DiscoverResponse(org.eclipse.leshan.core.response.DiscoverResponse) ExecuteResponse(org.eclipse.leshan.core.response.ExecuteResponse) LwM2mNode(org.eclipse.leshan.core.node.LwM2mNode) ObserveResponse(org.eclipse.leshan.core.response.ObserveResponse) DeleteResponse(org.eclipse.leshan.core.response.DeleteResponse) ReadResponse(org.eclipse.leshan.core.response.ReadResponse)

Aggregations

DeleteResponse (org.eclipse.leshan.core.response.DeleteResponse)9 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)7 Test (org.junit.Test)5 JsonObject (com.eclipsesource.json.JsonObject)2 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)2 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)2 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)2 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)2 DiscoverResponse (org.eclipse.leshan.core.response.DiscoverResponse)2 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)2 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)2 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)2 WriteAttributesResponse (org.eclipse.leshan.core.response.WriteAttributesResponse)2 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)2 ResponseCode (org.eclipse.leshan.ResponseCode)1 ResourceUtil.extractServerIdentity (org.eclipse.leshan.client.californium.impl.ResourceUtil.extractServerIdentity)1 ServerIdentity (org.eclipse.leshan.client.request.ServerIdentity)1 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)1 Registration (org.eclipse.leshan.server.registration.Registration)1