Skip to content

Commit a345506

Browse files
committed
fixed hardcoded node ids in unit tests
1 parent e068f2c commit a345506

File tree

1 file changed

+26
-63
lines changed

1 file changed

+26
-63
lines changed

src/test/java/n10s/RDFExportTest.java

Lines changed: 26 additions & 63 deletions
Original file line numberDiff line numberDiff line change
@@ -557,10 +557,10 @@ private void allTriplePatternsOnLPG() throws IOException {
557557
getNTriplesGraphFromSPOPattern(session,"http://base/about#nonexistingresource",DEFAULT_BASE_SCH_NS + "name", "MS", true, "http://www.w3.org/2001/XMLSchema#string", null), RDFFormat.NTRIPLES));
558558

559559
expected = "{\n" +
560-
" \"@id\" : \"n4ind:8\",\n" +
560+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
561561
" \"@type\" : \"n4sch:Person\",\n" +
562562
" \"n4sch:ACTED_IN\" : {\n" +
563-
" \"@id\" : \"n4ind:0\"\n" +
563+
" \"@id\" : \"n4ind:" + theMatrixId + "\"\n" +
564564
" },\n" +
565565
" \"n4sch:born\" : {\n" +
566566
" \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" +
@@ -578,7 +578,7 @@ private void allTriplePatternsOnLPG() throws IOException {
578578
getNTriplesGraphFromSPOPattern(session,BASE_INDIV_NS + emilId,null, null, false, null, null), RDFFormat.NTRIPLES));
579579

