diff --git a/README.md b/README.md index 183657f40..a30beba81 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 + 4.0.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: '4.0.0-SNAPSHOT'` You will find all classes packaged under `com.yoti.api` @@ -294,6 +294,10 @@ Instructions on how to run the Spring example projects can be found at the follo This major update does not have any major updates to the API, but instead builds upon and standardizes our implementation. +## Breaking changes and enhancements made in v4.0.0 + +- Creating an Identity Profile session now uses strongly typed classes, instead of a Map + ### Dropped support for Java 7 Minimum supported Java version is now 8. diff --git a/examples/doc-scan/pom.xml b/examples/doc-scan/pom.xml index 9cefeb59d..468e0e43a 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 + 4.0.0-SNAPSHOT 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 0f7096dcc..adc512f58 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 4538f9075..233f02180 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 1eab041d2..2ddeb6f4a 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 + + + + + + Expanded Document Fields + + + + + + + Media + + + + ID + + + + + + + + + + + + @@ -931,6 +965,14 @@ Identity Profile + + + Generated Profile Media: + + + + @@ -1010,6 +1052,17 @@ + + + + Tracked Devices + + + + + + + diff --git a/pom.xml b/pom.xml index 7a6a69ded..558915983 100644 --- a/pom.xml +++ b/pom.xml @@ -5,7 +5,7 @@ com.yoti yoti-sdk pom - 3.9.0 + 4.0.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 f38e0752e..3909c6adf 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 + 4.0.0-SNAPSHOT ../yoti-sdk-parent 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 fa0469807..4faf0d89e 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,31 @@ public SessionConfigurationResponse getSessionConfiguration(String sessionId) th return docScanService.fetchSessionConfiguration(sdkId, keyPair, sessionId); } + /** + * Fetches details of the devices tracked at key points in completing the session. + * + * @param sessionId the session ID + * + * @return the list of tracked devices information + * @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); + } + + /** + * 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/DocScanConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanConstants.java index 8a4a729ea..9ae74306d 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"; @@ -83,4 +87,11 @@ private DocScanConstants() { } public static final String GBP = "GBP"; + public static final String EARLY = "EARLY"; + 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/DocScanService.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/DocScanService.java index 4eb63331a..e586b6b8c 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,53 @@ 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); + } + } + + 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/create/IbvOptions.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/IbvOptions.java index 669697fda..3551278ec 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/IbvOptions.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/IbvOptions.java @@ -6,13 +6,13 @@ public class IbvOptions { - @JsonProperty(Property.SUPPORT) + @JsonProperty("support") private final String support; - @JsonProperty(Property.GUIDANCE_URL) + @JsonProperty("guidance_url") private final String guidanceUrl; - @JsonProperty(Property.USER_PRICE) + @JsonProperty("user_price") private final UserPrice userPrice; private IbvOptions(String support, String guidanceUrl, UserPrice userPrice) { @@ -102,14 +102,4 @@ public IbvOptions build() { } - private static final class Property { - - private static final String SUPPORT = "support"; - private static final String GUIDANCE_URL = "guidance_url"; - private static final String USER_PRICE = "user_price"; - - private Property() { } - - } - } 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 9e6ede238..51871ea46 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/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 63fedf3a8..972f94fce 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 @@ -9,61 +9,81 @@ */ public class SdkConfig { - @JsonProperty(Property.ALLOWED_CAPTURE_METHODS) + @JsonProperty("allowed_capture_methods") private final String allowedCaptureMethods; - @JsonProperty(Property.PRIMARY_COLOUR) + @JsonProperty("primary_colour") private final String primaryColour; - @JsonProperty(Property.SECONDARY_COLOUR) + @JsonProperty("primary_colour_dark_mode") + private final String primaryColourDarkMode; + + @JsonProperty("secondary_colour") private final String secondaryColour; - @JsonProperty(Property.FONT_COLOUR) + @JsonProperty("font_colour") private final String fontColour; - @JsonProperty(Property.LOCALE) + @JsonProperty("dark_mode") + private final String darkMode; + + @JsonProperty("locale") private final String locale; - @JsonProperty(Property.PRESET_ISSUING_COUNTRY) + @JsonProperty("preset_issuing_country") private final String presetIssuingCountry; - @JsonProperty(Property.SUCCESS_URL) + @JsonProperty("success_url") private final String successUrl; - @JsonProperty(Property.ERROR_URL) + @JsonProperty("error_url") private final String errorUrl; - @JsonProperty(Property.PRIVACY_POLICY_URL) + @JsonProperty("privacy_policy_url") private final String privacyPolicyUrl; - @JsonProperty(Property.ALLOW_HANDOFF) + @JsonProperty("allow_handoff") private final Boolean allowHandoff; - @JsonProperty(Property.ATTEMPTS_CONFIGURATION) + @JsonProperty("attempts_configuration") private final AttemptsConfiguration attemptsConfiguration; + @JsonProperty("brand_id") + private final String brandId; + + @JsonProperty("biometric_consent_flow") + private final String biometricConsentFlow; + SdkConfig(String allowedCaptureMethods, String primaryColour, + String primaryColourDarkMode, String secondaryColour, String fontColour, String locale, + String darkMode, String presetIssuingCountry, String successUrl, String errorUrl, String privacyPolicyUrl, Boolean allowHandoff, - AttemptsConfiguration attemptsConfiguration) { + AttemptsConfiguration attemptsConfiguration, + String brandId, + String biometricConsentFlow) { this.allowedCaptureMethods = allowedCaptureMethods; this.primaryColour = primaryColour; + this.primaryColourDarkMode = primaryColourDarkMode; this.secondaryColour = secondaryColour; this.fontColour = fontColour; this.locale = locale; + this.darkMode = darkMode; this.presetIssuingCountry = presetIssuingCountry; this.successUrl = successUrl; this.errorUrl = errorUrl; this.privacyPolicyUrl = privacyPolicyUrl; this.allowHandoff = allowHandoff; this.attemptsConfiguration = attemptsConfiguration; + this.brandId = brandId; + this.biometricConsentFlow = biometricConsentFlow; } public static SdkConfig.Builder builder() { @@ -88,6 +108,15 @@ public String getPrimaryColour() { return primaryColour; } + /** + * The primary colour to use when in dark mode + * + * @return the primary colour + */ + public String getPrimaryColourDarkMode() { + return primaryColourDarkMode; + } + /** * The secondary colour * @@ -115,6 +144,15 @@ public String getLocale() { return locale; } + /** + * Whether to use dark mode - may be 'ON', 'OFF', or 'AUTO' + * + * @return the dark mode + */ + public String getDarkMode() { + return darkMode; + } + /** * The preset issuing country * @@ -169,6 +207,24 @@ public AttemptsConfiguration getAttemptsConfiguration() { return attemptsConfiguration; } + /** + * The Brand ID to use for the session + * + * @return the configured brand ID + */ + 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}. */ @@ -176,15 +232,19 @@ public static class Builder { private String allowedCaptureMethods; private String primaryColour; + private String primaryColourDarkMode; private String secondaryColour; private String fontColour; private String locale; + private String darkMode; private String presetIssuingCountry; private String successUrl; private String errorUrl; private String privacyPolicyUrl; private Boolean allowHandoff; private AttemptsConfiguration attemptsConfiguration; + private String brandId; + private String biometricConsentFlow; private Builder() {} @@ -228,6 +288,17 @@ public Builder withPrimaryColour(String primaryColour) { return this; } + /** + * 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 + */ + 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) * @@ -261,6 +332,44 @@ public Builder withLocale(String locale) { return this; } + /** + * 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 + */ + 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() { + return withDarkMode(DocScanConstants.ON); + } + + /** + * Sets the dark mode to 'OFF' to be used by the web/native client + * + * @return the builder + */ + public Builder withDarkModeOff() { + return withDarkMode(DocScanConstants.OFF); + } + + /** + * Sets the dark mode to 'AUTO' to be used by the web/native client + * + * @return the builder + */ + public Builder withDarkModeAuto() { + return withDarkMode(DocScanConstants.AUTO); + } + /** * Sets the preset issuing country used by the web/native client * @@ -317,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 @@ -327,6 +436,46 @@ public Builder withAttemptsConfiguration(AttemptsConfiguration attemptsConfigura return this; } + /** + * Sets the brand ID used for customising the UI + * + * @param brandId the brand ID + * @return the builder + */ + public Builder withBrandId(String brandId) { + this.brandId = brandId; + return this; + } + + /** + * Sets the Biometric Consent Flow to be applied in the UI + * + * @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 EARLY + * + * @return the builder + */ + public Builder withBiometricConsentFlowEarly() { + return withBiometricConsentFlow(DocScanConstants.EARLY); + } + + /** + * Sets the biometric consent flow to JUST_IN_TIME + * + * @return the builder + */ + public Builder withBiometricConsentFlowJustInTime() { + return withBiometricConsentFlow(DocScanConstants.JUST_IN_TIME); + } + /** * Builds the {@link SdkConfig} using the values supplied to the builder * @@ -336,35 +485,21 @@ public SdkConfig build() { return new SdkConfig( allowedCaptureMethods, primaryColour, + primaryColourDarkMode, secondaryColour, fontColour, locale, + darkMode, presetIssuingCountry, successUrl, errorUrl, privacyPolicyUrl, allowHandoff, - attemptsConfiguration + attemptsConfiguration, + brandId, + biometricConsentFlow ); } } - 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 SECONDARY_COLOUR = "secondary_colour"; - private static final String FONT_COLOUR = "font_colour"; - private static final String LOCALE = "locale"; - private static final String PRESET_ISSUING_COUNTRY = "preset_issuing_country"; - private static final String SUCCESS_URL = "success_url"; - private static final String ERROR_URL = "error_url"; - 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 Property() {} - - } - } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SessionSpec.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SessionSpec.java index b7a0a763a..834bbbb15 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SessionSpec.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SessionSpec.java @@ -3,11 +3,11 @@ import java.time.ZonedDateTime; import java.util.ArrayList; import java.util.List; -import java.util.Map; import com.yoti.api.client.docs.session.create.check.RequestedCheck; import com.yoti.api.client.docs.session.create.filters.RequiredDocument; import com.yoti.api.client.docs.session.create.identityprofile.advanced.AdvancedIdentityProfileRequirementsPayload; +import com.yoti.api.client.docs.session.create.identityprofile.simple.IdentityProfileRequirementsPayload; import com.yoti.api.client.docs.session.create.resources.ResourceCreationContainer; import com.yoti.api.client.docs.session.create.task.RequestedTask; @@ -18,55 +18,55 @@ */ public class SessionSpec { - @JsonProperty(Property.CLIENT_SESSION_TOKEN_TTL) + @JsonProperty("client_session_token_ttl") private final Integer clientSessionTokenTtl; - @JsonProperty(Property.SESSION_DEADLINE) + @JsonProperty("session_deadline") private final ZonedDateTime sessionDeadline; - @JsonProperty(Property.RESOURCES_TTL) + @JsonProperty("resources_ttl") private final Integer resourcesTtl; - @JsonProperty(Property.IMPORT_TOKEN) + @JsonProperty("import_token") private final ImportTokenPayload importToken; - @JsonProperty(Property.USER_TRACKING_ID) + @JsonProperty("user_tracking_id") private final String userTrackingId; - @JsonProperty(Property.NOTIFICATIONS) + @JsonProperty("notifications") private final NotificationConfig notifications; - @JsonProperty(Property.REQUESTED_CHECKS) + @JsonProperty("requested_checks") private final List> requestedChecks; - @JsonProperty(Property.REQUESTED_TASKS) + @JsonProperty("requested_tasks") private final List> requestedTasks; - @JsonProperty(Property.SDK_CONFIG) + @JsonProperty("sdk_config") private final SdkConfig sdkConfig; - @JsonProperty(Property.REQUIRED_DOCUMENTS) + @JsonProperty("required_documents") private final List requiredDocuments; - @JsonProperty(Property.BLOCK_BIOMETRIC_CONSENT) + @JsonProperty("block_biometric_consent") private final Boolean blockBiometricConsent; - @JsonProperty(Property.IBV_OPTIONS) + @JsonProperty("ibv_options") private final IbvOptions ibvOptions; - @JsonProperty(Property.IDENTITY_PROFILE_REQUIREMENTS) - private final Map identityProfile; + @JsonProperty("identity_profile_requirements") + private final IdentityProfileRequirementsPayload identityProfile; - @JsonProperty(Property.ADVANCED_IDENTITY_PROFILE_REQUIREMENTS) + @JsonProperty("advanced_identity_profile_requirements") private final AdvancedIdentityProfileRequirementsPayload advancedIdentityProfileRequirements; - @JsonProperty(Property.SUBJECT) - private final Map subject; + @JsonProperty("subject") + private final SubjectPayload subject; - @JsonProperty(Property.RESOURCES) + @JsonProperty("resources") private final ResourceCreationContainer resources; - @JsonProperty(Property.CREATE_IDENTITY_PROFILE_PREVIEW) + @JsonProperty("create_identity_profile_preview") private final Boolean createIdentityProfilePreview; SessionSpec(Integer clientSessionTokenTtl, @@ -81,8 +81,8 @@ public class SessionSpec { Boolean blockBiometricConsent, IbvOptions ibvOptions, ZonedDateTime sessionDeadline, - Map identityProfile, - Map subject, + IdentityProfileRequirementsPayload identityProfile, + SubjectPayload subject, ResourceCreationContainer resources, Boolean createIdentityProfilePreview, AdvancedIdentityProfileRequirementsPayload advancedIdentityProfileRequirements) { @@ -223,7 +223,7 @@ public ZonedDateTime getSessionDeadline() { * * @return Identity Profile */ - public Object getIdentityProfile() { + public IdentityProfileRequirementsPayload getIdentityProfile() { return identityProfile; } @@ -232,7 +232,7 @@ public Object getIdentityProfile() { * * @return subject */ - public Map getSubject() { + public SubjectPayload getSubject() { return subject; } @@ -277,9 +277,9 @@ public static class Builder { private Boolean blockBiometricConsent; private IbvOptions ibvOptions; private ZonedDateTime sessionDeadline; - private Map identityProfile; + private IdentityProfileRequirementsPayload identityProfile; private AdvancedIdentityProfileRequirementsPayload advancedIdentityProfileRequirementsPayload; - private Map subject; + private SubjectPayload subject; private ResourceCreationContainer resources; private Boolean createIdentityProfilePreview; @@ -428,7 +428,7 @@ public Builder withSessionDeadline(ZonedDateTime sessionDeadline) { * @param identityProfile the Identity Profile * @return the Builder */ - public Builder withIdentityProfile(Map identityProfile) { + public Builder withIdentityProfile(IdentityProfileRequirementsPayload identityProfile) { this.identityProfile = identityProfile; return this; } @@ -439,7 +439,7 @@ public Builder withIdentityProfile(Map identityProfile) { * @param subject the subject * @return the Builder */ - public Builder withSubject(Map subject) { + public Builder withSubject(SubjectPayload subject) { this.subject = subject; return this; } @@ -504,28 +504,4 @@ public SessionSpec build() { } } - private static final class Property { - - private static final String CLIENT_SESSION_TOKEN_TTL = "client_session_token_ttl"; - private static final String SESSION_DEADLINE = "session_deadline"; - private static final String RESOURCES_TTL = "resources_ttl"; - private static final String USER_TRACKING_ID = "user_tracking_id"; - private static final String NOTIFICATIONS = "notifications"; - private static final String REQUESTED_CHECKS = "requested_checks"; - private static final String REQUESTED_TASKS = "requested_tasks"; - private static final String SDK_CONFIG = "sdk_config"; - private static final String REQUIRED_DOCUMENTS = "required_documents"; - private static final String BLOCK_BIOMETRIC_CONSENT = "block_biometric_consent"; - private static final String IBV_OPTIONS = "ibv_options"; - private static final String IDENTITY_PROFILE_REQUIREMENTS = "identity_profile_requirements"; - private static final String ADVANCED_IDENTITY_PROFILE_REQUIREMENTS = "advanced_identity_profile_requirements"; - private static final String SUBJECT = "subject"; - private static final String RESOURCES = "resources"; - private static final String CREATE_IDENTITY_PROFILE_PREVIEW = "create_identity_profile_preview"; - private static final String IMPORT_TOKEN = "import_token"; - - private Property() { } - - } - } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SubjectPayload.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SubjectPayload.java new file mode 100644 index 000000000..513a40595 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/SubjectPayload.java @@ -0,0 +1,45 @@ +package com.yoti.api.client.docs.session.create; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class SubjectPayload { + + @JsonProperty("subject_id") + private final String subjectId; + + SubjectPayload(String subjectId) { + this.subjectId = subjectId; + } + + public static Builder builder() { + return new Builder(); + } + + public String getSubjectId() { + return subjectId; + } + + public static class Builder { + + private String subjectId; + + Builder() {} + + /** + * Sets the subject ID for the Identity Profile requirement + * + * @param subjectId the subject ID + * @return the builder + */ + public Builder withSubjectId(String subjectId) { + this.subjectId = subjectId; + return this; + } + + public SubjectPayload build() { + return new SubjectPayload(subjectId); + } + + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/UserPrice.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/UserPrice.java index 38d1a745c..90c651a78 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/UserPrice.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/UserPrice.java @@ -6,10 +6,10 @@ public class UserPrice { - @JsonProperty(Property.AMOUNT) + @JsonProperty("amount") private final String amount; - @JsonProperty(Property.CURRENCY) + @JsonProperty("currency") private final String currency; private UserPrice(String amount, String currency) { @@ -78,13 +78,4 @@ public UserPrice build() { } - private static final class Property { - - private static final String AMOUNT = "amount"; - private static final String CURRENCY = "currency"; - - private Property() { } - - } - } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileRequirementsPayload.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileRequirementsPayload.java new file mode 100644 index 000000000..e75f454ca --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileRequirementsPayload.java @@ -0,0 +1,67 @@ +package com.yoti.api.client.docs.session.create.identityprofile.simple; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class IdentityProfileRequirementsPayload { + + @JsonProperty("trust_framework") + private final String trustFramework; + + @JsonProperty("scheme") + private final IdentityProfileSchemePayload scheme; + + IdentityProfileRequirementsPayload(String trustFramework, IdentityProfileSchemePayload scheme) { + this.trustFramework = trustFramework; + this.scheme = scheme; + } + + public static Builder builder() { + return new Builder(); + } + + public String getTrustFramework() { + return trustFramework; + } + + public IdentityProfileSchemePayload getScheme() { + return scheme; + } + + public static class Builder { + + private String trustFramework; + private IdentityProfileSchemePayload scheme; + + Builder() {} + + /** + * Sets the trust framework name for the Identity Profile requirement + * + * @param trustFramework the name of the trust framework + * @return the builder + */ + public Builder withTrustFramework(String trustFramework) { + this.trustFramework = trustFramework; + return this; + } + + /** + * Sets the scheme for the Identity Profile requirement + * + * @param scheme the scheme + * @return the builder + */ + public Builder withScheme(IdentityProfileSchemePayload scheme) { + this.scheme = scheme; + return this; + } + + public IdentityProfileRequirementsPayload build() { + return new IdentityProfileRequirementsPayload(trustFramework, scheme); + } + + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileSchemePayload.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileSchemePayload.java new file mode 100644 index 000000000..228173b11 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/create/identityprofile/simple/IdentityProfileSchemePayload.java @@ -0,0 +1,67 @@ +package com.yoti.api.client.docs.session.create.identityprofile.simple; + +import com.fasterxml.jackson.annotation.JsonInclude; +import com.fasterxml.jackson.annotation.JsonProperty; + +@JsonInclude(JsonInclude.Include.NON_NULL) +public class IdentityProfileSchemePayload { + + @JsonProperty("type") + private final String type; + + @JsonProperty("objective") + private final String objective; + + IdentityProfileSchemePayload(String type, String objective) { + this.type = type; + this.objective = objective; + } + + public static Builder builder() { + return new Builder(); + } + + public String getType() { + return type; + } + + public String getObjective() { + return objective; + } + + public static class Builder { + + private String type; + private String objective; + + Builder() {} + + /** + * Sets the type of the scheme for the Identity Profile + * + * @param type the type of scheme + * @return the builder + */ + public Builder withType(String type) { + this.type = type; + return this; + } + + /** + * Sets the objective of the scheme for the Identity Profile + * + * @param objective the objective of the scheme + * @return the builder + */ + public Builder withObjective(String objective) { + this.objective = objective; + return this; + } + + public IdentityProfileSchemePayload build() { + return new IdentityProfileSchemePayload(type, objective); + } + + } + +} 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 0f08f0331..51bbbed09 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,34 +31,64 @@ public static class Builder { private String manualCheck; 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; + } + 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 9911e7d74..ae7963573 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,13 @@ public String getChipData() { return chipData; } + /** + * Describes whether or not expanded document fields should be created as part of text extraction + * + * @return whether to create expanded document fields + */ + public Boolean getCreateExpandedDocumentFields() { + return createExpandedDocumentFields; + } + } 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 000000000..66464762e --- /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 000000000..73a975d15 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/devicemetadata/MetadataResponse.java @@ -0,0 +1,35 @@ +package com.yoti.api.client.docs.session.devicemetadata; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class MetadataResponse { + + @JsonProperty("event") + private String event; + + @JsonProperty("resource_id") + private String resourceId; + + @JsonProperty("created") + private String created; + + @JsonProperty("device") + private DeviceResponse device; + + public String getEvent() { + return event; + } + + public String getResourceId() { + return resourceId; + } + + public String getCreated() { + return created; + } + + public DeviceResponse getDevice() { + return device; + } + +} 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 000000000..83f2f785d --- /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/GetSessionResult.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/GetSessionResult.java index 5c56bad89..6be4325d8 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 @@ -9,43 +9,43 @@ public class GetSessionResult { - @JsonProperty(Property.CLIENT_SESSION_TOKEN_TTL) + @JsonProperty("client_session_token_ttl") private long clientSessionTokenTtl; - @JsonProperty(Property.SESSION_ID) + @JsonProperty("session_id") private String sessionId; - @JsonProperty(Property.USER_TRACKING_ID) + @JsonProperty("user_tracking_id") private String userTrackingId; - @JsonProperty(Property.STATE) + @JsonProperty("state") private String state; - @JsonProperty(Property.CLIENT_SESSION_TOKEN) + @JsonProperty("client_session_token") private String clientSessionToken; - @JsonProperty(Property.BIOMETRIC_CONSENT) + @JsonProperty("biometric_consent") private String biometricConsent; - @JsonProperty(Property.CHECKS) + @JsonProperty("checks") private List extends CheckResponse> checks; - @JsonProperty(Property.RESOURCES) + @JsonProperty("resources") private ResourceContainer resources; - @JsonProperty(Property.IDENTITY_PROFILE) + @JsonProperty("identity_profile") private IdentityProfileResponse identityProfile; - @JsonProperty(Property.ADVANCED_IDENTITY_PROFILE) + @JsonProperty("advanced_identity_profile") private AdvancedIdentityProfileResponse advancedIdentityProfile; - @JsonProperty(Property.IDENTITY_PROFILE_PREVIEW) + @JsonProperty("identity_profile_preview") private IdentityProfilePreviewResponse identityProfilePreview; - @JsonProperty(Property.ADVANCED_IDENTITY_PROFILE_PREVIEW) + @JsonProperty("advanced_identity_profile_preview") private IdentityProfilePreviewResponse advancedIdentityProfilePreview; - @JsonProperty(Property.IMPORT_TOKEN) + @JsonProperty("import_token") private ImportTokenResponse importToken; public long getClientSessionTokenTtl() { @@ -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); } @@ -167,24 +175,4 @@ private List filterChecksByType(Class clazz) { .collect(Collectors.toList()); } - private static final class Property { - - private static final String CLIENT_SESSION_TOKEN_TTL = "client_session_token_ttl"; - private static final String SESSION_ID = "session_id"; - private static final String USER_TRACKING_ID = "user_tracking_id"; - private static final String STATE = "state"; - private static final String CLIENT_SESSION_TOKEN = "client_session_token"; - private static final String BIOMETRIC_CONSENT = "biometric_consent"; - private static final String CHECKS = "checks"; - private static final String RESOURCES = "resources"; - private static final String IDENTITY_PROFILE = "identity_profile"; - private static final String ADVANCED_IDENTITY_PROFILE = "advanced_identity_profile"; - private static final String IDENTITY_PROFILE_PREVIEW = "identity_profile_preview"; - private static final String ADVANCED_IDENTITY_PROFILE_PREVIEW = "advanced_identity_profile_preview"; - private static final String IMPORT_TOKEN = "import_token"; - - private Property() { } - - } - } 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 4eee63ab2..256ea21e0 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/IdDocumentResourceResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdDocumentResourceResponse.java index 88476ec6d..83359d8aa 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; + } + } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileReportResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileReportResponse.java new file mode 100644 index 000000000..99cfc60f4 --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileReportResponse.java @@ -0,0 +1,45 @@ +package com.yoti.api.client.docs.session.retrieve; + +import java.util.List; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class IdentityProfileReportResponse { + + @JsonProperty("trust_framework") + private String trustFramework; + + @JsonProperty("media") + private MediaResponse media; + + @JsonProperty("schemes_compliance") + private List schemesCompliance; + + /** + * The trust framework the report was generated for + * + * @return the trust framework + */ + public String getTrustFramework() { + return trustFramework; + } + + /** + * The media object containing the report + * + * @return the report media + */ + public MediaResponse getMedia() { + return media; + } + + /** + * The list of schemes used in the trust framework + * + * @return the list of schemes + */ + public List getSchemesCompliance() { + return schemesCompliance; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileResponse.java index 896e56223..8cb52cc3c 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileResponse.java @@ -1,22 +1,20 @@ package com.yoti.api.client.docs.session.retrieve; -import java.util.Map; - import com.fasterxml.jackson.annotation.JsonProperty; public class IdentityProfileResponse { - @JsonProperty(Property.SUBJECT_ID) + @JsonProperty("subject_id") private String subjectId; - @JsonProperty(Property.RESULT) + @JsonProperty("result") private String result; - @JsonProperty(Property.FAILURE_REASON) + @JsonProperty("failure_reason") private IdentityProfileFailureResponse failureReason; - @JsonProperty(Property.IDENTITY_PROFILE_REPORT) - private Map identityProfileReport; + @JsonProperty("identity_profile_report") + private IdentityProfileReportResponse identityProfileReport; public String getSubjectId() { return subjectId; @@ -30,19 +28,8 @@ public IdentityProfileFailureResponse getFailureReason() { return failureReason; } - public Map getIdentityProfileReport() { + public IdentityProfileReportResponse getIdentityProfileReport() { return identityProfileReport; } - private static final class Property { - - 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 Property() { } - - } - } diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeComplianceReportResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeComplianceReportResponse.java new file mode 100644 index 000000000..646886c9b --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeComplianceReportResponse.java @@ -0,0 +1,43 @@ +package com.yoti.api.client.docs.session.retrieve; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class IdentityProfileSchemeComplianceReportResponse { + + @JsonProperty("scheme") + private IdentityProfileSchemeResponse scheme; + + @JsonProperty("requirements_met") + private Boolean requirementsMet; + + @JsonProperty("requirements_not_met_info") + private String requirementsNotMetInfo; + + /** + * The Identity Profile scheme + * + * @return the scheme + */ + public IdentityProfileSchemeResponse getScheme() { + return scheme; + } + + /** + * Whether or not the requirements for the scheme were met + * + * @return boolean + */ + public Boolean getRequirementsMet() { + return requirementsMet; + } + + /** + * Information about why the requirements for the scheme were not met + * + * @return string + */ + public String getRequirementsNotMetInfo() { + return requirementsNotMetInfo; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeResponse.java new file mode 100644 index 000000000..fe33fceed --- /dev/null +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/IdentityProfileSchemeResponse.java @@ -0,0 +1,31 @@ +package com.yoti.api.client.docs.session.retrieve; + +import com.fasterxml.jackson.annotation.JsonProperty; + +public class IdentityProfileSchemeResponse { + + @JsonProperty("type") + private String type; + + @JsonProperty("objective") + private String objective; + + /** + * The type of the scheme + * + * @return the type + */ + public String getType() { + return type; + } + + /** + * The objective of the scheme + * + * @return the objective + */ + public String getObjective() { + return objective; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ImportTokenResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ImportTokenResponse.java index 73e30650e..2cffb878d 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ImportTokenResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/ImportTokenResponse.java @@ -4,10 +4,10 @@ public class ImportTokenResponse { - @JsonProperty(Property.MEDIA) + @JsonProperty("media") private MediaResponse media; - @JsonProperty(Property.FAILURE_REASON) + @JsonProperty("failure_reason") private String failureReason; public MediaResponse getMedia() { @@ -18,13 +18,4 @@ public String getFailureReason() { return failureReason; } - private static final class Property { - - private static final String MEDIA = "media"; - private static final String FAILURE_REASON = "failure_reason"; - - private Property() { } - - } - } 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 857f8f1de..8d25c591c 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/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 fef7a3e62..b0ea61bd3 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 000000000..976c90e7e --- /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 000000000..56ecf6c2b --- /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; + } + +} diff --git a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/configuration/capture/liveness/UnknownRequiredLivenessResourceResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/configuration/capture/liveness/UnknownRequiredLivenessResourceResponse.java index 8a5c79677..375aa50ed 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/configuration/capture/liveness/UnknownRequiredLivenessResourceResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/docs/session/retrieve/configuration/capture/liveness/UnknownRequiredLivenessResourceResponse.java @@ -1,7 +1,5 @@ package com.yoti.api.client.docs.session.retrieve.configuration.capture.liveness; -import com.yoti.api.client.docs.session.retrieve.configuration.capture.liveness.RequiredLivenessResourceResponse; - public class UnknownRequiredLivenessResourceResponse extends RequiredLivenessResourceResponse { } 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 84431edbd..7f8423823 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/ProfileResponse.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileResponse.java index b3dcc319b..53c9ed8ce 100644 --- a/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileResponse.java +++ b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/ProfileResponse.java @@ -6,13 +6,13 @@ public class ProfileResponse { - @JsonProperty(Property.SESSION_DATA) + @JsonProperty("session_data") private String sessionData; - @JsonProperty(Property.RECEIPT) + @JsonProperty("receipt") private Receipt receipt; - @JsonProperty(Property.ERROR_DETAILS) + @JsonProperty("error_details") private ErrorDetails error; public ProfileResponse() { } @@ -105,14 +105,4 @@ public ProfileResponse build() { } - private static final class Property { - - private static final String SESSION_DATA = "session_data"; - private static final String RECEIPT = "receipt"; - private static final String ERROR_DETAILS = "error_details"; - - private Property() { } - - } - } 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 e6130834e..b971c050c 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/YotiConstants.java b/yoti-sdk-api/src/main/java/com/yoti/api/client/spi/remote/call/YotiConstants.java index d51962446..ae1f62831 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 + "-4.0.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-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 a8a57f589..6b322cdf2 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_TRACKED_DEVICES = "/sessions/%s/tracked-devices?sdkId=%s"; public String createAmlPath(String appId) { return format(AML, appId); @@ -121,4 +122,12 @@ 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_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/DocScanClientBuilderTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/DocScanClientBuilderTest.java index 095bae55c..21ac4dd6b 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 fc22e91af..265275b17 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); - try { - DocScanClient testObj = new DocScanClient(APP_ID, validKeyPairSource, docScanServiceMock); - testObj.createSession(sessionSpecMock); - } catch (DocScanException thrown) { - assertThat(thrown, is(original)); - return; - } - fail("Expected an exception"); + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.createSession(sessionSpecMock)); + + 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); - 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"); + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getSession(SOME_SESSION_ID)); + + 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); - 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"); + DocScanException thrown = assertThrows(DocScanException.class, () -> testObj.getMediaContent(SOME_SESSION_ID, SOME_MEDIA_ID)); + + 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,34 @@ 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()); + + 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)); + } + + @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)); - 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 7d2f61049..a945140fb 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,8 +10,8 @@ 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.any; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.instanceOf; @@ -30,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; @@ -39,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; @@ -58,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; @@ -79,7 +83,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 +102,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 +113,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 +208,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 +217,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 +307,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 +314,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 +408,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 +564,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); @@ -915,252 +695,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 @@ -1191,217 +959,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 @@ -1410,9 +1169,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 @@ -1421,9 +1180,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 @@ -1431,65 +1190,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 @@ -1500,10 +1259,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 @@ -1514,10 +1273,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 @@ -1529,10 +1288,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 @@ -1544,168 +1303,140 @@ 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 - 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 public void getSupportedDocuments_shouldWrapURISyntaxException() throws Exception { URISyntaxException uriSyntaxException = new URISyntaxException("someUrl", "Failed to build URI"); - 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 @@ -1719,4 +1450,168 @@ 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)); + } + + @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")); + } + } 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 e315a1e95..8c137c878 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() 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 d8b787378..94500ad47 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,10 +13,13 @@ 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"; + 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"; 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"; @@ -29,30 +32,36 @@ 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) + .withDarkMode(SOME_DARK_MODE) .withPresetIssuingCountry(SOME_PRESET_ISSUING_COUNTRY) .withSuccessUrl(SOME_SUCCESS_URL) .withErrorUrl(SOME_ERROR_URL) .withPrivacyPolicyUrl(SOME_PRIVACY_POLICY_URL) .withAllowHandoff(true) .withAttemptsConfiguration(attemptsConfigurationMock) + .withBrandId(SOME_BRAND_ID) .build(); assertThat(result, is(instanceOf(SdkConfig.class))); 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)); + 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)); 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 @@ -81,6 +90,24 @@ public void shouldBuildSimpleSdkConfigWithCameraAndUpload() { assertThat(result.getAllowedCaptureMethods(), is("CAMERA_AND_UPLOAD")); } + @Test + public void shouldBuildSimpleSdkConfigWithBiometricConsentFlowEarly() { + SdkConfig result = SdkConfig.builder() + .withBiometricConsentFlowEarly() + .build(); + + assertThat(result.getBiometricConsentFlow(), is("EARLY")); + } + + @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() @@ -91,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")); + } } 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 7cf4cce37..cf303428e 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 @@ -1,28 +1,27 @@ package com.yoti.api.client.docs.session.create; -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.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; -import java.util.HashMap; -import java.util.Map; import com.yoti.api.client.docs.session.create.check.RequestedDocumentAuthenticityCheck; import com.yoti.api.client.docs.session.create.check.RequestedLivenessCheck; import com.yoti.api.client.docs.session.create.filters.RequiredDocument; +import com.yoti.api.client.docs.session.create.identityprofile.simple.IdentityProfileRequirementsPayload; import com.yoti.api.client.docs.session.create.resources.ResourceCreationContainer; import com.yoti.api.client.docs.session.create.task.RequestedIdDocTextExtractionTask; -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 { @@ -43,16 +42,39 @@ public class SessionSpecTest { private static final String SOME_SDK_CONFIG_SUCCESS_URL = "https://yourdomain.com/some/success/endpoint"; private static final String SOME_SDK_CONFIG_ERROR_URL = "https://yourdomain.com/some/error/endpoint"; - private static final ObjectMapper MAPPER = new ObjectMapper(); - @Mock RequiredDocument requiredDocumentMock; @Mock IbvOptions ibvOptionsMock; @Mock ZonedDateTime sessionDeadlineMock; @Mock ResourceCreationContainer resourceCreationContainerMock; @Mock ImportTokenPayload importTokenMock; + @Mock IdentityProfileRequirementsPayload identityProfileRequirementsPayloadMock; + @Mock SubjectPayload subjectPayloadMock; @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 +82,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 +112,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 +120,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 +136,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 +157,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,51 +207,21 @@ public void withSessionDeadline_shouldSetTheSessionDeadline() { } @Test - public void buildWithIdentityProfile() throws IOException { - Map scheme = new HashMap<>(); - scheme.put(IdentityProperty.TYPE, "A_TYPE"); - scheme.put(IdentityProperty.OBJECTIVE, "AN_OBJECTIVE"); - - Map identityProfile = new HashMap<>(); - identityProfile.put(IdentityProperty.TRUST_FRAMEWORK, "A_FRAMEWORK"); - identityProfile.put(IdentityProperty.SCHEME, scheme); - - JsonNode json = toSessionSpecJson(identityProfile); - - assertThat( - json.get(IdentityProperty.TRUST_FRAMEWORK).asText(), - is(equalTo(identityProfile.get(IdentityProperty.TRUST_FRAMEWORK))) - ); - - JsonNode schemeJsonNode = json.get(IdentityProperty.SCHEME); - assertThat(schemeJsonNode.get(IdentityProperty.TYPE).asText(), is(equalTo(scheme.get(IdentityProperty.TYPE)))); - assertThat(schemeJsonNode.get(IdentityProperty.OBJECTIVE).asText(), is(equalTo(scheme.get(IdentityProperty.OBJECTIVE)))); - } - - private static JsonNode toSessionSpecJson(Map obj) throws IOException { - SessionSpec session = SessionSpec.builder() - .withIdentityProfile(obj) + public void withIdentityProfile_shouldSetTheIdentityProfile() { + SessionSpec result = SessionSpec.builder() + .withIdentityProfile(identityProfileRequirementsPayloadMock) .build(); - return MAPPER.readTree(MAPPER.writeValueAsString(session.getIdentityProfile()).getBytes(DEFAULT_CHARSET)); + assertThat(result.getIdentityProfile(), is(identityProfileRequirementsPayloadMock)); } @Test - public void buildWithSubject() throws IOException { - Map subject = new HashMap<>(); - subject.put(SubjectProperty.SUBJECT_ID, "A_SUBJECT_ID"); - - SessionSpec session = SessionSpec.builder() - .withSubject(subject) + public void withSubject_shouldSetTheSubject() { + SessionSpec result = SessionSpec.builder() + .withSubject(subjectPayloadMock) .build(); - ObjectMapper mapper = new ObjectMapper(); - - JsonNode json = mapper.readTree( - mapper.writeValueAsString(session.getSubject()).getBytes(DEFAULT_CHARSET) - ); - - assertThat(json.get("subject_id").asText(), is(Matchers.equalTo(subject.get(SubjectProperty.SUBJECT_ID)))); + assertThat(result.getSubject(), is(subjectPayloadMock)); } @Test @@ -295,14 +242,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() @@ -312,23 +251,4 @@ public void shouldBuildWithImportToken() { assertThat(sessionSpec.getImportToken(), is(importTokenMock)); } - private static final class IdentityProperty { - - private static final String TYPE = "type"; - private static final String SCHEME = "scheme"; - private static final String OBJECTIVE = "objective"; - private static final String TRUST_FRAMEWORK = "trust_framework"; - - private IdentityProperty() { } - - } - - private static final class SubjectProperty { - - private static final String SUBJECT_ID = "subject_id"; - - private SubjectProperty() {} - - } - } 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 27ed0aba6..b00e03600 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 213215f27..fb1d2efea 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 41ed53c8a..1c248fdd0 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 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 93e3562c4..626584d03 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,16 @@ public void shouldBuildSimpleRequestedTextExtractionTaskWithChipDataIgnore() { .withChipDataIgnore() .build(); - RequestedIdDocTextExtractionTaskConfig configResult = result.getConfig(); - assertThat(configResult.getChipData(), is("IGNORE")); + assertThat(result.getConfig().getChipData(), is("IGNORE")); + } + + @Test + public void shouldBuildSimpleRequestedTextExtractionTaskWithCreateExpandedDocumentFields() { + RequestedIdDocTextExtractionTask result = RequestedIdDocTextExtractionTask.builder() + .withCreateExpandedDocumentFields(true) + .build(); + + assertThat(result.getConfig().getCreateExpandedDocumentFields(), is(true)); } } 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 e0c644551..000000000 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultCheckTest.java +++ /dev/null @@ -1,236 +0,0 @@ -package com.yoti.api.client.docs.session.retrieve; - -import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.hasSize; - -import java.util.ArrayList; -import java.util.Arrays; -import java.util.List; - -import com.yoti.api.client.spi.remote.util.FieldSetter; - -import org.junit.Test; -import org.junit.runner.RunWith; -import org.mockito.Mock; -import org.mockito.junit.MockitoJUnitRunner; - -@RunWith(MockitoJUnitRunner.class) -public class GetSessionResultCheckTest { - - private static final int SESSION_CHECKS = 14; - - @Mock AuthenticityCheckResponse authenticityCheckResponse; - @Mock FaceMatchCheckResponse faceMatchCheckResponse; - @Mock FaceComparisonCheckResponse faceComparisonCheckResponse; - @Mock TextDataCheckResponse textDataCheckResponse; - @Mock SupplementaryDocumentTextDataCheckResponse supplementaryDocumentTextDataCheckResponse; - @Mock LivenessCheckResponse livenessCheckResponse; - @Mock IdDocumentComparisonCheckResponse idDocumentComparisonCheckResponse; - @Mock ThirdPartyIdentityCheckResponse thirdPartyIdentityCheckResponse; - @Mock WatchlistScreeningCheckResponse watchlistScreeningCheckResponse; - @Mock ThirdPartyIdentityFraudOneCheckResponse thirdPartyIdentityFraudOneCheckResponse; - @Mock IbvVisualReviewCheckResponse ibvVisualReviewCheckResponse; - @Mock DocumentSchemeValidityCheckResponse documentSchemeValidityCheckResponse; - @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponse; - @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponse; - - GetSessionResult getSessionResult; - - @Test - public void shouldFilterAuthenticityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getAuthenticityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterLivenessChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getLivenessChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterTextDataChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIdDocumentTextDataChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterSupplementaryDocumentTextDataChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getSupplementaryDocumentTextDataChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterFaceMatchChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getFaceMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterFaceComparisonChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getFaceComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterIdDocumentComparisonChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIdDocumentComparisonChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterThirdPartyIdentityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterWatchlistScreeningChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getWatchlistScreeningChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterIbvVisualReviewChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getIbvVisualReviewChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterDocumentSchemeValidityChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getDocumentSchemeValidityChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterProfileDocumentMatchChecks() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getProfileDocumentMatchChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterThirdPartyIdentityFraudOneCheck() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getThirdPartyIdentityFraudOneChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldFilterSynecticsIdentityFraudCheck() { - getSessionResult = new GetSessionResult(); - - setupGetSessionResult(); - - List result = getSessionResult.getSynecticsIdentityFraudChecks(); - assertThat(getSessionResult.getChecks(), hasSize(SESSION_CHECKS)); - assertThat(result, hasSize(1)); - } - - @Test - public void shouldReturnEmptyLists() { - getSessionResult = new GetSessionResult(); - - FieldSetter.setField( - getSessionResult, - "checks", - new ArrayList<>() - ); - - assertThat(getSessionResult.getChecks(), hasSize(0)); - assertThat(getSessionResult.getAuthenticityChecks(), hasSize(0)); - assertThat(getSessionResult.getFaceMatchChecks(), hasSize(0)); - assertThat(getSessionResult.getIdDocumentTextDataChecks(), hasSize(0)); - assertThat(getSessionResult.getSupplementaryDocumentTextDataChecks(), hasSize(0)); - assertThat(getSessionResult.getLivenessChecks(), hasSize(0)); - assertThat(getSessionResult.getThirdPartyIdentityFraudOneChecks(), hasSize(0)); - assertThat(getSessionResult.getSynecticsIdentityFraudChecks(), hasSize(0)); - } - - private void setupGetSessionResult() { - FieldSetter.setField( - getSessionResult, - "checks", - Arrays.asList( - authenticityCheckResponse, - livenessCheckResponse, - textDataCheckResponse, - supplementaryDocumentTextDataCheckResponse, - faceMatchCheckResponse, - faceComparisonCheckResponse, - idDocumentComparisonCheckResponse, - thirdPartyIdentityCheckResponse, - watchlistScreeningCheckResponse, - thirdPartyIdentityFraudOneCheckResponse, - ibvVisualReviewCheckResponse, - documentSchemeValidityCheckResponse, - profileDocumentMatchCheckResponse, - synecticsIdentityFraudCheckResponse - ) - ); - } - -} diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java index fb9de223c..aad431fa2 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/GetSessionResultTest.java @@ -1,205 +1,105 @@ package com.yoti.api.client.docs.session.retrieve; -import static com.yoti.api.client.spi.remote.call.YotiConstants.DEFAULT_CHARSET; - import static org.hamcrest.MatcherAssert.assertThat; -import static org.hamcrest.Matchers.*; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.core.Is.is; +import static org.junit.Assert.assertThrows; +import static org.mockito.Mockito.when; -import java.io.IOException; -import java.util.HashMap; -import java.util.Map; +import java.util.Arrays; +import java.util.Collections; +import java.util.List; -import com.yoti.api.client.docs.session.create.SessionSpec; +import com.yoti.api.client.spi.remote.util.FieldSetter; -import com.fasterxml.jackson.databind.DeserializationFeature; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import org.junit.*; +import org.junit.Before; +import org.junit.Test; +import org.junit.runner.RunWith; +import org.mockito.InjectMocks; +import org.mockito.Mock; +import org.mockito.junit.MockitoJUnitRunner; +@RunWith(MockitoJUnitRunner.class) public class GetSessionResultTest { - private static final ObjectMapper MAPPER = getMapper(); - - @Test - public void shouldReturnIdentityProfile() throws IOException { - Map scheme = new HashMap<>(); - scheme.put(Property.TYPE, "A_TYPE"); - scheme.put(Property.OBJECTIVE, "AN_OBJECTIVE"); - - Map schemesCompliance = new HashMap<>(); - schemesCompliance.put(Property.SCHEME, scheme); - - Map media = new HashMap<>(); - media.put(Property.ID, "A_MEDIA_ID"); - media.put(Property.TYPE, "A_TYPE"); - - Map identityProfileReport = new HashMap<>(); - identityProfileReport.put(Property.TRUST_FRAMEWORK, "A_FRAMEWORK"); - identityProfileReport.put(Property.SCHEMES_COMPLIANCE, schemesCompliance); - identityProfileReport.put(Property.MEDIA, media); - - Map identityProfile = new HashMap<>(); - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); - identityProfile.put(Property.RESULT, "A_RESULT"); - identityProfile.put(Property.IDENTITY_PROFILE_REPORT, identityProfileReport); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE, identityProfile); - - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); - - assertThat(sessionResultIdentityProfile, is(notNullValue())); - assertThat( - sessionResultIdentityProfile.getSubjectId(), - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) - ); - assertThat( - sessionResultIdentityProfile.getResult(), - is(equalTo(identityProfile.get(Property.RESULT))) - ); - assertThat(sessionResultIdentityProfile.getFailureReason(), is(nullValue())); - - JsonNode jsonIdentityProfileResponse = toSessionJson(sessionResultIdentityProfile.getIdentityProfileReport()); - - assertThat(jsonIdentityProfileResponse, is(notNullValue())); - assertThat( - jsonIdentityProfileResponse.get(Property.TRUST_FRAMEWORK).asText(), - is(equalTo(identityProfileReport.get(Property.TRUST_FRAMEWORK))) - ); - - JsonNode schemesComplianceResponse = jsonIdentityProfileResponse.get(Property.SCHEMES_COMPLIANCE); - assertThat(schemesComplianceResponse, is(notNullValue())); - - JsonNode schemeResponse = schemesComplianceResponse.get("scheme"); - assertThat(schemeResponse, is(notNullValue())); - assertThat(schemeResponse.get(Property.TYPE).asText(), is(equalTo(scheme.get(Property.TYPE)))); - assertThat(schemeResponse.get(Property.OBJECTIVE).asText(), is(equalTo(scheme.get(Property.OBJECTIVE)))); - - JsonNode mediaResponse = jsonIdentityProfileResponse.get(Property.MEDIA); - assertThat(mediaResponse, is(notNullValue())); - assertThat(mediaResponse.get(Property.ID).asText(), is(equalTo(media.get(Property.ID)))); - assertThat(mediaResponse.get(Property.TYPE).asText(), is(equalTo(media.get(Property.TYPE)))); + private static final String AUTH_CHECK_ID = "authCheckId"; + + @InjectMocks GetSessionResult testObj = new GetSessionResult(); + + @Mock AuthenticityCheckResponse authenticityCheckResponseMock; + @Mock FaceMatchCheckResponse faceMatchCheckResponseMock; + @Mock FaceComparisonCheckResponse faceComparisonCheckResponseMock; + @Mock TextDataCheckResponse textDataCheckResponseMock; + @Mock SupplementaryDocumentTextDataCheckResponse supplementaryDocumentTextDataCheckResponseMock; + @Mock LivenessCheckResponse livenessCheckResponseMock; + @Mock IdDocumentComparisonCheckResponse idDocumentComparisonCheckResponseMock; + @Mock ThirdPartyIdentityCheckResponse thirdPartyIdentityCheckResponseMock; + @Mock WatchlistScreeningCheckResponse watchlistScreeningCheckResponseMock; + @Mock ThirdPartyIdentityFraudOneCheckResponse thirdPartyIdentityFraudOneCheckResponseMock; + @Mock IbvVisualReviewCheckResponse ibvVisualReviewCheckResponseMock; + @Mock DocumentSchemeValidityCheckResponse documentSchemeValidityCheckResponseMock; + @Mock ProfileDocumentMatchCheckResponse profileDocumentMatchCheckResponseMock; + @Mock SynecticsIdentityFraudCheckResponse synecticsIdentityFraudCheckResponseMock; + + @Mock(name = "resources") ResourceContainer resourceContainerMock; + @Mock ResourceContainer checkResourceContainerMock; + + @Before + public void setUp() throws Exception { + when(authenticityCheckResponseMock.getId()).thenReturn(AUTH_CHECK_ID); } @Test - public void shouldReturnFailureIdentityProfile() throws IOException { - Map failureReason = new HashMap<>(); - failureReason.put(Property.REASON_CODE, "A_FAILURE_REASON_CODE"); - - Map identityProfile = new HashMap<>(); - identityProfile.put(Property.SUBJECT_ID, "A_SUBJECT_ID"); - identityProfile.put(Property.RESULT, "A_RESULT"); - identityProfile.put(Property.FAILURE_REASON, failureReason); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE, identityProfile); - - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfileResponse sessionResultIdentityProfile = sessionResult.getIdentityProfile(); - - assertThat(sessionResultIdentityProfile, is(notNullValue())); - assertThat( - sessionResultIdentityProfile.getSubjectId(), - is(equalTo(identityProfile.get(Property.SUBJECT_ID))) - ); - assertThat( - sessionResultIdentityProfile.getResult(), - is(equalTo(identityProfile.get(Property.RESULT))) - ); - - IdentityProfileFailureResponse sessionResultFailureReason = sessionResultIdentityProfile.getFailureReason(); - assertThat(sessionResultFailureReason, is(notNullValue())); - assertThat( - sessionResultFailureReason.getReasonCode(), - is(equalTo(failureReason.get(Property.REASON_CODE))) + public void shouldFilterChecks() { + List allChecks = Arrays.asList( + authenticityCheckResponseMock, + livenessCheckResponseMock, + textDataCheckResponseMock, + supplementaryDocumentTextDataCheckResponseMock, + faceMatchCheckResponseMock, + faceComparisonCheckResponseMock, + idDocumentComparisonCheckResponseMock, + thirdPartyIdentityCheckResponseMock, + watchlistScreeningCheckResponseMock, + thirdPartyIdentityFraudOneCheckResponseMock, + ibvVisualReviewCheckResponseMock, + documentSchemeValidityCheckResponseMock, + profileDocumentMatchCheckResponseMock, + synecticsIdentityFraudCheckResponseMock ); + FieldSetter.setField(testObj, "checks", allChecks); + + assertThat(testObj.getAuthenticityChecks(), contains(authenticityCheckResponseMock)); + assertThat(testObj.getLivenessChecks(), contains(livenessCheckResponseMock)); + assertThat(testObj.getIdDocumentTextDataChecks(), contains(textDataCheckResponseMock)); + assertThat(testObj.getSupplementaryDocumentTextDataChecks(), contains(supplementaryDocumentTextDataCheckResponseMock)); + assertThat(testObj.getFaceMatchChecks(), contains(faceMatchCheckResponseMock)); + assertThat(testObj.getFaceComparisonChecks(), contains(faceComparisonCheckResponseMock)); + assertThat(testObj.getIdDocumentComparisonChecks(), contains(idDocumentComparisonCheckResponseMock)); + assertThat(testObj.getThirdPartyIdentityChecks(), contains(thirdPartyIdentityCheckResponseMock)); + assertThat(testObj.getWatchlistScreeningChecks(), contains(watchlistScreeningCheckResponseMock)); + assertThat(testObj.getIbvVisualReviewChecks(), contains(ibvVisualReviewCheckResponseMock)); + assertThat(testObj.getDocumentSchemeValidityChecks(), contains(documentSchemeValidityCheckResponseMock)); + assertThat(testObj.getProfileDocumentMatchChecks(), contains(profileDocumentMatchCheckResponseMock)); + assertThat(testObj.getThirdPartyIdentityFraudOneChecks(), contains(thirdPartyIdentityFraudOneCheckResponseMock)); + assertThat(testObj.getSynecticsIdentityFraudChecks(), contains(synecticsIdentityFraudCheckResponseMock)); } @Test - public void shouldReturnIdentityProfilePreview() { - Map media = new HashMap<>(); - media.put(Property.ID, "someId"); - media.put(Property.TYPE, "someType"); - media.put(Property.CREATED, "someCreatedTime"); - media.put(Property.LAST_UPDATED, "someLastUpdatedTime"); - - Map identityProfilePreview = new HashMap<>(); - identityProfilePreview.put(Property.MEDIA, media); - - Map session = new HashMap<>(); - session.put(Property.IDENTITY_PROFILE_PREVIEW, identityProfilePreview); + public void getResourcesForCheck_shouldThrowExceptionForBadCheckId() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); - GetSessionResult sessionResult = toGetSessionResult(session); - - IdentityProfilePreviewResponse sessionResultIdentityProfilePreview = sessionResult.getIdentityProfilePreview(); - - assertThat(sessionResultIdentityProfilePreview, is(notNullValue())); - - MediaResponse identityProfilePreviewMedia = sessionResultIdentityProfilePreview.getMedia(); - - assertThat(identityProfilePreviewMedia, is(notNullValue())); - - assertThat( - identityProfilePreviewMedia.getId(), - is(equalTo(media.get(Property.ID))) - ); - assertThat( - identityProfilePreviewMedia.getType(), - is(equalTo(media.get(Property.TYPE))) - ); - assertThat( - identityProfilePreviewMedia.getCreated(), - is(equalTo(media.get(Property.CREATED))) - ); - assertThat( - identityProfilePreviewMedia.getLastUpdated(), - is(equalTo(media.get(Property.LAST_UPDATED))) - ); + assertThrows(IllegalArgumentException.class, () -> testObj.getResourcesForCheck("someBadCheckId")); } - private static GetSessionResult toGetSessionResult(Object obj) { - return MAPPER.convertValue(obj, GetSessionResult.class); - } - - private static JsonNode toSessionJson(Map identityProfile) throws IOException { - SessionSpec session = SessionSpec.builder() - .withIdentityProfile(identityProfile) - .build(); - - return MAPPER.readTree(MAPPER.writeValueAsString(session.getIdentityProfile()).getBytes(DEFAULT_CHARSET)); - } - - private static ObjectMapper getMapper() { - ObjectMapper mapper = new ObjectMapper(); - mapper.disable(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES); - - return mapper; - } + @Test + public void getResourcesForCheck_shouldReturnResultFromResources() { + FieldSetter.setField(testObj, "checks", Collections.singletonList(authenticityCheckResponseMock)); + when(resourceContainerMock.filterForCheck(authenticityCheckResponseMock)).thenReturn(checkResourceContainerMock); - private static final class Property { - - private static final String IDENTITY_PROFILE = "identity_profile"; - private static final String IDENTITY_PROFILE_PREVIEW = "identity_profile_preview"; - private static final String SUBJECT_ID = "subject_id"; - private static final String RESULT = "result"; - private static final String FAILURE_REASON = "failure_reason"; - private static final String IDENTITY_PROFILE_REPORT = "identity_profile_report"; - private static final String TRUST_FRAMEWORK = "trust_framework"; - private static final String REASON_CODE = "reason_code"; - private static final String SCHEMES_COMPLIANCE = "schemes_compliance"; - private static final String SCHEME = "scheme"; - private static final String OBJECTIVE = "objective"; - private static final String MEDIA = "media"; - private static final String ID = "id"; - private static final String TYPE = "type"; - private static final String CREATED = "created"; - private static final String LAST_UPDATED = "last_updated"; - - private Property() { } + ResourceContainer result = testObj.getResourcesForCheck(AUTH_CHECK_ID); + assertThat(result, is(checkResourceContainerMock)); } } diff --git a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java index eca9dd5b1..85270ea4b 100644 --- a/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java +++ b/yoti-sdk-api/src/test/java/com/yoti/api/client/docs/session/retrieve/ResourceContainerTest.java @@ -1,14 +1,20 @@ package com.yoti.api.client.docs.session.retrieve; +import static java.util.Arrays.asList; + import static org.hamcrest.MatcherAssert.assertThat; +import static org.hamcrest.Matchers.contains; +import static org.hamcrest.Matchers.emptyIterable; import static org.hamcrest.Matchers.hasSize; +import static org.hamcrest.Matchers.is; +import static org.mockito.Mockito.when; import java.util.ArrayList; -import java.util.Arrays; import java.util.List; import com.yoti.api.client.spi.remote.util.FieldSetter; +import org.junit.Before; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; @@ -17,63 +23,123 @@ @RunWith(MockitoJUnitRunner.class) public class ResourceContainerTest { - @Mock ZoomLivenessResourceResponse zoomLivenessResourceResponseMock; - @Mock StaticLivenessResourceResponse staticLivenessResourceResponseMock; - @Mock LivenessResourceResponse livenessResourceResponse; + private static final String ID_DOC_1_ID = "idDocumentResource1Id"; + private static final String SUPPLEMENTARY_DOC_1_ID = "supplementaryDocResource1Id"; + private static final String ZOOM_RESOURCE_1_ID = "zoomLivenessResource1MockId"; + private static final String FACE_CAPTURE_1_ID = "faceCaptureResource1Id"; + private static final String PROFILE_1_ID = "applicantProfileResource1Id"; + + ResourceContainer testObj = new ResourceContainer(); + + @Mock IdDocumentResourceResponse idDocResourceResponse1Mock; + @Mock IdDocumentResourceResponse idDocResourceResponse2Mock; + @Mock SupplementaryDocumentResourceResponse supplementaryDocResourceResponse1Mock; + @Mock SupplementaryDocumentResourceResponse supplementaryDocResourceResponse2Mock; + @Mock ZoomLivenessResourceResponse zoomLivenessResource1Mock; + @Mock ZoomLivenessResourceResponse zoomLivenessResource2Mock; + @Mock StaticLivenessResourceResponse staticLivenessResourceMock; + @Mock LivenessResourceResponse livenessResource; + @Mock FaceCaptureResourceResponse faceCaptureResourceResponse1Mock; + @Mock FaceCaptureResourceResponse faceCaptureResourceResponse2Mock; + @Mock ApplicantProfileResourceResponse applicantProfileResourceResponse1Mock; + @Mock ApplicantProfileResourceResponse applicantProfileResourceResponse2Mock; + + @Mock CheckResponse checkResponseMock; + + @Before + public void setUp() throws Exception { + when(idDocResourceResponse1Mock.getId()).thenReturn(ID_DOC_1_ID); + when(idDocResourceResponse2Mock.getId()).thenReturn("idDocumentResource2Id"); + when(supplementaryDocResourceResponse1Mock.getId()).thenReturn(SUPPLEMENTARY_DOC_1_ID); + when(supplementaryDocResourceResponse2Mock.getId()).thenReturn("supplementaryDocResource2Id"); + when(zoomLivenessResource1Mock.getId()).thenReturn(ZOOM_RESOURCE_1_ID); + when(zoomLivenessResource2Mock.getId()).thenReturn("zoomLivenessResource2MockId"); + when(faceCaptureResourceResponse1Mock.getId()).thenReturn(FACE_CAPTURE_1_ID); + when(faceCaptureResourceResponse2Mock.getId()).thenReturn("faceCaptureResource2Id"); + when(applicantProfileResourceResponse1Mock.getId()).thenReturn(PROFILE_1_ID); + when(applicantProfileResourceResponse2Mock.getId()).thenReturn("applicantProfileResource2Id"); + } + + @Test + public void getZoomLivenessResources_shouldFilterZoomLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getZoomLivenessResources(); - ResourceContainer simpleResourceContainer; + assertThat(result, contains(zoomLivenessResource1Mock)); + } @Test - public void shouldFilterZoomLivenessResources() { - simpleResourceContainer = new ResourceContainer(); - - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - Arrays.asList( - zoomLivenessResourceResponseMock, - livenessResourceResponse, - livenessResourceResponse - ) - ); - - List result = simpleResourceContainer.getZoomLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(3)); - assertThat(result, hasSize(1)); + public void getZoomLivenessResources_shouldReturnEmptyList() { + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); + + List result = testObj.getZoomLivenessResources(); + + assertThat(result, hasSize(0)); } @Test - public void shouldFilterStaticLivenessResources() { - simpleResourceContainer = new ResourceContainer(); - - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - Arrays.asList( - staticLivenessResourceResponseMock, - livenessResourceResponse, - livenessResourceResponse - ) - ); - - List result = simpleResourceContainer.getStaticLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(3)); - assertThat(result, hasSize(1)); + public void getStaticLivenessResources_shouldFilterStaticLivenessResources() { + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, staticLivenessResourceMock, livenessResource)); + + List result = testObj.getStaticLivenessResources(); + + assertThat(result, contains(staticLivenessResourceMock)); } @Test - public void shouldReturnEmptyList() { - simpleResourceContainer = new ResourceContainer(); + public void getStaticLivenessResources_shouldReturnEmptyList() { + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); - FieldSetter.setField( - simpleResourceContainer, - "livenessCapture", - new ArrayList<>() - ); + List result = testObj.getStaticLivenessResources(); - List result = simpleResourceContainer.getZoomLivenessResources(); - assertThat(simpleResourceContainer.getLivenessCapture(), hasSize(0)); assertThat(result, hasSize(0)); } + @Test + public void filterForCheck_shouldHandleNullResources() { + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), is(emptyIterable())); + assertThat(result.getSupplementaryDocuments(), is(emptyIterable())); + assertThat(result.getLivenessCapture(), is(emptyIterable())); + assertThat(result.getFaceCapture(), is(emptyIterable())); + assertThat(result.getApplicantProfiles(), is(emptyIterable())); + } + + @Test + public void filterForCheck_shouldReturnEmptyWhenNoMatches() { + FieldSetter.setField(testObj, "idDocuments", new ArrayList<>()); + FieldSetter.setField(testObj, "supplementaryDocuments", new ArrayList<>()); + FieldSetter.setField(testObj, "livenessCapture", new ArrayList<>()); + FieldSetter.setField(testObj, "faceCapture", new ArrayList<>()); + FieldSetter.setField(testObj, "applicantProfiles", new ArrayList<>()); + + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), is(emptyIterable())); + assertThat(result.getSupplementaryDocuments(), is(emptyIterable())); + assertThat(result.getLivenessCapture(), is(emptyIterable())); + assertThat(result.getFaceCapture(), is(emptyIterable())); + assertThat(result.getApplicantProfiles(), is(emptyIterable())); + } + + @Test + public void filterForCheck_shouldReturnFilteredCollections() { + FieldSetter.setField(testObj, "idDocuments", asList(idDocResourceResponse1Mock, idDocResourceResponse2Mock)); + FieldSetter.setField(testObj, "supplementaryDocuments", asList(supplementaryDocResourceResponse1Mock, supplementaryDocResourceResponse2Mock)); + FieldSetter.setField(testObj, "livenessCapture", asList(zoomLivenessResource1Mock, zoomLivenessResource2Mock, staticLivenessResourceMock)); + FieldSetter.setField(testObj, "faceCapture", asList(faceCaptureResourceResponse1Mock, faceCaptureResourceResponse2Mock)); + FieldSetter.setField(testObj, "applicantProfiles", asList(applicantProfileResourceResponse1Mock, applicantProfileResourceResponse2Mock)); + when(checkResponseMock.getResourcesUsed()).thenReturn(asList(ID_DOC_1_ID, SUPPLEMENTARY_DOC_1_ID, ZOOM_RESOURCE_1_ID, FACE_CAPTURE_1_ID, PROFILE_1_ID)); + + ResourceContainer result = testObj.filterForCheck(checkResponseMock); + + assertThat(result.getIdDocuments(), contains(idDocResourceResponse1Mock)); + assertThat(result.getSupplementaryDocuments(), contains(supplementaryDocResourceResponse1Mock)); + assertThat(result.getLivenessCapture(), contains(zoomLivenessResource1Mock)); + assertThat(result.getFaceCapture(), contains(faceCaptureResourceResponse1Mock)); + assertThat(result.getApplicantProfiles(), contains(applicantProfileResourceResponse1Mock)); + } + } diff --git a/yoti-sdk-parent/pom.xml b/yoti-sdk-parent/pom.xml index 1728a6b82..5849deca4 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 + 4.0.0-SNAPSHOT Yoti SDK Parent Pom Parent pom for the Java SDK projects https://github.com/getyoti/yoti-java-sdk @@ -98,10 +98,10 @@ 8 - 2.0.9 + 2.0.16 1.70 2.16.1 - 3.25.3 + 4.28.3 4.5.14 @@ -113,7 +113,7 @@ 4.13.2 4.11.0 2.2 - 3.13.0 + 3.17.0 3.8.5 diff --git a/yoti-sdk-sandbox/pom.xml b/yoti-sdk-sandbox/pom.xml index 8d3831c2f..078d0229b 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 + 4.0.0-SNAPSHOT ../yoti-sdk-parent 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 e271fe9a2..15b8f97f2 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,15 +7,21 @@ 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() { 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 000000000..441d0f2ce --- /dev/null +++ b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/check/SandboxStaticLivenessCheckBuilder.java @@ -0,0 +1,34 @@ +package com.yoti.api.client.sandbox.docs.request.check; + +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 { + + private Integer responseDelay; + + SandboxStaticLivenessCheckBuilder() {} + + public SandboxStaticLivenessCheckBuilder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; + } + + @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, 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 b650f6d0d..262267b95 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/SandboxDocumentIdPhoto.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxDocumentIdPhoto.java index 37906d3db..fcf0b4e05 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 54774991a..ca31eadcd 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} */ @@ -46,10 +54,11 @@ public static class Builder { private SandboxDocumentFilter documentFilter; private SandboxDocumentIdPhoto documentIdPhoto; 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) { @@ -82,15 +91,28 @@ 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 Builder withResponseDelay(Integer responseDelay) { + this.responseDelay = responseDelay; + return this; + } + public SandboxDocumentTextDataExtractionTask build() { - SandboxDocumentTextDataExtractionTaskResult result = new SandboxDocumentTextDataExtractionTaskResult(documentFields, this.documentIdPhoto, - detectedCountry, recommendation); - return new SandboxDocumentTextDataExtractionTask(result, documentFilter); + SandboxDocumentTextDataExtractionTaskResult result = new SandboxDocumentTextDataExtractionTaskResult(documentFields, + documentIdPhoto, + detectedCountry, + detectedDocumentType, + recommendation); + return new SandboxDocumentTextDataExtractionTask(result, documentFilter, responseDelay); } } } 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 0d3684a6f..21065d5f6 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/SandboxSupplementaryDocTextDataExtractionTask.java b/yoti-sdk-sandbox/src/main/java/com/yoti/api/client/sandbox/docs/request/task/SandboxSupplementaryDocTextDataExtractionTask.java index 2ccba4843..beb290b79 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/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 ef7a2399c..bef00ad80 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 9223a108c..505b70968 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") 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 2c0eb0d87..9e5d013c1 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")); + } + } 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 adc9bb5a1..d8dfc328c 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 0cb89d717..93cb6df02 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)); + } + +} diff --git a/yoti-sdk-spring-boot-auto-config/README.md b/yoti-sdk-spring-boot-auto-config/README.md index 3b2c5c561..2d7f8864f 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 + 4.0.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: '4.0.0-SNAPSHOT' ``` diff --git a/yoti-sdk-spring-boot-auto-config/pom.xml b/yoti-sdk-spring-boot-auto-config/pom.xml index a11b7a451..afa28fb84 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 + 4.0.0-SNAPSHOT ../yoti-sdk-parent diff --git a/yoti-sdk-spring-boot-example/README.md b/yoti-sdk-spring-boot-example/README.md index 0a7b046d5..75ec851cf 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 + 4.0.0-SNAPSHOT ``` diff --git a/yoti-sdk-spring-boot-example/pom.xml b/yoti-sdk-spring-boot-example/pom.xml index b3f6c1962..1364197bf 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 + 4.0.0-SNAPSHOT org.springframework.boot diff --git a/yoti-sdk-spring-security/README.md b/yoti-sdk-spring-security/README.md index d3bb0513b..f6fe0ca0a 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 + 4.0.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: '4.0.0-SNAPSHOT' ``` ### Provide a `YotiClient` instance diff --git a/yoti-sdk-spring-security/pom.xml b/yoti-sdk-spring-security/pom.xml index 42a631616..a902565b9 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 + 4.0.0-SNAPSHOT ../yoti-sdk-parent