From e05c2f96cb634c9657946d6d628294e97be52b95 Mon Sep 17 00:00:00 2001 From: aacitelli Date: Fri, 24 Jun 2022 16:39:31 +0200 Subject: [PATCH] [PPD-206] crud gps: corrected error "unable to find valid certification path" during JUNIT test execution --- .../CosmosDBContainerTest.java | 76 ------------------- ...=> SpontaneousPaymentApplicationTest.java} | 6 +- .../controller/EnrollmentsControllerTest.java | 3 +- .../service/EnrollmentsServiceTest.java | 5 ++ 4 files changed, 9 insertions(+), 81 deletions(-) delete mode 100644 src/test/java/it/gov/pagopa/spontaneouspayment/CosmosDBContainerTest.java rename src/test/java/it/gov/pagopa/spontaneouspayment/{SpontaneousPaymentApplicationTests.java => SpontaneousPaymentApplicationTest.java} (88%) diff --git a/src/test/java/it/gov/pagopa/spontaneouspayment/CosmosDBContainerTest.java b/src/test/java/it/gov/pagopa/spontaneouspayment/CosmosDBContainerTest.java deleted file mode 100644 index 3de371d..0000000 --- a/src/test/java/it/gov/pagopa/spontaneouspayment/CosmosDBContainerTest.java +++ /dev/null @@ -1,76 +0,0 @@ -package it.gov.pagopa.spontaneouspayment; - -import static org.junit.Assert.assertTrue; - -import java.io.FileOutputStream; -import java.io.IOException; -import java.nio.file.Path; -import java.security.KeyStore; -import java.security.KeyStoreException; -import java.security.NoSuchAlgorithmException; -import java.security.cert.CertificateException; - -import org.junit.jupiter.api.Assertions; -import org.junit.Rule; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.rules.TemporaryFolder; -import org.testcontainers.containers.CosmosDBEmulatorContainer; -import org.testcontainers.junit.jupiter.Container; -import org.testcontainers.junit.jupiter.Testcontainers; -import org.testcontainers.utility.DockerImageName; - -import com.azure.cosmos.CosmosAsyncClient; -import com.azure.cosmos.CosmosClientBuilder; -import com.azure.cosmos.models.CosmosContainerResponse; -import com.azure.cosmos.models.CosmosDatabaseResponse; - -@Testcontainers -class CosmosDBContainerTest { - - @Rule - public TemporaryFolder tempFolder= new TemporaryFolder(); - - - @Container - private static final CosmosDBEmulatorContainer emulator = new CosmosDBEmulatorContainer( - DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")); - - - - @BeforeEach - public void setUp() throws IOException, KeyStoreException, NoSuchAlgorithmException, CertificateException { - tempFolder.create(); - Path keyStoreFile = tempFolder.newFile("azure-cosmos-emulator.keystore").toPath(); - KeyStore keyStore = emulator.buildNewKeyStore(); - keyStore.store(new FileOutputStream(keyStoreFile.toFile()), emulator.getEmulatorKey().toCharArray()); - - System.setProperty("javax.net.ssl.trustStore", keyStoreFile.toString()); - System.setProperty("javax.net.ssl.trustStorePassword", emulator.getEmulatorKey()); - System.setProperty("javax.net.ssl.trustStoreType", "PKCS12"); - } - - @Test - void cosmosDBEmulatorCheck() { - - assertTrue(emulator.isRunning()); - - - - CosmosAsyncClient client = new CosmosClientBuilder() - .gatewayMode() - .endpointDiscoveryEnabled(false) - .endpoint(emulator.getEmulatorEndpoint()) - .key(emulator.getEmulatorKey()) - .buildAsyncClient(); - - CosmosDatabaseResponse databaseResponse = client.createDatabaseIfNotExists("Azure").block(); - - Assertions.assertEquals(201, databaseResponse.getStatusCode()); - CosmosContainerResponse containerResponse = client - .getDatabase("Azure") - .createContainerIfNotExists("ServiceContainer", "/name") - .block(); - Assertions.assertEquals(201, containerResponse.getStatusCode()); - } -} diff --git a/src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTests.java b/src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTest.java similarity index 88% rename from src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTests.java rename to src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTest.java index 27ec48a..37d4bc4 100644 --- a/src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTests.java +++ b/src/test/java/it/gov/pagopa/spontaneouspayment/SpontaneousPaymentApplicationTest.java @@ -1,12 +1,12 @@ package it.gov.pagopa.spontaneouspayment; +import static org.junit.jupiter.api.Assertions.assertTrue; + import org.junit.jupiter.api.Test; import org.springframework.boot.test.context.SpringBootTest; -import static org.junit.jupiter.api.Assertions.assertTrue; - @SpringBootTest -class SpontaneousPaymentApplicationTests { +class SpontaneousPaymentApplicationTest { @Test void contextLoads() { diff --git a/src/test/java/it/gov/pagopa/spontaneouspayment/controller/EnrollmentsControllerTest.java b/src/test/java/it/gov/pagopa/spontaneouspayment/controller/EnrollmentsControllerTest.java index 78b55b2..0e7d94c 100644 --- a/src/test/java/it/gov/pagopa/spontaneouspayment/controller/EnrollmentsControllerTest.java +++ b/src/test/java/it/gov/pagopa/spontaneouspayment/controller/EnrollmentsControllerTest.java @@ -23,14 +23,13 @@ import org.springframework.test.web.servlet.MockMvc; import org.springframework.test.web.servlet.MvcResult; -import it.gov.pagopa.spontaneouspayment.SpontaneousPaymentApplication; import it.gov.pagopa.spontaneouspayment.config.TestUtil; import it.gov.pagopa.spontaneouspayment.entity.Organization; import it.gov.pagopa.spontaneouspayment.model.EnrollmentModel; import it.gov.pagopa.spontaneouspayment.model.OrganizationModel; import it.gov.pagopa.spontaneouspayment.service.EnrollmentsService; -@SpringBootTest(classes = SpontaneousPaymentApplication.class) +@SpringBootTest @AutoConfigureMockMvc class EnrollmentsControllerTest { diff --git a/src/test/java/it/gov/pagopa/spontaneouspayment/service/EnrollmentsServiceTest.java b/src/test/java/it/gov/pagopa/spontaneouspayment/service/EnrollmentsServiceTest.java index e2d95ac..a2a7c5e 100644 --- a/src/test/java/it/gov/pagopa/spontaneouspayment/service/EnrollmentsServiceTest.java +++ b/src/test/java/it/gov/pagopa/spontaneouspayment/service/EnrollmentsServiceTest.java @@ -173,7 +173,12 @@ void teardown() { CosmosAsyncClient client = new CosmosClientBuilder().gatewayMode().endpointDiscoveryEnabled(false) .endpoint(emulator.getEmulatorEndpoint()).key(emulator.getEmulatorKey()).buildAsyncClient(); client.getDatabase("db").delete(); + client.close(); emulator.stop(); + emulator.close(); + System.clearProperty("javax.net.ssl.trustStore"); + System.clearProperty("javax.net.ssl.trustStorePassword"); + System.clearProperty("javax.net.ssl.trustStoreType"); }