Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.io

File BioJsHTMLOutputTest.java

 

Code metrics

0
48
6
1
161
126
12
0.25
8
6
2

Classes

Class Line # Actions
BioJsHTMLOutputTest 40 48 12 27
0.550%
 

Contributing tests

This file is covered by 3 tests. .

Source view

1    /*
2    * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3    * Copyright (C) $$Year-Rel$$ The Jalview Authors
4    *
5    * This file is part of Jalview.
6    *
7    * Jalview is free software: you can redistribute it and/or
8    * modify it under the terms of the GNU General Public License
9    * as published by the Free Software Foundation, either version 3
10    * of the License, or (at your option) any later version.
11    *
12    * Jalview is distributed in the hope that it will be useful, but
13    * WITHOUT ANY WARRANTY; without even the implied warranty
14    * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
15    * PURPOSE. See the GNU General Public License for more details.
16    *
17    * You should have received a copy of the GNU General Public License
18    * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
19    * The Jalview Authors are detailed in the 'AUTHORS' file.
20    */
21    package jalview.io;
22   
23    import jalview.gui.JvOptionPane;
24    import jalview.json.binding.biojs.BioJSReleasePojo;
25    import jalview.json.binding.biojs.BioJSRepositoryPojo;
26   
27    import java.io.File;
28    import java.io.IOException;
29    import java.net.MalformedURLException;
30    import java.net.URISyntaxException;
31    import java.net.URL;
32    import java.net.URLConnection;
33    import java.util.TreeMap;
34   
35    import org.testng.Assert;
36    import org.testng.AssertJUnit;
37    import org.testng.annotations.BeforeClass;
38    import org.testng.annotations.Test;
39   
 
40    public class BioJsHTMLOutputTest
41    {
42   
 
43  1 toggle @BeforeClass(alwaysRun = true)
44    public void setUpJvOptionPane()
45    {
46  1 JvOptionPane.setInteractiveMode(false);
47  1 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
48    }
49   
 
50  1 toggle @Test(groups = { "Functional" })
51    public void getJalviewAlignmentAsJsonString()
52    {
53  1 String bjsTemplate = null;
54  1 try
55    {
56  1 BioJsHTMLOutput.updateBioJS();
57  1 try
58    {
59    // allow the update some three seconds to complete before getting latest
60    // version of BioJS template
61  1 Thread.sleep(1000 * 3);
62    } catch (InterruptedException e)
63    {
64  0 e.printStackTrace();
65    }
66  1 bjsTemplate = HTMLOutput.readFileAsString(BioJsHTMLOutput
67    .getCurrentBJSTemplateFile());
68    // System.out.println(bjsTemplate);
69    } catch (IOException e)
70    {
71  0 e.printStackTrace();
72    }
73  1 Assert.assertNotNull(bjsTemplate);
74    }
75   
 
76  1 toggle @Test(
77    groups = { "Functional" },
78    expectedExceptions = NullPointerException.class)
79    public void expectedNullPointerException()
80    {
81  1 try
82    {
83  1 BioJsHTMLOutput.refreshVersionInfo(null);
84    } catch (URISyntaxException e)
85    {
86  0 AssertJUnit.fail("Expception occured while testing!");
87  0 e.printStackTrace();
88    }
89    }
90   
 
91  1 toggle @Test(groups = { "Functional" })
92    public void getBioJsMSAVersions()
93    {
94  1 TreeMap<String, File> versions = null;
95  1 try
96    {
97  1 BioJsHTMLOutput
98    .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
99  1 versions = BioJsHTMLOutput.getBioJsMSAVersions();
100    } catch (URISyntaxException e)
101    {
102  0 AssertJUnit.fail("Expception occured while testing!");
103  0 e.printStackTrace();
104    }
105  1 AssertJUnit.assertNotNull("No versions found", versions);
106  1 AssertJUnit.assertTrue("One or more Templates required",
107    versions.size() > 0);
108  1 System.out
109    .println("Number of discovered versions : " + versions.size());
110  1 for (String v : versions.keySet())
111    {
112  3 System.out.println("version : " + v);
113  3 System.out.println("File : " + versions.get(v));
114    }
115   
116  1 System.out.println("\nCurrent latest version : "
117    + BioJsHTMLOutput.getCurrentBJSTemplateFile());
118  1 AssertJUnit.assertNotNull("Latest BioJsMSA version NOT found!",
119    BioJsHTMLOutput.getCurrentBJSTemplateFile());
120   
121    }
122   
 
123  0 toggle @Test(groups = { "Network" })
124    public void testBioJsUpdate()
125    {
126  0 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
127  0 AssertJUnit
128    .assertTrue("URL not reacable : " + url, urlIsReachable(url));
129  0 String response = BioJsHTMLOutput.getURLContentAsString(url);
130  0 AssertJUnit.assertNotNull("Null response read from url!", response);
131  0 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
132  0 System.out.println(">>> description : " + repository.getDescription());
133  0 System.out.println(">>> latest version : "
134    + repository.getLatestReleaseVersion());
135  0 System.out.println(">>> repo count : "
136    + repository.getReleases().size());
137  0 for (BioJSReleasePojo release : repository.getReleases())
138    {
139  0 System.out.println("repo type : " + release.getType());
140  0 System.out.println("url : " + release.getUrl());
141  0 System.out.println("release version : " + release.getVersion());
142    }
143    }
144   
 
145  0 toggle private static boolean urlIsReachable(String urlString)
146    {
147  0 try
148    {
149  0 final URL url = new URL(urlString);
150  0 final URLConnection conn = url.openConnection();
151  0 conn.connect();
152  0 return true;
153    } catch (MalformedURLException e)
154    {
155  0 throw new RuntimeException(e);
156    } catch (IOException e)
157    {
158  0 return false;
159    }
160    }
161    }