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 = HTMLOutput.readFileAsString(BioJsHTMLOutput
58 .getCurrentBJSTemplateFile());
59 // System.out.println(bjsTemplate);
60 } catch (IOException e)
64 Assert.assertNotNull(bjsTemplate);
68 groups = { "Functional" },
69 expectedExceptions = NullPointerException.class)
70 public void expectedNullPointerException()
74 BioJsHTMLOutput.refreshVersionInfo(null);
75 } catch (URISyntaxException e)
77 AssertJUnit.fail("Expception occured while testing!");
82 @Test(groups = { "Functional" })
83 public void getBioJsMSAVersions()
85 TreeMap<String, File> versions = null;
89 .refreshVersionInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
90 versions = BioJsHTMLOutput.getBioJsMSAVersions();
91 } catch (URISyntaxException e)
93 AssertJUnit.fail("Expception occured while testing!");
96 AssertJUnit.assertNotNull("No versions found", versions);
97 AssertJUnit.assertTrue("One or more Templates required",
100 .println("Number of discovered versions : " + versions.size());
101 for (String v : versions.keySet())
103 System.out.println("version : " + v);
104 System.out.println("File : " + versions.get(v));
107 System.out.println("\nCurrent latest version : "
108 + BioJsHTMLOutput.getCurrentBJSTemplateFile());
109 AssertJUnit.assertNotNull("Latest BioJsMSA version NOT found!",
110 BioJsHTMLOutput.getCurrentBJSTemplateFile());
114 @Test(groups = { "Network" })
115 public void testBioJsUpdate()
117 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
119 .assertTrue("URL not reacable : " + url, urlIsReachable(url));
120 String response = BioJsHTMLOutput.getURLContentAsString(url);
121 AssertJUnit.assertNotNull("Null response read from url!", response);
122 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
123 System.out.println(">>> description : " + repository.getDescription());
124 System.out.println(">>> latest version : "
125 + repository.getLatestReleaseVersion());
126 System.out.println(">>> repo count : "
127 + repository.getReleases().size());
128 for (BioJSReleasePojo release : repository.getReleases())
130 System.out.println("repo type : " + release.getType());
131 System.out.println("url : " + release.getUrl());
132 System.out.println("release version : " + release.getVersion());
136 private static boolean urlIsReachable(String urlString)
140 final URL url = new URL(urlString);
141 final URLConnection conn = url.openConnection();
144 } catch (MalformedURLException e)
146 throw new RuntimeException(e);
147 } catch (IOException e)