Skip to content

Commit df863e5

Browse files
authored
#11 added support for Azurite (#12)
1 parent 8883f19 commit df863e5

File tree

9 files changed

+157
-6
lines changed

9 files changed

+157
-6
lines changed

README.md

Lines changed: 22 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -233,7 +233,7 @@ This will create a MariaDB container based on `mariadb:10.3` with the default us
233233

234234
````kotlin
235235
dependencies {
236-
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mariadb:0.1.1")
236+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-mariadb:0.1.2")
237237
}
238238
````
239239

@@ -250,7 +250,7 @@ dependencies {
250250

251251
````kotlin
252252
dependencies {
253-
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-postgres:0.1.1")
253+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-jdbc-postgres:0.1.2")
254254
}
255255
````
256256

@@ -268,7 +268,7 @@ dependencies {
268268

269269
````kotlin
270270
dependencies {
271-
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-minio:0.1.1")
271+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-minio:0.1.2")
272272
}
273273
````
274274

@@ -285,7 +285,7 @@ dependencies {
285285

286286
````kotlin
287287
dependencies {
288-
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-rabbitmq:0.1.1")
288+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-rabbitmq:0.1.2")
289289
}
290290
````
291291

@@ -302,9 +302,25 @@ dependencies {
302302

303303
````kotlin
304304
dependencies {
305-
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-redis:0.1.1")
305+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-redis:0.1.2")
306306
}
307307
````
308308

309309
* **Provided properties**:
310-
* `spring.data.redis.url`
310+
* `spring.data.redis.url`
311+
312+
## Azurite
313+
314+
* **Module-ID**: azurite
315+
* **Default-Image**: mcr.microsoft.com/azure-storage/azurite
316+
317+
````kotlin
318+
dependencies {
319+
testResourcesImplementation ("io.cloudflight.testresources.springboot:springboot-testresources-azurite:0.1.2")
320+
}
321+
````
322+
323+
* **Provided properties**:
324+
* `spring.cloud.azure.storage.blob.account-name`
325+
* `spring.cloud.azure.storage.blob.account-key`
326+
* `spring.cloud.azure.storage.blob.endpoint`

settings.gradle.kts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ plugins {
44

55
rootProject.name = "springboot-testresources"
66

7+
include("springboot-testresources-azurite")
78
include("springboot-testresources-client")
89
include("springboot-testresources-minio")
910
include("springboot-testresources-jdbc")
@@ -14,6 +15,7 @@ include("springboot-testresources-redis")
1415

1516
include("testprojects:jdbc:mariadb")
1617
include("testprojects:jdbc:postgres")
18+
include("testprojects:azurite")
1719
include("testprojects:minio")
1820
include("testprojects:rabbitmq")
1921
include("testprojects:redis")
Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
description = "Spring Boot TestResourceProvider for Azurite"
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
package io.cloudflight.testresources.springboot.azurite;
2+
3+
import io.micronaut.testresources.testcontainers.AbstractTestContainersProvider;
4+
import org.testcontainers.containers.GenericContainer;
5+
import org.testcontainers.utility.DockerImageName;
6+
7+
import java.util.*;
8+
9+
public class AzuriteTestResourceProvider extends AbstractTestContainersProvider<GenericContainer<?>> {
10+
11+
private static final String PREFIX = "spring.cloud.azure.storage.blob.";
12+
private static final String ACCOUNT_NAME_PROPERTY = PREFIX + "account-name";
13+
private static final String ACCOUNT_KEY_PROPERTY = PREFIX + "account-key";
14+
private static final String ACCOUNT_ENDPOINT_PROPERTY = PREFIX + "endpoint";
15+
private static final String DEFAULT_IMAGE = "mcr.microsoft.com/azure-storage/azurite";
16+
private static final String SIMPLE_NAME = "azurite";
17+
18+
/**
19+
* can't be changed, see <a href="https://github.com/Azure/Azurite#default-storage-account">https://github.com/Azure/Azurite#default-storage-account</a>
20+
*/
21+
private static final String ACCOUNT_NAME = "devstoreaccount1";
22+
23+
/**
24+
* can't be changed, see <a href="https://github.com/Azure/Azurite#default-storage-account">https://github.com/Azure/Azurite#default-storage-account</a>
25+
*/
26+
private static final String ACCOUNT_KEY = "Eby8vdM02xNOcqFlqUwJPLlmEtlCDXJ1OUzFT50uSRZ6IFsuFq2UVErCz4I6tq/K1SZFPTOtr/KBHBeksoGMGw==";
27+
28+
private static final int AZURITE_PORT = 10000;
29+
30+
private static final Set<String> SUPPORTED_PROPERTIES;
31+
32+
static {
33+
SUPPORTED_PROPERTIES = Set.of(ACCOUNT_NAME_PROPERTY, ACCOUNT_KEY_PROPERTY, ACCOUNT_ENDPOINT_PROPERTY);
34+
}
35+
36+
@Override
37+
public List<String> getResolvableProperties(Map<String, Collection<String>> propertyEntries, Map<String, Object> testResourcesConfig) {
38+
return SUPPORTED_PROPERTIES.stream().toList();
39+
}
40+
41+
@Override
42+
protected String getSimpleName() {
43+
return SIMPLE_NAME;
44+
}
45+
46+
@Override
47+
protected String getDefaultImageName() {
48+
return DEFAULT_IMAGE;
49+
}
50+
51+
@Override
52+
protected GenericContainer<?> createContainer(DockerImageName imageName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfiguration) {
53+
GenericContainer<?> container = new GenericContainer<>(imageName);
54+
container.withExposedPorts(AZURITE_PORT);
55+
return container;
56+
}
57+
58+
@Override
59+
protected Optional<String> resolveProperty(String propertyName, GenericContainer<?> container) {
60+
String value = switch (propertyName) {
61+
case ACCOUNT_ENDPOINT_PROPERTY -> "http://" + container.getHost() + ":" + container.getMappedPort(AZURITE_PORT) + "/" + ACCOUNT_NAME;
62+
case ACCOUNT_NAME_PROPERTY -> ACCOUNT_NAME;
63+
case ACCOUNT_KEY_PROPERTY -> ACCOUNT_KEY;
64+
default -> null;
65+
};
66+
return Optional.ofNullable(value);
67+
}
68+
69+
@Override
70+
protected boolean shouldAnswer(String propertyName, Map<String, Object> requestedProperties, Map<String, Object> testResourcesConfiguration) {
71+
return SUPPORTED_PROPERTIES.contains(propertyName);
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
io.cloudflight.testresources.springboot.azurite.AzuriteTestResourceProvider
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
plugins {
2+
id("io.micronaut.test-resources")
3+
}
4+
5+
dependencies {
6+
implementation("com.azure.spring:spring-cloud-azure-starter-storage-blob:6.0.0-beta.4")
7+
8+
testImplementation("org.springframework.boot:spring-boot-starter-test")
9+
10+
testRuntimeOnly(project(":springboot-testresources-client"))
11+
testResourcesImplementation(project(":springboot-testresources-azurite"))
12+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package io.cloudflight.testresources.springboot.azurite
2+
3+
import org.springframework.boot.autoconfigure.SpringBootApplication
4+
5+
@SpringBootApplication
6+
class Application
7+
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
spring:
2+
cloud:
3+
azure:
4+
storage:
5+
blob:
6+
enabled: true
7+
compatibility-verifier:
8+
enabled: false # TODO remove as soon as the ms-azurite library is final in version 6.0.0, see https://github.com/Azure/azure-sdk-for-java/wiki/Spring-Versions-Mapping
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
package io.cloudflight.testresources.springboot.azurite
2+
3+
import com.azure.storage.blob.BlobServiceClientBuilder
4+
import org.assertj.core.api.Assertions.assertThat
5+
import org.junit.jupiter.api.Test
6+
import org.springframework.beans.factory.annotation.Autowired
7+
import org.springframework.boot.test.context.SpringBootTest
8+
import java.util.*
9+
10+
@SpringBootTest
11+
class ApplicationTest(
12+
@Autowired private val blobServiceClientBuilder: BlobServiceClientBuilder
13+
) {
14+
15+
@Test
16+
fun accountName() {
17+
val blobServiceClient = blobServiceClientBuilder.buildClient()
18+
assertThat(blobServiceClient.accountName).isEqualTo("devstoreaccount1")
19+
}
20+
21+
@Test
22+
fun `do some basic operations to show that azurite is running and working correctly`() {
23+
val blobServiceClient = blobServiceClientBuilder.buildClient()
24+
val containersBefore = blobServiceClient.listBlobContainers().stream().count()
25+
val container = blobServiceClient.createBlobContainer(UUID.randomUUID().toString())
26+
assertThat(container.listBlobs().stream()).isEmpty()
27+
assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore + 1)
28+
container.delete()
29+
assertThat(blobServiceClient.listBlobContainers().stream().count()).isEqualTo(containersBefore)
30+
}
31+
}

0 commit comments

Comments
 (0)