From 4fe02c8a22680537bf3d4844d72b1f385ba530f4 Mon Sep 17 00:00:00 2001 From: Janis Saldabols Date: Wed, 15 Nov 2023 12:58:29 +0200 Subject: [PATCH] Init commit --- README.md | 2 +- descriptors/ModuleDescriptor-template.json | 17 +++++- pom.xml | 4 ++ .../org/folio/print/server/data/Message.java | 3 +- .../folio/print/server/data/PrintEntry.java | 38 ++---------- .../folio/print/server/main/MainVerticle.java | 3 +- .../resources/BatchCreationResource.java | 31 +++++----- .../print/server/service/PrintService.java | 12 +--- .../print/server/storage/PrintStorage.java | 21 ++++--- src/main/resources/openapi/batchPrint.yaml | 29 +++++---- .../resources/openapi/examples/errors.sample | 15 ----- .../openapi/examples/mailMessage.sample | 9 +++ src/main/resources/openapi/schemas/entry.json | 4 ++ .../openapi/schemas/messageRequest.json | 8 ++- .../print/server/main/MainVerticleTest.java | 59 ++++++++++--------- .../resources/BatchCreationResourceTest.java | 42 ++++++++----- src/test/resources/mail/mail.json | 5 +- 17 files changed, 152 insertions(+), 150 deletions(-) delete mode 100644 src/main/resources/openapi/examples/errors.sample create mode 100644 src/main/resources/openapi/examples/mailMessage.sample diff --git a/README.md b/README.md index 1c4cb09..6892c01 100644 --- a/README.md +++ b/README.md @@ -47,7 +47,7 @@ GRANT ALL PRIVILEGES ON DATABASE folio_modules TO folio; The module's database connection is then configured by setting environment variables: `DB_HOST`, `DB_PORT`, `DB_USERNAME`, `DB_PASSWORD`, `DB_DATABASE`, -`DB_MAXPOOLSIZE`, `DB_SERVER_PEM`. +`DB_MAXPOOLSIZE`. Once configured, start the module with: diff --git a/descriptors/ModuleDescriptor-template.json b/descriptors/ModuleDescriptor-template.json index 04e84ed..c58025f 100644 --- a/descriptors/ModuleDescriptor-template.json +++ b/descriptors/ModuleDescriptor-template.json @@ -124,6 +124,18 @@ ], "requires": [], "permissionSets": [ + { + "permissionName": "mod-batch-print.print.write", + "displayName": "batch print - write print entries", + "description": "Write print entries", + "visible": false + }, + { + "permissionName": "mod-batch-print.print.read", + "displayName": "batch print - read print entries", + "description": "Read print entries", + "visible": false + }, { "permissionName": "mod-batch-print.entries.mail.post", "displayName": "batch print - send mail", @@ -163,7 +175,10 @@ "mod-batch-print.entries.collection.get", "mod-batch-print.entries.item.get", "mod-batch-print.entries.item.put", - "mod-batch-print.entries.item.delete" + "mod-batch-print.entries.item.delete", + "mod-batch-print.entries.mail.post", + "mod-batch-print.print.write", + "mod-batch-print.print.read" ] } ], diff --git a/pom.xml b/pom.xml index dd88ade..8fda15b 100644 --- a/pom.xml +++ b/pom.xml @@ -65,6 +65,10 @@ io.vertx vertx-pg-client + + io.vertx + vertx-sql-client-templates + org.folio vertx-lib diff --git a/src/main/java/org/folio/print/server/data/Message.java b/src/main/java/org/folio/print/server/data/Message.java index 84d6989..415e3ca 100644 --- a/src/main/java/org/folio/print/server/data/Message.java +++ b/src/main/java/org/folio/print/server/data/Message.java @@ -8,8 +8,9 @@ @JsonIgnoreProperties(ignoreUnknown = true) @Data public class Message { - private String deliveryChannel; + private String notificationId; private String from; + private String to; private String outputFormat; private String header; private String body; diff --git a/src/main/java/org/folio/print/server/data/PrintEntry.java b/src/main/java/org/folio/print/server/data/PrintEntry.java index 10fd79c..1d7ad95 100644 --- a/src/main/java/org/folio/print/server/data/PrintEntry.java +++ b/src/main/java/org/folio/print/server/data/PrintEntry.java @@ -3,7 +3,11 @@ import com.fasterxml.jackson.annotation.JsonInclude; import java.time.ZonedDateTime; import java.util.UUID; +import lombok.Getter; +import lombok.Setter; +@Getter +@Setter @JsonInclude(JsonInclude.Include.NON_NULL) public class PrintEntry { @@ -13,37 +17,7 @@ public class PrintEntry { private PrintEntryType type; - private String content; - - public UUID getId() { - return id; - } - - public void setId(UUID id) { - this.id = id; - } - - public ZonedDateTime getCreated() { - return created; - } - - public void setCreated(ZonedDateTime created) { - this.created = created; - } + private String sortingField; - public PrintEntryType getType() { - return type; - } - - public void setType(PrintEntryType type) { - this.type = type; - } - - public String getContent() { - return content; - } - - public void setContent(String content) { - this.content = content; - } + private String content; } diff --git a/src/main/java/org/folio/print/server/main/MainVerticle.java b/src/main/java/org/folio/print/server/main/MainVerticle.java index f621840..f98cc54 100644 --- a/src/main/java/org/folio/print/server/main/MainVerticle.java +++ b/src/main/java/org/folio/print/server/main/MainVerticle.java @@ -33,13 +33,12 @@ public void start(Promise promise) { log.info("Listening on port {}", port); var printServiceService = new PrintService(); - var batchCreationResource = new BatchCreationResource(); RouterCreator[] routerCreators = { printServiceService, - batchCreationResource, new Tenant2Api(printServiceService), new HealthApi(), + new BatchCreationResource() }; RouterCreator.mountAll(vertx, routerCreators) diff --git a/src/main/java/org/folio/print/server/resources/BatchCreationResource.java b/src/main/java/org/folio/print/server/resources/BatchCreationResource.java index 89aa4a5..7b3da96 100644 --- a/src/main/java/org/folio/print/server/resources/BatchCreationResource.java +++ b/src/main/java/org/folio/print/server/resources/BatchCreationResource.java @@ -3,9 +3,9 @@ import io.vertx.core.Future; import io.vertx.core.Vertx; import io.vertx.core.http.HttpServerResponse; +import io.vertx.core.json.JsonArray; import io.vertx.ext.web.Router; import io.vertx.ext.web.RoutingContext; -import io.vertx.ext.web.handler.BodyHandler; import java.time.LocalDateTime; import java.time.LocalTime; import java.time.ZoneOffset; @@ -16,39 +16,37 @@ import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.pdfbox.util.Hex; +import org.folio.okapi.common.XOkapiHeaders; import org.folio.print.server.data.PrintEntry; import org.folio.print.server.data.PrintEntryType; import org.folio.print.server.service.PdfService; -import org.folio.print.server.service.PrintService; import org.folio.print.server.storage.PrintStorage; import org.folio.tlib.RouterCreator; - public class BatchCreationResource implements RouterCreator { private static final Logger LOGGER = LogManager.getLogger(BatchCreationResource.class); private static final int MAX_COUNT_IN_BATCH = 1000; - public BatchCreationResource() { - } - @Override public Future createRouter(Vertx vertx) { Router router = Router.router(vertx); - String rootPath = "/print/batch-creation"; - router.post(rootPath + "*").handler(BodyHandler.create()); - router.post(rootPath).handler(this::process) - .failureHandler(this::failureResponder); + router.post("/print/batch-creation").handler((ctx) -> process(ctx, vertx)) + .failureHandler(this::failureResponder); return Future.succeededFuture(router); } - private void process(RoutingContext ctx) { - PrintStorage storage = PrintService.create(ctx); + private void process(RoutingContext ctx, Vertx vertx) { + String tenant = ctx.request().getHeader(XOkapiHeaders.TENANT); + JsonArray permissions = new JsonArray(ctx.request().getHeader(XOkapiHeaders.PERMISSIONS)); + PrintStorage printStorage = new PrintStorage(vertx, tenant, permissions); LocalDateTime localDateTime = LocalDateTime.now().with(LocalTime.MIDNIGHT); - storage.getEntriesByQuery("type=\"SINGLE\" and created > " + localDateTime - + " order by created", 0, MAX_COUNT_IN_BATCH) - .onSuccess(l -> processListAndSaveResult(l, storage)) - .onFailure(e -> LOGGER.error("Failed to create print batch", e)); + printStorage.getEntriesByQuery("type=\"SINGLE\" and created > " + localDateTime + + " sortby sortingField created", 0, MAX_COUNT_IN_BATCH) + .onSuccess(l -> processListAndSaveResult(l, printStorage)) + .onFailure(e -> LOGGER.error("Failed to create print batch", e)); + ctx.response().setStatusCode(204); + ctx.response().end(); } private void processListAndSaveResult(List entries, PrintStorage storage) { @@ -65,7 +63,6 @@ private void processListAndSaveResult(List entries, PrintStorage sto private void failureResponder(RoutingContext context) { Throwable failure = context.failure(); - if (failure != null) { if (StringUtils.isNotBlank(failure.getMessage())) { internalError(context.response(), failure.getMessage()); diff --git a/src/main/java/org/folio/print/server/service/PrintService.java b/src/main/java/org/folio/print/server/service/PrintService.java index d9e2f8e..32785a4 100644 --- a/src/main/java/org/folio/print/server/service/PrintService.java +++ b/src/main/java/org/folio/print/server/service/PrintService.java @@ -120,17 +120,10 @@ static PrintStorage createFromParams(Vertx vertx, RequestParameters params) { RequestParameter tenantParameter = params.headerParameter(XOkapiHeaders.TENANT); String tenant = tenantParameter.getString(); - // get user Id - RequestParameter userIdParameter = params.headerParameter(XOkapiHeaders.USER_ID); - UUID currentUserId = null; - if (userIdParameter != null) { - currentUserId = UUID.fromString(userIdParameter.getString()); - } - // get permissions which is required in OpenAPI spec RequestParameter okapiPermissions = params.headerParameter(XOkapiHeaders.PERMISSIONS); JsonArray permissions = new JsonArray(okapiPermissions.getString()); - return new PrintStorage(vertx, tenant, currentUserId, permissions); + return new PrintStorage(vertx, tenant, permissions); } public static PrintStorage create(RoutingContext ctx) { @@ -159,6 +152,7 @@ Future saveMail(RoutingContext ctx) { entry.setId(UUID.randomUUID()); entry.setType(PrintEntryType.SINGLE); entry.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC)); + entry.setSortingField(message.getTo()); entry.setContent(Hex.getString(PdfService.createPdfFile(message.getBody()))); return storage.createEntry(entry) .map(entity -> { @@ -226,7 +220,7 @@ public Future postInit(Vertx vertx, String tenant, JsonObject tenantAttrib if (!tenantAttributes.containsKey("module_to")) { return Future.succeededFuture(); // doing nothing for disable } - PrintStorage storage = new PrintStorage(vertx, tenant, null, null); + PrintStorage storage = new PrintStorage(vertx, tenant, null); return storage.init(); } diff --git a/src/main/java/org/folio/print/server/storage/PrintStorage.java b/src/main/java/org/folio/print/server/storage/PrintStorage.java index cb3acb3..93a7326 100644 --- a/src/main/java/org/folio/print/server/storage/PrintStorage.java +++ b/src/main/java/org/folio/print/server/storage/PrintStorage.java @@ -50,21 +50,17 @@ public class PrintStorage { private final JsonArray permissions; - private final UUID currentUser; - /** * Construct storage request for a user with given okapi permissions. * * @param vertx Vert.x handle * @param tenant tenant - * @param currentUser UUID of user as it comes from X-Okapi-User-Id * @param permissions permissions as it comes from X-Okapi-Permissions */ - public PrintStorage(Vertx vertx, String tenant, UUID currentUser, JsonArray permissions) { + public PrintStorage(Vertx vertx, String tenant, JsonArray permissions) { this.pool = TenantPgPool.pool(vertx, tenant); this.permissions = permissions; - this.currentUser = currentUser; this.printTable = pool.getSchema() + ".printing"; } @@ -79,7 +75,8 @@ public Future init() { + "(id uuid NOT NULL PRIMARY KEY," + " created TIMESTAMP NOT NULL," + " type VARCHAR NOT NULL," - + " content JSONB NOT NULL" + + " sorting_field VARCHAR NULL," + + " content VARCHAR NOT NULL" + ")" )); } @@ -100,6 +97,7 @@ PrintEntry fromRow(Row row) { entry.setId(row.getUUID("id")); entry.setCreated(row.getLocalDateTime("created").atZone(ZoneId.of(ZoneOffset.UTC.getId()))); entry.setType(PrintEntryType.valueOf(row.getString("type"))); + entry.setSortingField(row.getString("sorting_field")); entry.setContent(row.getString("content")); return entry; } @@ -116,11 +114,11 @@ public Future createEntry(PrintEntry entry) { } return pool.preparedQuery( "INSERT INTO " + printTable - + " (id, created, type, content)" - + " VALUES ($1, $2, $3, $4)" + + " (id, created, type, sorting_field, content)" + + " VALUES ($1, $2, $3, $4, $5)" ) .execute(Tuple.of(entry.getId(), toLocalDateTime(entry.getCreated()), - entry.getType(), entry.getContent())) + entry.getType(), entry.getSortingField(), entry.getContent())) .map(rowSet -> { if (rowSet.rowCount() == 0) { throw new ForbiddenException(); @@ -204,11 +202,11 @@ public Future updateEntry(PrintEntry entry) { } return pool.preparedQuery( "UPDATE " + printTable - + " SET created = $2, type = $3, content = $4" + + " SET created = $2, type = $3, sorting_field = $4, content = $5" + " WHERE id = $1" ) .execute(Tuple.of(entry.getId(), toLocalDateTime(entry.getCreated()), - entry.getType(), entry.getContent())) + entry.getType(), entry.getSortingField(), entry.getContent())) .map(rowSet -> { if (rowSet.rowCount() == 0) { throw new NotFoundException(); @@ -342,6 +340,7 @@ private Pair createSqlQuery(String cqlQuery, int offset, int lim definition.addField("id", new PgCqlFieldUuid()); definition.addField("type", new PgCqlFieldText().withExact()); definition.addField("created", new PgCqlFieldTimestamp()); + definition.addField("sortingField", new PgCqlFieldText().withColumn("sorting_field")); PgCqlQuery pgCqlQuery = definition.parse(cqlQuery); String sqlOrderBy = pgCqlQuery.getOrderByClause(); diff --git a/src/main/resources/openapi/batchPrint.yaml b/src/main/resources/openapi/batchPrint.yaml index db7453c..31fdc80 100644 --- a/src/main/resources/openapi/batchPrint.yaml +++ b/src/main/resources/openapi/batchPrint.yaml @@ -158,27 +158,30 @@ paths: - $ref: headers/okapi-user.yaml post: description: > - Create batch print entry for day. - X-Okapi-Permissions must include mod-batch-print.print.write and mod-batch-print.print.read - requestBody: - content: - application/json: - schema: - $ref: schemas/messageRequest.json + Send mail to create print entry. + X-Okapi-Permissions must include mod-batch-print.print.write responses: "200": - description: Batch created - content: - application/json: - schema: - $ref: schemas/messageRequest.json + description: Print entry created "400": $ref: "#/components/responses/trait_400" "403": $ref: "#/components/responses/trait_403" "500": $ref: "#/components/responses/trait_500" - + /print/fake: + parameters: + - $ref: headers/okapi-permissions.yaml + - $ref: headers/okapi-tenant.yaml + - $ref: headers/okapi-token.yaml + - $ref: headers/okapi-url.yaml + - $ref: headers/okapi-user.yaml + post: + description: > + Fake endpoint for service to work + responses: + "200": + description: Fake components: responses: trait_400: diff --git a/src/main/resources/openapi/examples/errors.sample b/src/main/resources/openapi/examples/errors.sample deleted file mode 100644 index 03d7c12..0000000 --- a/src/main/resources/openapi/examples/errors.sample +++ /dev/null @@ -1,15 +0,0 @@ -{ - "errors": [ - { - "message": "may not be null", - "type": "1", - "code": "-1", - "parameters": [ - { - "key": "moduleTo", - "value": "null" - } - ] - } - ] -} diff --git a/src/main/resources/openapi/examples/mailMessage.sample b/src/main/resources/openapi/examples/mailMessage.sample new file mode 100644 index 0000000..2d62c77 --- /dev/null +++ b/src/main/resources/openapi/examples/mailMessage.sample @@ -0,0 +1,9 @@ +{ + "notificationId": "123", + "from": "folio@mail.com", + "to": "user@mail.com", + "outputFormat": "text/html", + "header": "okapi", + "body": "
Dear James

