generated from axonivy-market/market-product
-
Notifications
You must be signed in to change notification settings - Fork 1
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
b0d3a39
commit 6e59fdf
Showing
14 changed files
with
402 additions
and
6 deletions.
There are no files selected for viewing
Binary file not shown.
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
68 changes: 68 additions & 0 deletions
68
.../src/com/axonivy/connector/adobe/esign/connector/test/AdobeSignAgreementsServiceMock.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,68 @@ | ||
package com.axonivy.connector.adobe.esign.connector.test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.GET; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.PathParam; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
import ch.ivyteam.api.API; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
@Hidden | ||
@PermitAll | ||
@Path("adobeSignMock") | ||
public class AdobeSignAgreementsServiceMock { | ||
|
||
@POST | ||
@Consumes(MediaType.APPLICATION_JSON) | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("agreements") | ||
public Response createAgreement(String payload) { | ||
API.checkParameterNotNull(payload, "payload"); | ||
return Response.status(201).entity(load("json/createAgreement.json")).build(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("agreements/{agreementId}/documents") | ||
public Response getDocuments(@PathParam(value = "agreementId") String agreementId) { | ||
API.checkParameterNotNull(agreementId, "agreementId"); | ||
return Response.status(201).entity(load("json/getDocuments.json")).build(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("agreements/{agreementId}/documents/{documentId}") | ||
public Response downloadDocument(@PathParam(value = "agreementId") String agreementId, | ||
@PathParam(value = "documentId") String documentId) throws IOException { | ||
API.checkParameterNotNull(agreementId, "agreementId"); | ||
return Response.status(200).entity(TestService.getSamplePdf()).build(); | ||
} | ||
|
||
@GET | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Path("agreements/{agreementId}/signingUrls") | ||
public Response getSigningUrls(@PathParam(value = "agreementId") String agreementId) { | ||
API.checkParameterNotNull(agreementId, "agreementId"); | ||
return Response.status(201).entity(load("json/getSigningUrls.json")).build(); | ||
} | ||
|
||
private static String load(String path) { | ||
try (InputStream is = AdobeSignAgreementsServiceMock.class.getResourceAsStream(path)) { | ||
return IOUtils.toString(is, StandardCharsets.UTF_8); | ||
} catch (IOException ex) { | ||
throw new RuntimeException("Failed to read resource: " + path); | ||
} | ||
} | ||
} |
43 changes: 43 additions & 0 deletions
43
.../axonivy/connector/adobe/esign/connector/test/AdobeSignTransientDocumentsServiceMock.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,43 @@ | ||
package com.axonivy.connector.adobe.esign.connector.test; | ||
|
||
import java.io.IOException; | ||
import java.io.InputStream; | ||
import java.nio.charset.StandardCharsets; | ||
|
||
import javax.annotation.security.PermitAll; | ||
import javax.ws.rs.Consumes; | ||
import javax.ws.rs.POST; | ||
import javax.ws.rs.Path; | ||
import javax.ws.rs.Produces; | ||
import javax.ws.rs.core.MediaType; | ||
import javax.ws.rs.core.Response; | ||
|
||
import org.apache.commons.io.IOUtils; | ||
|
||
import ch.ivyteam.api.API; | ||
import io.swagger.v3.oas.annotations.Hidden; | ||
|
||
@Hidden | ||
@PermitAll | ||
@Path("adobeSignMock") | ||
public class AdobeSignTransientDocumentsServiceMock { | ||
|
||
@POST | ||
@Produces(MediaType.APPLICATION_JSON) | ||
@Consumes(MediaType.MULTIPART_FORM_DATA) | ||
@Path("transientDocuments") | ||
public Response transientDocuemts(String payload) { | ||
API.checkParameterNotNull(payload, "payload"); | ||
return Response.status(201) | ||
.entity(load("json/uploadDocument.json")) | ||
.build(); | ||
} | ||
|
||
private static String load(String path) { | ||
try (InputStream is = AdobeSignTransientDocumentsServiceMock.class.getResourceAsStream(path)) { | ||
return IOUtils.toString(is, StandardCharsets.UTF_8); | ||
} catch (IOException ex) { | ||
throw new RuntimeException("Failed to read resource: " + path); | ||
} | ||
} | ||
} |
27 changes: 27 additions & 0 deletions
27
...sign-connector-test/src/com/axonivy/connector/adobe/esign/connector/test/TestService.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,27 @@ | ||
package com.axonivy.connector.adobe.esign.connector.test; | ||
|
||
import java.io.FileOutputStream; | ||
import java.io.IOException; | ||
import java.util.Locale; | ||
|
||
import org.apache.commons.compress.utils.IOUtils; | ||
|
||
import ch.ivyteam.ivy.cm.ContentObjectValue; | ||
import ch.ivyteam.ivy.environment.Ivy; | ||
import ch.ivyteam.ivy.scripting.objects.File; | ||
|
||
public class TestService { | ||
private static final String SAMPLE_PDF_CMS_PATH = "/Files/samplePdf"; | ||
|
||
public static java.io.File getSamplePdf() throws IOException { | ||
ContentObjectValue cov = Ivy.cm().findValue(SAMPLE_PDF_CMS_PATH).resolve(Locale.ENGLISH).orElse(null); | ||
if (cov == null) { | ||
return null; | ||
} | ||
java.io.File sampleFile = new File("/samplePdf.pdf", true).getJavaFile(); | ||
FileOutputStream fos = new FileOutputStream(sampleFile); | ||
IOUtils.copy(cov.read().inputStream(), fos); | ||
return sampleFile; | ||
|
||
} | ||
} |
3 changes: 3 additions & 0 deletions
3
...ector-test/src/com/axonivy/connector/adobe/esign/connector/test/json/createAgreement.json
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,3 @@ | ||
{ | ||
"id": "CBJCHBCAABAAMaMFFCyiTyCblablablablabla" | ||
} |
17 changes: 17 additions & 0 deletions
17
...onnector-test/src/com/axonivy/connector/adobe/esign/connector/test/json/getDocuments.json
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,17 @@ | ||
{ | ||
"documents": [ | ||
{ | ||
"createdDate": [ | ||
2023, | ||
9, | ||
18 | ||
], | ||
"id": "3AAABLblqZhDM2f8YEhDF1N6Oz-8ZY5jVZVgpRh2b_69hblablablablabla", | ||
"label": null, | ||
"mimeType": "application/pdf", | ||
"name": "sample.pdf", | ||
"numPages": 2 | ||
} | ||
], | ||
"supportingDocuments": null | ||
} |
13 changes: 13 additions & 0 deletions
13
...nector-test/src/com/axonivy/connector/adobe/esign/connector/test/json/getSigningUrls.json
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,13 @@ | ||
{ | ||
"signingUrlSetInfos": [ | ||
{ | ||
"signingUrlSetName": null, | ||
"signingUrls": [ | ||
{ | ||
"email": "[email protected]", | ||
"esignUrl": "https://secure.eu2.adobesign.com/public/apiesign?pid=CBFCIBAA3AAABLblqZhBfFw-mWHXrt1tSN_AfnQQld3Ea9pq61iY57nLp7Duyp5I8XoIyLkT1TcjoW7lshFZXF4zoa5UPIOBRKUPhP8YuenqrWRNjVAXoTO8P7eMr3qIr8-hOhCOIfKUXiB0UOmQ%2A&client_id=CBJCHblablablablabla" | ||
} | ||
] | ||
} | ||
] | ||
} |
3 changes: 3 additions & 0 deletions
3
...nector-test/src/com/axonivy/connector/adobe/esign/connector/test/json/uploadDocument.json
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,3 @@ | ||
{ | ||
"transientDocumentId": "3AAABLblqZhDVSvtTTuHIxFoTcvrHMhZwdRBEz62SCvv1G8yTaPzxcu8NGkq9IIILoVyC4UHJ8vgl_Mw5CY9lBSMEbMriLGzZyy6KCWpF8Ac2TpP-3Bpfrr8LHyv92ukAsKnyJBDP9XPpSyVOm1CtLUbNtX7M6cfu_LKRSTl-nGfMK6eRalZ6AsxLzDTW8lALl20Md5x5EyOkBLW1ZvvyF2OITH-cPVgBAoh7ejVkDiHwskPq9NIUoTZ4jN3bvq0ma5Dz7gP1F5RGuLlzGDlje3_MIof7-EgdIQt92grPt7fe0-Dfgjblablabla" | ||
} |
34 changes: 34 additions & 0 deletions
34
...est/src_test/com/axonivy/connector/adobe/esign/connector/test/TestAdobeSignConnector.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,34 @@ | ||
package com.axonivy.connector.adobe.esign.connector.test; | ||
|
||
import ch.ivyteam.ivy.application.IApplication; | ||
import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; | ||
import ch.ivyteam.ivy.environment.AppFixture; | ||
import ch.ivyteam.ivy.rest.client.RestClient; | ||
import ch.ivyteam.ivy.rest.client.RestClient.Builder; | ||
import ch.ivyteam.ivy.rest.client.RestClients; | ||
|
||
@IvyProcessTest | ||
public class TestAdobeSignConnector { | ||
protected static final String TRANSIENT_DOCUMENTS = "TransientDocuments"; | ||
protected static final String AGREEMENTS = "Agreements"; | ||
|
||
protected void prepareRestClient(IApplication app, AppFixture fixture, String clientName) { | ||
fixture.var("adobe-sign-connector.host", "TESTHOST"); | ||
fixture.var("adobe-sign-connector.integrationKey", "TESTUSER"); | ||
RestClient restClient = RestClients.of(app).find(clientName); | ||
// change created client: use test url and a slightly different version of | ||
// the | ||
// DocuWare Auth feature | ||
Builder builder = RestClient.create(restClient.name()).uuid(restClient.uniqueId()) | ||
.uri("http://{ivy.engine.host}:{ivy.engine.http.port}/{ivy.request.application}/api/adobeSignMock") | ||
.description(restClient.description()).properties(restClient.properties()); | ||
|
||
for (String feature : restClient.features()) { | ||
builder.feature(feature); | ||
} | ||
|
||
builder.feature("ch.ivyteam.ivy.rest.client.security.CsrfHeaderFeature"); | ||
restClient = builder.toRestClient(); | ||
RestClients.of(app).set(restClient); | ||
} | ||
} |
143 changes: 143 additions & 0 deletions
143
...test/src_test/com/axonivy/connector/adobe/esign/connector/test/TestAgreementsService.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,143 @@ | ||
package com.axonivy.connector.adobe.esign.connector.test; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.io.IOException; | ||
import java.util.Arrays; | ||
import java.util.List; | ||
|
||
import org.junit.jupiter.api.Test; | ||
|
||
import com.axonivy.connector.adobe.esign.connector.AgreementsData; | ||
import com.axonivy.connector.adobe.esign.connector.rest.DownloadResult; | ||
import com.axonivy.connector.adobe.esign.connector.service.AdobeSignService; | ||
|
||
import api.rest.v6.client.AgreementCreationInfo; | ||
import api.rest.v6.client.AgreementCreationInfo.SignatureTypeEnum; | ||
import api.rest.v6.client.AgreementCreationInfo.StateEnum; | ||
import api.rest.v6.client.AgreementCreationInfoParticipantSetsInfo.RoleEnum; | ||
import api.rest.v6.client.AgreementCreationResponse; | ||
import api.rest.v6.client.AgreementDocuments; | ||
import api.rest.v6.client.SigningUrlResponseSigningUrlSetInfos; | ||
import ch.ivyteam.ivy.application.IApplication; | ||
import ch.ivyteam.ivy.bpm.engine.client.BpmClient; | ||
import ch.ivyteam.ivy.bpm.engine.client.ExecutionResult; | ||
import ch.ivyteam.ivy.bpm.engine.client.element.BpmElement; | ||
import ch.ivyteam.ivy.bpm.engine.client.element.BpmProcess; | ||
import ch.ivyteam.ivy.bpm.exec.client.IvyProcessTest; | ||
import ch.ivyteam.ivy.environment.AppFixture; | ||
import ch.ivyteam.ivy.environment.Ivy; | ||
import ch.ivyteam.ivy.security.ISession; | ||
|
||
@IvyProcessTest | ||
public class TestAgreementsService extends TestAdobeSignConnector { | ||
|
||
private static final BpmElement testeeCreateAgreement = BpmProcess.path("connector/Agreements") | ||
.elementName("createAgreement(AgreementCreationInfo)"); | ||
|
||
private static final BpmElement testeeGetDocuments = BpmProcess.path("connector/Agreements") | ||
.elementName("getDocuments(String)"); | ||
|
||
private static final BpmElement testeeDownloadDocument = BpmProcess.path("connector/Agreements") | ||
.elementName("dowloadDocument(String, String, String, Boolean)"); | ||
|
||
private static final BpmElement testeeGetSigningUrls = BpmProcess.path("connector/Agreements") | ||
.elementName("getSigningURLs(String,String)"); | ||
|
||
@Test | ||
public void createAgreement(BpmClient bpmClient, ISession session, AppFixture fixture, IApplication app) | ||
throws IOException { | ||
|
||
prepareRestClient(app, fixture, AGREEMENTS); | ||
|
||
AgreementCreationInfo agreement = createTestAgreement(); | ||
|
||
ExecutionResult result = bpmClient.start().subProcess(testeeCreateAgreement).withParam("agreement", agreement) | ||
.execute(); | ||
AgreementsData data = result.data().last(); | ||
AgreementCreationResponse response = data.getAgreementCreationResponse(); | ||
assertThat(response).isNotNull(); | ||
assertThat(response.getId()).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
public void getDocuments(BpmClient bpmClient, ISession session, AppFixture fixture, IApplication app) | ||
throws IOException { | ||
|
||
prepareRestClient(app, fixture, AGREEMENTS); | ||
|
||
String agreementId = "test-agreement-id"; | ||
|
||
ExecutionResult result = bpmClient.start().subProcess(testeeGetDocuments).withParam("agreementId", agreementId) | ||
.execute(); | ||
AgreementsData data = result.data().last(); | ||
AgreementDocuments response = data.getDocuments(); | ||
assertThat(response).isNotNull(); | ||
assertThat(response.getDocuments()).isNotEmpty(); | ||
} | ||
|
||
@Test | ||
public void downloadDocument(BpmClient bpmClient, ISession session, AppFixture fixture, IApplication app) | ||
throws IOException { | ||
|
||
prepareRestClient(app, fixture, AGREEMENTS); | ||
|
||
String agreementId = "test-agreement-id"; | ||
String documentId = "test-document-id"; | ||
String filename = "sample.pdf"; | ||
Boolean asFile = Boolean.TRUE; | ||
|
||
ExecutionResult result = bpmClient.start().subProcess(testeeDownloadDocument) | ||
.withParam("agreementId", agreementId).withParam("documentId", documentId) | ||
.withParam("filename", filename).withParam("asFile", asFile).execute(); | ||
AgreementsData data = result.data().last(); | ||
DownloadResult downloadResult = data.getDownload(); | ||
assertThat(downloadResult).isNotNull(); | ||
if (downloadResult.getError() != null) { | ||
Ivy.log().error(downloadResult.getError()); | ||
} | ||
assertThat(downloadResult.getFile()).isNotNull(); | ||
} | ||
|
||
@Test | ||
public void getSigningUrls(BpmClient bpmClient, ISession session, AppFixture fixture, IApplication app) | ||
throws IOException { | ||
|
||
prepareRestClient(app, fixture, AGREEMENTS); | ||
|
||
String agreementId = "test-agreement-id"; | ||
String frameParent = "test"; | ||
|
||
ExecutionResult result = bpmClient.start().subProcess(testeeGetSigningUrls) | ||
.withParam("agreementId", agreementId).withParam("frameParent", frameParent).execute(); | ||
AgreementsData data = result.data().last(); | ||
|
||
List<SigningUrlResponseSigningUrlSetInfos> signingUrls = data.getSigningUrls(); | ||
|
||
assertThat(signingUrls).isNotNull(); | ||
assertThat(signingUrls).isNotEmpty(); | ||
} | ||
|
||
private AgreementCreationInfo createTestAgreement() { | ||
AgreementCreationInfo agreement = new AgreementCreationInfo(); | ||
|
||
agreement.setName("test name"); | ||
agreement.setMessage("Please sign this document!"); | ||
agreement.setSignatureType(SignatureTypeEnum.ESIGN); | ||
agreement.setState(StateEnum.IN_PROCESS); | ||
|
||
// add signers | ||
AdobeSignService.getInstance().createParticipantInfoForEmail(Arrays.asList("[email protected]"), | ||
RoleEnum.SIGNER); | ||
agreement.setParticipantSetsInfo(AdobeSignService.getInstance() | ||
.createParticipantInfoForEmail(Arrays.asList("[email protected]"), RoleEnum.SIGNER)); | ||
|
||
// add documentIds - need to be already transferred with the upload document | ||
// service | ||
agreement.setFileInfos( | ||
AdobeSignService.getInstance().createFileInfosForDocumentIds(Arrays.asList("test-document-id"))); | ||
|
||
agreement.setEmailOption(AdobeSignService.getInstance().createAllDisabledSendOptions()); | ||
return agreement; | ||
} | ||
} |
Oops, something went wrong.