code coverage improved for MembershipResource and CustomerResource

and Customer not explicitly deletable anymore
This commit is contained in:
Michael Hoennig 2019-04-27 12:05:30 +02:00
parent 3b0d46a4c8
commit efa2972375
6 changed files with 50 additions and 27 deletions

View File

@ -131,7 +131,7 @@ public class CustomerResource {
@DeleteMapping("/customers/{id}") @DeleteMapping("/customers/{id}")
public ResponseEntity<Void> deleteCustomer(@PathVariable Long id) { public ResponseEntity<Void> deleteCustomer(@PathVariable Long id) {
log.debug("REST request to delete Customer : {}", id); log.debug("REST request to delete Customer : {}", id);
customerService.delete(id); // TODO mhoennig: Rather completely remove the endpoint?
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); throw new BadRequestAlertException("Customres can't be deleted", ENTITY_NAME, "customerNotDeletable");
} }
} }

View File

@ -1,25 +1,24 @@
package org.hostsharing.hsadminng.web.rest; package org.hostsharing.hsadminng.web.rest;
import io.github.jhipster.web.util.ResponseUtil;
import org.hostsharing.hsadminng.service.MembershipQueryService;
import org.hostsharing.hsadminng.service.MembershipService; import org.hostsharing.hsadminng.service.MembershipService;
import org.hostsharing.hsadminng.service.dto.MembershipCriteria;
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException; import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.hostsharing.hsadminng.web.rest.util.HeaderUtil; import org.hostsharing.hsadminng.web.rest.util.HeaderUtil;
import org.hostsharing.hsadminng.web.rest.util.PaginationUtil; import org.hostsharing.hsadminng.web.rest.util.PaginationUtil;
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
import org.hostsharing.hsadminng.service.dto.MembershipCriteria;
import org.hostsharing.hsadminng.service.MembershipQueryService;
import io.github.jhipster.web.util.ResponseUtil;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.data.domain.Page; import org.springframework.data.domain.Page;
import org.springframework.data.domain.Pageable; import org.springframework.data.domain.Pageable;
import org.springframework.http.HttpHeaders; import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity; import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
import javax.validation.Valid; import javax.validation.Valid;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import java.util.List; import java.util.List;
import java.util.Optional; import java.util.Optional;
@ -132,7 +131,7 @@ public class MembershipResource {
@DeleteMapping("/memberships/{id}") @DeleteMapping("/memberships/{id}")
public ResponseEntity<Void> deleteMembership(@PathVariable Long id) { public ResponseEntity<Void> deleteMembership(@PathVariable Long id) {
log.debug("REST request to delete Membership : {}", id); log.debug("REST request to delete Membership : {}", id);
membershipService.delete(id); // TODO mhoennig: Rather completely remove the endpoint?
return ResponseEntity.ok().headers(HeaderUtil.createEntityDeletionAlert(ENTITY_NAME, id.toString())).build(); throw new BadRequestAlertException("Memberships can't be deleted", ENTITY_NAME, "membershipNotDeletable");
} }
} }

View File

@ -5,6 +5,7 @@
"shareCancellationNegativeQuantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl", "shareCancellationNegativeQuantity": "Kündigungen von Geschäftsanteilen erfordern eine negative Stückzahl",
"shareTransactionImmutable": "Transaktionen mit Geschäftsanteilen sind unveränderlich", "shareTransactionImmutable": "Transaktionen mit Geschäftsanteilen sind unveränderlich",
"membershipNotDeletable": "Mitgliedschaft kann nicht gelöscht werden, setze stattdessen das 'untilDate'", "membershipNotDeletable": "Mitgliedschaft kann nicht gelöscht werden, setze stattdessen das 'untilDate'",
"customerNotDeletable": "Kunden können nicht explizit gelöscht werden'",
"untilDateMustBeAfterSinceDate": "Mitgliedshafts-Austrittsdatum muss nach dem Beitrittsdatum liegen", "untilDateMustBeAfterSinceDate": "Mitgliedshafts-Austrittsdatum muss nach dem Beitrittsdatum liegen",
"anotherUncancelledMembershipExists": "Nur eine einzige ungekündigte Mitgliedschaft pro Kunde ist zulässig", "anotherUncancelledMembershipExists": "Nur eine einzige ungekündigte Mitgliedschaft pro Kunde ist zulässig",
"initializationProhibited": "Initialisierung des Feldes unzulässig", "initializationProhibited": "Initialisierung des Feldes unzulässig",

