-
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.
Add CommandListener implementors to the mongoDB configuration.
- Loading branch information
jzuriaga
committed
Sep 30, 2020
1 parent
943e909
commit 8a5a020
Showing
7 changed files
with
127 additions
and
6 deletions.
There are no files selected for viewing
18 changes: 18 additions & 0 deletions
18
...ient/deployment/src/main/java/io/quarkus/mongodb/deployment/CommandListenerBuildItem.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,18 @@ | ||
package io.quarkus.mongodb.deployment; | ||
|
||
import java.util.List; | ||
|
||
import io.quarkus.builder.item.SimpleBuildItem; | ||
|
||
public final class CommandListenerBuildItem extends SimpleBuildItem { | ||
|
||
private List<String> commandListenerClassNames; | ||
|
||
public CommandListenerBuildItem(List<String> commandListenerClassNames) { | ||
this.commandListenerClassNames = commandListenerClassNames; | ||
} | ||
|
||
public List<String> getCommandListenerClassNames() { | ||
return commandListenerClassNames; | ||
} | ||
} |
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
18 changes: 18 additions & 0 deletions
18
...sions/mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MockCommandListener.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,18 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
import com.mongodb.event.CommandListener; | ||
import com.mongodb.event.CommandStartedEvent; | ||
|
||
public class MockCommandListener implements CommandListener { | ||
|
||
public static final List<String> EVENTS = new ArrayList<>(); | ||
|
||
@Override | ||
public void commandStarted(CommandStartedEvent startedEvent) { | ||
EVENTS.add(startedEvent.getCommandName()); | ||
} | ||
|
||
} |
46 changes: 46 additions & 0 deletions
46
.../mongodb-client/deployment/src/test/java/io/quarkus/mongodb/MongoCommandListenerTest.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,46 @@ | ||
package io.quarkus.mongodb; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.hamcrest.MatcherAssert.assertThat; | ||
import static org.hamcrest.Matchers.equalTo; | ||
import static org.hamcrest.Matchers.hasItems; | ||
import static org.hamcrest.Matchers.hasSize; | ||
|
||
import javax.inject.Inject; | ||
|
||
import org.jboss.shrinkwrap.api.ShrinkWrap; | ||
import org.jboss.shrinkwrap.api.spec.JavaArchive; | ||
import org.junit.jupiter.api.AfterEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.extension.RegisterExtension; | ||
|
||
import com.mongodb.client.MongoClient; | ||
|
||
import io.quarkus.test.QuarkusUnitTest; | ||
|
||
public class MongoCommandListenerTest extends MongoTestBase { | ||
|
||
@Inject | ||
MongoClient client; | ||
|
||
@RegisterExtension | ||
static final QuarkusUnitTest config = new QuarkusUnitTest() | ||
.setArchiveProducer( | ||
() -> ShrinkWrap.create(JavaArchive.class).addClasses(MongoTestBase.class, MockCommandListener.class)) | ||
.withConfigurationResource("default-mongoclient.properties"); | ||
|
||
@AfterEach | ||
void cleanup() { | ||
if (client != null) { | ||
client.close(); | ||
} | ||
} | ||
|
||
@Test | ||
void testClientInitialization() { | ||
assertThat(client.listDatabaseNames().first()).isNotEmpty(); | ||
assertThat(MockCommandListener.EVENTS, hasSize(1)); | ||
assertThat(MockCommandListener.EVENTS, hasItems(equalTo("listDatabases"))); | ||
} | ||
|
||
} |
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