diff --git a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/domain/usecase/e2e/repository/OpenApiRequestValidationTest.java b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/domain/usecase/e2e/repository/OpenApiRequestValidationTest.java
index 60b6f89b3..cde5d427c 100644
--- a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/domain/usecase/e2e/repository/OpenApiRequestValidationTest.java
+++ b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/domain/usecase/e2e/repository/OpenApiRequestValidationTest.java
@@ -34,6 +34,9 @@
import com.atlassian.oai.validator.model.SimpleRequest;
import org.junit.jupiter.api.Test;
+import org.alfresco.hxi_connector.live_ingester.util.insight_api.HxInsightRequest;
+import org.alfresco.hxi_connector.live_ingester.util.insight_api.RequestLoader;
+
public class OpenApiRequestValidationTest
{
@@ -43,13 +46,9 @@ public class OpenApiRequestValidationTest
@Test
void testRequestToPresignedUrls()
{
- Request request = SimpleRequest.Builder.post("/v1/presigned-urls")
- .withHeader("authorization", "string")
- .withHeader("content-type", "application/json")
- .withHeader("hxp-environment", "string")
- .withHeader("user-agent", "string")
- .withHeader("count", "string")
- .build();
+ HxInsightRequest hxInsightRequest = RequestLoader.load("/expected-hxinsight-requests/get-presigned-url-request.yml");
+
+ Request request = makeRequest(hxInsightRequest);
assertThat(classUnderTest.validateRequest(request).getMessages()).isEqualTo(Collections.emptyList());
}
@@ -57,51 +56,18 @@ void testRequestToPresignedUrls()
@Test
void testRequestToIngestionEvents()
{
- Request request = SimpleRequest.Builder.post("/v1/ingestion-events")
- .withHeader("authorization", "string")
- .withHeader("content-type", "application/json")
- .withHeader("hxp-environment", "string")
- .withHeader("user-agent", "string")
- .withBody(expectedBody)
- .build();
+ HxInsightRequest hxInsightRequest = RequestLoader.load("/expected-hxinsight-requests/create-document-request.yml");
+
+ Request request = makeRequest(hxInsightRequest);
// assertThat(classUnderTest.validateRequest(request).getMessages()).isEqualTo(expectedBody);
assertThat(classUnderTest.validateRequest(request).getMessages()).isEqualTo(Collections.emptyList());
}
- String expectedBody = """
- [
- {
- "objectId": "d71dd823-82c7-477c-8490-04cb0e826e65",
- "sourceId" : "alfresco-dummy-source-id-0a63de491876",
- "eventType": "create",
- "sourceTimestamp": 1611227656423,
- "properties": {
- "cm:autoVersion": {"value": true},
- "createdAt": {"value": 1611227655695},
- "modifiedAt": {"value" : 1611227655695},
- "cm:versionType": {"value": "MAJOR"},
- "aspectsNames": {"value": ["cm:versionable", "cm:auditable"]},
- "cm:name": {
- "value": "purchase-order-scan.doc",
- "annotation" : "name"
- },
- "type": {"value": "cm:content"},
- "createdBy": {"value": "admin"},
- "modifiedBy": {"value": "admin"},
- "cm:content": {
- "file": {
- "content-metadata": {
- "size": 531152,
- "name": "purchase-order-scan.doc",
- "content-type": "application/msword"
- }
- }
- },
- "ALLOW_ACCESS": {"value": ["GROUP_EVERYONE"]},
- "DENY_ACCESS": {"value": []}
- }
- }
- ]""";
-
+ private static Request makeRequest(HxInsightRequest hxInsightRequest)
+ {
+ SimpleRequest.Builder builder = SimpleRequest.Builder.post(hxInsightRequest.url());
+ hxInsightRequest.headers().forEach(builder::withHeader);
+ return builder.withBody(hxInsightRequest.body()).build();
+ }
}
diff --git a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/HxInsightRequest.java b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/HxInsightRequest.java
new file mode 100644
index 000000000..ef5a8c1f2
--- /dev/null
+++ b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/HxInsightRequest.java
@@ -0,0 +1,32 @@
+/*
+ * #%L
+ * Alfresco HX Insight Connector
+ * %%
+ * Copyright (C) 2023 - 2024 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.hxi_connector.live_ingester.util.insight_api;
+
+import java.util.Map;
+
+public record HxInsightRequest(String url, Map headers, String body)
+{
+}
diff --git a/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/RequestLoader.java b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/RequestLoader.java
new file mode 100644
index 000000000..015542f4c
--- /dev/null
+++ b/live-ingester/src/integration-test/java/org/alfresco/hxi_connector/live_ingester/util/insight_api/RequestLoader.java
@@ -0,0 +1,70 @@
+/*
+ * #%L
+ * Alfresco HX Insight Connector
+ * %%
+ * Copyright (C) 2023 - 2024 Alfresco Software Limited
+ * %%
+ * This file is part of the Alfresco software.
+ * If the software was purchased under a paid Alfresco license, the terms of
+ * the paid license agreement will prevail. Otherwise, the software is
+ * provided under the following open source license terms:
+ *
+ * Alfresco is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Lesser General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * Alfresco is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with Alfresco. If not, see .
+ * #L%
+ */
+package org.alfresco.hxi_connector.live_ingester.util.insight_api;
+
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.UncheckedIOException;
+import java.util.HashMap;
+import java.util.Map;
+
+import com.fasterxml.jackson.core.JsonProcessingException;
+import com.fasterxml.jackson.databind.ObjectMapper;
+import com.fasterxml.jackson.dataformat.yaml.YAMLFactory;
+
+public class RequestLoader
+{
+ static ObjectMapper jsonMapper = new ObjectMapper();
+ static ObjectMapper yamlMapper = new ObjectMapper(new YAMLFactory());
+
+ public static HxInsightRequest load(String path)
+ {
+ InputStream stream = HxInsightRequest.class.getResourceAsStream(path);
+ HashMap data;
+ try
+ {
+ data = yamlMapper.readValue(stream.readAllBytes(), HashMap.class);
+ }
+ catch (IOException e)
+ {
+ throw new UncheckedIOException(e);
+ }
+ Object body = data.get("body");
+ String bodyAsString = null;
+ if (body != null)
+ {
+ try
+ {
+ bodyAsString = jsonMapper.writeValueAsString(body);
+ }
+ catch (JsonProcessingException e)
+ {
+ throw new RuntimeException(e);
+ }
+ }
+ return new HxInsightRequest((String) data.get("url"), (Map) data.get("headers"), bodyAsString);
+ }
+}
diff --git a/live-ingester/src/integration-test/resources/expected-hxinsight-requests/create-document-request.yml b/live-ingester/src/integration-test/resources/expected-hxinsight-requests/create-document-request.yml
new file mode 100644
index 000000000..9ae55b5bd
--- /dev/null
+++ b/live-ingester/src/integration-test/resources/expected-hxinsight-requests/create-document-request.yml
@@ -0,0 +1,39 @@
+url: /v1/ingestion-events
+headers:
+ authorization: application/json
+ content-type: application/json
+ hxp-environment: string
+ user-agent: string
+body: [
+ {
+ "objectId": "d71dd823-82c7-477c-8490-04cb0e826e65",
+ "sourceId" : "alfresco-dummy-source-id-0a63de491876",
+ "eventType": "create",
+ "sourceTimestamp": 1611227656423,
+ "properties": {
+ "cm:autoVersion": {"value": true},
+ "createdAt": {"value": 1611227655695},
+ "modifiedAt": {"value" : 1611227655695},
+ "cm:versionType": {"value": "MAJOR"},
+ "aspectsNames": {"value": ["cm:versionable", "cm:auditable"]},
+ "cm:name": {
+ "value": "purchase-order-scan.doc",
+ "annotation" : "name"
+ },
+ "type": {"value": "cm:content"},
+ "createdBy": {"value": "admin"},
+ "modifiedBy": {"value": "admin"},
+ "cm:content": {
+ "file": {
+ "content-metadata": {
+ "size": 531152,
+ "name": "purchase-order-scan.doc",
+ "content-type": "application/msword"
+ }
+ }
+ },
+ "ALLOW_ACCESS": {"value": ["GROUP_EVERYONE"]},
+ "DENY_ACCESS": {"value": []}
+ }
+ }
+]
diff --git a/live-ingester/src/integration-test/resources/expected-hxinsight-requests/get-presigned-url-request.yml b/live-ingester/src/integration-test/resources/expected-hxinsight-requests/get-presigned-url-request.yml
new file mode 100644
index 000000000..e2a221118
--- /dev/null
+++ b/live-ingester/src/integration-test/resources/expected-hxinsight-requests/get-presigned-url-request.yml
@@ -0,0 +1,7 @@
+url: /v1/presigned-urls
+headers:
+ authorization: string
+ content-type: application/json
+ hxp-environment: string
+ user-agent: string
+ count: string