1 /*
   2  * Copyright (c) 2016 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  */
   5 package com.oracle.appbundlers.tests.functionality.jdk9test;
   6 
   7 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.OUTPUT_CONTAINS;
   8 
   9 import java.io.IOException;
  10 import java.util.Collections;
  11 import java.util.HashMap;
  12 import java.util.LinkedHashMap;
  13 import java.util.Map;
  14 
  15 import com.oracle.appbundlers.tests.functionality.functionalinterface.BasicParams;
  16 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
  17 import com.oracle.appbundlers.tests.functionality.parameters.GenericModuleParameters;
  18 import com.oracle.appbundlers.utils.AppWrapper;
  19 import com.oracle.appbundlers.utils.ExtensionType;
  20 import com.oracle.appbundlers.utils.Source;
  21 import com.oracle.appbundlers.utils.SourceFactory;
  22 import com.oracle.appbundlers.utils.Utils;
  23 
  24 /**
  25  * @author Ramesh BG
  26  * Aim: To execute other class avaialable in module other than Main-Class of Manifest
  27  * 
  28  */
  29 public class OtherClassInMainModuleTest extends ModuleTestBase {
  30 
  31     protected BasicParams getBasicParams() {
  32         return (AppWrapper app) -> {
  33             Map<String, Object> params = new HashMap<>();
  34             params.put(MODULEPATH, ((GenericModuleParameters) this.currentParameter).getModulePath());
  35             params.put(APP_NAME, getResultingAppName());
  36             params.put(MAIN_MODULE,
  37                     app.getMainModuleName() + "/" + COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME);
  38             return params;
  39         };
  40     }
  41 
  42     @Override
  43     public void overrideParameters(ExtensionType intermediate)
  44             throws IOException {
  45         this.currentParameter.setApp(getApp());
  46         this.currentParameter.setBasicParams(getBasicParams());
  47         this.currentParameter.setVerifiedOptions(getVerifiedOptions());
  48     }
  49     
  50     private VerifiedOptions getVerifiedOptions() {
  51         return () -> {
  52             Map<String, Object> verifications = new HashMap<>();
  53             verifications.put(OUTPUT_CONTAINS, PASS_2);
  54             return verifications;
  55         };
  56     }
  57     
  58     private AppWrapper getApp() throws IOException {
  59         Map<String, Map<String, String>> classNameToReplacements = new LinkedHashMap<>();
  60         classNameToReplacements.put(APP1_NAME, Collections.emptyMap());
  61         classNameToReplacements.put(APP2_NAME, Collections.emptyMap());
  62 
  63         Map<String, String> classNameToTemplateMap = new HashMap<>();
  64         classNameToTemplateMap.put(COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
  65                 FXAPP_JAVA_TEMPLATE);
  66         classNameToTemplateMap.put(COM_GREETINGS_APP2_QUALIFIED_CLASS_NAME,
  67                 FXAPP_JAVA_TEMPLATE);
  68         Source get_com_greetings_module = SourceFactory.get_com_greetings_module(
  69                 classNameToTemplateMap,
  70                 COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
  71                 classNameToReplacements);
  72         get_com_greetings_module.setMainModule(true);
  73         return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY),
  74                 COM_GREETINGS_APP1_QUALIFIED_CLASS_NAME,
  75                 get_com_greetings_module);
  76     }
  77 }