forked from quarkusio/quarkus
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request quarkusio#36503 from cescoffier/mongo-client-side-…
…encryption-jvm Allows Mongo client settings customization
- Loading branch information
Showing
10 changed files
with
399 additions
and
9 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
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
43 changes: 43 additions & 0 deletions
43
...ient/deployment/src/test/java/io/quarkus/mongodb/customization/DefaultCustomizerTest.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,43 @@ | ||
package io.quarkus.mongodb.customization; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.client.MongoClient; | ||
import com.mongodb.client.internal.MongoClientImpl; | ||
|
||
import io.quarkus.arc.ClientProxy; | ||
import io.quarkus.mongodb.MongoTestBase; | ||
import io.quarkus.mongodb.runtime.MongoClientCustomizer; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class DefaultCustomizerTest extends MongoTestBase { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class, MyCustomizer.class)) | ||
.withConfigurationResource("default-mongoclient.properties"); | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@Test | ||
void testCustomizationOnDefaultConnection() { | ||
MongoClientImpl clientImpl = (MongoClientImpl) ClientProxy.unwrap(client); | ||
Assertions.assertThat(clientImpl.getSettings().getApplicationName()).isEqualTo("my-app"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-app"); | ||
} | ||
} | ||
} |
60 changes: 60 additions & 0 deletions
60
...client/deployment/src/test/java/io/quarkus/mongodb/customization/NamedCustomizerTest.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,60 @@ | ||
package io.quarkus.mongodb.customization; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.client.MongoClient; | ||
import com.mongodb.client.internal.MongoClientImpl; | ||
|
||
import io.quarkus.arc.ClientProxy; | ||
import io.quarkus.mongodb.MongoClientName; | ||
import io.quarkus.mongodb.MongoTestBase; | ||
import io.quarkus.mongodb.runtime.MongoClientCustomizer; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class NamedCustomizerTest extends MongoTestBase { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class, MyCustomizer.class)) | ||
.withConfigurationResource("named-mongoclient.properties"); | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@Inject | ||
@MongoClientName("second") | ||
MongoClient secondClient; | ||
|
||
@Test | ||
void testCustomizationOnTwoConnections() { | ||
MongoClientImpl clientImpl = (MongoClientImpl) ClientProxy.unwrap(client); | ||
MongoClientImpl secondClientImpl = (MongoClientImpl) ClientProxy.unwrap(secondClient); | ||
Assertions.assertThat(clientImpl.getSettings().getApplicationName()).isEqualTo("my-app"); | ||
Assertions.assertThat(secondClientImpl.getSettings().getApplicationName()).isEqualTo("my-second-app"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-app"); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@MongoClientName("second") | ||
public static class MySecondCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-second-app"); | ||
} | ||
} | ||
} |
54 changes: 54 additions & 0 deletions
54
...loyment/src/test/java/io/quarkus/mongodb/customization/TooManyDefaultCustomizersTest.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,54 @@ | ||
package io.quarkus.mongodb.customization; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.mongodb.MongoTestBase; | ||
import io.quarkus.mongodb.runtime.MongoClientCustomizer; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class TooManyDefaultCustomizersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class, MyCustomizer.class, MySecondCustomizer.class)) | ||
.withConfigurationResource("default-mongoclient.properties") | ||
.assertException(t -> Assertions.assertThat(t).isInstanceOf(DeploymentException.class) | ||
.hasMessageContaining("Multiple Mongo client customizers found for client <default>: ")); | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@Test | ||
void test() { | ||
fail("Should not be run"); | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MyCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-app"); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
public static class MySecondCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-second-app"); | ||
} | ||
} | ||
} |
58 changes: 58 additions & 0 deletions
58
...eployment/src/test/java/io/quarkus/mongodb/customization/TooManyNamedCustomizersTest.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,58 @@ | ||
package io.quarkus.mongodb.customization; | ||
|
||
import static org.junit.jupiter.api.Assertions.fail; | ||
|
||
import jakarta.enterprise.context.ApplicationScoped; | ||
import jakarta.enterprise.inject.spi.DeploymentException; | ||
import jakarta.inject.Inject; | ||
|
||
import org.assertj.core.api.Assertions; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.MongoClientSettings; | ||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.mongodb.MongoClientName; | ||
import io.quarkus.mongodb.MongoTestBase; | ||
import io.quarkus.mongodb.runtime.MongoClientCustomizer; | ||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class TooManyNamedCustomizersTest { | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.withApplicationRoot((jar) -> jar.addClasses(MongoTestBase.class, MyCustomizer.class, MySecondCustomizer.class)) | ||
.withConfigurationResource("named-mongoclient.properties") | ||
.assertException(t -> Assertions.assertThat(t).isInstanceOf(DeploymentException.class) | ||
.hasMessageContaining("Multiple Mongo client customizers found for client second: ")); | ||
|
||
@Inject | ||
@MongoClientName("second") | ||
MongoClient client; | ||
|
||
@Test | ||
void test() { | ||
fail("Should not be run"); | ||
} | ||
|
||
@ApplicationScoped | ||
@MongoClientName("second") | ||
public static class MyCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-app"); | ||
} | ||
} | ||
|
||
@ApplicationScoped | ||
@MongoClientName("second") | ||
public static class MySecondCustomizer implements MongoClientCustomizer { | ||
|
||
@Override | ||
public MongoClientSettings.Builder customize(MongoClientSettings.Builder builder) { | ||
return builder.applicationName("my-second-app"); | ||
} | ||
} | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -205,4 +205,5 @@ public class MongoClientConfig { | |
*/ | ||
@ConfigItem | ||
public Optional<UuidRepresentation> uuidRepresentation; | ||
|
||
} |
Oops, something went wrong.