Skip to content

Commit 02ba888

Browse files
committed
Add smoke test for RabbitMQ AMQP 1.0
Signed-off-by: Eddú Meléndez <[email protected]>
1 parent 91b9044 commit 02ba888

File tree

5 files changed

+181
-0
lines changed

5 files changed

+181
-0
lines changed

settings.gradle

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -331,6 +331,7 @@ include ":smoke-test:spring-boot-smoke-test-prometheus"
331331
include ":smoke-test:spring-boot-smoke-test-property-validation"
332332
include ":smoke-test:spring-boot-smoke-test-pulsar"
333333
include ":smoke-test:spring-boot-smoke-test-quartz"
334+
include ":smoke-test:spring-boot-smoke-test-rabbit-amqp"
334335
include ":smoke-test:spring-boot-smoke-test-reactive-oauth2-client"
335336
include ":smoke-test:spring-boot-smoke-test-reactive-oauth2-resource-server"
336337
include ":smoke-test:spring-boot-smoke-test-rsocket"
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the License);
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
plugins {
18+
id "java"
19+
id "org.springframework.boot.docker-test"
20+
}
21+
22+
description = "Spring Boot RabbitMQ AMQP smoke test"
23+
24+
dependencies {
25+
implementation(project(":starter:spring-boot-starter-amqp"))
26+
implementation("org.springframework.amqp:spring-rabbitmq-client")
27+
28+
dockerTestImplementation(project(":starter:spring-boot-starter-test"))
29+
dockerTestImplementation(project(":core:spring-boot-testcontainers"))
30+
dockerTestImplementation(project(":test-support:spring-boot-docker-test-support"))
31+
dockerTestImplementation("org.awaitility:awaitility")
32+
dockerTestImplementation("org.testcontainers:junit-jupiter")
33+
dockerTestImplementation("org.testcontainers:rabbitmq")
34+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.amqp;
18+
19+
import java.time.Duration;
20+
21+
import org.awaitility.Awaitility;
22+
import org.junit.jupiter.api.Test;
23+
import org.junit.jupiter.api.extension.ExtendWith;
24+
import org.testcontainers.containers.RabbitMQContainer;
25+
import org.testcontainers.junit.jupiter.Container;
26+
import org.testcontainers.junit.jupiter.Testcontainers;
27+
28+
import org.springframework.beans.factory.annotation.Autowired;
29+
import org.springframework.boot.test.context.SpringBootTest;
30+
import org.springframework.boot.test.system.CapturedOutput;
31+
import org.springframework.boot.test.system.OutputCaptureExtension;
32+
import org.springframework.boot.testcontainers.service.connection.ServiceConnection;
33+
34+
import static org.assertj.core.api.Assertions.assertThat;
35+
36+
@SpringBootTest
37+
@Testcontainers(disabledWithoutDocker = true)
38+
@ExtendWith(OutputCaptureExtension.class)
39+
class SampleRabbitAmqpSimpleApplicationTests {
40+
41+
@Container
42+
@ServiceConnection
43+
static final RabbitMQContainer rabbit = new RabbitMQContainer("rabbitmq:4.0-management-alpine");
44+
45+
@Autowired
46+
private Sender sender;
47+
48+
@Test
49+
void sendSimpleMessage(CapturedOutput output) {
50+
this.sender.send("Test message");
51+
Awaitility.waitAtMost(Duration.ofMinutes(1)).untilAsserted(() -> assertThat(output).contains("Test message"));
52+
}
53+
54+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.amqp;
18+
19+
import org.apache.commons.logging.Log;
20+
import org.apache.commons.logging.LogFactory;
21+
22+
import org.springframework.amqp.core.Queue;
23+
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
24+
import org.springframework.amqp.rabbit.annotation.RabbitListener;
25+
import org.springframework.boot.ApplicationRunner;
26+
import org.springframework.boot.SpringApplication;
27+
import org.springframework.boot.autoconfigure.SpringBootApplication;
28+
import org.springframework.context.annotation.Bean;
29+
import org.springframework.messaging.handler.annotation.Payload;
30+
31+
@SpringBootApplication
32+
@RabbitListener(queues = "foo")
33+
public class SampleRabbitAmqpSimpleApplication {
34+
35+
private static final Log logger = LogFactory.getLog(SampleRabbitAmqpSimpleApplication.class);
36+
37+
@Bean
38+
public Sender mySender() {
39+
return new Sender();
40+
}
41+
42+
@Bean
43+
public Queue fooQueue() {
44+
return new Queue("foo");
45+
}
46+
47+
@RabbitHandler
48+
public void process(@Payload String foo) {
49+
logger.info(foo);
50+
}
51+
52+
@Bean
53+
public ApplicationRunner runner(Sender sender) {
54+
return (args) -> sender.send("Hello");
55+
}
56+
57+
public static void main(String[] args) {
58+
SpringApplication.run(SampleRabbitAmqpSimpleApplication.class, args);
59+
}
60+
61+
}
Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
/*
2+
* Copyright 2012-present the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package smoketest.amqp;
18+
19+
import org.springframework.amqp.rabbitmq.client.RabbitAmqpTemplate;
20+
import org.springframework.beans.factory.annotation.Autowired;
21+
22+
public class Sender {
23+
24+
@Autowired
25+
private RabbitAmqpTemplate rabbitAmqpTemplate;
26+
27+
public void send(String message) {
28+
this.rabbitAmqpTemplate.convertAndSend("foo", message);
29+
}
30+
31+
}

0 commit comments

Comments
 (0)