diff --git a/src/main/java/it/inaf/ia2/transfer/persistence/JobDAO.java b/src/main/java/it/inaf/ia2/transfer/persistence/JobDAO.java index f25bb688152823e8ec82b2fd235c3f9e1c1505c4..8a345fe264ce77aaf433dba986214c46555565e6 100644 --- a/src/main/java/it/inaf/ia2/transfer/persistence/JobDAO.java +++ b/src/main/java/it/inaf/ia2/transfer/persistence/JobDAO.java @@ -42,5 +42,23 @@ public class JobDAO { ps.setString(2, jobId); }); } + + public ExecutionPhase getJobPhase(String jobId) { + String sql = "SELECT phase FROM job WHERE job_id = ?"; + + ExecutionPhase result = jdbcTemplate.query(sql, + ps -> { + ps.setString(1, jobId); + }, rs -> { + if(rs.next()) + { + return ExecutionPhase.fromValue(rs.getString("phase")); + } else { + return null; + } + }); + + return result; + } } diff --git a/src/test/java/it/inaf/ia2/transfer/persistence/JobDAOTest.java b/src/test/java/it/inaf/ia2/transfer/persistence/JobDAOTest.java new file mode 100644 index 0000000000000000000000000000000000000000..1eaf974bf70684956c9a7e6a8ef1066a25d908e9 --- /dev/null +++ b/src/test/java/it/inaf/ia2/transfer/persistence/JobDAOTest.java @@ -0,0 +1,45 @@ +package it.inaf.ia2.transfer.persistence; + +import javax.sql.DataSource; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.extension.ExtendWith; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.test.context.ContextConfiguration; +import org.springframework.test.context.TestPropertySource; +import org.springframework.test.context.junit.jupiter.SpringExtension; +import org.junit.jupiter.api.Test; +import static org.junit.jupiter.api.Assertions.assertTrue; +import static org.junit.jupiter.api.Assertions.assertFalse; +import static org.junit.jupiter.api.Assertions.assertEquals; +import net.ivoa.xml.uws.v1.ExecutionPhase; + +@ExtendWith(SpringExtension.class) +@ContextConfiguration(classes = {DataSourceConfig.class}) +@TestPropertySource(locations = "classpath:test.properties") +public class JobDAOTest { + + @Autowired + private DataSource dataSource; + private JobDAO dao; + + @BeforeEach + public void init() { + dao = new JobDAO(dataSource); + } + + @Test + public void testNodeDAO() + { + assertTrue(dao.isJobExisting("pippo5")); + assertFalse(dao.isJobExisting("pippo22")); + + ExecutionPhase phase = dao.getJobPhase("pippo5"); + assertEquals(ExecutionPhase.EXECUTING, phase); + dao.updateJobPhase(ExecutionPhase.COMPLETED, "pippo5"); + phase = dao.getJobPhase("pippo5"); + assertEquals(ExecutionPhase.COMPLETED, phase); + } + + + +} diff --git a/src/test/resources/test-data.sql b/src/test/resources/test-data.sql index cf0fb583998325437c2c19139d5b22cc88602f50..df512241b15b27a5177fccadc7fdf07ed9325740 100644 --- a/src/test/resources/test-data.sql +++ b/src/test/resources/test-data.sql @@ -10,3 +10,12 @@ INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creat INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, group_read, group_write) VALUES ('2', NULL, '.tmp-123.txt', 'structured', 'user1', 'user1', '{"group1","group2"}','{"group2"}'); -- /test1/.tmp-123.txt INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, group_read, group_write, location_id) VALUES ('2', '', 'file1.txt', 'data', 'user1', 'user1', '{"group1","group2"}','{"group2"}', 1); -- /test1/file1.txt INSERT INTO node (parent_path, parent_relative_path, name, type, owner_id, creator_id, group_read, group_write, location_id) VALUES ('2', '', 'file2.txt', 'data', 'user1', 'user1', '{"group1","group2"}','{"group2"}', 1); -- /test1/file2.txt + +DELETE FROM job; + +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo1', 'user1', 'pullFromVoSpace', 'ARCHIVED', NULL, NULL, '2011-06-22 19:10:25', NULL, NULL); +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo2', 'user1', 'pullToVoSpace', 'PENDING', NULL, NULL, '2012-06-22 19:10:25', NULL, NULL); +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo3', 'user1', 'pullFromVoSpace', 'QUEUED', NULL, NULL, '2013-06-22 19:10:25', NULL, NULL); +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo4', 'user2', 'copyNode', 'PENDING', NULL, NULL, '2014-06-22 19:10:25', NULL, NULL); +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo5', 'user1', 'pushToVoSpace', 'EXECUTING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL); +INSERT INTO job (job_id, owner_id, job_type, phase, start_time, end_time, creation_time, job_info, results) VALUES ('pippo6', 'user2', 'pullFromVoSpace', 'PENDING', NULL, NULL, '2015-06-22 19:10:25', NULL, NULL); \ No newline at end of file