@Test public void testAddToIndex() { final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase()); matrixDataGraph.createNodespace(); final RestNode neoNode = restAPI.getNodeById(matrixDataGraph.getNeoNode().getId()); final Transaction tx = restAPI.beginTx(); restAPI.index().forNodes("heroes").add(neoNode, "indexname", "Neo2"); Node n1 = restAPI.createNode(map("name", "Apoc")); final Index<Node> index = restAPI.index().forNodes("heroes"); index.add(n1, "indexname", "Apoc"); final Node indexResult = getGraphDatabase().index().forNodes("heroes").get("indexname", "Neo2").getSingle(); assertNull(indexResult); final IndexHits<Node> heroes = index.query("indexname:Apoc"); tx.success(); tx.finish(); assertEquals("1 hero", 1, heroes.size()); IndexManager realIndex = getGraphDatabase().index(); Index<Node> goodGuys = realIndex.forNodes("heroes"); IndexHits<Node> hits = goodGuys.get("indexname", "Apoc"); Node apoc = hits.getSingle(); assertEquals("Apoc indexed", apoc, heroes.iterator().next()); }
@Test(expected = UnsupportedOperationException.class) public void testRemoveEntryFromIndexWithGivenNodeAndKeyAndValue() { final Transaction tx = restAPI.beginTx(); Node n1 = restAPI.createNode(map("name", "node1")); final Index<Node> index = restAPI.index().forNodes("testIndex"); index.add(n1, "indexname", "Node1"); index.remove(n1, "indexname", "Node1"); tx.success(); tx.finish(); assertNull(index.get("indexname", "Node1").getSingle()); }
@Test public void testRemoveEntryFromIndexWithGivenNode() { Node n1 = restAPI.createNode(map("name", "node1")); final Index<Node> index = restAPI.index().forNodes("testIndex"); index.add(n1, "indexname", "Node1"); final Transaction tx = restAPI.beginTx(); index.remove(n1); tx.success(); tx.finish(); assertNull(index.get("indexname", "Node1").getSingle()); }
@Test public void testDeleteIndex() { final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase()); matrixDataGraph.createNodespace(); final Transaction tx = restAPI.beginTx(); final Index<Node> heroes = restAPI.index().forNodes("heroes"); heroes.delete(); tx.success(); tx.finish(); Assert.assertFalse(getGraphDatabase().index().existsForNodes("heroes")); }
@Test public void testQueryIndex() { final MatrixDataGraph matrixDataGraph = new MatrixDataGraph(getGraphDatabase()); matrixDataGraph.createNodespace(); final Transaction tx = restAPI.beginTx(); final Index<Node> index = restAPI.index().forNodes("heroes"); final IndexHits<Node> heroes = index.query("name:Neo"); tx.success(); tx.finish(); assertEquals("1 hero", 1, heroes.size()); assertEquals("Neo indexed", matrixDataGraph.getNeoNode(), heroes.iterator().next()); }