Created
June 29, 2020 13:43
Star
You must be signed in to star a gist
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
@WebMvcTest | |
class HttpControllersTests(@Autowired val mockMvc: MockMvc) { | |
@MockkBean | |
private lateinit var articleRepository: ArticleRepository | |
@Test | |
fun `List articles`() { | |
val user = User("testUser", "John", "Doe") | |
val spring5Article = Article("Spring Framework 5.0 goes GA", "Dear Spring community ...", "Lorem ipsum", user) | |
val spring43Article = Article("Spring Framework 4.3 goes GA", "Dear Spring community ...", "Lorem ipsum", user) | |
every { articleRepository.findAllByOrderByAddedAtDesc() } returns listOf(spring5Article, spring43Article) | |
mockMvc.perform(get("/api/article/").accept(MediaType.APPLICATION_JSON)) | |
.andExpect(status().isOk) | |
.andExpect(content().contentType(MediaType.APPLICATION_JSON_UTF8)) | |
.andExpect(jsonPath("\$.[0].author.login").value(user.login)) | |
.andExpect(jsonPath("\$.[0].slug").value(spring5Article.slug)) | |
.andExpect(jsonPath("\$.[1].author.login").value(user.login)) | |
.andExpect(jsonPath("\$.[1].slug").value(spring43Article.slug)) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment