Loading src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ import java.io.UncheckedIOException; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; Loading @@ -24,6 +26,8 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class GetFileController { private static final Logger LOG = LoggerFactory.getLogger(GetFileController.class); @Value("${path_prefix}") String pathPrefix; Loading Loading @@ -87,10 +91,12 @@ public class GetFileController { File file = new File(path); if (!file.exists()) { LOG.error("File not found: " + file.getAbsolutePath()); return new ResponseEntity<>("File " + file.getName() + " not found", NOT_FOUND); } if (!file.canRead()) { LOG.error("File not readable: " + file.getAbsolutePath()); return new ResponseEntity<>("File " + file.getName() + " is not readable", INTERNAL_SERVER_ERROR); } Loading src/test/java/it/inaf/ia2/transfer/controller/GetFileControllerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -64,14 +64,14 @@ public class GetFileControllerTest { when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/myfile")) mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testFileNotFoundInDb() throws Exception { mockMvc.perform(get("/myfile")) mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isNotFound()); } Loading @@ -95,7 +95,7 @@ public class GetFileControllerTest { prepareMocksForPrivateFile(); mockMvc.perform(get("/myfile") mockMvc.perform(get("/path/to/myfile") .header("Authorization", "Bearer: <token>")) .andDo(print()) .andExpect(status().isOk()); Loading @@ -108,7 +108,7 @@ public class GetFileControllerTest { prepareMocksForPrivateFile(); mockMvc.perform(get("/myfile?token=<token>")) mockMvc.perform(get("/path/to/myfile?token=<token>")) .andDo(print()) .andExpect(status().isOk()); Loading Loading
src/main/java/it/inaf/ia2/transfer/controller/GetFileController.java +6 −0 Original line number Diff line number Diff line Loading @@ -12,6 +12,8 @@ import java.io.UncheckedIOException; import java.util.Optional; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import static org.springframework.http.HttpStatus.INTERNAL_SERVER_ERROR; Loading @@ -24,6 +26,8 @@ import org.springframework.web.bind.annotation.RestController; @RestController public class GetFileController { private static final Logger LOG = LoggerFactory.getLogger(GetFileController.class); @Value("${path_prefix}") String pathPrefix; Loading Loading @@ -87,10 +91,12 @@ public class GetFileController { File file = new File(path); if (!file.exists()) { LOG.error("File not found: " + file.getAbsolutePath()); return new ResponseEntity<>("File " + file.getName() + " not found", NOT_FOUND); } if (!file.canRead()) { LOG.error("File not readable: " + file.getAbsolutePath()); return new ResponseEntity<>("File " + file.getName() + " is not readable", INTERNAL_SERVER_ERROR); } Loading
src/test/java/it/inaf/ia2/transfer/controller/GetFileControllerTest.java +4 −4 Original line number Diff line number Diff line Loading @@ -64,14 +64,14 @@ public class GetFileControllerTest { when(fileDao.getFileInfo(any())).thenReturn(Optional.of(fileInfo)); mockMvc.perform(get("/myfile")) mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isOk()); } @Test public void testFileNotFoundInDb() throws Exception { mockMvc.perform(get("/myfile")) mockMvc.perform(get("/path/to/myfile")) .andDo(print()) .andExpect(status().isNotFound()); } Loading @@ -95,7 +95,7 @@ public class GetFileControllerTest { prepareMocksForPrivateFile(); mockMvc.perform(get("/myfile") mockMvc.perform(get("/path/to/myfile") .header("Authorization", "Bearer: <token>")) .andDo(print()) .andExpect(status().isOk()); Loading @@ -108,7 +108,7 @@ public class GetFileControllerTest { prepareMocksForPrivateFile(); mockMvc.perform(get("/myfile?token=<token>")) mockMvc.perform(get("/path/to/myfile?token=<token>")) .andDo(print()) .andExpect(status().isOk()); Loading