diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy index 29263cd45..5eb5f6d78 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy +++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesTest.groovy @@ -25,7 +25,7 @@ class RoutesTest extends TestSupport { def 'split'() { setup: - def context = startContext() + def context = startContextForSpec() mockEndpoint(context,'mock:split') { expectedMessageCount = 3 @@ -52,7 +52,7 @@ class RoutesTest extends TestSupport { def 'filter'() { setup: - def context = startContext() + def context = startContextForSpec() mockEndpoint(context, 'mock:route') { expectedMessageCount 2 @@ -81,7 +81,7 @@ class RoutesTest extends TestSupport { def 'aggregator'() { setup: - def context = startContext { + def context = startContextForSpec { registry.bind('aggregatorStrategy', new UseLatestAggregationStrategy()) } @@ -104,7 +104,7 @@ class RoutesTest extends TestSupport { def 'idempotentConsumer'() { setup: - def context = startContext { + def context = startContextForSpec { registry.bind('myRepo', new MemoryIdempotentRepository()) } @@ -132,7 +132,7 @@ class RoutesTest extends TestSupport { def 'onExceptionHandled'() { setup: - def context = startContext { + def context = startContextForSpec { registry.bind('myFailingProcessor', new MyFailingProcessor()) } when: @@ -145,7 +145,7 @@ class RoutesTest extends TestSupport { def 'errorHandler'() { setup: - def context = startContext { + def context = startContextForSpec { registry.bind('myFailingProcessor', new MyFailingProcessor()) } @@ -162,7 +162,7 @@ class RoutesTest extends TestSupport { def 'bean'() { setup: - def context = startContext() + def context = startContextForSpec() when: def out = context.createProducerTemplate().requestBody('direct:route', 'test'); then: diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RouteWithPlaceholdersTest.groovy b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesWithPlaceholdersTest.groovy similarity index 93% rename from camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RouteWithPlaceholdersTest.groovy rename to camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesWithPlaceholdersTest.groovy index eece0829d..1e7f2ead9 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RouteWithPlaceholdersTest.groovy +++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/RoutesWithPlaceholdersTest.groovy @@ -18,7 +18,7 @@ package org.apache.camel.k.loader.yaml import org.apache.camel.component.direct.DirectEndpoint -class RouteWithPlaceholdersTest extends TestSupport { +class RoutesWithPlaceholdersTest extends TestSupport { def 'route'() { setup: def parameters = [ @@ -26,7 +26,7 @@ class RouteWithPlaceholdersTest extends TestSupport { 'direct.timeout': 1234, 'direct.result': UUID.randomUUID().toString() ] - def context = startContext { + def context = startContextForSpec { propertiesComponent.initialProperties = parameters as Properties } when: @@ -44,7 +44,7 @@ class RouteWithPlaceholdersTest extends TestSupport { 'direct.timeout': 1234, 'direct.result': UUID.randomUUID().toString() ] - def context = startContext { + def context = startContextForSpec { propertiesComponent.initialProperties = parameters as Properties } when: @@ -67,7 +67,7 @@ class RouteWithPlaceholdersTest extends TestSupport { 'direct.timeout': 1234, 'direct.result': UUID.randomUUID().toString() ] - def context = startContext { + def context = startContextForSpec { propertiesComponent.initialProperties = parameters as Properties } when: @@ -85,7 +85,7 @@ class RouteWithPlaceholdersTest extends TestSupport { 'direct.timeout': 1234, 'direct.result': UUID.randomUUID().toString() ] - def context = startContext { + def context = startContextForSpec { propertiesComponent.initialProperties = parameters as Properties } when: diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/TestSupport.groovy b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/TestSupport.groovy index 0971ad068..ed2bb781d 100644 --- a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/TestSupport.groovy +++ b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/groovy/org/apache/camel/k/loader/yaml/TestSupport.groovy @@ -23,6 +23,9 @@ import org.apache.camel.FluentProducerTemplate import org.apache.camel.builder.RouteBuilder import org.apache.camel.component.mock.MockEndpoint import org.apache.camel.impl.DefaultCamelContext +import org.apache.camel.k.Runtime +import org.apache.camel.k.Source +import org.apache.camel.k.Sources import org.apache.camel.k.loader.yaml.spi.ProcessorStepParser import org.apache.camel.k.loader.yaml.spi.StartStepParser import org.apache.camel.k.loader.yaml.spi.StepParser @@ -58,28 +61,20 @@ class TestSupport extends Specification { return new StepParser.Context(builder, new RouteDefinition(), MAPPER, content, RESOLVER) } - static CamelContext startContext(String content) { - return startContext(content, null) - } - static CamelContext startContext( String content, @DelegatesTo(CamelContext) Closure closure) { return startContext( - new ByteArrayInputStream(content.stripMargin().getBytes(StandardCharsets.UTF_8)), + Sources.fromBytes('yaml', content.getBytes(StandardCharsets.UTF_8)), closure ) } - static CamelContext startContext(InputStream content) { - return startContext(content, null) - } - static CamelContext startContext( - InputStream content, + Source source, @DelegatesTo(CamelContext) Closure closure) { def context = new DefaultCamelContext() - def builder = new YamlSourceLoader().builder(content) + def builder = new YamlSourceLoader().load(Runtime.on(context), source).builder().orElseThrow(() -> new IllegalArgumentException()); context.disableJMX() context.setStreamCaching(true) @@ -96,16 +91,12 @@ class TestSupport extends Specification { return context } - CamelContext startContext() { - return startContext(null as Closure) - } - - CamelContext startContext(@DelegatesTo(CamelContext) Closure closure) { + CamelContext startContextForSpec(@DelegatesTo(CamelContext) Closure closure) { def name = specificationContext.currentIteration.name.replace(' ', '_') - def path = "/routes/${specificationContext.currentSpec.name}_${name}.yaml" + def path = "classpath:/routes/${specificationContext.currentSpec.name}_${name}.yaml" return startContext( - TestSupport.class.getResourceAsStream(path) as InputStream, + Sources.fromURI(path), closure ) } diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_from.yaml b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_from.yaml similarity index 100% rename from camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_from.yaml rename to camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_from.yaml diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_route.yaml b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_route.yaml similarity index 100% rename from camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_route.yaml rename to camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_route.yaml diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_to.yaml b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_to.yaml similarity index 100% rename from camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_to.yaml rename to camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_to.yaml diff --git a/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_tod.yaml b/camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_tod.yaml similarity index 100% rename from camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RouteWithPlaceholdersTest_tod.yaml rename to camel-k-loader-yaml/camel-k-loader-yaml/src/test/resources/routes/RoutesWithPlaceholdersTest_tod.yaml diff --git a/pom.xml b/pom.xml index 36c9853e2..1a9d162fa 100644 --- a/pom.xml +++ b/pom.xml @@ -50,7 +50,7 @@ 3.16.1 2.13.3 1.7.30 - 3.0.4 + 3.0.5 1.3.72 1.26 2.0-M3-groovy-3.0