@Test public void testUpdateNode() { double lon = -139.12; double lat = -45.24; Transaction tx = graphDb.beginTx(); String query = "MATCH n-[r]-() DELETE n, r"; graphDb.execute(query); query = "MATCH (n) WHERE HAS (n.geohash) DELETE n"; graphDb.execute(query); root = PrefixTree.getOrCreateRoot(INDEXLABEL, graphDb); List<Node> candidate = gendata.insertNode(graphDb, 10, true); for (Node node : candidate) { PrefixTree.addNode(graphDb, root, node); } String geoHashPre = (String) candidate.get(0).getProperty(GEOHASH); String geoHashCur = GeoHash.getHash(lon, lat); List<Node> child = PrefixTree.getChild(geoHashPre, root, 7); assertEquals(child.size(), 1); PrefixTree.updateNode(graphDb, root, candidate.get(0), lon, lat); child = PrefixTree.getChild(geoHashPre, root, 7); assertEquals(child.size(), 0); child = PrefixTree.getChild(geoHashCur, root, 7); assertEquals(child.size(), 1); tx.close(); graphDb.shutdown(); }
@Test public void testDeleteNode() { Transaction tx = graphDb.beginTx(); String query = "MATCH n-[r]-() DELETE n, r"; graphDb.execute(query); query = "MATCH (n) WHERE HAS (n.geohash) DELETE n"; graphDb.execute(query); root = PrefixTree.getOrCreateRoot(INDEXLABEL, graphDb); List<Node> candidate = gendata.insertNode(graphDb, 10, true); for (Node node : candidate) { PrefixTree.addNode(graphDb, root, node); } List<Node> child = PrefixTree.getChild((String) candidate.get(0).getProperty(GEOHASH), root, 7); assertTrue(candidate.get(0).getProperty(GEOHASH) == child.get(0).getProperty(GEOHASH)); PrefixTree.deleteNode(candidate.get(0)); child = PrefixTree.getChild((String) candidate.get(0).getProperty(GEOHASH), root, 7); assertEquals(child.size(), 0); tx.close(); graphDb.shutdown(); }
@Test public void testAddNode() { List<Node> candidate = null; List<Node> child = null; Transaction tx = graphDb.beginTx(); try { root = PrefixTree.getOrCreateRoot(INDEXLABEL, graphDb); candidate = gendata.insertNode(graphDb, 1, false); PrefixTree.addNode(graphDb, root, candidate.get(0)); child = PrefixTree.getChild((String) candidate.get(0).getProperty(GEOHASH), root, 7); assertTrue(candidate.get(0).getProperty(GEOHASH) == child.get(0).getProperty(GEOHASH)); } catch (Exception e) { System.out.println(e); } finally { tx.close(); } graphDb.shutdown(); }