This is an automated email from the ASF dual-hosted git repository. davsclaus 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 7d6cf65e0d8 CAMEL-20799: Added unit test 7d6cf65e0d8 is described below commit 7d6cf65e0d82edcc957a9e10e911ac30a27635e2 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed May 29 09:37:12 2024 +0200 CAMEL-20799: Added unit test --- .../spring/processor/SpringSetVariablesTest.java | 44 ++++++++++++++++++++++ .../processor/SpringSetVariablesTest-context.xml | 44 ++++++++++++++++++++++ .../src/test/resources/routeWithSetVariables.xml | 32 ++++++++++++++++ 3 files changed, 120 insertions(+) diff --git a/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringSetVariablesTest.java b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringSetVariablesTest.java new file mode 100644 index 00000000000..f386e86357d --- /dev/null +++ b/components/camel-spring-xml/src/test/java/org/apache/camel/spring/processor/SpringSetVariablesTest.java @@ -0,0 +1,44 @@ +/* + * Licensed to the Apache Software Foundation (ASF) under one or more + * contributor license agreements. See the NOTICE file distributed with + * this work for additional information regarding copyright ownership. + * The ASF licenses this file to You under the Apache License, Version 2.0 + * (the "License"); you may not use this file except in compliance with + * the License. You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ +package org.apache.camel.spring.processor; + +import org.apache.camel.CamelContext; +import org.apache.camel.ContextTestSupport; +import org.apache.camel.component.mock.MockEndpoint; +import org.junit.jupiter.api.Test; + +import static org.apache.camel.spring.processor.SpringTestHelper.createSpringCamelContext; + +public class SpringSetVariablesTest extends ContextTestSupport { + + @Test + public void testSetVariables() throws Exception { + MockEndpoint resultEndpoint = getMockEndpoint("mock:b"); + resultEndpoint.expectedBodiesReceived("World"); + resultEndpoint.expectedVariableReceived("myVar", "Hello World"); + resultEndpoint.expectedVariableReceived("myOtherVar", "Bye World"); + + sendBody("seda:a", "World"); + + resultEndpoint.assertIsSatisfied(); + } + + @Override + protected CamelContext createCamelContext() throws Exception { + return createSpringCamelContext(this, "org/apache/camel/spring/processor/SpringSetVariablesTest-context.xml"); + } +} diff --git a/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringSetVariablesTest-context.xml b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringSetVariablesTest-context.xml new file mode 100644 index 00000000000..e61c6283ec5 --- /dev/null +++ b/components/camel-spring-xml/src/test/resources/org/apache/camel/spring/processor/SpringSetVariablesTest-context.xml @@ -0,0 +1,44 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<beans xmlns="http://www.springframework.org/schema/beans" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation=" + http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + "> + + <!-- START SNIPPET: example --> + <camelContext xmlns="http://camel.apache.org/schema/spring"> + <jmxAgent id="jmx" disabled="true"/> + <route> + <from uri="seda:a"/> + <setVariables> + <setVariable name="myVar"> + <simple>Hello ${body}</simple> + </setVariable> + <setVariable name="myOtherVar"> + <simple>Bye ${body}</simple> + </setVariable> + </setVariables> + <to uri="mock:b"/> + </route> + </camelContext> + <!-- END SNIPPET: example --> +</beans> diff --git a/core/camel-xml-io/src/test/resources/routeWithSetVariables.xml b/core/camel-xml-io/src/test/resources/routeWithSetVariables.xml new file mode 100644 index 00000000000..03d6298f2fa --- /dev/null +++ b/core/camel-xml-io/src/test/resources/routeWithSetVariables.xml @@ -0,0 +1,32 @@ +<?xml version="1.0" encoding="UTF-8"?> +<!-- + + Licensed to the Apache Software Foundation (ASF) under one or more + contributor license agreements. See the NOTICE file distributed with + this work for additional information regarding copyright ownership. + The ASF licenses this file to You under the Apache License, Version 2.0 + (the "License"); you may not use this file except in compliance with + the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License is distributed on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + See the License for the specific language governing permissions and + limitations under the License. + +--> +<routes id="camel" xmlns="http://camel.apache.org/schema/spring"> + <route> + <from uri="seda:a"/> + <setVariables> + <setVariable name="myVar1"> + <simple>${body}</simple> + </setVariable> + <setVariable name="myVar2"> + <xpath>/value2</xpath> + </setVariable> + </setVariables> + </route> +</routes>