Re: [Neo4j] Using in-memory DB for unit tests
Oh man do I feel stupid - thank you both. The IMDB tutorial was so good I created a project without fully reading the API docs. Regards, Jon On Tue, Nov 29, 2011 at 10:54 PM, Michael Hunger michael.hun...@neotechnology.com wrote: you can also use rel.getOtherNode(startNode) Michael mobile mail please excuse brevity and typos Am 30.11.2011 um 06:03 schrieb Jim Webber j...@neotechnology.com: Hi Jon, // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty( asn, 123 ); as.createRelationshipTo( network, DynamicRelationshipType.withName( AS ) ); System.out.println( network.getSingleRelationship( IPAddressRelationshipType.AS, Direction.INCOMING ) .getStartNode() // It's the start node of the incoming relationship, which is the same as the end node of the outgoing relationship .getProperty( asn ) ); } You got the start and end node wrong - I changed that and your test ran just fine. Good luck with your first project - I hope it's as enjoyable as my first Neo4j project :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
[Neo4j] Using in-memory DB for unit tests
Greetings - I have started my first project using neo4j, and am having some trouble with unit tests. I must be missing something, but when I retrieve a node using an incoming direction, I am unable to get properties from that node.The first test works fine, the second one fails with a NotFoundException on the property asn. (although it does find the end-node with no trouble) Can anyone point out what I am doing wrong? Thanks, Jon /** * $Id$ */ package com.mcafee.tsw.webgraph; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.test.ImpermanentGraphDatabase; /** */ public class TestMe { private GraphDatabaseService svc; private Transaction tx; /** * @throws java.lang.Exception */ @Before public void initDB() throws Exception { svc = new ImpermanentGraphDatabase(); tx = svc.beginTx(); } /** * @throws java.lang.Exception */ @After public void closeDB() throws Exception { tx.failure(); tx.finish(); svc.shutdown(); svc = null; } // This one works. @Test public void testOutgoing() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); network.createRelationshipTo(as, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.OUTGOING) .getEndNode().getProperty(asn)); } // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); as.createRelationshipTo(network, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.INCOMING) .getEndNode().getProperty(asn)); } } ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Using in-memory DB for unit tests
Why call tx.failure in close db? On Wednesday, November 30, 2011, Jon Walton jon.w.wal...@gmail.com wrote: Greetings - I have started my first project using neo4j, and am having some trouble with unit tests. I must be missing something, but when I retrieve a node using an incoming direction, I am unable to get properties from that node.The first test works fine, the second one fails with a NotFoundException on the property asn. (although it does find the end-node with no trouble) Can anyone point out what I am doing wrong? Thanks, Jon /** * $Id$ */ package com.mcafee.tsw.webgraph; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.test.ImpermanentGraphDatabase; /** */ public class TestMe { private GraphDatabaseService svc; private Transaction tx; /** * @throws java.lang.Exception */ @Before public void initDB() throws Exception { svc = new ImpermanentGraphDatabase(); tx = svc.beginTx(); } /** * @throws java.lang.Exception */ @After public void closeDB() throws Exception { tx.failure(); tx.finish(); svc.shutdown(); svc = null; } // This one works. @Test public void testOutgoing() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); network.createRelationshipTo(as, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.OUTGOING) .getEndNode().getProperty(asn)); } // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); as.createRelationshipTo(network, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.INCOMING) .getEndNode().getProperty(asn)); } } ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user -- Best wishes, Linan Wang Architect, Programmer, PhD ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Using in-memory DB for unit tests
On Tue, Nov 29, 2011 at 7:20 PM, Linan Wang tali.w...@gmail.com wrote: Why call tx.failure in close db? To assure a pristine DB between unit tests, as suggested here: http://wiki.neo4j.org/content/Testing_with_Neo4j I don't think this is the cause of my problem as the exception gets thrown before the call to roll back the TX. On Wednesday, November 30, 2011, Jon Walton jon.w.wal...@gmail.com wrote: Greetings - I have started my first project using neo4j, and am having some trouble with unit tests. I must be missing something, but when I retrieve a node using an incoming direction, I am unable to get properties from that node.The first test works fine, the second one fails with a NotFoundException on the property asn. (although it does find the end-node with no trouble) Can anyone point out what I am doing wrong? Thanks, Jon /** * $Id$ */ package com.mcafee.tsw.webgraph; import org.junit.After; import org.junit.Before; import org.junit.Test; import org.neo4j.graphdb.Direction; import org.neo4j.graphdb.GraphDatabaseService; import org.neo4j.graphdb.Node; import org.neo4j.graphdb.RelationshipType; import org.neo4j.graphdb.Transaction; import org.neo4j.test.ImpermanentGraphDatabase; /** */ public class TestMe { private GraphDatabaseService svc; private Transaction tx; /** * @throws java.lang.Exception */ @Before public void initDB() throws Exception { svc = new ImpermanentGraphDatabase(); tx = svc.beginTx(); } /** * @throws java.lang.Exception */ @After public void closeDB() throws Exception { tx.failure(); tx.finish(); svc.shutdown(); svc = null; } // This one works. @Test public void testOutgoing() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); network.createRelationshipTo(as, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.OUTGOING) .getEndNode().getProperty(asn)); } // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty(asn, 123); as.createRelationshipTo(network, IPAddressRelationshipType.AS); System.out.println(network.getSingleRelationship(IPAddressRelationshipType.AS, Direction.INCOMING) .getEndNode().getProperty(asn)); } } ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user -- Best wishes, Linan Wang Architect, Programmer, PhD ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Using in-memory DB for unit tests
Hi Jon, // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty( asn, 123 ); as.createRelationshipTo( network, DynamicRelationshipType.withName( AS ) ); System.out.println( network.getSingleRelationship( IPAddressRelationshipType.AS, Direction.INCOMING ) .getStartNode() // It's the start node of the incoming relationship, which is the same as the end node of the outgoing relationship .getProperty( asn ) ); } You got the start and end node wrong - I changed that and your test ran just fine. Good luck with your first project - I hope it's as enjoyable as my first Neo4j project :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user
Re: [Neo4j] Using in-memory DB for unit tests
you can also use rel.getOtherNode(startNode) Michael mobile mail please excuse brevity and typos Am 30.11.2011 um 06:03 schrieb Jim Webber j...@neotechnology.com: Hi Jon, // This one results in a not found exception on the 'asn' property. @Test public void testIncoming() { Node network = svc.createNode(); Node as = svc.createNode(); as.setProperty( asn, 123 ); as.createRelationshipTo( network, DynamicRelationshipType.withName( AS ) ); System.out.println( network.getSingleRelationship( IPAddressRelationshipType.AS, Direction.INCOMING ) .getStartNode() // It's the start node of the incoming relationship, which is the same as the end node of the outgoing relationship .getProperty( asn ) ); } You got the start and end node wrong - I changed that and your test ran just fine. Good luck with your first project - I hope it's as enjoyable as my first Neo4j project :-) Jim ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user ___ Neo4j mailing list User@lists.neo4j.org https://lists.neo4j.org/mailman/listinfo/user