Skip to content

Commit 78c6a85

Browse files
Additional scenario compiler test
1 parent 65ccec5 commit 78c6a85

File tree

1 file changed

+43
-0
lines changed

1 file changed

+43
-0
lines changed

scenario-compiler/src/test/scala/pl/touk/nussknacker/engine/compile/ProcessValidatorSpec.scala

+43
Original file line numberDiff line numberDiff line change
@@ -51,6 +51,10 @@ class ProcessValidatorSpec extends AnyFunSuite with Matchers with Inside with Op
5151
private val baseDefinitionBuilder = ModelDefinitionBuilder.empty
5252
.withGlobalVariable("processHelper", ProcessHelper)
5353
.withService("sampleEnricher", Some(Typed[SimpleRecord]))
54+
.withService(
55+
"sampleEnricherWithPlainRecord",
56+
Some(Typed.record(List("someString" -> Typed[String], "someInt" -> Typed[Integer])))
57+
)
5458
.withService("withParamsService", Some(Typed[SimpleRecord]), Parameter[String](ParameterName("par1")))
5559
.withUnboundedStreamSource("source", Some(Typed[SimpleRecord]))
5660
.withUnboundedStreamSource("sourceWithUnknown", Some(Unknown))
@@ -956,6 +960,45 @@ class ProcessValidatorSpec extends AnyFunSuite with Matchers with Inside with Op
956960
}
957961
}
958962

963+
test("should allow mock expression matching enricher return type") {
964+
val process = ScenarioBuilder
965+
.streaming("process1")
966+
.source("id1", "typed-source")
967+
.enricherWithMockExpression(
968+
"enricher1",
969+
"out",
970+
"sampleEnricherWithPlainRecord",
971+
"""{someString: "abc", someInt: 1234}""".spel
972+
)
973+
.emptySink("id2", "sink")
974+
975+
inside(validate(process, definitionWithTypedSource).result) { case Valid(_) =>
976+
}
977+
}
978+
979+
test("should not allow mock expression not matching enricher return type") {
980+
val process = ScenarioBuilder
981+
.streaming("process1")
982+
.source("id1", "typed-source")
983+
.enricherWithMockExpression("enricher1", "out", "sampleEnricherWithPlainRecord", """{someString: "abc"}""".spel)
984+
.emptySink("id2", "sink")
985+
986+
inside(validate(process, definitionWithTypedSource).result) {
987+
case Invalid(
988+
NonEmptyList(
989+
ExpressionParserCompilationError(
990+
"Bad expression type, expected: Record{someInt: Integer, someString: String}, found: Record{someString: String(abc)}",
991+
"enricher1",
992+
Some(ParameterName("mockExpression")),
993+
_,
994+
None
995+
),
996+
Nil
997+
)
998+
) =>
999+
}
1000+
}
1001+
9591002
test("find usage of fields that does not exist in option object") {
9601003
val process = ScenarioBuilder
9611004
.streaming("process1")

0 commit comments

Comments
 (0)