use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class WriteTest method write_integer_resource.
private void write_integer_resource(ContentFormat format) throws InterruptedException {
// write resource
long expectedvalue = 999l;
WriteResponse response = helper.server.send(helper.getCurrentRegistration(), new WriteRequest(format, TEST_OBJECT_ID, 0, INTEGER_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, INTEGER_RESOURCE_ID));
LwM2mResource resource = (LwM2mResource) readResponse.getContent();
assertEquals(expectedvalue, resource.getValue());
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class ResponseSerDes method jSerialize.
public static JsonObject jSerialize(LwM2mResponse r) {
final JsonObject o = Json.object();
o.add("code", r.getCode().toString());
if (r.isFailure()) {
o.add("errorMessage", r.getErrorMessage());
return o;
}
if (r instanceof ReadResponse) {
o.add("kind", "read");
o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent()));
} else if (r instanceof ObserveResponse) {
o.add("kind", "observe");
o.add("content", LwM2mNodeSerDes.jSerialize(((ReadResponse) r).getContent()));
} else if (r instanceof DiscoverResponse) {
o.add("kind", "discover");
o.add("objectLinks", Link.serialize(((DiscoverResponse) r).getObjectLinks()));
} else if (r instanceof DeleteResponse) {
o.add("kind", "delete");
} else if (r instanceof ExecuteResponse) {
o.add("kind", "execute");
} else if (r instanceof WriteResponse) {
o.add("kind", "write");
} else if (r instanceof WriteAttributesResponse) {
o.add("kind", "writeAttributes");
} else if (r instanceof CreateResponse) {
o.add("kind", "create");
o.add("location", ((CreateResponse) r).getLocation());
}
return o;
}
use of org.eclipse.leshan.core.response.ReadResponse in project leshan by eclipse.
the class CreateTest method cannot_create_instance_with_extraneous_resources.
// TODO we must probably implement this.
@Ignore
@Test
public void cannot_create_instance_with_extraneous_resources() throws InterruptedException {
// create ACL instance
LwM2mObjectInstance instance = new LwM2mObjectInstance(0, Arrays.<LwM2mResource>asList(LwM2mSingleResource.newIntegerResource(3, 123), LwM2mSingleResource.newIntegerResource(50, 123)));
CreateRequest request = new CreateRequest(2, instance);
CreateResponse response = helper.server.send(helper.getCurrentRegistration(), request);
// verify result
assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// try to read to check if the instance is not created
// client registration
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2, 0));
assertEquals(ResponseCode.NOT_FOUND, readResponse.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 CreateTest method cannot_create_instance_without_all_required_resources.
// TODO not sure all the writable mandatory resource should be present
// E.g. for softwareUpdate (object 9) packageURI and package are writable resource mandatory
// but you will not make a create with this two resource.
@Ignore
@Test
public void cannot_create_instance_without_all_required_resources() throws InterruptedException {
// create ACL instance
CreateResponse response = helper.server.send(helper.getCurrentRegistration(), new CreateRequest(2, new LwM2mResource[0]));
// verify result
assertEquals(ResponseCode.BAD_REQUEST, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
// try to read to check if the instance is not created
// client registration
ReadResponse readResponse = helper.server.send(helper.getCurrentRegistration(), new ReadRequest(2, 0));
assertEquals(ResponseCode.NOT_FOUND, readResponse.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 FailingTest method async_send_without_acknowleged.
@Test
public void async_send_without_acknowleged() throws Exception {
// register client
LockStepLwM2mClient client = new LockStepLwM2mClient(helper.server.getUnsecuredAddress());
client.sendLwM2mRequest(new RegisterRequest(helper.getCurrentEndpoint(), 60l, null, BindingMode.U, null, Link.parse("</1>,</2>,</3>".getBytes()), null));
client.expectResponse().go();
helper.waitForRegistration(1);
// send read
Callback<ReadResponse> callback = new Callback<ReadResponse>();
helper.server.send(helper.getCurrentRegistration(), new ReadRequest(3), 3000l, callback, callback);
// Request should timedout in ~1s we don't send ACK
callback.waitForResponse(1500);
Assert.assertTrue("we should timeout", callback.getException() instanceof TimeoutException);
}
Aggregations