Loading src/main/java/it/inaf/oats/vospace/TransferController.java +20 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.time.LocalDateTime; import java.util.Arrays; import java.util.HashSet; import java.util.List; import net.ivoa.xml.uws.v1.ErrorSummary; import net.ivoa.xml.vospace.v2.Protocol; @RestController Loading Loading @@ -110,6 +111,24 @@ public class TransferController { return jobDAO.getJob(jobId).map(j -> ResponseEntity.ok(j)).orElse(ResponseEntity.notFound().build()); } @GetMapping(value = "/transfers/{jobId}/error", produces = {MediaType.TEXT_PLAIN_VALUE}) public ResponseEntity<String> getJobError(@PathVariable("jobId") String jobId) { return jobDAO.getJob(jobId).map(j -> { if (j.getPhase().equals(ExecutionPhase.ERROR)) { ErrorSummary e = j.getErrorSummary(); if (e.isHasDetail()) { return ResponseEntity.ok(e.getDetailMessage()); } else { return ResponseEntity.ok("No error details available"); } } else { return ResponseEntity.ok("Job is not in ERROR phase"); } }).orElse(ResponseEntity.notFound().build()); } @PostMapping(value = "/transfers/{jobId}/phase") public ResponseEntity<?> setJobPhase(@PathVariable("jobId") String jobId, @RequestParam("PHASE") String phase, User principal) { Loading src/test/java/it/inaf/oats/vospace/TransferControllerTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import static it.inaf.oats.vospace.VOSpaceXmlTestUtil.loadDocument; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.exception.ErrorSummaryFactory; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.persistence.JobDAO; import it.inaf.oats.vospace.persistence.LocationDAO; import it.inaf.oats.vospace.persistence.NodeDAO; Loading Loading @@ -46,6 +48,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.w3c.dom.Document; import java.util.List; import net.ivoa.xml.uws.v1.ErrorSummary; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeEach; import static org.mockito.ArgumentMatchers.argThat; Loading Loading @@ -259,6 +262,54 @@ public class TransferControllerTest { verify(jobDao, times(1)).getJob(eq("123")); } @Test public void testErrorEndpoint() throws Exception { JobSummary job = new JobSummary(); job.setJobId("123"); job.setPhase(ExecutionPhase.EXECUTING); ErrorSummary e = ErrorSummaryFactory.newErrorSummary( new PermissionDeniedException("/pippo1/pippo2") ); job.setErrorSummary(e); when(jobDao.getJob(eq("123"))).thenReturn(Optional.of(job)); String response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals("Job is not in ERROR phase", response); job.setPhase(ExecutionPhase.ERROR); response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals(e.getDetailMessage(), response); e.setHasDetail(false); response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals("No error details available", response); when(jobDao.getJob(eq("124"))).thenReturn(Optional.ofNullable(null)); mockMvc.perform(get("/transfers/124/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().is4xxClientError()); } @Test public void testGetJobs() throws Exception { Loading Loading
src/main/java/it/inaf/oats/vospace/TransferController.java +20 −1 Original line number Diff line number Diff line Loading @@ -25,6 +25,7 @@ import java.time.LocalDateTime; import java.util.Arrays; import java.util.HashSet; import java.util.List; import net.ivoa.xml.uws.v1.ErrorSummary; import net.ivoa.xml.vospace.v2.Protocol; @RestController Loading Loading @@ -110,6 +111,24 @@ public class TransferController { return jobDAO.getJob(jobId).map(j -> ResponseEntity.ok(j)).orElse(ResponseEntity.notFound().build()); } @GetMapping(value = "/transfers/{jobId}/error", produces = {MediaType.TEXT_PLAIN_VALUE}) public ResponseEntity<String> getJobError(@PathVariable("jobId") String jobId) { return jobDAO.getJob(jobId).map(j -> { if (j.getPhase().equals(ExecutionPhase.ERROR)) { ErrorSummary e = j.getErrorSummary(); if (e.isHasDetail()) { return ResponseEntity.ok(e.getDetailMessage()); } else { return ResponseEntity.ok("No error details available"); } } else { return ResponseEntity.ok("Job is not in ERROR phase"); } }).orElse(ResponseEntity.notFound().build()); } @PostMapping(value = "/transfers/{jobId}/phase") public ResponseEntity<?> setJobPhase(@PathVariable("jobId") String jobId, @RequestParam("PHASE") String phase, User principal) { Loading
src/test/java/it/inaf/oats/vospace/TransferControllerTest.java +51 −0 Original line number Diff line number Diff line Loading @@ -3,6 +3,8 @@ package it.inaf.oats.vospace; import it.inaf.ia2.aa.data.User; import static it.inaf.oats.vospace.VOSpaceXmlTestUtil.loadDocument; import it.inaf.oats.vospace.datamodel.NodeProperties; import it.inaf.oats.vospace.exception.ErrorSummaryFactory; import it.inaf.oats.vospace.exception.PermissionDeniedException; import it.inaf.oats.vospace.persistence.JobDAO; import it.inaf.oats.vospace.persistence.LocationDAO; import it.inaf.oats.vospace.persistence.NodeDAO; Loading Loading @@ -46,6 +48,7 @@ import static org.springframework.test.web.servlet.result.MockMvcResultHandlers. import static org.springframework.test.web.servlet.result.MockMvcResultMatchers.status; import org.w3c.dom.Document; import java.util.List; import net.ivoa.xml.uws.v1.ErrorSummary; import static org.junit.jupiter.api.Assertions.assertTrue; import org.junit.jupiter.api.BeforeEach; import static org.mockito.ArgumentMatchers.argThat; Loading Loading @@ -259,6 +262,54 @@ public class TransferControllerTest { verify(jobDao, times(1)).getJob(eq("123")); } @Test public void testErrorEndpoint() throws Exception { JobSummary job = new JobSummary(); job.setJobId("123"); job.setPhase(ExecutionPhase.EXECUTING); ErrorSummary e = ErrorSummaryFactory.newErrorSummary( new PermissionDeniedException("/pippo1/pippo2") ); job.setErrorSummary(e); when(jobDao.getJob(eq("123"))).thenReturn(Optional.of(job)); String response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals("Job is not in ERROR phase", response); job.setPhase(ExecutionPhase.ERROR); response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals(e.getDetailMessage(), response); e.setHasDetail(false); response = mockMvc.perform(get("/transfers/123/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().isOk()) .andReturn().getResponse().getContentAsString(); assertEquals("No error details available", response); when(jobDao.getJob(eq("124"))).thenReturn(Optional.ofNullable(null)); mockMvc.perform(get("/transfers/124/error") .accept(MediaType.TEXT_PLAIN_VALUE)) .andDo(print()) .andExpect(status().is4xxClientError()); } @Test public void testGetJobs() throws Exception { Loading