Skip to content

Commit

Permalink
cleanup test dependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Dec 29, 2024
1 parent ce94e40 commit b9d9bcf
Show file tree
Hide file tree
Showing 21 changed files with 320 additions and 304 deletions.
2 changes: 1 addition & 1 deletion actions/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ dependencies {
testImplementation project(':fkq-test-utils')
testImplementation project(':fkq-plugins')
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.4'
}

test {
Expand Down
2 changes: 1 addition & 1 deletion aws-ssm/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ dependencies {

testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.7'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.4'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.12.770'
}

Expand Down
4 changes: 2 additions & 2 deletions console/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,9 @@ dependencies {
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.7'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.4'

testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.4'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.12.770'
testImplementation group: 'com.microsoft.playwright', name: 'playwright', version: '1.46.0'
}
Expand Down
4 changes: 2 additions & 2 deletions dynamodb-documents/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ dependencies {
testImplementation group: 'org.slf4j', name: 'slf4j-simple', version: '2.0.7'

testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.4'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.4'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.12.770'

configurations.all {
Expand Down
4 changes: 2 additions & 2 deletions fkq-lambda-core/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,8 +19,8 @@ dependencies {

testImplementation project(':fkq-test-utils')
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.4'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.4'
}

test {
Expand Down
4 changes: 2 additions & 2 deletions fkq-test-utils/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -16,8 +16,8 @@ dependencies {
api group: 'com.formkiq', name: 'client', version:'1.16.1-SNAPSHOT'
implementation group: 'com.google.code.gson', name: 'gson', version: '2.11.0'
implementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
implementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.1'
implementation group: 'org.testcontainers', name: 'localstack', version: '1.20.1'
implementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.4'
implementation group: 'org.testcontainers', name: 'localstack', version: '1.20.4'
api group: 'org.mock-server', name: 'mockserver-netty', version: '5.15.0'
implementation group: 'io.jsonwebtoken', name: 'jjwt-api', version: '0.12.6'
implementation group: 'io.jsonwebtoken', name: 'jjwt-impl', version: '0.12.6'
Expand Down
10 changes: 3 additions & 7 deletions lambda-api/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -61,14 +61,10 @@ dependencies {

testImplementation group: 'commons-codec', name: 'commons-codec', version: '1.17.1'
testImplementation group: 'org.junit.jupiter', name: 'junit-jupiter-engine', version:'5.11.0'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.1'
testImplementation group: 'org.testcontainers', name: 'testcontainers', version: '1.20.4'
testImplementation group: 'org.testcontainers', name: 'junit-jupiter', version: '1.20.4'
testImplementation group: 'org.testcontainers', name: 'localstack', version: '1.20.4'
testImplementation group: 'com.amazonaws', name: 'aws-java-sdk', version: '1.12.770'
testImplementation group: 'org.mock-server', name: 'mockserver-netty', version: '5.15.0'

// TODO remove
testImplementation group: 'com.formkiq.stacks', name: 'client', version:'1.11.0'
}

compileJava {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,17 +23,22 @@
*/
package com.formkiq.stacks.api.awstest;

import static com.formkiq.aws.dynamodb.objects.Objects.notNull;
import static com.formkiq.testutils.aws.FkqDocumentService.addDocument;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForActions;
import static com.formkiq.testutils.aws.FkqDocumentService.waitForDocumentContent;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.io.IOException;
import java.io.InputStream;
import java.net.URISyntaxException;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.concurrent.TimeUnit;

import com.formkiq.client.model.DocumentAction;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.Timeout;
import org.junit.jupiter.api.parallel.Execution;
Expand All @@ -50,10 +55,8 @@
import com.formkiq.client.model.AddDocumentOcrResponse;
import com.formkiq.client.model.DocumentActionStatus;
import com.formkiq.client.model.DocumentActionType;
import com.formkiq.client.model.GetDocumentActionsResponse;
import com.formkiq.client.model.GetDocumentOcrResponse;
import com.formkiq.client.model.OcrEngine;
import com.formkiq.stacks.client.models.DocumentOcr;
import com.formkiq.testutils.aws.AbstractAwsIntegrationTest;
import software.amazon.awssdk.utils.IoUtils;

Expand All @@ -73,11 +76,10 @@ public class DocumentsDocumentIdOcrRequestTest extends AbstractAwsIntegrationTes
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddOcr01a() throws Exception {
String siteId = null;
ApiClient client = getApiClients(siteId).get(0);
addOcr01(client, siteId);
ApiClient client = getApiClients(null).get(0);
addOcr01(client, null);
}

/**
Expand All @@ -86,7 +88,7 @@ public void testAddOcr01a() throws Exception {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddOcr01b() throws Exception {
String siteId = SITE_ID;
ApiClient client = getApiClients(siteId).get(0);
Expand All @@ -109,6 +111,7 @@ private void addOcr01(final ApiClient client, final String siteId)
assertEquals("OCR request submitted", response.getMessage());

GetDocumentOcrResponse documentOcr = getDocumentOcr(api, siteId, documentId);
assertNotNull(documentOcr.getData());
assertTrue(documentOcr.getData().contains("East Repair"));
}

Expand All @@ -118,12 +121,10 @@ private void addOcr01(final ApiClient client, final String siteId)
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddOcr02a() throws Exception {

String siteId = null;
ApiClient client = getApiClients(siteId).get(0);
addOcr02(client, siteId);
ApiClient client = getApiClients(null).get(0);
addOcr02(client, null);
}

/**
Expand All @@ -132,7 +133,7 @@ public void testAddOcr02a() throws Exception {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddOcr02b() throws Exception {

String siteId = SITE_ID;
Expand All @@ -148,39 +149,39 @@ private void addOcr02(final ApiClient client, final String siteId)

DocumentActionsApi actionsApi = new DocumentActionsApi(client);
AddDocumentActionsRequest req = new AddDocumentActionsRequest()
.actions(Arrays.asList(new AddAction().type(DocumentActionType.OCR)));
.actions(List.of(new AddAction().type(DocumentActionType.OCR)));

// when
AddDocumentActionsResponse response = actionsApi.addDocumentActions(documentId, siteId, req);

// then
assertEquals("Actions saved", response.getMessage());
waitForActions(client, siteId, documentId, Arrays.asList(DocumentActionStatus.COMPLETE));
waitForActions(client, siteId, documentId, List.of(DocumentActionStatus.COMPLETE));

DocumentOcrApi api = new DocumentOcrApi(client);
GetDocumentOcrResponse documentOcr =
api.getDocumentOcr(documentId, siteId, null, null, null, null);
assertNotNull(documentOcr.getData());
assertTrue(documentOcr.getData().contains("East Repair"));

GetDocumentActionsResponse actions =
actionsApi.getDocumentActions(documentId, siteId, null, null, null);
assertEquals(1, actions.getActions().size());
assertEquals("COMPLETE", actions.getActions().get(0).getStatus().name());
List<DocumentAction> actions =
notNull(actionsApi.getDocumentActions(documentId, siteId, null, null, null).getActions());
assertEquals(1, actions.size());
assertEquals(DocumentActionStatus.COMPLETE, Objects.requireNonNull(actions.get(0).getStatus()));
}

/**
* Wait for {@link DocumentOcr} to have data.
* Wait for {@link DocumentOcrApi} to have data.
*
* @param api {@link DocumentOcrApi}
* @param siteId {@link String}
* @param documentId {@link String}
* @return {@link GetDocumentOcrResponse}
* @throws IOException IOException
* @throws InterruptedException InterruptedException
* @throws ApiException ApiException
*/
private GetDocumentOcrResponse getDocumentOcr(final DocumentOcrApi api, final String siteId,
final String documentId) throws IOException, InterruptedException, ApiException {
final String documentId) throws InterruptedException, ApiException {

GetDocumentOcrResponse documentOcr =
api.getDocumentOcr(documentId, siteId, null, null, null, null);
Expand All @@ -199,6 +200,7 @@ private GetDocumentOcrResponse getDocumentOcr(final DocumentOcrApi api, final St

private byte[] toBytes(final String name) throws IOException {
try (InputStream is = getClass().getResourceAsStream(name)) {
assertNotNull(is);
return IoUtils.toByteArray(is);
}
}
Expand All @@ -209,41 +211,41 @@ private byte[] toBytes(final String name) throws IOException {
* @throws Exception Exception
*/
@Test
@Timeout(unit = TimeUnit.SECONDS, value = TEST_TIMEOUT)
@Timeout(value = TEST_TIMEOUT)
public void testAddOcr03() throws Exception {
String siteId = null;
ApiClient client = getApiClients(siteId).get(0);
ApiClient client = getApiClients(null).get(0);

byte[] content = toBytes("/multipage_example.pdf");
String documentId =
addDocument(client, siteId, "multipage_example.pdf", content, "application/pdf", null);
waitForDocumentContent(client, siteId, documentId);
addDocument(client, null, "multipage_example.pdf", content, "application/pdf", null);
waitForDocumentContent(client, null, documentId);

DocumentActionsApi actionsApi = new DocumentActionsApi(client);
AddDocumentActionsRequest req = new AddDocumentActionsRequest()
.actions(Arrays.asList(new AddAction().type(DocumentActionType.OCR).parameters(
.actions(List.of(new AddAction().type(DocumentActionType.OCR).parameters(
new AddActionParameters().ocrEngine(OcrEngine.TESSERACT).ocrNumberOfPages("2"))));

// when
AddDocumentActionsResponse response = actionsApi.addDocumentActions(documentId, siteId, req);
AddDocumentActionsResponse response = actionsApi.addDocumentActions(documentId, null, req);

// then
assertEquals("Actions saved", response.getMessage());
waitForActions(client, siteId, documentId, Arrays.asList(DocumentActionStatus.COMPLETE));
waitForActions(client, null, documentId, List.of(DocumentActionStatus.COMPLETE));

DocumentOcrApi api = new DocumentOcrApi(client);
GetDocumentOcrResponse documentOcr =
api.getDocumentOcr(documentId, siteId, null, null, null, null);
api.getDocumentOcr(documentId, null, null, null, null, null);

String text = documentOcr.getData();
assertNotNull(text);
assertTrue(text.contains("Your Company"));
assertTrue(text.contains("2/9"));
assertFalse(text.contains("3/9"));
assertFalse(text.contains("Current process"));

GetDocumentActionsResponse actions =
actionsApi.getDocumentActions(documentId, siteId, null, null, null);
assertEquals(1, actions.getActions().size());
assertEquals("COMPLETE", actions.getActions().get(0).getStatus().name());
List<DocumentAction> actions =
notNull(actionsApi.getDocumentActions(documentId, null, null, null, null).getActions());
assertEquals(1, actions.size());
assertEquals(DocumentActionStatus.COMPLETE, actions.get(0).getStatus());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -40,15 +40,12 @@
import java.net.URI;
import java.net.URISyntaxException;
import java.net.http.HttpClient;
import java.net.http.HttpHeaders;
import java.net.http.HttpRequest;
import java.net.http.HttpRequest.BodyPublishers;
import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.text.SimpleDateFormat;
import java.util.Arrays;
import java.util.Collections;
import java.util.Date;
import java.util.List;
import java.util.Map;
Expand All @@ -70,6 +67,9 @@
import com.formkiq.client.model.DocumentActionType;
import com.formkiq.client.model.DocumentAttribute;
import com.formkiq.client.model.GetAttributeResponse;
import com.formkiq.module.http.HttpHeaders;
import com.formkiq.module.http.HttpService;
import com.formkiq.module.http.HttpServiceJdk11;
import com.formkiq.stacks.dynamodb.attributes.AttributeKeyReserved;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.jupiter.api.AfterAll;
Expand Down Expand Up @@ -100,13 +100,9 @@
import com.formkiq.client.model.GetDocumentTagsResponse;
import com.formkiq.client.model.GetDocumentsResponse;
import com.formkiq.client.model.UpdateDocumentRequest;
import com.formkiq.stacks.client.HttpService;
import com.formkiq.stacks.client.HttpServiceJava;
import com.formkiq.stacks.client.models.AddDocument;
import com.formkiq.stacks.dynamodb.ConfigService;
import com.formkiq.testutils.aws.AbstractAwsIntegrationTest;
import com.google.gson.Gson;
import software.amazon.awssdk.core.sync.RequestBody;

/**
* GET, OPTIONS, POST /documents. Tests.
Expand Down Expand Up @@ -626,10 +622,6 @@ public void testPost05() throws Exception {
ApiClient fclient = getApiClientForUser(FINANCE_EMAIL, USER_PASSWORD);
DocumentsApi fapi = new DocumentsApi(fclient);

AddDocument post = new AddDocument();
post.content("dummy data", StandardCharsets.UTF_8);
post.contentType("application/pdf");

AddDocumentRequest req =
new AddDocumentRequest().content("dummy data").contentType("application/pdf");

Expand All @@ -655,10 +647,6 @@ public void testPost06() throws Exception {
// given
configService.save(SITEID1, new DynamicObject(Map.of(MAX_DOCUMENTS, "1")));

AddDocument post = new AddDocument();
post.content("dummy data", StandardCharsets.UTF_8);
post.contentType("application/pdf");

ApiClient c = getApiClients(SITEID1).get(0);
DocumentsApi api = new DocumentsApi(c);
AddDocumentRequest req =
Expand Down Expand Up @@ -784,17 +772,16 @@ public void testPost08() throws Exception {
ApiClient client = getApiClients(null).get(0);
String url = client.getBasePath() + "/documents";

Map<String, List<String>> headers =
Map.of("Authorization", Collections.singletonList(getAdminToken().idToken()));
Optional<HttpHeaders> o = Optional.of(HttpHeaders.of(headers, (t, u) -> true));
Optional<HttpHeaders> o =
Optional.of(new HttpHeaders().add("Authorization", getAdminToken().idToken()));

String content = "{\"path\": \"test.txt\",\"contentType\":\"text/plain\","
+ "\"content\":\"dGhpcyBpcyBhIHRlc3Q=\","
+ "\"tags\":[{\"key\":\"author\",\"value\":\"Pierre Loti\"}]}";

// when
HttpService hs = new HttpServiceJava();
HttpResponse<String> response = hs.post(url, o, RequestBody.fromString(content));
HttpService hs = new HttpServiceJdk11();
HttpResponse<String> response = hs.post(url, o, Optional.empty(), content);

// then
assertEquals(STATUS_CREATED, response.statusCode());
Expand Down
Loading

0 comments on commit b9d9bcf

Please sign in to comment.