Search in sources :

Example 21 with LwM2mResource

use of org.eclipse.leshan.core.node.LwM2mResource 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 22 with LwM2mResource

use of org.eclipse.leshan.core.node.LwM2mResource 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 23 with LwM2mResource

use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.

the class ReadTest method can_read_resource.

@Test
public void can_read_resource() throws InterruptedException {
    // read device model number
    ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3, 0, 1));
    // verify result
    assertEquals(CONTENT, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    LwM2mResource resource = (LwM2mResource) response.getContent();
    assertEquals(1, resource.getId());
    assertEquals(IntegrationTestHelper.MODEL_NUMBER, resource.getValue());
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Example 24 with LwM2mResource

use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.

the class WriteTest method write_opaque_resource.

private void write_opaque_resource(ContentFormat format) throws InterruptedException {
    // write resource
    byte[] expectedvalue = new byte[] { 1, 2, 3 };
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, OPAQUE_RESOURCE_ID, expectedvalue));
    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // read resource to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TEST_OBJECT_ID, 0, OPAQUE_RESOURCE_ID));
    LwM2mResource resource = (LwM2mResource) readResponse.getContent();
    assertArrayEquals(expectedvalue, (byte[]) resource.getValue());
}
Also used : ReadResponse(org.eclipse.leshan.core.response.ReadResponse) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest)

Example 25 with LwM2mResource

use of org.eclipse.leshan.core.node.LwM2mResource in project leshan by eclipse.

the class WriteTest method can_write_updating_object_instance.

@Test
public void can_write_updating_object_instance() throws InterruptedException {
    // setup server object
    WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(1, 0, 3, 60));
    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // write server object
    LwM2mResource lifetime = LwM2mSingleResource.newIntegerResource(1, 120);
    LwM2mResource defaultMinPeriod = LwM2mSingleResource.newIntegerResource(2, 10);
    response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(Mode.UPDATE, 1, 0, lifetime, defaultMinPeriod));
    // verify result
    assertEquals(ResponseCode.CHANGED, response.getCode());
    assertNotNull(response.getCoapResponse());
    assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
    // read the values to check the value changed
    ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(1, 0));
    LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
    assertEquals(lifetime, instance.getResource(1));
    assertEquals(defaultMinPeriod, instance.getResource(2));
    // no resources are removed when updating
    assertNotNull(instance.getResource(3));
    assertNotNull(instance.getResource(6));
    assertNotNull(instance.getResource(7));
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) ReadResponse(org.eclipse.leshan.core.response.ReadResponse) WriteRequest(org.eclipse.leshan.core.request.WriteRequest) WriteResponse(org.eclipse.leshan.core.response.WriteResponse) LwM2mResource(org.eclipse.leshan.core.node.LwM2mResource) ReadRequest(org.eclipse.leshan.core.request.ReadRequest) Test(org.junit.Test)

Aggregations

LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)33 Test (org.junit.Test)15 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)14 LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)13 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)13 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)11 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)10 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)10 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)9 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)5 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)5 JsonObject (com.eclipsesource.json.JsonObject)4 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)4 JsonArray (com.eclipsesource.json.JsonArray)3 Collection (java.util.Collection)3 HashMap (java.util.HashMap)3 Map (java.util.Map)3 JsonValue (com.eclipsesource.json.JsonValue)2 SortedMap (java.util.SortedMap)2 TreeMap (java.util.TreeMap)2