From 186fde09edaa87b3c06a6bab8d29384f5251b832 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Tue, 20 Jun 2017 09:25:44 +0200 Subject: [PATCH 01/39] Docker configuration --- Dockerfile | 17 +++++++++++++++++ docker-compose.yml | 27 ++++++++++++++++++--------- 2 files changed, 35 insertions(+), 9 deletions(-) create mode 100644 Dockerfile diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 000000000..a1c890445 --- /dev/null +++ b/Dockerfile @@ -0,0 +1,17 @@ +FROM maven:latest + +# Set the workdir +WORKDIR /app + +# Copy the source to the container +COPY . . + +# Build the project +RUN mvn package + +# Make the jar executable +RUN sh -c 'touch target/spring-petclinic-*.jar' + +#Start the project +ENV JAVA_OPTS="" +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/spring-petclinic-*.jar" ] \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 1631ec9fa..b2c662c3f 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,9 +1,18 @@ -mysql: - image: mysql - ports: - - "3306:3306" - environment: - - MYSQL_ROOT_PASSWORD=root - - MYSQL_DATABASE=test - volumes: - - "./conf.d:/etc/mysql/conf.d:ro" \ No newline at end of file +version: '2' +services: + pet-clinic: + build: . + ports: + - "8080:8080" + links: + - mysql:mysql + command: java -jar ./target/*.jar + mysql: + image: mysql + ports: + - "3306:3306" + environment: + - MYSQL_ROOT_PASSWORD=root + - MYSQL_DATABASE=test + volumes: + - "./conf.d:/etc/mysql/conf.d:ro" \ No newline at end of file From 677296a44cc5e6b0b11b3bff5b37d42a484c237a Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 10:26:22 +0200 Subject: [PATCH 02/39] added sonarqube to travis --- .travis.yml | 9 +++++++++ 1 file changed, 9 insertions(+) diff --git a/.travis.yml b/.travis.yml index c0f28cfa4..84f4ec761 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,2 +1,11 @@ language: java jdk: oraclejdk8 + +addons: + sonarqube: + organization: "ihristovut-github" # the key of the org you chose at step #3 + token: + secure: fbc9e4a5677933a0f017872ab5d09baf6e3d48fd # encrypted value of your token +script: + # the following command line builds the project, runs the tests with coverage and then execute the SonarQube analysis + - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar From a71b15ef66f1c9b08ef647dc6b053be46c35e9f8 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 12:17:56 +0200 Subject: [PATCH 03/39] fix encrypted key and script using the sonar-project.properties --- .travis.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index 84f4ec761..73393029a 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,7 +5,6 @@ addons: sonarqube: organization: "ihristovut-github" # the key of the org you chose at step #3 token: - secure: fbc9e4a5677933a0f017872ab5d09baf6e3d48fd # encrypted value of your token + secure: IxpxC2EWCn1I6Ru6rV8yo47peEJ9Jj4HCsLYjsGNpcdOWhJ/VCAPxMKdf0TYw8Im6Xd/3IV+8B7DbY3UhDFhUOhdQLLaOdM1lVQWq4kooZluUQFTpcAvs/1tNoyAYHJkdqj9A+eJCNUz4pJPko+RmpuSAdt9FumJRbOk0V7nVpwQkq110JLmPfwPg207lkAqwvsTu32Ur3y9Tga8sBKq7FOOAk7wiuXoAlITZj72ZXxNXnrcGqx3GEduD4a+rlb/Gh0dGvprLi74AWORy/avvd6XWItLgesSc2Bw98JCpQQjUZC0IEgDT4usK9pdWXbvfMH/jRLa/K4i/qrSWpUNHVVVC/znW1tCfPD0Vmwo6IX3u49FBe7UqrstbZHFsyUPhOHtp9p4T9SQ9JMEAEY581SDwis4PE4xVSWaXxHJcWUbZhplVj+xwyC83hZeOr6mKPxZZOw6TaJyg+OahzZQ8qv+Gkl+zPs8yRz72iBAnIyIe+X8rkO9cC6aSVbsRDAikh/i+/DkXYJ2Q/DSMbx1wK7LBKwwCLgMH9UpX80bIRstDKyE0+v8VfvpMMNClmokFOmlLsHb5uJmJ/VXDPuLuTYk2UzR4fHWjdi7dL9gBNVviiUOd7wGC8JepIc/+xZS9lzNUu8bY3XNZaaSiFTwy/moUZhrgpOoTj/IL8BfamU= # encrypted value of your token script: - # the following command line builds the project, runs the tests with coverage and then execute the SonarQube analysis - - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar + - sonar-scanner From 5c6a158c88e3bdf90a15a0447cc30e85790a2a0c Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 14:56:38 +0200 Subject: [PATCH 04/39] wrong key again --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 73393029a..4ed88aa60 100644 --- a/.travis.yml +++ b/.travis.yml @@ -5,6 +5,6 @@ addons: sonarqube: organization: "ihristovut-github" # the key of the org you chose at step #3 token: - secure: IxpxC2EWCn1I6Ru6rV8yo47peEJ9Jj4HCsLYjsGNpcdOWhJ/VCAPxMKdf0TYw8Im6Xd/3IV+8B7DbY3UhDFhUOhdQLLaOdM1lVQWq4kooZluUQFTpcAvs/1tNoyAYHJkdqj9A+eJCNUz4pJPko+RmpuSAdt9FumJRbOk0V7nVpwQkq110JLmPfwPg207lkAqwvsTu32Ur3y9Tga8sBKq7FOOAk7wiuXoAlITZj72ZXxNXnrcGqx3GEduD4a+rlb/Gh0dGvprLi74AWORy/avvd6XWItLgesSc2Bw98JCpQQjUZC0IEgDT4usK9pdWXbvfMH/jRLa/K4i/qrSWpUNHVVVC/znW1tCfPD0Vmwo6IX3u49FBe7UqrstbZHFsyUPhOHtp9p4T9SQ9JMEAEY581SDwis4PE4xVSWaXxHJcWUbZhplVj+xwyC83hZeOr6mKPxZZOw6TaJyg+OahzZQ8qv+Gkl+zPs8yRz72iBAnIyIe+X8rkO9cC6aSVbsRDAikh/i+/DkXYJ2Q/DSMbx1wK7LBKwwCLgMH9UpX80bIRstDKyE0+v8VfvpMMNClmokFOmlLsHb5uJmJ/VXDPuLuTYk2UzR4fHWjdi7dL9gBNVviiUOd7wGC8JepIc/+xZS9lzNUu8bY3XNZaaSiFTwy/moUZhrgpOoTj/IL8BfamU= # encrypted value of your token + secure: "CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8=" script: - sonar-scanner From 312f3ddfaf4dc82b28219266fcd88f02084ff63b Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:16:09 +0200 Subject: [PATCH 05/39] trying travis env variable --- .travis.yml | 7 +++---- 1 file changed, 3 insertions(+), 4 deletions(-) diff --git a/.travis.yml b/.travis.yml index 4ed88aa60..4a67dc043 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,10 +1,9 @@ language: java jdk: oraclejdk8 - addons: sonarqube: - organization: "ihristovut-github" # the key of the org you chose at step #3 + organization: ihristovut-github token: - secure: "CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8=" + secure: $SONAR_TOKEN script: - - sonar-scanner +- sonar-scanner From d21aa773cc4a5ab44aebd3d15d4da5a223d6d976 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:21:27 +0200 Subject: [PATCH 06/39] removed travis env --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index 4a67dc043..e5a55f31c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,6 +4,6 @@ addons: sonarqube: organization: ihristovut-github token: - secure: $SONAR_TOKEN + secure: CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8= script: - sonar-scanner From 47c3da4c5bfdcc3a1d45be2fd7d818cb3b807864 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:31:27 +0200 Subject: [PATCH 07/39] key in quotes --- .travis.yml | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/.travis.yml b/.travis.yml index e5a55f31c..8856f0ce6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -1,9 +1,14 @@ language: java -jdk: oraclejdk8 +sudo: false +install: true + addons: sonarqube: - organization: ihristovut-github + organization: "ihristovut-github" token: - secure: CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8= + secure: "CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8=" + +jdk: oraclejdk8 + script: - sonar-scanner From 43b19acb6215a2d2f429f81247c67517bb275c41 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:37:43 +0200 Subject: [PATCH 08/39] added credentials in property file --- sonar-project.properties | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/sonar-project.properties b/sonar-project.properties index d84ed7c2d..30d6dbb0c 100755 --- a/sonar-project.properties +++ b/sonar-project.properties @@ -10,4 +10,7 @@ sonar.sources=src sonar.language=java # Encoding of the source files -sonar.sourceEncoding=UTF-8 \ No newline at end of file +sonar.sourceEncoding=UTF-8 + +sonar.organization=ihristovut-github +sonar.login=CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8= From 2b0bdec90251e01f1862c8a958d9701c20100a22 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:44:08 +0200 Subject: [PATCH 09/39] test env var again --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 8856f0ce6..a3f15b4ca 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,9 @@ addons: sonarqube: organization: "ihristovut-github" token: - secure: "CqXf1kvNas7kaHHD3TKCcVrAL//0kdYsg/EjVphwABi7JsKILKGHSPiu4JZNG0fQf9DQZpAMBolTnVEyBC89sCR2NalML0m+MZZzBeihvnhqo8wETWoyGvnkPrLe9WILiZBK591qOVRoyipWMqYacyiV42mDpJjTcMJf1HkDPDxcD7kCQTw6qo3TLXbpphR8Y8LeZMDsty0HxPc02QtKS5kOTCiW7NljKWXdnsNDc2ZrGQDj7zVNRsYZ5ULgH8Psi06I7vC2HS9/o7QJcc42nRcoFzkGjVxWEBYPS9r11GQoUM+FwRCL/CKGv2Xzw2H7h/5zrJ89A0ZxHyHR4fKQTv4MRkCHj5WIMSL9a9K1E6nnP9Rk6OTzbKAr+iPt1IMRvU5lxsEzy5yZwOaGw9t6ebtdo8PB6IxVeNVwsg2rFTjeB+G/ct6eOnCU8Kd9yB5WAeA2ySZf9qBIjHKReq1fS9pI9/ps+85a+irW8Ei6TSD3JFWI6wkWPAG00NErWmeWN1AWWgmR16u8uXMQxQcCHRUs1To5aNV4HsNtCqbZOMe8VtH6MF0Yir2vVLG7Ljes5Il1hp2Qhsqxqv2aWmgbtiM6yobJTUMYpZLVuXml5RDoq72b+wgJduH7gwy0H0FzvRQKn+NTEDcKeEt06nI0U42F8mb6TDYeSQsF038rDs8=" + secure: SONAR_TOKEN jdk: oraclejdk8 script: -- sonar-scanner +- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar From 61b20d2a23e20636863d13b684d847143687099a Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 20 Jun 2017 15:53:15 +0200 Subject: [PATCH 10/39] whoops --- .travis.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a3f15b4ca..b82faef95 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,7 +6,7 @@ addons: sonarqube: organization: "ihristovut-github" token: - secure: SONAR_TOKEN + secure: $SONAR_TOKEN jdk: oraclejdk8 From 116bb97970791d5cb60f1caa9a0d420f494a48d8 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 10:33:52 +0200 Subject: [PATCH 11/39] new token --- .travis.yml | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index b82faef95..07333ce38 100644 --- a/.travis.yml +++ b/.travis.yml @@ -6,9 +6,14 @@ addons: sonarqube: organization: "ihristovut-github" token: - secure: $SONAR_TOKEN + secure: "MP10DlQtkxqjU+wU70/Y178YOq5cBC9bx0xVsew8gsNwqrRPj6SSXLQBd9WCTIfDd2uuE6rHplTbwFIEjIoPZ3Kv8DyyDaqcT2J0Pjfxah4yueB1FXZL4OLgV41f/0OE4DKRIrB7URHfGhIc0z7lxslI3l3Q0yM9v8v3sjX8OLbt4C3UkPnOW6+ad+YX8BoS4bhp+U2IodQfWuKg9HSEdaAwB37bW+WDzHECKc4B4V4kl0eoDvItz5L8UJ3c0cuhe545Xe1Kx3i8zsxluJQae3sqxnaZFfEHGQBYVZ4MLp1FJIX1RBIevBJLv7+AeoUxBd6ZNFNqPFkUKvSpSFBOEIRQU61VXmxDonPniTx5zMMGZl1g4v3tlUQIy2ISfkHmwZBhVazx59wSJ7id2zS+qvfxQJOU/UPUxbqzPq+6b+uRo0g982ORECC4w1iO0ocYGs6RAZ/LNwWNg1hl28EqpPaE93tGgqu+S6gVkDBmVd/ByE/uCPBTZNkL5YGbF7C0Xoe+HZ2GYhb65mzIwjjuCVoo8WrW35/ruBSa/EnCwDpIh34CPnEVlIYkCtCSseBW7jJD94MIY7h6jLcHfuydeSlDfXL0qbDx3YTxE19cKLM8akbxoZ4LYejQPvdSP4FPdyx7bgw2mmSDbmVEPe59OL+hNgDXQbOP2ccWVVYRyo0=" jdk: oraclejdk8 script: -- mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar + - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar + +cache: + directories: + - '$HOME/.m2/repository' + - '$HOME/.sonar/cache' From d129f24d9f1c8aa84000c06d2a8536f23e60ff66 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 11:26:42 +0200 Subject: [PATCH 12/39] changed organization --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 07333ce38..e55f2b2b6 100644 --- a/.travis.yml +++ b/.travis.yml @@ -3,8 +3,8 @@ sudo: false install: true addons: - sonarqube: - organization: "ihristovut-github" + sonarcloud: + organization: "nqkavkey" token: secure: "MP10DlQtkxqjU+wU70/Y178YOq5cBC9bx0xVsew8gsNwqrRPj6SSXLQBd9WCTIfDd2uuE6rHplTbwFIEjIoPZ3Kv8DyyDaqcT2J0Pjfxah4yueB1FXZL4OLgV41f/0OE4DKRIrB7URHfGhIc0z7lxslI3l3Q0yM9v8v3sjX8OLbt4C3UkPnOW6+ad+YX8BoS4bhp+U2IodQfWuKg9HSEdaAwB37bW+WDzHECKc4B4V4kl0eoDvItz5L8UJ3c0cuhe545Xe1Kx3i8zsxluJQae3sqxnaZFfEHGQBYVZ4MLp1FJIX1RBIevBJLv7+AeoUxBd6ZNFNqPFkUKvSpSFBOEIRQU61VXmxDonPniTx5zMMGZl1g4v3tlUQIy2ISfkHmwZBhVazx59wSJ7id2zS+qvfxQJOU/UPUxbqzPq+6b+uRo0g982ORECC4w1iO0ocYGs6RAZ/LNwWNg1hl28EqpPaE93tGgqu+S6gVkDBmVd/ByE/uCPBTZNkL5YGbF7C0Xoe+HZ2GYhb65mzIwjjuCVoo8WrW35/ruBSa/EnCwDpIh34CPnEVlIYkCtCSseBW7jJD94MIY7h6jLcHfuydeSlDfXL0qbDx3YTxE19cKLM8akbxoZ4LYejQPvdSP4FPdyx7bgw2mmSDbmVEPe59OL+hNgDXQbOP2ccWVVYRyo0=" From 1260b6ec5fa776bb920b09af18f8bcdde9791003 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 11:32:14 +0200 Subject: [PATCH 13/39] Add selenium and two selenium tests to the project --- docker-compose.yml | 8 +- pom.xml | 444 +++++++++--------- .../utwente/bpsd/selenium/AddOwnerTest.java | 47 ++ .../utwente/bpsd/selenium/FindOwnerTest.java | 30 ++ .../bpsd/selenium/SeleniumBaseTest.java | 43 ++ 5 files changed, 353 insertions(+), 219 deletions(-) create mode 100644 src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java create mode 100644 src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java create mode 100644 src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java diff --git a/docker-compose.yml b/docker-compose.yml index b2c662c3f..73da6f62a 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -6,6 +6,7 @@ services: - "8080:8080" links: - mysql:mysql + - selenium command: java -jar ./target/*.jar mysql: image: mysql @@ -15,4 +16,9 @@ services: - MYSQL_ROOT_PASSWORD=root - MYSQL_DATABASE=test volumes: - - "./conf.d:/etc/mysql/conf.d:ro" \ No newline at end of file + - "./conf.d:/etc/mysql/conf.d:ro" + selenium: + image: selenium/standalone-firefox + shm_size: 2g + ports: + - "4444:4444" diff --git a/pom.xml b/pom.xml index ff677d097..757c84577 100644 --- a/pom.xml +++ b/pom.xml @@ -1,229 +1,237 @@ - 4.0.0 - org.springframework.samples - spring-petclinic - 1.5.1 + xmlns="http://maven.apache.org/POM/4.0.0" + xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> + 4.0.0 + org.springframework.samples + spring-petclinic + 1.5.1 - - org.springframework.boot - spring-boot-starter-parent - 1.5.1.RELEASE - - petclinic - - - - - 1.8 - UTF-8 - UTF-8 - - - 3.3.6 - 1.11.4 - 2.2.4 - 1.8.0 - - 3.0.2.RELEASE - - 2.7 - - - - - - - org.springframework.boot - spring-boot-starter-actuator - - - org.springframework.boot - spring-boot-starter-cache - - - org.springframework.boot - spring-boot-starter-data-jpa - - - org.springframework.boot - spring-boot-starter-web - - - org.springframework.boot - spring-boot-starter-thymeleaf - - - nz.net.ultraq.thymeleaf - thymeleaf-layout-dialect - - - - - org.springframework.boot - spring-boot-starter-test - test - - - - - org.hsqldb - hsqldb - runtime - - - mysql - mysql-connector-java - runtime - - - - - javax.cache - cache-api - - - org.ehcache - ehcache - - - - - org.webjars - webjars-locator - - - org.webjars - jquery - ${webjars-jquery.version} - - - org.webjars - jquery-ui - ${webjars-jquery-ui.version} - - - org.webjars - bootstrap - ${webjars-bootstrap.version} - - - - - org.springframework.boot - spring-boot-devtools - runtime - - - - - - + org.springframework.boot - spring-boot-maven-plugin - - - - - build-info - - - - ${project.build.sourceEncoding} - ${project.reporting.outputEncoding} - ${maven.compiler.source} - ${maven.compiler.target} - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - - - - - clean - check - - - - + spring-boot-starter-parent + 1.5.1.RELEASE + + petclinic - - - pl.project13.maven - git-commit-id-plugin - - - - revision - - - - - true - yyyy-MM-dd'T'HH:mm:ssZ - true - ${project.build.outputDirectory}/git.properties - - false - - + - - ro.isdc.wro4j - wro4j-maven-plugin - ${wro4j.version} - - - generate-resources - - run - - - - - ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory - ${project.build.directory}/classes/static/resources/css - ${basedir}/src/main/wro/wro.xml - ${basedir}/src/main/wro/wro.properties - ${basedir}/src/main/less - - - + + 1.8 + UTF-8 + UTF-8 + + + 3.3.6 + 1.11.4 + 2.2.4 + 1.8.0 + + 3.0.2.RELEASE + + 2.7 + + 3.4.0 + + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-cache + + + org.springframework.boot + spring-boot-starter-data-jpa + + + org.springframework.boot + spring-boot-starter-web + + + org.springframework.boot + spring-boot-starter-thymeleaf + + + nz.net.ultraq.thymeleaf + thymeleaf-layout-dialect + + + + + org.springframework.boot + spring-boot-starter-test + test + + + + + org.hsqldb + hsqldb + runtime + + + mysql + mysql-connector-java + runtime + + + + + javax.cache + cache-api + + + org.ehcache + ehcache + + + + + org.webjars + webjars-locator + + + org.webjars + jquery + ${webjars-jquery.version} + + + org.webjars + jquery-ui + ${webjars-jquery-ui.version} + + org.webjars bootstrap ${webjars-bootstrap.version} - - - - - - - - - - org.codehaus.mojo - cobertura-maven-plugin - ${cobertura.version} - - - html - - - - - - + + + + + org.springframework.boot + spring-boot-devtools + runtime + + + + + org.seleniumhq.selenium + selenium-java + ${selenium-java.version} + + + + + + + org.springframework.boot + spring-boot-maven-plugin + + + + + build-info + + + + ${project.build.sourceEncoding} + ${project.reporting.outputEncoding} + ${maven.compiler.source} + ${maven.compiler.target} + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + + + + + clean + check + + + + + + + + pl.project13.maven + git-commit-id-plugin + + + + revision + + + + + true + yyyy-MM-dd'T'HH:mm:ssZ + true + ${project.build.outputDirectory}/git.properties + + false + + + + + ro.isdc.wro4j + wro4j-maven-plugin + ${wro4j.version} + + + generate-resources + + run + + + + + ro.isdc.wro.maven.plugin.manager.factory.ConfigurableWroManagerFactory + ${project.build.directory}/classes/static/resources/css + ${basedir}/src/main/wro/wro.xml + ${basedir}/src/main/wro/wro.properties + ${basedir}/src/main/less + + + + org.webjars + bootstrap + ${webjars-bootstrap.version} + + + + + + + + + + org.codehaus.mojo + cobertura-maven-plugin + ${cobertura.version} + + + html + + + + + + diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java new file mode 100644 index 000000000..888e501c3 --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java @@ -0,0 +1,47 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.MalformedURLException; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class AddOwnerTest extends SeleniumBaseTest { + public AddOwnerTest() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseTest.class) + public void addOwnerTest() { + driver.get(BASE_URL+"/owners/new"); + + //Add an owner + fillTextField(By.name("firstName"), "Sophie"); + fillTextField(By.name("lastName"), "Lathouwers"); + fillTextField(By.name("address"), "Homeroad 12"); + fillTextField(By.name("city"), "Enschede"); + fillTextField(By.name("telephone"), "0534890000"); + driver.findElement(By.name("telephone")).submit(); + Assert.assertTrue(pageContainsText("Sophie Lathouwers")); + + //Add a pet + new WebDriverWait(driver, 3).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); + driver.findElement(By.linkText("Add New Pet")).click(); + fillTextField(By.name("name"), "Thumper"); + fillTextField(By.name("birthDate"), "1942/08/09"); + new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); + driver.findElement(By.name("name")).submit(); + + Assert.assertTrue(pageContainsText("Thumper")); + } + +} diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java new file mode 100644 index 000000000..ff6700f6d --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java @@ -0,0 +1,30 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.MalformedURLException; + +/** + * + * @author Martijn + * @since 21-6-2017. + */ +public class FindOwnerTest extends SeleniumBaseTest { + public FindOwnerTest() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseTest.class) + public void findOwnerTest() { + driver.get(BASE_URL+"/owners/find"); + fillTextField(By.name("lastName"),"Coleman"); + driver.findElement(By.name("lastName")).submit(); + Assert.assertTrue(driver.findElementsByXPath("//*[text()='Jean Coleman']").size() == 1); + } +} diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java new file mode 100644 index 000000000..8b72d1edf --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java @@ -0,0 +1,43 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.After; +import org.openqa.selenium.By; +import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.remote.DesiredCapabilities; +import org.openqa.selenium.remote.RemoteWebDriver; + +import java.net.MalformedURLException; +import java.net.URL; + +/** + * + * @author Martijn + * @since 21-6-2017. + */ +public class SeleniumBaseTest { + protected final RemoteWebDriver driver; + public static final String BASE_URL = "http://pet-clinic:8080/"; +// public static final String BASE_URL = "http://localhost:8080/"; + + public SeleniumBaseTest() throws MalformedURLException { +// System.setProperty("webdriver.chrome.driver","C:\\Users\\marti\\Downloads\\chromedriver_win32\\chromedriver.exe"); +// this.driver = new ChromeDriver(); + this.driver = new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox()); + driver.get(BASE_URL); + } + + public void fillTextField(By by, String text){ + driver.findElement(by).clear(); + driver.findElement(by).sendKeys(text); + } + + @After + public void afterTest() { + driver.close(); + } + + + protected boolean pageContainsText(String text) { + return driver.findElementsByXPath("//*[text()='"+text+"']").size() == 1; + } +} From 162f86302677ca10ed9617117670f2c938351eac Mon Sep 17 00:00:00 2001 From: Sophie Lathouwers Date: Wed, 21 Jun 2017 11:50:27 +0200 Subject: [PATCH 14/39] Added failing test and fixed spacing in docker-compose.yml --- docker-compose.yml | 10 +++---- .../nl/utwente/bpsd/selenium/FailingTest.java | 28 +++++++++++++++++++ 2 files changed, 33 insertions(+), 5 deletions(-) create mode 100644 src/test/java/nl/utwente/bpsd/selenium/FailingTest.java diff --git a/docker-compose.yml b/docker-compose.yml index 73da6f62a..bb5601aec 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -17,8 +17,8 @@ services: - MYSQL_DATABASE=test volumes: - "./conf.d:/etc/mysql/conf.d:ro" - selenium: - image: selenium/standalone-firefox - shm_size: 2g - ports: - - "4444:4444" + selenium: + image: selenium/standalone-firefox + shm_size: 2g + ports: + - "4444:4444" diff --git a/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java b/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java new file mode 100644 index 000000000..403e2ce71 --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java @@ -0,0 +1,28 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.Select; +import org.openqa.selenium.support.ui.WebDriverWait; + +import java.net.MalformedURLException; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class FailingTest extends SeleniumBaseTest { + public FailingTest() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseTest.class) + public void failTest() { + Assert.fail(); + } + +} From 3fffb7234e5d2feaacc745f5c9f9a1cdfd47eec9 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 13:02:23 +0200 Subject: [PATCH 15/39] Selenium now uses the failsafe plugin --- .travis.yml | 13 ++++++- Dockerfile | 34 +++++++++---------- pom.xml | 28 +++++++++++++++ .../{AddOwnerTest.java => AddOwnerIT.java} | 8 ++--- .../nl/utwente/bpsd/selenium/FailingIT.java | 26 ++++++++++++++ .../nl/utwente/bpsd/selenium/FailingTest.java | 28 --------------- .../{FindOwnerTest.java => FindOwnerIT.java} | 10 +++--- ...eniumBaseTest.java => SeleniumBaseIT.java} | 4 +-- 8 files changed, 93 insertions(+), 58 deletions(-) rename src/test/java/nl/utwente/bpsd/selenium/{AddOwnerTest.java => AddOwnerIT.java} (88%) create mode 100644 src/test/java/nl/utwente/bpsd/selenium/FailingIT.java delete mode 100644 src/test/java/nl/utwente/bpsd/selenium/FailingTest.java rename src/test/java/nl/utwente/bpsd/selenium/{FindOwnerTest.java => FindOwnerIT.java} (65%) rename src/test/java/nl/utwente/bpsd/selenium/{SeleniumBaseTest.java => SeleniumBaseIT.java} (92%) diff --git a/.travis.yml b/.travis.yml index e55f2b2b6..d0ad0d56f 100644 --- a/.travis.yml +++ b/.travis.yml @@ -10,8 +10,19 @@ addons: jdk: oraclejdk8 +install: + - docker-compose build + +before_script: + - docker-compose up -d + script: - - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar + - mvn verify -Dskip.surefire.tests +# - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar + +after_script: + - docker-compose stop + - docker-compose rm cache: directories: diff --git a/Dockerfile b/Dockerfile index a1c890445..d258da6b9 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,17 +1,17 @@ -FROM maven:latest - -# Set the workdir -WORKDIR /app - -# Copy the source to the container -COPY . . - -# Build the project -RUN mvn package - -# Make the jar executable -RUN sh -c 'touch target/spring-petclinic-*.jar' - -#Start the project -ENV JAVA_OPTS="" -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/spring-petclinic-*.jar" ] \ No newline at end of file +FROM maven:latest + +# Set the workdir +WORKDIR /app + +# Copy the source to the container +COPY . . + +# Build the project +RUN mvn package -Dskip.failsafe.tests + +# Make the jar executable +RUN sh -c 'touch target/spring-petclinic-*.jar' + +#Start the project +ENV JAVA_OPTS="" +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/spring-petclinic-*.jar" ] diff --git a/pom.xml b/pom.xml index 757c84577..a0b3f0eba 100644 --- a/pom.xml +++ b/pom.xml @@ -128,6 +128,34 @@ + + org.apache.maven.plugins + maven-surefire-plugin + + + ${skip.surefire.tests} + + + + org.apache.maven.plugins + maven-failsafe-plugin + + + ${skip.failsafe.tests} + + + + run-integration-tests + integration-test + + integration-test + verify + + + + org.springframework.boot spring-boot-maven-plugin diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java similarity index 88% rename from src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java rename to src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 888e501c3..de1dfaba9 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerTest.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -14,14 +14,14 @@ import java.net.MalformedURLException; * @author Martijn * @since 21-6-2017. */ -public class AddOwnerTest extends SeleniumBaseTest { - public AddOwnerTest() throws MalformedURLException { +public class AddOwnerIT extends SeleniumBaseIT { + public AddOwnerIT() throws MalformedURLException { super(); } @Test - @Category(SeleniumBaseTest.class) - public void addOwnerTest() { + @Category(SeleniumBaseIT.class) + public void addOwnerIT() { driver.get(BASE_URL+"/owners/new"); //Add an owner diff --git a/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java b/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java new file mode 100644 index 000000000..87a26e3ad --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java @@ -0,0 +1,26 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Ignore; +import org.junit.Test; +import org.junit.experimental.categories.Category; + +import java.net.MalformedURLException; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class FailingIT extends SeleniumBaseIT { + public FailingIT() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseIT.class) + @Ignore + public void failIT() { + Assert.fail(); + } + +} diff --git a/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java b/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java deleted file mode 100644 index 403e2ce71..000000000 --- a/src/test/java/nl/utwente/bpsd/selenium/FailingTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package nl.utwente.bpsd.selenium; - -import org.junit.Assert; -import org.junit.Test; -import org.junit.experimental.categories.Category; -import org.openqa.selenium.By; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.Select; -import org.openqa.selenium.support.ui.WebDriverWait; - -import java.net.MalformedURLException; - -/** - * @author Martijn - * @since 21-6-2017. - */ -public class FailingTest extends SeleniumBaseTest { - public FailingTest() throws MalformedURLException { - super(); - } - - @Test - @Category(SeleniumBaseTest.class) - public void failTest() { - Assert.fail(); - } - -} diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java similarity index 65% rename from src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java rename to src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java index ff6700f6d..17fcd7de4 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerTest.java +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java @@ -4,8 +4,6 @@ import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; import org.openqa.selenium.By; -import org.openqa.selenium.support.ui.ExpectedConditions; -import org.openqa.selenium.support.ui.WebDriverWait; import java.net.MalformedURLException; @@ -14,14 +12,14 @@ import java.net.MalformedURLException; * @author Martijn * @since 21-6-2017. */ -public class FindOwnerTest extends SeleniumBaseTest { - public FindOwnerTest() throws MalformedURLException { +public class FindOwnerIT extends SeleniumBaseIT { + public FindOwnerIT() throws MalformedURLException { super(); } @Test - @Category(SeleniumBaseTest.class) - public void findOwnerTest() { + @Category(SeleniumBaseIT.class) + public void findOwnerIT() { driver.get(BASE_URL+"/owners/find"); fillTextField(By.name("lastName"),"Coleman"); driver.findElement(By.name("lastName")).submit(); diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java similarity index 92% rename from src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java rename to src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index 8b72d1edf..d4f701966 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseTest.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -14,12 +14,12 @@ import java.net.URL; * @author Martijn * @since 21-6-2017. */ -public class SeleniumBaseTest { +public class SeleniumBaseIT { protected final RemoteWebDriver driver; public static final String BASE_URL = "http://pet-clinic:8080/"; // public static final String BASE_URL = "http://localhost:8080/"; - public SeleniumBaseTest() throws MalformedURLException { + public SeleniumBaseIT() throws MalformedURLException { // System.setProperty("webdriver.chrome.driver","C:\\Users\\marti\\Downloads\\chromedriver_win32\\chromedriver.exe"); // this.driver = new ChromeDriver(); this.driver = new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox()); From f80905648c40a026bcfa82b328ac07f29c432407 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 13:04:38 +0200 Subject: [PATCH 16/39] Add docker to the travis config --- .travis.yml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.travis.yml b/.travis.yml index d0ad0d56f..cb9f47b31 100644 --- a/.travis.yml +++ b/.travis.yml @@ -2,6 +2,9 @@ language: java sudo: false install: true +services: + - docker + addons: sonarcloud: organization: "nqkavkey" From 90d10b70430b050f2c2efd649a4033dbb9c4bf01 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 13:10:51 +0200 Subject: [PATCH 17/39] Remove mysql from the docker-compose file --- docker-compose.yml | 20 ++++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/docker-compose.yml b/docker-compose.yml index bb5601aec..fba4e9a6c 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,18 +5,18 @@ services: ports: - "8080:8080" links: - - mysql:mysql +# - mysql:mysql - selenium command: java -jar ./target/*.jar - mysql: - image: mysql - ports: - - "3306:3306" - environment: - - MYSQL_ROOT_PASSWORD=root - - MYSQL_DATABASE=test - volumes: - - "./conf.d:/etc/mysql/conf.d:ro" +# mysql: +# image: mysql +# ports: +# - "3306:3306" +# environment: +# - MYSQL_ROOT_PASSWORD=root +# - MYSQL_DATABASE=test +# volumes: +# - "./conf.d:/etc/mysql/conf.d:ro" selenium: image: selenium/standalone-firefox shm_size: 2g From f8f68bfb82b5bf3f0370d2f2e55ed24be85e2e4b Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 13:28:17 +0200 Subject: [PATCH 18/39] Make maven more quiet --- .travis.yml | 2 +- Dockerfile | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index cb9f47b31..be41421a1 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,7 @@ before_script: - docker-compose up -d script: - - mvn verify -Dskip.surefire.tests + - mvn verify -Dskip.surefire.tests -q --batch-mode # - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar after_script: diff --git a/Dockerfile b/Dockerfile index d258da6b9..e43802fb4 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,7 @@ WORKDIR /app COPY . . # Build the project -RUN mvn package -Dskip.failsafe.tests +RUN mvn package -Dskip.failsafe.tests -q --batch-mode # Make the jar executable RUN sh -c 'touch target/spring-petclinic-*.jar' From cb40c4276cdf795bddcb1f4e8809c31c1589900d Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 13:41:05 +0200 Subject: [PATCH 19/39] Run ITs in docker --- .travis.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index be41421a1..b800a7369 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,12 +20,12 @@ before_script: - docker-compose up -d script: - - mvn verify -Dskip.surefire.tests -q --batch-mode + - docker exec springpetclinic_pet-clinic_1 mvn verify -Dskip.surefire.tests -q --batch-mode # - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install sonar:sonar after_script: - docker-compose stop - - docker-compose rm + - docker-compose rm -f cache: directories: From a1de7e2ca39a315951b3737e757571b7ccf1125c Mon Sep 17 00:00:00 2001 From: Sophie Lathouwers Date: Wed, 21 Jun 2017 13:41:32 +0200 Subject: [PATCH 20/39] Renamed AddVisitTest to AddVisitIT --- .../nl/utwente/bpsd/selenium/AddVisitIT.java | 41 +++++++++++++++++++ 1 file changed, 41 insertions(+) create mode 100644 src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java new file mode 100644 index 000000000..c36098cda --- /dev/null +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -0,0 +1,41 @@ +package nl.utwente.bpsd.selenium; + +import org.junit.Assert; +import org.junit.Test; +import org.junit.experimental.categories.Category; +import org.openqa.selenium.By; +import org.openqa.selenium.WebElement; + +import java.net.MalformedURLException; +import java.util.List; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class AddVisitIT extends SeleniumBaseIT { + public AddVisitIT() throws MalformedURLException { + super(); + } + + @Test + @Category(SeleniumBaseIT.class) + public void addOwnerTest() { + driver.findElement(By.name("lastName")).submit(); + + //Go to first owner + WebElement table = driver.findElement(By.tagName("table")); + List cells = table.findElements(By.xpath("tr/td")); + cells.get(0).findElement(By.xpath("a")).click(); + + //Go to edit page of first pet + driver.findElement(By.xpath("//table//tr/td/table/tbody//a[text()='Edit Pet']")).click(); + + //Edit Name of pet + fillTextField(By.name("name"), "foobar"); + driver.findElement(By.name("name")).submit(); + + Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd/[contains(text(), 'foobar')]"))); + } + +} From 43b902a7a501178bc935fa5047910c097f377b40 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 13:45:35 +0200 Subject: [PATCH 21/39] fixed sonarqube groupid error and added new key --- .travis.yml | 4 ++-- pom.xml | 6 +++--- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.travis.yml b/.travis.yml index e55f2b2b6..f7d78f1a4 100644 --- a/.travis.yml +++ b/.travis.yml @@ -4,9 +4,9 @@ install: true addons: sonarcloud: - organization: "nqkavkey" + organization: "bpsdproject" token: - secure: "MP10DlQtkxqjU+wU70/Y178YOq5cBC9bx0xVsew8gsNwqrRPj6SSXLQBd9WCTIfDd2uuE6rHplTbwFIEjIoPZ3Kv8DyyDaqcT2J0Pjfxah4yueB1FXZL4OLgV41f/0OE4DKRIrB7URHfGhIc0z7lxslI3l3Q0yM9v8v3sjX8OLbt4C3UkPnOW6+ad+YX8BoS4bhp+U2IodQfWuKg9HSEdaAwB37bW+WDzHECKc4B4V4kl0eoDvItz5L8UJ3c0cuhe545Xe1Kx3i8zsxluJQae3sqxnaZFfEHGQBYVZ4MLp1FJIX1RBIevBJLv7+AeoUxBd6ZNFNqPFkUKvSpSFBOEIRQU61VXmxDonPniTx5zMMGZl1g4v3tlUQIy2ISfkHmwZBhVazx59wSJ7id2zS+qvfxQJOU/UPUxbqzPq+6b+uRo0g982ORECC4w1iO0ocYGs6RAZ/LNwWNg1hl28EqpPaE93tGgqu+S6gVkDBmVd/ByE/uCPBTZNkL5YGbF7C0Xoe+HZ2GYhb65mzIwjjuCVoo8WrW35/ruBSa/EnCwDpIh34CPnEVlIYkCtCSseBW7jJD94MIY7h6jLcHfuydeSlDfXL0qbDx3YTxE19cKLM8akbxoZ4LYejQPvdSP4FPdyx7bgw2mmSDbmVEPe59OL+hNgDXQbOP2ccWVVYRyo0=" + secure: "GBSEwXoZaohdFQyW5yJ3h6t8+HIztd+sEMS8jt10zo5tnenrGNv59YTl7B5VwxR2X/mJcdLsouR4z81TZfP4FX93NZAKwAdkj1d3yAyvEDYSlLywI7Xp3BGcO7Zc4mnHAU+yMhVI98Ww6C45OjirUgBT8STmjLTXk2yuA9T6IttwAmGdLzzzPjon710/6mIY3MzoqRpyhGhuJJjbJLA9BM5h1X79ikbOMk4e2ig3KaTIANS3oeCiQlNHgdikBZcsxow7qMXA5d8mgrBJnKH52EerLbMgVuKPBxdV+RMZQxOLZR6xzg5EQVUpoXCG8EqMbZw6lEdqfIYasm8EPQPaRM4fT6zIbJoQEFFXCIL1Wht7h0pO5RTavPE9jcpjni/QG+MAcr+v80/8RGOQ5MhQ/vF6T5DDf6J/03zAGX4LpPOb7s/8YuWWz+wB+uFYXsdZLOhFb8uuAyEiBzyXIn3ZgkLHxo57sGVgfSDiLgKGea7fIw+xN72JzTKts19jR1x+Sy6SvIgOJdjdmV+qzpbkn1nFtXo0t73RxwQkLLBx5hin02fEr1jWVXszVGCqKrxwglE0oTucMP6qtujMoqNo+eUUE064IAhRl9EPPcDMezctIKLp4vTUP3X5RCL1KRfE8uzeaY+Nnd+/DCh71Nhr4AHm570ISw6q7mKeStaB1dQ=" jdk: oraclejdk8 diff --git a/pom.xml b/pom.xml index ff677d097..747032c28 100644 --- a/pom.xml +++ b/pom.xml @@ -3,7 +3,7 @@ xmlns="http://maven.apache.org/POM/4.0.0" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"> 4.0.0 - org.springframework.samples + org.springframework.samples.bpsd spring-petclinic 1.5.1 @@ -125,7 +125,7 @@ spring-boot-maven-plugin - build-info @@ -158,7 +158,7 @@ - pl.project13.maven From d69f11b76f8609e1c31ea8ddd7db3ce3dc6afc53 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 14:43:48 +0200 Subject: [PATCH 22/39] Copy the jar to execute --- Dockerfile | 6 +++--- docker-compose.yml | 3 +-- 2 files changed, 4 insertions(+), 5 deletions(-) diff --git a/Dockerfile b/Dockerfile index e43802fb4..b7e4fc0c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,9 @@ COPY . . # Build the project RUN mvn package -Dskip.failsafe.tests -q --batch-mode -# Make the jar executable -RUN sh -c 'touch target/spring-petclinic-*.jar' +# Copy and make the jar executable +RUN sh -c 'cp target/spring-petclinic-*.jar app.jar && touch app.jar' #Start the project ENV JAVA_OPTS="" -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/spring-petclinic-*.jar" ] +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ] diff --git a/docker-compose.yml b/docker-compose.yml index fba4e9a6c..a3274a6d5 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -5,9 +5,8 @@ services: ports: - "8080:8080" links: -# - mysql:mysql - selenium - command: java -jar ./target/*.jar +# - mysql:mysql # mysql: # image: mysql # ports: From ed6c518f8672502390c61d751f40b6690d9fe53c Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 14:51:35 +0200 Subject: [PATCH 23/39] random change --- Dockerfile | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/Dockerfile b/Dockerfile index e43802fb4..b7e4fc0c8 100644 --- a/Dockerfile +++ b/Dockerfile @@ -9,9 +9,9 @@ COPY . . # Build the project RUN mvn package -Dskip.failsafe.tests -q --batch-mode -# Make the jar executable -RUN sh -c 'touch target/spring-petclinic-*.jar' +# Copy and make the jar executable +RUN sh -c 'cp target/spring-petclinic-*.jar app.jar && touch app.jar' #Start the project ENV JAVA_OPTS="" -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar target/spring-petclinic-*.jar" ] +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ] From c558caa5134eb0442f07942f95cf83915e6e79d3 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 15:48:01 +0200 Subject: [PATCH 24/39] added resources --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index b7e4fc0c8..30b1e5a6f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ COPY . . RUN mvn package -Dskip.failsafe.tests -q --batch-mode # Copy and make the jar executable -RUN sh -c 'cp target/spring-petclinic-*.jar app.jar && touch app.jar' +RUN sh -c 'cp -r target/ dist/ && touch dist/app.jar' #Start the project ENV JAVA_OPTS="" -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar app.jar" ] +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar dist/app.jar" ] From 29dc4b634f0162f318eb7a3ab1d98b64e4f92e9e Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 21 Jun 2017 16:07:51 +0200 Subject: [PATCH 25/39] fixed resources --- Dockerfile | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Dockerfile b/Dockerfile index 30b1e5a6f..68dfff9fe 100644 --- a/Dockerfile +++ b/Dockerfile @@ -10,8 +10,8 @@ COPY . . RUN mvn package -Dskip.failsafe.tests -q --batch-mode # Copy and make the jar executable -RUN sh -c 'cp -r target/ dist/ && touch dist/app.jar' +RUN sh -c 'mkdir dist/ && cp -a target/. dist/ && touch dist/spring-petclinic-*.jar' #Start the project ENV JAVA_OPTS="" -ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar dist/app.jar" ] +ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar dist/spring-petclinic-*.jar" ] From 99eb71c0cc9cf7a92754b1e149c8fedb376d9600 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 16:41:04 +0200 Subject: [PATCH 26/39] Refactor the code smells that were present according to SonarQube --- .../petclinic/PetClinicApplication.java | 4 +-- .../samples/petclinic/owner/Owner.java | 6 ++--- .../petclinic/owner/OwnerController.java | 6 ++--- .../petclinic/system/CrashController.java | 3 +-- .../petclinic/system/ExampleException.java | 15 +++++++++++ .../samples/petclinic/vet/VetController.java | 8 +++--- .../samples/petclinic/vet/VetRepository.java | 2 +- .../samples/petclinic/vet/Vets.java | 8 +++--- .../petclinic/visit/VisitRepository.java | 2 +- .../nl/utwente/bpsd/selenium/FailingIT.java | 26 ------------------- 10 files changed, 34 insertions(+), 46 deletions(-) create mode 100644 src/main/java/org/springframework/samples/petclinic/system/ExampleException.java delete mode 100644 src/test/java/nl/utwente/bpsd/selenium/FailingIT.java diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java index 224c326c7..5265770dc 100644 --- a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java +++ b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java @@ -21,14 +21,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; /** * PetClinic Spring Boot Application. - * + * * @author Dave Syer * */ @SpringBootApplication public class PetClinicApplication { - public static void main(String[] args) throws Exception { + public static void main(String[] args) { SpringApplication.run(PetClinicApplication.class, args); } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java index f6fcae7ac..e471b5c8a 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -126,13 +126,13 @@ public class Owner extends Person { * @param name to test * @return true if pet name is already in use */ - public Pet getPet(String name, boolean ignoreNew) { - name = name.toLowerCase(); + public Pet getPet(final String name, final boolean ignoreNew) { + String lowerCaseName = name.toLowerCase(); for (Pet pet : getPetsInternal()) { if (!ignoreNew || !pet.isNew()) { String compName = pet.getName(); compName = compName.toLowerCase(); - if (compName.equals(name)) { + if (compName.equals(lowerCaseName)) { return pet; } } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index ef3169b70..58be460a0 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -78,7 +78,7 @@ class OwnerController { } @RequestMapping(value = "/owners", method = RequestMethod.GET) - public String processFindForm(Owner owner, BindingResult result, Map model) { + public String processFindForm(final Owner owner, final BindingResult result, final Map model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { @@ -93,8 +93,8 @@ class OwnerController { return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found - owner = results.iterator().next(); - return "redirect:/owners/" + owner.getId(); + Owner founndOwner = results.iterator().next(); + return "redirect:/owners/" + founndOwner.getId(); } else { // multiple owners found model.put("selections", results); diff --git a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java index a702cfc8f..5fe9a3294 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java @@ -31,8 +31,7 @@ class CrashController { @RequestMapping(value = "/oups", method = RequestMethod.GET) public String triggerException() { - throw new RuntimeException( - "Expected: controller used to showcase what " + "happens when an exception is thrown"); + throw new ExampleException("Expected: controller used to showcase what happens when an exception is thrown"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java b/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java new file mode 100644 index 000000000..bcf5e2bdd --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java @@ -0,0 +1,15 @@ +package org.springframework.samples.petclinic.system; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class ExampleException extends RuntimeException { + public ExampleException(String message) { + super(ExampleException.class.getSimpleName() + ": " + message); + } + + protected ExampleException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(ExampleException.class.getSimpleName() + ": " + message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 8ddcca60a..7911aa702 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -31,11 +31,11 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller class VetController { - private final VetRepository vets; + private final VetRepository vetRepository; @Autowired public VetController(VetRepository clinicService) { - this.vets = clinicService; + this.vetRepository = clinicService; } @RequestMapping(value = { "/vets.html" }) @@ -43,7 +43,7 @@ class VetController { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for Object-Xml mapping Vets vets = new Vets(); - vets.getVetList().addAll(this.vets.findAll()); + vets.getVetList().addAll(this.vetRepository.findAll()); model.put("vets", vets); return "vets/vetList"; } @@ -53,7 +53,7 @@ class VetController { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for JSon/Object mapping Vets vets = new Vets(); - vets.getVetList().addAll(this.vets.findAll()); + vets.getVetList().addAll(this.vetRepository.findAll()); return vets; } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java index 20863ce76..bbe5d5fdd 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java @@ -40,7 +40,7 @@ public interface VetRepository extends Repository { */ @Transactional(readOnly = true) @Cacheable("vets") - Collection findAll() throws DataAccessException; + Collection findAll(); } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java index f5b24c3fc..152fa560e 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java @@ -30,14 +30,14 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Vets { - private List vets; + private List vetList; @XmlElement public List getVetList() { - if (vets == null) { - vets = new ArrayList<>(); + if (vetList == null) { + vetList = new ArrayList<>(); } - return vets; + return vetList; } } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java index c7853d170..d0c8d8c41 100644 --- a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java @@ -38,7 +38,7 @@ public interface VisitRepository extends Repository { * @param visit the Visit to save * @see BaseEntity#isNew */ - void save(Visit visit) throws DataAccessException; + void save(Visit visit); List findByPetId(Integer petId); diff --git a/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java b/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java deleted file mode 100644 index 87a26e3ad..000000000 --- a/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java +++ /dev/null @@ -1,26 +0,0 @@ -package nl.utwente.bpsd.selenium; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.net.MalformedURLException; - -/** - * @author Martijn - * @since 21-6-2017. - */ -public class FailingIT extends SeleniumBaseIT { - public FailingIT() throws MalformedURLException { - super(); - } - - @Test - @Category(SeleniumBaseIT.class) - @Ignore - public void failIT() { - Assert.fail(); - } - -} From 029fc4ec4e3e2754e523c957b33a1771eade187c Mon Sep 17 00:00:00 2001 From: Marty30 Date: Wed, 21 Jun 2017 16:41:04 +0200 Subject: [PATCH 27/39] Refactor the code smells that were present according to SonarQube --- .../petclinic/PetClinicApplication.java | 4 +-- .../samples/petclinic/owner/Owner.java | 6 ++--- .../petclinic/owner/OwnerController.java | 6 ++--- .../petclinic/system/CrashController.java | 3 +-- .../petclinic/system/ExampleException.java | 15 +++++++++++ .../samples/petclinic/vet/VetController.java | 8 +++--- .../samples/petclinic/vet/VetRepository.java | 3 +-- .../samples/petclinic/vet/Vets.java | 8 +++--- .../petclinic/visit/VisitRepository.java | 3 +-- .../nl/utwente/bpsd/selenium/FailingIT.java | 26 ------------------- 10 files changed, 34 insertions(+), 48 deletions(-) create mode 100644 src/main/java/org/springframework/samples/petclinic/system/ExampleException.java delete mode 100644 src/test/java/nl/utwente/bpsd/selenium/FailingIT.java diff --git a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java index 224c326c7..5265770dc 100644 --- a/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java +++ b/src/main/java/org/springframework/samples/petclinic/PetClinicApplication.java @@ -21,14 +21,14 @@ import org.springframework.boot.autoconfigure.SpringBootApplication; /** * PetClinic Spring Boot Application. - * + * * @author Dave Syer * */ @SpringBootApplication public class PetClinicApplication { - public static void main(String[] args) throws Exception { + public static void main(String[] args) { SpringApplication.run(PetClinicApplication.class, args); } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java index f6fcae7ac..e471b5c8a 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/Owner.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/Owner.java @@ -126,13 +126,13 @@ public class Owner extends Person { * @param name to test * @return true if pet name is already in use */ - public Pet getPet(String name, boolean ignoreNew) { - name = name.toLowerCase(); + public Pet getPet(final String name, final boolean ignoreNew) { + String lowerCaseName = name.toLowerCase(); for (Pet pet : getPetsInternal()) { if (!ignoreNew || !pet.isNew()) { String compName = pet.getName(); compName = compName.toLowerCase(); - if (compName.equals(name)) { + if (compName.equals(lowerCaseName)) { return pet; } } diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index ef3169b70..58be460a0 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -78,7 +78,7 @@ class OwnerController { } @RequestMapping(value = "/owners", method = RequestMethod.GET) - public String processFindForm(Owner owner, BindingResult result, Map model) { + public String processFindForm(final Owner owner, final BindingResult result, final Map model) { // allow parameterless GET request for /owners to return all records if (owner.getLastName() == null) { @@ -93,8 +93,8 @@ class OwnerController { return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found - owner = results.iterator().next(); - return "redirect:/owners/" + owner.getId(); + Owner founndOwner = results.iterator().next(); + return "redirect:/owners/" + founndOwner.getId(); } else { // multiple owners found model.put("selections", results); diff --git a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java index a702cfc8f..5fe9a3294 100644 --- a/src/main/java/org/springframework/samples/petclinic/system/CrashController.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CrashController.java @@ -31,8 +31,7 @@ class CrashController { @RequestMapping(value = "/oups", method = RequestMethod.GET) public String triggerException() { - throw new RuntimeException( - "Expected: controller used to showcase what " + "happens when an exception is thrown"); + throw new ExampleException("Expected: controller used to showcase what happens when an exception is thrown"); } } diff --git a/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java b/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java new file mode 100644 index 000000000..bcf5e2bdd --- /dev/null +++ b/src/main/java/org/springframework/samples/petclinic/system/ExampleException.java @@ -0,0 +1,15 @@ +package org.springframework.samples.petclinic.system; + +/** + * @author Martijn + * @since 21-6-2017. + */ +public class ExampleException extends RuntimeException { + public ExampleException(String message) { + super(ExampleException.class.getSimpleName() + ": " + message); + } + + protected ExampleException(String message, Throwable cause, boolean enableSuppression, boolean writableStackTrace) { + super(ExampleException.class.getSimpleName() + ": " + message, cause, enableSuppression, writableStackTrace); + } +} diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java index 8ddcca60a..7911aa702 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetController.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetController.java @@ -31,11 +31,11 @@ import org.springframework.web.bind.annotation.ResponseBody; @Controller class VetController { - private final VetRepository vets; + private final VetRepository vetRepository; @Autowired public VetController(VetRepository clinicService) { - this.vets = clinicService; + this.vetRepository = clinicService; } @RequestMapping(value = { "/vets.html" }) @@ -43,7 +43,7 @@ class VetController { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for Object-Xml mapping Vets vets = new Vets(); - vets.getVetList().addAll(this.vets.findAll()); + vets.getVetList().addAll(this.vetRepository.findAll()); model.put("vets", vets); return "vets/vetList"; } @@ -53,7 +53,7 @@ class VetController { // Here we are returning an object of type 'Vets' rather than a collection of Vet // objects so it is simpler for JSon/Object mapping Vets vets = new Vets(); - vets.getVetList().addAll(this.vets.findAll()); + vets.getVetList().addAll(this.vetRepository.findAll()); return vets; } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java index 20863ce76..15c4bf9ac 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/VetRepository.java @@ -18,7 +18,6 @@ package org.springframework.samples.petclinic.vet; import java.util.Collection; import org.springframework.cache.annotation.Cacheable; -import org.springframework.dao.DataAccessException; import org.springframework.data.repository.Repository; import org.springframework.transaction.annotation.Transactional; @@ -40,7 +39,7 @@ public interface VetRepository extends Repository { */ @Transactional(readOnly = true) @Cacheable("vets") - Collection findAll() throws DataAccessException; + Collection findAll(); } diff --git a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java index f5b24c3fc..152fa560e 100644 --- a/src/main/java/org/springframework/samples/petclinic/vet/Vets.java +++ b/src/main/java/org/springframework/samples/petclinic/vet/Vets.java @@ -30,14 +30,14 @@ import javax.xml.bind.annotation.XmlRootElement; @XmlRootElement public class Vets { - private List vets; + private List vetList; @XmlElement public List getVetList() { - if (vets == null) { - vets = new ArrayList<>(); + if (vetList == null) { + vetList = new ArrayList<>(); } - return vets; + return vetList; } } diff --git a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java index c7853d170..122599886 100644 --- a/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java +++ b/src/main/java/org/springframework/samples/petclinic/visit/VisitRepository.java @@ -17,7 +17,6 @@ package org.springframework.samples.petclinic.visit; import java.util.List; -import org.springframework.dao.DataAccessException; import org.springframework.data.repository.Repository; import org.springframework.samples.petclinic.model.BaseEntity; @@ -38,7 +37,7 @@ public interface VisitRepository extends Repository { * @param visit the Visit to save * @see BaseEntity#isNew */ - void save(Visit visit) throws DataAccessException; + void save(Visit visit); List findByPetId(Integer petId); diff --git a/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java b/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java deleted file mode 100644 index 87a26e3ad..000000000 --- a/src/test/java/nl/utwente/bpsd/selenium/FailingIT.java +++ /dev/null @@ -1,26 +0,0 @@ -package nl.utwente.bpsd.selenium; - -import org.junit.Assert; -import org.junit.Ignore; -import org.junit.Test; -import org.junit.experimental.categories.Category; - -import java.net.MalformedURLException; - -/** - * @author Martijn - * @since 21-6-2017. - */ -public class FailingIT extends SeleniumBaseIT { - public FailingIT() throws MalformedURLException { - super(); - } - - @Test - @Category(SeleniumBaseIT.class) - @Ignore - public void failIT() { - Assert.fail(); - } - -} From c4dd55342da6839ac2448914be3652a77337200a Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 13:37:43 +0200 Subject: [PATCH 28/39] Added more logging on the tests and added a wait --- .../nl/utwente/bpsd/selenium/AddOwnerIT.java | 2 + .../nl/utwente/bpsd/selenium/AddVisitIT.java | 4 +- .../nl/utwente/bpsd/selenium/FindOwnerIT.java | 5 +- .../utwente/bpsd/selenium/SeleniumBaseIT.java | 48 +++++++++++++++++-- 4 files changed, 52 insertions(+), 7 deletions(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index de1dfaba9..2bbba0077 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -41,7 +41,9 @@ public class AddOwnerIT extends SeleniumBaseIT { new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); driver.findElement(By.name("name")).submit(); + waitForPageToLoad(); Assert.assertTrue(pageContainsText("Thumper")); + setTestFinished(); } } diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java index c36098cda..cee199e50 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -22,7 +22,7 @@ public class AddVisitIT extends SeleniumBaseIT { @Category(SeleniumBaseIT.class) public void addOwnerTest() { driver.findElement(By.name("lastName")).submit(); - + //Go to first owner WebElement table = driver.findElement(By.tagName("table")); List cells = table.findElements(By.xpath("tr/td")); @@ -35,7 +35,9 @@ public class AddVisitIT extends SeleniumBaseIT { fillTextField(By.name("name"), "foobar"); driver.findElement(By.name("name")).submit(); + waitForPageToLoad(); Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd/[contains(text(), 'foobar')]"))); + setTestFinished(); } } diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java index 17fcd7de4..57da781d9 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java @@ -23,6 +23,9 @@ public class FindOwnerIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); fillTextField(By.name("lastName"),"Coleman"); driver.findElement(By.name("lastName")).submit(); - Assert.assertTrue(driver.findElementsByXPath("//*[text()='Jean Coleman']").size() == 1); + waitForPageToLoad(); + Assert.assertTrue("Could not find \"Jean Coleman\" on the current page. This is the html of the current page: "+getHTML(),driver.findElements(By.xpath("//*[text()='Jean Coleman']")).size() == 1); + setTestFinished(); } + } diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index d4f701966..a69a41e1d 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -1,13 +1,17 @@ package nl.utwente.bpsd.selenium; import org.junit.After; -import org.openqa.selenium.By; -import org.openqa.selenium.chrome.ChromeDriver; +import org.openqa.selenium.*; +import org.openqa.selenium.remote.Augmenter; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; +import org.openqa.selenium.support.ui.ExpectedCondition; +import org.openqa.selenium.support.ui.WebDriverWait; +import java.io.File; import java.net.MalformedURLException; import java.net.URL; +import java.util.logging.Logger; /** * @@ -15,14 +19,15 @@ import java.net.URL; * @since 21-6-2017. */ public class SeleniumBaseIT { - protected final RemoteWebDriver driver; + protected final WebDriver driver; public static final String BASE_URL = "http://pet-clinic:8080/"; + private boolean testFinished = false; // public static final String BASE_URL = "http://localhost:8080/"; public SeleniumBaseIT() throws MalformedURLException { // System.setProperty("webdriver.chrome.driver","C:\\Users\\marti\\Downloads\\chromedriver_win32\\chromedriver.exe"); // this.driver = new ChromeDriver(); - this.driver = new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox()); + this.driver = new Augmenter().augment(new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox())); driver.get(BASE_URL); } @@ -31,13 +36,46 @@ public class SeleniumBaseIT { driver.findElement(by).sendKeys(text); } + protected void setTestFinished() { + testFinished = true; + } + @After public void afterTest() { + if (!testFinished) { + if (driver instanceof TakesScreenshot) { + File screenshot = ((TakesScreenshot) driver).getScreenshotAs(OutputType.FILE); + Logger.getLogger(this.getClass().getName()).warning(screenshot.getAbsolutePath()); + } + } driver.close(); } protected boolean pageContainsText(String text) { - return driver.findElementsByXPath("//*[text()='"+text+"']").size() == 1; + return driver.findElements(By.xpath("//*[text()='"+text+"']")).size() == 1; + } + + public String getHTML() { + return driver.findElement(By.xpath("//html")).getAttribute("innerHTML"); + } + + protected void waitForPageToLoad() { + waitFor(new PageLoadedExpectedCondition()); + } + + private void waitFor(ExpectedCondition condition) { + new WebDriverWait(driver, 3).until(condition); + } + + private class PageLoadedExpectedCondition implements ExpectedCondition { + + @Override + public Boolean apply(WebDriver webDriver) { + if (webDriver instanceof JavascriptExecutor) { + return ((JavascriptExecutor)webDriver).executeScript("return document.readyState").equals("complete"); + } + throw new ClassCastException("This webdriver is not able to execute javascript."); + } } } From cc80b7482576668a1608edc2e0a2b6bc81ec4378 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 14:03:14 +0200 Subject: [PATCH 29/39] Add an extra wait --- .../nl/utwente/bpsd/selenium/FindOwnerIT.java | 1 + .../utwente/bpsd/selenium/SeleniumBaseIT.java | 21 ++++++++++++++++++- 2 files changed, 21 insertions(+), 1 deletion(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java index 57da781d9..45050f1ab 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java @@ -23,6 +23,7 @@ public class FindOwnerIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); fillTextField(By.name("lastName"),"Coleman"); driver.findElement(By.name("lastName")).submit(); + waitFor(new FixedPeriod(1000)); waitForPageToLoad(); Assert.assertTrue("Could not find \"Jean Coleman\" on the current page. This is the html of the current page: "+getHTML(),driver.findElements(By.xpath("//*[text()='Jean Coleman']")).size() == 1); setTestFinished(); diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index a69a41e1d..e65d5a692 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -64,7 +64,7 @@ public class SeleniumBaseIT { waitFor(new PageLoadedExpectedCondition()); } - private void waitFor(ExpectedCondition condition) { + protected void waitFor(ExpectedCondition condition) { new WebDriverWait(driver, 3).until(condition); } @@ -78,4 +78,23 @@ public class SeleniumBaseIT { throw new ClassCastException("This webdriver is not able to execute javascript."); } } + + protected class FixedPeriod implements ExpectedCondition { + private final int time; + + public FixedPeriod(int timeInMilliseconds) { + this.time = timeInMilliseconds; + } + + @Override + public Boolean apply(WebDriver webDriver) { + try { + Thread.sleep(time); + return true; + } catch (InterruptedException e) { + e.printStackTrace(); + return false; + } + } + } } From 6a85a1ac631a44d1d4aa899e7261ef166e2c220b Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 15:02:35 +0200 Subject: [PATCH 30/39] Add an extra wait and mostly fixed the addVisit test --- .../nl/utwente/bpsd/selenium/AddOwnerIT.java | 1 + .../nl/utwente/bpsd/selenium/AddVisitIT.java | 35 +++++++++++-------- .../utwente/bpsd/selenium/SeleniumBaseIT.java | 3 +- 3 files changed, 23 insertions(+), 16 deletions(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 2bbba0077..37903fb44 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -41,6 +41,7 @@ public class AddOwnerIT extends SeleniumBaseIT { new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); driver.findElement(By.name("name")).submit(); + waitFor(new FixedPeriod(1000)); waitForPageToLoad(); Assert.assertTrue(pageContainsText("Thumper")); setTestFinished(); diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java index cee199e50..7a8521a35 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -10,7 +10,7 @@ import java.net.MalformedURLException; import java.util.List; /** - * @author Martijn + * @author Sophie * @since 21-6-2017. */ public class AddVisitIT extends SeleniumBaseIT { @@ -20,24 +20,29 @@ public class AddVisitIT extends SeleniumBaseIT { @Test @Category(SeleniumBaseIT.class) - public void addOwnerTest() { - driver.findElement(By.name("lastName")).submit(); + public void editPetNameAndAddAVisit() { + driver.get(BASE_URL+"/owners/find"); - //Go to first owner - WebElement table = driver.findElement(By.tagName("table")); - List cells = table.findElements(By.xpath("tr/td")); - cells.get(0).findElement(By.xpath("a")).click(); + driver.findElement(By.name("lastName")).submit(); - //Go to edit page of first pet - driver.findElement(By.xpath("//table//tr/td/table/tbody//a[text()='Edit Pet']")).click(); + //Go to first owner + WebElement table = driver.findElement(By.tagName("table")); + List cells = table.findElements(By.xpath(".//tr/td")); + cells.get(0).findElement(By.xpath("a")).click(); - //Edit Name of pet - fillTextField(By.name("name"), "foobar"); - driver.findElement(By.name("name")).submit(); + //Go to edit page of first pet + driver.findElement(By.xpath("//table//tr/td/table/tbody//a[contains(text(),'Edit')]")).click(); - waitForPageToLoad(); - Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd/[contains(text(), 'foobar')]"))); - setTestFinished(); + //Edit Name of pet + fillTextField(By.name("name"), "foobar"); + driver.findElement(By.name("name")).submit(); + + waitFor(new FixedPeriod(1000)); + waitForPageToLoad(); + Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd[contains(text(), 'foobar')]"))); + + //TODO add a visit + setTestFinished(); } } diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index e65d5a692..0cf386804 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -2,6 +2,7 @@ package nl.utwente.bpsd.selenium; import org.junit.After; import org.openqa.selenium.*; +import org.openqa.selenium.chrome.ChromeDriver; import org.openqa.selenium.remote.Augmenter; import org.openqa.selenium.remote.DesiredCapabilities; import org.openqa.selenium.remote.RemoteWebDriver; @@ -20,8 +21,8 @@ import java.util.logging.Logger; */ public class SeleniumBaseIT { protected final WebDriver driver; - public static final String BASE_URL = "http://pet-clinic:8080/"; private boolean testFinished = false; + public static final String BASE_URL = "http://pet-clinic:8080/"; // public static final String BASE_URL = "http://localhost:8080/"; public SeleniumBaseIT() throws MalformedURLException { From b544ab80bdd1c610eb1e8d3d9bb1ed4146b3d83e Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 15:13:00 +0200 Subject: [PATCH 31/39] Add more waits --- src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java | 2 +- src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java | 2 ++ 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 37903fb44..42f62c063 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -43,7 +43,7 @@ public class AddOwnerIT extends SeleniumBaseIT { waitFor(new FixedPeriod(1000)); waitForPageToLoad(); - Assert.assertTrue(pageContainsText("Thumper")); + Assert.assertTrue("Could not locate \"Thumper\" on the page. This is the html of the current page: "+getHTML(),pageContainsText("Thumper")); setTestFinished(); } diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java index 7a8521a35..864ae7103 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -24,6 +24,8 @@ public class AddVisitIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); driver.findElement(By.name("lastName")).submit(); + waitFor(new FixedPeriod(1000)); + waitForPageToLoad(); //Go to first owner WebElement table = driver.findElement(By.tagName("table")); From c9d54ba6b8f3bd3aad48077a0ae895260a27a74c Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 15:39:03 +0200 Subject: [PATCH 32/39] Add more waits --- src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java | 5 ++--- src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java | 3 +-- src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java | 1 - src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java | 3 ++- 4 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 42f62c063..1bcaf0099 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -6,7 +6,6 @@ import org.junit.experimental.categories.Category; import org.openqa.selenium.By; import org.openqa.selenium.support.ui.ExpectedConditions; import org.openqa.selenium.support.ui.Select; -import org.openqa.selenium.support.ui.WebDriverWait; import java.net.MalformedURLException; @@ -31,17 +30,17 @@ public class AddOwnerIT extends SeleniumBaseIT { fillTextField(By.name("city"), "Enschede"); fillTextField(By.name("telephone"), "0534890000"); driver.findElement(By.name("telephone")).submit(); + waitForPageToLoad(); Assert.assertTrue(pageContainsText("Sophie Lathouwers")); //Add a pet - new WebDriverWait(driver, 3).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); + waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); driver.findElement(By.linkText("Add New Pet")).click(); fillTextField(By.name("name"), "Thumper"); fillTextField(By.name("birthDate"), "1942/08/09"); new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); driver.findElement(By.name("name")).submit(); - waitFor(new FixedPeriod(1000)); waitForPageToLoad(); Assert.assertTrue("Could not locate \"Thumper\" on the page. This is the html of the current page: "+getHTML(),pageContainsText("Thumper")); setTestFinished(); diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java index 864ae7103..82c2889a1 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -24,13 +24,13 @@ public class AddVisitIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); driver.findElement(By.name("lastName")).submit(); - waitFor(new FixedPeriod(1000)); waitForPageToLoad(); //Go to first owner WebElement table = driver.findElement(By.tagName("table")); List cells = table.findElements(By.xpath(".//tr/td")); cells.get(0).findElement(By.xpath("a")).click(); + waitForPageToLoad(); //Go to edit page of first pet driver.findElement(By.xpath("//table//tr/td/table/tbody//a[contains(text(),'Edit')]")).click(); @@ -39,7 +39,6 @@ public class AddVisitIT extends SeleniumBaseIT { fillTextField(By.name("name"), "foobar"); driver.findElement(By.name("name")).submit(); - waitFor(new FixedPeriod(1000)); waitForPageToLoad(); Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd[contains(text(), 'foobar')]"))); diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java index 45050f1ab..57da781d9 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java @@ -23,7 +23,6 @@ public class FindOwnerIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); fillTextField(By.name("lastName"),"Coleman"); driver.findElement(By.name("lastName")).submit(); - waitFor(new FixedPeriod(1000)); waitForPageToLoad(); Assert.assertTrue("Could not find \"Jean Coleman\" on the current page. This is the html of the current page: "+getHTML(),driver.findElements(By.xpath("//*[text()='Jean Coleman']")).size() == 1); setTestFinished(); diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index 0cf386804..333b62d5a 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -62,10 +62,11 @@ public class SeleniumBaseIT { } protected void waitForPageToLoad() { + waitFor(new FixedPeriod(333)); waitFor(new PageLoadedExpectedCondition()); } - protected void waitFor(ExpectedCondition condition) { + protected void waitFor(ExpectedCondition condition) { new WebDriverWait(driver, 3).until(condition); } From a8c71524acc2887593b437bd616730d4ffd10b7b Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 15:50:59 +0200 Subject: [PATCH 33/39] More logging --- src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 1bcaf0099..91158ea62 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -31,7 +31,7 @@ public class AddOwnerIT extends SeleniumBaseIT { fillTextField(By.name("telephone"), "0534890000"); driver.findElement(By.name("telephone")).submit(); waitForPageToLoad(); - Assert.assertTrue(pageContainsText("Sophie Lathouwers")); + Assert.assertTrue("Could not locate \"Sophie Lathouwers\" on the page. This is the html of the current page: "+getHTML(), pageContainsText("Sophie Lathouwers")); //Add a pet waitFor(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); From 71b820ac2d6ac69809916c837c27614193651262 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Sun, 25 Jun 2017 16:48:03 +0200 Subject: [PATCH 34/39] different wait to try --- src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java | 1 + 1 file changed, 1 insertion(+) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index 91158ea62..52a98b4f3 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -31,6 +31,7 @@ public class AddOwnerIT extends SeleniumBaseIT { fillTextField(By.name("telephone"), "0534890000"); driver.findElement(By.name("telephone")).submit(); waitForPageToLoad(); + waitFor(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='Sophie Lathouwers']"))); Assert.assertTrue("Could not locate \"Sophie Lathouwers\" on the page. This is the html of the current page: "+getHTML(), pageContainsText("Sophie Lathouwers")); //Add a pet From b137e5a64f4afefcd8a39c622dc1a1744e84ffb3 Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Tue, 27 Jun 2017 17:51:05 +0200 Subject: [PATCH 35/39] fixed 1 test --- src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java | 7 +++++-- src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java | 3 +++ src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java | 2 +- 3 files changed, 9 insertions(+), 3 deletions(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java index de1dfaba9..ce1573a39 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddOwnerIT.java @@ -31,16 +31,19 @@ public class AddOwnerIT extends SeleniumBaseIT { fillTextField(By.name("city"), "Enschede"); fillTextField(By.name("telephone"), "0534890000"); driver.findElement(By.name("telephone")).submit(); + new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='Owner Information']"))); Assert.assertTrue(pageContainsText("Sophie Lathouwers")); //Add a pet - new WebDriverWait(driver, 3).until(ExpectedConditions.presenceOfAllElementsLocatedBy(By.linkText("Add New Pet"))); - driver.findElement(By.linkText("Add New Pet")).click(); + new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='Pets and Visits']"))); + driver.findElements(By.className("btn")).get(1).click(); + new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='New']"))); fillTextField(By.name("name"), "Thumper"); fillTextField(By.name("birthDate"), "1942/08/09"); new Select(driver.findElement(By.name("type"))).selectByValue("hamster"); driver.findElement(By.name("name")).submit(); + new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='Pets and Visits']"))); Assert.assertTrue(pageContainsText("Thumper")); } diff --git a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java index 17fcd7de4..ac52cde29 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/FindOwnerIT.java @@ -4,6 +4,8 @@ import org.junit.Assert; import org.junit.Test; import org.junit.experimental.categories.Category; import org.openqa.selenium.By; +import org.openqa.selenium.support.ui.ExpectedConditions; +import org.openqa.selenium.support.ui.WebDriverWait; import java.net.MalformedURLException; @@ -23,6 +25,7 @@ public class FindOwnerIT extends SeleniumBaseIT { driver.get(BASE_URL+"/owners/find"); fillTextField(By.name("lastName"),"Coleman"); driver.findElement(By.name("lastName")).submit(); + new WebDriverWait(driver, 5).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[text()='Owner Information']"))); Assert.assertTrue(driver.findElementsByXPath("//*[text()='Jean Coleman']").size() == 1); } } diff --git a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java index d4f701966..02ae4c59d 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/SeleniumBaseIT.java @@ -22,7 +22,7 @@ public class SeleniumBaseIT { public SeleniumBaseIT() throws MalformedURLException { // System.setProperty("webdriver.chrome.driver","C:\\Users\\marti\\Downloads\\chromedriver_win32\\chromedriver.exe"); // this.driver = new ChromeDriver(); - this.driver = new RemoteWebDriver(new URL("http://selenium:4444/wd/hub"), DesiredCapabilities.firefox()); + this.driver = new RemoteWebDriver(new URL("http://localhost:4444/wd/hub"), DesiredCapabilities.firefox()); driver.get(BASE_URL); } From d42fa6e12a60823c09e4a095c8677c15bf0b43ef Mon Sep 17 00:00:00 2001 From: Marty30 Date: Tue, 27 Jun 2017 22:25:40 +0200 Subject: [PATCH 36/39] Added mutation testing --- .travis.yml | 3 ++- pom.xml | 10 ++++++++++ 2 files changed, 12 insertions(+), 1 deletion(-) diff --git a/.travis.yml b/.travis.yml index a9d5117be..3423bef64 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,8 @@ before_script: - docker-compose up -d script: - - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent install -Dskip.failsafe.tests sonar:sonar + - mvn org.pitest:pitest-maven:mutationCoverage + - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -Dskip.failsafe.tests sonar:sonar -Dsonar.pitest.mode=reuseReport - docker exec springpetclinic_pet-clinic_1 mvn verify -Dskip.surefire.tests -q --batch-mode after_script: diff --git a/pom.xml b/pom.xml index e7a215877..c0f1dc7a1 100644 --- a/pom.xml +++ b/pom.xml @@ -156,6 +156,16 @@ + + org.pitest + pitest-maven + 1.2.0 + + + XML + + + org.springframework.boot spring-boot-maven-plugin From 799eaf36b64758815f11a9b9de477381a7644382 Mon Sep 17 00:00:00 2001 From: Marty30 Date: Tue, 27 Jun 2017 22:39:57 +0200 Subject: [PATCH 37/39] Move mutation testing to the build phase --- .travis.yml | 1 - Dockerfile | 3 ++- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/.travis.yml b/.travis.yml index 3423bef64..351fd2b0c 100644 --- a/.travis.yml +++ b/.travis.yml @@ -20,7 +20,6 @@ before_script: - docker-compose up -d script: - - mvn org.pitest:pitest-maven:mutationCoverage - mvn clean org.jacoco:jacoco-maven-plugin:prepare-agent test -Dskip.failsafe.tests sonar:sonar -Dsonar.pitest.mode=reuseReport - docker exec springpetclinic_pet-clinic_1 mvn verify -Dskip.surefire.tests -q --batch-mode diff --git a/Dockerfile b/Dockerfile index 68dfff9fe..1f2d91493 100644 --- a/Dockerfile +++ b/Dockerfile @@ -7,7 +7,8 @@ WORKDIR /app COPY . . # Build the project -RUN mvn package -Dskip.failsafe.tests -q --batch-mode +RUN mvn package -Dskip.failsafe.tests -q --batch-mode && \ +mvn org.pitest:pitest-maven:mutationCoverage -q --batch-mode # Copy and make the jar executable RUN sh -c 'mkdir dist/ && cp -a target/. dist/ && touch dist/spring-petclinic-*.jar' From 5c20ec1c73299b5ef70b64dd8244693b14875b8d Mon Sep 17 00:00:00 2001 From: Ivaylo Hristov Date: Wed, 28 Jun 2017 10:33:51 +0200 Subject: [PATCH 38/39] added remaining part of the addvisit test --- .../java/nl/utwente/bpsd/selenium/AddVisitIT.java | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java index 3a9d0a589..d9314803d 100644 --- a/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java +++ b/src/test/java/nl/utwente/bpsd/selenium/AddVisitIT.java @@ -40,10 +40,20 @@ public class AddVisitIT extends SeleniumBaseIT { fillTextField(By.name("name"), "foobar"); driver.findElement(By.name("name")).submit(); + waitForPageToLoad(); Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/dl/dd[contains(text(), 'foobar')]"))); - //TODO add a visit + driver.findElement(By.xpath("//table//tr/td/table/tbody//a[contains(text(),'Add')]")).click(); + waitForPageToLoad(); + + + fillTextField(By.name("date"), "2017/12/12"); + fillTextField(By.name("description"), "Foobar check for disease"); + driver.findElement(By.name("date")).submit(); + waitForPageToLoad(); + Assert.assertNotNull(driver.findElement(By.xpath("//table//tr/td/table/tbody//td[contains(text(), '2017-12-12')]"))); + setTestFinished(); } From 54c8162fe348857cac8eec3f97c8087fa91b6f08 Mon Sep 17 00:00:00 2001 From: Sophie Lathouwers Date: Wed, 28 Jun 2017 12:17:46 +0200 Subject: [PATCH 39/39] P1706-25: Fix renaming of founndOwners --- .../samples/petclinic/owner/OwnerController.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java index 58be460a0..5432398f6 100644 --- a/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java +++ b/src/main/java/org/springframework/samples/petclinic/owner/OwnerController.java @@ -93,8 +93,8 @@ class OwnerController { return "owners/findOwners"; } else if (results.size() == 1) { // 1 owner found - Owner founndOwner = results.iterator().next(); - return "redirect:/owners/" + founndOwner.getId(); + Owner foundOwner = results.iterator().next(); + return "redirect:/owners/" + foundOwner.getId(); } else { // multiple owners found model.put("selections", results);