Skip to content

Commit

Permalink
Make LocalStorageOperations the primary bean (#314)
Browse files Browse the repository at this point in the history
  • Loading branch information
alvarosanchez authored Jul 26, 2023
1 parent b74ce4c commit 4d1e229
Show file tree
Hide file tree
Showing 4 changed files with 51 additions and 0 deletions.
1 change: 1 addition & 0 deletions object-storage-local/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ dependencies {
testImplementation(mnValidation.micronaut.validation)
testImplementation(mnValidation.micronaut.validation.processor)
testImplementation(projects.micronautObjectStorageTck)
testImplementation(projects.micronautObjectStorageAws)
}

micronautBuild {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@

import io.micronaut.context.annotation.EachBean;
import io.micronaut.context.annotation.Parameter;
import io.micronaut.context.annotation.Primary;
import io.micronaut.context.annotation.Requires;
import io.micronaut.core.annotation.NonNull;
import io.micronaut.objectstorage.ObjectStorageException;
Expand Down Expand Up @@ -53,6 +54,7 @@
@EachBean(LocalStorageConfiguration.class)
@Requires(condition = ToggeableCondition.class)
@Requires(beans = LocalStorageConfiguration.class)
@Primary
public class LocalStorageOperations implements ObjectStorageOperations<
LocalStorageOperations.LocalStorageFile,
LocalStorageOperations.LocalStorageFile,
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package io.micronaut.objectstorage.local

import io.micronaut.context.ApplicationContext
import io.micronaut.context.annotation.Factory
import io.micronaut.context.annotation.Property
import io.micronaut.context.annotation.Requires
import io.micronaut.objectstorage.ObjectStorageOperations
import io.micronaut.test.annotation.MockBean
import io.micronaut.test.extensions.spock.annotation.MicronautTest
import jakarta.inject.Inject
import software.amazon.awssdk.services.s3.S3Client
import spock.lang.Specification

@Property(name = "spec.name", value = SPEC_NAME)
@Property(name = "micronaut.object-storage.local.default.enabled", value = "true")
@Property(name = "micronaut.object-storage.aws.default.enabled", value = "true")
@MicronautTest
class LocalStoragePrimarySpec extends Specification {

public static final String SPEC_NAME = 'LocalStoragePrimarySpec'

@Inject
ApplicationContext ctx

void "both local and aws storage are enabled"() {
when:
def beans = ctx.getBeansOfType(ObjectStorageOperations)

then:
beans.size() == 2
}

void "local storage is primary"() {
when:
def operations = ctx.getBean(ObjectStorageOperations)

then:
operations instanceof LocalStorageOperations
}

@MockBean(S3Client)
S3Client s3Client() {
return Mock(S3Client)
}

}
2 changes: 2 additions & 0 deletions src/main/docs/guide/local.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ micronaut:
enabled: true
----

NOTE: When added to the classpath, api:objectstorage.local.LocalStorageOperations[] becomes the primary implementation of
api:objectstorage.ObjectStorageOperations[].

By default, it will create a temporary folder to store the files, but you can configure it to use a specific folder:

Expand Down

0 comments on commit 4d1e229

Please sign in to comment.