diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/GetSessionResult.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/GetSessionResult.java index 5c56bad8..87e2f233 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/GetSessionResult.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/GetSessionResult.java @@ -100,6 +100,14 @@ public ImportTokenResponse getImportToken() { return importToken; } + public ResourceContainer getResourcesForCheck(String checkId) { + CheckResponse checkResponse = this.checks.stream() + .filter(check -> check.getId().equals(checkId)) + .findFirst() + .orElseThrow(() -> new IllegalArgumentException("Check not found")); + return resources.filterForCheck(checkResponse); + } + public List getAuthenticityChecks() { return filterChecksByType(AuthenticityCheckResponse.class); } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ResourceContainer.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ResourceContainer.java index 857f8f1d..8d25c591 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ResourceContainer.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ResourceContainer.java @@ -1,7 +1,8 @@ package com.yoti.api.client.docs.session.retrieve; -import java.util.ArrayList; +import java.util.Collections; import java.util.List; +import java.util.stream.Collectors; import com.fasterxml.jackson.annotation.JsonProperty; @@ -72,7 +73,20 @@ public List getZoomLivenessResources() { * * @return the list of static liveness resources */ - public List getStaticLivenessResources() { return filterLivenessResourcesByType(StaticLivenessResourceResponse.class); } + public List getStaticLivenessResources() { + return filterLivenessResourcesByType(StaticLivenessResourceResponse.class); + } + + private List filterLivenessResourcesByType(Class clazz) { + if (livenessCapture == null) { + return Collections.emptyList(); + } else { + return livenessCapture.stream() + .filter(clazz::isInstance) + .map(clazz::cast) + .collect(Collectors.toList()); + } + } /** * Returns ApplicantProfile resources uploaded by the user/relying business @@ -83,14 +97,23 @@ public List getApplicantProfiles() { return applicantProfiles; } - private List filterLivenessResourcesByType(Class clazz) { - List filteredList = new ArrayList<>(); - for (LivenessResourceResponse livenessResourceResponse : livenessCapture) { - if (clazz.isInstance(livenessResourceResponse)) { - filteredList.add(clazz.cast(livenessResourceResponse)); - } + ResourceContainer filterForCheck(CheckResponse checkResponse) { + ResourceContainer newResourceContainer = new ResourceContainer(); + newResourceContainer.idDocuments = filterResources(this.idDocuments, checkResponse.getResourcesUsed()); + newResourceContainer.supplementaryDocuments = filterResources(this.supplementaryDocuments, checkResponse.getResourcesUsed()); + newResourceContainer.livenessCapture = filterResources(this.livenessCapture, checkResponse.getResourcesUsed()); + newResourceContainer.faceCapture = filterResources(this.faceCapture, checkResponse.getResourcesUsed()); + newResourceContainer.applicantProfiles = filterResources(this.applicantProfiles, checkResponse.getResourcesUsed()); + return newResourceContainer; + } + + private List filterResources(List resources, List resourceIds) { + if (resources == null) { + return Collections.emptyList(); } - return filteredList; + return resources.stream() + .filter(resource -> resourceIds.contains(resource.getId())) + .collect(Collectors.toList()); } } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java deleted file mode 100644 index e0c64455..00000000 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.yoti.api.client.docs.session.retrieve; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.yoti.api.client.spi.remote.util.FieldSetter; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class GetSessionResultCheckTest { - - private static final int SESSION_CHECKS = 14; - - @Mock AuthenticityCheckResponse authenticityCheckResponse; - @Mock FaceMatchCheckResponse faceMatchCheckResponse; - @Mock FaceComparisonCheckResponse faceComparisonCheckResponse; - @Mock TextDataCheckResponse textDataCheckResponse; - @Mock SupplementaryDocumentTextDataCheckResponse supplementaryDocumentTextDataCheckResponse; - @Mock LivenessCheckResponse livenessCheckResponse; - @Mock IdDocumentComparisonCheckResponse idDocumentComparisonCheckResponse; - @Mock ThirdPartyIdentityCheckResponse thirdPartyIdentityCheckResponse; - @Mock WatchlistScreeningCheckResponse watchlistScreeningCheckResponse; - @Mock ThirdPartyIdentityFraudOneCheckResponse thirdPartyIdentityFraudOneCheckResponse; - @Mock IbvVisualReviewCheckResponse ibvVisualReviewCheckResponse; - @Mock DocumentSchemeValidityCheckResponse documentSchemeValidityCheckResponse; - @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponse; - @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponse; - - GetSessionResult getSessionResult; - - @Test - public void shouldFilterAuthenticityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getAuthenticityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterLivenessChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getLivenessChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterTextDataChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIdDocumentTextDataChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterSupplementaryDocumentTextDataChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getSupplementaryDocumentTextDataChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterFaceMatchChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getFaceMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterFaceComparisonChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getFaceComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterIdDocumentComparisonChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIdDocumentComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterThirdPartyIdentityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterWatchlistScreeningChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getWatchlistScreeningChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterIbvVisualReviewChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIbvVisualReviewChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterDocumentSchemeValidityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getDocumentSchemeValidityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterProfileDocumentMatchChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getProfileDocumentMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterThirdPartyIdentityFraudOneCheck() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityFraudOneChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterSynecticsIdentityFraudCheck() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getSynecticsIdentityFraudChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldReturnEmptyLists() { - getSessionResult = new GetSessionResult(); - - FieldSetter.setField( - getSessionResult, - "checks", - new ArrayList<>() - ); - - assertThat(getSessionResult.getChecks(), hasSize(0)); - assertThat(getSessionResult.getAuthenticityChecks(), hasSize(0)); - assertThat(getSessionResult.getFaceMatchChecks(), hasSize(0)); - assertThat(getSessionResult.getIdDocumentTextDataChecks(), hasSize(0)); - assertThat(getSessionResult.getSupplementaryDocumentTextDataChecks(), hasSize(0)); - assertThat(getSessionResult.getLivenessChecks(), hasSize(0)); - assertThat(getSessionResult.getThirdPartyIdentityFraudOneChecks(), hasSize(0)); - assertThat(getSessionResult.getSynecticsIdentityFraudChecks(), hasSize(0)); - } - - private void setupGetSessionResult() { - FieldSetter.setField( - getSessionResult, - "checks", - Arrays.asList( - authenticityCheckResponse, - livenessCheckResponse, - textDataCheckResponse, - supplementaryDocumentTextDataCheckResponse, - faceMatchCheckResponse, - faceComparisonCheckResponse, - idDocumentComparisonCheckResponse, - thirdPartyIdentityCheckResponse, - watchlistScreeningCheckResponse, - thirdPartyIdentityFraudOneCheckResponse, - ibvVisualReviewCheckResponse, - documentSchemeValidityCheckResponse, - profileDocumentMatchCheckResponse, - synecticsIdentityFraudCheckResponse - ) - ); - } - -} diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java index fb9de223..aad431fa 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java @@ -1,205 +1,105 @@ package com.yoti.api.client.docs.session.retrieve; -import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET; - import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThrows; +import static org.mockito.Mockito.when; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; -import com.yoti.api.client.docs.session.create.SessionSpec; +import com.yoti.api.client.spi.remote.util.FieldSetter; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class GetSessionResultTest { - private static final ObjectMapper MAPPER = getMapper(); - - @Test - public void shouldReturnIdentityProfile() throws IOException { - Map scheme = new HashMap<>(); - scheme.put(Property.TYPE, "A_TYPE"); - scheme.put(Property.OBJECTIVE, "AN_OBJECTIVE"); - - Map schemesCompliance = new HashMap<>(); - schemesCompliance.put(Property.SCHEME, scheme); - - Map media = new HashMap<>(); - media.put(Property.ID, "A_MEDIA_ID"); - media.put(Property.TYPE, "A_TYPE"); - - Map identityProfileReport = new HashMap<>(); - identityProfileReport.put(Property.TRUST_FRAMEWORK, "A_FRAMEWORK"); - identityProfileReport.put(Property.SCHEMES_COMPLIANCE, schemesCompliance); - identityProfileReport.put(Property.MEDIA, media); - - Map identityProfile = new HashMap<>(); - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); - identityProfile.put(Property.RESULT, "A_RESULT"); - identityProfile.put(Property.IDENTITY_PROFILE_REPORT, identityProfileReport); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE, identityProfile); - - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); - - assertThat(sessionResultIdentityProfile, is(notNullValue())); - assertThat( - sessionResultIdentityProfile.getSubjectId(), - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) - ); - assertThat( - sessionResultIdentityProfile.getResult(), - is(equalTo(identityProfile.get(Property.RESULT))) - ); - assertThat(sessionResultIdentityProfile.getFailureReason(), is(nullValue())); - - JsonNode jsonIdentityProfileResponse = toSessionJson(sessionResultIdentityProfile.getIdentityProfileReport()); - - assertThat(jsonIdentityProfileResponse, is(notNullValue())); - assertThat( - jsonIdentityProfileResponse.get(Property.TRUST_FRAMEWORK).asText(), - is(equalTo(identityProfileReport.get(Property.TRUST_FRAMEWORK))) - ); - - JsonNode schemesComplianceResponse = jsonIdentityProfileResponse.get(Property.SCHEMES_COMPLIANCE); - assertThat(schemesComplianceResponse, is(notNullValue())); - - JsonNode schemeResponse = schemesComplianceResponse.get("scheme"); - assertThat(schemeResponse, is(notNullValue())); - assertThat(schemeResponse.get(Property.TYPE).asText(), is(equalTo(scheme.get(Property.TYPE)))); - assertThat(schemeResponse.get(Property.OBJECTIVE).asText(), is(equalTo(scheme.get(Property.OBJECTIVE)))); - - JsonNode mediaResponse = jsonIdentityProfileResponse.get(Property.MEDIA); - assertThat(mediaResponse, is(notNullValue())); - assertThat(mediaResponse.get(Property.ID).asText(), is(equalTo(media.get(Property.ID)))); - assertThat(mediaResponse.get(Property.TYPE).asText(), is(equalTo(media.get(Property.TYPE)))); + private static final String AUTH_CHECK_ID = "authCheckId"; + + @InjectMocks GetSessionResult testObj = new GetSessionResult(); + + @Mock AuthenticityCheckResponse authenticityCheckResponseMock; + @Mock FaceMatchCheckResponse faceMatchCheckResponseMock; + @Mock FaceComparisonCheckResponse faceComparisonCheckResponseMock; + @Mock TextDataCheckResponse textDataCheckResponseMock; + @Mock SupplementaryDocumentTextDataCheckResponse supplementaryDocumentTextDataCheckResponseMock; + @Mock LivenessCheckResponse livenessCheckResponseMock; + @Mock IdDocumentComparisonCheckResponse idDocumentComparisonCheckResponseMock; + @Mock ThirdPartyIdentityCheckResponse thirdPartyIdentityCheckResponseMock; + @Mock WatchlistScreeningCheckResponse watchlistScreeningCheckResponseMock; + @Mock ThirdPartyIdentityFraudOneCheckResponse thirdPartyIdentityFraudOneCheckResponseMock; + @Mock IbvVisualReviewCheckResponse ibvVisualReviewCheckResponseMock; + @Mock DocumentSchemeValidityCheckResponse documentSchemeValidityCheckResponseMock; + @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponseMock; + @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponseMock; + + @Mock(name = "resources") ResourceContainer resourceContainerMock; + @Mock ResourceContainer checkResourceContainerMock; + + @Before + public void setUp() throws Exception { + when(authenticityCheckResponseMock.getId()).thenReturn(AUTH_CHECK_ID); } @Test - public void shouldReturnFailureIdentityProfile() throws IOException { - Map failureReason = new HashMap<>(); - failureReason.put(Property.REASON_CODE, "A_FAILURE_REASON_CODE"); - - Map identityProfile = new HashMap<>(); - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); - identityProfile.put(Property.RESULT, "A_RESULT"); - identityProfile.put(Property.FAILURE_REASON, failureReason); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE, identityProfile); - - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); - - assertThat(sessionResultIdentityProfile, is(notNullValue())); - assertThat( - sessionResultIdentityProfile.getSubjectId(), - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) - ); - assertThat( - sessionResultIdentityProfile.getResult(), - is(equalTo(identityProfile.get(Property.RESULT))) - ); - - IdentityProfileFailureResponse sessionResultFailureReason = sessionResultIdentityProfile.getFailureReason(); - assertThat(sessionResultFailureReason, is(notNullValue())); - assertThat( - sessionResultFailureReason.getReasonCode(), - is(equalTo(failureReason.get(Property.REASON_CODE))) + public void shouldFilterChecks() { + List allChecks = Arrays.asList( + authenticityCheckResponseMock, + livenessCheckResponseMock, + textDataCheckResponseMock, + supplementaryDocumentTextDataCheckResponseMock, + faceMatchCheckResponseMock, + faceComparisonCheckResponseMock, + idDocumentComparisonCheckResponseMock, + thirdPartyIdentityCheckResponseMock, + watchlistScreeningCheckResponseMock, + thirdPartyIdentityFraudOneCheckResponseMock, + ibvVisualReviewCheckResponseMock, + documentSchemeValidityCheckResponseMock, + profileDocumentMatchCheckResponseMock, + synecticsIdentityFraudCheckResponseMock ); + FieldSetter.setField(testObj, "checks", allChecks); + + assertThat(testObj.getAuthenticityChecks(), contains(authenticityCheckResponseMock)); + assertThat(testObj.getLivenessChecks(), contains(livenessCheckResponseMock)); + assertThat(testObj.getIdDocumentTextDataChecks(), contains(textDataCheckResponseMock)); + assertThat(testObj.getSupplementaryDocumentTextDataChecks(), contains(supplementaryDocumentTextDataCheckResponseMock)); + assertThat(testObj.getFaceMatchChecks(), contains(faceMatchCheckResponseMock)); + assertThat(testObj.getFaceComparisonChecks(), contains(faceComparisonCheckResponseMock)); + assertThat(testObj.getIdDocumentComparisonChecks(), contains(idDocumentComparisonCheckResponseMock)); + assertThat(testObj.getThirdPartyIdentityChecks(), contains(thirdPartyIdentityCheckResponseMock)); + assertThat(testObj.getWatchlistScreeningChecks(), contains(watchlistScreeningCheckResponseMock)); + assertThat(testObj.getIbvVisualReviewChecks(), contains(ibvVisualReviewCheckResponseMock)); + assertThat(testObj.getDocumentSchemeValidityChecks(), contains(documentSchemeValidityCheckResponseMock)); + assertThat(testObj.getProfileDocumentMatchChecks(), contains(profileDocumentMatchCheckResponseMock)); + assertThat(testObj.getThirdPartyIdentityFraudOneChecks(), contains(thirdPartyIdentityFraudOneCheckResponseMock)); + assertThat(testObj.getSynecticsIdentityFraudChecks(), contains(synecticsIdentityFraudCheckResponseMock)); } @Test - public void shouldReturnIdentityProfilePreview() { - Map media = new HashMap<>(); - media.put(Property.ID, "someId"); - media.put(Property.TYPE, "someType"); - media.put(Property.CREATED, "someCreatedTime"); - media.put(Property.LAST_UPDATED, "someLastUpdatedTime"); - - Map identityProfilePreview = new HashMap<>(); - identityProfilePreview.put(Property.MEDIA, media); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE_PREVIEW, identityProfilePreview); + public void getResourcesForCheck_shouldThrowExceptionForBadCheckId() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfilePreviewResponse sessionResultIdentityProfilePreview = sessionResult.getIdentityProfilePreview(); - - assertThat(sessionResultIdentityProfilePreview, is(notNullValue())); - - MediaResponse identityProfilePreviewMedia = sessionResultIdentityProfilePreview.getMedia(); - - assertThat(identityProfilePreviewMedia, is(notNullValue())); - - assertThat( - identityProfilePreviewMedia.getId(), - is(equalTo(media.get(Property.ID))) - ); - assertThat( - identityProfilePreviewMedia.getType(), - is(equalTo(media.get(Property.TYPE))) - ); - assertThat( - identityProfilePreviewMedia.getCreated(), - is(equalTo(media.get(Property.CREATED))) - ); - assertThat( - identityProfilePreviewMedia.getLastUpdated(), - is(equalTo(media.get(Property.LAST_UPDATED))) - ); + assertThrows(IllegalArgumentException.class, () -> testObj.getResourcesForCheck("someBadCheckId")); } - private static GetSessionResult toGetSessionResult(Object obj) { - return MAPPER.convertValue(obj, GetSessionResult.class); - } - - private static JsonNode toSessionJson(Map identityProfile) throws IOException { - SessionSpec session = SessionSpec.builder() - .withIdentityProfile(identityProfile) - .build(); - - return MAPPER.readTree(MAPPER.writeValueAsString(session.getIdentityProfile()).getBytes(DEFAULT_CHARSET)); - } - - private static ObjectMapper getMapper() { - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - - return mapper; - } + @Test + public void getResourcesForCheck_shouldReturnResultFromResources() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); + when(resourceContainerMock.filterForCheck(authenticityCheckResponseMock)).thenReturn(checkResourceContainerMock); - private static final class Property { - - private static final String IDENTITY_PROFILE = "identity_profile"; - private static final String IDENTITY_PROFILE_PREVIEW = "identity_profile_preview"; - private static final String SUBJECT_ID = "subject_id"; - private static final String RESULT = "result"; - private static final String FAILURE_REASON = "failure_reason"; - private static final String IDENTITY_PROFILE_REPORT = "identity_profile_report"; - private static final String TRUST_FRAMEWORK = "trust_framework"; - private static final String REASON_CODE = "reason_code"; - private static final String SCHEMES_COMPLIANCE = "schemes_compliance"; - private static final String SCHEME = "scheme"; - private static final String OBJECTIVE = "objective"; - private static final String MEDIA = "media"; - private static final String ID = "id"; - private static final String TYPE = "type"; - private static final String CREATED = "created"; - private static final String LAST_UPDATED = "last_updated"; - - private Property() { } + ResourceContainer result = testObj.getResourcesForCheck(AUTH_CHECK_ID); + assertThat(result, is(checkResourceContainerMock)); } } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java index eca9dd5b..85270ea4 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java @@ -1,14 +1,20 @@ package com.yoti.api.client.docs.session.retrieve; +import static java.util.Arrays.asList; + import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.emptyIterable; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import com.yoti.api.client.spi.remote.util.FieldSetter; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -17,63 +23,123 @@ @RunWith(MockitoJUnitRunner.class) public class ResourceContainerTest { - @Mock ZoomLivenessResourceResponse zoomLivenessResourceResponseMock; - @Mock StaticLivenessResourceResponse staticLivenessResourceResponseMock; - @Mock LivenessResourceResponse livenessResourceResponse; + private static final String ID_DOC_1_ID = "idDocumentResource1Id"; + private static final String SUPPLEMENTARY_DOC_1_ID = "supplementaryDocResource1Id"; + private static final String ZOOM_RESOURCE_1_ID = "zoomLivenessResource1MockId"; + private static final String FACE_CAPTURE_1_ID = "faceCaptureResource1Id"; + private static final String PROFILE_1_ID = "applicantProfileResource1Id"; + + ResourceContainer testObj = new ResourceContainer(); + + @Mock IdDocumentResourceResponse idDocResourceResponse1Mock; + @Mock IdDocumentResourceResponse idDocResourceResponse2Mock; + @Mock SupplementaryDocumentResourceResponse supplementaryDocResourceResponse1Mock; + @Mock SupplementaryDocumentResourceResponse supplementaryDocResourceResponse2Mock; + @Mock ZoomLivenessResourceResponse zoomLivenessResource1Mock; + @Mock ZoomLivenessResourceResponse zoomLivenessResource2Mock; + @Mock StaticLivenessResourceResponse staticLivenessResourceMock; + @Mock LivenessResourceResponse livenessResource; + @Mock FaceCaptureResourceResponse faceCaptureResourceResponse1Mock; + @Mock FaceCaptureResourceResponse faceCaptureResourceResponse2Mock; + @Mock ApplicantProfileResourceResponse applicantProfileResourceResponse1Mock; + @Mock ApplicantProfileResourceResponse applicantProfileResourceResponse2Mock; + + @Mock CheckResponse checkResponseMock; + + @Before + public void setUp() throws Exception { + when(idDocResourceResponse1Mock.getId()).thenReturn(ID_DOC_1_ID); + when(idDocResourceResponse2Mock.getId()).thenReturn("idDocumentResource2Id"); + when(supplementaryDocResourceResponse1Mock.getId()).thenReturn(SUPPLEMENTARY_DOC_1_ID); + when(supplementaryDocResourceResponse2Mock.getId()).thenReturn("supplementaryDocResource2Id"); + when(zoomLivenessResource1Mock.getId()).thenReturn(ZOOM_RESOURCE_1_ID); + when(zoomLivenessResource2Mock.getId()).thenReturn("zoomLivenessResource2MockId"); + when(faceCaptureResourceResponse1Mock.getId()).thenReturn(FACE_CAPTURE_1_ID); + when(faceCaptureResourceResponse2Mock.getId()).thenReturn("faceCaptureResource2Id"); + when(applicantProfileResourceResponse1Mock.getId()).thenReturn(PROFILE_1_ID); + when(applicantProfileResourceResponse2Mock.getId()).thenReturn("applicantProfileResource2Id"); + } + + @Test + public void getZoomLivenessResources_shouldFilterZoomLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getZoomLivenessResources(); - ResourceContainer simpleResourceContainer; + assertThat(result, contains(zoomLivenessResource1Mock)); + } @Test - public void shouldFilterZoomLivenessResources() { - simpleResourceContainer = new ResourceContainer(); - - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - Arrays.asList( - zoomLivenessResourceResponseMock, - livenessResourceResponse, - livenessResourceResponse - ) - ); - - List result = simpleResourceContainer.getZoomLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(3)); - assertThat(result, hasSize(1)); + public void getZoomLivenessResources_shouldReturnEmptyList() { + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); + + List result = testObj.getZoomLivenessResources(); + + assertThat(result, hasSize(0)); } @Test - public void shouldFilterStaticLivenessResources() { - simpleResourceContainer = new ResourceContainer(); - - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - Arrays.asList( - staticLivenessResourceResponseMock, - livenessResourceResponse, - livenessResourceResponse - ) - ); - - List result = simpleResourceContainer.getStaticLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(3)); - assertThat(result, hasSize(1)); + public void getStaticLivenessResources_shouldFilterStaticLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getStaticLivenessResources(); + + assertThat(result, contains(staticLivenessResourceMock)); } @Test - public void shouldReturnEmptyList() { - simpleResourceContainer = new ResourceContainer(); + public void getStaticLivenessResources_shouldReturnEmptyList() { + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - new ArrayList<>() - ); + List result = testObj.getStaticLivenessResources(); - List result = simpleResourceContainer.getZoomLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(0)); assertThat(result, hasSize(0)); } + @Test + public void filterForCheck_shouldHandleNullResources() { + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), is(emptyIterable())); + assertThat(result.getSupplementaryDocuments(), is(emptyIterable())); + assertThat(result.getLivenessCapture(), is(emptyIterable())); + assertThat(result.getFaceCapture(), is(emptyIterable())); + assertThat(result.getApplicantProfiles(), is(emptyIterable())); + } + + @Test + public void filterForCheck_shouldReturnEmptyWhenNoMatches() { + FieldSetter.setField(testObj, "idDocuments", new ArrayList<>()); + FieldSetter.setField(testObj, "supplementaryDocuments", new ArrayList<>()); + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); + FieldSetter.setField(testObj, "faceCapture", new ArrayList<>()); + FieldSetter.setField(testObj, "applicantProfiles", new ArrayList<>()); + + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), is(emptyIterable())); + assertThat(result.getSupplementaryDocuments(), is(emptyIterable())); + assertThat(result.getLivenessCapture(), is(emptyIterable())); + assertThat(result.getFaceCapture(), is(emptyIterable())); + assertThat(result.getApplicantProfiles(), is(emptyIterable())); + } + + @Test + public void filterForCheck_shouldReturnFilteredCollections() { + FieldSetter.setField(testObj, "idDocuments", asList(idDocResourceResponse1Mock, idDocResourceResponse2Mock)); + FieldSetter.setField(testObj, "supplementaryDocuments", asList(supplementaryDocResourceResponse1Mock, supplementaryDocResourceResponse2Mock)); + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, zoomLivenessResource2Mock, staticLivenessResourceMock)); + FieldSetter.setField(testObj, "faceCapture", asList(faceCaptureResourceResponse1Mock, faceCaptureResourceResponse2Mock)); + FieldSetter.setField(testObj, "applicantProfiles", asList(applicantProfileResourceResponse1Mock, applicantProfileResourceResponse2Mock)); + when(checkResponseMock.getResourcesUsed()).thenReturn(asList(ID_DOC_1_ID, SUPPLEMENTARY_DOC_1_ID, ZOOM_RESOURCE_1_ID, FACE_CAPTURE_1_ID, PROFILE_1_ID)); + + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), contains(idDocResourceResponse1Mock)); + assertThat(result.getSupplementaryDocuments(), contains(supplementaryDocResourceResponse1Mock)); + assertThat(result.getLivenessCapture(), contains(zoomLivenessResource1Mock)); + assertThat(result.getFaceCapture(), contains(faceCaptureResourceResponse1Mock)); + assertThat(result.getApplicantProfiles(), contains(applicantProfileResourceResponse1Mock)); + } + }