BAEL-503: initial commit of a simple Spring AMQL example application (#1467)

This commit is contained in:
Justin Wilson
2017-03-22 12:47:23 +00:00
committed by maibin
parent d66703b5d9
commit e71358a9de
9 changed files with 217 additions and 0 deletions
@@ -0,0 +1,45 @@
package com.baeldung.springamqpsimple;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.amqp.rabbit.core.RabbitTemplate;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.test.context.ActiveProfiles;
import org.springframework.test.context.junit4.SpringRunner;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.verify;
@RunWith(SpringRunner.class)
@ActiveProfiles("test")
@SpringBootTest(webEnvironment=SpringBootTest.WebEnvironment.RANDOM_PORT)
public class MessageControllerTest {
@Autowired
private TestRestTemplate restTemplate;
@MockBean
private RabbitTemplate rabbitTemplate;
@Test
public void whenPostingMessage_thenMessageIsCreated() {
final String message = "Hello World!";
ResponseEntity<Void> responseEntity = restTemplate.postForEntity("/messages", message, Void.class);
assertEquals(HttpStatus.CREATED, responseEntity.getStatusCode());
}
@Test
public void whenPostingMessage_thenMessageIsSentToBroker() {
final String message = "Hello World!";
restTemplate.postForEntity("/messages", message, Void.class);
verify(rabbitTemplate).convertAndSend(SpringAmqpConfig.queueName, message);
}
}