Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 09af4fb

Browse files
committed
Upgraded to neo4j 2.1.4 and latest Doctor Who episodes (Capaldi)
1 parent 8a9a21b commit 09af4fb

File tree

9 files changed

+70
-35
lines changed

9 files changed

+70
-35
lines changed

settings/path.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<project name="path" default="donothingToMakeAValidAntFile"
44
basedir=".">
55

6-
<property name="neo4j.version" value="2.1.3"/>
6+
<property name="neo4j.version" value="2.1.4"/>
77

88
<property name="download.dir" location="downloads"/>
99
<property name="neo4j.download.dir" location="${download.dir}/neo4j"/>
@@ -32,7 +32,7 @@
3232

3333
<property name="settings.dir" location="settings"/>
3434

35-
<target name="donothingToMakeAValidAntFile"/>
35+
<target name="doNothingToMakeAValidAntFile"/>
3636

3737
<path id="path.libs">
3838
<fileset dir="${lib.dir}">

src/koan/java/org/neo4j/tutorial/Koan3.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ public void shouldFindAllTheEpisodesUsingLabels()
8181

8282
Iterator<String> iterator = result.javaColumnAs( "episode" );
8383

84-
assertEquals( 263l, count( iterator ) );
84+
assertEquals( 266l, count( iterator ) );
8585
}
8686

8787
private long count( Iterator<String> result )
@@ -211,7 +211,7 @@ public void shouldFindIndividualCompanionsAndEnemiesOfTheDoctor()
211211

212212
ExecutionResult result = engine.execute( cql );
213213

214-
assertEquals( 159, result.size() );
214+
assertEquals( 162, result.size() );
215215
transaction.success();
216216
}
217217
}

src/koan/java/org/neo4j/tutorial/advanced/BasicRestApiFormerlyKoan10.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,7 @@ public void shouldCountTheEnemiesOfTheDoctor() throws Exception
8787
// SNIPPET_END
8888

8989
List<Map<String, Object>> json = JsonHelper.jsonToList( response );
90-
int numberOfEnemiesOfTheDoctor = 156;
90+
int numberOfEnemiesOfTheDoctor = 159;
9191
assertEquals( numberOfEnemiesOfTheDoctor, json.size() );
9292
}
9393

src/koan/java/org/neo4j/tutorial/advanced/GraphAlgorithmsInJavaFormerlyKoan09.java

Lines changed: 24 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,10 @@
2525
import static org.junit.Assert.assertNotNull;
2626
import static org.junit.Assert.assertThat;
2727

28+
import static org.neo4j.graphdb.Direction.BOTH;
29+
import static org.neo4j.tutorial.DoctorWhoLabels.ACTOR;
30+
import static org.neo4j.tutorial.DoctorWhoLabels.EPISODE;
31+
import static org.neo4j.tutorial.DoctorWhoRelationships.APPEARED_IN;
2832
import static org.neo4j.tutorial.matchers.ContainsOnlySpecificNodes.containsOnlySpecificNodes;
2933
import static org.neo4j.tutorial.matchers.PathsMatcher.consistPreciselyOf;
3034

@@ -65,7 +69,7 @@ public void shouldRevealTheEpisodesWhereRoseTylerFoughtTheDaleks()
6569
// SNIPPET_START
6670

6771
PathFinder<Path> pathFinder = GraphAlgoFactory.pathsWithLength(
68-
Traversal.expanderForTypes( DoctorWhoRelationships.APPEARED_IN, Direction.BOTH ), 2 );
72+
Traversal.expanderForTypes( APPEARED_IN, BOTH ), 2 );
6973
paths = pathFinder.findAllPaths( rose, daleks );
7074

7175
// SNIPPET_END
@@ -84,8 +88,8 @@ private HashSet<Node> knownRoseVersusDaleksEpisodes()
8488
HashSet<Node> roseVersusDaleksEpisodes = new HashSet<>();
8589
for ( String title : roseVersusDaleksEpisodeTitles )
8690
{
87-
roseVersusDaleksEpisodes.add( universe.getDatabase().findNodesByLabelAndProperty( DoctorWhoLabels
88-
.EPISODE, "title", title ).iterator().next() );
91+
roseVersusDaleksEpisodes.add( universe.getDatabase().findNodesByLabelAndProperty(
92+
EPISODE, "title", title ).iterator().next() );
8993
}
9094
return roseVersusDaleksEpisodes;
9195
}
@@ -97,9 +101,9 @@ public void shouldFindTheNumberOfMasterRegenerationsTheEasyWay()
97101

