Commit f4f6471a authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Minor changes

parent 802fda65
Loading
Loading
Loading
Loading
+6 −0
Original line number Diff line number Diff line
@@ -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;
@@ -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;

@@ -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);
        }

+4 −4
Original line number Diff line number Diff line
@@ -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());
    }
@@ -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());
@@ -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());