f6867f71e30efddbf404387cb5fb4c11b136d330
[proteocache.git] / testsrc / compbio / engine / client / PathValidatorTester.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 \r
19 package compbio.engine.client;\r
20 \r
21 import static org.testng.Assert.assertFalse;\r
22 import static org.testng.Assert.assertTrue;\r
23 import static org.testng.Assert.fail;\r
24 \r
25 import java.io.File;\r
26 import java.io.IOException;\r
27 import java.net.URISyntaxException;\r
28 import java.net.URL;\r
29 \r
30 import org.testng.annotations.Test;\r
31 \r
32 import compbio.engine.client.PathValidator;\r
33 import compbio.runner.msa.ClustalW;\r
34 import compbio.util.SysPrefs;\r
35 \r
36 public class PathValidatorTester {\r
37 \r
38         @Test\r
39         public void testIsAbsolutePath() {\r
40 \r
41                 if (SysPrefs.isWindows) {\r
42                         /*\r
43                          * slash(\) has to be prefixed with another slash to produce a\r
44                          * single slash\r
45                          */\r
46                         assertTrue(PathValidator.isAbsolutePath("d:\\temp"));\r
47                         assertFalse(PathValidator.isAbsolutePath("/home"));\r
48                 } else {\r
49                         assertFalse(PathValidator.isAbsolutePath("d:\\temp"));\r
50                         assertTrue(PathValidator.isAbsolutePath("/home"));\r
51                 }\r
52                 assertFalse(PathValidator.isAbsolutePath("home"));\r
53         }\r
54 \r
55         @Test\r
56         public void testGetClassPath() {\r
57                 String clname = ClustalW.class.getSimpleName();\r
58                 System.out.println("%" + clname);\r
59                 URL url = ClustalW.class.getResource(clname + ".class");\r
60                 URL url2 = ClassLoader.getSystemResource("Engine.local.properties");\r
61 \r
62                 try {\r
63                         File f = new File(url.toURI());\r
64                         System.out.println("&" + f.getAbsolutePath());\r
65                         System.out.println("&" + f.getCanonicalPath());\r
66                         System.out.println("&" + f.getParent());\r
67                 } catch (URISyntaxException e) {\r
68                         e.printStackTrace();\r
69                         fail(e.getLocalizedMessage());\r
70                 } catch (IOException e) {\r
71                         e.printStackTrace();\r
72                         fail(e.getLocalizedMessage());\r
73                 }\r
74                 System.out.println("!!" + url2);\r
75                 System.out.println("!" + url.getFile());\r
76                 System.out.println("!" + System.getProperty("java.class.path", null));\r
77 \r
78         }\r
79 }\r