1 /*
   2  * Copyright (c) 2014, 2016 Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  */
   5 
   6 package com.oracle.appbundlers.tests.functionality;
   7 
   8 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.OUTPUT_CONTAINS;
   9 import static java.util.stream.Collectors.toSet;
  10 
  11 import java.io.IOException;
  12 import java.nio.file.Path;
  13 import java.util.Collections;
  14 import java.util.HashMap;
  15 import java.util.Map;
  16 import java.util.concurrent.ExecutionException;
  17 
  18 import com.oracle.appbundlers.tests.functionality.functionalinterface.BasicParams;
  19 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions;
  20 import com.oracle.appbundlers.utils.AppWrapper;
  21 import com.oracle.appbundlers.utils.BundlerUtils;
  22 import com.oracle.appbundlers.utils.BundlingManagers;
  23 import com.oracle.appbundlers.utils.ExtensionType;
  24 import com.oracle.tools.packager.RelativeFileSet;
  25 import com.oracle.tools.packager.StandardBundlerParam;
  26 
  27 /**
  28  * @author Dmitry Ginzburg <dmitry.x.ginzburg@oracle.com>
  29  */
  30 
  31 /**
  32  * This test's purpose is to check whether:
  33  * <ul>
  34  * <li>the main jar is extracted correctly without manually specifying it</li>
  35  * <li>the default classpath is extracted correctly from the main jar without
  36  * manually specifying it</li>
  37  * </ul>
  38  * So, the only passed parameter is essential {@code appResources}
  39  */
  40 public class DefaultClassPathTest extends TestBase {
  41 
  42     public VerifiedOptions getVerifiedOptions() {
  43         return () -> {
  44             Map<String, Object> verifiedOptions = new HashMap<>();
  45             verifiedOptions.put(OUTPUT_CONTAINS, PASS_1);
  46             return verifiedOptions;
  47         };
  48     }
  49 
  50     @Override
  51     protected void prepareApp(AppWrapper app, ExtensionType extension)
  52             throws IOException, ExecutionException {
  53         app.preinstallApp(extension);
  54         app.writeSourcesToAppDirectory();
  55         app.compileApp();
  56         app.jarApp(Collections.emptyList(), true);
  57     }
  58 
  59     @Override
  60     protected BundlingManagers[] getBundlingManagers() {
  61         return new BundlingManagers[] { BundlingManagers.CLI };
  62     }
  63 
  64     @Override
  65     protected BundlerUtils[] getBundlerUtils() {
  66         return new BundlerUtils[] { BundlerUtils.EXE };
  67     }
  68 
  69     @Override
  70     public void overrideParameters(ExtensionType intermediate)
  71             throws IOException {
  72         this.currentParameter.setVerifiedOptions(getVerifiedOptions());
  73         this.currentParameter.setBasicParams(getBasicParams());
  74     }
  75 
  76     protected BasicParams getBasicParams() {
  77         return (AppWrapper app) -> {
  78             Map<String, Object> basicParams = new HashMap<>();
  79             basicParams
  80                     .put(APP_RESOURCES,
  81                             new RelativeFileSet(app.getJarDir().toFile(),
  82                                     app.getJarFilesList().stream()
  83                                             .map(Path::toFile)
  84                                             .collect(toSet())));
  85             String mainClass = StandardBundlerParam.MAIN_CLASS
  86                     .fetchFrom(basicParams);
  87             basicParams.put(APPLICATION_CLASS, mainClass);
  88             return basicParams;
  89         };
  90     }
  91 
  92     @Override
  93     public boolean isTestCaseApplicableForExtensionType(
  94             ExtensionType extension) {
  95         return ExtensionType.NormalJar == extension;
  96     }
  97 }