Brought to you by Henryk Konsek / @hekonsek
my-project
my-project-services
my-project-routes
...
my-project-bundle
my-project-itest
@RunWith(PaxExam.class)
public class MyKarafTest extends Assert {
@Inject
MyOsgiService myOsgiService;
@Configuration
public Option[] configuration() {
...
}
@Test
public void shouldReturnResponse() {
...
}
}
@Configuration
public Option[] configuration() {
return new Option[]{
karafDistributionConfiguration()
.frameworkUrl(
maven().groupId("org.apache.karaf").artifactId("apache-karaf")
.type("zip").version("2.3.3")).
karafVersion("2.3.3").name("Apache Karaf")
.unpackDirectory(new File("target/pax"))
.useDeployFolder(false), keepRuntimeFolder(),
configureConsole().ignoreLocalConsole().ignoreRemoteShell(),
mavenBundle().groupId("com.example").artifactId("my-project-bundle").
versionAsInProject()};
}
@RunWith(PaxExam.class)
public class MyKarafTest extends Assert {
@Inject
MyOsgiService myOsgiService;
@Configuration
public Option[] configuration() {
...
}
@Test
public void shouldReturnResponse() {
assertEquals("Hello!", myOsgiService.helloWorld());
}
}
@RunWith(PaxExam.class)
public class MyDeployedCamelTest extends Assert {
@Inject
CamelContext camelContext;
@Configuration
public Option[] configuration() {...}
@Test
public void shouldReturnResponse() {
String response = camelContext.createProducerTemplate().
requestBody("jms:queue", "msg", String.class);
assertEquals("Hello!", response);
}
}
<repositories>
<repository>
<id>jboss-fuse-ea</id>
<url>https://repository.jboss.org/nexus/content/groups/ea</url>
</repository>
</repositories>
Engineering guys deploy here.
<properties> <fabric-version>1.0.0.redhat-340</fabric-version> </properties>
Pick up some bleeding edge yet stable version of Fabric test API.
<dependency>
<groupid>io.fabric8</groupid>
<artifactid>fabric8-karaf</artifactid>
<version>${fabric-version}</version>
<type>zip</type>
</dependency>
Download Fabric distribution.
<dependency>
<groupid>io.fabric8.itests</groupid>
<artifactid>fabric-itests-common</artifactid>
<version>${fabric-version}</version>
</dependency>
Include Fabric test API (and nothing more!).
public class NettyHttpRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("netty-http:http://localhost:18080/").
setBody().constant("Hello world!");
}
}
import io.fabric8.itests.paxexam.support.FabricTestSupport;
...
@RunWith(JUnit4TestRunner.class)
@ExamReactorStrategy(AllConfinedStagedReactorFactory.class)
public class SimpleFabricTest extends FabricTestSupport {
@Configuration
public Option[] config() {
return new Option[]{
new DefaultCompositeOption(fabricDistributionConfiguration()),
mavenBundle("commons-io", "commons-io").versionAsInProject()
};
}
...
}
import static java.lang.System.err;
@Test
public void shouldCreateCamelRouter() throws Exception {
err.println(executeCommand("fabric:create -n"));
err.println(executeCommand("fabric:profile-create " +
"--parents feature-camel netty-http-server"));
err.println(executeCommand("fabric:profile-edit " +
"--features camel-netty-http netty-http-server"));
err.println(executeCommand("fabric:profile-edit --bundles " +
"mvn:com.example/my-project-bundle/1.0-SNAPSHOT netty-http-server"));
ContainerBuilder.create().
withName("router-container").withProfiles("netty-http-server").
assertProvisioningResult().build();
// ... assertions
}
@Test
public void shouldCreateCamelRouter() throws Exception {
// ... creating container
InputStream inputStream =
new URL("http://localhost:18080/").openStream();
String response = IOUtils.toString(inputStream);
assertEquals("Hello world!", response);
}
fabric:create -n Using specified zookeeper password:admin fabric:profile-create --parents feature-camel netty-http-server fabric:profile-edit --features camel-netty-http netty-http-server Adding feature:camel-netty-http to profile:netty-http-server version:1.0 fabric:profile-edit --bundles ... netty-http-server Adding bundle:mvn:... to profile:netty-http-server version:1.0 Waiting for containers: [ router-container1 ] to successfully provision Container:router-container1 Alive:false Status: SSH URL:null Container:router-container1 Alive:true Status:analyzing SSH URL:... Container:router-container1 Alive:true Status:downloading SSH URL:... Container:router-container1 Alive:true Status:finalizing SSH URL:... Container:router-container1 Alive:true Status:success SSH URL:...
Container container = (Container) create().withName("router-container").
withProfiles("netty-http-server").
assertProvisioningResult().build().iterator().next();
String[] containerSshUrl = container.getSshUrl().split(":");
String containerHost = containerSshUrl[0];
String containerPort = containerSshUrl[1];
String bundlesOnContainer = executeCommand(format(
"ssh -l %s -P %s -p %s %s osgi:list",
"admin", "admin", containerPort, containerHost
));
assertTrue(bundlesOnContainer.contains("camel-netty-http"));
public class MasterRoute extends RouteBuilder {
@Override
public void configure() throws Exception {
from("master:netty-master:netty-http:http://localhost:18081/").
setBody().constant("master");
}
}
fabric:create -n fabric:profile-create --parents feature-camel master-netty fabric:profile-edit --features camel-netty-http master-netty fabric:profile-edit --bundles mvn:com.example/my-project-bundle/1.0-SNAPSHOT master-netty
Container master = ContainerBuilder.create().
withName("master").withProfiles("master-netty").
assertProvisioningResult().build();
InputStream inputStream =
new URL("http://localhost:18081/").openStream();
String response = IOUtils.toString(inputStream);
assertEquals("master", response);
Container slave = ContainerBuilder.create().
withName("slave").withProfiles("master-netty").
assertProvisioningResult().build();
Container master = ...;
...
master.destroy();
InputStream inputStream =
new URL("http://localhost:18081/").openStream();
String response = IOUtils.toString(inputStream);
assertEquals("master", response);
https://github.com/hekonsek/fuse-pocs/tree/master/fuse-pocs-fabric