AppPackage implements Closeable { public AppPackage(File file) throws IOException { this(new FileInputStream(file)); } AppPackage(File file);  AppPackage(InputStream input);  AppPackage(File file, File contentFolder, boolean processAppDirectory);  AppPackage(InputStream input, File contentFolder, boolean processAppDirectory);  AppPackage(File file, boolean processAppDirectory);  AppPackage(InputStream input, boolean processAppDirectory); static void extractToDirectory(File directory, File appPackageFile); static void createAppPackageFile(File fileToBeCreated, File directory); File tempDirectory(); @Override void close(); void cleanContent(); String getAppPackageName(); String getAppPackageVersion(); String getAppPackageGroupId(); String getAppPackageDescription(); String getAppPackageDisplayName(); String getDtEngineVersion(); List<String> getClassPath(); Collection<String> getConfigs(); File resourcesDirectory(); List<AppInfo> getApplications(); List<String> getAppJars(); List<String> getAppJsonFiles(); List<String> getAppPropertiesFiles(); Set<String> getRequiredProperties(); Map<String, PropertyInfo> getDefaultProperties(); void processAppDirectory(boolean skipJars); static final String ATTRIBUTE_DT_ENGINE_VERSION; static final String ATTRIBUTE_DT_APP_PACKAGE_NAME; static final String ATTRIBUTE_DT_APP_PACKAGE_VERSION; static final String ATTRIBUTE_DT_APP_PACKAGE_GROUP_ID; static final String ATTRIBUTE_CLASS_PATH; static final String ATTRIBUTE_DT_APP_PACKAGE_DISPLAY_NAME; static final String ATTRIBUTE_DT_APP_PACKAGE_DESCRIPTION; }
@Test public void testAppPackage() throws Exception { Assert.assertEquals("com.example", json.getString("appPackageGroupId")); Assert.assertEquals("mydtapp", json.getString("appPackageName")); Assert.assertEquals("1.0-SNAPSHOT", json.getString("appPackageVersion")); Assert.assertEquals(System.getProperty("apex.version", "3.4.0"), json.getString("dtEngineVersion")); Assert.assertEquals("lib/*.jar", json.getJSONArray("classPath").getString(0)); Assert.assertEquals("Number of applications", 2, json.getJSONArray("applications").length()); JSONArray applications = json.getJSONArray("applications"); Map<String, JSONObject> apps = new HashMap<>(); for (int i = 0; i < applications.length(); i++) { JSONObject application = applications.getJSONObject(i); apps.put(application.getString("name"), application); } JSONObject myFirstApplication = apps.get("MyFirstApplication"); JSONObject mySecondApplication = apps.get("MySecondApplication"); Assert.assertNotNull("MyFirstApplication not found", myFirstApplication); Assert.assertNotNull("MySecondApplication not found", mySecondApplication); Assert.assertEquals("mydtapp-1.0-SNAPSHOT.jar", myFirstApplication.getString("file")); String errorStackTrace = myFirstApplication.getString("errorStackTrace"); Assert.assertEquals("ErrorStackTrace", "null", errorStackTrace); JSONObject dag = myFirstApplication.getJSONObject("dag"); Assert.assertNotNull("MyFirstApplication DAG does not exist", dag); Assert.assertEquals("Number of streams", 1, dag.getJSONArray("streams").length()); Assert.assertEquals("Number of operators", 3, dag.getJSONArray("operators").length()); JSONArray operatorsJSONArray = dag.getJSONArray("operators"); Map<String, JSONObject> operatorMap = new HashMap<>(); for (int i = 0; i < operatorsJSONArray.length(); i++) { JSONObject operator = operatorsJSONArray.getJSONObject(i); operatorMap.put(operator.getString("name"), operator); } JSONObject operator = operatorMap.get("rand"); Assert.assertNotNull("Input Operator not found", operator); Assert.assertEquals("Input operator class", "com.example.mydtapp.RandomNumberGenerator", operator.getJSONObject("properties").get("@class")); operator = operatorMap.get("stdout"); Assert.assertNotNull("Output Operator not found", operator); Assert.assertEquals("Value for Output Operator's testInput:", "default-value-1", operator.getJSONObject("properties").get("testInput")); Assert.assertEquals("Output Operator class", "com.example.mydtapp.StdoutOperator", operator.getJSONObject("properties").get("@class")); operator = operatorMap.get("testModule$testModuleOperator"); Assert.assertNotNull("Test Module Operator not found", operator); Assert.assertEquals("Test Module Operator class", "com.example.mydtapp.TestModuleOperator", operator.getJSONObject("properties").get("@class")); Assert.assertEquals("Value for Test Module Operator's testInput:", "default-value-1", operator.getJSONObject("properties").get("testInput")); Assert.assertTrue("app package extraction folder should be retained", new File("target/testapp").exists()); yap.cleanContent(); Assert.assertTrue("app package extraction folder should be removed", !new File("target/testapp").exists()); }