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;
18 public class BioJsHTMLOutputTest
21 @Test(groups = { "Functional" })
22 public void getJalviewAlignmentAsJsonString()
24 String bjsTemplate = null;
27 BioJsHTMLOutput.updateBioJS();
30 // allow the update some three seconds to complete before getting latest
31 // version of BioJS template
32 Thread.sleep(1000 * 3);
33 } catch (InterruptedException e)
37 bjsTemplate = BioJsHTMLOutput.getBioJsTemplateAsString();
38 // System.out.println(bjsTemplate);
39 } catch (IOException e)
43 Assert.assertNotNull(bjsTemplate);
47 groups = { "Functional" },
48 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",
79 .println("Number of discovered versions : " + versions.size());
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());
93 @Test(groups = { "Network" })
94 public void testBioJsUpdate()
96 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
98 .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());
103 System.out.println(">>> latest version : "
104 + repository.getLatestReleaseVersion());
105 System.out.println(">>> repo count : "
106 + repository.getReleases().size());
107 for (BioJSReleasePojo release : repository.getReleases())
109 System.out.println("repo type : " + release.getType());
110 System.out.println("url : " + release.getUrl());
111 System.out.println("release version : " + release.getVersion());
115 private static boolean urlIsReachable(String urlString)
119 final URL url = new URL(urlString);
120 final URLConnection conn = url.openConnection();
123 } catch (MalformedURLException e)
125 throw new RuntimeException(e);
126 } catch (IOException e)