use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class ReadTest method cannot_read_security_resource.
@Test
public void cannot_read_security_resource() throws InterruptedException {
// read device 50 resource
ReadResponse response = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(0, 0, 0));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method write_opaque_resource.
private void write_opaque_resource(ContentFormat format) throws InterruptedException {
// write resource
byte[] expectedvalue = new byte[] { 1, 2, 3 };
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, OPAQUE_RESOURCE_ID, expectedvalue));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read resource to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TEST_OBJECT_ID, 0, OPAQUE_RESOURCE_ID));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertArrayEquals(expectedvalue, (byte[]) resource.getValue());
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method can_write_single_instance_objlnk_resource_in_tlv.
@Test
public void can_write_single_instance_objlnk_resource_in_tlv() throws InterruptedException {
ObjectLink data = new ObjectLink(10245, 1);
// Write objlnk resource in TLV format
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(ContentFormat.TLV, IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID, data));
// Verify Write result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// Reading back the written OBJLNK value
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(IntegrationTestHelper.TEST_OBJECT_ID, 0, IntegrationTestHelper.OBJLNK_SINGLE_INSTANCE_RESOURCE_ID));
LwM2mSingleResource resource = (LwM2mSingleResource) readResponse.getContent();
// verify read value
assertEquals(((ObjectLink) resource.getValue()).getObjectId(), 10245);
assertEquals(((ObjectLink) resource.getValue()).getObjectInstanceId(), 1);
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method can_write_updating_object_instance.
@Test
public void can_write_updating_object_instance() throws InterruptedException {
// setup server object
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(1, 0, 3, 60));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// write server object
LwM2mResource lifetime = LwM2mSingleResource.newIntegerResource(1, 120);
LwM2mResource defaultMinPeriod = LwM2mSingleResource.newIntegerResource(2, 10);
response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(Mode.UPDATE, 1, 0, lifetime, defaultMinPeriod));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read the values to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(1, 0));
LwM2mObjectInstance instance = (LwM2mObjectInstance) readResponse.getContent();
assertEquals(lifetime, instance.getResource(1));
assertEquals(defaultMinPeriod, instance.getResource(2));
// no resources are removed when updating
assertNotNull(instance.getResource(3));
assertNotNull(instance.getResource(6));
assertNotNull(instance.getResource(7));
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method write_string_resource.
private void write_string_resource(ContentFormat format) throws InterruptedException {
// write resource
String expectedvalue = "stringvalue";
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, STRING_RESOURCE_ID, expectedvalue));
// verify result
assertEquals(ResponseCode.CHANGED, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// read resource to check the value changed
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(TEST_OBJECT_ID, 0, STRING_RESOURCE_ID));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertEquals(expectedvalue, resource.getValue());
}
Aggregations