changeset 347:0787febc9b94

8170904: Fix javapackager failing testcases mentioned in description of bug Reviewed-by: cbensen
author rgangadhar
date Wed, 14 Dec 2016 12:05:20 +0530
parents b80a8efca46c
children 917b77e1b81f
files functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/AntBundlingManager.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/BundlingManager.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/AbstractBundlerUtils.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/CoupleSecondaryLaunchersTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherSameJreTest.java functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherWithJvmParametersTest.java
diffstat 6 files changed, 267 insertions(+), 99 deletions(-) [+]
line wrap: on
line diff
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/AntBundlingManager.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/AntBundlingManager.java	Wed Dec 14 12:05:20 2016 +0530
@@ -244,12 +244,16 @@
                             }
 
                             case MAIN_MODULE:
-                                launcherEl.setAttribute(MAIN_MODULE, (String) keyVal.getValue());
-                            break;
+                                launcherEl.setAttribute(MAIN_MODULE,
+                                        ((String) keyVal.getValue()).split("/")[0]);
+                                launcherEl.setAttribute("mainClass",
+                                        ((String) keyVal.getValue()).split("/")[1]);
+                                break;
 
                             case APPLICATION_CLASS:
-                                launcherEl.setAttribute("mainClass", (String) keyVal.getValue());
-                            break;
+                                launcherEl.setAttribute("mainClass",
+                                        (String) keyVal.getValue());
+                                break;
 
                             default:
                                 Element bundlerArgumentEntry = createBundleArgumentEntry(document,
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/BundlingManager.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/BundlingManager.java	Wed Dec 14 12:05:20 2016 +0530
@@ -152,7 +152,7 @@
 
         if (Objects.nonNull(getBundler().getID())) {
             stringBuilder.append("-");
-            stringBuilder.append(getBundler().getID());
+            stringBuilder.append(getBundler().getID().replace('.', '_'));
         }
         return stringBuilder.toString();
     }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/AbstractBundlerUtils.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/src/com/oracle/appbundlers/utils/installers/AbstractBundlerUtils.java	Wed Dec 14 12:05:20 2016 +0530
@@ -16,21 +16,20 @@
 import java.io.IOException;
 import java.nio.file.Files;
 import java.nio.file.Path;
-import java.nio.file.Paths;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashMap;
+import java.util.Iterator;
 import java.util.List;
 import java.util.Map;
 import java.util.Optional;
+import java.util.Set;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeoutException;
 import java.util.logging.Level;
 import java.util.logging.Logger;
-import java.util.stream.Stream;
-
-import javax.management.RuntimeErrorException;
+import java.util.stream.Collectors;
 
 import org.testng.Assert;
 
@@ -86,6 +85,7 @@
     public static final String APPCDS_CACHE_FILE_EXISTS_INSTALL = "APPCDS_CACHE_FILE_EXISTS_INSTALL";
     public static final String CHECK_MODULE_IN_JAVA_EXECUTABLE = "CHECK_MODULE_IN_JAVA_EXECUTABLE";
     public static final String CHECK_EXECUTABLES_AVAILABLE_IN_BIN = "EXECUTABLES_AVAILABLE";
+    public static final String SAME_JAVA_EXECUTABLE_OUTPUT = "SAME_JAVA_EXECUTABLE_OUTPUT";
 
     private final Bundler bundler;
 
