Skip to content

Commit 82df364

Browse files
author
muriloalvesdev
committed
create integration tests
1 parent 47635e5 commit 82df364

1 file changed

Lines changed: 78 additions & 0 deletions

File tree

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package br.com.developers.controller.github;
2+
3+
import static org.hamcrest.CoreMatchers.is;
4+
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
5+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
6+
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
7+
import org.junit.jupiter.api.BeforeEach;
8+
import org.junit.jupiter.api.Test;
9+
import org.springframework.beans.factory.annotation.Autowired;
10+
import org.springframework.boot.test.context.SpringBootTest;
11+
import org.springframework.http.MediaType;
12+
import org.springframework.test.web.servlet.MockMvc;
13+
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
14+
import org.springframework.web.context.WebApplicationContext;
15+
16+
@SpringBootTest
17+
class GithubControllerIntegrationTests {
18+
19+
private static final String QUALIFIER_USER = "muriloalvesdev";
20+
private static final String QUALIFIER_REPOSITORIE = "thehero-backend";
21+
22+
@Autowired
23+
private WebApplicationContext webApplicationContext;
24+
25+
private MockMvc mockMvc;
26+
27+
@BeforeEach
28+
void setUp() {
29+
this.mockMvc = MockMvcBuilders.webAppContextSetup(this.webApplicationContext).build();
30+
}
31+
32+
@Test
33+
void shouldSearchUsers() throws Exception {
34+
this.mockMvc
35+
.perform(get(GithubController.PATH + "search/users")
36+
.contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE)
37+
.param("qualifier", QUALIFIER_USER))
38+
.andExpect(status().isOk()).andExpect(jsonPath("$.total_count", is(1)))
39+
.andExpect(jsonPath("$.incomplete_results", is(false)))
40+
.andExpect(jsonPath("$.items[0].login", is("muriloalvesdev")))
41+
.andExpect(jsonPath("$.items[0].id", is(35849751)))
42+
.andExpect(jsonPath("$.items.[0].avatar_url",
43+
is("https://avatars0.githubusercontent.com/u/35849751?v=4")))
44+
.andExpect(jsonPath("$.items[0].html_url", is("https://github.com/muriloalvesdev")));
45+
}
46+
47+
@Test
48+
void shouldSearchRepositories() throws Exception {
49+
this.mockMvc
50+
.perform(get(GithubController.PATH + "search/repositories")
51+
.contentType(MediaType.APPLICATION_JSON_VALUE).accept(MediaType.APPLICATION_JSON_VALUE)
52+
.param("qualifier", QUALIFIER_REPOSITORIE))
53+
.andExpect(status().isOk()).andExpect(jsonPath("$.total_count", is(1)))
54+
.andExpect(jsonPath("$.incomplete_results", is(false)))
55+
.andExpect(jsonPath("$.items[0].private", is(false)))
56+
.andExpect(jsonPath("$.items[0].full_name", is("muriloalvesdev/thehero-backend")))
57+
.andExpect(jsonPath("$.items[0].description", is(
58+
"Este projeto foi desenvolvido com o intuito de ajudar ONGs que cuidam de animais.")))
59+
.andExpect(jsonPath("$.items[0].html_url",
60+
is("https://github.com/muriloalvesdev/thehero-backend")))
61+
.andExpect(jsonPath("$.items[0].created_at", is("2020-04-21T18:52:53Z")))
62+
.andExpect(jsonPath("$.items[0].clone_url",
63+
is("https://github.com/muriloalvesdev/thehero-backend.git")))
64+
.andExpect(jsonPath("$.items[0].homepage", is("https://thehero.netlify.app/")))
65+
.andExpect(jsonPath("$.items[0].language", is("Java")))
66+
.andExpect(jsonPath("$.items[0].license.key", is("apache-2.0")))
67+
.andExpect(jsonPath("$.items[0].license.name", is("Apache License 2.0")))
68+
.andExpect(jsonPath("$.items[0].license.spdx_id", is("Apache-2.0")))
69+
.andExpect(
70+
jsonPath("$.items[0].license.url", is("https://api.github.com/licenses/apache-2.0")))
71+
.andExpect(jsonPath("$.items[0].default_branch", is("master")))
72+
.andExpect(jsonPath("$.items[0].owner.login", is("muriloalvesdev")))
73+
.andExpect(jsonPath("$.items[0].owner.id", is(35849751)))
74+
.andExpect(jsonPath("$.items.[0].owner.avatar_url",
75+
is("https://avatars0.githubusercontent.com/u/35849751?v=4")))
76+
.andExpect(jsonPath("$.items[0].owner.html_url", is("https://github.com/muriloalvesdev")));
77+
}
78+
}

0 commit comments

Comments
 (0)