From b4eb39df432f200285a5cf7f8bb3bdf498b41b78 Mon Sep 17 00:00:00 2001 From: Luca Consalvi Date: Wed, 27 Nov 2024 16:03:02 +0100 Subject: [PATCH] update cosmos nosql connection strategy --- .../configuration/CosmosDBConfig.java | 29 +----------- .../configuration/CosmosPropertiesConfig.java | 19 -------- src/main/resources/application.properties | 7 +-- .../configuration/CosmosDBConfigTest.java | 44 ------------------- .../CosmosPropertiesConfigTest.java | 28 ------------ 5 files changed, 5 insertions(+), 122 deletions(-) delete mode 100644 src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java delete mode 100644 src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java delete mode 100644 src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java diff --git a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java index f8a6850..c4d8fd0 100644 --- a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java +++ b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfig.java @@ -1,37 +1,10 @@ package it.gov.pagopa.rtp.activator.configuration; -import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; -import com.azure.cosmos.CosmosClientBuilder; -import com.azure.identity.DefaultAzureCredential; -import com.azure.identity.DefaultAzureCredentialBuilder; -import com.azure.spring.data.cosmos.config.AbstractCosmosConfiguration; import com.azure.spring.data.cosmos.repository.config.EnableReactiveCosmosRepositories; @Configuration @EnableReactiveCosmosRepositories("it.gov.pagopa.rtp.activator.repository") -public class CosmosDBConfig extends AbstractCosmosConfiguration { - - private CosmosPropertiesConfig cosmosPropertiesConfig; - - public CosmosDBConfig(CosmosPropertiesConfig cosmosPropertiesConfig){ - this.cosmosPropertiesConfig = cosmosPropertiesConfig; - } - - @Override - protected String getDatabaseName() { - return cosmosPropertiesConfig.getDatabase(); - } - - @Bean - public CosmosClientBuilder getCosmosClientBuilder() { - DefaultAzureCredential credential = new DefaultAzureCredentialBuilder() - .build(); - - return new CosmosClientBuilder() - .endpoint(cosmosPropertiesConfig.getUri()) - .credential(credential); - } - +public class CosmosDBConfig { } diff --git a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java b/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java deleted file mode 100644 index 7f5e29c..0000000 --- a/src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java +++ /dev/null @@ -1,19 +0,0 @@ -package it.gov.pagopa.rtp.activator.configuration; - -import org.springframework.boot.context.properties.ConfigurationProperties; - -import lombok.Getter; -import lombok.Setter; - -@ConfigurationProperties(prefix = "azure.cosmos") -@Getter -@Setter -public class CosmosPropertiesConfig { - private String database; - private String uri; - - public CosmosPropertiesConfig(String database, String uri) { - this.database = database; - this.uri = uri; - } -} diff --git a/src/main/resources/application.properties b/src/main/resources/application.properties index 01c90d2..60aced9 100644 --- a/src/main/resources/application.properties +++ b/src/main/resources/application.properties @@ -10,7 +10,8 @@ management.endpoint.health.probes.enabled=true #repository -azure.cosmos.uri=${COSMOS_ACCOUNT_RTP_ENDPOINT:} -azure.cosmos.key=${AZURE_COSMOS_KEY:} -azure.cosmos.database=${DB_NAME:rtp} +spring.cloud.azure.cosmos.endpoint=${COSMOS_ACCOUNT_RTP_ENDPOINT:} +spring.cloud.azure.cosmos.key=${AZURE_COSMOS_KEY:} +spring.cloud.azure.cosmos.database=${DB_NAME:rtp} +spring.cloud.azure.cosmos.populate-query-metrics=true activation.base-url=${BASE_URL:http://localhost} diff --git a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java deleted file mode 100644 index 6ec6f87..0000000 --- a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java +++ /dev/null @@ -1,44 +0,0 @@ -package it.gov.pagopa.rtp.activator.configuration; - -import com.azure.cosmos.CosmosClientBuilder; -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.mockito.InjectMocks; -import org.mockito.Mock; - -import org.mockito.junit.jupiter.MockitoExtension; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.mockito.Mockito.lenient; -import static org.mockito.Mockito.verify; - -@ExtendWith(MockitoExtension.class) -class CosmosDBConfigTest { - - @Mock - private CosmosPropertiesConfig cosmosPropertiesConfig; - - @InjectMocks - private CosmosDBConfig cosmosDBConfig; - - @BeforeEach - void setUp() { - lenient().when(cosmosPropertiesConfig.getDatabase()).thenReturn("test-db"); - lenient().when(cosmosPropertiesConfig.getUri()).thenReturn("https://test-endpoint:443/"); - } - - @Test - void testGetDatabaseName() { - String database = cosmosDBConfig.getDatabaseName(); - assertEquals("test-db", database); - } - - @Test - void testGetCosmosClientBuilder() { - CosmosClientBuilder builder = cosmosDBConfig.getCosmosClientBuilder(); - verify(cosmosPropertiesConfig).getUri(); - assertNotNull(builder); - } -} diff --git a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java b/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java deleted file mode 100644 index 06d7b46..0000000 --- a/src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java +++ /dev/null @@ -1,28 +0,0 @@ -package it.gov.pagopa.rtp.activator.configuration; - -import static org.junit.jupiter.api.Assertions.assertEquals; -import static org.junit.jupiter.api.Assertions.assertNotNull; - -import org.junit.jupiter.api.Test; -import org.junit.jupiter.api.extension.ExtendWith; -import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.boot.context.properties.EnableConfigurationProperties; -import org.springframework.test.context.TestPropertySource; -import org.springframework.test.context.junit.jupiter.SpringExtension; - -@ExtendWith(SpringExtension.class) -@EnableConfigurationProperties(value = CosmosPropertiesConfig.class) -@TestPropertySource("classpath:application.properties") -class CosmosPropertiesConfigTest { - - @Autowired - private CosmosPropertiesConfig cosmosPropertiesConfig; - - @Test - void testPropertiesLoaded() { - assertNotNull(cosmosPropertiesConfig); - assertEquals("https://example.com/db/endpoint", cosmosPropertiesConfig.getUri()); - assertEquals("rtp", cosmosPropertiesConfig.getDatabase()); - - } -} \ No newline at end of file