Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: [P4PU-516] fix logic cf #95

Merged
merged 2 commits into from
Sep 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ public class BizEventsServiceImpl implements BizEventsService{
private final BizEventsTransactionDTO2TransactionDTO transactionDTOMapper;
private final BizEventsTransactionsListDTO2TransactionsListDTO transactionsListDTOMapper;
private final BizEventsTransactionDetails2TransactionDetailsDTO transactionDetailsDTOMapper;
private String userFiscalCode;

public BizEventsServiceImpl(BizEventsConnector bizEventsConnector,
BizEventsTransactionDTO2TransactionDTO transactionDTOMapper,
Expand All @@ -35,16 +34,9 @@ public BizEventsServiceImpl(BizEventsConnector bizEventsConnector,
this.transactionDetailsDTOMapper = transactionDetailsDTOMapper;
}

private String getUserFiscalCode() {
if (this.userFiscalCode == null) {
this.userFiscalCode = SecurityUtils.getUserFiscalCode();
}
return this.userFiscalCode;
}

@Override
public TransactionsListDTO retrieveTransactionsListFromBizEvents(Integer page, Integer size, String filter) {
String retrievedUserFiscalCode = getUserFiscalCode();
String retrievedUserFiscalCode = SecurityUtils.getUserFiscalCode();
List<TransactionDTO> transactions;
BizEventsTransactionsListDTO bizEventsTransactionsList = bizEventsConnector.getTransactionsList(retrievedUserFiscalCode, size);
if(!bizEventsTransactionsList.getTransactions().isEmpty()) {
Expand All @@ -61,14 +53,14 @@ public TransactionsListDTO retrieveTransactionsListFromBizEvents(Integer page, I

@Override
public TransactionDetailsDTO retrieveTransactionDetailsFromBizEvents(String transactionId) {
String retrievedUserFiscalCode = getUserFiscalCode();
String retrievedUserFiscalCode = SecurityUtils.getUserFiscalCode();
BizEventsTransactionDetailsDTO bizEventsTransactionDetails = bizEventsConnector.getTransactionDetails(retrievedUserFiscalCode, transactionId);
return transactionDetailsDTOMapper.apply(bizEventsTransactionDetails);
}

@Override
public Resource retrieveTransactionReceiptFromBizEvents(String transactionId) {
String retrievedUserFiscalCode = getUserFiscalCode();
String retrievedUserFiscalCode = SecurityUtils.getUserFiscalCode();
return bizEventsConnector.getTransactionReceipt(retrievedUserFiscalCode, transactionId);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ public class PullPaymentServiceImpl implements PullPaymentService{
private final PullPaymentConnector pullPaymentConnector;
private final PullPaymentNoticeDTO2PaymentNoticeDTO paymentNoticeDTOMapper;
private final PaymentNoticesListDTOMapper paymentNoticesListDTOMapper;
private String userFiscalCode;

public PullPaymentServiceImpl(PullPaymentConnector pullPaymentConnector,
PullPaymentNoticeDTO2PaymentNoticeDTO paymentNoticeDTOMapper,
Expand All @@ -28,16 +27,9 @@ public PullPaymentServiceImpl(PullPaymentConnector pullPaymentConnector,
this.paymentNoticesListDTOMapper = paymentNoticesListDTOMapper;
}

private String getUserFiscalCode() {
if (this.userFiscalCode == null) {
this.userFiscalCode = SecurityUtils.getUserFiscalCode();
}
return this.userFiscalCode;
}

@Override
public PaymentNoticesListDTO retrievePaymentNoticesListFromPullPayment(LocalDate dueDate, Integer size, Integer page) {
String retrievedUserFiscalCode = getUserFiscalCode();
String retrievedUserFiscalCode = SecurityUtils.getUserFiscalCode();
List<PullPaymentNoticeDTO> pullPaymentNoticeDTOList = pullPaymentConnector.getPaymentNotices(retrievedUserFiscalCode, dueDate, size, page);
List<PaymentNoticeDTO> paymentNoticeDTOFilteredList;

Expand Down
1 change: 0 additions & 1 deletion src/main/resources/application.yml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,6 @@ zendesk-assistance:
private-key: \${JWT_TOKEN_ASSISTANCE_ZENDESK_PRIVATE_KEY:}

rest-client:
fake-fiscal-code: "HSLZYB90L59D030S"
biz-events:
baseUrl: \${BIZ_EVENTS_BASE_URL:}
api-key: \${BIZ_EVENTS_SERVICE_API_KEY:}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,13 +15,11 @@
import it.gov.pagopa.arc.model.generated.TransactionDTO;
import it.gov.pagopa.arc.model.generated.TransactionDetailsDTO;
import it.gov.pagopa.arc.model.generated.TransactionsListDTO;
import it.gov.pagopa.arc.utils.SecurityUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -33,17 +31,14 @@
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import java.io.IOException;
import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.file.Files;
import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.*;
import static org.mockito.Mockito.when;

@ExtendWith(MockitoExtension.class)
class BizEventsServiceImplTest {
Expand Down Expand Up @@ -206,37 +201,5 @@ void givenTransactionIdWhenCallRetrieveTransactionReceiptFromBizEventsThenReturn
Mockito.verify(bizEventsConnectorMock).getTransactionReceipt(anyString(),anyString());
}

@Test
void givenFiscalCodeWhenGetUserFiscalCodeThenNotCallMethod() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {
try (MockedStatic<SecurityUtils> mockedSecurityUtils = mockStatic(SecurityUtils.class)) {

Field userFiscalCodeField = BizEventsServiceImpl.class.getDeclaredField("userFiscalCode");
userFiscalCodeField.setAccessible(true);
userFiscalCodeField.set(bizEventsService, "PRESET_FISCAL_CODE");

Method getUserFiscalCodeMethod = bizEventsService.getClass().getDeclaredMethod("getUserFiscalCode");
getUserFiscalCodeMethod.setAccessible(true);
String result = (String) getUserFiscalCodeMethod.invoke(bizEventsService);

assertEquals("PRESET_FISCAL_CODE", result);
mockedSecurityUtils.verify(SecurityUtils::getUserFiscalCode, times(0));
}
}

@Test
void givenNullWhenGetUserFiscalCodeThenCallMethod() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {

Field userFiscalCodeField = BizEventsServiceImpl.class.getDeclaredField("userFiscalCode");
userFiscalCodeField.setAccessible(true);
userFiscalCodeField.set(bizEventsService, null);

Method getUserFiscalCodeMethod = bizEventsService.getClass().getDeclaredMethod("getUserFiscalCode");
getUserFiscalCodeMethod.setAccessible(true);
String result = (String) getUserFiscalCodeMethod.invoke(bizEventsService);

assertEquals("FISCAL-CODE789456", result);


}

}
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@
import it.gov.pagopa.arc.fakers.paymentNotices.PaymentNoticeDTOFaker;
import it.gov.pagopa.arc.model.generated.PaymentNoticeDTO;
import it.gov.pagopa.arc.model.generated.PaymentNoticesListDTO;
import it.gov.pagopa.arc.utils.SecurityUtils;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
import org.mockito.MockedStatic;
import org.mockito.Mockito;
import org.mockito.junit.jupiter.MockitoExtension;
import org.springframework.beans.factory.annotation.Autowired;
Expand All @@ -28,18 +26,12 @@
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.security.web.authentication.WebAuthenticationDetails;

import java.lang.reflect.Field;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.List;

import static org.assertj.core.api.Assertions.assertThat;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.*;
import static org.mockito.Mockito.mockStatic;
import static org.mockito.Mockito.times;

@ExtendWith(MockitoExtension.class)
class PullPaymentServiceImplTest {
Expand Down Expand Up @@ -218,36 +210,4 @@ void givenParametersWhenRetrieveEmptyPaymentNoticesListFromPullPaymentThenReturn

}

@Test
void givenFiscalCodeWhenGetUserFiscalCodeThenNotCallMethod() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {
try (MockedStatic<SecurityUtils> mockedSecurityUtils = mockStatic(SecurityUtils.class)) {

Field userFiscalCodeField = PullPaymentServiceImpl.class.getDeclaredField("userFiscalCode");
userFiscalCodeField.setAccessible(true);
userFiscalCodeField.set(pullPaymentService, "PRESET_FISCAL_CODE");

Method getUserFiscalCodeMethod = pullPaymentService.getClass().getDeclaredMethod("getUserFiscalCode");
getUserFiscalCodeMethod.setAccessible(true);
String result = (String) getUserFiscalCodeMethod.invoke(pullPaymentService);

assertEquals("PRESET_FISCAL_CODE", result);
mockedSecurityUtils.verify(SecurityUtils::getUserFiscalCode, times(0));
}
}

@Test
void givenNullWhenGetUserFiscalCodeThenCallMethod() throws NoSuchMethodException, NoSuchFieldException, IllegalAccessException, InvocationTargetException {

Field userFiscalCodeField = PullPaymentServiceImpl.class.getDeclaredField("userFiscalCode");
userFiscalCodeField.setAccessible(true);
userFiscalCodeField.set(pullPaymentService, null);

Method getUserFiscalCodeMethod = pullPaymentService.getClass().getDeclaredMethod("getUserFiscalCode");
getUserFiscalCodeMethod.setAccessible(true);
String result = (String) getUserFiscalCodeMethod.invoke(pullPaymentService);

assertEquals("FISCAL-CODE789456", result);


}
}
Loading