@Test public void getTermWithInvalidTermReturnsNull() throws ComponentLookupException, URISyntaxException, ClientProtocolException, IOException { URI expectedURI = new URI("http: 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("NOTHING.json")); VocabularyTerm result = this.mocker.getComponentUnderTest().getTerm("NOTHING"); Assert.assertEquals(expectedURI, reqCapture.getLastValue().getURI()); Assert.assertEquals("application/json", reqCapture.getLastValue().getLastHeader("Accept").getValue()); Assert.assertNull(result); verify(this.cache).set("NOTHING", this.emptyMarker); }
@Override public VocabularyTerm getTerm(String id) { VocabularyTerm result = this.cache.get(id); String safeID; if (result == null) { try { safeID = URLEncoder.encode(id, Consts.UTF_8.name()); } catch (UnsupportedEncodingException e) { safeID = id.replaceAll("\\s", ""); this.logger.warn("Could not find the encoding: {}", Consts.UTF_8.name()); } HttpGet method = new HttpGet(this.fetchServiceURL + "symbol/" + safeID); 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); if (docs.length() == 1) { result = new JSONOntologyTerm(docs.getJSONObject(0), this); this.cache.set(id, result); } else { this.cache.set(id, EMPTY_MARKER); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to fetch gene definition: {}", ex.getMessage()); } } return (result == EMPTY_MARKER) ? null : result; }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public VocabularyTerm getTerm(String id) { VocabularyTerm result = this.cache.get(id); String safeID; if (result == null) { try { safeID = URLEncoder.encode(id, Consts.UTF_8.name()); } catch (UnsupportedEncodingException e) { safeID = id.replaceAll("\\s", ""); this.logger.warn("Could not find the encoding: {}", Consts.UTF_8.name()); } HttpGet method = new HttpGet(this.fetchServiceURL + "symbol/" + safeID); 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); if (docs.length() == 1) { result = new JSONOntologyTerm(docs.getJSONObject(0), this); this.cache.set(id, result); } else { this.cache.set(id, EMPTY_MARKER); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to fetch gene definition: {}", ex.getMessage()); } } return (result == EMPTY_MARKER) ? null : result; } }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public VocabularyTerm getTerm(String id) { VocabularyTerm result = this.cache.get(id); String safeID; if (result == null) { try { safeID = URLEncoder.encode(id, Consts.UTF_8.name()); } catch (UnsupportedEncodingException e) { safeID = id.replaceAll("\\s", ""); this.logger.warn("Could not find the encoding: {}", Consts.UTF_8.name()); } HttpGet method = new HttpGet(this.fetchServiceURL + "symbol/" + safeID); 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); if (docs.length() == 1) { result = new JSONOntologyTerm(docs.getJSONObject(0), this); this.cache.set(id, result); } else { this.cache.set(id, EMPTY_MARKER); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to fetch gene definition: {}", ex.getMessage()); } } return (result == EMPTY_MARKER) ? null : result; }  }
RemoteGeneNomenclature implements Vocabulary, Initializable { @Override public VocabularyTerm getTerm(String id) { VocabularyTerm result = this.cache.get(id); String safeID; if (result == null) { try { safeID = URLEncoder.encode(id, Consts.UTF_8.name()); } catch (UnsupportedEncodingException e) { safeID = id.replaceAll("\\s", ""); this.logger.warn("Could not find the encoding: {}", Consts.UTF_8.name()); } HttpGet method = new HttpGet(this.fetchServiceURL + "symbol/" + safeID); 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); if (docs.length() == 1) { result = new JSONOntologyTerm(docs.getJSONObject(0), this); this.cache.set(id, result); } else { this.cache.set(id, EMPTY_MARKER); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to fetch gene definition: {}", ex.getMessage()); } } return (result == EMPTY_MARKER) ? null : result; }  @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 VocabularyTerm getTerm(String id) { VocabularyTerm result = this.cache.get(id); String safeID; if (result == null) { try { safeID = URLEncoder.encode(id, Consts.UTF_8.name()); } catch (UnsupportedEncodingException e) { safeID = id.replaceAll("\\s", ""); this.logger.warn("Could not find the encoding: {}", Consts.UTF_8.name()); } HttpGet method = new HttpGet(this.fetchServiceURL + "symbol/" + safeID); 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); if (docs.length() == 1) { result = new JSONOntologyTerm(docs.getJSONObject(0), this); this.cache.set(id, result); } else { this.cache.set(id, EMPTY_MARKER); } } catch (IOException | JSONException ex) { this.logger.warn("Failed to fetch gene definition: {}", ex.getMessage()); } } return (result == EMPTY_MARKER) ? null : result; }  @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();  }