Skip to content

Commit 1d9c947

Browse files
authored
Ref apache#489: Add camel-exec integration test (apache#490)
1 parent d9935ac commit 1d9c947

File tree

4 files changed

+136
-0
lines changed

4 files changed

+136
-0
lines changed

tests/features/camel-exec/pom.xml

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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"
21+
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
22+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
23+
<modelVersion>4.0.0</modelVersion>
24+
<parent>
25+
<groupId>org.apache.camel.karaf</groupId>
26+
<artifactId>camel-karaf-features-test</artifactId>
27+
<version>4.7.0-SNAPSHOT</version>
28+
</parent>
29+
30+
<artifactId>camel-exec-test</artifactId>
31+
<name>Apache Camel :: Karaf :: Tests :: Features :: Exec</name>
32+
33+
<dependencies>
34+
<dependency>
35+
<groupId>org.apache.camel</groupId>
36+
<artifactId>camel-exec</artifactId>
37+
<version>${camel-version}</version>
38+
</dependency>
39+
</dependencies>
40+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
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+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.apache.karaf.camel.test;
17+
18+
import org.apache.camel.builder.RouteBuilder;
19+
import org.apache.camel.model.RouteDefinition;
20+
import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteSupplier;
21+
import org.osgi.service.component.annotations.Component;
22+
23+
@Component(
24+
name = "karaf-camel-exec-test",
25+
immediate = true,
26+
service = CamelExecRouteSupplier.class
27+
)
28+
public class CamelExecRouteSupplier extends AbstractCamelSingleFeatureResultMockBasedRouteSupplier {
29+
30+
@Override
31+
protected boolean consumerEnabled() {
32+
return false;
33+
}
34+
35+
@Override
36+
protected void configureProducer(RouteBuilder builder, RouteDefinition producerRoute) {
37+
configureConsumer(producerRoute.to("exec:java?args=-server -version"));
38+
}
39+
}
40+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
1+
/*
2+
* Licensed under the Apache License, Version 2.0 (the "License");
3+
* you may not use this file except in compliance with the License.
4+
* You may obtain a copy of the License at
5+
*
6+
* http://www.apache.org/licenses/LICENSE-2.0
7+
*
8+
* Unless required by applicable law or agreed to in writing, software
9+
* distributed under the License is distributed on an "AS IS" BASIS,
10+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
11+
* See the License for the specific language governing permissions and
12+
* limitations under the License.
13+
*/
14+
package org.apache.karaf.camel.itest;
15+
16+
import java.io.IOException;
17+
18+
import org.apache.camel.Exchange;
19+
import org.apache.camel.Predicate;
20+
import org.apache.camel.component.exec.ExecResult;
21+
import org.apache.camel.component.mock.MockEndpoint;
22+
import org.apache.karaf.camel.itests.AbstractCamelSingleFeatureResultMockBasedRouteITest;
23+
import org.apache.karaf.camel.itests.PaxExamWithExternalResource;
24+
import org.junit.Test;
25+
import org.junit.runner.RunWith;
26+
import org.ops4j.pax.exam.spi.reactors.ExamReactorStrategy;
27+
import org.ops4j.pax.exam.spi.reactors.PerClass;
28+
29+
@RunWith(PaxExamWithExternalResource.class)
30+
@ExamReactorStrategy(PerClass.class)
31+
public class CamelExecITest extends AbstractCamelSingleFeatureResultMockBasedRouteITest {
32+
33+
@Override
34+
public void configureMock(MockEndpoint mock) {
35+
mock.expectedMessageCount(1);
36+
mock.expectedMessagesMatches(new Predicate() {
37+
38+
@Override
39+
public boolean matches(Exchange exchange) {
40+
ExecResult execResult = exchange.getIn().getBody(ExecResult.class);
41+
try {
42+
String out = new String(execResult.getStderr().readAllBytes());
43+
return out.contains("Server VM") && execResult.getExitValue() == 0;
44+
} catch (IOException e) {
45+
return false;
46+
}
47+
}
48+
});
49+
}
50+
51+
@Test
52+
public void testResultMock() throws Exception {
53+
assertMockEndpointsSatisfied();
54+
}
55+
}

tests/features/pom.xml

+1
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,7 @@
7272
<module>camel-drill</module>
7373
<module>camel-ehcache</module>
7474
<module>camel-elasticsearch</module>
75+
<module>camel-exec</module>
7576
<module>camel-fastjson</module>
7677
<module>camel-flatpack</module>
7778
<module>camel-ftp</module>

0 commit comments

Comments
 (0)