use of com.chimbori.hermitcrab.schema.manifest.RelatedApp in project lite-apps by chimbori.
the class Scraper method findRelatedApps.
private List<RelatedApp> findRelatedApps() {
List<RelatedApp> relatedApps = new ArrayList<>();
Elements playStoreLinks = doc.select("a[href*=play.google.com]");
for (Element playStoreLink : playStoreLinks) {
String playStoreUrl = playStoreLink.attr("href");
System.out.println(playStoreUrl);
Matcher matcher = Pattern.compile("id=([^&]+)").matcher(playStoreUrl);
while (matcher.find()) {
relatedApps.add(new RelatedApp(matcher.group(1)));
}
}
return relatedApps.isEmpty() ? null : relatedApps;
}
use of com.chimbori.hermitcrab.schema.manifest.RelatedApp in project lite-apps by chimbori.
the class LiteAppsValidator method testManifestIsValid.
@Test
public void testManifestIsValid() throws UnsupportedEncodingException {
File manifestFile = new File(liteApp, FilePaths.MANIFEST_JSON_FILE_NAME);
Manifest manifest = readManifest(manifestFile);
String tag = liteApp.getName();
assertNotNull(manifest);
assertFieldExists(tag, "name", manifest.name);
assertFieldExists(tag, "start_url", manifest.startUrl);
assertFieldExists(tag, "lang", manifest.lang);
assertFieldExists(tag, "manifest_url", manifest.manifestUrl);
assertFieldExists(tag, "theme_color", manifest.themeColor);
assertFieldExists(tag, "secondary_color", manifest.secondaryColor);
assertFieldExists(tag, "manifest_version", manifest.manifestVersion);
assertFieldExists(tag, "icon", manifest.icon);
assertNotEquals(String.format("priority not defined for %s", liteApp), 0, manifest.priority.longValue());
// Test that the "manifest_url" field contains a valid URL.
try {
URL manifestUrl = new URL(manifest.manifestUrl);
assertEquals("https", manifestUrl.getProtocol());
assertEquals("hermit.chimbori.com", manifestUrl.getHost());
assertTrue(manifestUrl.getPath().startsWith("/lite-apps/"));
assertTrue(manifestUrl.getPath().endsWith(".hermit"));
assertEquals(liteApp.getName() + ".hermit", new File(URLDecoder.decode(manifestUrl.getFile(), "UTF-8")).getName());
} catch (MalformedURLException e) {
fail(e.getMessage());
}
// Test that colors are valid hex colors.
assertTrue(String.format("[%s] theme_color should be a valid hex color", tag), HEX_COLOR_PATTERN.matcher(manifest.themeColor).matches());
assertTrue(String.format("[%s] secondary_color should be a valid hex color", tag), HEX_COLOR_PATTERN.matcher(manifest.secondaryColor).matches());
// Test that the name of the icon file is "icon.png" & that the file exists.
// Although any filename should work, having it be consistent in the library can let us
// avoid a filename lookup in automated tests and refactors.
assertEquals(IconFile.FAVICON_FILE, manifest.icon);
File iconsDirectory = new File(liteApp, FilePaths.ICONS_DIR_NAME);
assertTrue(new File(iconsDirectory, IconFile.FAVICON_FILE.fileName).exists());
// Test Endpoints for basic parseability.
validateEndpoints(tag, manifest.hermitBookmarks, EndpointRole.BOOKMARK);
validateEndpoints(tag, manifest.hermitFeeds, EndpointRole.FEED);
validateEndpoints(tag, manifest.hermitShare, EndpointRole.SHARE);
validateEndpoints(tag, manifest.hermitSearch, EndpointRole.SEARCH);
validateEndpoints(tag, manifest.hermitMonitors, EndpointRole.MONITOR);
// Test all Settings to see whether they belong to our whitelisted set of allowable strings.
validateSettings(tag, manifestFile);
// Test "related_apps" for basic sanity, that if one exists, then it’s pointing to a Play Store app.
if (manifest.relatedApplications != null) {
for (RelatedApp relatedApplication : manifest.relatedApplications) {
assertEquals(GOOGLE_PLAY, relatedApplication.platform);
assertFalse(relatedApplication.id.isEmpty());
assertTrue(relatedApplication.url.startsWith("https://play.google.com/store/apps/details?id="));
assertTrue(relatedApplication.url.endsWith(relatedApplication.id));
}
}
// Test that if any localization files are present, then they are well-formed.
File localesDirectory = new File(liteApp, FilePaths.LOCALES_DIR_NAME);
if (localesDirectory.exists()) {
File[] localizations = localesDirectory.listFiles(File::isDirectory);
if (localizations != null) {
for (File localization : localizations) {
File messagesFile = new File(localization, FilePaths.MESSAGES_JSON_FILE_NAME);
// With no specific field checks, we at least validate that the file is well-formed JSON.
try {
TestHelpers.assertJsonIsWellFormedAndReformat(messagesFile);
} catch (IOException e) {
fail(e.getMessage());
}
}
}
}
}
Aggregations