-
Notifications
You must be signed in to change notification settings - Fork 2.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fix broken MongoClientBuildItem support
Fixes: #7378
- Loading branch information
Showing
8 changed files
with
216 additions
and
52 deletions.
There are no files selected for viewing
20 changes: 20 additions & 0 deletions
20
...ient/deployment/src/main/java/io/quarkus/mongodb/deployment/MongoClientNameBuildItem.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,20 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
import io.quarkus.mongodb.runtime.MongoClientName; | ||
|
||
/** | ||
* Represents the values of the {@link MongoClientName} | ||
*/ | ||
final class MongoClientNameBuildItem extends MultiBuildItem { | ||
|
||
private final String name; | ||
|
||
public MongoClientNameBuildItem(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
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
19 changes: 19 additions & 0 deletions
19
.../deployment/src/main/java/io/quarkus/mongodb/deployment/MongoConnectionNameBuildItem.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,19 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import io.quarkus.builder.item.MultiBuildItem; | ||
|
||
/** | ||
* Holds a Mongo connection name | ||
*/ | ||
final class MongoConnectionNameBuildItem extends MultiBuildItem { | ||
|
||
private final String name; | ||
|
||
public MongoConnectionNameBuildItem(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
...loyment/src/main/java/io/quarkus/mongodb/deployment/MongoUnremovableClientsBuildItem.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,10 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
/** | ||
* If generated, all the Mongo clients need to be unremovable | ||
*/ | ||
final class MongoUnremovableClientsBuildItem extends SimpleBuildItem { | ||
|
||
} |
52 changes: 52 additions & 0 deletions
52
...-client/deployment/src/test/java/io/quarkus/mongodb/MongoClientBuildItemConsumerTest.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,52 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
|
||
import java.util.List; | ||
import java.util.function.Consumer; | ||
|
||
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.FeatureBuildItem; | ||
import io.quarkus.mongodb.deployment.MongoClientBuildItem; | ||
import io.quarkus.mongodb.reactive.ReactiveMongoClient; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MongoClientBuildItemConsumerTest { | ||
|
||
@RegisterExtension | ||
static QuarkusUnitTest runner = new QuarkusUnitTest() | ||
.setArchiveProducer(() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class)) | ||
.withConfigurationResource("default-mongoclient.properties") | ||
.addBuildChainCustomizer(buildCustomizer()); | ||
|
||
@Test | ||
public void testContainerHasBeans() { | ||
assertThat(Arc.container().instance(MongoClient.class).get()).isNotNull(); | ||
assertThat(Arc.container().instance(ReactiveMongoClient.class).get()).isNotNull(); | ||
// this one hasn't been made un-removeable because it's not used in MongoClientBuildItem | ||
assertThat(Arc.container().instance(io.quarkus.mongodb.ReactiveMongoClient.class).get()).isNull(); | ||
} | ||
|
||
protected static Consumer<BuildChainBuilder> buildCustomizer() { | ||
return new Consumer<BuildChainBuilder>() { | ||
// This represents the extension. | ||
@Override | ||
public void accept(BuildChainBuilder builder) { | ||
builder.addBuildStep(context -> { | ||
List<MongoClientBuildItem> mongoClientBuildItems = context.consumeMulti(MongoClientBuildItem.class); | ||
context.produce(new FeatureBuildItem("dummy")); | ||
}).consumes(MongoClientBuildItem.class) | ||
.produces(FeatureBuildItem.class) | ||
.build(); | ||
} | ||
}; | ||
} | ||
} |
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
Oops, something went wrong.