-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
1fc83a2
commit 291e9c0
Showing
5 changed files
with
115 additions
and
8 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
21 changes: 21 additions & 0 deletions
21
src/main/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfig.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
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; | ||
private String key; | ||
|
||
public CosmosPropertiesConfig(String database, String uri, String key) { | ||
this.database = database; | ||
this.uri = uri; | ||
this.key = key; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
44 changes: 44 additions & 0 deletions
44
src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosDBConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
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); | ||
} | ||
} |
28 changes: 28 additions & 0 deletions
28
src/test/java/it/gov/pagopa/rtp/activator/configuration/CosmosPropertiesConfigTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
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()); | ||
|
||
} | ||
} |