Search in sources :

Example 11 with CreateRequest

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

the class CreateTest method cannot_create_instance_without_all_required_resources.

// TODO not sure all the writable mandatory resource should be present
// E.g. for softwareUpdate (object 9) packageURI and package are writable resource mandatory
// but you will not make a create with this two resource.
@Ignore
@Test
public void cannot_create_instance_without_all_required_resources() throws InterruptedException {
    // create ACL instance
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mResource[0]));
    // verify result
    assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // try to read to check if the instance is not created
    // client registration
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2, 0));
    assertEquals(ResponseCode.NOT_FOUND, readResponse.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) CreateResponse(org.eclipse.leshan.core.response.CreateResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 12 with CreateRequest

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

the class CreateTest method cannot_create_instance_of_object.

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

Example 13 with CreateRequest

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

the class CreateTest method cannot_create_instance_of_security_object.

@Test
public void cannot_create_instance_of_security_object() throws InterruptedException {
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(0, new LwM2mResource[] { LwM2mSingleResource.newStringResource(0, "new.dest") }));
    // verify result
    assertEquals(ResponseCode.NOT_FOUND, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Also used : CreateResponse(org.eclipse.leshan.core.response.CreateResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) Test(org.junit.Test)

Example 14 with CreateRequest

use of org.eclipse.leshan.core.request.CreateRequest 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 15 with CreateRequest

use of org.eclipse.leshan.core.request.CreateRequest 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

CreateRequest (org.eclipse.leshan.core.request.CreateRequest)17 Test (org.junit.Test)12 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)10 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)10 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)10 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)6 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)6 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)6 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)6 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)5 DiscoverRequest (org.eclipse.leshan.core.request.DiscoverRequest)4 WriteAttributesRequest (org.eclipse.leshan.core.request.WriteAttributesRequest)4 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)3 Registration (org.eclipse.leshan.server.registration.Registration)3 JsonArray (com.eclipsesource.json.JsonArray)2 JsonObject (com.eclipsesource.json.JsonObject)2 Request (org.eclipse.californium.core.coap.Request)2 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)2 BootstrapWriteRequest (org.eclipse.leshan.core.request.BootstrapWriteRequest)2 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)2