From 30bf99f424b6cf82e64eb7b51331ab680e80d65c Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 13:56:39 +0100 Subject: [PATCH 1/7] NA: Drop unhelpful tests on GetSessionResult --- .../retrieve/GetSessionResultCheckTest.java | 115 ++++-------------- 1 file changed, 23 insertions(+), 92 deletions(-) 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 index e0c64455..09628cac 100644 --- 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 @@ -9,6 +9,7 @@ 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; @@ -34,185 +35,115 @@ public class GetSessionResultCheckTest { @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponse; @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponse; - GetSessionResult getSessionResult; + GetSessionResult testObj; + + @Before + public void setUp() throws Exception { + testObj = new GetSessionResult(); + setupGetSessionResult(); + } @Test public void shouldFilterAuthenticityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); + List result = testObj.getAuthenticityChecks(); - List result = getSessionResult.getAuthenticityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterLivenessChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getLivenessChecks(); - setupGetSessionResult(); - - List result = getSessionResult.getLivenessChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterTextDataChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getIdDocumentTextDataChecks(); - 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 = testObj.getSupplementaryDocumentTextDataChecks(); - List result = getSessionResult.getSupplementaryDocumentTextDataChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterFaceMatchChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); + List result = testObj.getFaceMatchChecks(); - List result = getSessionResult.getFaceMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterFaceComparisonChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); + List result = testObj.getFaceComparisonChecks(); - List result = getSessionResult.getFaceComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterIdDocumentComparisonChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getIdDocumentComparisonChecks(); - setupGetSessionResult(); - - List result = getSessionResult.getIdDocumentComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterThirdPartyIdentityChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getThirdPartyIdentityChecks(); - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterWatchlistScreeningChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getWatchlistScreeningChecks(); - 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 = testObj.getIbvVisualReviewChecks(); - List result = getSessionResult.getIbvVisualReviewChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterDocumentSchemeValidityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); + List result = testObj.getDocumentSchemeValidityChecks(); - List result = getSessionResult.getDocumentSchemeValidityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterProfileDocumentMatchChecks() { - getSessionResult = new GetSessionResult(); + List result = testObj.getProfileDocumentMatchChecks(); - setupGetSessionResult(); - - List result = getSessionResult.getProfileDocumentMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterThirdPartyIdentityFraudOneCheck() { - getSessionResult = new GetSessionResult(); + List result = testObj.getThirdPartyIdentityFraudOneChecks(); - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityFraudOneChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); assertThat(result, hasSize(1)); } @Test public void shouldFilterSynecticsIdentityFraudCheck() { - getSessionResult = new GetSessionResult(); + List result = testObj.getSynecticsIdentityFraudChecks(); - 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, + testObj, "checks", Arrays.asList( authenticityCheckResponse, From 2718a929ade255ae1dc748627960aa42afb056ed Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:01:00 +0100 Subject: [PATCH 2/7] NA: Make remaining tests in GetSessionResultCheckTest a little more helpful --- .../retrieve/GetSessionResultCheckTest.java | 33 +++++++++---------- 1 file changed, 15 insertions(+), 18 deletions(-) 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 index 09628cac..9aab24de 100644 --- 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 @@ -1,9 +1,8 @@ package com.yoti.api.client.docs.session.retrieve; import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.contains; -import java.util.ArrayList; import java.util.Arrays; import java.util.List; @@ -18,8 +17,6 @@ @RunWith(MockitoJUnitRunner.class) public class GetSessionResultCheckTest { - private static final int SESSION_CHECKS = 14; - @Mock AuthenticityCheckResponse authenticityCheckResponse; @Mock FaceMatchCheckResponse faceMatchCheckResponse; @Mock FaceComparisonCheckResponse faceComparisonCheckResponse; @@ -47,98 +44,98 @@ public void setUp() throws Exception { public void shouldFilterAuthenticityChecks() { List result = testObj.getAuthenticityChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(authenticityCheckResponse)); } @Test public void shouldFilterLivenessChecks() { List result = testObj.getLivenessChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(livenessCheckResponse)); } @Test public void shouldFilterTextDataChecks() { List result = testObj.getIdDocumentTextDataChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(textDataCheckResponse)); } @Test public void shouldFilterSupplementaryDocumentTextDataChecks() { List result = testObj.getSupplementaryDocumentTextDataChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(supplementaryDocumentTextDataCheckResponse)); } @Test public void shouldFilterFaceMatchChecks() { List result = testObj.getFaceMatchChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(faceMatchCheckResponse)); } @Test public void shouldFilterFaceComparisonChecks() { List result = testObj.getFaceComparisonChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(faceComparisonCheckResponse)); } @Test public void shouldFilterIdDocumentComparisonChecks() { List result = testObj.getIdDocumentComparisonChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(idDocumentComparisonCheckResponse)); } @Test public void shouldFilterThirdPartyIdentityChecks() { List result = testObj.getThirdPartyIdentityChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(thirdPartyIdentityCheckResponse)); } @Test public void shouldFilterWatchlistScreeningChecks() { List result = testObj.getWatchlistScreeningChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(watchlistScreeningCheckResponse)); } @Test public void shouldFilterIbvVisualReviewChecks() { List result = testObj.getIbvVisualReviewChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(ibvVisualReviewCheckResponse)); } @Test public void shouldFilterDocumentSchemeValidityChecks() { List result = testObj.getDocumentSchemeValidityChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(documentSchemeValidityCheckResponse)); } @Test public void shouldFilterProfileDocumentMatchChecks() { List result = testObj.getProfileDocumentMatchChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(profileDocumentMatchCheckResponse)); } @Test public void shouldFilterThirdPartyIdentityFraudOneCheck() { List result = testObj.getThirdPartyIdentityFraudOneChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(thirdPartyIdentityFraudOneCheckResponse)); } @Test public void shouldFilterSynecticsIdentityFraudCheck() { List result = testObj.getSynecticsIdentityFraudChecks(); - assertThat(result, hasSize(1)); + assertThat(result, contains(synecticsIdentityFraudCheckResponse)); } private void setupGetSessionResult() { From 6df581d3bf0958dccf6bbff46db41b8796ffa6e6 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:05:18 +0100 Subject: [PATCH 3/7] NA: Consolidate remaining tests in GetSessionResultCheckTest --- .../retrieve/GetSessionResultCheckTest.java | 160 ++++-------------- 1 file changed, 34 insertions(+), 126 deletions(-) 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 index 9aab24de..ab962765 100644 --- 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 @@ -8,7 +8,6 @@ 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,6 +16,8 @@ @RunWith(MockitoJUnitRunner.class) public class GetSessionResultCheckTest { + GetSessionResult testObj = new GetSessionResult(); + @Mock AuthenticityCheckResponse authenticityCheckResponse; @Mock FaceMatchCheckResponse faceMatchCheckResponse; @Mock FaceComparisonCheckResponse faceComparisonCheckResponse; @@ -32,133 +33,40 @@ public class GetSessionResultCheckTest { @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponse; @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponse; - GetSessionResult testObj; - - @Before - public void setUp() throws Exception { - testObj = new GetSessionResult(); - setupGetSessionResult(); - } - - @Test - public void shouldFilterAuthenticityChecks() { - List result = testObj.getAuthenticityChecks(); - - assertThat(result, contains(authenticityCheckResponse)); - } - - @Test - public void shouldFilterLivenessChecks() { - List result = testObj.getLivenessChecks(); - - assertThat(result, contains(livenessCheckResponse)); - } - - @Test - public void shouldFilterTextDataChecks() { - List result = testObj.getIdDocumentTextDataChecks(); - - assertThat(result, contains(textDataCheckResponse)); - } - - @Test - public void shouldFilterSupplementaryDocumentTextDataChecks() { - List result = testObj.getSupplementaryDocumentTextDataChecks(); - - assertThat(result, contains(supplementaryDocumentTextDataCheckResponse)); - } - @Test - public void shouldFilterFaceMatchChecks() { - List result = testObj.getFaceMatchChecks(); - - assertThat(result, contains(faceMatchCheckResponse)); - } - - @Test - public void shouldFilterFaceComparisonChecks() { - List result = testObj.getFaceComparisonChecks(); - - assertThat(result, contains(faceComparisonCheckResponse)); - } - - @Test - public void shouldFilterIdDocumentComparisonChecks() { - List result = testObj.getIdDocumentComparisonChecks(); - - assertThat(result, contains(idDocumentComparisonCheckResponse)); - } - - @Test - public void shouldFilterThirdPartyIdentityChecks() { - List result = testObj.getThirdPartyIdentityChecks(); - - assertThat(result, contains(thirdPartyIdentityCheckResponse)); - } - - @Test - public void shouldFilterWatchlistScreeningChecks() { - List result = testObj.getWatchlistScreeningChecks(); - - assertThat(result, contains(watchlistScreeningCheckResponse)); - } - - @Test - public void shouldFilterIbvVisualReviewChecks() { - List result = testObj.getIbvVisualReviewChecks(); - - assertThat(result, contains(ibvVisualReviewCheckResponse)); - } - - @Test - public void shouldFilterDocumentSchemeValidityChecks() { - List result = testObj.getDocumentSchemeValidityChecks(); - - assertThat(result, contains(documentSchemeValidityCheckResponse)); - } - - @Test - public void shouldFilterProfileDocumentMatchChecks() { - List result = testObj.getProfileDocumentMatchChecks(); - - assertThat(result, contains(profileDocumentMatchCheckResponse)); - } - - @Test - public void shouldFilterThirdPartyIdentityFraudOneCheck() { - List result = testObj.getThirdPartyIdentityFraudOneChecks(); - - assertThat(result, contains(thirdPartyIdentityFraudOneCheckResponse)); - } - - @Test - public void shouldFilterSynecticsIdentityFraudCheck() { - List result = testObj.getSynecticsIdentityFraudChecks(); - - assertThat(result, contains(synecticsIdentityFraudCheckResponse)); - } - - private void setupGetSessionResult() { - FieldSetter.setField( - testObj, - "checks", - Arrays.asList( - authenticityCheckResponse, - livenessCheckResponse, - textDataCheckResponse, - supplementaryDocumentTextDataCheckResponse, - faceMatchCheckResponse, - faceComparisonCheckResponse, - idDocumentComparisonCheckResponse, - thirdPartyIdentityCheckResponse, - watchlistScreeningCheckResponse, - thirdPartyIdentityFraudOneCheckResponse, - ibvVisualReviewCheckResponse, - documentSchemeValidityCheckResponse, - profileDocumentMatchCheckResponse, - synecticsIdentityFraudCheckResponse - ) + public void shouldFilterChecks() { + List allChecks = Arrays.asList( + authenticityCheckResponse, + livenessCheckResponse, + textDataCheckResponse, + supplementaryDocumentTextDataCheckResponse, + faceMatchCheckResponse, + faceComparisonCheckResponse, + idDocumentComparisonCheckResponse, + thirdPartyIdentityCheckResponse, + watchlistScreeningCheckResponse, + thirdPartyIdentityFraudOneCheckResponse, + ibvVisualReviewCheckResponse, + documentSchemeValidityCheckResponse, + profileDocumentMatchCheckResponse, + synecticsIdentityFraudCheckResponse ); + FieldSetter.setField(testObj, "checks", allChecks); + + assertThat(testObj.getAuthenticityChecks(), contains(authenticityCheckResponse)); + assertThat(testObj.getLivenessChecks(), contains(livenessCheckResponse)); + assertThat(testObj.getIdDocumentTextDataChecks(), contains(textDataCheckResponse)); + assertThat(testObj.getSupplementaryDocumentTextDataChecks(), contains(supplementaryDocumentTextDataCheckResponse)); + assertThat(testObj.getFaceMatchChecks(), contains(faceMatchCheckResponse)); + assertThat(testObj.getFaceComparisonChecks(), contains(faceComparisonCheckResponse)); + assertThat(testObj.getIdDocumentComparisonChecks(), contains(idDocumentComparisonCheckResponse)); + assertThat(testObj.getThirdPartyIdentityChecks(), contains(thirdPartyIdentityCheckResponse)); + assertThat(testObj.getWatchlistScreeningChecks(), contains(watchlistScreeningCheckResponse)); + assertThat(testObj.getIbvVisualReviewChecks(), contains(ibvVisualReviewCheckResponse)); + assertThat(testObj.getDocumentSchemeValidityChecks(), contains(documentSchemeValidityCheckResponse)); + assertThat(testObj.getProfileDocumentMatchChecks(), contains(profileDocumentMatchCheckResponse)); + assertThat(testObj.getThirdPartyIdentityFraudOneChecks(), contains(thirdPartyIdentityFraudOneCheckResponse)); + assertThat(testObj.getSynecticsIdentityFraudChecks(), contains(synecticsIdentityFraudCheckResponse)); } } From c7064b57d2ddd37af4be4f02d234069ea44445f8 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:10:53 +0100 Subject: [PATCH 4/7] NA: We don't need the UTs to test jackson for us --- .../retrieve/GetSessionResultTest.java | 200 ------------------ 1 file changed, 200 deletions(-) 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..8c726734 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,5 @@ 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 java.io.IOException; -import java.util.HashMap; -import java.util.Map; - -import com.yoti.api.client.docs.session.create.SessionSpec; - -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.*; - 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)))); - } - - @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))) - ); - } - - @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); - - 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))) - ); - } - - 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; - } - - 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() { } - - } - } From febed0a9ee93ba801f7e5804b6947d0e8e8d8790 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:12:36 +0100 Subject: [PATCH 5/7] NA: Consolidate tests for GetSessionResultTest --- .../retrieve/GetSessionResultCheckTest.java | 72 ------------------- .../retrieve/GetSessionResultTest.java | 67 +++++++++++++++++ 2 files changed, 67 insertions(+), 72 deletions(-) delete mode 100644 yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java 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 ab962765..00000000 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java +++ /dev/null @@ -1,72 +0,0 @@ -package com.yoti.api.client.docs.session.retrieve; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.contains; - -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 { - - GetSessionResult testObj = new GetSessionResult(); - - @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; - - @Test - public void shouldFilterChecks() { - List allChecks = Arrays.asList( - authenticityCheckResponse, - livenessCheckResponse, - textDataCheckResponse, - supplementaryDocumentTextDataCheckResponse, - faceMatchCheckResponse, - faceComparisonCheckResponse, - idDocumentComparisonCheckResponse, - thirdPartyIdentityCheckResponse, - watchlistScreeningCheckResponse, - thirdPartyIdentityFraudOneCheckResponse, - ibvVisualReviewCheckResponse, - documentSchemeValidityCheckResponse, - profileDocumentMatchCheckResponse, - synecticsIdentityFraudCheckResponse - ); - FieldSetter.setField(testObj, "checks", allChecks); - - assertThat(testObj.getAuthenticityChecks(), contains(authenticityCheckResponse)); - assertThat(testObj.getLivenessChecks(), contains(livenessCheckResponse)); - assertThat(testObj.getIdDocumentTextDataChecks(), contains(textDataCheckResponse)); - assertThat(testObj.getSupplementaryDocumentTextDataChecks(), contains(supplementaryDocumentTextDataCheckResponse)); - assertThat(testObj.getFaceMatchChecks(), contains(faceMatchCheckResponse)); - assertThat(testObj.getFaceComparisonChecks(), contains(faceComparisonCheckResponse)); - assertThat(testObj.getIdDocumentComparisonChecks(), contains(idDocumentComparisonCheckResponse)); - assertThat(testObj.getThirdPartyIdentityChecks(), contains(thirdPartyIdentityCheckResponse)); - assertThat(testObj.getWatchlistScreeningChecks(), contains(watchlistScreeningCheckResponse)); - assertThat(testObj.getIbvVisualReviewChecks(), contains(ibvVisualReviewCheckResponse)); - assertThat(testObj.getDocumentSchemeValidityChecks(), contains(documentSchemeValidityCheckResponse)); - assertThat(testObj.getProfileDocumentMatchChecks(), contains(profileDocumentMatchCheckResponse)); - assertThat(testObj.getThirdPartyIdentityFraudOneChecks(), contains(thirdPartyIdentityFraudOneCheckResponse)); - assertThat(testObj.getSynecticsIdentityFraudChecks(), contains(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 8c726734..3822d7e7 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,5 +1,72 @@ package com.yoti.api.client.docs.session.retrieve; +import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; + +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 GetSessionResultTest { + 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; + + @Test + 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)); + } + } From 0ffb992d6a38738143c94c3e6b038b9b38594927 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 15:57:53 +0100 Subject: [PATCH 6/7] NA: Straighten out ResourceContainerTest --- .../retrieve/ResourceContainerTest.java | 59 ++++++------------- 1 file changed, 17 insertions(+), 42 deletions(-) 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..a3aebae9 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,6 +1,7 @@ package com.yoti.api.client.docs.session.retrieve; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.hasSize; import java.util.ArrayList; @@ -17,62 +18,36 @@ @RunWith(MockitoJUnitRunner.class) public class ResourceContainerTest { - @Mock ZoomLivenessResourceResponse zoomLivenessResourceResponseMock; - @Mock StaticLivenessResourceResponse staticLivenessResourceResponseMock; - @Mock LivenessResourceResponse livenessResourceResponse; + ResourceContainer testObj = new ResourceContainer(); - ResourceContainer simpleResourceContainer; + @Mock ZoomLivenessResourceResponse zoomLivenessResourceMock; + @Mock StaticLivenessResourceResponse staticLivenessResourceMock; + @Mock LivenessResourceResponse livenessResource; @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)); + FieldSetter.setField(testObj, "livenessCapture", Arrays.asList(zoomLivenessResourceMock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getZoomLivenessResources(); + + assertThat(result, contains(zoomLivenessResourceMock)); } @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)); + FieldSetter.setField(testObj, "livenessCapture", Arrays.asList(zoomLivenessResourceMock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getStaticLivenessResources(); + + assertThat(result, contains(staticLivenessResourceMock)); } @Test public void shouldReturnEmptyList() { - simpleResourceContainer = new ResourceContainer(); + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - new ArrayList<>() - ); + List result = testObj.getZoomLivenessResources(); - List result = simpleResourceContainer.getZoomLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(0)); assertThat(result, hasSize(0)); } From 149b765876e015378e6078c95165d263a546498d Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 11:01:42 +0100 Subject: [PATCH 7/7] SDK-2528: Helper method for finding the Resources that belong to a Check --- .../session/retrieve/GetSessionResult.java | 8 ++ .../session/retrieve/ResourceContainer.java | 41 +++++-- .../retrieve/GetSessionResultTest.java | 35 +++++- .../retrieve/ResourceContainerTest.java | 109 ++++++++++++++++-- 4 files changed, 174 insertions(+), 19 deletions(-) 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/GetSessionResultTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java index 3822d7e7..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 @@ -2,21 +2,29 @@ import static org.hamcrest.MatcherAssert.assertThat; 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.util.Arrays; +import java.util.Collections; 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.InjectMocks; import org.mockito.Mock; import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class GetSessionResultTest { - GetSessionResult testObj = new GetSessionResult(); + private static final String AUTH_CHECK_ID = "authCheckId"; + + @InjectMocks GetSessionResult testObj = new GetSessionResult(); @Mock AuthenticityCheckResponse authenticityCheckResponseMock; @Mock FaceMatchCheckResponse faceMatchCheckResponseMock; @@ -33,6 +41,14 @@ public class GetSessionResultTest { @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 shouldFilterChecks() { List allChecks = Arrays.asList( @@ -69,4 +85,21 @@ public void shouldFilterChecks() { assertThat(testObj.getSynecticsIdentityFraudChecks(), contains(synecticsIdentityFraudCheckResponseMock)); } + @Test + public void getResourcesForCheck_shouldThrowExceptionForBadCheckId() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); + + assertThrows(IllegalArgumentException.class, () -> testObj.getResourcesForCheck("someBadCheckId")); + } + + @Test + public void getResourcesForCheck_shouldReturnResultFromResources() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); + when(resourceContainerMock.filterForCheck(authenticityCheckResponseMock)).thenReturn(checkResourceContainerMock); + + 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 a3aebae9..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,15 +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; @@ -18,24 +23,64 @@ @RunWith(MockitoJUnitRunner.class) public class ResourceContainerTest { + 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 ZoomLivenessResourceResponse zoomLivenessResourceMock; + @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 shouldFilterZoomLivenessResources() { - FieldSetter.setField(testObj, "livenessCapture", Arrays.asList(zoomLivenessResourceMock, staticLivenessResourceMock, livenessResource)); + public void getZoomLivenessResources_shouldFilterZoomLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); List result = testObj.getZoomLivenessResources(); - assertThat(result, contains(zoomLivenessResourceMock)); + assertThat(result, contains(zoomLivenessResource1Mock)); } @Test - public void shouldFilterStaticLivenessResources() { - FieldSetter.setField(testObj, "livenessCapture", Arrays.asList(zoomLivenessResourceMock, staticLivenessResourceMock, livenessResource)); + public void getZoomLivenessResources_shouldReturnEmptyList() { + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); + + List result = testObj.getZoomLivenessResources(); + + assertThat(result, hasSize(0)); + } + + @Test + public void getStaticLivenessResources_shouldFilterStaticLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); List result = testObj.getStaticLivenessResources(); @@ -43,12 +88,58 @@ public void shouldFilterStaticLivenessResources() { } @Test - public void shouldReturnEmptyList() { + public void getStaticLivenessResources_shouldReturnEmptyList() { FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); - List result = testObj.getZoomLivenessResources(); + List result = testObj.getStaticLivenessResources(); 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)); + } + }