you were charged a Lost item fee
amount: 10.00

Owner: Test owner for cd1
Type: Lost item fee
Status: Cancelled item returned
Date: 1/4/24
Time: 1/4/24, 12:12 PM
Amount: 10.00
Remaining: 0.00
Info:
", + "attachments": [] +} diff --git a/src/main/resources/openapi/schemas/entry.json b/src/main/resources/openapi/schemas/entry.json index a9d2b1f..15592e7 100644 --- a/src/main/resources/openapi/schemas/entry.json +++ b/src/main/resources/openapi/schemas/entry.json @@ -15,6 +15,10 @@ "type": "string", "description": "Print entry type" }, + "sortingField": { + "type": "string", + "description": "Print entry sorting field" + }, "content": { "type": "string", "description": "Print entry content" diff --git a/src/main/resources/openapi/schemas/messageRequest.json b/src/main/resources/openapi/schemas/messageRequest.json index 9de6025..1aba192 100644 --- a/src/main/resources/openapi/schemas/messageRequest.json +++ b/src/main/resources/openapi/schemas/messageRequest.json @@ -3,14 +3,18 @@ "title": "Mail Entity Schema", "type": "object", "properties": { - "deliveryChannel": { - "description":"Delivery channel", + "notificationId": { + "description":"notification ID", "type": "string" }, "from": { "description":"sender's address", "type": "string" }, + "to": { + "description":"receiver's address", + "type": "string" + }, "outputFormat": { "description":"format type: `text/html` or `text/plain`", "type": "string" diff --git a/src/test/java/org/folio/print/server/main/MainVerticleTest.java b/src/test/java/org/folio/print/server/main/MainVerticleTest.java index d814162..c83c0d2 100644 --- a/src/test/java/org/folio/print/server/main/MainVerticleTest.java +++ b/src/test/java/org/folio/print/server/main/MainVerticleTest.java @@ -18,10 +18,13 @@ import org.folio.print.server.data.PrintEntry; import org.folio.print.server.data.PrintEntryType; import org.folio.print.server.service.PrintService; +import org.junit.Ignore; import org.junit.Test; import org.junit.runner.RunWith; import static org.hamcrest.Matchers.containsString; +import static org.hamcrest.Matchers.greaterThan; +import static org.hamcrest.Matchers.greaterThanOrEqualTo; import static org.hamcrest.Matchers.hasSize; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; @@ -48,10 +51,10 @@ public void testCrudGlobalOk() { entry.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC)); entry.setId(UUID.randomUUID()); entry.setType(PrintEntryType.SINGLE); + entry.setSortingField("Last,User"); JsonObject en = JsonObject.mapFrom(entry); - RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) .header(XOkapiHeaders.PERMISSIONS, permWrite.encode()) @@ -249,14 +252,14 @@ public void testNotFound() { JsonObject en = JsonObject.mapFrom(entry); RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) - .header(XOkapiHeaders.PERMISSIONS, permRead) + .header(XOkapiHeaders.PERMISSIONS, permRead.encode()) .get("/print/entries/" + UUID.randomUUID()) .then() .statusCode(404); RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) - .header(XOkapiHeaders.PERMISSIONS, permRead) + .header(XOkapiHeaders.PERMISSIONS, permRead.encode()) .delete("/print/entries/" + UUID.randomUUID()) .then() .statusCode(404); @@ -276,10 +279,10 @@ public void testGetPrintEntries() { PrintEntry entry = new PrintEntry(); entry.setCreated(ZonedDateTime.now().withZoneSameInstant(ZoneOffset.UTC)); entry.setType(PrintEntryType.SINGLE); - String[] ids = new String[3]; for (int i = 0; i < 3; i++) { entry.setId(UUID.randomUUID()); entry.setContent("A" + i); + entry.setSortingField("A" + (5 - i)); entry.setType(i % 2 == 0 ? PrintEntryType.SINGLE : PrintEntryType.BATCH); JsonObject en = JsonObject.mapFrom(entry); RestAssured.given() @@ -290,7 +293,6 @@ public void testGetPrintEntries() { .post("/print/entries") .then() .statusCode(204); - ids[0] = entry.getId().toString(); } RestAssured.given() @@ -300,8 +302,8 @@ public void testGetPrintEntries() { .then() .statusCode(200) .contentType(ContentType.JSON) - .body("items", hasSize(3)) - .body("resultInfo.totalRecords", is(3)); + .body("items", hasSize(greaterThanOrEqualTo(3))) + .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(3))); RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) @@ -312,7 +314,7 @@ public void testGetPrintEntries() { .statusCode(200) .contentType(ContentType.JSON) .body("items", hasSize(0)) - .body("resultInfo.totalRecords", is(3)); + .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(3))); RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) @@ -322,8 +324,8 @@ public void testGetPrintEntries() { .then() .statusCode(200) .contentType(ContentType.JSON) - .body("items", hasSize(2)) - .body("resultInfo.totalRecords", is(2)); + .body("items", hasSize(greaterThanOrEqualTo(2))) + .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2))); RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) @@ -346,9 +348,22 @@ public void testGetPrintEntries() { .then() .statusCode(200) .contentType(ContentType.JSON) - .body("items", hasSize(2)) - .body("resultInfo.totalRecords", is(2)); - cleanEntries(ids); + .body("items", hasSize(greaterThanOrEqualTo(2))) + .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2))); + + + RestAssured.given() + .header(XOkapiHeaders.TENANT, TENANT_1) + .header(XOkapiHeaders.PERMISSIONS, permRead.encode()) + .queryParam("query", "type=\"SINGLE\" sortby sortingField created") + .get("/print/entries") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .body("items", hasSize(greaterThanOrEqualTo(2))) + .body("items[0].sortingField", is("A3")) + .body("items[1].sortingField", is("A5")) + .body("resultInfo.totalRecords", is(greaterThanOrEqualTo(2))); } @Test @@ -371,14 +386,11 @@ public void testSaveMailMessage() throws IOException { RestAssured.given() .header(XOkapiHeaders.TENANT, TENANT_1) .header(XOkapiHeaders.PERMISSIONS, permRead.encode()) - .get("/print/entries") + .get("/print/entries/" + id) .then() .statusCode(200) .contentType(ContentType.JSON) - .body("items", hasSize(1)) - .body("resultInfo.totalRecords", is(1)); - - cleanEntries(id); + .body("content", notNullValue()); } private String getResourceAsString(String name) throws IOException { @@ -389,15 +401,4 @@ private String getResourceAsString(String name) throws IOException { return new String(inputStream.readAllBytes()); } } - - private void cleanEntries(String... ids){ - for(String id : ids){ - RestAssured.given() - .header(XOkapiHeaders.TENANT, TENANT_1) - .header(XOkapiHeaders.PERMISSIONS, permWrite.encode()) - .delete("/print/entries/" + id) - .then() - .statusCode(204); - } - } } diff --git a/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java b/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java index 47ee9e1..330b305 100644 --- a/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java +++ b/src/test/java/org/folio/print/server/resources/BatchCreationResourceTest.java @@ -16,6 +16,7 @@ @RunWith(VertxUnitRunner.class) public class BatchCreationResourceTest extends TestBase { + @Test public void createBatch() throws IOException { String message = getResourceAsString("mail/mail.json"); @@ -23,23 +24,34 @@ public void createBatch() throws IOException { JsonArray perm = new JsonArray().add("mod-batch-print.print.write").add("mod-batch-print.print.read"); RestAssured.given() - .header(XOkapiHeaders.TENANT, TENANT_1) - .header(XOkapiHeaders.PERMISSIONS, perm.encode()) - .contentType(ContentType.JSON) - .body(message) - .post("/mail") - .then() - .statusCode(200) - .contentType(ContentType.JSON) - .body("id", notNullValue()); + .header(XOkapiHeaders.TENANT, TENANT_1) + .header(XOkapiHeaders.PERMISSIONS, perm.encode()) + .contentType(ContentType.JSON) + .body(message) + .post("/mail") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .body("id", notNullValue()); + + RestAssured.given() + .header(XOkapiHeaders.TENANT, TENANT_1) + .header(XOkapiHeaders.PERMISSIONS, perm.encode()) + .contentType(ContentType.JSON) + .body(message) + .post("/mail") + .then() + .statusCode(200) + .contentType(ContentType.JSON) + .body("id", notNullValue()); RestAssured.given() - .header(XOkapiHeaders.TENANT, TENANT_1) - .header(XOkapiHeaders.PERMISSIONS, perm.encode()) - .contentType(ContentType.JSON) - .post("/print/batch-creation") - .then() - .statusCode(200); + .baseUri(MODULE_URL) + .header(XOkapiHeaders.TENANT, TENANT_1) + .header(XOkapiHeaders.PERMISSIONS, perm.encode()) + .post("/print/batch-creation") + .then() + .statusCode(204); } private String getResourceAsString(String name) throws IOException { diff --git a/src/test/resources/mail/mail.json b/src/test/resources/mail/mail.json index 6d3bacc..2d62c77 100644 --- a/src/test/resources/mail/mail.json +++ b/src/test/resources/mail/mail.json @@ -1,6 +1,7 @@ { - "deliveryChannel": "mail", - "from": "user@mail.com", + "notificationId": "123", + "from": "folio@mail.com", + "to": "user@mail.com", "outputFormat": "text/html", "header": "okapi", "body": "
Dear James

you were charged a Lost item fee
amount: 10.00

Owner: Test owner for cd1
Type: Lost item fee
Status: Cancelled item returned
Date: 1/4/24
Time: 1/4/24, 12:12 PM
Amount: 10.00
Remaining: 0.00
Info:
",