35 import org.junit.After; 36 import org.junit.Assume; 37 import org.junit.Before; 38 import org.junit.BeforeClass; 39 import org.junit.Test; 40 41 import java.io.File; 42 import java.io.IOException; 43 import java.util.ArrayList; 44 import java.util.Arrays; 45 import java.util.Collection; 46 import java.util.HashMap; 47 import java.util.HashSet; 48 import java.util.List; 49 import java.util.Map; 50 import java.util.Set; 51 import java.util.TreeMap; 52 53 import static com.oracle.tools.packager.StandardBundlerParam.*; 54 import static com.oracle.tools.packager.linux.LinuxAppBundler.ICON_PNG; 55 import static com.oracle.tools.packager.linux.LinuxRpmBundler.BUNDLE_NAME; 56 import static org.junit.Assert.*; 57 58 public class LinuxRpmBundlerTest { 59 60 static File tmpBase; 61 static File workDir; 62 static File appResourcesDir; 63 static File fakeMainJar; 64 static Set<File> appResources; 65 static boolean retain = false; 66 67 @BeforeClass 68 public static void prepareApp() { 69 // only run on linux 70 Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("linux")); 71 72 Assume.assumeTrue(LinuxRpmBundler.testTool(LinuxRpmBundler.TOOL_RPMBUILD, LinuxRpmBundler.TOOL_RPMBUILD_MIN_VERSION)); 73 74 Log.setLogger(new Log.Logger(true)); 75 Log.setDebug(true); 76 77 retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); 78 79 workDir = new File("build/tmp/tests", "linuxrpm"); 80 appResourcesDir = new File("build/tmp/tests", "appResources"); 81 fakeMainJar = new File(appResourcesDir, "mainApp.jar"); 82 83 appResources = new HashSet<>(Arrays.asList(fakeMainJar, 84 new File(appResourcesDir, "LICENSE"), 85 new File(appResourcesDir, "LICENSE2") 86 )); 87 } 88 89 @Before 90 public void createTmpDir() throws IOException { 91 if (retain) { 504 for (int i = 0; i < description.length; i++) { 505 Map<String, Object> fileAssociation = new HashMap<>(); 506 fileAssociation.put(FA_DESCRIPTION.getID(), description[i]); 507 fileAssociation.put(FA_EXTENSIONS.getID(), extensions[i]); 508 fileAssociation.put(FA_CONTENT_TYPE.getID(), contentType[i]); 509 fileAssociation.put(FA_ICON.getID(), icon[i]); 510 511 associations.add(fileAssociation); 512 } 513 514 bundleParams.put(FILE_ASSOCIATIONS.getID(), associations); 515 516 boolean valid = bundler.validate(bundleParams); 517 assertTrue(valid); 518 519 File result = bundler.execute(bundleParams, new File(workDir, APP_FS_NAME.fetchFrom(bundleParams))); 520 System.err.println("Bundle at - " + result); 521 assertNotNull(result); 522 assertTrue(result.exists()); 523 } 524 } | 35 import org.junit.After; 36 import org.junit.Assume; 37 import org.junit.Before; 38 import org.junit.BeforeClass; 39 import org.junit.Test; 40 41 import java.io.File; 42 import java.io.IOException; 43 import java.util.ArrayList; 44 import java.util.Arrays; 45 import java.util.Collection; 46 import java.util.HashMap; 47 import java.util.HashSet; 48 import java.util.List; 49 import java.util.Map; 50 import java.util.Set; 51 import java.util.TreeMap; 52 53 import static com.oracle.tools.packager.StandardBundlerParam.*; 54 import static com.oracle.tools.packager.linux.LinuxAppBundler.ICON_PNG; 55 import static com.oracle.tools.packager.linux.LinuxAppBundler.LINUX_RUNTIME; 56 import static com.oracle.tools.packager.linux.LinuxRpmBundler.BUNDLE_NAME; 57 import static org.junit.Assert.*; 58 59 public class LinuxRpmBundlerTest { 60 61 static File tmpBase; 62 static File workDir; 63 static File appResourcesDir; 64 static File fakeMainJar; 65 static String runtimeJdk; 66 static String runtimeJre; 67 static Set<File> appResources; 68 static boolean retain = false; 69 70 @BeforeClass 71 public static void prepareApp() { 72 // only run on linux 73 Assume.assumeTrue(System.getProperty("os.name").toLowerCase().startsWith("linux")); 74 75 runtimeJdk = System.getenv("PACKAGER_JDK_ROOT"); 76 runtimeJre = System.getenv("PACKAGER_JRE_ROOT"); 77 78 Assume.assumeTrue(LinuxRpmBundler.testTool(LinuxRpmBundler.TOOL_RPMBUILD, LinuxRpmBundler.TOOL_RPMBUILD_MIN_VERSION)); 79 80 Log.setLogger(new Log.Logger(true)); 81 Log.setDebug(true); 82 83 retain = Boolean.parseBoolean(System.getProperty("RETAIN_PACKAGER_TESTS")); 84 85 workDir = new File("build/tmp/tests", "linuxrpm"); 86 appResourcesDir = new File("build/tmp/tests", "appResources"); 87 fakeMainJar = new File(appResourcesDir, "mainApp.jar"); 88 89 appResources = new HashSet<>(Arrays.asList(fakeMainJar, 90 new File(appResourcesDir, "LICENSE"), 91 new File(appResourcesDir, "LICENSE2") 92 )); 93 } 94 95 @Before 96 public void createTmpDir() throws IOException { 97 if (retain) { 510 for (int i = 0; i < description.length; i++) { 511 Map<String, Object> fileAssociation = new HashMap<>(); 512 fileAssociation.put(FA_DESCRIPTION.getID(), description[i]); 513 fileAssociation.put(FA_EXTENSIONS.getID(), extensions[i]); 514 fileAssociation.put(FA_CONTENT_TYPE.getID(), contentType[i]); 515 fileAssociation.put(FA_ICON.getID(), icon[i]); 516 517 associations.add(fileAssociation); 518 } 519 520 bundleParams.put(FILE_ASSOCIATIONS.getID(), associations); 521 522 boolean valid = bundler.validate(bundleParams); 523 assertTrue(valid); 524 525 File result = bundler.execute(bundleParams, new File(workDir, APP_FS_NAME.fetchFrom(bundleParams))); 526 System.err.println("Bundle at - " + result); 527 assertNotNull(result); 528 assertTrue(result.exists()); 529 } 530 531 /** 532 * Turn on AppCDS 533 */ 534 @Test 535 public void testAppCDS() throws IOException, ConfigException, UnsupportedPlatformException { 536 Bundler bundler = new LinuxRpmBundler(); 537 538 Map<String, Object> bundleParams = new HashMap<>(); 539 540 // not part of the typical setup, for testing 541 bundleParams.put(BUILD_ROOT.getID(), tmpBase); 542 bundleParams.put(VERBOSE.getID(), true); 543 if (runtimeJdk != null) { 544 bundleParams.put(LINUX_RUNTIME.getID(), runtimeJdk); 545 } 546 547 bundleParams.put(APP_NAME.getID(), "AppCDS"); 548 bundleParams.put(IDENTIFIER.getID(), "com.example.appcds.rpm.Test"); 549 bundleParams.put(APP_RESOURCES.getID(), new RelativeFileSet(appResourcesDir, appResources)); 550 bundleParams.put(UNLOCK_COMMERCIAL_FEATURES.getID(), true); 551 bundleParams.put(ENABLE_APP_CDS.getID(), true); 552 553 boolean valid = bundler.validate(bundleParams); 554 assertTrue(valid); 555 556 File output = bundler.execute(bundleParams, new File(workDir, "CDSTest")); 557 System.err.println("Bundle at - " + output); 558 assertNotNull(output); 559 assertTrue(output.exists()); 560 } 561 562 } |