Skip to content

Commit 69998c9

Browse files
committed
closes #1697: add vhost parameter for policies
1 parent 3806235 commit 69998c9

File tree

2 files changed

+29
-15
lines changed

2 files changed

+29
-15
lines changed

modules/rabbitmq/src/main/java/org/testcontainers/containers/RabbitMQContainer.java

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -263,6 +263,15 @@ public RabbitMQContainer withPolicy(String name, String pattern, Map<String, Obj
263263
return self();
264264
}
265265

266+
public RabbitMQContainer withPolicy(String vhost, String name, String pattern, Map<String, Object> definition) {
267+
values.add(asList("rabbitmqadmin", "declare", "policy",
268+
"--vhost=" + vhost,
269+
"name=" + name,
270+
"pattern=" + pattern,
271+
"definition=" + toJson(definition)));
272+
return self();
273+
}
274+
266275
public RabbitMQContainer withPolicy(String name, String pattern, Map<String, Object> definition, int priority, String applyTo) {
267276
values.add(asList("rabbitmqadmin", "declare", "policy",
268277
"name=" + name,

modules/rabbitmq/src/test/java/org/testcontainers/containers/RabbitMQContainerTest.java

Lines changed: 20 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -154,21 +154,22 @@ public void shouldStartTheWholeEnchilada() throws IOException, InterruptedExcept
154154
{
155155
try (RabbitMQContainer container = new RabbitMQContainer()) {
156156
container
157-
.withVhost("vhost1")
158-
.withVhostLimit("vhost1", "max-connections", 1)
159-
.withVhost("vhost2", true)
160-
.withExchange("direct-exchange", "direct")
161-
.withExchange("topic-exchange", "topic")
162-
.withQueue("queue1")
163-
.withQueue("queue2", true, false, ImmutableMap.of("x-message-ttl", 1000))
164-
.withBinding("direct-exchange", "queue1")
165-
.withUser("user1", "password1")
166-
.withUser("user2", "password2", ImmutableSet.of("administrator"))
167-
.withPermission("vhost1", "user1", ".*", ".*", ".*")
168-
.withPolicy("max length policy", "^dog", ImmutableMap.of("max-length", 1), 1, "queues")
169-
.withPolicy("alternate exchange policy", "^direct-exchange", ImmutableMap.of("alternate-exchange", "amq.direct"))
170-
.withOperatorPolicy("operator policy 1", "^queue1", ImmutableMap.of("message-ttl", 1000), 1, "queues")
171-
.withPluginsEnabled("rabbitmq_shovel", "rabbitmq_random_exchange");
157+
.withVhost("vhost1")
158+
.withVhostLimit("vhost1", "max-connections", 1)
159+
.withVhost("vhost2", true)
160+
.withExchange("direct-exchange", "direct")
161+
.withExchange("topic-exchange", "topic")
162+
.withQueue("queue1")
163+
.withQueue("queue2", true, false, ImmutableMap.of("x-message-ttl", 1000))
164+
.withBinding("direct-exchange", "queue1")
165+
.withUser("user1", "password1")
166+
.withUser("user2", "password2", ImmutableSet.of("administrator"))
167+
.withPermission("vhost1", "user1", ".*", ".*", ".*")
168+
.withPolicy("max length policy", "^dog", ImmutableMap.of("max-length", 1), 1, "queues")
169+
.withPolicy("alternate exchange policy", "^direct-exchange", ImmutableMap.of("alternate-exchange", "amq.direct"))
170+
.withPolicy("vhost2", "ha-all", ".*", ImmutableMap.of("ha-mode", "all", "ha-sync-mode", "automatic"))
171+
.withOperatorPolicy("operator policy 1", "^queue1", ImmutableMap.of("message-ttl", 1000), 1, "queues")
172+
.withPluginsEnabled("rabbitmq_shovel", "rabbitmq_random_exchange");
172173

173174
container.start();
174175

@@ -192,6 +193,10 @@ public void shouldStartTheWholeEnchilada() throws IOException, InterruptedExcept
192193
.getStdout())
193194
.contains("max length policy", "alternate exchange policy");
194195

196+
assertThat(container.execInContainer("rabbitmqadmin", "list", "policies", "--vhost=vhost2")
197+
.getStdout())
198+
.contains("ha-all", "ha-sync-mode");
199+
195200
assertThat(container.execInContainer("rabbitmqadmin", "list", "operator_policies")
196201
.getStdout())
197202
.contains("operator policy 1");

0 commit comments

Comments
 (0)