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.json.binding.biojs.BioJSReleasePojo;
24 import jalview.json.binding.biojs.BioJSRepositoryPojo;
27 import java.io.IOException;
28 import java.net.MalformedURLException;
29 import java.net.URISyntaxException;
31 import java.net.URLConnection;
32 import java.util.TreeMap;
34 import org.testng.Assert;
35 import org.testng.AssertJUnit;
36 import org.testng.annotations.Test;
38 public class BioJsHTMLOutputTest
41 @Test(groups = { "Functional" })
42 public void getJalviewAlignmentAsJsonString()
44 String bjsTemplate = null;
47 BioJsHTMLOutput.updateBioJS();
50 // allow the update some three seconds to complete before getting latest
51 // version of BioJS template
52 Thread.sleep(1000 * 3);
53 } catch (InterruptedException e)
57 bjsTemplate = BioJsHTMLOutput.getBioJsTemplateAsString();
58 // System.out.println(bjsTemplate);
59 } catch (IOException e)
63 Assert.assertNotNull(bjsTemplate);
67 groups = { "Functional" },
68 expectedExceptions = NullPointerException.class)
69 public void expectedNullPointerException()
73 BioJsHTMLOutput.refreshBioJSVersionsInfo(null);
74 } catch (URISyntaxException e)
76 AssertJUnit.fail("Expception occured while testing!");
81 @Test(groups = { "Functional" })
82 public void getBioJsMSAVersions()
84 TreeMap<String, File> versions = null;
88 .refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
89 versions = BioJsHTMLOutput.getBioJsMSAVersions();
90 } catch (URISyntaxException e)
92 AssertJUnit.fail("Expception occured while testing!");
95 AssertJUnit.assertNotNull("No versions found", versions);
96 AssertJUnit.assertTrue("One or more Templates required",
99 .println("Number of discovered versions : " + versions.size());
100 for (String v : versions.keySet())
102 System.out.println("version : " + v);
103 System.out.println("File : " + versions.get(v));
106 System.out.println("\nCurrent latest version : "
107 + BioJsHTMLOutput.getCurrentBJSTemplateFile());
108 AssertJUnit.assertNotNull("Latest BioJsMSA version NOT found!",
109 BioJsHTMLOutput.getCurrentBJSTemplateFile());
113 @Test(groups = { "Network" })
114 public void testBioJsUpdate()
116 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
118 .assertTrue("URL not reacable : " + url, urlIsReachable(url));
119 String response = BioJsHTMLOutput.getURLContentAsString(url);
120 AssertJUnit.assertNotNull("Null response read from url!", response);
121 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
122 System.out.println(">>> description : " + repository.getDescription());
123 System.out.println(">>> latest version : "
124 + repository.getLatestReleaseVersion());
125 System.out.println(">>> repo count : "
126 + repository.getReleases().size());
127 for (BioJSReleasePojo release : repository.getReleases())
129 System.out.println("repo type : " + release.getType());
130 System.out.println("url : " + release.getUrl());
131 System.out.println("release version : " + release.getVersion());
135 private static boolean urlIsReachable(String urlString)
139 final URL url = new URL(urlString);
140 final URLConnection conn = url.openConnection();
143 } catch (MalformedURLException e)
145 throw new RuntimeException(e);
146 } catch (IOException e)