index
int64
0
0
repo_id
stringlengths
9
205
file_path
stringlengths
31
246
content
stringlengths
1
12.2M
__index_level_0__
int64
0
10k
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services/strategies/HyperWalletCreateSellerServiceStrategyTest.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.slf4j.Logger; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class HyperWalletCreateSellerServiceStrategyTest extends HyperwalletSellerServiceStrategyTest { @Spy @InjectMocks private HyperWalletCreateSellerServiceStrategy testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Test void pushToHyperwallet_shouldCreateUserInHyperwallet() { prepareHyperwalletSDKInstance(); when(hyperwalletMock.createUser(hyperwalletUserRequestMock)).thenReturn(hyperwalletUserResponseMock); final HyperwalletUser result = testObj.pushToHyperwallet(hyperwalletUserRequestMock); verify(hyperwalletMock).createUser(hyperwalletUserRequestMock); assertThat(result).isEqualTo(hyperwalletUserResponseMock); } @Test void pushToHyperwallet_shouldThrowHMCHyperwalletAPIExceptionWhenHyperwalletSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); ensureHyperwalletSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCHyperwalletAPIException.class); } @Test void pushToHyperwallet_shouldSendAnEmailWhenHyperwalletSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); ensureHyperwalletSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCHyperwalletAPIException.class); verify(testObj).reportError("Issue detected when creating seller in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Seller not created with clientId [%s]%n%s").formatted(CLIENT_USER_ID, HyperwalletLoggingErrorsUtil.stringify(hyperwalletException))); } @Test void pushToHyperwallet_shouldLogTheExceptionWhenHyperwalletSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); ensureHyperwalletSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCHyperwalletAPIException.class); verify(testObj).logErrors( eq("Error creating seller in hyperwallet with clientUserId [%s].%n%s".formatted(CLIENT_USER_ID, HyperwalletLoggingErrorsUtil.stringify(hyperwalletException))), eq(hyperwalletException), any(Logger.class)); } @Test void pushToHyperwallet_shouldUpdateTheTokenInMiraklAfterAnUserIsSuccessfullyCreatedInHw() { prepareHyperwalletSDKInstance(); when(hyperwalletMock.createUser(hyperwalletUserRequestMock)).thenReturn(hyperwalletUserResponseMock); testObj.pushToHyperwallet(hyperwalletUserRequestMock); verify(miraklSellersExtractServiceMock).updateUserToken(hyperwalletUserResponseMock); } @Test void pushToHyperwallet_shouldThrowHMCMiraklAPIExceptionWhenMiraklSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); when(hyperwalletMock.createUser(hyperwalletUserRequestMock)).thenReturn(hyperwalletUserResponseMock); ensureMiraklSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCMiraklAPIException.class); } @Test void pushToHyperwallet_shouldSendAnEmailWhenMiraklSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); when(hyperwalletMock.createUser(hyperwalletUserRequestMock)).thenReturn(hyperwalletUserResponseMock); ensureMiraklSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCMiraklAPIException.class); verify(testObj).reportError("Issue detected when updating seller in Mirakl", (ERROR_MESSAGE_PREFIX + "Seller token not updated with clientId [%s]%n%s").formatted(CLIENT_USER_ID, MiraklLoggingErrorsUtil.stringify(miraklException))); } @Test void pushToHyperwallet_shouldLogTheExceptionWhenMiraklSDKFails() { doNothing().when(testObj).reportError(anyString(), anyString()); prepareHyperwalletSDKInstance(); when(hyperwalletMock.createUser(hyperwalletUserRequestMock)).thenReturn(hyperwalletUserResponseMock); ensureMiraklSDKThrowsAnHMCException(); assertThatThrownBy(() -> testObj.pushToHyperwallet(hyperwalletUserRequestMock)) .isInstanceOf(HMCMiraklAPIException.class); verify(testObj).logErrors( eq("Error updating token in mirakl with clientUserId [%s]: [{}]".formatted(CLIENT_USER_ID)), eq(miraklException), any(Logger.class)); } @Test void isApplicable_shouldReturnTrueWhenTokenIsNull() { when(sellerModelMock.getToken()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenTokenIsNull() { when(sellerModelMock.getToken()).thenReturn(TOKEN); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } private void ensureHyperwalletSDKThrowsAnHMCException() { doThrow(hyperwalletException).when(hyperwalletMock).createUser(hyperwalletUserRequestMock); } private void ensureMiraklSDKThrowsAnHMCException() { doThrow(miraklException).when(miraklSellersExtractServiceMock).updateUserToken(hyperwalletUserResponseMock); } }
4,800
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services/strategies/HyperWalletUserServiceStrategyExecutorSingleTest.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.strategies.HyperWalletUserServiceStrategyExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class HyperWalletUserServiceStrategyExecutorSingleTest { @InjectMocks private HyperWalletUserServiceStrategyExecutor testObj; @Mock private Strategy<SellerModel, SellerModel> strategyMock; @BeforeEach void setUp() { testObj = new HyperWalletUserServiceStrategyExecutor(Set.of(strategyMock)); } @Test void getStrategies_shouldReturnConverterStrategyMock() { final Set<Strategy<SellerModel, SellerModel>> result = testObj.getStrategies(); assertThat(result).containsExactly(strategyMock); } }
4,801
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services/converters/AbstractMiraklShopToIndividualSellerModelConverterTest.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel.SellerModelBuilder; import com.paypal.sellers.sellerextractioncommons.services.converters.AbstractMiraklShopToSellerModelConverter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collections; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AbstractMiraklShopToIndividualSellerModelConverterTest { @InjectMocks private MyAbstractMiraklShopToSellerModelConverter testObj; @Mock private SellersMiraklApiConfig sellersMiraklApiConfigMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklContactInformation contactInformationMock; @Mock private StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor; @Mock private IBANBankAccountModel IBANBankAccountModelMock; @Test void convert_ShouldTransformFromMiraklShopToProfessionalSeller() { when(sellersMiraklApiConfigMock.getTimeZone()).thenReturn("UTC"); when(miraklShopMock.getId()).thenReturn("shopId"); when(miraklShopMock.getName()).thenReturn("shopName"); when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(contactInformationMock.getFirstname()).thenReturn("firstName"); when(contactInformationMock.getLastname()).thenReturn("lastName"); when(contactInformationMock.getPhone()).thenReturn("phone"); when(contactInformationMock.getPhoneSecondary()).thenReturn("secondaryPhone"); when(contactInformationMock.getEmail()).thenReturn("email@example.com"); when(contactInformationMock.getStreet1()).thenReturn("street1"); when(contactInformationMock.getStreet2()).thenReturn("street2"); when(contactInformationMock.getCity()).thenReturn("city"); when(contactInformationMock.getZipCode()).thenReturn("zipcode"); when(contactInformationMock.getState()).thenReturn("state"); when(contactInformationMock.getCountry()).thenReturn("USA"); // Not testing the builder part where it is converting and setting values from // mirakl custom fields when(miraklShopMock.getAdditionalFieldValues()).thenReturn(Collections.emptyList()); when(miraklShopBankAccountModelStrategyExecutor.execute(miraklShopMock)).thenReturn(IBANBankAccountModelMock); final SellerModelBuilder result = testObj.getCommonFieldsBuilder(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("clientUserId", "shopId") .hasFieldOrPropertyWithValue("businessName", "shopName") .hasFieldOrPropertyWithValue("firstName", "firstName") .hasFieldOrPropertyWithValue("lastName", "lastName") .hasFieldOrPropertyWithValue("phoneNumber", "phone") .hasFieldOrPropertyWithValue("mobilePhone", "secondaryPhone") .hasFieldOrPropertyWithValue("email", "email@example.com") .hasFieldOrPropertyWithValue("addressLine1", "street1") .hasFieldOrPropertyWithValue("addressLine2", "street2") .hasFieldOrPropertyWithValue("city", "city") .hasFieldOrPropertyWithValue("postalCode", "zipcode") .hasFieldOrPropertyWithValue("stateProvince", "state") .hasFieldOrPropertyWithValue("country", "US") .hasFieldOrPropertyWithValue("bankAccountDetails", IBANBankAccountModelMock); //@formatter:on } @Test void convert_ShouldTransformFromMiraklShopToProfessionalSellerWhenBankAccountDetailsAreNullOrEmpty() { when(sellersMiraklApiConfigMock.getTimeZone()).thenReturn("UTC"); when(miraklShopMock.getId()).thenReturn("shopId"); when(miraklShopMock.getName()).thenReturn("shopName"); when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(contactInformationMock.getFirstname()).thenReturn("firstName"); when(contactInformationMock.getLastname()).thenReturn("lastName"); when(contactInformationMock.getPhone()).thenReturn("phone"); when(contactInformationMock.getPhoneSecondary()).thenReturn("secondaryPhone"); when(contactInformationMock.getEmail()).thenReturn("email@example.com"); when(contactInformationMock.getStreet1()).thenReturn("street1"); when(contactInformationMock.getStreet2()).thenReturn("street2"); when(contactInformationMock.getCity()).thenReturn("city"); when(contactInformationMock.getZipCode()).thenReturn("zipcode"); when(contactInformationMock.getState()).thenReturn("state"); when(contactInformationMock.getCountry()).thenReturn("USA"); // Not testing the builder part where it is converting and setting values from // mirakl custom fields when(miraklShopMock.getAdditionalFieldValues()).thenReturn(Collections.emptyList()); final SellerModelBuilder result = testObj.getCommonFieldsBuilder(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("clientUserId", "shopId") .hasFieldOrPropertyWithValue("businessName", "shopName") .hasFieldOrPropertyWithValue("firstName", "firstName") .hasFieldOrPropertyWithValue("lastName", "lastName") .hasFieldOrPropertyWithValue("phoneNumber", "phone") .hasFieldOrPropertyWithValue("mobilePhone", "secondaryPhone") .hasFieldOrPropertyWithValue("email", "email@example.com") .hasFieldOrPropertyWithValue("addressLine1", "street1") .hasFieldOrPropertyWithValue("addressLine2", "street2") .hasFieldOrPropertyWithValue("city", "city") .hasFieldOrPropertyWithValue("postalCode", "zipcode") .hasFieldOrPropertyWithValue("stateProvince", "state") .hasFieldOrPropertyWithValue("country", "US") .hasFieldOrPropertyWithValue("bankAccountDetails", null); //@formatter:on } private static class MyAbstractMiraklShopToSellerModelConverter extends AbstractMiraklShopToSellerModelConverter { protected MyAbstractMiraklShopToSellerModelConverter( final StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor, final SellersMiraklApiConfig sellersMiraklApiConfig) { super(miraklShopBankAccountModelStrategyExecutor, sellersMiraklApiConfig); } @Override public SellerModel execute(final MiraklShop source) { return null; } @Override public boolean isApplicable(final MiraklShop source) { return false; } } }
4,802
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services/converters/SellerModelToHyperWalletUserConverterTest.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.infrastructure.hyperwallet.configuration.HyperwalletProgramsConfiguration; import com.paypal.infrastructure.support.date.DateUtil; import com.paypal.sellers.sellerextractioncommons.model.SellerBusinessType; import com.paypal.sellers.sellerextractioncommons.model.SellerGovernmentIdType; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.model.SellerProfileType; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.springframework.test.util.ReflectionTestUtils; import java.time.LocalDate; import java.time.ZoneId; import java.util.Date; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.lenient; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SellerModelToHyperWalletUserConverterTest { private static final String PROGRAM_TOKEN = "PROGRAM_TOKEN"; private static final String CLIENT_USER_ID = "1025"; private static final String FIRST_NAME = "John"; private static final String SECOND_NAME = "Doe"; private static final String ADDRESS_LINE_ONE = "Elmo Street"; private static final String ADDRESS_LINE_TWO = "Door 1"; private static final String BUSINESS_NAME = "Super Business"; private static final String CITY = "Wonder Town"; private static final String COUNTRY = "USA"; private static final String COUNTRY_OF_BIRTH = "ESP"; private static final Date DATE_OF_BIRTH = DateUtil.convertToDate(LocalDate.of(1985, 9, 6), ZoneId.systemDefault()); private static final String COUNTRY_OF_NATIONALITY = "FRA"; private static final String DRIVERS_LICENSE = "489663020J"; private static final String EMAIL = "mysuperstore@paypal.com"; private static final String GOVERNMENT_ID = "JKL20"; private static final String MOBILE_PHONE = "+34656201324"; private static final String PHONE_NUMBER = "+34920124568"; private static final String POSTAL_CODE = "ZIP2005"; private static final String STATE_PROVINCE = "Ohio"; private static final String PASSPORT_ID = "12346502KLM"; private static final String USER_TOKEN = "2134654512574"; private static final String COMPANY_NAME = "companyName"; private static final String COMPANY_REGISTRATION_NUMBER = "companyRegistrationNumber"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; private static final String BUSINESS_REGISTRATION_STATE_PROVINCE = "businessRegistrationStateProvince"; private static final String COMPANY_REGISTRATION_COUNTRY = "companyRegistrationCountry"; private static final String NEW_USER_MAPPING_ENABLED = "newUserMappingEnabled"; @InjectMocks private SellerModelToHyperWalletUserConverter testObj; @Mock private SellerModel sellerModelMock; @Mock private HyperwalletProgramsConfiguration hyperwalletProgramsConfiguration; @Mock private HyperwalletProgramsConfiguration.HyperwalletProgramConfiguration hyperwalletProgramConfigurationMock; @BeforeEach void setUp() { ReflectionTestUtils.setField(testObj, NEW_USER_MAPPING_ENABLED, false); when(sellerModelMock.getClientUserId()).thenReturn(CLIENT_USER_ID); when(sellerModelMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(hyperwalletProgramsConfiguration.getProgramConfiguration(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletProgramConfigurationMock); when(hyperwalletProgramConfigurationMock.getUsersProgramToken()).thenReturn(PROGRAM_TOKEN); when(sellerModelMock.getBusinessName()).thenReturn(BUSINESS_NAME); when(sellerModelMock.getBusinessType()).thenReturn(SellerBusinessType.PRIVATE_COMPANY); when(sellerModelMock.getCity()).thenReturn(CITY); when(sellerModelMock.getPostalCode()).thenReturn(POSTAL_CODE); when(sellerModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_ONE); when(sellerModelMock.getCountry()).thenReturn(COUNTRY); when(sellerModelMock.getStateProvince()).thenReturn(STATE_PROVINCE); when(sellerModelMock.getToken()).thenReturn(USER_TOKEN); when(sellerModelMock.getEmail()).thenReturn(EMAIL); lenient().when(sellerModelMock.getCompanyRegistrationCountry()).thenReturn(COMPANY_REGISTRATION_COUNTRY); lenient().when(sellerModelMock.getBusinessRegistrationStateProvince()) .thenReturn(BUSINESS_REGISTRATION_STATE_PROVINCE); lenient().when(sellerModelMock.getCompanyRegistrationNumber()).thenReturn(COMPANY_REGISTRATION_NUMBER); lenient().when(sellerModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_TWO); lenient().when(sellerModelMock.getPhoneNumber()).thenReturn(PHONE_NUMBER); lenient().when(sellerModelMock.getLastName()).thenReturn(SECOND_NAME); lenient().when(sellerModelMock.getFirstName()).thenReturn(FIRST_NAME); lenient().when(sellerModelMock.getCountryOfBirth()).thenReturn(COUNTRY_OF_BIRTH); lenient().when(sellerModelMock.getDateOfBirth()).thenReturn(DATE_OF_BIRTH); lenient().when(sellerModelMock.getCountryOfNationality()).thenReturn(COUNTRY_OF_NATIONALITY); lenient().when(sellerModelMock.getDriversLicenseId()).thenReturn(DRIVERS_LICENSE); lenient().when(sellerModelMock.getGovernmentIdType()).thenReturn(SellerGovernmentIdType.NATIONAL_ID_CARD); lenient().when(sellerModelMock.getGovernmentId()).thenReturn(GOVERNMENT_ID); lenient().when(sellerModelMock.getPassportId()).thenReturn(PASSPORT_ID); lenient().when(sellerModelMock.getMobilePhone()).thenReturn(MOBILE_PHONE); lenient().when(sellerModelMock.getCompanyName()).thenReturn(COMPANY_NAME); } @Test void convert_shouldCreateAHyperWalletUserWithTheDetailsFromTheProfessionalSellerModelPassedAsParameterAndNewUserMappingEnabled() { when(sellerModelMock.getProfileType()).thenReturn(SellerProfileType.BUSINESS); final HyperwalletUser result = testObj.convert(sellerModelMock); assertThat(result).hasAllNullFieldsOrPropertiesExcept("clientUserId", "businessName", "profileType", "businessType", "addressLine1", "city", "stateProvince", "postalCode", "programToken", "country", "token", "inclusions", "email", "businessRegistrationCountry", "businessRegistrationStateProvince", "businessRegistrationId", "businessOperatingName"); assertThat(result.getClientUserId()).isEqualTo(CLIENT_USER_ID); assertThat(result.getBusinessName()).isEqualTo(BUSINESS_NAME); assertThat(result.getBusinessOperatingName()).isEqualTo(COMPANY_NAME); assertThat(result.getProfileType()).isEqualTo(HyperwalletUser.ProfileType.BUSINESS); assertThat(result.getBusinessType()).isEqualTo(HyperwalletUser.BusinessType.PRIVATE_COMPANY); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_ONE); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); assertThat(result.getProgramToken()).isEqualTo(PROGRAM_TOKEN); assertThat(result.getToken()).isEqualTo(USER_TOKEN); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getBusinessRegistrationCountry()).isEqualTo(COMPANY_REGISTRATION_COUNTRY); assertThat(result.getBusinessRegistrationStateProvince()).isEqualTo(BUSINESS_REGISTRATION_STATE_PROVINCE); assertThat(result.getBusinessRegistrationId()).isEqualTo(COMPANY_REGISTRATION_NUMBER); } @Test void convert_shouldCreateAHyperWalletUserWithTheDetailsFromTheProfessionalSellerModelPassedAsParameterAndNewUserMappingNotEnabled() { ReflectionTestUtils.setField(testObj, NEW_USER_MAPPING_ENABLED, true); when(sellerModelMock.getProfileType()).thenReturn(SellerProfileType.BUSINESS); final HyperwalletUser result = testObj.convert(sellerModelMock); assertThat(result).hasAllNullFieldsOrPropertiesExcept("clientUserId", "businessName", "profileType", "businessType", "addressLine1", "city", "stateProvince", "postalCode", "programToken", "country", "token", "inclusions", "email", "businessRegistrationCountry", "businessRegistrationStateProvince", "businessRegistrationId", "businessOperatingName"); assertThat(result.getClientUserId()).isEqualTo(CLIENT_USER_ID); assertThat(result.getBusinessName()).isEqualTo(COMPANY_NAME); assertThat(result.getBusinessOperatingName()).isEqualTo(BUSINESS_NAME); assertThat(result.getProfileType()).isEqualTo(HyperwalletUser.ProfileType.BUSINESS); assertThat(result.getBusinessType()).isEqualTo(HyperwalletUser.BusinessType.PRIVATE_COMPANY); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_ONE); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); assertThat(result.getProgramToken()).isEqualTo(PROGRAM_TOKEN); assertThat(result.getToken()).isEqualTo(USER_TOKEN); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getBusinessRegistrationCountry()).isEqualTo(COMPANY_REGISTRATION_COUNTRY); assertThat(result.getBusinessRegistrationStateProvince()).isEqualTo(BUSINESS_REGISTRATION_STATE_PROVINCE); assertThat(result.getBusinessRegistrationId()).isEqualTo(COMPANY_REGISTRATION_NUMBER); } @Test void convert_shouldCreateAHyperWalletUserWithTheDetailsFromTheIndividualSellerModelPassedAsParameter() { when(sellerModelMock.getProfileType()).thenReturn(SellerProfileType.INDIVIDUAL); final HyperwalletUser result = testObj.convert(sellerModelMock); assertThat(result.getClientUserId()).isEqualTo(CLIENT_USER_ID); assertThat(result.getBusinessName()).isEqualTo(BUSINESS_NAME); assertThat(result.getProfileType()).isEqualTo(HyperwalletUser.ProfileType.INDIVIDUAL); assertThat(result.getFirstName()).isEqualTo(FIRST_NAME); assertThat(result.getLastName()).isEqualTo(SECOND_NAME); assertThat(result.getDateOfBirth()).isEqualTo(DATE_OF_BIRTH); assertThat(result.getCountryOfBirth()).isEqualTo(COUNTRY_OF_BIRTH); assertThat(result.getCountryOfNationality()).isEqualTo(COUNTRY_OF_NATIONALITY); assertThat(result.getPhoneNumber()).isEqualTo(PHONE_NUMBER); assertThat(result.getMobileNumber()).isEqualTo(MOBILE_PHONE); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getGovernmentId()).isEqualTo(GOVERNMENT_ID); assertThat(result.getPassportId()).isEqualTo(PASSPORT_ID); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_ONE); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_TWO); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); assertThat(result.getProgramToken()).isEqualTo(PROGRAM_TOKEN); assertThat(result.getDriversLicenseId()).isEqualTo(DRIVERS_LICENSE); assertThat(result.getBusinessType()).isEqualTo(HyperwalletUser.BusinessType.PRIVATE_COMPANY); assertThat(result.getGovernmentIdType()).isEqualTo(HyperwalletUser.GovernmentIdType.NATIONAL_ID_CARD); assertThat(result.getToken()).isEqualTo(USER_TOKEN); } }
4,803
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/sellerextractioncommons/services/converters/MiraklShopToSellerConverterExecutorTest.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.converters.MiraklShopToSellerConverterExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class MiraklShopToSellerConverterExecutorTest { @InjectMocks private MiraklShopToSellerConverterExecutor testObj; @Mock private Strategy<MiraklShop, SellerModel> strategyMock; @BeforeEach void setUp() { testObj = new MiraklShopToSellerConverterExecutor(Set.of(strategyMock)); } @Test void getStrategies_shouldReturnConverterStrategyMock() { final Set<Strategy<MiraklShop, SellerModel>> result = testObj.getStrategies(); assertThat(result).containsExactly(strategyMock); } }
4,804
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/BankAccountExtractionJobsConfigTest.java
package com.paypal.sellers.bankaccountextraction; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBean; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountRetryBatchJob; import com.paypal.sellers.bankaccountextraction.jobs.BankAccountExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerKey; import org.quartz.impl.triggers.CronTriggerImpl; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BankAccountExtractionJobsConfigTest { private static final String CRON_EXPRESSION = "0 0 0 1/1 * ? *"; private static final String RETRY_CRON_EXPRESSION = "0 0/15 * ? * * *"; private static final String TRIGGER_PREFIX = "Trigger"; private static final String JOB_NAME = "BankAccountExtractJob"; private static final String RETRY_JOB_NAME = "BankAccountRetryJob"; @InjectMocks private BankAccountExtractionJobsConfig testObj; @Mock private BankAccountRetryBatchJob bankAccountRetryBatchJob; @Test void bankAccountExtractJob_createsJobDetailWithNameBankAccountJobAndTypeBankAccountExtractJob() { final JobDetail result = testObj.bankAccountExtractJob(); assertThat(result.getJobClass()).hasSameClassAs(BankAccountExtractionJobsConfig.class); assertThat(result.getKey().getName()).isEqualTo("BankAccountExtractJob"); } @Test void bankAccountExtractJobTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = JobBuilder.newJob(BankAccountExtractJob.class).withIdentity(JOB_NAME).build(); final Trigger result = testObj.bankAccountExtractJobTrigger(jobDetail, CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(result.getKey()).isEqualTo(TriggerKey.triggerKey(TRIGGER_PREFIX + JOB_NAME)); assertThat(result).isInstanceOf(CronTriggerImpl.class); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(CRON_EXPRESSION); } @Test void bankAccountRetryJob_createsJobDetailWithNameBankAccountJobAndBankAccountRetryBatchJob() { final JobDetail result = testObj.bankAccountRetryJob(bankAccountRetryBatchJob); assertThat(result.getJobClass()).hasSameClassAs(QuartzBatchJobBean.class); assertThat(result.getKey().getName()).isEqualTo(RETRY_JOB_NAME); assertThat(result.getJobDataMap()).containsEntry("batchJob", bankAccountRetryBatchJob); } @Test void bankAccountRetryJobTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = testObj.bankAccountRetryJob(bankAccountRetryBatchJob); final Trigger result = testObj.bankAccountRetryJobTrigger(jobDetail, RETRY_CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(result.getKey()).isEqualTo(TriggerKey.triggerKey(TRIGGER_PREFIX + RETRY_JOB_NAME)); assertThat(result).isInstanceOf(CronTriggerImpl.class); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(RETRY_CRON_EXPRESSION); } }
4,805
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountRetryBatchJobTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJobItemProcessor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountRetryBatchJob; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountRetryBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.InjectMocks; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BankAccountRetryBatchJobTest { @InjectMocks private BankAccountRetryBatchJob testObj; @Mock private BankAccountExtractBatchJobItemProcessor bankAccountExtractBatchJobItemProcessorMock; @Mock private BankAccountRetryBatchJobItemsExtractor bankAccountRetryBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_shouldReturnBatchJobItemProcessor() { assertThat(testObj.getBatchJobItemProcessor()).isEqualTo(bankAccountExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_shouldReturnRetryBatchJobItemExtractor() { assertThat(testObj.getBatchJobItemsExtractor()).isEqualTo(bankAccountRetryBatchJobItemsExtractorMock); } }
4,806
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountExtractBatchJobItemsExtractorTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJobItemsExtractor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.Date; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BankAccountExtractBatchJobItemsExtractorTest { private static final Date DELTA = new Date(); @InjectMocks private BankAccountExtractBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2, sellerModelMock3, sellerModelMock4; @Mock private BatchJobContext batchJobContextMock; @Test void getItems_ShouldRetrieveAllBankAccountExtractJobItemForTheGivenDelta() { when(miraklSellersExtractServiceMock.extractIndividuals(DELTA)) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); when(miraklSellersExtractServiceMock.extractProfessionals(DELTA)) .thenReturn(List.of(sellerModelMock3, sellerModelMock4)); final Collection<BankAccountExtractJobItem> result = testObj.getItems(batchJobContextMock, DELTA); assertThat(result.stream().map(BankAccountExtractJobItem::getItem)).containsExactlyInAnyOrder(sellerModelMock1, sellerModelMock2, sellerModelMock3, sellerModelMock4); } }
4,807
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountExtractBatchJobItemProcessorTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.sellers.bankaccountextraction.services.BankAccountTokenSynchronizationServiceImpl; import com.paypal.sellers.bankaccountextraction.services.strategies.HyperWalletBankAccountStrategyExecutor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJobItemProcessor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BankAccountExtractBatchJobItemProcessorTest { @InjectMocks private BankAccountExtractBatchJobItemProcessor testObj; @Mock private HyperWalletBankAccountStrategyExecutor hyperWalletBankAccountStrategyExecutorMock; @Mock private BankAccountTokenSynchronizationServiceImpl bankAccountTokenSynchronizationServiceMock; @Mock private BatchJobContext batchJobContextMock; @Test void processItem_ShouldExecuteHyperWalletBankAccountServiceExecutor() { final SellerModel sellerModel = SellerModel.builder().build(); final BankAccountExtractJobItem bankAccountExtractJobItem = new BankAccountExtractJobItem(sellerModel); final SellerModel synchronizedSellerModel = SellerModel.builder().build(); when(bankAccountTokenSynchronizationServiceMock.synchronizeToken(sellerModel)) .thenReturn(synchronizedSellerModel); testObj.processItem(batchJobContextMock, bankAccountExtractJobItem); verify(hyperWalletBankAccountStrategyExecutorMock).execute(synchronizedSellerModel); } }
4,808
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountExtractJobItemTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class BankAccountExtractJobItemTest { private static final String CLIENT_USER_ID = "clientUserId"; private static final String BANK_ACCOUNT = "BankAccount"; @Test void getItemId_ShouldReturnTheClientUserId() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final BankAccountExtractJobItem testObj = new BankAccountExtractJobItem(sellerModel); assertThat(testObj.getItemId()).isEqualTo(CLIENT_USER_ID); } @Test void getItemType_ShouldReturnBankAccount() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final BankAccountExtractJobItem testObj = new BankAccountExtractJobItem(sellerModel); assertThat(testObj.getItemType()).isEqualTo(BANK_ACCOUNT); } }
4,809
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountRetryBatchJobItemsExtractorTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobItem; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractJobItem; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountRetryBatchJobItemsExtractor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BankAccountRetryBatchJobItemsExtractorTest { private static final String SELLER_ID_1 = "1"; private static final String SELLER_ID_2 = "2"; @InjectMocks private BankAccountRetryBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Test void getItem_shouldReturnBankAccountType() { final String result = testObj.getItemType(); assertThat(result).isEqualTo(BankAccountExtractJobItem.ITEM_TYPE); } @Test void getItems_ShouldReturnAllSellersByTheGivenIds() { when(miraklSellersExtractServiceMock.extractSellers(List.of(SELLER_ID_1, SELLER_ID_2))) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); final Collection<BankAccountExtractJobItem> result = testObj.getItems(List.of(SELLER_ID_1, SELLER_ID_2)); assertThat(result.stream().map(BatchJobItem::getItem).map(SellerModel.class::cast)) .containsExactlyInAnyOrder(sellerModelMock1, sellerModelMock2); } }
4,810
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/batchjobs/BankAccountExtractBatchJobTest.java
package com.paypal.sellers.bankaccountextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJob; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJobItemProcessor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJobItemsExtractor; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractJobItem; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BankAccountExtractBatchJobTest { @InjectMocks private BankAccountExtractBatchJob testObj; @Mock private BankAccountExtractBatchJobItemProcessor bankAccountExtractBatchJobItemProcessorMock; @Mock private BankAccountExtractBatchJobItemsExtractor bankAccountExtractBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_ShouldReturnTheBankAccountExtractBatchJobItemProcessor() { final BatchJobItemProcessor<BatchJobContext, BankAccountExtractJobItem> result = testObj .getBatchJobItemProcessor(); assertThat(result).isEqualTo(bankAccountExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_ShouldReturnTheBankAccountExtractBatchJobItemsExtractor() { final BatchJobItemsExtractor<BatchJobContext, BankAccountExtractJobItem> result = testObj .getBatchJobItemsExtractor(); assertThat(result).isEqualTo(bankAccountExtractBatchJobItemsExtractorMock); } }
4,811
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/model/ABABankAccountModelTest.java
package com.paypal.sellers.bankaccountextraction.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.ABABankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @ExtendWith(MockitoExtension.class) class ABABankAccountModelTest { private static final String TOKEN_VALUE_1 = "token1"; private static final String TOKEN_VALUE_2 = "token2"; @Test void setCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final ABABankAccountModel testObj = ABABankAccountModel.builder().country("USA").build(); assertThat(testObj.getCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> ABABankAccountModel.builder().country("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final ABABankAccountModel testObj = ABABankAccountModel.builder().transferMethodCountry("USA").build(); assertThat(testObj.getTransferMethodCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> ABABankAccountModel.builder().transferMethodCountry("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCurrency_shouldSetCurrencyIsoCodeWhenCurrencyIsoCodeIsValid() { final ABABankAccountModel testObj = ABABankAccountModel.builder().transferMethodCurrency("EUR").build(); assertThat(testObj.getTransferMethodCurrency()).isEqualTo("EUR"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCurrency_shouldThrowAnExceptionWhenCurrencyIsInvalid() { assertThatThrownBy(() -> ABABankAccountModel.builder().transferMethodCurrency("INVALID_CURRENCY").build()) .isInstanceOf(IllegalStateException.class) .hasMessage("Transfer method currency with code: [INVALID_CURRENCY] not valid"); } @Test void toBuild_ShouldReturnCopyOABABankAccountModel() { final ABABankAccountModel bankAccountModel = createABABankAccountModelObject(TOKEN_VALUE_1); final ABABankAccountModel copyBankAccountModel = bankAccountModel.toBuilder().build(); assertThat(bankAccountModel).isEqualTo(copyBankAccountModel); } @Test void toBuild_ShouldReturnCopyOfABABankAccountModelWithTheUpdatedToken() { final ABABankAccountModel bankAccountModel1 = createABABankAccountModelObject(TOKEN_VALUE_1); final ABABankAccountModel bankAccountModel2 = createABABankAccountModelObject(TOKEN_VALUE_2); final ABABankAccountModel copyBankAccountModel = bankAccountModel1.toBuilder().token(TOKEN_VALUE_2).build(); assertThat(bankAccountModel2).isEqualTo(copyBankAccountModel); } private ABABankAccountModel createABABankAccountModelObject(final String token) { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue(token); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return ABABankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("EUR") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .branchId("branchId") .bankAccountPurpose("bankAccountPurpose") .build(); //@formatter:on } }
4,812
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/model/CanadianBankAccountModelTest.java
package com.paypal.sellers.bankaccountextraction.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.CanadianBankAccountModel; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @ExtendWith(MockitoExtension.class) class CanadianBankAccountModelTest { private static final String TOKEN_VALUE_1 = "token1"; private static final String TOKEN_VALUE_2 = "token2"; @Test void setCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final CanadianBankAccountModel testObj = CanadianBankAccountModel.builder().country("USA").build(); assertThat(testObj.getCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> CanadianBankAccountModel.builder().country("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final CanadianBankAccountModel testObj = CanadianBankAccountModel.builder().transferMethodCountry("USA") .build(); assertThat(testObj.getTransferMethodCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> CanadianBankAccountModel.builder().transferMethodCountry("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCurrency_shouldSetCurrencyIsoCodeWhenCurrencyIsoCodeIsValid() { final CanadianBankAccountModel testObj = CanadianBankAccountModel.builder().transferMethodCurrency("EUR") .build(); assertThat(testObj.getTransferMethodCurrency()).isEqualTo("EUR"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCurrency_shouldThrowAnExceptionWhenCurrencyIsInvalid() { assertThatThrownBy(() -> CanadianBankAccountModel.builder().transferMethodCurrency("INVALID_CURRENCY").build()) .isInstanceOf(IllegalStateException.class) .hasMessage("Transfer method currency with code: [INVALID_CURRENCY] not valid"); } @Test void toBuild_ShouldReturnCopyOfCanadianBankAccountModel() { final CanadianBankAccountModel bankAccountModel = createCanadianBankAccountModelObject(TOKEN_VALUE_1); final CanadianBankAccountModel copyBankAccountModel = bankAccountModel.toBuilder().build(); assertThat(bankAccountModel).isEqualTo(copyBankAccountModel); } @Test void toBuild_ShouldReturnCopyOfCanadianBankAccountModelWithTheUpdatedToken() { final CanadianBankAccountModel bankAccountModel1 = createCanadianBankAccountModelObject(TOKEN_VALUE_1); final CanadianBankAccountModel bankAccountModel2 = createCanadianBankAccountModelObject(TOKEN_VALUE_2); final CanadianBankAccountModel copyBankAccountModel = bankAccountModel1.toBuilder().token(TOKEN_VALUE_2) .build(); assertThat(bankAccountModel2).isEqualTo(copyBankAccountModel); } private CanadianBankAccountModel createCanadianBankAccountModelObject(final String token) { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue(token); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return CanadianBankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("EUR") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .bankId("bankId") .branchId("branchId") .build(); //@formatter:on } }
4,813
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/model/IBANBankAccountModelTest.java
package com.paypal.sellers.bankaccountextraction.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; class IBANBankAccountModelTest { private static final String TOKEN_VALUE_1 = "token1"; private static final String TOKEN_VALUE_2 = "token2"; @Test void setCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final IBANBankAccountModel testObj = IBANBankAccountModel.builder().country("USA").build(); assertThat(testObj.getCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> IBANBankAccountModel.builder().country("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final IBANBankAccountModel testObj = IBANBankAccountModel.builder().transferMethodCountry("USA").build(); assertThat(testObj.getTransferMethodCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> IBANBankAccountModel.builder().transferMethodCountry("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCurrency_shouldSetCurrencyIsoCodeWhenCurrencyIsoCodeIsValid() { final IBANBankAccountModel testObj = IBANBankAccountModel.builder().transferMethodCurrency("EUR").build(); assertThat(testObj.getTransferMethodCurrency()).isEqualTo("EUR"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCurrency_shouldThrowAnExceptionWhenCurrencyIsInvalid() { assertThatThrownBy(() -> IBANBankAccountModel.builder().transferMethodCurrency("INVALID_CURRENCY").build()) .isInstanceOf(IllegalStateException.class) .hasMessage("Transfer method currency with code: [INVALID_CURRENCY] not valid"); } @Test void toBuild_ShouldReturnCopyOfIBANBankAccountModel() { final IBANBankAccountModel bankAccountModel = createIBANBankAccountModelObject(TOKEN_VALUE_1); final IBANBankAccountModel copyBankAccountModel = bankAccountModel.toBuilder().build(); assertThat(bankAccountModel).isEqualTo(copyBankAccountModel); } @Test void toBuild_ShouldReturnCopyOfIBANBankAccountModelWithTheUpdatedToken() { final IBANBankAccountModel bankAccountModel1 = createIBANBankAccountModelObject(TOKEN_VALUE_1); final IBANBankAccountModel bankAccountModel2 = createIBANBankAccountModelObject(TOKEN_VALUE_2); final IBANBankAccountModel copyBankAccountModel = bankAccountModel1.toBuilder().token(TOKEN_VALUE_2).build(); assertThat(bankAccountModel2).isEqualTo(copyBankAccountModel); } private IBANBankAccountModel createIBANBankAccountModelObject(final String token) { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue(token); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return IBANBankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("EUR") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .bankBic("bankBic") .build(); //@formatter:on } }
4,814
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/model/UKBankAccountModelTest.java
package com.paypal.sellers.bankaccountextraction.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.bankaccountextraction.model.UKBankAccountModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; @ExtendWith(MockitoExtension.class) class UKBankAccountModelTest { private static final String TOKEN_VALUE_1 = "token1"; private static final String TOKEN_VALUE_2 = "token2"; @Test void setCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final UKBankAccountModel testObj = UKBankAccountModel.builder().country("USA").build(); assertThat(testObj.getCountry()).isEqualTo("US"); } @Test void setBankAccountId_shouldSetBankAccountId() { final UKBankAccountModel testObj = UKBankAccountModel.builder().bankAccountId("bankAccountId").build(); assertThat(testObj.getBankAccountId()).isEqualTo("bankAccountId"); } @SuppressWarnings("java:S5778") @Test void setCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> UKBankAccountModel.builder().country("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCountry_shouldConvertTo2LettersWhenCountry3IsocodeExists() { final UKBankAccountModel testObj = UKBankAccountModel.builder().transferMethodCountry("USA").build(); assertThat(testObj.getTransferMethodCountry()).isEqualTo("US"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCountry_shouldThrowAnExceptionWhenCountry3IsocodeDoesNotExists() { assertThatThrownBy(() -> UKBankAccountModel.builder().transferMethodCountry("PAY").build()) .isInstanceOf(IllegalStateException.class).hasMessage("Country with isocode: [PAY] not valid"); } @Test void setTransferMethodCurrency_shouldSetCurrencyIsoCodeWhenCurrencyIsoCodeIsValid() { final UKBankAccountModel testObj = UKBankAccountModel.builder().transferMethodCurrency("EUR").build(); assertThat(testObj.getTransferMethodCurrency()).isEqualTo("EUR"); } @SuppressWarnings("java:S5778") @Test void setTransferMethodCurrency_shouldThrowAnExceptionWhenCurrencyIsInvalid() { assertThatThrownBy(() -> UKBankAccountModel.builder().transferMethodCurrency("INVALID_CURRENCY").build()) .isInstanceOf(IllegalStateException.class) .hasMessage("Transfer method currency with code: [INVALID_CURRENCY] not valid"); } @Test void toBuild_ShouldReturnCopyOfUKBankAccountModel() { final UKBankAccountModel bankAccountModel = createUKBankAccountModelObject(TOKEN_VALUE_1); final UKBankAccountModel copyBankAccountModel = bankAccountModel.toBuilder().build(); assertThat(bankAccountModel).isEqualTo(copyBankAccountModel); } @Test void toBuild_ShouldReturnCopyOfUKBankAccountModelWithTheUpdatedToken() { final UKBankAccountModel bankAccountModel1 = createUKBankAccountModelObject(TOKEN_VALUE_1); final UKBankAccountModel bankAccountModel2 = createUKBankAccountModelObject(TOKEN_VALUE_2); final UKBankAccountModel copyBankAccountModel = bankAccountModel1.toBuilder().token(TOKEN_VALUE_2).build(); assertThat(bankAccountModel2).isEqualTo(copyBankAccountModel); } private UKBankAccountModel createUKBankAccountModelObject(final String token) { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue(token); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return UKBankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("EUR") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .bankAccountId("bankAccountId") .build(); //@formatter:on } }
4,815
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/model/BankAccountModelTest.java
package com.paypal.sellers.bankaccountextraction.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BankAccountModelTest { private static final String TOKEN_VALUE_1 = "token1"; private static final String TOKEN_VALUE_2 = "token2"; @Test void equals_shouldReturnTrueWhenBothAreEquals() { final BankAccountModel bankAccountModelOne = createBankAccountModelObject(TOKEN_VALUE_1); final BankAccountModel bankAccountModelTwo = createBankAccountModelObject(TOKEN_VALUE_1); final boolean result = bankAccountModelOne.equals(bankAccountModelTwo); assertThat(result).isTrue(); } @Test void equals_shouldReturnFalseWhenBothAreNotEquals() { final BankAccountModel bankAccountModelOne = createBankAccountModelObject(TOKEN_VALUE_1); final BankAccountModel bankAccountModelTwo = createAnotherBankAccountModelObject(); final boolean result = bankAccountModelOne.equals(bankAccountModelTwo); assertThat(result).isFalse(); } @Test void equals_shouldReturnTrueWhenSameObjectIsCompared() { final BankAccountModel bankAccountModelOne = createBankAccountModelObject(TOKEN_VALUE_1); final boolean result = bankAccountModelOne.equals(bankAccountModelOne); assertThat(result).isTrue(); } @Test void equals_shouldReturnFalseWhenComparedWithAnotherInstanceObject() { final BankAccountModel bankAccountModelOne = createBankAccountModelObject(TOKEN_VALUE_1); final Object o = new Object(); final boolean result = bankAccountModelOne.equals(o); assertThat(result).isFalse(); } @Test void toBuild_ShouldReturnCopyOfBankAccountModel() { final BankAccountModel bankAccountModel = createBankAccountModelObject(TOKEN_VALUE_1); final BankAccountModel copyBankAccountModel = bankAccountModel.toBuilder().build(); assertThat(bankAccountModel).isEqualTo(copyBankAccountModel); } @Test void toBuild_ShouldReturnCopyOfBankAccountModelWithTheUpdatedToken() { final BankAccountModel bankAccountModel1 = createBankAccountModelObject(TOKEN_VALUE_1); final BankAccountModel bankAccountModel2 = createBankAccountModelObject(TOKEN_VALUE_2); final BankAccountModel copyBankAccountModel = bankAccountModel1.toBuilder().token(TOKEN_VALUE_2).build(); assertThat(bankAccountModel2).isEqualTo(copyBankAccountModel); } private BankAccountModel createBankAccountModelObject(final String token) { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue(token); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return BankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("EUR") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .build(); //@formatter:on } private BankAccountModel createAnotherBankAccountModelObject() { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue tokenBankAccountField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); tokenBankAccountField.setCode(HYPERWALLET_BANK_ACCOUNT_TOKEN); tokenBankAccountField.setValue("token"); final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(HYPERWALLET_BANK_ACCOUNT_STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue hyperwalletProgramAccountField = new MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue(); hyperwalletProgramAccountField.setCode(HYPERWALLET_PROGRAM); hyperwalletProgramAccountField.setValue("hyperwalletProgram"); //@formatter:off return BankAccountModel.builder() .transferMethodCountry("USA") .transferMethodCurrency("USD") .transferType(TransferType.BANK_ACCOUNT) .type(BankAccountType.ABA) .bankAccountNumber("111") .businessName("businessName") .firstName("firstName") .lastName("lastName") .country("USA") .addressLine1("addressLine1") .addressLine2("addressLine2") .city("city") .stateProvince(List.of(stateProvinceBusinessStakeHolderField)) .postalCode("2222") .token(List.of(tokenBankAccountField)) .hyperwalletProgram(List.of(hyperwalletProgramAccountField)) .build(); //@formatter:on } }
4,816
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/jobs/BankAccountExtractJobTest.java
package com.paypal.sellers.bankaccountextraction.jobs; import com.paypal.jobsystem.batchjob.model.BatchJob; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobAdapterFactory; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountExtractBatchJob; import com.paypal.sellers.bankaccountextraction.jobs.BankAccountExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class BankAccountExtractJobTest { @InjectMocks @Spy private MyBankAccountExtractJob testObj; @Mock private BankAccountExtractBatchJob bankAccountExtractBatchJobMock; @Mock private JobExecutionContext jobExecutionContextMock; @Test void execute_ShouldExecuteBankAccountExtractBatchJob() throws JobExecutionException { doNothing().when(testObj).executeBatchJob(bankAccountExtractBatchJobMock, jobExecutionContextMock); testObj.execute(jobExecutionContextMock); verify(testObj).executeBatchJob(bankAccountExtractBatchJobMock, jobExecutionContextMock); } static class MyBankAccountExtractJob extends BankAccountExtractJob { public MyBankAccountExtractJob(final QuartzBatchJobAdapterFactory quartzBatchJobAdapterFactory, final BankAccountExtractBatchJob bankAccountExtractBatchJob) { super(quartzBatchJobAdapterFactory, bankAccountExtractBatchJob); } @Override protected void executeBatchJob(final BatchJob batchJob, final JobExecutionContext context) throws JobExecutionException { super.executeBatchJob(batchJob, context); } } }
4,817
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/controllers/BankAccountExtractJobControllerTest.java
package com.paypal.sellers.bankaccountextraction.controllers; import com.paypal.jobsystem.quartzintegration.support.AbstractDeltaInfoJob; import com.paypal.jobsystem.quartzintegration.services.JobService; import com.paypal.infrastructure.support.date.DateUtil; import com.paypal.infrastructure.support.date.TimeMachine; import com.paypal.sellers.bankaccountextraction.controllers.BankAccountExtractJobController; import com.paypal.sellers.bankaccountextraction.jobs.BankAccountExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.SchedulerException; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class BankAccountExtractJobControllerTest { private static final String JOB_NAME = "jobName"; @InjectMocks private BankAccountExtractJobController testObj; @Mock private JobService jobService; @Test void runJob_shouldCallJobServiceWithValuesPassedAsParam() throws SchedulerException { TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 45)); final LocalDateTime now = TimeMachine.now(); final Date delta = DateUtil.convertToDate(now, ZoneId.systemDefault()); testObj.runJob(delta, "jobName"); verify(jobService).createAndRunSingleExecutionJob(JOB_NAME, BankAccountExtractJob.class, AbstractDeltaInfoJob.createJobDataMap(delta), null); } }
4,818
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/BankAccountTokenSynchronizationServiceImplTest.java
package com.paypal.sellers.bankaccountextraction.services; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.hyperwallet.clientsdk.model.HyperwalletList; import com.mirakl.client.core.exception.MiraklApiException; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.AssertionsForClassTypes.assertThatThrownBy; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class BankAccountTokenSynchronizationServiceImplTest { private static final String BANK_ACCOUNT_TOKEN_VALUE = "bankToken"; private static final String BANK_ACCOUNT_TOKEN_VALUE_2 = "bankToken2"; private static final String BANK_ACCOUNT_NUMBER = "bankAccountNumber"; private static final String SELLER_TOKEN_VALUE = "sellerToken"; private static final String PROGRAM_TOKEN = "programToken"; @InjectMocks private BankAccountTokenSynchronizationServiceImpl testObj; @Mock private UserHyperwalletSDKService userHyperwalletSDKServiceMock; @Mock private MiraklBankAccountExtractService miraklBankAccountExtractServiceMock; @Mock private HyperwalletMiraklBankAccountMatcher miraklBankAccountMatcherMock; @Mock private Hyperwallet hyperwalletSDKMock; @Test void synchronizeToken_ShouldReturnCurrentSellerModel_WhenSellerBankAccountDetailsAreNull() { final SellerModel originalSellerModel = SellerModel.builder().build(); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result).isEqualTo(originalSellerModel); } @Test void synchronizeToken_ShouldReturnCurrentSellerModel_WhenSellerBankAccountNumberIsBlank() { final SellerModel originalSellerModel = SellerModel.builder().token(SELLER_TOKEN_VALUE) .programToken(PROGRAM_TOKEN) .bankAccountDetails(BankAccountModel.builder().bankAccountNumber("").build()).build(); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result).isEqualTo(originalSellerModel); } @Test void synchronizeToken_ShouldUpdateMiraklToken_WhenBankAccountMatchIsFound_AndMiraklBankAccountTokenIsNull() { final SellerModel originalSellerModel = SellerModel.builder().token(SELLER_TOKEN_VALUE) .programToken(PROGRAM_TOKEN) .bankAccountDetails(BankAccountModel.builder().bankAccountNumber(BANK_ACCOUNT_NUMBER).build()).build(); final HyperwalletBankAccount hyperwalletBankAccount1 = new HyperwalletBankAccount(); hyperwalletBankAccount1.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletBankAccount hyperwalletBankAccount2 = new HyperwalletBankAccount(); hyperwalletBankAccount2.setToken(BANK_ACCOUNT_TOKEN_VALUE_2); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(List.of(hyperwalletBankAccount1, hyperwalletBankAccount2)); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(hyperwalletBankAccountList.getData(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.of(hyperwalletBankAccount2)); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result.getBankAccountDetails().getToken()).isEqualTo(BANK_ACCOUNT_TOKEN_VALUE_2); verify(miraklBankAccountExtractServiceMock, times(1)).updateBankAccountToken(originalSellerModel, hyperwalletBankAccount2); } @Test void synchronizeToken_ShouldUpdateMiraklToken_WhenBankAccountMatchIsFound_AndMiraklBankAccountTokenIsNotNull() { final SellerModel originalSellerModel = SellerModel .builder().token(SELLER_TOKEN_VALUE).programToken(PROGRAM_TOKEN).bankAccountDetails(BankAccountModel .builder().token(BANK_ACCOUNT_TOKEN_VALUE).bankAccountNumber(BANK_ACCOUNT_NUMBER).build()) .build(); final HyperwalletBankAccount hyperwalletBankAccount1 = new HyperwalletBankAccount(); hyperwalletBankAccount1.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletBankAccount hyperwalletBankAccount2 = new HyperwalletBankAccount(); hyperwalletBankAccount2.setToken(BANK_ACCOUNT_TOKEN_VALUE_2); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(List.of(hyperwalletBankAccount1, hyperwalletBankAccount2)); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(hyperwalletBankAccountList.getData(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.of(hyperwalletBankAccount2)); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result.getBankAccountDetails().getToken()).isEqualTo(BANK_ACCOUNT_TOKEN_VALUE_2); verify(miraklBankAccountExtractServiceMock, times(1)).updateBankAccountToken(originalSellerModel, hyperwalletBankAccount2); } @Test void synchronizeToken_ShouldSetMiraklTokenToNull_WhenHyperwalletBankAccountsIsEmpty_AndMiraklBankAccountTokenIsNotNull() { final SellerModel originalSellerModel = SellerModel .builder().token(SELLER_TOKEN_VALUE).programToken(PROGRAM_TOKEN).bankAccountDetails(BankAccountModel .builder().token(BANK_ACCOUNT_TOKEN_VALUE).bankAccountNumber(BANK_ACCOUNT_NUMBER).build()) .build(); final HyperwalletBankAccount hyperwalletBankAccount1 = new HyperwalletBankAccount(); hyperwalletBankAccount1.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletBankAccount hyperwalletBankAccount2 = new HyperwalletBankAccount(); hyperwalletBankAccount2.setToken(BANK_ACCOUNT_TOKEN_VALUE_2); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(null); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(List.of(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.empty()); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result.getBankAccountDetails().getToken()).isNull(); verify(miraklBankAccountExtractServiceMock, times(1)).updateBankAccountToken(eq(originalSellerModel), argThat(arg -> arg.getToken() == null)); } @Test void synchronizeToken_ShouldSetMiraklTokenToNull_WhenBankAccountMatchIsNotFound_AndMiraklBankAccountTokenIsNotNull() { final SellerModel originalSellerModel = SellerModel .builder().token(SELLER_TOKEN_VALUE).programToken(PROGRAM_TOKEN).bankAccountDetails(BankAccountModel .builder().token(BANK_ACCOUNT_TOKEN_VALUE).bankAccountNumber(BANK_ACCOUNT_NUMBER).build()) .build(); final HyperwalletBankAccount hyperwalletBankAccount1 = new HyperwalletBankAccount(); hyperwalletBankAccount1.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletBankAccount hyperwalletBankAccount2 = new HyperwalletBankAccount(); hyperwalletBankAccount2.setToken(BANK_ACCOUNT_TOKEN_VALUE_2); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(List.of(hyperwalletBankAccount1, hyperwalletBankAccount2)); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(hyperwalletBankAccountList.getData(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.empty()); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result.getBankAccountDetails().getToken()).isNull(); verify(miraklBankAccountExtractServiceMock, times(1)).updateBankAccountToken(eq(originalSellerModel), argThat(arg -> arg.getToken() == null)); } @Test void synchronizeToken_ShouldNotUpdateAnything_WhenBankAccountMatchIsNotFound_AndMiraklBankAccountTokenIsNull() { final SellerModel originalSellerModel = SellerModel.builder().token(SELLER_TOKEN_VALUE) .programToken(PROGRAM_TOKEN) .bankAccountDetails(BankAccountModel.builder().bankAccountNumber(BANK_ACCOUNT_NUMBER).build()).build(); final HyperwalletBankAccount hyperwalletBankAccount1 = new HyperwalletBankAccount(); hyperwalletBankAccount1.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletBankAccount hyperwalletBankAccount2 = new HyperwalletBankAccount(); hyperwalletBankAccount2.setToken(BANK_ACCOUNT_TOKEN_VALUE_2); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(List.of(hyperwalletBankAccount1, hyperwalletBankAccount2)); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(hyperwalletBankAccountList.getData(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.empty()); final SellerModel result = testObj.synchronizeToken(originalSellerModel); assertThat(result).isEqualTo(originalSellerModel); assertThat(result.getBankAccountDetails().getToken()).isNull(); verify(miraklBankAccountExtractServiceMock, times(0)).updateBankAccountToken(any(), any()); } @Test void synchronizeToken_ShouldThrowHMCHyperwalletAPIException_WhenHWRequestThrowAHyperwalletException() { final SellerModel originalSellerModel = SellerModel.builder().token(SELLER_TOKEN_VALUE) .programToken(PROGRAM_TOKEN) .bankAccountDetails(BankAccountModel.builder().bankAccountNumber(BANK_ACCOUNT_NUMBER).build()).build(); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)) .thenThrow(new HyperwalletException("Something went wrong")); assertThatThrownBy(() -> testObj.synchronizeToken(originalSellerModel)) .isInstanceOf(HMCHyperwalletAPIException.class) .hasMessageContaining("An error has occurred while invoking Hyperwallet API"); } @Test void synchronizeToken_ShouldThrowHMCMiraklAPIException_WhenMiraklRequestThrowAMiraklApiException() { final SellerModel originalSellerModel = SellerModel.builder().token(SELLER_TOKEN_VALUE) .programToken(PROGRAM_TOKEN) .bankAccountDetails(BankAccountModel.builder().bankAccountNumber(BANK_ACCOUNT_NUMBER).build()).build(); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setToken(BANK_ACCOUNT_TOKEN_VALUE); final HyperwalletList<HyperwalletBankAccount> hyperwalletBankAccountList = new HyperwalletList<>(); hyperwalletBankAccountList.setData(List.of(hyperwalletBankAccount)); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByProgramToken(PROGRAM_TOKEN)) .thenReturn(hyperwalletSDKMock); when(hyperwalletSDKMock.listBankAccounts(SELLER_TOKEN_VALUE)).thenReturn(hyperwalletBankAccountList); when(miraklBankAccountMatcherMock.findExactOrCompatibleMatch(hyperwalletBankAccountList.getData(), originalSellerModel.getBankAccountDetails())).thenReturn(Optional.of(hyperwalletBankAccount)); doThrow(MiraklApiException.class).when(miraklBankAccountExtractServiceMock) .updateBankAccountToken(originalSellerModel, hyperwalletBankAccount); assertThatThrownBy(() -> testObj.synchronizeToken(originalSellerModel)) .isInstanceOf(HMCMiraklAPIException.class) .hasMessageContaining("An error has occurred while invoking Mirakl API"); } }
4,819
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/MiraklBankAccountExtractServiceImplTest.java
package com.paypal.sellers.bankaccountextraction.services; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.mirakl.client.core.error.MiraklErrorResponseBean; import com.mirakl.client.core.exception.MiraklApiException; import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop; import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest; import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue; import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.mirakl.client.MiraklClient; import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.ArgumentMatchers.any; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class MiraklBankAccountExtractServiceImplTest { private static final String TOKEN_VALUE = "tokenValue"; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; private MiraklBankAccountExtractServiceImpl testObj; @Mock private MiraklClient miraklMarketplacePlatformOperatorApiClientMock; @Mock private HyperwalletBankAccount hyperwalletBankAccount; @Mock private SellerModel sellerModelMock; @Mock private MailNotificationUtil mailNotificationUtilMock; @Captor private ArgumentCaptor<MiraklUpdateShopsRequest> miraklUpdateShopsRequestCaptor; @BeforeEach void setUp() { testObj = new MiraklBankAccountExtractServiceImpl(miraklMarketplacePlatformOperatorApiClientMock, mailNotificationUtilMock); } @DisplayName("Should Update Value for Custom Field 'hw-bankaccount-token'") @Test void updateBankAccountToken_shouldUpdateValueForCustomFieldHwBankAccountToken() { when(hyperwalletBankAccount.getToken()).thenReturn(TOKEN_VALUE); when(sellerModelMock.getClientUserId()).thenReturn("12345"); testObj.updateBankAccountToken(sellerModelMock, hyperwalletBankAccount); verify(miraklMarketplacePlatformOperatorApiClientMock).updateShops(miraklUpdateShopsRequestCaptor.capture()); final MiraklUpdateShopsRequest miraklUpdateShopsRequest = miraklUpdateShopsRequestCaptor.getValue(); assertThat(miraklUpdateShopsRequest.getShops()).hasSize(1); final MiraklUpdateShop shopToUpdate = miraklUpdateShopsRequest.getShops().get(0); assertThat(shopToUpdate).hasFieldOrPropertyWithValue("shopId", 12345L); assertThat(shopToUpdate.getAdditionalFieldValues()).hasSize(1); final MiraklRequestAdditionalFieldValue additionalFieldValue = shopToUpdate.getAdditionalFieldValues().get(0); assertThat(additionalFieldValue).isInstanceOf(MiraklSimpleRequestAdditionalFieldValue.class); final MiraklSimpleRequestAdditionalFieldValue castedAdditionalFieldValue = (MiraklSimpleRequestAdditionalFieldValue) additionalFieldValue; assertThat(castedAdditionalFieldValue.getCode()).isEqualTo("hw-bankaccount-token"); assertThat(castedAdditionalFieldValue.getValue()).isEqualTo(TOKEN_VALUE); } @Test void updateBankAccountToken_shouldSendEmailNotification_whenMiraklExceptionIsThrown() { when(hyperwalletBankAccount.getToken()).thenReturn(TOKEN_VALUE); when(sellerModelMock.getClientUserId()).thenReturn("12345"); final MiraklApiException miraklApiException = new MiraklApiException( new MiraklErrorResponseBean(1, "Something went wrong", "correlation-id")); doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock) .updateShops(any(MiraklUpdateShopsRequest.class)); testObj.updateBankAccountToken(sellerModelMock, hyperwalletBankAccount); verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected updating bank token in Mirakl", (ERROR_MESSAGE_PREFIX + "Something went wrong updating bank token of shop [12345]%n%s") .formatted(MiraklLoggingErrorsUtil.stringify(miraklApiException))); } }
4,820
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/HyperwalletMiraklBankAccountEqualityCheckerTest.java
package com.paypal.sellers.bankaccountextraction.services; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.*; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; import java.util.stream.Stream; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; //@formatter:off class HyperwalletMiraklBankAccountEqualityCheckerTest { private final HyperwalletMiraklBankAccountEqualityChecker testObj = new HyperwalletMiraklBankAccountEqualityChecker(); @ParameterizedTest @MethodSource void isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsIBAN(final HyperwalletBankAccount hyperwalletBankAccount, final IBANBankAccountModel miraklBankAccount, final boolean areEquals) { assertThat(testObj.isSameBankAccount(hyperwalletBankAccount, miraklBankAccount)).isEqualTo(areEquals); } @ParameterizedTest @MethodSource void isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsABA(final HyperwalletBankAccount hyperwalletBankAccount, final ABABankAccountModel miraklBankAccount, final boolean areEquals) { assertThat(testObj.isSameBankAccount(hyperwalletBankAccount, miraklBankAccount)).isEqualTo(areEquals); } @ParameterizedTest @MethodSource void isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsCanadian(final HyperwalletBankAccount hyperwalletBankAccount, final CanadianBankAccountModel miraklBankAccount, final boolean areEquals) { assertThat(testObj.isSameBankAccount(hyperwalletBankAccount, miraklBankAccount)).isEqualTo(areEquals); } @ParameterizedTest @MethodSource void isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsUK(final HyperwalletBankAccount hyperwalletBankAccount, final UKBankAccountModel miraklBankAccount, final boolean areEquals) { assertThat(testObj.isSameBankAccount(hyperwalletBankAccount, miraklBankAccount)).isEqualTo(areEquals); } @Test void isSameBankAccount_ShouldThrowException_WhenBankAccountTypeIsNotSupported() { final BankAccountModel miraklBankAccount = new BankAccountModel(BankAccountModel.builder() .transferMethodCurrency("USD") .transferMethodCountry("US") .bankAccountNumber("BAN1")) {}; final HyperwalletBankAccount hyperwalletBankAccount = createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"); assertThatThrownBy(() ->testObj.isSameBankAccount(hyperwalletBankAccount, miraklBankAccount)) .isInstanceOf(IllegalArgumentException.class); } private static Stream<? extends Arguments> isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsIBAN() { return Stream.of( Arguments.of( createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createIBANBankAccountModel("USD", "US", "BI1", "BAN1"), true), Arguments.of( createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createIBANBankAccountModel("EUR", "US", "BI1", "BAN1"), false), Arguments.of(createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createIBANBankAccountModel("USD", "CA", "BI1", "BAN1"), false), Arguments.of(createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createIBANBankAccountModel("USD", "US", "BI2", "BAN1"), false), Arguments.of(createIbanHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createIBANBankAccountModel("USD", "US", "BI1", "BA2"), false)); } private static Stream<? extends Arguments> isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsABA() { return Stream.of( Arguments.of( createABAHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createABABankAccountModel("USD", "US", "BI1", "BAN1"), true), Arguments.of( createABAHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createABABankAccountModel("EUR", "US", "BI1", "BAN1"), false), Arguments.of(createABAHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createABABankAccountModel("USD", "CA", "BI1", "BAN1"), false), Arguments.of(createABAHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createABABankAccountModel("USD", "US", "BI2", "BAN1"), false), Arguments.of(createABAHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createABABankAccountModel("USD", "US", "BI1", "BA2"), false)); } private static Stream<? extends Arguments> isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsCanadian() { return Stream.of( Arguments.of( createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("USD", "US", "BRI1", "BI1", "BAN1"), true), Arguments.of( createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("USD", "US", "BRI2", "BI1", "BAN1"), false), Arguments.of( createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("EUR", "US", "BRI1", "BI1", "BAN1"), false), Arguments.of(createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("USD", "CA", "BRI1", "BI1", "BAN1"), false), Arguments.of(createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("USD", "US", "BRI1", "BI2", "BAN1"), false), Arguments.of(createCanadianHyperwalletBankAccount("USD", "US", "BRI1", "BI1", "BAN1"), createCanadianBankAccountModel("USD", "US", "BRI1", "BI1", "BA2"), false)); } private static Stream<? extends Arguments> isSameBankAccount_shouldDetectSameBankAccount_whenBankAccountTypeIsUK() { return Stream.of( Arguments.of( createUKHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createUKBankAccountModel("USD", "US", "BI1", "BAN1"), true), Arguments.of( createUKHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createUKBankAccountModel("EUR", "US", "BI1", "BAN1"), false), Arguments.of(createUKHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createUKBankAccountModel("USD", "CA", "BI1", "BAN1"), false), Arguments.of(createUKHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createUKBankAccountModel("USD", "US", "BI2", "BAN1"), false), Arguments.of(createUKHyperwalletBankAccount("USD", "US", "BI1", "BAN1"), createUKBankAccountModel("USD", "US", "BI1", "BA2"), false)); } private static HyperwalletBankAccount createIbanHyperwalletBankAccount(final String currency, final String country, final String bankId, final String bankAccountId) { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCurrency(currency); hyperwalletBankAccount.setTransferMethodCountry(country); hyperwalletBankAccount.setBankId(bankId); hyperwalletBankAccount.setBankAccountId("*******" + bankAccountId); return hyperwalletBankAccount; } private static HyperwalletBankAccount createABAHyperwalletBankAccount(final String currency, final String country, final String branchId, final String bankAccountId) { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCurrency(currency); hyperwalletBankAccount.setTransferMethodCountry(country); hyperwalletBankAccount.setBranchId(branchId); hyperwalletBankAccount.setBankAccountPurpose("CHECKING"); hyperwalletBankAccount.setBankAccountId("*******" + bankAccountId); return hyperwalletBankAccount; } private static HyperwalletBankAccount createCanadianHyperwalletBankAccount(final String currency, final String country, final String branchId, final String bankId, final String bankAccountId) { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCurrency(currency); hyperwalletBankAccount.setTransferMethodCountry(country); hyperwalletBankAccount.setBankId(bankId); hyperwalletBankAccount.setBranchId(branchId); hyperwalletBankAccount.setBankAccountId("*******" + bankAccountId); return hyperwalletBankAccount; } private static HyperwalletBankAccount createUKHyperwalletBankAccount(final String currency, final String country, final String bankId, final String bankAccountId) { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCurrency(currency); hyperwalletBankAccount.setTransferMethodCountry(country); hyperwalletBankAccount.setBankId(bankId); hyperwalletBankAccount.setBankAccountId("*******" + bankAccountId); return hyperwalletBankAccount; } private static IBANBankAccountModel createIBANBankAccountModel(final String currency, final String country, final String bankId, final String bankAccountId) { return IBANBankAccountModel.builder() .transferMethodCountry(country) .transferMethodCurrency(currency) .bankBic(bankId) .bankAccountNumber("1234567890" + bankAccountId) .build(); } private static ABABankAccountModel createABABankAccountModel(final String currency, final String country, final String bankId, final String bankAccountId) { return ABABankAccountModel.builder() .transferMethodCountry(country) .transferMethodCurrency(currency) .branchId(bankId) .bankAccountPurpose("CHECKING") .bankAccountNumber("1234567890" + bankAccountId) .build(); } private static CanadianBankAccountModel createCanadianBankAccountModel(final String currency, final String country, final String branchId, final String bankId, final String bankAccountId) { return CanadianBankAccountModel.builder() .transferMethodCountry(country) .transferMethodCurrency(currency) .bankId(bankId) .branchId(branchId) .bankAccountNumber("1234567890" + bankAccountId) .build(); } private static UKBankAccountModel createUKBankAccountModel(final String currency, final String country, final String bankId, final String bankAccountId) { return UKBankAccountModel.builder() .transferMethodCountry(country) .transferMethodCurrency(currency) .bankAccountId(bankId) .bankAccountNumber("1234567890" + bankAccountId) .build(); } }
4,821
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/HyperwalletMiraklBankAccountCompatibilityCheckerTest.java
package com.paypal.sellers.bankaccountextraction.services; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.bankaccountextraction.services.converters.bankaccounttype.HyperwalletBankAccountTypeResolver; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class HyperwalletMiraklBankAccountCompatibilityCheckerTest { @InjectMocks private HyperwalletMiraklBankAccountCompatibilityChecker testObj; @Mock private HyperwalletBankAccountTypeResolver hyperwalletBankAccountTypeResolverMock; @Test void isBankAccountCompatible_shouldReturnTrue_whenSameBankAccountTypeAndSameBankAccountCountry() { final IBANBankAccountModel miraklBankAccount = IBANBankAccountModel.builder().transferMethodCountry("US") .type(BankAccountType.ABA).build(); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCountry("US"); when(hyperwalletBankAccountTypeResolverMock.getBankAccountType(hyperwalletBankAccount)) .thenReturn(BankAccountType.ABA); assertThat(testObj.isBankAccountCompatible(hyperwalletBankAccount, miraklBankAccount)).isTrue(); } @Test void isBankAccountCompatible_shouldReturnFalse_whenDifferentBankAccountTypeAndSameBankAccountCountry() { final IBANBankAccountModel miraklBankAccount = IBANBankAccountModel.builder().transferMethodCountry("US") .type(BankAccountType.IBAN).build(); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCountry("US"); when(hyperwalletBankAccountTypeResolverMock.getBankAccountType(hyperwalletBankAccount)) .thenReturn(BankAccountType.ABA); assertThat(testObj.isBankAccountCompatible(hyperwalletBankAccount, miraklBankAccount)).isFalse(); } @Test void isBankAccountCompatible_shouldReturnFalse_whenSameBankAccountTypeAndDifferentBankAccountCountry() { final IBANBankAccountModel miraklBankAccount = IBANBankAccountModel.builder().transferMethodCountry("ES") .type(BankAccountType.ABA).build(); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCountry("US"); when(hyperwalletBankAccountTypeResolverMock.getBankAccountType(hyperwalletBankAccount)) .thenReturn(BankAccountType.ABA); assertThat(testObj.isBankAccountCompatible(hyperwalletBankAccount, miraklBankAccount)).isFalse(); } }
4,822
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/HyperwalletMiraklBankAccountMatcherTest.java
package com.paypal.sellers.bankaccountextraction.services; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class HyperwalletMiraklBankAccountMatcherTest { @InjectMocks private HyperwalletMiraklBankAccountMatcher testObj; @Mock private HyperwalletMiraklBankAccountCompatibilityChecker hyperwalletMiraklBankAccountCompatibilityCheckerMock; @Mock private HyperwalletMiraklBankAccountEqualityChecker hyperwalletMiraklBankAccountEqualityCheckerMock; @Test void findExactOrCompatibleMatch_shouldReturnBankAccountWithSameToken_whenBankAccountWithSameTokenExists_andIsTheSameBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(1); when(hyperwalletMiraklBankAccountEqualityCheckerMock.isSameBankAccount(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(true); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isPresent().contains(hyperwalletBankAccounts.get(0)); } @Test void findExactOrCompatibleMatch_shouldReturnBankAccountWithSameToken_whenBankAccountWithSameTokenExists_andIsACompatibleBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(2); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(true); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isPresent().contains(hyperwalletBankAccounts.get(1)); } @Test void findExactOrCompatibleMatch_shouldReturnBankAccountWithExactMatch_whenBankAccountWithExactMatchExists() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(); when(hyperwalletMiraklBankAccountEqualityCheckerMock.isSameBankAccount(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountEqualityCheckerMock.isSameBankAccount(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(true); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isPresent().contains(hyperwalletBankAccounts.get(1)); } @Test void findExactOrCompatibleMatch_shouldReturnBankAccountWithOtherToken_whenBankAccountWithSameTokenIsNotCompatible_andIsCompatibleWithOtherBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(1); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(true); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isPresent().contains(hyperwalletBankAccounts.get(1)); } @Test void findExactOrCompatibleMatch_shouldReturnCompatibleBankAccount_whenBankAccountDoesNotHaveToken_andThereIsACompatibleBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(true); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isPresent().contains(hyperwalletBankAccounts.get(1)); } @Test void findExactOrCompatibleMatch_shouldReturnEmptyOptional_whenBankAccountWithSameTokenDoesNotExist_andIsNotACompatibleBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(3); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isEmpty(); } @Test void findExactOrCompatibleMatch_shouldReturnEmptyOptional_whenThereIsNotACompatibleBankAccount_andThereIsNotSameBankAccount() { final List<HyperwalletBankAccount> hyperwalletBankAccounts = List.of(hyperwalletBankAccount(1), hyperwalletBankAccount(2)); final IBANBankAccountModel miraklBankAccount = ibanBankAccountModel(); when(hyperwalletMiraklBankAccountEqualityCheckerMock.isSameBankAccount(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountEqualityCheckerMock.isSameBankAccount(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(0), miraklBankAccount)).thenReturn(false); when(hyperwalletMiraklBankAccountCompatibilityCheckerMock .isBankAccountCompatible(hyperwalletBankAccounts.get(1), miraklBankAccount)).thenReturn(false); final Optional<HyperwalletBankAccount> result = testObj.findExactOrCompatibleMatch(hyperwalletBankAccounts, miraklBankAccount); assertThat(result).isEmpty(); } private HyperwalletBankAccount hyperwalletBankAccount(final int idx) { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setToken("token" + idx); return hyperwalletBankAccount; } private IBANBankAccountModel ibanBankAccountModel(final int idx) { final IBANBankAccountModel ibanBankAccountModel = IBANBankAccountModel.builder().token("token" + idx).build(); return ibanBankAccountModel; } private IBANBankAccountModel ibanBankAccountModel() { final IBANBankAccountModel ibanBankAccountModel = IBANBankAccountModel.builder().build(); return ibanBankAccountModel; } }
4,823
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/strategies/HyperWalletUpdateBankAccountServiceStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class HyperWalletUpdateBankAccountServiceStrategyTest { private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @InjectMocks private HyperWalletUpdateBankAccountServiceStrategy testObj; @Mock private SellerModel sellerModelMock; @Mock private HyperwalletBankAccount hyperwalletBankAccountRequestMock, hyperwalletBankAccountResultMock; @Mock private Hyperwallet hyperwalletMock; @Mock private UserHyperwalletSDKService userHyperwalletSDKServiceMock; @Mock private BankAccountModel bankAccountModelMock; private static final String TOKEN = "token"; @Test void callHyperwalletAPI_shouldCreateBankAccount() { when(hyperwalletMock.updateBankAccount(hyperwalletBankAccountRequestMock)) .thenReturn(hyperwalletBankAccountResultMock); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletMock); final HyperwalletBankAccount result = testObj.callHyperwalletAPI(HYPERWALLET_PROGRAM, hyperwalletBankAccountRequestMock); verify(userHyperwalletSDKServiceMock).getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM); verify(hyperwalletMock).updateBankAccount(hyperwalletBankAccountRequestMock); assertThat(result).isEqualTo(hyperwalletBankAccountResultMock); } @Test void isApplicable_shouldReturnFalseWhenBankAccountReceivedAsParameterHasANullToken() { when(sellerModelMock.getBankAccountDetails()).thenReturn(bankAccountModelMock); when(bankAccountModelMock.getToken()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnTrueWhenBankAccountReceivedAsParameterIsNotEmpty() { when(sellerModelMock.getBankAccountDetails()).thenReturn(bankAccountModelMock); when(bankAccountModelMock.getToken()).thenReturn(TOKEN); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } }
4,824
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/strategies/HyperWalletCreateBankAccountServiceStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.services.MiraklBankAccountExtractService; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class HyperWalletCreateBankAccountServiceStrategyTest { private static final String TOKEN = "token"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @Spy @InjectMocks private HyperWalletCreateBankAccountServiceStrategy testObj; @Mock private SellerModel sellerModelMock; @Mock private HyperwalletBankAccount hyperwalletBankAccountRequestMock, hyperwalletBankAccountResultMock; @Mock private Hyperwallet hyperwalletMock; @Mock private UserHyperwalletSDKService userHyperwalletSDKServiceMock; @Mock private MiraklBankAccountExtractService miraklBankAccountExtractServiceMock; @Mock private BankAccountModel bankAccountModelMock; @Test void execute_shouldCallSuperExecuteAndUpdateBankAccountToken() { doReturn(Optional.of(hyperwalletBankAccountRequestMock)).when(testObj).callSuperExecute(sellerModelMock); final Optional<HyperwalletBankAccount> result = testObj.execute(sellerModelMock); verify(testObj).callSuperExecute(sellerModelMock); verify(miraklBankAccountExtractServiceMock).updateBankAccountToken(sellerModelMock, hyperwalletBankAccountRequestMock); assertThat(result).isPresent().contains(hyperwalletBankAccountRequestMock); } @Test void callHyperwalletAPI_shouldCreateBankAccount() { when(hyperwalletMock.createBankAccount(hyperwalletBankAccountRequestMock)) .thenReturn(hyperwalletBankAccountResultMock); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletMock); final HyperwalletBankAccount result = testObj.callHyperwalletAPI(HYPERWALLET_PROGRAM, hyperwalletBankAccountRequestMock); verify(userHyperwalletSDKServiceMock).getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM); verify(hyperwalletMock).createBankAccount(hyperwalletBankAccountRequestMock); assertThat(result).isEqualTo(hyperwalletBankAccountResultMock); } @Test void isApplicable_shouldReturnTrueWhenBankAccountReceivedAsParameterHasANullToken() { when(sellerModelMock.getBankAccountDetails()).thenReturn(bankAccountModelMock); when(bankAccountModelMock.getToken()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenBankAccountReceivedAsParameterIsNotEmpty() { when(sellerModelMock.getBankAccountDetails()).thenReturn(bankAccountModelMock); when(bankAccountModelMock.getToken()).thenReturn(TOKEN); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } }
4,825
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/strategies/AbstractHyperwalletBankAccountStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.strategies; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.mirakl.client.core.exception.MiraklApiException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.assertj.core.api.AssertionsForClassTypes; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class AbstractHyperwalletBankAccountStrategyTest { private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @Spy @InjectMocks private MyAbstractHyperwalletBankAccountStrategy testObj; @Mock private SellerModel sellerModelMock; @Mock private StrategyExecutor<SellerModel, HyperwalletBankAccount> sellerModelToHyperwalletBankAccountStrategyExecutorMock; @Mock private HyperwalletBankAccount hyperwalletBankAccountMock; @Mock private MailNotificationUtil mailNotificationUtilMock; @Mock private HyperwalletException hyperwalletExceptionMock; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; @Test void execute_shouldCallHyperwalletAPI() { when(sellerModelToHyperwalletBankAccountStrategyExecutorMock.execute(sellerModelMock)) .thenReturn(hyperwalletBankAccountMock); when(sellerModelMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); testObj.execute(sellerModelMock); verify(sellerModelToHyperwalletBankAccountStrategyExecutorMock).execute(sellerModelMock); verify(testObj).callHyperwalletAPI(HYPERWALLET_PROGRAM, hyperwalletBankAccountMock); } @Test void execute_shouldSendEmailNotificationHyperwalletExceptionIsThrown() { final HyperwalletException hyperwalletException = new HyperwalletException("Something went wrong"); when(sellerModelMock.getClientUserId()).thenReturn("2001"); when(sellerModelMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(sellerModelToHyperwalletBankAccountStrategyExecutorMock.execute(sellerModelMock)) .thenReturn(hyperwalletBankAccountMock); doThrow(hyperwalletException).when(testObj).callHyperwalletAPI(HYPERWALLET_PROGRAM, hyperwalletBankAccountMock); AssertionsForClassTypes.assertThatThrownBy(() -> testObj.execute(sellerModelMock)) .isInstanceOf(HMCHyperwalletAPIException.class) .hasMessageContaining("An error has occurred while invoking Hyperwallet API"); verify(mailNotificationUtilMock).sendPlainTextEmail( "Issue detected when creating or updating bank account in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Bank account not created or updated for seller with clientId [%s]%n%s") .formatted("2001", HyperwalletLoggingErrorsUtil.stringify(hyperwalletException))); } @Test void execute_ShouldThrowMiraklApiException_WhenMiraklRequestThrowsAnHMCMiraklAPIException() { when(sellerModelMock.getClientUserId()).thenReturn("2001"); when(sellerModelMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(sellerModelToHyperwalletBankAccountStrategyExecutorMock.execute(sellerModelMock)) .thenReturn(hyperwalletBankAccountMock); doThrow(MiraklApiException.class).when(testObj).callHyperwalletAPI(HYPERWALLET_PROGRAM, hyperwalletBankAccountMock); AssertionsForClassTypes.assertThatThrownBy(() -> testObj.execute(sellerModelMock)) .isInstanceOf(HMCMiraklAPIException.class) .hasMessageContaining("An error has occurred while invoking Mirakl API"); } private static class MyAbstractHyperwalletBankAccountStrategy extends AbstractHyperwalletBankAccountStrategy { public MyAbstractHyperwalletBankAccountStrategy( final StrategyExecutor<SellerModel, HyperwalletBankAccount> sellerModelToHyperwalletBankAccountStrategyExecutor, final UserHyperwalletSDKService userHyperwalletSDKService, final MailNotificationUtil mailNotificationUtil) { super(sellerModelToHyperwalletBankAccountStrategyExecutor, userHyperwalletSDKService, mailNotificationUtil); } @Override protected HyperwalletBankAccount callHyperwalletAPI(final String hyperwalletProgram, final HyperwalletBankAccount hyperwalletBankAccount) { return null; } @Override public boolean isApplicable(final SellerModel source) { return false; } } }
4,826
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/strategies/HyperWalletBankAccountStrategyExecutorSingleTest.java
package com.paypal.sellers.bankaccountextraction.services.strategies; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.services.strategies.HyperWalletBankAccountStrategyExecutor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Optional; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class HyperWalletBankAccountStrategyExecutorSingleTest { @Spy @InjectMocks private HyperWalletBankAccountStrategyExecutor testObj; @Mock private Strategy<SellerModel, Optional<HyperwalletBankAccount>> strategyMock; @Mock private SellerModel sellerModelMock; @Mock private BankAccountModel bankAccountModelMock; @Test void getStrategies_shouldReturnConverterStrategyMock() { testObj = new HyperWalletBankAccountStrategyExecutor(Set.of(strategyMock)); final Set<Strategy<SellerModel, Optional<HyperwalletBankAccount>>> result = testObj.getStrategies(); assertThat(result).containsExactly(strategyMock); } @Test void execute_shouldReturnEmptyWhenEmptyBankDetailsIsReceived() { testObj = new HyperWalletBankAccountStrategyExecutor(Set.of(strategyMock)); when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final Optional<HyperwalletBankAccount> result = testObj.execute(sellerModelMock); assertThat(result).isNotPresent(); } @Test void execute_shouldCallExecuteWhenBankDetailsAreNotEmpty() { when(sellerModelMock.getBankAccountDetails()).thenReturn(bankAccountModelMock); testObj.execute(sellerModelMock); verify(testObj).callSuperExecute(sellerModelMock); } }
4,827
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/MiraklToBankAccountModelExecutorTest.java
package com.paypal.sellers.bankaccountextraction.services.converters; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.bank.MiraklPaymentInformation; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.services.converters.MiraklToBankAccountModelExecutor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class MiraklToBankAccountModelExecutorTest { @Spy @InjectMocks private MiraklToBankAccountModelExecutor testObj; @Mock private Strategy<MiraklShop, BankAccountModel> strategyMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklPaymentInformation miraklPaymentInformationMock; @Test void getStrategies_shouldReturnConverterStrategyMock() { when(testObj.getStrategies()).thenReturn(Set.of(strategyMock)); final Set<Strategy<MiraklShop, BankAccountModel>> result = testObj.getStrategies(); assertThat(result).containsExactly(strategyMock); } @Test void execute_shouldReturnNullWhenNoPaymentDetailsIsDefined() { final BankAccountModel result = testObj.execute(miraklShopMock); assertThat(result).isNull(); } @Test void execute_shouldCallSuperExecuteMethodWhenPaymentDetailsIsDefined() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklPaymentInformationMock); testObj.execute(miraklShopMock); verify(testObj).callSuperExecute(miraklShopMock); } }
4,828
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/AbstractSellerModelToHyperwalletBankAccountConverterTest.java
package com.paypal.sellers.bankaccountextraction.services.converters; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.sellers.bankaccountextraction.services.converters.hyperwallet.AbstractSellerModelToHyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.model.SellerProfileType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class AbstractSellerModelToHyperwalletBankAccountConverterTest { private static final String FIRST_NAME = "John"; private static final String SECOND_NAME = "Doe"; private static final String ADDRESS_LINE_ONE = "Elmo Street"; private static final String ADDRESS_LINE_TWO = "Door 1"; private static final String BUSINESS_NAME = "Super Business"; private static final String CITY = "Wonder Town"; private static final String COUNTRY = "USA"; private static final String CURRENCY = "USD"; private static final String USER_TOKEN = "124657895635121"; private static final String BIC_CODE = "BIC"; private static final String IBAN_ACCOUNT = "IBAN"; private static final String BANK_ACCOUNT_TOKEN = "BANK_ACCOUNT_TOKEN"; @InjectMocks private MySellerModelToHyperwalletBankAccount testObj; @Mock private SellerModel sellerModelMock; @Mock private IBANBankAccountModel IBANBankAccountModelMock; @Test void convert_shouldAddIndividualAttributes_whenIndividualModelIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(IBANBankAccountModelMock); when(IBANBankAccountModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_ONE); when(IBANBankAccountModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_TWO); when(IBANBankAccountModelMock.getBankAccountNumber()).thenReturn(IBAN_ACCOUNT); when(IBANBankAccountModelMock.getTransferMethodCountry()).thenReturn(COUNTRY); when(IBANBankAccountModelMock.getTransferMethodCurrency()).thenReturn(CURRENCY); when(IBANBankAccountModelMock.getTransferType()).thenReturn(TransferType.BANK_ACCOUNT); when(IBANBankAccountModelMock.getCountry()).thenReturn(COUNTRY); when(IBANBankAccountModelMock.getCity()).thenReturn(CITY); when(sellerModelMock.getToken()).thenReturn(USER_TOKEN); when(sellerModelMock.getProfileType()).thenReturn(SellerProfileType.INDIVIDUAL); when(IBANBankAccountModelMock.getFirstName()).thenReturn(FIRST_NAME); when(IBANBankAccountModelMock.getLastName()).thenReturn(SECOND_NAME); when(IBANBankAccountModelMock.getToken()).thenReturn(BANK_ACCOUNT_TOKEN); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_ONE); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_TWO); assertThat(result.getBankAccountId()).isEqualTo(IBAN_ACCOUNT); assertThat(result.getTransferMethodCountry()).isEqualTo(COUNTRY); assertThat(result.getTransferMethodCurrency()).isEqualTo(CURRENCY); assertThat(result.getType()).isEqualTo(HyperwalletBankAccount.Type.BANK_ACCOUNT); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getUserToken()).isEqualTo(USER_TOKEN); assertThat(result.getProfileType()).isEqualTo(HyperwalletUser.ProfileType.INDIVIDUAL); assertThat(result.getFirstName()).isEqualTo(FIRST_NAME); assertThat(result.getLastName()).isEqualTo(SECOND_NAME); assertThat(result.getToken()).isEqualTo(BANK_ACCOUNT_TOKEN); } @Test void convert_shouldAddProfessionalAttributes_whenProfessionalModelIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(IBANBankAccountModelMock); when(IBANBankAccountModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_ONE); when(IBANBankAccountModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_TWO); when(IBANBankAccountModelMock.getBankAccountNumber()).thenReturn(IBAN_ACCOUNT); when(IBANBankAccountModelMock.getTransferMethodCountry()).thenReturn(COUNTRY); when(IBANBankAccountModelMock.getTransferMethodCurrency()).thenReturn(CURRENCY); when(IBANBankAccountModelMock.getTransferType()).thenReturn(TransferType.BANK_ACCOUNT); when(IBANBankAccountModelMock.getCountry()).thenReturn(COUNTRY); when(IBANBankAccountModelMock.getCity()).thenReturn(CITY); when(sellerModelMock.getToken()).thenReturn(USER_TOKEN); when(sellerModelMock.getProfileType()).thenReturn(SellerProfileType.BUSINESS); when(sellerModelMock.getBusinessName()).thenReturn(BUSINESS_NAME); when(IBANBankAccountModelMock.getToken()).thenReturn(BANK_ACCOUNT_TOKEN); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_ONE); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_TWO); assertThat(result.getBankAccountId()).isEqualTo(IBAN_ACCOUNT); assertThat(result.getTransferMethodCountry()).isEqualTo(COUNTRY); assertThat(result.getTransferMethodCurrency()).isEqualTo(CURRENCY); assertThat(result.getType()).isEqualTo(HyperwalletBankAccount.Type.BANK_ACCOUNT); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getUserToken()).isEqualTo(USER_TOKEN); assertThat(result.getProfileType()).isEqualTo(HyperwalletUser.ProfileType.BUSINESS); assertThat(result.getBusinessName()).isEqualTo(BUSINESS_NAME); assertThat(result.getToken()).isEqualTo(BANK_ACCOUNT_TOKEN); } @Test void convert_shouldReturnNull_whenSellerModelHasNoBankAccountAssociated() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result).isNull(); } @Test void execute_shouldReturnNull_whenNullPaymentInformationIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result).isNull(); } private static class MySellerModelToHyperwalletBankAccount extends AbstractSellerModelToHyperwalletBankAccount { @Override public boolean isApplicable(final SellerModel source) { return true; } } }
4,829
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/SellerModelToHyperwalletBankAccountExecutorTest.java
package com.paypal.sellers.bankaccountextraction.services.converters; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.bankaccountextraction.services.converters.SellerModelToHyperwalletBankAccountExecutor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class SellerModelToHyperwalletBankAccountExecutorTest { @InjectMocks private SellerModelToHyperwalletBankAccountExecutor testObj; @Mock private Strategy<SellerModel, HyperwalletBankAccount> strategy1, strategy2; @BeforeEach void setUp() { testObj = new SellerModelToHyperwalletBankAccountExecutor(Set.of(strategy1, strategy2)); } @Test void getStrategies_shouldReturnSetOfAvailableStrategies() { final Set<Strategy<SellerModel, HyperwalletBankAccount>> result = testObj.getStrategies(); assertThat(result).containsExactlyInAnyOrder(strategy1, strategy2); } }
4,830
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/bankaccounttype/HyperwalletBankAccountTypeResolverImplTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.bankaccounttype; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.infrastructure.support.exceptions.HMCException; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyInfo; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyRestrictions; import org.jetbrains.annotations.NotNull; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.catchThrowable; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class HyperwalletBankAccountTypeResolverImplTest { @InjectMocks private HyperwalletBankAccountTypeResolverImpl testObj; @Mock private HyperwalletBankAccountCurrencyRestrictions countryCurrencyConfigurationMock; @Test void getBankAccountType_shouldReturnFirstBankAccountTypeCandidate() { when(countryCurrencyConfigurationMock.getEntriesFor("US", "USD", TransferType.BANK_ACCOUNT)) .thenReturn(List.of(currencyEntry("ABA", "US", "USD", TransferType.BANK_ACCOUNT), currencyEntry("CAD", "US", "USD", TransferType.BANK_ACCOUNT))); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCountry("US"); hyperwalletBankAccount.setTransferMethodCurrency("USD"); hyperwalletBankAccount.setType(HyperwalletBankAccount.Type.BANK_ACCOUNT); final BankAccountType bankAccountType = testObj.getBankAccountType(hyperwalletBankAccount); assertThat(bankAccountType).isEqualTo(BankAccountType.ABA); } @Test void getBankAccountType_shouldThrowException_whenThereAreNotBankAccountTypeCandidates() { when(countryCurrencyConfigurationMock.getEntriesFor("US", "USD", TransferType.BANK_ACCOUNT)) .thenReturn(List.of()); final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); hyperwalletBankAccount.setTransferMethodCountry("US"); hyperwalletBankAccount.setTransferMethodCurrency("USD"); hyperwalletBankAccount.setType(HyperwalletBankAccount.Type.BANK_ACCOUNT); final Throwable throwable = catchThrowable(() -> testObj.getBankAccountType(hyperwalletBankAccount)); assertThat(throwable).isInstanceOf(HMCException.class) .hasMessage("No bank account type found for country US, currency USD and transfer type BANK_ACCOUNT"); } @NotNull private static HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry currencyEntry( final String bankAccountType, final String country, final String currency, final TransferType transferType) { return new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry(bankAccountType, country, List.of(new HyperwalletBankAccountCurrencyInfo(country, currency, transferType))); } }
4,831
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/hyperwallet/SellerModelToHyperWalletABABankAccountConverterTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.ABABankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountPurposeType; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SellerModelToHyperWalletABABankAccountConverterTest { private static final String BRANCH_ID = "branchId"; private static final String NY_STATE = "NY"; private static final String POSTAL_CODE = "NY2000"; @Spy @InjectMocks private SellerModelToHyperWalletABABankAccount testObj; @Mock private SellerModel sellerModelMock; @Mock private ABABankAccountModel abaBankAccountModelMock; @Mock private IBANBankAccountModel ibanBankAccountModelMock; @Test void execute_shouldReturnABAHyperwalletBankAccount() { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); when(sellerModelMock.getBankAccountDetails()).thenReturn(abaBankAccountModelMock); when(abaBankAccountModelMock.getBankAccountPurpose()).thenReturn(BankAccountPurposeType.CHECKING.name()); when(abaBankAccountModelMock.getBranchId()).thenReturn(BRANCH_ID); when(abaBankAccountModelMock.getStateProvince()).thenReturn(NY_STATE); when(abaBankAccountModelMock.getPostalCode()).thenReturn(POSTAL_CODE); doReturn(hyperwalletBankAccount).when(testObj).callSuperConvert(sellerModelMock); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getBranchId()).isEqualTo(BRANCH_ID); assertThat(result.getBankAccountPurpose()).isEqualTo(BankAccountPurposeType.CHECKING.name()); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); assertThat(result.getStateProvince()).isEqualTo(NY_STATE); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsAbaBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(abaBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenBankAccountDetailsIsDifferentFromAbaBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(ibanBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } }
4,832
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/hyperwallet/SellerModelToHyperWalletUKBankAccountTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.ABABankAccountModel; import com.paypal.sellers.bankaccountextraction.model.UKBankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SellerModelToHyperWalletUKBankAccountTest { private static final String SORT_CODE = "sortCode"; @Spy @InjectMocks private SellerModelToHyperWalletUKBankAccount testObj; @Mock private SellerModel sellerModelMock; @Mock private UKBankAccountModel ukBankAccountModelMock; @Mock private ABABankAccountModel abaBankAccountModelMock; @Test void convert_shouldReturnUKHyperwalletBankAccount() { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); when(sellerModelMock.getBankAccountDetails()).thenReturn(ukBankAccountModelMock); when(ukBankAccountModelMock.getBankAccountId()).thenReturn(SORT_CODE); doReturn(hyperwalletBankAccount).when(testObj).callSuperConvert(sellerModelMock); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getBankId()).isEqualTo(SORT_CODE); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsUKBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(ukBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsDifferentFromUKBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(abaBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } }
4,833
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/hyperwallet/SellerModelToHyperWalletCanadianBankAccountTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.CanadianBankAccountModel; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SellerModelToHyperWalletCanadianBankAccountTest { private static final String BRANCH_ID = "branchId"; private static final String BANK_ID = "bankId"; @Spy @InjectMocks private SellerModelToHyperWalletCanadianBankAccount testObj; @Mock private SellerModel sellerModelMock; @Mock private CanadianBankAccountModel canadianBankAccountModelMock; @Mock private IBANBankAccountModel ibanBankAccountModelMock; @Test void execute_shouldReturnCanadianHyperwalletBankAccount() { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); when(sellerModelMock.getBankAccountDetails()).thenReturn(canadianBankAccountModelMock); when(canadianBankAccountModelMock.getBankId()).thenReturn(BANK_ID); when(canadianBankAccountModelMock.getBranchId()).thenReturn(BRANCH_ID); doReturn(hyperwalletBankAccount).when(testObj).callSuperConvert(sellerModelMock); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getBranchId()).isEqualTo(BRANCH_ID); assertThat(result.getBankId()).isEqualTo(BANK_ID); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsCanadianBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(canadianBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenBankAccountDetailsIsDifferentFromCanadianBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(ibanBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } }
4,834
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/hyperwallet/SellerModelToHyperWalletIBANBankAccountConverterTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.hyperwallet; import com.hyperwallet.clientsdk.model.HyperwalletBankAccount; import com.paypal.sellers.bankaccountextraction.model.ABABankAccountModel; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.doReturn; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class SellerModelToHyperWalletIBANBankAccountConverterTest { private static final String BANK_BIC = "BankBIC"; @Spy @InjectMocks private SellerModelToHyperWalletIBANBankAccount testObj; @Mock private SellerModel sellerModelMock; @Mock private IBANBankAccountModel ibanBankAccountModelMock; @Mock private ABABankAccountModel abaBankAccountModelMock; @Test void convert_shouldReturnIBANHyperwalletBankAccount() { final HyperwalletBankAccount hyperwalletBankAccount = new HyperwalletBankAccount(); when(sellerModelMock.getBankAccountDetails()).thenReturn(ibanBankAccountModelMock); when(ibanBankAccountModelMock.getBankBic()).thenReturn(BANK_BIC); doReturn(hyperwalletBankAccount).when(testObj).callSuperConvert(sellerModelMock); final HyperwalletBankAccount result = testObj.execute(sellerModelMock); assertThat(result.getBankId()).isEqualTo(BANK_BIC); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsIbanBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(ibanBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnTrueWhenBankAccountDetailsIsDifferentFromIbanBankAccountType() { when(sellerModelMock.getBankAccountDetails()).thenReturn(abaBankAccountModelMock); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(sellerModelMock.getBankAccountDetails()).thenReturn(null); final boolean result = testObj.isApplicable(sellerModelMock); assertThat(result).isFalse(); } }
4,835
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/currency/HyperwalletBankAccountCurrencyPriorityResolverTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.currency; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import java.util.Map; import java.util.stream.Collectors; import java.util.stream.IntStream; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; //@formatter:off @ExtendWith(MockitoExtension.class) class HyperwalletBankAccountCurrencyPriorityResolverTest { @InjectMocks private HyperwalletBankAccountCurrencyPriorityResolver testObj; @Mock private HyperwalletBankAccountCurrencyResolutionConfiguration hyperwalletBankAccountCurrencyResolutionConfigurationMock; @Test void sortCurrenciesByPriority_shouldReturnEmptyList_whenCurrencyCandidatesIsNull() { //given final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = null; //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertThat(result).isEmpty(); } @Test void sortCurrenciesByPriority_shouldReturnEmptyList_whenCurrencyCandidatesIsEmpty() { //given final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = List.of(); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertThat(result).isEmpty(); } @Test void sortCurrenciesByPriority_shouldReturnOriginalPriorities_whenPrioritizeFlagsAreDisabled() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(false); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currencies( "GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT ); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currencies("GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT)); assertThat(result).hasSize(3); } @Test void sortCurrenciesByPriority_shouldPrioritizeBankAccountTransferType_whenPrioritizeTransferTypeOverCurrencyFlagIsEnabled() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currencies( "GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT ); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currencies("EUR", TransferType.BANK_ACCOUNT, "GBP", TransferType.WIRE_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT)); assertThat(result).hasSize(3); } @Test void sortCurrenciesByPriority_shouldPrioritizeBankAccountTransferTypeOnlyForSameCurrency_whenPrioritizeTransferTypeOverCurrencyFlagIsDisabled() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(false); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currencies( "GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currencies("GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "EUR", TransferType.WIRE_ACCOUNT, "USD", TransferType.WIRE_ACCOUNT)); } @Test void sortCurrenciesByPriority_prioritizeTransferTypeShouldNotChangeRelativeCurrencyOrder() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currencies( "GBP", TransferType.WIRE_ACCOUNT, "GBP", TransferType.BANK_ACCOUNT, "EUR", TransferType.WIRE_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.BANK_ACCOUNT); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currencies( "GBP", TransferType.BANK_ACCOUNT, "EUR", TransferType.BANK_ACCOUNT, "USD", TransferType.BANK_ACCOUNT, "GBP", TransferType.WIRE_ACCOUNT, "EUR", TransferType.WIRE_ACCOUNT)); } @Test void sortCurrenciesByPriority_shouldFollowGlobalCurrencyPriority_whenOverrideCurrencyPriorityIsEnabledAndNoPerCountryPrioritiesExist() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.getGlobalCurrencyPriority()).thenReturn(List.of("EUR", "GBP", "USD")); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currenciesWithCountry( "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "ES", "EUR", TransferType.BANK_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currenciesWithCountry( "ES", "EUR", TransferType.BANK_ACCOUNT, "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT)); } @Test void sortCurrenciesByPriority_shouldFollowPerCountryCurrencyPriority_whenOverrideCurrencyPriorityIsEnabledAndPerCountryPrioritiesExist() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(false); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.getGlobalCurrencyPriority()).thenReturn(List.of("EUR", "GBP", "USD")); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.getPerCountryCurrencyPriority()).thenReturn(Map.of("UK", List.of("USD", "GBP"))); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currenciesWithCountry( "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "ES", "EUR", TransferType.BANK_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currenciesWithCountry( "ES", "EUR", TransferType.BANK_ACCOUNT, "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT)); } @Test void sortCurrenciesByPriority_shouldFollowPerCountryCurrencyPriority_whenOverrideCurrencyPriorityIsEnabledAndPerCountryPrioritiesExist2() { //given when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isOverrideCurrencySelectionPriority()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isPrioritizeBankAccountTypeOverCurrency()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.getGlobalCurrencyPriority()).thenReturn(List.of("EUR", "GBP", "USD")); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.getPerCountryCurrencyPriority()).thenReturn(Map.of("UK", List.of("USD", "GBP"))); final List<HyperwalletBankAccountCurrencyInfo> currencyCandidates = currenciesWithCountry( "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "ES", "EUR", TransferType.WIRE_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT); //when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.sortCurrenciesByPriority(currencyCandidates); //then assertSortedList(result, currenciesWithCountry( "ES", "USD", TransferType.BANK_ACCOUNT, "ES", "CAD", TransferType.BANK_ACCOUNT, "ES", "EUR", TransferType.WIRE_ACCOUNT, "UK", "USD", TransferType.BANK_ACCOUNT, "UK", "GBP", TransferType.BANK_ACCOUNT)); } private static List<HyperwalletBankAccountCurrencyInfo> currencies(final Object... args) { // Create a list of HyperwalletBankAccountCurrencyInfo with a fixed "COUNTRY" country by // iterating over the args array so we take an item as the currency and the next consecutive item // as the transfer type. return IntStream.range(0, args.length) .filter(i -> i % 2 == 0) .mapToObj(i -> new HyperwalletBankAccountCurrencyInfo("COUNTRY", (String) args[i], (TransferType) args[i + 1])) .collect(Collectors.toList()); } private static List<HyperwalletBankAccountCurrencyInfo> currenciesWithCountry(final Object... args) { return IntStream.range(0, args.length) .filter(i -> i % 3 == 0) .mapToObj(i -> new HyperwalletBankAccountCurrencyInfo((String) args[i], (String) args[i + 1], (TransferType) args[i + 2])) .collect(Collectors.toList()); } private void assertSortedList(final List<HyperwalletBankAccountCurrencyInfo> result, final List<HyperwalletBankAccountCurrencyInfo> expected) { assertThat(result).hasSize(expected.size()); for (int i = 0; i < result.size(); i++) { assertThat(result.get(i).getCountry()).isEqualTo(expected.get(i).getCountry()); assertThat(result.get(i).getCurrency()).isEqualTo(expected.get(i).getCurrency()); assertThat(result.get(i).getTransferType()).isEqualTo(expected.get(i).getTransferType()); } } }
4,836
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/currency/HyperwalletBankAccountCurrencyResolverImplTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.currency; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; //@formatter:off @ExtendWith(MockitoExtension.class) class HyperwalletBankAccountCurrencyResolverImplTest { @InjectMocks private HyperwalletBankAccountCurrencyResolverImpl testObj; @Mock private HyperwalletBankAccountCurrencyRestrictions hyperwalletBankAccountCurrencyRestrictionsMock; @Mock private HyperwalletBankAccountCurrencyResolutionConfiguration hyperwalletBankAccountCurrencyResolutionConfigurationMock; @Mock private HyperwalletBankAccountCurrencyPriorityResolver hyperwalletBankAccountCurrencyPriorityResolverMock; @Test void getCurrencyForCountry_shouldReturnShopCurrency_whenAutomaticCurrencySelectionIsDisabled() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(false); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "EUR"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("EUR"); assertThat(result.getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnShopCurrency_whenIsSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.BANK_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "EUR", TransferType.BANK_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(hyperwalletBankAccountCurrencyInfos)) .thenReturn(hyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "EUR"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("EUR"); assertThat(result.getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnFirstSupportedHyperwalletCurrency_whenShopCurrencyIsNotSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.BANK_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "EUR", TransferType.BANK_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(hyperwalletBankAccountCurrencyInfos)) .thenReturn(hyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "GBP"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("USD"); assertThat(result.getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnFirstSupportedHyperwalletCurrencyIgnoringWireAccounts_whenShopCurrencyIsNotSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isAllowWireAccounts()).thenReturn(false); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.WIRE_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "CAD", TransferType.BANK_ACCOUNT) ); final List<HyperwalletBankAccountCurrencyInfo> supportedHyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "CAD", TransferType.BANK_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(supportedHyperwalletBankAccountCurrencyInfos)) .thenReturn(supportedHyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "GBP"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("CAD"); assertThat(result.getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnFirstSupportedHyperwalletIncludingWireAccounts_whenShopCurrencyIsNotSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isAllowWireAccounts()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.WIRE_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "CAD", TransferType.WIRE_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(hyperwalletBankAccountCurrencyInfos)) .thenReturn(hyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "GBP"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("USD"); assertThat(result.getTransferType()).isEqualTo(TransferType.WIRE_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnShopCurrencyWithWireAccount_whenIsSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isAllowWireAccounts()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.BANK_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "EUR", TransferType.WIRE_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(hyperwalletBankAccountCurrencyInfos)) .thenReturn(hyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "EUR"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("EUR"); assertThat(result.getTransferType()).isEqualTo(TransferType.WIRE_ACCOUNT); } @Test void getCurrencyForCountry_shouldReturnPrioritizedCurrency_whenShopCurrencyIsNotSupportedInHyperwallet() { when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isEnableAutomaticCurrencySelection()).thenReturn(true); when(hyperwalletBankAccountCurrencyResolutionConfigurationMock.isAllowWireAccounts()).thenReturn(true); final List<HyperwalletBankAccountCurrencyInfo> hyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.WIRE_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "CAD", TransferType.WIRE_ACCOUNT) ); final List<HyperwalletBankAccountCurrencyInfo> prioritizedHyperwalletBankAccountCurrencyInfos = List.of( new HyperwalletBankAccountCurrencyInfo("ES", "CAD", TransferType.WIRE_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("ES", "USD", TransferType.WIRE_ACCOUNT) ); when(hyperwalletBankAccountCurrencyRestrictionsMock.getCurrenciesFor("IBAN", "ES")) .thenReturn(hyperwalletBankAccountCurrencyInfos); when(hyperwalletBankAccountCurrencyPriorityResolverMock.sortCurrenciesByPriority(hyperwalletBankAccountCurrencyInfos)) .thenReturn(prioritizedHyperwalletBankAccountCurrencyInfos); final HyperwalletBankAccountCurrencyInfo result = testObj.getCurrencyForCountry("IBAN", "ES", "GBP"); assertThat(result.getCountry()).isEqualTo("ES"); assertThat(result.getCurrency()).isEqualTo("CAD"); assertThat(result.getTransferType()).isEqualTo(TransferType.WIRE_ACCOUNT); } }
4,837
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/currency/HyperwalletBankAccountCurrencyRestrictionsLoaderTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.currency; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class HyperwalletBankAccountCurrencyRestrictionsLoaderTest { private static final String PROPERTY_PREFIX = "payment.hyperwallet.country-currencies."; private static final String ENV_PREFIX = "PAYMENT_HYPERWALLET_COUNTRY-CURRENCIES_"; private final HyperwalletBankAccountCurrencyRestrictionsLoader testObj = new HyperwalletBankAccountCurrencyRestrictionsLoader(); @Test void countryCurrencyConfiguration_shouldReturnCountryCurrencyConfiguration() { // When final HyperwalletBankAccountCurrencyRestrictions result = testObj.countryCurrencyConfiguration(); // Then // We simply check the expected size and some well known entries assertThat(result.numEntries()).isEqualTo(223); assertThat(result.getCurrenciesFor("ABA", "US")).size().isEqualTo(2); assertThat(result.getCurrenciesFor("ABA", "US").get(0).getCurrency()).isEqualTo("USD"); assertThat(result.getCurrenciesFor("ABA", "US").get(1).getCurrency()).isEqualTo("USD"); assertThat(result.getCurrenciesFor("UK", "GB")).size().isEqualTo(1); assertThat(result.getCurrenciesFor("UK", "GB").get(0).getCurrency()).isEqualTo("GBP"); assertThat(result.getCurrenciesFor("UK", "GB").get(0).getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); assertThat(result.getCurrenciesFor("IBAN", "GB")).size().isEqualTo(2); assertThat(result.getCurrenciesFor("IBAN", "GB").get(0).getCurrency()).isEqualTo("EUR"); assertThat(result.getCurrenciesFor("IBAN", "GB").get(0).getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); assertThat(result.getCurrenciesFor("IBAN", "GB").get(1).getCurrency()).isEqualTo("USD"); assertThat(result.getCurrenciesFor("IBAN", "GB").get(1).getTransferType()).isEqualTo(TransferType.WIRE_ACCOUNT); } }
4,838
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/currency/HyperwalletBankAccountCurrencyResolutionConfigurationTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.currency; import org.junit.jupiter.api.Test; import java.util.List; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; class HyperwalletBankAccountCurrencyResolutionConfigurationTest { private HyperwalletBankAccountCurrencyResolutionConfiguration testObj; @Test void constructor_shouldSetGlobalCurrencyPriority_whenNoPerCountryEntryExists() { // Given testObj = new HyperwalletBankAccountCurrencyResolutionConfiguration("USD, EUR"); // When final List<String> result = testObj.getGlobalCurrencyPriority(); final Map<String, List<String>> perCountryResult = testObj.getPerCountryCurrencyPriority(); // Then assertThat(result).containsExactly("USD", "EUR"); assertThat(perCountryResult).isEmpty(); } @Test void constructor_shouldSetGlobalCurrencyPriority_whenOnlyOneCurrencyIsDefined() { // Given testObj = new HyperwalletBankAccountCurrencyResolutionConfiguration("USD"); // When final List<String> result = testObj.getGlobalCurrencyPriority(); // Then assertThat(result).containsExactly("USD"); } @Test void constructor_shouldSetPerCountryCurrencyPriority_whenPerCountryEntryExists() { // Given testObj = new HyperwalletBankAccountCurrencyResolutionConfiguration("US:USD;CA:CAD,USD"); // When final Map<String, List<String>> perCountryResult = testObj.getPerCountryCurrencyPriority(); final List<String> globalResult = testObj.getGlobalCurrencyPriority(); // Then assertThat(perCountryResult.get("US")).containsExactly("USD"); assertThat(perCountryResult.get("CA")).containsExactly("CAD", "USD"); assertThat(globalResult).isEmpty(); } @Test void constructor_shouldSupportMultipleGlobalAndPerCountryConfigurations() { // Given testObj = new HyperwalletBankAccountCurrencyResolutionConfiguration("GB,CAD;US:USD;CA:CAD,USD"); // When final Map<String, List<String>> perCountryResult = testObj.getPerCountryCurrencyPriority(); final List<String> globalResult = testObj.getGlobalCurrencyPriority(); // Then assertThat(perCountryResult.get("US")).containsExactly("USD"); assertThat(perCountryResult.get("CA")).containsExactly("CAD", "USD"); assertThat(globalResult).containsExactly("GB", "CAD"); } }
4,839
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/currency/HyperwalletBankAccountCurrencyRestrictionsTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.currency; import com.paypal.sellers.bankaccountextraction.model.TransferType; import org.junit.jupiter.api.Test; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; class HyperwalletBankAccountCurrencyRestrictionsTest { private HyperwalletBankAccountCurrencyRestrictions testObj; @Test void getCurrenciesFor_shouldReturnEmptyList_whenNoEntryFound() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List.of(); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.getCurrenciesFor("bankAccountType", "country"); // then assertThat(result).isEmpty(); } @Test void getCurrenciesFor_shouldReturnEmptyList_whenEntryFoundButNoCurrency() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List .of(new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country", List.of())); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.getCurrenciesFor("bankAccountType", "country"); // then assertThat(result).isEmpty(); } @Test void getCurrenciesFor_shouldReturnSingleEntry_whenEntryFound() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List.of( new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country", List.of(new HyperwalletBankAccountCurrencyInfo("country", "currency", TransferType.BANK_ACCOUNT))), new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country2", List.of(new HyperwalletBankAccountCurrencyInfo("country2", "currency", TransferType.BANK_ACCOUNT)))); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.getCurrenciesFor("bankAccountType", "country"); // then assertThat(result).hasSize(1); assertThat(result.get(0).getCurrency()).isEqualTo("currency"); assertThat(result.get(0).getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getCurrenciesFor_shouldReturnMultipleEntries_whenEntryFound() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List.of( new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country", List .of(new HyperwalletBankAccountCurrencyInfo("country", "currency", TransferType.BANK_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("country", "currency2", TransferType.BANK_ACCOUNT))), new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country2", List.of(new HyperwalletBankAccountCurrencyInfo("country2", "currency", TransferType.BANK_ACCOUNT)))); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyInfo> result = testObj.getCurrenciesFor("bankAccountType", "country"); // then assertThat(result).hasSize(2); assertThat(result.get(0).getCurrency()).isEqualTo("currency"); assertThat(result.get(0).getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); assertThat(result.get(1).getCurrency()).isEqualTo("currency2"); assertThat(result.get(1).getTransferType()).isEqualTo(TransferType.BANK_ACCOUNT); } @Test void getEntriesFor_shouldReturnEmptyList_whenNoEntryFound() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List.of(); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> result = testObj .getEntriesFor("bankAccuntCountry", "currency", TransferType.BANK_ACCOUNT); // then assertThat(result).isEmpty(); } @Test void getEntriesFor_shouldReturnEntries_whenEntryFound() { // given final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> countryCurrencyEntries = List.of( new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country", List .of(new HyperwalletBankAccountCurrencyInfo("country", "currency", TransferType.BANK_ACCOUNT), new HyperwalletBankAccountCurrencyInfo("country", "currency2", TransferType.BANK_ACCOUNT))), new HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry("bankAccountType", "country2", List.of(new HyperwalletBankAccountCurrencyInfo("country2", "currency", TransferType.BANK_ACCOUNT)))); testObj = new HyperwalletBankAccountCurrencyRestrictions(countryCurrencyEntries); // when final List<HyperwalletBankAccountCurrencyRestrictions.CountryCurrencyEntry> result = testObj .getEntriesFor("country", "currency", TransferType.BANK_ACCOUNT); // then assertThat(result).hasSize(1); assertThat(result.get(0).getBankAccountType()).isEqualTo("bankAccountType"); assertThat(result.get(0).getCountry()).isEqualTo("country"); assertThat(result.get(0).getSupportedCurrencies()).hasSize(2); assertThat(result.get(0).getSupportedCurrencies().get(0).getCountry()).isEqualTo("country"); assertThat(result.get(0).getSupportedCurrencies().get(0).getCurrency()).isEqualTo("currency"); assertThat(result.get(0).getSupportedCurrencies().get(0).getTransferType()) .isEqualTo(TransferType.BANK_ACCOUNT); assertThat(result.get(0).getSupportedCurrencies().get(1).getCountry()).isEqualTo("country"); assertThat(result.get(0).getSupportedCurrencies().get(1).getCurrency()).isEqualTo("currency2"); assertThat(result.get(0).getSupportedCurrencies().get(1).getTransferType()) .isEqualTo(TransferType.BANK_ACCOUNT); } }
4,840
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/mirakl/MiraklShopToABABankAccountModelConverterStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.mirakl; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.currency.MiraklIsoCurrencyCode; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklProfessionalInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.bank.MiraklAbaBankAccountInformation; import com.mirakl.client.mmp.domain.shop.bank.MiraklIbanBankAccountInformation; import com.paypal.sellers.bankaccountextraction.model.ABABankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyInfo; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyResolver; import com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_STATE; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class MiraklShopToABABankAccountModelConverterStrategyTest { private static final String FIRST_NAME = "firstName"; private static final String LAST_NAME = "lastName"; private static final String STREET_1 = "street1"; private static final String STREET_2 = "street2"; private static final String CITY_NAME = "city"; private static final String ABA_ACCOUNT = "ABA"; private static final String BUSINESS_NAME = "business_name"; private static final String CONTACT_COUNTRY = "FRA"; private static final String FR_COUNTRY_ISO = "FR"; private static final String USA_COUNTRY_ISO = "US"; private static final String USD_CURRENCY = "USD"; private static final String TOKEN = "bankAccountToken"; private static final String STATE = "NEW YORK"; private static final String BANK_ZIP = "NY 10036 US"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @InjectMocks private MiraklShopToABABankAccountModelConverterStrategy testObj; @Mock private HyperwalletBankAccountCurrencyResolver hyperwalletBankAccountCurrencyResolverMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklContactInformation contactInformationMock; @Mock private MiraklAbaBankAccountInformation miraklABABankAccountInformationMock; @Mock private MiraklProfessionalInformation miraklProfessionalInformationMock; @Mock private MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock; @Mock private MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue miraklHyperwalletProgramFieldValueMock; @Mock private MiraklIbanBankAccountInformation miraklIBANBankAccountInformationMock; @Test void execute_ShouldTransformFromMiraklShopToABAAccountModel() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklABABankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.USD); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(STREET_2); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklABABankAccountInformationMock.getBankZip()).thenReturn(BANK_ZIP); when(miraklABABankAccountInformationMock.getBankAccountNumber()).thenReturn(ABA_ACCOUNT); when(miraklABABankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( USA_COUNTRY_ISO, USD_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.ABA.name(), USA_COUNTRY_ISO, USD_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final ABABankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", USA_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", USD_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.ABA) .hasFieldOrPropertyWithValue("bankAccountNumber", ABA_ACCOUNT) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", STREET_2) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("postalCode", BANK_ZIP) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void execute_shouldEnsureThatOptionalFieldLineAddress2IsFilledWithAnEmptyString() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklABABankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.USD); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(null); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklABABankAccountInformationMock.getBankZip()).thenReturn(BANK_ZIP); when(miraklABABankAccountInformationMock.getBankAccountNumber()).thenReturn(ABA_ACCOUNT); when(miraklABABankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( USA_COUNTRY_ISO, USD_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.ABA.name(), USA_COUNTRY_ISO, USD_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final ABABankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", USA_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", USD_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.ABA) .hasFieldOrPropertyWithValue("bankAccountNumber", ABA_ACCOUNT) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", StringUtils.EMPTY) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("postalCode", BANK_ZIP) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void isApplicable_shouldReturnTrue_whenPaymentInformationIsABA() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklABABankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalse_whenPaymentInformationIsNotABA() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIBANBankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(miraklShopMock.getPaymentInformation()).thenReturn(null); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } }
4,841
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/mirakl/MiraklShopToCanadianBankAccountModelConverterStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.mirakl; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.currency.MiraklIsoCurrencyCode; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklProfessionalInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.bank.MiraklCanadianBankAccountInformation; import com.mirakl.client.mmp.domain.shop.bank.MiraklIbanBankAccountInformation; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyInfo; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyResolver; import com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_STATE; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class MiraklShopToCanadianBankAccountModelConverterStrategyTest { private static final String FIRST_NAME = "firstName"; private static final String LAST_NAME = "lastName"; private static final String STREET_1 = "street1"; private static final String STREET_2 = "street2"; private static final String CONTACT_COUNTRY = "FRA"; private static final String FR_COUNTRY_ISO = "FR"; private static final String BUSINESS_NAME = "business_name"; private static final String CA_COUNTRY_ISO = "CA"; private static final String USD_CURRENCY = "USD"; private static final String TOKEN = "bankAccountToken"; private static final String STATE = "NEW YORK"; private static final String INSTITUTION_NUMBER = "INSTITUTION_NUMBER"; private static final String TRANSIT_NUMBER = "TRANSIT_NUMBER"; private static final String CITY_NAME = "city"; private static final String BANK_ACCOUNT_NUMBER = "123456789"; private final static String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @InjectMocks private MiraklShopToCanadianBankAccountModelConverterStrategy testObj; @Mock private HyperwalletBankAccountCurrencyResolver hyperwalletBankAccountCurrencyResolverMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklContactInformation contactInformationMock; @Mock private MiraklCanadianBankAccountInformation miraklCanadianBankAccountInformationMock; @Mock private MiraklProfessionalInformation miraklProfessionalInformationMock; @Mock private MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock; @Mock private MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue miraklHyperwalletProgramFieldValueMock; @Mock private MiraklIbanBankAccountInformation miraklIBANBankAccountInformationMock; @Test void execute_ShouldTransformFromMiraklShopToCanadianAccountModel() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklCanadianBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.USD); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()) .thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(STREET_2); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklCanadianBankAccountInformationMock.getInstitutionNumber()).thenReturn(INSTITUTION_NUMBER); when(miraklCanadianBankAccountInformationMock.getTransitNumber()).thenReturn(TRANSIT_NUMBER); when(miraklCanadianBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklCanadianBankAccountInformationMock.getBankAccountNumber()).thenReturn(BANK_ACCOUNT_NUMBER); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( CA_COUNTRY_ISO, USD_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.CANADIAN.name(), CA_COUNTRY_ISO, USD_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final BankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", CA_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", USD_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.CANADIAN) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", STREET_2) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("branchId", TRANSIT_NUMBER) .hasFieldOrPropertyWithValue("bankId", INSTITUTION_NUMBER) .hasFieldOrPropertyWithValue("bankAccountNumber", BANK_ACCOUNT_NUMBER) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void execute_shouldEnsureThatOptionalFieldLineAddress2IsFilledWithAnEmptyString() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklCanadianBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.USD); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()) .thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(null); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklCanadianBankAccountInformationMock.getInstitutionNumber()).thenReturn(INSTITUTION_NUMBER); when(miraklCanadianBankAccountInformationMock.getTransitNumber()).thenReturn(TRANSIT_NUMBER); when(miraklCanadianBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklCanadianBankAccountInformationMock.getBankAccountNumber()).thenReturn(BANK_ACCOUNT_NUMBER); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( CA_COUNTRY_ISO, USD_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.CANADIAN.name(), CA_COUNTRY_ISO, USD_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final BankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", CA_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", USD_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.CANADIAN) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", StringUtils.EMPTY) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("branchId", TRANSIT_NUMBER) .hasFieldOrPropertyWithValue("bankId", INSTITUTION_NUMBER) .hasFieldOrPropertyWithValue("bankAccountNumber", BANK_ACCOUNT_NUMBER) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void isApplicable_shouldReturnTrue_whenPaymentInformationIsCanadian() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklCanadianBankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalse_whenPaymentInformationIsNotCanadian() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIBANBankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(miraklShopMock.getPaymentInformation()).thenReturn(null); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } }
4,842
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/mirakl/MiraklShopToIBANBankAccountModelConverterStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.mirakl; import java.util.List; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyInfo; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyResolver; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.currency.MiraklIsoCurrencyCode; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklProfessionalInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.bank.MiraklAbaBankAccountInformation; import com.mirakl.client.mmp.domain.shop.bank.MiraklIbanBankAccountInformation; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.IBANBankAccountModel; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_STATE; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class MiraklShopToIBANBankAccountModelConverterStrategyTest { private static final String FIRST_NAME = "firstName"; private static final String LAST_NAME = "lastName"; private static final String STREET_1 = "street1"; private static final String STREET_2 = "street2"; private static final String CITY_NAME = "city"; private static final String SPAIN_COUNTRY = "ESP"; private static final String BIC_CODE = "BIC"; private static final String ES_IBAN_ACCOUNT = "ESIBAN"; private static final String UK_IBAN_ACCOUNT = "GBIBAN"; private static final String BUSINESS_NAME = "business_name"; private static final String ES_COUNTRY_ISO = "ES"; private static final String UK_COUNTRY_ISO = "GB"; private static final String EUR_CURRENCY = "EUR"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; private static final String TOKEN = "bankAccountToken"; private static final String STATE = "bankAccountState"; @InjectMocks private MiraklShopToIBANBankAccountModelConverterStrategy testObj; @Mock private HyperwalletBankAccountCurrencyResolver hyperwalletBankAccountCurrencyResolverMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklContactInformation contactInformationMock; @Mock private MiraklIbanBankAccountInformation miraklIbanBankAccountInformationMock; @Mock private MiraklProfessionalInformation miraklProfessionalInformationMock; @Mock private MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock; @Mock private MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue miraklHyperwalletProgramFieldValueMock; @Mock private MiraklAbaBankAccountInformation miraklABABankAccountInformationMock; @Test void convert_ShouldTransformFromMiraklShopToIbanBankAccountModel() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIbanBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.EUR); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(STREET_2); when(contactInformationMock.getCountry()).thenReturn(SPAIN_COUNTRY); when(miraklIbanBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklIbanBankAccountInformationMock.getBic()).thenReturn(BIC_CODE); when(miraklIbanBankAccountInformationMock.getIban()).thenReturn(ES_IBAN_ACCOUNT); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( ES_COUNTRY_ISO, EUR_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.IBAN.name(), ES_COUNTRY_ISO, EUR_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.IBAN.name(), ES_COUNTRY_ISO, EUR_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final IBANBankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", ES_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", EUR_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.IBAN) .hasFieldOrPropertyWithValue("bankBic", BIC_CODE) .hasFieldOrPropertyWithValue("bankAccountNumber", ES_IBAN_ACCOUNT) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", ES_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", STREET_2) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void convert_ShouldTransformFromMiraklShopToUKIbanBankAccountModel() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIbanBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.GBP); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(STREET_2); when(contactInformationMock.getCountry()).thenReturn(SPAIN_COUNTRY); when(miraklIbanBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklIbanBankAccountInformationMock.getIban()).thenReturn(UK_IBAN_ACCOUNT); when(miraklIbanBankAccountInformationMock.getBic()).thenReturn(BIC_CODE); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( UK_COUNTRY_ISO, MiraklIsoCurrencyCode.GBP.name(), TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.IBAN.name(), UK_COUNTRY_ISO, MiraklIsoCurrencyCode.GBP.name())).thenReturn(hyperwalletBankAccountCurrencyInfo); final IBANBankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", UK_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.IBAN) .hasFieldOrPropertyWithValue("bankBic", BIC_CODE) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", ES_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", STREET_2) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void convert_shouldEnsureThatOptionalFieldLineAddress2IsFilledWithAnEmptyString() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIbanBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.EUR); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()) .thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(null); when(contactInformationMock.getCountry()).thenReturn(SPAIN_COUNTRY); when(miraklIbanBankAccountInformationMock.getBic()).thenReturn(BIC_CODE); when(miraklIbanBankAccountInformationMock.getIban()).thenReturn(ES_IBAN_ACCOUNT); when(miraklIbanBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( ES_COUNTRY_ISO, EUR_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.IBAN.name(), ES_COUNTRY_ISO, EUR_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final IBANBankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", ES_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", EUR_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.IBAN) .hasFieldOrPropertyWithValue("bankBic", BIC_CODE) .hasFieldOrPropertyWithValue("bankAccountNumber", ES_IBAN_ACCOUNT) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", ES_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", StringUtils.EMPTY) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void convert_shouldThrowErrorWhenCountryNotExists() { final MiraklIbanBankAccountInformation ibanAccount = defaultMiraklIbanBankAccount(); ibanAccount.setIban("100"); when(miraklShopMock.getPaymentInformation()).thenReturn(ibanAccount); when(miraklShopMock.getContactInformation()).thenReturn(defaultMiraklContanctInformation()); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.GBP); Assertions.assertThrows(IllegalStateException.class, () -> testObj.execute(miraklShopMock), "Country with isocode: [10] not valid"); } @Test void convert_shouldThrowErrorWhenIBANIsNotFilledProperly() { final String id_mock = "id_mock"; final MiraklIbanBankAccountInformation ibanAccount = defaultMiraklIbanBankAccount(); ibanAccount.setIban("x"); when(miraklShopMock.getPaymentInformation()).thenReturn(ibanAccount); when(miraklShopMock.getId()).thenReturn(id_mock); when(miraklShopMock.getContactInformation()).thenReturn(defaultMiraklContanctInformation()); Assertions.assertThrows(IllegalStateException.class, () -> testObj.execute(miraklShopMock), "IBAN invalid on shop: id_mock"); } private MiraklContactInformation defaultMiraklContanctInformation() { final MiraklContactInformation contactInformation = new MiraklContactInformation(); contactInformation.setFirstname(FIRST_NAME); contactInformation.setLastname(LAST_NAME); contactInformation.setStreet1(STREET_1); contactInformation.setStreet2(null); contactInformation.setCountry(SPAIN_COUNTRY); return contactInformation; } private MiraklIbanBankAccountInformation defaultMiraklIbanBankAccount() { final MiraklIbanBankAccountInformation ibanAccountInfo = new MiraklIbanBankAccountInformation(); ibanAccountInfo.setIban(ES_IBAN_ACCOUNT); ibanAccountInfo.setBic(BIC_CODE); ibanAccountInfo.setBankCity(CITY_NAME); return ibanAccountInfo; } private MiraklProfessionalInformation defaultProfessionalInformation() { final MiraklProfessionalInformation professionalInformation = new MiraklProfessionalInformation(); professionalInformation.setCorporateName(BUSINESS_NAME); return professionalInformation; } @Test void isApplicable_shouldReturnTrue_whenPaymentInformationIsIBAN() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklIbanBankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalse_whenPaymentInformationIsNotIBAN() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklABABankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(miraklShopMock.getPaymentInformation()).thenReturn(null); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } }
4,843
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/bankaccountextraction/services/converters/mirakl/MiraklShopToUKBankAccountModelConverterStrategyTest.java
package com.paypal.sellers.bankaccountextraction.services.converters.mirakl; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.currency.MiraklIsoCurrencyCode; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklProfessionalInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.bank.MiraklAbaBankAccountInformation; import com.mirakl.client.mmp.domain.shop.bank.MiraklUkBankAccountInformation; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.bankaccountextraction.model.BankAccountType; import com.paypal.sellers.bankaccountextraction.model.TransferType; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyInfo; import com.paypal.sellers.bankaccountextraction.services.converters.currency.HyperwalletBankAccountCurrencyResolver; import com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_STATE; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_BANK_ACCOUNT_TOKEN; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class MiraklShopToUKBankAccountModelConverterStrategyTest { private static final String FIRST_NAME = "firstName"; private static final String LAST_NAME = "lastName"; private static final String STREET_1 = "street1"; private static final String STREET_2 = "street2"; private static final String CITY_NAME = "city"; private static final String CONTACT_COUNTRY = "FRA"; private static final String FR_COUNTRY_ISO = "FR"; private static final String BUSINESS_NAME = "business_name"; private static final String UK_COUNTRY_ISO = "GB"; private static final String GBP_CURRENCY = "GBP"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; private static final String TOKEN = "bankAccountToken"; private static final String STATE = "bankAccountState"; private static final String BANK_ACCOUNT_NUMBER = "bankAccountNumber"; private static final String SORT_CODE = "sortCode"; @InjectMocks private MiraklShopToUKBankAccountModelConverterStrategy testObj; @Mock private HyperwalletBankAccountCurrencyResolver hyperwalletBankAccountCurrencyResolverMock; @Mock private MiraklShop miraklShopMock; @Mock private MiraklContactInformation contactInformationMock; @Mock private MiraklUkBankAccountInformation miraklUKBankAccountInformationMock; @Mock private MiraklProfessionalInformation miraklProfessionalInformationMock; @Mock private MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock; @Mock private MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue miraklHyperwalletProgramFieldValueMock; @Mock private MiraklAbaBankAccountInformation miraklABABankAccountInformationMock; @Test void convert_ShouldTransformFromMiraklShopToUkBankAccountModel() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklUKBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.GBP); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklBankAccountStateFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklBankAccountStateFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_STATE); when(miraklBankAccountStateFieldValueMock.getValue()).thenReturn(STATE); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(STREET_2); when(miraklUKBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklUKBankAccountInformationMock.getBankAccountNumber()).thenReturn(BANK_ACCOUNT_NUMBER); when(miraklUKBankAccountInformationMock.getBankSortCode()).thenReturn(SORT_CODE); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( UK_COUNTRY_ISO, GBP_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.UK.name(), UK_COUNTRY_ISO, GBP_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final BankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", UK_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", GBP_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.UK) .hasFieldOrPropertyWithValue("bankAccountId", SORT_CODE) .hasFieldOrPropertyWithValue("bankAccountNumber", BANK_ACCOUNT_NUMBER) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", STREET_2) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("stateProvince", STATE) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void convert_shouldEnsureThatOptionalFieldLineAddress2IsFilledWithAnEmptyString() { when(miraklShopMock.getContactInformation()).thenReturn(contactInformationMock); when(miraklShopMock.getPaymentInformation()).thenReturn(miraklUKBankAccountInformationMock); when(miraklShopMock.getCurrencyIsoCode()).thenReturn(MiraklIsoCurrencyCode.GBP); when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklShopMock.getAdditionalFieldValues()) .thenReturn(List.of(miraklBankAccountTokenFieldValueMock, miraklHyperwalletProgramFieldValueMock)); when(miraklBankAccountTokenFieldValueMock.getCode()).thenReturn(HYPERWALLET_BANK_ACCOUNT_TOKEN); when(miraklBankAccountTokenFieldValueMock.getValue()).thenReturn(TOKEN); when(miraklHyperwalletProgramFieldValueMock.getCode()).thenReturn(SellerModelConstants.HYPERWALLET_PROGRAM); when(miraklHyperwalletProgramFieldValueMock.getValue()).thenReturn(HYPERWALLET_PROGRAM); when(contactInformationMock.getFirstname()).thenReturn(FIRST_NAME); when(contactInformationMock.getLastname()).thenReturn(LAST_NAME); when(contactInformationMock.getStreet1()).thenReturn(STREET_1); when(contactInformationMock.getStreet2()).thenReturn(null); when(contactInformationMock.getCountry()).thenReturn(CONTACT_COUNTRY); when(miraklUKBankAccountInformationMock.getBankSortCode()).thenReturn(SORT_CODE); when(miraklUKBankAccountInformationMock.getBankAccountNumber()).thenReturn(BANK_ACCOUNT_NUMBER); when(miraklUKBankAccountInformationMock.getBankCity()).thenReturn(CITY_NAME); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(BUSINESS_NAME); final HyperwalletBankAccountCurrencyInfo hyperwalletBankAccountCurrencyInfo = new HyperwalletBankAccountCurrencyInfo( UK_COUNTRY_ISO, GBP_CURRENCY, TransferType.BANK_ACCOUNT); when(hyperwalletBankAccountCurrencyResolverMock.getCurrencyForCountry(BankAccountType.UK.name(), UK_COUNTRY_ISO, GBP_CURRENCY)).thenReturn(hyperwalletBankAccountCurrencyInfo); final BankAccountModel result = testObj.execute(miraklShopMock); //@formatter:off assertThat(result).hasFieldOrPropertyWithValue("transferMethodCountry", UK_COUNTRY_ISO) .hasFieldOrPropertyWithValue("transferMethodCurrency", GBP_CURRENCY) .hasFieldOrPropertyWithValue("transferType", TransferType.BANK_ACCOUNT) .hasFieldOrPropertyWithValue("type", BankAccountType.UK) .hasFieldOrPropertyWithValue("bankAccountId", SORT_CODE) .hasFieldOrPropertyWithValue("bankAccountNumber", BANK_ACCOUNT_NUMBER) .hasFieldOrPropertyWithValue("businessName", BUSINESS_NAME) .hasFieldOrPropertyWithValue("firstName", FIRST_NAME) .hasFieldOrPropertyWithValue("lastName", LAST_NAME) .hasFieldOrPropertyWithValue("country", FR_COUNTRY_ISO) .hasFieldOrPropertyWithValue("addressLine1", STREET_1) .hasFieldOrPropertyWithValue("addressLine2", StringUtils.EMPTY) .hasFieldOrPropertyWithValue("city", CITY_NAME) .hasFieldOrPropertyWithValue("token", TOKEN) .hasFieldOrPropertyWithValue("hyperwalletProgram", HYPERWALLET_PROGRAM); //@formatter:on } @Test void isApplicable_shouldReturnTrue_whenPaymentInformationIsUK() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklUKBankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalse_whenPaymentInformationIsNotIBAN() { when(miraklShopMock.getPaymentInformation()).thenReturn(miraklABABankAccountInformationMock); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnFalse_whenNullPaymentInformationIsReceived() { when(miraklShopMock.getPaymentInformation()).thenReturn(null); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } }
4,844
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/BusinessStakeholdersExtractionJobsConfigTest.java
package com.paypal.sellers.stakeholdersextraction; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBean; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersRetryBatchJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerKey; import org.quartz.impl.triggers.CronTriggerImpl; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersExtractionJobsConfigTest { private static final String RETRY_CRON_EXPRESSION = "0 0/15 * ? * * *"; private static final String TRIGGER_PREFIX = "Trigger"; private static final String RETRY_JOB_NAME = "BusinessStakeholdersRetryJob"; @InjectMocks private BusinessStakeholdersExtractionJobsConfig testObj; @Mock private BusinessStakeholdersRetryBatchJob businessStakeholdersRetryBatchJob; @Test void businessStakeholdersRetryJob_createsJobDetailWithNameBusinessStakeholderRetryJobAndBusinessStakeholdersRetryBatchJob() { final JobDetail result = testObj.businessStakeholdersRetryJob(businessStakeholdersRetryBatchJob); assertThat(result.getJobClass()).hasSameClassAs(QuartzBatchJobBean.class); assertThat(result.getKey().getName()).isEqualTo(RETRY_JOB_NAME); assertThat(result.getJobDataMap()).containsEntry("batchJob", businessStakeholdersRetryBatchJob); } @Test void businessStakeholdersRetryJob_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = testObj.businessStakeholdersRetryJob(businessStakeholdersRetryBatchJob); final Trigger result = testObj.businessStakeholdersRetryTrigger(jobDetail, RETRY_CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(result.getKey()).isEqualTo(TriggerKey.triggerKey(TRIGGER_PREFIX + RETRY_JOB_NAME)); assertThat(result).isInstanceOf(CronTriggerImpl.class); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(RETRY_CRON_EXPRESSION); } }
4,845
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholderExtractJobItemTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholderExtractJobItem; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class BusinessStakeholderExtractJobItemTest { private static final String CLIENT_USER_ID = "clientUserId"; private static final int STK_ID = 100; private static final String BUSINESS_STAKEHOLDER = "BusinessStakeholder"; @Test void getItemId_ShouldReturnClientUserIdAndStkId() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).stkId(STK_ID).build(); final BusinessStakeholderExtractJobItem testObj = new BusinessStakeholderExtractJobItem( businessStakeHolderModel); assertThat(testObj.getItemId()).isEqualTo(CLIENT_USER_ID + "-" + STK_ID); } @Test void getItemType_ShouldReturnBusinessStakeholder() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).stkId(STK_ID).build(); final BusinessStakeholderExtractJobItem testObj = new BusinessStakeholderExtractJobItem( businessStakeHolderModel); assertThat(testObj.getItemType()).isEqualTo(BUSINESS_STAKEHOLDER); } }
4,846
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholdersExtractBatchJobItemProcessorTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.infrastructure.support.services.TokenSynchronizationService; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.stakeholdersextraction.services.strategies.HyperWalletBusinessStakeHolderStrategyExecutor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersExtractBatchJobItemProcessorTest { private static final String CLIENT_USER_ID = "clientUserId"; @InjectMocks private BusinessStakeholdersExtractBatchJobItemProcessor testObj; @Mock private HyperWalletBusinessStakeHolderStrategyExecutor hyperWalletBusinessStakeHolderStrategyExecutorMock; @Mock private TokenSynchronizationService<BusinessStakeHolderModel> businessStakeholderTokenSynchronizationServiceImplMock; @Mock private BatchJobContext batchJobContextMock; @Test void processItem_ShouldSynchronizedBusinessStakeHolderTokenAndExecuteIt() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).build(); final BusinessStakeholderExtractJobItem businessStakeholderExtractJobItem = new BusinessStakeholderExtractJobItem( businessStakeHolderModel); final BusinessStakeHolderModel synchronizedBusinessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).build(); when(businessStakeholderTokenSynchronizationServiceImplMock.synchronizeToken(businessStakeHolderModel)) .thenReturn(synchronizedBusinessStakeHolderModel); testObj.processItem(batchJobContextMock, businessStakeholderExtractJobItem); verify(hyperWalletBusinessStakeHolderStrategyExecutorMock).execute(synchronizedBusinessStakeHolderModel); } }
4,847
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholdersRetryBatchJobTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJobItemProcessor; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersRetryBatchJob; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersRetryBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.InjectMocks; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersRetryBatchJobTest { @InjectMocks private BusinessStakeholdersRetryBatchJob testObj; @Mock private BusinessStakeholdersExtractBatchJobItemProcessor businessStakeholdersExtractBatchJobItemProcessorMock; @Mock private BusinessStakeholdersRetryBatchJobItemsExtractor businessStakeholdersRetryBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_shouldReturnBatchJobItemProcessor() { assertThat(testObj.getBatchJobItemProcessor()).isEqualTo(businessStakeholdersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_shouldReturnRetryBatchJobItemExtractor() { assertThat(testObj.getBatchJobItemsExtractor()).isEqualTo(businessStakeholdersRetryBatchJobItemsExtractorMock); } }
4,848
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholdersRetryBatchJobItemsExtractorTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholderExtractJobItem; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersRetryBatchJobItemsExtractor; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.stakeholdersextraction.services.BusinessStakeholderExtractService; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersRetryBatchJobItemsExtractorTest { public static final String PROFESSIONAL_SELLER_1 = "1"; public static final String PROFESSIONAL_SELLER_2 = "2"; @InjectMocks private BusinessStakeholdersRetryBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private BusinessStakeholderExtractService businessStakeholderExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Mock private BusinessStakeHolderModel businessStakeHolderModelMock1, businessStakeHolderModelMock2; @Test void getItemType_shouldReturnBusinessStakeholderType() { final String result = testObj.getItemType(); assertThat(result).isEqualTo(BusinessStakeholderExtractJobItem.ITEM_TYPE); } @Test void getItems_ShouldReturnBusinessStakeholderExtractJobItems() { when(miraklSellersExtractServiceMock .extractProfessionals(List.of(PROFESSIONAL_SELLER_1, PROFESSIONAL_SELLER_2))) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); when(businessStakeholderExtractServiceMock .extractBusinessStakeHolders(List.of(sellerModelMock1, sellerModelMock2))) .thenReturn(List.of(businessStakeHolderModelMock1, businessStakeHolderModelMock2)); final Collection<BusinessStakeholderExtractJobItem> result = testObj .getItems(List.of(PROFESSIONAL_SELLER_1, PROFESSIONAL_SELLER_2)); assertThat(result.stream().map(BusinessStakeholderExtractJobItem::getItem).collect(Collectors.toList())) .containsExactlyInAnyOrder(businessStakeHolderModelMock1, businessStakeHolderModelMock2); } }
4,849
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholdersExtractBatchJobItemsExtractorTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholderExtractJobItem; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJobItemsExtractor; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.stakeholdersextraction.services.BusinessStakeholderExtractService; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersExtractBatchJobItemsExtractorTest { private static final Date DELTA = new Date(); @InjectMocks private BusinessStakeholdersExtractBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private BusinessStakeholderExtractService businessStakeholderExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Mock private BusinessStakeHolderModel businessStakeHolderModelMock1, businessStakeHolderModelMock2; @Mock private BatchJobContext batchJobContextMock; @Test void getItems_ShouldReturnBusinessStakeholderExtractJobItems() { when(miraklSellersExtractServiceMock.extractProfessionals(DELTA)) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); when(businessStakeholderExtractServiceMock .extractBusinessStakeHolders(List.of(sellerModelMock1, sellerModelMock2))) .thenReturn(List.of(businessStakeHolderModelMock1, businessStakeHolderModelMock2)); final Collection<BusinessStakeholderExtractJobItem> result = testObj.getItems(batchJobContextMock, DELTA); assertThat(result.stream().map(BusinessStakeholderExtractJobItem::getItem).collect(Collectors.toList())) .containsExactlyInAnyOrder(businessStakeHolderModelMock1, businessStakeHolderModelMock2); } }
4,850
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/batchjobs/BusinessStakeholdersExtractBatchJobTest.java
package com.paypal.sellers.stakeholdersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholderExtractJobItem; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJob; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJobItemProcessor; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BusinessStakeholdersExtractBatchJobTest { @InjectMocks private BusinessStakeholdersExtractBatchJob testObj; @Mock private BusinessStakeholdersExtractBatchJobItemProcessor professionalSellersExtractBatchJobItemProcessorMock; @Mock private BusinessStakeholdersExtractBatchJobItemsExtractor professionalSellersExtractBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_ShouldReturnBusinessStakeholdersExtractBatchJobItemProcessor() { final BatchJobItemProcessor<BatchJobContext, BusinessStakeholderExtractJobItem> result = testObj .getBatchJobItemProcessor(); assertThat(result).isEqualTo(professionalSellersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_ShouldReturnBusinessStakeholdersExtractBatchJobItemsExtractor() { final BatchJobItemsExtractor<BatchJobContext, BusinessStakeholderExtractJobItem> result = testObj .getBatchJobItemsExtractor(); assertThat(result).isEqualTo(professionalSellersExtractBatchJobItemsExtractorMock); } }
4,851
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/model/BusinessStakeHolderModelTest.java
package com.paypal.sellers.stakeholdersextraction.model; import com.callibrity.logging.test.LogTracker; import com.callibrity.logging.test.LogTrackerStub; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue.MiraklDateAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue; import com.paypal.sellers.sellerextractioncommons.model.SellerGender; import com.paypal.sellers.sellerextractioncommons.model.SellerGovernmentIdType; import com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_USER_TOKEN; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BusinessStakeHolderModelTest { private static final String USER_TOKEN = "userToken"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; private static final String UTC = "UTC"; @RegisterExtension final LogTrackerStub logTrackerStub = LogTrackerStub.create().recordForLevel(LogTracker.LogLevel.WARN) .recordForType(BusinessStakeHolderModel.class); private static final Integer BUSINESS_STAKE_HOLDER_NUMBER = 1; private static final Integer INVALID_BUSINESS_STAKE_HOLDER_NUMBER = 0; private static final String DATE_OF_BIRTH = "1970-10-10T10:00:00Z"; private static final String TOKEN = "hw-stakeholder-token-1"; private static final String BUSINESS = "hw-stakeholder-business-contact-1"; private static final String DIRECTOR = "hw-stakeholder-director-1"; private static final String UBO = "hw-stakeholder-ubo-1"; private static final String SMO = "hw-stakeholder-smo-1"; private static final String FIRST_NAME = "hw-stakeholder-first-name-1"; private static final String MIDDLE_NAME = "hw-stakeholder-middle-name-1"; private static final String LAST_NAME = "hw-stakeholder-last-name-1"; private static final String DOB = "hw-stakeholder-dob-1"; private static final String COUNTRY_OF_BIRTH = "hw-stakeholder-country-of-birth-1"; private static final String NATIONALITY = "hw-stakeholder-nationality-1"; private static final String GENDER = "hw-stakeholder-gender-1"; private static final String PHONE_NUMBER = "hw-stakeholder-phone-number-1"; private static final String MOBILE_NUMBER = "hw-stakeholder-mobile-number-1"; private static final String EMAIL = "hw-stakeholder-email-1"; private static final String ADDRESS_LINE_1 = "hw-stakeholder-address-line1-1"; private static final String ADDRESS_LINE_2 = "hw-stakeholder-address-line2-1"; private static final String CITY = "hw-stakeholder-city-1"; private static final String STATE = "hw-stakeholder-state-1"; private static final String POST_CODE = "hw-stakeholder-post-code-1"; private static final String COUNTRY = "hw-stakeholder-country-1"; private static final String GOVERNMENT_ID_TYPE = "hw-stakeholder-government-id-type-1"; private static final String GOVERNMENT_ID_NUM = "hw-stakeholder-government-id-num-1"; private static final String DRIVERS_LICENSE_NUM = "hw-stakeholder-drivers-license-num-1"; private static final String US = "US"; private static final int STK_ID = 1; @Test void token_whenMiraklTokenBusinessStakeHolderFieldValueHasAValue_shouldSetToken() { final MiraklStringAdditionalFieldValue tokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); tokenBusinessStakeHolderField.setCode(TOKEN); tokenBusinessStakeHolderField.setValue("token"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .token(List.of(tokenBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getToken()).isEqualTo("token"); } @Test void token_whenMiraklTokenBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetToken() { final MiraklStringAdditionalFieldValue tokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); tokenBusinessStakeHolderField.setCode(TOKEN); tokenBusinessStakeHolderField.setValue("token"); //@formatter:off BusinessStakeHolderModel.builder() .token(List.of(tokenBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void businessContact_whenMiraklBusinessContactBusinessStakeHolderFieldValueHasAValue_shouldSetBusinessContact() { final MiraklBooleanAdditionalFieldValue businessContactBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); businessContactBusinessStakeHolderField.setCode(BUSINESS); businessContactBusinessStakeHolderField.setValue("true"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .businessContact(List.of(businessContactBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getBusinessContact()).isTrue(); } @Test void businessContact_whenMiraklBusinessContactBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetBusinessContact() { final MiraklBooleanAdditionalFieldValue businessContactBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); businessContactBusinessStakeHolderField.setCode(BUSINESS); businessContactBusinessStakeHolderField.setValue("true"); //@formatter:off BusinessStakeHolderModel.builder() .businessContact(List.of(businessContactBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void director_whenMiraklDirectorBusinessStakeHolderFieldValueHasAValue_shouldSetDirector() { final MiraklBooleanAdditionalFieldValue directorBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); directorBusinessStakeHolderField.setCode(DIRECTOR); directorBusinessStakeHolderField.setValue("true"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .director(List.of(directorBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getDirector()).isTrue(); } @Test void director_whenMiraklDirectorBusinessStakeHolderFieldValueHasAValueHasAValueButHolderNumberIsNotValid_shouldNotSetDirector() { final MiraklBooleanAdditionalFieldValue directorBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); directorBusinessStakeHolderField.setCode(DIRECTOR); directorBusinessStakeHolderField.setValue("true"); //@formatter:off BusinessStakeHolderModel.builder() .director(List.of(directorBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void ubo_whenMiraklUboBusinessStakeHolderFieldValueHasAValue_shouldSetUbo() { final MiraklBooleanAdditionalFieldValue uboBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); uboBusinessStakeHolderField.setCode(UBO); uboBusinessStakeHolderField.setValue("true"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .ubo(List.of(uboBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getUbo()).isTrue(); } @Test void ubo_whenMiraklUboBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetUbo() { final MiraklBooleanAdditionalFieldValue uboBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); uboBusinessStakeHolderField.setCode(UBO); uboBusinessStakeHolderField.setValue("true"); //@formatter:off BusinessStakeHolderModel.builder() .ubo(List.of(uboBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void smo_whenMiraklSmoBusinessStakeHolderFieldValueHasAValue_shouldSetSmo() { final MiraklBooleanAdditionalFieldValue smoBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); smoBusinessStakeHolderField.setCode(SMO); smoBusinessStakeHolderField.setValue("true"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .smo(List.of(smoBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getSmo()).isTrue(); } @Test void smo_whenMiraklSmoBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetSmo() { final MiraklBooleanAdditionalFieldValue smoBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); smoBusinessStakeHolderField.setCode(SMO); smoBusinessStakeHolderField.setValue("true"); //@formatter:off BusinessStakeHolderModel.builder() .smo(List.of(smoBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void firstName_whenMiraklFirstNameBusinessStakeHolderFieldValueHasAValue_shouldSetFirstName() { final MiraklStringAdditionalFieldValue firstNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); firstNameBusinessStakeHolderField.setCode(FIRST_NAME); firstNameBusinessStakeHolderField.setValue("firstName"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .firstName(List.of(firstNameBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getFirstName()).isEqualTo("firstName"); } @Test void firstName_whenMiraklFirstNameBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetFirstName() { final MiraklStringAdditionalFieldValue firstNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); firstNameBusinessStakeHolderField.setCode(FIRST_NAME); firstNameBusinessStakeHolderField.setValue("firstName"); //@formatter:off BusinessStakeHolderModel.builder() .firstName(List.of(firstNameBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void middleName_whenMiraklMiddleNameBusinessStakeHolderFieldValueHasAValue_shouldSetMiddleName() { final MiraklStringAdditionalFieldValue middleNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); middleNameBusinessStakeHolderField.setCode(MIDDLE_NAME); middleNameBusinessStakeHolderField.setValue("middleName"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .middleName(List.of(middleNameBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getMiddleName()).isEqualTo("middleName"); } @Test void middleName_whenMiraklMiddleNameBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetMiddleName() { final MiraklStringAdditionalFieldValue middleNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); middleNameBusinessStakeHolderField.setCode(MIDDLE_NAME); middleNameBusinessStakeHolderField.setValue("middleName"); //@formatter:off BusinessStakeHolderModel.builder() .middleName(List.of(middleNameBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void lastName_whenMiraklLastNameBusinessStakeHolderFieldValueHasAValue_shouldSetLastName() { final MiraklStringAdditionalFieldValue lastNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); lastNameBusinessStakeHolderField.setCode(LAST_NAME); lastNameBusinessStakeHolderField.setValue("lastName"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .lastName(List.of(lastNameBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getLastName()).isEqualTo("lastName"); } @Test void lastName_whenMiraklLastNameBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetLastName() { final MiraklStringAdditionalFieldValue lastNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); lastNameBusinessStakeHolderField.setCode(LAST_NAME); lastNameBusinessStakeHolderField.setValue("lastName"); //@formatter:off BusinessStakeHolderModel.builder() .lastName(List.of(lastNameBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void dateOfBirth_whenMiraklDateOfBirthBusinessStakeHolderFieldValueHasAValue_shouldSetDateOfBirth() { final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue(DATE_OF_BIRTH); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .timeZone(UTC) .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getDateOfBirth()).hasYear(1970).hasMonth(10).hasDayOfMonth(10); } @Test void dateOfBirth_whenMiraklDateOfBirthBusinessStakeHolderFieldValueHasAValueAndTimeZoneIsUTCPlusTwo_shouldSetDateOfBirthNextDay() { final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue("1970-10-10T23:00:00Z"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .timeZone("UTC+2") .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getDateOfBirth()).hasYear(1970).hasMonth(10).hasDayOfMonth(11); } @Test void dateOfBirth_whenMiraklDateOfBirthBusinessStakeHolderFieldValueHasAValueAndTimeZoneIsUTCMinusThree_shouldSetDateOfBirthSameDay() { final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue("1970-10-10T23:00:00Z"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .timeZone("UTC-3") .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getDateOfBirth()).hasYear(1970).hasMonth(10).hasDayOfMonth(10); } @Test void dateOfBirth_whenMiraklDateOfBirthBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetDateOfBirth() { final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue(DATE_OF_BIRTH); //@formatter:off BusinessStakeHolderModel.builder() .timeZone(UTC) .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void countryOfBirth_whenMiraklCountryOfBirthBusinessStakeHolderFieldValueHasAValue_shouldSetCountryOfBirth() { final MiraklStringAdditionalFieldValue countryOfBirthBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfBirthBusinessStakeHolderField.setCode(COUNTRY_OF_BIRTH); countryOfBirthBusinessStakeHolderField.setValue(US); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .countryOfBirth(List.of(countryOfBirthBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getCountryOfBirth()).isEqualTo("US"); } @Test void countryOfBirth_whenMiraklCountryOfBirthBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetCountryOfBirth() { final MiraklStringAdditionalFieldValue countryOfBirthBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfBirthBusinessStakeHolderField.setCode(COUNTRY_OF_BIRTH); countryOfBirthBusinessStakeHolderField.setValue(US); //@formatter:off BusinessStakeHolderModel.builder() .countryOfBirth(List.of(countryOfBirthBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void countryOfNationality_whenMiraklCountryOfNationalityBusinessStakeHolderFieldValueHasAValue_shouldSetCountryOfNationality() { final MiraklStringAdditionalFieldValue countryOfNationalityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfNationalityBusinessStakeHolderField.setCode(NATIONALITY); countryOfNationalityBusinessStakeHolderField.setValue(US); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .countryOfNationality(List.of(countryOfNationalityBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getCountryOfNationality()).isEqualTo("US"); } @Test void countryOfNationality_whenMiraklCountryOfNationalityBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetCountryOfNationality() { final MiraklStringAdditionalFieldValue countryOfNationalityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfNationalityBusinessStakeHolderField.setCode(NATIONALITY); countryOfNationalityBusinessStakeHolderField.setValue(US); //@formatter:off BusinessStakeHolderModel.builder() .countryOfNationality(List.of(countryOfNationalityBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void gender_whenMiraklGenderBusinessStakeHolderFieldValueHasAValue_shouldSetGender() { final MiraklValueListAdditionalFieldValue genderBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); genderBusinessStakeHolderField.setCode(GENDER); genderBusinessStakeHolderField.setValue("MALE"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .gender(List.of(genderBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getGender()).isEqualTo(SellerGender.MALE); } @Test void gender_whenMiraklGenderBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetGender() { final MiraklValueListAdditionalFieldValue genderBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); genderBusinessStakeHolderField.setCode(GENDER); genderBusinessStakeHolderField.setValue("MALE"); //@formatter:off BusinessStakeHolderModel.builder() .gender(List.of(genderBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void phoneNumber_whenMiraklPhoneNumberBusinessStakeHolderFieldValueHasAValue_shouldSetPhoneNumber() { final MiraklStringAdditionalFieldValue phoneNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); phoneNumberBusinessStakeHolderField.setCode(PHONE_NUMBER); phoneNumberBusinessStakeHolderField.setValue("phoneNumber"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .phoneNumber(List.of(phoneNumberBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getPhoneNumber()).isEqualTo("phoneNumber"); } @Test void phoneNumber_whenMiraklPhoneNumberBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetPhoneNumber() { final MiraklStringAdditionalFieldValue phoneNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); phoneNumberBusinessStakeHolderField.setCode(PHONE_NUMBER); phoneNumberBusinessStakeHolderField.setValue("phoneNumber"); //@formatter:off BusinessStakeHolderModel.builder() .phoneNumber(List.of(phoneNumberBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void mobileNumber_whenMiraklMobileNumberBusinessStakeHolderFieldValueHasAValue_shouldSetMobileNumber() { final MiraklStringAdditionalFieldValue mobileNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); mobileNumberBusinessStakeHolderField.setCode(MOBILE_NUMBER); mobileNumberBusinessStakeHolderField.setValue("mobileNumber"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .mobileNumber(List.of(mobileNumberBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getMobileNumber()).isEqualTo("mobileNumber"); } @Test void mobileNumber_whenMiraklMobileNumberBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetMobileNumber() { final MiraklStringAdditionalFieldValue mobileNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); mobileNumberBusinessStakeHolderField.setCode(MOBILE_NUMBER); mobileNumberBusinessStakeHolderField.setValue("mobileNumber"); //@formatter:off BusinessStakeHolderModel.builder() .mobileNumber(List.of(mobileNumberBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void email_whenMiraklEmailBusinessStakeHolderFieldValueHasAValue_shouldSetEmail() { final MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue("email"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .email(List.of(emailBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getEmail()).isEqualTo("email"); } @Test void email_whenMiraklEmailBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetEmail() { final MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue("email"); //@formatter:off BusinessStakeHolderModel.builder() .email(List.of(emailBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void governmentId_whenMiraklGovernmentIdBusinessStakeHolderFieldValueHasAValue_shouldSetGovernmentId() { final MiraklStringAdditionalFieldValue governmentIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); governmentIdBusinessStakeHolderField.setCode(GOVERNMENT_ID_NUM); governmentIdBusinessStakeHolderField.setValue("governmentId"); //@formatter:off BusinessStakeHolderModel.builder() .governmentId(List.of(governmentIdBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void governmentIdType_whenMiraklGovernmentIdTypeBusinessStakeHolderFieldValueHasAValue_shouldSetGovernmentIdType() { final MiraklValueListAdditionalFieldValue governmentIdTypeBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); governmentIdTypeBusinessStakeHolderField.setCode(GOVERNMENT_ID_TYPE); governmentIdTypeBusinessStakeHolderField.setValue("PASSPORT"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .governmentIdType(List.of(governmentIdTypeBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getGovernmentIdType()).isEqualTo(SellerGovernmentIdType.PASSPORT); } @Test void governmentIdType_whenMiraklGovernmentIdTypeBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetGovernmentIdType() { final MiraklValueListAdditionalFieldValue governmentIdTypeBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); governmentIdTypeBusinessStakeHolderField.setCode(GOVERNMENT_ID_TYPE); governmentIdTypeBusinessStakeHolderField.setValue("PASSPORT"); //@formatter:off BusinessStakeHolderModel.builder() .governmentIdType(List.of(governmentIdTypeBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void driversLicenseId_whenMiraklDriversLicenseIdBusinessStakeHolderFieldValueHasAValue_shouldSetDriversLicenseId() { final MiraklStringAdditionalFieldValue driversLicenseIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); driversLicenseIdBusinessStakeHolderField.setCode(DRIVERS_LICENSE_NUM); driversLicenseIdBusinessStakeHolderField.setValue("driversLicenseId"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .driversLicenseId(List.of(driversLicenseIdBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getDriversLicenseId()).isEqualTo("driversLicenseId"); } @Test void driversLicenseId_whenMiraklDriversLicenseIdBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetDriversLicenseId() { final MiraklStringAdditionalFieldValue driversLicenseIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); driversLicenseIdBusinessStakeHolderField.setCode(DRIVERS_LICENSE_NUM); driversLicenseIdBusinessStakeHolderField.setValue("driversLicenseId"); //@formatter:off BusinessStakeHolderModel.builder() .driversLicenseId(List.of(driversLicenseIdBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void addressLine1_whenMiraklAddressLine1BusinessStakeHolderFieldValueHasAValue_shouldSetAddressLine1() { final MiraklStringAdditionalFieldValue addressLine1BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine1BusinessStakeHolderField.setCode(ADDRESS_LINE_1); addressLine1BusinessStakeHolderField.setValue("addressLine1"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .addressLine1(List.of(addressLine1BusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getAddressLine1()).isEqualTo("addressLine1"); } @Test void addressLine1_whenMiraklAddressLine1BusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetAddressLine1() { final MiraklStringAdditionalFieldValue addressLine1BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine1BusinessStakeHolderField.setCode(ADDRESS_LINE_1); addressLine1BusinessStakeHolderField.setValue("addressLine1"); //@formatter:off BusinessStakeHolderModel.builder() .addressLine1(List.of(addressLine1BusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void addressLine2_whenMiraklAddressLine2BusinessStakeHolderFieldValueHasAValue_shouldSetAddressLine2() { final MiraklStringAdditionalFieldValue addressLine2BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine2BusinessStakeHolderField.setCode(ADDRESS_LINE_2); addressLine2BusinessStakeHolderField.setValue("addressLine2"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .addressLine2(List.of(addressLine2BusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getAddressLine2()).isEqualTo("addressLine2"); } @Test void addressLine2_whenMiraklAddressLine2BusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetAddressLine2() { final MiraklStringAdditionalFieldValue addressLine2BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine2BusinessStakeHolderField.setCode(ADDRESS_LINE_2); addressLine2BusinessStakeHolderField.setValue("addressLine2"); //@formatter:off BusinessStakeHolderModel.builder() .addressLine2(List.of(addressLine2BusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void city_whenMiraklCityBusinessStakeHolderFieldValueHasAValue_shouldSetCity() { final MiraklStringAdditionalFieldValue cityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); cityBusinessStakeHolderField.setCode(CITY); cityBusinessStakeHolderField.setValue("city"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .city(List.of(cityBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getCity()).isEqualTo("city"); } @Test void city_whenMiraklCityBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetCity() { final MiraklStringAdditionalFieldValue cityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); cityBusinessStakeHolderField.setCode(CITY); cityBusinessStakeHolderField.setValue("city"); //@formatter:off BusinessStakeHolderModel.builder() .city(List.of(cityBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void stateProvince_whenMiraklStateProvinceBusinessStakeHolderFieldValueHasAValue_shouldStateProvince() { final MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .stateProvince(List.of(stateProvinceBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getStateProvince()).isEqualTo("stateProvince"); } @Test void stateProvince_whenMiraklStateProvinceBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetStateProvince() { final MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); //@formatter:off BusinessStakeHolderModel.builder() .stateProvince(List.of(stateProvinceBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void country_whenMiraklCountryBusinessStakeHolderFieldValueHasAValue_shouldSetCountry() { final MiraklStringAdditionalFieldValue countryBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryBusinessStakeHolderField.setCode(COUNTRY); countryBusinessStakeHolderField.setValue(US); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .country(List.of(countryBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getCountry()).isEqualTo("US"); } @Test void country_whenMiraklCountryBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetCountry() { final MiraklStringAdditionalFieldValue countryBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryBusinessStakeHolderField.setCode(COUNTRY); countryBusinessStakeHolderField.setValue(US); //@formatter:off BusinessStakeHolderModel.builder() .country(List.of(countryBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void postalCode_whenMiraklPostalCodeBusinessStakeHolderFieldValueHasAValue_shouldSetPostalCode() { final MiraklStringAdditionalFieldValue postalCodeBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); postalCodeBusinessStakeHolderField.setCode(POST_CODE); postalCodeBusinessStakeHolderField.setValue("postalCode"); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .postalCode(List.of(postalCodeBusinessStakeHolderField), BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(result.getPostalCode()).isEqualTo("postalCode"); } @Test void postalCode_whenMiraklPostalCodeBusinessStakeHolderFieldValueHasAValueButHolderNumberIsNotValid_shouldNotSetPostalCode() { final MiraklStringAdditionalFieldValue postalCodeBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); postalCodeBusinessStakeHolderField.setCode(POST_CODE); postalCodeBusinessStakeHolderField.setValue("postalCode"); //@formatter:off BusinessStakeHolderModel.builder() .postalCode(List.of(postalCodeBusinessStakeHolderField), INVALID_BUSINESS_STAKE_HOLDER_NUMBER) .build(); //@formatter:on assertThat(logTrackerStub.contains( "Business Stake Holder number 0 incorrect. System only allows Business stake holder attributes from 1 to 5")) .isTrue(); } @Test void toBuilder() { final MiraklStringAdditionalFieldValue tokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); tokenBusinessStakeHolderField.setCode(TOKEN); tokenBusinessStakeHolderField.setValue("token"); final MiraklBooleanAdditionalFieldValue businessContactBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); businessContactBusinessStakeHolderField.setCode(BUSINESS); businessContactBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue directorBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); directorBusinessStakeHolderField.setCode(DIRECTOR); directorBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue uboBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); uboBusinessStakeHolderField.setCode(UBO); uboBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue smoBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); smoBusinessStakeHolderField.setCode(SMO); smoBusinessStakeHolderField.setValue("true"); final MiraklStringAdditionalFieldValue firstNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); firstNameBusinessStakeHolderField.setCode(FIRST_NAME); firstNameBusinessStakeHolderField.setValue("firstName"); final MiraklStringAdditionalFieldValue middleNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); middleNameBusinessStakeHolderField.setCode(MIDDLE_NAME); middleNameBusinessStakeHolderField.setValue("middleName"); final MiraklStringAdditionalFieldValue lastNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); lastNameBusinessStakeHolderField.setCode(LAST_NAME); lastNameBusinessStakeHolderField.setValue("lastName"); final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue(DATE_OF_BIRTH); final MiraklStringAdditionalFieldValue countryOfBirthBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfBirthBusinessStakeHolderField.setCode(COUNTRY_OF_BIRTH); countryOfBirthBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue countryOfNationalityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfNationalityBusinessStakeHolderField.setCode(NATIONALITY); countryOfNationalityBusinessStakeHolderField.setValue(US); final MiraklValueListAdditionalFieldValue genderBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); genderBusinessStakeHolderField.setCode(GENDER); genderBusinessStakeHolderField.setValue("MALE"); final MiraklStringAdditionalFieldValue phoneNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); phoneNumberBusinessStakeHolderField.setCode(PHONE_NUMBER); phoneNumberBusinessStakeHolderField.setValue("phoneNumber"); final MiraklStringAdditionalFieldValue mobileNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); mobileNumberBusinessStakeHolderField.setCode(MOBILE_NUMBER); mobileNumberBusinessStakeHolderField.setValue("mobileNumber"); final MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue("email"); final MiraklStringAdditionalFieldValue governmentIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); governmentIdBusinessStakeHolderField.setCode(GOVERNMENT_ID_NUM); governmentIdBusinessStakeHolderField.setValue("governmentId"); final MiraklValueListAdditionalFieldValue governmentIdTypeBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); governmentIdTypeBusinessStakeHolderField.setCode(GOVERNMENT_ID_TYPE); governmentIdTypeBusinessStakeHolderField.setValue("PASSPORT"); final MiraklStringAdditionalFieldValue driversLicenseIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); driversLicenseIdBusinessStakeHolderField.setCode(DRIVERS_LICENSE_NUM); driversLicenseIdBusinessStakeHolderField.setValue("driversLicenseId"); final MiraklStringAdditionalFieldValue addressLine1BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine1BusinessStakeHolderField.setCode(ADDRESS_LINE_1); addressLine1BusinessStakeHolderField.setValue("addressLine1"); final MiraklStringAdditionalFieldValue addressLine2BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine2BusinessStakeHolderField.setCode(ADDRESS_LINE_2); addressLine2BusinessStakeHolderField.setValue("addressLine2"); final MiraklStringAdditionalFieldValue cityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); cityBusinessStakeHolderField.setCode(CITY); cityBusinessStakeHolderField.setValue("city"); final MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklStringAdditionalFieldValue countryBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryBusinessStakeHolderField.setCode(COUNTRY); countryBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue postalCodeBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); postalCodeBusinessStakeHolderField.setCode(POST_CODE); postalCodeBusinessStakeHolderField.setValue("postalCode"); final BusinessStakeHolderModel testObj = BusinessStakeHolderModel.builder().build(); //@formatter:off final BusinessStakeHolderModel result = testObj.toBuilder() .stkId(STK_ID) .token(List.of(tokenBusinessStakeHolderField), STK_ID) .businessContact(List.of(businessContactBusinessStakeHolderField), STK_ID) .director(List.of(directorBusinessStakeHolderField), STK_ID) .ubo(List.of(uboBusinessStakeHolderField), STK_ID) .smo(List.of(smoBusinessStakeHolderField), STK_ID) .firstName(List.of(firstNameBusinessStakeHolderField), STK_ID) .middleName(List.of(middleNameBusinessStakeHolderField), STK_ID) .lastName(List.of(lastNameBusinessStakeHolderField), STK_ID) .timeZone(UTC) .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), STK_ID) .countryOfBirth(List.of(countryOfBirthBusinessStakeHolderField), STK_ID) .countryOfNationality(List.of(countryOfNationalityBusinessStakeHolderField), STK_ID) .gender(List.of(genderBusinessStakeHolderField), STK_ID) .phoneNumber(List.of(phoneNumberBusinessStakeHolderField), STK_ID) .mobileNumber(List.of(mobileNumberBusinessStakeHolderField), STK_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID) .governmentId(List.of(governmentIdBusinessStakeHolderField), STK_ID) .governmentIdType(List.of(governmentIdTypeBusinessStakeHolderField), STK_ID) .driversLicenseId(List.of(driversLicenseIdBusinessStakeHolderField), STK_ID) .addressLine1(List.of(addressLine1BusinessStakeHolderField), STK_ID) .addressLine2(List.of(addressLine2BusinessStakeHolderField), STK_ID) .city(List.of(cityBusinessStakeHolderField), STK_ID) .stateProvince(List.of(stateProvinceBusinessStakeHolderField), STK_ID) .country(List.of(countryBusinessStakeHolderField), STK_ID) .postalCode(List.of(postalCodeBusinessStakeHolderField), STK_ID) .build(); assertThat(result.getDateOfBirth()).hasYear(1970).hasMonth(10).hasDayOfMonth(10); assertThat(result).hasFieldOrPropertyWithValue("stkId", STK_ID) .hasFieldOrPropertyWithValue("token", "token") .hasFieldOrPropertyWithValue("businessContact", Boolean.TRUE) .hasFieldOrPropertyWithValue("director", Boolean.TRUE) .hasFieldOrPropertyWithValue("ubo", Boolean.TRUE) .hasFieldOrPropertyWithValue("smo", Boolean.TRUE) .hasFieldOrPropertyWithValue("firstName", "firstName") .hasFieldOrPropertyWithValue("middleName", "middleName") .hasFieldOrPropertyWithValue("lastName", "lastName") .hasFieldOrPropertyWithValue("countryOfBirth", US) .hasFieldOrPropertyWithValue("countryOfNationality", US) .hasFieldOrPropertyWithValue("gender", SellerGender.MALE) .hasFieldOrPropertyWithValue("phoneNumber", "phoneNumber") .hasFieldOrPropertyWithValue("mobileNumber", "mobileNumber") .hasFieldOrPropertyWithValue("email", "email") .hasFieldOrPropertyWithValue("governmentId", "governmentId") .hasFieldOrPropertyWithValue("governmentIdType", SellerGovernmentIdType.PASSPORT) .hasFieldOrPropertyWithValue("driversLicenseId", "driversLicenseId") .hasFieldOrPropertyWithValue("addressLine1", "addressLine1") .hasFieldOrPropertyWithValue("addressLine2", "addressLine2") .hasFieldOrPropertyWithValue("city", "city") .hasFieldOrPropertyWithValue("stateProvince", "stateProvince") .hasFieldOrPropertyWithValue("country", US) .hasFieldOrPropertyWithValue("postalCode", "postalCode"); //@formatter:on } @Test void isEmpty_shouldReturnFalseIfAnyAttributeIsNotNullExceptStkId() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder().stkId(1) .token("token").build(); final boolean result = businessStakeHolderModel.isEmpty(); assertThat(result).isFalse(); } @Test void isEmpty_shouldReturnTrueIfAnyAttributeIsNotNullExceptStkId() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder().stkId(1).build(); final boolean result = businessStakeHolderModel.isEmpty(); assertThat(result).isTrue(); } @Test void isEmpty_shouldReturnFalseWhenAllAttributesAreFilledIn() { final MiraklStringAdditionalFieldValue tokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); tokenBusinessStakeHolderField.setCode(TOKEN); tokenBusinessStakeHolderField.setValue("token"); final MiraklBooleanAdditionalFieldValue businessContactBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); businessContactBusinessStakeHolderField.setCode(BUSINESS); businessContactBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue directorBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); directorBusinessStakeHolderField.setCode(DIRECTOR); directorBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue uboBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); uboBusinessStakeHolderField.setCode(UBO); uboBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue smoBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); smoBusinessStakeHolderField.setCode(SMO); smoBusinessStakeHolderField.setValue("true"); final MiraklStringAdditionalFieldValue firstNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); firstNameBusinessStakeHolderField.setCode(FIRST_NAME); firstNameBusinessStakeHolderField.setValue("firstName"); final MiraklStringAdditionalFieldValue middleNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); middleNameBusinessStakeHolderField.setCode(MIDDLE_NAME); middleNameBusinessStakeHolderField.setValue("middleName"); final MiraklStringAdditionalFieldValue lastNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); lastNameBusinessStakeHolderField.setCode(LAST_NAME); lastNameBusinessStakeHolderField.setValue("lastName"); final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue(DATE_OF_BIRTH); final MiraklStringAdditionalFieldValue countryOfBirthBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfBirthBusinessStakeHolderField.setCode(COUNTRY_OF_BIRTH); countryOfBirthBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue countryOfNationalityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfNationalityBusinessStakeHolderField.setCode(NATIONALITY); countryOfNationalityBusinessStakeHolderField.setValue(US); final MiraklValueListAdditionalFieldValue genderBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); genderBusinessStakeHolderField.setCode(GENDER); genderBusinessStakeHolderField.setValue("MALE"); final MiraklStringAdditionalFieldValue phoneNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); phoneNumberBusinessStakeHolderField.setCode(PHONE_NUMBER); phoneNumberBusinessStakeHolderField.setValue("phoneNumber"); final MiraklStringAdditionalFieldValue mobileNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); mobileNumberBusinessStakeHolderField.setCode(MOBILE_NUMBER); mobileNumberBusinessStakeHolderField.setValue("mobileNumber"); final MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue("email"); final MiraklStringAdditionalFieldValue governmentIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); governmentIdBusinessStakeHolderField.setCode(GOVERNMENT_ID_NUM); governmentIdBusinessStakeHolderField.setValue("governmentId"); final MiraklValueListAdditionalFieldValue governmentIdTypeBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); governmentIdTypeBusinessStakeHolderField.setCode(GOVERNMENT_ID_TYPE); governmentIdTypeBusinessStakeHolderField.setValue("PASSPORT"); final MiraklStringAdditionalFieldValue driversLicenseIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); driversLicenseIdBusinessStakeHolderField.setCode(DRIVERS_LICENSE_NUM); driversLicenseIdBusinessStakeHolderField.setValue("driversLicenseId"); final MiraklStringAdditionalFieldValue addressLine1BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine1BusinessStakeHolderField.setCode(ADDRESS_LINE_1); addressLine1BusinessStakeHolderField.setValue("addressLine1"); final MiraklStringAdditionalFieldValue addressLine2BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine2BusinessStakeHolderField.setCode(ADDRESS_LINE_2); addressLine2BusinessStakeHolderField.setValue("addressLine2"); final MiraklStringAdditionalFieldValue cityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); cityBusinessStakeHolderField.setCode(CITY); cityBusinessStakeHolderField.setValue("city"); final MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklStringAdditionalFieldValue countryBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryBusinessStakeHolderField.setCode(COUNTRY); countryBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue postalCodeBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); postalCodeBusinessStakeHolderField.setCode(POST_CODE); postalCodeBusinessStakeHolderField.setValue("postalCode"); final BusinessStakeHolderModel testObj = BusinessStakeHolderModel.builder().build(); //@formatter:off final BusinessStakeHolderModel businessStakeHolderStub = testObj.toBuilder() .stkId(STK_ID) .token(List.of(tokenBusinessStakeHolderField), STK_ID) .businessContact(List.of(businessContactBusinessStakeHolderField), STK_ID) .director(List.of(directorBusinessStakeHolderField), STK_ID) .ubo(List.of(uboBusinessStakeHolderField), STK_ID) .smo(List.of(smoBusinessStakeHolderField), STK_ID) .firstName(List.of(firstNameBusinessStakeHolderField), STK_ID) .middleName(List.of(middleNameBusinessStakeHolderField), STK_ID) .lastName(List.of(lastNameBusinessStakeHolderField), STK_ID) .timeZone(UTC) .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), STK_ID) .countryOfBirth(List.of(countryOfBirthBusinessStakeHolderField), STK_ID) .countryOfNationality(List.of(countryOfNationalityBusinessStakeHolderField), STK_ID) .gender(List.of(genderBusinessStakeHolderField), STK_ID) .phoneNumber(List.of(phoneNumberBusinessStakeHolderField), STK_ID) .mobileNumber(List.of(mobileNumberBusinessStakeHolderField), STK_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID) .governmentId(List.of(governmentIdBusinessStakeHolderField), STK_ID) .governmentIdType(List.of(governmentIdTypeBusinessStakeHolderField), STK_ID) .driversLicenseId(List.of(driversLicenseIdBusinessStakeHolderField), STK_ID) .addressLine1(List.of(addressLine1BusinessStakeHolderField), STK_ID) .addressLine2(List.of(addressLine2BusinessStakeHolderField), STK_ID) .city(List.of(cityBusinessStakeHolderField), STK_ID) .stateProvince(List.of(stateProvinceBusinessStakeHolderField), STK_ID) .country(List.of(countryBusinessStakeHolderField), STK_ID) .postalCode(List.of(postalCodeBusinessStakeHolderField), STK_ID) .build(); final boolean result = businessStakeHolderStub.isEmpty(); assertThat(result).isFalse(); } @Test void isJustCreated_shouldReturnTrueWhenSetToFalse() { final BusinessStakeHolderModel businessStakeHolderModelStub = BusinessStakeHolderModel.builder().justCreated(false).build(); final boolean result = businessStakeHolderModelStub.isJustCreated(); assertThat(result).isFalse(); } @Test void isJustCreated_shouldReturnTrueWhenSetToTrue() { final BusinessStakeHolderModel businessStakeHolderModelStub = BusinessStakeHolderModel.builder().justCreated(true).build(); final boolean result = businessStakeHolderModelStub.isJustCreated(); assertThat(result).isTrue(); } @Test void equals_shouldReturnTrueWhenBothAreEquals() { final BusinessStakeHolderModel businessStakeHolderModelOne = createBusinessStakeHolderModelObject(); final BusinessStakeHolderModel businessStakeHolderModelTwo = businessStakeHolderModelOne.toBuilder().build(); final boolean result = businessStakeHolderModelOne.equals(businessStakeHolderModelTwo); assertThat(result).isTrue(); } @Test void equals_shouldReturnFalseWhenBothAreNotEquals() { final BusinessStakeHolderModel businessStakeHolderModelOne = createBusinessStakeHolderModelObject(); final BusinessStakeHolderModel businessStakeHolderModelTwo = businessStakeHolderModelOne.toBuilder().token("newToken").build(); final boolean result = businessStakeHolderModelOne.equals(businessStakeHolderModelTwo); assertThat(result).isFalse(); } @Test void equals_shouldReturnTrueWhenSameObjectIsCompared() { final BusinessStakeHolderModel businessStakeHolderModelOne = createBusinessStakeHolderModelObject(); final boolean result = businessStakeHolderModelOne.equals(businessStakeHolderModelOne); assertThat(result).isTrue(); } @Test void equals_shouldReturnFalseWhenComparedWithAnotherInstanceObject() { final BusinessStakeHolderModel businessStakeHolderModelOne = createBusinessStakeHolderModelObject(); final Object o = new Object(); final boolean result = businessStakeHolderModelOne.equals(o); assertThat(result).isFalse(); } @Test void userToken_whenMiraklUserTokenBusinessStakeHolderFieldValueHasAValue_shouldSetUserToken() { final MiraklStringAdditionalFieldValue userTokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); userTokenBusinessStakeHolderField.setCode(HYPERWALLET_USER_TOKEN); userTokenBusinessStakeHolderField.setValue(USER_TOKEN); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .userToken(List.of(userTokenBusinessStakeHolderField)) .build(); //@formatter:on assertThat(result.getUserToken()).isEqualTo(USER_TOKEN); } @Test void hyperwalletProgram_whenMiraklHyperwalletProgramBusinessStakeHolderFieldValueHasAValue_shouldSetHyperwalletProgram() { final MiraklValueListAdditionalFieldValue hyperwalletProgramBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); hyperwalletProgramBusinessStakeHolderField.setCode(SellerModelConstants.HYPERWALLET_PROGRAM); hyperwalletProgramBusinessStakeHolderField.setValue(HYPERWALLET_PROGRAM); //@formatter:off final BusinessStakeHolderModel result = BusinessStakeHolderModel.builder() .hyperwalletProgram(List.of(hyperwalletProgramBusinessStakeHolderField)) .build(); //@formatter:on assertThat(result.getHyperwalletProgram()).isEqualTo(HYPERWALLET_PROGRAM); } private BusinessStakeHolderModel createBusinessStakeHolderModelObject() { final MiraklStringAdditionalFieldValue tokenBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); tokenBusinessStakeHolderField.setCode(TOKEN); tokenBusinessStakeHolderField.setValue("token"); final MiraklBooleanAdditionalFieldValue businessContactBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); businessContactBusinessStakeHolderField.setCode(BUSINESS); businessContactBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue directorBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); directorBusinessStakeHolderField.setCode(DIRECTOR); directorBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue uboBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); uboBusinessStakeHolderField.setCode(UBO); uboBusinessStakeHolderField.setValue("true"); final MiraklBooleanAdditionalFieldValue smoBusinessStakeHolderField = new MiraklBooleanAdditionalFieldValue(); smoBusinessStakeHolderField.setCode(SMO); smoBusinessStakeHolderField.setValue("true"); final MiraklStringAdditionalFieldValue firstNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); firstNameBusinessStakeHolderField.setCode(FIRST_NAME); firstNameBusinessStakeHolderField.setValue("firstName"); final MiraklStringAdditionalFieldValue middleNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); middleNameBusinessStakeHolderField.setCode(MIDDLE_NAME); middleNameBusinessStakeHolderField.setValue("middleName"); final MiraklStringAdditionalFieldValue lastNameBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); lastNameBusinessStakeHolderField.setCode(LAST_NAME); lastNameBusinessStakeHolderField.setValue("lastName"); final MiraklDateAdditionalFieldValue dateOfBirthBusinessStakeHolderField = new MiraklDateAdditionalFieldValue(); dateOfBirthBusinessStakeHolderField.setCode(DOB); dateOfBirthBusinessStakeHolderField.setValue(DATE_OF_BIRTH); final MiraklStringAdditionalFieldValue countryOfBirthBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfBirthBusinessStakeHolderField.setCode(COUNTRY_OF_BIRTH); countryOfBirthBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue countryOfNationalityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryOfNationalityBusinessStakeHolderField.setCode(NATIONALITY); countryOfNationalityBusinessStakeHolderField.setValue(US); final MiraklValueListAdditionalFieldValue genderBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); genderBusinessStakeHolderField.setCode(GENDER); genderBusinessStakeHolderField.setValue("MALE"); final MiraklStringAdditionalFieldValue phoneNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); phoneNumberBusinessStakeHolderField.setCode(PHONE_NUMBER); phoneNumberBusinessStakeHolderField.setValue("phoneNumber"); final MiraklStringAdditionalFieldValue mobileNumberBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); mobileNumberBusinessStakeHolderField.setCode(MOBILE_NUMBER); mobileNumberBusinessStakeHolderField.setValue("mobileNumber"); final MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue("email"); final MiraklStringAdditionalFieldValue governmentIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); governmentIdBusinessStakeHolderField.setCode(GOVERNMENT_ID_NUM); governmentIdBusinessStakeHolderField.setValue("governmentId"); final MiraklValueListAdditionalFieldValue governmentIdTypeBusinessStakeHolderField = new MiraklValueListAdditionalFieldValue(); governmentIdTypeBusinessStakeHolderField.setCode(GOVERNMENT_ID_TYPE); governmentIdTypeBusinessStakeHolderField.setValue("PASSPORT"); final MiraklStringAdditionalFieldValue driversLicenseIdBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); driversLicenseIdBusinessStakeHolderField.setCode(DRIVERS_LICENSE_NUM); driversLicenseIdBusinessStakeHolderField.setValue("driversLicenseId"); final MiraklStringAdditionalFieldValue addressLine1BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine1BusinessStakeHolderField.setCode(ADDRESS_LINE_1); addressLine1BusinessStakeHolderField.setValue("addressLine1"); final MiraklStringAdditionalFieldValue addressLine2BusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); addressLine2BusinessStakeHolderField.setCode(ADDRESS_LINE_2); addressLine2BusinessStakeHolderField.setValue("addressLine2"); final MiraklStringAdditionalFieldValue cityBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); cityBusinessStakeHolderField.setCode(CITY); cityBusinessStakeHolderField.setValue("city"); final MiraklStringAdditionalFieldValue stateProvinceBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); stateProvinceBusinessStakeHolderField.setCode(STATE); stateProvinceBusinessStakeHolderField.setValue("stateProvince"); final MiraklStringAdditionalFieldValue countryBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); countryBusinessStakeHolderField.setCode(COUNTRY); countryBusinessStakeHolderField.setValue(US); final MiraklStringAdditionalFieldValue postalCodeBusinessStakeHolderField = new MiraklStringAdditionalFieldValue(); postalCodeBusinessStakeHolderField.setCode(POST_CODE); postalCodeBusinessStakeHolderField.setValue("postalCode"); final MiraklValueListAdditionalFieldValue hyperwalletProgramBusinessStakeHolderFiled = new MiraklValueListAdditionalFieldValue(); hyperwalletProgramBusinessStakeHolderFiled.setCode(SellerModelConstants.HYPERWALLET_PROGRAM); hyperwalletProgramBusinessStakeHolderFiled.setValue(HYPERWALLET_PROGRAM); //@formatter:off return BusinessStakeHolderModel.builder() .stkId(STK_ID) .token(List.of(tokenBusinessStakeHolderField), STK_ID) .businessContact(List.of(businessContactBusinessStakeHolderField), STK_ID) .director(List.of(directorBusinessStakeHolderField), STK_ID) .ubo(List.of(uboBusinessStakeHolderField), STK_ID) .smo(List.of(smoBusinessStakeHolderField), STK_ID) .firstName(List.of(firstNameBusinessStakeHolderField), STK_ID) .middleName(List.of(middleNameBusinessStakeHolderField), STK_ID) .lastName(List.of(lastNameBusinessStakeHolderField), STK_ID) .timeZone(UTC) .dateOfBirth(List.of(dateOfBirthBusinessStakeHolderField), STK_ID) .countryOfBirth(List.of(countryOfBirthBusinessStakeHolderField), STK_ID) .countryOfNationality(List.of(countryOfNationalityBusinessStakeHolderField), STK_ID) .gender(List.of(genderBusinessStakeHolderField), STK_ID) .phoneNumber(List.of(phoneNumberBusinessStakeHolderField), STK_ID) .mobileNumber(List.of(mobileNumberBusinessStakeHolderField), STK_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID) .governmentId(List.of(governmentIdBusinessStakeHolderField), STK_ID) .governmentIdType(List.of(governmentIdTypeBusinessStakeHolderField), STK_ID) .driversLicenseId(List.of(driversLicenseIdBusinessStakeHolderField), STK_ID) .addressLine1(List.of(addressLine1BusinessStakeHolderField), STK_ID) .addressLine2(List.of(addressLine2BusinessStakeHolderField), STK_ID) .city(List.of(cityBusinessStakeHolderField), STK_ID) .stateProvince(List.of(stateProvinceBusinessStakeHolderField), STK_ID) .country(List.of(countryBusinessStakeHolderField), STK_ID) .postalCode(List.of(postalCodeBusinessStakeHolderField), STK_ID) .hyperwalletProgram(List.of(hyperwalletProgramBusinessStakeHolderFiled)) .build(); } }
4,852
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/BusinessStakeholderExtractServiceImplTest.java
package com.paypal.sellers.stakeholdersextraction.services; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.stakeholdersextraction.services.BusinessStakeholderExtractServiceImpl; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderConstants; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class BusinessStakeholderExtractServiceImplTest { private static final String TOKEN_1 = "token1"; private static final String TOKEN_2 = "token2"; private static final String CLIENT_ID_1 = "clientId1"; private static final String CLIENT_ID_2 = "clientId2"; @InjectMocks private BusinessStakeholderExtractServiceImpl testObj; @Test void extractBusinessStakeHolders_shouldReturnAllBusinessStakeHoldersWithDifferentSellers() { final BusinessStakeHolderModel stkOne = BusinessStakeHolderModel.builder().userToken(TOKEN_1) .clientUserId("0001").token("STK1_TOKEN") .firstName(List.of(new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue( BusinessStakeHolderConstants.FIRST_NAME, "john")), 1) .build(); final BusinessStakeHolderModel stkTwo = BusinessStakeHolderModel.builder().userToken(TOKEN_2) .firstName(List.of(new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue( BusinessStakeHolderConstants.FIRST_NAME, "susan")), 1) .clientUserId("0002").token("STK2_TOKEN").build(); final SellerModel sellerModelOne = SellerModel.builder().token(TOKEN_1) .businessStakeHolderDetails(List.of(stkOne)).clientUserId(CLIENT_ID_1).build(); final SellerModel sellerModelTwo = SellerModel.builder().token(TOKEN_2) .businessStakeHolderDetails(List.of(stkTwo)).clientUserId(CLIENT_ID_2).build(); final List<BusinessStakeHolderModel> result = testObj .extractBusinessStakeHolders(List.of(sellerModelOne, sellerModelTwo)); assertThat(result).containsExactly(stkOne, stkTwo); } }
4,853
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/BusinessStakeholderTokenUpdateServiceImplTest.java
package com.paypal.sellers.stakeholdersextraction.services; import com.mirakl.client.core.error.MiraklErrorResponseBean; import com.mirakl.client.core.exception.MiraklApiException; import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop; import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest; import com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.mirakl.client.MiraklClient; import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.ArgumentCaptor; import org.mockito.Captor; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class BusinessStakeholderTokenUpdateServiceImplTest { private static final String BUSINESS_STAKE_HOLDER_TOKEN = "businessStakeHolderToken"; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; @InjectMocks private BusinessStakeholderTokenUpdateServiceImpl testObj; @Mock private MiraklClient miraklMarketplacePlatformOperatorApiClientMock; @Mock private SellerModel sellerModelMock; @Mock private BusinessStakeHolderModel businessStakeHolderModelMock; @Mock private MailNotificationUtil mailNotificationUtilMock; @Captor private ArgumentCaptor<MiraklUpdateShopsRequest> miraklUpdateShopsRequestCaptor; @BeforeEach void setUp() { testObj = new BusinessStakeholderTokenUpdateServiceImpl(miraklMarketplacePlatformOperatorApiClientMock, mailNotificationUtilMock); } @DisplayName("Should Update Value for Custom Field 'hw-user-token'") @Test void updateBusinessStakeholderToken_shouldUpdateValueForCustomFieldHwUserToken() { when(sellerModelMock.getBusinessStakeHolderDetails()).thenReturn(List.of(businessStakeHolderModelMock)); when(sellerModelMock.getClientUserId()).thenReturn("12345"); when(businessStakeHolderModelMock.getToken()).thenReturn(BUSINESS_STAKE_HOLDER_TOKEN); when(businessStakeHolderModelMock.getStkId()).thenReturn(1); testObj.updateBusinessStakeholderToken(sellerModelMock.getClientUserId(), sellerModelMock.getBusinessStakeHolderDetails()); verify(miraklMarketplacePlatformOperatorApiClientMock).updateShops(miraklUpdateShopsRequestCaptor.capture()); final MiraklUpdateShopsRequest miraklUpdateShopsRequest = miraklUpdateShopsRequestCaptor.getValue(); assertThat(miraklUpdateShopsRequest.getShops()).hasSize(1); final MiraklUpdateShop shopToUpdate = miraklUpdateShopsRequest.getShops().get(0); assertThat(shopToUpdate).hasFieldOrPropertyWithValue("shopId", 12345L); assertThat(shopToUpdate.getAdditionalFieldValues()).hasSize(1); final MiraklRequestAdditionalFieldValue additionalFieldValue = shopToUpdate.getAdditionalFieldValues().get(0); assertThat(additionalFieldValue).isInstanceOf(MiraklSimpleRequestAdditionalFieldValue.class); final MiraklSimpleRequestAdditionalFieldValue castedAdditionalFieldValue = (MiraklSimpleRequestAdditionalFieldValue) additionalFieldValue; assertThat(castedAdditionalFieldValue.getCode()).isEqualTo("hw-stakeholder-token-1"); assertThat(castedAdditionalFieldValue.getValue()).isEqualTo(BUSINESS_STAKE_HOLDER_TOKEN); } @Test void updateUserToken_shouldSendEmailNotification_whenMiraklExceptionIsThrown() { when(sellerModelMock.getClientUserId()).thenReturn("12345"); when(sellerModelMock.getBusinessStakeHolderDetails()).thenReturn(List.of(businessStakeHolderModelMock)); final MiraklApiException miraklApiException = new MiraklApiException( new MiraklErrorResponseBean(1, "Something went wrong", "correlation-id")); doThrow(miraklApiException).when(miraklMarketplacePlatformOperatorApiClientMock) .updateShops(any(MiraklUpdateShopsRequest.class)); testObj.updateBusinessStakeholderToken(sellerModelMock.getClientUserId(), sellerModelMock.getBusinessStakeHolderDetails()); verify(mailNotificationUtilMock).sendPlainTextEmail("Issue detected getting shop information in Mirakl", (ERROR_MESSAGE_PREFIX + "Something went wrong getting information of shop [12345]%n%s") .formatted(MiraklLoggingErrorsUtil.stringify(miraklApiException))); } @Test void updateUserToken_shouldDoNothing_whenSellerModelHasNoBusinessStakeHolders() { when(sellerModelMock.getBusinessStakeHolderDetails()).thenReturn(null); testObj.updateBusinessStakeholderToken(sellerModelMock.getClientUserId(), sellerModelMock.getBusinessStakeHolderDetails()); verifyNoInteractions(mailNotificationUtilMock); verifyNoInteractions(miraklMarketplacePlatformOperatorApiClientMock); } }
4,854
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/BusinessStakeholderTokenSynchronizationServiceImplTest.java
package com.paypal.sellers.stakeholdersextraction.services; import com.callibrity.logging.test.LogTrackerStub; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder; import com.hyperwallet.clientsdk.model.HyperwalletList; import com.mirakl.client.core.exception.MiraklException; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.infrastructure.support.exceptions.HMCException; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.apache.commons.lang3.StringUtils; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.RegisterExtension; import org.mockito.*; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.assertj.core.api.Assertions.assertThatThrownBy; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class BusinessStakeholderTokenSynchronizationServiceImplTest { private static final String EMAIL = "hw-stakeholder-email-1"; private static final String CLIENT_USER_ID = "1234"; private static final String STK_TOKEN = "89f7f89"; private static final int STK_ID = 1; private static final String STK_EMAIL = "test@test.com"; public static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; public static final String USER_TOKEN = "userToken"; @Spy @InjectMocks private BusinessStakeholderTokenSynchronizationServiceImpl testObj; @Mock private UserHyperwalletSDKService userHyperwalletSDKServiceMock; @Mock private BusinessStakeholderTokenUpdateService businessStakeholderTokenUpdateServiceMock; @Mock private MailNotificationUtil mailNotificationUtilMock; @RegisterExtension final LogTrackerStub logTrackerStub = LogTrackerStub.create() .recordForType(BusinessStakeholderTokenSynchronizationServiceImpl.class); @Mock private Hyperwallet hyperwalletMock; @Captor private ArgumentCaptor<List<BusinessStakeHolderModel>> businessStakeHolderModelsArgumentCaptor; @Test void synchronizeToken_ShouldSendAnEmailAndThrowAnHMCException_WhenStkEmailIsMandatoryAndSTKEmailIsNullAndSTKTokenIsNull() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).stkId(STK_ID).build(); doReturn(true).when(testObj).isStkEmailMandatory(); assertThatThrownBy(() -> testObj.synchronizeToken(businessStakeHolderModel)).isInstanceOf(HMCException.class) .hasMessage("Business stakeholder without email and Hyperwallet token defined for shop [" + CLIENT_USER_ID + "]"); verify(mailNotificationUtilMock).sendPlainTextEmail( "Validation error occurred when processing a stakeholder for seller {" + CLIENT_USER_ID + "}", "There was an error processing the {" + CLIENT_USER_ID + "} seller and the operation could not be completed. Email address for the stakeholder {" + STK_ID + "} must be filled.\n" + "Please check the logs for further information."); } @Test void synchronizeToken_ShouldReturnTheCurrentSTK_WhenSTKTokenIsNotBlank() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).token(STK_TOKEN).build(); final BusinessStakeHolderModel result = testObj.synchronizeToken(businessStakeHolderModel); assertThat(result).isEqualTo(businessStakeHolderModel); assertThat(logTrackerStub.contains("Hyperwallet token already exists for business stakeholder [" + STK_TOKEN + "] for shop [" + CLIENT_USER_ID + "], synchronization not needed")).isTrue(); } @Test void synchronizeToken_ShouldReturnTheCurrentSTK_WhenSTKTokenIsNullAndEmailIsNullAndStkEmailIsNotMandatory() { final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder() .clientUserId(CLIENT_USER_ID).stkId(STK_ID).build(); doReturn(false).when(testObj).isStkEmailMandatory(); final BusinessStakeHolderModel result = testObj.synchronizeToken(businessStakeHolderModel); assertThat(result).isEqualTo(businessStakeHolderModel); assertThat(logTrackerStub.contains( "Hyperwallet business stakeholder [" + STK_ID + "] for shop [" + CLIENT_USER_ID + "] not found")) .isTrue(); } @Test void synchronizeToken_ShouldThrowAnHMCHyperwalletAPIException_WhenGettingHwBusinessStakeholdersAnHyperwalletExceptionIsThrown() { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue(STK_EMAIL); final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder().stkId(STK_ID) .hyperwalletProgram(HYPERWALLET_PROGRAM).userToken(USER_TOKEN).clientUserId(CLIENT_USER_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID).build(); doReturn(false).when(testObj).isStkEmailMandatory(); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletMock); when(hyperwalletMock.listBusinessStakeholders(USER_TOKEN)).thenThrow(HyperwalletException.class); assertThatThrownBy(() -> testObj.synchronizeToken(businessStakeHolderModel)) .isInstanceOf(HMCHyperwalletAPIException.class); assertThat(logTrackerStub .contains("Error while getting Hyperwallet business stakeholders for shop [" + CLIENT_USER_ID + "]")) .isTrue(); } @Test void synchronizeToken_ShouldThrowAnHMCMiraklAPIException_WhenUpdatingSTKTokenInMiraklThrowsAMiraklException() { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue(STK_EMAIL); final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder().stkId(STK_ID) .hyperwalletProgram(HYPERWALLET_PROGRAM).userToken(USER_TOKEN).clientUserId(CLIENT_USER_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID).build(); doReturn(false).when(testObj).isStkEmailMandatory(); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletMock); final HyperwalletBusinessStakeholder hyperwalletBusinessStakeholder = new HyperwalletBusinessStakeholder(); hyperwalletBusinessStakeholder.setToken(STK_TOKEN); hyperwalletBusinessStakeholder.setEmail(STK_EMAIL); final HyperwalletList<HyperwalletBusinessStakeholder> hyperwalletBusinessStakeholders = new HyperwalletList<>(); hyperwalletBusinessStakeholders.setData(List.of(hyperwalletBusinessStakeholder)); when(hyperwalletMock.listBusinessStakeholders(USER_TOKEN)).thenReturn(hyperwalletBusinessStakeholders); doThrow(MiraklException.class).when(businessStakeholderTokenUpdateServiceMock) .updateBusinessStakeholderToken(eq(CLIENT_USER_ID), anyList()); assertThatThrownBy(() -> testObj.synchronizeToken(businessStakeHolderModel)) .isInstanceOf(HMCMiraklAPIException.class); assertThat(logTrackerStub.contains("Error while updating Mirakl business stakeholder [" + STK_TOKEN + "] for shop [" + CLIENT_USER_ID + "]")).isTrue(); } @Test void synchronizeToken_ShouldRetrieveSTKFromHyperwalletAndSynchronizedTokenInMirakl_WhenEmailIsNotBlankAndSTKTokenIsEmpty() { final MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue emailBusinessStakeHolderField = new MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue(); emailBusinessStakeHolderField.setCode(EMAIL); emailBusinessStakeHolderField.setValue(STK_EMAIL); final BusinessStakeHolderModel businessStakeHolderModel = BusinessStakeHolderModel.builder().stkId(STK_ID) .hyperwalletProgram(HYPERWALLET_PROGRAM).userToken(USER_TOKEN).clientUserId(CLIENT_USER_ID) .email(List.of(emailBusinessStakeHolderField), STK_ID).build(); doReturn(false).when(testObj).isStkEmailMandatory(); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletMock); final HyperwalletBusinessStakeholder hyperwalletBusinessStakeholder = new HyperwalletBusinessStakeholder(); hyperwalletBusinessStakeholder.setToken(STK_TOKEN); hyperwalletBusinessStakeholder.setEmail(STK_EMAIL); final HyperwalletList<HyperwalletBusinessStakeholder> hyperwalletBusinessStakeholders = new HyperwalletList<>(); hyperwalletBusinessStakeholders.setData(List.of(hyperwalletBusinessStakeholder)); when(hyperwalletMock.listBusinessStakeholders(USER_TOKEN)).thenReturn(hyperwalletBusinessStakeholders); final BusinessStakeHolderModel result = testObj.synchronizeToken(businessStakeHolderModel); verify(businessStakeholderTokenUpdateServiceMock).updateBusinessStakeholderToken(eq(CLIENT_USER_ID), businessStakeHolderModelsArgumentCaptor.capture()); assertThat(result.getToken()).isEqualTo(STK_TOKEN); assertThat(result.getEmail()).isEqualTo(STK_EMAIL); assertThat(result.getUserToken()).isEqualTo(USER_TOKEN); assertThat(result.getClientUserId()).isEqualTo(CLIENT_USER_ID); assertThat(businessStakeHolderModelsArgumentCaptor.getValue().stream().findFirst() .map(BusinessStakeHolderModel::getToken).orElse(StringUtils.EMPTY)).isEqualTo(STK_TOKEN); } }
4,855
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/strategies/HyperWalletBusinessStakeHolderStrategyExecutorSingleTest.java
package com.paypal.sellers.stakeholdersextraction.services.strategies; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Set; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class HyperWalletBusinessStakeHolderStrategyExecutorSingleTest { @InjectMocks private HyperWalletBusinessStakeHolderStrategyExecutor testObj; @Mock private Strategy<BusinessStakeHolderModel, BusinessStakeHolderModel> strategyMock; @BeforeEach void setUp() { testObj = new HyperWalletBusinessStakeHolderStrategyExecutor(Set.of(strategyMock)); } @Test void getStrategies_shouldReturnConverterStrategyMock() { final Set<Strategy<BusinessStakeHolderModel, BusinessStakeHolderModel>> result = testObj.getStrategies(); assertThat(result).containsExactly(strategyMock); } }
4,856
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/strategies/HyperWalletUpdateBusinessStakeHolderServiceStrategyTest.java
package com.paypal.sellers.stakeholdersextraction.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class HyperWalletUpdateBusinessStakeHolderServiceStrategyTest { @InjectMocks private HyperWalletUpdateBusinessStakeHolderServiceStrategy testObj; @Mock private BusinessStakeHolderModel businessStakeHolderMock; @Mock private Converter<BusinessStakeHolderModel, HyperwalletBusinessStakeholder> businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock; @Mock private HyperwalletBusinessStakeholder hyperwalletBusinessStakeholderMock, hyperwalletBusinessStakeholderResponseMock; @Mock private Hyperwallet hyperwalletClientMock; @Mock private UserHyperwalletSDKService userHyperwalletSDKService; @Mock private MailNotificationUtil mailNotificationUtilMock; private static final String CLIENT_ID = "clientID"; private static final String TOKEN = "token"; private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; @Test void execute_shouldReturnUpdatedHyperWalletBusinessStakeHolder() { when(businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock.convert(businessStakeHolderMock)) .thenReturn(hyperwalletBusinessStakeholderMock); when(hyperwalletClientMock.updateBusinessStakeholder(TOKEN, hyperwalletBusinessStakeholderMock)) .thenReturn(hyperwalletBusinessStakeholderResponseMock); when(businessStakeHolderMock.getUserToken()).thenReturn(TOKEN); when(businessStakeHolderMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(userHyperwalletSDKService.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletClientMock); final BusinessStakeHolderModel result = testObj.execute(businessStakeHolderMock); assertThat(result).isEqualTo(businessStakeHolderMock); } @Test void execute_shouldSendEmailNotificationHyperwalletExceptionIsThrown() { when(businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock.convert(businessStakeHolderMock)) .thenReturn(hyperwalletBusinessStakeholderMock); when(businessStakeHolderMock.getUserToken()).thenReturn(TOKEN); when(businessStakeHolderMock.getClientUserId()).thenReturn(CLIENT_ID); when(businessStakeHolderMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(userHyperwalletSDKService.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletClientMock); final HyperwalletException hyperwalletException = new HyperwalletException("Something went wrong"); doThrow(hyperwalletException).when(hyperwalletClientMock).updateBusinessStakeholder(TOKEN, hyperwalletBusinessStakeholderMock); testObj.execute(businessStakeHolderMock); verify(mailNotificationUtilMock).sendPlainTextEmail( "Issue detected when updating business stakeholder in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Business stakeholder not updated for clientId [%s]%n%s").formatted(CLIENT_ID, HyperwalletLoggingErrorsUtil.stringify(hyperwalletException))); } @Test void isApplicable_shouldReturnFalseWhenBusinessStakeHolderHasAnEmptyToken() { final boolean result = testObj.isApplicable(businessStakeHolderMock); assertThat(result).isFalse(); } @Test void isApplicable_shouldReturnTrueWhenBusinessStakeHolderHasAToken() { when(businessStakeHolderMock.getToken()).thenReturn("TOKEN"); final boolean result = testObj.isApplicable(businessStakeHolderMock); assertThat(result).isTrue(); } }
4,857
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/strategies/HyperWalletCreateBusinessStakeHolderServiceStrategyTest.java
package com.paypal.sellers.stakeholdersextraction.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.stakeholdersextraction.services.BusinessStakeholderTokenUpdateService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class HyperWalletCreateBusinessStakeHolderServiceStrategyTest { private static final String HYPERWALLET_PROGRAM = "hyperwalletProgram"; @InjectMocks private HyperWalletCreateBusinessStakeHolderServiceStrategy testObj; @Mock private BusinessStakeHolderModel businessStakeHolderMock, businessStakeHolderResponseMock; @Mock private Converter<BusinessStakeHolderModel, HyperwalletBusinessStakeholder> businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock; @Mock private HyperwalletBusinessStakeholder hyperwalletBusinessStakeholderMock, hyperwalletBusinessStakeholderResponseMock; @Mock private Hyperwallet hyperwalletClientMock; @Mock private UserHyperwalletSDKService userHyperwalletSDKServiceMock; @Mock private MailNotificationUtil mailNotificationUtilMock; @Mock private BusinessStakeHolderModel.BusinessStakeHolderModelBuilder businessStakeHolderBuilderMock; @Mock private BusinessStakeholderTokenUpdateService businessStakeholderTokenUpdateServiceMock; private static final String CLIENT_ID = "clientID"; private static final String TOKEN = "token"; private static final String BUSINESS_STAKE_HOLDER_TOKEN = "stk-token"; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; @Test void execute_shouldReturnCreatedHyperWalletBusinessStakeHolder() { when(businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock.convert(businessStakeHolderMock)) .thenReturn(hyperwalletBusinessStakeholderMock); when(hyperwalletClientMock.createBusinessStakeholder(TOKEN, hyperwalletBusinessStakeholderMock)) .thenReturn(hyperwalletBusinessStakeholderResponseMock); when(hyperwalletBusinessStakeholderResponseMock.getToken()).thenReturn(BUSINESS_STAKE_HOLDER_TOKEN); when(businessStakeHolderMock.getUserToken()).thenReturn(TOKEN); when(businessStakeHolderMock.toBuilder()).thenReturn(businessStakeHolderBuilderMock); when(businessStakeHolderBuilderMock.token(BUSINESS_STAKE_HOLDER_TOKEN)) .thenReturn(businessStakeHolderBuilderMock); when(businessStakeHolderBuilderMock.justCreated(true)).thenReturn(businessStakeHolderBuilderMock); when(businessStakeHolderBuilderMock.build()).thenReturn(businessStakeHolderResponseMock); when(businessStakeHolderResponseMock.getClientUserId()).thenReturn(CLIENT_ID); when(businessStakeHolderMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletClientMock); final BusinessStakeHolderModel result = testObj.execute(businessStakeHolderMock); verify(businessStakeholderTokenUpdateServiceMock).updateBusinessStakeholderToken(CLIENT_ID, List.of(businessStakeHolderResponseMock)); assertThat(result).isEqualTo(businessStakeHolderResponseMock); } @Test void execute_shouldSendEmailNotificationHyperwalletExceptionIsThrown() { when(businessStakeHolderModelHyperwalletBusinessStakeholderConverterMock.convert(businessStakeHolderMock)) .thenReturn(hyperwalletBusinessStakeholderMock); when(businessStakeHolderMock.getClientUserId()).thenReturn(CLIENT_ID); when(businessStakeHolderMock.getUserToken()).thenReturn(TOKEN); when(businessStakeHolderMock.getHyperwalletProgram()).thenReturn(HYPERWALLET_PROGRAM); when(userHyperwalletSDKServiceMock.getHyperwalletInstanceByHyperwalletProgram(HYPERWALLET_PROGRAM)) .thenReturn(hyperwalletClientMock); final HyperwalletException hyperwalletException = new HyperwalletException("Something went wrong"); doThrow(hyperwalletException).when(hyperwalletClientMock).createBusinessStakeholder(TOKEN, hyperwalletBusinessStakeholderMock); testObj.execute(businessStakeHolderMock); verify(mailNotificationUtilMock).sendPlainTextEmail( "Issue detected when creating business stakeholder in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Business stakeholder not created for clientId [%s]%n%s").formatted(CLIENT_ID, HyperwalletLoggingErrorsUtil.stringify(hyperwalletException))); } @Test void isApplicable_shouldReturnTrueWhenBusinessStakeHolderHasAnEmptyToken() { final boolean result = testObj.isApplicable(businessStakeHolderMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenBusinessStakeHolderHasAToken() { when(businessStakeHolderMock.getToken()).thenReturn("TOKEN"); final boolean result = testObj.isApplicable(businessStakeHolderMock); assertThat(result).isFalse(); } }
4,858
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/converters/BusinessStakeHolderModelToHyperWalletBusinessStakeHolderConverterTest.java
package com.paypal.sellers.stakeholdersextraction.services.converters; import com.hyperwallet.clientsdk.model.HyperwalletBusinessStakeholder; import com.hyperwallet.clientsdk.model.HyperwalletUser.Gender; import com.paypal.infrastructure.hyperwallet.constants.HyperWalletConstants; import com.paypal.infrastructure.support.date.DateUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.sellerextractioncommons.model.SellerGender; import com.paypal.sellers.sellerextractioncommons.model.SellerGovernmentIdType; import com.paypal.sellers.stakeholdersextraction.services.converters.BusinessStakeHolderModelToHyperWalletBusinessStakeHolderConverter; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.TimeZone; import static com.hyperwallet.clientsdk.model.HyperwalletUser.GovernmentIdType.NATIONAL_ID_CARD; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class BusinessStakeHolderModelToHyperWalletBusinessStakeHolderConverterTest { private static final String FIRST_NAME = "firstName"; private static final String MIDDLE_NAME = "middleName"; private static final String LAST_NAME = "lastName"; private static final String DATE_OF_BIRTH = "1970-10-10T10:00:00"; private static final String COUNTRY_OF_BIRTH = "countryOfBirth"; private static final String COUNTRY_OF_NATIONALITY = "countryOfNationality"; private static final String PHONE_NUMBER = "phoneNumber"; private static final String MOBILE_NUMBER = "mobileNumber"; private static final String EMAIL = "email"; private static final String GOVERNMENT_ID = "governmentId"; private static final String DRIVERS_LICENSE_ID = "driversLicenseId"; private static final String ADDRESS_LINE_1 = "addressLine1"; private static final String ADDRESS_LINE_2 = "addressLine2"; private static final String CITY = "city"; private static final String STATE_PROVINCE = "stateProvince"; private static final String COUNTRY = "country"; private static final String POSTAL_CODE = "postalCode"; private static final String TOKEN = "TOKEN"; @InjectMocks private BusinessStakeHolderModelToHyperWalletBusinessStakeHolderConverter testObj; @Mock private BusinessStakeHolderModel businessStakeHolderModelMock; @Test void convert_shouldReturnHyperWalletBusinessStakeHolder() { when(businessStakeHolderModelMock.getBusinessContact()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getDirector()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getUbo()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getSmo()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getFirstName()).thenReturn(FIRST_NAME); when(businessStakeHolderModelMock.getMiddleName()).thenReturn(MIDDLE_NAME); when(businessStakeHolderModelMock.getLastName()).thenReturn(LAST_NAME); when(businessStakeHolderModelMock.getDateOfBirth()).thenReturn(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); when(businessStakeHolderModelMock.getCountryOfBirth()).thenReturn(COUNTRY_OF_BIRTH); when(businessStakeHolderModelMock.getCountryOfNationality()).thenReturn(COUNTRY_OF_NATIONALITY); when(businessStakeHolderModelMock.getGender()).thenReturn(SellerGender.MALE); when(businessStakeHolderModelMock.getPhoneNumber()).thenReturn(PHONE_NUMBER); when(businessStakeHolderModelMock.getMobileNumber()).thenReturn(MOBILE_NUMBER); when(businessStakeHolderModelMock.getEmail()).thenReturn(EMAIL); when(businessStakeHolderModelMock.getGovernmentId()).thenReturn(GOVERNMENT_ID); when(businessStakeHolderModelMock.getGovernmentIdType()).thenReturn(SellerGovernmentIdType.NATIONAL_ID_CARD); when(businessStakeHolderModelMock.getDriversLicenseId()).thenReturn(DRIVERS_LICENSE_ID); when(businessStakeHolderModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_1); when(businessStakeHolderModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_2); when(businessStakeHolderModelMock.getCity()).thenReturn(CITY); when(businessStakeHolderModelMock.getStateProvince()).thenReturn(STATE_PROVINCE); when(businessStakeHolderModelMock.getCountry()).thenReturn(COUNTRY); when(businessStakeHolderModelMock.getPostalCode()).thenReturn(POSTAL_CODE); when(businessStakeHolderModelMock.getToken()).thenReturn(TOKEN); final HyperwalletBusinessStakeholder result = testObj.convert(businessStakeHolderModelMock); assertThat(result.getToken()).isEqualTo(TOKEN); assertThat(result.getIsBusinessContact()).isTrue(); assertThat(result.getIsDirector()).isFalse(); assertThat(result.getIsUltimateBeneficialOwner()).isFalse(); assertThat(result.getIsSeniorManagingOfficial()).isTrue(); assertThat(result.getFirstName()).isEqualTo(FIRST_NAME); assertThat(result.getMiddleName()).isEqualTo(MIDDLE_NAME); assertThat(result.getLastName()).isEqualTo(LAST_NAME); assertThat(result.getDateOfBirth()).isEqualTo(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); assertThat(result.getCountryOfBirth()).isEqualTo(COUNTRY_OF_BIRTH); assertThat(result.getCountryOfNationality()).isEqualTo(COUNTRY_OF_NATIONALITY); assertThat(result.getGender().name()).isEqualTo(Gender.MALE.name()); assertThat(result.getPhoneNumber()).isEqualTo(PHONE_NUMBER); assertThat(result.getMobileNumber()).isEqualTo(MOBILE_NUMBER); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getGovernmentId()).isEqualTo(GOVERNMENT_ID); assertThat(result.getGovernmentIdType().name()).isEqualTo(NATIONAL_ID_CARD.name()); assertThat(result.getDriversLicenseId()).isEqualTo(DRIVERS_LICENSE_ID); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_1); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_2); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); } @Test void convert_shouldReturnHyperWalletBusinessStakeHolder_whenStringValueIsNull() { when(businessStakeHolderModelMock.getFirstName()).thenReturn(null); when(businessStakeHolderModelMock.getBusinessContact()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getDirector()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getUbo()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getSmo()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getMiddleName()).thenReturn(MIDDLE_NAME); when(businessStakeHolderModelMock.getLastName()).thenReturn(LAST_NAME); when(businessStakeHolderModelMock.getDateOfBirth()).thenReturn(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); when(businessStakeHolderModelMock.getCountryOfBirth()).thenReturn(COUNTRY_OF_BIRTH); when(businessStakeHolderModelMock.getCountryOfNationality()).thenReturn(COUNTRY_OF_NATIONALITY); when(businessStakeHolderModelMock.getGender()).thenReturn(SellerGender.MALE); when(businessStakeHolderModelMock.getPhoneNumber()).thenReturn(PHONE_NUMBER); when(businessStakeHolderModelMock.getMobileNumber()).thenReturn(MOBILE_NUMBER); when(businessStakeHolderModelMock.getEmail()).thenReturn(EMAIL); when(businessStakeHolderModelMock.getGovernmentId()).thenReturn(GOVERNMENT_ID); when(businessStakeHolderModelMock.getGovernmentIdType()).thenReturn(SellerGovernmentIdType.NATIONAL_ID_CARD); when(businessStakeHolderModelMock.getDriversLicenseId()).thenReturn(DRIVERS_LICENSE_ID); when(businessStakeHolderModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_1); when(businessStakeHolderModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_2); when(businessStakeHolderModelMock.getCity()).thenReturn(CITY); when(businessStakeHolderModelMock.getStateProvince()).thenReturn(STATE_PROVINCE); when(businessStakeHolderModelMock.getCountry()).thenReturn(COUNTRY); when(businessStakeHolderModelMock.getPostalCode()).thenReturn(POSTAL_CODE); final HyperwalletBusinessStakeholder result = testObj.convert(businessStakeHolderModelMock); assertThat(result.getFirstName()).isNull(); assertThat(result.getIsBusinessContact()).isTrue(); assertThat(result.getIsDirector()).isFalse(); assertThat(result.getIsUltimateBeneficialOwner()).isFalse(); assertThat(result.getIsSeniorManagingOfficial()).isTrue(); assertThat(result.getMiddleName()).isEqualTo(MIDDLE_NAME); assertThat(result.getLastName()).isEqualTo(LAST_NAME); assertThat(result.getDateOfBirth()).isEqualTo(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); assertThat(result.getCountryOfBirth()).isEqualTo(COUNTRY_OF_BIRTH); assertThat(result.getCountryOfNationality()).isEqualTo(COUNTRY_OF_NATIONALITY); assertThat(result.getGender().name()).isEqualTo(Gender.MALE.name()); assertThat(result.getPhoneNumber()).isEqualTo(PHONE_NUMBER); assertThat(result.getMobileNumber()).isEqualTo(MOBILE_NUMBER); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getGovernmentId()).isEqualTo(GOVERNMENT_ID); assertThat(result.getGovernmentIdType().name()).isEqualTo(NATIONAL_ID_CARD.name()); assertThat(result.getDriversLicenseId()).isEqualTo(DRIVERS_LICENSE_ID); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_1); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_2); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); } @Test void convert_shouldReturnHyperWalletBusinessStakeHolder_whenDateIsNull() { when(businessStakeHolderModelMock.getDateOfBirth()).thenReturn(null); when(businessStakeHolderModelMock.getBusinessContact()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getDirector()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getUbo()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getSmo()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getFirstName()).thenReturn(FIRST_NAME); when(businessStakeHolderModelMock.getMiddleName()).thenReturn(MIDDLE_NAME); when(businessStakeHolderModelMock.getLastName()).thenReturn(LAST_NAME); when(businessStakeHolderModelMock.getCountryOfBirth()).thenReturn(COUNTRY_OF_BIRTH); when(businessStakeHolderModelMock.getCountryOfNationality()).thenReturn(COUNTRY_OF_NATIONALITY); when(businessStakeHolderModelMock.getGender()).thenReturn(SellerGender.MALE); when(businessStakeHolderModelMock.getPhoneNumber()).thenReturn(PHONE_NUMBER); when(businessStakeHolderModelMock.getMobileNumber()).thenReturn(MOBILE_NUMBER); when(businessStakeHolderModelMock.getEmail()).thenReturn(EMAIL); when(businessStakeHolderModelMock.getGovernmentId()).thenReturn(GOVERNMENT_ID); when(businessStakeHolderModelMock.getGovernmentIdType()).thenReturn(SellerGovernmentIdType.NATIONAL_ID_CARD); when(businessStakeHolderModelMock.getDriversLicenseId()).thenReturn(DRIVERS_LICENSE_ID); when(businessStakeHolderModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_1); when(businessStakeHolderModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_2); when(businessStakeHolderModelMock.getCity()).thenReturn(CITY); when(businessStakeHolderModelMock.getStateProvince()).thenReturn(STATE_PROVINCE); when(businessStakeHolderModelMock.getCountry()).thenReturn(COUNTRY); when(businessStakeHolderModelMock.getPostalCode()).thenReturn(POSTAL_CODE); final HyperwalletBusinessStakeholder result = testObj.convert(businessStakeHolderModelMock); assertThat(result.getDateOfBirth()).isNull(); assertThat(result.getIsBusinessContact()).isTrue(); assertThat(result.getIsDirector()).isFalse(); assertThat(result.getIsUltimateBeneficialOwner()).isFalse(); assertThat(result.getIsSeniorManagingOfficial()).isTrue(); assertThat(result.getFirstName()).isEqualTo(FIRST_NAME); assertThat(result.getMiddleName()).isEqualTo(MIDDLE_NAME); assertThat(result.getLastName()).isEqualTo(LAST_NAME); assertThat(result.getCountryOfBirth()).isEqualTo(COUNTRY_OF_BIRTH); assertThat(result.getCountryOfNationality()).isEqualTo(COUNTRY_OF_NATIONALITY); assertThat(result.getGender().name()).isEqualTo(Gender.MALE.name()); assertThat(result.getPhoneNumber()).isEqualTo(PHONE_NUMBER); assertThat(result.getMobileNumber()).isEqualTo(MOBILE_NUMBER); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getGovernmentId()).isEqualTo(GOVERNMENT_ID); assertThat(result.getGovernmentIdType().name()).isEqualTo(NATIONAL_ID_CARD.name()); assertThat(result.getDriversLicenseId()).isEqualTo(DRIVERS_LICENSE_ID); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_1); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_2); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); } @Test void convert_shouldReturnHyperWalletBusinessStakeHolder_whenAnEnumIsNull() { when(businessStakeHolderModelMock.getGender()).thenReturn(null); when(businessStakeHolderModelMock.getBusinessContact()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getDirector()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getUbo()).thenReturn(Boolean.FALSE); when(businessStakeHolderModelMock.getSmo()).thenReturn(Boolean.TRUE); when(businessStakeHolderModelMock.getFirstName()).thenReturn(FIRST_NAME); when(businessStakeHolderModelMock.getMiddleName()).thenReturn(MIDDLE_NAME); when(businessStakeHolderModelMock.getLastName()).thenReturn(LAST_NAME); when(businessStakeHolderModelMock.getDateOfBirth()).thenReturn(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); when(businessStakeHolderModelMock.getCountryOfBirth()).thenReturn(COUNTRY_OF_BIRTH); when(businessStakeHolderModelMock.getCountryOfNationality()).thenReturn(COUNTRY_OF_NATIONALITY); when(businessStakeHolderModelMock.getPhoneNumber()).thenReturn(PHONE_NUMBER); when(businessStakeHolderModelMock.getMobileNumber()).thenReturn(MOBILE_NUMBER); when(businessStakeHolderModelMock.getEmail()).thenReturn(EMAIL); when(businessStakeHolderModelMock.getGovernmentId()).thenReturn(GOVERNMENT_ID); when(businessStakeHolderModelMock.getGovernmentIdType()).thenReturn(SellerGovernmentIdType.NATIONAL_ID_CARD); when(businessStakeHolderModelMock.getDriversLicenseId()).thenReturn(DRIVERS_LICENSE_ID); when(businessStakeHolderModelMock.getAddressLine1()).thenReturn(ADDRESS_LINE_1); when(businessStakeHolderModelMock.getAddressLine2()).thenReturn(ADDRESS_LINE_2); when(businessStakeHolderModelMock.getCity()).thenReturn(CITY); when(businessStakeHolderModelMock.getStateProvince()).thenReturn(STATE_PROVINCE); when(businessStakeHolderModelMock.getCountry()).thenReturn(COUNTRY); when(businessStakeHolderModelMock.getPostalCode()).thenReturn(POSTAL_CODE); final HyperwalletBusinessStakeholder result = testObj.convert(businessStakeHolderModelMock); assertThat(result.getGender()).isNull(); assertThat(result.getIsBusinessContact()).isTrue(); assertThat(result.getIsDirector()).isFalse(); assertThat(result.getIsUltimateBeneficialOwner()).isFalse(); assertThat(result.getIsSeniorManagingOfficial()).isTrue(); assertThat(result.getFirstName()).isEqualTo(FIRST_NAME); assertThat(result.getMiddleName()).isEqualTo(MIDDLE_NAME); assertThat(result.getLastName()).isEqualTo(LAST_NAME); assertThat(result.getDateOfBirth()).isEqualTo(DateUtil.convertToDate(DATE_OF_BIRTH, HyperWalletConstants.HYPERWALLET_DATE_FORMAT, TimeZone.getTimeZone("UTC"))); assertThat(result.getCountryOfBirth()).isEqualTo(COUNTRY_OF_BIRTH); assertThat(result.getCountryOfNationality()).isEqualTo(COUNTRY_OF_NATIONALITY); assertThat(result.getPhoneNumber()).isEqualTo(PHONE_NUMBER); assertThat(result.getMobileNumber()).isEqualTo(MOBILE_NUMBER); assertThat(result.getEmail()).isEqualTo(EMAIL); assertThat(result.getGovernmentId()).isEqualTo(GOVERNMENT_ID); assertThat(result.getGovernmentIdType().name()).isEqualTo(NATIONAL_ID_CARD.name()); assertThat(result.getDriversLicenseId()).isEqualTo(DRIVERS_LICENSE_ID); assertThat(result.getAddressLine1()).isEqualTo(ADDRESS_LINE_1); assertThat(result.getAddressLine2()).isEqualTo(ADDRESS_LINE_2); assertThat(result.getCity()).isEqualTo(CITY); assertThat(result.getStateProvince()).isEqualTo(STATE_PROVINCE); assertThat(result.getCountry()).isEqualTo(COUNTRY); assertThat(result.getPostalCode()).isEqualTo(POSTAL_CODE); } }
4,859
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/stakeholdersextraction/services/converters/ListAdditionalFieldValuesToBusinessStakeHolderModelConverterTest.java
package com.paypal.sellers.stakeholdersextraction.services.converters; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import com.paypal.sellers.stakeholdersextraction.services.converters.ListAdditionalFieldValuesToBusinessStakeHolderModelConverter; import org.apache.commons.lang3.tuple.Triple; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class ListAdditionalFieldValuesToBusinessStakeHolderModelConverterTest { private static final Integer BUSINESS_STAKE_HOLDER_NUMBER = 1; private static final String CLIENT_ID = "clientId1"; private static final String UTC = "UTC"; @Spy @InjectMocks private ListAdditionalFieldValuesToBusinessStakeHolderModelConverter testObj; @Mock private SellersMiraklApiConfig sellersMiraklApiConfigMock; @Mock private BusinessStakeHolderModel businessStakeHolderModelMock; @Mock private BusinessStakeHolderModel.BusinessStakeHolderModelBuilder businessStakeHolderModelBuilderMock; @Mock private MiraklAdditionalFieldValue miraklAdditionalFieldValueOneMock; @Test void convert_shouldReturnBusinessStakeHolderModelBasedOnValuesOfMiraklShop() { final List<MiraklAdditionalFieldValue> miraklAdditionalFieldValues = List.of(miraklAdditionalFieldValueOneMock); doReturn(businessStakeHolderModelBuilderMock).when(testObj).getBuilder(); when(sellersMiraklApiConfigMock.getTimeZone()).thenReturn(UTC); when(businessStakeHolderModelBuilderMock.timeZone(UTC)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.userToken(miraklAdditionalFieldValues)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.clientUserId(CLIENT_ID)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.token(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.businessContact(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.director(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.ubo(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.smo(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.firstName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.middleName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.lastName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.dateOfBirth(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.countryOfBirth(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.countryOfNationality(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.gender(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.phoneNumber(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.mobileNumber(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.email(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.governmentId(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.governmentIdType(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.driversLicenseId(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.addressLine1(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.addressLine2(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.city(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.stateProvince(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.country(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.postalCode(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER)) .thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.build()).thenReturn(businessStakeHolderModelMock); when(businessStakeHolderModelBuilderMock.stkId(1)).thenReturn(businessStakeHolderModelBuilderMock); when(businessStakeHolderModelBuilderMock.hyperwalletProgram(miraklAdditionalFieldValues)) .thenReturn(businessStakeHolderModelBuilderMock); final BusinessStakeHolderModel result = testObj .convert(Triple.of(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER, CLIENT_ID)); verifyAttributes(miraklAdditionalFieldValues); assertThat(result).isEqualTo(businessStakeHolderModelMock); } private void verifyAttributes(final List<MiraklAdditionalFieldValue> miraklAdditionalFieldValues) { verify(businessStakeHolderModelBuilderMock).userToken(miraklAdditionalFieldValues); verify(businessStakeHolderModelBuilderMock).hyperwalletProgram(miraklAdditionalFieldValues); verify(businessStakeHolderModelBuilderMock).clientUserId(CLIENT_ID); verify(businessStakeHolderModelBuilderMock).token(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).businessContact(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).director(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).ubo(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).smo(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).firstName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).middleName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).lastName(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).dateOfBirth(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).countryOfBirth(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).countryOfNationality(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).gender(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).phoneNumber(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).mobileNumber(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).email(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).governmentId(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).governmentIdType(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).driversLicenseId(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).addressLine1(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).addressLine2(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).city(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).stateProvince(miraklAdditionalFieldValues, BUSINESS_STAKE_HOLDER_NUMBER); verify(businessStakeHolderModelBuilderMock).timeZone(UTC); } @Test void getBuilder_shouldReturnAnBusinessStakeHolderModelBuilderInstance() { final BusinessStakeHolderModel.BusinessStakeHolderModelBuilder builder = testObj.getBuilder(); assertThat(builder).isInstanceOf(BusinessStakeHolderModel.BusinessStakeHolderModelBuilder.class); } }
4,860
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/IndividualSellersExtractionJobsConfigTest.java
package com.paypal.sellers.individualsellersextraction; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBean; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBuilder; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersRetryBatchJob; import com.paypal.sellers.individualsellersextraction.jobs.IndividualSellersExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.impl.triggers.CronTriggerImpl; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractionJobsConfigTest { private static final String CRON_EXPRESSION = "0 0 0 1/1 * ? *"; private static final String JOB_NAME = "IndividualSellersExtractJob"; private static final String INDIVIDUAL_SELLERS_EXTRACT_RETRY_JOB_IDENTITY = "IndividualSellersExtractRetryJob"; @InjectMocks private IndividualSellersExtractionJobsConfig testObj; @Mock private IndividualSellersRetryBatchJob individualSellersRetryBatchJobMock; @Test void extractSellersJob_createsJobDetailWithNameExtractSellersJobAndTypeExtractSellersJob() { final JobDetail result = testObj.sellerExtractJob(); assertThat(result.getJobClass()).hasSameClassAs(IndividualSellersExtractJob.class); assertThat(result.getKey().getName()).isEqualTo("IndividualSellersExtractJob"); } @Test void sellerExtractTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = JobBuilder.newJob(IndividualSellersExtractJob.class).withIdentity(JOB_NAME).build(); final Trigger result = testObj.sellerExtractTrigger(jobDetail, CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); } @Test void sellerExtractRetryJob_createsAIndividualSellersRetryBatchJobWithNameIndividualSellersExtractRetryJob() { final JobDetail result = testObj.sellerExtractRetryJob(individualSellersRetryBatchJobMock); assertThat(result.getJobClass()).hasSameClassAs(QuartzBatchJobBean.class); assertThat(result.getKey().getName()).isEqualTo(INDIVIDUAL_SELLERS_EXTRACT_RETRY_JOB_IDENTITY); assertThat(result.getJobDataMap()).containsEntry(QuartzBatchJobBean.KEY_BATCH_JOB_BEAN, individualSellersRetryBatchJobMock); } @Test void sellerExtractRetryTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = QuartzBatchJobBuilder.newJob(individualSellersRetryBatchJobMock) .withIdentity(INDIVIDUAL_SELLERS_EXTRACT_RETRY_JOB_IDENTITY).build(); final Trigger result = testObj.sellerExtractTrigger(jobDetail, CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(CRON_EXPRESSION); } }
4,861
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersRetryBatchJobTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJobItemProcessor; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractJobItem; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersRetryBatchJob; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersRetryBatchJobItemExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.AssertionsForClassTypes.assertThat; @ExtendWith(MockitoExtension.class) class IndividualSellersRetryBatchJobTest { @InjectMocks private IndividualSellersRetryBatchJob testObj; @Mock private IndividualSellersRetryBatchJobItemExtractor individualSellersRetryBatchJobItemExtractorMock; @Mock private IndividualSellersExtractBatchJobItemProcessor individualSellersExtractBatchJobItemProcessorMock; @Test void getBatchJobItemProcessor_ShouldReturnIndividualSellersExtractBatchJobItemProcessor() { final BatchJobItemProcessor<BatchJobContext, IndividualSellersExtractJobItem> result = testObj .getBatchJobItemProcessor(); assertThat(result).isEqualTo(individualSellersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_ShouldReturnIndividualSellersRetryBatchJobItemExtractor() { final BatchJobItemsExtractor<BatchJobContext, IndividualSellersExtractJobItem> result = testObj .getBatchJobItemsExtractor(); assertThat(result).isEqualTo(individualSellersRetryBatchJobItemExtractorMock); } }
4,862
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersExtractBatchJobItemsExtractorTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJobItemsExtractor; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.Date; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractBatchJobItemsExtractorTest { private static final Date DELTA = new Date(); @InjectMocks private IndividualSellersExtractBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private BatchJobContext batchJobContextMock; @Test void getItems_ShouldRetrieveAllSellersAndMapThemIntoIndividualSellersExtractJobItems() { final SellerModel sellerModel1 = SellerModel.builder().build(); final SellerModel sellerModel2 = SellerModel.builder().build(); when(miraklSellersExtractServiceMock.extractIndividuals(DELTA)).thenReturn(List.of(sellerModel1, sellerModel2)); final Collection<IndividualSellersExtractJobItem> individualSellersExtractJobItems = testObj .getItems(batchJobContextMock, DELTA); assertThat(individualSellersExtractJobItems.stream().map(IndividualSellersExtractJobItem::getItem)) .containsExactly(sellerModel1, sellerModel2); } }
4,863
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersExtractBatchJobTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJob; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJobItemProcessor; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractBatchJobTest { @InjectMocks private IndividualSellersExtractBatchJob testObj; @Mock private IndividualSellersExtractBatchJobItemProcessor individualSellersExtractBatchJobItemProcessorMock; @Mock private IndividualSellersExtractBatchJobItemsExtractor individualSellersExtractBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_ShouldReturnIndividualSellersExtractBatchJobItemProcessor() { assertThat(testObj.getBatchJobItemProcessor()).isEqualTo(individualSellersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_ShouldReturnIndividualSellersExtractBatchJobItemsExtractor() { assertThat(testObj.getBatchJobItemsExtractor()).isEqualTo(individualSellersExtractBatchJobItemsExtractorMock); } }
4,864
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersRetryBatchJobItemExtractorTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobItem; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractJobItem; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersRetryBatchJobItemExtractor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class IndividualSellersRetryBatchJobItemExtractorTest { private static final String SELLER_ID_1 = "1"; private static final String SELLER_ID_2 = "2"; @InjectMocks private IndividualSellersRetryBatchJobItemExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Test void getItems_ShouldReturnAllSellersByTheGivenIds() { when(miraklSellersExtractServiceMock.extractSellers(List.of(SELLER_ID_1, SELLER_ID_2))) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); final Collection<IndividualSellersExtractJobItem> result = testObj.getItems(List.of(SELLER_ID_1, SELLER_ID_2)); assertThat(result.stream().map(BatchJobItem::getItem).map(SellerModel.class::cast)) .containsExactlyInAnyOrder(sellerModelMock1, sellerModelMock2); } }
4,865
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersExtractBatchJobItemProcessorTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.infrastructure.support.services.TokenSynchronizationService; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.strategies.HyperWalletUserServiceStrategyExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractBatchJobItemProcessorTest { @InjectMocks private IndividualSellersExtractBatchJobItemProcessor testObj; @Mock private HyperWalletUserServiceStrategyExecutor hyperWalletUserServiceStrategyExecutorMock; @Mock private TokenSynchronizationService<SellerModel> tokenSynchronizationServiceMock; @Mock private BatchJobContext batchJobContextMock; private SellerModel sellerModel; private IndividualSellersExtractJobItem individualSellersExtractJobItem; @BeforeEach void setUp() { sellerModel = SellerModel.builder().build(); individualSellersExtractJobItem = new IndividualSellersExtractJobItem(sellerModel); when(tokenSynchronizationServiceMock.synchronizeToken(sellerModel)).thenReturn(sellerModel); } @Test void processItem_ShouldAlwaysExecuteHyperWalletUserServiceStrategyExecutor() { when(hyperWalletUserServiceStrategyExecutorMock.execute(sellerModel)).thenReturn(sellerModel); testObj.processItem(batchJobContextMock, individualSellersExtractJobItem); verify(hyperWalletUserServiceStrategyExecutorMock).execute(sellerModel); } @Test void processItem_shouldSynchronizeSellerBetweenHyperwalletAndMirakl() { when(hyperWalletUserServiceStrategyExecutorMock.execute(sellerModel)).thenReturn(sellerModel); testObj.processItem(batchJobContextMock, individualSellersExtractJobItem); verify(tokenSynchronizationServiceMock).synchronizeToken(sellerModel); } }
4,866
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/batchjobs/IndividualSellersExtractJobItemTest.java
package com.paypal.sellers.individualsellersextraction.batchjobs; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import static org.assertj.core.api.Assertions.assertThat; class IndividualSellersExtractJobItemTest { private static final String CLIENT_USER_ID = "clientUserId"; private static final String INDIVIDUAL_SELLER = "IndividualSeller"; @Test void getItemId_ShouldReturnItemId() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final IndividualSellersExtractJobItem testObj = new IndividualSellersExtractJobItem(sellerModel); assertThat(testObj.getItemId()).isEqualTo(CLIENT_USER_ID); } @Test void getItemType_ShouldReturnItemType() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final IndividualSellersExtractJobItem testObj = new IndividualSellersExtractJobItem(sellerModel); assertThat(testObj.getItemType()).isEqualTo(INDIVIDUAL_SELLER); } }
4,867
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/jobs/IndividualSellersExtractJobTest.java
package com.paypal.sellers.individualsellersextraction.jobs; import com.paypal.jobsystem.batchjob.model.BatchJob; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobAdapterFactory; import com.paypal.sellers.individualsellersextraction.batchjobs.IndividualSellersExtractBatchJob; import com.paypal.sellers.individualsellersextraction.jobs.IndividualSellersExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractJobTest { @InjectMocks @Spy private MyIndividualSellersExtractJob testObj; @Mock private IndividualSellersExtractBatchJob individualSellersExtractBatchJobMock; @Mock private JobExecutionContext jobContextMock; @Test void execute_shouldCallIndividualSellerExtractBatchJob() throws JobExecutionException { doNothing().when(testObj).executeBatchJob(individualSellersExtractBatchJobMock, jobContextMock); testObj.execute(jobContextMock); verify(testObj).executeBatchJob(individualSellersExtractBatchJobMock, jobContextMock); } static class MyIndividualSellersExtractJob extends IndividualSellersExtractJob { public MyIndividualSellersExtractJob(final QuartzBatchJobAdapterFactory quartzBatchJobAdapterFactory, final IndividualSellersExtractBatchJob individualSellersExtractBatchJob) { super(quartzBatchJobAdapterFactory, individualSellersExtractBatchJob); } @Override protected void executeBatchJob(final BatchJob batchJob, final JobExecutionContext context) throws JobExecutionException { super.executeBatchJob(batchJob, context); } } }
4,868
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/controllers/IndividualSellersExtractJobControllerTest.java
package com.paypal.sellers.individualsellersextraction.controllers; import com.paypal.jobsystem.quartzintegration.support.AbstractDeltaInfoJob; import com.paypal.jobsystem.quartzintegration.services.JobService; import com.paypal.infrastructure.support.date.DateUtil; import com.paypal.infrastructure.support.date.TimeMachine; import com.paypal.sellers.individualsellersextraction.controllers.IndividualSellersExtractJobController; import com.paypal.sellers.individualsellersextraction.jobs.IndividualSellersExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.SchedulerException; import java.time.LocalDateTime; import java.time.ZoneId; import java.util.Date; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class IndividualSellersExtractJobControllerTest { private static final String JOB_NAME = "jobName"; @InjectMocks private IndividualSellersExtractJobController testObj; @Mock private JobService jobService; @Test void runJob_shouldCallJobServiceWithValuesPassedAsParam() throws SchedulerException { TimeMachine.useFixedClockAt(LocalDateTime.of(2020, 11, 10, 20, 45)); final LocalDateTime now = TimeMachine.now(); final Date delta = DateUtil.convertToDate(now, ZoneId.systemDefault()); testObj.runJob(delta, "jobName"); verify(jobService).createAndRunSingleExecutionJob(JOB_NAME, IndividualSellersExtractJob.class, AbstractDeltaInfoJob.createJobDataMap(delta), null); } }
4,869
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/individualsellersextraction/services/converters/MiraklShopToIndividualSellerModelConverterTest.java
package com.paypal.sellers.individualsellersextraction.services.converters; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.individualsellersextraction.services.converters.MiraklShopToIndividualSellerModelConverter; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.model.SellerProfileType; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class MiraklShopToIndividualSellerModelConverterTest { @Spy @InjectMocks private MyMiraklShopToIndividualSellerModelConverter testObj; @Mock private MiraklShop miraklShopMock; @Test void execute_shouldSetProfileTypeToIndividual() { final SellerModel.SellerModelBuilder sellerModelBuilderStub = SellerModel.builder(); doReturn(sellerModelBuilderStub).when(testObj).getCommonFieldsBuilder(miraklShopMock); final SellerModel result = testObj.execute(miraklShopMock); verify(testObj).getCommonFieldsBuilder(miraklShopMock); assertThat(result.getProfileType()).isEqualTo(SellerProfileType.INDIVIDUAL); } @Test void isApplicable_shouldReturnTrueWhenMiraklShopIsNotProfessional() { when(miraklShopMock.isProfessional()).thenReturn(false); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenMiraklShopIsProfessional() { when(miraklShopMock.isProfessional()).thenReturn(true); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } static class MyMiraklShopToIndividualSellerModelConverter extends MiraklShopToIndividualSellerModelConverter { protected MyMiraklShopToIndividualSellerModelConverter( final StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor, final SellersMiraklApiConfig sellersMiraklApiConfig) { super(miraklShopBankAccountModelStrategyExecutor, sellersMiraklApiConfig); } @Override public SellerModel.SellerModelBuilder getCommonFieldsBuilder(final MiraklShop source) { return super.getCommonFieldsBuilder(source); } } }
4,870
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/ProfessionalSellersExtractionJobsConfigTest.java
package com.paypal.sellers.professionalsellersextraction; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBean; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersRetryBatchJob; import com.paypal.sellers.professionalsellersextraction.jobs.ProfessionalSellersExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobBuilder; import org.quartz.JobDetail; import org.quartz.Trigger; import org.quartz.TriggerKey; import org.quartz.impl.triggers.CronTriggerImpl; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractionJobsConfigTest { private static final String CRON_EXPRESSION = "0 0 0 1/1 * ? *"; private static final String RETRY_CRON_EXPRESSION = "0 0/15 * ? * * *"; private static final String TRIGGER_PREFIX = "Trigger"; private static final String JOB_NAME = "ProfessionalSellersExtractJob"; private static final String RETRY_JOB_NAME = "ProfessionalSellersRetryJob"; @InjectMocks private ProfessionalSellersExtractionJobsConfig testObj; @Mock private ProfessionalSellersRetryBatchJob professionalSellersRetryBatchJob; @Test void extractSellersJob_createsJobDetailWithNameExtractProfessionalSellersJobAndTypeExtractProfessionalSellersJob() { final JobDetail result = this.testObj.professionalSellerExtractJob(); assertThat(result.getJobClass()).hasSameClassAs(ProfessionalSellersExtractJob.class); assertThat(result.getKey().getName()).isEqualTo("ProfessionalSellersExtractJob"); } @Test void sellerExtractTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = JobBuilder.newJob(ProfessionalSellersExtractJob.class).withIdentity(JOB_NAME) .build(); final Trigger result = this.testObj.professionalSellerExtractTrigger(jobDetail, CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(result.getKey()).isEqualTo(TriggerKey.triggerKey(TRIGGER_PREFIX + JOB_NAME)); assertThat(result).isInstanceOf(CronTriggerImpl.class); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(CRON_EXPRESSION); } @Test void extractSellersRetryJob_createsJobDetailWithNameRetryProfessionalSellersJobAndProfessionalSellersRetryBatchJob() { final JobDetail result = testObj.professionalSellerRetryJob(professionalSellersRetryBatchJob); assertThat(result.getJobClass()).hasSameClassAs(QuartzBatchJobBean.class); assertThat(result.getKey().getName()).isEqualTo(RETRY_JOB_NAME); assertThat(result.getJobDataMap()).containsEntry("batchJob", professionalSellersRetryBatchJob); } @Test void sellerRetryTrigger_shouldReturnATriggerCreatedWithTheCronExpressionPassedAsArgumentAndJob() { final JobDetail jobDetail = testObj.professionalSellerRetryJob(professionalSellersRetryBatchJob); final Trigger result = testObj.professionalSellerRetryTrigger(jobDetail, RETRY_CRON_EXPRESSION); assertThat(result.getJobKey()).isEqualTo(jobDetail.getKey()); assertThat(result.getKey()).isEqualTo(TriggerKey.triggerKey(TRIGGER_PREFIX + RETRY_JOB_NAME)); assertThat(result).isInstanceOf(CronTriggerImpl.class); assertThat(((CronTriggerImpl) result).getCronExpression()).isEqualTo(RETRY_CRON_EXPRESSION); } }
4,871
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellerExtractJobItemTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellerExtractJobItem; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class ProfessionalSellerExtractJobItemTest { private static final String CLIENT_USER_ID = "clientUserId"; private static final String PROFESSIONAL_SELLER = "ProfessionalSeller"; @Test void getItemId_ShouldReturnClientUserId() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final ProfessionalSellerExtractJobItem testObj = new ProfessionalSellerExtractJobItem(sellerModel); assertThat(testObj.getItemId()).isEqualTo(CLIENT_USER_ID); } @Test void getItemType_ShouldReturnProfessionalSeller() { final SellerModel sellerModel = SellerModel.builder().clientUserId(CLIENT_USER_ID).build(); final ProfessionalSellerExtractJobItem testObj = new ProfessionalSellerExtractJobItem(sellerModel); assertThat(testObj.getItemId()).isEqualTo(CLIENT_USER_ID); assertThat(testObj.getItemType()).isEqualTo(PROFESSIONAL_SELLER); } }
4,872
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellersExtractBatchJobItemsExtractorTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellerExtractJobItem; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJobItemsExtractor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.Date; import java.util.List; import java.util.stream.Collectors; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractBatchJobItemsExtractorTest { private static final Date DELTA = new Date(); @InjectMocks private ProfessionalSellersExtractBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Mock private BatchJobContext batchJobContextMock; @Test void getItems_ShouldReturnProfessionalSellersExtractJobItems() { when(miraklSellersExtractServiceMock.extractProfessionals(DELTA)) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); final Collection<ProfessionalSellerExtractJobItem> result = testObj.getItems(batchJobContextMock, DELTA); assertThat(result.stream().map(ProfessionalSellerExtractJobItem::getItem).collect(Collectors.toList())) .containsExactlyInAnyOrder(sellerModelMock1, sellerModelMock2); } }
4,873
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellersRetryBatchJobTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJobItemProcessor; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersRetryBatchJob; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersRetryBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.mockito.InjectMocks; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class ProfessionalSellersRetryBatchJobTest { @InjectMocks private ProfessionalSellersRetryBatchJob testObj; @Mock private ProfessionalSellersExtractBatchJobItemProcessor professionalSellersExtractBatchJobItemProcessorMock; @Mock private ProfessionalSellersRetryBatchJobItemsExtractor professionalSellersRetryBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_shouldReturnBatchJobItemProcessor() { assertThat(testObj.getBatchJobItemProcessor()).isEqualTo(professionalSellersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_shouldReturnRetryBatchJobItemExtractor() { assertThat(testObj.getBatchJobItemsExtractor()).isEqualTo(professionalSellersRetryBatchJobItemsExtractorMock); } }
4,874
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellersExtractBatchJobTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemProcessor; import com.paypal.jobsystem.batchjobsupport.model.BatchJobItemsExtractor; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellerExtractJobItem; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJob; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJobItemProcessor; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJobItemsExtractor; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.assertj.core.api.Assertions.assertThat; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractBatchJobTest { @InjectMocks private ProfessionalSellersExtractBatchJob testObj; @Mock private ProfessionalSellersExtractBatchJobItemProcessor professionalSellersExtractBatchJobItemProcessorMock; @Mock private ProfessionalSellersExtractBatchJobItemsExtractor professionalSellersExtractBatchJobItemsExtractorMock; @Test void getBatchJobItemProcessor_ShouldReturnProfessionalSellersExtractBatchJobItemProcessor() { final BatchJobItemProcessor<BatchJobContext, ProfessionalSellerExtractJobItem> result = testObj .getBatchJobItemProcessor(); assertThat(result).isEqualTo(professionalSellersExtractBatchJobItemProcessorMock); } @Test void getBatchJobItemsExtractor_ShouldReturnBusinessStakeholdersExtractBatchJobItemsExtractor() { final BatchJobItemsExtractor<BatchJobContext, ProfessionalSellerExtractJobItem> result = testObj .getBatchJobItemsExtractor(); assertThat(result).isEqualTo(professionalSellersExtractBatchJobItemsExtractorMock); } }
4,875
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellersRetryBatchJobItemsExtractorTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobItem; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellerExtractJobItem; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersRetryBatchJobItemsExtractor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import java.util.Collection; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class ProfessionalSellersRetryBatchJobItemsExtractorTest { private static final String SELLER_ID_1 = "1"; private static final String SELLER_ID_2 = "2"; @InjectMocks private ProfessionalSellersRetryBatchJobItemsExtractor testObj; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private SellerModel sellerModelMock1, sellerModelMock2; @Test void getItem_shouldReturnProfessionalSellerType() { final String result = testObj.getItemType(); assertThat(result).isEqualTo(ProfessionalSellerExtractJobItem.ITEM_TYPE); } @SuppressWarnings("uncheked") @Test void getItems_ShouldReturnAllProfessionalSellersByTheGivenIds() { when(miraklSellersExtractServiceMock.extractProfessionals(List.of(SELLER_ID_1, SELLER_ID_2))) .thenReturn(List.of(sellerModelMock1, sellerModelMock2)); final Collection<ProfessionalSellerExtractJobItem> result = testObj.getItems(List.of(SELLER_ID_1, SELLER_ID_2)); assertThat(result.stream().map(BatchJobItem::getItem).map(SellerModel.class::cast)) .containsExactlyInAnyOrder(sellerModelMock1, sellerModelMock2); } }
4,876
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/batchjobs/ProfessionalSellersExtractBatchJobItemProcessorTest.java
package com.paypal.sellers.professionalsellersextraction.batchjobs; import com.paypal.jobsystem.batchjob.model.BatchJobContext; import com.paypal.infrastructure.support.services.TokenSynchronizationService; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import com.paypal.sellers.sellerextractioncommons.services.strategies.HyperWalletUserServiceStrategyExecutor; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import static org.mockito.Mockito.verify; import static org.mockito.Mockito.when; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractBatchJobItemProcessorTest { @InjectMocks private ProfessionalSellersExtractBatchJobItemProcessor testObj; @Mock private HyperWalletUserServiceStrategyExecutor hyperWalletUserServiceStrategyExecutorMock; @Mock private MiraklSellersExtractService miraklSellersExtractServiceMock; @Mock private TokenSynchronizationService<SellerModel> tokenSynchronizationServiceMock; @Mock private BatchJobContext batchJobContextMock; private SellerModel sellerModel; private ProfessionalSellerExtractJobItem professionalSellerExtractJobItem; @BeforeEach void setUp() { sellerModel = SellerModel.builder().build(); professionalSellerExtractJobItem = new ProfessionalSellerExtractJobItem(sellerModel); when(tokenSynchronizationServiceMock.synchronizeToken(sellerModel)).thenReturn(sellerModel); } @Test void processItem_ShouldAlwaysExecuteHyperWalletUserServiceStrategyExecutor() { when(hyperWalletUserServiceStrategyExecutorMock.execute(sellerModel)).thenReturn(sellerModel); testObj.processItem(batchJobContextMock, professionalSellerExtractJobItem); verify(hyperWalletUserServiceStrategyExecutorMock).execute(sellerModel); } @Test void processItem_shouldSynchronizeSellerBetweenHyperwalletAndMirakl() { when(hyperWalletUserServiceStrategyExecutorMock.execute(sellerModel)).thenReturn(sellerModel); testObj.processItem(batchJobContextMock, professionalSellerExtractJobItem); verify(tokenSynchronizationServiceMock).synchronizeToken(sellerModel); } }
4,877
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/jobs/ProfessionalSellersExtractJobTest.java
package com.paypal.sellers.professionalsellersextraction.jobs; import com.paypal.jobsystem.batchjob.model.BatchJob; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobAdapterFactory; import com.paypal.sellers.stakeholdersextraction.batchjobs.BusinessStakeholdersExtractBatchJob; import com.paypal.sellers.professionalsellersextraction.batchjobs.ProfessionalSellersExtractBatchJob; import com.paypal.sellers.professionalsellersextraction.jobs.ProfessionalSellersExtractJob; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.JobExecutionContext; import org.quartz.JobExecutionException; import static org.mockito.Mockito.doNothing; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractJobTest { @InjectMocks @Spy private MyProfessionalSellersExtractJob testObj; @Mock private ProfessionalSellersExtractBatchJob professionalSellersExtractBatchJob; @Mock private BusinessStakeholdersExtractBatchJob businessStakeholdersExtractBatchJobMock; @Mock private JobExecutionContext jobExecutionContextMock; @Test void execute_ShouldCallProfessionalSellersExtractBatchJob() throws JobExecutionException { doNothing().when(testObj).executeBatchJob(professionalSellersExtractBatchJob, jobExecutionContextMock); doNothing().when(testObj).executeBatchJob(businessStakeholdersExtractBatchJobMock, jobExecutionContextMock); testObj.execute(jobExecutionContextMock); verify(testObj).executeBatchJob(professionalSellersExtractBatchJob, jobExecutionContextMock); verify(testObj).executeBatchJob(businessStakeholdersExtractBatchJobMock, jobExecutionContextMock); } static class MyProfessionalSellersExtractJob extends ProfessionalSellersExtractJob { public MyProfessionalSellersExtractJob(final QuartzBatchJobAdapterFactory quartzBatchJobAdapterFactory, final ProfessionalSellersExtractBatchJob professionalSellersExtractBatchJob, final BusinessStakeholdersExtractBatchJob businessStakeholdersExtractBatchJob) { super(quartzBatchJobAdapterFactory, professionalSellersExtractBatchJob, businessStakeholdersExtractBatchJob); } @Override protected void executeBatchJob(final BatchJob batchJob, final JobExecutionContext context) throws JobExecutionException { super.executeBatchJob(batchJob, context); } } }
4,878
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/controllers/ProfessionalSellersExtractJobControllerTest.java
package com.paypal.sellers.professionalsellersextraction.controllers; import com.paypal.jobsystem.quartzintegration.support.AbstractDeltaInfoJob; import com.paypal.jobsystem.quartzintegration.services.JobService; import com.paypal.sellers.professionalsellersextraction.jobs.ProfessionalSellersExtractJob; import com.paypal.sellers.professionalsellersextraction.controllers.ProfessionalSellersExtractJobController; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.junit.jupiter.MockitoExtension; import org.quartz.SchedulerException; import java.util.Date; import static org.mockito.Mockito.verify; @ExtendWith(MockitoExtension.class) class ProfessionalSellersExtractJobControllerTest { private static final String JOB_NAME = "jobName"; @InjectMocks private ProfessionalSellersExtractJobController testObj; @Mock private JobService jobService; @Mock private Date deltaMock; @Test void runJob_shouldCallJobServiceWithValuesPassedAsParam() throws SchedulerException { this.testObj.runJob(this.deltaMock, "jobName"); verify(this.jobService).createAndRunSingleExecutionJob(JOB_NAME, ProfessionalSellersExtractJob.class, AbstractDeltaInfoJob.createJobDataMap(this.deltaMock), null); } }
4,879
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/test/java/com/paypal/sellers/professionalsellersextraction/services/converters/MiraklShopToProfessionalSellerModelConverterTest.java
package com.paypal.sellers.professionalsellersextraction.services.converters; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.shop.MiraklProfessionalInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.model.SellerProfileType; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import org.apache.commons.lang3.tuple.Triple; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.extension.ExtendWith; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; import org.mockito.junit.jupiter.MockitoExtension; import java.util.List; import static com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue; import static org.assertj.core.api.Assertions.assertThat; import static org.mockito.Mockito.*; @ExtendWith(MockitoExtension.class) class MiraklShopToProfessionalSellerModelConverterTest { private static final String CORP_NAME = "Globex Corporation"; private static final String IDENTIFICATION_NUMBER = "123478532"; private static final String VAT_NUMBER = "vatNumber"; private static final String CLIENT_ID_1 = "clientID1"; private static final String STATE_PROVINCE_VALUE = "stateProvince"; @Spy @InjectMocks private MyMiraklShopToProfessionalSellerModelConverter testObj; @Mock private MiraklShop miraklShopMock; @Mock private Converter<Triple<List<MiraklAdditionalFieldValue>, Integer, String>, BusinessStakeHolderModel> businessStakeHolderModelConverterMock; @Mock private MiraklProfessionalInformation miraklProfessionalInformationMock; @Mock private MiraklAdditionalFieldValue tokenOneAdditionalFieldMock, businessOneAdditionalFieldMock, directorOneAdditionalFieldMock, uboOneAdditionalFieldMock, smoOneAdditionalFieldMock, firstNameOneAdditionalFieldMock, middleNameOneAdditionalFieldMock, lastNameOneAdditionalFieldMock, dobOneAdditionalFieldMock, countryOfBirthOneAdditionalFieldMock, nationalityOneAdditionalFieldMock, genderOneAdditionalFieldMock, phoneNumberOneAdditionalFieldMock, mobileNumberOneAdditionalFieldMock, emailOneAdditionalFieldMock, addressLine1OneAdditionalFieldMock, addressLine2OneAdditionalFieldMock, cityOneAdditionalFieldMock, stateOneAdditionalFieldMock, postCodeOneAdditionalFieldMock, countryOneAdditionalFieldMock, governmentIdTypeOneAdditionalFieldMock, governmentIdNumOneAdditionalFieldMock, governmentIdCountOneAdditionalFieldMock, driversLicenseOneNumAdditionalFieldMock, driversLicenseCntOneAdditionalFieldMock; @Mock private MiraklAdditionalFieldValue tokenTwoAdditionalFieldMock, businessTwoAdditionalFieldMock, directorTwoAdditionalFieldMock, uboTwoAdditionalFieldMock, smoTwoAdditionalFieldMock, firstNameTwoAdditionalFieldMock, middleNameTwoAdditionalFieldMock, lastNameTwoAdditionalFieldMock, dobTwoAdditionalFieldMock, countryOfBirthTwoAdditionalFieldMock, nationalityTwoAdditionalFieldMock, genderTwoAdditionalFieldMock, phTwoNumberTwoAdditionalFieldMock, mobileNumberTwoAdditionalFieldMock, emailTwoAdditionalFieldMock, addressLine1TwoAdditionalFieldMock, addressLine2TwoAdditionalFieldMock, cityTwoAdditionalFieldMock, stateTwoAdditionalFieldMock, postCodeTwoAdditionalFieldMock, countryTwoAdditionalFieldMock, governmentIdTypeTwoAdditionalFieldMock, governmentIdNumTwoAdditionalFieldMock, governmentIdCountTwoAdditionalFieldMock, driversLicenseTwoNumAdditionalFieldMock, driversLicenseCntTwoAdditionalFieldMock; @Mock private BusinessStakeHolderModel businessStakeHolderModelOneMock, businessStakeHolderModelTwoMock; @Test void execute_shouldSetProfileTypeToIndividual() { when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(CORP_NAME); when(miraklProfessionalInformationMock.getIdentificationNumber()).thenReturn(IDENTIFICATION_NUMBER); when(miraklProfessionalInformationMock.getTaxIdentificationNumber()).thenReturn(VAT_NUMBER); final MiraklStringAdditionalFieldValue businessRegistrationStateProvinceMiraklCustomField = new MiraklStringAdditionalFieldValue(); businessRegistrationStateProvinceMiraklCustomField.setCode("hw-business-reg-state-province"); businessRegistrationStateProvinceMiraklCustomField.setValue(STATE_PROVINCE_VALUE); final MiraklStringAdditionalFieldValue businessRegistrationCountryMiraklCustomField = new MiraklStringAdditionalFieldValue(); businessRegistrationCountryMiraklCustomField.setCode("hw-business-reg-country"); businessRegistrationCountryMiraklCustomField.setValue("US"); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(List .of(businessRegistrationStateProvinceMiraklCustomField, businessRegistrationCountryMiraklCustomField)); final SellerModel.SellerModelBuilder sellerModelBuilderStub = SellerModel.builder(); doReturn(sellerModelBuilderStub).when(testObj).getCommonFieldsBuilder(miraklShopMock); final SellerModel result = testObj.execute(miraklShopMock); verify(testObj).getCommonFieldsBuilder(miraklShopMock); assertThat(result.getProfileType()).isEqualTo(SellerProfileType.BUSINESS); assertThat(result.getCompanyName()).isEqualTo(CORP_NAME); assertThat(result.getCompanyRegistrationNumber()).isEqualTo(IDENTIFICATION_NUMBER); assertThat(result.getVatNumber()).isEqualTo(VAT_NUMBER); assertThat(result.getBusinessRegistrationStateProvince()).isEqualTo(STATE_PROVINCE_VALUE); assertThat(result.getCompanyRegistrationCountry()).isEqualTo("US"); } @Test void execute_shouldConvertMiraklBusinessStakeHolderAttributesIntoListOfBusinessStakeHolderModel() { when(miraklShopMock.getProfessionalInformation()).thenReturn(miraklProfessionalInformationMock); when(miraklProfessionalInformationMock.getCorporateName()).thenReturn(CORP_NAME); when(miraklShopMock.getId()).thenReturn(CLIENT_ID_1); when(miraklProfessionalInformationMock.getIdentificationNumber()).thenReturn(IDENTIFICATION_NUMBER); when(miraklProfessionalInformationMock.getTaxIdentificationNumber()).thenReturn(VAT_NUMBER); final List<MiraklAdditionalFieldValue> additionalFieldValues = List.of(tokenOneAdditionalFieldMock, businessOneAdditionalFieldMock, directorOneAdditionalFieldMock, uboOneAdditionalFieldMock, smoOneAdditionalFieldMock, firstNameOneAdditionalFieldMock, middleNameOneAdditionalFieldMock, lastNameOneAdditionalFieldMock, dobOneAdditionalFieldMock, countryOfBirthOneAdditionalFieldMock, nationalityOneAdditionalFieldMock, genderOneAdditionalFieldMock, phoneNumberOneAdditionalFieldMock, mobileNumberOneAdditionalFieldMock, emailOneAdditionalFieldMock, addressLine1OneAdditionalFieldMock, addressLine2OneAdditionalFieldMock, cityOneAdditionalFieldMock, stateOneAdditionalFieldMock, postCodeOneAdditionalFieldMock, countryOneAdditionalFieldMock, governmentIdTypeOneAdditionalFieldMock, governmentIdNumOneAdditionalFieldMock, governmentIdCountOneAdditionalFieldMock, driversLicenseOneNumAdditionalFieldMock, driversLicenseCntOneAdditionalFieldMock, tokenTwoAdditionalFieldMock, businessTwoAdditionalFieldMock, directorTwoAdditionalFieldMock, uboTwoAdditionalFieldMock, smoTwoAdditionalFieldMock, firstNameTwoAdditionalFieldMock, middleNameTwoAdditionalFieldMock, lastNameTwoAdditionalFieldMock, dobTwoAdditionalFieldMock, countryOfBirthTwoAdditionalFieldMock, nationalityTwoAdditionalFieldMock, genderTwoAdditionalFieldMock, phTwoNumberTwoAdditionalFieldMock, mobileNumberTwoAdditionalFieldMock, emailTwoAdditionalFieldMock, addressLine1TwoAdditionalFieldMock, addressLine2TwoAdditionalFieldMock, cityTwoAdditionalFieldMock, stateTwoAdditionalFieldMock, postCodeTwoAdditionalFieldMock, countryTwoAdditionalFieldMock, governmentIdTypeTwoAdditionalFieldMock, governmentIdNumTwoAdditionalFieldMock, governmentIdCountTwoAdditionalFieldMock, driversLicenseTwoNumAdditionalFieldMock, driversLicenseCntTwoAdditionalFieldMock); when(miraklShopMock.getAdditionalFieldValues()).thenReturn(additionalFieldValues) .thenReturn(additionalFieldValues).thenReturn(additionalFieldValues).thenReturn(additionalFieldValues) .thenReturn(additionalFieldValues).thenReturn(List.of()); when(businessStakeHolderModelConverterMock.convert(Triple.of(additionalFieldValues, 1, CLIENT_ID_1))) .thenReturn(businessStakeHolderModelOneMock); when(businessStakeHolderModelConverterMock.convert(Triple.of(additionalFieldValues, 2, CLIENT_ID_1))) .thenReturn(businessStakeHolderModelTwoMock); final SellerModel.SellerModelBuilder sellerModelBuilderStub = SellerModel.builder(); doReturn(sellerModelBuilderStub).when(testObj).getCommonFieldsBuilder(miraklShopMock); final BusinessStakeHolderModel.BusinessStakeHolderModelBuilder businessStakeHolderModelBuilder = BusinessStakeHolderModel .builder(); doReturn(businessStakeHolderModelBuilder).when(businessStakeHolderModelOneMock).toBuilder(); doReturn(businessStakeHolderModelBuilder).when(businessStakeHolderModelTwoMock).toBuilder(); testObj.execute(miraklShopMock); verify(businessStakeHolderModelConverterMock).convert(Triple.of(additionalFieldValues, 1, CLIENT_ID_1)); verify(businessStakeHolderModelConverterMock).convert(Triple.of(additionalFieldValues, 2, CLIENT_ID_1)); verify(businessStakeHolderModelConverterMock).convert(Triple.of(additionalFieldValues, 3, CLIENT_ID_1)); verify(businessStakeHolderModelConverterMock).convert(Triple.of(additionalFieldValues, 4, CLIENT_ID_1)); verify(businessStakeHolderModelConverterMock).convert(Triple.of(additionalFieldValues, 5, CLIENT_ID_1)); } @Test void isApplicable_shouldReturnTrueWhenMiraklShopIsProfessional() { when(miraklShopMock.isProfessional()).thenReturn(true); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isTrue(); } @Test void isApplicable_shouldReturnFalseWhenMiraklShopIsNotProfessional() { when(miraklShopMock.isProfessional()).thenReturn(false); final boolean result = testObj.isApplicable(miraklShopMock); assertThat(result).isFalse(); } static class MyMiraklShopToProfessionalSellerModelConverter extends MiraklShopToProfessionalSellerModelConverter { protected MyMiraklShopToProfessionalSellerModelConverter( final StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor, final Converter<Triple<List<MiraklAdditionalFieldValue>, Integer, String>, BusinessStakeHolderModel> pairBusinessStakeHolderModelConverter, final SellersMiraklApiConfig sellersMiraklApiConfig) { super(miraklShopBankAccountModelStrategyExecutor, pairBusinessStakeHolderModelConverter, sellersMiraklApiConfig); } @Override public SellerModel.SellerModelBuilder getCommonFieldsBuilder(final MiraklShop source) { return super.getCommonFieldsBuilder(source); } } }
4,880
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/SellersConfiguration.java
package com.paypal.sellers; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import org.springframework.boot.context.properties.EnableConfigurationProperties; import org.springframework.context.annotation.ComponentScan; @ComponentScan @EnableConfigurationProperties({ SellersMiraklApiConfig.class }) public class SellersConfiguration { }
4,881
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/configuration/SellersMiraklApiConfig.java
package com.paypal.sellers.sellerextractioncommons.configuration; import lombok.Data; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Component; /** * Configuration class to instantiate Mirakl API client */ @Data @Component public class SellersMiraklApiConfig { @Value("${hmc.mirakl.settings.timezone}") private String timeZone; }
4,882
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerGovernmentIdType.java
package com.paypal.sellers.sellerextractioncommons.model; public enum SellerGovernmentIdType { PASSPORT, NATIONAL_ID_CARD }
4,883
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerModel.java
package com.paypal.sellers.sellerextractioncommons.model; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.infrastructure.support.countries.CountriesUtil; import com.paypal.sellers.stakeholdersextraction.model.BusinessStakeHolderModel; import lombok.Builder; import lombok.Getter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.EnumUtils; import org.apache.commons.lang3.builder.EqualsBuilder; import org.apache.commons.lang3.builder.HashCodeBuilder; import java.time.Instant; import java.time.ZoneId; import java.time.ZoneOffset; import java.time.ZonedDateTime; import java.util.*; import java.util.concurrent.TimeUnit; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.*; @Slf4j @Getter @Builder public class SellerModel { protected final String timeZone; private final String clientUserId; private final String firstName; private final String lastName; private final Date dateOfBirth; private final String countryOfBirth; private final String countryOfNationality; private final String gender; private final String phoneNumber; private final String mobilePhone; private final String email; private final String governmentId; private final SellerGovernmentIdType governmentIdType; private final String passportId; private final String driversLicenseId; private final String addressLine1; private final String addressLine2; private final String city; private final String stateProvince; private final String country; private final String postalCode; private final String language; private final String programToken; private final SellerBusinessType businessType; private final String businessName; private final String token; private final BankAccountModel bankAccountDetails; private final SellerProfileType profileType; private final String companyName; private final String companyRegistrationNumber; private final String companyRegistrationCountry; private final String businessRegistrationStateProvince; private final String vatNumber; private final boolean hwTermsConsent; private final List<BusinessStakeHolderModel> businessStakeHolderDetails; private final String hyperwalletProgram; public SellerModelBuilder toBuilder() { //@formatter:off return SellerModel.builder() .clientUserId(clientUserId) .firstName(firstName) .lastName(lastName) .timeZone(timeZone) .dateOfBirth(dateOfBirth) .countryOfBirth(countryOfBirth) .countryOfNationality(countryOfNationality) .gender(gender) .phoneNumber(phoneNumber) .mobilePhone(mobilePhone) .email(email) .governmentId(governmentId) .governmentIdType(governmentIdType) .passportId(passportId) .driversLicenseId(driversLicenseId) .addressLine1(addressLine1) .addressLine2(addressLine2) .city(city) .stateProvince(stateProvince) .internalBusinessRegistrationStateProvince(businessRegistrationStateProvince) .internalCountry(country) .internalCompanyRegistrationCountry(companyRegistrationCountry) .postalCode(postalCode) .language(language) .programToken(programToken) .businessType(businessType) .businessName(businessName) .token(token) .bankAccountDetails(bankAccountDetails) .profileType(profileType) .companyName(companyName) .companyRegistrationNumber(companyRegistrationNumber) .vatNumber(vatNumber) .businessStakeHolderDetails(businessStakeHolderDetails) .hyperwalletProgram(hyperwalletProgram); //@formatter:on } public boolean hasAcceptedTermsAndConditions() { return isHwTermsConsent() || Objects.nonNull(getToken()); } @Override public boolean equals(final Object o) { if (this == o) { return true; } if (!(o instanceof SellerModel)) { return false; } final SellerModel that = (SellerModel) o; return EqualsBuilder.reflectionEquals(this, that, "businessStakeHolderDetails") && CollectionUtils .isEqualCollection(Optional.ofNullable(getBusinessStakeHolderDetails()).orElse(List.of()), Optional.ofNullable(that.businessStakeHolderDetails).orElse(List.of())); } @Override public int hashCode() { return HashCodeBuilder.reflectionHashCode(this); } public static class SellerModelBuilder { private SellerModelBuilder internalCountry(final String country) { this.country = country; return this; } private SellerModelBuilder internalCompanyRegistrationCountry(final String companyRegistrationCountry) { this.companyRegistrationCountry = companyRegistrationCountry; return this; } private SellerModelBuilder internalBusinessRegistrationStateProvince( final String businessRegistrationStateProvince) { this.businessRegistrationStateProvince = businessRegistrationStateProvince; return this; } public SellerModelBuilder country(final String country) { this.country = transform3CharIsocodeTo2CharIsocode(country); return this; } public SellerModelBuilder companyRegistrationCountry(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, HYPERWALLET_BUSINESS_REGISTRATION_COUNTRY) .ifPresent(countryIsocode -> companyRegistrationCountry = countryIsocode); return this; } public SellerModelBuilder businessRegistrationStateProvince(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, HYPERWALLET_BUSINESS_REGISTRATION_STATE_PROVINCE).ifPresent( businessRegistrationStateProvinceValue -> this.businessRegistrationStateProvince = businessRegistrationStateProvinceValue); return this; } public SellerModelBuilder token(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, HYPERWALLET_USER_TOKEN) .ifPresent(retrievedToken -> token = retrievedToken); return this; } public SellerModelBuilder dateOfBirth(final List<MiraklAdditionalFieldValue> fields) { //@formatter:off fields.stream().filter(field -> field.getCode().equals(DATE_OF_BIRTH)) .filter(MiraklAdditionalFieldValue.MiraklDateAdditionalFieldValue.class::isInstance) .map(MiraklAdditionalFieldValue.MiraklDateAdditionalFieldValue.class::cast).findAny() .map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue) .ifPresent(dateAsStringISO8601 -> { final ZonedDateTime zonedDateTime = Instant.parse(dateAsStringISO8601).atZone(ZoneId.of(timeZone)); final long offsetMillis = TimeUnit.SECONDS.toMillis(ZoneOffset.from(zonedDateTime).getTotalSeconds()); final long isoMillis = zonedDateTime.toInstant().toEpochMilli(); dateOfBirth = new Date(isoMillis + offsetMillis); }); //@formatter:on return this; } public SellerModelBuilder hwTermsConsent(final List<MiraklAdditionalFieldValue> fields) { getMiraklBooleanCustomFieldValue(fields, HYPERWALLET_TERMS_CONSENT) .ifPresent(termsConsent -> hwTermsConsent = Boolean.parseBoolean(termsConsent)); return this; } public SellerModelBuilder countryOfBirth(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, COUNTRY_OF_BIRTH) .ifPresent(retrievedCountryOfBirth -> countryOfBirth = retrievedCountryOfBirth); return this; } public SellerModelBuilder countryOfNationality(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, COUNTRY_OF_NATIONALITY) .ifPresent(retrievedCountryOfNationality -> countryOfNationality = retrievedCountryOfNationality); return this; } public SellerModelBuilder governmentId(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, GOVERNMENT_ID) .ifPresent(retrievedGovernmentId -> governmentId = retrievedGovernmentId); return this; } public SellerModelBuilder governmentIdType(final List<MiraklAdditionalFieldValue> fields) { getMiraklSingleValueListCustomFieldValue(fields, GOVERNMENT_ID_TYPE) .ifPresent(retrievedGovernmentIdType -> governmentIdType = EnumUtils .getEnum(SellerGovernmentIdType.class, retrievedGovernmentIdType)); return this; } public SellerModelBuilder passportId(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, PASSPORT_ID) .ifPresent(retrievedPassportId -> passportId = retrievedPassportId); return this; } public SellerModelBuilder driversLicenseId(final List<MiraklAdditionalFieldValue> fields) { getMiraklStringCustomFieldValue(fields, DRIVERS_LICENSE_ID) .ifPresent(retrievedDriversLicenseId -> driversLicenseId = retrievedDriversLicenseId); return this; } public SellerModelBuilder businessType(final List<MiraklAdditionalFieldValue> fields) { getMiraklSingleValueListCustomFieldValue(fields, BUSINESS_TYPE) .ifPresent(retrievedBusinessType -> businessType = EnumUtils.getEnum(SellerBusinessType.class, retrievedBusinessType)); return this; } public SellerModelBuilder businessStakeHolderDetails( final List<BusinessStakeHolderModel> businessStakeHolderModels) { businessStakeHolderDetails = Stream.ofNullable(businessStakeHolderModels).flatMap(Collection::stream) .filter(Objects::nonNull) .map(businessStakeHolderModel -> businessStakeHolderModel.toBuilder().build()) .collect(Collectors.toList()); return this; } public SellerModelBuilder hyperwalletProgram(final List<MiraklAdditionalFieldValue> fields) { getMiraklSingleValueListCustomFieldValue(fields, HYPERWALLET_PROGRAM) .ifPresent(hyperwalletProgramValue -> hyperwalletProgram = hyperwalletProgramValue); return this; } private Optional<String> getMiraklSingleValueListCustomFieldValue(final List<MiraklAdditionalFieldValue> fields, final String customFieldCode) { //@formatter:off return fields.stream() .filter(field -> field.getCode().equals(customFieldCode)) .filter(MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue.class::isInstance) .map(MiraklAdditionalFieldValue.MiraklValueListAdditionalFieldValue.class::cast).findAny() .map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue); //@formatter:on } private Optional<String> getMiraklStringCustomFieldValue(final List<MiraklAdditionalFieldValue> fields, final String customFieldCode) { return fields.stream().filter(field -> field.getCode().equals(customFieldCode)) .filter(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::isInstance) .map(MiraklAdditionalFieldValue.MiraklStringAdditionalFieldValue.class::cast).findAny() .map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue); } private Optional<String> getMiraklBooleanCustomFieldValue(final List<MiraklAdditionalFieldValue> fields, final String customFieldCode) { return fields.stream().filter(field -> field.getCode().equals(customFieldCode)) .filter(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::isInstance) .map(MiraklAdditionalFieldValue.MiraklBooleanAdditionalFieldValue.class::cast).findAny() .map(MiraklAdditionalFieldValue.MiraklAbstractAdditionalFieldWithSingleValue::getValue); } private String transform3CharIsocodeTo2CharIsocode(final String country) { final Locale countryLocale = CountriesUtil.getLocaleByIsocode(country).orElseThrow( () -> new IllegalStateException("Country with isocode: [%s] not valid".formatted(country))); return countryLocale.getCountry(); } private SellerModelBuilder dateOfBirth(final Date dateOfBirth) { this.dateOfBirth = dateOfBirth; return this; } private SellerModelBuilder countryOfBirth(final String countryOfBirth) { this.countryOfBirth = countryOfBirth; return this; } private SellerModelBuilder countryOfNationality(final String countryOfNationality) { this.countryOfNationality = countryOfNationality; return this; } private SellerModelBuilder governmentId(final String governmentId) { this.governmentId = governmentId; return this; } private SellerModelBuilder governmentIdType(final SellerGovernmentIdType governmentIdType) { this.governmentIdType = governmentIdType; return this; } private SellerModelBuilder passportId(final String passportId) { this.passportId = passportId; return this; } private SellerModelBuilder driversLicenseId(final String driversLicenseId) { this.driversLicenseId = driversLicenseId; return this; } private SellerModelBuilder businessType(final SellerBusinessType businessType) { this.businessType = businessType; return this; } public SellerModelBuilder token(final String token) { this.token = token; return this; } public SellerModelBuilder hyperwalletProgram(final String hyperwalletProgram) { this.hyperwalletProgram = hyperwalletProgram; return this; } public SellerModelBuilder bankAccountDetails(final BankAccountModel bankAccountDetails) { this.bankAccountDetails = bankAccountDetails; return this; } } }
4,884
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerModelConstants.java
package com.paypal.sellers.sellerextractioncommons.model; public final class SellerModelConstants { private SellerModelConstants() { } public static final String COUNTRY_OF_BIRTH = "hw-country-of-birth"; public static final String COUNTRY_OF_NATIONALITY = "hw-country-of-nationality"; public static final String GOVERNMENT_ID = "hw-government-id"; public static final String GOVERNMENT_ID_TYPE = "hw-government-id-type"; public static final String PASSPORT_ID = "hw-passport-id"; public static final String DRIVERS_LICENSE_ID = "hw-drivers-license-id"; public static final String BUSINESS_TYPE = "hw-business-type"; public static final String DATE_OF_BIRTH = "hw-date-of-birth"; public static final String HYPERWALLET_USER_TOKEN = "hw-user-token"; public static final String HYPERWALLET_BANK_ACCOUNT_TOKEN = "hw-bankaccount-token"; public static final String HYPERWALLET_BANK_ACCOUNT_STATE = "hw-bankaccount-state"; public static final String HYPERWALLET_TERMS_CONSENT = "hw-terms-consent"; public static final String HYPERWALLET_PROGRAM = "hw-program"; public static final String HYPERWALLET_BUSINESS_REGISTRATION_COUNTRY = "hw-business-reg-country"; public static final String HYPERWALLET_BUSINESS_REGISTRATION_STATE_PROVINCE = "hw-business-reg-state-province"; }
4,885
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerProfileType.java
package com.paypal.sellers.sellerextractioncommons.model; public enum SellerProfileType { INDIVIDUAL, BUSINESS }
4,886
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerGender.java
package com.paypal.sellers.sellerextractioncommons.model; /** * Possible genders for a seller */ public enum SellerGender { MALE, FEMALE }
4,887
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/model/SellerBusinessType.java
package com.paypal.sellers.sellerextractioncommons.model; public enum SellerBusinessType { CORPORATION, PRIVATE_COMPANY, PARTNERSHIP, NOT_FOR_PROFIT_ORGANIZATION, GOVERNMENT_ENTITY, PUBLIC_COMPANY }
4,888
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/SellersTokenSynchronizationServiceImpl.java
package com.paypal.sellers.sellerextractioncommons.services; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletList; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.hyperwallet.clientsdk.model.HyperwalletUsersListPaginationOptions; import com.mirakl.client.core.exception.MiraklException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.infrastructure.support.services.TokenSynchronizationService; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import lombok.extern.slf4j.Slf4j; import org.apache.commons.collections4.CollectionUtils; import org.apache.commons.lang3.StringUtils; import org.springframework.stereotype.Service; import java.util.Optional; /** * Class that implements the {@link TokenSynchronizationService} interface for the * synchronization of tokens for sellers */ @Slf4j @Service("sellersTokenSynchronizationService") public class SellersTokenSynchronizationServiceImpl implements TokenSynchronizationService<SellerModel> { private final UserHyperwalletSDKService userHyperwalletSDKService; private final MiraklSellersExtractService miraklSellersExtractService; public SellersTokenSynchronizationServiceImpl(final UserHyperwalletSDKService userHyperwalletSDKService, final MiraklSellersExtractService miraklSellersExtractService) { this.userHyperwalletSDKService = userHyperwalletSDKService; this.miraklSellersExtractService = miraklSellersExtractService; } /** * Ensures the seller's token between Hyperwallet and Mirakl is synchronized * @param sellerModel that contains the seller item to be synchronized * @return the seller with the seller's token synchronized */ @Override public SellerModel synchronizeToken(final SellerModel sellerModel) { if (StringUtils.isNotBlank(sellerModel.getToken())) { log.debug("Hyperwallet token already exists for client user id [{}], synchronization not needed", sellerModel.getClientUserId()); return sellerModel; } final Optional<HyperwalletUser> hyperwalletUser = getHwUser(sellerModel); if (hyperwalletUser.isPresent()) { updateTokenInMirakl(hyperwalletUser.get()); return updateSellerWithHyperwalletToken(sellerModel, hyperwalletUser.get()); } else { return sellerModel; } } private void updateTokenInMirakl(final HyperwalletUser hyperwalletUser) { try { miraklSellersExtractService.updateUserToken(hyperwalletUser); } catch (final MiraklException e) { log.error("Error while updating Mirakl user by clientUserId [%s]" .formatted(hyperwalletUser.getClientUserId()), e); throw new HMCMiraklAPIException(e); } } private Optional<HyperwalletUser> getHwUser(final SellerModel sellerModel) { final HyperwalletList<HyperwalletUser> hyperwalletUserHyperwalletList = getHwUserByClientUserId(sellerModel); if (CollectionUtils.isEmpty(hyperwalletUserHyperwalletList.getData())) { log.debug("Hyperwallet user with client user id [{}] not found", sellerModel.getClientUserId()); return Optional.empty(); } else { log.debug("Hyperwallet user with client user id [{}] found", sellerModel.getClientUserId()); return Optional.of(hyperwalletUserHyperwalletList.getData().get(0)); } } private HyperwalletList<HyperwalletUser> getHwUserByClientUserId(final SellerModel sellerModel) { final Hyperwallet hyperwalletSDK = userHyperwalletSDKService .getHyperwalletInstanceByProgramToken(sellerModel.getProgramToken()); final HyperwalletUsersListPaginationOptions paginationOptions = new HyperwalletUsersListPaginationOptions(); paginationOptions.setClientUserId(sellerModel.getClientUserId()); try { return hyperwalletSDK.listUsers(paginationOptions); } catch (final HyperwalletException e) { log.error(String.format("Error while getting Hyperwallet user by clientUserId [%s].%n%s", sellerModel.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e)), e); throw new HMCHyperwalletAPIException(e); } } private SellerModel updateSellerWithHyperwalletToken(final SellerModel sellerModel, final HyperwalletUser hyperwalletUser) { return sellerModel.toBuilder().token(hyperwalletUser.getToken()).build(); } }
4,889
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/MiraklSellersExtractService.java
package com.paypal.sellers.sellerextractioncommons.services; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.springframework.lang.Nullable; import java.util.Date; import java.util.List; /** * Service to manipulate the shop extraction from Mirakl */ public interface MiraklSellersExtractService { /** * Extracts the {@link SellerModel} individuals data from Mirakl environment * @param delta Optional parameter to filter all shops that have been modified since * this parameter value * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractIndividuals(@Nullable Date delta); /** * Extracts the {@link SellerModel} professionals data from Mirakl environment * @param delta Optional parameter to filter all shops that have been modified since * this parameter value * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractProfessionals(@Nullable Date delta); /** * Extracts all {@link SellerModel} data from Mirakl environment * @param delta Optional parameter to filter all shops that have been modified since * this parameter value * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractSellers(@Nullable Date delta); /** * Extracts all {@link SellerModel} individuals data from Mirakl environment * @param shopIds {@link List<String>} that includes all shop ids to retrieve from * database * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractIndividuals(List<String> shopIds); /** * Extracts all {@link SellerModel} professionals data from Mirakl environment * @param shopIds {@link List<String>} that includes all shop ids to retrieve from * database * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractProfessionals(List<String> shopIds); /** * Extracts all {@link SellerModel} data from Mirakl environment * @param shopIds {@link List<String>} that includes all shop ids to retrieve from * @return a {@link List} of {@link SellerModel} */ List<SellerModel> extractSellers(List<String> shopIds); /** * Updates the custom field {@code hw-user-field} with the token received after * creation of the {@link HyperwalletUser} * @param hyperwalletUser */ void updateUserToken(HyperwalletUser hyperwalletUser); }
4,890
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/MiraklSellersExtractServiceImpl.java
package com.paypal.sellers.sellerextractioncommons.services; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.mirakl.client.core.exception.MiraklApiException; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.mirakl.client.mmp.domain.shop.MiraklShops; import com.mirakl.client.mmp.operator.domain.shop.update.MiraklUpdateShop; import com.mirakl.client.mmp.operator.request.shop.MiraklUpdateShopsRequest; import com.mirakl.client.mmp.request.shop.MiraklGetShopsRequest; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.mirakl.client.MiraklClient; import com.paypal.infrastructure.support.logging.LoggingConstantsUtil; import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import lombok.extern.slf4j.Slf4j; import org.springframework.lang.NonNull; import org.springframework.lang.Nullable; import org.springframework.stereotype.Service; import org.springframework.util.CollectionUtils; import java.util.Collection; import java.util.Collections; import java.util.Date; import java.util.List; import java.util.function.Predicate; import java.util.stream.Collectors; import java.util.stream.Stream; import static com.mirakl.client.mmp.request.additionalfield.MiraklRequestAdditionalFieldValue.MiraklSimpleRequestAdditionalFieldValue; import static com.paypal.sellers.sellerextractioncommons.model.SellerModelConstants.HYPERWALLET_USER_TOKEN; /** * Class to handle operations related with the seller extraction from Mirakl */ @Slf4j @Service public class MiraklSellersExtractServiceImpl implements MiraklSellersExtractService { private static final String SHOPS_RETRIEVED_MESSAGE = "Shops retrieved [{}]"; private static final String EMAIL_SUBJECT_MESSAGE = "Issue detected getting shop information in Mirakl"; private final MiraklClient miraklOperatorClient; private final StrategyExecutor<MiraklShop, SellerModel> miraklShopSellerModelStrategyExecutor; private final MailNotificationUtil sellerMailNotificationUtil; private static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; public MiraklSellersExtractServiceImpl(final MiraklClient miraklOperatorClient, final StrategyExecutor<MiraklShop, SellerModel> miraklShopSellerModelStrategyExecutor, final MailNotificationUtil sellerMailNotificationUtil) { this.miraklOperatorClient = miraklOperatorClient; this.miraklShopSellerModelStrategyExecutor = miraklShopSellerModelStrategyExecutor; this.sellerMailNotificationUtil = sellerMailNotificationUtil; } /** * {@inheritDoc} */ @Override public List<SellerModel> extractIndividuals(@Nullable final Date delta) { final MiraklShops shops = retrieveMiraklShopsByDate(delta); return internalExtractIndividuals(shops); } /** * {@inheritDoc} */ @Override public List<SellerModel> extractIndividuals(final List<String> shopIds) { if (CollectionUtils.isEmpty(shopIds)) { return Collections.emptyList(); } final MiraklShops shops = retrieveMiraklShopsByShopIds(shopIds); return internalExtractIndividuals(shops); } /** * {@inheritDoc} */ @Override public List<SellerModel> extractProfessionals(@Nullable final Date delta) { final MiraklShops shops = retrieveMiraklShopsByDate(delta); return internalExtractProfessionals(shops); } /** * {@inheritDoc} */ @Override public List<SellerModel> extractProfessionals(final List<String> shopIds) { if (CollectionUtils.isEmpty(shopIds)) { return Collections.emptyList(); } final MiraklShops shops = retrieveMiraklShopsByShopIds(shopIds); return internalExtractProfessionals(shops); } /** * {@inheritDoc} */ @Override public List<SellerModel> extractSellers(final List<String> shopIds) { if (CollectionUtils.isEmpty(shopIds)) { return Collections.emptyList(); } final MiraklShops shops = retrieveMiraklShopsByShopIds(shopIds); return Stream.ofNullable(shops.getShops()).flatMap(Collection::stream) .map(miraklShopSellerModelStrategyExecutor::execute).collect(Collectors.toList()); } @Override public List<SellerModel> extractSellers(@Nullable final Date delta) { final MiraklShops shops = retrieveMiraklShopsByDate(delta); //@formatter:off log.info(SHOPS_RETRIEVED_MESSAGE, Stream.ofNullable(shops.getShops()) .flatMap(Collection::stream) .map(MiraklShop::getId) .collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR))); return Stream.ofNullable(shops.getShops()) .flatMap(Collection::stream) .map(miraklShopSellerModelStrategyExecutor::execute) .filter(SellerModel::hasAcceptedTermsAndConditions) .collect(Collectors.toList()); //@formatter:on } /** * {@inheritDoc} */ @Override public void updateUserToken(final HyperwalletUser hyperwalletUser) { final MiraklUpdateShop miraklUpdateShop = new MiraklUpdateShop(); miraklUpdateShop.setShopId(Long.valueOf(hyperwalletUser.getClientUserId())); final MiraklSimpleRequestAdditionalFieldValue userTokenCustomField = new MiraklSimpleRequestAdditionalFieldValue(); userTokenCustomField.setCode(HYPERWALLET_USER_TOKEN); userTokenCustomField.setValue(hyperwalletUser.getToken()); miraklUpdateShop.setAdditionalFieldValues(List.of(userTokenCustomField)); final MiraklUpdateShopsRequest request = new MiraklUpdateShopsRequest(List.of(miraklUpdateShop)); log.info("Updating token for shop [{}] to [{}]", hyperwalletUser.getClientUserId(), hyperwalletUser.getToken()); try { miraklOperatorClient.updateShops(request); } catch (final MiraklApiException ex) { log.error("Something went wrong getting information of shop [{}]", hyperwalletUser.getClientUserId()); sellerMailNotificationUtil.sendPlainTextEmail(EMAIL_SUBJECT_MESSAGE, (ERROR_MESSAGE_PREFIX + "Something went wrong getting information of shop [%s]%n%s") .formatted(hyperwalletUser.getClientUserId(), MiraklLoggingErrorsUtil.stringify(ex))); } } @NonNull private List<SellerModel> internalExtractIndividuals(final MiraklShops shops) { //@formatter:off log.info(SHOPS_RETRIEVED_MESSAGE, shops.getShops().stream() .filter(Predicate.not(MiraklShop::isProfessional)) .map(MiraklShop::getId) .collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR))); return shops.getShops() .stream() .filter(Predicate.not(MiraklShop::isProfessional)) .map(miraklShopSellerModelStrategyExecutor::execute) .filter(SellerModel::hasAcceptedTermsAndConditions) .collect(Collectors.toList()); //@formatter:on } @NonNull private List<SellerModel> internalExtractProfessionals(final MiraklShops shops) { //@formatter:off log.info(SHOPS_RETRIEVED_MESSAGE, shops.getShops().stream() .filter(MiraklShop::isProfessional) .map(MiraklShop::getId) .collect(Collectors.joining(LoggingConstantsUtil.LIST_LOGGING_SEPARATOR))); return shops.getShops() .stream() .filter(MiraklShop::isProfessional) .map(miraklShopSellerModelStrategyExecutor::execute) .filter(SellerModel::hasAcceptedTermsAndConditions) .collect(Collectors.toList()); //@formatter:on } private MiraklShops retrieveMiraklShopsByDate(@Nullable final Date delta) { final MiraklGetShopsRequest request = new MiraklGetShopsRequest(); request.setUpdatedSince(delta); request.setPaginate(false); log.info("Retrieving shops since {}", delta); try { return miraklOperatorClient.getShops(request); } catch (final MiraklApiException ex) { log.error("Something went wrong getting shop information since [{}]", delta); sellerMailNotificationUtil.sendPlainTextEmail(EMAIL_SUBJECT_MESSAGE, (ERROR_MESSAGE_PREFIX + "Something went wrong getting shop information since [%s]%n%s") .formatted(delta, MiraklLoggingErrorsUtil.stringify(ex))); return new MiraklShops(); } } private MiraklShops retrieveMiraklShopsByShopIds(final List<String> shopIds) { final MiraklGetShopsRequest request = new MiraklGetShopsRequest(); request.setShopIds(shopIds); request.setPaginate(false); log.info("Retrieving shops with ids {}", shopIds); try { return miraklOperatorClient.getShops(request); } catch (final MiraklApiException ex) { log.error("Something went wrong getting s information with ids [{}]", shopIds); sellerMailNotificationUtil.sendPlainTextEmail(EMAIL_SUBJECT_MESSAGE, (ERROR_MESSAGE_PREFIX + "Something went wrong getting shop information with ids [%s]%n%s") .formatted(shopIds, MiraklLoggingErrorsUtil.stringify(ex))); return new MiraklShops(); } } }
4,891
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/strategies/AbstractHyperwalletSellerServiceStrategy.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.slf4j.Logger; public abstract class AbstractHyperwalletSellerServiceStrategy implements Strategy<SellerModel, SellerModel> { protected final Converter<SellerModel, HyperwalletUser> sellerModelHyperwalletUserConverter; protected final UserHyperwalletSDKService userHyperwalletSDKService; protected final MailNotificationUtil mailNotificationUtil; protected static final String ERROR_MESSAGE_PREFIX = "There was an error, please check the logs for further " + "information:\n"; protected AbstractHyperwalletSellerServiceStrategy( final Converter<SellerModel, HyperwalletUser> sellerModelHyperwalletUserConverter, final UserHyperwalletSDKService userHyperwalletSDKService, final MailNotificationUtil mailNotificationUtil) { this.sellerModelHyperwalletUserConverter = sellerModelHyperwalletUserConverter; this.userHyperwalletSDKService = userHyperwalletSDKService; this.mailNotificationUtil = mailNotificationUtil; } /** * {@inheritDoc} */ @Override public SellerModel execute(final SellerModel seller) { final HyperwalletUser hwUserRequest = sellerModelHyperwalletUserConverter.convert(seller); final HyperwalletUser hyperwalletUser = pushToHyperwallet(hwUserRequest); return updateSellerToken(seller, hyperwalletUser); } private SellerModel updateSellerToken(final SellerModel seller, final HyperwalletUser hyperwalletUser) { //@formatter:off return seller.toBuilder() .token(hyperwalletUser.getToken()) .build(); //@formatter:on } protected abstract HyperwalletUser pushToHyperwallet(HyperwalletUser hyperwalletUser); protected void logErrors(final String message, final Exception e, final Logger log) { log.error(message, e); } protected void reportError(final String subject, final String message) { mailNotificationUtil.sendPlainTextEmail(subject, message); } }
4,892
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/strategies/HyperWalletUserServiceStrategyExecutor.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.paypal.infrastructure.support.strategy.SingleAbstractStrategyExecutor; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Set; /** * Executor class that controls strategies to insert or update sellers information into * Hyperwallet */ @Slf4j @Service public class HyperWalletUserServiceStrategyExecutor extends SingleAbstractStrategyExecutor<SellerModel, SellerModel> { private final Set<Strategy<SellerModel, SellerModel>> strategies; public HyperWalletUserServiceStrategyExecutor(final Set<Strategy<SellerModel, SellerModel>> strategies) { this.strategies = strategies; } @Override protected Set<Strategy<SellerModel, SellerModel>> getStrategies() { return strategies; } }
4,893
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/strategies/HyperWalletCreateSellerServiceStrategy.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.mirakl.client.core.exception.MiraklException; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.support.exceptions.HMCMiraklAPIException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.infrastructure.support.logging.MiraklLoggingErrorsUtil; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import com.paypal.sellers.sellerextractioncommons.services.MiraklSellersExtractService; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Objects; /** * Strategy class that manages sellers creation in hyperwallet and token update in Mirakl */ @Slf4j @Service public class HyperWalletCreateSellerServiceStrategy extends AbstractHyperwalletSellerServiceStrategy { private final MiraklSellersExtractService miraklSellersExtractService; protected HyperWalletCreateSellerServiceStrategy( final Converter<SellerModel, HyperwalletUser> sellerModelHyperwalletUserConverter, final UserHyperwalletSDKService userHyperwalletSDKService, final MailNotificationUtil mailNotificationUtil, final MiraklSellersExtractService miraklSellersExtractService) { super(sellerModelHyperwalletUserConverter, userHyperwalletSDKService, mailNotificationUtil); this.miraklSellersExtractService = miraklSellersExtractService; } /** * It creates the user on HyperWallet side and updates the token in Mirakl * @param hyperwalletUser The User to be created * @return The created HyperWallet user */ @Override protected HyperwalletUser pushToHyperwallet(final HyperwalletUser hyperwalletUser) { final Hyperwallet hyperwallet = userHyperwalletSDKService .getHyperwalletInstanceByProgramToken(hyperwalletUser.getProgramToken()); try { final HyperwalletUser hwUser = hyperwallet.createUser(hyperwalletUser); log.info("Seller created for seller with clientUserId [{}]", hyperwalletUser.getClientUserId()); miraklSellersExtractService.updateUserToken(hwUser); return hwUser; } catch (final HyperwalletException e) { logErrors("Error creating seller in hyperwallet with clientUserId [%s].%n%s" .formatted(hyperwalletUser.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e)), e, log); reportError("Issue detected when creating seller in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Seller not created with clientId [%s]%n%s") .formatted(hyperwalletUser.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e))); throw new HMCHyperwalletAPIException(e); } catch (final MiraklException e) { logErrors("Error updating token in mirakl with clientUserId [%s]: [{}]" .formatted(hyperwalletUser.getClientUserId()), e, log); reportError("Issue detected when updating seller in Mirakl", (ERROR_MESSAGE_PREFIX + "Seller token not updated with clientId [%s]%n%s") .formatted(hyperwalletUser.getClientUserId(), MiraklLoggingErrorsUtil.stringify(e))); throw new HMCMiraklAPIException(e); } } /** * Checks whether the strategy must be executed based on the not existence of the * {@code seller} * @param seller the seller object * @return returns whether the strategy is applicable or not */ @Override public boolean isApplicable(final SellerModel seller) { return Objects.isNull(seller.getToken()); } }
4,894
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/strategies/HyperWalletUpdateSellerServiceStrategy.java
package com.paypal.sellers.sellerextractioncommons.services.strategies; import com.hyperwallet.clientsdk.Hyperwallet; import com.hyperwallet.clientsdk.HyperwalletException; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.infrastructure.support.exceptions.HMCHyperwalletAPIException; import com.paypal.infrastructure.hyperwallet.services.UserHyperwalletSDKService; import com.paypal.infrastructure.mail.services.MailNotificationUtil; import com.paypal.infrastructure.support.logging.HyperwalletLoggingErrorsUtil; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Service; import java.util.Objects; /** * Strategy class that manages sellers update in hyperwallet */ @Slf4j @Service public class HyperWalletUpdateSellerServiceStrategy extends AbstractHyperwalletSellerServiceStrategy { protected HyperWalletUpdateSellerServiceStrategy( final Converter<SellerModel, HyperwalletUser> sellerModelHyperwalletUserConverter, final UserHyperwalletSDKService userHyperwalletSDKService, final MailNotificationUtil mailNotificationUtil) { super(sellerModelHyperwalletUserConverter, userHyperwalletSDKService, mailNotificationUtil); } @Override protected HyperwalletUser pushToHyperwallet(final HyperwalletUser hyperwalletUser) { try { final Hyperwallet hyperwallet = userHyperwalletSDKService .getHyperwalletInstanceByProgramToken(hyperwalletUser.getProgramToken()); final HyperwalletUser updatedUser = hyperwallet.updateUser(hyperwalletUser); log.info("Seller updated for seller with clientUserId [{}]", hyperwalletUser.getClientUserId()); return updatedUser; } catch (final HyperwalletException e) { logErrors("Error updating seller in hyperwallet with clientUserId [%s].%n%s" .formatted(hyperwalletUser.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e)), e, log); reportError("Issue detected when updating seller in Hyperwallet", (ERROR_MESSAGE_PREFIX + "Seller not updated with clientId [%s]%n%s") .formatted(hyperwalletUser.getClientUserId(), HyperwalletLoggingErrorsUtil.stringify(e))); throw new HMCHyperwalletAPIException(e); } } /** * Checks whether the strategy must be executed based on the {@code seller} * @param seller the seller object * @return returns whether the strategy is applicable or not */ @Override public boolean isApplicable(final SellerModel seller) { return Objects.nonNull(seller.getToken()); } }
4,895
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/converters/SellerModelToHyperWalletUserConverter.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.hyperwallet.clientsdk.model.HyperwalletUser; import com.paypal.infrastructure.hyperwallet.configuration.HyperwalletProgramsConfiguration; import com.paypal.infrastructure.support.converter.Converter; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.apache.commons.lang3.EnumUtils; import org.springframework.beans.factory.annotation.Value; import org.springframework.stereotype.Service; import java.util.Optional; @Service public class SellerModelToHyperWalletUserConverter implements Converter<SellerModel, HyperwalletUser> { protected final HyperwalletProgramsConfiguration hyperwalletProgramsConfiguration; @Value("${hmc.toggle-features.new-user-mapping}") private boolean newUserMappingEnabled; public SellerModelToHyperWalletUserConverter( final HyperwalletProgramsConfiguration hyperwalletProgramsConfiguration) { this.hyperwalletProgramsConfiguration = hyperwalletProgramsConfiguration; } /** * Method that retrieves a {@link SellerModel} and returns a {@link HyperwalletUser} * @param sellerModel the source object {@link SellerModel} * @return the returned object {@link HyperwalletUser} */ @Override public HyperwalletUser convert(final SellerModel sellerModel) { final HyperwalletUser hyperwalletUser = new HyperwalletUser(); final HyperwalletUser.ProfileType profileType = EnumUtils.getEnum(HyperwalletUser.ProfileType.class, sellerModel.getProfileType().name(), HyperwalletUser.ProfileType.UNKNOWN); hyperwalletUser.setClientUserId(sellerModel.getClientUserId()); hyperwalletUser.setProfileType(profileType); Optional.ofNullable(sellerModel.getBusinessType()).map(Enum::name).map(HyperwalletUser.BusinessType::valueOf) .ifPresent(hyperwalletUser::setBusinessType); hyperwalletUser.setAddressLine1(sellerModel.getAddressLine1()); hyperwalletUser.setCity(sellerModel.getCity()); hyperwalletUser.setStateProvince(sellerModel.getStateProvince()); hyperwalletUser.setPostalCode(sellerModel.getPostalCode()); hyperwalletUser.setCountry(sellerModel.getCountry()); hyperwalletUser.setProgramToken(hyperwalletProgramsConfiguration .getProgramConfiguration(sellerModel.getHyperwalletProgram()).getUsersProgramToken()); hyperwalletUser.setToken(sellerModel.getToken()); hyperwalletUser.setEmail(sellerModel.getEmail()); if (HyperwalletUser.ProfileType.BUSINESS.equals(profileType)) { hyperwalletUser.setBusinessRegistrationCountry(sellerModel.getCompanyRegistrationCountry()); hyperwalletUser.setBusinessRegistrationStateProvince(sellerModel.getBusinessRegistrationStateProvince()); hyperwalletUser.setBusinessRegistrationId(sellerModel.getCompanyRegistrationNumber()); if (newUserMappingEnabled) { hyperwalletUser.setBusinessName(sellerModel.getCompanyName()); hyperwalletUser.setBusinessOperatingName(sellerModel.getBusinessName()); } else { hyperwalletUser.setBusinessName(sellerModel.getBusinessName()); hyperwalletUser.setBusinessOperatingName(sellerModel.getCompanyName()); } } if (HyperwalletUser.ProfileType.INDIVIDUAL.equals(profileType)) { hyperwalletUser.setBusinessName(sellerModel.getBusinessName()); hyperwalletUser.setFirstName(sellerModel.getFirstName()); hyperwalletUser.setLastName(sellerModel.getLastName()); hyperwalletUser.setDateOfBirth(sellerModel.getDateOfBirth()); hyperwalletUser.setCountryOfBirth(sellerModel.getCountryOfBirth()); hyperwalletUser.setCountryOfNationality(sellerModel.getCountryOfNationality()); hyperwalletUser.setPhoneNumber(sellerModel.getPhoneNumber()); hyperwalletUser.setMobileNumber(sellerModel.getMobilePhone()); hyperwalletUser.setAddressLine2(sellerModel.getAddressLine2()); hyperwalletUser.setGovernmentId(sellerModel.getGovernmentId()); hyperwalletUser.setPassportId(sellerModel.getPassportId()); hyperwalletUser.setDriversLicenseId(sellerModel.getDriversLicenseId()); Optional.ofNullable(sellerModel.getGovernmentIdType()).map(Enum::name) .map(HyperwalletUser.GovernmentIdType::valueOf).ifPresent(hyperwalletUser::setGovernmentIdType); } return hyperwalletUser; } }
4,896
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/converters/MiraklShopToSellerConverterExecutor.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.strategy.SingleAbstractStrategyExecutor; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import org.springframework.stereotype.Service; import java.util.Set; @Service public class MiraklShopToSellerConverterExecutor extends SingleAbstractStrategyExecutor<MiraklShop, SellerModel> { private final Set<Strategy<MiraklShop, SellerModel>> strategies; public MiraklShopToSellerConverterExecutor(final Set<Strategy<MiraklShop, SellerModel>> strategies) { this.strategies = strategies; } @Override protected Set<Strategy<MiraklShop, SellerModel>> getStrategies() { return strategies; } }
4,897
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/sellerextractioncommons/services/converters/AbstractMiraklShopToSellerModelConverter.java
package com.paypal.sellers.sellerextractioncommons.services.converters; import com.mirakl.client.mmp.domain.common.MiraklAdditionalFieldValue; import com.mirakl.client.mmp.domain.shop.MiraklContactInformation; import com.mirakl.client.mmp.domain.shop.MiraklShop; import com.paypal.infrastructure.support.strategy.Strategy; import com.paypal.infrastructure.support.strategy.StrategyExecutor; import com.paypal.sellers.bankaccountextraction.model.BankAccountModel; import com.paypal.sellers.sellerextractioncommons.configuration.SellersMiraklApiConfig; import com.paypal.sellers.sellerextractioncommons.model.SellerModel; import java.util.List; public abstract class AbstractMiraklShopToSellerModelConverter implements Strategy<MiraklShop, SellerModel> { private final StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor; private final SellersMiraklApiConfig sellersMiraklApiConfig; protected AbstractMiraklShopToSellerModelConverter( final StrategyExecutor<MiraklShop, BankAccountModel> miraklShopBankAccountModelStrategyExecutor, final SellersMiraklApiConfig sellersMiraklApiConfig) { this.miraklShopBankAccountModelStrategyExecutor = miraklShopBankAccountModelStrategyExecutor; this.sellersMiraklApiConfig = sellersMiraklApiConfig; } protected SellerModel.SellerModelBuilder getCommonFieldsBuilder(final MiraklShop source) { final MiraklContactInformation contactInformation = source.getContactInformation(); final List<MiraklAdditionalFieldValue> additionalFieldValues = source.getAdditionalFieldValues(); final BankAccountModel bankAccountModel = miraklShopBankAccountModelStrategyExecutor.execute(source); //@formatter:off return SellerModel.builder() .clientUserId(source.getId()) .businessName(source.getName()) .firstName(contactInformation.getFirstname()) .lastName(contactInformation.getLastname()) .phoneNumber(contactInformation.getPhone()) .mobilePhone(contactInformation.getPhoneSecondary()) .email(contactInformation.getEmail()) .addressLine1(contactInformation.getStreet1()) .addressLine2(contactInformation.getStreet2()) .city(contactInformation.getCity()) .postalCode(contactInformation.getZipCode()) .stateProvince(contactInformation.getState()) .country(contactInformation.getCountry()) .timeZone(sellersMiraklApiConfig.getTimeZone()) .dateOfBirth(additionalFieldValues) .passportId(additionalFieldValues) .countryOfBirth(additionalFieldValues) .countryOfNationality(additionalFieldValues) .governmentId(additionalFieldValues) .governmentIdType(additionalFieldValues) .driversLicenseId(additionalFieldValues) .businessType(additionalFieldValues) .token(additionalFieldValues) .bankAccountDetails(bankAccountModel) .hwTermsConsent(additionalFieldValues) .hyperwalletProgram(additionalFieldValues); //@formatter:on } }
4,898
0
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers
Create_ds/mirakl-hyperwallet-connector/hmc-sellers/src/main/java/com/paypal/sellers/bankaccountextraction/BankAccountExtractionJobsConfig.java
package com.paypal.sellers.bankaccountextraction; import com.paypal.jobsystem.quartzadapter.job.QuartzBatchJobBuilder; import com.paypal.sellers.bankaccountextraction.batchjobs.BankAccountRetryBatchJob; import com.paypal.sellers.bankaccountextraction.jobs.BankAccountExtractJob; import org.quartz.*; import org.springframework.beans.factory.annotation.Qualifier; import org.springframework.beans.factory.annotation.Value; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; /** * Configuration class for scheduling jobs at startup */ @Configuration public class BankAccountExtractionJobsConfig { private static final String TRIGGER_SUFFIX = "Trigger"; private static final String JOB_NAME = "BankAccountExtractJob"; private static final String RETRY_JOB_NAME = "BankAccountRetryJob"; /** * Creates a recurring job {@link BankAccountExtractJob} * @return the {@link JobDetail} */ @Bean public JobDetail bankAccountExtractJob() { //@formatter:off return JobBuilder.newJob(BankAccountExtractJob.class) .withIdentity(JOB_NAME) .storeDurably() .build(); //@formatter:on } /** * Schedules the recurring job {@link BankAccountExtractJob} with the * {@code jobDetails} set on * {@link BankAccountExtractionJobsConfig#bankAccountExtractJob()} * @param jobDetails the {@link JobDetail} * @return the {@link Trigger} */ @Bean public Trigger bankAccountExtractJobTrigger(@Qualifier("bankAccountExtractJob") final JobDetail jobDetails, @Value("${hmc.jobs.scheduling.extract-jobs.bankaccounts}") final String cronExpression) { //@formatter:off return TriggerBuilder.newTrigger() .forJob(jobDetails) .withIdentity(TRIGGER_SUFFIX + JOB_NAME) .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) .build(); //@formatter:on } @Bean public JobDetail bankAccountRetryJob(final BankAccountRetryBatchJob bankAccountRetryBatchJob) { //@formatter:off return QuartzBatchJobBuilder.newJob(bankAccountRetryBatchJob) .withIdentity(RETRY_JOB_NAME) .storeDurably() .build(); //@formatter:on } @Bean public Trigger bankAccountRetryJobTrigger(@Qualifier("bankAccountRetryJob") final JobDetail jobDetails, @Value("${hmc.jobs.scheduling.retry-jobs.bankaccounts}") final String cronExpression) { //@formatter:off return TriggerBuilder.newTrigger() .forJob(jobDetails) .withIdentity(TRIGGER_SUFFIX + RETRY_JOB_NAME) .withSchedule(CronScheduleBuilder.cronSchedule(cronExpression)) .build(); //@formatter:on } }
4,899