98102
try ( Transaction tx = database.beginTx() )
99103
{
100-
Node delgado = database.findNodesByLabelAndProperty( DoctorWhoLabels.ACTOR, "actor",
104+
Node delgado = database.findNodesByLabelAndProperty( ACTOR, "actor",
101105
"Roger Delgado" ).iterator().next();
102-
Node simm = database.findNodesByLabelAndProperty( DoctorWhoLabels.ACTOR, "actor",
106+
Node simm = database.findNodesByLabelAndProperty( ACTOR, "actor",
103107
"John Simm" ).iterator().next();
104108
Path path = null;
105109

@@ -122,32 +126,37 @@ public void shouldFindTheNumberOfMasterRegenerationsTheEasyWay()
122126
}
123127

124128
@Test
125-
public void shouldRevealEpisodeWhenTennantRegeneratedToSmith()
129+
public void shouldFindEpisodesWhereMattSmithAndDavidTennantAppeared()
126130
{
127131
GraphDatabaseService database = universe.getDatabase();
128132
try ( Transaction tx = database.beginTx() )
129133
{
130-
Node tennant = database.findNodesByLabelAndProperty( DoctorWhoLabels.ACTOR, "actor",
131-
"David Tennant" ).iterator().next();
132-
Node smith = database.findNodesByLabelAndProperty( DoctorWhoLabels.ACTOR, "actor",
133-
"Matt Smith" ).iterator().next();
134-
Path path = null;
134+
Node tennant = database.findNodesByLabelAndProperty( ACTOR, "actor", "David Tennant" ).iterator().next();
135+
Node smith = database.findNodesByLabelAndProperty( ACTOR, "actor", "Matt Smith" ).iterator().next();
136+
Iterable<Path> path = null;
135137

136138
// YOUR CODE GOES HERE
137139
// SNIPPET_START
138140

139141
PathFinder<Path> pathFinder = GraphAlgoFactory.pathsWithLength(
140-
Traversal.expanderForTypes( DoctorWhoRelationships.APPEARED_IN, Direction.BOTH ), 2 );
141-
path = pathFinder.findSinglePath( tennant, smith );
142+
Traversal.expanderForTypes( APPEARED_IN, BOTH ), 2 );
143+
144+
path = pathFinder.findAllPaths( tennant, smith );
145+
146+
System.out.println( path );
142147

143148
// SNIPPET_END
144149

145150
tx.success();
146151

147152
assertNotNull( path );
148-
Node endOfTimeEpisode = database.findNodesByLabelAndProperty( DoctorWhoLabels.EPISODE, "title",
153+
Node endOfTime = database.findNodesByLabelAndProperty( EPISODE, "title",
149154
"The End of Time" ).iterator().next();
150-
assertThat( path, containsOnlySpecificNodes( tennant, smith, endOfTimeEpisode ) );
155+
156+
Node dayOfTheDoctor = database.findNodesByLabelAndProperty( EPISODE, "title",
157+
"The Day of the Doctor" ).iterator().next();
158+
159+
assertThat( path, containsOnlySpecificNodes( tennant, smith, dayOfTheDoctor, endOfTime ) );
151160
}
152161
}
153162
}

src/koan/java/org/neo4j/tutorial/advanced/ManagedExtensionsFormerlyKoan12.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -67,8 +67,7 @@ public void shouldFindAwesomenessRatingsRoseTyler() throws Exception
6767
// Remember to configure src/koan/resources as test source in your IDE or the org.neo4j.server.plugins
6868
// .ServerPlugin
6969
// file will not be found and this unit test will fail (the Ant build will still be ok)
70-
// See: http://www.markhneedham.com/blog/2011/06/09/intellij-adding-resources-with-unusual-extensions-onto
71-
// -the-classpath/
70+
// See: http://www.markhneedham.com/blog/2011/06/09/intellij-adding-resources-with-unusual-extensions-onto-the-classpath/
7271
// You'll need to add *ServerPlugin* onto your classpath accordingly.
7372

7473
ClientConfig config = new DefaultClientConfig();

src/koan/java/org/neo4j/tutorial/matchers/ContainsOnlySpecificNodes.java

Lines changed: 9 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
import org.neo4j.graphdb.Node;
1111
import org.neo4j.graphdb.Path;
1212

13-
public class ContainsOnlySpecificNodes extends TypeSafeMatcher<Path>
13+
public class ContainsOnlySpecificNodes extends TypeSafeMatcher<Iterable<Path>>
1414
{
1515

1616
private final HashSet<Node> nodes = new HashSet<>();
@@ -30,25 +30,23 @@ public void describeTo( Description description )
3030
}
3131

3232
@Override
33-
public boolean matchesSafely( Path path )
33+
public boolean matchesSafely( Iterable<Path> paths )
3434
{
35-
for ( Node n : path.nodes() )
35+
for ( Path path : paths )
3636
{
37-
if ( nodes.contains( n ) )
37+
for ( Node n : path.nodes() )
3838
{
39-
nodes.remove( n );
40-
}
41-
else
42-
{
43-
return false;
39+
if ( nodes.contains( n ) )
40+
{
41+
nodes.remove( n );
42+
}
4443
}
4544
}
46-
4745
return nodes.size() == 0;
4846
}
4947

5048
@Factory
51-
public static <T> Matcher<Path> containsOnlySpecificNodes( Node... nodes )
49+
public static <T> Matcher<Iterable<Path>> containsOnlySpecificNodes( Node... nodes )
5250
{
5351
return new ContainsOnlySpecificNodes( nodes );
5452
}

src/main/java/org/neo4j/tutorial/EpisodeBuilder.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,14 @@ public EpisodeBuilder title( String title )
5252

5353
public EpisodeBuilder doctor( String... actorNames )
5454
{
55+
for ( String actor : actorNames )
56+
{
57+
if ( actor.contains( "," ) )
58+
{
59+
throw new RuntimeException( "Doctor actor appears to have inappropriate punctuation in name. Perhaps " +
60+
"you've written the builder call incorrectly." );
61+
}
62+
}
5563
addAll( doctorActors, actorNames );
5664
return this;
5765
}

src/main/java/org/neo4j/tutorial/Episodes.java

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ public void insert()
9292
season32();
9393
season33();
9494
season34();
95+
season35();
9596

9697

9798
EpisodeBuilder.reset();
@@ -100,6 +101,26 @@ public void insert()
100101
}
101102
}
102103