@@ -187,22 +187,26 @@
 
         verificators.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
                 (value, app, applicationTitle) -> {
-                    @SuppressWarnings("unchecked")
-                    Pair<String, List<String>> args = (Pair<String, List<String>>) value;
-                    final String execName = args.getKey();
-                    final List<String> expectedOutput = args.getValue();
+                    if (value instanceof List) {
+                        Iterator<Pair<String, List<String>>> iterator = ((List<Pair<String, List<String>>>) value)
+                                .iterator();
+                        while (iterator.hasNext()) {
+                            Pair<String, List<String>> args = iterator.next();
+                            final String execName = args.getKey();
+                            final List<String> expectedOutput = args.getValue();
 
-                    try {
-                        ProcessOutput process = Utils.runCommand(
-                                new String[] {
-                                        getInstalledExecutableLocation(app,
-                                                applicationTitle, execName)
-                                                        .toString() },
-                                /* verbose = */ true,
-                                CONFIG_INSTANCE.getRunTimeout());
-                        checkOutputContains(process, expectedOutput);
-                    } catch (IOException | ExecutionException e) {
-                        Assert.fail(e.getMessage(), e);
+                            try {
+                                ProcessOutput process = Utils.runCommand(
+                                        new String[] {
+                                                getInstalledExecutableLocation(
+                                                        app, applicationTitle,
+                                                        execName).toString() },
+                                        true, CONFIG_INSTANCE.getRunTimeout());
+                                checkOutputContains(process, expectedOutput);
+                            } catch (IOException | ExecutionException e) {
+                                Assert.fail(e.getMessage(), e);
+                            }
+                        }
                     }
                 });
 
