|
1 | 1 | package org.biojava.nbio.protmod.phosphosite; |
2 | 2 |
|
3 | | -import junit.framework.TestCase; |
| 3 | + |
4 | 4 | import org.biojava.nbio.phosphosite.Dataset; |
5 | 5 | import org.biojava.nbio.phosphosite.Site; |
| 6 | +import org.junit.Before; |
| 7 | +import org.junit.Test; |
6 | 8 |
|
7 | 9 | import java.io.File; |
| 10 | +import java.io.IOException; |
8 | 11 | import java.net.URL; |
9 | 12 | import java.util.List; |
10 | 13 |
|
11 | | -/** |
| 14 | +import static org.junit.Assert.assertTrue; |
| 15 | +import static org.junit.Assert.fail; |
| 16 | + |
| 17 | +/** Makes sure there is a local installation of the Acetyaltion site file from Phosphosite and |
| 18 | + * tests if it can get parsed by the parser. |
| 19 | + * |
12 | 20 | * Created by andreas on 11/29/16. |
13 | 21 | */ |
14 | | -public class TestAcetylation extends TestCase { |
| 22 | +public class TestAcetylation { |
15 | 23 |
|
16 | 24 |
|
17 | | - /** Tests that the acetylation file can get downloaded and parsed |
| 25 | + /** Make sure an Acetylation file is available locally. |
| 26 | + * Downloads from Phosphosite if needed. |
18 | 27 | * |
19 | 28 | */ |
20 | | - public void testAcetylation() { |
21 | | - String f = Dataset.ACETYLATION; |
| 29 | + @Before |
| 30 | + public void setUp(){ |
22 | 31 |
|
23 | 32 | Dataset ds = new Dataset(); |
24 | 33 |
|
25 | | - try { |
26 | | - File localDir = ds.getLocalDir(); |
27 | | - if ( ! localDir.exists()) |
28 | | - localDir.mkdir(); |
29 | | - |
30 | | - int slashIndex = f.lastIndexOf("/"); |
31 | | - |
32 | | - String fileName = f.substring(slashIndex); |
| 34 | + String f = Dataset.ACETYLATION; |
33 | 35 |
|
34 | | - File localFile = new File(localDir + "/" + fileName); |
| 36 | + File localFile = getLocalFileName(f); |
35 | 37 |
|
| 38 | + try { |
36 | 39 | if (!localFile.exists()) { |
37 | 40 | ds.downloadFile(new URL(f), localFile); |
38 | 41 | } |
| 42 | + } catch (IOException e) { |
| 43 | + e.printStackTrace(); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + /** returns the local file name where the Acetylation file will get cached locally. |
| 48 | + * |
| 49 | + * @param phosphoSiteFileLocation location of file at PhosphoSitePlus. |
| 50 | + * @return a File pointing to the location of the locally cached file. |
| 51 | + */ |
| 52 | + private File getLocalFileName(String phosphoSiteFileLocation){ |
| 53 | + |
| 54 | + Dataset ds = new Dataset(); |
| 55 | + File localDir = ds.getLocalDir(); |
| 56 | + if ( ! localDir.exists()) { |
| 57 | + boolean success = localDir.mkdir(); |
| 58 | + if ( ! success) |
| 59 | + fail("Could not create directory " + localDir.getAbsolutePath()); |
| 60 | + } |
| 61 | + |
| 62 | + int slashIndex = phosphoSiteFileLocation.lastIndexOf("/"); |
| 63 | + |
| 64 | + String fileName = phosphoSiteFileLocation.substring(slashIndex); |
| 65 | + |
| 66 | + return new File(localDir + "/" + fileName); |
| 67 | + } |
| 68 | + |
| 69 | + /** Tests that the acetylation file can get parsed without problems. |
| 70 | + * |
| 71 | + */ |
| 72 | + @Test |
| 73 | + public void testAcetylation() { |
| 74 | + |
| 75 | + try { |
| 76 | + |
| 77 | + File localFile = getLocalFileName(Dataset.ACETYLATION); |
39 | 78 |
|
40 | 79 | List<Site> sites = Site.parseSites(localFile); |
41 | 80 |
|
|
0 commit comments