diff --git a/guides/integration_testing_using_arquillian_cube.textile b/guides/integration_testing_using_arquillian_cube.textile new file mode 100644 index 00000000000..60ab4895515 --- /dev/null +++ b/guides/integration_testing_using_arquillian_cube.textile @@ -0,0 +1,183 @@ +--- +layout: guide +title: Integration Testing using Arquillian Cube +authors: [dipak-pawar] +tags: [openshift] +description: Learn How to write integration tests for openshift using Arquillian Cube. +guide_group: 2 +guide_order: 4 +--- +[maven_download]http://maven.apache.org/download.html +[jdk_download]http://www.oracle.com/technetwork/java/javase/downloads + +This guide introduces you to Arquillian Cube. After reading this guide, you’ll be able to: + +* Write an Arquillian test which deploys your application on openshift cluster and verify your application. +* Execute an Integration Test in both Maven and IDE using arquillian configuration. + +You'll learn how to write an integration test for Openshift using Arquillian Cube and it's configuration. + +h3. Assumptions + +This guide assumes you have openshift cluster up and running. If you don't please download and install "minishift":https://docs.openshift.org/latest/minishift/getting-started/installing.html. Also make sure you have Maven available, either in your command shell or your IDE(Integrated Development Environment). If you don't, please "download and install Maven now":maven_download. You'll also need "JDK(Java Development Kit) 1.8":jdk_download installed on your machine. + +h3. Application Under Testing + +In order to write an Arquillian Cube Integration Test, you need to have a application for it. Let's take a clone of sample "spring boot application":https://github.com/dipak-pawar/arquillian-cube-openshift-ftest which we are going to use in this guide. + +bc(command).. git clone https://github.com/dipak-pawar/arquillian-cube-openshift-ftest + +h3. Setting Dependencies and Plugin Configurations + +Go ahead and open up the @pom.xml@ in your editor. Add following dependencies in pom.xml inside @@ section. + +bc(prettify). + org.arquillian.cube + arquillian-cube-openshift-starter # <1> + ${version.arquillian.cube} + test + + + io.rest-assured + rest-assured # <2> + ${version.restassured} + test + + + junit + junit # <3> + ${version.junit} + test + + +<1> Cube openshift dependency for standalone mode. +<2> Validate interesting things from response. +<3> Unit Testing Framework. + + +Add @Maven@ profile with "fabric8-maven-plugin":https://maven.fabric8.io/ configuration as follows: + +bc(prettify). + + openshift + + + + io.fabric8 + fabric8-maven-plugin + ${version.fabric8.maven.plugin} + + + + resource + build + + + + + + + + + +Add "Failsafe Plugin":http://maven.apache.org/surefire/maven-failsafe-plugin and it's configuration to run integration tests. + +bc(prettify). + org.apache.maven.plugins + maven-failsafe-plugin + ${version.failsafe.plugin} + + + + integration-test + verify + + + + + + +You can find entire @pom.xml@ "here":https://raw.githubusercontent.com/dipak-pawar/arquillian-cube-openshift-ftest/integration_test/pom.xml. + +h3. Write Integration Test + +Once all dependency and plugin configuration is set, you are ready to write Integration Test. In your IDE, create a new Java class named @OpenshiftIT@ in the @org.arquillian.cube@ package. Add following code in it. + +div(filename). src/test/java/org/arquillian/cube/OpenshiftIT.java + +bc(prettify).. package org.arquillian.cube; + +import io.restassured.RestAssured; +import java.net.URL; +import org.arquillian.cube.openshift.impl.enricher.AwaitRoute; +import org.arquillian.cube.openshift.impl.enricher.RouteURL; +import org.jboss.arquillian.junit.Arquillian; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; + +import static io.restassured.RestAssured.when; +import static org.hamcrest.CoreMatchers.containsString; + +@RunWith(Arquillian.class) +public class OpenshiftIT { + + @AwaitRoute + @RouteURL("${app.name}") #<1> + private URL baseURL; + + @Before + public void setup() throws Exception { + RestAssured.baseURI = baseURL.toString(); + } + + @Test + public void testGreetingEndpoint() { + when() + .get() + .then() + .statusCode(200) + .body(containsString("Greetings from Spring Boot!")); + } +} + +p. <1> To Resolve @${app.name}@, you have to set @app.name@ either using system property or environment variable or arquillian.xml properties. + +h3. Creating Arquillian Configuration for Integration Test + +Below snippet shows how to set Arquillian configuration for your integration test. + +div(filename). src/test/resources/arquillian.xml + +bc(prettify). + + true #<1> + true #<2> + false #<3> + arquillian-cube-openshift-ftest #<4> + true #<5> + openshift #<6> + + + +<1> Use current namespace for this test. +<2> Initialize environment (apply kubernetes resources). +<3> Disable detecting ImageStream resources located at @target/*-is.json@. +<4> Resolve @@RouteUrl@ expression used in injecting baseUrl for your application. +<5> Execute fabric8-maven-plugin goal @mvn package fabric8:build fabric8:resource -Dfabric8.namespace=${namespace_configured_to_use_in_test}@ during test execution from @IDE@. +<6> Enable profile with @fabric8-maven-plugin@ configuration. + +h3. Run Integration Test + +1. To Run integration test from Maven + +bc(command). mvn clean install -Popenshift + +2. To run the same test from @IDE@ simply select @Run as JUnit Test@ option. + +h3. What's Next + +You can find full source code with application and integration test "here":https://github.com/dipak-pawar/arquillian-cube-openshift-ftest/tree/integration_test. Similarly, you can write integration tests for @Vert.x@, @Wildfly Swarm@ applications. + +You can find more examples "here":https://github.com/arquillian/arquillian-cube/tree/master/openshift.