Skip to content

Commit 088561d

Browse files
authored
Variables - global vs local setVariable test (#5654)
1 parent 2ab84a1 commit 088561d

File tree

8 files changed

+658
-0
lines changed

8 files changed

+658
-0
lines changed

integration-test-groups/foundation/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -57,6 +57,7 @@
5757
<module>timer</module>
5858
<module>transformer</module>
5959
<module>type-converter</module>
60+
<module>variables</module>
6061
</modules>
6162

6263
</project>
Lines changed: 149 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,149 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!--
3+
4+
Licensed to the Apache Software Foundation (ASF) under one or more
5+
contributor license agreements. See the NOTICE file distributed with
6+
this work for additional information regarding copyright ownership.
7+
The ASF licenses this file to You under the Apache License, Version 2.0
8+
(the "License"); you may not use this file except in compliance with
9+
the License. You may obtain a copy of the License at
10+
11+
http://www.apache.org/licenses/LICENSE-2.0
12+
13+
Unless required by applicable law or agreed to in writing, software
14+
distributed under the License is distributed on an "AS IS" BASIS,
15+
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16+
See the License for the specific language governing permissions and
17+
limitations under the License.
18+
19+
-->
20+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
21+
<modelVersion>4.0.0</modelVersion>
22+
<parent>
23+
<groupId>org.apache.camel.quarkus</groupId>
24+
<artifactId>camel-quarkus-build-parent-it</artifactId>
25+
<version>3.7.0-SNAPSHOT</version>
26+
<relativePath>../../../poms/build-parent-it/pom.xml</relativePath>
27+
</parent>
28+
29+
<artifactId>camel-quarkus-integration-test-variables</artifactId>
30+
<name>Camel Quarkus :: Integration Tests :: Variables</name>
31+
32+
<dependencies>
33+
<dependency>
34+
<groupId>org.apache.camel.quarkus</groupId>
35+
<artifactId>camel-quarkus-bean</artifactId>
36+
</dependency>
37+
<dependency>
38+
<groupId>org.apache.camel.quarkus</groupId>
39+
<artifactId>camel-quarkus-mock</artifactId>
40+
</dependency>
41+
<dependency>
42+
<groupId>org.apache.camel.quarkus</groupId>
43+
<artifactId>camel-quarkus-direct</artifactId>
44+
</dependency>
45+
<dependency>
46+
<groupId>io.quarkus</groupId>
47+
<artifactId>quarkus-resteasy</artifactId>
48+
</dependency>
49+
50+
51+
<!-- test dependencies -->
52+
<dependency>
53+
<groupId>io.quarkus</groupId>
54+
<artifactId>quarkus-junit5</artifactId>
55+
<scope>test</scope>
56+
</dependency>
57+
<dependency>
58+
<groupId>io.rest-assured</groupId>
59+
<artifactId>rest-assured</artifactId>
60+
<scope>test</scope>
61+
</dependency>
62+
<dependency>
63+
<groupId>org.apache.camel.quarkus</groupId>
64+
<artifactId>camel-quarkus-integration-wiremock-support</artifactId>
65+
<scope>test</scope>
66+
</dependency>
67+
</dependencies>
68+
69+
<profiles>
70+
<profile>
71+
<id>native</id>
72+
<activation>
73+
<property>
74+
<name>native</name>
75+
</property>
76+
</activation>
77+
<properties>
78+
<quarkus.package.type>native</quarkus.package.type>
79+
</properties>
80+
<build>
81+
<plugins>
82+
<plugin>
83+
<groupId>org.apache.maven.plugins</groupId>
84+
<artifactId>maven-failsafe-plugin</artifactId>
85+
<executions>
86+
<execution>
87+
<goals>
88+
<goal>integration-test</goal>
89+
<goal>verify</goal>
90+
</goals>
91+
</execution>
92+
</executions>
93+
</plugin>
94+
</plugins>
95+
</build>
96+
</profile>
97+
<profile>
98+
<id>virtualDependencies</id>
99+
<activation>
100+
<property>
101+
<name>!noVirtualDependencies</name>
102+
</property>
103+
</activation>
104+
<dependencies>
105+
<!-- The following dependencies guarantee that this module is built after them. You can update them by running `mvn process-resources -Pformat -N` from the source tree root directory -->
106+
<dependency>
107+
<groupId>org.apache.camel.quarkus</groupId>
108+
<artifactId>camel-quarkus-bean-deployment</artifactId>
109+
<version>${project.version}</version>
110+
<type>pom</type>
111+
<scope>test</scope>
112+
<exclusions>
113+
<exclusion>
114+
<groupId>*</groupId>
115+
<artifactId>*</artifactId>
116+
</exclusion>
117+
</exclusions>
118+
</dependency>
119+
<dependency>
120+
<groupId>org.apache.camel.quarkus</groupId>
121+
<artifactId>camel-quarkus-direct-deployment</artifactId>
122+
<version>${project.version}</version>
123+
<type>pom</type>
124+
<scope>test</scope>
125+
<exclusions>
126+
<exclusion>
127+
<groupId>*</groupId>
128+
<artifactId>*</artifactId>
129+
</exclusion>
130+
</exclusions>
131+
</dependency>
132+
<dependency>
133+
<groupId>org.apache.camel.quarkus</groupId>
134+
<artifactId>camel-quarkus-mock-deployment</artifactId>
135+
<version>${project.version}</version>
136+
<type>pom</type>
137+
<scope>test</scope>
138+
<exclusions>
139+
<exclusion>
140+
<groupId>*</groupId>
141+
<artifactId>*</artifactId>
142+
</exclusion>
143+
</exclusions>
144+
</dependency>
145+
</dependencies>
146+
</profile>
147+
</profiles>
148+
149+
</project>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
/*
2+
* Licensed to the Apache Software Foundation (ASF) under one or more
3+
* contributor license agreements. See the NOTICE file distributed with
4+
* this work for additional information regarding copyright ownership.
5+
* The ASF licenses this file to You under the Apache License, Version 2.0
6+
* (the "License"); you may not use this file except in compliance with
7+
* the License. You may obtain a copy of the License at
8+
*
9+
* http://www.apache.org/licenses/LICENSE-2.0
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*/
17+
package org.apache.camel.quarkus.variables.it;
18+
19+
import io.quarkus.runtime.annotations.RegisterForReflection;
20+
import jakarta.enterprise.context.ApplicationScoped;
21+
import jakarta.enterprise.inject.Alternative;
22+
import jakarta.inject.Named;
23+
import org.apache.camel.Variable;
24+
import org.apache.camel.spi.VariableRepository;
25+
import org.apache.camel.support.service.ServiceSupport;
26+
27+
public class VariablesProducers {
28+
29+
//repository is created as alternative to be disabled by default
30+
//QuarkusTestProfile is used to enable the bean for the appropriate tests.
31+
@Named("global-variable-repository")
32+
@Alternative
33+
@ApplicationScoped
34+
public static class MyGlobalRepo extends ServiceSupport implements VariableRepository {
35+
36+
private Object value;
37+
38+
@Override
39+
public String getId() {
40+
return "myGlobal";
41+
}
42+
43+
@Override
44+
public Object getVariable(String name) {
45+
if (value != null) {
46+
return "!" + value + "!";
47+
}
48+
return null;
49+
}
50+
51+
@Override
52+
public void setVariable(String name, Object value) {
53+
this.value = value;
54+
}
55+
56+
@Override
57+
public Object removeVariable(String name) {
58+
return null;
59+
}
60+
}
61+
62+
@Named("my-bean")
63+
@ApplicationScoped
64+
@RegisterForReflection(methods = true)
65+
public static class MyBean {
66+
public boolean matches(@Variable("location") String location) {
67+
return "Medford".equals(location);
68+
}
69+
}
70+
71+
}

0 commit comments

Comments
 (0)