### Question:
RsDocumentBuilder { public Urlset getSourceDescription(@Nullable User user) { RsMd rsMd = new RsMd(Capability.DESCRIPTION.xmlValue); Urlset sourceDescription = new Urlset(rsMd); for (DataSet dataSet : dataSetRepository.getDataSetsWithReadAccess(user)) { DataSetMetaData dataSetMetaData = dataSet.getMetadata(); String loc = rsUriHelper.uriForRsDocument(dataSetMetaData, Capability.CAPABILITYLIST); String descriptionUrl = rsUriHelper.uriForRsDocument(dataSetMetaData, DESCRIPTION_FILENAME); UrlItem item = new UrlItem(loc) .withMetadata(new RsMd(Capability.CAPABILITYLIST.xmlValue)) .addLink(new RsLn(REL_DESCRIBED_BY, descriptionUrl) .withType(DESCRIPTION_TYPE)); sourceDescription.addItem(item); } return sourceDescription; } RsDocumentBuilder(DataSetRepository dataSetRepository, UriHelper uriHelper); Urlset getSourceDescription(@Nullable User user); Optional<Urlset> getCapabilityList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getResourceList(@Nullable User user, String ownerId, String dataSetId); Optional<Urlset> getChangeList(@Nullable User user, String ownerId, String dataSetId); Optional<Stream<String>> getChanges(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<Stream<String>> getResourceData(@Nullable User user, String ownerId, String dataSetId); Optional<CachedFile> getCachedFile(@Nullable User user, String ownerId, String dataSetId, String fileId); Optional<File> getDataSetDescription(@Nullable User user, String ownerId, String dataSetId); static final String SOURCE_DESCRIPTION_PATH; }### Answer:
@Test public void emptySourceDescription() throws Exception { when(dataSetRepository.getDataSetsWithReadAccess(null)).thenReturn(Collections.emptyList()); Urlset sourceDescription = rsDocumentBuilder.getSourceDescription(null); String xml = rsBuilder.toXml(sourceDescription, true); rsBuilder.setXmlString(xml).build(); Urlset sd = rsBuilder.getUrlset().get(); assertThat(sd.getCapability().get(), is(Capability.DESCRIPTION)); assertThat(sd.getItemList().size(), is(0)); }
@Test public void sourceDescriptionWithCapabilityLists() throws Exception { when(dataSetRepository.getDataSetsWithReadAccess(null)).thenReturn(Arrays.asList(dataSet, dataSet)); Urlset sourceDescription = rsDocumentBuilder.getSourceDescription(null); String xml = rsBuilder.toXml(sourceDescription, true); rsBuilder.setXmlString(xml).build(); Urlset sd = rsBuilder.getUrlset().get(); assertThat(sd.getCapability().get(), is(Capability.DESCRIPTION)); assertThat(sd.getItemList().size(), is(2)); assertThat(sd.getItemList().get(0).getLoc(), is("http: assertThat(sd.getItemList().get(1).getLoc(), is("http: assertThat(sd.getItemList().get(0).getMetadata().get().getCapability().get(), is(Capability.CAPABILITYLIST.xmlValue)); assertThat(sd.getItemList().get(1).getLink("describedby").get().getHref(), is("http: assertThat(sd.getItemList().get(1).getLink("describedby").get().getType().get(), is("application/rdf+xml")); }