11package net .sansa_stack .test .conformance
22
3+ import java .io .ByteArrayOutputStream
4+
35import scala .collection .mutable
46
7+ import com .typesafe .scalalogging .LazyLogging
58import org .apache .jena .rdf .model .Model
69import org .apache .jena .shared .PrefixMapping
710import org .junit .runner .RunWith
@@ -17,9 +20,10 @@ import net.sansa_stack.inference.data.{RDF, RDFOps}
1720 *
1821 */
1922@ RunWith (classOf [JUnitRunner ])
20- abstract class ConformanceTestBase [Rdf <: RDF ](val rdfOps : RDFOps [Rdf ]) extends FlatSpec with BeforeAndAfterAll {
21-
22- val logger = com.typesafe.scalalogging.Logger (" ConformanceTestBase" )
23+ abstract class ConformanceTestBase [Rdf <: RDF ](val rdfOps : RDFOps [Rdf ])
24+ extends FlatSpec
25+ with BeforeAndAfterAll
26+ with LazyLogging {
2327
2428 behavior of " "
2529
@@ -86,20 +90,30 @@ abstract class ConformanceTestBase[Rdf <: RDF](val rdfOps: RDFOps[Rdf]) extends
8690 // compare models, i.e. the inferred model should contain exactly the triples of the conclusion graph
8791 val correctOutput = inferredModel.containsAll(testCase.outputGraph)
8892 if (! correctOutput) {
89- println(" Missing triples in inferred graph:" )
90- testCase.outputGraph.difference(inferredModel).write(System .out, " TURTLE" )
93+ logger.whenErrorEnabled {
94+ logger.error(" Missing triples in inferred graph:\n {}" , toNTriplesString(testCase.outputGraph.difference(inferredModel)))
95+ }
9196 }
9297 assert(correctOutput, " contains all expected triples" )
9398
9499
95100 val isomorph = inferredModel.isIsomorphicWith(testCase.outputGraph)
96101 if (! isomorph) {
97- println(" inferred graph:" )
98- inferredModel.write(System .out, " TURTLE" )
102+ logger.whenErrorEnabled {
103+ logger.error(s " Inferred graph not isomorph to target graph. Inferred triples: \n {} " , toNTriplesString(inferredModel))
104+ }
105+
99106 }
100107 assert(isomorph, " input and output are isomorph" )
101108 }
102109 }
103110
111+ private def toNTriplesString (model : Model ): String = {
112+ val baos = new ByteArrayOutputStream ()
113+ model.write(baos, " N-Triples" )
114+ val s = new String (baos.toByteArray)
115+ s
116+ }
117+
104118 def computeInferredModel (triples : mutable.HashSet [Rdf # Triple ]): Model
105119}
0 commit comments