@Test public void can_write_replace_resource_in_json() { // write device timezone final String timeZone = "Europe/Paris"; WriteResponse response = helper.server.send(helper.getClient(), new WriteRequest(Mode.REPLACE, 3, 0, 15, timeZone)); // verify result assertEquals(ResponseCode.CHANGED, response.getCode()); // read the timezone to check the value changed ReadResponse readResponse = helper.server.send(helper.getClient(), new ReadRequest(3, 0, 15)); LwM2mResource resource = (LwM2mResource) readResponse.getContent(); assertEquals(timeZone, resource.getValue()); }
@Test public void can_write_object_instance() { // write device timezone and offset LwM2mResource utcOffset = LwM2mSingleResource.newStringResource(14, "+02"); LwM2mResource timeZone = LwM2mSingleResource.newStringResource(15, "Europe/Paris"); WriteResponse response = helper.server.send( helper.getClient(), new WriteRequest(Mode.REPLACE, 3, 0, utcOffset, timeZone)); // verify result assertEquals(ResponseCode.CHANGED, response.getCode()); // read the timezone to check the value changed ReadResponse readResponse = helper.server.send(helper.getClient(), new ReadRequest(3, 0)); LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent(); assertEquals(utcOffset, instance.getResource(14)); assertEquals(timeZone, instance.getResource(15)); }
@Test public void cannot_write_non_writable_resource() { // try to write unwritable resource like manufacturer on device final String manufacturer = "new manufacturer"; WriteResponse response = helper.server.send( helper.getClient(), new WriteRequest(Mode.REPLACE, 3, 0, 0, manufacturer)); // verify result assertEquals(ResponseCode.METHOD_NOT_ALLOWED, response.getCode()); }