From c904a7eb0f2ac3ff19357783595430389f571cbc Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:49:24 +0530 Subject: [PATCH 01/11] Create Docker-compose.dev.yml --- Docker-compose.dev.yml | 6 ++++++ 1 file changed, 6 insertions(+) create mode 100644 Docker-compose.dev.yml diff --git a/Docker-compose.dev.yml b/Docker-compose.dev.yml new file mode 100644 index 0000000..484dc1a --- /dev/null +++ b/Docker-compose.dev.yml @@ -0,0 +1,6 @@ +version: '3' +services: + my-app: + image: ankitbansal14/github-actions-docker-java-app:0.0.1.Release + ports: + - "5000:5000" From abea598eb59b3103d67b388ac963929f56feec89 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 11:57:49 +0530 Subject: [PATCH 02/11] Create streamline.yml --- .github/workflow/streamline.yml | 47 +++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflow/streamline.yml diff --git a/.github/workflow/streamline.yml b/.github/workflow/streamline.yml new file mode 100644 index 0000000..93730a4 --- /dev/null +++ b/.github/workflow/streamline.yml @@ -0,0 +1,47 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "master" ] + pull_request: + branches: [ "master" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + #- name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + + - name: Build Docker image + run: docker build -t ankitbansal360/github-actions-docker-java-app:0.0.1.Release . + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Docker Image + run: docker push ankitbansal360/github-actions-docker-java-app:0.0.1.Release From f8077f193b0ac2158b676173318a9f6d553fedf8 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:17:25 +0530 Subject: [PATCH 03/11] Update streamline.yml --- .github/workflow/streamline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflow/streamline.yml b/.github/workflow/streamline.yml index 93730a4..b984c4a 100644 --- a/.github/workflow/streamline.yml +++ b/.github/workflow/streamline.yml @@ -10,9 +10,9 @@ name: Java CI with Maven on: push: - branches: [ "master" ] + branches: [ "ankit-features" ] pull_request: - branches: [ "master" ] + branches: [ "ankit-features" ] jobs: build: From ed2c7b32960e68c0e162f3e4d4416c6b5eaf471f Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:20:02 +0530 Subject: [PATCH 04/11] Update streamline.yml --- .github/workflow/streamline.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflow/streamline.yml b/.github/workflow/streamline.yml index b984c4a..23efcfa 100644 --- a/.github/workflow/streamline.yml +++ b/.github/workflow/streamline.yml @@ -35,7 +35,7 @@ jobs: # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 - name: Build Docker image - run: docker build -t ankitbansal360/github-actions-docker-java-app:0.0.1.Release . + run: docker build -t ankitbansal14/github-actions-docker-java-app:0.0.1.Release . - name: Login to Docker Hub uses: docker/login-action@v1 @@ -44,4 +44,4 @@ jobs: password: ${{ secrets.DOCKER_PASSWORD }} - name: Push Docker Image - run: docker push ankitbansal360/github-actions-docker-java-app:0.0.1.Release + run: docker push ankitbansal14/github-actions-docker-java-app:0.0.1.Release From 8f9f1ee3068d88aaeffeb99ff3d01f455c035e64 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:26:38 +0530 Subject: [PATCH 05/11] Delete .github/workflow directory --- .github/workflow/streamline.yml | 47 --------------------------------- 1 file changed, 47 deletions(-) delete mode 100644 .github/workflow/streamline.yml diff --git a/.github/workflow/streamline.yml b/.github/workflow/streamline.yml deleted file mode 100644 index 23efcfa..0000000 --- a/.github/workflow/streamline.yml +++ /dev/null @@ -1,47 +0,0 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Java CI with Maven - -on: - push: - branches: [ "ankit-features" ] - pull_request: - branches: [ "ankit-features" ] - -jobs: - build: - - runs-on: ubuntu-latest - - steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - #- name: Update dependency graph - # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 - - - name: Build Docker image - run: docker build -t ankitbansal14/github-actions-docker-java-app:0.0.1.Release . - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} - - - name: Push Docker Image - run: docker push ankitbansal14/github-actions-docker-java-app:0.0.1.Release From e9173c7d26fd2004fc4106db13e954fd7ecf82f6 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 12:28:05 +0530 Subject: [PATCH 06/11] Create streamline.yml --- .github/workflows/streamline.yml | 47 ++++++++++++++++++++++++++++++++ 1 file changed, 47 insertions(+) create mode 100644 .github/workflows/streamline.yml diff --git a/.github/workflows/streamline.yml b/.github/workflows/streamline.yml new file mode 100644 index 0000000..23efcfa --- /dev/null +++ b/.github/workflows/streamline.yml @@ -0,0 +1,47 @@ +# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time +# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven + +# This workflow uses actions that are not certified by GitHub. +# They are provided by a third-party and are governed by +# separate terms of service, privacy policy, and support +# documentation. + +name: Java CI with Maven + +on: + push: + branches: [ "ankit-features" ] + pull_request: + branches: [ "ankit-features" ] + +jobs: + build: + + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v3 + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + - name: Build with Maven + run: mvn -B package --file pom.xml + + # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive + #- name: Update dependency graph + # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 + + - name: Build Docker image + run: docker build -t ankitbansal14/github-actions-docker-java-app:0.0.1.Release . + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Docker Image + run: docker push ankitbansal14/github-actions-docker-java-app:0.0.1.Release From af0d9aa87f592dab738a2324e5fbfa71b70e1f4a Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:12:28 +0530 Subject: [PATCH 07/11] Update streamline.yml --- .github/workflows/streamline.yml | 91 +++++++++++++++++++------------- 1 file changed, 53 insertions(+), 38 deletions(-) diff --git a/.github/workflows/streamline.yml b/.github/workflows/streamline.yml index 23efcfa..e0b2e0e 100644 --- a/.github/workflows/streamline.yml +++ b/.github/workflows/streamline.yml @@ -1,47 +1,62 @@ -# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time -# For more information see: https://docs.github.com/en/actions/automating-builds-and-tests/building-and-testing-java-with-maven - -# This workflow uses actions that are not certified by GitHub. -# They are provided by a third-party and are governed by -# separate terms of service, privacy policy, and support -# documentation. - -name: Java CI with Maven +name: Azure Web App Container Deployment on: push: - branches: [ "ankit-features" ] - pull_request: - branches: [ "ankit-features" ] + branches: + - feature # Change this to your default branch jobs: - build: - + build-and-deploy: runs-on: ubuntu-latest steps: - - uses: actions/checkout@v3 - - name: Set up JDK 17 - uses: actions/setup-java@v3 - with: - java-version: '17' - distribution: 'temurin' - cache: maven - - name: Build with Maven - run: mvn -B package --file pom.xml - - # Optional: Uploads the full dependency graph to GitHub to improve the quality of Dependabot alerts this repository can receive - #- name: Update dependency graph - # uses: advanced-security/maven-dependency-submission-action@571e99aab1055c2e71a1e2309b9691de18d6b7d6 - - - name: Build Docker image - run: docker build -t ankitbansal14/github-actions-docker-java-app:0.0.1.Release . - - - name: Login to Docker Hub - uses: docker/login-action@v1 - with: - username: ${{ secrets.DOCKER_USERNAME }} - password: ${{ secrets.DOCKER_PASSWORD }} + - name: Checkout code + uses: actions/checkout@v2 + + - name: Set up JDK 17 + uses: actions/setup-java@v3 + with: + java-version: '17' + distribution: 'temurin' + cache: maven + + # - name: Skip TEST Maven + # run: mvn install -Dmaven.test.skip=true + + - name: Build with Maven + run: mvn -B package --file pom.xml - - name: Push Docker Image - run: docker push ankitbansal14/github-actions-docker-java-app:0.0.1.Release + - name: Set up Docker + uses: azure/docker-login@v1 + with: + login-server: https://hub.docker.com/ + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + # - name: Build and push Docker image + # run: | + # docker build -t ankitbansal14/shell-java-app:0.0.1.Release . + # docker push ankitbansal14/shell-java-app:0.0.1.Release + + - name: Build Docker Image + run: docker build -t ankitbansal14/shell-java-app:0.0.1.Release . + + - name: Login to Docker Hub + uses: docker/login-action@v1 + with: + username: ${{ secrets.DOCKER_USERNAME }} + password: ${{ secrets.DOCKER_PASSWORD }} + + - name: Push Docker Image + run: docker push ankitbansal14/shell-java-app:0.0.1.Release + + - name: Login to Azure + uses: azure/login@v1 + with: + creds: ${{ secrets.AZURE_CREDENTIALS }} + + - name: Deploy to Azure Web App + uses: azure/webapps-deploy@v2 + with: + app-name: azure-web-app-shell-java-app + images: ankitbansal14/shell-java-app:0.0.1.Release From 1035ece852b5aa439240033738158a0a896e0f19 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:15:58 +0530 Subject: [PATCH 08/11] Update and rename Docker-compose.dev.yml to Dockerfile --- Docker-compose.dev.yml | 6 ------ Dockerfile | 22 ++++++++++++++++++++++ 2 files changed, 22 insertions(+), 6 deletions(-) delete mode 100644 Docker-compose.dev.yml create mode 100644 Dockerfile diff --git a/Docker-compose.dev.yml b/Docker-compose.dev.yml deleted file mode 100644 index 484dc1a..0000000 --- a/Docker-compose.dev.yml +++ /dev/null @@ -1,6 +0,0 @@ -version: '3' -services: - my-app: - image: ankitbansal14/github-actions-docker-java-app:0.0.1.Release - ports: - - "5000:5000" diff --git a/Dockerfile b/Dockerfile new file mode 100644 index 0000000..973fb6a --- /dev/null +++ b/Dockerfile @@ -0,0 +1,22 @@ +# syntax=docker/dockerfile:1 + +FROM eclipse-temurin:17-jdk-jammy as base +WORKDIR /app +COPY .mvn/ .mvn +COPY mvnw pom.xml ./ +RUN ./mvnw dependency:resolve +COPY src ./src + +FROM base as test +RUN ["./mvnw", "test"] + +FROM base as development +CMD ["./mvnw", "spring-boot:run", "-Dspring-boot.run.profiles=mysql", "-Dspring-boot.run.jvmArguments='-agentlib:jdwp=transport=dt_socket,server=y,suspend=n,address=*:8000'"] + +FROM base as build +RUN ./mvnw package + +FROM eclipse-temurin:17-jre-jammy as production +EXPOSE 8080 +COPY --from=build /app/target/spring-petclinic-*.jar /spring-petclinic.jar +CMD ["java", "-Djava.security.egd=file:/dev/./urandom", "-jar", "/spring-petclinic.jar"] From 4a4fbf88666444859eae64acb6ec3c10111be168 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:20:51 +0530 Subject: [PATCH 09/11] Delete src/test directory --- .../petclinic/MySqlIntegrationTests.java | 71 --- .../petclinic/MysqlTestApplication.java | 46 -- .../petclinic/PetClinicIntegrationTests.java | 63 --- .../petclinic/PostgresIntegrationTests.java | 140 ----- .../petclinic/model/ValidatorTests.java | 60 --- .../petclinic/owner/OwnerControllerTests.java | 246 --------- .../petclinic/owner/PetControllerTests.java | 130 ----- .../owner/PetTypeFormatterTests.java | 97 ---- .../petclinic/owner/VisitControllerTests.java | 89 ---- .../petclinic/service/ClinicServiceTests.java | 228 -------- .../petclinic/service/EntityUtils.java | 53 -- .../CrashControllerIntegrationTests.java | 98 ---- .../system/CrashControllerTests.java | 46 -- .../petclinic/vet/VetControllerTests.java | 98 ---- .../samples/petclinic/vet/VetTests.java | 40 -- src/test/jmeter/petclinic_test_plan.jmx | 487 ------------------ 16 files changed, 1992 deletions(-) delete mode 100644 src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java delete mode 100755 src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/system/CrashControllerIntegrationTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java delete mode 100644 src/test/java/org/springframework/samples/petclinic/vet/VetTests.java delete mode 100644 src/test/jmeter/petclinic_test_plan.jmx diff --git a/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java deleted file mode 100644 index d868aed..0000000 --- a/src/test/java/org/springframework/samples/petclinic/MySqlIntegrationTests.java +++ /dev/null @@ -1,71 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.boot.testcontainers.service.connection.ServiceConnection; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.web.client.RestTemplate; -import org.testcontainers.containers.MySQLContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -@ActiveProfiles("mysql") -@Testcontainers(disabledWithoutDocker = true) -@DisabledInNativeImage -class MySqlIntegrationTests { - - @ServiceConnection - @Container - static MySQLContainer container = new MySQLContainer<>("mysql:5.7"); - - @LocalServerPort - int port; - - @Autowired - private VetRepository vets; - - @Autowired - private RestTemplateBuilder builder; - - @Test - void testFindAll() throws Exception { - vets.findAll(); - vets.findAll(); // served from cache - } - - @Test - void testOwnerDetails() { - RestTemplate template = builder.rootUri("http://localhost:" + port).build(); - ResponseEntity result = template.exchange(RequestEntity.get("/owners/1").build(), String.class); - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java b/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java deleted file mode 100644 index 3df8418..0000000 --- a/src/test/java/org/springframework/samples/petclinic/MysqlTestApplication.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic; - -import org.springframework.boot.SpringApplication; -import org.springframework.boot.testcontainers.service.connection.ServiceConnection; -import org.springframework.context.annotation.Bean; -import org.springframework.context.annotation.Configuration; -import org.springframework.context.annotation.Profile; -import org.testcontainers.containers.MySQLContainer; - -/** - * PetClinic Spring Boot Application. - * - * @author Dave Syer - * - */ -@Configuration -public class MysqlTestApplication { - - @ServiceConnection - @Profile("mysql") - @Bean - static MySQLContainer container() { - return new MySQLContainer<>("mysql:5.7"); - } - - public static void main(String[] args) { - SpringApplication.run(PetClinicApplication.class, "--spring.profiles.active=mysql"); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java deleted file mode 100644 index 6472a12..0000000 --- a/src/test/java/org/springframework/samples/petclinic/PetClinicIntegrationTests.java +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic; - -import static org.assertj.core.api.Assertions.assertThat; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.SpringApplication; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.web.client.RestTemplate; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT) -public class PetClinicIntegrationTests { - - @LocalServerPort - int port; - - @Autowired - private VetRepository vets; - - @Autowired - private RestTemplateBuilder builder; - - @Test - void testFindAll() throws Exception { - vets.findAll(); - vets.findAll(); // served from cache - } - - @Test - void testOwnerDetails() { - RestTemplate template = builder.rootUri("http://localhost:" + port).build(); - ResponseEntity result = template.exchange(RequestEntity.get("/owners/1").build(), String.class); - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - public static void main(String[] args) { - SpringApplication.run(PetClinicApplication.class, args); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java deleted file mode 100644 index 18945a5..0000000 --- a/src/test/java/org/springframework/samples/petclinic/PostgresIntegrationTests.java +++ /dev/null @@ -1,140 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.junit.jupiter.api.Assumptions.assumeTrue; - -import java.util.Arrays; -import java.util.LinkedList; -import java.util.List; - -import org.apache.commons.logging.Log; -import org.apache.commons.logging.LogFactory; -import org.junit.jupiter.api.BeforeAll; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.builder.SpringApplicationBuilder; -import org.springframework.boot.context.event.ApplicationPreparedEvent; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.context.SpringBootTest.WebEnvironment; -import org.springframework.boot.test.web.server.LocalServerPort; -import org.springframework.boot.web.client.RestTemplateBuilder; -import org.springframework.context.ApplicationListener; -import org.springframework.core.env.ConfigurableEnvironment; -import org.springframework.core.env.EnumerablePropertySource; -import org.springframework.core.env.PropertySource; -import org.springframework.http.HttpStatus; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.test.context.ActiveProfiles; -import org.springframework.web.client.RestTemplate; -import org.testcontainers.DockerClientFactory; - -@SpringBootTest(webEnvironment = WebEnvironment.RANDOM_PORT, properties = { "spring.docker.compose.skip.in-tests=false", // - "spring.docker.compose.profiles.active=postgres" }) -@ActiveProfiles("postgres") -@DisabledInNativeImage -public class PostgresIntegrationTests { - - @LocalServerPort - int port; - - @Autowired - private VetRepository vets; - - @Autowired - private RestTemplateBuilder builder; - - @BeforeAll - static void available() { - assumeTrue(DockerClientFactory.instance().isDockerAvailable(), "Docker not available"); - } - - public static void main(String[] args) { - new SpringApplicationBuilder(PetClinicApplication.class) // - .profiles("postgres") // - .properties( // - "spring.docker.compose.profiles.active=postgres" // - ) // - .listeners(new PropertiesLogger()) // - .run(args); - } - - @Test - void testFindAll() throws Exception { - vets.findAll(); - vets.findAll(); // served from cache - } - - @Test - void testOwnerDetails() { - RestTemplate template = builder.rootUri("http://localhost:" + port).build(); - ResponseEntity result = template.exchange(RequestEntity.get("/owners/1").build(), String.class); - assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); - } - - static class PropertiesLogger implements ApplicationListener { - - private static final Log log = LogFactory.getLog(PropertiesLogger.class); - - private ConfigurableEnvironment environment; - - private boolean isFirstRun = true; - - @Override - public void onApplicationEvent(ApplicationPreparedEvent event) { - if (isFirstRun) { - environment = event.getApplicationContext().getEnvironment(); - printProperties(); - } - isFirstRun = false; - } - - public void printProperties() { - for (EnumerablePropertySource source : findPropertiesPropertySources()) { - log.info("PropertySource: " + source.getName()); - String[] names = source.getPropertyNames(); - Arrays.sort(names); - for (String name : names) { - String resolved = environment.getProperty(name); - String value = source.getProperty(name).toString(); - if (resolved.equals(value)) { - log.info(name + "=" + resolved); - } - else { - log.info(name + "=" + value + " OVERRIDDEN to " + resolved); - } - } - } - } - - private List> findPropertiesPropertySources() { - List> sources = new LinkedList<>(); - for (PropertySource source : environment.getPropertySources()) { - if (source instanceof EnumerablePropertySource enumerable) { - sources.add(enumerable); - } - } - return sources; - } - - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java b/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java deleted file mode 100644 index 9fcd598..0000000 --- a/src/test/java/org/springframework/samples/petclinic/model/ValidatorTests.java +++ /dev/null @@ -1,60 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.model; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.util.Locale; -import java.util.Set; - -import org.junit.jupiter.api.Test; -import org.springframework.context.i18n.LocaleContextHolder; -import org.springframework.validation.beanvalidation.LocalValidatorFactoryBean; - -import jakarta.validation.ConstraintViolation; -import jakarta.validation.Validator; - -/** - * @author Michael Isvy Simple test to make sure that Bean Validation is working (useful - * when upgrading to a new version of Hibernate Validator/ Bean Validation) - */ -class ValidatorTests { - - private Validator createValidator() { - LocalValidatorFactoryBean localValidatorFactoryBean = new LocalValidatorFactoryBean(); - localValidatorFactoryBean.afterPropertiesSet(); - return localValidatorFactoryBean; - } - - @Test - void shouldNotValidateWhenFirstNameEmpty() { - - LocaleContextHolder.setLocale(Locale.ENGLISH); - Person person = new Person(); - person.setFirstName(""); - person.setLastName("smith"); - - Validator validator = createValidator(); - Set> constraintViolations = validator.validate(person); - - assertThat(constraintViolations).hasSize(1); - ConstraintViolation violation = constraintViolations.iterator().next(); - assertThat(violation.getPropertyPath().toString()).isEqualTo("firstName"); - assertThat(violation.getMessage()).isEqualTo("must not be blank"); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java deleted file mode 100644 index 4b0f38a..0000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/OwnerControllerTests.java +++ /dev/null @@ -1,246 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.owner; - -import static org.hamcrest.Matchers.empty; -import static org.hamcrest.Matchers.hasProperty; -import static org.hamcrest.Matchers.is; -import static org.hamcrest.Matchers.not; -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.ArgumentMatchers.anyString; -import static org.mockito.ArgumentMatchers.eq; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import java.time.LocalDate; -import java.util.List; - -import org.assertj.core.util.Lists; -import org.hamcrest.BaseMatcher; -import org.hamcrest.Description; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.mockito.Mockito; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for {@link OwnerController} - * - * @author Colin But - */ -@WebMvcTest(OwnerController.class) -@DisabledInNativeImage -class OwnerControllerTests { - - private static final int TEST_OWNER_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private OwnerRepository owners; - - private Owner george() { - Owner george = new Owner(); - george.setId(TEST_OWNER_ID); - george.setFirstName("George"); - george.setLastName("Franklin"); - george.setAddress("110 W. Liberty St."); - george.setCity("Madison"); - george.setTelephone("6085551023"); - Pet max = new Pet(); - PetType dog = new PetType(); - dog.setName("dog"); - max.setType(dog); - max.setName("Max"); - max.setBirthDate(LocalDate.now()); - george.addPet(max); - max.setId(1); - return george; - }; - - @BeforeEach - void setup() { - - Owner george = george(); - given(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))) - .willReturn(new PageImpl(Lists.newArrayList(george))); - - given(this.owners.findAll(any(Pageable.class))).willReturn(new PageImpl(Lists.newArrayList(george))); - - given(this.owners.findById(TEST_OWNER_ID)).willReturn(george); - Visit visit = new Visit(); - visit.setDate(LocalDate.now()); - george.getPet("Max").getVisits().add(visit); - - } - - @Test - void testInitCreationForm() throws Exception { - mockMvc.perform(get("/owners/new")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testProcessCreationFormSuccess() throws Exception { - mockMvc - .perform(post("/owners/new").param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("address", "123 Caramel Street") - .param("city", "London") - .param("telephone", "01316761638")) - .andExpect(status().is3xxRedirection()); - } - - @Test - void testProcessCreationFormHasErrors() throws Exception { - mockMvc - .perform(post("/owners/new").param("firstName", "Joe").param("lastName", "Bloggs").param("city", "London")) - .andExpect(status().isOk()) - .andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testInitFindForm() throws Exception { - mockMvc.perform(get("/owners/find")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(view().name("owners/findOwners")); - } - - @Test - void testProcessFindFormSuccess() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList(george(), new Owner())); - Mockito.when(this.owners.findByLastName(anyString(), any(Pageable.class))).thenReturn(tasks); - mockMvc.perform(get("/owners?page=1")).andExpect(status().isOk()).andExpect(view().name("owners/ownersList")); - } - - @Test - void testProcessFindFormByLastName() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList(george())); - Mockito.when(this.owners.findByLastName(eq("Franklin"), any(Pageable.class))).thenReturn(tasks); - mockMvc.perform(get("/owners?page=1").param("lastName", "Franklin")) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/" + TEST_OWNER_ID)); - } - - @Test - void testProcessFindFormNoOwnersFound() throws Exception { - Page tasks = new PageImpl(Lists.newArrayList()); - Mockito.when(this.owners.findByLastName(eq("Unknown Surname"), any(Pageable.class))).thenReturn(tasks); - mockMvc.perform(get("/owners?page=1").param("lastName", "Unknown Surname")) - .andExpect(status().isOk()) - .andExpect(model().attributeHasFieldErrors("owner", "lastName")) - .andExpect(model().attributeHasFieldErrorCode("owner", "lastName", "notFound")) - .andExpect(view().name("owners/findOwners")); - - } - - @Test - void testInitUpdateOwnerForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/edit", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("owner")) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testProcessUpdateOwnerFormSuccess() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("address", "123 Caramel Street") - .param("city", "London") - .param("telephone", "01616291589")) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessUpdateOwnerFormUnchangedSuccess() throws Exception { - mockMvc.perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID)) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessUpdateOwnerFormHasErrors() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/edit", TEST_OWNER_ID).param("firstName", "Joe") - .param("lastName", "Bloggs") - .param("address", "") - .param("telephone", "")) - .andExpect(status().isOk()) - .andExpect(model().attributeHasErrors("owner")) - .andExpect(model().attributeHasFieldErrors("owner", "address")) - .andExpect(model().attributeHasFieldErrors("owner", "telephone")) - .andExpect(view().name("owners/createOrUpdateOwnerForm")); - } - - @Test - void testShowOwner() throws Exception { - mockMvc.perform(get("/owners/{ownerId}", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(model().attribute("owner", hasProperty("lastName", is("Franklin")))) - .andExpect(model().attribute("owner", hasProperty("firstName", is("George")))) - .andExpect(model().attribute("owner", hasProperty("address", is("110 W. Liberty St.")))) - .andExpect(model().attribute("owner", hasProperty("city", is("Madison")))) - .andExpect(model().attribute("owner", hasProperty("telephone", is("6085551023")))) - .andExpect(model().attribute("owner", hasProperty("pets", not(empty())))) - .andExpect(model().attribute("owner", hasProperty("pets", new BaseMatcher>() { - - @Override - public boolean matches(Object item) { - @SuppressWarnings("unchecked") - List pets = (List) item; - Pet pet = pets.get(0); - if (pet.getVisits().isEmpty()) { - return false; - } - return true; - } - - @Override - public void describeTo(Description description) { - description.appendText("Max did not have any visits"); - } - }))) - .andExpect(view().name("owners/ownerDetails")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java deleted file mode 100755 index 763e801..0000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetControllerTests.java +++ /dev/null @@ -1,130 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.owner; - -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.context.annotation.FilterType; -import org.springframework.test.web.servlet.MockMvc; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -/** - * Test class for the {@link PetController} - * - * @author Colin But - */ -@WebMvcTest(value = PetController.class, - includeFilters = @ComponentScan.Filter(value = PetTypeFormatter.class, type = FilterType.ASSIGNABLE_TYPE)) -@DisabledInNativeImage -class PetControllerTests { - - private static final int TEST_OWNER_ID = 1; - - private static final int TEST_PET_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private OwnerRepository owners; - - @BeforeEach - void setup() { - PetType cat = new PetType(); - cat.setId(3); - cat.setName("hamster"); - given(this.owners.findPetTypes()).willReturn(Lists.newArrayList(cat)); - Owner owner = new Owner(); - Pet pet = new Pet(); - owner.addPet(pet); - pet.setId(TEST_PET_ID); - given(this.owners.findById(TEST_OWNER_ID)).willReturn(owner); - } - - @Test - void testInitCreationForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/pets/new", TEST_OWNER_ID)) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")) - .andExpect(model().attributeExists("pet")); - } - - @Test - void testProcessCreationFormSuccess() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty") - .param("type", "hamster") - .param("birthDate", "2015-02-12")) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessCreationFormHasErrors() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/new", TEST_OWNER_ID).param("name", "Betty") - .param("birthDate", "2015-02-12")) - .andExpect(model().attributeHasNoErrors("owner")) - .andExpect(model().attributeHasErrors("pet")) - .andExpect(model().attributeHasFieldErrors("pet", "type")) - .andExpect(model().attributeHasFieldErrorCode("pet", "type", "required")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - - @Test - void testInitUpdateForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID)) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("pet")) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - - @Test - void testProcessUpdateFormSuccess() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty") - .param("type", "hamster") - .param("birthDate", "2015-02-12")) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessUpdateFormHasErrors() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/{petId}/edit", TEST_OWNER_ID, TEST_PET_ID).param("name", "Betty") - .param("birthDate", "2015/02/12")) - .andExpect(model().attributeHasNoErrors("owner")) - .andExpect(model().attributeHasErrors("pet")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdatePetForm")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java b/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java deleted file mode 100644 index dabade7..0000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/PetTypeFormatterTests.java +++ /dev/null @@ -1,97 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.owner; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.mockito.BDDMockito.given; - -import java.text.ParseException; -import java.util.ArrayList; -import java.util.Collection; -import java.util.List; -import java.util.Locale; - -import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.Mock; -import org.mockito.junit.jupiter.MockitoExtension; - -/** - * Test class for {@link PetTypeFormatter} - * - * @author Colin But - */ -@ExtendWith(MockitoExtension.class) -@DisabledInNativeImage -class PetTypeFormatterTests { - - @Mock - private OwnerRepository pets; - - private PetTypeFormatter petTypeFormatter; - - @BeforeEach - void setup() { - this.petTypeFormatter = new PetTypeFormatter(pets); - } - - @Test - void testPrint() { - PetType petType = new PetType(); - petType.setName("Hamster"); - String petTypeName = this.petTypeFormatter.print(petType, Locale.ENGLISH); - assertThat(petTypeName).isEqualTo("Hamster"); - } - - @Test - void shouldParse() throws ParseException { - given(this.pets.findPetTypes()).willReturn(makePetTypes()); - PetType petType = petTypeFormatter.parse("Bird", Locale.ENGLISH); - assertThat(petType.getName()).isEqualTo("Bird"); - } - - @Test - void shouldThrowParseException() throws ParseException { - given(this.pets.findPetTypes()).willReturn(makePetTypes()); - Assertions.assertThrows(ParseException.class, () -> { - petTypeFormatter.parse("Fish", Locale.ENGLISH); - }); - } - - /** - * Helper method to produce some sample pet types just for test purpose - * @return {@link Collection} of {@link PetType} - */ - private List makePetTypes() { - List petTypes = new ArrayList<>(); - petTypes.add(new PetType() { - { - setName("Dog"); - } - }); - petTypes.add(new PetType() { - { - setName("Bird"); - } - }); - return petTypes; - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java b/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java deleted file mode 100644 index 7f456cc..0000000 --- a/src/test/java/org/springframework/samples/petclinic/owner/VisitControllerTests.java +++ /dev/null @@ -1,89 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.owner; - -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.model; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.view; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.test.web.servlet.MockMvc; - -/** - * Test class for {@link VisitController} - * - * @author Colin But - */ -@WebMvcTest(VisitController.class) -@DisabledInNativeImage -class VisitControllerTests { - - private static final int TEST_OWNER_ID = 1; - - private static final int TEST_PET_ID = 1; - - @Autowired - private MockMvc mockMvc; - - @MockBean - private OwnerRepository owners; - - @BeforeEach - void init() { - Owner owner = new Owner(); - Pet pet = new Pet(); - owner.addPet(pet); - pet.setId(TEST_PET_ID); - given(this.owners.findById(TEST_OWNER_ID)).willReturn(owner); - } - - @Test - void testInitNewVisitForm() throws Exception { - mockMvc.perform(get("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID)) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdateVisitForm")); - } - - @Test - void testProcessNewVisitFormSuccess() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID) - .param("name", "George") - .param("description", "Visit Description")) - .andExpect(status().is3xxRedirection()) - .andExpect(view().name("redirect:/owners/{ownerId}")); - } - - @Test - void testProcessNewVisitFormHasErrors() throws Exception { - mockMvc - .perform(post("/owners/{ownerId}/pets/{petId}/visits/new", TEST_OWNER_ID, TEST_PET_ID).param("name", - "George")) - .andExpect(model().attributeHasErrors("visit")) - .andExpect(status().isOk()) - .andExpect(view().name("pets/createOrUpdateVisitForm")); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java b/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java deleted file mode 100644 index d7240f3..0000000 --- a/src/test/java/org/springframework/samples/petclinic/service/ClinicServiceTests.java +++ /dev/null @@ -1,228 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.service; - -import static org.assertj.core.api.Assertions.assertThat; - -import java.time.LocalDate; -import java.util.Collection; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase; -import org.springframework.boot.test.autoconfigure.jdbc.AutoConfigureTestDatabase.Replace; -import org.springframework.boot.test.autoconfigure.orm.jpa.DataJpaTest; -import org.springframework.context.annotation.ComponentScan; -import org.springframework.data.domain.Page; -import org.springframework.data.domain.Pageable; -import org.springframework.samples.petclinic.owner.Owner; -import org.springframework.samples.petclinic.owner.OwnerRepository; -import org.springframework.samples.petclinic.owner.Pet; -import org.springframework.samples.petclinic.owner.PetType; -import org.springframework.samples.petclinic.owner.Visit; -import org.springframework.samples.petclinic.vet.Vet; -import org.springframework.samples.petclinic.vet.VetRepository; -import org.springframework.stereotype.Service; -import org.springframework.transaction.annotation.Transactional; - -/** - * Integration test of the Service and the Repository layer. - *

- * ClinicServiceSpringDataJpaTests subclasses benefit from the following services provided - * by the Spring TestContext Framework: - *

- *
    - *
  • Spring IoC container caching which spares us unnecessary set up - * time between test execution.
  • - *
  • Dependency Injection of test fixture instances, meaning that we - * don't need to perform application context lookups. See the use of - * {@link Autowired @Autowired} on the instance variable, which uses - * autowiring by type. - *
  • Transaction management, meaning each test method is executed in - * its own transaction, which is automatically rolled back by default. Thus, even if tests - * insert or otherwise change database state, there is no need for a teardown or cleanup - * script. - *
  • An {@link org.springframework.context.ApplicationContext ApplicationContext} is - * also inherited and can be used for explicit bean lookup if necessary.
  • - *
- * - * @author Ken Krebs - * @author Rod Johnson - * @author Juergen Hoeller - * @author Sam Brannen - * @author Michael Isvy - * @author Dave Syer - */ -@DataJpaTest(includeFilters = @ComponentScan.Filter(Service.class)) -// Ensure that if the mysql profile is active we connect to the real database: -@AutoConfigureTestDatabase(replace = Replace.NONE) -// @TestPropertySource("/application-postgres.properties") -class ClinicServiceTests { - - @Autowired - protected OwnerRepository owners; - - @Autowired - protected VetRepository vets; - - Pageable pageable; - - @Test - void shouldFindOwnersByLastName() { - Page owners = this.owners.findByLastName("Davis", pageable); - assertThat(owners).hasSize(2); - - owners = this.owners.findByLastName("Daviss", pageable); - assertThat(owners).isEmpty(); - } - - @Test - void shouldFindSingleOwnerWithPet() { - Owner owner = this.owners.findById(1); - assertThat(owner.getLastName()).startsWith("Franklin"); - assertThat(owner.getPets()).hasSize(1); - assertThat(owner.getPets().get(0).getType()).isNotNull(); - assertThat(owner.getPets().get(0).getType().getName()).isEqualTo("cat"); - } - - @Test - @Transactional - void shouldInsertOwner() { - Page owners = this.owners.findByLastName("Schultz", pageable); - int found = (int) owners.getTotalElements(); - - Owner owner = new Owner(); - owner.setFirstName("Sam"); - owner.setLastName("Schultz"); - owner.setAddress("4, Evans Street"); - owner.setCity("Wollongong"); - owner.setTelephone("4444444444"); - this.owners.save(owner); - assertThat(owner.getId().longValue()).isNotEqualTo(0); - - owners = this.owners.findByLastName("Schultz", pageable); - assertThat(owners.getTotalElements()).isEqualTo(found + 1); - } - - @Test - @Transactional - void shouldUpdateOwner() { - Owner owner = this.owners.findById(1); - String oldLastName = owner.getLastName(); - String newLastName = oldLastName + "X"; - - owner.setLastName(newLastName); - this.owners.save(owner); - - // retrieving new name from database - owner = this.owners.findById(1); - assertThat(owner.getLastName()).isEqualTo(newLastName); - } - - @Test - void shouldFindAllPetTypes() { - Collection petTypes = this.owners.findPetTypes(); - - PetType petType1 = EntityUtils.getById(petTypes, PetType.class, 1); - assertThat(petType1.getName()).isEqualTo("cat"); - PetType petType4 = EntityUtils.getById(petTypes, PetType.class, 4); - assertThat(petType4.getName()).isEqualTo("snake"); - } - - @Test - @Transactional - void shouldInsertPetIntoDatabaseAndGenerateId() { - Owner owner6 = this.owners.findById(6); - int found = owner6.getPets().size(); - - Pet pet = new Pet(); - pet.setName("bowser"); - Collection types = this.owners.findPetTypes(); - pet.setType(EntityUtils.getById(types, PetType.class, 2)); - pet.setBirthDate(LocalDate.now()); - owner6.addPet(pet); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - - this.owners.save(owner6); - - owner6 = this.owners.findById(6); - assertThat(owner6.getPets().size()).isEqualTo(found + 1); - // checks that id has been generated - pet = owner6.getPet("bowser"); - assertThat(pet.getId()).isNotNull(); - } - - @Test - @Transactional - void shouldUpdatePetName() throws Exception { - Owner owner6 = this.owners.findById(6); - Pet pet7 = owner6.getPet(7); - String oldName = pet7.getName(); - - String newName = oldName + "X"; - pet7.setName(newName); - this.owners.save(owner6); - - owner6 = this.owners.findById(6); - pet7 = owner6.getPet(7); - assertThat(pet7.getName()).isEqualTo(newName); - } - - @Test - void shouldFindVets() { - Collection vets = this.vets.findAll(); - - Vet vet = EntityUtils.getById(vets, Vet.class, 3); - assertThat(vet.getLastName()).isEqualTo("Douglas"); - assertThat(vet.getNrOfSpecialties()).isEqualTo(2); - assertThat(vet.getSpecialties().get(0).getName()).isEqualTo("dentistry"); - assertThat(vet.getSpecialties().get(1).getName()).isEqualTo("surgery"); - } - - @Test - @Transactional - void shouldAddNewVisitForPet() { - Owner owner6 = this.owners.findById(6); - Pet pet7 = owner6.getPet(7); - int found = pet7.getVisits().size(); - Visit visit = new Visit(); - visit.setDescription("test"); - - owner6.addVisit(pet7.getId(), visit); - this.owners.save(owner6); - - owner6 = this.owners.findById(6); - - assertThat(pet7.getVisits()) // - .hasSize(found + 1) // - .allMatch(value -> value.getId() != null); - } - - @Test - void shouldFindVisitsByPetId() throws Exception { - Owner owner6 = this.owners.findById(6); - Pet pet7 = owner6.getPet(7); - Collection visits = pet7.getVisits(); - - assertThat(visits) // - .hasSize(2) // - .element(0) - .extracting(Visit::getDate) - .isNotNull(); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java b/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java deleted file mode 100644 index 7b7a5e6..0000000 --- a/src/test/java/org/springframework/samples/petclinic/service/EntityUtils.java +++ /dev/null @@ -1,53 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.service; - -import org.springframework.orm.ObjectRetrievalFailureException; -import org.springframework.samples.petclinic.model.BaseEntity; - -import java.util.Collection; - -/** - * Utility methods for handling entities. Separate from the BaseEntity class mainly - * because of dependency on the ORM-associated ObjectRetrievalFailureException. - * - * @author Juergen Hoeller - * @author Sam Brannen - * @see org.springframework.samples.petclinic.model.BaseEntity - * @since 29.10.2003 - */ -public abstract class EntityUtils { - - /** - * Look up the entity of the given class with the given id in the given collection. - * @param entities the collection to search - * @param entityClass the entity class to look up - * @param entityId the entity id to look up - * @return the found entity - * @throws ObjectRetrievalFailureException if the entity was not found - */ - public static T getById(Collection entities, Class entityClass, int entityId) - throws ObjectRetrievalFailureException { - for (T entity : entities) { - if (entity.getId() == entityId && entityClass.isInstance(entity)) { - return entity; - } - } - throw new ObjectRetrievalFailureException(entityClass, entityId); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerIntegrationTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerIntegrationTests.java deleted file mode 100644 index 4edf2af..0000000 --- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerIntegrationTests.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.system; - -import static org.assertj.core.api.Assertions.assertThat; -import static org.springframework.boot.test.context.SpringBootTest.WebEnvironment.RANDOM_PORT; - -import java.util.List; -import java.util.Map; - -import org.junit.jupiter.api.Test; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.beans.factory.annotation.Value; -import org.springframework.boot.autoconfigure.SpringBootApplication; -import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration; -import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration; -import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration; -import org.springframework.boot.test.context.SpringBootTest; -import org.springframework.boot.test.web.client.TestRestTemplate; -import org.springframework.core.ParameterizedTypeReference; -import org.springframework.http.HttpEntity; -import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpMethod; -import org.springframework.http.MediaType; -import org.springframework.http.RequestEntity; -import org.springframework.http.ResponseEntity; - -/** - * Integration Test for {@link CrashController}. - * - * @author Alex Lutz - */ -// NOT Waiting https://github.com/spring-projects/spring-boot/issues/5574 -@SpringBootTest(webEnvironment = RANDOM_PORT, - properties = { "server.error.include-message=ALWAYS", "management.endpoints.enabled-by-default=false" }) -class CrashControllerIntegrationTests { - - @SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, - DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class }) - static class TestConfiguration { - - } - - @Value(value = "${local.server.port}") - private int port; - - @Autowired - private TestRestTemplate rest; - - @Test - void testTriggerExceptionJson() { - ResponseEntity> resp = rest.exchange( - RequestEntity.get("http://localhost:" + port + "/oups").build(), - new ParameterizedTypeReference>() { - }); - assertThat(resp).isNotNull(); - assertThat(resp.getStatusCode().is5xxServerError()); - assertThat(resp.getBody().containsKey("timestamp")); - assertThat(resp.getBody().containsKey("status")); - assertThat(resp.getBody().containsKey("error")); - assertThat(resp.getBody()).containsEntry("message", - "Expected: controller used to showcase what happens when an exception is thrown"); - assertThat(resp.getBody()).containsEntry("path", "/oups"); - } - - @Test - void testTriggerExceptionHtml() { - HttpHeaders headers = new HttpHeaders(); - headers.setAccept(List.of(MediaType.TEXT_HTML)); - ResponseEntity resp = rest.exchange("http://localhost:" + port + "/oups", HttpMethod.GET, - new HttpEntity<>(headers), String.class); - assertThat(resp).isNotNull(); - assertThat(resp.getStatusCode().is5xxServerError()); - assertThat(resp.getBody()).isNotNull(); - // html: - assertThat(resp.getBody()).containsSubsequence("", "

", "Something happened...", "

", "

", - "Expected:", "controller", "used", "to", "showcase", "what", "happens", "when", "an", "exception", "is", - "thrown", "

", ""); - // Not the whitelabel error page: - assertThat(resp.getBody()).doesNotContain("Whitelabel Error Page", - "This application has no explicit mapping for"); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java b/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java deleted file mode 100644 index 65d3b89..0000000 --- a/src/test/java/org/springframework/samples/petclinic/system/CrashControllerTests.java +++ /dev/null @@ -1,46 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.system; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertThrows; - -import org.junit.jupiter.api.Test; - -/** - * Test class for {@link CrashController} - * - * @author Colin But - * @author Alex Lutz - */ -// Waiting https://github.com/spring-projects/spring-boot/issues/5574 ..good -// luck ((plain(st) UNIT test)! :) -class CrashControllerTests { - - CrashController testee = new CrashController(); - - @Test - void testTriggerException() throws Exception { - RuntimeException thrown = assertThrows(RuntimeException.class, () -> { - testee.triggerException(); - }); - - assertEquals("Expected: controller used to showcase what happens when an exception is thrown", - thrown.getMessage()); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java deleted file mode 100644 index 739ac01..0000000 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetControllerTests.java +++ /dev/null @@ -1,98 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ - -package org.springframework.samples.petclinic.vet; - -import org.assertj.core.util.Lists; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.condition.DisabledInNativeImage; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest; -import org.springframework.boot.test.mock.mockito.MockBean; -import org.springframework.data.domain.PageImpl; -import org.springframework.data.domain.Pageable; -import org.springframework.http.MediaType; -import org.springframework.test.web.servlet.MockMvc; -import org.springframework.test.web.servlet.ResultActions; -import org.springframework.test.web.servlet.request.MockMvcRequestBuilders; - -import static org.mockito.ArgumentMatchers.any; -import static org.mockito.BDDMockito.given; -import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; -import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; - -/** - * Test class for the {@link VetController} - */ - -@WebMvcTest(VetController.class) -@DisabledInNativeImage -class VetControllerTests { - - @Autowired - private MockMvc mockMvc; - - @MockBean - private VetRepository vets; - - private Vet james() { - Vet james = new Vet(); - james.setFirstName("James"); - james.setLastName("Carter"); - james.setId(1); - return james; - } - - private Vet helen() { - Vet helen = new Vet(); - helen.setFirstName("Helen"); - helen.setLastName("Leary"); - helen.setId(2); - Specialty radiology = new Specialty(); - radiology.setId(1); - radiology.setName("radiology"); - helen.addSpecialty(radiology); - return helen; - } - - @BeforeEach - void setup() { - given(this.vets.findAll()).willReturn(Lists.newArrayList(james(), helen())); - given(this.vets.findAll(any(Pageable.class))) - .willReturn(new PageImpl(Lists.newArrayList(james(), helen()))); - - } - - @Test - void testShowVetListHtml() throws Exception { - - mockMvc.perform(MockMvcRequestBuilders.get("/vets.html?page=1")) - .andExpect(status().isOk()) - .andExpect(model().attributeExists("listVets")) - .andExpect(view().name("vets/vetList")); - - } - - @Test - void testShowResourcesVetList() throws Exception { - ResultActions actions = mockMvc.perform(get("/vets").accept(MediaType.APPLICATION_JSON)) - .andExpect(status().isOk()); - actions.andExpect(content().contentType(MediaType.APPLICATION_JSON)) - .andExpect(jsonPath("$.vetList[0].id").value(1)); - } - -} diff --git a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java b/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java deleted file mode 100644 index d8df78b..0000000 --- a/src/test/java/org/springframework/samples/petclinic/vet/VetTests.java +++ /dev/null @@ -1,40 +0,0 @@ -/* - * Copyright 2012-2019 the original author or authors. - * - * Licensed under the Apache License, Version 2.0 (the "License"); - * you may not use this file except in compliance with the License. - * You may obtain a copy of the License at - * - * https://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.springframework.samples.petclinic.vet; - -import org.junit.jupiter.api.Test; -import org.springframework.util.SerializationUtils; - -import static org.assertj.core.api.Assertions.assertThat; - -/** - * @author Dave Syer - */ -class VetTests { - - @Test - void testSerialization() { - Vet vet = new Vet(); - vet.setFirstName("Zaphod"); - vet.setLastName("Beeblebrox"); - vet.setId(123); - Vet other = (Vet) SerializationUtils.deserialize(SerializationUtils.serialize(vet)); - assertThat(other.getFirstName()).isEqualTo(vet.getFirstName()); - assertThat(other.getLastName()).isEqualTo(vet.getLastName()); - assertThat(other.getId()).isEqualTo(vet.getId()); - } - -} diff --git a/src/test/jmeter/petclinic_test_plan.jmx b/src/test/jmeter/petclinic_test_plan.jmx deleted file mode 100644 index 8014ffb..0000000 --- a/src/test/jmeter/petclinic_test_plan.jmx +++ /dev/null @@ -1,487 +0,0 @@ - - - - - - false - false - - - - PETCLINIC_HOST - localhost - = - - - PETCLINIC_PORT - 8080 - = - - - CONTEXT_WEB - - = - - - - - - - - continue - - false - 10 - - 500 - 10 - 1361531541000 - 1361531541000 - false - - - true - Original : 500 - 10 - 10 - - - - 300 - - - - - - - ${PETCLINIC_HOST} - ${PETCLINIC_PORT} - - - - - - 4 - - - - - true - - - - 1 - 3 - 1 - count - - false - - - - 1 - 3 - 1 - petCount - - false - - - - - - - - - - - - - ${CONTEXT_WEB}/ - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/resources/css/petclinic.css - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/webjars/bootstrap/5.2.3/dist/js/bootstrap.bundle.min.js - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/vets.html - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/find - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners?lastName= - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count} - GET - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/edit - GET - true - false - true - false - false - - - - - - - - false - Test - = - true - firstName - - - false - ${count} - = - true - lastName - - - false - 1234+Test+St. - = - true - address - - - false - TestCity - = - true - city - - - false - 612345678 - = - true - telephone - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/edit - POST - true - false - true - false - false - - - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/new - GET - true - false - true - false - false - - - - - - - - false - Test+Fluffy+${petCount} - = - true - name - - - false - 2020-12-20 - = - true - birthDate - - - false - cat - = - true - type - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/new - POST - true - false - true - false - false - - - - - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new - GET - true - false - true - false - - - - - - - - - - false - 2013-02-22 - = - true - date - - - false - visit - = - true - description - - - - - - - - ${CONTEXT_WEB}/owners/${count}/pets/${petCount}/visits/new - POST - true - false - true - false - false - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - false - false - false - false - false - false - 0 - true - true - - - - - - - false - - saveConfig - - - true - true - true - - true - true - true - true - false - true - true - false - false - false - false - false - false - false - false - 0 - true - true - - - - - - - - - From 939e7f365a3e64f003b41ad5e2d5da5d5d0d7a72 Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:24:05 +0530 Subject: [PATCH 10/11] Rename streamline.yml to main.yml --- .github/workflows/{streamline.yml => main.yml} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename .github/workflows/{streamline.yml => main.yml} (100%) diff --git a/.github/workflows/streamline.yml b/.github/workflows/main.yml similarity index 100% rename from .github/workflows/streamline.yml rename to .github/workflows/main.yml From e7714f7e9041ae1022b3a72115f768ef6c60f49a Mon Sep 17 00:00:00 2001 From: ankitbansal360 <80330786+ankitbansal360@users.noreply.github.com> Date: Mon, 28 Aug 2023 14:40:43 +0530 Subject: [PATCH 11/11] Update main.yml --- .github/workflows/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/main.yml b/.github/workflows/main.yml index e0b2e0e..9348bda 100644 --- a/.github/workflows/main.yml +++ b/.github/workflows/main.yml @@ -3,7 +3,7 @@ name: Azure Web App Container Deployment on: push: branches: - - feature # Change this to your default branch + - ankit-features # Change this to your default branch jobs: build-and-deploy: