import org.junit.jupiter.api.Test;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
-import org.springframework.boot.test.web.server.LocalServerPort;
import org.springframework.core.io.Resource;
import org.springframework.http.MediaType;
import org.springframework.test.annotation.DirtiesContext;
String NONEXISTENT_CHATROOM = "7f59ec77-832e-4a17-8d22-55ef46242c17";
- @LocalServerPort
- int port;
@Autowired
WebTestClient webTestClient;
@Autowired
{
webTestClient
.get()
- .uri(
- "http://localhost:{port}/actuator/health",
- port)
+ .uri("/actuator/health")
.exchange()
.expectStatus().isOk()
.expectBody().jsonPath("$.status").isEqualTo("UP");
AtomicBoolean existingChatRoomFound = new AtomicBoolean(false);
webTestClient
.get()
- .uri(
- "http://localhost:{port}/list",
- port)
+ .uri("/list")
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
{
webTestClient
.get()
- .uri(
- "http://localhost:{port}/{chatRoomId}",
- port,
- EXISTING_CHATROOM)
+ .uri("/{chatRoomId}", EXISTING_CHATROOM)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
{
webTestClient
.get()
- .uri(
- "http://localhost:{port}/{chatRoomId}/ute/1",
- port,
- EXISTING_CHATROOM)
+ .uri("/{chatRoomId}/ute/1", EXISTING_CHATROOM)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
{
webTestClient
.get()
- .uri(
- "http://localhost:{port}/{chatRoomId}/peter/1",
- port,
- EXISTING_CHATROOM)
+ .uri("/{chatRoomId}/peter/1", EXISTING_CHATROOM)
.accept(MediaType.APPLICATION_JSON)
.exchange()
.expectStatus().isOk()
{
webTestClient
.put()
- .uri(
- "http://localhost:{port}/{chatRoomId}/otto/66",
- port,
- NONEXISTENT_CHATROOM)
+ .uri("/{chatRoomId}/otto/66", NONEXISTENT_CHATROOM)
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON)
.bodyValue("The devil rules route 66")
// that is owned by the instance
chatRoomInfo = webTestClient
.post()
- .uri("http://localhost:{port}/create", port)
+ .uri("/create")
.contentType(MediaType.TEXT_PLAIN)
.bodyValue("bar")
.accept(MediaType.APPLICATION_JSON)
{
webTestClient
.put()
- .uri(
- "http://localhost:{port}/{chatRoomId}/nerd/7",
- port,
- chatRoomId)
+ .uri("/{chatRoomId}/nerd/7", chatRoomId)
.contentType(MediaType.TEXT_PLAIN)
.accept(MediaType.APPLICATION_JSON)
.bodyValue("Hello world!")
MessageTo sentMessage = webTestClient
.put()
.uri(
- "http://localhost:{port}/{chatRoomId}/nerd/{messageId}",
- port,
+ "/{chatRoomId}/nerd/{messageId}",
EXISTING_CHATROOM,
RandomGenerator.getDefault().nextInt())
.contentType(MediaType.TEXT_PLAIN)
Flux<MessageTo> result = webTestClient
.get()
- .uri(
- "http://localhost:{port}/{chatRoomId}/listen",
- port,
- EXISTING_CHATROOM)
+ .uri("/{chatRoomId}/listen", EXISTING_CHATROOM)
.accept(MediaType.TEXT_EVENT_STREAM)
.exchange()
.expectStatus().isOk()