Skip to content

Commit

Permalink
[PRDP-127] Cleaned & updated integration tests - changed main package…
Browse files Browse the repository at this point in the history
… name
  • Loading branch information
svariant committed Sep 5, 2023
1 parent b4031fb commit 5b489af
Show file tree
Hide file tree
Showing 74 changed files with 195 additions and 288 deletions.
4 changes: 2 additions & 2 deletions docker/run_docker.sh
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ done

stack_name=$(cd .. && basename "$PWD")
docker compose -p "${stack_name}" up -d --remove-orphans --force-recreate --build
#docker build -t receipt-pdf-datastore ../
# docker run -d -p 60486:80 --name="${stack_name}" receipt-pdf-datastore
#docker build -t receipt-pdf-generator ../
# docker run -d -p 60486:80 --name="${stack_name}" receipt-pdf-generator

# waiting the containers
printf 'Waiting for the service'
Expand Down
4 changes: 0 additions & 4 deletions integration-test/src/config/.env.dev
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
BIZEVENTS_COSMOS_CONN_STRING=<cosmos-connection-string>
BIZ_EVENT_COSMOS_DB_NAME=db
BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events

RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
Expand Down
4 changes: 0 additions & 4 deletions integration-test/src/config/.env.local
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
BIZEVENTS_COSMOS_CONN_STRING=<cosmos-connection-string>
BIZ_EVENT_COSMOS_DB_NAME=db
BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events

RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
Expand Down
4 changes: 0 additions & 4 deletions integration-test/src/config/.env.uat
Original file line number Diff line number Diff line change
@@ -1,7 +1,3 @@
BIZEVENTS_COSMOS_CONN_STRING=<cosmos-connection-string>
BIZ_EVENT_COSMOS_DB_NAME=db
BIZ_EVENT_COSMOS_DB_CONTAINER_NAME=biz-events

RECEIPTS_COSMOS_CONN_STRING=<cosmos-connection-string>
RECEIPT_COSMOS_DB_NAME=db
RECEIPT_COSMOS_DB_CONTAINER_NAME=receipts
Expand Down
48 changes: 24 additions & 24 deletions integration-test/src/features/receipt_pdf_datastore.feature
Original file line number Diff line number Diff line change
@@ -1,44 +1,44 @@
Feature: All about payment events consumed by Azure functions receipt-pdf-datastore
Feature: All about payment events consumed by Azure functions receipt-pdf-generator

Scenario: a biz event stored on biz-events datastore is stored into receipts datastore
Given a random biz event with id "receipt-datastore-int-test-id-1" stored on biz-events datastore with status DONE
When biz event has been properly stored into receipt datastore after 10000 ms with eventId "receipt-datastore-int-test-id-1"
Then the receipts datastore returns the receipt
And the receipt has eventId "receipt-datastore-int-test-id-1"
Scenario: a biz event stored on biz-events generator is stored into receipts generator
Given a random biz event with id "receipt-generator-int-test-id-1" stored on biz-events generator with status DONE
When biz event has been properly stored into receipt generator after 10000 ms with eventId "receipt-generator-int-test-id-1"
Then the receipts generator returns the receipt
And the receipt has eventId "receipt-generator-int-test-id-1"
And the receipt has not the status "NOT_QUEUE_SENT"

Scenario: a biz event enqueued on receipts queue trigger the PDF receipt generation that is stored on receipts datastore and blob storage
Given a receipt with id "receipt-datastore-int-test-id-2" stored into receipt datastore
And a random biz event with id "receipt-datastore-int-test-id-2" enqueued on receipts queue
Scenario: a biz event enqueued on receipts queue trigger the PDF receipt generation that is stored on receipts generator and blob storage
Given a receipt with id "receipt-generator-int-test-id-2" stored into receipt generator
And a random biz event with id "receipt-generator-int-test-id-2" enqueued on receipts queue
When the PDF receipt has been properly generate from biz event after 20000 ms
Then the receipts datastore returns the receipt
And the receipt has eventId "receipt-datastore-int-test-id-2"
Then the receipts generator returns the receipt
And the receipt has eventId "receipt-generator-int-test-id-2"
And the receipt has not the status "NOT_QUEUE_SENT"
And the receipt has not the status "INSERTED"
And the blob storage has the PDF document

