From 75746c6d1142a6cf7a93a6882b664e3956471bab Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Wed, 10 Jul 2024 11:25:03 +0100 Subject: [PATCH 01/30] SDK: Bump DEVELOPMENT version to 3.10.0-SNAPSHOT --- README.md | 4 ++-- examples/doc-scan/pom.xml | 2 +- pom.xml | 2 +- yoti-sdk-api/pom.xml | 2 +- .../com/yoti/api/client/spi/remote/call/YotiConstants.java | 2 +- yoti-sdk-parent/pom.xml | 2 +- yoti-sdk-sandbox/pom.xml | 2 +- yoti-sdk-spring-boot-auto-config/README.md | 4 ++-- yoti-sdk-spring-boot-auto-config/pom.xml | 2 +- yoti-sdk-spring-boot-example/README.md | 2 +- yoti-sdk-spring-boot-example/pom.xml | 2 +- yoti-sdk-spring-security/README.md | 4 ++-- yoti-sdk-spring-security/pom.xml | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index 183657f4..af8208aa 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,13 @@ If you are using Maven, you need to add the following dependency: com.yoti yoti-sdk-api - 3.9.0 + 3.10.0-SNAPSHOT ``` If you are using Gradle, here is the dependency to add: -`compile group: 'com.yoti', name: 'yoti-sdk-api', version: '3.9.0'` +`compile group: 'com.yoti', name: 'yoti-sdk-api', version: '3.10.0-SNAPSHOT'` You will find all classes packaged under `com.yoti.api` diff --git a/examples/doc-scan/pom.xml b/examples/doc-scan/pom.xml index 9cefeb59..3b9d50d9 100644 --- a/examples/doc-scan/pom.xml +++ b/examples/doc-scan/pom.xml @@ -53,7 +53,7 @@ com.yoti yoti-sdk-api - 3.9.0 + 3.10.0-SNAPSHOT diff --git a/pom.xml b/pom.xml index 7a6a69de..dbdad87d 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk pom - 3.9.0 + 3.10.0-SNAPSHOT Yoti SDK Java SDK for simple integration with the Yoti platform https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-api/pom.xml b/yoti-sdk-api/pom.xml index f38e0752..6e69ea00 100644 --- a/yoti-sdk-api/pom.xml +++ b/yoti-sdk-api/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 3.9.0 + 3.10.0-SNAPSHOT ../yoti-sdk-parent diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java index d5196244..19167112 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java @@ -29,7 +29,7 @@ private YotiConstants() {} public static final String CONTENT_TYPE_JPEG = "image/jpeg"; public static final String JAVA = "Java"; - public static final String SDK_VERSION = JAVA + "-3.9.0"; + public static final String SDK_VERSION = JAVA + "-3.10.0-SNAPSHOT"; public static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; public static final String ASYMMETRIC_CIPHER = "RSA/NONE/PKCS1Padding"; public static final String SYMMETRIC_CIPHER = "AES/CBC/PKCS7Padding"; diff --git a/yoti-sdk-parent/pom.xml b/yoti-sdk-parent/pom.xml index 1728a6b8..6964c01e 100644 --- a/yoti-sdk-parent/pom.xml +++ b/yoti-sdk-parent/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk-parent pom - 3.9.0 + 3.10.0-SNAPSHOT Yoti SDK Parent Pom Parent pom for the Java SDK projects https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-sandbox/pom.xml b/yoti-sdk-sandbox/pom.xml index 8d3831c2..46d90c9e 100644 --- a/yoti-sdk-sandbox/pom.xml +++ b/yoti-sdk-sandbox/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 3.9.0 + 3.10.0-SNAPSHOT ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-auto-config/README.md b/yoti-sdk-spring-boot-auto-config/README.md index 3b2c5c56..e5a9ea6f 100644 --- a/yoti-sdk-spring-boot-auto-config/README.md +++ b/yoti-sdk-spring-boot-auto-config/README.md @@ -18,7 +18,7 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-boot-auto-config - 3.9.0 + 3.10.0-SNAPSHOT ``` @@ -26,7 +26,7 @@ If you are using Maven, you need to add the following dependencies: If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '3.9.0' +compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '3.10.0-SNAPSHOT' ``` diff --git a/yoti-sdk-spring-boot-auto-config/pom.xml b/yoti-sdk-spring-boot-auto-config/pom.xml index a11b7a45..29e22ff8 100644 --- a/yoti-sdk-spring-boot-auto-config/pom.xml +++ b/yoti-sdk-spring-boot-auto-config/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 3.9.0 + 3.10.0-SNAPSHOT ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-example/README.md b/yoti-sdk-spring-boot-example/README.md index 0a7b046d..fe99f823 100644 --- a/yoti-sdk-spring-boot-example/README.md +++ b/yoti-sdk-spring-boot-example/README.md @@ -17,7 +17,7 @@ Note that: com.yoti yoti-sdk-api - 3.9.0 + 3.10.0-SNAPSHOT ``` diff --git a/yoti-sdk-spring-boot-example/pom.xml b/yoti-sdk-spring-boot-example/pom.xml index b3f6c196..d55427eb 100644 --- a/yoti-sdk-spring-boot-example/pom.xml +++ b/yoti-sdk-spring-boot-example/pom.xml @@ -6,7 +6,7 @@ com.yoti yoti-sdk-spring-boot-example Yoti Spring Boot Example - 3.9.0 + 3.10.0-SNAPSHOT org.springframework.boot diff --git a/yoti-sdk-spring-security/README.md b/yoti-sdk-spring-security/README.md index d3bb0513..41267adb 100644 --- a/yoti-sdk-spring-security/README.md +++ b/yoti-sdk-spring-security/README.md @@ -25,14 +25,14 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-security - 3.9.0 + 3.10.0-SNAPSHOT ``` If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '3.9.0' +compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '3.10.0-SNAPSHOT' ``` ### Provide a `YotiClient` instance diff --git a/yoti-sdk-spring-security/pom.xml b/yoti-sdk-spring-security/pom.xml index 42a63161..3dd5979e 100644 --- a/yoti-sdk-spring-security/pom.xml +++ b/yoti-sdk-spring-security/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 3.9.0 + 3.10.0-SNAPSHOT ../yoti-sdk-parent From 4244aef727a7decdd656d3b522e34478c52702c0 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Wed, 10 Jul 2024 11:34:04 +0100 Subject: [PATCH 02/30] SDK-2437: Add support for setting sandbox response configuration for static liveness --- .../request/check/SandboxLivenessCheck.java | 2 ++ .../SandboxStaticLivenessCheckBuilder.java | 28 +++++++++++++++++++ .../check/SandboxZoomLivenessCheckTest.java | 12 +++++++- 3 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java index e271fe9a..dbbbbf42 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java @@ -16,6 +16,8 @@ public static SandboxZoomLivenessCheckBuilder forZoomLiveness() { return new SandboxZoomLivenessCheckBuilder(); } + public static SandboxStaticLivenessCheckBuilder forStaticLiveness() { return new SandboxStaticLivenessCheckBuilder(); } + public String getLivenessType() { return livenessType; } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java new file mode 100644 index 00000000..723b0457 --- /dev/null +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java @@ -0,0 +1,28 @@ +package com.yoti.api.client.sandbox.docs.request.check; + +import static com.yoti.api.client.spi.remote.util.Validation.notNull; + +import com.yoti.api.client.docs.DocScanConstants; +import com.yoti.api.client.sandbox.docs.request.check.report.SandboxCheckReport; + +public class SandboxStaticLivenessCheckBuilder extends SandboxCheck.Builder { + + SandboxStaticLivenessCheckBuilder() { + } + + @Override + protected SandboxStaticLivenessCheckBuilder self() { + return this; + } + + @Override + public SandboxLivenessCheck build() { + notNull(recommendation, "recommendation"); + + SandboxCheckReport report = new SandboxCheckReport(recommendation, breakdown); + SandboxCheckResult result = new SandboxCheckResult(report); + + return new SandboxLivenessCheck(result, DocScanConstants.STATIC); + } + +} diff --git a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckTest.java b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckTest.java index 2c0eb0d8..9e5d013c 100644 --- a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckTest.java +++ b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckTest.java @@ -45,7 +45,7 @@ public void builder_shouldBuildWithCorrectValues() { } @Test - public void builder_shouldSetCorrectLivenessType() { + public void builder_shouldSetCorrectLivenessTypeForZoom() { SandboxLivenessCheck result = new SandboxZoomLivenessCheckBuilder() .withRecommendation(sandboxRecommendationMock) .withBreakdown(sandboxBreakdownMock) @@ -54,4 +54,14 @@ public void builder_shouldSetCorrectLivenessType() { assertThat(result.getLivenessType(), is("ZOOM")); } + @Test + public void builder_shouldSetCorrectLivenessTypeForStatic() { + SandboxLivenessCheck result = new SandboxStaticLivenessCheckBuilder() + .withRecommendation(sandboxRecommendationMock) + .withBreakdown(sandboxBreakdownMock) + .build(); + + assertThat(result.getLivenessType(), is("STATIC")); + } + } From d5da72880b017f7245f15da6162b24ef2f67f15d Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 12 Aug 2024 14:59:34 +0100 Subject: [PATCH 03/30] SDK-2445: [AB] Add text-extraction task recommendation to the GET session endpoint --- .../IdDocTextExtractionTaskResponse.java | 14 +++++++++ ...aryDocumentTextExtractionTaskResponse.java | 14 +++++++++ .../session/retrieve/TaskReasonResponse.java | 31 +++++++++++++++++++ .../retrieve/TaskRecommendationResponse.java | 31 +++++++++++++++++++ 4 files changed, 90 insertions(+) create mode 100644 yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskReasonResponse.java create mode 100644 yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskRecommendationResponse.java diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocTextExtractionTaskResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocTextExtractionTaskResponse.java index 4eee63ab..256ea21e 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocTextExtractionTaskResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocTextExtractionTaskResponse.java @@ -2,8 +2,22 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + public class IdDocTextExtractionTaskResponse extends TaskResponse { + @JsonProperty("recommendation") + private TaskRecommendationResponse recommendation; + + /** + * The recommendation for the task + * + * @return the recommendation + */ + public TaskRecommendationResponse getRecommendation() { + return recommendation; + } + public List getGeneratedTextDataChecks() { return filterGeneratedChecksByType(GeneratedTextDataCheckResponse.class); } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/SupplementaryDocumentTextExtractionTaskResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/SupplementaryDocumentTextExtractionTaskResponse.java index fef7a3e6..b0ea61bd 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/SupplementaryDocumentTextExtractionTaskResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/SupplementaryDocumentTextExtractionTaskResponse.java @@ -2,8 +2,22 @@ import java.util.List; +import com.fasterxml.jackson.annotation.JsonProperty; + public class SupplementaryDocumentTextExtractionTaskResponse extends TaskResponse { + @JsonProperty("recommendation") + private TaskRecommendationResponse recommendation; + + /** + * The recommendation for the task + * + * @return the recommendation + */ + public TaskRecommendationResponse getRecommendation() { + return recommendation; + } + public List getGeneratedTextDataChecks() { return filterGeneratedChecksByType(GeneratedSupplementaryDocumentTextDataCheckResponse.class); } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskReasonResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskReasonResponse.java new file mode 100644 index 00000000..976c90e7 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskReasonResponse.java @@ -0,0 +1,31 @@ +package com.yoti.api.client.docs.session.retrieve; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class TaskReasonResponse { + + @JsonProperty("value") + private String value; + + @JsonProperty("detail") + private String detail; + + /** + * The reason for the recommendation + * + * @return the reason value + */ + public String getValue() { + return value; + } + + /** + * The fine-grained details for the reason of the recommendation + * + * @return the details + */ + public String getDetail() { + return detail; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskRecommendationResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskRecommendationResponse.java new file mode 100644 index 00000000..56ecf6c2 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/TaskRecommendationResponse.java @@ -0,0 +1,31 @@ +package com.yoti.api.client.docs.session.retrieve; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class TaskRecommendationResponse { + + @JsonProperty("value") + private String value; + + @JsonProperty("reason") + private TaskReasonResponse reason; + + /** + * The recommendation value + * + * @return the value + */ + public String getValue() { + return value; + } + + /** + * The reason for the recommendation + * + * @return the reason + */ + public TaskReasonResponse getReason() { + return reason; + } + +} From 528dbd1c1525e3c8e0863e2fc8e8719bed2e0cc8 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Fri, 9 Aug 2024 15:10:58 +0100 Subject: [PATCH 04/30] SDK-2467: [AB] Allow the brand ID to be set at session creation (as part of the sdk_config) --- .../client/docs/session/create/SdkConfig.java | 31 +++++++++++++++++-- .../docs/session/create/SdkConfigTest.java | 3 ++ 2 files changed, 32 insertions(+), 2 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index 63fedf3a..9a157fc6 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -42,6 +42,9 @@ public class SdkConfig { @JsonProperty(Property.ATTEMPTS_CONFIGURATION) private final AttemptsConfiguration attemptsConfiguration; + @JsonProperty(Property.BRAND_ID) + private final String brandId; + SdkConfig(String allowedCaptureMethods, String primaryColour, String secondaryColour, @@ -52,7 +55,7 @@ public class SdkConfig { String errorUrl, String privacyPolicyUrl, Boolean allowHandoff, - AttemptsConfiguration attemptsConfiguration) { + AttemptsConfiguration attemptsConfiguration, String brandId) { this.allowedCaptureMethods = allowedCaptureMethods; this.primaryColour = primaryColour; this.secondaryColour = secondaryColour; @@ -64,6 +67,7 @@ public class SdkConfig { this.privacyPolicyUrl = privacyPolicyUrl; this.allowHandoff = allowHandoff; this.attemptsConfiguration = attemptsConfiguration; + this.brandId = brandId; } public static SdkConfig.Builder builder() { @@ -169,6 +173,15 @@ public AttemptsConfiguration getAttemptsConfiguration() { return attemptsConfiguration; } + /** + * The Brand ID to use for the session + * + * @return the configured brand ID + */ + public String getBrandId() { + return brandId; + } + /** * Builder to assist in the creation of {@link SdkConfig}. */ @@ -185,6 +198,7 @@ public static class Builder { private String privacyPolicyUrl; private Boolean allowHandoff; private AttemptsConfiguration attemptsConfiguration; + private String brandId; private Builder() {} @@ -327,6 +341,17 @@ public Builder withAttemptsConfiguration(AttemptsConfiguration attemptsConfigura return this; } + /** + * Sets the brand ID to be used for the session + * + * @param brandId the brand ID + * @return the builder + */ + public Builder withBrandId(String brandId) { + this.brandId = brandId; + return this; + } + /** * Builds the {@link SdkConfig} using the values supplied to the builder * @@ -344,7 +369,8 @@ public SdkConfig build() { errorUrl, privacyPolicyUrl, allowHandoff, - attemptsConfiguration + attemptsConfiguration, + brandId ); } } @@ -362,6 +388,7 @@ private static final class Property { private static final String PRIVACY_POLICY_URL = "privacy_policy_url"; private static final String ALLOW_HANDOFF = "allow_handoff"; private static final String ATTEMPTS_CONFIGURATION = "attempts_configuration"; + private static final String BRAND_ID = "brand_id"; private Property() {} diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java index d8b78737..b128429e 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java @@ -17,6 +17,7 @@ public class SdkConfigTest { private static final String SOME_FONT_COLOUR = "#b40c12"; private static final String SOME_LOCALE = "en"; private static final String SOME_PRESET_ISSUING_COUNTRY = "USA"; + private static final String SOME_BRAND_ID = "someBrandId"; private static final String SOME_SUCCESS_URL = "https://yourdomain.com/some/success/endpoint"; private static final String SOME_ERROR_URL = "https://yourdomain.com/some/error/endpoint"; @@ -38,6 +39,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { .withPrivacyPolicyUrl(SOME_PRIVACY_POLICY_URL) .withAllowHandoff(true) .withAttemptsConfiguration(attemptsConfigurationMock) + .withBrandId(SOME_BRAND_ID) .build(); assertThat(result, is(instanceOf(SdkConfig.class))); @@ -53,6 +55,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { assertThat(result.getPrivacyPolicyUrl(), is(SOME_PRIVACY_POLICY_URL)); assertThat(result.getAllowHandoff(), is(true)); assertThat(result.getAttemptsConfiguration(), is(attemptsConfigurationMock)); + assertThat(result.getBrandId(), is(SOME_BRAND_ID)); } @Test From e5c0b03d107fa29a8bfd2a9041579034f138b362 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 23 Sep 2024 02:03:37 +0100 Subject: [PATCH 05/30] SDK-2309: Add support for setting biometric consent flow for a session --- .../api/client/docs/DocScanConstants.java | 3 ++ .../client/docs/session/create/SdkConfig.java | 51 ++++++++++++++++++- .../docs/session/create/SdkConfigTest.java | 18 +++++++ 3 files changed, 70 insertions(+), 2 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java index 8a4a729e..4a1e33fc 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java @@ -83,4 +83,7 @@ private DocScanConstants() { } public static final String GBP = "GBP"; + public static final String EAGER = "EAGER"; + public static final String JUST_IN_TIME = "JUST_IN_TIME"; + } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index 9a157fc6..9a5b8791 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -45,6 +45,9 @@ public class SdkConfig { @JsonProperty(Property.BRAND_ID) private final String brandId; + @JsonProperty(Property.BIOMETRIC_CONSENT_FLOW) + private final String biometricConsentFlow; + SdkConfig(String allowedCaptureMethods, String primaryColour, String secondaryColour, @@ -55,7 +58,9 @@ public class SdkConfig { String errorUrl, String privacyPolicyUrl, Boolean allowHandoff, - AttemptsConfiguration attemptsConfiguration, String brandId) { + AttemptsConfiguration attemptsConfiguration, + String brandId, + String biometricConsentFlow) { this.allowedCaptureMethods = allowedCaptureMethods; this.primaryColour = primaryColour; this.secondaryColour = secondaryColour; @@ -68,6 +73,7 @@ public class SdkConfig { this.allowHandoff = allowHandoff; this.attemptsConfiguration = attemptsConfiguration; this.brandId = brandId; + this.biometricConsentFlow = biometricConsentFlow; } public static SdkConfig.Builder builder() { @@ -182,6 +188,15 @@ public String getBrandId() { return brandId; } + /** + * The configured biometric consent flow for the session + * + * @return the configured biometric consent flow + */ + public String getBiometricConsentFlow() { + return biometricConsentFlow; + } + /** * Builder to assist in the creation of {@link SdkConfig}. */ @@ -199,6 +214,7 @@ public static class Builder { private Boolean allowHandoff; private AttemptsConfiguration attemptsConfiguration; private String brandId; + private String biometricConsentFlow; private Builder() {} @@ -352,6 +368,35 @@ public Builder withBrandId(String brandId) { return this; } + /** + * Sets the Biometric Consent Flow for the session + * + * @param biometricConsentFlow the biometric consent flow + * @return the builder + */ + public Builder withBiometricConsentFlow(String biometricConsentFlow) { + this.biometricConsentFlow = biometricConsentFlow; + return this; + } + + /** + * Sets the biometric consent flow to EAGER for the session + * + * @return the builder + */ + public Builder withBiometricConsentFlowEager() { + return withBiometricConsentFlow(DocScanConstants.EAGER); + } + + /** + * Sets the biometric consent flow to JUST_IN_TIME for the session + * + * @return the builder + */ + public Builder withBiometricConsentFlowJustInTime() { + return withBiometricConsentFlow(DocScanConstants.JUST_IN_TIME); + } + /** * Builds the {@link SdkConfig} using the values supplied to the builder * @@ -370,7 +415,8 @@ public SdkConfig build() { privacyPolicyUrl, allowHandoff, attemptsConfiguration, - brandId + brandId, + biometricConsentFlow ); } } @@ -389,6 +435,7 @@ private static final class Property { private static final String ALLOW_HANDOFF = "allow_handoff"; private static final String ATTEMPTS_CONFIGURATION = "attempts_configuration"; private static final String BRAND_ID = "brand_id"; + private static final String BIOMETRIC_CONSENT_FLOW = "biometric_consent_flow"; private Property() {} diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java index b128429e..57ab3e0c 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java @@ -84,6 +84,24 @@ public void shouldBuildSimpleSdkConfigWithCameraAndUpload() { assertThat(result.getAllowedCaptureMethods(), is("CAMERA_AND_UPLOAD")); } + @Test + public void shouldBuildSimpleSdkConfigWithBiometricConsentFlowEager() { + SdkConfig result = SdkConfig.builder() + .withBiometricConsentFlowEager() + .build(); + + assertThat(result.getBiometricConsentFlow(), is("EAGER")); + } + + @Test + public void shouldBuildSimpleSdkConfigWithBiometricConsentFlowJustInTime() { + SdkConfig result = SdkConfig.builder() + .withBiometricConsentFlowJustInTime() + .build(); + + assertThat(result.getBiometricConsentFlow(), is("JUST_IN_TIME")); + } + @Test public void shouldOverridePreviousAllowedCaptureMethods() { SdkConfig result = SdkConfig.builder() From 26b71ed337cc08f609c2450ae691488e39d93c05 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 23 Sep 2024 02:13:12 +0100 Subject: [PATCH 06/30] SDK-2340: Allow Relying Business to configure if expanded document fields should be created for a text-extraction task --- .../task/RequestedIdDocTextExtractionTask.java | 8 +++++++- .../RequestedIdDocTextExtractionTaskConfig.java | 16 +++++++++++++++- .../RequestedIdDocTextExtractionTaskTest.java | 10 ++++++++++ 3 files changed, 32 insertions(+), 2 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java index 0f08f033..9ba67453 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java @@ -31,6 +31,7 @@ public static class Builder { private String manualCheck; private String chipData; + private Boolean createExpandedDocumentFields; public Builder withManualCheckAlways() { this.manualCheck = DocScanConstants.ALWAYS; @@ -57,8 +58,13 @@ public Builder withChipDataIgnore() { return this; } + public Builder withCreateExpandedDocumentFields(boolean value) { + this.createExpandedDocumentFields = value; + return this; + } + public RequestedIdDocTextExtractionTask build() { - RequestedIdDocTextExtractionTaskConfig config = new RequestedIdDocTextExtractionTaskConfig(manualCheck, chipData); + RequestedIdDocTextExtractionTaskConfig config = new RequestedIdDocTextExtractionTaskConfig(manualCheck, chipData, createExpandedDocumentFields); return new RequestedIdDocTextExtractionTask(config); } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java index 9911e7d7..2f86306d 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java @@ -13,9 +13,13 @@ public class RequestedIdDocTextExtractionTaskConfig implements RequestedTaskConf @JsonProperty("chip_data") private final String chipData; - RequestedIdDocTextExtractionTaskConfig(String manualCheck, String chipData) { + @JsonProperty("create_expanded_document_fields") + private final Boolean createExpandedDocumentFields; + + RequestedIdDocTextExtractionTaskConfig(String manualCheck, String chipData, Boolean createExpandedDocumentFields) { this.manualCheck = manualCheck; this.chipData = chipData; + this.createExpandedDocumentFields = createExpandedDocumentFields; } /** @@ -37,4 +41,14 @@ public String getChipData() { return chipData; } + /** + * Describes if expanded document fields should be created for a text-extraction task + * in the session. + * + * @return if expanded document fields should be created + */ + public Boolean getCreateExpandedDocumentFields() { + return createExpandedDocumentFields; + } + } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java index 93e3562c..65452c4d 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java @@ -63,4 +63,14 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithChipDataIgnore() { assertThat(configResult.getChipData(), is("IGNORE")); } + @Test + public void shouldBuildSimpleRequestedTextExtractionTaskWithCreateExpandedDocumentFields() { + RequestedIdDocTextExtractionTask result = RequestedIdDocTextExtractionTask.builder() + .withCreateExpandedDocumentFields(true) + .build(); + + RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); + assertThat(configResult.getCreateExpandedDocumentFields(), is(true)); + } + } From 364d037e083c8d79eea5a131b523bbdf4418dda6 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 12:38:18 +0100 Subject: [PATCH 07/30] SDK-2340: Add missing javadoc comments / add missing test --- .../RequestedIdDocTextExtractionTask.java | 24 ++++++++++++++ ...equestedIdDocTextExtractionTaskConfig.java | 5 ++- .../RequestedIdDocTextExtractionTaskTest.java | 31 ++++++++++--------- 3 files changed, 42 insertions(+), 18 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java index 9ba67453..51bbbed0 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTask.java @@ -33,31 +33,55 @@ public static class Builder { private String chipData; private Boolean createExpandedDocumentFields; + /** + * Apply manual_check ALWAYS to all ID_DOCUMENT_TEXT_DATA_EXTRACTION tasks in the session + * @return the builder + */ public Builder withManualCheckAlways() { this.manualCheck = DocScanConstants.ALWAYS; return this; } + /** + * Apply manual_check FALLBACK to all ID_DOCUMENT_TEXT_DATA_EXTRACTION tasks in the session + * @return the builder + */ public Builder withManualCheckFallback() { this.manualCheck = DocScanConstants.FALLBACK; return this; } + /** + * Apply manual_check NEVER to all ID_DOCUMENT_TEXT_DATA_EXTRACTION tasks in the session + * @return the builder + */ public Builder withManualCheckNever() { this.manualCheck = DocScanConstants.NEVER; return this; } + /** + * Apply chip_data DESIRED to all ID_DOCUMENT_TEXT_DATA_EXTRACTION tasks in the session + * @return the builder + */ public Builder withChipDataDesired() { this.chipData = DocScanConstants.DESIRED; return this; } + /** + * Apply chip_data IGNORED to all ID_DOCUMENT_TEXT_DATA_EXTRACTION tasks in the session + * @return the builder + */ public Builder withChipDataIgnore() { this.chipData = DocScanConstants.IGNORE; return this; } + /** + * Whether to request the creation of expanded document fields for every ID_DOCUMENT_TEXT_DATA_EXTRACTION task + * @return the builder + */ public Builder withCreateExpandedDocumentFields(boolean value) { this.createExpandedDocumentFields = value; return this; diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java index 2f86306d..ae796357 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskConfig.java @@ -42,10 +42,9 @@ public String getChipData() { } /** - * Describes if expanded document fields should be created for a text-extraction task - * in the session. + * Describes whether or not expanded document fields should be created as part of text extraction * - * @return if expanded document fields should be created + * @return whether to create expanded document fields */ public Boolean getCreateExpandedDocumentFields() { return createExpandedDocumentFields; diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java index 65452c4d..626584d0 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/task/RequestedIdDocTextExtractionTaskTest.java @@ -1,24 +1,30 @@ package com.yoti.api.client.docs.session.create.task; - import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.nullValue; import org.junit.Test; public class RequestedIdDocTextExtractionTaskTest { + @Test + public void shouldDefaultConfigValuesToNull() { + RequestedIdDocTextExtractionTask result = RequestedIdDocTextExtractionTask.builder().build(); + + assertThat(result.getType(), is("ID_DOCUMENT_TEXT_DATA_EXTRACTION")); + assertThat(result.getConfig().getChipData(), is(nullValue())); + assertThat(result.getConfig().getManualCheck(), is(nullValue())); + assertThat(result.getConfig().getCreateExpandedDocumentFields(), is(nullValue())); + } + @Test public void shouldBuildSimpleRequestedTextExtractionTaskWithManualFallbackAlways() { RequestedIdDocTextExtractionTask result = RequestedIdDocTextExtractionTask.builder() .withManualCheckAlways() .build(); - assertThat(result, is(instanceOf(RequestedIdDocTextExtractionTask.class))); - assertThat(result.getConfig(), instanceOf(RequestedIdDocTextExtractionTaskConfig.class)); assertThat(result.getType(), is("ID_DOCUMENT_TEXT_DATA_EXTRACTION")); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); assertThat(configResult.getManualCheck(), is("ALWAYS")); } @@ -29,8 +35,7 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithManualFallbackFallba .withManualCheckFallback() .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getManualCheck(), is("FALLBACK")); + assertThat(result.getConfig().getManualCheck(), is("FALLBACK")); } @Test @@ -39,8 +44,7 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithManualFallbackNever( .withManualCheckNever() .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getManualCheck(), is("NEVER")); + assertThat(result.getConfig().getManualCheck(), is("NEVER")); } @Test @@ -49,8 +53,7 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithChipDataDesired() { .withChipDataDesired() .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getChipData(), is("DESIRED")); + assertThat(result.getConfig().getChipData(), is("DESIRED")); } @Test @@ -59,8 +62,7 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithChipDataIgnore() { .withChipDataIgnore() .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getChipData(), is("IGNORE")); + assertThat(result.getConfig().getChipData(), is("IGNORE")); } @Test @@ -69,8 +71,7 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithCreateExpandedDocume .withCreateExpandedDocumentFields(true) .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getCreateExpandedDocumentFields(), is(true)); + assertThat(result.getConfig().getCreateExpandedDocumentFields(), is(true)); } } From 721a8cfa1e92d0541619b9e22a2f76f10b031f61 Mon Sep 17 00:00:00 2001 From: Artem Lukyanau Date: Sun, 22 Sep 2024 14:13:44 +0200 Subject: [PATCH 08/30] SDK-2486: Add support for primary colour dark mode to be set at sdk config creation --- .../client/docs/session/create/SdkConfig.java | 28 +++++++++++++++++++ .../docs/session/create/SdkConfigTest.java | 3 ++ 2 files changed, 31 insertions(+) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index 9a5b8791..bc05ec1b 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -15,6 +15,9 @@ public class SdkConfig { @JsonProperty(Property.PRIMARY_COLOUR) private final String primaryColour; + @JsonProperty(Property.PRIMARY_COLOUR_DARK_MODE) + private final String primaryColourDarkMode; + @JsonProperty(Property.SECONDARY_COLOUR) private final String secondaryColour; @@ -50,6 +53,7 @@ public class SdkConfig { SdkConfig(String allowedCaptureMethods, String primaryColour, + String primaryColourDarkMode, String secondaryColour, String fontColour, String locale, @@ -63,6 +67,7 @@ public class SdkConfig { String biometricConsentFlow) { this.allowedCaptureMethods = allowedCaptureMethods; this.primaryColour = primaryColour; + this.primaryColourDarkMode = primaryColourDarkMode; this.secondaryColour = secondaryColour; this.fontColour = fontColour; this.locale = locale; @@ -98,6 +103,15 @@ public String getPrimaryColour() { return primaryColour; } + /** + * The primary colour for the dark mode + * + * @return the primary colour + */ + public String getPrimaryColourDarkMode() { + return primaryColourDarkMode; + } + /** * The secondary colour * @@ -204,6 +218,7 @@ public static class Builder { private String allowedCaptureMethods; private String primaryColour; + private String primaryColourDarkMode; private String secondaryColour; private String fontColour; private String locale; @@ -258,6 +273,17 @@ public Builder withPrimaryColour(String primaryColour) { return this; } + /** + * Sets the primary colour for the dark mode to be used by the web/native client + * + * @param primaryColourDarkMode the primary colour for the dark mode, hexadecimal value e.g. #ff0000 + * @return the builder + */ + public Builder withPrimaryColourDarkMode(String primaryColourDarkMode) { + this.primaryColourDarkMode = primaryColourDarkMode; + return this; + } + /** * Sets the secondary colour to be used by the web/native client (used on the button) * @@ -406,6 +432,7 @@ public SdkConfig build() { return new SdkConfig( allowedCaptureMethods, primaryColour, + primaryColourDarkMode, secondaryColour, fontColour, locale, @@ -425,6 +452,7 @@ private static final class Property { private static final String ALLOWED_CAPTURE_METHODS = "allowed_capture_methods"; private static final String PRIMARY_COLOUR = "primary_colour"; + private static final String PRIMARY_COLOUR_DARK_MODE = "primary_colour_dark_mode"; private static final String SECONDARY_COLOUR = "secondary_colour"; private static final String FONT_COLOUR = "font_colour"; private static final String LOCALE = "locale"; diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java index 57ab3e0c..60750cc0 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java @@ -13,6 +13,7 @@ public class SdkConfigTest { private static final String SOME_PRIMARY_COLOUR = "#FFFFFF"; + private static final String SOME_PRIMARY_COLOUR_DARK_MODE = "#3b706f"; private static final String SOME_SECONDARY_COLOUR = "#679bdd"; private static final String SOME_FONT_COLOUR = "#b40c12"; private static final String SOME_LOCALE = "en"; @@ -30,6 +31,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { SdkConfig result = SdkConfig.builder() .withAllowsCamera() .withPrimaryColour(SOME_PRIMARY_COLOUR) + .withPrimaryColourDarkMode(SOME_PRIMARY_COLOUR_DARK_MODE) .withSecondaryColour(SOME_SECONDARY_COLOUR) .withFontColour(SOME_FONT_COLOUR) .withLocale(SOME_LOCALE) @@ -46,6 +48,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { assertThat(result.getAllowedCaptureMethods(), is("CAMERA")); assertThat(result.getPrimaryColour(), is(SOME_PRIMARY_COLOUR)); + assertThat(result.getPrimaryColourDarkMode(), is(SOME_PRIMARY_COLOUR_DARK_MODE)); assertThat(result.getSecondaryColour(), is(SOME_SECONDARY_COLOUR)); assertThat(result.getFontColour(), is(SOME_FONT_COLOUR)); assertThat(result.getLocale(), is(SOME_LOCALE)); From ec18befe63cdd3a94b322586e51bbecc65a137da Mon Sep 17 00:00:00 2001 From: Artem Lukyanau Date: Sun, 22 Sep 2024 14:25:59 +0200 Subject: [PATCH 09/30] SDK-2486: Add support for dark mode to be set at sdk config creation --- .../api/client/docs/DocScanConstants.java | 4 ++ .../client/docs/session/create/SdkConfig.java | 60 ++++++++++++++++++- .../docs/session/create/SdkConfigTest.java | 29 +++++++++ 3 files changed, 92 insertions(+), 1 deletion(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java index 4a1e33fc..b41ad95a 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java @@ -86,4 +86,8 @@ private DocScanConstants() { } public static final String EAGER = "EAGER"; public static final String JUST_IN_TIME = "JUST_IN_TIME"; + public static final String ON = "ON"; + public static final String OFF = "OFF"; + public static final String AUTO = "AUTO"; + } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index bc05ec1b..0abdb498 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -24,6 +24,9 @@ public class SdkConfig { @JsonProperty(Property.FONT_COLOUR) private final String fontColour; + @JsonProperty(Property.DARK_MODE) + private final String darkMode; + @JsonProperty(Property.LOCALE) private final String locale; @@ -57,6 +60,7 @@ public class SdkConfig { String secondaryColour, String fontColour, String locale, + String darkMode, String presetIssuingCountry, String successUrl, String errorUrl, @@ -71,6 +75,7 @@ public class SdkConfig { this.secondaryColour = secondaryColour; this.fontColour = fontColour; this.locale = locale; + this.darkMode = darkMode; this.presetIssuingCountry = presetIssuingCountry; this.successUrl = successUrl; this.errorUrl = errorUrl; @@ -104,7 +109,7 @@ public String getPrimaryColour() { } /** - * The primary colour for the dark mode + * The primary colour for dark mode, configured for the session * * @return the primary colour */ @@ -139,6 +144,15 @@ public String getLocale() { return locale; } + /** + * The dark mode option configured for the session + * + * @return the dark mode + */ + public String getDarkMode() { + return darkMode; + } + /** * The preset issuing country * @@ -222,6 +236,7 @@ public static class Builder { private String secondaryColour; private String fontColour; private String locale; + private String darkMode; private String presetIssuingCountry; private String successUrl; private String errorUrl; @@ -317,6 +332,47 @@ public Builder withLocale(String locale) { return this; } + /** + * Sets the dark mode to be used by the web/native client + * + * @param darkMode the dark mode, e.g. "ON" + * @return the builder + */ + public Builder withDarkMode(String darkMode) { + this.darkMode = darkMode; + return this; + } + + /** + * Sets the dark mode to 'ON' to be used by the web/native client + * + * @return the builder + */ + public Builder withDarkModeOn() { + this.darkMode = DocScanConstants.ON; + return this; + } + + /** + * Sets the dark mode to 'OFF' to be used by the web/native client + * + * @return the builder + */ + public Builder withDarkModeOff() { + this.darkMode = DocScanConstants.OFF; + return this; + } + + /** + * Sets the dark mode to 'AUTO' to be used by the web/native client + * + * @return the builder + */ + public Builder withDarkModeAuto() { + this.darkMode = DocScanConstants.AUTO; + return this; + } + /** * Sets the preset issuing country used by the web/native client * @@ -436,6 +492,7 @@ public SdkConfig build() { secondaryColour, fontColour, locale, + darkMode, presetIssuingCountry, successUrl, errorUrl, @@ -455,6 +512,7 @@ private static final class Property { private static final String PRIMARY_COLOUR_DARK_MODE = "primary_colour_dark_mode"; private static final String SECONDARY_COLOUR = "secondary_colour"; private static final String FONT_COLOUR = "font_colour"; + private static final String DARK_MODE = "dark_mode"; private static final String LOCALE = "locale"; private static final String PRESET_ISSUING_COUNTRY = "preset_issuing_country"; private static final String SUCCESS_URL = "success_url"; diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java index 60750cc0..24dba45d 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java @@ -17,6 +17,7 @@ public class SdkConfigTest { private static final String SOME_SECONDARY_COLOUR = "#679bdd"; private static final String SOME_FONT_COLOUR = "#b40c12"; private static final String SOME_LOCALE = "en"; + private static final String SOME_DARK_MODE = "ON"; private static final String SOME_PRESET_ISSUING_COUNTRY = "USA"; private static final String SOME_BRAND_ID = "someBrandId"; @@ -35,6 +36,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { .withSecondaryColour(SOME_SECONDARY_COLOUR) .withFontColour(SOME_FONT_COLOUR) .withLocale(SOME_LOCALE) + .withDarkMode(SOME_DARK_MODE) .withPresetIssuingCountry(SOME_PRESET_ISSUING_COUNTRY) .withSuccessUrl(SOME_SUCCESS_URL) .withErrorUrl(SOME_ERROR_URL) @@ -52,6 +54,7 @@ public void shouldBuildSimpleSdkConfigWithAllOptions() { assertThat(result.getSecondaryColour(), is(SOME_SECONDARY_COLOUR)); assertThat(result.getFontColour(), is(SOME_FONT_COLOUR)); assertThat(result.getLocale(), is(SOME_LOCALE)); + assertThat(result.getDarkMode(), is(SOME_DARK_MODE)); assertThat(result.getPresetIssuingCountry(), is(SOME_PRESET_ISSUING_COUNTRY)); assertThat(result.getSuccessUrl(), is(SOME_SUCCESS_URL)); assertThat(result.getErrorUrl(), is(SOME_ERROR_URL)); @@ -115,5 +118,31 @@ public void shouldOverridePreviousAllowedCaptureMethods() { assertThat(result.getAllowedCaptureMethods(), is("CAMERA")); } + @Test + public void shouldSetDarkModeToOn() { + SdkConfig result = SdkConfig.builder() + .withDarkModeOn() + .build(); + + assertThat(result.getDarkMode(), is("ON")); + } + + @Test + public void shouldSetDarkModeToOff() { + SdkConfig result = SdkConfig.builder() + .withDarkModeOff() + .build(); + + assertThat(result.getDarkMode(), is("OFF")); + } + + @Test + public void shouldSetDarkModeToAuto() { + SdkConfig result = SdkConfig.builder() + .withDarkModeAuto() + .build(); + + assertThat(result.getDarkMode(), is("AUTO")); + } } From e1224a6a6b2230c3d016f19eae45cf70a9ded981 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 12:09:10 +0100 Subject: [PATCH 10/30] SDK-2486: Amended Java Doc comments / helper methods should always use the builder method --- .../client/docs/session/create/SdkConfig.java | 17 +++++++---------- 1 file changed, 7 insertions(+), 10 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index 0abdb498..d7ad1541 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -109,7 +109,7 @@ public String getPrimaryColour() { } /** - * The primary colour for dark mode, configured for the session + * The primary colour to use when in dark mode * * @return the primary colour */ @@ -145,7 +145,7 @@ public String getLocale() { } /** - * The dark mode option configured for the session + * Whether to use dark mode - may be 'ON', 'OFF', or 'AUTO' * * @return the dark mode */ @@ -289,7 +289,7 @@ public Builder withPrimaryColour(String primaryColour) { } /** - * Sets the primary colour for the dark mode to be used by the web/native client + * Sets the primary colour to be used by the web/native client when in dark mode * * @param primaryColourDarkMode the primary colour for the dark mode, hexadecimal value e.g. #ff0000 * @return the builder @@ -333,7 +333,7 @@ public Builder withLocale(String locale) { } /** - * Sets the dark mode to be used by the web/native client + * Whether to use dark mode on the web/native client - may be 'ON', 'OFF', or 'AUTO' * * @param darkMode the dark mode, e.g. "ON" * @return the builder @@ -349,8 +349,7 @@ public Builder withDarkMode(String darkMode) { * @return the builder */ public Builder withDarkModeOn() { - this.darkMode = DocScanConstants.ON; - return this; + return withDarkMode(DocScanConstants.ON); } /** @@ -359,8 +358,7 @@ public Builder withDarkModeOn() { * @return the builder */ public Builder withDarkModeOff() { - this.darkMode = DocScanConstants.OFF; - return this; + return withDarkMode(DocScanConstants.OFF); } /** @@ -369,8 +367,7 @@ public Builder withDarkModeOff() { * @return the builder */ public Builder withDarkModeAuto() { - this.darkMode = DocScanConstants.AUTO; - return this; + return withDarkMode(DocScanConstants.AUTO); } /** From e5a6e86dd526e0734624c83b249c39b7b8d895c4 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 15:27:41 +0100 Subject: [PATCH 11/30] NA: Straighten out a unit test --- .../docs/session/create/SessionSpecTest.java | 97 +++++++------------ 1 file changed, 37 insertions(+), 60 deletions(-) diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java index 7cf4cce3..d0bb1463 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SessionSpecTest.java @@ -3,7 +3,14 @@ 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.Matchers.equalTo; +import static org.hamcrest.Matchers.hasItems; +import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.instanceOf; +import static org.hamcrest.Matchers.is; +import static org.hamcrest.Matchers.notNullValue; +import static org.hamcrest.Matchers.nullValue; import java.io.IOException; import java.time.ZonedDateTime; @@ -19,10 +26,10 @@ import com.fasterxml.jackson.databind.JsonNode; import com.fasterxml.jackson.databind.ObjectMapper; import org.hamcrest.Matchers; -import org.junit.*; +import org.junit.Test; import org.junit.runner.RunWith; -import org.mockito.*; -import org.mockito.junit.*; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; @RunWith(MockitoJUnitRunner.class) public class SessionSpecTest { @@ -53,6 +60,29 @@ public class SessionSpecTest { @Test public void shouldBuildWithMinimalConfiguration() { + SessionSpec result = SessionSpec.builder().build(); + + assertThat(result.getClientSessionTokenTtl(), is(nullValue())); + assertThat(result.getSessionDeadline(), is(nullValue())); + assertThat(result.getResourcesTtl(), is(nullValue())); + assertThat(result.getImportToken(), is(nullValue())); + assertThat(result.getUserTrackingId(), is(nullValue())); + assertThat(result.getNotifications(), is(nullValue())); + assertThat(result.getRequestedChecks(), hasSize(0)); + assertThat(result.getRequestedTasks(), hasSize(0)); + assertThat(result.getSdkConfig(), is(nullValue())); + assertThat(result.getRequiredDocuments(), hasSize(0)); + assertThat(result.getBlockBiometricConsent(), is(nullValue())); + assertThat(result.getIbvOptions(), is(nullValue())); + assertThat(result.getIdentityProfile(), is(nullValue())); + assertThat(result.getAdvancedIdentityProfileRequirements(), is(nullValue())); + assertThat(result.getSubject(), is(nullValue())); + assertThat(result.getResources(), is(nullValue())); + assertThat(result.getCreateIdentityProfilePreview(), is(nullValue())); + } + + @Test + public void shouldBuildWithSimpleValues() { SessionSpec result = SessionSpec.builder() .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) .withResourcesTtl(SOME_RESOURCES_TTL) @@ -60,44 +90,10 @@ public void shouldBuildWithMinimalConfiguration() { .withBlockBiometricConsent(true) .build(); - assertThat(result, is(instanceOf(SessionSpec.class))); assertThat(result.getClientSessionTokenTtl(), is(SOME_CLIENT_SESSION_TOKEN_TTL)); assertThat(result.getResourcesTtl(), is(SOME_RESOURCES_TTL)); assertThat(result.getUserTrackingId(), is(SOME_USER_TRACKING_ID)); assertThat(result.getBlockBiometricConsent(), is(true)); - assertThat(result.getRequiredDocuments(), hasSize(0)); - } - - @Test - public void shouldRaiseForMissingClientSessionTokenTtl() { - try { - SessionSpec.builder().build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("clientSessionTokenTtl")); - } - } - - @Test - public void shouldRaiseForMissingResourcesTtl() { - try { - SessionSpec.builder() - .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("resourcesTtl")); - } - } - - @Test - public void shouldRaiseForMissingUserTrackingId() { - try { - SessionSpec.builder() - .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) - .withResourcesTtl(SOME_RESOURCES_TTL) - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("userTrackingId")); - } } @Test @@ -124,8 +120,7 @@ public void shouldBuildWithValidNotifications() { @Test public void shouldBuildWithValidRequestedChecks() { - RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder() - .build(); + RequestedDocumentAuthenticityCheck authenticityCheck = RequestedDocumentAuthenticityCheck.builder().build(); RequestedLivenessCheck livenessCheck = RequestedLivenessCheck.builder() .forZoomLiveness() @@ -133,9 +128,6 @@ public void shouldBuildWithValidRequestedChecks() { .build(); SessionSpec result = SessionSpec.builder() - .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) - .withResourcesTtl(SOME_RESOURCES_TTL) - .withUserTrackingId(SOME_USER_TRACKING_ID) .withRequestedCheck(authenticityCheck) .withRequestedCheck(livenessCheck) .build(); @@ -152,9 +144,6 @@ public void shouldBuildWithValidRequestedTasks() { .build(); SessionSpec result = SessionSpec.builder() - .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) - .withResourcesTtl(SOME_RESOURCES_TTL) - .withUserTrackingId(SOME_USER_TRACKING_ID) .withRequestedTask(textExtractionTask) .build(); @@ -176,13 +165,9 @@ public void shouldBuildWithValidSdkConfig() { .build(); SessionSpec result = SessionSpec.builder() - .withClientSessionTokenTtl(SOME_CLIENT_SESSION_TOKEN_TTL) - .withResourcesTtl(SOME_RESOURCES_TTL) - .withUserTrackingId(SOME_USER_TRACKING_ID) .withSdkConfig(sdkConfig) .build(); - assertThat(result.getSdkConfig(), is(notNullValue())); assertThat(result.getSdkConfig().getAllowedCaptureMethods(), is("CAMERA_AND_UPLOAD")); assertThat(result.getSdkConfig().getPrimaryColour(), is(SOME_SDK_CONFIG_PRIMARY_COLOUR)); assertThat(result.getSdkConfig().getSecondaryColour(), is(SOME_SDK_CONFIG_SECONDARY_COLOUR)); @@ -230,7 +215,7 @@ public void withSessionDeadline_shouldSetTheSessionDeadline() { } @Test - public void buildWithIdentityProfile() throws IOException { + public void shouldBuildWithIdentityProfileRequirements() throws IOException { Map scheme = new HashMap<>(); scheme.put(IdentityProperty.TYPE, "A_TYPE"); scheme.put(IdentityProperty.OBJECTIVE, "AN_OBJECTIVE"); @@ -260,7 +245,7 @@ private static JsonNode toSessionSpecJson(Map obj) throws IOExce } @Test - public void buildWithSubject() throws IOException { + public void shouldBuildWithSubject() throws IOException { Map subject = new HashMap<>(); subject.put(SubjectProperty.SUBJECT_ID, "A_SUBJECT_ID"); @@ -295,14 +280,6 @@ public void shouldBuildWithCreateIdentityProfilePreview() { assertThat(sessionSpec.getCreateIdentityProfilePreview(), is(true)); } - @Test - public void shouldSetNullForCreateIdentityProfilePreviewWhenNotProvidedExplicitly() { - SessionSpec sessionSpec = SessionSpec.builder() - .build(); - - assertThat(sessionSpec.getCreateIdentityProfilePreview(), nullValue()); - } - @Test public void shouldBuildWithImportToken() { SessionSpec sessionSpec = SessionSpec.builder() From c2f35523345bc62b953699b4ad4e47613dc8a2cd Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 16:31:20 +0100 Subject: [PATCH 12/30] NA: UTs can just use assertThrows instead of try-catch --- .../client/docs/DocScanClientBuilderTest.java | 38 +- .../api/client/docs/DocScanClientTest.java | 135 ++-- .../api/client/docs/DocScanServiceTest.java | 686 ++++++------------ ...RequestedWatchlistScreeningConfigTest.java | 16 +- .../DocumentRestrictionsFilterTest.java | 13 +- .../RequiredSupplementaryDocumentTest.java | 35 +- 6 files changed, 291 insertions(+), 632 deletions(-) diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientBuilderTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientBuilderTest.java index 095bae55..21ac4dd6 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientBuilderTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientBuilderTest.java @@ -4,6 +4,7 @@ import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; +import static org.junit.Assert.assertThrows; import static org.junit.Assert.fail; import com.yoti.api.client.KeyPairSource; @@ -26,40 +27,25 @@ public void setUp() { @Test public void build_shouldThrowExceptionWhenSdkIdIsNull() { - try { - DocScanClient.builder() - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DocScanClient.builder().build()); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void build_shouldThrowExceptionWhenSdkIdIsEmpty() { - try { - DocScanClient.builder() - .withClientSdkId("") - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DocScanClient.builder().withClientSdkId("").build()); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void build_shouldThrowExceptionWhenKeyPairSourceIsNull() { - try { - DocScanClient.builder() - .withClientSdkId(SOME_APPLICATION_ID) - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + DocScanClient.Builder builder = DocScanClient.builder().withClientSdkId(SOME_APPLICATION_ID); + + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> builder.build()); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java index fc22e91a..e2375549 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java @@ -5,7 +5,6 @@ import static org.hamcrest.Matchers.instanceOf; import static org.hamcrest.Matchers.is; import static org.junit.Assert.assertThrows; -import static org.junit.Assert.fail; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.eq; import static org.mockito.Mockito.doThrow; @@ -49,106 +48,74 @@ public void setUp() { public void constructor_shouldFailWhenStreamExceptionLoadingKeys() { KeyPairSource badKeyPairSource = new StaticKeyPairSource(true); - try { - new DocScanClient(APP_ID, badKeyPairSource, docScanServiceMock); - } catch (InitialisationException e) { - assertThat(e.getCause(), is(instanceOf(IOException.class))); - assertThat(e.getCause().getMessage(), containsString("Test stream exception")); - return; - } - fail("Expected an Exception"); + InitialisationException ex = assertThrows(InitialisationException.class, () -> new DocScanClient(APP_ID, badKeyPairSource, docScanServiceMock)); + + assertThat(ex.getCause(), is(instanceOf(IOException.class))); + assertThat(ex.getCause().getMessage(), containsString("Test stream exception")); } @Test public void createDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - when(docScanServiceMock.createSession(eq(APP_ID), any(KeyPair.class), eq(sessionSpecMock))).thenThrow(original); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.createSession(sessionSpecMock)); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.createSession(sessionSpecMock); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + assertThat(thrown, is(original)); } @Test public void getDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - when(docScanServiceMock.retrieveSession(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID))).thenThrow(original); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getSession(SOME_SESSION_ID)); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getSession(SOME_SESSION_ID); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + assertThat(thrown, is(original)); } @Test public void getDocScanMedia_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - when(docScanServiceMock.getMediaContent(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(SOME_MEDIA_ID))).thenThrow(original); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID)); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + assertThat(thrown, is(original)); } @Test public void deleteDocScanMedia_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).deleteMediaContent(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(SOME_MEDIA_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.deleteMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertThat(thrown, is(original)); } @Test public void deleteDocScanSession_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).deleteSession(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.deleteSession(SOME_SESSION_ID); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteSession(SOME_SESSION_ID)); + + assertThat(thrown, is(original)); } @Test public void putIbvInstructions_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).putIbvInstructions(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID), eq(instructionsMock)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.putIbvInstructions(SOME_SESSION_ID, instructionsMock); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.putIbvInstructions(SOME_SESSION_ID, instructionsMock)); assertThat(exception, is(original)); } @@ -156,13 +123,10 @@ public void putIbvInstructions_shouldFailWithExceptionFromYotiDocsService() thro @Test public void getIbvInstructions_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).getIbvInstructions(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getIbvInstructions(SOME_SESSION_ID); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getIbvInstructions(SOME_SESSION_ID)); assertThat(exception, is(original)); } @@ -170,13 +134,10 @@ public void getIbvInstructions_shouldFailWithExceptionFromYotiDocsService() thro @Test public void getIbvInstructionsPdf_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).getIbvInstructionsPdf(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getIbvInstructionsPdf(SOME_SESSION_ID); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getIbvInstructionsPdf(SOME_SESSION_ID)); assertThat(exception, is(original)); } @@ -184,13 +145,10 @@ public void getIbvInstructionsPdf_shouldFailWithExceptionFromYotiDocsService() t @Test public void fetchInstructionsContactProfile_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).fetchInstructionsContactProfile(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.fetchInstructionsContactProfile(SOME_SESSION_ID); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.fetchInstructionsContactProfile(SOME_SESSION_ID)); assertThat(exception, is(original)); } @@ -198,27 +156,21 @@ public void fetchInstructionsContactProfile_shouldFailWithExceptionFromYotiDocsS @Test public void triggerIbvEmailNotification_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).triggerIbvEmailNotification(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.triggerIbvEmailNotification(SOME_SESSION_ID); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.triggerIbvEmailNotification(SOME_SESSION_ID)); assertThat(exception, is(original)); } - + @Test public void getSessionConfiguration_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).fetchSessionConfiguration(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - DocScanException exception = assertThrows(DocScanException.class, () -> { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getSessionConfiguration(SOME_SESSION_ID); - }); + DocScanException exception = assertThrows(DocScanException.class, () -> testObj.getSessionConfiguration(SOME_SESSION_ID)); assertThat(exception, is(original)); } @@ -226,17 +178,12 @@ public void getSessionConfiguration_shouldFailWithExceptionFromYotiDocsService() @Test public void getSupportedDocuments_shouldFailWithExceptionFromYotiDocsService() throws Exception { DocScanException original = new DocScanException("Test exception"); - doThrow(original).when(docScanServiceMock).getSupportedDocuments(any(KeyPair.class), any(Boolean.class)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getSupportedDocuments()); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.getSupportedDocuments(); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + assertThat(thrown, is(original)); } } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java index 7d2f6104..81b43e20 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java @@ -10,7 +10,6 @@ import static com.yoti.api.client.spi.remote.util.CryptoUtil.generateKeyPairFrom; import static junit.framework.TestCase.assertSame; -import static junit.framework.TestCase.fail; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; @@ -79,7 +78,7 @@ public class DocScanServiceTest { private static final String SOME_API_URL = System.getProperty(PROPERTY_YOTI_DOCS_URL, DEFAULT_YOTI_DOCS_URL); private static final String SOME_RESOURCE_ID = "someResourceId"; private static final String SOME_IMAGE_CONTENT_TYPE = "someImageContentType"; - private static final byte[] SOME_SESSION_SPEC_BYTES = new byte[]{ 1, 2, 3, 4 }; + private static final byte[] SOME_SESSION_SPEC_BYTES = new byte[] { 1, 2, 3, 4 }; private static final byte[] IMAGE_BODY = "some-image-body".getBytes(); private static final ObjectMapper MAPPER = new ObjectMapper(); @@ -98,7 +97,6 @@ public class DocScanServiceTest { @Mock CreateFaceCaptureResourcePayload createFaceCaptureResourcePayloadMock; @Mock UploadFaceCaptureImagePayload uploadFaceCaptureImagePayloadMock; - @BeforeClass public static void setUpClass() throws Exception { KEY_PAIR = generateKeyPairFrom(KEY_PAIR_PEM); @@ -110,132 +108,93 @@ public void setUp() { } @Test - public void createSession_shouldThrowExceptionWhenMissingAppId() throws Exception { - try { - docScanService.createSession(null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void createSession_shouldThrowExceptionWhenMissingAppId() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createSession(null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void createSession_shouldThrowExceptionWhenMissingKeyPair() throws Exception { - try { - docScanService.createSession(SOME_APP_ID, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void createSession_shouldThrowExceptionWhenMissingKeyPair() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createSession(SOME_APP_ID, null, null)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test - public void createSession_shouldThrowExceptionWhenMissingSessionSpec() throws Exception { - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionSpec")); - return; - } - fail("Expected an exception"); + public void createSession_shouldThrowExceptionWhenMissingSessionSpec() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, null)); + + assertThat(ex.getMessage(), containsString("sessionSpec")); } @Test public void createSession_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - SessionSpec sessionSpecMock = mock(SessionSpec.class); when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void createSession_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - SessionSpec sessionSpecMock = mock(SessionSpec.class); when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(CreateSessionResult.class)).thenThrow(resourceException); - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error posting the request: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error posting the request: Failed Request")); } @Test public void createSession_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - SessionSpec sessionSpecMock = mock(SessionSpec.class); when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(CreateSessionResult.class)).thenThrow(ioException); - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void createSession_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - SessionSpec sessionSpecMock = mock(SessionSpec.class); when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); - } catch (DocScanException ex) { - assertSame(ex.getCause(), uriSyntaxException); - assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + } @Test public void createSession_shouldWrapGeneralException() { - final Exception someException = new Exception("Some exception we weren't expecting"); - + Exception someException = new Exception("Some exception we weren't expecting"); SessionSpec sessionSpecMock = mock(SessionSpec.class); - doAnswer(i -> { - throw someException; - }).when(signedRequestBuilderFactoryMock).create(); + doAnswer(i -> {throw someException;}).when(signedRequestBuilderFactoryMock).create(); - try { - docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); - } catch (DocScanException ex) { - assertSame(ex.getCause(), someException); - assertThat(ex.getMessage(), containsString("Error creating the session: Some exception we weren't expecting")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock)); + + assertSame(ex.getCause(), someException); + assertThat(ex.getMessage(), containsString("Error creating the session: Some exception we weren't expecting")); } @Test public void createSession_shouldCallSignedRequestBuilderWithCorrectMethods() throws Exception { SessionSpec sessionSpecMock = mock(SessionSpec.class); CreateSessionResult createSessionResultMock = mock(CreateSessionResult.class); - when(objectMapperMock.writeValueAsBytes(sessionSpecMock)).thenReturn(SOME_SESSION_SPEC_BYTES); when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(CreateSessionResult.class)).thenReturn(createSessionResultMock); @@ -244,7 +203,6 @@ public void createSession_shouldCallSignedRequestBuilderWithCorrectMethods() thr CreateSessionResult result = docScanService.createSession(SOME_APP_ID, KEY_PAIR, sessionSpecMock); assertThat(result, is(createSessionResultMock)); - verify(signedRequestBuilderMock).withKeyPair(KEY_PAIR); verify(signedRequestBuilderMock).withEndpoint(SOME_PATH); verify(signedRequestBuilderMock).withBaseUrl(SOME_API_URL); @@ -254,132 +212,89 @@ public void createSession_shouldCallSignedRequestBuilderWithCorrectMethods() thr } @Test - public void retrieveSession_shouldThrowExceptionWhenAppIdIsNull() throws Exception { - try { - docScanService.retrieveSession(null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void retrieveSession_shouldThrowExceptionWhenAppIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.retrieveSession(null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void retrieveSession_shouldThrowExceptionWhenAppIdIsEmpty() throws Exception { - try { - docScanService.retrieveSession("", null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void retrieveSession_shouldThrowExceptionWhenAppIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.retrieveSession("", null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void retrieveSession_shouldThrowExceptionWhenMissingKeyPair() throws Exception { - try { - docScanService.retrieveSession(SOME_APP_ID, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void retrieveSession_shouldThrowExceptionWhenMissingKeyPair() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.retrieveSession(SOME_APP_ID, null, null)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test - public void retrieveSession_shouldThrowExceptionWhenSessionIdIsNull() throws Exception { - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void retrieveSession_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void retrieveSession_shouldThrowExceptionWhenSessionIdIsEmpty() throws Exception { - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, ""); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void retrieveSession_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, "")); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void retrieveSession_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void retrieveSession_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(GetSessionResult.class)).thenThrow(resourceException); - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void retrieveSession_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(GetSessionResult.class)).thenThrow(ioException); - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void retrieveSession_shouldWrapGeneralException() { - final Exception someException = new Exception("Some exception we weren't expecting"); + Exception someException = new Exception("Some exception we weren't expecting"); + doAnswer(i -> {throw someException;}).when(signedRequestBuilderFactoryMock).create(); - doAnswer(i -> { - throw someException; - }).when(signedRequestBuilderFactoryMock).create(); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - try { - docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), someException); - assertThat(ex.getMessage(), containsString("Error retrieving the session: Some exception we weren't expecting")); - return; - } - fail("Expected an exception"); + assertSame(ex.getCause(), someException); + assertThat(ex.getMessage(), containsString("Error retrieving the session: Some exception we weren't expecting")); } @Test public void retrieveSession_shouldCallSignedRequestBuilderWithCorrectMethods() throws Exception { GetSessionResult docScanSessionResponseMock = mock(GetSessionResult.class); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(GetSessionResult.class)).thenReturn(docScanSessionResponseMock); when(unsignedPathFactoryMock.createYotiDocsSessionPath(SOME_APP_ID, SOME_SESSION_ID)).thenReturn(SOME_PATH); @@ -387,7 +302,6 @@ public void retrieveSession_shouldCallSignedRequestBuilderWithCorrectMethods() t GetSessionResult result = docScanService.retrieveSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); assertThat(result, is(docScanSessionResponseMock)); - verify(signedRequestBuilderMock).withKeyPair(KEY_PAIR); verify(signedRequestBuilderMock).withEndpoint(SOME_PATH); verify(signedRequestBuilderMock).withBaseUrl(SOME_API_URL); @@ -395,126 +309,84 @@ public void retrieveSession_shouldCallSignedRequestBuilderWithCorrectMethods() t } @Test - public void deleteSession_shouldThrowExceptionWhenAppIdIsNull() throws Exception { - try { - docScanService.deleteSession(null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void deleteSession_shouldThrowExceptionWhenAppIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteSession(null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void deleteSession_shouldThrowExceptionWhenAppIdIsEmpty() throws Exception { - try { - docScanService.deleteSession("", null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void deleteSession_shouldThrowExceptionWhenAppIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteSession("", null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void deleteSession_shouldThrowExceptionWhenKeyPairIsNull() throws Exception { - try { - docScanService.deleteSession(SOME_APP_ID, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void deleteSession_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteSession(SOME_APP_ID, null, null)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test - public void deleteSession_shouldThrowExceptionWhenSessionIdIsNull() throws Exception { - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void deleteSession_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void deleteSession_shouldThrowExceptionWhenSessionIdIsEmpty() throws Exception { - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, ""); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void deleteSession_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, "")); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void deleteSession_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void deleteSession_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error executing the DELETE: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the DELETE: Failed Request")); } @Test public void deleteSession_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void deleteSession_shouldWrapGeneralException() { - final Exception someException = new Exception("Some exception we weren't expecting"); + Exception someException = new Exception("Some exception we weren't expecting"); + doAnswer(i -> {throw someException;}).when(signedRequestBuilderFactoryMock).create(); - doAnswer(i -> { - throw someException; - }).when(signedRequestBuilderFactoryMock).create(); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - try { - docScanService.deleteSession(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), someException); - assertThat(ex.getMessage(), containsString("Error deleting the session: Some exception we weren't expecting")); - return; - } - fail("Expected an exception"); + assertSame(ex.getCause(), someException); + assertThat(ex.getMessage(), containsString("Error deleting the session: Some exception we weren't expecting")); } @Test @@ -531,146 +403,98 @@ public void deleteSession_shouldBuildSignedRequest() throws Exception { } @Test - public void getMediaContent_shouldThrowExceptionWhenApplicationIdIsNull() throws Exception { - try { - docScanService.getMediaContent(null, null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenApplicationIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(null, null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void getMediaContent_shouldThrowExceptionWhenApplicationIdIsEmpty() throws Exception { - try { - docScanService.getMediaContent("", null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenApplicationIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent("", null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void getMediaContent_shouldThrowExceptionWhenKeyPairIsNull() throws Exception { - try { - docScanService.getMediaContent(SOME_APP_ID, null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(SOME_APP_ID, null, null, null)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test - public void getMediaContent_shouldThrowExceptionWhenSessionIdIsNull() throws Exception { - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, null, null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void getMediaContent_shouldThrowExceptionWhenSessionIdIsEmpty() throws Exception { - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, "", null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, "", null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void getMediaContent_shouldThrowExceptionWhenMediaIdIsNull() throws Exception { - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("mediaId")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenMediaIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); + + assertThat(ex.getMessage(), containsString("mediaId")); } @Test - public void getMediaContent_shouldThrowExceptionWhenMediaIdIsEmpty() throws Exception { - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, ""); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("mediaId")); - return; - } - fail("Expected an exception"); + public void getMediaContent_shouldThrowExceptionWhenMediaIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, "")); + + assertThat(ex.getMessage(), containsString("mediaId")); } @Test public void getMediaContent_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void getMediaContent_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void getMediaContent_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void getMediaContent_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - try { - docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), uriSyntaxException); - assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test @@ -735,152 +559,103 @@ private Map> createHeadersMap(String key, String value) { } @Test - public void deleteMediaContent_shouldThrowExceptionWhenApplicationIdIsNull() throws Exception { - try { - docScanService.deleteMediaContent(null, null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenApplicationIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(null, null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenApplicationIdIsEmpty() throws Exception { - try { - docScanService.deleteMediaContent("", null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("SDK ID")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenApplicationIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent("", null, null, null)); + + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenKeyPairIsNull() throws Exception { - try { - docScanService.deleteMediaContent(SOME_APP_ID, null, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, null, null, null)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenSessionIdIsNull() throws Exception { - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, null, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, null, null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenSessionIdIsEmpty() throws Exception { - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, "", null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("sessionId")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, "", null)); + + assertThat(ex.getMessage(), containsString("sessionId")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenMediaIdIsNull() throws Exception { - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("mediaId")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenMediaIdIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); + + assertThat(ex.getMessage(), containsString("mediaId")); } @Test - public void deleteMediaContent_shouldThrowExceptionWhenMediaIdIsEmpty() throws Exception { - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, ""); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("mediaId")); - return; - } - fail("Expected an exception"); + public void deleteMediaContent_shouldThrowExceptionWhenMediaIdIsEmpty() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, "")); + + assertThat(ex.getMessage(), containsString("mediaId")); } @Test public void deleteMediaContent_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void deleteMediaContent_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error executing the DELETE: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the DELETE: Failed Request")); } @Test public void deleteMediaContent_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void deleteMediaContent_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - try { - docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); - } catch (DocScanException ex) { - assertSame(ex.getCause(), uriSyntaxException); - assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void deleteMediaContent_shouldBuildSignedRequest() throws Exception { when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); - when(unsignedPathFactoryMock.createMediaContentPath(SOME_APP_ID, SOME_SESSION_ID, SOME_MEDIA_ID)).thenReturn(SOME_PATH); docScanService.deleteMediaContent(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_MEDIA_ID); @@ -1549,7 +1324,7 @@ public void uploadFaceCaptureImage_shouldWrapResourceException() throws Exceptio assertSame(docScanException.getCause(), resourceException); assertThat(docScanException.getMessage(), containsString("Error executing the PUT: Failed Request")); } - + @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenSdkIdIsNull() { IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(null, KEY_PAIR, SOME_SESSION_ID)); @@ -1632,64 +1407,45 @@ public void triggerIbvEmailNotification_shouldWrapURISyntaxException() throws Ex } @Test - public void getSupportedDocuments_shouldThrowExceptionWhenKeyPairIsNull() throws Exception { - try { - docScanService.getSupportedDocuments(null, false); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("Application key Pair")); - return; - } - fail("Expected an exception"); + public void getSupportedDocuments_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getSupportedDocuments(null, false)); + + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void getSupportedDocuments_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - try { - docScanService.getSupportedDocuments(KEY_PAIR, false); - } catch (DocScanException ex) { - assertSame(ex.getCause(), gse); - assertThat(ex.getMessage(), containsString("Error executing the GET: some gse")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getSupportedDocuments(KEY_PAIR, false)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error executing the GET: some gse")); } @Test public void getSupportedDocuments_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(SupportedDocumentsResponse.class)).thenThrow(resourceException); - try { - docScanService.getSupportedDocuments(KEY_PAIR, false); - } catch (DocScanException ex) { - assertSame(ex.getCause(), resourceException); - assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getSupportedDocuments(KEY_PAIR, false)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void getSupportedDocuments_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(SupportedDocumentsResponse.class)).thenThrow(ioException); - try { - docScanService.getSupportedDocuments(KEY_PAIR, false); - } catch (DocScanException ex) { - assertSame(ex.getCause(), ioException); - assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getSupportedDocuments(KEY_PAIR, false)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test @@ -1698,14 +1454,10 @@ public void getSupportedDocuments_shouldWrapURISyntaxException() throws Exceptio when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - try { - docScanService.getSupportedDocuments(KEY_PAIR, false); - } catch (DocScanException ex) { - assertSame(ex.getCause(), uriSyntaxException); - assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); - return; - } - fail("Expected an exception"); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getSupportedDocuments(KEY_PAIR, false)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/check/RequestedWatchlistScreeningConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/check/RequestedWatchlistScreeningConfigTest.java index 27ed0aba..b00e0360 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/check/RequestedWatchlistScreeningConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/check/RequestedWatchlistScreeningConfigTest.java @@ -10,7 +10,7 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; import static org.hamcrest.core.StringContains.containsString; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import org.junit.Test; @@ -73,17 +73,11 @@ public void builder_shouldNotAddCategoryMoreThanOnceEvenIfCalled() { public void builder_shouldNotAllowNullCategory() { RequestedWatchlistScreeningConfig.Builder builder = RequestedWatchlistScreeningConfig.builder(); - try { - builder.withCategory(null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("category")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> builder.withCategory(null)); - RequestedWatchlistScreeningConfig result = builder.build(); - assertThat(result.getCategories(), is(nullValue())); - return; - } - - fail("Expected an IllegalArgumentException"); + assertThat(ex.getMessage(), containsString("category")); + RequestedWatchlistScreeningConfig result = builder.build(); + assertThat(result.getCategories(), is(nullValue())); } @Test diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/DocumentRestrictionsFilterTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/DocumentRestrictionsFilterTest.java index 213215f2..fb1d2efe 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/DocumentRestrictionsFilterTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/DocumentRestrictionsFilterTest.java @@ -6,7 +6,7 @@ import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.nullValue; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.util.Arrays; import java.util.List; @@ -30,14 +30,9 @@ public class DocumentRestrictionsFilterTest { @Test public void shouldThrowExceptionForMissingInclusion() { - try { - DocumentRestrictionsFilter.builder() - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("inclusion")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> DocumentRestrictionsFilter.builder().build()); + + assertThat(ex.getMessage(), containsString("inclusion")); } @Test diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/RequiredSupplementaryDocumentTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/RequiredSupplementaryDocumentTest.java index 41ed53c8..1c248fdd 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/RequiredSupplementaryDocumentTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/filters/RequiredSupplementaryDocumentTest.java @@ -4,7 +4,7 @@ import static org.hamcrest.Matchers.containsInAnyOrder; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; -import static org.junit.Assert.fail; +import static org.junit.Assert.assertThrows; import java.util.Arrays; @@ -33,38 +33,23 @@ public void shouldHaveTheCorrectType() { @Test public void shouldThrowExceptionWhenDocumentTypesIsNull() { - try { - RequiredSupplementaryDocument.builder() - .withDocumentTypes(null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("documentTypes")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, ()-> RequiredSupplementaryDocument.builder().withDocumentTypes(null)); + + assertThat(ex.getMessage(), containsString("documentTypes")); } @Test public void shouldThrowExceptionWhenCountryCodesIsNull() { - try { - RequiredSupplementaryDocument.builder() - .withCountryCodes(null); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("countryCodes")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, ()-> RequiredSupplementaryDocument.builder().withCountryCodes(null)); + + assertThat(ex.getMessage(), containsString("countryCodes")); } @Test public void shouldRequireObjectiveBeforeBuilding() { - try { - RequiredSupplementaryDocument.builder() - .build(); - } catch (IllegalArgumentException ex) { - assertThat(ex.getMessage(), containsString("objective")); - return; - } - fail("Expected an exception"); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, ()-> RequiredSupplementaryDocument.builder().build()); + + assertThat(ex.getMessage(), containsString("objective")); } @Test From 537c4e7e65a4305f03fc1cf3d8eb5f8e30e1f68d Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 23 Sep 2024 02:16:12 +0100 Subject: [PATCH 13/30] SDK-2339: Allow the Relying Business to retrieve expanded document fields --- .../retrieve/ExpandedDocumentFieldsResponse.java | 14 ++++++++++++++ .../retrieve/IdDocumentResourceResponse.java | 7 +++++++ 2 files changed, 21 insertions(+) create mode 100644 yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ExpandedDocumentFieldsResponse.java diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ExpandedDocumentFieldsResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ExpandedDocumentFieldsResponse.java new file mode 100644 index 00000000..83f2f785 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ExpandedDocumentFieldsResponse.java @@ -0,0 +1,14 @@ +package com.yoti.api.client.docs.session.retrieve; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class ExpandedDocumentFieldsResponse { + + @JsonProperty("media") + private MediaResponse media; + + public MediaResponse getMedia() { + return media; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocumentResourceResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocumentResourceResponse.java index 88476ec6..83359d8a 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocumentResourceResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocumentResourceResponse.java @@ -21,6 +21,9 @@ public class IdDocumentResourceResponse extends ResourceResponse { @JsonProperty("document_id_photo") private DocumentIdPhotoResponse documentIdPhoto; + @JsonProperty("expanded_document_fields") + private ExpandedDocumentFieldsResponse expandedDocumentFields; + public String getDocumentType() { return documentType; } @@ -45,4 +48,8 @@ public DocumentIdPhotoResponse getDocumentIdPhoto() { return documentIdPhoto; } + public ExpandedDocumentFieldsResponse getExpandedDocumentFields() { + return expandedDocumentFields; + } + } From 1538ee0c233d10504dc95c7cacbecd185e2a36f0 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 16:47:26 +0100 Subject: [PATCH 14/30] NA: Standardise structure of UTs in DocScanServiceTest --- .../api/client/docs/DocScanServiceTest.java | 342 ++++++++---------- 1 file changed, 158 insertions(+), 184 deletions(-) diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java index 81b43e20..ad756814 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java @@ -690,252 +690,240 @@ public void shouldNotFailForUnknownChecks() throws Exception { @Test public void putIbvInstructions_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(null, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(null, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void putIbvInstructions_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions("", KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions("", KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void putIbvInstructions_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, null, SOME_SESSION_ID, instructionsMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, null, SOME_SESSION_ID, instructionsMock)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void putIbvInstructions_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, null, instructionsMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, null, instructionsMock)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void putIbvInstructions_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, "", instructionsMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, "", instructionsMock)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void putIbvInstructions_shouldThrowExceptionWhenInstructionsIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); - assertThat(exception.getMessage(), containsString("instructions")); + assertThat(ex.getMessage(), containsString("instructions")); } @Test public void putIbvInstructions_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void putIbvInstructions_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(docScanException.getMessage(), containsString("Error executing the PUT: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the PUT: Failed Request")); } @Test public void putIbvInstructions_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void putIbvInstructions_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.putIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, instructionsMock)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void getIbvInstructions_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(null, KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(null, KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void getIbvInstructions_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions("", KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions("", KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void getIbvInstructions_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, null, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, null, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void getIbvInstructions_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, null)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void getIbvInstructions_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, "")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, "")); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void getIbvInstructions_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void getIbvInstructions_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(InstructionsResponse.class)).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the GET: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void getIbvInstructions_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(InstructionsResponse.class)).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void getIbvInstructions_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructions(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void getIbvInstructionsPdf_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(null, KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(null, KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void getIbvInstructionsPdf_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf("", KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf("", KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void getIbvInstructionsPdf_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, null, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, null, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void getIbvInstructionsPdf_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, null)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void getIbvInstructionsPdf_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, "")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, "")); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void getIbvInstructionsPdf_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void getIbvInstructionsPdf_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the GET: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void getIbvInstructionsPdf_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void getIbvInstructionsPdf_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getIbvInstructionsPdf(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test @@ -966,217 +954,208 @@ public void getIbvInstructionsPdf_shouldReturnNullForNoContent() throws Exceptio @Test public void fetchInstructionsContactProfile_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(null, KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(null, KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void fetchInstructionsContactProfile_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile("", KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile("", KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void fetchInstructionsContactProfile_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, null, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, null, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void fetchInstructionsContactProfile_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, null)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void fetchInstructionsContactProfile_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, "")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, "")); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void fetchInstructionsContactProfile_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void fetchInstructionsContactProfile_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(ContactProfileResponse.class)).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the GET: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void fetchInstructionsContactProfile_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(ContactProfileResponse.class)).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void fetchInstructionsContactProfile_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchInstructionsContactProfile(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void fetchSessionConfiguration_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(null, KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(null, KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void fetchSessionConfiguration_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration("", KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration("", KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void fetchSessionConfiguration_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, null, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, null, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void fetchSessionConfiguration_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, null)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void fetchSessionConfiguration_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, "")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, "")); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void fetchSessionConfiguration_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test public void fetchSessionConfiguration_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(SessionConfigurationResponse.class)).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the GET: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); } @Test public void fetchSessionConfiguration_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(SessionConfigurationResponse.class)).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void fetchSessionConfiguration_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.fetchSessionConfiguration(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(null, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(null, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource("", KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource("", KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, null, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, null, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, null, createFaceCaptureResourcePayloadMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, null, createFaceCaptureResourcePayloadMock)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, "", createFaceCaptureResourcePayloadMock)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, "", createFaceCaptureResourcePayloadMock)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void createFaceCaptureResource_shouldThrowExceptionWhenPayloadIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null)); - assertThat(exception.getMessage(), containsString("createFaceCaptureResourcePayload")); + assertThat(ex.getMessage(), containsString("createFaceCaptureResourcePayload")); } @Test public void createFaceCaptureResource_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(docScanException.getMessage(), containsString("Error signing the request: some gse")); + assertThat(ex.getMessage(), containsString("Error signing the request: some gse")); } @Test @@ -1185,9 +1164,9 @@ public void createFaceCaptureResource_shouldWrapResourceException() throws Excep when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(CreateFaceCaptureResourceResponse.class)).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(docScanException.getMessage(), containsString("Error executing the POST: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the POST: Failed Request")); } @Test @@ -1196,9 +1175,9 @@ public void createFaceCaptureResource_shouldWrapIOException() throws Exception { when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute(CreateFaceCaptureResourceResponse.class)).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test @@ -1206,65 +1185,65 @@ public void createFaceCaptureResource_shouldWrapURISyntaxException() throws Exce URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.createFaceCaptureResource(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, createFaceCaptureResourcePayloadMock)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test public void uploadFaceCaptureImage_shouldFailForNullSdkId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(null, null, null, null, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(null, null, null, null, null)); - assertThat(docScanException.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void uploadFaceCaptureImage_shouldFailForEmptySdkId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage("", null, null, null, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage("", null, null, null, null)); - assertThat(docScanException.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void uploadFaceCaptureImage_shouldFailForNullKeyPair() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, null, null, null, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, null, null, null, null)); - assertThat(docScanException.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void uploadFaceCaptureImage_shouldFailForNullSessionId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, null, null,null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, null, null,null)); - assertThat(docScanException.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void uploadFaceCaptureImage_shouldFailForEmptySessionId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, "", null, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, "", null, null)); - assertThat(docScanException.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void uploadFaceCaptureImage_shouldFailForNullResourceId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null,null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, null,null)); - assertThat(docScanException.getMessage(), containsString("resourceId")); + assertThat(ex.getMessage(), containsString("resourceId")); } @Test public void uploadFaceCaptureImage_shouldFailForEmptyResourceId() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, "", null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, "", null)); - assertThat(docScanException.getMessage(), containsString("resourceId")); + assertThat(ex.getMessage(), containsString("resourceId")); } @Test public void uploadFaceCaptureImage_shouldFailForNullPayload() { - IllegalArgumentException docScanException = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, null)); - assertThat(docScanException.getMessage(), containsString("faceCaptureImagePayload")); + assertThat(ex.getMessage(), containsString("faceCaptureImagePayload")); } @Test @@ -1275,10 +1254,10 @@ public void uploadFaceCaptureImage_shouldWrapGeneralSecurityException() throws E GeneralSecurityException gse = new GeneralSecurityException("some gse"); when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); - assertSame(docScanException.getCause(), gse); - assertThat(docScanException.getMessage(), containsString("Error executing the PUT: some gse")); + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error executing the PUT: some gse")); } @Test @@ -1289,10 +1268,10 @@ public void uploadFaceCaptureImage_shouldWrapURISyntaxException() throws Excepti URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); - assertSame(docScanException.getCause(), uriSyntaxException); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test @@ -1304,10 +1283,10 @@ public void uploadFaceCaptureImage_shouldWrapIOException() throws Exception { when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); - assertSame(docScanException.getCause(), ioException); - assertThat(docScanException.getMessage(), containsString("Error building the request: some IO exception")); + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: some IO exception")); } @Test @@ -1319,91 +1298,87 @@ public void uploadFaceCaptureImage_shouldWrapResourceException() throws Exceptio when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.uploadFaceCaptureImage(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID, SOME_RESOURCE_ID, uploadFaceCaptureImagePayloadMock)); - assertSame(docScanException.getCause(), resourceException); - assertThat(docScanException.getMessage(), containsString("Error executing the PUT: Failed Request")); + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the PUT: Failed Request")); } @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenSdkIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(null, KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(null, KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenSdkIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification("", KEY_PAIR, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification("", KEY_PAIR, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("SDK ID")); + assertThat(ex.getMessage(), containsString("SDK ID")); } @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenKeyPairIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, null, SOME_SESSION_ID)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, null, SOME_SESSION_ID)); - assertThat(exception.getMessage(), containsString("Application key Pair")); + assertThat(ex.getMessage(), containsString("Application key Pair")); } @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenSessionIdIsNull() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, null)); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, null)); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void triggerIbvEmailNotification_shouldThrowExceptionWhenSessionIdIsEmpty() { - IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, "")); + IllegalArgumentException ex = assertThrows(IllegalArgumentException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, "")); - assertThat(exception.getMessage(), containsString("sessionId")); + assertThat(ex.getMessage(), containsString("sessionId")); } @Test public void triggerIbvEmailNotification_shouldWrapGeneralSecurityException() throws Exception { GeneralSecurityException gse = new GeneralSecurityException("some gse"); - when(signedRequestBuilderMock.build()).thenThrow(gse); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the POST: some gse")); + assertThat(ex.getMessage(), containsString("Error executing the POST: some gse")); } @Test public void triggerIbvEmailNotification_shouldWrapResourceException() throws Exception { ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(resourceException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error executing the POST: Failed Request")); + assertThat(ex.getMessage(), containsString("Error executing the POST: Failed Request")); } @Test public void triggerIbvEmailNotification_shouldWrapIOException() throws Exception { IOException ioException = new IOException("Some io exception"); - when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); when(signedRequestMock.execute()).thenThrow(ioException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Some io exception")); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); } @Test public void triggerIbvEmailNotification_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); - DocScanException docScanException = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.triggerIbvEmailNotification(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); - assertThat(docScanException.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); } @Test @@ -1451,7 +1426,6 @@ public void getSupportedDocuments_shouldWrapIOException() throws Exception { @Test public void getSupportedDocuments_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getSupportedDocuments(KEY_PAIR, false)); From bddc4a5c2b868b6d5d4a8b5cd459c43bad799816 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 23 Sep 2024 02:08:39 +0100 Subject: [PATCH 15/30] SDK-2493: Add new helper methods for session notifications --- .../api/client/docs/DocScanConstants.java | 4 ++ .../session/create/NotificationConfig.java | 36 +++++++++++++++++ .../create/NotificationConfigTest.java | 40 +++++++++++++++++++ 3 files changed, 80 insertions(+) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java index b41ad95a..1bf0e5fc 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java @@ -53,6 +53,10 @@ private DocScanConstants() { } public static final String CHECK_COMPLETION = "CHECK_COMPLETION"; public static final String SESSION_COMPLETION = "SESSION_COMPLETION"; public static final String CLIENT_SESSION_TOKEN_DELETED = "CLIENT_SESSION_TOKEN_DELETED"; + public static final String NEW_PDF_SUPPLIED = "NEW_PDF_SUPPLIED"; + public static final String INSTRUCTIONS_EMAIL_REQUESTED = "INSTRUCTIONS_EMAIL_REQUESTED"; + public static final String THANK_YOU_EMAIL_REQUESTED = "THANK_YOU_EMAIL_REQUESTED"; + public static final String FIRST_BRANCH_VISIT = "FIRST_BRANCH_VISIT"; public static final String ALWAYS = "ALWAYS"; public static final String FALLBACK = "FALLBACK"; diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/NotificationConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/NotificationConfig.java index 9e6ede23..51871ea4 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/NotificationConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/NotificationConfig.java @@ -175,6 +175,42 @@ public Builder forClientSessionCompletion() { return withTopic(DocScanConstants.CLIENT_SESSION_TOKEN_DELETED); } + /** + * Adds NEW_PDF_SUPPLIED to the list of topics that trigger notification messages + * + * @return the builder + */ + public Builder forNewPdfSupplied() { + return withTopic(DocScanConstants.NEW_PDF_SUPPLIED); + } + + /** + * Adds INSTRUCTIONS_EMAIL_REQUESTED to the list of topics that trigger notification messages + * + * @return the builder + */ + public Builder forInstructionsEmailRequested() { + return withTopic(DocScanConstants.INSTRUCTIONS_EMAIL_REQUESTED); + } + + /** + * Adds THANK_YOU_EMAIL_REQUESTED to the list of topics that trigger notification messages + * + * @return the builder + */ + public Builder forThankYouEmailRequested() { + return withTopic(DocScanConstants.THANK_YOU_EMAIL_REQUESTED); + } + + /** + * Adds FIRST_BRANCH_VISIT to the list of topics that trigger notification messages + * + * @return the builder + */ + public Builder forFirstBranchVisit() { + return withTopic(DocScanConstants.FIRST_BRANCH_VISIT); + } + /** * Adds a topic to the list of topics that trigger notification messages * diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/NotificationConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/NotificationConfigTest.java index e315a1e9..8c137c87 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/NotificationConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/NotificationConfigTest.java @@ -69,6 +69,46 @@ public void shouldCreateSimpleNotificationConfigWithTaskCompletion() { assertThat(result.getTopics(), hasItem("RESOURCE_UPDATE")); } + @Test + public void shouldCreateSimpleNotificationConfigWithNewPdfSupplied() { + NotificationConfig result = NotificationConfig.builder() + .withEndpoint(SOME_ENDPOINT) + .forNewPdfSupplied() + .build(); + + assertThat(result.getTopics(), hasItem("NEW_PDF_SUPPLIED")); + } + + @Test + public void shouldCreateSimpleNotificationConfigWithInstructionsEmailRequested() { + NotificationConfig result = NotificationConfig.builder() + .withEndpoint(SOME_ENDPOINT) + .forInstructionsEmailRequested() + .build(); + + assertThat(result.getTopics(), hasItem("INSTRUCTIONS_EMAIL_REQUESTED")); + } + + @Test + public void shouldCreateSimpleNotificationConfigWithThankYouEmailRequested() { + NotificationConfig result = NotificationConfig.builder() + .withEndpoint(SOME_ENDPOINT) + .forThankYouEmailRequested() + .build(); + + assertThat(result.getTopics(), hasItem("THANK_YOU_EMAIL_REQUESTED")); + } + + @Test + public void shouldCreateSimpleNotificationConfigWithFirstBranchVisit() { + NotificationConfig result = NotificationConfig.builder() + .withEndpoint(SOME_ENDPOINT) + .forFirstBranchVisit() + .build(); + + assertThat(result.getTopics(), hasItem("FIRST_BRANCH_VISIT")); + } + @Test public void shouldCreateSimpleNotificationConfigWithAllNotificationOptions() { NotificationConfig result = NotificationConfig.builder() From 6ecb704aee429b7034cc544c09c9d1f49d9e0eb3 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Mon, 23 Sep 2024 17:40:43 +0100 Subject: [PATCH 16/30] SDK-2521: Support detected document_type in IDV Sandbox SDK --- .../docs/request/task/SandboxDocumentIdPhoto.java | 2 ++ .../task/SandboxDocumentTextDataExtractionTask.java | 13 +++++++++++-- ...SandboxDocumentTextDataExtractionTaskResult.java | 11 +++++++++++ ...upplementaryDocTextDataExtractionTaskResult.java | 2 ++ .../task/SandboxTextExtractionTaskReason.java | 2 ++ 5 files changed, 28 insertions(+), 2 deletions(-) diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentIdPhoto.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentIdPhoto.java index 37906d3d..fcf0b4e0 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentIdPhoto.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentIdPhoto.java @@ -1,7 +1,9 @@ package com.yoti.api.client.sandbox.docs.request.task; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@JsonInclude(JsonInclude.Include.NON_NULL) public class SandboxDocumentIdPhoto { @JsonProperty("content_type") diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java index 54774991..806917a5 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java @@ -46,6 +46,7 @@ public static class Builder { private SandboxDocumentFilter documentFilter; private SandboxDocumentIdPhoto documentIdPhoto; private String detectedCountry; + private String detectedDocumentType; private SandboxTextExtractionTaskRecommendation recommendation; private Builder() { @@ -82,14 +83,22 @@ public Builder withDetectedCountry(String detectedCountry) { return this; } + public Builder withDetectedDocumentType(String detectedDocumentType) { + this.detectedDocumentType = detectedDocumentType; + return this; + } + public Builder withRecommendation(SandboxTextExtractionTaskRecommendation recommendation) { this.recommendation = recommendation; return this; } public SandboxDocumentTextDataExtractionTask build() { - SandboxDocumentTextDataExtractionTaskResult result = new SandboxDocumentTextDataExtractionTaskResult(documentFields, this.documentIdPhoto, - detectedCountry, recommendation); + SandboxDocumentTextDataExtractionTaskResult result = new SandboxDocumentTextDataExtractionTaskResult(documentFields, + documentIdPhoto, + detectedCountry, + detectedDocumentType, + recommendation); return new SandboxDocumentTextDataExtractionTask(result, documentFilter); } } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskResult.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskResult.java index 0d3684a6..21065d5f 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskResult.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskResult.java @@ -2,8 +2,10 @@ import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@JsonInclude(JsonInclude.Include.NON_NULL) public class SandboxDocumentTextDataExtractionTaskResult { @JsonProperty("document_fields") @@ -15,16 +17,21 @@ public class SandboxDocumentTextDataExtractionTaskResult { @JsonProperty("detected_country") private final String detectedCountry; + @JsonProperty("detected_document_type") + private final String detectedDocumentType; + @JsonProperty("recommendation") private final SandboxTextExtractionTaskRecommendation recommendation; SandboxDocumentTextDataExtractionTaskResult(Map documentFields, SandboxDocumentIdPhoto documentIdPhoto, String detectedCountry, + String detectedDocumentType, SandboxTextExtractionTaskRecommendation recommendation) { this.documentFields = documentFields; this.documentIdPhoto = documentIdPhoto; this.detectedCountry = detectedCountry; + this.detectedDocumentType = detectedDocumentType; this.recommendation = recommendation; } @@ -40,6 +47,10 @@ public String getDetectedCountry() { return detectedCountry; } + public String getDetectedDocumentType() { + return detectedDocumentType; + } + public SandboxTextExtractionTaskRecommendation getRecommendation() { return recommendation; } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskResult.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskResult.java index ef7a2399..bef00ad8 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskResult.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskResult.java @@ -2,8 +2,10 @@ import java.util.Map; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@JsonInclude(JsonInclude.Include.NON_NULL) public class SandboxSupplementaryDocTextDataExtractionTaskResult { @JsonProperty("document_fields") diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxTextExtractionTaskReason.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxTextExtractionTaskReason.java index 9223a108..505b7096 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxTextExtractionTaskReason.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxTextExtractionTaskReason.java @@ -2,8 +2,10 @@ import com.yoti.api.client.sandbox.docs.SandboxDocScanConstants; +import com.fasterxml.jackson.annotation.JsonInclude; import com.fasterxml.jackson.annotation.JsonProperty; +@JsonInclude(JsonInclude.Include.NON_NULL) public class SandboxTextExtractionTaskReason { @JsonProperty("value") From 6649c24b6b6ebd3b70b6d081161acd12ac3699c4 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Tue, 24 Sep 2024 10:28:52 +0100 Subject: [PATCH 17/30] SDK-2507: Allow the Relying Business to set response delay for tasks and Liveness checks in the sandbox --- .../request/check/SandboxLivenessCheck.java | 6 ++++- .../SandboxStaticLivenessCheckBuilder.java | 12 +++++++--- .../SandboxZoomLivenessCheckBuilder.java | 14 +++++++---- ...SandboxDocumentTextDataExtractionTask.java | 23 ++++++++++++++---- ...upplementaryDocTextDataExtractionTask.java | 24 +++++++++++++++---- ...boxDocumentTextDataExtractionTaskTest.java | 9 +++++++ ...ementaryDocTextDataExtractionTaskTest.java | 11 ++++++++- 7 files changed, 81 insertions(+), 18 deletions(-) diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java index dbbbbf42..15b8f97f 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxLivenessCheck.java @@ -7,9 +7,13 @@ public class SandboxLivenessCheck extends SandboxCheck { @JsonProperty("liveness_type") private final String livenessType; - SandboxLivenessCheck(SandboxCheckResult result, String livenessType) { + @JsonProperty("response_delay") + private final Integer responseDelay; + + SandboxLivenessCheck(SandboxCheckResult result, String livenessType, Integer responseDelay) { super(result); this.livenessType = livenessType; + this.responseDelay = responseDelay; } public static SandboxZoomLivenessCheckBuilder forZoomLiveness() { diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java index 723b0457..441d0f2c 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java @@ -1,13 +1,19 @@ package com.yoti.api.client.sandbox.docs.request.check; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import com.yoti.api.client.docs.DocScanConstants; import com.yoti.api.client.sandbox.docs.request.check.report.SandboxCheckReport; public class SandboxStaticLivenessCheckBuilder extends SandboxCheck.Builder { - SandboxStaticLivenessCheckBuilder() { + private Integer responseDelay; + + SandboxStaticLivenessCheckBuilder() {} + + public SandboxStaticLivenessCheckBuilder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; } @Override @@ -22,7 +28,7 @@ public SandboxLivenessCheck build() { SandboxCheckReport report = new SandboxCheckReport(recommendation, breakdown); SandboxCheckResult result = new SandboxCheckResult(report); - return new SandboxLivenessCheck(result, DocScanConstants.STATIC); + return new SandboxLivenessCheck(result, DocScanConstants.STATIC, responseDelay); } } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckBuilder.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckBuilder.java index b650f6d0..262267b9 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckBuilder.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxZoomLivenessCheckBuilder.java @@ -1,20 +1,26 @@ package com.yoti.api.client.sandbox.docs.request.check; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import com.yoti.api.client.docs.DocScanConstants; import com.yoti.api.client.sandbox.docs.request.check.report.SandboxCheckReport; public class SandboxZoomLivenessCheckBuilder extends SandboxCheck.Builder { - SandboxZoomLivenessCheckBuilder() { - } + private Integer responseDelay; + + SandboxZoomLivenessCheckBuilder() {} @Override protected SandboxZoomLivenessCheckBuilder self() { return this; } + public SandboxZoomLivenessCheckBuilder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; + } + @Override public SandboxLivenessCheck build() { notNull(recommendation, "recommendation"); @@ -22,7 +28,7 @@ public SandboxLivenessCheck build() { SandboxCheckReport report = new SandboxCheckReport(recommendation, breakdown); SandboxCheckResult result = new SandboxCheckResult(report); - return new SandboxLivenessCheck(result, DocScanConstants.ZOOM); + return new SandboxLivenessCheck(result, DocScanConstants.ZOOM, responseDelay); } } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java index 806917a5..ca31eadc 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTask.java @@ -1,6 +1,6 @@ package com.yoti.api.client.sandbox.docs.request.task; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import java.util.Base64; import java.util.HashMap; @@ -20,9 +20,13 @@ public class SandboxDocumentTextDataExtractionTask { @JsonProperty("document_filter") private final SandboxDocumentFilter documentFilter; - SandboxDocumentTextDataExtractionTask(SandboxDocumentTextDataExtractionTaskResult result, SandboxDocumentFilter documentFilter) { + @JsonProperty("response_delay") + private final Integer responseDelay; + + SandboxDocumentTextDataExtractionTask(SandboxDocumentTextDataExtractionTaskResult result, SandboxDocumentFilter documentFilter, Integer responseDelay) { this.result = result; this.documentFilter = documentFilter; + this.responseDelay = responseDelay; } public static Builder builder() { @@ -37,6 +41,10 @@ public SandboxDocumentFilter getDocumentFilter() { return documentFilter; } + public Integer getResponseDelay() { + return responseDelay; + } + /** * Builder for {@link SandboxDocumentTextDataExtractionTask} */ @@ -48,9 +56,9 @@ public static class Builder { private String detectedCountry; private String detectedDocumentType; private SandboxTextExtractionTaskRecommendation recommendation; + private Integer responseDelay; - private Builder() { - } + private Builder() {} public Builder withDocumentField(String key, Object value) { if (documentFields == null) { @@ -93,13 +101,18 @@ public Builder withRecommendation(SandboxTextExtractionTaskRecommendation recomm return this; } + public Builder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; + } + public SandboxDocumentTextDataExtractionTask build() { SandboxDocumentTextDataExtractionTaskResult result = new SandboxDocumentTextDataExtractionTaskResult(documentFields, documentIdPhoto, detectedCountry, detectedDocumentType, recommendation); - return new SandboxDocumentTextDataExtractionTask(result, documentFilter); + return new SandboxDocumentTextDataExtractionTask(result, documentFilter, responseDelay); } } } diff --git a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTask.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTask.java index 2ccba484..beb290b7 100644 --- a/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTask.java +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTask.java @@ -1,6 +1,6 @@ package com.yoti.api.client.sandbox.docs.request.task; -import static com.yoti.api.client.spi.remote.util.Validation.notNull; +import static com.yoti.validation.Validation.notNull; import java.util.HashMap; import java.util.Map; @@ -19,9 +19,15 @@ public class SandboxSupplementaryDocTextDataExtractionTask { @JsonProperty("document_filter") private final SandboxDocumentFilter documentFilter; - SandboxSupplementaryDocTextDataExtractionTask(SandboxSupplementaryDocTextDataExtractionTaskResult result, SandboxDocumentFilter documentFilter) { + @JsonProperty("response_delay") + private final Integer responseDelay; + + SandboxSupplementaryDocTextDataExtractionTask(SandboxSupplementaryDocTextDataExtractionTaskResult result, + SandboxDocumentFilter documentFilter, + Integer responseDelay) { this.result = result; this.documentFilter = documentFilter; + this.responseDelay = responseDelay; } public static Builder builder() { @@ -36,6 +42,10 @@ public SandboxDocumentFilter getDocumentFilter() { return documentFilter; } + public Integer getResponseDelay() { + return responseDelay; + } + /** * Builder for {@link SandboxSupplementaryDocTextDataExtractionTask} */ @@ -45,6 +55,7 @@ public static class Builder { private SandboxDocumentFilter documentFilter; private String detectedCountry; private SandboxTextExtractionTaskRecommendation recommendation; + private Integer responseDelay; private Builder() {} @@ -78,10 +89,15 @@ public Builder withRecommendation(SandboxTextExtractionTaskRecommendation recomm return this; } + public Builder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; + } + public SandboxSupplementaryDocTextDataExtractionTask build() { SandboxSupplementaryDocTextDataExtractionTaskResult result = new SandboxSupplementaryDocTextDataExtractionTaskResult(documentFields, detectedCountry, recommendation); - return new SandboxSupplementaryDocTextDataExtractionTask(result, documentFilter); + return new SandboxSupplementaryDocTextDataExtractionTask(result, documentFilter, responseDelay); } } -} \ No newline at end of file +} diff --git a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskTest.java b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskTest.java index adc9bb5a..d8dfc328 100644 --- a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskTest.java +++ b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentTextDataExtractionTaskTest.java @@ -96,4 +96,13 @@ public void builder_shouldAllowRecommendation() { assertThat(result.getResult().getRecommendation(), is(recommendationMock)); } + @Test + public void builder_shouldSetResponseDelay() { + SandboxDocumentTextDataExtractionTask result = SandboxDocumentTextDataExtractionTask.builder() + .withResponseDelay(10) + .build(); + + assertThat(result.getResponseDelay(), is(10)); + } + } diff --git a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskTest.java b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskTest.java index 0cb89d71..93cb6df0 100644 --- a/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskTest.java +++ b/yoti-sdk-sandbox/src/test/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTaskTest.java @@ -81,4 +81,13 @@ public void builder_shouldAllowRecommendation() { assertThat(result.getResult().getRecommendation(), is(recommendationMock)); } -} \ No newline at end of file + @Test + public void builder_shouldSetResponseDelay() { + SandboxSupplementaryDocTextDataExtractionTask result = SandboxSupplementaryDocTextDataExtractionTask.builder() + .withResponseDelay(10) + .build(); + + assertThat(result.getResponseDelay(), is(10)); + } + +} From 234f73096c519b04c5cd54d8f04530d853d8335b Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Tue, 24 Sep 2024 11:15:19 +0100 Subject: [PATCH 18/30] SDK-2478: Allow the Relying Business to retrieve tracked devices for a session --- .../yoti/api/client/docs/DocScanClient.java | 15 +++ .../yoti/api/client/docs/DocScanService.java | 29 ++++++ .../devicemetadata/DeviceResponse.java | 77 +++++++++++++++ .../devicemetadata/MetadataResponse.java | 28 ++++++ .../spi/remote/call/JsonResourceFetcher.java | 6 ++ .../client/spi/remote/call/SignedRequest.java | 6 ++ .../call/factory/UnsignedPathFactory.java | 5 + .../api/client/docs/DocScanClientTest.java | 11 +++ .../api/client/docs/DocScanServiceTest.java | 93 +++++++++++++++++++ 9 files changed, 270 insertions(+) create mode 100644 yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/DeviceResponse.java create mode 100644 yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java index fa046980..d59f1c39 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java @@ -6,6 +6,7 @@ import java.io.IOException; import java.security.KeyPair; import java.security.Security; +import java.util.List; import com.yoti.api.client.InitialisationException; import com.yoti.api.client.KeyPairSource; @@ -14,6 +15,7 @@ import com.yoti.api.client.docs.session.create.SessionSpec; import com.yoti.api.client.docs.session.create.facecapture.CreateFaceCaptureResourcePayload; import com.yoti.api.client.docs.session.create.facecapture.UploadFaceCaptureImagePayload; +import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse; import com.yoti.api.client.docs.session.instructions.Instructions; import com.yoti.api.client.docs.session.retrieve.CreateFaceCaptureResourceResponse; import com.yoti.api.client.docs.session.retrieve.GetSessionResult; @@ -242,6 +244,19 @@ public SessionConfigurationResponse getSessionConfiguration(String sessionId) th return docScanService.fetchSessionConfiguration(sdkId, keyPair, sessionId); } + /** + * Fetches the tracked devices used by the end user, to interact with the given sessionID. + * + * @param sessionId the session ID + * + * @return the session configuration + * @throws DocScanException if an error has occurred + */ + public List getTrackedDevices(String sessionId) throws DocScanException { + LOG.debug("Fetching tracked devices for session '{}'", sessionId); + return docScanService.getTrackedDevices(sdkId, keyPair, sessionId); + } + private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException { try { LOG.debug("Loading key pair from '{}'", kpSource); diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java index 4eb63331..b6d2ba18 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java @@ -24,6 +24,7 @@ import com.yoti.api.client.docs.session.create.SessionSpec; import com.yoti.api.client.docs.session.create.facecapture.CreateFaceCaptureResourcePayload; import com.yoti.api.client.docs.session.create.facecapture.UploadFaceCaptureImagePayload; +import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse; import com.yoti.api.client.docs.session.instructions.Instructions; import com.yoti.api.client.docs.session.retrieve.CreateFaceCaptureResourceResponse; import com.yoti.api.client.docs.session.retrieve.GetSessionResult; @@ -39,6 +40,7 @@ import com.yoti.api.client.spi.remote.call.factory.UnsignedPathFactory; import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.SerializationFeature; import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; @@ -52,6 +54,9 @@ final class DocScanService { private static final Logger LOG = LoggerFactory.getLogger(DocScanService.class); + + private static final TypeReference> METADATA_RESPONSE_TYPE_REF = new TypeReference>() {}; + private static final int HTTP_STATUS_NO_CONTENT = 204; private static final String YOTI_MULTIPART_BOUNDARY = "yoti-doc-scan-boundary"; @@ -527,6 +532,30 @@ public void triggerIbvEmailNotification(String sdkId, KeyPair keyPair, String se } } + public List getTrackedDevices(String sdkId, KeyPair keyPair, String sessionId) throws DocScanException { + notNullOrEmpty(sdkId, "SDK ID"); + notNull(keyPair, "Application key Pair"); + notNullOrEmpty(sessionId, "sessionId"); + + String path = unsignedPathFactory.createFetchTrackedDevices(sdkId, sessionId); + LOG.info("Fetching tracked devices at '{}'", path); + + try { + SignedRequest signedRequest = signedRequestBuilderFactory.create() + .withKeyPair(keyPair) + .withBaseUrl(apiUrl) + .withEndpoint(path) + .withHttpMethod(HTTP_GET) + .build(); + + return signedRequest.execute(METADATA_RESPONSE_TYPE_REF); + } catch (GeneralSecurityException | ResourceException ex) { + throw new DocScanException("Error executing the GET: " + ex.getMessage(), ex); + } catch (IOException | URISyntaxException ex) { + throw new DocScanException("Error building the request: " + ex.getMessage(), ex); + } + } + private String findContentType(SignedRequestResponse response) { List contentTypeValues = null; for (Map.Entry> entry : response.getResponseHeaders().entrySet()) { diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/DeviceResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/DeviceResponse.java new file mode 100644 index 00000000..66464762 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/DeviceResponse.java @@ -0,0 +1,77 @@ +package com.yoti.api.client.docs.session.devicemetadata; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class DeviceResponse { + + @JsonProperty("ip_address") + private String ipAddress; + + @JsonProperty("ip_iso_country_code") + private String ipIsoCountryCode; + + @JsonProperty("manufacture_name") + private String manufactureName; + + @JsonProperty("model_name") + private String modelName; + + @JsonProperty("os_name") + private String osName; + + @JsonProperty("os_version") + private String osVersion; + + @JsonProperty("browser_name") + private String browserName; + + @JsonProperty("browser_version") + private String browserVersion; + + @JsonProperty("locale") + private String locale; + + @JsonProperty("client_version") + private String clientVersion; + + public String getIpAddress() { + return ipAddress; + } + + public String getIpIsoCountryCode() { + return ipIsoCountryCode; + } + + public String getManufactureName() { + return manufactureName; + } + + public String getModelName() { + return modelName; + } + + public String getOsName() { + return osName; + } + + public String getOsVersion() { + return osVersion; + } + + public String getBrowserName() { + return browserName; + } + + public String getBrowserVersion() { + return browserVersion; + } + + public String getLocale() { + return locale; + } + + public String getClientVersion() { + return clientVersion; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java new file mode 100644 index 00000000..0311cc1d --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java @@ -0,0 +1,28 @@ +package com.yoti.api.client.docs.session.devicemetadata; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MetadataResponse { + + @JsonProperty("event") + private String event; + + @JsonProperty("created") + private String created; + + @JsonProperty("device") + private DeviceResponse device; + + public String getEvent() { + return event; + } + + public String getCreated() { + return created; + } + + public DeviceResponse getDevice() { + return device; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/JsonResourceFetcher.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/JsonResourceFetcher.java index 84431edb..7f842382 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/JsonResourceFetcher.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/JsonResourceFetcher.java @@ -4,6 +4,7 @@ import com.yoti.api.client.docs.session.retrieve.configuration.capture.liveness.RequiredLivenessResourceResponse; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.module.SimpleModule; @@ -40,4 +41,9 @@ public T doRequest(SignedRequest signedRequest, Class resourceClass) thro return objectMapper.readValue(signedRequestResponse.getResponseBody(), resourceClass); } + public T doRequest(SignedRequest signedRequest, TypeReference resourceClass) throws ResourceException, IOException { + SignedRequestResponse signedRequestResponse = rawResourceFetcher.doRequest(signedRequest); + return objectMapper.readValue(signedRequestResponse.getResponseBody(), resourceClass); + } + } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/SignedRequest.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/SignedRequest.java index e6130834..b971c050 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/SignedRequest.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/SignedRequest.java @@ -6,6 +6,8 @@ import com.yoti.api.client.Image; +import com.fasterxml.jackson.core.type.TypeReference; + public class SignedRequest { private final URI uri; @@ -56,6 +58,10 @@ public T execute(Class clazz) throws ResourceException, IOException { return jsonResourceFetcher.doRequest(this, clazz); } + public T execute(TypeReference typeReference) throws ResourceException, IOException { + return jsonResourceFetcher.doRequest(this, typeReference); + } + public SignedRequestResponse execute() throws ResourceException, IOException { return rawResourceFetcher.doRequest(this); } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java index a8a57f58..5d8d59e2 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java @@ -32,6 +32,7 @@ public class UnsignedPathFactory { private static final String DOCS_NEW_FACE_CAPTURE_RESOURCE = "/sessions/%s/resources/face-capture?sdkId=%s"; private static final String DOCS_UPLOAD_FACE_CAPTURE_IMAGE = "/sessions/%s/resources/face-capture/%s/image?sdkId=%s"; private static final String DOCS_TRIGGER_IBV_NOTIFICATION = "/sessions/%s/instructions/email?sdkId=%s"; + private static final String DOCS_FETCH_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s"; public String createAmlPath(String appId) { return format(AML, appId); @@ -121,4 +122,8 @@ public String createTriggerIbvEmailNotificationPath(String sdkId, String session return format(DOCS_TRIGGER_IBV_NOTIFICATION, sessionId, sdkId); } + public String createFetchTrackedDevices(String sdkId, String sessionId) { + return format(DOCS_FETCH_TRACKED_DEVICES, sessionId, sdkId); + } + } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java index e2375549..536835a6 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java @@ -186,4 +186,15 @@ public void getSupportedDocuments_shouldFailWithExceptionFromYotiDocsService() t assertThat(thrown, is(original)); } + @Test + public void getTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throws Exception { + DocScanException original = new DocScanException("Test exception"); + doThrow(original).when(docScanServiceMock).getTrackedDevices(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getTrackedDevices(SOME_SESSION_ID)); + + assertThat(thrown, is(original)); + } + } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java index ad756814..354e2720 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java @@ -11,6 +11,7 @@ import static junit.framework.TestCase.assertSame; import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.any; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; @@ -29,6 +30,7 @@ import java.net.URISyntaxException; import java.security.GeneralSecurityException; import java.security.KeyPair; +import java.util.Collections; import java.util.HashMap; import java.util.List; import java.util.Map; @@ -38,6 +40,7 @@ import com.yoti.api.client.docs.session.create.SessionSpec; import com.yoti.api.client.docs.session.create.facecapture.CreateFaceCaptureResourcePayload; import com.yoti.api.client.docs.session.create.facecapture.UploadFaceCaptureImagePayload; +import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse; import com.yoti.api.client.docs.session.instructions.Instructions; import com.yoti.api.client.docs.session.retrieve.AuthenticityCheckResponse; import com.yoti.api.client.docs.session.retrieve.CheckResponse; @@ -57,12 +60,14 @@ import com.yoti.api.client.spi.remote.call.SignedRequestResponse; import com.yoti.api.client.spi.remote.call.factory.UnsignedPathFactory; +import com.fasterxml.jackson.core.type.TypeReference; import com.fasterxml.jackson.databind.ObjectMapper; import org.junit.Before; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Answers; +import org.mockito.ArgumentMatchers; import org.mockito.InjectMocks; import org.mockito.Mock; import org.mockito.Spy; @@ -1445,4 +1450,92 @@ public void getSupportedDocuments_shouldReturnSupportedDocuments() throws Except assertThat(result, is(instanceOf(SupportedDocumentsResponse.class))); } + @Test + public void getTrackedDevices_shouldThrowExceptionWhenSdkIdIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getTrackedDevices(null, KEY_PAIR, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("SDK ID")); + } + + @Test + public void getTrackedDevices_shouldThrowExceptionWhenSdkIdIsEmpty() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getTrackedDevices("", KEY_PAIR, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("SDK ID")); + } + + @Test + public void getTrackedDevices_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, null, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("Application key Pair")); + } + + @Test + public void getTrackedDevices_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, null)); + assertThat(exception.getMessage(), containsString("sessionId")); + } + + @Test + public void getTrackedDevices_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, "")); + assertThat(exception.getMessage(), containsString("sessionId")); + } + + @Test + public void getTrackedDevices_shouldWrapGeneralSecurityException() throws Exception { + GeneralSecurityException gse = new GeneralSecurityException("some gse"); + when(signedRequestBuilderMock.build()).thenThrow(gse); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error executing the GET: some gse")); + } + + @Test + public void getTrackedDevices_shouldWrapResourceException() throws Exception { + ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); + when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); + when(signedRequestMock.execute(ArgumentMatchers.any(TypeReference.class))).thenThrow(resourceException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); + } + + @Test + public void getTrackedDevices_shouldWrapIOException() throws Exception { + IOException ioException = new IOException("Some io exception"); + when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); + when(signedRequestMock.execute(ArgumentMatchers.any(TypeReference.class))).thenThrow(ioException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); + } + + @Test + public void getTrackedDevices_shouldWrapURISyntaxException() throws Exception { + URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); + when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + } + + @Test + public void getTrackedDevices_shouldReturnTrackedDevices() throws Exception { + when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); + MetadataResponse metadataResponseMock = mock(MetadataResponse.class); + when(signedRequestMock.execute(ArgumentMatchers.any(TypeReference.class))).thenReturn(Collections.singletonList(metadataResponseMock)); + when(unsignedPathFactoryMock.createFetchTrackedDevices(SOME_APP_ID, SOME_SESSION_ID)).thenReturn(SOME_PATH); + + List result = docScanService.getTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID); + + assertThat(result.get(0), is(metadataResponseMock)); + } + } From 7f531f220a07011cb3ac854550621a893c51ba51 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Tue, 24 Sep 2024 11:21:03 +0100 Subject: [PATCH 19/30] SDK-2478: Allow the Relying Business to delete tracked device metadata for a given session --- .../yoti/api/client/docs/DocScanClient.java | 16 +++- .../yoti/api/client/docs/DocScanService.java | 23 ++++++ .../devicemetadata/MetadataResponse.java | 7 ++ .../call/factory/UnsignedPathFactory.java | 8 +- .../api/client/docs/DocScanClientTest.java | 11 +++ .../api/client/docs/DocScanServiceTest.java | 76 +++++++++++++++++++ 6 files changed, 137 insertions(+), 4 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java index d59f1c39..4faf0d89 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanClient.java @@ -245,11 +245,11 @@ public SessionConfigurationResponse getSessionConfiguration(String sessionId) th } /** - * Fetches the tracked devices used by the end user, to interact with the given sessionID. + * Fetches details of the devices tracked at key points in completing the session. * * @param sessionId the session ID * - * @return the session configuration + * @return the list of tracked devices information * @throws DocScanException if an error has occurred */ public List getTrackedDevices(String sessionId) throws DocScanException { @@ -257,6 +257,18 @@ public List getTrackedDevices(String sessionId) throws DocScan return docScanService.getTrackedDevices(sdkId, keyPair, sessionId); } + /** + * Deletes the tracked devices metadata for the given sessionID. + * + * @param sessionId the session ID + * + * @throws DocScanException if an error has occurred + */ + public void deleteTrackedDevices(String sessionId) throws DocScanException { + LOG.debug("Deleting tracked devices for session '{}'", sessionId); + docScanService.deleteTrackedDevices(sdkId, keyPair, sessionId); + } + private KeyPair loadKeyPair(KeyPairSource kpSource) throws InitialisationException { try { LOG.debug("Loading key pair from '{}'", kpSource); diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java index b6d2ba18..e586b6b8 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java @@ -556,6 +556,29 @@ public List getTrackedDevices(String sdkId, KeyPair keyPair, S } } + public void deleteTrackedDevices(String sdkId, KeyPair keyPair, String sessionId) throws DocScanException { + notNullOrEmpty(sdkId, "SDK ID"); + notNull(keyPair, "Application key Pair"); + notNullOrEmpty(sessionId, "sessionId"); + + String path = unsignedPathFactory.createDeleteTrackedDevices(sdkId, sessionId); + LOG.info("Deleting tracked devices at '{}'", path); + + try { + signedRequestBuilderFactory.create() + .withKeyPair(keyPair) + .withBaseUrl(apiUrl) + .withEndpoint(path) + .withHttpMethod(HTTP_DELETE) + .build() + .execute(); + } catch (GeneralSecurityException | ResourceException ex) { + throw new DocScanException("Error executing the GET: " + ex.getMessage(), ex); + } catch (IOException | URISyntaxException ex) { + throw new DocScanException("Error building the request: " + ex.getMessage(), ex); + } + } + private String findContentType(SignedRequestResponse response) { List contentTypeValues = null; for (Map.Entry> entry : response.getResponseHeaders().entrySet()) { diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java index 0311cc1d..73a975d1 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java @@ -7,6 +7,9 @@ public class MetadataResponse { @JsonProperty("event") private String event; + @JsonProperty("resource_id") + private String resourceId; + @JsonProperty("created") private String created; @@ -17,6 +20,10 @@ public String getEvent() { return event; } + public String getResourceId() { + return resourceId; + } + public String getCreated() { return created; } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java index 5d8d59e2..6b322cdf 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/factory/UnsignedPathFactory.java @@ -32,7 +32,7 @@ public class UnsignedPathFactory { private static final String DOCS_NEW_FACE_CAPTURE_RESOURCE = "/sessions/%s/resources/face-capture?sdkId=%s"; private static final String DOCS_UPLOAD_FACE_CAPTURE_IMAGE = "/sessions/%s/resources/face-capture/%s/image?sdkId=%s"; private static final String DOCS_TRIGGER_IBV_NOTIFICATION = "/sessions/%s/instructions/email?sdkId=%s"; - private static final String DOCS_FETCH_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s"; + private static final String DOCS_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s"; public String createAmlPath(String appId) { return format(AML, appId); @@ -123,7 +123,11 @@ public String createTriggerIbvEmailNotificationPath(String sdkId, String session } public String createFetchTrackedDevices(String sdkId, String sessionId) { - return format(DOCS_FETCH_TRACKED_DEVICES, sessionId, sdkId); + return format(DOCS_TRACKED_DEVICES, sessionId, sdkId); + } + + public String createDeleteTrackedDevices(String sdkId, String sessionId) { + return format(DOCS_TRACKED_DEVICES, sessionId, sdkId); } } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java index 536835a6..265275b1 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientTest.java @@ -197,4 +197,15 @@ public void getTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throw assertThat(thrown, is(original)); } + @Test + public void deleteTrackedDevices_shouldFailWithExceptionFromYotiDocsService() throws Exception { + DocScanException original = new DocScanException("Test exception"); + doThrow(original).when(docScanServiceMock).deleteTrackedDevices(eq(APP_ID), any(KeyPair.class), eq(SOME_SESSION_ID)); + DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); + + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.deleteTrackedDevices(SOME_SESSION_ID)); + + assertThat(thrown, is(original)); + } + } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java index 354e2720..a945140f 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanServiceTest.java @@ -1538,4 +1538,80 @@ public void getTrackedDevices_shouldReturnTrackedDevices() throws Exception { assertThat(result.get(0), is(metadataResponseMock)); } + @Test + public void deleteTrackedDevices_shouldThrowExceptionWhenSdkIdIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(null, KEY_PAIR, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("SDK ID")); + } + + @Test + public void deleteTrackedDevices_shouldThrowExceptionWhenSdkIdIsEmpty() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices("", KEY_PAIR, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("SDK ID")); + } + + @Test + public void deleteTrackedDevices_shouldThrowExceptionWhenKeyPairIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, null, SOME_SESSION_ID)); + assertThat(exception.getMessage(), containsString("Application key Pair")); + } + + @Test + public void deleteTrackedDevices_shouldThrowExceptionWhenSessionIdIsNull() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, null)); + assertThat(exception.getMessage(), containsString("sessionId")); + } + + @Test + public void deleteTrackedDevices_shouldThrowExceptionWhenSessionIdIsEmpty() { + IllegalArgumentException exception = assertThrows(IllegalArgumentException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, "")); + assertThat(exception.getMessage(), containsString("sessionId")); + } + + @Test + public void deleteTrackedDevices_shouldWrapGeneralSecurityException() throws Exception { + GeneralSecurityException gse = new GeneralSecurityException("some gse"); + when(signedRequestBuilderMock.build()).thenThrow(gse); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), gse); + assertThat(ex.getMessage(), containsString("Error executing the GET: some gse")); + } + + @Test + public void deleteTrackedDevices_shouldWrapResourceException() throws Exception { + ResourceException resourceException = new ResourceException(400, "Failed Request", "Some response from API"); + when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); + when(signedRequestMock.execute()).thenThrow(resourceException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), resourceException); + assertThat(ex.getMessage(), containsString("Error executing the GET: Failed Request")); + } + + @Test + public void deleteTrackedDevices_shouldWrapIOException() throws Exception { + IOException ioException = new IOException("Some io exception"); + when(signedRequestBuilderMock.build()).thenReturn(signedRequestMock); + when(signedRequestMock.execute()).thenThrow(ioException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), ioException); + assertThat(ex.getMessage(), containsString("Error building the request: Some io exception")); + } + + @Test + public void deleteTrackedDevices_shouldWrapURISyntaxException() throws Exception { + URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); + when(signedRequestBuilderMock.build()).thenThrow(uriSyntaxException); + + DocScanException ex = assertThrows(DocScanException.class, () -> docScanService.deleteTrackedDevices(SOME_APP_ID, KEY_PAIR, SOME_SESSION_ID)); + + assertSame(ex.getCause(), uriSyntaxException); + assertThat(ex.getMessage(), containsString("Error building the request: Failed to build URI: someUrl")); + } + } From 6279ca6f63bec10cf8a55caa9164ac54f7b50af2 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 13:56:39 +0100 Subject: [PATCH 20/30] 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 8c2a1bc7da0bfd18ad62a1b7adf6a400c18818a1 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:01:00 +0100 Subject: [PATCH 21/30] 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 9cd130e5346cbd00cac0356d2213391dd840fcc5 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:05:18 +0100 Subject: [PATCH 22/30] 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 9bd58a734e044e43868284b192be877e9c4219fd Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:10:53 +0100 Subject: [PATCH 23/30] 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 a7b674dc3c95a961da84e6a547d74000d0f3fada Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 14:12:36 +0100 Subject: [PATCH 24/30] 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 fad292c9c978c6f6517c95c6d17940c4bf7f5305 Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 15:57:53 +0100 Subject: [PATCH 25/30] 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 5123a0b4ff763fa2e67d47ee7ab695f4fb70157d Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Tue, 24 Sep 2024 11:01:42 +0100 Subject: [PATCH 26/30] 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)); + } + } From 1c07134b22f9d765292f9286eccb0404c2c43d3e Mon Sep 17 00:00:00 2001 From: Michael Buck Date: Wed, 25 Sep 2024 14:28:03 +0100 Subject: [PATCH 27/30] SDK-2309: [MB] The biometric_consent_flow is EARLY not EAGER --- .../com/yoti/api/client/docs/DocScanConstants.java | 2 +- .../api/client/docs/session/create/SdkConfig.java | 14 +++++++------- .../client/docs/session/create/SdkConfigTest.java | 6 +++--- 3 files changed, 11 insertions(+), 11 deletions(-) diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java index 1bf0e5fc..9ae74306 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java @@ -87,7 +87,7 @@ private DocScanConstants() { } public static final String GBP = "GBP"; - public static final String EAGER = "EAGER"; + public static final String EARLY = "EARLY"; public static final String JUST_IN_TIME = "JUST_IN_TIME"; public static final String ON = "ON"; diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java index d7ad1541..776b9d51 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SdkConfig.java @@ -426,7 +426,7 @@ public Builder withAllowHandoff(boolean allowHandoff) { } /** - * Sets the {@link AttemptsConfiguration} for the session + * Sets the {@link AttemptsConfiguration} for any Text Extractions Tasks * * @param attemptsConfiguration the configuration for retries * @return the builder @@ -437,7 +437,7 @@ public Builder withAttemptsConfiguration(AttemptsConfiguration attemptsConfigura } /** - * Sets the brand ID to be used for the session + * Sets the brand ID used for customising the UI * * @param brandId the brand ID * @return the builder @@ -448,7 +448,7 @@ public Builder withBrandId(String brandId) { } /** - * Sets the Biometric Consent Flow for the session + * Sets the Biometric Consent Flow to be applied in the UI * * @param biometricConsentFlow the biometric consent flow * @return the builder @@ -459,16 +459,16 @@ public Builder withBiometricConsentFlow(String biometricConsentFlow) { } /** - * Sets the biometric consent flow to EAGER for the session + * Sets the biometric consent flow to EARLY * * @return the builder */ - public Builder withBiometricConsentFlowEager() { - return withBiometricConsentFlow(DocScanConstants.EAGER); + public Builder withBiometricConsentFlowEarly() { + return withBiometricConsentFlow(DocScanConstants.EARLY); } /** - * Sets the biometric consent flow to JUST_IN_TIME for the session + * Sets the biometric consent flow to JUST_IN_TIME * * @return the builder */ diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java index 24dba45d..94500ad4 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/create/SdkConfigTest.java @@ -91,12 +91,12 @@ public void shouldBuildSimpleSdkConfigWithCameraAndUpload() { } @Test - public void shouldBuildSimpleSdkConfigWithBiometricConsentFlowEager() { + public void shouldBuildSimpleSdkConfigWithBiometricConsentFlowEarly() { SdkConfig result = SdkConfig.builder() - .withBiometricConsentFlowEager() + .withBiometricConsentFlowEarly() .build(); - assertThat(result.getBiometricConsentFlow(), is("EAGER")); + assertThat(result.getBiometricConsentFlow(), is("EARLY")); } @Test From 703d50100ab7e27c15df6877d63bdbe677c44552 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Thu, 26 Sep 2024 15:56:43 +0100 Subject: [PATCH 28/30] Release 3.10.0: Update example project to show new properties --- .../demo/controller/DocScanController.java | 18 +++++++- .../docscan/demo/service/DocScanService.java | 6 +++ .../src/main/resources/templates/success.html | 45 +++++++++++++++++++ 3 files changed, 67 insertions(+), 2 deletions(-) diff --git a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java index 0f7096dc..adc512f5 100644 --- a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java +++ b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java @@ -1,11 +1,14 @@ package com.yoti.docscan.demo.controller; +import java.util.List; + import javax.servlet.http.HttpSession; import com.yoti.api.client.Media; import com.yoti.api.client.docs.DocScanClient; import com.yoti.api.client.docs.DocScanException; import com.yoti.api.client.docs.session.create.CreateSessionResult; +import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse; import com.yoti.api.client.docs.session.retrieve.GetSessionResult; import com.yoti.docscan.demo.service.DocScanService; @@ -23,6 +26,7 @@ import org.springframework.web.bind.annotation.RequestMapping; import org.springframework.web.bind.annotation.RequestMethod; import org.springframework.web.bind.annotation.RequestParam; +import org.springframework.web.bind.annotation.ResponseBody; import org.springframework.web.servlet.config.annotation.EnableWebMvc; import org.springframework.web.servlet.config.annotation.ResourceHandlerRegistry; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; @@ -68,8 +72,13 @@ public String getIndex(final Model model, HttpSession httpSession) { } @RequestMapping(value = "/success", method = RequestMethod.GET) - public String getUserSession(final Model model, HttpSession httpSession) { - String sessionId = (String) httpSession.getAttribute(DOC_SCAN_SESSION_ID); + public String getUserSession(@RequestParam(value = "sessionId") String sessionIdQueryParam, final Model model, HttpSession httpSession) { + String sessionId; + if (sessionIdQueryParam != null) { + sessionId = sessionIdQueryParam; + } else { + sessionId = (String) httpSession.getAttribute(DOC_SCAN_SESSION_ID); + } if (sessionId == null || sessionId.equals("")) { return "redirect:/"; @@ -117,6 +126,11 @@ public ResponseEntity getMedia( return new ResponseEntity<>(media.getContent(), headers, HttpStatus.OK); } + @RequestMapping(value = "/tracked-devices", method = RequestMethod.GET) + public @ResponseBody List getTrackedDevices(@RequestParam(value = "sessionId") String sessionId) throws DocScanException { + return docScanService.getTrackedDevices(sessionId); + } + @RequestMapping(value = "/privacy-policy", method = RequestMethod.GET) public String showPrivacyPolicyPage() { return "privacy"; diff --git a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/service/DocScanService.java b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/service/DocScanService.java index 4538f907..233f0218 100644 --- a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/service/DocScanService.java +++ b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/service/DocScanService.java @@ -1,6 +1,7 @@ package com.yoti.docscan.demo.service; import java.util.Arrays; +import java.util.List; import com.yoti.api.client.Media; import com.yoti.api.client.docs.DocScanClient; @@ -22,6 +23,7 @@ import com.yoti.api.client.docs.session.create.objective.ProofOfAddressObjective; import com.yoti.api.client.docs.session.create.task.RequestedIdDocTextExtractionTask; import com.yoti.api.client.docs.session.create.task.RequestedSupplementaryDocTextExtractionTask; +import com.yoti.api.client.docs.session.devicemetadata.MetadataResponse; import com.yoti.api.client.docs.session.retrieve.GetSessionResult; import com.yoti.api.client.spi.remote.call.YotiConstants; @@ -148,4 +150,8 @@ public String getIframeUrl(CreateSessionResult createSessionResult) { public Media getMedia(String sessionId, String mediaId) throws DocScanException { return docScanClient.getMediaContent(sessionId, mediaId); } + + public List getTrackedDevices(String sessionId) throws DocScanException { + return docScanClient.getTrackedDevices(sessionId); + } } diff --git a/examples/doc-scan/src/main/resources/templates/success.html b/examples/doc-scan/src/main/resources/templates/success.html index 1eab041d..1d85831f 100644 --- a/examples/doc-scan/src/main/resources/templates/success.html +++ b/examples/doc-scan/src/main/resources/templates/success.html @@ -446,6 +446,40 @@
Media
+ +
+
+

+ +

+
+
+
+ +
Media
+ + + + + + + +
ID + + +
+
+
+
+
+
@@ -1010,6 +1044,17 @@

+
+
+

+ Tracked Devices + + + + +

+
+

From 1888d34b91bce6580c5a93246190704c346ba6f3 Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Tue, 22 Oct 2024 11:01:03 +0100 Subject: [PATCH 29/30] RELEASE-3.10.0: Make sessionId request parameter optional in IDV demo project --- .../com/yoti/docscan/demo/controller/DocScanController.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java index adc512f5..1a2d73af 100644 --- a/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java +++ b/examples/doc-scan/src/main/java/com/yoti/docscan/demo/controller/DocScanController.java @@ -72,7 +72,7 @@ public String getIndex(final Model model, HttpSession httpSession) { } @RequestMapping(value = "/success", method = RequestMethod.GET) - public String getUserSession(@RequestParam(value = "sessionId") String sessionIdQueryParam, final Model model, HttpSession httpSession) { + public String getUserSession(@RequestParam(value = "sessionId", required = false) String sessionIdQueryParam, final Model model, HttpSession httpSession) { String sessionId; if (sessionIdQueryParam != null) { sessionId = sessionIdQueryParam; From 8b2ca6b789f12a646600383359dc7fb17509ed4c Mon Sep 17 00:00:00 2001 From: Alex Burt Date: Mon, 9 Dec 2024 10:17:28 +0000 Subject: [PATCH 30/30] Release 3.10.0: Set version for release --- README.md | 4 ++-- examples/doc-scan/pom.xml | 2 +- pom.xml | 2 +- yoti-sdk-api/pom.xml | 2 +- .../com/yoti/api/client/spi/remote/call/YotiConstants.java | 2 +- yoti-sdk-parent/pom.xml | 2 +- yoti-sdk-sandbox/pom.xml | 2 +- yoti-sdk-spring-boot-auto-config/README.md | 4 ++-- yoti-sdk-spring-boot-auto-config/pom.xml | 2 +- yoti-sdk-spring-boot-example/README.md | 2 +- yoti-sdk-spring-boot-example/pom.xml | 2 +- yoti-sdk-spring-security/README.md | 4 ++-- yoti-sdk-spring-security/pom.xml | 2 +- 13 files changed, 16 insertions(+), 16 deletions(-) diff --git a/README.md b/README.md index af8208aa..b9bc0942 100644 --- a/README.md +++ b/README.md @@ -101,13 +101,13 @@ If you are using Maven, you need to add the following dependency: com.yoti yoti-sdk-api - 3.10.0-SNAPSHOT + 3.10.0 ``` If you are using Gradle, here is the dependency to add: -`compile group: 'com.yoti', name: 'yoti-sdk-api', version: '3.10.0-SNAPSHOT'` +`compile group: 'com.yoti', name: 'yoti-sdk-api', version: '3.10.0'` You will find all classes packaged under `com.yoti.api` diff --git a/examples/doc-scan/pom.xml b/examples/doc-scan/pom.xml index 3b9d50d9..26217080 100644 --- a/examples/doc-scan/pom.xml +++ b/examples/doc-scan/pom.xml @@ -53,7 +53,7 @@ com.yoti yoti-sdk-api - 3.10.0-SNAPSHOT + 3.10.0 diff --git a/pom.xml b/pom.xml index dbdad87d..3e74e85b 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk pom - 3.10.0-SNAPSHOT + 3.10.0 Yoti SDK Java SDK for simple integration with the Yoti platform https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-api/pom.xml b/yoti-sdk-api/pom.xml index 6e69ea00..2059153e 100644 --- a/yoti-sdk-api/pom.xml +++ b/yoti-sdk-api/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 3.10.0-SNAPSHOT + 3.10.0 ../yoti-sdk-parent diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java index 19167112..957c7c7c 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java @@ -29,7 +29,7 @@ private YotiConstants() {} public static final String CONTENT_TYPE_JPEG = "image/jpeg"; public static final String JAVA = "Java"; - public static final String SDK_VERSION = JAVA + "-3.10.0-SNAPSHOT"; + public static final String SDK_VERSION = JAVA + "-3.10.0"; public static final String SIGNATURE_ALGORITHM = "SHA256withRSA"; public static final String ASYMMETRIC_CIPHER = "RSA/NONE/PKCS1Padding"; public static final String SYMMETRIC_CIPHER = "AES/CBC/PKCS7Padding"; diff --git a/yoti-sdk-parent/pom.xml b/yoti-sdk-parent/pom.xml index 6964c01e..a5e2dcb8 100644 --- a/yoti-sdk-parent/pom.xml +++ b/yoti-sdk-parent/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk-parent pom - 3.10.0-SNAPSHOT + 3.10.0 Yoti SDK Parent Pom Parent pom for the Java SDK projects https://github.com/getyoti/yoti-java-sdk diff --git a/yoti-sdk-sandbox/pom.xml b/yoti-sdk-sandbox/pom.xml index 46d90c9e..bf711fe9 100644 --- a/yoti-sdk-sandbox/pom.xml +++ b/yoti-sdk-sandbox/pom.xml @@ -11,7 +11,7 @@ com.yoti yoti-sdk-parent - 3.10.0-SNAPSHOT + 3.10.0 ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-auto-config/README.md b/yoti-sdk-spring-boot-auto-config/README.md index e5a9ea6f..320b698e 100644 --- a/yoti-sdk-spring-boot-auto-config/README.md +++ b/yoti-sdk-spring-boot-auto-config/README.md @@ -18,7 +18,7 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-boot-auto-config - 3.10.0-SNAPSHOT + 3.10.0 ``` @@ -26,7 +26,7 @@ If you are using Maven, you need to add the following dependencies: If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '3.10.0-SNAPSHOT' +compile group: 'com.yoti', name: 'yoti-sdk-spring-boot-auto-config', version: '3.10.0' ``` diff --git a/yoti-sdk-spring-boot-auto-config/pom.xml b/yoti-sdk-spring-boot-auto-config/pom.xml index 29e22ff8..f6ae6df4 100644 --- a/yoti-sdk-spring-boot-auto-config/pom.xml +++ b/yoti-sdk-spring-boot-auto-config/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 3.10.0-SNAPSHOT + 3.10.0 ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-example/README.md b/yoti-sdk-spring-boot-example/README.md index fe99f823..d28bcfb1 100644 --- a/yoti-sdk-spring-boot-example/README.md +++ b/yoti-sdk-spring-boot-example/README.md @@ -17,7 +17,7 @@ Note that: com.yoti yoti-sdk-api - 3.10.0-SNAPSHOT + 3.10.0 ``` diff --git a/yoti-sdk-spring-boot-example/pom.xml b/yoti-sdk-spring-boot-example/pom.xml index d55427eb..4ffc1d6e 100644 --- a/yoti-sdk-spring-boot-example/pom.xml +++ b/yoti-sdk-spring-boot-example/pom.xml @@ -6,7 +6,7 @@ com.yoti yoti-sdk-spring-boot-example Yoti Spring Boot Example - 3.10.0-SNAPSHOT + 3.10.0 org.springframework.boot diff --git a/yoti-sdk-spring-security/README.md b/yoti-sdk-spring-security/README.md index 41267adb..ae6ed223 100644 --- a/yoti-sdk-spring-security/README.md +++ b/yoti-sdk-spring-security/README.md @@ -25,14 +25,14 @@ If you are using Maven, you need to add the following dependencies: com.yoti yoti-sdk-spring-security - 3.10.0-SNAPSHOT + 3.10.0 ``` If you are using Gradle, here is the dependency to add: ``` -compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '3.10.0-SNAPSHOT' +compile group: 'com.yoti', name: 'yoti-sdk-spring-security', version: '3.10.0' ``` ### Provide a `YotiClient` instance diff --git a/yoti-sdk-spring-security/pom.xml b/yoti-sdk-spring-security/pom.xml index 3dd5979e..c03e6436 100644 --- a/yoti-sdk-spring-security/pom.xml +++ b/yoti-sdk-spring-security/pom.xml @@ -12,7 +12,7 @@ com.yoti yoti-sdk-parent - 3.10.0-SNAPSHOT + 3.10.0 ../yoti-sdk-parent