prevent deleting memberhsip via service call

This commit is contained in:
Michael Hoennig 2019-04-11 16:52:50 +02:00
parent 4fdcf77e8e
commit c6bf856b34
7 changed files with 54 additions and 12 deletions

View File

@ -1,17 +1,15 @@
package org.hostsharing.hsadminng.domain; package org.hostsharing.hsadminng.domain;
import com.fasterxml.jackson.annotation.JsonIgnore;
import com.fasterxml.jackson.annotation.JsonIgnoreProperties; import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
import javax.persistence.*; import javax.persistence.*;
import javax.validation.constraints.*; import javax.validation.constraints.NotNull;
import java.io.Serializable; import java.io.Serializable;
import java.time.LocalDate; import java.time.LocalDate;
import java.util.HashSet; import java.util.HashSet;
import java.util.Set;
import java.util.Objects; import java.util.Objects;
import java.util.Set;
/** /**
* A Membership. * A Membership.
@ -22,6 +20,8 @@ public class Membership implements Serializable {
private static final long serialVersionUID = 1L; private static final long serialVersionUID = 1L;
public static final String ENTITY_NAME = "membership";
@Id @Id
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator") @GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
@SequenceGenerator(name = "sequenceGenerator") @SequenceGenerator(name = "sequenceGenerator")

View File

@ -4,9 +4,9 @@ import org.hostsharing.hsadminng.domain.Membership;
import org.hostsharing.hsadminng.repository.MembershipRepository; import org.hostsharing.hsadminng.repository.MembershipRepository;
import org.hostsharing.hsadminng.service.dto.MembershipDTO; import org.hostsharing.hsadminng.service.dto.MembershipDTO;
import org.hostsharing.hsadminng.service.mapper.MembershipMapper; import org.hostsharing.hsadminng.service.mapper.MembershipMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
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.stereotype.Service; import org.springframework.stereotype.Service;
@ -73,12 +73,12 @@ public class MembershipService {
} }
/** /**
* Delete the membership by id. * Prevent deleting a membership by id via service call.
* *
* @param id the id of the entity * @param id the id of the entity
*/ */
public void delete(Long id) { public void delete(Long id) {
log.debug("Request to delete Membership : {}", id); log.debug("Request to delete Membership : {}", id);
membershipRepository.deleteById(id); throw new BadRequestAlertException("Membership cannot be deleted", Membership.ENTITY_NAME, "membershipNotDeletable");
} }
} }

View File

@ -85,7 +85,7 @@ public class ShareService {
} }
/** /**
* Delete the share by id. * Prevent deleting a share transaction by id via service call
* *
* @param id the id of the entity * @param id the id of the entity
*/ */

View File

@ -2,6 +2,7 @@
"error": { "error": {
"shareSubscriptionPositivQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl", "shareSubscriptionPositivQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive Stückzahl",
"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'"
} }
} }

View File

@ -2,6 +2,7 @@
"error": { "error": {
"shareSubscriptionPositivQuantity": "Share subscriptions require a positive quantity", "shareSubscriptionPositivQuantity": "Share subscriptions require a positive quantity",
"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'"
} }
} }

View File

@ -0,0 +1,40 @@
package org.hostsharing.hsadminng.service;
import org.apache.commons.lang3.RandomUtils;
import org.hostsharing.hsadminng.repository.MembershipRepository;
import org.hostsharing.hsadminng.service.mapper.MembershipMapper;
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnit;
import org.mockito.junit.MockitoRule;
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.catchThrowableOfType;
public class MembershipServiceUnitTest {
@Rule
public MockitoRule mockitoRule = MockitoJUnit.rule();
@Mock
private MembershipRepository membershipRepository;
@Mock
private MembershipMapper membershipMapper;
@InjectMocks
private MembershipService membershipService;
@Test
public void deleteIsRejectedForMembership() {
// when
final Throwable throwException = catchThrowableOfType(() -> membershipService.delete(RandomUtils.nextLong()), BadRequestAlertException.class);
// then
assertThat(throwException).isEqualToComparingFieldByField(
new BadRequestAlertException("Membership cannot be deleted", "membership", "membershipNotDeletable"));
}
}

View File

@ -32,7 +32,7 @@ public class ShareServiceUnitTest {
private ShareRepository shareRepository; private ShareRepository shareRepository;
@Mock @Mock
private ShareMapper shareMapper; // = new ShareMapperImpl(); private ShareMapper shareMapper;
@InjectMocks @InjectMocks
private ShareService shareService; private ShareService shareService;