Skip to content

Commit

Permalink
- fix Lwm2mNodeTextEncoder for ResourcInstance
Browse files Browse the repository at this point in the history
- fixed write in BaseInstanceEnabler
- added tests

Signed-off-by: Dmytro Zakharenko <[email protected]>
  • Loading branch information
zakharenkodmytro committed Oct 1, 2020
1 parent 8e4c409 commit d4f2e5b
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -184,7 +184,7 @@ public WriteResponse write(ServerIdentity identity, int resourceid, int resource
if (instances.containsKey(resourceInstanceId)) {
instances.put(resourceInstanceId, value);
return write(identity, resourceid,
new LwM2mMultipleResource(resourceInstanceId, value.getType(), instances.values()));
new LwM2mMultipleResource(resourceid, value.getType(), instances.values()));
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,6 +96,7 @@ protected LwM2mMultipleResource initializeMultipleResource(ObjectModel objectMod
switch (resourceModel.type) {
case STRING:
values.put(0, createDefaultStringValueFor(objectModel, resourceModel));
values.put(1, createDefaultStringValueFor(objectModel, resourceModel));
break;
case BOOLEAN:
values.put(0, createDefaultBooleanValueFor(objectModel, resourceModel));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ public void visit(LwM2mResource resource) {
public void visit(LwM2mResourceInstance instance) {
LOG.trace("Encoding resource instance {} into text", instance);

ResourceModel rSpec = model.getResourceModel(path.getObjectId(), instance.getId());
ResourceModel rSpec = model.getResourceModel(path.getObjectId(), path.getResourceId());
Type expectedType = rSpec != null ? rSpec.type : instance.getType();
Object val = converter.convertValue(instance.getValue(), instance.getType(), expectedType, path);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -202,34 +202,40 @@ private void write_integer_resource(ContentFormat format) throws InterruptedExce

@Test
public void can_write_string_resource_json_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.JSON);
write_string_resource_instance(ContentFormat.JSON, 0);
}

@Test
public void can_write_string_resource_old_json_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_JSON_CODE));
write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_JSON_CODE), 0);
}

@Test
public void can_write_string_resource_text_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.TEXT);
write_string_resource_instance(ContentFormat.TEXT, 0);
}

@Test
public void can_write_string_multiple_resource_text_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.TEXT, 0);
write_string_resource_instance(ContentFormat.TEXT, 1);
}

@Test
public void can_write_string_resource_tlv_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.TLV);
write_string_resource_instance(ContentFormat.TLV, 0);
}

@Test
public void can_write_string_resource_old_tlv_instance() throws InterruptedException {
write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_TLV_CODE));
write_string_resource_instance(ContentFormat.fromCode(ContentFormat.OLD_TLV_CODE), 0);
}

private void write_string_resource_instance(ContentFormat format) throws InterruptedException {
private void write_string_resource_instance(ContentFormat format, int resourceInstance) throws InterruptedException {
// read device model number
String valueToWrite = "newValue";
WriteResponse response = helper.server.send(helper.getCurrentRegistration(),
new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, 0, valueToWrite, Type.STRING));
new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, resourceInstance, valueToWrite, Type.STRING));

// verify result
assertEquals(CHANGED, response.getCode());
Expand All @@ -238,7 +244,7 @@ private void write_string_resource_instance(ContentFormat format) throws Interru

// read resource to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(),
new ReadRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, 0));
new ReadRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_INSTANCE_ID, resourceInstance));

// verify result
LwM2mResourceInstance resource = (LwM2mResourceInstance) readResponse.getContent();
Expand Down

0 comments on commit d4f2e5b

Please sign in to comment.