-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
4427e1c
commit 7eb79ce
Showing
2 changed files
with
84 additions
and
14 deletions.
There are no files selected for viewing
58 changes: 58 additions & 0 deletions
58
src/test/java/com/onfido/integration/QualifiedElectronicSignatureTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,58 @@ | ||
package com.onfido.integration; | ||
|
||
import com.google.gson.internal.LinkedTreeMap; | ||
import com.onfido.model.TaskItem; | ||
import com.onfido.model.WorkflowRun; | ||
import com.onfido.model.WorkflowRunBuilder; | ||
import java.util.ArrayList; | ||
import java.util.HashMap; | ||
import java.util.Map; | ||
import java.util.UUID; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class QualifiedElectronicSignatureTest extends TestBase { | ||
|
||
@Test | ||
public void documentsTest() throws Exception { | ||
UUID applicantId = createApplicant().getId(); | ||
UUID workflowId = UUID.fromString("8b74614f-9e7f-42fd-852a-5f2bcc852587"); | ||
|
||
Map<String, Object> customData = new HashMap<>(); | ||
customData.put("country_of_operation", "GBR"); | ||
customData.put("document_date_of_expiry", "2022-01-01"); | ||
customData.put("document_issuing_country", "FRA"); | ||
customData.put("document_issuing_date", "2022-01-01"); | ||
customData.put("document_number", "Example string"); | ||
customData.put( | ||
"document_to_sign_url", | ||
"https://www.w3.org/WAI/ER/tests/xhtml/testfiles/resources/pdf/dummy.pdf"); | ||
customData.put("document_type", "driving_licence"); | ||
|
||
WorkflowRun workflowRun = | ||
onfido.createWorkflowRun( | ||
new WorkflowRunBuilder() | ||
.workflowId(workflowId) | ||
.applicantId(applicantId) | ||
.customData(customData)); | ||
UUID workflowRunId = workflowRun.getId(); | ||
|
||
TaskItem task = onfido.listTasks(workflowRunId).get(0); | ||
|
||
LinkedTreeMap output = | ||
(LinkedTreeMap) | ||
repeatRequestUntilTaskOutputChanges( | ||
"findTask", new Object[] {workflowRunId, task.getId()}, 10, 3000) | ||
.getOutput(); | ||
|
||
LinkedTreeMap properties = (LinkedTreeMap) output.get("properties"); | ||
ArrayList signedDocuments = (ArrayList) properties.get("signed_documents"); | ||
LinkedTreeMap signedDocument = (LinkedTreeMap) signedDocuments.get(0); | ||
UUID fileId = UUID.fromString((String) signedDocument.get("id")); | ||
|
||
byte[] byteArray = onfido.downloadQesDocument(workflowRunId, fileId).getByteArray(); | ||
|
||
Assertions.assertEquals("%PDF", new String(byteArray, 0, 4)); | ||
Assertions.assertTrue(byteArray.length > 0); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,20 +4,7 @@ | |
import com.onfido.Configuration; | ||
import com.onfido.FileTransfer; | ||
import com.onfido.api.DefaultApi; | ||
import com.onfido.model.Applicant; | ||
import com.onfido.model.ApplicantBuilder; | ||
import com.onfido.model.Check; | ||
import com.onfido.model.CheckBuilder; | ||
import com.onfido.model.CountryCodes; | ||
import com.onfido.model.Document; | ||
import com.onfido.model.IdPhoto; | ||
import com.onfido.model.LivePhoto; | ||
import com.onfido.model.LocationBuilder; | ||
import com.onfido.model.WatchlistMonitor; | ||
import com.onfido.model.WatchlistMonitorBuilder; | ||
import com.onfido.model.Webhook; | ||
import com.onfido.model.WorkflowRun; | ||
import com.onfido.model.WorkflowRunBuilder; | ||
import com.onfido.model.*; | ||
import java.io.File; | ||
import java.io.IOException; | ||
import java.lang.reflect.InvocationTargetException; | ||
|
@@ -65,6 +52,8 @@ public Applicant createApplicant(String first_name) | |
new ApplicantBuilder() | ||
.firstName(first_name) | ||
.lastName("Last") | ||
.email("[email protected]") | ||
.phoneNumber("351911111111") | ||
.location( | ||
new LocationBuilder() | ||
.ipAddress("127.0.0.1") | ||
|
@@ -190,6 +179,29 @@ public Object repeatRequestUntilStatusChanges( | |
return instance; | ||
} | ||
|
||
public Task repeatRequestUntilTaskOutputChanges( | ||
String methodName, Object[] params, int maxRetries, int sleepTime) | ||
throws NoSuchMethodException, | ||
IllegalAccessException, | ||
InterruptedException, | ||
InvocationTargetException { | ||
Method method = getMethod(methodName, params); | ||
Task instance = (Task) method.invoke(onfido, params); | ||
|
||
int iteration = 0; | ||
|
||
while (instance.getOutput() == null) { | ||
if (iteration > maxRetries) { | ||
throw new RuntimeException("Task output did not change in time"); | ||
} | ||
|
||
iteration += 1; | ||
Thread.sleep(sleepTime); | ||
instance = (Task) method.invoke(onfido, params); | ||
} | ||
return instance; | ||
} | ||
|
||
public Object repeatRequestUntilHttpCodeChanges( | ||
String methodName, Object[] params, int maxRetries, int sleepTime) | ||
throws NoSuchMethodException, IllegalAccessException, InterruptedException { | ||
|