Skip to content

Commit

Permalink
fix repository tests
Browse files Browse the repository at this point in the history
  • Loading branch information
gioelemella committed Oct 21, 2024
1 parent d0c9db8 commit 392db59
Show file tree
Hide file tree
Showing 3 changed files with 49 additions and 6 deletions.
1 change: 1 addition & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -79,6 +79,7 @@
<dependency>
<groupId>io.quarkus</groupId>
<artifactId>quarkus-jdbc-h2</artifactId>
<scope>test</scope>
</dependency>

<dependency>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,10 @@
@ApplicationScoped
public class PaymentPositionRepository implements PanacheRepository<PaymentPosition> {

private static final String GET_VALID_POSITIONS_BY_TAXCODE_BASE =
public static final String GET_VALID_POSITIONS_BY_TAXCODE_BASE =
"from PaymentPosition AS ppos Where ppos.fiscalCode = ?1 " +
"AND ppos.status IN ('VALID', 'PARTIALLY_PAID') AND ppos.pull = true";
private static final String GET_VALID_POSITIONS_BY_TAXCODE_AND_DUE_DATE =
public static final String GET_VALID_POSITIONS_BY_TAXCODE_AND_DUE_DATE =
"from PaymentPosition AS ppos Where ppos.fiscalCode = ?1 " +
"AND ppos.status IN ('VALID', 'PARTIALLY_PAID') AND ppos.pull = true " +
"AND EXISTS (from ppos.paymentOption AS po WHERE po.dueDate >= ?2)";
Expand Down
Original file line number Diff line number Diff line change
@@ -1,28 +1,70 @@
package it.gov.pagopa.gpd.payments.pull.repository;

import io.quarkus.hibernate.orm.panache.PanacheQuery;
import io.quarkus.test.junit.QuarkusTest;
import jakarta.inject.Inject;
import io.quarkus.test.junit.mockito.InjectSpy;
import it.gov.pagopa.gpd.payments.pull.entity.PaymentPosition;
import it.gov.pagopa.gpd.payments.pull.models.enums.DebtPositionStatus;
import it.gov.pagopa.gpd.payments.pull.models.enums.Type;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;

import java.util.Collections;
import java.util.List;

import static it.gov.pagopa.gpd.payments.pull.Constants.DUE_DATE;
import static it.gov.pagopa.gpd.payments.pull.Constants.FISCAL_CODE;
import static it.gov.pagopa.gpd.payments.pull.repository.PaymentPositionRepository.GET_VALID_POSITIONS_BY_TAXCODE_AND_DUE_DATE;
import static it.gov.pagopa.gpd.payments.pull.repository.PaymentPositionRepository.GET_VALID_POSITIONS_BY_TAXCODE_BASE;
import static org.junit.jupiter.api.Assertions.assertDoesNotThrow;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.when;

@QuarkusTest
class PaymentPositionRepositoryTest {

@Inject
@InjectSpy
PaymentPositionRepository paymentPositionRepository;

@Test
void findNoticesOnRepositoryWithoutDueDate() {
assertDoesNotThrow(() -> paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(
PanacheQuery panacheQuery = Mockito.mock(PanacheQuery.class);
when(paymentPositionRepository.find(GET_VALID_POSITIONS_BY_TAXCODE_BASE, FISCAL_CODE)).thenReturn(panacheQuery);
when(panacheQuery.page(any())).thenReturn(panacheQuery);
when(panacheQuery.list()).thenReturn(Collections.singletonList(
PaymentPosition.builder()
.iupd("iupd")
.status(DebtPositionStatus.VALID)
.type(Type.F)
.build()));

List<PaymentPosition> result = assertDoesNotThrow(() -> paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(
FISCAL_CODE, null, 50, 0));

assertNotNull(result);
assertEquals(1, result.size());
}


@Test
void findNoticesOnRepositoryWithDueDate() {
assertDoesNotThrow(() -> paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(
PanacheQuery panacheQuery = Mockito.mock(PanacheQuery.class);
when(paymentPositionRepository.find(GET_VALID_POSITIONS_BY_TAXCODE_AND_DUE_DATE, FISCAL_CODE, DUE_DATE.atStartOfDay()))
.thenReturn(panacheQuery);
when(panacheQuery.page(any())).thenReturn(panacheQuery);
when(panacheQuery.list()).thenReturn(Collections.singletonList(
PaymentPosition.builder()
.iupd("iupd")
.status(DebtPositionStatus.VALID)
.type(Type.F)
.build()));

List<PaymentPosition> result = assertDoesNotThrow(() -> paymentPositionRepository.findPaymentPositionsByTaxCodeAndDueDate(
FISCAL_CODE, DUE_DATE, 50, 0));

assertNotNull(result);
assertEquals(1, result.size());
}
}

0 comments on commit 392db59

Please sign in to comment.