-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Program Area and Project Boundary test stubs
- Loading branch information
Showing
2 changed files
with
190 additions
and
0 deletions.
There are no files selected for viewing
95 changes: 95 additions & 0 deletions
95
server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProgramAreaControllerTest.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,95 @@ | ||
package ca.bc.gov.nrs.wfprev; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.mockito.Mockito.when; | ||
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.annotation.Import; | ||
import org.springframework.hateoas.CollectionModel; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import ca.bc.gov.nrs.wfprev.controllers.ProgramAreaController; | ||
import ca.bc.gov.nrs.wfprev.data.models.ProgramAreaModel; | ||
import ca.bc.gov.nrs.wfprev.services.ProgramAreaService; | ||
|
||
@WebMvcTest(ProgramAreaController.class) | ||
@Import({SecurityConfig.class, TestcontainersConfiguration.class}) | ||
class ProgramAreaControllerTest { | ||
@MockBean | ||
private ProgramAreaService programAreaService; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
@WithMockUser | ||
void testGetProject() throws Exception { | ||
String guid = UUID.randomUUID().toString(); | ||
|
||
ProgramAreaModel programArea = new ProgramAreaModel(); | ||
programArea.setProgramAreaGuid(guid); | ||
|
||
List<ProgramAreaModel> programAreaList = Arrays.asList(programArea); | ||
CollectionModel<ProgramAreaModel> programAreaModel = CollectionModel.of(programAreaList); | ||
|
||
when(programAreaService.getAllProgramAreas()).thenReturn(programAreaModel); | ||
|
||
mockMvc.perform(get("/programAreas") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
|
||
when(programAreaService.getProgramAreaById(guid)).thenReturn(programArea); | ||
|
||
mockMvc.perform(get("/programAreas/{id}", guid) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
@WithMockUser | ||
void testCreateUpdateProject() throws Exception { | ||
ProgramAreaModel programArea = new ProgramAreaModel(); | ||
when(programAreaService.createOrUpdateProgramArea(programArea)).thenReturn(programArea); | ||
|
||
mockMvc.perform(post("/programAreas", programArea) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
|
||
|
||
programArea.setProgramAreaName("Test"); | ||
when(programAreaService.createOrUpdateProgramArea(programArea)).thenReturn(programArea); | ||
|
||
mockMvc.perform(put("/programAreas", programArea) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
@WithMockUser | ||
void testDeleteProject() throws Exception { | ||
ProgramAreaModel programArea = new ProgramAreaModel(); | ||
when(programAreaService.createOrUpdateProgramArea(programArea)).thenReturn(programArea); | ||
|
||
mockMvc.perform(post("/programArea", programArea) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
|
||
when(programAreaService.deleteProgramArea(programArea.getProgramAreaGuid())).thenReturn(null); | ||
|
||
mockMvc.perform(delete("/programArea/{id}", programArea.getProgramAreaGuid()) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
} |
95 changes: 95 additions & 0 deletions
95
server/wfprev-api/src/test/java/ca/bc/gov/nrs/wfprev/ProjectBoundaryControllerTest.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,95 @@ | ||
package ca.bc.gov.nrs.wfprev; | ||
|
||
import java.util.Arrays; | ||
import java.util.List; | ||
import java.util.UUID; | ||
|
||
import org.junit.jupiter.api.Test; | ||
import static org.mockito.Mockito.when; | ||
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.annotation.Import; | ||
import org.springframework.hateoas.CollectionModel; | ||
import org.springframework.http.MediaType; | ||
import org.springframework.security.test.context.support.WithMockUser; | ||
import org.springframework.test.web.servlet.MockMvc; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.get; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.post; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.put; | ||
import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.delete; | ||
import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; | ||
|
||
import ca.bc.gov.nrs.wfprev.controllers.ProjectBoundaryController; | ||
import ca.bc.gov.nrs.wfprev.data.models.ProjectBoundaryModel; | ||
import ca.bc.gov.nrs.wfprev.services.ProjectBoundaryService; | ||
|
||
@WebMvcTest(ProjectBoundaryController.class) | ||
@Import({SecurityConfig.class, TestcontainersConfiguration.class}) | ||
class ProjectBoundaryControllerTest { | ||
@MockBean | ||
private ProjectBoundaryService projectBoundaryService; | ||
|
||
@Autowired | ||
private MockMvc mockMvc; | ||
|
||
@Test | ||
@WithMockUser | ||
void testGetProject() throws Exception { | ||
String guid = UUID.randomUUID().toString(); | ||
|
||
ProjectBoundaryModel project = new ProjectBoundaryModel(); | ||
project.setProjectGuid(guid); | ||
|
||
List<ProjectBoundaryModel> projectList = Arrays.asList(project); | ||
CollectionModel<ProjectBoundaryModel> projectModel = CollectionModel.of(projectList); | ||
|
||
when(projectBoundaryService.getAllProjectBoundaries()).thenReturn(projectModel); | ||
|
||
mockMvc.perform(get("/projectBoundaries") | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
|
||
when(projectBoundaryService.getProjectBoundaryById(guid)).thenReturn(project); | ||
|
||
mockMvc.perform(get("/projectBoundaries/{id}", guid) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
|
||
@Test | ||
@WithMockUser | ||
void testCreateUpdateProject() throws Exception { | ||
ProjectBoundaryModel project = new ProjectBoundaryModel(); | ||
when(projectBoundaryService.createOrUpdateProjectBoundary(project)).thenReturn(project); | ||
|
||
mockMvc.perform(post("/projectBoundaries", project) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
|
||
|
||
project.setBoundaryComment("Test"); | ||
when(projectBoundaryService.createOrUpdateProjectBoundary(project)).thenReturn(project); | ||
|
||
mockMvc.perform(put("/projectBoundaries", project) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
} | ||
|
||
@Test | ||
@WithMockUser | ||
void testDeleteProject() throws Exception { | ||
ProjectBoundaryModel project = new ProjectBoundaryModel(); | ||
when(projectBoundaryService.createOrUpdateProjectBoundary(project)).thenReturn(project); | ||
|
||
mockMvc.perform(post("/projectBoundaries", project) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isCreated()); | ||
|
||
when(projectBoundaryService.deleteProjectBoundary(project.getProjectGuid())).thenReturn(null); | ||
|
||
mockMvc.perform(delete("/projectBoundaries/{id}", project.getProjectGuid()) | ||
.contentType(MediaType.APPLICATION_JSON)) | ||
.andExpect(status().isOk()); | ||
} | ||
} |