Search in sources :

Example 81 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionNoParams.

@Test
public void findInteractionNoParams() throws IOException {
    String expectedQuery = "START study = node:studies('*:*') " + EXPECTED_MATCH_CLAUSE_ALL + EXPECTED_RETURN_CLAUSE;
    CypherQuery query = buildInteractionQuery(new HashMap<String, String[]>(), MULTI_TAXON_ALL);
    assertThat(query.getQuery(), is(expectedQuery));
    assertThat(query.getParams().toString(), is("{}"));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 82 with CypherQuery

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

the class CypherQueryBuilderTest method findInteractionForTargetTaxaOnlyByEmptyInteractionTypeNotSupported.

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

        {
            put("sourceTaxon", new String[] { "Arthropoda" });
            put("targetTaxon", new String[] { "Mammalia" });
            put("interactionType", new String[] { "" });
        }
    };
    String expectedQuery = "START sourceTaxon = node:taxonPaths({source_taxon_name}) " + expectedMatchClause(EXPECTED_INTERACTION_CLAUSE_ALL_INTERACTIONS, false, true) + EXTERNAL_WHERE_CLAUSE_MAMMALIA + EXPECTED_RETURN_CLAUSE;
    CypherQuery query = buildInteractionQuery(params, MULTI_TAXON_ALL);
    assertThat(query.getQuery(), is(expectedQuery));
    assertThat(query.getParams().toString(), is("{source_taxon_name=path:\\\"Arthropoda\\\", target_taxon_name=path:\\\"Mammalia\\\"}"));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 83 with CypherQuery

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

the class CypherQueryBuilderTest method findTaxaAtLocationsDistinct.

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

        {
            put("bbox", new String[] { "-67.87,12.79,-57.08,23.32" });
        }
    };
    CypherQuery query = CypherQueryBuilder.createDistinctTaxaInLocationQuery(params);
    assertThat(query.getQuery(), is("START loc = node:locations('latitude:*') " + "WHERE has(loc.latitude) AND has(loc.longitude) AND loc.latitude < 23.32 AND loc.longitude > -67.87 AND loc.latitude > 12.79 AND loc.longitude < -57.08 " + "WITH loc " + "MATCH taxon<-[:CLASSIFIED_AS]-specimen-[:COLLECTED_AT]->loc " + "RETURN distinct(taxon.name?) as taxon_name, taxon.commonNames? as taxon_common_names, taxon.externalId? as taxon_external_id, taxon.path? as taxon_path, taxon.pathIds? as taxon_path_ids, taxon.pathNames? as taxon_path_ranks"));
    assertThat(query.getParams().isEmpty(), is(true));
}
Also used : HashMap(java.util.HashMap) CypherQuery(org.eol.globi.util.CypherQuery) Test(org.junit.Test)

Example 84 with CypherQuery

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

the class TaxonSearchImplIT method findCloseMatchesScientificNameRedFoxWithTypo.

@Test
public void findCloseMatchesScientificNameRedFoxWithTypo() throws IOException {
    CypherQuery cypherQuery = new TaxonSearchImpl().findCloseMatchesForCommonAndScientificNames("Vulpes vules", null);
    CypherTestUtil.validate(cypherQuery, neo4j.getGraphDatabaseService());
    String response = new CypherQueryExecutor(cypherQuery).execute(null);
    assertThat(response, StringContains.containsString("Vulpes vulpes"));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) Test(org.junit.Test)

Example 85 with CypherQuery

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

the class TaxonSearchImplIT method findCloseMatchesLowerCase.

@Test
public void findCloseMatchesLowerCase() throws IOException {
    CypherQuery cypherQuery = new TaxonSearchImpl().findCloseMatchesForCommonAndScientificNames("King mackerel", null);
    CypherTestUtil.validate(cypherQuery, neo4j.getGraphDatabaseService());
    String response = new CypherQueryExecutor(cypherQuery).execute(null);
    assertThat(response, StringContains.containsString("Scomberomorus cavalla"));
    assertThat(response, StringContains.containsString("king mackeral"));
}
Also used : CypherQuery(org.eol.globi.util.CypherQuery) Matchers.containsString(org.hamcrest.Matchers.containsString) 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