From 5856e5163498cdc8e33f220de5af88c33acbe930 Mon Sep 17 00:00:00 2001
From: Anthony Galagade <72087089+agalagade@users.noreply.github.com>
Date: Mon, 9 Jan 2023 16:30:14 +0100
Subject: [PATCH] :FC-1343: :zap: Integration Tests (#100)
* :FC-1343: :zap: Integration Tests
* :zap: removed workflow due to write permissions issues
* :zap: Added the integration test workflow
* :zap: added log
* :zap: update workflow to check env
* :zap: updated the workflow
* :zap: testing Environment variables
* :zap: testing env
* :zap: adding integration test env
* :zap: update
* :zap: added env variables
* :zap: removed the env variables and ignore the integration test
* :zap: ignore integration tests in Java CI
* :zap: update Java CI
* :zap: custom test ignore module
* :zap: applied ignore test on Java CI
* :zap: removed the test log
* :zap: moving test related files to test folder
Co-authored-by: LivePerson FaaS Core Team Account <60709588+LivePersonFaas@users.noreply.github.com>
Co-authored-by: chrbrt <20794486+chrbrt@users.noreply.github.com>
---
.github/workflows/integration-test.maven.yml | 37 +++
.github/workflows/maven-publish.yml | 6 +
.github/workflows/test.maven.yml | 2 +-
pom.xml | 16 ++
.../client/FaaSIntegrationClientTest.java | 272 ++++++++++++++++++
.../faas/util/AuthBearerGenerator.java | 90 ++++++
.../faas/util/BearerConfigResponseObject.java | 49 ++++
.../liveperson/faas/util/BearerResponse.java | 62 ++++
8 files changed, 533 insertions(+), 1 deletion(-)
create mode 100644 .github/workflows/integration-test.maven.yml
create mode 100644 src/test/java/com/liveperson/faas/client/FaaSIntegrationClientTest.java
create mode 100644 src/test/java/com/liveperson/faas/util/AuthBearerGenerator.java
create mode 100644 src/test/java/com/liveperson/faas/util/BearerConfigResponseObject.java
create mode 100644 src/test/java/com/liveperson/faas/util/BearerResponse.java
diff --git a/.github/workflows/integration-test.maven.yml b/.github/workflows/integration-test.maven.yml
new file mode 100644
index 0000000..426b17b
--- /dev/null
+++ b/.github/workflows/integration-test.maven.yml
@@ -0,0 +1,37 @@
+# This workflow will run Integration Tests for the project with Maven, and cache/restore any dependencies to improve the workflow execution time
+# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven
+
+name: Integration Tests
+
+on:
+ pull_request:
+ branches: [ develop, master ]
+
+jobs:
+ build:
+ runs-on: ubuntu-latest
+ steps:
+ - uses: actions/checkout@v3
+ - name: Set up JDK 1.8
+ uses: actions/setup-java@v3
+ with:
+ java-version: 11
+ distribution: 'adopt'
+ server-id: ossrh
+ server-username: OSSRH_USERNAME
+ server-password: OSSRH_PASSWORD
+ gpg-private-key: ${{ secrets.GPG_PRIVATE_KEY_1 }}
+ gpg-passphrase: MAVEN_GPG_PASSPHRASE
+ - name: Integration testing with Maven
+ run: |
+ mvn test -Dtest=FaaSIntegrationClientTest
+ env:
+ ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
+ LAMBDAUUID: ${{ secrets.LAMBDAUUID }}
+ CLIENT_ID: ${{ secrets.CLIENT_ID }}
+ CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
+ USER: ${{ secrets.USER }}
+ PASS: ${{ secrets.PASS }}
+ OSSRH_USERNAME: ${{ secrets.NEXUS_USERNAME }}
+ OSSRH_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
+ MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
diff --git a/.github/workflows/maven-publish.yml b/.github/workflows/maven-publish.yml
index 68d6374..43f3334 100644
--- a/.github/workflows/maven-publish.yml
+++ b/.github/workflows/maven-publish.yml
@@ -30,3 +30,9 @@ jobs:
OSSRH_USERNAME: ${{ secrets.NEXUS_USERNAME }}
OSSRH_PASSWORD: ${{ secrets.NEXUS_PASSWORD }}
MAVEN_GPG_PASSPHRASE: ${{ secrets.GPG_PRIVATE_KEY_PASSPHRASE }}
+ ACCOUNT_ID: ${{ secrets.ACCOUNT_ID }}
+ LAMBDAUUID: ${{ secrets.LAMBDAUUID }}
+ CLIENT_ID: ${{ secrets.CLIENT_ID }}
+ CLIENT_SECRET: ${{ secrets.CLIENT_SECRET }}
+ USER: ${{ secrets.USER }}
+ PASS: ${{ secrets.PASS }}
diff --git a/.github/workflows/test.maven.yml b/.github/workflows/test.maven.yml
index 11591f1..f11dd35 100644
--- a/.github/workflows/test.maven.yml
+++ b/.github/workflows/test.maven.yml
@@ -21,4 +21,4 @@ jobs:
distribution: 'temurin'
cache: maven
- name: Build with Maven
- run: mvn --batch-mode --update-snapshots verify
+ run: mvn --batch-mode --update-snapshots verify -DIntegrationModule.test.excludes="**/*FaaSIntegrationClientTest.java"
diff --git a/pom.xml b/pom.xml
index d5cced1..3ffc1d5 100644
--- a/pom.xml
+++ b/pom.xml
@@ -146,8 +146,24 @@
+
+ org.apache.maven.plugins
+ maven-surefire-plugin
+ 2.9
+
+
+ ${IntegrationModule.test.excludes}
+
+
+
+
+ false
+ ${IntegrationModule.skip.tests}
+ **/*Test.java
+ **/*FaaSIntegrationClientTest.java
+
ossrh
diff --git a/src/test/java/com/liveperson/faas/client/FaaSIntegrationClientTest.java b/src/test/java/com/liveperson/faas/client/FaaSIntegrationClientTest.java
new file mode 100644
index 0000000..62eea42
--- /dev/null
+++ b/src/test/java/com/liveperson/faas/client/FaaSIntegrationClientTest.java
@@ -0,0 +1,272 @@
+package com.liveperson.faas.client;
+
+import com.liveperson.faas.client.types.OptionalParams;
+import com.liveperson.faas.csds.CsdsMapClient;
+import com.liveperson.faas.dto.FaaSInvocation;
+import com.liveperson.faas.exception.*;
+import com.liveperson.faas.http.DefaultRestClient;
+import com.liveperson.faas.metriccollector.MetricCollector;
+import com.liveperson.faas.response.lambda.ErrorLogResponseObject;
+import com.liveperson.faas.response.lambda.LambdaResponse;
+import com.liveperson.faas.security.AuthSignatureBuilder;
+import com.liveperson.faas.util.AuthBearerGenerator;
+import com.liveperson.faas.util.BearerConfigResponseObject;
+import com.liveperson.faas.util.EventResponse;
+import com.liveperson.faas.util.UUIDResponse;
+
+import org.junit.Before;
+import org.junit.Test;
+
+import java.io.IOException;
+import java.util.HashMap;
+import java.util.List;
+import java.util.Map;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+public class FaaSIntegrationClientTest {
+ private static AuthSignature authSignatureBuilder;
+ private FaaSWebClient client;
+ private FaaSWebClient clientWithBearer;
+ private DefaultRestClient restClient = new DefaultRestClient();
+ private MetricCollector metricCollector;
+ private DefaultIsImplementedCache defaultIsImplementedCache;
+ private String accountId = System.getenv("ACCOUNT_ID");
+ private String clientId = System.getenv("CLIENT_ID");
+ private String clientSecret = System.getenv("CLIENT_SECRET");
+ private String userId;
+ private String externalSystem = "test_system";
+ private FaaSEvent event = FaaSEvent.MessagingNewConversation;
+ private String lambdaUUID = System.getenv("LAMBDAUUID");
+ private String requestId = "requestId";
+
+ private int defaultTimeOut = 15000;
+
+ private OptionalParams optionalParams;
+
+ @Before
+ public void before() throws Exception, TokenGenerationException {
+ client = getFaaSClient();
+ authSignatureBuilder = new AuthSignature();
+ clientWithBearer = getFaaSClientBearer();
+ optionalParams = new OptionalParams();
+ optionalParams.setTimeOutInMs(defaultTimeOut);
+ optionalParams.setRequestId(requestId);
+ userId = authSignatureBuilder.getUserId();
+ }
+
+ @Test
+ public void getLambdas() throws Exception {
+ List lambdaResponse = clientWithBearer.getLambdas(userId, new HashMap(),
+ optionalParams);
+ assertTrue(lambdaResponse.size() > 0);
+ assertTrue(lambdaResponse.toString().contains("name"));
+ assertTrue(lambdaResponse.toString().contains("uuid"));
+ assertTrue(lambdaResponse.toString().contains("createdAt"));
+ assertTrue(lambdaResponse.toString().contains("updatedAt"));
+ assertTrue(lambdaResponse.toString().contains("updatedBy"));
+ }
+
+ @Test
+ public void getLambdasWithOptionalQueryParameters() throws Exception {
+ HashMap filterMap = new HashMap();
+ filterMap.put("eventId", "not-existing");
+ List lambdaResponse = clientWithBearer.getLambdas(userId, filterMap, optionalParams);
+ assertTrue(lambdaResponse.size() == 0);
+ }
+
+ @Test(expected = FaaSException.class)
+ public void getLambdasWithInvalidStateValueQueryParameter() throws IOException, FaaSException {
+ try {
+ HashMap filterMap = new HashMap();
+ filterMap.put("state", "active");
+ clientWithBearer.getLambdas(userId, filterMap, optionalParams);
+
+ } catch (FaaSException e) {
+ assertTrue(e.getCause().toString().contains("Received response code 400"));
+ throw e;
+ }
+ }
+
+ @Test
+ public void isImplementedEventRetrievedFromCache() throws Exception {
+ boolean isImplemented = client.isImplemented(externalSystem, event, optionalParams);
+ assertTrue("Lambda should be implemented", isImplemented);
+ }
+
+ @Test
+ public void isImplementedEventRetrievedFromCacheOnNotExistingEvent() throws Exception {
+ boolean isImplemented = client.isImplemented(externalSystem, FaaSEvent.ChatPostSurveyEmailTranscript,
+ optionalParams);
+ assertFalse("Lambda should not be implemented", isImplemented);
+ }
+
+ @Test
+ public void invokeViaEventType() throws Exception {
+ UUIDResponse eventPayload = new UUIDResponse();
+ long timestamp = System.currentTimeMillis();
+ Map headers = getTestHeaders();
+ FaaSInvocation invocationData = getUUIDResponseFaaSInvocation(eventPayload, timestamp, headers);
+ EventResponse[] response = client.invokeByEvent(externalSystem, event, invocationData, EventResponse[].class,
+ optionalParams);
+ assertEquals("Success", response[0].result.value);
+ assertNotNull(response[0].uuid, "The uuid should not be null");
+ }
+
+ @Test
+ public void invokeViaEventTypeWithValidPayload() throws Exception {
+ UUIDResponse eventPayload = new UUIDResponse();
+ eventPayload.value = "validLogs";
+ long timestamp = System.currentTimeMillis();
+ Map headers = getTestHeaders();
+ FaaSInvocation invocationData = getUUIDResponseFaaSInvocation(eventPayload, timestamp, headers);
+ EventResponse[] response = client.invokeByEvent(externalSystem, event, invocationData, EventResponse[].class,
+ optionalParams);
+ assertEquals("With Payload", response[0].result.value);
+ }
+
+ @Test
+ public void invokeViaEventTypeWithNonExistingEvent() throws Exception {
+ UUIDResponse eventPayload = new UUIDResponse();
+ long timestamp = System.currentTimeMillis();
+ Map headers = getTestHeaders();
+ FaaSInvocation invocationData = getUUIDResponseFaaSInvocation(eventPayload, timestamp, headers);
+ EventResponse[] response = client.invokeByEvent(externalSystem, FaaSEvent.ChatPostSurveyEmailTranscript,
+ invocationData, EventResponse[].class, optionalParams);
+ assertTrue(response.length == 0);
+ }
+
+ @Test
+ public void invokeViaUUIDWithRequestId() throws Exception {
+ String payload = "request_data";
+ long timestamp = System.currentTimeMillis();
+ FaaSInvocation invocationData = new FaaSInvocation(null, payload);
+ invocationData.setTimestamp(timestamp);
+ optionalParams.setRequestId(requestId);
+
+ String response = client.invokeByUUID(externalSystem, lambdaUUID, invocationData, String.class, optionalParams);
+ assertEquals("Success", response);
+ }
+
+ @Test
+ public void invokeViaUUIDWithoutPayload() throws Exception {
+ long timestamp = System.currentTimeMillis();
+ FaaSInvocation