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));
}
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)));
}
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)));
}
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));
}
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);
}
Aggregations