580580
expected = "{\n" +
581-
" \"@id\" : \"n4ind:8\",\n" +
581+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
582582
" \"n4sch:name\" : \"Emil Eifrem\",\n" +
583583
" \"@context\" : {\n" +
584584
" \"n4sch\" : \"neo4j://graph.schema#\",\n" +
@@ -592,7 +592,7 @@ private void allTriplePatternsOnLPG() throws IOException {
592592

593593

594594
expected = "{\n" +
595-
" \"@id\" : \"n4ind:8\",\n" +
595+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
596596
" \"@type\" : \"n4sch:Person\",\n" +
597597
" \"@context\" : {\n" +
598598
" \"n4sch\" : \"neo4j://graph.schema#\",\n" +
@@ -607,7 +607,7 @@ private void allTriplePatternsOnLPG() throws IOException {
607607

608608

609609
expected = "{\n" +
610-
" \"@id\" : \"n4ind:8\",\n" +
610+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
611611
" \"n4sch:name\" : \"Emil Eifrem\",\n" +
612612
" \"@context\" : {\n" +
613613
" \"n4sch\" : \"neo4j://graph.schema#\",\n" +
@@ -620,7 +620,7 @@ private void allTriplePatternsOnLPG() throws IOException {
620620
getNTriplesGraphFromSPOPattern(session,BASE_INDIV_NS + emilId,DEFAULT_BASE_SCH_NS + "name", "Emil Eifrem", true, "http://www.w3.org/2001/XMLSchema#string", null), RDFFormat.NTRIPLES));
621621

622622
expected = "{\n" +
623-
" \"@id\" : \"n4ind:8\",\n" +
623+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
624624
" \"n4sch:born\" : {\n" +
625625
" \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" +
626626
" \"@value\" : \"1978\"\n" +
@@ -645,7 +645,7 @@ private void allTriplePatternsOnLPG() throws IOException {
645645

646646

647647
expected = "{\n" +
648-
" \"@id\" : \"n4ind:8\",\n" +
648+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
649649
" \"@type\" : \"n4sch:Person\",\n" +
650650
" \"@context\" : {\n" +
651651
" \"n4sch\" : \"neo4j://graph.schema#\",\n" +
@@ -683,55 +683,20 @@ private void allTriplePatternsOnLPG() throws IOException {
683683
.compareModels("{}", RDFFormat.JSONLD,
684684
getNTriplesGraphFromSPOPattern(session,null,"http://undefinedvoc.org/name", null, false, null, null), RDFFormat.NTRIPLES));
685685

686+
StringBuilder titleTriplesSb = new StringBuilder();
687+
Result titlesQueryResult = session.run("MATCH (n:Movie) RETURN id(n) as id, n.title as title ");
688+
while(titlesQueryResult.hasNext()){
689+
Record movie = titlesQueryResult.next();
690+
titleTriplesSb.append("<neo4j://graph.individuals#").append(movie.get("id").asLong()).append("> <neo4j://graph.schema#title> \"")
691+
.append(movie.get("title").asString()).append("\" .\n");
692+
}
686693

687-
// if we hardcode the ids here what's the point of getting them at the beginning for Emil, Renier and The Matrix?
688-
//TODO: do this right
689-
String titleTriples = "<neo4j://graph.individuals#0> <neo4j://graph.schema#title> \"The Matrix\" .\n" +
690-
"<neo4j://graph.individuals#9> <neo4j://graph.schema#title> \"The Matrix Reloaded\" .\n" +
691-
"<neo4j://graph.individuals#10> <neo4j://graph.schema#title> \"The Matrix Revolutions\" .\n" +
692-
"<neo4j://graph.individuals#11> <neo4j://graph.schema#title> \"The Devil's Advocate\" .\n" +
693-
"<neo4j://graph.individuals#15> <neo4j://graph.schema#title> \"A Few Good Men\" .\n" +
694-
"<neo4j://graph.individuals#29> <neo4j://graph.schema#title> \"Top Gun\" .\n" +
695-
"<neo4j://graph.individuals#37> <neo4j://graph.schema#title> \"Jerry Maguire\" .\n" +
696-
"<neo4j://graph.individuals#46> <neo4j://graph.schema#title> \"Stand By Me\" .\n" +
697-
"<neo4j://graph.individuals#52> <neo4j://graph.schema#title> \"As Good as It Gets\" .\n" +
698-
"<neo4j://graph.individuals#56> <neo4j://graph.schema#title> \"What Dreams May Come\" .\n" +
699-
"<neo4j://graph.individuals#62> <neo4j://graph.schema#title> \"Snow Falling on Cedars\" .\n" +
700-
"<neo4j://graph.individuals#67> <neo4j://graph.schema#title> \"You've Got Mail\" .\n" +
701-
"<neo4j://graph.individuals#73> <neo4j://graph.schema#title> \"Sleepless in Seattle\" .\n" +
702-
"<neo4j://graph.individuals#78> <neo4j://graph.schema#title> \"Joe Versus the Volcano\" .\n" +
703-
"<neo4j://graph.individuals#81> <neo4j://graph.schema#title> \"When Harry Met Sally\" .\n" +
704-
"<neo4j://graph.individuals#85> <neo4j://graph.schema#title> \"That Thing You Do\" .\n" +
705-
"<neo4j://graph.individuals#87> <neo4j://graph.schema#title> \"The Replacements\" .\n" +
706-
"<neo4j://graph.individuals#92> <neo4j://graph.schema#title> \"RescueDawn\" .\n" +
707-
"<neo4j://graph.individuals#95> <neo4j://graph.schema#title> \"The Birdcage\" .\n" +
708-
"<neo4j://graph.individuals#97> <neo4j://graph.schema#title> \"Unforgiven\" .\n" +
709-
"<neo4j://graph.individuals#100> <neo4j://graph.schema#title> \"Johnny Mnemonic\" .\n" +
710-
"<neo4j://graph.individuals#105> <neo4j://graph.schema#title> \"Cloud Atlas\" .\n" +
711-
"<neo4j://graph.individuals#111> <neo4j://graph.schema#title> \"The Da Vinci Code\" .\n" +
712-
"<neo4j://graph.individuals#116> <neo4j://graph.schema#title> \"V for Vendetta\" .\n" +
713-
"<neo4j://graph.individuals#121> <neo4j://graph.schema#title> \"Speed Racer\" .\n" +
714-
"<neo4j://graph.individuals#128> <neo4j://graph.schema#title> \"Ninja Assassin\" .\n" +
715-
"<neo4j://graph.individuals#130> <neo4j://graph.schema#title> \"The Green Mile\" .\n" +
716-
"<neo4j://graph.individuals#137> <neo4j://graph.schema#title> \"Frost/Nixon\" .\n" +
717-
"<neo4j://graph.individuals#141> <neo4j://graph.schema#title> \"Hoffa\" .\n" +
718-
"<neo4j://graph.individuals#144> <neo4j://graph.schema#title> \"Apollo 13\" .\n" +
719-
"<neo4j://graph.individuals#147> <neo4j://graph.schema#title> \"Twister\" .\n" +
720-
"<neo4j://graph.individuals#150> <neo4j://graph.schema#title> \"Cast Away\" .\n" +
721-
"<neo4j://graph.individuals#152> <neo4j://graph.schema#title> \"One Flew Over the Cuckoo's Nest\" .\n" +
722-
"<neo4j://graph.individuals#154> <neo4j://graph.schema#title> \"Something's Gotta Give\" .\n" +
723-
"<neo4j://graph.individuals#157> <neo4j://graph.schema#title> \"Bicentennial Man\" .\n" +
724-
"<neo4j://graph.individuals#159> <neo4j://graph.schema#title> \"Charlie Wilson's War\" .\n" +
725-
"<neo4j://graph.individuals#161> <neo4j://graph.schema#title> \"The Polar Express\" .\n" +
726-
"<neo4j://graph.individuals#162> <neo4j://graph.schema#title> \"A League of Their Own\" .";
727-
728-
729-
assertTrue(ModelTestUtils
730-
.compareModels(titleTriples, RDFFormat.NTRIPLES,
694+
assertTrue(ModelTestUtils
695+
.compareModels(titleTriplesSb.toString(), RDFFormat.NTRIPLES,
731696
getNTriplesGraphFromSPOPattern(session,null,DEFAULT_BASE_SCH_NS + "title", null, false, null, null), RDFFormat.NTRIPLES));
732697

733698
expected = "{\n" +
734-
" \"@id\" : \"n4ind:8\",\n" +
699+
" \"@id\" : \"n4ind:" + emilId + "\",\n" +
735700
" \"n4sch:born\" : {\n" +
736701
" \"@type\" : \"http://www.w3.org/2001/XMLSchema#long\",\n" +
737702
" \"@value\" : \"1978\"\n" +
@@ -769,19 +734,17 @@ private void allTriplePatternsOnLPG() throws IOException {
769734
{ criticTypesTriples.append("<" + BASE_INDIV_NS + id + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + DEFAULT_BASE_SCH_NS + "Critic> .\n");
770735
criticTypesTriples.append("<" + BASE_INDIV_NS + id + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + DEFAULT_BASE_SCH_NS + "Person> .\n");} );
771736

772-
String someMovies = "<neo4j://graph.individuals#0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
773-
"<neo4j://graph.individuals#9> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
774-
"<neo4j://graph.individuals#10> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
775-
"<neo4j://graph.individuals#11> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
776-
"<neo4j://graph.individuals#15> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
777-
"<neo4j://graph.individuals#29> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
778-
"<neo4j://graph.individuals#37> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
779-
"<neo4j://graph.individuals#46> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" +
780-
"<neo4j://graph.individuals#52> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n" ;
737+
StringBuilder someMoviesSb = new StringBuilder();
738+
Result someMoviesQueryResult = session.run("MATCH (n:Movie) RETURN id(n) as id skip 30 limit 10");
739+
while(someMoviesQueryResult.hasNext()){
740+
Record movie = someMoviesQueryResult.next();
741+
someMoviesSb.append("<neo4j://graph.individuals#").append(movie.get("id").asLong())
742+
.append("> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#Movie> .\n");
743+
}
781744

782745
assertTrue(ModelTestUtils
783746
.modelContains(getNTriplesGraphFromSPOPattern(session,null,"http://www.w3.org/1999/02/22-rdf-syntax-ns#type", null, false, null, null), RDFFormat.NTRIPLES,
784-
criticTypesTriples.toString() + someMovies, RDFFormat.NTRIPLES));
747+
criticTypesTriples.toString() + someMoviesSb.toString(), RDFFormat.NTRIPLES));
785748

786749
StringBuilder criticTypesTriples2 = new StringBuilder();
787750
critics.forEach(id-> criticTypesTriples2.append("<" + BASE_INDIV_NS + id + "> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <" + DEFAULT_BASE_SCH_NS + "Critic> .\n") );
@@ -792,7 +755,7 @@ private void allTriplePatternsOnLPG() throws IOException {
792755

793756
String allGraphAsNTriples = getNTriplesGraphFromSPOPattern(session, null, null, null, false, null, null);
794757
assertTrue(ModelTestUtils.modelContains(allGraphAsNTriples, RDFFormat.NTRIPLES,
795-
criticTypesTriples.toString() + someMovies + titleTriples, RDFFormat.NTRIPLES ));
758+
criticTypesTriples.toString() + someMoviesSb.toString() + titleTriplesSb.toString(), RDFFormat.NTRIPLES ));
796759

797760
assertFalse(ModelTestUtils.modelContains(allGraphAsNTriples, RDFFormat.NTRIPLES,
798761
"<neo4j://graph.individuals#0> <http://www.w3.org/1999/02/22-rdf-syntax-ns#type> <neo4j://graph.schema#AwesomeMovie> ." , RDFFormat.NTRIPLES ));

0 commit comments

Comments
 (0)