View File

@ -5,6 +5,7 @@
"shareCancellationNegativeQuantity": "Share cancellations require a negative quantity", "shareCancellationNegativeQuantity": "Share cancellations require a negative quantity",
"shareTransactionImmutable": "Share transactions are immutable", "shareTransactionImmutable": "Share transactions are immutable",
"membershipNotDeletable": "Membership cannot be deleted, instead set 'untilDate'", "membershipNotDeletable": "Membership cannot be deleted, instead set 'untilDate'",
"customerNotDeletable": "Customer cannot be deleted explicitly'",
"untilDateMustBeAfterSinceDate": "Membership until date must be after since date", "untilDateMustBeAfterSinceDate": "Membership until date must be after since date",
"anotherUncancelledMembershipExists": "Only a single uncancelled membership allowed per customer", "anotherUncancelledMembershipExists": "Only a single uncancelled membership allowed per customer",
"initializationProhibited": "Initialization of the field prohibited", "initializationProhibited": "Initialization of the field prohibited",

View File

@ -265,7 +265,7 @@ public class CustomerResourceIntTest {
public void createCustomerWithNonExistingIdIsRejected() throws Exception { public void createCustomerWithNonExistingIdIsRejected() throws Exception {
int databaseSizeBeforeCreate = customerRepository.findAll().size(); int databaseSizeBeforeCreate = customerRepository.findAll().size();
// Create the Customer with an existing ID // Create the Customer with an ID for which no entity exists
customer.setId(1L); customer.setId(1L);
CustomerDTO customerDTO = customerMapper.toDto(customer); CustomerDTO customerDTO = customerMapper.toDto(customer);
@ -434,20 +434,20 @@ public class CustomerResourceIntTest {
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE)) .andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8_VALUE))
.andExpect(jsonPath("$.id").value(customer.getId().intValue())) .andExpect(jsonPath("$.id").value(customer.getId().intValue()))
.andExpect(jsonPath("$.reference").value(DEFAULT_REFERENCE)) .andExpect(jsonPath("$.reference").value(DEFAULT_REFERENCE))
.andExpect(jsonPath("$.prefix").value(DEFAULT_PREFIX.toString())) .andExpect(jsonPath("$.prefix").value(DEFAULT_PREFIX))
.andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString())) .andExpect(jsonPath("$.name").value(DEFAULT_NAME))
.andExpect(jsonPath("$.kind").value(DEFAULT_KIND.toString())) .andExpect(jsonPath("$.kind").value(DEFAULT_KIND.toString()))
.andExpect(jsonPath("$.birthDate").value(DEFAULT_BIRTH_DATE.toString())) .andExpect(jsonPath("$.birthDate").value(DEFAULT_BIRTH_DATE.toString()))
.andExpect(jsonPath("$.birthPlace").value(DEFAULT_BIRTH_PLACE.toString())) .andExpect(jsonPath("$.birthPlace").value(DEFAULT_BIRTH_PLACE))
.andExpect(jsonPath("$.registrationCourt").value(DEFAULT_REGISTRATION_COURT.toString())) .andExpect(jsonPath("$.registrationCourt").value(DEFAULT_REGISTRATION_COURT))
.andExpect(jsonPath("$.registrationNumber").value(DEFAULT_REGISTRATION_NUMBER.toString())) .andExpect(jsonPath("$.registrationNumber").value(DEFAULT_REGISTRATION_NUMBER))
.andExpect(jsonPath("$.vatRegion").value(DEFAULT_VAT_REGION.toString())) .andExpect(jsonPath("$.vatRegion").value(DEFAULT_VAT_REGION.toString()))
.andExpect(jsonPath("$.vatNumber").value(DEFAULT_VAT_NUMBER.toString())) .andExpect(jsonPath("$.vatNumber").value(DEFAULT_VAT_NUMBER))
.andExpect(jsonPath("$.contractualSalutation").value(DEFAULT_CONTRACTUAL_SALUTATION.toString())) .andExpect(jsonPath("$.contractualSalutation").value(DEFAULT_CONTRACTUAL_SALUTATION))
.andExpect(jsonPath("$.contractualAddress").value(DEFAULT_CONTRACTUAL_ADDRESS.toString())) .andExpect(jsonPath("$.contractualAddress").value(DEFAULT_CONTRACTUAL_ADDRESS))
.andExpect(jsonPath("$.billingSalutation").value(DEFAULT_BILLING_SALUTATION.toString())) .andExpect(jsonPath("$.billingSalutation").value(DEFAULT_BILLING_SALUTATION))
.andExpect(jsonPath("$.billingAddress").value(DEFAULT_BILLING_ADDRESS.toString())) .andExpect(jsonPath("$.billingAddress").value(DEFAULT_BILLING_ADDRESS))
.andExpect(jsonPath("$.remark").value(DEFAULT_REMARK.toString())); .andExpect(jsonPath("$.remark").value(DEFAULT_REMARK));
} }
@Test @Test
@ -1269,11 +1269,11 @@ public class CustomerResourceIntTest {
// Delete the customer // Delete the customer
restCustomerMockMvc.perform(delete("/api/customers/{id}", customer.getId()) restCustomerMockMvc.perform(delete("/api/customers/{id}", customer.getId())
.accept(TestUtil.APPLICATION_JSON_UTF8)) .accept(TestUtil.APPLICATION_JSON_UTF8))
.andExpect(status().isOk()); .andExpect(status().isBadRequest());
// Validate the database is empty // Validate the database is unchanged
List<Customer> customerList = customerRepository.findAll(); List<Customer> customerList = customerRepository.findAll();
assertThat(customerList).hasSize(databaseSizeBeforeDelete - 1); assertThat(customerList).hasSize(databaseSizeBeforeDelete);
} }
@Test @Test

