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

Commit

Permalink
log output of test base class
Browse files Browse the repository at this point in the history
  • Loading branch information
LorenzBuehmann committed Jun 27, 2019
1 parent 2e84e5b commit 89394b0
Showing 1 changed file with 21 additions and 7 deletions.
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package net.sansa_stack.test.conformance

import java.io.ByteArrayOutputStream

import scala.collection.mutable

import com.typesafe.scalalogging.LazyLogging
import org.apache.jena.rdf.model.Model
import org.apache.jena.shared.PrefixMapping
import org.junit.runner.RunWith
Expand All @@ -17,9 +20,10 @@ import net.sansa_stack.inference.data.{RDF, RDFOps}
*
*/
@RunWith(classOf[JUnitRunner])
abstract class ConformanceTestBase[Rdf <: RDF](val rdfOps: RDFOps[Rdf]) extends FlatSpec with BeforeAndAfterAll {

val logger = com.typesafe.scalalogging.Logger("ConformanceTestBase")
abstract class ConformanceTestBase[Rdf <: RDF](val rdfOps: RDFOps[Rdf])
extends FlatSpec
with BeforeAndAfterAll
with LazyLogging {

behavior of ""

Expand Down Expand Up @@ -86,20 +90,30 @@ abstract class ConformanceTestBase[Rdf <: RDF](val rdfOps: RDFOps[Rdf]) extends
// compare models, i.e. the inferred model should contain exactly the triples of the conclusion graph
val correctOutput = inferredModel.containsAll(testCase.outputGraph)
if(!correctOutput) {
println("Missing triples in inferred graph:")
testCase.outputGraph.difference(inferredModel).write(System.out, "TURTLE")
logger.whenErrorEnabled {
logger.error("Missing triples in inferred graph:\n {}", toNTriplesString(testCase.outputGraph.difference(inferredModel)))
}
}
assert(correctOutput, "contains all expected triples")


val isomorph = inferredModel.isIsomorphicWith(testCase.outputGraph)
if(!isomorph) {
println("inferred graph:")
inferredModel.write(System.out, "TURTLE")
logger.whenErrorEnabled {
logger.error(s"Inferred graph not isomorph to target graph. Inferred triples:\n{}", toNTriplesString(inferredModel))
}

}
assert(isomorph, "input and output are isomorph")
}
}

private def toNTriplesString(model: Model): String = {
val baos = new ByteArrayOutputStream()
model.write(baos, "N-Triples")
val s = new String(baos.toByteArray)
s
}

def computeInferredModel(triples: mutable.HashSet[Rdf#Triple]): Model
}

0 comments on commit 89394b0

Please sign in to comment.