Skip to content

Commit

Permalink
update
Browse files Browse the repository at this point in the history
  • Loading branch information
mfriesen committed Jun 2, 2024
1 parent 51e38c7 commit 5ec432a
Show file tree
Hide file tree
Showing 12 changed files with 186 additions and 37 deletions.
18 changes: 18 additions & 0 deletions docs/openapi/openapi-iam.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,24 @@
type: object
additionalProperties:
type: object
attributes:
type: object
additionalProperties:
type: object
properties:
stringValues:
type: array
description: Attribute with string values
items:
type: string
numberValues:
type: array
description: Attribute with number values
items:
type: number
booleanValue:
type: boolean
description: Attribute with boolean value
GetDocumentSyncResponse:
type: object
properties:
Expand Down
18 changes: 18 additions & 0 deletions docs/openapi/openapi-jwt.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,24 @@
type: object
additionalProperties:
type: object
attributes:
type: object
additionalProperties:
type: object
properties:
stringValues:
type: array
description: Attribute with string values
items:
type: string
numberValues:
type: array
description: Attribute with number values
items:
type: number
booleanValue:
type: boolean
description: Attribute with boolean value
GetDocumentSyncResponse:
type: object
properties:
Expand Down
18 changes: 18 additions & 0 deletions docs/openapi/openapi-key.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -7086,6 +7086,24 @@
type: object
additionalProperties:
type: object
attributes:
type: object
additionalProperties:
type: object
properties:
stringValues:
type: array
description: Attribute with string values
items:
type: string
numberValues:
type: array
description: Attribute with number values
items:
type: number
booleanValue:
type: boolean
description: Attribute with boolean value
GetDocumentSyncResponse:
type: object
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,8 @@
import java.io.ByteArrayOutputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;
Expand All @@ -50,9 +50,9 @@
public abstract class AbstractFormKiqApiResponseCallback implements ExpectationResponseCallback {

/** {@link Context}. */
private Context context = new LambdaContextRecorder();
private final Context context = new LambdaContextRecorder();
/** {@link Gson}. */
private Gson gson = new GsonBuilder().disableHtmlEscaping().create();
private final Gson gson = new GsonBuilder().disableHtmlEscaping().create();
/** Environment Map. */
private Map<String, String> environment = null;

Expand All @@ -73,11 +73,12 @@ private HttpResponse createResponse(final String response) {
Map<String, Object> map = this.gson.fromJson(response, Map.class);
Map<String, String> headerList = (Map<String, String>) map.get("headers");
List<Header> headers = headerList.entrySet().stream()
.map(e -> new Header(e.getKey(), Arrays.asList(e.getValue()))).collect(Collectors.toList());
.map(e -> new Header(e.getKey(), Collections.singletonList(e.getValue())))
.collect(Collectors.toList());

int statusCode = ((Double) map.get("statusCode")).intValue();
return HttpResponse.response().withHeaders(new Headers(headers))
.withStatusCode(Integer.valueOf(statusCode)).withBody(map.get("body").toString());
return HttpResponse.response().withHeaders(new Headers(headers)).withStatusCode(statusCode)
.withBody(map.get("body").toString());
}

/**
Expand Down Expand Up @@ -110,7 +111,7 @@ public HttpResponse handle(final HttpRequest httpRequest) throws Exception {
ByteArrayOutputStream outstream = new ByteArrayOutputStream();
getHandler().handleRequest(is, outstream, this.context);

String response = new String(outstream.toByteArray(), "UTF-8");
String response = outstream.toString(StandardCharsets.UTF_8);
return createResponse(response);
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
/**
* MIT License
*
* Copyright (c) 2018 - 2020 FormKiQ
*
* Permission is hereby granted, free of charge, to any person obtaining a copy
* of this software and associated documentation files (the "Software"), to deal
* in the Software without restriction, including without limitation the rights
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the Software is
* furnished to do so, subject to the following conditions:
*
* The above copyright notice and this permission notice shall be included in all
* copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
* SOFTWARE.
*/
package com.formkiq.testutils.aws;

import java.util.Map;

/**
* FormKiQ API Extension Config.
*/
public interface FormKiQApiExtensionConfig {
/**
* Get Environment Map.
*
* @return Map
*/
Map<String, String> getEnvironment();
}
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ public class FormKiqApiExtension

/** {@link Random}. */
private static final Random NUM_RAND = new Random();
/** {@link FormKiQApiExtensionConfig}. */
private final FormKiQApiExtensionConfig config;

/**
* Generate Random Port.
Expand All @@ -65,40 +67,38 @@ public static int generatePort() {
}

/** {@link AbstractFormKiqApiResponseCallback}. */
private AbstractFormKiqApiResponseCallback callback;
private final AbstractFormKiqApiResponseCallback callback;
/** Environment {@link Map}. */
private Map<String, String> environmentMap;
/** {@link Map}. */
private Map<String, String> extraEnvironmentMap;

/** {@link ClientAndServer}. */
private ClientAndServer formkiqServer;
/** {@link LocalStackExtension}. */
private LocalStackExtension localStackExtension;
private final LocalStackExtension localStackExtension;
/** Port to run Test server. */
private int port = -1;
private final int port;
/** Is server running. */
private boolean running = false;
/** {@link TypesenseExtension}. */
private TypesenseExtension typeSenseExtension;
private final TypesenseExtension typeSenseExtension;

/**
* constructor.
*
* @param localstack {@link LocalStackExtension}
* @param typeSense {@link TypesenseExtension}
* @param extraEnvironment {@link Map}
* @param extensionConfig {@link FormKiQApiExtensionConfig}
* @param responseCallback {@link AbstractFormKiqApiResponseCallback}
*/
public FormKiqApiExtension(final LocalStackExtension localstack,
final TypesenseExtension typeSense, final Map<String, String> extraEnvironment,
final TypesenseExtension typeSense, final FormKiQApiExtensionConfig extensionConfig,
final AbstractFormKiqApiResponseCallback responseCallback) {

this.localStackExtension = localstack;
this.typeSenseExtension = typeSense;
this.port = generatePort();
this.callback = responseCallback;
this.extraEnvironmentMap = extraEnvironment;
this.config = extensionConfig;
}

@Override
Expand All @@ -110,7 +110,7 @@ public void beforeAll(final ExtensionContext context) throws Exception {

this.callback.setEnvironmentMap(this.environmentMap);

this.formkiqServer = startClientAndServer(Integer.valueOf(this.port));
this.formkiqServer = startClientAndServer(this.port);

this.formkiqServer.when(request()).respond(this.callback);
this.running = true;
Expand All @@ -129,14 +129,17 @@ public void close() throws Throwable {

private Map<String, String> generateMap() {

Map<String, String> map = new HashMap<>(this.extraEnvironmentMap);
Map<String, String> map = new HashMap<>();

if (this.config != null) {
map.putAll(this.config.getEnvironment());
}

if (this.localStackExtension != null) {
map.put("SNS_DOCUMENT_EVENT", this.localStackExtension.getSnsDocumentEvent());
map.put("SQS_DOCUMENT_EVENT_URL", this.localStackExtension.getSqsDocumentEventUrl());
}

// map.put("DOCUMENT_VERSIONS_PLUGIN", DocumentVersionServiceNoVersioning.class.getName());
map.put("APP_ENVIRONMENT", FORMKIQ_APP_ENVIRONMENT);
map.put("DOCUMENTS_TABLE", DOCUMENTS_TABLE);
map.put("DOCUMENT_VERSIONS_TABLE", DOCUMENTS_VERSION_TABLE);
Expand All @@ -147,13 +150,9 @@ private Map<String, String> generateMap() {
map.put("OCR_S3_BUCKET", OCR_BUCKET_NAME);
map.put("AWS_REGION", AWS_REGION.toString());
map.put("DEBUG", "true");
// map.put("SQS_DOCUMENT_FORMATS",
// TestServices.getSqsDocumentFormatsQueueUrl(TestServices.getSqsConnection(null)));
map.put("DISTRIBUTION_BUCKET", "formkiq-distribution-us-east-pro");
map.put("FORMKIQ_TYPE", "core");
map.put("USER_AUTHENTICATION", "cognito");
// map.put("WEBSOCKET_SQS_URL",
// TestServices.getSqsWebsocketQueueUrl(TestServices.getSqsConnection(null)));

if (this.typeSenseExtension != null) {
map.put("TYPESENSE_HOST", "http://localhost:" + this.typeSenseExtension.getFirstMappedPort());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7121,6 +7121,24 @@ Resources:
type: "object"
additionalProperties:
type: object
attributes:
type: "object"
additionalProperties:
type: object
properties:
stringValues:
type: "array"
description: "Attribute with string values"
items:
type: "string"
numberValues:
type: "array"
description: "Attribute with number values"
items:
type: "number"
booleanValue:
type: "boolean"
description: "Attribute with boolean value"
GetDocumentSyncResponse:
type: "object"
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7121,6 +7121,24 @@ Resources:
type: "object"
additionalProperties:
type: object
attributes:
type: "object"
additionalProperties:
type: object
properties:
stringValues:
type: "array"
description: "Attribute with string values"
items:
type: "string"
numberValues:
type: "array"
description: "Attribute with number values"
items:
type: "number"
booleanValue:
type: "boolean"
description: "Attribute with boolean value"
GetDocumentSyncResponse:
type: "object"
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7121,6 +7121,24 @@ Resources:
type: "object"
additionalProperties:
type: object
attributes:
type: "object"
additionalProperties:
type: object
properties:
stringValues:
type: "array"
description: "Attribute with string values"
items:
type: "string"
numberValues:
type: "array"
description: "Attribute with number values"
items:
type: "number"
booleanValue:
type: "boolean"
description: "Attribute with boolean value"
GetDocumentSyncResponse:
type: "object"
properties:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,6 @@
import java.util.Arrays;
import java.util.Date;
import java.util.List;
import java.util.Map;
import java.util.UUID;

import com.formkiq.aws.services.lambda.ApiResponseStatus;
Expand Down Expand Up @@ -74,7 +73,7 @@ public class IndicesRequestHandlerTest {
private static final FormKiQResponseCallback CALLBACK = new FormKiQResponseCallback();
/** FormKiQ Server. */
@RegisterExtension
static FormKiqApiExtension server = new FormKiqApiExtension(null, null, Map.of(), CALLBACK);
static FormKiqApiExtension server = new FormKiqApiExtension(null, null, null, CALLBACK);
/** {@link ApiClient}. */
private final ApiClient client =
Configuration.getDefaultApiClient().setReadTimeout(0).setBasePath(server.getBasePath());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Map;

import com.formkiq.client.api.MappingsApi;
import com.formkiq.testutils.aws.FormKiQApiExtensionConfig;
import org.junit.jupiter.api.Order;
import org.junit.jupiter.api.extension.ExtendWith;
import org.junit.jupiter.api.extension.RegisterExtension;
Expand Down Expand Up @@ -93,9 +94,14 @@ public abstract class AbstractApiClientRequestTest {
/** FormKiQ Server. */
@RegisterExtension
@Order(2)
static FormKiqApiExtension server = new FormKiqApiExtension(localstack, typeSense,
Map.of("DOCUMENT_VERSIONS_PLUGIN", DocumentVersionServiceNoVersioning.class.getName()),
new FormKiQResponseCallback());
static FormKiqApiExtension server =
new FormKiqApiExtension(localstack, typeSense, new FormKiQApiExtensionConfig() {
@Override
public Map<String, String> getEnvironment() {
return Map.of("DOCUMENT_VERSIONS_PLUGIN",
DocumentVersionServiceNoVersioning.class.getName());
}
}, new FormKiQResponseCallback());

/** 500 Milliseconds. */
private static final long SLEEP = 500L;
Expand Down
Loading

0 comments on commit 5ec432a

Please sign in to comment.