Commit b5714d9a authored by Enriko Käsper's avatar Enriko Käsper
Browse files

Merge branch 'develop' into 'master'

Release: merge 'develop' into 'master' created by Enriko Käsper

See merge request teis/payments-service!35
parents 6199727f 94ec2348
theGroup=ee.sm.ti.teis
theVersion=1.2.1
pluginVersion=1.0.0
commonsVersion=1.4.0
officeApiGatewayVersion=1.4.0
theVersion=1.3.0
pluginVersion=1.0.1
commonsVersion=1.5.0
officeApiGatewayVersion=1.5.0
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
......@@ -138,7 +138,7 @@ public class ClaimGwListenerTest extends PaymentsAppTestBase implements Listener
assertThat(payment.getReceiptDate()).isEqualTo(LocalDate.of(2020, 1, 22));
assertThat(payment.getObjectStatus()).isEqualTo(CURRENT);
EnforcementDto enforcement = dto.getEnforcement();
EnforcementPublicDto enforcement = dto.getEnforcement();
assertThat(enforcement.getId()).isEqualTo(UUID.fromString("95aed995-6357-40cf-b675-419c5d91512e"));
assertThat(enforcement.getClaimId()).isEqualTo(CLAIM_ID);
assertThat(enforcement.getStartDate()).isEqualTo(LocalDate.of(2020, 4, 3));
......
package ee.sm.ti.teis.payments.enforcement;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.officegateway.payments.enforcement.EnforcementDto;
import ee.sm.ti.teis.officegateway.payments.enforcement.request.CreateEnforcementRequest;
import ee.sm.ti.teis.officegateway.payments.enforcement.response.CreateEnforcementResponse;
import ee.sm.ti.teis.servicecommon.test.ListenerCreateRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import java.time.LocalDate;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PAYMENTS;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
public class CreateEnforcementGwListenerTest extends PaymentsAppTestBase implements ListenerCreateRequestTestBase {
private static final UUID CLAIM_ID = UUID.fromString("03f442f9-9ac0-4238-acaa-60ffc4bd873e");
@Autowired
EnforcementGwListener listener;
CreateEnforcementRequest request;
EnforcementDto payload;
RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), emptyList());
requestMetaDTO.setPrivileges(singletonList(TI_MANAGE_PAYMENTS.name()));
payload = new EnforcementDto();
request = new CreateEnforcementRequest();
request.setPayload(payload, requestMetaDTO);
}
@Override
@Test
public void create_minimumData_success() {
payload.setClaimId(CLAIM_ID);
payload.setStartDate(LocalDate.of(2020, 5, 13));
request.setPayload(payload, requestMetaDTO);
CreateEnforcementResponse response = listener.create(request);
EnforcementDto dto = response.getPayload();
assertThat(dto.getId()).isNotNull();
assertThat(dto.getClaimId()).isEqualTo(payload.getClaimId());
assertThat(dto.getStartDate()).isEqualTo(payload.getStartDate());
assertThat(dto.getObjectStatus()).isEqualTo(CURRENT);
}
@Override
@Test
public void create_fullData_success() {
payload.setClaimId(UUID.fromString("4565f867-94be-4fe1-907d-5aa1f34766bb"));
payload.setId(UUID.fromString("936d82ce-a620-4dc0-8610-6351ef557c56"));
payload.setObjectStatus(DELETED);
payload.setStartDate(LocalDate.of(2020, 5, 13));
request.setPayload(payload, requestMetaDTO);
CreateEnforcementResponse response = listener.create(request);
EnforcementDto dto = response.getPayload();
assertThat(dto.getId()).isNotEqualTo(payload.getId());
assertThat(dto.getClaimId()).isEqualTo(payload.getClaimId());
assertThat(dto.getStartDate()).isEqualTo(payload.getStartDate());
assertThat(dto.getObjectStatus()).isEqualTo(CURRENT);
}
@Override
@Test
public void missingPrivilege_forbidden() {
request.getRequestMetaDTO().setPrivileges(emptyList());
CreateEnforcementResponse response = listener.create(request);
assertResponseForbidden(response.getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
request.getRequestMetaDTO().setUserType(PERSON);
CreateEnforcementResponse response = listener.create(request);
assertResponseForbidden(response.getError());
}
@Test
public void create_claimIdMissing_badRequest() {
payload.setStartDate(LocalDate.now());
request.setPayload(payload, requestMetaDTO);
CreateEnforcementResponse response = listener.create(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().get(0).getFieldName()).isEqualTo("create.dto.claimId");
}
@Test
public void create_startDateMissing_badRequest() {
payload.setClaimId(UUID.randomUUID());
request.setPayload(payload, requestMetaDTO);
CreateEnforcementResponse response = listener.create(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().get(0).getFieldName()).isEqualTo("create.dto.startDate");
}
}
package ee.sm.ti.teis.payments.enforcement;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.officegateway.payments.enforcement.EnforcementDto;
import ee.sm.ti.teis.officegateway.payments.enforcement.UpdateEnforcementDto;
import ee.sm.ti.teis.officegateway.payments.enforcement.request.UpdateEnforcementRequest;
import ee.sm.ti.teis.officegateway.payments.enforcement.response.UpdateEnforcementResponse;
import ee.sm.ti.teis.payments.claim.entity.EnforcementEntity;
import ee.sm.ti.teis.payments.enforcement.service.EnforcementDataService;
import ee.sm.ti.teis.servicecommon.test.ListenerUpdateRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import javax.transaction.Transactional;
import java.time.LocalDate;
import java.util.UUID;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PAYMENTS;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.Collections.singletonList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
public class UpdateEnforcementGwListenerTest extends PaymentsAppTestBase implements ListenerUpdateRequestTestBase {
private static final UUID ID = UUID.fromString("809d4f9e-a7f4-4225-8bc6-33830aa5457a");
private static final UUID CLAIM_ID = UUID.fromString("bfa0a43f-0b42-434d-ba71-a5013685cf89");
@Autowired
EnforcementGwListener listener;
@Autowired
EnforcementDataService dataService;
UpdateEnforcementRequest request;
UpdateEnforcementDto payload;
RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), emptyList());
requestMetaDTO.setPrivileges(singletonList(TI_MANAGE_PAYMENTS.name()));
payload = new UpdateEnforcementDto();
request = new UpdateEnforcementRequest();
request.setPayload(payload, requestMetaDTO);
}
@Override
@Test
public void update_idNotExists_notFound() {
payload.setId(UUID.randomUUID());
payload.setStartDate(LocalDate.now());
request.setPayload(payload, requestMetaDTO);
UpdateEnforcementResponse response = listener.update(request);
assertResponseNotFound(response.getError());
}
@Override
@Test
public void update_objectStatusDeleted_notFound() {
payload.setId(UUID.fromString("ff30b34a-f953-4696-8576-a5fea22863d1"));
payload.setStartDate(LocalDate.now());
request.setPayload(payload, requestMetaDTO);
UpdateEnforcementResponse response = listener.update(request);
assertResponseNotFound(response.getError());
}
@Override
@Test
public void update_minimumData_success() {
// not applicable
}
@Override
@Test
@Transactional
public void update_fullData_success() {
payload.setId(ID);
payload.setStartDate(LocalDate.of(2020, 2, 21));
request.setPayload(payload, requestMetaDTO);
UpdateEnforcementResponse response = listener.update(request);
EnforcementDto dto = response.getPayload();
assertThat(dto.getId()).isEqualTo(payload.getId());
assertThat(dto.getClaimId()).isEqualTo(CLAIM_ID);
assertThat(dto.getStartDate()).isEqualTo(payload.getStartDate());
assertThat(dto.getObjectStatus()).isEqualTo(CURRENT);
}
@Override
public void update_verifyObjectExistsInDatabase_success() {
payload.setId(ID);
payload.setStartDate(LocalDate.of(2020, 2, 21));
request.setPayload(payload, requestMetaDTO);
listener.update(request);
EnforcementEntity entity = dataService.getCurrentById(ID);
assertThat(entity.getId()).isEqualTo(payload.getId());
assertThat(entity.getClaim().getId()).isEqualTo(CLAIM_ID);
assertThat(entity.getStartDate()).isEqualTo(payload.getStartDate());
assertThat(entity.getObjectStatus()).isEqualTo(CURRENT);
}
@Override
@Test
public void missingPrivilege_forbidden() {
request.getRequestMetaDTO().setPrivileges(emptyList());
UpdateEnforcementResponse response = listener.update(request);
assertResponseForbidden(response.getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
request.getRequestMetaDTO().setUserType(PERSON);
UpdateEnforcementResponse response = listener.update(request);
assertResponseForbidden(response.getError());
}
@Test
public void update_idMissing_badRequest() {
request.setPayload(payload, requestMetaDTO);
payload.setStartDate(LocalDate.of(2020, 2, 21));
UpdateEnforcementResponse response = listener.update(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().get(0).getFieldName()).isEqualTo("update.dto.id");
}
@Test
public void update_startDateMissing_badRequest() {
request.setPayload(payload, requestMetaDTO);
payload.setId(UUID.randomUUID());
UpdateEnforcementResponse response = listener.update(request);
assertBadRequest(response.getError());
assertThat(response.getError().getViolations().get(0).getFieldName()).isEqualTo("update.dto.startDate");
}
}
......@@ -37,19 +37,18 @@ public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements
@Autowired
PaymentGwListener listener;
private CreatePaymentRequest createPaymentRequest;
private CreatePaymentRequest request;
private RequestMetaDTO requestMetaDTO;
private CreatePaymentDto createPayload;
private CreatePaymentDto payload;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), emptyList());
requestMetaDTO.setPrivileges(of(TI_MANAGE_PAYMENTS.name()));
createPaymentRequest = new CreatePaymentRequest();
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
createPayload = new CreatePaymentDto();
request = new CreatePaymentRequest();
request.setRequestMetaDTO(requestMetaDTO);
payload = new CreatePaymentDto();
}
@Override
......@@ -57,65 +56,65 @@ public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements
public void missingPrivilege_forbidden() {
requestMetaDTO.setPrivileges(null);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(createPaymentRequest).getError());
request.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(request).getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
request.setRequestMetaDTO(requestMetaDTO);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(createPaymentRequest).getError());
request.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(request).getError());
}
@Override
@Test
public void create_fullData_success() {
createPayload.setPayerName(PAYER_NAME);
createPayload.setReceiptDate(LocalDate.of(2020, 4, 20));
createPayload.setAmount(BigDecimal.valueOf(1000L));
createPayload.setDescription("Payment description");
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setPayerName(PAYER_NAME);
payload.setReceiptDate(LocalDate.of(2020, 4, 20));
payload.setAmount(BigDecimal.valueOf(1000L));
payload.setDescription("Payment description");
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
PaymentDto paymentDto = response.getPayload();
assertThat(paymentDto.getId()).isNotNull();
assertThat(paymentDto.getPayerName()).isEqualTo(createPayload.getPayerName());
assertThat(paymentDto.getReceiptDate()).isEqualTo(createPayload.getReceiptDate());
assertThat(paymentDto.getAmount()).isEqualTo(createPayload.getAmount());
assertThat(paymentDto.getDescription()).isEqualTo(createPayload.getDescription());
assertThat(paymentDto.getBalance()).isEqualTo(createPayload.getAmount());
assertThat(paymentDto.getPayerName()).isEqualTo(payload.getPayerName());
assertThat(paymentDto.getReceiptDate()).isEqualTo(payload.getReceiptDate());
assertThat(paymentDto.getAmount()).isEqualTo(payload.getAmount());
assertThat(paymentDto.getDescription()).isEqualTo(payload.getDescription());
assertThat(paymentDto.getBalance()).isEqualTo(payload.getAmount());
}
@Override
@Test
public void create_minimumData_success() {
createPayload.setPayerName(PAYER_NAME);
createPayload.setReceiptDate(LocalDate.of(2020, 4, 20));
createPayload.setAmount(BigDecimal.valueOf(1000L));
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setPayerName(PAYER_NAME);
payload.setReceiptDate(LocalDate.of(2020, 4, 20));
payload.setAmount(BigDecimal.valueOf(1000L));
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
PaymentDto paymentDto = response.getPayload();
assertThat(paymentDto.getId()).isNotNull();
assertThat(paymentDto.getPayerName()).isEqualTo(createPayload.getPayerName());
assertThat(paymentDto.getReceiptDate()).isEqualTo(createPayload.getReceiptDate());
assertThat(paymentDto.getAmount()).isEqualTo(createPayload.getAmount());
assertThat(paymentDto.getBalance()).isEqualTo(createPayload.getAmount());
assertThat(paymentDto.getPayerName()).isEqualTo(payload.getPayerName());
assertThat(paymentDto.getReceiptDate()).isEqualTo(payload.getReceiptDate());
assertThat(paymentDto.getAmount()).isEqualTo(payload.getAmount());
assertThat(paymentDto.getBalance()).isEqualTo(payload.getAmount());
}
@Test
public void create_missingPayerName_failure() {
createPayload.setReceiptDate(LocalDate.of(2020, 4, 20));
createPayload.setAmount(BigDecimal.valueOf(10L));
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setReceiptDate(LocalDate.of(2020, 4, 20));
payload.setAmount(BigDecimal.valueOf(10L));
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
ErrorDTO errorDto = response.getError();
assertThat(errorDto.getHttpResponse()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(errorDto.getMessage()).isEqualTo(INPUT_VALIDATION_ERROR);
......@@ -128,11 +127,11 @@ public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements
@Test
public void create_missingReceiptDate_failure() {
createPayload.setPayerName(PAYER_NAME);
createPayload.setAmount(BigDecimal.valueOf(10L));
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setPayerName(PAYER_NAME);
payload.setAmount(BigDecimal.valueOf(10L));
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
ErrorDTO errorDto = response.getError();
assertThat(errorDto.getHttpResponse()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(errorDto.getMessage()).isEqualTo(INPUT_VALIDATION_ERROR);
......@@ -145,11 +144,11 @@ public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements
@Test
public void create_missingAmount_failure() {
createPayload.setPayerName(PAYER_NAME);
createPayload.setReceiptDate(LocalDate.of(2020, 4, 20));
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setPayerName(PAYER_NAME);
payload.setReceiptDate(LocalDate.of(2020, 4, 20));
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
ErrorDTO errorDto = response.getError();
assertThat(errorDto.getHttpResponse()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(errorDto.getMessage()).isEqualTo(INPUT_VALIDATION_ERROR);
......@@ -162,12 +161,12 @@ public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements
@Test
public void create_negativeAmount_failure() {
createPayload.setPayerName(PAYER_NAME);
createPayload.setReceiptDate(LocalDate.of(2020, 4, 20));
createPayload.setAmount(BigDecimal.valueOf(-1L));
createPaymentRequest.setPayload(createPayload, requestMetaDTO);
payload.setPayerName(PAYER_NAME);
payload.setReceiptDate(LocalDate.of(2020, 4, 20));
payload.setAmount(BigDecimal.valueOf(-1L));
request.setPayload(payload, requestMetaDTO);
CreatePaymentResponse response = listener.create(createPaymentRequest);
CreatePaymentResponse response = listener.create(request);
ErrorDTO errorDto = response.getError();
assertThat(errorDto.getHttpResponse()).isEqualTo(HttpStatus.BAD_REQUEST);
assertThat(errorDto.getMessage()).isEqualTo(INPUT_VALIDATION_ERROR);
......
package ee.sm.ti.teis.payments.payment.listener;
import ee.sm.ti.teis.ErrorDTO;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.officegateway.payments.payment.request.DeletePaymentRequest;
import ee.sm.ti.teis.officegateway.payments.payment.response.DeletePaymentResponse;
import ee.sm.ti.teis.payments.payment.entity.PaymentEntity;
import ee.sm.ti.teis.payments.payment.service.PaymentDataService;
import ee.sm.ti.teis.servicecommon.test.ListenerDeleteRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpStatus;
import java.util.UUID;
import static ee.sm.ti.teis.payments.payment.PaymentErrorCode.PAYMENTS_2010;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.servicerequest.UserType.PERSON;
import static ee.sm.ti.teis.types.enums.ObjectStatus.DELETED;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_MANAGE_PAYMENTS;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseForbidden;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.http.HttpStatus.BAD_REQUEST;
import static org.testcontainers.shaded.com.google.common.collect.ImmutableList.of;
public class DeletePaymentGwListenerTest extends PaymentsAppTestBase implements ListenerDeleteRequestTestBase {
public static final UUID CURRENT_PAYMENT_ID = UUID.fromString("10c1bddd-6f17-4f1f-ae29-0518e6fa2186");
public static final UUID DELETED_PAYMENT_ID = UUID.fromString("9c65e71b-1ad9-4a92-988f-d69e3bfac4a9");
public static final UUID RECONCILED_PAYMENT_ID = UUID.fromString("896eaa60-1ff6-4cb2-8902-6fa1cd48a950");
@Autowired
PaymentGwListener listener;
@Autowired
PaymentDataService dataService;
private DeletePaymentRequest request;
private RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
requestMetaDTO = createRequestMeta(randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(), emptyList());
requestMetaDTO.setPrivileges(of(TI_MANAGE_PAYMENTS.name()));
request = new DeletePaymentRequest();
request.setRequestMetaDTO(requestMetaDTO);
}
@Override
@Test
public void missingPrivilege_forbidden() {
requestMetaDTO.setPrivileges(null);
request.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.delete(request).getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
request.setRequestMetaDTO(requestMetaDTO);
request.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.delete(request).getError());