2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
23 import jalview.gui.JvOptionPane;
24 import jalview.json.binding.biojs.BioJSReleasePojo;
25 import jalview.json.binding.biojs.BioJSRepositoryPojo;
28 import java.io.IOException;
29 import java.net.MalformedURLException;
30 import java.net.URISyntaxException;
32 import java.net.URLConnection;
33 import java.util.TreeMap;
35 import org.testng.Assert;
36 import org.testng.AssertJUnit;
37 import org.testng.annotations.BeforeClass;
38 import org.testng.annotations.Test;
40 public class BioJsHTMLOutputTest
43 @BeforeClass(alwaysRun = true)
44 public void setUpJvOptionPane()
46 JvOptionPane.setInteractiveMode(false);
47 JvOptionPane.setMockResponse(JvOptionPane.CANCEL_OPTION);
50 @Test(groups = { "Functional" })
51 public void getJalviewAlignmentAsJsonString()
53 String bjsTemplate = null;
56 BioJsHTMLOutput.updateBioJS();
59 // allow the update some three seconds to complete before getting latest
60 // version of BioJS template
61 Thread.sleep(1000 * 3);
62 } catch (InterruptedException e)
66 bjsTemplate = HTMLOutput.readFileAsString(
67 BioJsHTMLOutput.getCurrentBJSTemplateFile());
68 // System.out.println(bjsTemplate);
69 } catch (IOException e)
73 Assert.assertNotNull(bjsTemplate);
79 expectedExceptions = NullPointerException.class)
80 public void expectedNullPointerException()
84 BioJsHTMLOutput.refreshVersionInfo(null);
85 } catch (URISyntaxException e)
87 AssertJUnit.fail("Expception occured while testing!");
92 @Test(groups = { "Functional" })
93 public void getBioJsMSAVersions()
95 TreeMap<String, File> versions = null;
98 BioJsHTMLOutput.refreshVersionInfo(
99 BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
100 versions = BioJsHTMLOutput.getBioJsMSAVersions();
101 } catch (URISyntaxException e)
103 AssertJUnit.fail("Expception occured while testing!");
106 AssertJUnit.assertNotNull("No versions found", versions);
107 AssertJUnit.assertTrue("One or more Templates required",
108 versions.size() > 0);
110 .println("Number of discovered versions : " + versions.size());
111 for (String v : versions.keySet())
113 System.out.println("version : " + v);
114 System.out.println("File : " + versions.get(v));
117 System.out.println("\nCurrent latest version : "
118 + BioJsHTMLOutput.getCurrentBJSTemplateFile());
119 AssertJUnit.assertNotNull("Latest BioJsMSA version NOT found!",
120 BioJsHTMLOutput.getCurrentBJSTemplateFile());
124 @Test(groups = { "Network" })
125 public void testBioJsUpdate()
127 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
128 AssertJUnit.assertTrue("URL not reacable : " + url,
129 urlIsReachable(url));
130 String response = BioJsHTMLOutput.getURLContentAsString(url);
131 AssertJUnit.assertNotNull("Null response read from url!", response);
132 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
133 System.out.println(">>> description : " + repository.getDescription());
135 ">>> latest version : " + repository.getLatestReleaseVersion());
137 .println(">>> repo count : " + repository.getReleases().size());
138 for (BioJSReleasePojo release : repository.getReleases())
140 System.out.println("repo type : " + release.getType());
141 System.out.println("url : " + release.getUrl());
142 System.out.println("release version : " + release.getVersion());
146 private static boolean urlIsReachable(String urlString)
150 final URL url = new URL(urlString);
151 final URLConnection conn = url.openConnection();
154 } catch (MalformedURLException e)
156 throw new RuntimeException(e);
157 } catch (IOException e)