Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

- fix Lwm2mNodeTextEncoder for ResourcInstance #898

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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