use of org.eclipse.leshan.core.response.DiscoverResponse 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.DiscoverResponse in project leshan by eclipse.
the class ResponseSerDesTest method ser_and_des_discover_response.
@Test
public void ser_and_des_discover_response() throws Exception {
Link[] objs = new Link[2];
Map<String, Object> att = new HashMap<>();
att.put("ts", 12);
att.put("rt", "test");
objs[0] = new Link("/0/1024/2", att);
objs[1] = new Link("/0/2");
DiscoverResponse dr = DiscoverResponse.success(objs);
JsonObject obj = ResponseSerDes.jSerialize(dr);
LwM2mResponse dr2 = ResponseSerDes.deserialize(obj);
assertEquals(dr.toString(), dr2.toString());
}
use of org.eclipse.leshan.core.response.DiscoverResponse in project leshan by eclipse.
the class DiscoverTest method can_discover_object.
@Test
public void can_discover_object() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(2));
// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
Link[] payload = response.getObjectLinks();
assertArrayEquals(Link.parse("</2>, </2/0/0>, </2/0/1>, </2/0/2>, </2/0/3>".getBytes()), payload);
}
use of org.eclipse.leshan.core.response.DiscoverResponse in project leshan by eclipse.
the class DiscoverTest method can_discover_resource.
@Test
public void can_discover_resource() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(3, 0, 0));
// verify result
assertEquals(CONTENT, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
Link[] payload = response.getObjectLinks();
assertArrayEquals(Link.parse("</3/0/0>".getBytes()), payload);
}
use of org.eclipse.leshan.core.response.DiscoverResponse in project leshan by eclipse.
the class DiscoverTest method cant_discover_resource_of_non_existent_object.
@Test
public void cant_discover_resource_of_non_existent_object() throws InterruptedException {
// read ACL object
DiscoverResponse response = helper.server.send(helper.getCurrentRegistration(), new DiscoverRequest(4, 0, 0));
// verify result
assertEquals(NOT_FOUND, response.getCode());
assertNotNull(response.getCoapResponse());
assertThat(response.getCoapResponse(), is(instanceOf(Response.class)));
}
Aggregations