diff --git a/build.gradle b/build.gradle index e664287e..7f1f6b7f 100644 --- a/build.gradle +++ b/build.gradle @@ -31,6 +31,7 @@ plugins { } apply plugin: 'java' +apply plugin: 'jacoco' apply plugin: 'org.owasp.dependencycheck' sourceCompatibility=1.8 targetCompatibility=1.8 @@ -111,6 +112,75 @@ test { reports.html.enabled = false } +// --- JaCoCo Code Coverage --- + +jacoco { + toolVersion = "0.8.3" +} + +test.finalizedBy jacocoTestReport +check.dependsOn jacocoTestCoverageVerification + +// Only for purely JHipster/MapStruct generated classes. +// Please do NOT add any self coded classes! +// Keep in mind, git will blame you ;-) +def jhipsterGeneratedClassesWithDecentCoverage = [ + 'org.hostsharing.hsadminng.repository.CustomAuditEventRepository', + 'org.hostsharing.hsadminng.service.ContactQueryService', + 'org.hostsharing.hsadminng.service.UserService', + 'org.hostsharing.hsadminng.service.CustomerContactQueryService' +] + +// Only for purely JHipster/MapStruct generated classes. +// Please do NOT add any self coded classes! +// Keep in mind, git will blame you ;-) +def jhipsterGeneratedClassesWithLowCoverage = [ + 'org.hostsharing.hsadminng.service.MailService', + 'org.hostsharing.hsadminng.security.SecurityUtils', + 'org.hostsharing.hsadminng.config.DefaultProfileUtil', + 'org.hostsharing.hsadminng.config.WebConfigurer', + 'org.hostsharing.hsadminng.web.rest.AccountResource', + 'org.hostsharing.hsadminng.web.rest.errors.ExceptionTranslator', + 'org.hostsharing.hsadminng.web.rest.errors.CustomParameterizedException', + 'org.hostsharing.hsadminng.config.audit.AuditEventConverter', + 'org.hostsharing.hsadminng.security.jwt.TokenProvider', + 'org.hostsharing.hsadminng.aop.logging.LoggingAspect', + 'org.hostsharing.hsadminng.HsadminNgApp', + '*.*QueryService', + '*.*Configuration', + '*MapperImpl', + '*Criteria', + '*_' +] + +jacocoTestCoverageVerification { + violationRules { + rule { + element = 'CLASS' + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + // Increasing the threshold is fine, decreasing is not. + // Keep in mind, git will blame you ;-) + minimum = 0.95 + } + excludes = jhipsterGeneratedClassesWithDecentCoverage + jhipsterGeneratedClassesWithLowCoverage + } + + rule { + element = 'CLASS' + limit { + counter = 'BRANCH' + value = 'COVEREDRATIO' + minimum = 0.85 + } + includes = jhipsterGeneratedClassesWithDecentCoverage + } + } +} + +// --- Cucumber BDD Tests --- + task cucumberTest(type: Test) { description = "Execute cucumber BDD tests." group = "verification" @@ -133,6 +203,8 @@ task cucumberTestReport(type: TestReport) { reportOn cucumberTest } +// ------------------------------ + apply from: 'gradle/docker.gradle' apply from: 'gradle/sonar.gradle' apply from: 'gradle/swagger.gradle' diff --git a/src/main/java/org/hostsharing/hsadminng/web/rest/ShareResource.java b/src/main/java/org/hostsharing/hsadminng/web/rest/ShareResource.java index d7c2d2f2..64bc8430 100644 --- a/src/main/java/org/hostsharing/hsadminng/web/rest/ShareResource.java +++ b/src/main/java/org/hostsharing/hsadminng/web/rest/ShareResource.java @@ -1,25 +1,24 @@ package org.hostsharing.hsadminng.web.rest; + +import io.github.jhipster.web.util.ResponseUtil; +import org.hostsharing.hsadminng.service.ShareQueryService; import org.hostsharing.hsadminng.service.ShareService; +import org.hostsharing.hsadminng.service.dto.ShareCriteria; +import org.hostsharing.hsadminng.service.dto.ShareDTO; import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException; import org.hostsharing.hsadminng.web.rest.util.HeaderUtil; import org.hostsharing.hsadminng.web.rest.util.PaginationUtil; -import org.hostsharing.hsadminng.service.dto.ShareDTO; -import org.hostsharing.hsadminng.service.dto.ShareCriteria; -import org.hostsharing.hsadminng.service.ShareQueryService; -import io.github.jhipster.web.util.ResponseUtil; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.data.domain.Page; import org.springframework.data.domain.Pageable; import org.springframework.http.HttpHeaders; -import org.springframework.http.HttpStatus; import org.springframework.http.ResponseEntity; import org.springframework.web.bind.annotation.*; import javax.validation.Valid; import java.net.URI; import java.net.URISyntaxException; - import java.util.List; import java.util.Optional; @@ -74,13 +73,8 @@ public class ShareResource { @PutMapping("/shares") public ResponseEntity updateShare(@Valid @RequestBody ShareDTO shareDTO) throws URISyntaxException { log.debug("REST request to update Share : {}", shareDTO); - if (shareDTO.getId() == null) { - throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); - } - ShareDTO result = shareService.save(shareDTO); - return ResponseEntity.ok() - .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, shareDTO.getId().toString())) - .body(result); + // TODO mhoennig: Rather completely remove the endpoint? + throw new BadRequestAlertException("Shares are immutable", ENTITY_NAME, "shareTransactionImmutable"); } /** @@ -132,7 +126,7 @@ public class ShareResource { @DeleteMapping("/shares/{id}") public ResponseEntity deleteShare(@PathVariable Long id) { log.debug("REST request to delete Share : {}", id); - shareService.delete(id); - return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + // TODO mhoennig: Rather completely remove the endpoint? + throw new BadRequestAlertException("Shares are immutable", ENTITY_NAME, "shareTransactionImmutable"); } }