AppSetupHelper { protected static JSONObject readViewFile(final String viewfile) { String json = getPaths(viewfile).stream() .map(filename -> tryResource(filename)) .filter(j -> j != null && !j.isEmpty()) .findFirst() .orElse(null); if (json == null) { throw new OskariRuntimeException("Couldn't locate appsetup JSON for " + viewfile); } return JSONHelper.createJSONObject(json); }  static long create(Connection conn, final String viewfile); static List<Long> getSetupsForUserAndDefaultType(Connection connection); static List<Long> getSetupsForUserAndDefaultType(Connection connection, String applicationName); static List<Long> getSetupsForType(Connection connection, String... types); static List<Long> getSetupsForApplicationByType(Connection conn, String applicationName, String... types); static String getUuidForDefaultSetup(Connection conn, String applicationName); static boolean appContainsBundle(Connection connection, long viewId, String bundle); static Bundle getAppBundle(Connection connection, long viewId, String bundle); static Bundle updateAppBundle(Connection connection, long viewId, Bundle bundle); static void addBundleToApps(Connection connection, String bundlename); static void addBundleToApps(Connection connection, Bundle bundle); static void addBundleToApps(Connection connection, Bundle bundle, String application); static void addOrUpdateBundleInApps(Connection connection, Bundle bundle, List<Long> appsetupIds); static void addBundleToApp(Connection connection, long viewId, String bundleid); static void removeBundleFromApp(Connection connection, long viewId, String bundleName);  }
@Test public void readViewFile() throws Exception { assertEquals("root", AppSetupHelper.readViewFile("/test.json").optString("name")); assertEquals("apps", AppSetupHelper.readViewFile("/json/apps/custom/appsetup.json").optString("name")); JSONObject apps = AppSetupHelper.readViewFile("custom/appsetup.json"); assertEquals("apps", apps.optString("name")); JSONObject views = AppSetupHelper.readViewFile("appsetup.json"); assertEquals("views", views.optString("name")); assertEquals("root", AppSetupHelper.readViewFile("test.json").optString("name")); }