AllThesaurus extends Thesaurus { @Override public List<KeywordBean> getRelated(final String uri, final KeywordRelation request, final String... languages) { final DecomposedAllUri decomposedAllUri = new DecomposedAllUri(uri); final Thesaurus thesaurus = this.thesaurusFinder.getThesaurusByName(decomposedAllUri.thesaurusKey); return Lists.transform(thesaurus.getRelated(decomposedAllUri.keywordUri, request, languages), new Function<KeywordBean, KeywordBean>() { @Nullable @Override public KeywordBean apply(@Nullable KeywordBean keywordBean) { return updateKeywordBeanThesaurusInfo(keywordBean); } }); } AllThesaurus(ThesaurusFinder thesaurusFinder, IsoLanguagesMapper isoLangMapper, String siteUrl); static String buildKeywordUri(KeywordBean actualWord); @Override String getKey(); @Override String getDname(); @Override String getFname(); @Override Path getFile(); @Override String getType(); @Override String getTitle(); @Override String getDate(); @Override String getDownloadUrl(); @Override String getKeywordUrl(); @Override void retrieveThesaurusTitle(); @Override synchronized LocalRepository getRepository(); @Override synchronized Thesaurus setRepository(LocalRepository repository); @Override synchronized Thesaurus initRepository(); @Override synchronized QueryResultsTable performRequest(final String query); @Override boolean hasConceptScheme(String uri); @Override synchronized URI addElement(KeywordBean keyword); @Override synchronized Thesaurus removeElement(KeywordBean keyword); @Override synchronized Thesaurus removeElement(String namespace, String code); @Override synchronized Thesaurus removeElement(String uri); @Override synchronized URI updateElement(KeywordBean keyword, boolean replace); @Override synchronized boolean isFreeCode(final String namespace, final String code); @Override Thesaurus updateCode(KeywordBean bean, String newcode); @Override synchronized Thesaurus updateCode(String namespace, String oldcode, String newcode); @Override synchronized Thesaurus updateCodeByURI(String olduri, String newuri); @Override void addTitleElement(String thesaurusTitle); @Override IsoLanguagesMapper getIsoLanguageMapper(); @Override synchronized void addRelation(String subject, KeywordRelation related, String relatedSubject); @Override KeywordBean getKeyword(String uri, String... languages); @Override boolean hasKeyword(String uri); @Override List<KeywordBean> getRelated(final String uri, final KeywordRelation request, final String... languages); @Override boolean hasKeywordWithLabel(final String label, final String langCode); @Override KeywordBean getKeywordWithLabel(final String label, final String langCode); @Override synchronized void clear(); @Nonnull @Override FileTime getLastModifiedTime(); @Override String getDefaultNamespace(); static final String FNAME; static final String SEPARATOR; static final String ALL_THESAURUS_KEY; }
@Test public void testGetRelated() throws Exception { final String regionsPath = "/org/fao/geonet/services/region/external/thesauri/place/regions.rdf"; Path regionsFile = Paths.get(AllThesaurusTest.class.getResource(regionsPath).toURI()); final Thesaurus regionsThesaurus = new Thesaurus(isoLangMapper, regionsFile.getFileName().toString(), null, null, "external", "place", regionsFile, "http: regionsThesaurus.initRepository(); final HashMap<String, Thesaurus> thesauri = Maps.newHashMap(); thesauri.put(regionsThesaurus.getKey(), regionsThesaurus); this.thesaurusFinder = Mockito.mock(ThesaurusFinder.class); Mockito.when(thesaurusFinder.getThesauriMap()).thenReturn(thesauri); Mockito.when(thesaurusFinder.getThesaurusByName(regionsThesaurus.getKey())).thenReturn(regionsThesaurus); Mockito.when(thesaurusFinder.existsThesaurus(regionsThesaurus.getKey())).thenReturn(true); this.allThesaurus = new AllThesaurus(thesaurusFinder, isoLangMapper, "http: thesauri.put(AllThesaurus.ALL_THESAURUS_KEY, this.allThesaurus); final KeywordBean country = regionsThesaurus.getKeyword("http: String countryAllURI = AllThesaurus.buildKeywordUri(country); assertRelated(countryAllURI, KeywordRelation.BROADER, 278); assertRelated(countryAllURI, KeywordRelation.NARROWER, 0); assertRelated(countryAllURI, KeywordRelation.RELATED, 0); final KeywordBean brazil = regionsThesaurus.getKeyword("http: String brazilAllURI = AllThesaurus.buildKeywordUri(brazil); assertRelated(brazilAllURI, KeywordRelation.BROADER, 0); assertRelated(brazilAllURI, KeywordRelation.NARROWER, 1); assertRelated(brazilAllURI, KeywordRelation.RELATED, 0); }