Skip to content
Snippets Groups Projects
Commit a25fafc4 authored by xkromm's avatar xkromm
Browse files

new dependency

parent 60b3b78d
No related branches found
No related tags found
1 merge request!8Rest tests
//package cz.muni.fi.pa165.hr.rest;
//
//import cz.muni.fi.pa165.api.employee.Employee;
//import cz.muni.fi.pa165.hr.facade.EmployeeFacade;
//import cz.muni.fi.pa165.hr.util.ObjectConverter;
//import cz.muni.fi.pa165.hr.util.TestDaoFactory;
//import org.junit.jupiter.api.Test;
//import org.mockito.Mockito;
//import org.springframework.beans.factory.annotation.Autowired;
//import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
//import org.springframework.boot.test.mock.mockito.MockBean;
//import org.springframework.context.ApplicationContext;
//import org.springframework.http.MediaType;
//import org.springframework.test.web.servlet.MockMvc;
//
//import java.nio.charset.StandardCharsets;
//import java.util.UUID;
//
//import static org.assertj.core.api.Assertions.assertThat;
//import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
//import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
//
//
//@WebMvcTest(controllers = {EmployeeController.class})
//class EmployeeControllerTest {
//
// @Autowired
// private ApplicationContext applicationContext;
//
// @Autowired
// private MockMvc mockMvc;
//
// @MockBean
// private EmployeeFacade employeeFacade;
//
package cz.muni.fi.pa165.hr.rest;
import cz.muni.fi.pa165.api.employee.Employee;
import cz.muni.fi.pa165.hr.facade.EmployeeFacade;
import cz.muni.fi.pa165.hr.util.ObjectConverter;
import cz.muni.fi.pa165.hr.util.TestDaoFactory;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.test.autoconfigure.web.servlet.WebMvcTest;
import org.springframework.boot.test.mock.mockito.MockBean;
import org.springframework.context.ApplicationContext;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.request.MockMvcRequestBuilders;
import java.nio.charset.StandardCharsets;
import java.util.UUID;
import static org.assertj.core.api.Assertions.assertThat;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.http.MediaType;
import org.springframework.test.web.servlet.MockMvc;
import org.springframework.test.web.servlet.setup.MockMvcBuilders;
import java.util.UUID;
import static org.mockito.Mockito.*;
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*;
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*;
@WebMvcTest(controllers = {EmployeeController.class})
class EmployeeControllerTest {
@Autowired
private ApplicationContext applicationContext;
@Autowired
private MockMvc mockMvc;
@MockBean
private EmployeeFacade employeeFacade;
@Test
public void testGetEmployeeById() throws Exception {
UUID id = UUID.randomUUID();
Employee employee = new Employee();
employee.setId(id);
employee.setName("John");
employee.setSurname("Doe");
// Stubbing the behavior of employeeFacade.get(id) to return the employee object
Mockito.when(employeeFacade.get(id)).thenReturn(employee);
// Perform GET request to /employee/{id}
mockMvc.perform(get("/employee/{id}", id))
.andExpect(status().isOk())
.andExpect(content().contentType(MediaType.APPLICATION_JSON))
.andExpect(jsonPath("$.id").value(id.toString()))
.andExpect(jsonPath("$.name").value("John"))
.andExpect(jsonPath("$.surname").value("Doe"));
// Verify that employeeFacade.get(id) is called exactly once with the correct argument
Mockito.verify(employeeFacade, Mockito.times(1)).get(id);
}
// @Test
// void findById_personFound_returnsPerson() throws Exception {
// // Arrange
......@@ -53,5 +89,5 @@
//
// assertThat(response).isEqualTo(TestDaoFactory.employeeEntity);
// }
//
//}
\ No newline at end of file
}
\ No newline at end of file
......@@ -35,6 +35,11 @@
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>6.1.5</version>
</dependency>
<dependency>
<groupId>org.mapstruct</groupId>
<artifactId>mapstruct</artifactId>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment