BioEntityPropertyDao { public Map<BioentityPropertyName, Set<String>> fetchGenePageProperties(String identifier) { Map<BioentityPropertyName, Set<String>> propertiesByName = solrClient.getMap(identifier, BIOENTITY_PROPERTY_NAMES); if (propertiesByName.isEmpty()) { SolrQueryBuilder<AnalyticsCollectionProxy> solrQueryBuilder = new SolrQueryBuilder<>(); solrQueryBuilder.addQueryFieldByTerm(BIOENTITY_IDENTIFIER_SEARCH, identifier); if (analyticsCollectionProxy.query(solrQueryBuilder).getResults().isEmpty()) { throw new BioentityNotFoundException("Gene/protein <em>" + identifier + "</em> not found."); } else { propertiesByName.put(ENSGENE, ImmutableSet.of(identifier)); } } return propertiesByName; } @Inject  BioEntityPropertyDao(BioentitiesSolrClient gxaSolrClient,
                                SolrCloudCollectionProxyFactory collectionProxyFactory); Set<String> fetchPropertyValuesForGeneId(String identifier, BioentityPropertyName propertyName); Set<String> fetchGeneIdsForPropertyValue(BioentityPropertyName bioentityPropertyName,
                                                    String bioentityPropertyValue); Map<BioentityPropertyName, Set<String>> fetchGenePageProperties(String identifier);  }
@Test(expected = BioentityNotFoundException.class) public void geneIdNotFoundInBioentitiesNorAnalyticsCollectionThrows() { when(analyticsCollectionProxyMock.query( argThat(solrQueryBuilder -> !solrQueryBuilder.build().get("q") .equals("bioentity_identifier_search:" + ID_IN_ANALYTICS)))) .thenReturn(noResultsQueryResponseMock); subject.fetchGenePageProperties("ENSFOOBAR"); }
@Test public void ifGeneIdInBioentitiesWeDontQueryAnalytics() { assertThat(subject.fetchGenePageProperties(ID_IN_BIOENTITIES)) .containsOnlyKeys(SYMBOL) .containsValues(ImmutableSet.of(ID_IN_BIOENTITIES_SYMBOL)); verifyZeroInteractions(analyticsCollectionProxyMock); }
@Test public void ifGeneIdNotInBioentitiesButInAnalytics() { when(analyticsCollectionProxyMock.query( argThat(solrQueryBuilder -> solrQueryBuilder.build().getQuery() .equals("bioentity_identifier_search:(\"" + ID_IN_ANALYTICS + "\")")))) .thenReturn(oneResultQueryResponseMock); assertThat(subject.fetchGenePageProperties(ID_IN_ANALYTICS)) .containsOnlyKeys(ENSGENE); verify(analyticsCollectionProxyMock) .query( argThat(solrQueryBuilder -> solrQueryBuilder.build().getQuery() .equals("bioentity_identifier_search:(\"" + ID_IN_ANALYTICS + "\")"))); }