diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherBodyTest.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherBodyTest.scala deleted file mode 100644 index 9fb7544e926..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherBodyTest.scala +++ /dev/null @@ -1,248 +0,0 @@ -package pl.touk.nussknacker.http - -import com.github.tomakehurst.wiremock.client.WireMock._ -import pl.touk.nussknacker.engine.build.ScenarioBuilder -import pl.touk.nussknacker.engine.graph.expression.Expression -import pl.touk.nussknacker.engine.spel.SpelExtension.SpelExpresion -import pl.touk.nussknacker.engine.util.test.TestScenarioRunner -import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage.convertValidatedToValuable - -class HttpEnricherBodyTest extends HttpEnricherTestSuite { - - import org.scalatest.prop.TableDrivenPropertyChecks._ - - test("returns response body as value based on content type header with fallback to passing it a string") { - forAll( - Table( - ("contentType", "body", "expectedBodyRuntimeValue"), - ("application/json", """ "string" """, "string"), - ("application/json", "true", true), - ( - "application/json", - TestData.recordWithAllTypesNestedAsJson, - TestData.recordWithAllTypesNestedAsComparableAsNuRuntimeValue - ), - ("text/plain", "string", "string"), - ("text/plain", "string", "string"), - ("text/html", "value", "value"), - ) - ) { case (contentType, body, expected) => - wireMock.stubFor( - get(urlEqualTo("/body-test")).willReturn( - aResponse() - .withHeader("Content-Type", contentType) - .withBody(body) - ) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http-node-id", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl()}/body-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Body Type" -> "'None'".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.body".spel) - - val result = runner - .runWithData[String, AnyRef](scenario, List("irrelevantInput")) - .validValue - .successes - .head - deepToScala(result) shouldBe expected - } - } - - test("makes request without body") { - wireMock.stubFor( - post(urlEqualTo("/body-test")) - .withRequestBody(absent()) - .willReturn(aResponse()) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl()}/body-test'".spel, - "HTTP Method" -> "'POST'".spel, - "Body Type" -> "'None'".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevantInput")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("makes request with plain text body") { - wireMock.stubFor( - post(urlEqualTo("/body-test")) - .withRequestBody(equalTo("Plain text body")) - .withHeader("Content-Type", equalTo("text/plain; charset=UTF-8")) - .willReturn(aResponse()) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl()}/body-test'".spel, - "HTTP Method" -> "'POST'".spel, - "Body Type" -> "'Plain Text'".spel, - "Body" -> "'Plain text body'".spel - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevantInput")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("makes request with json body parsed from spel") { - forAll( - Table( - ("spelJsonBody", "stringJsonBody"), - ("null".spel, "null"), - ("{}".spel, "[]"), - ("{1,2,3}".spel, "[1,2,3]"), - (TestData.recordWithAllTypesNestedAsSpelString, TestData.recordWithAllTypesNestedAsJson) - ) - ) { - case (spelJsonBody, requestJsonBodyString) => { - wireMock.stubFor( - post(urlEqualTo("/body-test")) - .withRequestBody(equalToJson(requestJsonBodyString)) - .withHeader("Content-Type", equalTo("application/json; charset=UTF-8")) - .willReturn( - aResponse().withStatus(200) - ) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl()}/body-test'".spel, - "HTTP Method" -> "'POST'".spel, - "Body Type" -> "'JSON'".spel, - "Body" -> spelJsonBody - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevantInput")) - .validValue - .successes - .head - - result shouldBe 200 - } - } - } - - object TestData { - - val recordWithAllTypesNestedAsJson: String = - """ - |{ - | "string": "this is a string", - | "number": 123, - | "decimal": 123.456, - | "booleanTrue": true, - | "nullValue": null, - | "object": { - | "nestedString": "nested value", - | "nestedArray": [1, 2, 3], - | "nestedObject": { - | "innerKey": "innerValue" - | } - | }, - | "arrayOfObjects": [ - | {"key1": "value1"}, - | {"key2": "value2"} - | ], - | "array": [1, "string", true, null, {"innerArrayObject": [1, 2, 3]}] - |} - |""".stripMargin - - val recordWithAllTypesNestedAsSpelString: Expression = - """ - |{ - | "string": "this is a string", - | "number": 123, - | "decimal": 123.456, - | "booleanTrue": true, - | "nullValue": null, - | "object": { - | "nestedString": "nested value", - | "nestedArray": {1, 2, 3}, - | "nestedObject": { - | "innerKey": "innerValue" - | } - | }, - | "arrayOfObjects": { - | {"key1": "value1"}, - | {"key2": "value2"} - | }, - | "array": {1, "string", true, null, {"innerArrayObject": {1, 2, 3}}} - |} - |""".stripMargin.spel - - - val recordWithAllTypesNestedAsComparableAsNuRuntimeValue: Map[String, Any] = Map( - "string" -> "this is a string", - "number" -> java.math.BigDecimal.valueOf(123), - "decimal" -> java.math.BigDecimal.valueOf(123.456), - "booleanTrue" -> true, - "nullValue" -> null, - "object" -> Map( - "nestedString" -> "nested value", - "nestedArray" -> List( - java.math.BigDecimal.valueOf(1), - java.math.BigDecimal.valueOf(2), - java.math.BigDecimal.valueOf(3) - ), - "nestedObject" -> Map( - "innerKey" -> "innerValue" - ) - ), - "arrayOfObjects" -> List( - Map("key1" -> "value1"), - Map("key2" -> "value2") - ), - "array" -> List( - java.math.BigDecimal.valueOf(1), - "string", - true, - null, - Map( - "innerArrayObject" -> List( - java.math.BigDecimal.valueOf(1), - java.math.BigDecimal.valueOf(2), - java.math.BigDecimal.valueOf(3) - ) - ) - ) - ) - - } - -} diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherConfigTest.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherConfigTest.scala deleted file mode 100644 index ad9d03ab02d..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherConfigTest.scala +++ /dev/null @@ -1,46 +0,0 @@ -package pl.touk.nussknacker.http - -import com.typesafe.config.ConfigFactory -import org.scalatest.funsuite.AnyFunSuite -import org.scalatest.matchers.should.Matchers -import pl.touk.nussknacker.engine.api.process.ProcessObjectDependencies -import pl.touk.nussknacker.http.enricher.HttpEnricher.HttpMethod.{DELETE, GET, POST, PUT} -import pl.touk.nussknacker.http.enricher.HttpEnricherFactory - -class HttpEnricherConfigTest extends AnyFunSuite with Matchers { - - test("should create enricher with defaults for empty config") { - new HttpEnricherComponentProvider() - .create(ConfigFactory.empty(), ProcessObjectDependencies.withConfig(ConfigFactory.empty())) - .head - .component - .asInstanceOf[HttpEnricherFactory] - .config should matchPattern { case HttpEnricherConfig(None, None, _, List(GET, POST, PUT, DELETE)) => - } - } - - test("should throw exception when creating enricher with root url with query parameters") { - val config = ConfigFactory.parseString(s""" - |{ - | rootUrl: "http://example.io?someIntParam=123" - |} - |""".stripMargin) - intercept[IllegalArgumentException] { - new HttpEnricherComponentProvider() - .create(config, ProcessObjectDependencies.withConfig(config)) - }.getMessage shouldBe "Root URL for HTTP enricher has to be without query parameters." - } - - test("should throw exception when creating enricher with empty allowed methods") { - val config = ConfigFactory.parseString(s""" - |{ - | allowedMethods: [] - |} - |""".stripMargin) - intercept[IllegalArgumentException] { - new HttpEnricherComponentProvider() - .create(config, ProcessObjectDependencies.withConfig(config)) - }.getMessage shouldBe "Allowed methods cannot be empty." - } - -} diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherHeadersTest.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherHeadersTest.scala deleted file mode 100644 index e178fb72697..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherHeadersTest.scala +++ /dev/null @@ -1,223 +0,0 @@ -package pl.touk.nussknacker.http - -import com.github.tomakehurst.wiremock.client.WireMock._ -import com.github.tomakehurst.wiremock.matching.EqualToPattern -import com.typesafe.config.ConfigFactory -import pl.touk.nussknacker.engine.api.component.ComponentDefinition -import pl.touk.nussknacker.engine.api.context.ProcessCompilationError.ExpressionParserCompilationError -import pl.touk.nussknacker.engine.api.parameter.ParameterName -import pl.touk.nussknacker.engine.api.process.ProcessObjectDependencies -import pl.touk.nussknacker.engine.build.ScenarioBuilder -import pl.touk.nussknacker.engine.spel.SpelExtension.SpelExpresion -import pl.touk.nussknacker.engine.util.test.TestScenarioRunner -import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage.convertValidatedToValuable - -import scala.jdk.CollectionConverters._ - -class HttpEnricherHeadersTest extends HttpEnricherTestSuite { - - val configuredHeadersEnricher: ComponentDefinition = { - val configuredAdditionalHeadersHttpConfig = ConfigFactory.parseString( - s""" - |{ - | security: [ - | { - | in: "header" - | name: "configured_header_1_key" - | value: "configured_header_1_value" - | }, - | { - | in: "header" - | name: "configured_header_2_key" - | value: "configured_header_2_value" - | }, - | { - | in: "cookie" - | name: "configured_cookie_key" - | value: "configured_cookie_value" - | } - | ] - |} - |""".stripMargin - ) - new HttpEnricherComponentProvider() - .create(configuredAdditionalHeadersHttpConfig, ProcessObjectDependencies.withConfig(ConfigFactory.empty())) - .head - .copy(name = "configuredSecurityInHeadersHttp") - } - - override protected lazy val additionalComponents: List[ComponentDefinition] = List(configuredHeadersEnricher) - - test("makes request with lazily evaluated header") { - wireMock.stubFor( - get(urlEqualTo("/header-test")) - .withHeader("spel_header_1_key", new EqualToPattern("spel_header_1_value")) - .withHeader("spel_header_2_key", new EqualToPattern("input_header_2_key")) - .willReturn(aResponse().withStatus(200)) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http-node-id", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "{ spel_header_1_key : 'spel_header_1_value', spel_header_2_key : #input }".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("input_header_2_key")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("makes request with header from config") { - wireMock.stubFor( - get(urlEqualTo("/header-test")) - .withHeader("configured_header_1_key", new EqualToPattern("configured_header_1_value")) - .withHeader("configured_header_2_key", new EqualToPattern("configured_header_2_value")) - .willReturn(aResponse().withStatus(200)) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevant value")) - .validValue - .successes - .head - - result shouldBe 200 - } - - // TODO http: is this ok? even if we validate not overriding we cant ensure that in runtime - test("makes request with header from parameter that overwrites configured header") { - wireMock.stubFor( - get(urlEqualTo("/header-test")) - .withHeader("configured_header_1_key", new EqualToPattern("overwriten_spel_header_1_value")) - .willReturn(aResponse().withStatus(200)) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "{ configured_header_1_key : 'overwriten_spel_header_1_value' }".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevant value")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("makes request with cookie from config") { - wireMock.stubFor( - get(urlEqualTo("/header-test")) - .withCookie("configured_cookie_key", new EqualToPattern("configured_cookie_value")) - .willReturn(aResponse().withStatus(200)) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("irrelevant value")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("returns received headers from response") { - wireMock.stubFor( - get(urlEqualTo("/header-test")) - .willReturn(aResponse().withStatus(200).withHeader("response_header_key", "response_header_value")) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.headers".spel) - - val result = runner - .runWithData[String, java.util.Map[String, String]](scenario, List("irrelevant value")) - .validValue - .successes - .head - - result.asScala should contain("response_header_key" -> "response_header_value") - } - - // TODO http: is this behaviour ok? or should we treat {} as empty map to not confuse users? - test("returns error when using list in headers parameter") { - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredHeadersEnricher.name, - "URL" -> s"'${wireMock.baseUrl()}/header-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "{}".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.headers".spel) - - val result = runner - .runWithData[String, java.util.Map[String, String]](scenario, List("irrelevant value")) - .invalidValue - .head - - result should matchPattern { - case ExpressionParserCompilationError( - "Bad expression type, expected: Map[String,String], found: List[Unknown]({})", - _, - Some(ParameterName("Headers")), - _, - _ - ) => - } - } - -} diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherOutputTest.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherOutputTest.scala deleted file mode 100644 index 4a20c8448cb..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherOutputTest.scala +++ /dev/null @@ -1,95 +0,0 @@ -package pl.touk.nussknacker.http - -import com.github.tomakehurst.wiremock.client.WireMock._ -import pl.touk.nussknacker.engine.api.NodeId -import pl.touk.nussknacker.engine.api.context.ValidationContext -import pl.touk.nussknacker.engine.api.context.transformation.{ - DefinedEagerParameter, - DefinedLazyParameter, - DynamicComponent, - OutputVariableNameValue -} -import pl.touk.nussknacker.engine.api.parameter.ParameterName -import pl.touk.nussknacker.engine.api.typed.typing.Typed -import pl.touk.nussknacker.engine.build.ScenarioBuilder -import pl.touk.nussknacker.engine.spel.SpelExtension.SpelExpresion -import pl.touk.nussknacker.engine.util.test.TestScenarioRunner -import pl.touk.nussknacker.http.backend.DefaultHttpClientConfig -import pl.touk.nussknacker.http.enricher.HttpEnricher.{BodyType, HttpMethod} -import pl.touk.nussknacker.http.enricher.HttpEnricherFactory -import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage.convertValidatedToValuable - -// TODO: add test for request data -// TODO: add test for typing -class HttpEnricherOutputTest extends HttpEnricherTestSuite { - - test("returns request and response data as seperate fields") { - wireMock.stubFor( - get(urlEqualTo("/code-test")).willReturn( - aResponse().withStatus(200).withHeader("response_header_key_1", "response_header_value_1") - ) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http-node-id", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl()}/code-test'".spel, - "HTTP Method" -> "'GET'".spel, - "Headers" -> "{ spel_header_1_key : 'spel_header_1_value' }".spel, - "Body Type" -> "'None'".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput".spel) - - val result = runner - .runWithData[String, java.util.Map[String, AnyRef]](scenario, List("irrelevantInput")) - .validValue - .successes - .head - - val resultMap = deepToScala(result).asInstanceOf[Map[String, AnyRef]] - - val request = resultMap("request").asInstanceOf[Map[String, AnyRef]] - request("url") shouldBe s"${wireMock.baseUrl()}/code-test" - request("method") shouldBe "GET" - request("body") shouldBe null - - val requestHeaders = request("headers").asInstanceOf[Map[String, String]] - requestHeaders("spel_header_1_key") shouldBe "spel_header_1_value" - - val response = resultMap("response").asInstanceOf[Map[String, AnyRef]] - response("statusCode") shouldBe 200 - response("statusText") shouldBe "OK" - response("body") shouldBe null - - val responseHeaders = response("headers").asInstanceOf[Map[String, String]] - responseHeaders("response_header_key_1") shouldBe "response_header_value_1" - } - - // TODO: how to test typing result from context transformation - ignore("return typing result of request body if can be determined") { - val enricherService = - new HttpEnricherFactory(HttpEnricherConfig.apply(None, None, DefaultHttpClientConfig(), List(HttpMethod.GET))) - val transformation = { - enricherService.contextTransformation(ValidationContext.empty, List(OutputVariableNameValue("outputVar")))( - NodeId("test") - )( - enricherService.TransformationStep( - List( - (ParameterName("URL"), DefinedLazyParameter(Typed.fromInstance("http://somehost.com"))), - (ParameterName("Query Parameters"), DefinedLazyParameter(Typed.fromInstance(null))), - (ParameterName("HTTP Method"), DefinedEagerParameter("GET", Typed.fromInstance("GET"))), - (ParameterName("Headers"), DefinedLazyParameter(Typed.fromInstance(null))), - (ParameterName("Body Type"), DefinedEagerParameter("None", Typed.fromInstance("None"))), - (ParameterName("Body"), DefinedLazyParameter(Typed.fromInstance(null))), - ), - Some(HttpEnricherFactory.TransformationState.BodyTypeDeclared(BodyType.PlainText)) - ) - ) - } - // cant match on DynamicComponent.FinalResults - no way to do it from here? - } - -} diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherTestSuite.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherTestSuite.scala deleted file mode 100644 index 35d23a73368..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherTestSuite.scala +++ /dev/null @@ -1,71 +0,0 @@ -package pl.touk.nussknacker.http - -import com.github.tomakehurst.wiremock.WireMockServer -import com.github.tomakehurst.wiremock.core.WireMockConfiguration -import com.typesafe.config.ConfigFactory -import org.scalatest.BeforeAndAfterAll -import org.scalatest.funsuite.AnyFunSuite -import org.scalatest.matchers.should.Matchers -import pl.touk.nussknacker.engine.api.component.ComponentDefinition -import pl.touk.nussknacker.engine.api.process.ProcessObjectDependencies -import pl.touk.nussknacker.engine.flink.test.FlinkSpec -import pl.touk.nussknacker.engine.flink.util.test.FlinkTestScenarioRunner -import pl.touk.nussknacker.engine.flink.util.test.FlinkTestScenarioRunner.FlinkTestScenarioRunnerExt -import pl.touk.nussknacker.engine.util.test.TestScenarioRunner -import pl.touk.nussknacker.test.AvailablePortFinder - -import scala.jdk.CollectionConverters._ - -class HttpEnricherTestSuite extends AnyFunSuite with BeforeAndAfterAll with FlinkSpec with Matchers { - - protected val wireMock: WireMockServer = { - val server = AvailablePortFinder.withAvailablePortsBlocked(1)(l => { - new WireMockServer( - WireMockConfiguration - .wireMockConfig() - .port(l.head) - ) - }) - server.start() - server - } - - override protected def afterAll(): Unit = { - try { - wireMock.stop() - } finally { - super.afterAll() - } - } - - protected val noConfigHttpEnricherName = "no-config-http" - - protected lazy val additionalComponents: List[ComponentDefinition] = List.empty - - protected lazy val runner: FlinkTestScenarioRunner = TestScenarioRunner - .flinkBased(ConfigFactory.empty(), flinkMiniCluster) - .withExtraComponents( - new HttpEnricherComponentProvider() - .create( - ConfigFactory.empty(), - ProcessObjectDependencies.withConfig(ConfigFactory.empty()) - ) - .head - .copy(name = noConfigHttpEnricherName) +: additionalComponents - ) - .build() - - protected def deepToScala(obj: Any): Any = obj match { - case map: java.util.Map[_, _] => - map.asScala.map { case (key, value) => (deepToScala(key), deepToScala(value)) }.toMap - case list: java.util.List[_] => - list.asScala.map(deepToScala).toList - case set: java.util.Set[_] => - set.asScala.map(deepToScala).toSet - case array: Array[_] => - array.map(deepToScala) - case other => - other - } - -} diff --git a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherURLTest.scala b/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherURLTest.scala deleted file mode 100644 index c495db015a1..00000000000 --- a/components/http/src/test/scala/pl/touk/nussknacker/http/HttpEnricherURLTest.scala +++ /dev/null @@ -1,132 +0,0 @@ -package pl.touk.nussknacker.http - -import com.github.tomakehurst.wiremock.client.WireMock._ -import com.typesafe.config.ConfigFactory -import pl.touk.nussknacker.engine.api.component.ComponentDefinition -import pl.touk.nussknacker.engine.api.context.ProcessCompilationError.CustomNodeError -import pl.touk.nussknacker.engine.api.parameter.ParameterName -import pl.touk.nussknacker.engine.api.process.ProcessObjectDependencies -import pl.touk.nussknacker.engine.build.ScenarioBuilder -import pl.touk.nussknacker.engine.spel.SpelExtension.SpelExpresion -import pl.touk.nussknacker.engine.util.test.TestScenarioRunner -import pl.touk.nussknacker.test.ValidatedValuesDetailedMessage.convertValidatedToValuable - -class HttpEnricherURLTest extends HttpEnricherTestSuite { - - import org.scalatest.prop.TableDrivenPropertyChecks._ - - lazy val configuredRootURLEnricher: ComponentDefinition = { - val configuredAdditionalHeadersHttpConfig = ConfigFactory.parseString( - s""" - |{ - | rootUrl: "${wireMock.baseUrl()}", - | security: [ - | { - | in: "query" - | name: "configured_query_1_key" - | value: "configured_query_1_value" - | } - | ] - |} - |""".stripMargin - ) - new HttpEnricherComponentProvider() - .create(configuredAdditionalHeadersHttpConfig, ProcessObjectDependencies.withConfig(ConfigFactory.empty())) - .head - .copy(name = "configured-root-url-and-query-security-key-http") - } - - override protected lazy val additionalComponents: List[ComponentDefinition] = List(configuredRootURLEnricher) - - test("makes request under specified url with configured root url and query params") { - wireMock.stubFor( - get(urlEqualTo("/url-test?spel_query_key_1=input_query_value_1&configured_query_1_key=configured_query_1_value")) - .willReturn( - aResponse().withStatus(200) - ) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - configuredRootURLEnricher.name, - "URL" -> s"'/url-test'".spel, - "Query Parameters" -> "{ spel_query_key_1 : #input }".spel, - "HTTP Method" -> "'GET'".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("input_query_value_1")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("makes request under specified url with encoded query params") { - wireMock.stubFor( - get(urlEqualTo("/url-test?spel_query_unencoded_header_+!%23=spel_query_unencoded_header_+!%23")) - .willReturn( - aResponse().withStatus(200) - ) - ) - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> s"'${wireMock.baseUrl}/url-test'".spel, - "Query Parameters" -> "{ 'spel_query_unencoded_header_ !#' : 'spel_query_unencoded_header_ !#' }".spel, - "HTTP Method" -> "'GET'".spel, - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput.response.statusCode".spel) - - val result = runner - .runWithData[String, Integer](scenario, List("input_query_value_1")) - .validValue - .successes - .head - - result shouldBe 200 - } - - test("validates url during parameters validation") { - forAll( - Table( - ("invalidUrlExpr", "expectedErrorMessage"), - ("'noturl'".spel, "Invalid URL: no protocol: noturl"), - ("'badprotocol://'".spel, "Invalid URL: unknown protocol: badprotocol"), - ("'http://'".spel, "Invalid URL: Expected scheme-specific part at index 5: http:"), - ( - "'http://host_with_space in_authority'".spel, - "Invalid URL: Illegal character in authority at index 7: http://host_with_space in_authority" - ) - ) - ) { (invalidUrlExpr, errorMessage) => - val scenario = ScenarioBuilder - .streaming("id") - .source("start", TestScenarioRunner.testDataSource) - .enricher( - "http", - "httpOutput", - noConfigHttpEnricherName, - "URL" -> invalidUrlExpr, - "HTTP Method" -> "'GET'".spel - ) - .emptySink("end", TestScenarioRunner.testResultSink, "value" -> "#httpOutput".spel) - - val errors = runner - .runWithData[String, Integer](scenario, List("irrelevant")) - .invalidValue - - errors.head shouldBe CustomNodeError("http", errorMessage, Some(ParameterName("URL"))) - } - } - -} diff --git a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/DynamicNodeValidator.scala b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/DynamicNodeValidator.scala index e6eb398d1c1..10f1e641bc3 100644 --- a/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/DynamicNodeValidator.scala +++ b/scenario-compiler/src/main/scala/pl/touk/nussknacker/engine/compile/nodecompilation/DynamicNodeValidator.scala @@ -108,6 +108,8 @@ class DynamicNodeValidator( // we add distinct here, as multi-step, partial validation of parameters can cause duplicate errors if implementation is not v. careful val allErrors = (errorsCombined ++ errors).distinct Valid(TransformationResult(allErrors, evaluatedSoFar.map(_._1), finalContext, state, nodeParameters)) + case component.NextParameters(Nil, _, _) => + returnUnmatchedFallback case component.NextParameters(newParameters, newParameterErrors, state) => val enrichedParameters = StandardParameterEnrichment.enrichParameterDefinitions(newParameters, parametersConfig)