@@ -222,45 +226,77 @@
                 (value, app, applicationTitle) -> {
                     @SuppressWarnings("unchecked")
 
-                    Pair<String, String> params = (Pair<String, String>) value;
-                    String secondAppName = params.getValue();
+                    Map<String, Map<String, String>> params = (Map<String, Map<String, String>>) value;
+                    Map<String, String> appNamesToOutput = params
+                            .get(SAME_JAVA_EXECUTABLE_OUTPUT);
+                    Set<String> appNames = appNamesToOutput.keySet();
+                    Set<String> secondAppNameSet = appNames.stream()
+                            .filter((String appName) -> !appName
+                                    .equals(applicationTitle))
+                            .collect(Collectors.toSet());
+                    String secondAppName = secondAppNameSet.iterator().next();
+                    LOG.log(Level.INFO, "first app name is {0}",
+                            applicationTitle);
+                    LOG.log(Level.INFO, "second app name is {0}",
+                            secondAppName);
+                    try {
+                        ProcessOutput firstAppProcessOutput = runInstalledExecutable(
+                                app, applicationTitle);
+                        final String openedText = "[info][class,load] opened:";
 
-                    try {
-                        ProcessOutput processOutput = runInstalledExecutable(app,
-                                applicationTitle);
-                        final String openedText = "[info][class,load] opened:";
-                        Optional<String> maybePath = processOutput.getOutputStream()
-                                .stream()
+                        List<String> outputStream = firstAppProcessOutput
+                                .getOutputStream();
+
+                        checkOutputContains(firstAppProcessOutput,
+                                Arrays.asList(appNamesToOutput
+                                        .get(applicationTitle)));
+                        Optional<String> maybePath = outputStream.stream()
                                 .filter(s -> s.contains(openedText))
                                 .findFirst();
-                        String[] firstAppVerboseOutput = maybePath.orElseThrow(Exception::new)
-                                .split("opened:");
+                        String[] firstAppVerboseOutput = maybePath
+                                .orElseThrow(Exception::new).split("opened:");
 
                         Path root = getInstalledAppRootLocation(app,
                                 applicationTitle).toAbsolutePath();
 
-                        String firstAppJdk9ModulesPath = firstAppVerboseOutput[1].trim();
-                        assertTrue(firstAppJdk9ModulesPath.startsWith(root.toString()), String.format(
-                                "[%s does not start with %s]", firstAppJdk9ModulesPath, firstAppJdk9ModulesPath));
+                        String firstAppJdk9ModulesPath = firstAppVerboseOutput[1]
+                                .trim();
+                        assertTrue(
+                                firstAppJdk9ModulesPath
+                                        .startsWith(root.toString()),
+                                String.format("[%s does not start with %s]",
+                                        firstAppJdk9ModulesPath,
+                                        firstAppJdk9ModulesPath));
 
                         ProcessOutput secondAppProcessOutput = Utils.runCommand(
                                 new String[] {
                                         getInstalledExecutableLocation(app,
                                                 applicationTitle, secondAppName)
                                                         .toString() },
-                                true,
-                                CONFIG_INSTANCE.getRunTimeout());
+                                true, CONFIG_INSTANCE.getRunTimeout());
 
-                        Optional<String> secondMaybePath = secondAppProcessOutput.getOutputStream()
-                                .stream()
-                                .filter(s -> s.contains(openedText))
+                        checkOutputContains(secondAppProcessOutput, Arrays
+                                .asList(appNamesToOutput.get(secondAppName)));
+
+                        List<String> outputStream2 = secondAppProcessOutput
+                                .getOutputStream();
+                        Optional<String> secondMaybePath = outputStream2
+                                .stream().filter(s -> s.contains(openedText))
                                 .findFirst();
-                        String[] secondAppVerboseOutput = secondMaybePath.orElseThrow(Exception::new)
-                                .split("opened:");
+                        String[] secondAppVerboseOutput = secondMaybePath
+                                .orElseThrow(Exception::new).split("opened:");
+                        LOG.log(Level.INFO,
+                                "Root Location of Installed Application is {0}",
+                                root.toString());
+                        LOG.log(Level.INFO, "FirstAppVerboseOutput is {0}",
+                                Arrays.toString(firstAppVerboseOutput));
+                        LOG.log(Level.INFO, "Second App Verbose Output is {0}",
+                                Arrays.toString(secondAppVerboseOutput));
+                        String secondAppJdk9ModulesPath = secondAppVerboseOutput[1]
+                                .trim();
 
-                        String secondAppJdk9ModulesPath = secondAppVerboseOutput[1].trim();
-
-                        assertEquals(firstAppJdk9ModulesPath, secondAppJdk9ModulesPath,
+                        assertEquals(firstAppJdk9ModulesPath,
+                                secondAppJdk9ModulesPath,
                                 "[Second app uses different java location]");
 
                     } catch (Exception e) {
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/CoupleSecondaryLaunchersTest.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/CoupleSecondaryLaunchersTest.java	Wed Dec 14 12:05:20 2016 +0530
@@ -75,11 +75,13 @@
     private Map<String, Object> getSecondLauncher() throws IOException {
         Map<String, Object> secondLauncher = new HashMap<>();
         secondLauncher.put(APP_NAME, secondAppName);
-        secondLauncher.put(APPLICATION_CLASS,
-                COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
         if (this.currentParameter.getApp().isAppContainsModules()) {
             secondLauncher.put(MAIN_MODULE,
-                    COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
+                    String.join("/", COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
+                            COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME));
+        } else {
+            secondLauncher.put(APPLICATION_CLASS,
+                    COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
         }
         secondLauncher.put(ARGUMENTS, asList(secondAppName));
         return secondLauncher;
@@ -88,11 +90,13 @@
     private Map<String, Object> getThirdLauncher() throws IOException {
         Map<String, Object> thirdLauncher = new HashMap<>();
         thirdLauncher.put(APP_NAME, thirdAppName);
-        thirdLauncher.put(APPLICATION_CLASS,
-                COM_GREETINGS_APP3_QUALIFIED_CLASS_NAME);
         if (this.currentParameter.getApp().isAppContainsModules()) {
             thirdLauncher.put(MAIN_MODULE,
-                    COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
+                    String.join("/", COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
+                            COM_GREETINGS_APP3_QUALIFIED_CLASS_NAME));
+        } else {
+            thirdLauncher.put(APPLICATION_CLASS,
+                    COM_GREETINGS_APP3_QUALIFIED_CLASS_NAME);
         }
         thirdLauncher.put(ARGUMENTS, asList(thirdAppName));
         return thirdLauncher;
@@ -103,10 +107,12 @@
             Map<String, Object> verifiedOptions = getAdditionalParams()
                     .getAdditionalParams();
             verifiedOptions.put(OUTPUT_CONTAINS, PASS_1);
+
+            List<Pair<String, List<String>>> multipleExpectedOutputPair = new ArrayList<>();
+            multipleExpectedOutputPair.add(new Pair<>(secondAppName, asList(PASS_2, secondAppName)));
+            multipleExpectedOutputPair.add(new Pair<>(thirdAppName, asList(PASS_3, thirdAppName)));
             verifiedOptions.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
-                    new Pair<>(secondAppName, asList(PASS_2, secondAppName)));
-            verifiedOptions.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
-                    new Pair<>(thirdAppName, asList(PASS_3, thirdAppName)));
+                    multipleExpectedOutputPair);
             return verifiedOptions;
         };
     }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherSameJreTest.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherSameJreTest.java	Wed Dec 14 12:05:20 2016 +0530
@@ -8,20 +8,26 @@
 import static com.oracle.appbundlers.utils.BundlerUtils.RPM;
 import static com.oracle.appbundlers.utils.BundlerUtils.WIN_APP;
 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.SAME_JAVA_EXECUTABLE;
+import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.SAME_JAVA_EXECUTABLE_OUTPUT;
 
 import java.io.IOException;
 import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams;
 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
+import com.oracle.appbundlers.utils.AppWrapper;
 import com.oracle.appbundlers.utils.BundlerUtils;
 import com.oracle.appbundlers.utils.BundlingManagers;
 import com.oracle.appbundlers.utils.ExtensionType;
-
-import javafx.util.Pair;
+import com.oracle.appbundlers.utils.Source;
+import com.oracle.appbundlers.utils.SourceFactory;
+import com.oracle.appbundlers.utils.Utils;
 
 /**
  *
@@ -29,9 +35,11 @@
  */
 public class SecondLauncherSameJreTest extends TestBase {
 
-    private static final String appName = "SQE-TEST-APP";
     private static final String secondAppName = "SQE-TEST-APP-FOOBAR";
 
+    private static final List<String> jvmOptions = Arrays.asList(
+            "-verbose:class");
+
     @Override
     protected BundlerUtils[] getBundlerUtils() {
         // Mac OS is not supported
@@ -43,11 +51,6 @@
     }
 
     @Override
-    public String getResultingAppName() {
-        return appName;
-    }
-
-    @Override
     protected BundlingManagers[] getBundlingManagers() {
         return new BundlingManagers[] { BundlingManagers.ANT,
                 BundlingManagers.JAVA_API };
@@ -55,9 +58,15 @@
 
     public VerifiedOptions getVerifiedOptions() {
         return () -> {
+            Map<String, String> appNamesToOutput = new HashMap<>();
+            appNamesToOutput.put(getResultingAppName(), PASS_1);
+            appNamesToOutput.put(secondAppName, PASS_2);
+
+            Map<String, Map<String, String>> entireAppOutput = new HashMap<String, Map<String, String>>();
+            entireAppOutput.put(SAME_JAVA_EXECUTABLE_OUTPUT, appNamesToOutput);
+
             Map<String, Object> verifiedOptions = new HashMap<>();
-            verifiedOptions.put(SAME_JAVA_EXECUTABLE,
-                    new Pair<>(appName, secondAppName));
+            verifiedOptions.put(SAME_JAVA_EXECUTABLE, entireAppOutput);
             return verifiedOptions;
         };
     }
@@ -65,25 +74,84 @@
     public AdditionalParams getAdditionalParams() {
         return () -> {
             Map<String, Object> additionalParams = new HashMap<>();
+            additionalParams.put(APP_NAME, getResultingAppName());
+            additionalParams.put(JVM_OPTIONS, jvmOptions);
+            String mainModuleWithAppClass = String.join("/",
+                    this.currentParameter.getApp().getMainModuleName(),
+                    this.currentParameter.getApp().getMainClass());
+            if (this.currentParameter.getApp().isAppContainsModules()) {
+                additionalParams.put(MAIN_MODULE, mainModuleWithAppClass);
+            } else {
+                additionalParams.put(APPLICATION_CLASS,
+                        this.currentParameter.getApp().getMainClass());
+            }
 
-            additionalParams.put(APP_NAME_REPLACEMENT_STATEMENT, appName);
+            Map<String, Object> secondLauncher = new HashMap<>();
+            secondLauncher.put(APP_NAME, secondAppName);
+            secondLauncher.put(JVM_OPTIONS, jvmOptions);
 
-            Map<String, Object> launcherParams = new HashMap<>();
-            launcherParams.put(APP_NAME_REPLACEMENT_STATEMENT, secondAppName);
-            launcherParams.put(APPLICATION_CLASS, APP2_FULLNAME);
+            if (this.currentParameter.getApp().isAppContainsModules()) {
+                secondLauncher.put(MAIN_MODULE,
+                        COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
+                secondLauncher.put(MAIN_MODULE,
+                        String.join("/", COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
+                                COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME));
+            } else {
+                secondLauncher.put(APPLICATION_CLASS,
+                        COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
+            }
+
             List<Map<String, Object>> launchers = new ArrayList<>();
-            launchers.add(launcherParams);
+            launchers.add(secondLauncher);
 
             additionalParams.put(SECONDARY_LAUNCHERS, launchers);
-
             return additionalParams;
         };
     }
 
     @Override
-    public void overrideParameters(ExtensionType intermediate)
+    public void overrideParameters(ExtensionType javaExtensionFormat)
             throws IOException {
+        this.currentParameter.setApp(getApp(javaExtensionFormat));
         this.currentParameter.setAdditionalParams(getAdditionalParams());
         this.currentParameter.setVerifiedOptions(getVerifiedOptions());
     }
+
+    private AppWrapper getApp(ExtensionType extension) throws IOException {
+        Map<String, String> replacementsInSourceCodeForApp2 = new HashMap<String, String>();
+        replacementsInSourceCodeForApp2.put(PASS_STRING_REPLACEMENT_STATEMENT,
+                PASS_2);
+        replacementsInSourceCodeForApp2.put(APP_NAME_REPLACEMENT_STATEMENT,
+                APP2_NAME);
+
+        switch (extension) {
+        default:
+            return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY),
+                    COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    SourceFactory.get_com_greetings_app_unnamed_module(),
+                    SourceFactory.get_com_greetings_app_unnamed_module(
+                            COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME,
+                            replacementsInSourceCodeForApp2));
+        case ExplodedModules:
+        case Jmods:
+        case ModularJar:
+            Map<String, Map<String, String>> classNameToReplacements = new LinkedHashMap<>();
+            classNameToReplacements.put(APP1_NAME, Collections.emptyMap());
+            classNameToReplacements.put(APP2_NAME, Collections.emptyMap());
+
+            Map<String, String> classNameToTemplateMap = new HashMap<>();
+            classNameToTemplateMap.put(COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    FXAPP_JAVA_TEMPLATE);
+            classNameToTemplateMap.put(COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME,
+                    FXAPP_JAVA_TEMPLATE);
+            Source get_com_greetings_module_source = SourceFactory
+                    .get_com_greetings_module(classNameToTemplateMap,
+                            COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                            classNameToReplacements);
+            get_com_greetings_module_source.setMainModule(true);
+            return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY),
+                    COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    get_com_greetings_module_source);
+        }
+    }
 }
--- a/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherWithJvmParametersTest.java	Wed Dec 07 11:54:42 2016 +0530
+++ b/functional/appBundlerTestsJDK9/appBundlerTestsJDK9/test/com/oracle/appbundlers/tests/functionality/SecondLauncherWithJvmParametersTest.java	Wed Dec 14 12:05:20 2016 +0530
@@ -9,22 +9,27 @@
 import static com.oracle.appbundlers.utils.BundlerUtils.WIN_APP;
 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.OUTPUT_CONTAINS;
 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS;
-import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.SECOND_LAUNCHER_OUTPUT_CONTAINS;
 import static java.util.stream.Collectors.toList;
 
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.LinkedHashMap;
 import java.util.List;
 import java.util.Map;
 
 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams;
 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
+import com.oracle.appbundlers.utils.AppWrapper;
 import com.oracle.appbundlers.utils.BundlerUtils;
 import com.oracle.appbundlers.utils.BundlingManagers;
 import com.oracle.appbundlers.utils.Constants;
 import com.oracle.appbundlers.utils.ExtensionType;
+import com.oracle.appbundlers.utils.Source;
+import com.oracle.appbundlers.utils.SourceFactory;
+import com.oracle.appbundlers.utils.Utils;
 
 import javafx.util.Pair;
 
@@ -68,36 +73,41 @@
 
     public AdditionalParams getAdditionalParams() {
         return () -> {
-            Map<String, Object> firstLauncherParams = new HashMap<>();
+            Map<String, Object> additionalParams = new HashMap<>();
 
-            firstLauncherParams.put(APP_NAME,
+            additionalParams.put(APP_NAME,
                     SecondLauncherWithJvmParametersTest.this.getResultingAppName());
             String mainModuleWithAppClass = String.join("/",
                     this.currentParameter.getApp().getMainModuleName(),
                     this.currentParameter.getApp().getMainClass());
-            if(this.currentParameter.getApp().isAppContainsModules()) {
-                firstLauncherParams.put(MAIN_MODULE, mainModuleWithAppClass);
+            if (this.currentParameter.getApp().isAppContainsModules()) {
+                additionalParams.put(MAIN_MODULE, mainModuleWithAppClass);
+            } else {
+                additionalParams.put(APPLICATION_CLASS,
+                        this.currentParameter.getApp().getMainClass());
             }
 
-            Map<String, Object> secondLauncher = new HashMap<>();
-            secondLauncher.put(APP_NAME,
+            Map<String, Object> secondLauncherParams = new HashMap<>();
+            secondLauncherParams.put(APP_NAME,
                     SecondLauncherWithJvmParametersTest.this.getSecondaryLauncherName());
             if (this.currentParameter.getApp().isAppContainsModules()) {
-                secondLauncher.put(MAIN_MODULE,
-                        Constants.COM_GREETINGS_MODULE_CUM_PACKAGE_NAME);
+                secondLauncherParams.put(MAIN_MODULE, String.join("/",
+                        Constants.COM_GREETINGS_MODULE_CUM_PACKAGE_NAME,
+                        Constants.COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME));
+            } else {
+                secondLauncherParams.put(APPLICATION_CLASS,
+                        Constants.COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
             }
-            secondLauncher.put(APPLICATION_CLASS,
-                    Constants.COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
-            secondLauncher.put(JVM_OPTIONS, jvmOptions);
-            secondLauncher.put(JVM_PROPERTIES, jvmProperties);
-            secondLauncher.put(USER_JVM_OPTIONS, userJvmOptions);
+            secondLauncherParams.put(JVM_OPTIONS, jvmOptions);
+            secondLauncherParams.put(JVM_PROPERTIES, jvmProperties);
+            secondLauncherParams.put(USER_JVM_OPTIONS, userJvmOptions);
 
             List<Map<String, Object>> secondarylaunchersList = new ArrayList<>();
-            secondarylaunchersList.add(secondLauncher);
+            secondarylaunchersList.add(secondLauncherParams);
 
-            firstLauncherParams.put(SECONDARY_LAUNCHERS, secondarylaunchersList);
+            additionalParams.put(SECONDARY_LAUNCHERS, secondarylaunchersList);
 
-            return firstLauncherParams;
+            return additionalParams;
         };
 
     }
@@ -106,8 +116,6 @@
         return () -> {
             Map<String, Object> verifiedOptions = new HashMap<>(
                     getAdditionalParams().getAdditionalParams());
-            verifiedOptions.put(SECOND_LAUNCHER_OUTPUT_CONTAINS,
-                    new Pair<>(getSecondaryLauncherName(), PASS_2));
             verifiedOptions.put(OUTPUT_CONTAINS, PASS_1);
 
             List<String> expectedJvmProps = jvmProperties.entrySet()
@@ -115,28 +123,74 @@
                             entry.getKey(), entry.getValue()))
                     .collect(toList());
 
-            verifiedOptions.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
-                    new Pair<>(getSecondaryLauncherName(), expectedJvmProps));
-            verifiedOptions.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
-                    new Pair<>(getSecondaryLauncherName(), jvmOptions));
             final List<String> usrJvmOpts = userJvmOptions.entrySet().stream()
                     .map(entry -> entry.getKey() + entry.getValue())
                     .collect(toList());
+
+            List<String> expectedSecondaryLauncherOutput = new ArrayList<String>();
+            expectedSecondaryLauncherOutput.addAll(expectedJvmProps);
+            expectedSecondaryLauncherOutput.addAll(jvmOptions);
+            expectedSecondaryLauncherOutput.addAll(usrJvmOpts);
+            expectedSecondaryLauncherOutput.add(PASS_2);
+
+
+            List<Pair<String, List<String>>> multipleExpectedOutputPair = new ArrayList<>();
+            multipleExpectedOutputPair.add(new Pair<>(getSecondaryLauncherName(),
+                    expectedSecondaryLauncherOutput));
             verifiedOptions.put(SECOND_LAUNCHER_MULTI_OUTPUT_CONTAINS,
-                    new Pair<>(getSecondaryLauncherName(), usrJvmOpts));
+                    multipleExpectedOutputPair);
 
             return verifiedOptions;
         };
     }
 
     @Override
