use of org.eclipse.leshan.Link 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.Link in project leshan by eclipse.
the class LinkFormatHelper method getObjectDescription.
public static Link[] getObjectDescription(ObjectModel objectModel, String root) {
List<Link> links = new ArrayList<>();
// clean root path
String rootPath = root == null ? "" : root;
// create link for "object"
Map<String, ?> objectAttributes = getObjectAttributes(objectModel);
String objectURL = getPath("/", rootPath, Integer.toString(objectModel.id));
links.add(new Link(objectURL, objectAttributes));
// sort resources
List<ResourceModel> resources = new ArrayList<>(objectModel.resources.values());
Collections.sort(resources, new Comparator<ResourceModel>() {
@Override
public int compare(ResourceModel o1, ResourceModel o2) {
return o1.id - o2.id;
}
});
// create links for resource
for (ResourceModel resourceModel : resources) {
String resourceURL = getPath("/", rootPath, Integer.toString(objectModel.id), "0", Integer.toString(resourceModel.id));
links.add(new Link(resourceURL));
}
return links.toArray(new Link[] {});
}
use of org.eclipse.leshan.Link in project leshan by eclipse.
the class LinkFormatHelper method getClientDescription.
public static Link[] getClientDescription(Collection<LwM2mObjectEnabler> objectEnablers, String rootPath) {
List<Link> links = new ArrayList<>();
// clean root path
String root = rootPath == null ? "" : rootPath;
// create links for "object"
String rootURL = getPath("/", root);
Map<String, Object> attributes = new HashMap<>();
attributes.put("rt", "oma.lwm2m");
links.add(new Link(rootURL, attributes));
// sort resources
List<LwM2mObjectEnabler> objEnablerList = new ArrayList<>(objectEnablers);
Collections.sort(objEnablerList, new Comparator<LwM2mObjectEnabler>() {
@Override
public int compare(LwM2mObjectEnabler o1, LwM2mObjectEnabler o2) {
return o1.getId() - o2.getId();
}
});
for (LwM2mObjectEnabler objectEnabler : objEnablerList) {
// skip the security Object
if (objectEnabler.getId() == LwM2mId.SECURITY)
continue;
List<Integer> availableInstance = objectEnabler.getAvailableInstanceIds();
// Include an object link if there are no instances or there are object attributes (e.g. "ver")
Map<String, ?> objectAttributes = getObjectAttributes(objectEnabler.getObjectModel());
if (availableInstance.isEmpty() || (objectAttributes != null)) {
String objectInstanceUrl = getPath("/", root, Integer.toString(objectEnabler.getId()));
links.add(new Link(objectInstanceUrl, objectAttributes));
}
for (Integer instanceId : objectEnabler.getAvailableInstanceIds()) {
String objectInstanceUrl = getPath("/", root, Integer.toString(objectEnabler.getId()), instanceId.toString());
links.add(new Link(objectInstanceUrl));
}
}
return links.toArray(new Link[] {});
}
use of org.eclipse.leshan.Link in project leshan by eclipse.
the class LinkFormatHelperTest method encode_objectModel_to_linkObject_without_root_path.
@Test
public void encode_objectModel_to_linkObject_without_root_path() {
ObjectModel locationModel = getObjectModel(6);
Link[] links = LinkFormatHelper.getObjectDescription(locationModel, null);
String strLinks = Link.serialize(links);
assertEquals("</6>, </6/0/0>, </6/0/1>, </6/0/2>, </6/0/3>, </6/0/4>, </6/0/5>, </6/0/6>", strLinks);
}
use of org.eclipse.leshan.Link in project leshan by eclipse.
the class LinkFormatHelperTest method encode_objectModel_to_linkObject_with_version2_0.
@Test
public void encode_objectModel_to_linkObject_with_version2_0() {
ObjectModel locationModel = getVersionedObjectModel(6, "2.0");
Link[] links = LinkFormatHelper.getObjectDescription(locationModel, "/");
String strLinks = Link.serialize(links);
assertEquals("</6>;ver=\"2.0\", </6/0/0>, </6/0/1>, </6/0/2>, </6/0/3>, </6/0/4>, </6/0/5>, </6/0/6>", strLinks);
}
Aggregations