add integration test to find by id user controller
This commit is contained in:
parent
54f841dc83
commit
f106857e17
1 changed files with 46 additions and 0 deletions
|
|
@ -0,0 +1,46 @@
|
|||
package br.com.rayankonecny.userserviceapi.controller.impl;
|
||||
|
||||
import static br.com.rayankonecny.userserviceapi.creator.CreatorUtils.generateMock;
|
||||
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureMockMvc;
|
||||
import org.springframework.boot.test.context.SpringBootTest;
|
||||
import org.springframework.test.context.ActiveProfiles;
|
||||
import org.springframework.test.web.servlet.MockMvc;
|
||||
|
||||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.jsonPath;
|
||||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
|
||||
|
||||
import br.com.rayankonecny.userserviceapi.entity.User;
|
||||
import br.com.rayankonecny.userserviceapi.repository.UserRepository;
|
||||
|
||||
@SpringBootTest
|
||||
@AutoConfigureMockMvc
|
||||
@ActiveProfiles("test")
|
||||
public class UserControllerImpTest {
|
||||
|
||||
@Autowired
|
||||
private MockMvc mockMvc;
|
||||
|
||||
@Autowired
|
||||
private UserRepository userRepository;
|
||||
|
||||
@Test
|
||||
void testFindByIdWithSucces() throws Exception {
|
||||
final var entity = generateMock(User.class);
|
||||
final var userId = userRepository.save(entity).getId();
|
||||
|
||||
mockMvc.perform(get("/api/users/{id}", userId))
|
||||
.andExpect(status().isOk())
|
||||
.andExpect(jsonPath("$.id").value(userId))
|
||||
.andExpect(jsonPath("$.name").value(entity.getName()))
|
||||
.andExpect(jsonPath("$.email").value(entity.getEmail()))
|
||||
.andExpect(jsonPath("$.password").value(entity.getPassword()))
|
||||
.andExpect(jsonPath("$.profiles").isArray());
|
||||
|
||||
userRepository.deleteById(userId);
|
||||
}
|
||||
|
||||
}
|
||||
Loading…
Add table
Reference in a new issue