generated from pagopa/template-java-spring-microservice
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: nav2iuv with multiple '_' PAGOPA-2316 (#159)
- Loading branch information
Showing
9 changed files
with
104 additions
and
10 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Large diffs are not rendered by default.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
94 changes: 94 additions & 0 deletions
94
src/test/java/it/gov/pagopa/wispconverter/service/DecouplerServiceTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package it.gov.pagopa.wispconverter.service; | ||
|
||
import it.gov.pagopa.wispconverter.exception.AppErrorCodeMessageEnum; | ||
import it.gov.pagopa.wispconverter.exception.AppException; | ||
import it.gov.pagopa.wispconverter.repository.CacheRepository; | ||
import it.gov.pagopa.wispconverter.repository.ReceiptDeadLetterRepository; | ||
import it.gov.pagopa.wispconverter.secondary.IdempotencyKeyRepositorySecondary; | ||
import it.gov.pagopa.wispconverter.secondary.RTRepositorySecondary; | ||
import it.gov.pagopa.wispconverter.secondary.ReEventRepositorySecondary; | ||
import it.gov.pagopa.wispconverter.service.model.CachedKeysMapping; | ||
import lombok.SneakyThrows; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.params.ParameterizedTest; | ||
import org.junit.jupiter.params.provider.CsvSource; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.boot.test.mock.mockito.MockBean; | ||
import org.springframework.test.context.ActiveProfiles; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.fail; | ||
import static org.mockito.ArgumentMatchers.any; | ||
import static org.mockito.Mockito.*; | ||
|
||
@ActiveProfiles(profiles = "test") | ||
@SpringBootTest | ||
class DecouplerServiceTest { | ||
|
||
@Autowired | ||
private DecouplerService decouplerService; | ||
|
||
@MockBean | ||
private CacheRepository cacheRepository; | ||
|
||
@MockBean | ||
private ReceiptDeadLetterRepository receiptDeadLetterRepository; | ||
|
||
@MockBean | ||
private RTRepositorySecondary rtRepositorySecondary; | ||
|
||
@MockBean | ||
private ReEventRepositorySecondary reEventRepositorySecondary; | ||
|
||
@MockBean | ||
private IdempotencyKeyRepositorySecondary idempotencyKeyRepositorySecondary; | ||
|
||
private static final String DOMAIN_ID = "12345678910"; | ||
|
||
private static final String NAV = "350000000000000000"; | ||
|
||
@ParameterizedTest | ||
@CsvSource({"wisp_nav2iuv_123456IUVMOCK1,123456IUVMOCK1", "wisp_nav2iuv_123456IUVMOCK1_123456IUVMOCK2,123456IUVMOCK1_123456IUVMOCK2"}) | ||
@SneakyThrows | ||
void getCachedMappingFromNavToIuvTestOK(String nav2iuv, String iuv) { | ||
|
||
// mocking decoupler cached keys | ||
when(cacheRepository.read(anyString(), any())).thenReturn(nav2iuv); | ||
|
||
CachedKeysMapping result = decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV); | ||
Assertions.assertEquals(iuv, result.getIuv()); | ||
|
||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void getCachedMappingFromNavToIuvTestKONullKey() { | ||
|
||
// mocking decoupler cached keys | ||
when(cacheRepository.read(anyString(), any())).thenReturn(null); | ||
|
||
try { | ||
decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV); | ||
fail(); | ||
} catch (AppException e) { | ||
assertEquals(AppErrorCodeMessageEnum.PERSISTENCE_REQUESTID_CACHING_ERROR, e.getError()); | ||
} | ||
} | ||
|
||
@Test | ||
@SneakyThrows | ||
void getCachedMappingFromNavToIuvTestKOWrongKey() { | ||
|
||
// mocking decoupler cached keys | ||
when(cacheRepository.read(anyString(), any())).thenReturn("wrong_string"); | ||
|
||
try { | ||
decouplerService.getCachedMappingFromNavToIuv(DOMAIN_ID, NAV); | ||
fail(); | ||
} catch (AppException e) { | ||
assertEquals(AppErrorCodeMessageEnum.PERSISTENCE_MAPPING_NAV_TO_IUV_ERROR, e.getError()); | ||
} | ||
} | ||
} |