Skip to content

Commit

Permalink
Merge pull request #14 from salter31/software-testing
Browse files Browse the repository at this point in the history
finished viewTrustNetwork(Email)
  • Loading branch information
James Miller V committed Sep 20, 2013
2 parents b676ae8 + 40b095f commit 148e93c
Show file tree
Hide file tree
Showing 2 changed files with 107 additions and 6 deletions.
30 changes: 24 additions & 6 deletions src/app/Cli.java
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,10 @@
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.*;

public class Cli {

Expand All @@ -18,15 +22,15 @@ private class Result {
Session session = null;
String payload = "";

public Result( boolean ans, Session s ) {
success = ans;
session = s;
}

public Result( boolean ans, String reason ) {
success = ans;
payload = reason;
}

public Result( boolean ans, Session s ) {
success = ans;
session = s;
}

public String toString() {
if( success )
Expand Down Expand Up @@ -221,7 +225,21 @@ public Result viewSubjectiveNetwork( String session_id, String subject, int thre

@Command
public Result viewTrustNetwork( String email ) {
return null;
GraphDatabaseService gdb=app.GraphDatabase.get();
try(Transaction tx=gdb.beginTx()){
Email me=new Email(email);
Node node=me.getInternalNode();
for(Path pos:Traversal.description().breadthFirst().evaluator(Evaluators.fromDepth(1)).relationships(RelType.TO,Direction.OUTGOING).traverse(node)){
User u=new User(pos.endNode());
for(Email e: u.viewEmails()){
System.out.println(e.getAddress());
break;
}
}
}
return new Result(true,"");


}

public static void main(String[] args) throws IOException {
Expand Down
83 changes: 83 additions & 0 deletions src/test/integrate/ViewNetwork.java
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"));

}

}
}

0 comments on commit 148e93c

Please sign in to comment.