KeywordsSearcher { public void selectUnselectKeywords(Element params) { @SuppressWarnings("unchecked") List<Element> listIdKeywordsSelected = params.getChildren("pIdKeyword"); Set<String> ids = new LinkedHashSet<String>(); for (Element el : listIdKeywordsSelected) { ids.add(el.getTextTrim()); } selectUnselectKeywords(ids); } KeywordsSearcher(IsoLanguagesMapper mapper, ThesaurusFinder thesaurusFinder);  KeywordsSearcher(ServiceContext context, ThesaurusFinder thesaurusFinder); static Element toRawElement(Element rootEl, KeywordBean kb); KeywordBean searchById(String id, String sThesaurusName, String... languages); void searchTopConcepts(String sThesaurusName, String... languages); void search(KeywordSearchParams params); void search(String contextLanguage, Element params); void search(String contextLanguage, Element params, Comparator<KeywordBean> comparator); void searchForRelated(Element params, KeywordRelation request, @Nullable Comparator<KeywordBean> comparator,
                                 String... languages); void searchForRelated(String id, String sThesaurusName, KeywordRelation request, @Nullable Comparator<KeywordBean> comparator,
                                 String... languages); int getNbResults(); List<KeywordBean> getResults(); Element getXmlResults(); void selectUnselectKeywords(Element params); void selectUnselectKeywords(Set<String> idSet); void clearSelection(); Element getSelectedKeywordsAsXml(); List<KeywordBean> getSelectedKeywordsInList(); KeywordBean getKeywordFromResultsById(int id); KeywordBean getKeywordFromResultsById(String id); KeywordBean getKeywordFromResultsByUriCode(String code);  }
@Test public void testSelectUnselectKeywords() throws Exception { KeywordsSearcher searcher = new KeywordsSearcher(isoLangMapper, thesaurusFinder); KeywordSearchParamsBuilder params = new KeywordSearchParamsBuilder(isoLangMapper) .addLang("eng") .maxResults(10); searcher.search(params.build()); Element selectParams = new Element("params"); Set<String> ids = new HashSet<String>(); for (int i = 0; i < 5; i++) { KeywordBean bean = searcher.getResults().get(i); if (i % 2 == 0) { ids.add(bean.getUriCode()); } else { ids.add("" + bean.getId()); } } for (String string : ids) { selectParams.addContent(new Element("pIdKeyword").setText(string)); } searcher.selectUnselectKeywords(selectParams); assertEquals(5, searcher.getSelectedKeywordsInList().size()); assertEquals(5, searcher.getSelectedKeywordsAsXml().getChildren("keyword").size()); searcher.selectUnselectKeywords(selectParams); assertEquals(0, searcher.getSelectedKeywordsInList().size()); assertEquals(0, searcher.getSelectedKeywordsAsXml().getChildren("keyword").size()); searcher.selectUnselectKeywords(ids); assertEquals(5, searcher.getSelectedKeywordsInList().size()); searcher.selectUnselectKeywords(ids); assertEquals(0, searcher.getSelectedKeywordsInList().size()); searcher.selectUnselectKeywords(ids); searcher.clearSelection(); assertEquals(0, searcher.getSelectedKeywordsInList().size()); }