Commit 5a003e9c authored by Nicola Fulvio Calabria's avatar Nicola Fulvio Calabria
Browse files

Added tests to FileDAOTest

parent 05dcfd63
......@@ -75,22 +75,6 @@ public class FileDAO {
return Arrays.asList((String[]) array.getArray());
}
public void setBusy(int nodeId, String jobId) {
String sql = "UPDATE node SET job_id = ? WHERE node_id = ?";
jdbcTemplate.update(conn -> {
PreparedStatement ps = conn.prepareStatement(sql);
if (jobId == null) {
ps.setNull(1, Types.VARCHAR);
} else {
ps.setString(1, jobId);
}
ps.setInt(2, nodeId);
return ps;
});
}
public int setBusy(String vosPath, String jobId) {
String sql = "UPDATE node SET job_id = ? WHERE node_id = id_from_vos_path(?)";
......@@ -216,8 +200,7 @@ public class FileDAO {
// TODO: same problem as get archive file infos
public List<FileInfo> getBranchFileInfos(String rootVosPath, String jobId) {
// TODO: validate rootVosPath as a vos_path
String sql = "SELECT n.node_id, n.is_public, n.group_read, n.group_write, n.creator_id, n.async_trans,\n"
+ "n.content_type, n.content_encoding, n.content_length, n.content_md5,\n"
+ "n.accept_views, n.provide_views, l.location_type, n.path <> n.relative_path AS virtual_parent,\n"
......
......@@ -41,27 +41,27 @@ public class FileDAOTest {
dao = new FileDAO(dataSource);
ReflectionTestUtils.setField(dao, "uploadLocationId", uploadLocationId);
}
@Test
public void testGetBranchFileInfo() {
List<FileInfo> fi = dao.getBranchFileInfos("/test100", "pippo");
assertEquals(3, fi.size());
List<FileInfo> fi2 = dao.getBranchFileInfos("/test100/test1001.txt", "pippo");
assertEquals(1, fi2.size());
List<FileInfo> fi = dao.getBranchFileInfos("/test100", "pippo");
assertEquals(3, fi.size());
List<FileInfo> fi2 = dao.getBranchFileInfos("/test100/test1001.txt", "pippo");
assertEquals(1, fi2.size());
}
@Test
public void testSetBranchLocationId() {
dao.setBranchLocationId("/test100", "pippo", 3);
List<FileInfo> fi = dao.getBranchFileInfos("/test100", "pippo");
assertEquals(3, fi.size());
for(FileInfo f : fi) {
fi.forEach(f -> {
assertEquals(3, f.getLocationId());
}
});
}
@Test
public void testGetFileInfo() {
......@@ -113,13 +113,26 @@ public class FileDAOTest {
FileInfo fileInfo = dao.getFileInfo("/public/file1").get();
assertNull(fileInfo.getJobId());
dao.setBusy(fileInfo.getNodeId(), "pippo1");
dao.setBusy(fileInfo.getVirtualPath(), "pippo1");
assertEquals("pippo1", dao.getFileInfo("/public/file1").get().getJobId());
dao.setBusy(fileInfo.getNodeId(), null);
dao.setBusy(fileInfo.getVirtualPath(), null);
assertNull(dao.getFileInfo("/public/file1").get().getJobId());
}
@Test
public void testReleaseNodesByJobId() {
List<FileInfo> fi = dao.getBranchFileInfos("/test100", "pippo");
assertEquals(3, fi.size());
dao.releaseBusyNodesByJobId("pippo");
fi = dao.getBranchFileInfos("/test100", "pippo");
assertEquals(0, fi.size());
}
@Test
public void testSetOsName() {
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment