@Test public void countFetchesFromRemoteServer() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http: + "+status%3A%28Approved%29+AND+%28+symbol%3A%28brcA*%29+alias_symbol%3A%28brcA*%29%29"); CapturingMatcher<HttpUriRequest> reqCapture = new CapturingMatcher<>(); when(this.client.execute(Matchers.argThat(reqCapture))).thenReturn(this.response); when(this.response.getEntity()).thenReturn(this.responseEntity); when(this.responseEntity.getContent()).thenReturn(ClassLoader.getSystemResourceAsStream("brca.json")); Map<String, Object> search = new LinkedHashMap<>(); search.put("status", "Approved"); Map<String, String> subquery = new LinkedHashMap<>(); subquery.put("symbol", "brcA*"); subquery.put("alias_symbol", "brcA*"); search.put("AND", subquery); long result = this.mocker.getComponentUnderTest().count(search); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertEquals(6, result); }
@Override public long count(Map<String, ?> fieldValues) { try { HttpGet method = new HttpGet(this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); return docs.length(); } catch (IOException | JSONException ex) { this.logger.warn("Failed to count matching gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { } return -1; }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public long count(Map<String, ?> fieldValues) { try { HttpGet method = new HttpGet(this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); return docs.length(); } catch (IOException | JSONException ex) { this.logger.warn("Failed to count matching gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { } return -1; } }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public long count(Map<String, ?> fieldValues) { try { HttpGet method = new HttpGet(this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); return docs.length(); } catch (IOException | JSONException ex) { this.logger.warn("Failed to count matching gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { } return -1; }  }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public long count(Map<String, ?> fieldValues) { try { HttpGet method = new HttpGet(this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); return docs.length(); } catch (IOException | JSONException ex) { this.logger.warn("Failed to count matching gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { } return -1; }  @Override void initialize(); @Override VocabularyTerm getTerm(String id); @Override Set<VocabularyTerm> getTerms(Collection<String> ids); @Override List<VocabularyTerm> search(Map<String, ?> fieldValues); @Override List<VocabularyTerm> search(Map<String, ?> fieldValues, Map<String, String> queryOptions); @Override List<VocabularyTerm> search(String input); @Override List<VocabularyTerm> search(String input, int maxResults, String sort, String customFilter); @Override long count(Map<String, ?> fieldValues); @Override long getDistance(String fromTermId, String toTermId); @Override long getDistance(VocabularyTerm fromTerm, VocabularyTerm toTerm); @Override String getIdentifier(); @Override String getName(); @Override Set<String> getAliases(); @Override Collection<String> getSupportedCategories(); @Override String getWebsite(); @Override String getCitation(); @Override long size(); @Override int reindex(String ontologyUrl); @Override String getDefaultSourceLocation(); @Override String getVersion(); @Override List<VocabularyExtension> getExtensions(); }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public long count(Map<String, ?> fieldValues) { try { HttpGet method = new HttpGet(this.searchServiceURL + URLEncoder.encode(generateQuery(fieldValues), Consts.UTF_8.name())); method.setHeader(HttpHeaders.ACCEPT, ContentType.APPLICATION_JSON.getMimeType()); try (CloseableHttpResponse httpResponse = this.client.execute(method)) { String response = IOUtils.toString(httpResponse.getEntity().getContent(), Consts.UTF_8); JSONObject responseJSON = new JSONObject(response); JSONArray docs = responseJSON.getJSONObject(RESPONSE_KEY).getJSONArray(DATA_KEY); return docs.length(); } catch (IOException | JSONException ex) { this.logger.warn("Failed to count matching gene names: {}", ex.getMessage()); } } catch (UnsupportedEncodingException ex) { } return -1; }  @Override void initialize(); @Override VocabularyTerm getTerm(String id); @Override Set<VocabularyTerm> getTerms(Collection<String> ids); @Override List<VocabularyTerm> search(Map<String, ?> fieldValues); @Override List<VocabularyTerm> search(Map<String, ?> fieldValues, Map<String, String> queryOptions); @Override List<VocabularyTerm> search(String input); @Override List<VocabularyTerm> search(String input, int maxResults, String sort, String customFilter); @Override long count(Map<String, ?> fieldValues); @Override long getDistance(String fromTermId, String toTermId); @Override long getDistance(VocabularyTerm fromTerm, VocabularyTerm toTerm); @Override String getIdentifier(); @Override String getName(); @Override Set<String> getAliases(); @Override Collection<String> getSupportedCategories(); @Override String getWebsite(); @Override String getCitation(); @Override long size(); @Override int reindex(String ontologyUrl); @Override String getDefaultSourceLocation(); @Override String getVersion(); @Override List<VocabularyExtension> getExtensions();  }