-    public void overrideParameters(ExtensionType intermediate)
+    public void overrideParameters(ExtensionType javaExtensionFormat)
             throws IOException {
+        this.currentParameter.setApp(getApp(javaExtensionFormat));
         this.currentParameter.setAdditionalParams(getAdditionalParams());
         this.currentParameter.setVerifiedOptions(getVerifiedOptions());
     }
 
     private String getSecondaryLauncherName() {
-        return String.join("", getResultingAppName(), "SecondaryLauncher");
+        return String.join("_", getResultingAppName(), "SecondaryLauncher");
+    }
+
+    private AppWrapper getApp(ExtensionType extension) throws IOException {
+        Map<String, String> replacementsInSourceCodeForApp2 = new HashMap<String, String>();
+        replacementsInSourceCodeForApp2.put(PASS_STRING_REPLACEMENT_STATEMENT,
+                PASS_2);
+        replacementsInSourceCodeForApp2.put(APP_NAME_REPLACEMENT_STATEMENT,
+                APP2_NAME);
+
+        switch (extension) {
+        default:
+            return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY),
+                    COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    SourceFactory.get_com_greetings_app_unnamed_module(),
+                    SourceFactory.get_com_greetings_app_unnamed_module(
+                            COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME,
+                            replacementsInSourceCodeForApp2));
+        case ExplodedModules:
+        case Jmods:
+        case ModularJar:
+            Map<String, Map<String, String>> classNameToReplacements = new LinkedHashMap<>();
+            classNameToReplacements.put(APP1_NAME, Collections.emptyMap());
+            classNameToReplacements.put(APP2_NAME, Collections.emptyMap());
+
+            Map<String, String> classNameToTemplateMap = new HashMap<>();
+            classNameToTemplateMap.put(COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    FXAPP_JAVA_TEMPLATE);
+            classNameToTemplateMap.put(COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME,
+                    FXAPP_JAVA_TEMPLATE);
+            Source get_com_greetings_module_source = SourceFactory
+                    .get_com_greetings_module(classNameToTemplateMap,
+                            COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                            classNameToReplacements);
+            get_com_greetings_module_source.setMainModule(true);
+            return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY),
+                    COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
+                    get_com_greetings_module_source);
+        }
     }
 }