Skip to content

Commit 75470a0

Browse files
committed
test fix
1 parent 49f60f5 commit 75470a0

File tree

3 files changed

+112
-91
lines changed

3 files changed

+112
-91
lines changed

src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfFromJellySpec.scala

Lines changed: 43 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -430,53 +430,60 @@ class RdfFromJellySpec extends AnyWordSpec with Matchers with TestFixtureHelper:
430430
val frameBytes = frame.toByteArray
431431

432432
"term validation disabled (default)" in {
433-
JenaSystemOptions.resetTermValidation()
434-
JenaParameters.enableEagerLiteralValidation = true
435-
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
436-
val (out, err) = RdfFromJelly.runTestCommand(
437-
List("rdf", "from-jelly", "--out-format", RdfFormat.NQuads.cliOptions.head),
438-
)
439-
out.length should be > 0
440-
out should include("<notgood://malformed")
441-
err.isEmpty shouldBe true
433+
// Run in synchronized block to avoid interference with other tests
434+
JenaSystemOptions.synchronized {
435+
JenaSystemOptions.resetTermValidation()
436+
JenaParameters.enableEagerLiteralValidation = true
437+
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
438+
val (out, err) = RdfFromJelly.runTestCommand(
439+
List("rdf", "from-jelly", "--out-format", RdfFormat.NQuads.cliOptions.head),
440+
)
441+
out.length should be > 0
442+
out should include("<notgood://malformed")
443+
err.isEmpty shouldBe true
444+
}
442445
}
443446

444447
"term validation disabled (explicit)" in {
445-
JenaSystemOptions.resetTermValidation()
446-
JenaParameters.enableEagerLiteralValidation = true
447-
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
448-
val (out, err) = RdfFromJelly.runTestCommand(
449-
List(
450-
"rdf",
451-
"from-jelly",
452-
"--out-format",
453-
RdfFormat.NQuads.cliOptions.head,
454-
"--validate-terms=false",
455-
),
456-
)
457-
out.length should be > 0
458-
out should include("<notgood://malformed")
459-
err.isEmpty shouldBe true
460-
}
461-
462-
"term validation enabled" in {
463-
JenaSystemOptions.resetTermValidation()
464-
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
465-
JenaParameters.enableEagerLiteralValidation = true
466-
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
467-
val ex = intercept[ExitException] {
468-
RdfFromJelly.runTestCommand(
448+
JenaSystemOptions.synchronized {
449+
JenaSystemOptions.resetTermValidation()
450+
JenaParameters.enableEagerLiteralValidation = true
451+
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
452+
val (out, err) = RdfFromJelly.runTestCommand(
469453
List(
470454
"rdf",
471455
"from-jelly",
472456
"--out-format",
473457
RdfFormat.NQuads.cliOptions.head,
474-
"--validate-terms=true",
458+
"--validate-terms=false",
475459
),
476460
)
461+
out.length should be > 0
462+
out should include("<notgood://malformed")
463+
err.isEmpty shouldBe true
464+
}
465+
}
466+
467+
"term validation enabled" in {
468+
JenaSystemOptions.synchronized {
469+
JenaSystemOptions.resetTermValidation()
470+
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
471+
JenaParameters.enableEagerLiteralValidation = true
472+
RdfFromJelly.setStdIn(ByteArrayInputStream(frameBytes))
473+
val ex = intercept[ExitException] {
474+
RdfFromJelly.runTestCommand(
475+
List(
476+
"rdf",
477+
"from-jelly",
478+
"--out-format",
479+
RdfFormat.NQuads.cliOptions.head,
480+
"--validate-terms=true",
481+
),
482+
)
483+
}
484+
ex.cause.get shouldBe a[JellyDeserializationError]
485+
ex.cause.get.getMessage should include("datatype")
477486
}
478-
ex.cause.get shouldBe a[JellyDeserializationError]
479-
ex.cause.get.getMessage should include("datatype")
480487
}
481488
}
482489
}

src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfToJellySpec.scala

Lines changed: 39 additions & 32 deletions
Original file line numberDiff line numberDiff line change
@@ -891,45 +891,52 @@ class RdfToJellySpec extends AnyWordSpec with TestFixtureHelper with Matchers:
891891
.getBytes
892892

893893
"term validation disabled (default)" in {
894-
JenaSystemOptions.resetTermValidation()
895-
JenaParameters.enableEagerLiteralValidation = true
896-
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
897-
val (out, err) = RdfToJelly.runTestCommand(
898-
List("rdf", "to-jelly", "--in-format=nt"),
899-
)
900-
val newIn = new ByteArrayInputStream(RdfToJelly.getOutBytes)
901-
val frame = readJellyFile(newIn)
902-
frame.size should be(1)
903-
frame.head.getRows.size() should be > 3
904-
err shouldBe empty
894+
// Run in synchronized block to avoid interference with other tests
895+
JenaSystemOptions.synchronized {
896+
JenaSystemOptions.resetTermValidation()
897+
JenaParameters.enableEagerLiteralValidation = true
898+
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
899+
val (out, err) = RdfToJelly.runTestCommand(
900+
List("rdf", "to-jelly", "--in-format=nt"),
901+
)
902+
val newIn = new ByteArrayInputStream(RdfToJelly.getOutBytes)
903+
val frame = readJellyFile(newIn)
904+
frame.size should be(1)
905+
frame.head.getRows.size() should be > 3
906+
err shouldBe empty
907+
}
905908
}
906909

