forked from hantsy/spring-reactive-sample
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
5 changed files
with
123 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
78 changes: 78 additions & 0 deletions
78
data-mongo-pageable/src/test/java/com/example/demo/IntegrationTests.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
/* | ||
* To change this license header, choose License Headers in Project Properties. | ||
* To change this template file, choose Tools | Templates | ||
* and open the template in the editor. | ||
*/ | ||
package com.example.demo; | ||
|
||
import org.junit.Before; | ||
import org.junit.Test; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.beans.factory.annotation.Value; | ||
import org.springframework.context.ApplicationContext; | ||
import org.springframework.test.context.ActiveProfiles; | ||
import org.springframework.test.context.ContextConfiguration; | ||
import org.springframework.test.context.junit4.SpringRunner; | ||
import org.springframework.test.web.reactive.server.WebTestClient; | ||
|
||
import java.time.Duration; | ||
|
||
/** | ||
* | ||
* @author hantsy | ||
*/ | ||
@RunWith(SpringRunner.class) | ||
@ContextConfiguration(classes = Application.class) | ||
public class IntegrationTests { | ||
|
||
@Value("#{@nettyContext.address().getPort()}") | ||
int port; | ||
|
||
WebTestClient rest; | ||
|
||
@Before | ||
public void setup() { | ||
this.rest =WebTestClient | ||
.bindToServer() | ||
.responseTimeout(Duration.ofDays(1)) | ||
.baseUrl("http://localhost:" + this.port) | ||
.build(); | ||
} | ||
|
||
@Test | ||
public void searchPostsByKeyword_shouldBeOK() throws Exception { | ||
this.rest | ||
.get() | ||
.uri("/posts/search?q=post") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBodyList(Post.class).hasSize(10); | ||
} | ||
|
||
@Test | ||
public void countPostsByKeyword_shouldBeOK() throws Exception { | ||
this.rest | ||
.get() | ||
.uri("/posts/count?q=0") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody().jsonPath("$.count").isEqualTo(10); | ||
|
||
this.rest | ||
.get() | ||
.uri("/posts/count?q=5") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody().jsonPath("$.count").isEqualTo(19); | ||
|
||
this.rest | ||
.get() | ||
.uri("/posts/count?q=post") | ||
.exchange() | ||
.expectStatus().isOk() | ||
.expectBody().jsonPath("$.count").isEqualTo(100); | ||
} | ||
|
||
|
||
} |