use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_acl_object_multi_instance.
@Test
public void tlv_acl_object_multi_instance() throws Exception {
LwM2mObject oObject = ((LwM2mObject) decoder.decode(ENCODED_ACL, ContentFormat.TLV, new LwM2mPath(2), model));
assertAclInstances(oObject);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_timestamped_resources.
@Test
public void json_timestamped_resources() throws CodecException {
// json content for instance 0 of device object
StringBuilder b = new StringBuilder();
b.append("{\"e\":[");
b.append("{\"n\":\"\",\"v\":22.9,\"t\":-30},");
b.append("{\"n\":\"\",\"v\":22.4,\"t\":-5},");
b.append("{\"n\":\"\",\"v\":24.1,\"t\":-50}],");
b.append("\"bt\":25462634}");
List<TimestampedLwM2mNode> timestampedResources = decoder.decodeTimestampedData(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(1024, 0, 1), model);
assertEquals(3, timestampedResources.size());
assertEquals(Long.valueOf(25462634L - 5), timestampedResources.get(0).getTimestamp());
assertEquals(22.4d, ((LwM2mResource) timestampedResources.get(0).getNode()).getValue());
assertEquals(Long.valueOf(25462634L - 30), timestampedResources.get(1).getTimestamp());
assertEquals(22.9d, ((LwM2mResource) timestampedResources.get(1).getNode()).getValue());
assertEquals(Long.valueOf(25462634 - 50), timestampedResources.get(2).getTimestamp());
assertEquals(24.1d, ((LwM2mResource) timestampedResources.get(2).getNode()).getValue());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method tlv_multi_instance_with_obj_link.
@Test
public void tlv_multi_instance_with_obj_link() throws Exception {
LwM2mObject oObject = ((LwM2mObject) decoder.decode(ENCODED_OBJ66, ContentFormat.TLV, new LwM2mPath(66), model));
assertObj66Instance(oObject);
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class LwM2mNodeDecoderTest method json_empty_multi_resource.
@Test
public void json_empty_multi_resource() {
// Completely empty
StringBuilder b = new StringBuilder();
b.append("{}");
LwM2mResource resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
// with empty resource list
b = new StringBuilder();
b.append("{\"e\":[]}");
resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
// with empty resources list and base name
b = new StringBuilder();
b.append("{\"bn\":\"3/0/6\", \"e\":[]}");
resource = (LwM2mResource) decoder.decode(b.toString().getBytes(), ContentFormat.JSON, new LwM2mPath(3, 0, 6), model);
assertNotNull(resource);
assertTrue(resource instanceof LwM2mMultipleResource);
assertEquals(6, resource.getId());
assertTrue(resource.getValues().isEmpty());
}
use of org.eclipse.leshan.core.node.LwM2mPath in project leshan by eclipse.
the class ObjectEnabler method doWrite.
@Override
protected BootstrapWriteResponse doWrite(ServerIdentity identity, BootstrapWriteRequest request) {
LwM2mPath path = request.getPath();
// Manage Object case
if (path.isObject()) {
for (LwM2mObjectInstance instanceNode : ((LwM2mObject) request.getNode()).getInstances().values()) {
LwM2mInstanceEnabler instanceEnabler = instances.get(instanceNode.getId());
if (instanceEnabler == null) {
doCreate(new CreateRequest(path.getObjectId(), instanceNode));
} else {
doWrite(identity, new WriteRequest(Mode.REPLACE, path.getObjectId(), path.getObjectInstanceId(), instanceNode.getResources().values()));
}
}
return BootstrapWriteResponse.success();
}
// Manage Instance case
if (path.isObjectInstance()) {
LwM2mObjectInstance instanceNode = (LwM2mObjectInstance) request.getNode();
LwM2mInstanceEnabler instanceEnabler = instances.get(path.getObjectInstanceId());
if (instanceEnabler == null) {
doCreate(new CreateRequest(path.getObjectId(), instanceNode));
} else {
doWrite(identity, new WriteRequest(Mode.REPLACE, request.getContentFormat(), path.getObjectId(), path.getObjectInstanceId(), instanceNode.getResources().values()));
}
return BootstrapWriteResponse.success();
}
// Manage resource case
LwM2mResource resource = (LwM2mResource) request.getNode();
LwM2mInstanceEnabler instanceEnabler = instances.get(path.getObjectInstanceId());
if (instanceEnabler == null) {
doCreate(new CreateRequest(path.getObjectId(), new LwM2mObjectInstance(path.getObjectInstanceId(), resource)));
} else {
instanceEnabler.write(path.getResourceId(), resource);
}
return BootstrapWriteResponse.success();
}
Aggregations