907910
"term validation disabled (explicit)" in {
908-
JenaSystemOptions.resetTermValidation()
909-
JenaParameters.enableEagerLiteralValidation = true
910-
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
911-
val (out, err) = RdfToJelly.runTestCommand(
912-
List("rdf", "to-jelly", "--in-format=nt", "--validate-terms=false"),
913-
)
914-
val newIn = new ByteArrayInputStream(RdfToJelly.getOutBytes)
915-
val frame = readJellyFile(newIn)
916-
frame.size should be(1)
917-
frame.head.getRows.size() should be > 3
918-
err shouldBe empty
911+
JenaSystemOptions.synchronized {
912+
JenaSystemOptions.resetTermValidation()
913+
JenaParameters.enableEagerLiteralValidation = true
914+
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
915+
val (out, err) = RdfToJelly.runTestCommand(
916+
List("rdf", "to-jelly", "--in-format=nt", "--validate-terms=false"),
917+
)
918+
val newIn = new ByteArrayInputStream(RdfToJelly.getOutBytes)
919+
val frame = readJellyFile(newIn)
920+
frame.size should be(1)
921+
frame.head.getRows.size() should be > 3
922+
err shouldBe empty
923+
}
919924
}
920925

921926
"term validation enabled (explicit)" in {
922-
JenaSystemOptions.resetTermValidation()
923-
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
924-
JenaParameters.enableEagerLiteralValidation = true
925-
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
926-
val e = intercept[ExitException] {
927-
RdfToJelly.runTestCommand(
928-
List("rdf", "to-jelly", "--in-format=nt", "--validate-terms=true"),
929-
)
927+
JenaSystemOptions.synchronized {
928+
JenaSystemOptions.resetTermValidation()
929+
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
930+
JenaParameters.enableEagerLiteralValidation = true
931+
RdfToJelly.setStdIn(new ByteArrayInputStream(input))
932+
val e = intercept[ExitException] {
933+
RdfToJelly.runTestCommand(
934+
List("rdf", "to-jelly", "--in-format=nt", "--validate-terms=true"),
935+
)
936+
}
937+
e.code should be(1)
938+
e.cause.get shouldBe a[DatatypeFormatException]
930939
}
931-
e.code should be(1)
932-
e.cause.get shouldBe a[DatatypeFormatException]
933940
}
934941
}
935942
}

src/test/scala/eu/neverblink/jelly/cli/command/rdf/RdfValidateSpec.scala

Lines changed: 30 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -752,37 +752,44 @@ class RdfValidateSpec extends AnyWordSpec, Matchers, TestFixtureHelper:
752752
val frameBytes = frame.toByteArray
753753

754754
"term validation enabled (default)" in {
755-
JenaSystemOptions.resetTermValidation()
756-
JenaParameters.enableEagerLiteralValidation = true
757-
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
758-
val e = intercept[ExitException] {
759-
RdfValidate.runTestCommand(List("rdf", "validate"))
755+
// Run in synchronized block to avoid interference with other tests
756+
JenaSystemOptions.synchronized {
757+
JenaSystemOptions.resetTermValidation()
758+
JenaParameters.enableEagerLiteralValidation = true
759+
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
760+
val e = intercept[ExitException] {
761+
RdfValidate.runTestCommand(List("rdf", "validate"))
762+
}
763+
e.cause.get shouldBe a[RdfProtoDeserializationError]
764+
e.cause.get.getMessage should include("datatype")
760765
}
761-
e.cause.get shouldBe a[RdfProtoDeserializationError]
762-
e.cause.get.getMessage should include("datatype")
763766
}
764767

765768
"term validation enabled (explicit)" in {
766-
JenaSystemOptions.resetTermValidation()
767-
JenaParameters.enableEagerLiteralValidation = true
768-
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
769-
val e = intercept[ExitException] {
770-
RdfValidate.runTestCommand(List("rdf", "validate", "--validate-terms=true"))
769+
JenaSystemOptions.synchronized {
770+
JenaSystemOptions.resetTermValidation()
771+
JenaParameters.enableEagerLiteralValidation = true
772+
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
773+
val e = intercept[ExitException] {
774+
RdfValidate.runTestCommand(List("rdf", "validate", "--validate-terms=true"))
775+
}
776+
e.cause.get shouldBe a[RdfProtoDeserializationError]
777+
e.cause.get.getMessage should include("datatype")
771778
}
772-
e.cause.get shouldBe a[RdfProtoDeserializationError]
773-
e.cause.get.getMessage should include("datatype")
774779
}
775780

776781
"term validation disabled" in {
777-
JenaSystemOptions.resetTermValidation()
778-
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
779-
JenaParameters.enableEagerLiteralValidation = true
780-
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
781-
val (out, err) = RdfValidate.runTestCommand(
782-
List("rdf", "validate", "--validate-terms=false"),
783-
)
784-
out shouldBe empty
785-
err shouldBe empty
782+
JenaSystemOptions.synchronized {
783+
JenaSystemOptions.resetTermValidation()
784+
// This is normally not set. We use it to make sure the invalid date literal is actually detected.
785+
JenaParameters.enableEagerLiteralValidation = true
786+
RdfValidate.setStdIn(ByteArrayInputStream(frameBytes))
787+
val (out, err) = RdfValidate.runTestCommand(
788+
List("rdf", "validate", "--validate-terms=false"),
789+
)
790+
out shouldBe empty
791+
err shouldBe empty
792+
}
786793
}
787794
}
788795
}

0 commit comments

Comments
 (0)