Spaces:
Build error
Build error
da-admin-service-dev
/
src
/test
/java
/com
/dalab
/adminservice
/controller
/JobStatusControllerTest.java
| package com.dalab.adminservice.controller; | |
| import static org.mockito.BDDMockito.*; | |
| import static org.springframework.test.web.servlet.request.MockMvcRequestBuilders.*; | |
| import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.*; | |
| import java.util.Collections; | |
| import org.junit.jupiter.api.Test; | |
| 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.http.MediaType; | |
| import org.springframework.security.test.context.support.WithMockUser; | |
| import org.springframework.test.web.servlet.MockMvc; | |
| import com.dalab.adminservice.config.TestSecurityConfiguration; | |
| import com.dalab.adminservice.dto.AggregatedJobStatusDTO; | |
| import com.dalab.adminservice.service.IJobStatusService; | |
| import com.fasterxml.jackson.databind.ObjectMapper; | |
| class JobStatusControllerTest { | |
| private MockMvc mockMvc; | |
| private IJobStatusService jobStatusService; | |
| private ObjectMapper objectMapper; | |
| void getAggregatedJobStatuses_shouldReturnAggregatedStatuses() throws Exception { | |
| AggregatedJobStatusDTO aggregatedStatus = AggregatedJobStatusDTO.builder() | |
| .jobs(Collections.emptyList()) | |
| .totalJobs(0) | |
| .build(); | |
| given(jobStatusService.getAggregatedJobStatuses()).willReturn(aggregatedStatus); | |
| mockMvc.perform(get("/api/v1/admin/job-statuses") | |
| .contentType(MediaType.APPLICATION_JSON)) | |
| .andExpect(status().isOk()) | |
| .andExpect(jsonPath("$.totalJobs").value(0)); | |
| } | |
| // A user without ADMIN or VIEWER role | |
| void getAggregatedJobStatuses_whenUnauthorized_shouldReturnForbidden() throws Exception { | |
| mockMvc.perform(get("/api/v1/admin/job-statuses") | |
| .contentType(MediaType.APPLICATION_JSON)) | |
| .andExpect(status().isForbidden()); | |
| } | |
| } |