-
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.
Improved error handling and added some more tests (#54)
- Loading branch information
1 parent
8e54a64
commit 42d7847
Showing
2 changed files
with
57 additions
and
3 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
53 changes: 53 additions & 0 deletions
53
src/test/java/no/ssb/dlp/pseudo/service/sid/ExternalSidServiceTest.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,53 @@ | ||
package no.ssb.dlp.pseudo.service.sid; | ||
|
||
import io.micronaut.core.async.publisher.Publishers; | ||
import io.micronaut.test.annotation.MockBean; | ||
import io.micronaut.test.extensions.junit5.annotation.MicronautTest; | ||
import org.junit.jupiter.api.Test; | ||
|
||
import javax.inject.Inject; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.Optional; | ||
|
||
import static org.mockito.Mockito.*; | ||
|
||
@MicronautTest | ||
public class ExternalSidServiceTest { | ||
|
||
@Inject | ||
SidService sidService; | ||
@Inject | ||
SidClient sidClient; | ||
|
||
@Test | ||
public void testInvokeSingleFnr() { | ||
// sidService should call our sidClient mock | ||
when(sidClient.lookup(any(SidRequest.class))).thenReturn(Publishers.just( | ||
SidInfo.builder().fnr("11854898347").snr("0001ha3").build()) | ||
); | ||
sidService.lookupFnr("11854898347", Optional.ofNullable(null)); | ||
|
||
verify(sidClient, times(1)).lookup(any(SidRequest.class)); | ||
} | ||
|
||
@Test | ||
public void testInvokeMultiFnr() { | ||
// sidService should call our sidClient mock | ||
when(sidClient.lookup(any(MultiSidRequest.class))).thenReturn(Publishers.just( | ||
MultiSidResponse.builder().mapping(MultiSidResponse.Mapping.builder() | ||
.fnrList(Arrays.asList("11854898347")) | ||
.fnr(Arrays.asList("11854898347")) | ||
.snr(Arrays.asList("0001ha3")) | ||
.build()).build()) | ||
); | ||
sidService.lookupFnr(List.of("11854898347"), Optional.ofNullable(null)); | ||
|
||
verify(sidClient, times(1)).lookup(any(MultiSidRequest.class)); | ||
} | ||
@MockBean(SidClient.class) | ||
SidClient sidClient() { | ||
return mock(SidClient.class); | ||
} | ||
} |