Scenario: a biz event enqueued on receipts poison queue is enqueued on receipt queue that trigger the PDF receipt generation
Given a receipt with id "receipt-datastore-int-test-id-3" stored into receipt datastore
And a random biz event with id "receipt-datastore-int-test-id-3" enqueued on receipts poison queue with poison retry "false"
Given a receipt with id "receipt-generator-int-test-id-3" stored into receipt generator
And a random biz event with id "receipt-generator-int-test-id-3" enqueued on receipts poison queue with poison retry "false"
When the PDF receipt has been properly generate from biz event after 20000 ms
Then the receipts datastore returns the receipt
And the receipt has eventId "receipt-datastore-int-test-id-3"
Then the receipts generator returns the receipt
And the receipt has eventId "receipt-generator-int-test-id-3"
And the receipt has not the status "NOT_QUEUE_SENT"
And the receipt has not the status "INSERTED"
And the blob storage has the PDF document

Scenario: a biz event enqueued on receipts poison queue is stored on receipt-message-error datastore
Given a random biz event with id "receipt-datastore-int-test-id-4" enqueued on receipts poison queue with poison retry "true"
When the biz event has been properly stored on receipt-message-error datastore after 20000 ms
Then the receipt-message-error datastore returns the error receipt
Scenario: a biz event enqueued on receipts poison queue is stored on receipt-message-error generator
Given a random biz event with id "receipt-generator-int-test-id-4" enqueued on receipts poison queue with poison retry "true"
When the biz event has been properly stored on receipt-message-error generator after 20000 ms
Then the receipt-message-error generator returns the error receipt
And the error receipt has the status "TO_REVIEW"

Scenario: a biz event stored on receipt-message-error datastore is enqueued on receipt queue that trigger the PDF receipt generation
Given a receipt with id "receipt-datastore-int-test-id-5" stored into receipt datastore
And a error receipt with id "receipt-datastore-int-test-id-5" stored into receipt-message-error datastore with status REVIEWED
Scenario: a biz event stored on receipt-message-error generator is enqueued on receipt queue that trigger the PDF receipt generation
Given a receipt with id "receipt-generator-int-test-id-5" stored into receipt generator
And a error receipt with id "receipt-generator-int-test-id-5" stored into receipt-message-error generator with status REVIEWED
When the PDF receipt has been properly generate from biz event after 20000 ms
Then the receipts datastore returns the receipt
And the receipt has eventId "receipt-datastore-int-test-id-5"
Then the receipts generator returns the receipt
And the receipt has eventId "receipt-generator-int-test-id-5"
And the receipt has not the status "NOT_QUEUE_SENT"
And the receipt has not the status "INSERTED"
And the blob storage has the PDF document

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
const assert = require('assert');
const { After, Given, When, Then, setDefaultTimeout } = require('@cucumber/cucumber');
const { sleep, createEventForQueue, createEventForPoisonQueue } = require("./common");
const { createDocumentInBizEventsDatastore, deleteDocumentFromBizEventsDatastore } = require("./biz_events_datastore_client");
const { getDocumentByIdFromReceiptsDatastore, deleteDocumentFromErrorReceiptsDatastoreByMessagePayload, deleteDocumentFromReceiptsDatastoreByEventId, deleteDocumentFromReceiptsDatastore, createDocumentInReceiptsDatastore, createDocumentInErrorReceiptsDatastore, deleteDocumentFromErrorReceiptsDatastore, getDocumentByMessagePayloadFromErrorReceiptsDatastore } = require("./receipts_datastore_client");
const { putMessageOnPoisonQueue, putMessageOnReceiptQueue } = require("./reqeipt_queue_client");
const { receiptPDFExist } = require("./receipts_blob_storage_client");
Expand All @@ -18,10 +17,7 @@ this.event = null;

// After each Scenario
After(async function () {
// remove event
if (this.eventId != null) {
await deleteDocumentFromBizEventsDatastore(this.eventId);
}
// remove documents
if (this.eventId != null && this.receiptId != null) {
await deleteDocumentFromReceiptsDatastore(this.receiptId, this.eventId);
}
Expand All @@ -35,39 +31,8 @@ After(async function () {
this.event = null;
});

Given('a random biz event with id {string} stored on biz-events datastore with status DONE', async function (id) {
this.eventId = id;
// prior cancellation to avoid dirty cases
await deleteDocumentFromBizEventsDatastore(this.eventId);
await deleteDocumentFromReceiptsDatastoreByEventId(this.eventId);

let bizEventStoreResponse = await createDocumentInBizEventsDatastore(this.eventId);
assert.strictEqual(bizEventStoreResponse.statusCode, 201);
});

When('biz event has been properly stored into receipt datastore after {int} ms with eventId {string}', async function (time, eventId) {
// boundary time spent by azure function to process event
await sleep(time);
this.responseToCheck = await getDocumentByIdFromReceiptsDatastore(eventId);
});

Then('the receipts datastore returns the receipt', async function () {
assert.notStrictEqual(this.responseToCheck.resources.length, 0);
this.receiptId = this.responseToCheck.resources[0].id;
assert.strictEqual(this.responseToCheck.resources.length, 1);
});

Then('the receipt has eventId {string}', function (targetId) {
assert.strictEqual(this.responseToCheck.resources[0].eventId, targetId);
});

Then('the receipt has not the status {string}', function (targetStatus) {
assert.notStrictEqual(this.responseToCheck.resources[0].status, targetStatus);
});



Given('a receipt with id {string} stored into receipt datastore', async function (id) {
Given('a receipt with id {string} stored into receipt generator', async function (id) {
this.eventId = id;
// prior cancellation to avoid dirty cases
await deleteDocumentFromReceiptsDatastore(this.eventId, this.eventId);
Expand Down Expand Up @@ -104,13 +69,13 @@ Given('a random biz event with id {string} enqueued on receipts poison queue wit
await putMessageOnPoisonQueue(this.event);
});

When('the biz event has been properly stored on receipt-message-error datastore after {int} ms', async function (time) {
When('the biz event has been properly stored on receipt-message-error generator after {int} ms', async function (time) {
// boundary time spent by azure function to process event
await sleep(time);
this.responseToCheck = await getDocumentByMessagePayloadFromErrorReceiptsDatastore(this.event);
});

Then('the receipt-message-error datastore returns the error receipt', async function () {
Then('the receipt-message-error generator returns the error receipt', async function () {
assert.notStrictEqual(this.responseToCheck.resources.length, 0);
this.errorReceiptId = this.responseToCheck.resources[0].id;
assert.strictEqual(this.responseToCheck.resources.length, 1);
Expand All @@ -123,7 +88,7 @@ Then('the error receipt has the status {string}', function (targetStatus) {



Given('a error receipt with id {string} stored into receipt-message-error datastore with status REVIEWED', async function (id) {
Given('a error receipt with id {string} stored into receipt-message-error generator with status REVIEWED', async function (id) {
assert.strictEqual(this.eventId, id);
let response = await createDocumentInErrorReceiptsDatastore(id);
assert.strictEqual(response.statusCode, 201);
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.receipt.pdf.datastore;
package it.gov.pagopa.receipt.pdf.generator;

import com.fasterxml.jackson.core.JsonProcessingException;
import com.microsoft.azure.functions.ExecutionContext;
Expand All @@ -7,15 +7,15 @@
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.QueueOutput;
import com.microsoft.azure.functions.annotation.QueueTrigger;
import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptCosmosClientImpl;
import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.enumeration.ReceiptStatusType;
import it.gov.pagopa.receipt.pdf.datastore.exception.BizEventNotValidException;
import it.gov.pagopa.receipt.pdf.datastore.exception.ReceiptNotFoundException;
import it.gov.pagopa.receipt.pdf.datastore.model.PdfGeneration;
import it.gov.pagopa.receipt.pdf.datastore.service.GenerateReceiptPdfService;
import it.gov.pagopa.receipt.pdf.datastore.utils.ObjectMapperUtils;
import it.gov.pagopa.receipt.pdf.generator.client.impl.ReceiptCosmosClientImpl;
import it.gov.pagopa.receipt.pdf.generator.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReceiptStatusType;
import it.gov.pagopa.receipt.pdf.generator.exception.BizEventNotValidException;
import it.gov.pagopa.receipt.pdf.generator.exception.ReceiptNotFoundException;
import it.gov.pagopa.receipt.pdf.generator.model.PdfGeneration;
import it.gov.pagopa.receipt.pdf.generator.service.GenerateReceiptPdfService;
import it.gov.pagopa.receipt.pdf.generator.utils.ObjectMapperUtils;
import org.apache.http.HttpStatus;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.receipt.pdf.datastore;
package it.gov.pagopa.receipt.pdf.generator;

import com.microsoft.azure.functions.ExecutionContext;
import com.microsoft.azure.functions.HttpMethod;
Expand All @@ -8,14 +8,13 @@
import com.microsoft.azure.functions.annotation.AuthorizationLevel;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.HttpTrigger;
import it.gov.pagopa.receipt.pdf.datastore.model.AppInfo;
import it.gov.pagopa.receipt.pdf.generator.model.AppInfo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.io.InputStream;
import java.util.Optional;
import java.util.Properties;
import java.util.logging.Level;


/**
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.receipt.pdf.datastore;
package it.gov.pagopa.receipt.pdf.generator;

import com.azure.core.http.rest.Response;
import com.azure.storage.queue.models.SendMessageResult;
Expand All @@ -9,12 +9,12 @@
import com.microsoft.azure.functions.annotation.CosmosDBOutput;
import com.microsoft.azure.functions.annotation.FunctionName;
import com.microsoft.azure.functions.annotation.QueueTrigger;
import it.gov.pagopa.receipt.pdf.datastore.client.impl.ReceiptQueueClientImpl;
import it.gov.pagopa.receipt.pdf.datastore.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.ReceiptError;
import it.gov.pagopa.receipt.pdf.datastore.entity.receipt.enumeration.ReceiptErrorStatusType;
import it.gov.pagopa.receipt.pdf.datastore.exception.UnableToQueueException;
import it.gov.pagopa.receipt.pdf.datastore.utils.ObjectMapperUtils;
import it.gov.pagopa.receipt.pdf.generator.client.impl.ReceiptQueueClientImpl;
import it.gov.pagopa.receipt.pdf.generator.entity.event.BizEvent;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.ReceiptError;
import it.gov.pagopa.receipt.pdf.generator.entity.receipt.enumeration.ReceiptErrorStatusType;
import it.gov.pagopa.receipt.pdf.generator.exception.UnableToQueueException;
import it.gov.pagopa.receipt.pdf.generator.utils.ObjectMapperUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.gov.pagopa.receipt.pdf.generator.client;

import it.gov.pagopa.receipt.pdf.generator.model.request.PdfEngineRequest;
import it.gov.pagopa.receipt.pdf.generator.model.response.PdfEngineResponse;

public interface PdfEngineClient {

PdfEngineResponse generatePDF(PdfEngineRequest pdfEngineRequest);
}
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package it.gov.pagopa.receipt.pdf.datastore.client;
package it.gov.pagopa.receipt.pdf.generator.client;

import it.gov.pagopa.receipt.pdf.datastore.model.response.BlobStorageResponse;
import it.gov.pagopa.receipt.pdf.generator.model.response.BlobStorageResponse;

import java.io.InputStream;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package it.gov.pagopa.receipt.pdf.generator.client;

import it.gov.pagopa.receipt.pdf.generator.entity.receipt.Receipt;
import it.gov.pagopa.receipt.pdf.generator.exception.ReceiptNotFoundException;

public interface ReceiptCosmosClient {

Receipt getReceiptDocument(String receiptId) throws ReceiptNotFoundException;
}
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
package it.gov.pagopa.receipt.pdf.datastore.client;
package it.gov.pagopa.receipt.pdf.generator.client;

import com.azure.core.http.rest.Response;
import com.azure.storage.queue.models.SendMessageResult;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package it.gov.pagopa.receipt.pdf.datastore.client.impl;
package it.gov.pagopa.receipt.pdf.generator.client.impl;

import it.gov.pagopa.receipt.pdf.datastore.client.PdfEngineClient;
import it.gov.pagopa.receipt.pdf.datastore.model.PdfEngineErrorResponse;
import it.gov.pagopa.receipt.pdf.datastore.model.request.PdfEngineRequest;
import it.gov.pagopa.receipt.pdf.datastore.model.response.PdfEngineResponse;
import it.gov.pagopa.receipt.pdf.datastore.utils.ObjectMapperUtils;
import it.gov.pagopa.receipt.pdf.generator.client.PdfEngineClient;
import it.gov.pagopa.receipt.pdf.generator.model.PdfEngineErrorResponse;
import it.gov.pagopa.receipt.pdf.generator.model.request.PdfEngineRequest;
import it.gov.pagopa.receipt.pdf.generator.model.response.PdfEngineResponse;
import it.gov.pagopa.receipt.pdf.generator.utils.ObjectMapperUtils;
import org.apache.commons.io.FileUtils;
import org.apache.http.HttpEntity;
import org.apache.http.HttpStatus;
Expand Down
Loading

0 comments on commit 5b489af

Please sign in to comment.