Search in sources :

Example 6 with CreateResponse

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

the class CreateTest method cannot_create_mandatory_single_object.

@Test
public void cannot_create_mandatory_single_object() throws InterruptedException {
    // try to create another instance of device object
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(3, new LwM2mResource[] { LwM2mSingleResource.newIntegerResource(3, 123) }));
    // verify result
    assertEquals(ResponseCode.METHOD_NOT_ALLOWED, 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 7 with CreateResponse

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

the class CreateTest method cannot_create_instance_with_extraneous_resources.

// TODO we must probably implement this.
@Ignore
@Test
public void cannot_create_instance_with_extraneous_resources() throws InterruptedException {
    // create ACL instance
    LwM2mObjectInstance instance = new LwM2mObjectInstance(0, Arrays.<LwM2mResource>asList(LwM2mSingleResource.newIntegerResource(3, 123), LwM2mSingleResource.newIntegerResource(50, 123)));
    CreateRequest request = new CreateRequest(2, instance);
    CreateResponse response = helper.server.send(helper.getCurrentRegistration(), request);
    // 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 : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) CreateRequest(org.eclipse.leshan.core.request.CreateRequest) CreateResponse(org.eclipse.leshan.core.response.CreateResponse) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Ignore(org.junit.Ignore) Test(org.junit.Test)

Example 8 with CreateResponse

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

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

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

Aggregations

CreateResponse (org.eclipse.leshan.core.response.CreateResponse)12 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)10 Test (org.junit.Test)8 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)5 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)5 ExecuteResponse (org.eclipse.leshan.core.response.ExecuteResponse)4 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)4 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)3 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)3 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)3 JsonObject (com.eclipsesource.json.JsonObject)2 ContentFormat (org.eclipse.leshan.core.request.ContentFormat)2 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)2 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)2 DeleteResponse (org.eclipse.leshan.core.response.DeleteResponse)2 DiscoverResponse (org.eclipse.leshan.core.response.DiscoverResponse)2 WriteAttributesResponse (org.eclipse.leshan.core.response.WriteAttributesResponse)2 Ignore (org.junit.Ignore)2 ResponseCode (org.eclipse.leshan.ResponseCode)1 ResourceUtil.extractServerIdentity (org.eclipse.leshan.client.californium.impl.ResourceUtil.extractServerIdentity)1