104+
private void season35()
105+
{
106+
episode( 242 ).title( "Deep Breath" )
107+
.doctor( "Peter Capaldi", "Matt Smith" )
108+
.companion( "Clara Oswald" )
109+
.enemy( "Half-Face Man" )
110+
.fact( engine );
111+
episode( 243 ).title( "Into the Dalek" )
112+
.doctor( "Peter Capaldi" )
113+
.companion( "Clara Oswald" )
114+
.enemy( "Dalek" )
115+
.fact( engine );
116+
episode( 244 ).title( "Robot of Sherwood" )
117+
.doctor( "Peter Capaldi" )
118+
.companion( "Clara Oswald" )
119+
.enemy( "Sheriff of Nottingham" )
120+
.allies( "Robin Hood" )
121+
.fact( engine );
122+
}
123+
103124
private void season34()
104125
{
105126
episode( 232 ).title( "The Bells of Saint John" )

src/test/java/org/neo4j/tutorial/DoctorWhoUniverseGeneratorTest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -422,7 +422,7 @@ else if ( path.length() > 2 )
422422

423423
List<Node> enemiesOfEnemies = asList( nodes );
424424

425-
int numberOfIndividualAndSpeciesEnemiesInTheDatabase = 148;
425+
int numberOfIndividualAndSpeciesEnemiesInTheDatabase = 151;
426426
assertEquals( numberOfIndividualAndSpeciesEnemiesInTheDatabase, enemiesOfEnemies.size() );
427427

428428
assertTrue( isInList( getNodeFromDatabase( SPECIES, "Dalek" ), enemiesOfEnemies ) );
@@ -492,7 +492,7 @@ public void shouldHaveCorrectNumberofIndividualEnemyCharactersInTotal()
492492
{
493493
try ( Transaction tx = database.beginTx() )
494494
{
495-
int numberOfEnemies = 113;
495+
int numberOfEnemies = 116;
496496

497497
Node theDoctor = universe.theDoctor();
498498

0 commit comments

Comments
 (0)