3 import jalview.json.binding.biojs.BioJSReleasePojo;
4 import jalview.json.binding.biojs.BioJSRepositoryPojo;
7 import java.io.IOException;
8 import java.net.MalformedURLException;
9 import java.net.URISyntaxException;
11 import java.net.URLConnection;
12 import java.util.TreeMap;
14 import org.testng.Assert;
15 import org.testng.AssertJUnit;
16 import org.testng.annotations.Test;
19 public class BioJsHTMLOutputTest
22 @Test(groups ={ "Functional" })
23 public void getJalviewAlignmentAsJsonString()
25 String bjsTemplate = null;
28 BioJsHTMLOutput.updateBioJS();
31 // allow the update some three seconds to complete before getting latest
32 // version of BioJS template
33 Thread.sleep(1000 * 3);
34 } catch (InterruptedException e)
38 bjsTemplate = BioJsHTMLOutput.getBioJsTemplateAsString();
39 // System.out.println(bjsTemplate);
40 } catch (IOException e)
44 Assert.assertNotNull(bjsTemplate);
48 { "Functional" }, expectedExceptions = NullPointerException.class)
49 public void expectedNullPointerException()
53 BioJsHTMLOutput.refreshBioJSVersionsInfo(null);
54 } catch (URISyntaxException e)
56 AssertJUnit.fail("Expception occured while testing!");
61 @Test(groups ={ "Functional" })
62 public void getBioJsMSAVersions()
64 TreeMap<String, File> versions = null;
68 .refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
69 versions = BioJsHTMLOutput.getBioJsMSAVersions();
70 } catch (URISyntaxException e)
72 AssertJUnit.fail("Expception occured while testing!");
75 AssertJUnit.assertNotNull("No versions found", versions);
76 AssertJUnit.assertTrue("One or more Templates required", versions.size() > 0);
78 .println("Number of discovered versions : "
80 for (String v : versions.keySet())
82 System.out.println("version : " + v);
83 System.out.println("File : " + versions.get(v));
86 System.out.println("\nCurrent latest version : "
87 + BioJsHTMLOutput.getCurrentBJSTemplateFile());
88 AssertJUnit.assertNotNull("Latest BioJsMSA version NOT found!",
89 BioJsHTMLOutput.getCurrentBJSTemplateFile());
95 public void testBioJsUpdate()
97 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
98 AssertJUnit.assertTrue("URL not reacable : " + url, urlIsReachable(url));
99 String response = BioJsHTMLOutput.getURLContentAsString(url);
100 AssertJUnit.assertNotNull("Null response read from url!", response);
101 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
102 System.out.println(">>> description : " + repository.getDescription());
104 .println(">>> latest version : "
105 + repository.getLatestReleaseVersion());
106 System.out.println(">>> repo count : "
107 + repository.getReleases().size());
108 for (BioJSReleasePojo release : repository.getReleases())
110 System.out.println("repo type : " + release.getType());
111 System.out.println("url : " + release.getUrl());
112 System.out.println("release version : " + release.getVersion());
116 private static boolean urlIsReachable(String urlString)
120 final URL url = new URL(urlString);
121 final URLConnection conn = url.openConnection();
124 } catch (MalformedURLException e)
126 throw new RuntimeException(e);
127 } catch (IOException e)