OtaHtmlGenerator extends VelocityBase<Parameters> { public static OtaHtmlGenerator getInstance() { return getInstance(null); } private  OtaHtmlGenerator(String template); static OtaHtmlGenerator getInstance(); static synchronized OtaHtmlGenerator getInstance(String template); static synchronized OtaHtmlGenerator getInstance(String template, boolean forceNewInstance); static URL generateHtmlServiceUrl(URL htmlServiceUrl, Map<String, String> params);  }
@Test public void testAlternativeTemplateByResource() throws IOException { URL plistURL = OtaPlistGenerator.generatePlistRequestUrl(new URL(plistServiceUrl), paramMap); String generated = OtaHtmlGenerator.getInstance("alternativeTemplate.html").generate( new Parameters(plistURL, null, buildMap(KEY_REFERER, referer, KEY_TITLE, title, KEY_BUNDLE_IDENTIFIER, bundleIdentifier), initParams)); checkAlternativeResult(plistURL, generated); }
@Test public void testAlternativeTemplateByFile() throws IOException { URL plistURL = OtaPlistGenerator.generatePlistRequestUrl(new URL(plistServiceUrl), paramMap); File templateFile = new File("./src/test/resources/alternativeTemplate.html"); assertTrue("File does not exist at " + templateFile.getAbsolutePath(), templateFile.isFile()); String generated = OtaHtmlGenerator.getInstance(templateFile.getAbsolutePath()).generate( new Parameters(plistURL, null, buildMap(KEY_REFERER, referer, KEY_TITLE, title, KEY_BUNDLE_IDENTIFIER, bundleIdentifier), initParams)); checkAlternativeResult(plistURL, generated); }
@Test public void getNewInstanceNull() throws FileNotFoundException { assertEquals(OtaHtmlGenerator.DEFAULT_TEMPLATE, OtaHtmlGenerator.getInstance(null).template.getName()); }
@Test public void getNewInstanceEmpty() throws FileNotFoundException { assertEquals(OtaHtmlGenerator.DEFAULT_TEMPLATE, OtaHtmlGenerator.getInstance("").template.getName()); }
@Test(expected = ResourceNotFoundException.class) public void getNewInstanceWrongResource() throws FileNotFoundException { assertEquals(OtaHtmlGenerator.DEFAULT_TEMPLATE, OtaHtmlGenerator.getInstance("doesnotexist.htm").template.getName()); }
@Test public void getNewInstanceCorrectFile() throws FileNotFoundException { assertEquals( "alternativeTemplate.html", OtaHtmlGenerator.getInstance(new File("./src/test/resources/alternativeTemplate.html").getAbsolutePath()).template .getName()); }
@Test(expected = ResourceNotFoundException.class) public void getNewInstanceWrongFile() throws FileNotFoundException { assertEquals(OtaHtmlGenerator.DEFAULT_TEMPLATE, OtaHtmlGenerator.getInstance(new File("./doesnotexist.htm").getAbsolutePath()).template.getName()); }
@Test public void testCorrectValues() throws IOException { URL plistURL = OtaPlistGenerator.generatePlistRequestUrl(new URL(plistServiceUrl), paramMap); String generated = OtaHtmlGenerator.getInstance().generate( new Parameters(plistURL, null, buildMap(KEY_REFERER, referer, KEY_TITLE, title, KEY_BUNDLE_IDENTIFIER, bundleIdentifier), initParams)); assertContains(String.format("Install App: %s", title), generated); TestUtils.assertOtaLink(generated, plistURL.toString(), bundleIdentifier); Pattern checkIpaLinkPattern = Pattern.compile("href='([^']+)'[^>]*>Install via iTunes</a>"); Matcher checkIpaLinkMatcher = checkIpaLinkPattern.matcher(generated); assertTrue("Ipa link not found", checkIpaLinkMatcher.find()); assertEquals(checkIpaURL, checkIpaLinkMatcher.group(1)); }