private String concatenateLabels(Value labels) { return labels.toString().replace("\", \"", ":").replaceAll("[\"\\[\\]]", ""); }
return v.asString(); case "LegacyIndex": return v.toString(); case "version": return v.toString(); case "planner": return v.toString(); case "planner-impl": return v.toString(); case "runtime": return v.toString(); case "runtime-impl": return v.toString(); case "MergePattern": return "MergePattern(" + v.toString() + ")"; case "DbHits": return v.asNumber().toString();
@Test public void triesAgainOnSessionExpired() throws Exception { Session sessionMock = mock(Session.class); StatementResult versionMock = mock(StatementResult.class); StatementResult resultMock = mock(StatementResult.class); Record recordMock = mock(Record.class); Value valueMock = mock(Value.class); Driver driverMock = stubVersionInAnOpenSession(versionMock, sessionMock, "neo4j-version"); when(resultMock.list()).thenReturn(asList(recordMock)); when(valueMock.toString()).thenReturn("999"); when(recordMock.get(0)).thenReturn(valueMock); when(sessionMock.run(any(Statement.class))) .thenThrow(new SessionExpiredException("leaderswitch")) .thenReturn(resultMock); OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock); boltStateHandler.connect(); BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get(); verify(driverMock, times(2)).session(any(), anyString()); verify(sessionMock, times(2)).run(any(Statement.class)); assertEquals("999", boltResult.getRecords().get(0).get(0).toString()); }
@Test public void shouldRunCypherQuery() throws CommandException { Session sessionMock = mock(Session.class); StatementResult versionMock = mock(StatementResult.class); StatementResult resultMock = mock(StatementResult.class); Record recordMock = mock(Record.class); Value valueMock = mock(Value.class); Driver driverMock = stubVersionInAnOpenSession(versionMock, sessionMock, "neo4j-version"); when(resultMock.list()).thenReturn(asList(recordMock)); when(valueMock.toString()).thenReturn("999"); when(recordMock.get(0)).thenReturn(valueMock); when(sessionMock.run(any(Statement.class))).thenReturn(resultMock); OfflineBoltStateHandler boltStateHandler = new OfflineBoltStateHandler(driverMock); boltStateHandler.connect(); BoltResult boltResult = boltStateHandler.runCypher("RETURN 999", new HashMap<>()).get(); verify(sessionMock).run(any(Statement.class)); assertEquals("999", boltResult.getRecords().get(0).get(0).toString()); }
@Test public void prettyPrintPlanInformation() throws Exception { // given ResultSummary resultSummary = mock(ResultSummary.class); ProfiledPlan plan = mock(ProfiledPlan.class); when(plan.dbHits()).thenReturn(1000L); when(plan.records()).thenReturn(20L); when(resultSummary.hasPlan()).thenReturn(true); when(resultSummary.hasProfile()).thenReturn(true); when(resultSummary.plan()).thenReturn(plan); when(resultSummary.profile()).thenReturn(plan); when(resultSummary.resultAvailableAfter(anyObject())).thenReturn(5L); when(resultSummary.resultConsumedAfter(anyObject())).thenReturn(7L); when(resultSummary.statementType()).thenReturn(StatementType.READ_ONLY); Map<String, Value> argumentMap = Values.parameters("Version", "3.1", "Planner", "COST", "Runtime", "INTERPRETED").asMap(v -> v); when(plan.arguments()).thenReturn(argumentMap); BoltResult result = mock(BoltResult.class); when(result.getRecords()).thenReturn(Collections.emptyList()); when(result.getSummary()).thenReturn(resultSummary); // when String actual = verbosePrinter.format(result); // then argumentMap.forEach((k, v) -> { assertThat(actual, CoreMatchers.containsString("| " + k)); assertThat(actual, CoreMatchers.containsString("| " + v.toString())); }); }
when(boltResultMock2.getRecords()).thenReturn(asList(record3)); when(str1Val.toString()).thenReturn("str1"); when(str2Val.toString()).thenReturn("str2"); when(val1.toString()).thenReturn("1"); when(val2.toString()).thenReturn("2"); assertEquals("1", actualRecord1.get(0).toString()); assertEquals("2", actualRecord2.get(0).toString()); assertEquals("str1", actualRecord3.get(0).toString()); assertEquals("str2", actualRecord3.get(1).toString());
/** * Checks if the cellular location given in properties is already in database. If not, it creates it and * returns the node. * * @param tx Transaction * @param properties: Map containing all the properties to be added. Key "id" must be among all the possible keys. * @return Node that has been created. */ private StatementResult getOrCreateCellularLocationNode(Transaction tx, ObjectMap properties) { StatementResult cellLoc = getOrCreateNode(tx, NodeTypes.CELLULAR_LOCATION.toString(), new ObjectMap("name", properties.get("name"))); // gets or creates ontology node if (properties.containsKey("ontologies")) { for (ObjectMap myOntology : (List<ObjectMap>) properties.get("ontologies")) { StatementResult ont = getOrCreateNode(tx, NodeTypes.ONTOLOGY.toString(), myOntology); addRelationship(tx, NodeTypes.CELLULAR_LOCATION.toString(), NodeTypes.ONTOLOGY.toString(), cellLoc.peek().get("ID").toString(), ont.peek().get("ID").toString(), RelTypes.CELLOC_ONTOLOGY); } } return cellLoc; }
/** * Method to annotate Xrefs in the database. * * @param nodeID ID of the node we want to annotate * @param xrefList List containing all the Xref annotations to be added in the database */ @Override public void addXrefs(String nodeID, List<Xref> xrefList) throws BioNetDBException { Session session = this.driver.session(); try (Transaction tx = session.beginTransaction()) { StatementResult xrefNode = getNode(tx, NodeTypes.XREF.toString(), new ObjectMap("id", nodeID)); if (xrefNode.hasNext()) { // Look for the physical entity to which the xref is associated with StatementResult pE = tx.run("MATCH (n:" + NodeTypes.PHYSICAL_ENTITY + ")-[" + RelTypes.XREF + "]->(x:" + NodeTypes.XREF + ") WHERE ID(x) = " + xrefNode.peek().get("ID").toString() + " RETURN ID(n) AS ID, LABELS(n) AS LABELS"); for (Xref x : xrefList) { StatementResult myxref = getOrCreateNode(tx, NodeTypes.XREF.toString(), parseXref(x)); addRelationship(tx, concatenateLabels(pE.peek().get("LABELS")), NodeTypes.XREF.toString(), pE.peek().get("ID").toString(), myxref.peek().get("ID").toString(), RelTypes.XREF); } } else { throw new BioNetDBException("The node to be annotated does not exist in the database."); } tx.success(); } session.close(); }
case NULL: default: return value.toString();
String peLabel = NodeTypes.PHYSICAL_ENTITY + ":" + p.getType(); StatementResult n = getOrCreateNode(tx, peLabel, parsePhysicalEntity(p)); String pEID = n.peek().get("ID").toString(); StatementResult ont = getOrCreateNode(tx, NodeTypes.ONTOLOGY.toString(), parseOntology(o)); addRelationship(tx, peLabel, NodeTypes.ONTOLOGY.toString(), pEID, ont.peek().get("ID").toString(), RelTypes.ONTOLOGY); StatementResult cellLoc = getOrCreateCellularLocationNode(tx, parseCellularLocation(c)); addRelationship(tx, peLabel, NodeTypes.CELLULAR_LOCATION.toString(), pEID, cellLoc.peek().get("ID").toString(), RelTypes.CELLULAR_LOCATION); StatementResult xr = getOrCreateNode(tx, NodeTypes.XREF.toString(), parseXref(xref)); addRelationship(tx, peLabel, NodeTypes.XREF.toString(), pEID, xr.peek().get("ID").toString(), RelTypes.XREF); + "\": is not properly inserted"); if (complexNode.peek().get("LABELS").toString().contains(PhysicalEntity.Type.COMPLEX.toString())) { String peLabel = NodeTypes.PHYSICAL_ENTITY + ":" + p.getType(); addRelationship(tx, peLabel, NodeTypes.PHYSICAL_ENTITY + ":" + PhysicalEntity.Type.COMPLEX, peNode.peek().get("ID").toString(), complexNode.peek().get("ID").toString(), RelTypes.COMPONENTOFCOMPLEX); } else { throw new BioNetDBException("Relationship 'COMPONENTOFCOMPLEX' cannot be created " + "because the destiny node is of type \"" + complexNode.peek().get("LABELS").toString() + "\" Check Physical Entity \"" + complexID + "\"");
String interactionLabel = NodeTypes.INTERACTION + ":" + i.getType(); StatementResult interaction = getNode(tx, interactionLabel, new ObjectMap("id", i.getId())); String interactionID = interaction.peek().get("ID").toString(); new ObjectMap("id", myId)); addRelationship(tx, concatenateLabels(reactant.peek().get("LABELS")), interactionLabel, reactant.peek().get("ID").toString(), interactionID, RelTypes.REACTANT); new ObjectMap("id", myId)); addRelationship(tx, interactionLabel, concatenateLabels(product.peek().get("LABELS")), interactionID, product.peek().get("ID").toString(), RelTypes.PRODUCT); new ObjectMap("id", myId)); addRelationship(tx, concatenateLabels(reactant.peek().get("LABELS")), interactionLabel, reactant.peek().get("ID").toString(), interactionID, RelTypes.CONTROLLER); new ObjectMap("id", myId)); addRelationship(tx, interactionLabel, concatenateLabels(product.peek().get("LABELS")), interactionID, product.peek().get("ID").toString(), RelTypes.CONTROLLED); new ObjectMap("id", myId)); addRelationship(tx, concatenateLabels(reactant.peek().get("LABELS")), interactionLabel, reactant.peek().get("ID").toString(), interactionID, RelTypes.CONTROLLER); new ObjectMap("id", myId)); addRelationship(tx, interactionLabel, concatenateLabels(product.peek().get("LABELS")),