@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 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()); }
/** * get the number of all nodes that know the neo node * * @throws Exception */ @Test public void getNeoFriends() throws Exception { Node neoNode = restmdg.getNeoNode(); System.out.println(neoNode.getProperty("name")); Traverser friendsTraverser = getFriends(neoNode); int numberOfFriends = 0; for (Path friendPath : friendsTraverser) { numberOfFriends++; } assertEquals(4, numberOfFriends); }
@Test public void testSetMaxtrixProperty() { restmdg.getNeoNode().setProperty("occupation", "the one"); Node node = embeddedmdg.getNeoNode(); Assert.assertEquals("the one", node.getProperty("occupation")); }