Search in sources :

Example 36 with LwM2mObjectInstance

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

Example 37 with LwM2mObjectInstance

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

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

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

the class LwM2mNodeEncoderTest method json_encode_timestamped_instances.

@Test
public void json_encode_timestamped_instances() throws CodecException {
    List<TimestampedLwM2mNode> data = new ArrayList<>();
    LwM2mObjectInstance instanceAt110 = new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.9));
    LwM2mObjectInstance instanceAt120 = new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 22.4), LwM2mSingleResource.newStringResource(0, "a string"));
    LwM2mObjectInstance instanceAt130 = new LwM2mObjectInstance(0, LwM2mSingleResource.newFloatResource(1, 24.1));
    data.add(new TimestampedLwM2mNode(110L, instanceAt110));
    data.add(new TimestampedLwM2mNode(120L, instanceAt120));
    data.add(new TimestampedLwM2mNode(130L, instanceAt130));
    byte[] encoded = encoder.encodeTimestampedData(data, ContentFormat.JSON, new LwM2mPath(1024, 0), model);
    StringBuilder b = new StringBuilder();
    b.append("{\"bn\":\"/1024/0\",\"e\":[");
    b.append("{\"n\":\"1\",\"v\":22.9,\"t\":110},");
    b.append("{\"n\":\"0\",\"sv\":\"a string\",\"t\":120},");
    b.append("{\"n\":\"1\",\"v\":22.4,\"t\":120},");
    b.append("{\"n\":\"1\",\"v\":24.1,\"t\":130}]}");
    String expected = b.toString();
    Assert.assertEquals(expected, new String(encoded));
}
Also used : TimestampedLwM2mNode(org.eclipse.leshan.core.node.TimestampedLwM2mNode) LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) ArrayList(java.util.ArrayList) Test(org.junit.Test)

Example 40 with LwM2mObjectInstance

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

the class LwM2mNodeDecoderTest method tlv_device_object_instance0_from_resources_tlv.

@Test
public void tlv_device_object_instance0_from_resources_tlv() throws CodecException {
    LwM2mObjectInstance oInstance = (LwM2mObjectInstance) decoder.decode(ENCODED_DEVICE_WITHOUT_INSTANCE, ContentFormat.TLV, new LwM2mPath(3, 0), model);
    assertDeviceInstance(oInstance);
}
Also used : LwM2mObjectInstance(org.eclipse.leshan.core.node.LwM2mObjectInstance) LwM2mPath(org.eclipse.leshan.core.node.LwM2mPath) Test(org.junit.Test)

Aggregations

LwM2mObjectInstance (org.eclipse.leshan.core.node.LwM2mObjectInstance)49 Test (org.junit.Test)30 LwM2mPath (org.eclipse.leshan.core.node.LwM2mPath)25 LwM2mObject (org.eclipse.leshan.core.node.LwM2mObject)13 LwM2mResource (org.eclipse.leshan.core.node.LwM2mResource)13 ReadRequest (org.eclipse.leshan.core.request.ReadRequest)11 CreateRequest (org.eclipse.leshan.core.request.CreateRequest)10 ReadResponse (org.eclipse.leshan.core.response.ReadResponse)9 ArrayList (java.util.ArrayList)8 WriteRequest (org.eclipse.leshan.core.request.WriteRequest)8 TimestampedLwM2mNode (org.eclipse.leshan.core.node.TimestampedLwM2mNode)6 ObserveRequest (org.eclipse.leshan.core.request.ObserveRequest)6 LwM2mNode (org.eclipse.leshan.core.node.LwM2mNode)5 CreateResponse (org.eclipse.leshan.core.response.CreateResponse)5 DeleteRequest (org.eclipse.leshan.core.request.DeleteRequest)4 ExecuteRequest (org.eclipse.leshan.core.request.ExecuteRequest)4 ObserveResponse (org.eclipse.leshan.core.response.ObserveResponse)4 WriteResponse (org.eclipse.leshan.core.response.WriteResponse)4 JsonObject (com.eclipsesource.json.JsonObject)3 Collection (java.util.Collection)3