47 lines
1.6 KiB
Java
47 lines
1.6 KiB
Java
package io.spring.api;
|
|
|
|
import io.restassured.RestAssured;
|
|
import io.spring.application.Page;
|
|
import io.spring.application.article.ArticleDataList;
|
|
import io.spring.application.article.ArticleQueryService;
|
|
import org.junit.Before;
|
|
import org.junit.Test;
|
|
import org.junit.runner.RunWith;
|
|
import org.springframework.boot.context.embedded.LocalServerPort;
|
|
import org.springframework.boot.test.context.SpringBootTest;
|
|
import org.springframework.boot.test.mock.mockito.MockBean;
|
|
import org.springframework.test.context.junit4.SpringRunner;
|
|
|
|
import static io.spring.TestHelper.articleDataFixture;
|
|
import static java.util.Arrays.asList;
|
|
import static org.mockito.Matchers.eq;
|
|
import static org.mockito.Mockito.when;
|
|
|
|
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
|
|
@RunWith(SpringRunner.class)
|
|
public class ListArticleApiTest extends TestWithCurrentUser {
|
|
@MockBean
|
|
private ArticleQueryService articleQueryService;
|
|
|
|
@LocalServerPort
|
|
private int port;
|
|
|
|
@Before
|
|
public void setUp() throws Exception {
|
|
RestAssured.port = port;
|
|
userFixture();
|
|
}
|
|
|
|
@Test
|
|
public void should_get_default_article_list() throws Exception {
|
|
ArticleDataList articleDataList = new ArticleDataList(
|
|
asList(articleDataFixture("1", user), articleDataFixture("2", user)), 2);
|
|
when(articleQueryService.findRecentArticles(eq(null), eq(null), eq(null), eq(new Page(0, 20)))).thenReturn(articleDataList);
|
|
RestAssured.when()
|
|
.get("/articles")
|
|
.prettyPeek()
|
|
.then()
|
|
.statusCode(200);
|
|
}
|
|
}
|