File tree 8 files changed +59
-44
lines changed
consumer-driven-contracts-with-spring-cloud-contract
main/java/de/rieckpil/blog
test/java/de/rieckpil/blog
src/test/java/de/rieckpil/blog
8 files changed +59
-44
lines changed Original file line number Diff line number Diff line change @@ -4,5 +4,5 @@ Steps to run this project:
4
4
5
5
1 . Clone this Git repository
6
6
2 . Navigate to the folder ` consumer-driven-contracts-with-spring-cloud-contract `
7
- 3 . Navigate to the ` book-store-server ` folder and build the project with ` mvn install `
7
+ 3 . Navigate to the ` book-store-server ` folder and build the project with ` mvn install ` (yes - ` install ` is required here)
8
8
4 . Navigate to the ` book-store-client ` folder and execute ` mvn test ` . The tests should pass and make use of the ` book-store-server ` stubs
Original file line number Diff line number Diff line change 1
1
<?xml version =" 1.0" encoding =" UTF-8" ?>
2
- <project xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance" xmlns =" http://maven.apache.org/POM/4.0.0"
3
- xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
2
+ <project
3
+ xmlns : xsi =" http://www.w3.org/2001/XMLSchema-instance"
4
+ xmlns =" http://maven.apache.org/POM/4.0.0"
5
+ xsi : schemaLocation =" http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd" >
4
6
<modelVersion >4.0.0</modelVersion >
7
+
5
8
<parent >
6
9
<groupId >org.springframework.boot</groupId >
7
10
<artifactId >spring-boot-starter-parent</artifactId >
8
- <version >2.3.0.RELEASE </version >
11
+ <version >2.4.6 </version >
9
12
<relativePath /> <!-- lookup parent from repository -->
10
13
</parent >
14
+
11
15
<groupId >de.rieckpil.blog</groupId >
12
16
<artifactId >book-store-client</artifactId >
13
17
<version >0.0.1-SNAPSHOT</version >
16
20
17
21
<properties >
18
22
<java .version>11</java .version>
19
- <spring-cloud .version>Hoxton.SR5 </spring-cloud .version>
23
+ <spring-cloud .version>2020.0.2 </spring-cloud .version>
20
24
</properties >
21
25
22
26
<dependencies >
59
63
<groupId >org.springframework.boot</groupId >
60
64
<artifactId >spring-boot-maven-plugin</artifactId >
61
65
</plugin >
66
+ <plugin >
67
+ <groupId >org.apache.maven.plugins</groupId >
68
+ <artifactId >maven-surefire-plugin</artifactId >
69
+ <version >3.0.0-M5</version >
70
+ </plugin >
62
71
</plugins >
63
72
</build >
64
73
Original file line number Diff line number Diff line change 6
6
import io .netty .handler .timeout .WriteTimeoutHandler ;
7
7
import org .springframework .http .MediaType ;
8
8
import org .springframework .http .client .reactive .ReactorClientHttpConnector ;
9
+ import org .springframework .stereotype .Component ;
9
10
import org .springframework .stereotype .Service ;
10
11
import org .springframework .web .reactive .function .client .WebClient ;
11
12
import reactor .netty .http .client .HttpClient ;
12
- import reactor .netty .tcp .TcpClient ;
13
13
14
14
import javax .annotation .PostConstruct ;
15
15
16
- @ Service
16
+ @ Component
17
17
public class BookClient {
18
18
19
19
private WebClient webClient ;
20
20
21
21
@ PostConstruct
22
22
public void setUpWebClient () {
23
- var tcpClient = TcpClient .create ()
23
+ var httpClient = HttpClient .create ()
24
24
.option (ChannelOption .CONNECT_TIMEOUT_MILLIS , 2_000 )
25
25
.doOnConnected (connection ->
26
26
connection .addHandlerLast (new ReadTimeoutHandler (2 ))
27
27
.addHandlerLast (new WriteTimeoutHandler (2 )));
28
28
29
29
this .webClient = WebClient .builder ()
30
30
.baseUrl ("http://localhost:8080" )
31
- .clientConnector (new ReactorClientHttpConnector (HttpClient . from ( tcpClient ) ))
31
+ .clientConnector (new ReactorClientHttpConnector (httpClient ))
32
32
.build ();
33
33
}
34
34
Original file line number Diff line number Diff line change 9
9
10
10
import static org .junit .jupiter .api .Assertions .assertTrue ;
11
11
12
- @ SpringBootTest (webEnvironment = SpringBootTest .WebEnvironment .NONE )
13
- @ AutoConfigureStubRunner (ids = {"de.rieckpil.blog:book-store-server:+:stubs:8080" }, stubsMode = StubRunnerProperties .StubsMode .LOCAL )
14
- public class BookClientTest {
12
+ @ SpringBootTest
13
+ @ AutoConfigureStubRunner (
14
+ ids = {"de.rieckpil.blog:book-store-server:+:stubs:8080" },
15
+ stubsMode = StubRunnerProperties .StubsMode .LOCAL
16
+ )
17
+ class BookClientTest {
15
18
16
19
@ Autowired
17
20
private BookClient cut ;
18
21
19
22
@ Test
20
- public void testContractToBookStoreServer () {
23
+ void testContractToBookStoreServer () {
21
24
22
25
JsonNode result = cut .getAllAvailableBooks ();
23
26
@@ -32,5 +35,4 @@ public void testContractToBookStoreServer() {
32
35
assertTrue (firstBook .get ("genre" ).isTextual ());
33
36
assertTrue (firstBook .get ("title" ).isTextual ());
34
37
}
35
-
36
38
}
Original file line number Diff line number Diff line change 4
4
import org .springframework .boot .test .context .SpringBootTest ;
5
5
6
6
@ SpringBootTest
7
- public class BookStoreClientApplicationTests {
7
+ class BookStoreClientApplicationTests {
8
8
9
9
@ Test
10
- public void contextLoads () {
10
+ void contextLoads () {
11
11
}
12
12
13
13
}
Original file line number Diff line number Diff line change 6
6
<parent >
7
7
<groupId >org.springframework.boot</groupId >
8
8
<artifactId >spring-boot-starter-parent</artifactId >
9
- <version >2.3.0.RELEASE </version >
9
+ <version >2.4.6 </version >
10
10
<relativePath /> <!-- lookup parent from repository -->
11
11
</parent >
12
12
18
18
19
19
<properties >
20
20
<java .version>11</java .version>
21
- <spring-cloud .version>Hoxton.SR5 </spring-cloud .version>
21
+ <spring-cloud .version>2020.0.2 </spring-cloud .version>
22
22
</properties >
23
23
24
24
<dependencies >
55
55
</dependencies >
56
56
</dependencyManagement >
57
57
58
- <build >
59
- <plugins >
60
- <plugin >
61
- <groupId >org.springframework.boot</groupId >
62
- <artifactId >spring-boot-maven-plugin</artifactId >
63
- </plugin >
58
+ <build >
59
+ <plugins >
60
+ <plugin >
61
+ <groupId >org.springframework.boot</groupId >
62
+ <artifactId >spring-boot-maven-plugin</artifactId >
63
+ </plugin >
64
+ <plugin >
65
+ <groupId >org.springframework.cloud</groupId >
66
+ <artifactId >spring-cloud-contract-maven-plugin</artifactId >
67
+ <version >3.0.2</version >
68
+ <extensions >true</extensions >
69
+ <configuration >
70
+ <baseClassForTests >de.rieckpil.blog.BaseTest</baseClassForTests >
71
+ </configuration >
72
+ </plugin >
64
73
<plugin >
65
- <groupId >org.springframework.cloud</groupId >
66
- <artifactId >spring-cloud-contract-maven-plugin</artifactId >
67
- <version >2.2.2.RELEASE</version >
68
- <extensions >true</extensions >
69
- <configuration >
70
- <baseClassForTests >de.rieckpil.blog.BaseTest</baseClassForTests >
71
- </configuration >
74
+ <groupId >org.apache.maven.plugins</groupId >
75
+ <artifactId >maven-surefire-plugin</artifactId >
76
+ <version >3.0.0-M5</version >
72
77
</plugin >
73
78
</plugins >
74
79
</build >
Original file line number Diff line number Diff line change 1
1
package de .rieckpil .blog ;
2
2
3
3
import io .restassured .module .mockmvc .RestAssuredMockMvc ;
4
- import org .junit .Before ;
5
- import org .junit .runner . RunWith ;
4
+ import org .junit .jupiter . api . BeforeEach ;
5
+ import org .junit .jupiter . api . extension . ExtendWith ;
6
6
import org .mockito .Mock ;
7
- import org .springframework . test . context . junit4 . SpringRunner ;
7
+ import org .mockito . junit . jupiter . MockitoExtension ;
8
8
9
9
import java .util .List ;
10
10
11
11
import static org .mockito .Mockito .when ;
12
12
13
- @ RunWith ( SpringRunner .class )
13
+ @ ExtendWith ( MockitoExtension .class )
14
14
public abstract class BaseTest {
15
15
16
16
@ Mock
17
17
private BookService mockedBookService ;
18
18
19
- @ Before
20
- public void setup () {
21
- when (mockedBookService .getBooks ()).thenReturn (List .of (new Book ("Java 11" , "Technology" , "42" )));
19
+ @ BeforeEach
20
+ void setup () {
21
+ when (mockedBookService .getBooks ())
22
+ .thenReturn (List .of (new Book ("Java 11" , "Technology" , "42" )));
23
+
22
24
RestAssuredMockMvc .standaloneSetup (new BookController (mockedBookService ));
23
25
}
24
26
}
Original file line number Diff line number Diff line change 1
1
package de .rieckpil .blog ;
2
2
3
- import org .junit .Test ;
4
- import org .junit .runner .RunWith ;
3
+ import org .junit .jupiter .api .Test ;
5
4
import org .springframework .boot .test .context .SpringBootTest ;
6
- import org .springframework .test .context .junit4 .SpringRunner ;
7
5
8
- @ RunWith (SpringRunner .class )
9
6
@ SpringBootTest
10
- public class BookStoreServerApplicationTests {
7
+ class BookStoreServerApplicationTests {
11
8
12
9
@ Test
13
- public void contextLoads () {
10
+ void contextLoads () {
14
11
}
15
12
16
13
}
You can’t perform that action at this time.
0 commit comments