@@ -333,8 +333,7 @@ public String toString() {
333
333
private static Stream <TestCase > findTestCases (String testCase , ExpectedResult baseCase ) {
334
334
String shacl ;
335
335
336
- try (InputStream resourceAsStream = AbstractShaclTest .class .getClassLoader ()
337
- .getResourceAsStream (testCase + "/shacl.trig" )) {
336
+ try (InputStream resourceAsStream = getResourceAsStream (testCase + "/shacl.trig" )) {
338
337
assert Objects .nonNull (resourceAsStream ) : "Could not find: " + testCase + "/shacl.trig" ;
339
338
shacl = IOUtils .toString (resourceAsStream , StandardCharsets .UTF_8 );
340
339
@@ -347,7 +346,7 @@ private static Stream<TestCase> findTestCases(String testCase, ExpectedResult ba
347
346
return Stream .empty ();
348
347
}
349
348
350
- return Arrays .stream (new File (resource .getFile ()).list ())
349
+ return Arrays .stream (Objects . requireNonNull ( new File (resource .getFile ()).list () ))
351
350
.filter (s -> !s .startsWith ("." ))
352
351
.sorted ()
353
352
.map (caseName -> {
@@ -443,8 +442,6 @@ void runTestCase(TestCase testCase, IsolationLevel isolationLevel, boolean prelo
443
442
444
443
}
445
444
446
- Model validationReportActual = new LinkedHashModel ();
447
-
448
445
for (File queryFile : testCase .getQueries ()) {
449
446
try {
450
447
String query = FileUtils .readFileToString (queryFile , StandardCharsets .UTF_8 );
@@ -466,8 +463,6 @@ void runTestCase(TestCase testCase, IsolationLevel isolationLevel, boolean prelo
466
463
467
464
exception = true ;
468
465
logger .debug (sailException .getMessage ());
469
- validationReportActual = ((ShaclSailValidationException ) sailException .getCause ())
470
- .validationReportAsModel ();
471
466
printResults (sailException );
472
467
}
473
468
} catch (IOException e ) {
@@ -506,17 +501,18 @@ private void printTestCase(TestCase testCase) {
506
501
507
502
private static void testValidationReport (String dataPath , Model validationReportActual ) {
508
503
try {
509
- InputStream resourceAsStream = AbstractShaclTest .class .getClassLoader ()
510
- .getResourceAsStream (dataPath + "report.ttl" );
504
+ InputStream resourceAsStream = getResourceAsStream (dataPath + "report.ttl" );
511
505
if (resourceAsStream == null ) {
512
- logger .error (dataPath + "report.ttl did not exist. Creating an empty file!" );
506
+ logger .warn (dataPath + "report.ttl did not exist, attempting to create an empty file!" );
513
507
514
508
String file = Objects .requireNonNull (AbstractShaclTest .class .getClassLoader ()
515
509
.getResource (dataPath ))
516
510
.getFile ()
517
511
.replace ("/target/test-classes/" , "/src/test/resources/" );
518
512
boolean newFile = new File (file + "report.ttl" ).createNewFile ();
519
-
513
+ if (!newFile ) {
514
+ logger .error (dataPath + "report.ttl did not exist and could not create an empty file!" );
515
+ }
520
516
}
521
517
Model validationReportExpected = getModel (resourceAsStream );
522
518
@@ -533,6 +529,10 @@ private static void testValidationReport(String dataPath, Model validationReport
533
529
}
534
530
}
535
531
532
+ private static InputStream getResourceAsStream (String dataPath ) {
533
+ return AbstractShaclTest .class .getClassLoader ().getResourceAsStream (dataPath );
534
+ }
535
+
536
536
private static void writeActualModelToExpectedModelForDevPurposes (String dataPath , Model report )
537
537
throws IOException {
538
538
String file = Objects .requireNonNull (AbstractShaclTest .class .getClassLoader ()
@@ -631,8 +631,7 @@ void referenceImplementationTestCaseValidation(TestCase testCase) {
631
631
org .apache .jena .rdf .model .Model data = JenaUtil .createMemoryModel ();
632
632
633
633
if (testCase .hasInitialData ()) {
634
- try (InputStream resourceAsStream = AbstractShaclTest .class .getClassLoader ()
635
- .getResourceAsStream (testCase .getInitialData ())) {
634
+ try (InputStream resourceAsStream = getResourceAsStream (testCase .getInitialData ())) {
636
635
data .read (resourceAsStream , "" , org .apache .jena .util .FileUtils .langTurtle );
637
636
} catch (IOException e ) {
638
637
throw new IllegalStateException (e );
@@ -668,8 +667,7 @@ void referenceImplementationTestCaseValidation(TestCase testCase) {
668
667
RDFFormat .TRIG );
669
668
670
669
try {
671
- InputStream resourceAsStream = AbstractShaclTest .class .getClassLoader ()
672
- .getResourceAsStream (testCase .getTestCasePath () + "report.ttl" );
670
+ InputStream resourceAsStream = getResourceAsStream (testCase .getTestCasePath () + "report.ttl" );
673
671
674
672
Model validationReportActual = getModel (resourceAsStream );
675
673
@@ -717,8 +715,7 @@ private static Model getModel(InputStream resourceAsStream) throws IOException {
717
715
718
716
private static void checkShapesConformToW3cShaclRecommendation (org .apache .jena .rdf .model .Model shacl ) {
719
717
org .apache .jena .rdf .model .Model w3cShacl = JenaUtil .createMemoryModel ();
720
- try (InputStream resourceAsStream = AbstractShaclTest .class .getClassLoader ()
721
- .getResourceAsStream ("w3cshacl.ttl" )) {
718
+ try (InputStream resourceAsStream = getResourceAsStream ("w3cshacl.ttl" )) {
722
719
w3cShacl .read (resourceAsStream , "" , org .apache .jena .util .FileUtils .langTurtle );
723
720
} catch (IOException e ) {
724
721
throw new IllegalStateException (e );
@@ -870,7 +867,7 @@ private void printFile(String filename) {
870
867
try {
871
868
System .out .println ("### " + filename + " ###" );
872
869
String s = IOUtils .toString (
873
- Objects .requireNonNull (AbstractShaclTest . class . getClassLoader (). getResourceAsStream (filename )),
870
+ Objects .requireNonNull (getResourceAsStream (filename )),
874
871
StandardCharsets .UTF_8 );
875
872
876
873
s = removeLeadingPrefixStatements (s );
@@ -883,29 +880,30 @@ private void printFile(String filename) {
883
880
}
884
881
885
882
private static String removeLeadingPrefixStatements (String s ) {
886
- String [] split = s .split ("\n " );
887
- s = "" ;
883
+ String [] splitByNewLine = s .split ("\n " );
884
+
888
885
boolean skippingPrefixes = true ;
889
886
890
- for (String s1 : split ) {
887
+ StringBuilder stringBuilder = new StringBuilder ();
888
+ for (String line : splitByNewLine ) {
891
889
if (skippingPrefixes ) {
892
- if (!(s1 .trim ().equals ("" ) ||
893
- s1 .trim ().toLowerCase ().startsWith ("@prefix" ) ||
894
- s1 .trim ().toLowerCase ().startsWith ("@base" ) ||
895
- s1 .trim ().toLowerCase ().startsWith ("prefix" ))) {
890
+ if (!(line .trim ().equals ("" ) ||
891
+ line .trim ().toLowerCase ().startsWith ("@prefix" ) ||
892
+ line .trim ().toLowerCase ().startsWith ("@base" ) ||
893
+ line .trim ().toLowerCase ().startsWith ("prefix" ))) {
896
894
skippingPrefixes = false ;
897
895
}
898
896
}
899
897
900
898
if (!skippingPrefixes ) {
901
- s += s1 + "\n " ;
899
+ stringBuilder . append ( line ). append ( "\n " ) ;
902
900
}
903
901
904
902
}
905
- return s ;
903
+ return stringBuilder . toString () ;
906
904
}
907
905
908
- void runTestCaseSingleTransaction (TestCase testCase , IsolationLevel isolationLevel ) {
906
+ void runTestCaseSingleTransaction (TestCase testCase ) {
909
907
910
908
SailRepository shaclRepository = getShaclSail (testCase , true );
911
909
@@ -915,7 +913,7 @@ void runTestCaseSingleTransaction(TestCase testCase, IsolationLevel isolationLev
915
913
Model validationReportActual = new LinkedHashModel ();
916
914
917
915
try (SailRepositoryConnection shaclSailConnection = shaclRepository .getConnection ()) {
918
- shaclSailConnection .begin (isolationLevel );
916
+ shaclSailConnection .begin (IsolationLevels . NONE );
919
917
920
918
for (File queryFile : testCase .getQueries ()) {
921
919
try {
@@ -1028,7 +1026,6 @@ void runParsingTest(TestCase testCase) {
1028
1026
.getDataAndRelease ();
1029
1027
1030
1028
Model actual = new DynamicModelFactory ().createEmptyModel ();
1031
- HashSet <Resource > dedupe = new HashSet <>();
1032
1029
shapes .forEach (shape -> shape .toModel (actual ));
1033
1030
1034
1031
Model expected = new LinkedHashModel (testCase .getShacl ());
@@ -1093,8 +1090,8 @@ private void printResults(ValidationReport report) {
1093
1090
}
1094
1091
1095
1092
private void printResults (RepositoryException sailException ) {
1096
- ValidationReport validationReport = (( ShaclSailValidationException ) sailException .getCause ())
1097
- .getValidationReport ();
1093
+ var shaclSailValidationException = (ShaclSailValidationException ) sailException .getCause ();
1094
+ ValidationReport validationReport = shaclSailValidationException .getValidationReport ();
1098
1095
printResults (validationReport );
1099
1096
}
1100
1097
@@ -1159,27 +1156,6 @@ void runWithAutomaticLogging(Runnable r) {
1159
1156
}
1160
1157
}
1161
1158
1162
- /**
1163
- * Sort and output testCasePaths
1164
- *
1165
- * @param args
1166
- */
1167
- public static void main (String [] args ) {
1168
-
1169
- System .out .println ("\n \t private static final List<String> testCasePaths = Stream.of(" );
1170
- String testCasesString = testCasePaths
1171
- .stream ()
1172
- .map (a -> "\t \t \" " + a + "\" " )
1173
- .reduce ((a , b ) -> a + ",\n " + b )
1174
- .orElse ("" );
1175
-
1176
- System .out .println (testCasesString );
1177
- System .out .println ("\t )\n " +
1178
- "\t \t .distinct()\n " +
1179
- "\t \t .sorted()\n " +
1180
- "\t \t .collect(Collectors.toList());" );
1181
- }
1182
-
1183
1159
enum ExpectedResult {
1184
1160
valid ,
1185
1161
invalid
0 commit comments