Skip to content

Commit

Permalink
Introduce tests
Browse files Browse the repository at this point in the history
  • Loading branch information
nqhoan-axonivy committed Aug 29, 2024
1 parent 692e84e commit 97f7952
Show file tree
Hide file tree
Showing 8 changed files with 89 additions and 62 deletions.
23 changes: 0 additions & 23 deletions a-trust-connector-test/config/variables.yaml
Original file line number Diff line number Diff line change
@@ -1,24 +1 @@
Variables:
ATrust:
# API Key for "A-Trust Handysignature API"
APIKey: ''

# The Server URL under which the SigBox Server is reachable
ServerUrl: ''

# The SignBox belong to your ATrust server
SignBox: ''

# The default signature template ID to be used
TemplateId: 0

# To config the Handy-Signature view in iframe. The Details can be found on the A-Trust Website https://labs.a-trust.at/developer/Handy-Signatur.aspx.
HandySignaturParameter:
# For setting width of frame.
Width: 350
# For setting height of frame.
Height: 350
# For setting background color of frame.
BackgroundColor: 0
# For setting phone number of frame.
PhoneNumber: 0
Original file line number Diff line number Diff line change
@@ -1,24 +1,30 @@
package com.axonivy.connector.atrust.test;

import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.net.MalformedURLException;
import java.net.URISyntaxException;
import java.net.URL;
import java.nio.charset.StandardCharsets;
import java.util.UUID;

import javax.annotation.security.PermitAll;
import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
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.QueryParam;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import org.apache.commons.io.IOUtils;
import org.glassfish.jersey.media.multipart.FormDataContentDisposition;
import org.glassfish.jersey.media.multipart.FormDataParam;

import ch.ivyteam.ivy.environment.Ivy;
import io.swagger.v3.oas.annotations.Hidden;

