diff --git a/Jenkinsfile_CNP b/Jenkinsfile_CNP index ad1f864f07..96c36644a0 100644 --- a/Jenkinsfile_CNP +++ b/Jenkinsfile_CNP @@ -13,6 +13,8 @@ def component = "processor" def channel = '#bsp-build-notices' +env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = 'hmctspublic.azurecr.io/imported/' + def combinedSecrets = [ 'bulk-scan-${env}': [ secret('processed-envelopes-staging-queue-send-shared-access-key', diff --git a/Jenkinsfile_nightly b/Jenkinsfile_nightly index 1963c86612..36ecb5f36e 100644 --- a/Jenkinsfile_nightly +++ b/Jenkinsfile_nightly @@ -13,6 +13,8 @@ def component = "processor" def channel = '#bsp-build-notices' +env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = 'hmctspublic.azurecr.io/imported/' + def secrets = [ 'bulk-scan-${env}': [ secret('fortify-on-demand-username', 'FORTIFY_USER_NAME'), diff --git a/Jenkinsfile_parameterized b/Jenkinsfile_parameterized index c54d1feb21..dfb3798dfb 100644 --- a/Jenkinsfile_parameterized +++ b/Jenkinsfile_parameterized @@ -4,6 +4,8 @@ def channel = '#bsp-build-notices' +env.TESTCONTAINERS_HUB_IMAGE_NAME_PREFIX = 'hmctspublic.azurecr.io/imported/' + def combinedSecrets = [ 'bulk-scan-${env}': [ secret('storage-account-primary-key', 'TEST_STORAGE_ACCOUNT_KEY'), diff --git a/charts/bulk-scan-processor/Chart.yaml b/charts/bulk-scan-processor/Chart.yaml index ae824d95a8..082f4e5834 100644 --- a/charts/bulk-scan-processor/Chart.yaml +++ b/charts/bulk-scan-processor/Chart.yaml @@ -1,7 +1,7 @@ name: bulk-scan-processor apiVersion: v2 home: https://github.com/hmcts/bulk-scan-processor -version: 1.0.25 +version: 1.0.26 description: HMCTS Bulk scan processor service maintainers: - name: HMCTS BSP Team @@ -11,10 +11,10 @@ dependencies: version: 5.2.0 repository: https://hmctspublic.azurecr.io/helm/v1/repo/ - name: servicebus - version: 1.0.4 + version: 1.0.6 repository: https://hmctspublic.azurecr.io/helm/v1/repo/ condition: servicebus.enabled - name: blobstorage - version: 2.0.0 + version: 2.0.1 repository: https://hmctspublic.azurecr.io/helm/v1/repo/ condition: blobstorage.enabled diff --git a/docker/database/Dockerfile b/docker/database/Dockerfile index bd575e3b20..1c4047ceea 100644 --- a/docker/database/Dockerfile +++ b/docker/database/Dockerfile @@ -1,4 +1,4 @@ -FROM postgres:15 +FROM hmctspublic.azurecr.io/imported/postgres:16-alpine MAINTAINER "HMCTS BSP " LABEL maintainer = "HMCTS BSP " diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/EnvelopeControllerTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/EnvelopeControllerTest.java index b0f6f20869..849982a1dd 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/EnvelopeControllerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/EnvelopeControllerTest.java @@ -18,7 +18,7 @@ import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.authorisation.validators.AuthTokenValidator; import uk.gov.hmcts.reform.bulkscanprocessor.config.BlobManagementProperties; import uk.gov.hmcts.reform.bulkscanprocessor.config.ContainerMappings; @@ -73,6 +73,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import static uk.gov.hmcts.reform.bulkscanprocessor.entity.Status.UPLOADED; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; @ActiveProfiles({ IntegrationContextInitializer.PROFILE_WIREMOCK, @@ -110,18 +113,17 @@ public class EnvelopeControllerTest { private UploadEnvelopeDocumentsTask uploadTask; private BlobContainerClient testContainer; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; @BeforeAll public static void initialize() { - File dockerComposeFile = new File("src/integrationTest/resources/docker-compose.yml"); - - dockerComposeContainer = new DockerComposeContainer(dockerComposeFile) - .withExposedService("azure-storage", 10000); - + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll @@ -132,9 +134,14 @@ public static void tearDownContainer() { @BeforeEach public void setup() { - BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) - .buildClient(); + BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() + .connectionString( + String.format( + TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) + .buildClient(); BlobManager blobManager = new BlobManager(blobServiceClient, blobManagementProperties); EnvelopeValidator envelopeValidator = new EnvelopeValidator(); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/ZipStatusControllerTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/ZipStatusControllerTest.java index 8a4629f9f8..caa8d5b3e8 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/ZipStatusControllerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/controllers/ZipStatusControllerTest.java @@ -17,7 +17,7 @@ import org.springframework.boot.test.mock.mockito.MockBean; import org.springframework.test.context.ActiveProfiles; import org.springframework.test.web.servlet.MockMvc; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.authorisation.validators.AuthTokenValidator; import uk.gov.hmcts.reform.bulkscanprocessor.config.BlobManagementProperties; import uk.gov.hmcts.reform.bulkscanprocessor.config.ContainerMappings; @@ -64,6 +64,9 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers.print; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.content; import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; @ActiveProfiles({ IntegrationContextInitializer.PROFILE_WIREMOCK, @@ -101,18 +104,17 @@ class ZipStatusControllerTest { private BlobContainerClient testContainer; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; @BeforeAll - static void initialize() { - File dockerComposeFile = new File("src/integrationTest/resources/docker-compose.yml"); - - dockerComposeContainer = new DockerComposeContainer(dockerComposeFile) - .withExposedService("azure-storage", 10000); - + public static void initialize() { + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll @@ -124,8 +126,13 @@ static void tearDownContainer() { void setup() { BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) - .buildClient(); + .connectionString( + String.format( + TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) + .buildClient(); BlobManager blobManager = new BlobManager(blobServiceClient, blobManagementProperties); EnvelopeValidator envelopeValidator = new EnvelopeValidator(); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/reports/RejectedFilesReportServiceTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/reports/RejectedFilesReportServiceTest.java index 5fa9d2913f..93e3116f63 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/reports/RejectedFilesReportServiceTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/reports/RejectedFilesReportServiceTest.java @@ -8,17 +8,19 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.bulkscanprocessor.config.BlobManagementProperties; import uk.gov.hmcts.reform.bulkscanprocessor.services.reports.models.RejectedFile; import uk.gov.hmcts.reform.bulkscanprocessor.tasks.processor.BlobManager; import uk.gov.hmcts.reform.bulkscanprocessor.util.TestStorageHelper; import java.io.ByteArrayInputStream; -import java.io.File; import java.util.List; import static org.assertj.core.api.Assertions.assertThat; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; public class RejectedFilesReportServiceTest { @@ -28,17 +30,17 @@ public class RejectedFilesReportServiceTest { private BlobContainerClient rejectedContainer; private BlobManager blobManager; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; @BeforeAll public static void initialize() { - dockerComposeContainer = - new DockerComposeContainer(new File("src/integrationTest/resources/docker-compose.yml")) - .withExposedService("azure-storage", 10000); - + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll @@ -48,9 +50,12 @@ public static void tearDownContainer() { @BeforeEach public void setUp() { - BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) + .connectionString( + String.format(TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) .buildClient(); this.blobManager = new BlobManager(blobServiceClient, blobManagementProperties); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/storage/OcrValidationRetryManagerTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/storage/OcrValidationRetryManagerTest.java index b7f83e6315..9a036b107c 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/storage/OcrValidationRetryManagerTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/services/storage/OcrValidationRetryManagerTest.java @@ -12,15 +12,17 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.bulkscanprocessor.config.IntegrationTest; import uk.gov.hmcts.reform.bulkscanprocessor.util.TestStorageHelper; import java.io.ByteArrayInputStream; -import java.io.File; import static org.assertj.core.api.Assertions.assertThat; import static uk.gov.hmcts.reform.bulkscanprocessor.helper.DirectoryZipper.zipDir; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; @IntegrationTest class OcrValidationRetryManagerTest { @@ -31,7 +33,9 @@ class OcrValidationRetryManagerTest { @Autowired private OcrValidationRetryManager ocrValidationRetryManager; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; private BlobContainerClient testContainer; @@ -39,7 +43,12 @@ class OcrValidationRetryManagerTest { @BeforeEach void setUp() { BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) + .connectionString( + String.format( + TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) .buildClient(); testContainer = blobServiceClient.getBlobContainerClient(CONTAINER_NAME); @@ -57,13 +66,10 @@ void cleanUp() { @BeforeAll static void initialize() { - File dockerComposeFile = new File("src/integrationTest/resources/docker-compose.yml"); - - dockerComposeContainer = new DockerComposeContainer(dockerComposeFile) - .withExposedService("azure-storage", 10000); - + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/CleanUpRejectedFilesTaskTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/CleanUpRejectedFilesTaskTest.java index 95dfe15d73..89c8f80d1b 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/CleanUpRejectedFilesTaskTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/CleanUpRejectedFilesTaskTest.java @@ -10,7 +10,7 @@ import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.bulkscanprocessor.config.BlobManagementProperties; import uk.gov.hmcts.reform.bulkscanprocessor.config.IntegrationTest; import uk.gov.hmcts.reform.bulkscanprocessor.services.storage.LeaseAcquirer; @@ -18,7 +18,6 @@ import uk.gov.hmcts.reform.bulkscanprocessor.util.TestStorageHelper; import java.io.ByteArrayInputStream; -import java.io.File; import java.time.LocalDateTime; import java.util.HashMap; import java.util.List; @@ -27,6 +26,9 @@ import static org.assertj.core.api.Assertions.assertThat; import static uk.gov.hmcts.reform.bulkscanprocessor.services.storage.LeaseMetaDataChecker.LEASE_EXPIRATION_TIME; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; import static uk.gov.hmcts.reform.bulkscanprocessor.util.TimeZones.EUROPE_LONDON_ZONE_ID; @IntegrationTest @@ -44,17 +46,17 @@ public class CleanUpRejectedFilesTaskTest { private BlobManager blobManager; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; @BeforeAll public static void initialize() { - dockerComposeContainer = - new DockerComposeContainer(new File("src/integrationTest/resources/docker-compose.yml")) - .withExposedService("azure-storage", 10000); - + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll @@ -63,9 +65,14 @@ public static void tearDownContainer() { } @BeforeEach - public void setUp() throws Exception { + public void setUp() { blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) + .connectionString( + String.format( + TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) .buildClient(); this.blobManager = new BlobManager(blobServiceClient, blobManagementProperties); diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/ProcessorTestSuite.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/ProcessorTestSuite.java index c15005206e..53457762da 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/ProcessorTestSuite.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/ProcessorTestSuite.java @@ -12,7 +12,7 @@ import org.mockito.Mock; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import uk.gov.hmcts.reform.bulkscanprocessor.config.BlobManagementProperties; import uk.gov.hmcts.reform.bulkscanprocessor.config.ContainerMappings; import uk.gov.hmcts.reform.bulkscanprocessor.entity.Envelope; @@ -40,7 +40,6 @@ import uk.gov.hmcts.reform.bulkscanprocessor.validation.OcrValidator; import java.io.ByteArrayInputStream; -import java.io.File; import java.util.List; import static com.jayway.awaitility.Awaitility.await; @@ -49,6 +48,9 @@ import static org.assertj.core.api.Assertions.tuple; import static org.hamcrest.Matchers.is; import static org.mockito.Mockito.verify; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; public abstract class ProcessorTestSuite { @@ -124,14 +126,21 @@ public abstract class ProcessorTestSuite { protected BlobContainerClient testContainer; protected BlobContainerClient rejectedContainer; - private static DockerComposeContainer dockerComposeContainer; + private static GenericContainer dockerComposeContainer = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private static String dockerHost; @BeforeEach public void setUp() { BlobServiceClient blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(TestStorageHelper.STORAGE_CONN_STRING, dockerHost, 10000)) + .connectionString( + String.format( + TestStorageHelper.STORAGE_CONN_STRING, + dockerHost, + dockerComposeContainer.getMappedPort(CONTAINER_PORT)) + ) .buildClient(); blobManager = new BlobManager(blobServiceClient, blobManagementProperties); @@ -213,13 +222,10 @@ public void prepare() { @BeforeAll public static void initialize() { - File dockerComposeFile = new File("src/integrationTest/resources/docker-compose.yml"); - - dockerComposeContainer = new DockerComposeContainer(dockerComposeFile) - .withExposedService("azure-storage", 10000); - + dockerComposeContainer.withEnv("executable", "blob"); + dockerComposeContainer.withNetworkAliases(EXTRACTION_HOST); dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); + dockerHost = dockerComposeContainer.getHost(); } @AfterAll diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/UploadEnvelopeDocumentsTaskTest.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/UploadEnvelopeDocumentsTaskTest.java index f968feacb1..6b5fcafb83 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/UploadEnvelopeDocumentsTaskTest.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/tasks/UploadEnvelopeDocumentsTaskTest.java @@ -40,6 +40,7 @@ import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; import static uk.gov.hmcts.reform.bulkscanprocessor.entity.Status.UPLOADED; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_NAME; @IntegrationTest @SuppressWarnings("unchecked") @@ -101,13 +102,13 @@ public void should_mark_envelope_as_uploaded() throws Exception { ); Envelope envelope = EnvelopeMapper.toDbEnvelope( inputEnvelope, - TestStorageHelper.CONTAINER_NAME, + CONTAINER_NAME, Optional.empty() ); UUID envelopeId = envelopeRepository.saveAndFlush(envelope).getId(); // when - BlobManager blobManager = new BlobManager(STORAGE_HELPER.blobServiceClient, blobManagementProperties); + BlobManager blobManager = new BlobManager(STORAGE_HELPER.BLOB_SERVICE_CLIENT, blobManagementProperties); UploadEnvelopeDocumentsService uploadService = new UploadEnvelopeDocumentsService( blobManager, zipFileProcessor, diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/AzureHelper.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/AzureHelper.java new file mode 100644 index 0000000000..c57039accf --- /dev/null +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/AzureHelper.java @@ -0,0 +1,14 @@ +package uk.gov.hmcts.reform.bulkscanprocessor.util; + +public final class AzureHelper { + + private AzureHelper() { + } + + public static final String AZURE_TEST_CONTAINER = "hmctspublic.azurecr.io/imported/azure-storage/azurite:3.29.0"; + public static final String EXTRACTION_HOST = "azurite"; + public static final int CONTAINER_PORT = 10000; + public static final String CONTAINER_NAME = "bulkscan"; + + +} diff --git a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/TestStorageHelper.java b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/TestStorageHelper.java index 8e91076f34..8f46ac2f71 100644 --- a/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/TestStorageHelper.java +++ b/src/integrationTest/java/uk/gov/hmcts/reform/bulkscanprocessor/util/TestStorageHelper.java @@ -4,28 +4,30 @@ import com.azure.storage.blob.BlobContainerClient; import com.azure.storage.blob.BlobServiceClient; import com.azure.storage.blob.BlobServiceClientBuilder; -import org.testcontainers.containers.DockerComposeContainer; +import org.testcontainers.containers.GenericContainer; import java.io.ByteArrayInputStream; -import java.io.File; import static uk.gov.hmcts.reform.bulkscanprocessor.helper.DirectoryZipper.zipDir; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.AZURE_TEST_CONTAINER; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_NAME; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.CONTAINER_PORT; +import static uk.gov.hmcts.reform.bulkscanprocessor.util.AzureHelper.EXTRACTION_HOST; public class TestStorageHelper { - private static TestStorageHelper INSTANCE; - - public static final String CONTAINER_NAME = "bulkscan"; public static final String ZIP_FILE_NAME = "1_24-06-2018-00-00-00.zip"; - private static DockerComposeContainer dockerComposeContainer; - private static String dockerHost; + private static String DOCKER_HOST; public static final String STORAGE_CONN_STRING = "DefaultEndpointsProtocol=http;AccountName=devstoreaccount1;" + "AccountKey=Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==;" + "BlobEndpoint=http://%s:%d/devstoreaccount1;"; - public static BlobServiceClient blobServiceClient; + public static BlobServiceClient BLOB_SERVICE_CLIENT; private BlobContainerClient testContainer; + private static GenericContainer DOCKER_COMPOSE_CONTAINER = + new GenericContainer<>(AZURE_TEST_CONTAINER).withExposedPorts(CONTAINER_PORT); + private TestStorageHelper() { // empty constructor } @@ -38,31 +40,27 @@ public static TestStorageHelper getInstance() { return INSTANCE; } - private static void createDocker() { - dockerComposeContainer = new DockerComposeContainer<>( - new File("src/integrationTest/resources/docker-compose.yml") - ).withExposedService("azure-storage", 10000); - dockerComposeContainer.start(); - dockerHost = dockerComposeContainer.getServiceHost("azure-storage", 10000); - } - - private static void initializeStorage() { - blobServiceClient = new BlobServiceClientBuilder() - .connectionString(String.format(STORAGE_CONN_STRING, dockerHost, 10000)) - .buildClient(); - } - public static void initialize() { - createDocker(); - initializeStorage(); + DOCKER_COMPOSE_CONTAINER.withEnv("executable", "blob"); + DOCKER_COMPOSE_CONTAINER.withNetworkAliases(EXTRACTION_HOST); + DOCKER_COMPOSE_CONTAINER.start(); + DOCKER_HOST = DOCKER_COMPOSE_CONTAINER.getHost(); + + BLOB_SERVICE_CLIENT = new BlobServiceClientBuilder() + .connectionString( + String.format(STORAGE_CONN_STRING, + DOCKER_HOST, + DOCKER_COMPOSE_CONTAINER.getMappedPort(CONTAINER_PORT)) + ) + .buildClient(); } public static void stopDocker() { - dockerComposeContainer.stop(); + DOCKER_COMPOSE_CONTAINER.stop(); } public void createBulkscanContainer() { - testContainer = blobServiceClient.getBlobContainerClient(CONTAINER_NAME); + testContainer = BLOB_SERVICE_CLIENT.getBlobContainerClient(CONTAINER_NAME); testContainer.create(); }