-
Notifications
You must be signed in to change notification settings - Fork 317
Expand file tree
/
Copy pathBeerControllerWebClientTest.java
More file actions
107 lines (85 loc) · 2.91 KB
/
BeerControllerWebClientTest.java
File metadata and controls
107 lines (85 loc) · 2.91 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
package com.example;
import java.util.Objects;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.springframework.boot.test.autoconfigure.json.AutoConfigureJsonTesters;
import org.springframework.boot.webmvc.test.autoconfigure.AutoConfigureMockMvc;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.context.SpringBootTest.WebEnvironment;
import org.springframework.cloud.contract.stubrunner.spring.AutoConfigureStubRunner;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerPort;
import org.springframework.cloud.contract.stubrunner.spring.StubRunnerProperties;
import org.springframework.test.annotation.DirtiesContext;
import org.springframework.test.web.reactive.server.WebTestClient;
/**
* @author Marcin Grzejszczak
*/
@SpringBootTest(webEnvironment = WebEnvironment.MOCK)
@AutoConfigureMockMvc
@AutoConfigureJsonTesters
@AutoConfigureStubRunner(stubsMode = StubRunnerProperties.StubsMode.LOCAL, ids = "com.example:beer-api-producer-webflux")
@DirtiesContext
//@org.junit.jupiter.api.Disabled
public class BeerControllerWebClientTest extends AbstractTest {
@StubRunnerPort("beer-api-producer-webflux") int producerPort;
@Test
@Disabled("TODO: Issues with RestAssured")
public void should_give_me_a_beer_when_im_old_enough() throws Exception {
WebTestClient.bindToServer()
.build()
.post()
.uri("http://localhost:" + this.producerPort + "/check")
.bodyValue(new WebClientPerson("marcin", 22))
.header("Content-Type", "application/json")
.exchange()
.expectStatus().is2xxSuccessful()
.expectBody(WebClientResponse.class)
.isEqualTo(new WebClientResponse(WebClientResponseStatus.OK));
}
@Test
@Disabled("TODO: Issues with RestAssured")
public void should_reject_a_beer_when_im_too_young() throws Exception {
WebTestClient.bindToServer()
.build()
.post()
.uri("http://localhost:" + this.producerPort + "/check")
.bodyValue(new WebClientPerson("marcin", 17))
.header("Content-Type", "application/json")
.exchange()
.expectStatus().is2xxSuccessful()
.expectBody(WebClientResponse.class)
.isEqualTo(new WebClientResponse(WebClientResponseStatus.NOT_OK));
}
}
class WebClientPerson {
public String name;
public int age;
public WebClientPerson(String name, int age) {
this.name = name;
this.age = age;
}
public WebClientPerson() {
}
}
class WebClientResponse {
public WebClientResponseStatus status;
WebClientResponse(WebClientResponseStatus status) {
this.status = status;
}
WebClientResponse() {
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
WebClientResponse that = (WebClientResponse) o;
return this.status == that.status;
}
@Override
public int hashCode() {
return Objects.hash(this.status);
}
}
enum WebClientResponseStatus {
OK, NOT_OK
}