You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2021/05/13 20:10:34 UTC
[camel] branch main updated: CAMEL-16607: Allow to use #type and
#class for local beans (tests)
This is an automated email from the ASF dual-hosted git repository.
lburgazzoli pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new d7ab43c CAMEL-16607: Allow to use #type and #class for local beans (tests)
d7ab43c is described below
commit d7ab43c9437ead7c3a41bf68c31b008cfa0038a5
Author: Luca Burgazzoli <lb...@gmail.com>
AuthorDate: Thu May 13 22:09:56 2021 +0200
CAMEL-16607: Allow to use #type and #class for local beans (tests)
---
.../apache/camel/catalog/schemas/camel-spring.xsd | 49 +++------
.../apache/camel/dsl/yaml/RouteTemplateTest.groovy | 121 ++++++++++-----------
2 files changed, 75 insertions(+), 95 deletions(-)
diff --git a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
index 3c71d8e..220e055 100644
--- a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
+++ b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/schemas/camel-spring.xsd
@@ -10298,43 +10298,20 @@ Whether tracing is enabled on this route.
</xs:complexType>
<xs:complexType name="routeTemplateBeanDefinition">
- <xs:sequence>
- <xs:element maxOccurs="unbounded" minOccurs="0" ref="tns:property"/>
- <xs:element minOccurs="0" name="script" type="tns:routeTemplateScriptDefinition">
- <xs:annotation>
- <xs:documentation xml:lang="en"><![CDATA[
-The script to execute that creates the bean when using scripting languages. If
-the script use the prefix resource: such as
-resource:classpath:com/foo/myscript.groovy, resource:file:/var/myscript.groovy,
-then its loaded from the external resource.
- ]]></xs:documentation>
- </xs:annotation>
- </xs:element>
- </xs:sequence>
- <xs:attribute name="name" type="xs:string" use="required">
- <xs:annotation>
- <xs:documentation xml:lang="en"><![CDATA[
+ <xs:simpleContent>
+ <xs:extension base="xs:string">
+ <xs:attribute name="name" type="xs:string" use="required">
+ <xs:annotation>
+ <xs:documentation xml:lang="en"><![CDATA[
Bean name.
- ]]></xs:documentation>
- </xs:annotation>
- </xs:attribute>
- <xs:attribute name="type" type="xs:string" use="required">
- <xs:annotation>
- <xs:documentation xml:lang="en"><![CDATA[
-What type to use for creating the bean. Can be one of:
-#class,#type,bean,groovy,joor,language,mvel,ognl. #class or #type then the bean
-is created via the fully qualified classname, such as #class:com.foo.MyBean The
-others are scripting languages that gives more power to create the bean with an
-inlined code in the script section, such as using groovy.
- ]]></xs:documentation>
- </xs:annotation>
- </xs:attribute>
+ ]]></xs:documentation>
+ </xs:annotation>
+ </xs:attribute>
+ <xs:attribute name="language" type="xs:string" use="required"/>
+ </xs:extension>
+ </xs:simpleContent>
</xs:complexType>
- <xs:simpleType name="routeTemplateScriptDefinition">
- <xs:restriction base="xs:string"/>
- </xs:simpleType>
-
<xs:complexType name="routeTemplateContextRefDefinition">
<xs:sequence/>
<xs:attribute name="ref" type="xs:string" use="required">
@@ -10393,6 +10370,10 @@ Description of the parameter.
</xs:attribute>
</xs:complexType>
+ <xs:simpleType name="routeTemplateScriptDefinition">
+ <xs:restriction base="xs:string"/>
+ </xs:simpleType>
+
<xs:complexType name="routeTemplatesDefinition">
<xs:complexContent>
<xs:extension base="tns:optionalIdentifiedDefinition">
diff --git a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RouteTemplateTest.groovy b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RouteTemplateTest.groovy
index b8a3293..449e6e2 100644
--- a/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RouteTemplateTest.groovy
+++ b/dsl/camel-yaml-dsl/camel-yaml-dsl/src/test/groovy/org/apache/camel/dsl/yaml/RouteTemplateTest.groovy
@@ -22,6 +22,7 @@ import org.apache.camel.dsl.yaml.support.model.MyUppercaseProcessor
import org.apache.camel.model.LogDefinition
import org.apache.camel.model.RouteTemplateDefinition
import org.apache.camel.model.ToDefinition
+import org.apache.camel.spi.Resource
import org.junit.jupiter.api.Assertions
class RouteTemplateTest extends YamlTestSupport {
@@ -48,68 +49,9 @@ class RouteTemplateTest extends YamlTestSupport {
}
}
- def "create template with beans"() {
+ def "create template with beans (#resource.location)"(Resource resource) {
setup:
- loadRoutes """
- - template:
- id: "myTemplate"
- beans:
- - name: "myProcessor"
- type: "#class:${MyUppercaseProcessor.class.name}"
- from:
- uri: "direct:{{directName}}"
- steps:
- - process:
- ref: "{{myProcessor}}"
- - from:
- uri: "direct:start"
- steps:
- - to: "direct:myId"
- - to: "mock:result"
- """
-
- withMock('mock:result') {
- expectedMessageCount 1
- expectedBodiesReceived 'HELLO'
- }
- when:
- context.addRouteFromTemplate('myId', 'myTemplate', ['directName': 'myId'])
- context.start()
-
- withTemplate {
- to('direct:start').withBody('hello').send()
- }
- then:
- context.routeTemplateDefinitions.size() == 1
-
- with(context.routeTemplateDefinitions[0], RouteTemplateDefinition) {
- id == 'myTemplate'
- templateBeans.size() == 1
- }
-
- MockEndpoint.assertIsSatisfied(context)
- }
-
- def "create template with script"() {
- setup:
- loadRoutes """
- - template:
- id: "myTemplate"
- beans:
- - name: "myProcessor"
- type: "groovy"
- script: "new ${MyUppercaseProcessor.class.name}()"
- from:
- uri: "direct:{{directName}}"
- steps:
- - process:
- ref: "{{myProcessor}}"
- - from:
- uri: "direct:start"
- steps:
- - to: "direct:myId"
- - to: "mock:result"
- """
+ context.routesLoader.loadRoutes(resource)
withMock('mock:result') {
expectedMessageCount 1
@@ -131,6 +73,63 @@ class RouteTemplateTest extends YamlTestSupport {
}
MockEndpoint.assertIsSatisfied(context)
+ where:
+ resource << [
+ asResource('beans', """
+ - template:
+ id: "myTemplate"
+ beans:
+ - name: "myProcessor"
+ type: "#class:${MyUppercaseProcessor.class.name}"
+ from:
+ uri: "direct:{{directName}}"
+ steps:
+ - process:
+ ref: "{{myProcessor}}"
+ - from:
+ uri: "direct:start"
+ steps:
+ - to: "direct:myId"
+ - to: "mock:result"
+ """),
+ asResource('script', """
+ - template:
+ id: "myTemplate"
+ beans:
+ - name: "myProcessor"
+ type: "groovy"
+ script: "new ${MyUppercaseProcessor.class.name}()"
+ from:
+ uri: "direct:{{directName}}"
+ steps:
+ - process:
+ ref: "{{myProcessor}}"
+ - from:
+ uri: "direct:start"
+ steps:
+ - to: "direct:myId"
+ - to: "mock:result"
+ """),
+ asResource('script-block', """
+ - template:
+ id: "myTemplate"
+ beans:
+ - name: "myProcessor"
+ type: "groovy"
+ script: |
+ new ${MyUppercaseProcessor.class.name}()
+ from:
+ uri: "direct:{{directName}}"
+ steps:
+ - process:
+ ref: "{{myProcessor}}"
+ - from:
+ uri: "direct:start"
+ steps:
+ - to: "direct:myId"
+ - to: "mock:result"
+ """)
+ ]
}
def "create template with properties"() {