Created
November 4, 2024 16:05
-
-
Save jagedn/b4a6f5a2e44de62d336bdfa0c5035952 to your computer and use it in GitHub Desktop.
Micronaut abstract test class for CosmosDB
This file contains hidden or 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
abstract class AbstractCosmosDBSpec extends Specification implements TestPropertyProvider{ | |
static CosmosDBEmulatorContainer emulator = new CosmosDBEmulatorContainer( | |
DockerImageName.parse("mcr.microsoft.com/cosmosdb/linux/azure-cosmos-emulator:latest")) | |
.withLogConsumer { | |
println new String(it.bytes) } | |
.waitingFor( | |
Wait.forSuccessfulCommand("curl --insecure https://127.0.0.1:8081/_explorer/emulator.pem || exit 1") | |
.withStartupTimeout(Duration.ofMinutes(2))) | |
.withReuse(true) | |
static { | |
emulator.start() | |
} | |
@Override | |
Map<String, String> getProperties() { | |
Path keyStoreFile = Path.of("build").resolve("azure-cosmos-emulator.keystore") | |
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") | |
[ | |
"azure.cosmos.endpoint": emulator.emulatorEndpoint, | |
"azure.cosmos.key": emulator.emulatorKey, | |
] | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment