|
29 | 29 | import net.luckperms.rest.event.EventCall; |
30 | 30 | import net.luckperms.rest.event.EventProducer; |
31 | 31 | import net.luckperms.rest.model.Action; |
| 32 | +import net.luckperms.rest.model.CustomMessage; |
| 33 | +import net.luckperms.rest.model.CustomMessageReceiveEvent; |
32 | 34 | import net.luckperms.rest.model.LogBroadcastEvent; |
33 | 35 | import org.junit.jupiter.api.Disabled; |
34 | 36 | import org.junit.jupiter.api.Test; |
| 37 | +import org.testcontainers.containers.GenericContainer; |
| 38 | +import org.testcontainers.containers.Network; |
| 39 | +import org.testcontainers.utility.DockerImageName; |
35 | 40 |
|
36 | 41 | import java.io.IOException; |
37 | 42 | import java.util.ArrayList; |
|
41 | 46 | import java.util.concurrent.CountDownLatch; |
42 | 47 | import java.util.concurrent.TimeUnit; |
43 | 48 | import java.util.function.Consumer; |
| 49 | +import java.util.function.Supplier; |
44 | 50 |
|
45 | 51 | import static org.junit.jupiter.api.Assertions.assertEquals; |
46 | 52 | import static org.junit.jupiter.api.Assertions.assertNotSame; |
@@ -72,6 +78,39 @@ public void testLogBroadcastEvent() throws Exception { |
72 | 78 | assertNotSame(event.entry(), exampleAction); |
73 | 79 | } |
74 | 80 |
|
| 81 | + @Test |
| 82 | + public void testCustomMessageReceiveEvent() throws Exception { |
| 83 | + try (Network network = Network.newNetwork(); GenericContainer<?> redis = new GenericContainer<>(DockerImageName.parse("redis"))) { |
| 84 | + redis.withNetwork(network).withNetworkAliases("redis").start(); |
| 85 | + |
| 86 | + Supplier<GenericContainer<?>> restSupplier = () -> createContainer() |
| 87 | + .withNetwork(network) |
| 88 | + .withEnv("LUCKPERMS_MESSAGING_SERVICE", "redis") |
| 89 | + .withEnv("LUCKPERMS_REDIS_ENABLED", "true") |
| 90 | + .withEnv("LUCKPERMS_REDIS_ADDRESS", "redis:6379"); |
| 91 | + |
| 92 | + try (GenericContainer<?> restA = restSupplier.get(); GenericContainer<?> restB = restSupplier.get()) { |
| 93 | + restA.start(); |
| 94 | + restB.start(); |
| 95 | + |
| 96 | + LuckPermsRestClient clientA = createClient(restA); |
| 97 | + LuckPermsRestClient clientB = createClient(restB); |
| 98 | + |
| 99 | + EventCall<CustomMessageReceiveEvent> call = clientA.events().customMessageReceive(); |
| 100 | + CustomMessageReceiveEvent event = testEvent(call, 5, () -> { |
| 101 | + try { |
| 102 | + clientB.messaging().sendCustomMessage(new CustomMessage("custom:test", "aaabbbccc")).execute(); |
| 103 | + } catch (IOException e) { |
| 104 | + throw new RuntimeException(e); |
| 105 | + } |
| 106 | + }); |
| 107 | + |
| 108 | + assertEquals("custom:test", event.channelId()); |
| 109 | + assertEquals("aaabbbccc", event.payload()); |
| 110 | + } |
| 111 | + } |
| 112 | + } |
| 113 | + |
75 | 114 | @Test |
76 | 115 | @Disabled("takes too long to run") |
77 | 116 | public void testLogBroadcastEventLongWait() throws Exception { |
|
0 commit comments