3 import jalview.json.binding.v1.BioJSReleasePojo;
4 import jalview.json.binding.v1.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.junit.Assert;
15 import org.junit.Test;
18 public class BioJsHTMLOutputTest
22 public void getJalviewAlignmentAsJsonString()
24 BioJsHTMLOutput bioJsHtmlOutput = new BioJsHTMLOutput(null, null);
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);
47 @Test(expected = NullPointerException.class)
48 public void expectedNullPointerException()
50 BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null);
53 bjs.refreshBioJSVersionsInfo(null);
54 } catch (URISyntaxException e)
56 Assert.fail("Expception occured while testing!");
62 public void getBioJsMSAVersions()
64 BioJsHTMLOutput bjs = new BioJsHTMLOutput(null, null);
65 TreeMap<String, File> versions = null;
68 bjs.refreshBioJSVersionsInfo(BioJsHTMLOutput.BJS_TEMPLATES_LOCAL_DIRECTORY);
69 versions = BioJsHTMLOutput.getBioJsMSAVersions();
70 } catch (URISyntaxException e)
72 Assert.fail("Expception occured while testing!");
75 Assert.assertNotNull("No versions found", versions);
76 Assert.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 Assert.assertNotNull("Latest BioJsMSA version NOT found!",
89 BioJsHTMLOutput.getCurrentBJSTemplateFile());
94 public void testBioJsUpdate()
96 String url = BioJsHTMLOutput.BJS_TEMPLATE_GIT_REPO;
97 Assert.assertTrue("URL not reacable : " + url, urlIsReachable(url));
98 String response = BioJsHTMLOutput.getURLContentAsString(url);
99 Assert.assertNotNull("Null response read from url!", response);
100 BioJSRepositoryPojo repository = new BioJSRepositoryPojo(response);
101 System.out.println(">>> description : " + repository.getDescription());
103 .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)