-
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.
Add initial tests for Authentication endpoint.
- Loading branch information
1 parent
ceb8fd6
commit a76c884
Showing
5 changed files
with
114 additions
and
39 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
16 changes: 0 additions & 16 deletions
16
src/test/java/quem/me/ajuda/QuemMeAjudaApplicationTests.java
This file was deleted.
Oops, something went wrong.
75 changes: 75 additions & 0 deletions
75
src/test/java/quem/me/ajuda/controllers/AuthenticationControllerTest.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,75 @@ | ||
/** | ||
* | ||
*/ | ||
package quem.me.ajuda.controllers; | ||
|
||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
import static org.springframework.test.web.servlet.setup.MockMvcBuilders.standaloneSetup; | ||
|
||
import org.junit.jupiter.api.BeforeAll; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
import org.junit.jupiter.api.TestInstance; | ||
import org.junit.jupiter.api.TestInstance.Lifecycle; | ||
import org.junit.jupiter.api.extension.ExtendWith; | ||
import org.junit.platform.runner.JUnitPlatform; | ||
import org.junit.runner.RunWith; | ||
import org.springframework.beans.factory.annotation.Autowired; | ||
import org.springframework.boot.test.context.SpringBootTest; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.test.context.junit.jupiter.SpringExtension; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
|
||
import com.fasterxml.jackson.databind.ObjectMapper; | ||
|
||
import quem.me.ajuda.constants.Endpoints; | ||
import quem.me.ajuda.models.Student; | ||
import quem.me.ajuda.services.StudentService; | ||
|
||
/** | ||
* | ||
*/ | ||
@SpringBootTest | ||
@RunWith(JUnitPlatform.class) | ||
@ExtendWith(SpringExtension.class) | ||
@TestInstance(Lifecycle.PER_CLASS) | ||
class AuthenticationControllerTest { | ||
private final String ENDPOINT = "/".concat(Endpoints.LOGIN_ENDPOINT); | ||
|
||
private Student testUser; | ||
|
||
private MockMvc mockMvc; | ||
|
||
@Autowired | ||
private StudentService studentService; | ||
|
||
@Autowired | ||
private ObjectMapper objectMapper; | ||
|
||
/** | ||
* | ||
*/ | ||
@BeforeAll | ||
void setUpAll() { | ||
this.mockMvc = standaloneSetup(AuthenticationController.class).build(); | ||
} | ||
|
||
@BeforeEach | ||
void setUp() { | ||
testUser = new Student("user", "pass", "phone", "email", "password"); | ||
this.studentService.create(testUser); | ||
} | ||
|
||
/** | ||
* @throws Exception | ||
*/ | ||
@Test | ||
void testLoginSucessfully() throws Exception { | ||
mockMvc.perform(post(ENDPOINT) | ||
.contentType(MediaType.APPLICATION_JSON) | ||
.content(objectMapper.writeValueAsString(testUser))) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
} |