LinkFormatHelper { public static Link[] getObjectDescription(LwM2mObjectEnabler objectEnabler, String root) { List<Link> links = new ArrayList<>(); String rootPath = root == null ? "" : root; Map<String, String> objectAttributes = getObjectAttributes(objectEnabler.getObjectModel()); String objectURL = getPath("/", rootPath, Integer.toString(objectEnabler.getId())); links.add(new Link(objectURL, objectAttributes)); for (Integer instanceId : objectEnabler.getAvailableInstanceIds()) { links.addAll(Arrays.asList(getInstanceDescription(objectEnabler, instanceId, rootPath))); } return links.toArray(new Link[] {}); } private  LinkFormatHelper(); static Link[] getClientDescription(Collection<LwM2mObjectEnabler> objectEnablers, String rootPath); static Link[] getBootstrapClientDescription(Collection<LwM2mObjectEnabler> objectEnablers); static Link[] getObjectDescription(LwM2mObjectEnabler objectEnabler, String root); static Link[] getBootstrapObjectDescription(LwM2mObjectEnabler objectEnabler); static Link[] getInstanceDescription(LwM2mObjectEnabler objectEnabler, int instanceId, String root); static Link getResourceDescription(LwM2mObjectEnabler objectEnabler, int instanceId, int resourceId,
            String root);  }
@Test public void encode_objectModel_to_linkObject_without_root_path() { ObjectModel locationModel = getObjectModel(6); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), null); String strLinks = Link.serialize(links); assertEquals("</6>,</6/0>,</6/0/0>,</6/0/1>,</6/0/2>,</6/0/3>,</6/0/4>,</6/0/5>,</6/0/6>", strLinks); }
@Test public void encode_objectModel_to_linkObject_with_simple_root_path() { ObjectModel locationModel = getObjectModel(6); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), "rp"); String strLinks = Link.serialize(links); assertEquals( "</rp/6>,</rp/6/0>,</rp/6/0/0>,</rp/6/0/1>,</rp/6/0/2>,</rp/6/0/3>,</rp/6/0/4>,</rp/6/0/5>,</rp/6/0/6>", strLinks); }
@Test public void encode_objectModel_to_linkObject_with_empty_root_path() { ObjectModel locationModel = getObjectModel(6); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), ""); String strLinks = Link.serialize(links); assertEquals("</6>,</6/0>,</6/0/0>,</6/0/1>,</6/0/2>,</6/0/3>,</6/0/4>,</6/0/5>,</6/0/6>", strLinks); }
@Test public void encode_objectModel_to_linkObject_with_explicit_empty_root_path() { ObjectModel locationModel = getObjectModel(6); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), "/"); String strLinks = Link.serialize(links); assertEquals("</6>,</6/0>,</6/0/0>,</6/0/1>,</6/0/2>,</6/0/3>,</6/0/4>,</6/0/5>,</6/0/6>", strLinks); }
@Test public void encode_objectModel_to_linkObject_with_version2_0() { ObjectModel locationModel = getVersionedObjectModel(6, "2.0"); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), "/"); String strLinks = Link.serialize(links); assertEquals("</6>;ver=2.0,</6/0>,</6/0/0>,</6/0/1>,</6/0/2>,</6/0/3>,</6/0/4>,</6/0/5>,</6/0/6>", strLinks); }
@Test public void encode_objectModel_to_linkObject_with_explicit_complex_root_path() { ObjectModel locationModel = getObjectModel(6); Link[] links = LinkFormatHelper.getObjectDescription(createObjectEnabler(locationModel), "/r/t/"); String strLinks = Link.serialize(links); assertEquals( "</r/t/6>,</r/t/6/0>,</r/t/6/0/0>,</r/t/6/0/1>,</r/t/6/0/2>,</r/t/6/0/3>,</r/t/6/0/4>,</r/t/6/0/5>,</r/t/6/0/6>", strLinks); }