Loading src/main/java/it/inaf/ia2/transfer/controller/FileController.java +4 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,10 @@ public abstract class FileController { protected HttpServletRequest request; public String getPath() { String[] parts = request.getRequestURI().split("/"); String uri = request.getRequestURI().substring(request.getContextPath().length()); String[] parts = uri.split("/"); return String.join("/", Arrays.stream(parts) .map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8)) .collect(Collectors.toList())); Loading src/test/java/it/inaf/ia2/transfer/controller/GetFileControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -61,13 +61,28 @@ public class GetFileControllerTest { fileInfo.setVirtualPath("/path/to/myfile"); fileInfo.setIsPublic(true); when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo)); when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testContextPathIsRemoved() throws Exception { FileInfo fileInfo = new FileInfo(); fileInfo.setOsPath(tempFile.getAbsolutePath()); fileInfo.setVirtualPath("/path/to/myfile"); fileInfo.setIsPublic(true); when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/context/path/to/myfile").contextPath("/context")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testFileNotFoundInDb() throws Exception { mockMvc.perform(get("/path/to/myfile")) Loading Loading
src/main/java/it/inaf/ia2/transfer/controller/FileController.java +4 −1 Original line number Diff line number Diff line Loading @@ -13,7 +13,10 @@ public abstract class FileController { protected HttpServletRequest request; public String getPath() { String[] parts = request.getRequestURI().split("/"); String uri = request.getRequestURI().substring(request.getContextPath().length()); String[] parts = uri.split("/"); return String.join("/", Arrays.stream(parts) .map(p -> URLDecoder.decode(p, StandardCharsets.UTF_8)) .collect(Collectors.toList())); Loading
src/test/java/it/inaf/ia2/transfer/controller/GetFileControllerTest.java +16 −1 Original line number Diff line number Diff line Loading @@ -61,13 +61,28 @@ public class GetFileControllerTest { fileInfo.setVirtualPath("/path/to/myfile"); fileInfo.setIsPublic(true); when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo)); when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testContextPathIsRemoved() throws Exception { FileInfo fileInfo = new FileInfo(); fileInfo.setOsPath(tempFile.getAbsolutePath()); fileInfo.setVirtualPath("/path/to/myfile"); fileInfo.setIsPublic(true); when(fileDao.getFileInfo(eq("/path/to/myfile"))).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/context/path/to/myfile").contextPath("/context")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testFileNotFoundInDb() throws Exception { mockMvc.perform(get("/path/to/myfile")) Loading