Commit 5bd13b15 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added jobId to FileInfo; Added missing tests

parent 1e6dafc3
Loading
Loading
Loading
Loading
+7 −3
Original line number Diff line number Diff line
@@ -45,7 +45,7 @@ public class FileDAO {
        String sql = "SELECT n.node_id, is_public, group_read, group_write, creator_id, async_trans,\n"
                + "content_type, content_encoding, content_length, content_md5, name, n.location_id,\n"
                + "accept_views, provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n"
                + "(SELECT user_name FROM users WHERE user_id = creator_id) AS username,\n"
                + "(SELECT user_name FROM users WHERE user_id = creator_id) AS username, n.job_id,\n"
                + "base_path, get_os_path(n.node_id) AS os_path, ? AS vos_path, false AS is_directory\n"
                + "FROM node n\n"
                + "JOIN location l ON (n.location_id IS NOT NULL AND n.location_id = l.location_id) OR (n.location_id IS NULL AND l.location_id = ?)\n"
@@ -168,7 +168,7 @@ public class FileDAO {
                + "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n"
                + "(SELECT user_name FROM users WHERE user_id = n.creator_id) AS username,\n"
                + "base_path, get_os_path(n.node_id) AS os_path, get_vos_path(n.node_id) AS vos_path,\n"
                + "n.type = 'container' AS is_directory, n.name, n.location_id\n"
                + "n.type = 'container' AS is_directory, n.name, n.location_id, n.job_id\n"
                + "FROM node n\n"
                + "JOIN node p ON p.path @> n.path\n"
                + "LEFT JOIN location l ON l.location_id = n.location_id\n"
@@ -206,10 +206,14 @@ public class FileDAO {
        fi.setVirtualPath(rs.getString("vos_path"));
        fi.setVirtualName(rs.getString("name"));
        fi.setContentEncoding(rs.getString("content_encoding"));
        fi.setContentLength(rs.getLong("content_length"));
        long contentLength = rs.getLong("content_length");
        if (!rs.wasNull()) {
            fi.setContentLength(contentLength);
        }
        fi.setContentMd5(rs.getString("content_md5"));
        fi.setContentType(rs.getString("content_type"));
        fi.setDirectory(rs.getBoolean("is_directory"));
        fi.setJobId(rs.getString("job_id"));
        int locationId = rs.getInt("location_id");
        if (!rs.wasNull()) {
            fi.setLocationId(locationId);
+9 −0
Original line number Diff line number Diff line
@@ -27,6 +27,7 @@ public class FileInfo {
    private Long contentLength;
    private String contentMd5;
    private Integer locationId;
    private String jobId;

    public int getNodeId() {
        return nodeId;
@@ -171,4 +172,12 @@ public class FileInfo {
    public void setLocationId(Integer locationId) {
        this.locationId = locationId;
    }

    public String getJobId() {
        return jobId;
    }

    public void setJobId(String jobId) {
        this.jobId = jobId;
    }
}
+49 −0
Original line number Diff line number Diff line
@@ -17,9 +17,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;

@ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {DataSourceConfig.class})
@@ -29,11 +31,15 @@ public class FileDAOTest {
    @Autowired
    private DataSource dataSource;

    @Value("${upload_location_id}")
    private int uploadLocationId;

    private FileDAO dao;

    @BeforeEach
    public void init() {
        dao = new FileDAO(dataSource);
        ReflectionTestUtils.setField(dao, "uploadLocationId", uploadLocationId);
    }

    @Test
@@ -80,4 +86,47 @@ public class FileDAOTest {

        assertNull(dao.getRemainingQuota("/"));
    }

    @Test
    public void testSetBusy() {

        FileInfo fileInfo = dao.getFileInfo("/public/file1").get();
        assertNull(fileInfo.getJobId());

        dao.setBusy(fileInfo.getNodeId(), "pippo1");
        assertEquals("pippo1", dao.getFileInfo("/public/file1").get().getJobId());

        dao.setBusy(fileInfo.getNodeId(), null);
        assertNull(dao.getFileInfo("/public/file1").get().getJobId());
    }

    @Test
    public void testSetOsName() {

        FileInfo fileInfo = dao.getFileInfo("/public/file1").get();
        assertTrue(fileInfo.getOsPath().endsWith("/file1"));

        dao.setOsName(fileInfo.getNodeId(), "file1-renamed");
        fileInfo = dao.getFileInfo("/public/file1").get();
        assertTrue(fileInfo.getOsPath().endsWith("/file1-renamed"));
    }

    @Test
    public void testUpdateFileAttributes() {

        FileInfo fileInfo = dao.getFileInfo("/public/file1").get();

        assertNull(fileInfo.getContentLength());
        assertNull(fileInfo.getContentType());
        assertNull(fileInfo.getContentEncoding());
        assertNull(fileInfo.getContentMd5());

        dao.updateFileAttributes(fileInfo.getNodeId(), "text/plain", "UTF-8", 50000l, "<md5>");

        fileInfo = dao.getFileInfo("/public/file1").get();
        assertEquals(50000l, fileInfo.getContentLength());
        assertEquals("text/plain", fileInfo.getContentType());
        assertEquals("UTF-8", fileInfo.getContentEncoding());
        assertEquals("<md5>", fileInfo.getContentMd5());
    }
}