Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package ru.rostelecom.eip2.steps.payments;
- import io.qameta.allure.Step;
- import org.apache.logging.log4j.LogManager;
- import org.apache.logging.log4j.Logger;
- import org.assertj.core.api.SoftAssertions;
- import ru.rostelecom.database.entities.dto.mdm.PaymentDto;
- import ru.rostelecom.model.Payment;
- import ru.rostelecom.model.PaymentResponse;
- import java.util.ArrayList;
- import java.util.Date;
- import java.util.List;
- import static org.assertj.core.api.Assertions.assertThat;
- import static ru.rostelecom.execution.jira.Watcher.TEST_STEP_MARKER;
- public class PaymentResponseAssertionSteps {
- private static final Logger LOGGER = LogManager.getLogger(PaymentResponseAssertionSteps.class);
- @Step("Проверяем ответ от сервиса по платежам с пагинацией. " + TEST_STEP_MARKER)
- public static void assertPaymentResponseWithPagination(
- final String testCaseKey,
- final Integer stepNumber,
- final PaymentResponse paymentResponse,
- final Number pageNumber,
- final Number totalCount,
- final Number fetchCount,
- final Number pageCount,
- final List<PaymentDto> dbPayments
- ) {
- SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(paymentResponse.getPageNum())
- .as(
- "В ответе от сервиса pagNum %s должен быть равен переданному параметру %s",
- paymentResponse.getPageNum(),
- pageNumber
- )
- .isEqualTo(pageNumber);
- softly.assertThat(paymentResponse.getTotalCount())
- .as(
- "В ответе от сервиса totalCount: %s должен равен количеству записей в БД: %s",
- paymentResponse.getTotalCount(),
- totalCount
- )
- .isEqualTo(totalCount);
- softly.assertThat(paymentResponse.getFetchCount())
- .as(
- "В ответе от сервиса fetchCount %d должен быть равен переданному значению: %d, " +
- "количеству объектов в поле dtos JSON-объекта: %d",
- paymentResponse.getFetchCount(),
- fetchCount,
- paymentResponse.getDtos().size()
- )
- .isEqualTo(fetchCount)
- .isEqualTo(paymentResponse.getDtos().size());
- softly.assertThat(paymentResponse.getPageCount())
- .as(
- "В ответе от сервиса pageCount %s должен быть равен %s"
- )
- .isEqualTo(pageCount);
- });
- assertListsOfServicePaymentsAndDbPayments(paymentResponse.getDtos(), dbPayments);
- }
- @Step("Проверяем ответ от сервиса по платежам и фильтрацией по дате. " + TEST_STEP_MARKER)
- public static void assertPaymentResponseContainsFilteredData(
- final String testCaseKey,
- final Integer stepNumber,
- final PaymentResponse paymentResponse,
- final List<PaymentDto> dbPayments,
- final Date dateFrom,
- final Date dateTo) {
- paymentResponse.getDtos().forEach(payment -> assertThat(payment.getRegDateTime())
- .as("REGDATETIME платежа: %s должен быть в диапазоне от %s и до %s",
- payment.getRegDateTime(),
- dateFrom,
- dateTo)
- .isBetween(dateFrom, dateTo));
- assertListsOfServicePaymentsAndDbPayments(paymentResponse.getDtos(), dbPayments);
- }
- @Step("Проверяем ответ от сервиса по платежам и фильтрацией по дате. " + TEST_STEP_MARKER)
- public static void assertPaymentResponseContainsFilteredDateFrom(
- final String testCaseKey,
- final Integer stepNumber,
- final PaymentResponse paymentResponse,
- final List<PaymentDto> dbPayments,
- final Date dateFrom) {
- paymentResponse.getDtos().forEach(payment -> assertThat(payment.getRegDateTime())
- .as("REGDATETIME платежа: %s должен быть начинаться от %s", payment.getRegDateTime(), dateFrom)
- .isAfter(dateFrom));
- assertListsOfServicePaymentsAndDbPayments(paymentResponse.getDtos(), dbPayments);
- }
- @Step("Проверяем ответ от сервиса по платежам и фильтрацией по дате. " + TEST_STEP_MARKER)
- public static void assertPaymentResponseContainsFilteredDateTo(
- final String testCaseKey,
- final Integer stepNumber,
- final PaymentResponse paymentResponse,
- final List<PaymentDto> dbPayments,
- final Date dateTo) {
- paymentResponse.getDtos().forEach(payment -> assertThat(payment.getRegDateTime())
- .as("REGDATETIME платежа: %s должен быть до %s", payment.getRegDateTime(), dateTo)
- .isBefore(dateTo));
- assertListsOfServicePaymentsAndDbPayments(paymentResponse.getDtos(), dbPayments);
- }
- @Step("Проверяем ответ от сервиса по платежам. " + TEST_STEP_MARKER)
- public static void assertPaymentResponse(
- final String testCaseKey,
- final Integer stepNumber,
- final PaymentResponse paymentResponse,
- final List<PaymentDto> dbPayments
- ) {
- SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(paymentResponse.getPageNum())
- .as(
- "В ответе от сервиса pagNum %s должен быть равен 0",
- paymentResponse.getPageNum()
- )
- .isEqualTo(0);
- softly.assertThat(paymentResponse.getTotalCount())
- .as(
- "В ответе от сервиса totalCount %s должен быть равен количеству записей в БД %s",
- paymentResponse.getTotalCount(),
- dbPayments.size()
- )
- .isEqualTo(dbPayments.size());
- if (paymentResponse.getTotalCount().intValue() >= 100) {
- softly.assertThat(paymentResponse.getFetchCount())
- .as(
- "В ответе от сервиса fetchCount %s должен быть равен 100",
- paymentResponse.getFetchCount()
- )
- .isEqualTo(100);
- final int pageCount = paymentResponse.getTotalCount().intValue() / 100 + 1;
- softly.assertThat(paymentResponse.getPageCount())
- .as(
- "В ответе от сервиса pageCount %s должен быть равен %s",
- paymentResponse.getPageCount(),
- pageCount
- )
- .isEqualTo(pageCount);
- } else {
- softly.assertThat(paymentResponse.getFetchCount())
- .as(
- "В ответе от сервиса fetchCount %s должен быть равен количеству записей в БД %s",
- paymentResponse.getFetchCount(),
- dbPayments.size()
- )
- .isEqualTo(dbPayments.size());
- softly.assertThat(paymentResponse.getPageCount())
- .as(
- "В ответе от сервиса pageCount %s должен быть равен 1",
- paymentResponse.getPageCount()
- )
- .isEqualTo(1);
- }
- });
- assertListsOfServicePaymentsAndDbPayments(paymentResponse.getDtos(), dbPayments);
- }
- @Step("Сравниваем списки платежей из ответа от сервиса и из БД")
- private static void assertListsOfServicePaymentsAndDbPayments(
- final List<Payment> servicePayments,
- final List<PaymentDto> dbPayments
- ) {
- for (Payment payment : servicePayments) {
- for (PaymentDto paymentDb : dbPayments) {
- if (paymentDb.getLocalSystemId().equals(payment.getId().getLocalSystemId()) &&
- payment.getId().getAppPkid().equals(paymentDb.getAppPkId())) {
- assertPaymentWithPaymentDto(payment, paymentDb);
- break;
- }
- }
- }
- // final List<PaymentDto> sortedDbPayments = sortPaymentDtoListByPaymentList(dbPayments, servicePayments);
- //
- // if (sortedDbPayments.isEmpty()) {
- // fail("В списках из БД и из ответа от сервиса не нашлось соответствий");
- // }
- //
- // if (servicePayments.size() == 1) {
- // assertPaymentWithPaymentDto(servicePayments.get(0), sortedDbPayments.get(0));
- // } else {
- // for (int i = 0; i < servicePayments.size(); i++) {
- // final Payment payment = servicePayments.get(i);
- // final PaymentDto paymentDto = sortedDbPayments.get(i);
- //
- // assertPaymentWithPaymentDto(payment, paymentDto);
- // }
- // }
- }
- @Step("Сортируем список платежей")
- private static List<PaymentDto> sortPaymentDtoListByPaymentList(List<PaymentDto> paymentDtos, List<Payment> payments) {
- final List<PaymentDto> sortedList = new ArrayList<>();
- for (Payment payment : payments) {
- for (PaymentDto paymentDto : paymentDtos) {
- if (paymentDto.getLocalSystemId().equals(payment.getId().getLocalSystemId()) &&
- payment.getId().getAppPkid().equals(paymentDto.getAppPkId())) {
- LOGGER.info("!!!!!!! APPPKID db: " + paymentDto.getAppPkId() + " = service: " + payment.getId().getAppPkid() + " ? " + payment.getId().getAppPkid().equals(paymentDto.getAppPkId()));
- LOGGER.info("!!!!!!! LSID db: " + paymentDto.getLocalSystemId() + " = service: " + payment.getId().getLocalSystemId() + " ? " + paymentDto.getLocalSystemId().equals(payment.getId().getLocalSystemId()));
- sortedList.add(paymentDto);
- }
- }
- }
- // payments.forEach(payment -> paymentDtos.forEach(paymentDto -> {
- // System.out.println("!!!!!!! APPPKID db: " + paymentDto.getAppPkId() + " = service: " + payment.getId().getAppPkid() + " ? " + payment.getId().getAppPkid().equals(paymentDto.getAppPkId()));
- // System.out.println("!!!!!!! LSID db: " + paymentDto.getLocalSystemId() + " = service: " + payment.getId().getLocalSystemId() + " ? " + paymentDto.getLocalSystemId().equals(payment.getId().getLocalSystemId()));
- //
- // if (paymentDto.getLocalSystemId().equals(payment.getId().getLocalSystemId()) &&
- // payment.getId().getAppPkid().equals(paymentDto.getAppPkId())) {
- //
- // sortedList.add(paymentDto);
- // }
- // }));
- return sortedList;
- }
- @Step("Сравниваем платеж из ответа от сервиса и из БД")
- private static void assertPaymentWithPaymentDto(final Payment payment, final PaymentDto dbPayment) {
- SoftAssertions.assertSoftly(softly -> {
- softly.assertThat(payment.getId().getLocalSystemId())
- .as(
- "LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getId().getLocalSystemId(),
- dbPayment.getLocalSystemId()
- )
- .isEqualTo(dbPayment.getLocalSystemId());
- softly.assertThat(payment.getApplicationName())
- .as(
- "APPLICATION_NAME от сервиса %s должен быть равен значению из БД %s",
- payment.getApplicationName(),
- dbPayment.getApplicationName()
- )
- .isEqualTo(dbPayment.getApplicationName());
- softly.assertThat(payment.getPersistDate())
- .as(
- "PERSIST_DATE от сервиса %s должен быть равен значению из БД %s",
- payment.getPersistDate(),
- dbPayment.getPersistDate()
- )
- .isEqualToIgnoringMillis(dbPayment.getPersistDate());
- softly.assertThat(payment.getTitle())
- .as(
- "TITLE от сервиса %s должен быть равен значению из БД %s",
- payment.getTitle(),
- dbPayment.getTitle()
- )
- .isEqualTo(dbPayment.getTitle());
- softly.assertThat(payment.getOwnerLogin())
- .as(
- "OWNER_LOGIN от сервиса %s должен быть равен значению из БД %s",
- payment.getOwnerLogin(),
- dbPayment.getOwnerLogin()
- )
- .isEqualTo(dbPayment.getOwnerLogin());
- softly.assertThat(payment.getAmount())
- .as(
- "AMOUNT от сервиса %s должен быть равен значению из БД %s",
- payment.getAmount(),
- dbPayment.getAmount()
- )
- .isEqualTo(dbPayment.getAmount());
- softly.assertThat(payment.getCashType())
- .as(
- "CASH_TYPE от сервиса %s должен быть равен значению из БД %s",
- payment.getCashType(),
- dbPayment.getCashType()
- )
- .isEqualTo(dbPayment.getCashType());
- softly.assertThat(payment.getNds())
- .as(
- "NDS от сервиса %s должен быть равен значению из БД %s",
- payment.getNds(),
- dbPayment.getNds()
- )
- .isEqualTo(dbPayment.getNds());
- softly.assertThat(payment.getChangeDate())
- .as(
- "CHANGE_DATE от сервиса %s должен быть равен значению из БД %s",
- payment.getChangeDate(),
- dbPayment.getChangeDate()
- )
- .isEqualToIgnoringMillis(dbPayment.getChangeDate());
- softly.assertThat(payment.getPaymentType())
- .as(
- "PAYMENT_TYPE от сервиса %s должен быть равен значению из БД %s",
- payment.getPaymentType(),
- dbPayment.getPaymentType()
- )
- .isEqualTo(dbPayment.getPaymentType());
- softly.assertThat(payment.getReason())
- .as(
- "REASON от сервиса %s должен быть равен значению из БД %s",
- payment.getReason(),
- dbPayment.getReason()
- )
- .isEqualTo(dbPayment.getReason());
- softly.assertThat(payment.getRegDateTime())
- .as(
- "REG_DATE_TIME от сервиса %s должен быть равен значению из БД %s",
- payment.getRegDateTime(),
- dbPayment.getRegDateTime()
- )
- .isEqualToIgnoringMillis(dbPayment.getRegDateTime());
- if (payment.getDeadline() == null) {
- softly.assertThat(payment.getDeadline())
- .as(
- "Если DEADLINE от сервиса %s равен null значение из БД %s также должно быть null",
- payment.getDeadline(),
- dbPayment.getDeadline()
- )
- .isNull();
- } else {
- softly.assertThat(payment.getDeadline())
- .as(
- "DEADLINE от сервиса %s должен быть равен значению из БД %s",
- payment.getDeadline(),
- dbPayment.getDeadline()
- )
- .isEqualToIgnoringMillis(dbPayment.getDeadline());
- }
- if (payment.getBillingPeriodAppPkId() == null) {
- softly.assertThat(dbPayment.getBillingPeriodAppPkId())
- .as(
- "Если BILLING_PERIOD_APP_PKID от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getBillingPeriodAppPkId(),
- dbPayment.getBillingPeriodAppPkId()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getBillingPeriodAppPkId())
- .as(
- "BILLING_PERIOD_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getBillingPeriodAppPkId(),
- dbPayment.getBillingPeriodAppPkId()
- )
- .isEqualTo(dbPayment.getBillingPeriodAppPkId());
- }
- softly.assertThat(payment.getBillingPeriodLocalSystemId())
- .as(
- "BILLING_PERIOD_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getBillingPeriodLocalSystemId(),
- dbPayment.getBillingPeriodLocalSystemId()
- )
- .isEqualTo(dbPayment.getBillingPeriodLocalSystemId());
- softly.assertThat(payment.getClientAppPkId())
- .as(
- "CLIENT_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getClientAppPkId(),
- dbPayment.getClientAppPkId()
- )
- .isEqualTo(dbPayment.getClientAppPkId());
- softly.assertThat(payment.getClientLocalSystemId())
- .as(
- "CLIENT_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getClientLocalSystemId(),
- dbPayment.getClientLocalSystemId()
- )
- .isEqualTo(dbPayment.getClientLocalSystemId());
- if (payment.getPaymentOfficeAppPkId() == null) {
- softly.assertThat(dbPayment.getPaymentOfficeAppPkId())
- .as(
- "Если PAYMENT_OFFICE_APP_PKID от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getPaymentOfficeAppPkId(),
- dbPayment.getPaymentOfficeAppPkId()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getPaymentOfficeAppPkId())
- .as(
- "PAYMENT_OFFICE_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getPaymentOfficeAppPkId(),
- dbPayment.getPaymentOfficeAppPkId()
- )
- .isEqualTo(dbPayment.getPaymentOfficeAppPkId());
- }
- softly.assertThat(payment.getPaymentOfficeLocalSystemId())
- .as(
- "PAYMENT_OFFICE_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getPaymentOfficeLocalSystemId(),
- dbPayment.getPaymentOfficeLocalSystemId()
- )
- .isEqualTo(dbPayment.getPaymentOfficeLocalSystemId());
- if (payment.getPaymentOfficeVersion() == null) {
- softly.assertThat(dbPayment.getPaymentOfficeVersion())
- .as(
- "Если PAYMENT_OFFICE_VERSION от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getPaymentOfficeVersion(),
- dbPayment.getPaymentOfficeVersion()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getPaymentOfficeVersion())
- .as(
- "PAYMENT_OFFICE_VERSION от сервиса %s должен быть равен значению из БД %s",
- payment.getPaymentOfficeVersion(),
- dbPayment.getPaymentOfficeVersion()
- )
- .isEqualTo(dbPayment.getPaymentOfficeVersion());
- }
- if (payment.getReferenceAppPkId() == null) {
- softly.assertThat(dbPayment.getReferenceAppPkId())
- .as(
- "Если REFERENCE_APP_PKID от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getReferenceAppPkId(),
- dbPayment.getReferenceAppPkId()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getReferenceAppPkId())
- .as(
- "REFERENCE_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getReferenceAppPkId(),
- dbPayment.getReferenceAppPkId()
- )
- .isEqualTo(dbPayment.getReferenceAppPkId());
- }
- softly.assertThat(payment.getReferenceLocalSystemId())
- .as(
- "REFERENCE_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getReferenceLocalSystemId(),
- dbPayment.getReferenceLocalSystemId()
- )
- .isEqualTo(dbPayment.getReferenceLocalSystemId());
- if (payment.getServiceProviderAppPkId() == null) {
- softly.assertThat(dbPayment.getServiceProviderAppPkId())
- .as(
- "Если SERVICE_PROVIDER_APP_PKID от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getServiceProviderAppPkId(),
- dbPayment.getServiceProviderAppPkId()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getServiceProviderAppPkId())
- .as(
- "SERVICE_PROVIDER_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getServiceProviderAppPkId(),
- dbPayment.getServiceProviderAppPkId()
- )
- .isEqualTo(dbPayment.getServiceProviderAppPkId());
- }
- softly.assertThat(payment.getServiceProviderLocalSystemId())
- .as(
- "SERVICE_PROVIDER_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getServiceProviderLocalSystemId(),
- dbPayment.getServiceProviderLocalSystemId()
- )
- .isEqualTo(dbPayment.getServiceProviderLocalSystemId());
- if (payment.getServiceProviderVersion() == null) {
- softly.assertThat(dbPayment.getServiceProviderVersion())
- .as(
- "Если SERVICE_PROVIDER_VERSION от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getServiceProviderVersion(),
- dbPayment.getServiceProviderVersion()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getServiceProviderVersion())
- .as(
- "SERVICE_PROVIDER_VERSION от сервиса %s должен быть равен значению из БД %s",
- payment.getServiceProviderVersion(),
- dbPayment.getServiceProviderVersion()
- )
- .isEqualTo(dbPayment.getServiceProviderVersion());
- }
- softly.assertThat(payment.getPenaltyAmount())
- .as(
- "PENALTY_AMOUNT от сервиса %s должен быть равен значению из БД %s",
- payment.getPenaltyAmount(),
- dbPayment.getPenaltyAmount()
- )
- .isEqualTo(dbPayment.getPenaltyAmount());
- softly.assertThat(payment.getPenaltyNds())
- .as(
- "PENALTY_NDS от сервиса %s должен быть равен значению из БД %s",
- payment.getPenaltyNds(),
- dbPayment.getPenaltyNds()
- )
- .isEqualTo(dbPayment.getPenaltyNds());
- if (payment.getCurrentVersion() == null) {
- softly.assertThat(dbPayment.getCurrentVersion())
- .as(
- "Если CURRENT_VERSION от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getCurrentVersion(),
- dbPayment.getCurrentVersion()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getCurrentVersion())
- .as(
- "CURRENT_VERSION от сервиса %s должен быть равен значению из БД %s",
- payment.getCurrentVersion(),
- dbPayment.getCurrentVersion()
- )
- .isEqualTo(dbPayment.getCurrentVersion());
- }
- if (payment.getCustomerServiceAppPkId() == null) {
- softly.assertThat(dbPayment.getCustomerServiceAppPkId())
- .as(
- "Если CUSTOMER_SERVICE_APP_PKID от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getCustomerServiceAppPkId(),
- dbPayment.getCustomerServiceAppPkId()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getCustomerServiceAppPkId())
- .as(
- "CUSTOMER_SERVICE_APP_PKID от сервиса %s должен быть равен значению из БД %s",
- payment.getCustomerServiceAppPkId(),
- dbPayment.getCustomerServiceAppPkId()
- )
- .isEqualTo(dbPayment.getCustomerServiceAppPkId());
- }
- softly.assertThat(payment.getCustomerServiceLocalSystemId())
- .as(
- "CUSTOMER_SERVICE_LOCAL_SYSTEM_ID от сервиса %s должен быть равен значению из БД %s",
- payment.getCustomerServiceLocalSystemId(),
- dbPayment.getCustomerServiceLocalSystemId()
- )
- .isEqualTo(dbPayment.getCustomerServiceLocalSystemId());
- if (payment.getCustomerServiceVersion() == null) {
- softly.assertThat(dbPayment.getCustomerServiceVersion())
- .as(
- "Если CUSTOMER_SERVICE_VERSION от сервиса %s пустой, то в БД %s должен быть 0",
- payment.getCustomerServiceVersion(),
- dbPayment.getCustomerServiceVersion()
- )
- .isEqualTo(0);
- } else {
- softly.assertThat(payment.getCustomerServiceVersion())
- .as(
- "CUSTOMER_SERVICE_VERSION от сервиса %s должен быть равен значению из БД %s",
- payment.getCustomerServiceVersion(),
- dbPayment.getCustomerServiceVersion()
- )
- .isEqualTo(dbPayment.getCustomerServiceVersion());
- }
- softly.assertThat(payment.getDType())
- .as(
- "D_TYPE от сервиса %s должен быть равен значению из БД %s",
- payment.getDType(),
- dbPayment.getDType()
- )
- .isEqualTo(dbPayment.getDType());
- });
- }
- }
Add Comment
Please, Sign In to add comment