From 20228c1e9c8d2cb3cd005fa801f2c5ed69c22380 Mon Sep 17 00:00:00 2001 From: Dipak Pawar Date: Tue, 3 Apr 2018 19:11:29 +0530 Subject: [PATCH 1/2] docs: add guide for writing integration tests --- ...tion_testing_using_arquillian_cube.textile | 166 ++++++++++++++++++ 1 file changed, 166 insertions(+) create mode 100644 guides/integration_testing_using_arquillian_cube.textile diff --git a/guides/integration_testing_using_arquillian_cube.textile b/guides/integration_testing_using_arquillian_cube.textile new file mode 100644 index 00000000000..c814b6f97bb --- /dev/null +++ b/guides/integration_testing_using_arquillian_cube.textile @@ -0,0 +1,166 @@ +In this guide, we'll walk you through sample Spring Boot application to demonstrate how to write an integration test for Openshift using Arquillian Cube. + +h4. Prerequisites + +Take a clone of sample "spring boot application":https://github.com/dipak-pawar/arquillian-cube-openshift-ftest used in this guide. + +bc(bash).. git clone https://github.com/dipak-pawar/arquillian-cube-openshift-ftest + +h3. Setting Dependencies and Plugin Configurations + +* Ensure that @version.arquillian.cube@ >= @1.15.3@ +* Ensure following dependencies are added in pom.xml + + +bc(xml).. + 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 + + + +bc. <1> Cube openshift dependency for standalone mode. +<2> Validate interesting things from response. +<3> Unit Testing Framework. + + +* Ensure Maven profile with "fabric8-maven-plugin":https://maven.fabric8.io/ configuration is included as follows: + +bc(xml). + + openshift + + + + io.fabric8 + fabric8-maven-plugin + ${version.fabric8.maven.plugin} + + + + resource + build + + + + + + + + + +* Make sure to include "Failsafe Plugin":http://maven.apache.org/surefire/maven-failsafe-plugin and it's configuration to run integration tests. + +bc(xml). + 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. Integration Test Example + +Once all dependency and plugin configuration is set, you are ready to write Integration Test. + +The following example illustrates how to write integration test using Arquillian Cube for Openshift. + +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. Setting 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(xml). + + 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 + +* To Run integration test from Maven + +bc(bash). mvn clean install -Popenshift + +* To run the same test from @IDE@ simply select @Run as JUnit Test@ option. + +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. From 51490c1d800ca990d21b74ea226edd78e9d3ff92 Mon Sep 17 00:00:00 2001 From: Dipak Pawar Date: Wed, 4 Apr 2018 21:42:28 +0530 Subject: [PATCH 2/2] chore: update guide with formatting and missing content --- ...tion_testing_using_arquillian_cube.textile | 73 ++++++++++++------- 1 file changed, 45 insertions(+), 28 deletions(-) diff --git a/guides/integration_testing_using_arquillian_cube.textile b/guides/integration_testing_using_arquillian_cube.textile index c814b6f97bb..60ab4895515 100644 --- a/guides/integration_testing_using_arquillian_cube.textile +++ b/guides/integration_testing_using_arquillian_cube.textile @@ -1,18 +1,37 @@ -In this guide, we'll walk you through sample Spring Boot application to demonstrate how to write an integration test for Openshift using Arquillian Cube. +--- +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 -h4. Prerequisites +This guide introduces you to Arquillian Cube. After reading this guide, you’ll be able to: -Take a clone of sample "spring boot application":https://github.com/dipak-pawar/arquillian-cube-openshift-ftest used in this guide. +* 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. -bc(bash).. git clone https://github.com/dipak-pawar/arquillian-cube-openshift-ftest +You'll learn how to write an integration test for Openshift using Arquillian Cube and it's configuration. -h3. Setting Dependencies and Plugin Configurations +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 -* Ensure that @version.arquillian.cube@ >= @1.15.3@ -* Ensure following dependencies are added in pom.xml +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 -bc(xml).. +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} @@ -31,15 +50,14 @@ bc(xml).. test - -bc. <1> Cube openshift dependency for standalone mode. +<1> Cube openshift dependency for standalone mode. <2> Validate interesting things from response. <3> Unit Testing Framework. -* Ensure Maven profile with "fabric8-maven-plugin":https://maven.fabric8.io/ configuration is included as follows: +Add @Maven@ profile with "fabric8-maven-plugin":https://maven.fabric8.io/ configuration as follows: -bc(xml). +bc(prettify). openshift @@ -62,9 +80,9 @@ bc(xml). -* Make sure to include "Failsafe Plugin":http://maven.apache.org/surefire/maven-failsafe-plugin and it's configuration to run integration tests. +Add "Failsafe Plugin":http://maven.apache.org/surefire/maven-failsafe-plugin and it's configuration to run integration tests. -bc(xml). +bc(prettify). org.apache.maven.plugins maven-failsafe-plugin ${version.failsafe.plugin} @@ -79,13 +97,11 @@ bc(xml). -You can find entire @pom.xml@ "here":https://raw.githubusercontent.com/dipak-pawar/arquillian-cube-openshift-ftest/integration_test/pom.xml +You can find entire @pom.xml@ "here":https://raw.githubusercontent.com/dipak-pawar/arquillian-cube-openshift-ftest/integration_test/pom.xml. -h3. Integration Test Example +h3. Write Integration Test -Once all dependency and plugin configuration is set, you are ready to write Integration Test. - -The following example illustrates how to write integration test using Arquillian Cube for Openshift. +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 @@ -125,16 +141,15 @@ public class OpenshiftIT { } } -p. -<1> To Resolve @${app.name}@, you have to set @app.name@ either using @system property@ or @environment variable@ or @arquillian.xml properties@ +p. <1> To Resolve @${app.name}@, you have to set @app.name@ either using system property or environment variable or arquillian.xml properties. -h3. Setting Arquillian Configuration for Integration Test +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(xml). true #<1> @@ -155,12 +170,14 @@ bc(xml).