mirror of
https://github.com/spring-projects/spring-petclinic.git
synced 2025-07-21 23:05:50 +00:00
Added tests and selenium.
This commit is contained in:
parent
9f3a641789
commit
974db5aafe
6 changed files with 328 additions and 2 deletions
46
pom.xml
46
pom.xml
|
@ -10,7 +10,7 @@
|
||||||
<parent>
|
<parent>
|
||||||
<groupId>org.springframework.boot</groupId>
|
<groupId>org.springframework.boot</groupId>
|
||||||
<artifactId>spring-boot-starter-parent</artifactId>
|
<artifactId>spring-boot-starter-parent</artifactId>
|
||||||
<version>2.1.6.RELEASE</version>
|
<version>2.2.2.RELEASE</version>
|
||||||
</parent>
|
</parent>
|
||||||
<name>petclinic</name>
|
<name>petclinic</name>
|
||||||
|
|
||||||
|
@ -108,6 +108,11 @@
|
||||||
<artifactId>spring-boot-devtools</artifactId>
|
<artifactId>spring-boot-devtools</artifactId>
|
||||||
<optional>true</optional>
|
<optional>true</optional>
|
||||||
</dependency>
|
</dependency>
|
||||||
|
|
||||||
|
<dependency>
|
||||||
|
<groupId>org.seleniumhq.selenium</groupId>
|
||||||
|
<artifactId>selenium-java</artifactId>
|
||||||
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
|
|
||||||
<build>
|
<build>
|
||||||
|
@ -208,9 +213,48 @@
|
||||||
</dependency>
|
</dependency>
|
||||||
</dependencies>
|
</dependencies>
|
||||||
</plugin>
|
</plugin>
|
||||||
|
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-surefire-plugin</artifactId>
|
||||||
|
<configuration>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/integration/*</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
</plugin>
|
||||||
</plugins>
|
</plugins>
|
||||||
</build>
|
</build>
|
||||||
|
|
||||||
|
<profiles>
|
||||||
|
<profile>
|
||||||
|
<id>failsafe</id>
|
||||||
|
<build>
|
||||||
|
<plugins>
|
||||||
|
<plugin>
|
||||||
|
<artifactId>maven-failsafe-plugin</artifactId>
|
||||||
|
<version>2.22.0</version>
|
||||||
|
<configuration>
|
||||||
|
<includes>
|
||||||
|
<include>**/integration/*</include>
|
||||||
|
</includes>
|
||||||
|
<excludes>
|
||||||
|
<exclude>**/test/*</exclude>
|
||||||
|
</excludes>
|
||||||
|
</configuration>
|
||||||
|
<executions>
|
||||||
|
<execution>
|
||||||
|
<goals>
|
||||||
|
<goal>integration-test</goal>
|
||||||
|
<goal>verify</goal>
|
||||||
|
</goals>
|
||||||
|
</execution>
|
||||||
|
</executions>
|
||||||
|
</plugin>
|
||||||
|
</plugins>
|
||||||
|
</build>
|
||||||
|
</profile>
|
||||||
|
</profiles>
|
||||||
|
|
||||||
<!-- Apache 2 license -->
|
<!-- Apache 2 license -->
|
||||||
<licenses>
|
<licenses>
|
||||||
<license>
|
<license>
|
||||||
|
|
116
resources/app-template.yaml
Normal file
116
resources/app-template.yaml
Normal file
|
@ -0,0 +1,116 @@
|
||||||
|
kind: Template
|
||||||
|
apiVersion: v1
|
||||||
|
metadata:
|
||||||
|
name: app-template
|
||||||
|
annotations:
|
||||||
|
openshift.io/display-name: "Demo App Example: Front End App"
|
||||||
|
description: >-
|
||||||
|
Front End App
|
||||||
|
openshift.io/long-description: >-
|
||||||
|
This template defines resources needed to deploy a simple demo app.
|
||||||
|
tags: "quickstart,java,demo"
|
||||||
|
iconClass: icon-openjdk
|
||||||
|
openshift.io/provider-display-name: "Nobody, Inc."
|
||||||
|
openshift.io/documentation-url: "https://github.com/pittar/ocp-devops-setup"
|
||||||
|
openshift.io/support-url: "https://google.ca"
|
||||||
|
message: "Your app is being instantiated."
|
||||||
|
labels:
|
||||||
|
template: "demo-app-frontend-template"
|
||||||
|
app: "demo-app-frontend"
|
||||||
|
objects:
|
||||||
|
- apiVersion: apps.openshift.io/v1
|
||||||
|
kind: DeploymentConfig
|
||||||
|
metadata:
|
||||||
|
name: frontend
|
||||||
|
spec:
|
||||||
|
replicas: 1
|
||||||
|
revisionHistoryLimit: 10
|
||||||
|
selector:
|
||||||
|
deploymentConfig: frontend
|
||||||
|
strategy:
|
||||||
|
activeDeadlineSeconds: 21600
|
||||||
|
resources: {}
|
||||||
|
rollingParams:
|
||||||
|
intervalSeconds: 1
|
||||||
|
maxSurge: 25%
|
||||||
|
maxUnavailable: 25%
|
||||||
|
timeoutSeconds: 600
|
||||||
|
updatePeriodSeconds: 1
|
||||||
|
type: Rolling
|
||||||
|
template:
|
||||||
|
metadata:
|
||||||
|
labels:
|
||||||
|
deploymentConfig: frontend
|
||||||
|
name: frontend
|
||||||
|
spec:
|
||||||
|
containers:
|
||||||
|
- name: frontend
|
||||||
|
envFrom:
|
||||||
|
- configMapRef:
|
||||||
|
name: frontend-cm
|
||||||
|
imagePullPolicy: Always
|
||||||
|
ports:
|
||||||
|
- containerPort: 8778
|
||||||
|
name: jolokia
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 8080
|
||||||
|
name: http
|
||||||
|
protocol: TCP
|
||||||
|
- containerPort: 8443
|
||||||
|
name: https
|
||||||
|
protocol: TCP
|
||||||
|
resources: {}
|
||||||
|
terminationMessagePath: /dev/termination-log
|
||||||
|
terminationMessagePolicy: File
|
||||||
|
dnsPolicy: ClusterFirst
|
||||||
|
restartPolicy: Always
|
||||||
|
schedulerName: default-scheduler
|
||||||
|
securityContext: {}
|
||||||
|
terminationGracePeriodSeconds: 75
|
||||||
|
test: false
|
||||||
|
triggers:
|
||||||
|
- imageChangeParams:
|
||||||
|
automatic: false
|
||||||
|
containerNames:
|
||||||
|
- frontend
|
||||||
|
from:
|
||||||
|
kind: ImageStreamTag
|
||||||
|
name: ${IMAGE_NAME}:${IMAGE_TAG}
|
||||||
|
namespace: cicd
|
||||||
|
type: ImageChange
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: Service
|
||||||
|
metadata:
|
||||||
|
name: frontend
|
||||||
|
spec:
|
||||||
|
ports:
|
||||||
|
- port: 8080
|
||||||
|
protocol: TCP
|
||||||
|
targetPort: 8080
|
||||||
|
selector:
|
||||||
|
deploymentConfig: frontend
|
||||||
|
sessionAffinity: None
|
||||||
|
type: ClusterIP
|
||||||
|
status:
|
||||||
|
loadBalancer: {}
|
||||||
|
- apiVersion: route.openshift.io/v1
|
||||||
|
kind: Route
|
||||||
|
metadata:
|
||||||
|
name: frontend
|
||||||
|
spec:
|
||||||
|
to:
|
||||||
|
kind: Service
|
||||||
|
name: frontend
|
||||||
|
weight: 100
|
||||||
|
wildcardPolicy: None
|
||||||
|
parameters:
|
||||||
|
- name: IMAGE_NAME
|
||||||
|
displayName: Frontend image
|
||||||
|
description: The frontend image to use.
|
||||||
|
value: frontend
|
||||||
|
required: true
|
||||||
|
- name: IMAGE_TAG
|
||||||
|
displayName: Frontend image tag
|
||||||
|
description: The tag (version) of the frontend image to use.
|
||||||
|
value: latest
|
||||||
|
required: true
|
95
resources/build-template.yaml
Normal file
95
resources/build-template.yaml
Normal file
|
@ -0,0 +1,95 @@
|
||||||
|
apiVersion: v1
|
||||||
|
kind: Template
|
||||||
|
metadata:
|
||||||
|
name: jenkins-java-pipeline
|
||||||
|
parameters:
|
||||||
|
- name: APP_NAME
|
||||||
|
description: Name of the container to build.
|
||||||
|
displayName: Application container name.
|
||||||
|
required: true
|
||||||
|
- name: GIT_SOURCE_URL
|
||||||
|
description: The source URL for the application
|
||||||
|
displayName: Source URL
|
||||||
|
required: true
|
||||||
|
- name: GIT_SOURCE_REF
|
||||||
|
description: The source Ref for the application
|
||||||
|
displayName: Source Ref
|
||||||
|
required: true
|
||||||
|
value: master
|
||||||
|
- description: Github trigger secret. A difficult to guess string encoded as part of the webhook URL. Not encrypted.
|
||||||
|
displayName: GitHub Webhook Secret
|
||||||
|
from: '[a-zA-Z0-9]{40}'
|
||||||
|
generate: expression
|
||||||
|
name: GITHUB_WEBHOOK_SECRET
|
||||||
|
required: true
|
||||||
|
- description: A secret string used to configure the Generic webhook.
|
||||||
|
displayName: Generic Webhook Secret
|
||||||
|
from: '[a-zA-Z0-9]{40}'
|
||||||
|
generate: expression
|
||||||
|
name: GENERIC_WEBHOOK_SECRET
|
||||||
|
required: true
|
||||||
|
labels:
|
||||||
|
template: "demo-app-build-template"
|
||||||
|
app: "demo-app-build"
|
||||||
|
objects:
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: ImageStream
|
||||||
|
metadata:
|
||||||
|
name: ${APP_NAME}
|
||||||
|
spec: {}
|
||||||
|
status:
|
||||||
|
dockerImageRepository: ""
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: BuildConfig
|
||||||
|
metadata:
|
||||||
|
creationTimestamp: null
|
||||||
|
labels:
|
||||||
|
name: ${APP_NAME}
|
||||||
|
name: ${APP_NAME}
|
||||||
|
spec:
|
||||||
|
strategy:
|
||||||
|
jenkinsPipelineStrategy:
|
||||||
|
jenkinsfilePath: Jenkinsfile
|
||||||
|
env:
|
||||||
|
- name: APP_NAME
|
||||||
|
value: ${APP_NAME}
|
||||||
|
- name: GIT_SOURCE_URL
|
||||||
|
value: ${GIT_SOURCE_URL}
|
||||||
|
- name: GIT_SOURCE_REF
|
||||||
|
value: ${GIT_SOURCE_REF}
|
||||||
|
type: JenkinsPipeline
|
||||||
|
source:
|
||||||
|
git:
|
||||||
|
uri: "${GIT_SOURCE_URL}"
|
||||||
|
ref: "${GIT_SOURCE_REF}"
|
||||||
|
type: "Git"
|
||||||
|
triggers:
|
||||||
|
- github:
|
||||||
|
secret: "${GITHUB_WEBHOOK_SECRET}"
|
||||||
|
type: GitHub
|
||||||
|
- generic:
|
||||||
|
secret: "${GENERIC_WEBHOOK_SECRET}"
|
||||||
|
type: Generic
|
||||||
|
- apiVersion: v1
|
||||||
|
kind: BuildConfig
|
||||||
|
metadata:
|
||||||
|
name: "${APP_NAME}-build"
|
||||||
|
spec:
|
||||||
|
output:
|
||||||
|
to:
|
||||||
|
kind: ImageStreamTag
|
||||||
|
name: ${APP_NAME}:latest
|
||||||
|
postCommit: {}
|
||||||
|
resources: {}
|
||||||
|
runPolicy: Serial
|
||||||
|
source:
|
||||||
|
binary: {}
|
||||||
|
type: Binary
|
||||||
|
strategy:
|
||||||
|
sourceStrategy:
|
||||||
|
from:
|
||||||
|
kind: ImageStreamTag
|
||||||
|
name: redhat-openjdk18-openshift:1.4
|
||||||
|
namespace: openshift
|
||||||
|
type: Source
|
||||||
|
triggers: []
|
|
@ -4,7 +4,7 @@
|
||||||
|
|
||||||
<body>
|
<body>
|
||||||
|
|
||||||
<h2>Welcome to the Pet Clinic!</h2>
|
<h2 id="welcome">Welcome to the Pet Clinic!</h2>
|
||||||
<div class="row">
|
<div class="row">
|
||||||
<div class="col-md-12">
|
<div class="col-md-12">
|
||||||
<img class="img-responsive" src="../static/resources/images/pets.png" th:src="@{/resources/images/pets.png}"/>
|
<img class="img-responsive" src="../static/resources/images/pets.png" th:src="@{/resources/images/pets.png}"/>
|
||||||
|
|
45
src/test/java/integration/MainPageIT.java
Normal file
45
src/test/java/integration/MainPageIT.java
Normal file
|
@ -0,0 +1,45 @@
|
||||||
|
package integration;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertEquals;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
|
||||||
|
import org.junit.After;
|
||||||
|
import org.junit.Test;
|
||||||
|
import org.openqa.selenium.By;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
|
||||||
|
public class MainPageIT {
|
||||||
|
|
||||||
|
private SeleniumConfig config;
|
||||||
|
private String url = "http://app-petclinic-dev.apps.cluster-ottawa-630b.ottawa-630b.example.opentlc.com/";
|
||||||
|
|
||||||
|
public MainPageIT() throws MalformedURLException {
|
||||||
|
config = new SeleniumConfig();
|
||||||
|
}
|
||||||
|
|
||||||
|
public String getTitle() {
|
||||||
|
return this.config.getDriver().getTitle();
|
||||||
|
}
|
||||||
|
|
||||||
|
@After
|
||||||
|
public void closeConnection() {
|
||||||
|
config.getDriver().quit();
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void googleTitleIT() {
|
||||||
|
WebDriver driver = config.getDriver();
|
||||||
|
driver.get(url);
|
||||||
|
assertEquals("Title not as expected: ", "PetClinic :: a Spring Framework demonstration", getTitle());
|
||||||
|
// Save the random value from the page.
|
||||||
|
String welcomeText = driver.findElement(By.id("welcome")).getText();
|
||||||
|
// Reload the page and get a new random value.
|
||||||
|
driver.get(url);
|
||||||
|
String value2 = driver.findElement(By.id("random-value")).getText();
|
||||||
|
// Values should not be the same.
|
||||||
|
assertEquals("Wrong welcome text.", "Welcome to the Pet Clinic!", welcomeText);
|
||||||
|
System.out.println("Text extracted: " + welcomeText);
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
26
src/test/java/integration/SeleniumConfig.java
Normal file
26
src/test/java/integration/SeleniumConfig.java
Normal file
|
@ -0,0 +1,26 @@
|
||||||
|
package integration;
|
||||||
|
|
||||||
|
import java.net.MalformedURLException;
|
||||||
|
import java.net.URL;
|
||||||
|
import java.util.concurrent.TimeUnit;
|
||||||
|
|
||||||
|
import org.openqa.selenium.Capabilities;
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
|
||||||
|
public class SeleniumConfig {
|
||||||
|
private WebDriver driver;
|
||||||
|
|
||||||
|
public SeleniumConfig() throws MalformedURLException {
|
||||||
|
Capabilities capabilities = new FirefoxOptions();
|
||||||
|
driver = new RemoteWebDriver(
|
||||||
|
new URL("http://selenium-hub-cicd.apps.cluster-ottawa-630b.ottawa-630b.example.opentlc.com/wd/hub"),
|
||||||
|
capabilities);
|
||||||
|
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
|
||||||
|
}
|
||||||
|
|
||||||
|
public WebDriver getDriver() {
|
||||||
|
return driver;
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in a new issue