-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Browse files
Browse the repository at this point in the history
Fix reactive Mongo client CDI handling
- Loading branch information
Showing
8 changed files
with
90 additions
and
21 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
65 changes: 65 additions & 0 deletions
65
...loyment/src/test/java/io/quarkus/mongodb/MongoNamedClientClientBuildItemConsumerTest.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,65 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.Collections; | ||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
import javax.enterprise.inject.Default; | ||
import javax.enterprise.inject.literal.NamedLiteral; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.arc.Arc; | ||
import io.quarkus.builder.BuildChainBuilder; | ||
import io.quarkus.deployment.builditem.ApplicationArchivesBuildItem; | ||
import io.quarkus.deployment.builditem.FeatureBuildItem; | ||
import io.quarkus.mongodb.deployment.MongoClientBuildItem; | ||
import io.quarkus.mongodb.deployment.MongoClientNameBuildItem; | ||
import io.quarkus.mongodb.reactive.ReactiveMongoClient; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MongoNamedClientClientBuildItemConsumerTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class)) | ||
.withConfigurationResource("named-mongoclient.properties") | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
@Test | ||
public void testContainerHasBeans() { | ||
assertThat(Arc.container().instance(MongoClient.class, Default.Literal.INSTANCE).get()).isNotNull(); | ||
assertThat(Arc.container().instance(MongoClient.class, NamedLiteral.of("second")).get()).isNotNull(); | ||
assertThat(Arc.container().instance(ReactiveMongoClient.class, Default.Literal.INSTANCE).get()).isNotNull(); | ||
assertThat(Arc.container().instance(ReactiveMongoClient.class, NamedLiteral.of("secondreactive")).get()).isNotNull(); | ||
} | ||
|
||
protected static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
// This represents the extension. | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(context -> { | ||
ApplicationArchivesBuildItem archive = context.consume(ApplicationArchivesBuildItem.class); | ||
context.produce(Collections.singletonList(new MongoClientNameBuildItem("second"))); | ||
}).consumes(ApplicationArchivesBuildItem.class) | ||
.produces(MongoClientNameBuildItem.class) | ||
.build(); | ||
|
||
builder.addBuildStep(context -> { | ||
List<MongoClientBuildItem> mongoClientBuildItems = context.consumeMulti(MongoClientBuildItem.class); | ||
context.produce(new FeatureBuildItem("dummy")); | ||
}).consumes(MongoClientBuildItem.class) | ||
.produces(FeatureBuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
} |
2 changes: 2 additions & 0 deletions
2
extensions/mongodb-client/deployment/src/test/resources/named-mongoclient.properties
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,2 @@ | ||
quarkus.mongodb.connection-string=mongodb://localhost:27018 | ||
quarkus.mongodb.second.connection-string=mongodb://localhost:27018 |
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
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
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
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
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