AppCatalogSolrClient { public List<AppStoreEntry> getRecommendedApps() { List<AppStoreEntry> apps = new ArrayList<AppStoreEntry>(); SolrClient solr = getSolrClient(); SolrQuery query = new SolrQuery(); query.setQuery("*:*"); query.setSort("download_i", ORDER.desc); query.setFilterQueries("type_s:AppStoreEntry"); query.setRows(40); QueryResponse response; try { response = solr.query(query); Iterator<SolrDocument> list = response.getResults().listIterator(); while (list.hasNext()) { SolrDocument d = list.next(); AppStoreEntry entry = new AppStoreEntry(); entry.setId(d.get("id").toString()); entry.setOrg(d.get("org_s").toString()); entry.setName(d.get("name_s").toString()); entry.setDesc(d.get("desc_s").toString()); if (d.get("icon_s")!=null) { entry.setIcon(d.get("icon_s").toString()); } entry.setLike(Integer.parseInt(d.get("like_i").toString())); entry.setDownload(Integer.parseInt(d.get("download_i").toString())); apps.add(entry); } } catch (SolrServerException | IOException e) { LOG.error("Error getting a list of recommended applications: ", e); } return apps; } AppCatalogSolrClient(); SolrClient getSolrClient(); List<AppStoreEntry> getRecommendedApps(); List<AppStoreEntry> search(String keyword); List<AppEntry> listAppEntries(); AppStoreEntry findAppStoreEntry(String id); AppEntry findAppEntry(String id); void deployApp(String id, Service service); void deleteApp(String id); void register(Application app); void upgradeApp(Service service);  }
@Test public void testGetRecommendedApps() throws Exception { AppStoreEntry example = new AppStoreEntry(); example.setOrg("jenkins-ci.org"); example.setName("jenkins"); example.setDesc("World leading open source automation system."); example.setIcon("/css/img/feather.png"); example.setDownload(100); spy.register(example); AppStoreEntry example2 = new AppStoreEntry(); example2.setOrg("Apache"); example2.setName("httpd"); example2.setDesc("Apache webserver"); example2.setIcon("/css/img/feather.png"); example2.setDownload(1); spy.register(example2); List<AppStoreEntry> actual = spy.getRecommendedApps(); long previous = 1000L; for (AppStoreEntry app: actual) { assertTrue("Recommend app is not sort by download count.", previous > app.getDownload()); previous = app.getDownload(); } }