Search in sources :

Example 31 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class CypherQueryBuilderTest method findInteractionsTaxaInteractionIndexTargetTaxaNumberOfInteractionsInteractionType.

@Test
public void findInteractionsTaxaInteractionIndexTargetTaxaNumberOfInteractionsInteractionType() throws IOException {
    HashMap<String, String[]> params = new HashMap<String, String[]>() {

        {
            put("targetTaxon", new String[] { "Arthropoda" });
            put("field", new String[] { "source_taxon_name", "target_taxon_name", "interaction_type" });
        }
    };
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_DISTINCT_BY_NAME_ONLY);
    assertThat(query.getQuery(), is("START targetTaxon = node:taxonPaths({target_taxon_name}) " + "MATCH sourceTaxon-[interaction:" + InteractUtil.interactionsCypherClause(INTERACTS_WITH) + "]->targetTaxon " + "RETURN sourceTaxon.name as source_taxon_name,targetTaxon.name as target_taxon_name,interaction.label? as interaction_type"));
    Map<String, String> expected = new HashMap<String, String>() {

        {
            put("target_taxon_name", "path:\\\"Arthropoda\\\"");
        }
    };
    assertThat(query.getParams(), is(expected));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 32 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class ReportControllerTest method distinctSourcePrefix.

@Test
public void distinctSourcePrefix() throws IOException {
    CypherQuery source = new ReportController().sources("bla:someSourceId", null);
    assertThat(source.getVersionedQuery(), is(CYPHER_VERSION + "START report = node:reports(sourceId={sourceId}) " + "RETURN report.citation as study_citation, " + "report.externalId as study_url, " + "report.doi as study_doi, " + "null as study_source_citation, " + "report.nInteractions as number_of_interactions, " + "report.nTaxa as number_of_distinct_taxa, " + "report.nStudies as number_of_studies, " + "report.nSources as number_of_sources, " + "report.nTaxaNoMatch as number_of_distinct_taxa_no_match, " + "report.sourceId as study_source_id " + "SKIP 0 " + "LIMIT 1024"));
    assertThat(source.getParams().get("sourceId"), is("bla:someSourceId"));
    validate(source);
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 33 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class TaxonSearchImplIT method findCloseMatchesShortPartial2.

@Test
public void findCloseMatchesShortPartial2() throws IOException {
    CypherQuery cypherQuery = new TaxonSearchImpl().findCloseMatchesForCommonAndScientificNames("h s", null);
    CypherTestUtil.validate(cypherQuery, neo4j.getGraphDatabaseService());
    String response = new CypherQueryExecutor(cypherQuery).execute(null);
    assertThat(response.startsWith(COLUMN_PREFIX), is(true));
    // expect at least one common name
    assertThat(response, StringContains.containsString("@en"));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 34 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class TaxonSearchImplIT method assertHuman.

private void assertHuman(String searchTerm) throws IOException {
    CypherQuery cypherQuery = new TaxonSearchImpl().findCloseMatchesForCommonAndScientificNames(searchTerm, null);
    CypherTestUtil.validate(cypherQuery, neo4j.getGraphDatabaseService());
    String response = new CypherQueryExecutor(cypherQuery).execute(null);
    assertThat(response, startsWith(COLUMN_PREFIX));
    assertThat(response, StringContains.containsString("Homo sapiens"));
    assertThat(response, StringContains.containsString("man"));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Matchers.containsString(org.hamcrest.Matchers.containsString)

Example 35 with CypherQuery

use of org.eol.globi.util.CypherQuery in project eol-globi-data by jhpoelen.

the class TaxonSearchImplIT method findCloseMatchesScientificGenus.

@Test
public void findCloseMatchesScientificGenus() throws IOException {
    CypherQuery cypherQuery = new TaxonSearchImpl().findCloseMatchesForCommonAndScientificNames("Ariidae", null);
    CypherTestUtil.validate(cypherQuery, neo4j.getGraphDatabaseService());
    String response = new CypherQueryExecutor(cypherQuery).execute(null);
    JsonNode mapper = new ObjectMapper().readTree(response);
    JsonNode data = mapper.get("data");
    assertThat(data.isArray(), is(true));
    assertThat(data.size() > 0, is(true));
    assertThat(response, StringContains.containsString("Ariidae"));
}
Also used : JsonNode(com.fasterxml.jackson.databind.JsonNode) CypherQuery(org.eol.globi.util.CypherQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

CypherQuery (org.eol.globi.util.CypherQuery)109 Test (org.junit.Test)92 HashMap (java.util.HashMap)66 Matchers.containsString (org.hamcrest.Matchers.containsString)13 RequestMapping (org.springframework.web.bind.annotation.RequestMapping)7 ResponseBody (org.springframework.web.bind.annotation.ResponseBody)7 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)4 Map (java.util.Map)4 ResultField (org.eol.globi.server.util.ResultField)3 ArrayList (java.util.ArrayList)2 HashSet (java.util.HashSet)2 TreeMap (java.util.TreeMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1 JsonNode (org.codehaus.jackson.JsonNode)1 ObjectMapper (org.codehaus.jackson.map.ObjectMapper)1 InteractionTypeExternal (org.eol.globi.server.util.InteractionTypeExternal)1 ResultFormatterCSV (org.eol.globi.server.util.ResultFormatterCSV)1 CoreMatchers.containsString (org.hamcrest.CoreMatchers.containsString)1 StringContains.containsString (org.hamcrest.core.StringContains.containsString)1