@Path(ATrustSignMock.PATH_SUFFIX)
Expand All @@ -29,7 +35,9 @@ public class ATrustSignMock {
static final String PATH_SUFFIX = "testbox/testboxrest/v2/";
public static final String URI = "{ivy.app.baseurl}/api/" + PATH_SUFFIX;
static final String TEMPLATE_PATH = "templates";
static final String MOCK_TEMPLATE_LOCATION = URI + TEMPLATE_PATH + "/101";
static final String SIGNATURE_BATCHES_PATH = "signaturebatches";
static final String MOCK_TEMPLATE_LOCATION = PATH_SUFFIX + TEMPLATE_PATH + "/101";
static final String MOCK_BATCH_LOCATION = PATH_SUFFIX + SIGNATURE_BATCHES_PATH + "/" + UUID.randomUUID().toString();

@GET
@Produces(MediaType.APPLICATION_JSON)
Expand All @@ -39,14 +47,52 @@ public String getTemplates() {
}

@POST
@Produces(MediaType.APPLICATION_JSON)
@Produces()
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path(TEMPLATE_PATH)
public Response addTemplate(File template) throws MalformedURLException, URISyntaxException {
var location = new URL(MOCK_TEMPLATE_LOCATION).toURI();
public Response addTemplate(@FormDataParam("file") InputStream uploadStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData)
throws MalformedURLException, URISyntaxException {
var location = new URL(Ivy.html().applicationHomeRef() + MOCK_TEMPLATE_LOCATION).toURI();
return Response.created(location).build();
}

@DELETE
@Produces(MediaType.APPLICATION_JSON)
@Path(TEMPLATE_PATH + "/{templateId}")
public Response deleteTemplate(@PathParam(value = "templateId") String templateId) {
return Response.ok().build();
}

@POST
@Path(SIGNATURE_BATCHES_PATH)
public Response createBatch() throws MalformedURLException, URISyntaxException {
var location = new URL(Ivy.html().applicationHomeRef() + MOCK_BATCH_LOCATION).toURI();
return Response.created(location).build();
}

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path(SIGNATURE_BATCHES_PATH + "/{ticketId}/documents")
public Response addDocToBatch(@PathParam("ticketId") String ticketId,
@FormDataParam("file") InputStream uploadStream,
@FormDataParam("file") FormDataContentDisposition fileMetaData, @QueryParam("location") String location,
@QueryParam("location") String reason, @QueryParam("template") String template,
@QueryParam("page") String page, @QueryParam("x") String x, @QueryParam("y") String y,
@QueryParam("w") String w, @QueryParam("h") String h) throws MalformedURLException, URISyntaxException {
var locationURL = new URL(Ivy.html().applicationHomeRef() + MOCK_BATCH_LOCATION).toURI();
return Response.created(locationURL).build();
}

@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path(SIGNATURE_BATCHES_PATH + "/{ticketId}/mobileSignature")
public Response createMobileSignature(@PathParam("ticketId") String ticketId)
throws MalformedURLException, URISyntaxException {
var locationURL = new URL(Ivy.html().applicationHomeRef() + MOCK_BATCH_LOCATION).toURI();
return Response.created(locationURL).build();
}

private static String load(String path) {
try (InputStream is = ATrustSignMock.class.getResourceAsStream(path)) {
return IOUtils.toString(is, StandardCharsets.UTF_8);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,14 +67,10 @@ static void beforeAll(AppFixture fixture, IApplication app) {
RestClients clients = RestClients.of(app);
RestClient atrustRestClient = clients.find(ATRUST_REST_CLIENT);
var mockClient = atrustRestClient.toBuilder()
.features(List.of(JsonFeature.class.getName(),
HeaderFeature.class.getName(),
MultiPartFeature.class.getName(),
OpenApiJsonFeature.class.getName()))
.property("AUTH.apiKey", "apiKey")
.property("PATH.serverUrl", "serverUrl")
.property("PATH.signBox", "signBox")
.toRestClient();
.features(List.of(JsonFeature.class.getName(), HeaderFeature.class.getName(),
MultiPartFeature.class.getName(), OpenApiJsonFeature.class.getName()))
.property("AUTH.apiKey", "apiKey").property("PATH.serverUrl", "serverUrl")
.property("PATH.signBox", "signBox").toRestClient();
clients.set(mockClient);
}

Expand Down
45 changes: 25 additions & 20 deletions a-trust-connector/processes/ATrust/StartSignature.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@
{ "id" : "f0", "to" : "S20", "label" : {
"name" : "yes"
}, "condition" : "org.apache.commons.lang3.StringUtils.isNoneBlank(in.signatureTicket)" },
{ "id" : "f6", "to" : "f1", "label" : {
{ "id" : "f15", "to" : "f7", "label" : {
"name" : "no",
"segment" : 0.13
} }
Expand Down Expand Up @@ -260,14 +260,14 @@
"output" : {
"map" : {
"out" : "in",
"out.signatureDocumentData.lastSignatureError" : "error.getCause().getLocalizedMessage()"
"out.signatureDocumentData.lastSignatureError" : "error.getErrorMessage()"
}
}
},
"visual" : {
"at" : { "x" : 552, "y" : 192 }
"at" : { "x" : 552, "y" : 194 }
},
"connect" : { "id" : "S10-f8", "to" : "S10-f4" }
"connect" : { "id" : "S10-f4", "to" : "S10-f1" }
} ],
"connect" : { "id" : "S10-f3", "to" : "S10-g1" }
}, {
Expand All @@ -287,12 +287,6 @@
"at" : { "x" : 672, "y" : 160 }
},
"parentConnector" : "f48"
}, {
"id" : "S10-f4",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 552, "y" : 280 }
}
}, {
"id" : "S10-f5",
"type" : "Script",
Expand Down Expand Up @@ -333,6 +327,13 @@
"at" : { "x" : 344, "y" : 160 }
},
"connect" : { "id" : "S10-f10", "to" : "S10-f0" }
}, {
"id" : "S10-f1",
"type" : "CallSubEnd",
"visual" : {
"at" : { "x" : 552, "y" : 296 },
"icon" : "res:/webContent/icons/atrust-icon.png?small"
}
} ],
"visual" : {
"at" : { "x" : 328, "y" : 192 },
Expand Down Expand Up @@ -449,12 +450,14 @@
"at" : { "x" : 512, "y" : 256 },
"size" : { "width" : 160, "height" : 60 }
},
"connect" : { "id" : "S20-f10", "to" : "S20-f6" }
"connect" : { "id" : "S20-f12", "to" : "S20-f11" }
}, {
"id" : "S20-f6",
"type" : "TaskEnd",
"id" : "S20-f11",
"type" : "CallSubEnd",
"visual" : {
"at" : { "x" : 512, "y" : 344 }
"at" : { "x" : 512, "y" : 352 },
"icon" : "res:/webContent/icons/atrust-icon.png?small",
"color" : "NodeStyle3"
}
} ],
"visual" : {
Expand Down Expand Up @@ -583,12 +586,6 @@
"icon" : "res:/webContent/icons/atrust-icon.png"
},
"connect" : { "id" : "f4", "to" : "f12" }
}, {
"id" : "f1",
"type" : "TaskEnd",
"visual" : {
"at" : { "x" : 448, "y" : 288 }
}
}, {
"id" : "f8",
"type" : "Script",
Expand Down Expand Up @@ -628,6 +625,14 @@
"name" : "yes"
} }
]
}, {
"id" : "f7",
"type" : "CallSubEnd",
"visual" : {
"at" : { "x" : 448, "y" : 296 },
"icon" : "res:/webContent/icons/atrust-icon.png?small",
"color" : "NodeStyle3"
}
} ],
"layout" : {
"lanes" : [ {
Expand Down
3 changes: 1 addition & 2 deletions a-trust-connector/processes/ATrust/TemplateManagement.p.json
Original file line number Diff line number Diff line change
Expand Up @@ -155,8 +155,7 @@
},
"templateParams" : {
"templateId" : "in.templateId"
},
"responseCode" : "ivy.log.warn(\"Delete template {0}\", response);"
}
},
"visual" : {
"at" : { "x" : 312, "y" : 304 }
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,14 @@
import javax.ws.rs.core.Feature;
import javax.ws.rs.core.FeatureContext;

import com.axonivy.connector.atrust.constant.Constants;
import com.fasterxml.jackson.jaxrs.json.JacksonJsonProvider;

import ch.ivyteam.ivy.rest.client.FeatureConfig;

public class HeaderFeature implements Feature {
public static final String REQUIRED_HEADER_KEY = "X-API-KEY";
public static final String REQUESTED_BY = "X-Requested-By";;
public static final String API_KEY = "AUTH.apiKey";

@Override
Expand All @@ -35,6 +37,7 @@ private ATrustRequestFilter(String apiKey) {
@Override
public void filter(ClientRequestContext context) throws IOException {
context.getHeaders().add(REQUIRED_HEADER_KEY, apiKey);
context.getHeaders().add(REQUESTED_BY, Constants.IVY);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

public class Constants {

public static final String IVY = "ivy";
public static final String SIGNED_PREFIX = "SIGNED_";
public static final String SEMICOLON = ";";
public static final String PDF = ".pdf";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,10 @@

public enum ATrustVariable {

TEMPLATE_ID("ATrust/TemplateId"), HANDY_SIGN_WIDTH("ATrust/HandySignaturParameter/Width"),
HANDY_SIGN_HEIGHT("ATrust/HandySignaturParameter/Height"),
HANDY_SIGN_BACKGROUNDCOLOR("ATrust/HandySignaturParameter/BackgroundColor"),
HANDY_SIGN_PHONENUMBER("ATrust/HandySignaturParameter/PhoneNumber");
TEMPLATE_ID("ATrust.TemplateId"), HANDY_SIGN_WIDTH("ATrust.HandySignaturParameter.Width"),
HANDY_SIGN_HEIGHT("ATrust.HandySignaturParameter.Height"),
HANDY_SIGN_BACKGROUNDCOLOR("ATrust.HandySignaturParameter.BackgroundColor"),
HANDY_SIGN_PHONENUMBER("ATrust.HandySignaturParameter.PhoneNumber");

private String key;

Expand Down

0 comments on commit 97f7952

Please sign in to comment.