Skip to content
Snippets Groups Projects
Commit 5bd13b15 authored by Sonia Zorba's avatar Sonia Zorba
Browse files

Added jobId to FileInfo; Added missing tests

parent 1e6dafc3
No related branches found
No related tags found
No related merge requests found
...@@ -45,7 +45,7 @@ public class FileDAO { ...@@ -45,7 +45,7 @@ public class FileDAO {
String sql = "SELECT n.node_id, is_public, group_read, group_write, creator_id, async_trans,\n" 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" + "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" + "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" + "base_path, get_os_path(n.node_id) AS os_path, ? AS vos_path, false AS is_directory\n"
+ "FROM node n\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" + "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 { ...@@ -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" + "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" + "(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" + "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" + "FROM node n\n"
+ "JOIN node p ON p.path @> n.path\n" + "JOIN node p ON p.path @> n.path\n"
+ "LEFT JOIN location l ON l.location_id = n.location_id\n" + "LEFT JOIN location l ON l.location_id = n.location_id\n"
...@@ -206,10 +206,14 @@ public class FileDAO { ...@@ -206,10 +206,14 @@ public class FileDAO {
fi.setVirtualPath(rs.getString("vos_path")); fi.setVirtualPath(rs.getString("vos_path"));
fi.setVirtualName(rs.getString("name")); fi.setVirtualName(rs.getString("name"));
fi.setContentEncoding(rs.getString("content_encoding")); 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.setContentMd5(rs.getString("content_md5"));
fi.setContentType(rs.getString("content_type")); fi.setContentType(rs.getString("content_type"));
fi.setDirectory(rs.getBoolean("is_directory")); fi.setDirectory(rs.getBoolean("is_directory"));
fi.setJobId(rs.getString("job_id"));
int locationId = rs.getInt("location_id"); int locationId = rs.getInt("location_id");
if (!rs.wasNull()) { if (!rs.wasNull()) {
fi.setLocationId(locationId); fi.setLocationId(locationId);
......
...@@ -27,6 +27,7 @@ public class FileInfo { ...@@ -27,6 +27,7 @@ public class FileInfo {
private Long contentLength; private Long contentLength;
private String contentMd5; private String contentMd5;
private Integer locationId; private Integer locationId;
private String jobId;
public int getNodeId() { public int getNodeId() {
return nodeId; return nodeId;
...@@ -171,4 +172,12 @@ public class FileInfo { ...@@ -171,4 +172,12 @@ public class FileInfo {
public void setLocationId(Integer locationId) { public void setLocationId(Integer locationId) {
this.locationId = locationId; this.locationId = locationId;
} }
public String getJobId() {
return jobId;
}
public void setJobId(String jobId) {
this.jobId = jobId;
}
} }
...@@ -17,9 +17,11 @@ import org.junit.jupiter.api.BeforeEach; ...@@ -17,9 +17,11 @@ import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.extension.ExtendWith; import org.junit.jupiter.api.extension.ExtendWith;
import org.springframework.beans.factory.annotation.Autowired; 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.ContextConfiguration;
import org.springframework.test.context.TestPropertySource; import org.springframework.test.context.TestPropertySource;
import org.springframework.test.context.junit.jupiter.SpringExtension; import org.springframework.test.context.junit.jupiter.SpringExtension;
import org.springframework.test.util.ReflectionTestUtils;
@ExtendWith(SpringExtension.class) @ExtendWith(SpringExtension.class)
@ContextConfiguration(classes = {DataSourceConfig.class}) @ContextConfiguration(classes = {DataSourceConfig.class})
...@@ -29,11 +31,15 @@ public class FileDAOTest { ...@@ -29,11 +31,15 @@ public class FileDAOTest {
@Autowired @Autowired
private DataSource dataSource; private DataSource dataSource;
@Value("${upload_location_id}")
private int uploadLocationId;
private FileDAO dao; private FileDAO dao;
@BeforeEach @BeforeEach
public void init() { public void init() {
dao = new FileDAO(dataSource); dao = new FileDAO(dataSource);
ReflectionTestUtils.setField(dao, "uploadLocationId", uploadLocationId);
} }
@Test @Test
...@@ -80,4 +86,47 @@ public class FileDAOTest { ...@@ -80,4 +86,47 @@ public class FileDAOTest {
assertNull(dao.getRemainingQuota("/")); 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());
}
} }
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment