Next version of JABA
[jabaws.git] / testsrc / compbio / runner / _impl / RPSBlastTester.java
1 /* Copyright (c) 2009 Peter Troshin\r
2  *  \r
3  *  JAva Bioinformatics Analysis Web Services (JABAWS) @version: 1.0     \r
4  * \r
5  *  This library is free software; you can redistribute it and/or modify it under the terms of the\r
6  *  Apache License version 2 as published by the Apache Software Foundation\r
7  * \r
8  *  This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without\r
9  *  even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Apache \r
10  *  License for more details.\r
11  * \r
12  *  A copy of the license is in apache_license.txt. It is also available here:\r
13  * @see: http://www.apache.org/licenses/LICENSE-2.0.txt\r
14  * \r
15  * Any republication or derived work distributed in source code form\r
16  * must include this copyright and license notice.\r
17  */\r
18 package compbio.runner._impl;\r
19 \r
20 import static org.testng.AssertJUnit.assertFalse;\r
21 import static org.testng.AssertJUnit.assertNotNull;\r
22 import static org.testng.AssertJUnit.assertTrue;\r
23 import static org.testng.AssertJUnit.fail;\r
24 \r
25 import java.text.ParseException;\r
26 \r
27 import org.ggf.drmaa.DrmaaException;\r
28 import org.ggf.drmaa.JobInfo;\r
29 import org.testng.annotations.Test;\r
30 \r
31 import compbio.engine.cluster.drmaa.ClusterUtil;\r
32 import compbio.engine.cluster.drmaa.JobRunner;\r
33 import compbio.engine.cluster.drmaa.StatisticManager;\r
34 import compbio.metadata.AllTestSuit;\r
35 import compbio.metadata.JobExecutionException;\r
36 import compbio.metadata.JobStatus;\r
37 import compbio.metadata.JobSubmissionException;\r
38 \r
39 public class RPSBlastTester {\r
40 \r
41         public static String test_input = "/homes/pvtroshin/TO1381.fasta";\r
42         public static String test_outfile = "/homes/pvtroshin/TO1381.rpsblastpout";\r
43 \r
44         @Test()\r
45         public void testGetTestCommand() {\r
46                 System.out.println(RPSBlast.getTestCommand());\r
47         }\r
48 \r
49         @Test()\r
50         public void testGetTestArgsCommand() {\r
51                 System.out.println(RPSBlast.getTestArgs());\r
52         }\r
53 \r
54         @Test(enabled = false, groups = { AllTestSuit.test_group_cluster,\r
55                         AllTestSuit.test_group_runner })\r
56         public void testBuildCommand() {\r
57                 RPSBlast rpsblast = new RPSBlast(AllTestSuit.OUTPUT_DIR_ABSOLUTE);\r
58                 // TODO rpsblast.setInput(test_input).setOutput(test_outfile);\r
59                 // rpsblast.setParameters(RPSBlast.getTestArgs());\r
60 \r
61                 try {\r
62                         JobRunner runner = JobRunner.getInstance(null);\r
63                         assertNotNull("Runner is NULL", runner);\r
64                         runner.executeJob();\r
65                         // assertNotNull(jobId1);\r
66 \r
67                         JobStatus status = runner.getJobStatus();\r
68                         assertTrue(status == JobStatus.PENDING\r
69                                         || status == JobStatus.RUNNING);\r
70                         JobInfo info = runner.getJobInfo();\r
71                         assertNotNull(info);\r
72                         StatisticManager sm = new StatisticManager(info);\r
73                         assertNotNull(sm);\r
74                         try {\r
75                                 String time_s = sm.getCalculationTime();\r
76                                 assertNotNull(time_s);\r
77                                 float time = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(time_s)\r
78                                                 .floatValue();\r
79                                 assertTrue(time > 0);\r
80                                 String exits = sm.getExitStatus();\r
81                                 assertNotNull(exits);\r
82                                 int exitsInt = ClusterUtil.CLUSTER_STAT_IN_SEC.parse(exits)\r
83                                                 .intValue();\r
84                                 // assertEquals(0, exitsInt);\r
85                                 System.out.println(sm.getAllStats());\r
86 \r
87                         } catch (ParseException e) {\r
88                                 e.printStackTrace();\r
89                                 fail("Parse Exception: " + e.getLocalizedMessage());\r
90                         }\r
91 \r
92                         assertTrue(sm.hasExited());\r
93                         assertFalse(sm.wasAborted());\r
94                         assertFalse(sm.hasDump());\r
95                         assertFalse(sm.hasSignaled());\r
96 \r
97                 } catch (DrmaaException e) {\r
98                         e.printStackTrace();\r
99                         fail(e.getLocalizedMessage());\r
100                 } catch (JobSubmissionException e) {\r
101                         e.printStackTrace();\r
102                         fail(e.getLocalizedMessage());\r
103                 } catch (JobExecutionException e) {\r
104                         e.printStackTrace();\r
105                         fail(e.getLocalizedMessage());\r
106                 }\r
107         }\r
108 \r
109 }\r