diff --git a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala index cabfdc7..5b0a647 100644 --- a/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala +++ b/src/main/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidate.scala @@ -8,7 +8,7 @@ import eu.neverblink.jelly.cli.util.io.IoUtil import eu.neverblink.jelly.cli.util.jena.* import eu.ostrzyciel.jelly.convert.jena.JenaConverterFactory import eu.ostrzyciel.jelly.core.JellyOptions -import eu.ostrzyciel.jelly.core.proto.v1.RdfStreamFrame +import eu.ostrzyciel.jelly.core.proto.v1.{RdfStreamFrame, RdfStreamOptions} import org.apache.jena.graph.Triple import org.apache.jena.riot.RDFParser import org.apache.jena.riot.system.StreamRDFLib @@ -92,10 +92,10 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]: // Step 1: Validate delimiting validateDelimiting(delimiting, delimited) // Step 2: Validate basic stream structure & the stream options - val framesSeq = skipEmptyFrames(frameIterator.toSeq) - validateOptions(framesSeq) + val framesSeq = frameIterator.toSeq + val streamOptions = validateOptions(skipEmptyFrames(framesSeq)) // Step 3: Validate the content - validateContent(framesSeq, frameIndices, rdfComparison) + validateContent(framesSeq, frameIndices, rdfComparison, streamOptions) private def validateDelimiting( expected: Delimiting, @@ -109,7 +109,7 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]: if delimited then throw CriticalException("Expected undelimited input, but the file was delimited") - private def validateOptions(frames: Seq[RdfStreamFrame]): Unit = + private def validateOptions(frames: Seq[RdfStreamFrame]): RdfStreamOptions = if !frames.head.rows.head.row.isOptions then throw CriticalException("First row in the input stream does not contain stream options") val streamOptions = frames.head.rows.head.row.options @@ -134,17 +134,18 @@ object RdfValidate extends JellyCommand[RdfValidateOptions]: streamOptions, expectedOptions.getOrElse(JellyOptions.defaultSupportedOptions), ) + streamOptions private def validateContent( frames: Seq[RdfStreamFrame], frameIndices: IndexRange, maybeRdfComparison: Option[StreamRdfCollector], + opt: RdfStreamOptions, ): Unit = // Prepare data structures val jellyStreamConsumer = if maybeRdfComparison.isDefined then StreamRdfCollector() else StreamRDFLib.sinkNull() - val opt = frames.head.rows.head.row.options val dec = JenaConverterFactory.anyStatementDecoder( None, (prefix, iri) => jellyStreamConsumer.prefix(prefix, iri.getURI), diff --git a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala index dfa4b16..f253bc1 100644 --- a/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala +++ b/src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala @@ -443,6 +443,36 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper: } } + "content matches the reference RDF file, empty frames in the stream, sliced comparison" in withFullJenaFile { + jenaF => + withEmptyJenaFile { emptyJenaF => + withFullJellyFile { jellyF => + // Three empty frames and the start and end + val input = + Array[Byte](0, 0, 0) ++ FileInputStream(jellyF).readAllBytes() ++ Array[Byte]( + 0, + 0, + 0, + ) + val params = Seq( + (jenaF, "3"), + (emptyJenaF, "0..=2"), + (emptyJenaF, "4..=6"), + ) + for (comparisonFile, frameIndices) <- params do + RdfValidate.setStdIn(ByteArrayInputStream(input)) + RdfValidate.runTestCommand( + List( + "rdf", + "validate", + "--compare-to-rdf-file=" + comparisonFile, + "--compare-frame-indices=" + frameIndices, + ), + ) + } + } + } + "content matches the reference RDF file, using a slice of the stream" in withFullJenaFile { jenaF => withFullJellyFile { jellyF =>