View File

@ -182,10 +182,32 @@ public class MembershipResourceIntTest {
@Test @Test
@Transactional @Transactional
public void createMembershipWithExistingId() throws Exception { public void createCustomerWithExistingIdIsRejected() throws Exception {
// Initialize the database
final long existingCustomerId = membershipRepository.saveAndFlush(membership).getId();
int databaseSizeBeforeCreate = membershipRepository.findAll().size(); int databaseSizeBeforeCreate = membershipRepository.findAll().size();
// Create the Membership with an existing ID // Create the Customer with an existing ID
membership.setId(existingCustomerId);
MembershipDTO membershipDTO = membershipMapper.toDto(membership);
// An entity with an existing ID cannot be created, so this API call must fail
restMembershipMockMvc.perform(post("/api/memberships")
.contentType(TestUtil.APPLICATION_JSON_UTF8)
.content(TestUtil.convertObjectToJsonBytes(membershipDTO)))
.andExpect(status().isBadRequest());
// Validate the Customer in the database
List<Membership> membershipList = membershipRepository.findAll();
assertThat(membershipList).hasSize(databaseSizeBeforeCreate);
}
@Test
@Transactional
public void createCustomerWithNonExistingIdIsRejected() throws Exception {
int databaseSizeBeforeCreate = membershipRepository.findAll().size();
// Create the Membership with an ID for which no entity exists
membership.setId(1L); membership.setId(1L);
MembershipDTO membershipDTO = membershipMapper.toDto(membership); MembershipDTO membershipDTO = membershipMapper.toDto(membership);