From 7ba20b36872385e08747767cdf34a36692c8aac1 Mon Sep 17 00:00:00 2001 From: Michael Hoennig Date: Sat, 20 Apr 2019 10:47:01 +0200 Subject: [PATCH] improving branch coverage for AssetResourceIntTest --- README.md | 9 +++++++++ .../hsadminng/web/rest/AssetResource.java | 13 ++++--------- src/main/webapp/i18n/de/custom-error.json | 1 + src/main/webapp/i18n/en/custom-error.json | 1 + .../hsadminng/web/rest/AssetResourceIntTest.java | 6 +++--- 5 files changed, 18 insertions(+), 12 deletions(-) diff --git a/README.md b/README.md index 063c4000..836ec401 100644 --- a/README.md +++ b/README.md @@ -19,3 +19,12 @@ Either simply: or with a specific port: SERVER_PORT=8081 ./gradlew bootRun + +== Running JUnit tests with branch coverage + +=== for IntelliJ IDEA + +see: https://confluence.jetbrains.com/display/IDEADEV/IDEA+Coverage+Runner + +Either apply it to specific test configurations or, +better, delete the previous test configurations and amend the JUnit template. diff --git a/src/main/java/org/hostsharing/hsadminng/web/rest/AssetResource.java b/src/main/java/org/hostsharing/hsadminng/web/rest/AssetResource.java index 3e142f28..819dd519 100644 --- a/src/main/java/org/hostsharing/hsadminng/web/rest/AssetResource.java +++ b/src/main/java/org/hostsharing/hsadminng/web/rest/AssetResource.java @@ -74,13 +74,8 @@ public class AssetResource { @PutMapping("/assets") public ResponseEntity updateAsset(@Valid @RequestBody AssetDTO assetDTO) throws URISyntaxException { log.debug("REST request to update Asset : {}", assetDTO); - if (assetDTO.getId() == null) { - throw new BadRequestAlertException("Invalid id", ENTITY_NAME, "idnull"); - } - AssetDTO result = assetService.save(assetDTO); - return ResponseEntity.ok() - .headers(HeaderUtil.createEntityUpdateAlert(ENTITY_NAME, assetDTO.getId().toString())) - .body(result); + // TODO mhoennig: Rather completely remove the endpoint? + throw new BadRequestAlertException("Assets are immutable", ENTITY_NAME, "assetTransactionImmutable"); } /** @@ -132,7 +127,7 @@ public class AssetResource { @DeleteMapping("/assets/{id}") public ResponseEntity deleteAsset(@PathVariable Long id) { log.debug("REST request to delete Asset : {}", id); - assetService.delete(id); - return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); + // TODO mhoennig: Rather completely remove the endpoint? + throw new BadRequestAlertException("Asset are immutable", ENTITY_NAME, "assetTransactionImmutable"); } } diff --git a/src/main/webapp/i18n/de/custom-error.json b/src/main/webapp/i18n/de/custom-error.json index 08b8fd1c..8c5722c8 100644 --- a/src/main/webapp/i18n/de/custom-error.json +++ b/src/main/webapp/i18n/de/custom-error.json @@ -6,6 +6,7 @@ "membershipNotDeletable": "Mitgliedschaft kann nicht gelöscht werden, setze stattdessen das 'untilDate'", "untilDateMustBeAfterSinceDate": "Mitgliedshaftsaustrittsdatum muss nach dem Beitrittsdatum liegen", "documentDateMayNotBeAfterValueDate": "Belegdatum darf nicht vor dem Buchungsdatum liegen", + "assetTransactionImmutable": "Transaktionen mit Geschäftsguthaben sind unveränderlich", "anotherUncancelledMembershipExists": "Nur eine einzige ungekündigte Mitgliedschaft pro Kunde ist zulässig", "assetPaymentsPositiveAmount": "Einzahlungen von Geschäftsguthaben erfordern einen positiven Betrag", "assetAdoptionsPositiveAmount": "Übernahmen von Geschäftsguthaben erfordern einen positiven Betrag", diff --git a/src/main/webapp/i18n/en/custom-error.json b/src/main/webapp/i18n/en/custom-error.json index 277e3d4d..b6f699a5 100644 --- a/src/main/webapp/i18n/en/custom-error.json +++ b/src/main/webapp/i18n/en/custom-error.json @@ -7,6 +7,7 @@ "untilDateMustBeAfterSinceDate": "Membership until date must be after since date", "documentDateMayNotBeAfterValueDate": "Document date may not be after value date", "anotherUncancelledMembershipExists": "Only a single uncancelled membership allowed per customer", + "assetTransactionImmutable": "Asset transactions are immutable", "assetPaymentsPositiveAmount": "Asset payments require a positive amount", "assetAdoptionsPositiveAmount": "Asset adoptions require a positive amount", "assetPaybacksNegativeAmount": "Asset paybacks require a negative amount", diff --git a/src/test/java/org/hostsharing/hsadminng/web/rest/AssetResourceIntTest.java b/src/test/java/org/hostsharing/hsadminng/web/rest/AssetResourceIntTest.java index 53e6f60e..9074099d 100644 --- a/src/test/java/org/hostsharing/hsadminng/web/rest/AssetResourceIntTest.java +++ b/src/test/java/org/hostsharing/hsadminng/web/rest/AssetResourceIntTest.java @@ -689,11 +689,11 @@ public class AssetResourceIntTest { // Delete the asset restAssetMockMvc.perform(delete("/api/assets/{id}", asset.getId()) .accept(TestUtil.APPLICATION_JSON_UTF8)) - .andExpect(status().isOk()); + .andExpect(status().isBadRequest()); - // Validate the database is empty + // Validate the database still contains the same number of assets List assetList = assetRepository.findAll(); - assertThat(assetList).hasSize(databaseSizeBeforeDelete - 1); + assertThat(assetList).hasSize(databaseSizeBeforeDelete); } @Test