Skip to content

Commit

Permalink
Update groovy to v3.0.5
Browse files Browse the repository at this point in the history
  • Loading branch information
lburgazzoli committed Jul 23, 2020
1 parent 20ce62c commit 7586604
Show file tree
Hide file tree
Showing 8 changed files with 22 additions and 31 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class RoutesTest extends TestSupport {

def 'split'() {
setup:
def context = startContext()
def context = startContextForSpec()

mockEndpoint(context,'mock:split') {
expectedMessageCount = 3
Expand All @@ -52,7 +52,7 @@ class RoutesTest extends TestSupport {

def 'filter'() {
setup:
def context = startContext()
def context = startContextForSpec()

mockEndpoint(context, 'mock:route') {
expectedMessageCount 2
Expand Down Expand Up @@ -81,7 +81,7 @@ class RoutesTest extends TestSupport {

def 'aggregator'() {
setup:
def context = startContext {
def context = startContextForSpec {
registry.bind('aggregatorStrategy', new UseLatestAggregationStrategy())
}

Expand All @@ -104,7 +104,7 @@ class RoutesTest extends TestSupport {

def 'idempotentConsumer'() {
setup:
def context = startContext {
def context = startContextForSpec {
registry.bind('myRepo', new MemoryIdempotentRepository())
}

Expand Down Expand Up @@ -132,7 +132,7 @@ class RoutesTest extends TestSupport {

def 'onExceptionHandled'() {
setup:
def context = startContext {
def context = startContextForSpec {
registry.bind('myFailingProcessor', new MyFailingProcessor())
}
when:
Expand All @@ -145,7 +145,7 @@ class RoutesTest extends TestSupport {

def 'errorHandler'() {
setup:
def context = startContext {
def context = startContextForSpec {
registry.bind('myFailingProcessor', new MyFailingProcessor())
}

Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,15 @@ 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 = [
'direct.id': 'myDirect',
'direct.timeout': 1234,
'direct.result': UUID.randomUUID().toString()
]
def context = startContext {
def context = startContextForSpec {
propertiesComponent.initialProperties = parameters as Properties
}
when:
Expand All @@ -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:
Expand All @@ -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:
Expand All @@ -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:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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<CamelContext> 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)
Expand All @@ -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
)
}
Expand Down
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@
<assertj.version>3.16.1</assertj.version>
<log4j2.version>2.13.3</log4j2.version>
<slf4j.version>1.7.30</slf4j.version>
<groovy.version>3.0.4</groovy.version>
<groovy.version>3.0.5</groovy.version>
<kotlin.version>1.3.72</kotlin.version>
<snakeyaml.version>1.26</snakeyaml.version>
<spock.version>2.0-M3-groovy-3.0</spock.version>
Expand Down

0 comments on commit 7586604

Please sign in to comment.