Skip to content
This repository was archived by the owner on Oct 8, 2020. It is now read-only.

Commit 89394b0

Browse files
log output of test base class
1 parent 2e84e5b commit 89394b0

1 file changed

Lines changed: 21 additions & 7 deletions

File tree

sansa-inference-tests/src/test/scala/net/sansa_stack/test/conformance/ConformanceTestBase.scala

Lines changed: 21 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,10 @@
11
package net.sansa_stack.test.conformance
22

3+
import java.io.ByteArrayOutputStream
4+
35
import scala.collection.mutable
46

7+
import com.typesafe.scalalogging.LazyLogging
58
import org.apache.jena.rdf.model.Model
69
import org.apache.jena.shared.PrefixMapping
710
import 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

Comments
 (0)