Commit 812b5aba 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!25
parents caeaf92c c5c41d54
......@@ -55,9 +55,9 @@ allprojects {
apply from: this.getClass().getClassLoader().getResource('teis.test-sonar.gradle')
dependencies {
// TEiS
// TeIS
compile "ee.sm.ti.teis:service-common-lib:${commonsVersion}"
compile "ee.sm.ti.teis:common-api-gateway-lib:${commonApiGatewayVersion}"
compile "ee.sm.ti.teis:office-api-gateway-lib:${officeApiGatewayVersion}"
compile "ee.sm.ti.teis:data-types-lib:${commonsVersion}"
compile "ee.sm.ti.teis:domain-cache-lib:${commonsVersion}"
}
......
theGroup=ee.sm.ti.teis
theVersion=1.1.0
theVersion=1.2.0
pluginVersion=1.0.0
commonsVersion=1.2.0
commonApiGatewayVersion=1.2.0
commonsVersion=1.4.0
officeApiGatewayVersion=1.4.0
mapstructVersion=1.3.0.Final
querydslVersion=4.1.3
distributionBase=GRADLE_USER_HOME
distributionPath=wrapper/dists
distributionUrl=https\://services.gradle.org/distributions/gradle-5.2.1-bin.zip
distributionUrl=https\://repo.tehik.ee/artifactory/gradle-distributions/gradle-5.2.1-bin.zip
zipStoreBase=GRADLE_USER_HOME
zipStorePath=wrapper/dists
......@@ -20,8 +20,10 @@ dependencies {
// Querydsl
implementation("com.querydsl:querydsl-core:${querydslVersion}")
implementation("com.querydsl:querydsl-jpa:${querydslVersion}")
implementation("javax.inject:javax.inject:1")
integTestImplementation("com.querydsl:querydsl-core:${querydslVersion}")
integTestImplementation("com.querydsl:querydsl-jpa:${querydslVersion}")
integTestImplementation("javax.inject:javax.inject:1")
// MapStruct
implementation "org.mapstruct:mapstruct:${mapstructVersion}"
......@@ -32,6 +34,9 @@ dependencies {
"javax.annotation:javax.annotation-api:1.3.2",
)
implementation("javax.inject:javax.inject:1")
integTestImplementation("javax.inject:javax.inject:1")
// Tests
integTestImplementation 'org.springframework.boot:spring-boot-starter-validation'
}
......
package ee.sm.ti.teis.payments.claim.listener;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDefinitionDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.EnforcementDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.PaymentDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ReconciliationDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.*;
import ee.sm.ti.teis.commongateway.payments.claim.request.ClaimRequest;
import ee.sm.ti.teis.commongateway.payments.claim.response.ClaimResponse;
import ee.sm.ti.teis.commongateway.person.LegalPersonDto;
......@@ -28,9 +24,7 @@ import static ee.sm.ti.teis.types.enums.PersonType.L;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.EX_VIEW_PAYMENTS;
import static ee.sm.ti.teis.types.enums.RolePrivilegeCode.TI_VIEW_PAYMENTS;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.CLAIM_PAYMENT;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseForbidden;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
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;
......@@ -131,21 +125,17 @@ public class ClaimGwListenerTest extends PaymentsAppTestBase implements Listener
.extracting("id")
.doesNotContain(UUID.fromString("8d76f079-eabc-4a0e-86a3-6cf79a0e145d"));
ReconciliationDto reconciliation = dto.getReconciliations().get(0);
ReconciliationPublicDto reconciliation = dto.getReconciliations().get(0);
assertThat(reconciliation.getId()).isEqualTo(UUID.fromString("e5b5af0f-a342-4055-ac63-55ed79978289"));
assertThat(reconciliation.getAmount()).isEqualTo(BigDecimal.valueOf(32.56));
assertThat(reconciliation.getClaimId()).isEqualTo(CLAIM_ID);
assertThat(reconciliation.getObjectStatus()).isEqualTo(CURRENT);
PaymentDto payment = reconciliation.getPayment();
PaymentPublicDto payment = reconciliation.getPayment();
assertThat(payment.getId()).isEqualTo(UUID.fromString("254f1c13-6c07-44a6-ae6a-3543fa20e78f"));
assertThat(payment.getAmount()).isEqualTo(BigDecimal.valueOf(7612.21));
assertThat(payment.getBalance()).isEqualTo(BigDecimal.valueOf(4534.32));
assertThat(payment.getDescription()).isEqualTo("test description");
assertThat(payment.getPayer()).isEqualTo("margus meekas");
assertThat(payment.getReceiptDate()).isEqualTo(LocalDate.of(2020, 1, 22));
assertThat(payment.getRefunded()).isTrue();
assertThat(payment.getRefundedAmount()).isEqualTo(BigDecimal.valueOf(213.22));
assertThat(payment.getObjectStatus()).isEqualTo(CURRENT);
EnforcementDto enforcement = dto.getEnforcement();
......
......@@ -3,6 +3,7 @@ package ee.sm.ti.teis.payments.claim.listener;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDefinitionDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimDto;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimSearchFilterDto;
import ee.sm.ti.teis.commongateway.payments.claim.request.ClaimsRequest;
import ee.sm.ti.teis.commongateway.payments.claim.request.ClaimsRequest.Parameters;
import ee.sm.ti.teis.commongateway.payments.claim.response.ClaimsResponse;
......@@ -10,6 +11,7 @@ import ee.sm.ti.teis.commongateway.person.LegalPersonDto;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.servicecommon.test.ListenerGetListRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.jetbrains.annotations.NotNull;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
......@@ -49,37 +51,32 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
void setUp() {
requestMetaDTO = createRequestMeta(UUID.randomUUID().toString(), OFFICIAL_USER, randomUUID().toString(),
emptyList());
request = new ClaimsRequest();
request.setRequestMetaDTO(requestMetaDTO);
}
@Override
@Test
public void getObjects_deletedRelatedObjectsExcluded_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(true, LocalDate.of(2020, 1, 15),
EMPLOYER_ID, "deleted reference 1", null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(true, LocalDate.of(2020, 1, 15),
EMPLOYER_ID, "deleted reference 1", null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getError()).isNull();
assertThat(response.getPayload()).isEmpty();
assertThat(response.getPayload().getContent()).isEmpty();
}
@Override
@Test
public void getObjects_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(null, null, null, null, null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(null, null, null, null, null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getPayload().isEmpty()).isFalse();
assertThat(response.getPayload().getContent().isEmpty()).isFalse();
ClaimDto dto = response.getPayload().stream()
ClaimDto dto = response.getPayload().getContent().stream()
.filter(claim -> claim.getId().equals(CLAIM_ID))
.findFirst()
.orElse(new ClaimDto());
......@@ -123,19 +120,18 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
@Test
public void getObjects_noResult_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(null, null, UUID.randomUUID(), null, null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(null, null, UUID.randomUUID(), null, null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getError()).isNull();
assertThat(response.getPayload()).isEmpty();
assertThat(response.getPayload().getContent()).isEmpty();
}
@Override
@Test
public void missingPrivilege_forbidden() {
ClaimsResponse response = listener.getClaims(request);
ClaimsResponse response = listener.getClaims(composeClaimsRequest(null, null, UUID.randomUUID(), null, null, requestMetaDTO));
assertResponseForbidden(response.getError());
}
......@@ -145,8 +141,7 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(null, null, UUID.randomUUID(), null, null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(null, null, UUID.randomUUID(), null, null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
......@@ -156,38 +151,35 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
@Test
void getClaims_deadlineDateBefore_noResult_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(true, LocalDate.of(2020, 1, 14),
EMPLOYER_ID, NEW_REFERENCE, null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(true, LocalDate.of(2020, 1, 14),
EMPLOYER_ID, NEW_REFERENCE, null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getError()).isNull();
assertThat(response.getPayload()).isEmpty();
assertThat(response.getPayload().getContent()).isEmpty();
}
@Test
void getClaims_reference_notFound_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(null, null, null, UUID.randomUUID().toString(), null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(null, null, null, UUID.randomUUID().toString(), null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getError()).isNull();
assertThat(response.getPayload()).isEmpty();
assertThat(response.getPayload().getContent()).isEmpty();
}
@Test
void getClaims_allFalse_balanceStatusMatch_notFound_success() {
requestMetaDTO.setPrivileges(singletonList(TI_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(false, LocalDate.of(2020, 1, 15),
EMPLOYER_ID, NEW_REFERENCE, null);
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(false, LocalDate.of(2020, 1, 15),
EMPLOYER_ID, NEW_REFERENCE, null, requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
ClaimDto dto = response.getPayload().get(0);
ClaimDto dto = response.getPayload().getContent().get(0);
assertThat(dto.getId()).isEqualTo(CLAIM_ID);
}
......@@ -196,13 +188,12 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
requestMetaDTO.setUserType(PERSON);
requestMetaDTO.setCompanyId("69a31369-f74d-404d-a221-ba7d30bf3455");
requestMetaDTO.setPrivileges(singletonList(EX_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(false, null, null, null,
UUID.fromString("907f82f2-0cc4-4662-a32e-31daaf208c0b"));
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(false, null, null, null,
UUID.fromString("907f82f2-0cc4-4662-a32e-31daaf208c0b"), requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
ClaimDto dto = response.getPayload().get(0);
ClaimDto dto = response.getPayload().getContent().get(0);
assertThat(dto.getId()).isEqualTo(UUID.fromString("f5a6d513-efe6-4c88-ae24-abbaa7d089ea"));
}
......@@ -211,12 +202,25 @@ public class ClaimsGwListenerTest extends PaymentsAppTestBase implements Listene
requestMetaDTO.setUserType(PERSON);
requestMetaDTO.setCompanyId(UUID.randomUUID().toString());
requestMetaDTO.setPrivileges(singletonList(EX_VIEW_PAYMENTS.name()));
Parameters parameters = new Parameters(false, null, null, null,
UUID.fromString("907f82f2-0cc4-4662-a32e-31daaf208c0b"));
request.setPayload(parameters, requestMetaDTO);
request = composeClaimsRequest(false, null, null, null,
UUID.fromString("907f82f2-0cc4-4662-a32e-31daaf208c0b"), requestMetaDTO);
ClaimsResponse response = listener.getClaims(request);
assertThat(response.getPayload()).isEmpty();
assertThat(response.getPayload().getContent()).isEmpty();
}
@NotNull
private ClaimsRequest composeClaimsRequest(Boolean all, LocalDate deadlineUntil, UUID employerId, String reference, UUID dataObjectId, RequestMetaDTO requestMetaDTO) {
ClaimsRequest claimsRequest = new ClaimsRequest();
ClaimSearchFilterDto searchFilter = new ClaimSearchFilterDto();
searchFilter.setAll(all);
searchFilter.setDeadlineUntil(deadlineUntil);
searchFilter.setEmployerId(employerId);
searchFilter.setReference(reference);
searchFilter.setDataObjectId(dataObjectId);
Parameters parameters = new Parameters(searchFilter);
claimsRequest.setPayload(parameters, requestMetaDTO);
return claimsRequest;
}
}
......@@ -9,7 +9,7 @@ import ee.sm.ti.teis.commongateway.payments.claim.request.CreateClaimRequest;
import ee.sm.ti.teis.commongateway.payments.claim.response.CreateClaimResponse;
import ee.sm.ti.teis.commongateway.person.PersonDto;
import ee.sm.ti.teis.domain.task.Task;
import ee.sm.ti.teis.payments.claim.service.TaskNotifyService.CreateTaskMsResponse;
import ee.sm.ti.teis.payments.serviceclient.TaskServiceClient.CreateTaskMsResponse;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
......
......@@ -8,7 +8,7 @@ import ee.sm.ti.teis.domain.payments.claim.DataObjectReference;
import ee.sm.ti.teis.domain.person.Person;
import ee.sm.ti.teis.domain.task.Task;
import ee.sm.ti.teis.payments.claim.config.ClaimQueueConfig.CreateClaimMsRequest;
import ee.sm.ti.teis.payments.claim.service.TaskNotifyService.CreateTaskMsResponse;
import ee.sm.ti.teis.payments.serviceclient.TaskServiceClient.CreateTaskMsResponse;
import ee.sm.ti.teis.servicecommon.test.ListenerCreateRequestTestBase;
import ee.sm.ti.teis.servicerequest.RequestMetaDTO;
import org.junit.jupiter.api.BeforeEach;
......@@ -27,9 +27,7 @@ import static ee.sm.ti.teis.types.enums.ClaimStatusType.VALID;
import static ee.sm.ti.teis.types.enums.ObjectStatus.CURRENT;
import static ee.sm.ti.teis.types.enums.PersonType.L;
import static ee.sm.ti.teis.types.enums.classifier.ObjectType.CLAIM_PAYMENT;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
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;
......
......@@ -15,13 +15,11 @@ import org.springframework.beans.factory.annotation.Autowired;
import javax.transaction.Transactional;
import java.util.UUID;
import static ee.sm.ti.teis.payments.PaymentsErrorCode.CLAIM_HAS_ACTIVE_RECONCILIATIONS;
import static ee.sm.ti.teis.payments.claim.ClaimErrorCode.CLAIMS_1001;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.CANCELED;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.VALID;
import static ee.sm.ti.teis.utils.TestUtils.assertBadRequest;
import static ee.sm.ti.teis.utils.TestUtils.assertResponseNotFound;
import static ee.sm.ti.teis.utils.TestUtils.createRequestMeta;
import static ee.sm.ti.teis.utils.TestUtils.*;
import static java.util.Collections.emptyList;
import static java.util.UUID.randomUUID;
import static org.assertj.core.api.Assertions.assertThat;
......@@ -108,7 +106,7 @@ public class PatchClaimMsListenerTest extends PaymentsAppTestBase {
PatchClaimMsResponse response = listener.patch(request);
assertThat(response.getError().getCode()).isEqualTo(CLAIM_HAS_ACTIVE_RECONCILIATIONS.getCode());
assertThat(response.getError().getCode()).isEqualTo(CLAIMS_1001.getCode());
assertThat(response.getError().getHttpResponse()).isEqualTo(BAD_REQUEST);
}
......
package ee.sm.ti.teis.payments.claim.service;
import ee.sm.ti.teis.PaymentsAppTestBase;
import ee.sm.ti.teis.commongateway.payments.claim.dto.ClaimSearchFilterDto;
import ee.sm.ti.teis.payments.claim.entity.ClaimEntity;
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.data.domain.Page;
import java.math.BigDecimal;
import java.util.List;
import java.util.UUID;
import java.util.stream.Collectors;
import static ee.sm.ti.teis.servicerequest.UserType.OFFICIAL_USER;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.CANCELED;
import static ee.sm.ti.teis.types.enums.ClaimStatusType.VALID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.testcontainers.shaded.com.google.common.collect.ImmutableList.of;
public class ClaimDataServiceTest extends PaymentsAppTestBase {
@Autowired
ClaimDataService dataService;
ClaimSearchFilterDto searchFilter;
RequestMetaDTO requestMetaDTO;
@BeforeEach
void setUp() {
searchFilter = ClaimSearchFilterDto.builder().build();
requestMetaDTO = RequestMetaDTO.builder().userType(OFFICIAL_USER).build();
}
@Test
void getClaims_valid_paging() {
searchFilter.setPage(1);
searchFilter.setSize(2);
Page<ClaimEntity> claims = dataService.queryClaims(searchFilter, requestMetaDTO);
assertThat(claims.getContent().size()).isEqualTo(2);
assertThat(claims.getTotalElements()).isGreaterThan(10);
assertThat(claims.getSize()).isEqualTo(2);
}
@Test
void getClaims_sortBy_personName_and_status() {
searchFilter.setSort(of("person:desc", "status:asc"));
Page<ClaimEntity> claims = dataService.queryClaims(searchFilter, requestMetaDTO);
assertThat(claims.getTotalElements()).isGreaterThan(10);
}
@Test
void getClaims_sortBy_status_ascending() {
searchFilter.setAll(true);
searchFilter.setSort(of("status:asc"));
Page<ClaimEntity> claims = dataService.queryClaims(searchFilter, requestMetaDTO);
assertThat(claims.getTotalElements()).isGreaterThanOrEqualTo(3L);
ClaimEntity first = claims.getContent().get(0);
ClaimEntity second = claims.getContent().get(1);
ClaimEntity last = claims.getContent().get(claims.getContent().size() - 1);
assertThat(first.getStatus()).isEqualTo(VALID);
assertThat(second.getStatus()).isEqualTo(VALID);
assertThat(first.getBalance()).isLessThanOrEqualTo(second.getBalance());
assertThat(last.getStatus()).isEqualTo(CANCELED);
}
@Test
void getClaims_sortBy_status_descending() {
searchFilter.setAll(true);
searchFilter.setSort(of("status:desc"));
Page<ClaimEntity> claims = dataService.queryClaims(searchFilter, requestMetaDTO);
assertThat(claims.getTotalElements()).isGreaterThanOrEqualTo(3L);
ClaimEntity first = claims.getContent().get(0);
ClaimEntity secondToLast = claims.getContent().get(claims.getContent().size() - 2);
ClaimEntity last = claims.getContent().get(claims.getContent().size() - 1);
assertThat(first.getStatus()).isEqualTo(CANCELED);
assertThat(secondToLast.getStatus()).isEqualTo(VALID);
assertThat(last.getStatus()).isEqualTo(VALID);
assertThat(last.getBalance()).isLessThanOrEqualTo(secondToLast.getBalance());
}
@Test
void getClaims_sortBy_reconciliated_ascending() {
searchFilter.setSort(of("reconciliated:asc"));
Page<ClaimEntity> claims = dataService.queryClaims(searchFilter, requestMetaDTO);
assertThat(claims.getTotalElements()).isGreaterThanOrEqualTo(3L);
List<BigDecimal> reconciliatedAmounts = claims.getContent().stream().map(c -> c.getAmount().subtract(c.getBalance())).collect(Collectors.toList());
assertThat(reconciliatedAmounts.get(0)).isLessThanOrEqualTo(reconciliatedAmounts.get(1));
assertThat(reconciliatedAmounts.get(0)).isLessThanOrEqualTo(reconciliatedAmounts.get(reconciliatedAmounts.size() - 1));
}
@Test
void getClaims_sortBy_issuedDate_descending_if_sorted_values_are_equal() {
searchFilter.setEmployerId(UUID.fromString("6b68de81-37be-4613-b7c4-f226107978e5"));
searchFilter.setSort(of("person:asc"));
Page<ClaimEntity> claimsPage = dataService.queryClaims(searchFilter, requestMetaDTO);
List<ClaimEntity> claims = claimsPage.getContent();
assertThat(claimsPage.getTotalElements()).isGreaterThanOrEqualTo(3L);
assertThat(claims.get(0).getIssuedDate()).isAfterOrEqualTo(claims.get(1).getIssuedDate());
assertThat(claims.get(0).getIssuedDate()).isAfterOrEqualTo(claims.get(claims.size() - 1).getIssuedDate());
}
}
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.errors.ConstraintViolationDto;
import ee.sm.ti.teis.officegateway.payments.payment.dto.CreatePaymentDto;
import ee.sm.ti.teis.officegateway.payments.payment.dto.PaymentDto;
import ee.sm.ti.teis.officegateway.payments.payment.request.CreatePaymentRequest;
import ee.sm.ti.teis.officegateway.payments.payment.response.CreatePaymentResponse;
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 org.springframework.http.HttpStatus;
import java.math.BigDecimal;
import java.time.LocalDate;
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.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.testcontainers.shaded.com.google.common.collect.ImmutableList.of;
public class CreatePaymentGwListenerTest extends PaymentsAppTestBase implements ListenerCreateRequestTestBase {
public static final String PAYER_NAME = "Payer 1";
public static final String INPUT_VALIDATION_ERROR = "Input validation error";
public static final String NOT_NULL = "NotNull";
public static final String MUST_NOT_BE_NULL = "must not be null";
@Autowired
PaymentGwListener listener;
private CreatePaymentRequest createPaymentRequest;
private RequestMetaDTO requestMetaDTO;
private CreatePaymentDto createPayload;
@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();
}
@Override
@Test
public void missingPrivilege_forbidden() {
requestMetaDTO.setPrivileges(null);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(createPaymentRequest).getError());
}
@Override
@Test
public void wrongUserType_forbidden() {
requestMetaDTO.setUserType(PERSON);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
createPaymentRequest.setRequestMetaDTO(requestMetaDTO);
assertResponseForbidden(listener.create(createPaymentRequest).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);
CreatePaymentResponse response = listener.create(createPaymentRequest);
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());
}
@Override
@Test
public void create_minimumData_success() {
createPayload.setPayerName(PAYER_NAME);