Skip to content

Commit

Permalink
Fix TEXT format can be used to Write OPAQUE resource. (see #675)
Browse files Browse the repository at this point in the history
  • Loading branch information
sbernard31 committed Jun 24, 2020
1 parent 6e1aa4e commit 202dcf3
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -40,16 +40,16 @@ public class WriteRequest extends AbstractDownlinkRequest<WriteResponse> {
* Define the behavior of a write request.
*/
public enum Mode {
/**
* Replaces the Object Instance or the Resource(s) with the new value provided in the “Write” operation. (see
* section 5.3.3 of the LW M2M spec).
*/
REPLACE,
/**
* Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see section
* 5.3.3 of the LW M2M spec).
*/
UPDATE
/**
* Replaces the Object Instance or the Resource(s) with the new value provided in the “Write” operation. (see
* section 5.3.3 of the LW M2M spec).
*/
REPLACE,
/**
* Adds or updates Resources provided in the new value and leaves other existing Resources unchanged. (see
* section 5.3.3 of the LW M2M spec).
*/
UPDATE
}

private final LwM2mNode node;
Expand Down Expand Up @@ -332,16 +332,10 @@ private WriteRequest(Mode mode, ContentFormat format, LwM2mPath target, LwM2mNod
throw new InvalidRequestException(
"Invalid format for path %s: format must be used only for single resources", target,
format);
} else {
if (resource.getType() == Type.OPAQUE && format == ContentFormat.TEXT) {
throw new InvalidRequestException(
"Invalid format for %s: TEXT format must not be used for byte array single resources",
target);
} else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) {
throw new InvalidRequestException(
"Invalid format for %s: OPAQUE format must be used only for byte array single resources",
target);
}
} else if (resource.getType() != Type.OPAQUE && format == ContentFormat.OPAQUE) {
throw new InvalidRequestException(
"Invalid format for %s: OPAQUE format must be used only for byte array single resources",
target);
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -304,6 +304,11 @@ public void can_write_opaque_resource_in_json() throws InterruptedException {
write_opaque_resource(ContentFormat.JSON);
}

@Test
public void can_write_opaque_resource_in_text() throws InterruptedException {
write_opaque_resource(ContentFormat.TEXT);
}

@Test
public void can_write_opaque_resource_in_old_json() throws InterruptedException {
write_opaque_resource(ContentFormat.fromCode(ContentFormat.OLD_JSON_CODE));
Expand Down

0 comments on commit 202dcf3

Please sign in to comment.