From 22b0be22a7dea9f08a062e4ce7c6b9fbc4d5f000 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 12:17:50 +0530 Subject: [PATCH 01/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 46 ++++++++++++++++++++++++++++++++++ 1 file changed, 46 insertions(+) create mode 100644 .github/workflows/covergae.yml diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml new file mode 100644 index 00000000..b88c2a50 --- /dev/null +++ b/.github/workflows/covergae.yml @@ -0,0 +1,46 @@ +name: CI + +on: + pull_request: + branches: + - main + +jobs: + build: + runs-on: ubuntu-latest + + steps: + - uses: actions/checkout@v2 + with: + ref: 'petclinic-junit' + + - name: Set up JDK 11 + uses: actions/setup-java@v2 + with: + java-version: '11' + distribution: 'adopt' + + - name: Set up Maven + uses: actions/setup-java@v2 + with: + distribution: 'maven' + maven-version: '3.8.4' + + - name: Download and prepare Keploy binary + run: | + curl --silent --location 'https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz' | tar xz -C /tmp + sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin + + - name: Build and test with Maven and Keploy + run: | + cd spring-petclinic/spring-petclinic-rest + mvn clean install -Dmaven.test.skip=true + sudo -E env PATH="$PATH" keploybin test -c "mvn test" --delay 30 --coverage + + - name: SonarQube Analysis + run: | + cd spring-petclinic/spring-petclinic-rest + mvn clean install -Dmaven.test.skip=true + sudo -E env PATH="$PATH" keploybin test -c "mvn verify sonar:sonar -Dsonar.projectKey=msil-test-new -Dsonar.coverage.jacoco.xmlReportPaths=target/site/e2e-ut-aggregate/jacoco.xml" --delay 30 --coverage + + # Add additional steps for coverage threshold enforcement if needed From 3f23043ad96ef60fb1da847dfb3de551a930767b Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 12:21:19 +0530 Subject: [PATCH 02/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index b88c2a50..032dea3b 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -14,10 +14,10 @@ jobs: with: ref: 'petclinic-junit' - - name: Set up JDK 11 + - name: Set up JDK 17 uses: actions/setup-java@v2 with: - java-version: '11' + java-version: '17' distribution: 'adopt' - name: Set up Maven From 8d78f306066295fa3c0d77abd7448cf92434a1c1 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 12:23:42 +0530 Subject: [PATCH 03/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 5 ----- 1 file changed, 5 deletions(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 032dea3b..0066256b 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -19,11 +19,6 @@ jobs: with: java-version: '17' distribution: 'adopt' - - - name: Set up Maven - uses: actions/setup-java@v2 - with: - distribution: 'maven' maven-version: '3.8.4' - name: Download and prepare Keploy binary From 925995ed717aedcd79f1ab94bcb722c8128eed67 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 12:27:45 +0530 Subject: [PATCH 04/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 0066256b..05c0b11f 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -23,7 +23,7 @@ jobs: - name: Download and prepare Keploy binary run: | - curl --silent --location 'https://github.com/keploy/keploy/releases/latest/download/keploy_linux_arm64.tar.gz' | tar xz -C /tmp + curl --silent --location 'https://github.com/keploy/keploy/releases/latest/download/keploy_linux_amd64.tar.gz' | tar xz -C /tmp sudo mkdir -p /usr/local/bin && sudo mv /tmp/keploy /usr/local/bin/keploybin - name: Build and test with Maven and Keploy From f349182ffe48baedd4c89f8e3597f3be5a8ecb85 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 12:40:04 +0530 Subject: [PATCH 05/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 05c0b11f..f3f1e0e5 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -30,12 +30,12 @@ jobs: run: | cd spring-petclinic/spring-petclinic-rest mvn clean install -Dmaven.test.skip=true - sudo -E env PATH="$PATH" keploybin test -c "mvn test" --delay 30 --coverage + mvn test - name: SonarQube Analysis run: | cd spring-petclinic/spring-petclinic-rest mvn clean install -Dmaven.test.skip=true - sudo -E env PATH="$PATH" keploybin test -c "mvn verify sonar:sonar -Dsonar.projectKey=msil-test-new -Dsonar.coverage.jacoco.xmlReportPaths=target/site/e2e-ut-aggregate/jacoco.xml" --delay 30 --coverage + mvn verify sonar:sonar -Dsonar.projectKey=msil-test-new -Dsonar.coverage.jacoco.xmlReportPaths=target/site/e2e-ut-aggregate/jacoco.xml # Add additional steps for coverage threshold enforcement if needed From dd5665cc6b057babebda2bdee1c61b7d389fe000 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:12:22 +0530 Subject: [PATCH 06/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index f3f1e0e5..3484a4c9 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -32,10 +32,13 @@ jobs: mvn clean install -Dmaven.test.skip=true mvn test - - name: SonarQube Analysis - run: | - cd spring-petclinic/spring-petclinic-rest - mvn clean install -Dmaven.test.skip=true - mvn verify sonar:sonar -Dsonar.projectKey=msil-test-new -Dsonar.coverage.jacoco.xmlReportPaths=target/site/e2e-ut-aggregate/jacoco.xml + + - name: Publish JaCoCo report + uses: cicirello/jacoco-report@v2 + with: + jacoco-csv-file: spring-petclinic/spring-petclinic-rest/target/site/e2e-ut-aggregate/jacoco.csv + report-name: "JaCoCo Coverage Report" + minimum-coverage: 85 + fail-if-coverage-less-than-minimum: true # Add additional steps for coverage threshold enforcement if needed From b72d46d8b1028117c060587c5c33fbe236fd741f Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:25:52 +0530 Subject: [PATCH 07/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 16 +++++++--------- 1 file changed, 7 insertions(+), 9 deletions(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 3484a4c9..2539dbe0 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -32,13 +32,11 @@ jobs: mvn clean install -Dmaven.test.skip=true mvn test - - - name: Publish JaCoCo report - uses: cicirello/jacoco-report@v2 + - name: Add coverage to PR + id: jacoco + uses: madrapps/jacoco-report@v1.6.1 with: - jacoco-csv-file: spring-petclinic/spring-petclinic-rest/target/site/e2e-ut-aggregate/jacoco.csv - report-name: "JaCoCo Coverage Report" - minimum-coverage: 85 - fail-if-coverage-less-than-minimum: true - - # Add additional steps for coverage threshold enforcement if needed + paths: | + spring-petclinic/spring-petclinic-rest/target/site/e2e-ut-aggregate/jacoco.xml + min-coverage-overall: 40 + min-coverage-changed-files: 60 \ No newline at end of file From 71d70d9275c1694b107e8d23d3c0928839b75ac1 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:31:38 +0530 Subject: [PATCH 08/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 2539dbe0..a6ba6780 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -38,5 +38,8 @@ jobs: with: paths: | spring-petclinic/spring-petclinic-rest/target/site/e2e-ut-aggregate/jacoco.xml + token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 - min-coverage-changed-files: 60 \ No newline at end of file + min-coverage-changed-files: 60 + + From 68c95d46e2ae59849ea37a0fd5eb153f82221401 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:35:21 +0530 Subject: [PATCH 09/18] feat: add coverage action Signed-off-by: charankamarapu --- .../samples/petclinic/service/ClinicServiceImpl.java | 1 + 1 file changed, 1 insertion(+) diff --git a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java index 0244b39d..1290d849 100644 --- a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java +++ b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java @@ -154,6 +154,7 @@ public void deleteOwner(Owner owner) throws DataAccessException { @Transactional(readOnly = true) public PetType findPetTypeById(int petTypeId) { PetType petType = null; + petType = null; try { petType = petTypeRepository.findById(petTypeId); } catch (ObjectRetrievalFailureException|EmptyResultDataAccessException e) { From 10c56ef0ff1c550bd5dd53289353cee41930b580 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:41:25 +0530 Subject: [PATCH 10/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index a6ba6780..c9a32952 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -41,5 +41,9 @@ jobs: token: ${{ secrets.GITHUB_TOKEN }} min-coverage-overall: 40 min-coverage-changed-files: 60 + title: Code Coverage + update-comment: true + pass-emoji: ':green_circle:' + ail-emoji: ':red_circle:' From d84e609844aa49a73d878b361546722b60d9a1fc Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 14:47:14 +0530 Subject: [PATCH 11/18] feat: add coverage action Signed-off-by: charankamarapu --- .../samples/petclinic/service/ClinicServiceImpl.java | 3 +++ 1 file changed, 3 insertions(+) diff --git a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java index 1290d849..9ed66dbf 100644 --- a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java +++ b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/service/ClinicServiceImpl.java @@ -161,6 +161,9 @@ public PetType findPetTypeById(int petTypeId) { // just ignore not found exceptions for Jdbc/Jpa realization return null; } + if (petType == null) { + return null; + } return petType; } From beb3b1f540a5a95e473a62d15fdcfa157f0cabae Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 15:27:09 +0530 Subject: [PATCH 12/18] feat: add coverage action Signed-off-by: charankamarapu --- .../rest/controller/OwnerRestController.java | 12 ++++++++++++ 1 file changed, 12 insertions(+) diff --git a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/rest/controller/OwnerRestController.java b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/rest/controller/OwnerRestController.java index 116656af..d44647b7 100644 --- a/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/rest/controller/OwnerRestController.java +++ b/spring-petclinic/spring-petclinic-rest/src/main/java/org/springframework/samples/petclinic/rest/controller/OwnerRestController.java @@ -104,6 +104,18 @@ public ResponseEntity addOwner(OwnerFieldsDto ownerFieldsDto) { return new ResponseEntity<>(ownerDto, headers, HttpStatus.CREATED); } + @PreAuthorize("hasRole(@roles.OWNER_ADMIN)") + @Override + public ResponseEntity addOwnernm(OwnerFieldsDto ownerFieldsDto) { + HttpHeaders headers = new HttpHeaders(); + Owner owner = ownerMapper.toOwner(ownerFieldsDto); + this.clinicService.saveOwner(owner); + OwnerDto ownerDto = ownerMapper.toOwnerDto(owner); + headers.setLocation(UriComponentsBuilder.newInstance() + .path("/api/ownersnm/{id}").buildAndExpand(owner.getId()).toUri()); + return new ResponseEntity<>(ownerDto, headers, HttpStatus.CREATED); + } + @PreAuthorize("hasRole(@roles.OWNER_ADMIN)") @Override public ResponseEntity updateOwner(Integer ownerId, OwnerFieldsDto ownerFieldsDto) { From 268825692140657c2fb043eb2d36f1dadbc42dde Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 15:34:44 +0530 Subject: [PATCH 13/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index c9a32952..9ab49db2 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -46,4 +46,10 @@ jobs: pass-emoji: ':green_circle:' ail-emoji: ':red_circle:' + - name: Fail PR if coverage of changed files is less than 60% + if: ${{ steps.jacoco.outputs.coverage-changed-files < 60.0 }} + run: | + echo "Coverage of changed files is less than 60%!" + exit 1 + From 019dfd7ba456d2d7c0e187c0ece4fdab1212d7b5 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 16:01:48 +0530 Subject: [PATCH 14/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 9ab49db2..585ae4b7 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -47,7 +47,7 @@ jobs: ail-emoji: ':red_circle:' - name: Fail PR if coverage of changed files is less than 60% - if: ${{ steps.jacoco.outputs.coverage-changed-files < 60.0 }} + if: ${{ steps.jacoco.outputs.coverage-changed-files < 0.0 }} run: | echo "Coverage of changed files is less than 60%!" exit 1 From 852e46c25db49dd4c704fc38ad1e971abb0ed762 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 16:05:21 +0530 Subject: [PATCH 15/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 585ae4b7..2730b7cc 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -47,7 +47,7 @@ jobs: ail-emoji: ':red_circle:' - name: Fail PR if coverage of changed files is less than 60% - if: ${{ steps.jacoco.outputs.coverage-changed-files < 0.0 }} + if: ${{ steps.jacoco.outputs.coverage-changed-files < 1.0 }} run: | echo "Coverage of changed files is less than 60%!" exit 1 From 2c3253df6bbc5daab9dcf1913a70a7a2b2d6b82a Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 16:08:30 +0530 Subject: [PATCH 16/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 2730b7cc..9ab49db2 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -47,7 +47,7 @@ jobs: ail-emoji: ':red_circle:' - name: Fail PR if coverage of changed files is less than 60% - if: ${{ steps.jacoco.outputs.coverage-changed-files < 1.0 }} + if: ${{ steps.jacoco.outputs.coverage-changed-files < 60.0 }} run: | echo "Coverage of changed files is less than 60%!" exit 1 From 8d7dc6ae9daff09d55c97a1f9326242ddcabe9ba Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 16:13:01 +0530 Subject: [PATCH 17/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 9ab49db2..9b828343 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -46,8 +46,13 @@ jobs: pass-emoji: ':green_circle:' ail-emoji: ':red_circle:' + - name: Get the Coverage info + run: | + echo "Total coverage ${{ steps.jacoco.outputs.coverage-overall }}" + echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}" + - name: Fail PR if coverage of changed files is less than 60% - if: ${{ steps.jacoco.outputs.coverage-changed-files < 60.0 }} + if: ${{ steps.jacoco.outputs.coverage-changed-files < 01.0 }} run: | echo "Coverage of changed files is less than 60%!" exit 1 From d6be410d857d3068d4e199ef7f5caa2341c39e51 Mon Sep 17 00:00:00 2001 From: charankamarapu Date: Wed, 3 Apr 2024 16:23:42 +0530 Subject: [PATCH 18/18] feat: add coverage action Signed-off-by: charankamarapu --- .github/workflows/covergae.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml index 9b828343..699fa487 100644 --- a/.github/workflows/covergae.yml +++ b/.github/workflows/covergae.yml @@ -52,7 +52,7 @@ jobs: echo "Changed Files coverage ${{ steps.jacoco.outputs.coverage-changed-files }}" - name: Fail PR if coverage of changed files is less than 60% - if: ${{ steps.jacoco.outputs.coverage-changed-files < 01.0 }} + if: ${{ steps.jacoco.outputs.coverage-changed-files < 43.0 }} run: | echo "Coverage of changed files is less than 60%!" exit 1