-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
added vewTrustNetwork() integration test in ViewNetwork.java
- Loading branch information
salter31
committed
Sep 20, 2013
1 parent
c02707c
commit 40b095f
Showing
2 changed files
with
107 additions
and
6 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
package test.integrate; | ||
|
||
import static org.junit.Assert.*; | ||
import org.junit.*; | ||
import org.neo4j.graphdb.Transaction; | ||
import app.*; | ||
import asg.cliche.Command; | ||
import asg.cliche.ShellFactory; | ||
import asg.cliche.InputConverter; | ||
import java.io.IOException; | ||
import java.util.HashMap; | ||
import java.util.Random; | ||
import java.util.Iterator; | ||
import org.neo4j.kernel.Traversal; | ||
import org.neo4j.graphdb.traversal.*; | ||
import org.neo4j.graphdb.*; | ||
|
||
/** | ||
* Unit test for {@link app.viewTrustNetwork}. | ||
*/ | ||
public class ViewNetwork { | ||
|
||
@Before | ||
@After | ||
public void clearDb() { | ||
app.GraphDatabase.clearDb(); | ||
} | ||
|
||
/* | ||
checks cases: | ||
user with valid tree and checks edge directions are correct | ||
user with no outgoing edges | ||
*/ | ||
@Test | ||
public void check_cases() { | ||
String out=""; | ||
GraphDatabaseService gdb=app.GraphDatabase.get(); | ||
try(Transaction tx=gdb.beginTx()){ | ||
User jason,andrew,nat,jim,christina; | ||
jason=new User(); | ||
jason.addEmail(new Email("[email protected]")); | ||
andrew=new User(); | ||
andrew.addEmail(new Email("[email protected]")); | ||
andrew.addEmail(new Email("[email protected]")); | ||
jim=new User(); | ||
jim.addEmail(new Email("[email protected]")); | ||
christina=new User(); | ||
christina.addEmail(new Email("[email protected]")); | ||
nat=new User(); | ||
nat.addEmail(new Email("[email protected]")); | ||
|
||
app.RelationshipFactory.get().getOrCreateRelationship(jason.getInternalNode(),andrew.getInternalNode(),app.RelType.TO); | ||
app.RelationshipFactory.get().getOrCreateRelationship(jason.getInternalNode(),jim.getInternalNode(),app.RelType.TO); | ||
app.RelationshipFactory.get().getOrCreateRelationship(jim.getInternalNode(),christina.getInternalNode(),app.RelType.TO); | ||
app.RelationshipFactory.get().getOrCreateRelationship(nat.getInternalNode(),jim.getInternalNode(),app.RelType.TO); | ||
|
||
for(Path pos:Traversal.description().breadthFirst().evaluator(Evaluators.fromDepth(1)).relationships(RelType.TO,Direction.OUTGOING).traverse(jason.getInternalNode())){ | ||
Node n=pos.endNode(); | ||
User u=new User(n); | ||
for(Email e: u.viewEmails()){ | ||
out=out+e.getAddress()+"\n"; | ||
break; | ||
} | ||
} | ||
|
||
assertTrue(out.equals("[email protected]\n[email protected]\n[email protected]\n")); | ||
out=""; | ||
|
||
for(Path pos:Traversal.description().breadthFirst().evaluator(Evaluators.fromDepth(1)).relationships(RelType.TO,Direction.OUTGOING).traverse(andrew.getInternalNode())){ | ||
Node n=pos.endNode(); | ||
User u=new User(n); | ||
for(Email e: u.viewEmails()){ | ||
out=out+e.getAddress()+"\n"; | ||
break; | ||
} | ||
} | ||
|
||
assertTrue(out.equals("\n")); | ||
|
||
} | ||
|
||
} | ||
} |