prevent deleting memberhsip via service call
This commit is contained in:
parent
4fdcf77e8e
commit
c6bf856b34
@ -1,17 +1,15 @@
|
||||
package org.hostsharing.hsadminng.domain;
|
||||
|
||||
|
||||
import com.fasterxml.jackson.annotation.JsonIgnore;
|
||||
import com.fasterxml.jackson.annotation.JsonIgnoreProperties;
|
||||
|
||||
import javax.persistence.*;
|
||||
import javax.validation.constraints.*;
|
||||
|
||||
import javax.validation.constraints.NotNull;
|
||||
import java.io.Serializable;
|
||||
import java.time.LocalDate;
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
import java.util.Objects;
|
||||
import java.util.Set;
|
||||
|
||||
/**
|
||||
* A Membership.
|
||||
@ -21,7 +19,9 @@ import java.util.Objects;
|
||||
public class Membership implements Serializable {
|
||||
|
||||
private static final long serialVersionUID = 1L;
|
||||
|
||||
|
||||
public static final String ENTITY_NAME = "membership";
|
||||
|
||||
@Id
|
||||
@GeneratedValue(strategy = GenerationType.SEQUENCE, generator = "sequenceGenerator")
|
||||
@SequenceGenerator(name = "sequenceGenerator")
|
||||
|
@ -4,9 +4,9 @@ import org.hostsharing.hsadminng.domain.Membership;
|
||||
import org.hostsharing.hsadminng.repository.MembershipRepository;
|
||||
import org.hostsharing.hsadminng.service.dto.MembershipDTO;
|
||||
import org.hostsharing.hsadminng.service.mapper.MembershipMapper;
|
||||
import org.hostsharing.hsadminng.web.rest.errors.BadRequestAlertException;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import org.springframework.data.domain.Page;
|
||||
import org.springframework.data.domain.Pageable;
|
||||
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
|
||||
*/
|
||||
public void delete(Long id) {
|
||||
log.debug("Request to delete Membership : {}", id);
|
||||
membershipRepository.deleteById(id);
|
||||
throw new BadRequestAlertException("Membership cannot be deleted", Membership.ENTITY_NAME, "membershipNotDeletable");
|
||||
}
|
||||
}
|
||||
|
@ -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
|
||||
*/
|
||||
|
@ -2,6 +2,7 @@
|
||||
"error": {
|
||||
"shareSubscriptionPositivQuantity": "Zeichnungen von Geschäftsanteilen erfordern eine positive 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'"
|
||||
}
|
||||
}
|
||||
|
@ -2,6 +2,7 @@
|
||||
"error": {
|
||||
"shareSubscriptionPositivQuantity": "Share subscriptions require a positive 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'"
|
||||
}
|
||||
}
|
||||
|
@ -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"));
|
||||
}
|
||||
}
|
@ -32,7 +32,7 @@ public class ShareServiceUnitTest {
|
||||
private ShareRepository shareRepository;
|
||||
|
||||
@Mock
|
||||
private ShareMapper shareMapper; // = new ShareMapperImpl();
|
||||
private ShareMapper shareMapper;
|
||||
|
||||
@InjectMocks
|
||||
private ShareService shareService;
|
||||
|
Loading…
Reference in New Issue
Block a user