diff --git a/.github/workflows/covergae.yml b/.github/workflows/covergae.yml new file mode 100644 index 00000000..699fa487 --- /dev/null +++ b/.github/workflows/covergae.yml @@ -0,0 +1,60 @@ +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 17 + uses: actions/setup-java@v2 + with: + java-version: '17' + distribution: 'adopt' + 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_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 + run: | + cd spring-petclinic/spring-petclinic-rest + mvn clean install -Dmaven.test.skip=true + mvn test + + - name: Add coverage to PR + id: jacoco + uses: madrapps/jacoco-report@v1.6.1 + 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 + title: Code Coverage + update-comment: true + 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 < 43.0 }} + run: | + echo "Coverage of changed files is less than 60%!" + exit 1 + + 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) { 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..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 @@ -154,12 +154,16 @@ 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) { // just ignore not found exceptions for Jdbc/Jpa realization return null; } + if (petType == null) { + return null; + } return petType; }