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 package com.oracle.appbundlers.tests.functionality; 6 7 import static com.oracle.appbundlers.tests.functionality.IconTest.iconExtension; 8 import static com.oracle.appbundlers.utils.Config.CONFIG_INSTANCE; 9 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.ASSOCIATED_EXTENSIONS; 10 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.WIN_SYSTEM_WIDE_FILE_ASSOCIATIONS; 11 import static com.oracle.appbundlers.utils.installers.AbstractBundlerUtils.WIN_USER_FILE_ASSOCIATIONS; 12 13 import java.io.IOException; 14 import java.util.Arrays; 15 import java.util.HashMap; 16 import java.util.Map; 17 import java.util.concurrent.ExecutionException; 18 import java.util.concurrent.TimeUnit; 19 20 import com.oracle.appbundlers.tests.functionality.functionalinterface.AdditionalParams; 21 import com.oracle.appbundlers.tests.functionality.functionalinterface.VerifiedOptions; 22 import com.oracle.appbundlers.utils.AppWrapper; 23 import com.oracle.appbundlers.utils.BundlerUtils; 24 import com.oracle.appbundlers.utils.BundlingManagers; 25 import com.oracle.appbundlers.utils.ExtensionType; 26 import com.oracle.appbundlers.utils.Source; 27 import com.oracle.appbundlers.utils.Utils; 28 29 import javafx.util.Pair; 30 31 /** 32 * @author Dmitry Ginzburg <dmitry.x.ginzburg@oracle.com> 33 */ 34 35 public class FileAssociationTest extends TestBase { 36 public static final String RM_FULLNAME = "testapp.RmApp"; 37 public static final String RM_NAME = "RmApp"; 38 public static final String ext1 = "foo", ext2 = "bar", ext3 = "baz", 39 ext4 = "qux"; 40 41 @Override 42 protected BundlerUtils[] getBundlerUtils() { 43 return new BundlerUtils[] { BundlerUtils.MAC_APP, BundlerUtils.PKG, 44 BundlerUtils.DMG, 45 46 BundlerUtils.EXE, BundlerUtils.MSI, BundlerUtils.DEB, 47 BundlerUtils.RPM }; 48 } 49 50 @Override 51 protected BundlingManagers[] getBundlingManagers() { 52 return new BundlingManagers[] { BundlingManagers.JAVA_API, 53 BundlingManagers.ANT }; 54 } 55 56 protected AdditionalParams getAdditionalParams() { 57 return () -> { 58 Map<String, Object> additionalParams = new HashMap<>(); 59 Map<String, Object> association1 = new HashMap<>(); 60 association1.put(FA_EXTENSIONS, Arrays.asList(ext1, ext2)); 61 association1.put(FA_CONTENT_TYPE, 62 Arrays.asList("application/example")); 63 association1.put(FA_DESCRIPTION, "The sample description"); 64 Map<String, Object> association2 = new HashMap<>(); 65 association2.put(FA_EXTENSIONS, Arrays.asList(ext3, ext4)); 66 association2.put(FA_CONTENT_TYPE, Arrays.asList("hello/world")); 67 association2.put(FA_ICON, CONFIG_INSTANCE 68 .getResourceFilePath("icon2." + iconExtension()).toFile()); 69 additionalParams.put(FILE_ASSOCIATIONS, 70 Arrays.asList(association1, association2)); 71 additionalParams.put(SYSTEM_WIDE, true); 72 return additionalParams; 73 }; 74 } 75 76 protected VerifiedOptions getVerifiedOptions() { 77 return () -> { 78 Map<String, Object> verifiedOptions = new HashMap<>( 79 getAdditionalParams().getAdditionalParams()); 80 verifiedOptions.put(ASSOCIATED_EXTENSIONS, 81 Arrays.asList(ext1, ext2, ext3, ext4)); 82 verifiedOptions.put(WIN_SYSTEM_WIDE_FILE_ASSOCIATIONS, 83 getAdditionalParams().getAdditionalParams() 84 .get(FILE_ASSOCIATIONS)); 85 verifiedOptions.remove(WIN_USER_FILE_ASSOCIATIONS); 86 return verifiedOptions; 87 }; 88 } 89 90 public AppWrapper getApp() throws IOException { 91 String templateName = Utils.isMacOS() ? "MacRmApp.java.template" 92 : "RmApp.java.template"; 93 return new AppWrapper(Utils.getTempSubDir(WORK_DIRECTORY), RM_FULLNAME, 94 new Source(RM_FULLNAME, templateName, "rmApp", 95 new HashMap<String, String>() { 96 /** 97 * serial version UID 98 */ 99 private static final long serialVersionUID = -559615341303319079L; 100 101 { 102 put(APP_NAME_REPLACEMENT_STATEMENT, RM_NAME); 103 } 104 })); 105 } 106 107 @Override 108 public String getResultingAppName() { 109 return RM_NAME; 110 } 111 112 @Override 113 protected Pair<TimeUnit, Integer> getDelayAfterInstall() { 114 return new Pair<>(TimeUnit.MILLISECONDS, 115 CONFIG_INSTANCE.getAfterInstallationPause()); 116 } 117 118 @Override 119 protected void prepareApp(AppWrapper app, ExtensionType extension) throws IOException, ExecutionException { 120 final String makeJavacReadClassesFromRtJar = "-XDignore.symbol.file=true"; 121 app.preinstallApp(extension); 122 app.writeSourcesToAppDirectory(); 123 app.compileApp(new String[] { makeJavacReadClassesFromRtJar }); 124 app.jarApp(extension); 125 } 126 127 @Override 128 public void overrideParameters(ExtensionType intermediate) 129 throws IOException { 130 this.currentParameter.setAdditionalParams(getAdditionalParams()); 131 this.currentParameter.setVerifiedOptions(getVerifiedOptions()); 132 this.currentParameter.setApp(getApp()); 133 } 134 }