53 54 test = new PackageTest() 55 .forTypes(type) 56 .configureHelloApp() 57 .addInitializer(cmd -> { 58 cmd.setFakeRuntime().saveConsoleOutput(true); 59 }); 60 } 61 62 @Parameters 63 public static List<Object[]> data() { 64 return List.of(new Object[][]{ 65 {PackageType.WIN_MSI}, 66 {PackageType.WIN_EXE} 67 }); 68 } 69 70 @Test 71 @Parameter("0") 72 @Parameter("10") 73 public void test(int wsfExitCode) { 74 final ScriptData appImageScriptData; 75 if (wsfExitCode != 0 && packageType == PackageType.WIN_EXE) { 76 appImageScriptData = new ScriptData(PackageType.WIN_MSI, 0); 77 } else { 78 appImageScriptData = new ScriptData(PackageType.WIN_MSI, wsfExitCode); 79 } 80 81 final ScriptData msiScriptData = new ScriptData(PackageType.WIN_EXE, wsfExitCode); 82 83 test.setExpectedExitCode(wsfExitCode == 0 ? 0 : 1); 84 TKit.withTempDirectory("resources", tempDir -> { 85 test.addInitializer(cmd -> { 86 cmd.addArguments("--resource-dir", tempDir); 87 88 appImageScriptData.createScript(cmd); 89 msiScriptData.createScript(cmd); 90 }); 91 92 if (packageType == PackageType.WIN_MSI) { 93 test.addBundleVerifier((cmd, result) -> { 94 appImageScriptData.assertJPackageOutput(result.getOutput()); 95 }); 96 } 97 98 if (packageType == PackageType.WIN_EXE) { 99 test.addBundleVerifier((cmd, result) -> { 100 appImageScriptData.assertJPackageOutput(result.getOutput()); 101 msiScriptData.assertJPackageOutput(result.getOutput()); 102 }); 103 } 104 105 test.run(); 106 }); 107 } 108 109 private static class ScriptData { 110 ScriptData(PackageType scriptType, int wsfExitCode) { 111 if (scriptType == PackageType.WIN_MSI) { 112 echoText = "post app image wsf"; 113 envVarName = "JpAppImageDir"; 114 scriptSuffixName = "post-image"; 115 } else { 116 echoText = "post msi wsf"; 117 envVarName = "JpMsiFile"; 118 scriptSuffixName = "post-msi"; 119 } 120 this.wsfExitCode = wsfExitCode; 121 } 122 123 void assertJPackageOutput(List<String> output) { 124 TKit.assertTextStream(String.format("jp: %s", echoText)) 125 .predicate(String::equals) 126 .apply(output.stream()); | 53 54 test = new PackageTest() 55 .forTypes(type) 56 .configureHelloApp() 57 .addInitializer(cmd -> { 58 cmd.setFakeRuntime().saveConsoleOutput(true); 59 }); 60 } 61 62 @Parameters 63 public static List<Object[]> data() { 64 return List.of(new Object[][]{ 65 {PackageType.WIN_MSI}, 66 {PackageType.WIN_EXE} 67 }); 68 } 69 70 @Test 71 @Parameter("0") 72 @Parameter("10") 73 public void test(int wsfExitCode) throws IOException { 74 final ScriptData appImageScriptData; 75 if (wsfExitCode != 0 && packageType == PackageType.WIN_EXE) { 76 appImageScriptData = new ScriptData(PackageType.WIN_MSI, 0); 77 } else { 78 appImageScriptData = new ScriptData(PackageType.WIN_MSI, wsfExitCode); 79 } 80 81 final ScriptData msiScriptData = new ScriptData(PackageType.WIN_EXE, wsfExitCode); 82 83 test.setExpectedExitCode(wsfExitCode == 0 ? 0 : 1); 84 85 final Path tempDir = TKit.createTempDirectory("resources"); 86 87 test.addInitializer(cmd -> { 88 cmd.addArguments("--resource-dir", tempDir); 89 90 appImageScriptData.createScript(cmd); 91 msiScriptData.createScript(cmd); 92 }); 93 94 switch (packageType) { 95 case WIN_MSI: 96 test.addBundleVerifier((cmd, result) -> { 97 appImageScriptData.assertJPackageOutput(result.getOutput()); 98 }); 99 break; 100 101 case WIN_EXE: 102 test.addBundleVerifier((cmd, result) -> { 103 appImageScriptData.assertJPackageOutput(result.getOutput()); 104 msiScriptData.assertJPackageOutput(result.getOutput()); 105 }); 106 break; 107 } 108 109 test.run(); 110 } 111 112 private static class ScriptData { 113 ScriptData(PackageType scriptType, int wsfExitCode) { 114 if (scriptType == PackageType.WIN_MSI) { 115 echoText = "post app image wsf"; 116 envVarName = "JpAppImageDir"; 117 scriptSuffixName = "post-image"; 118 } else { 119 echoText = "post msi wsf"; 120 envVarName = "JpMsiFile"; 121 scriptSuffixName = "post-msi"; 122 } 123 this.wsfExitCode = wsfExitCode; 124 } 125 126 void assertJPackageOutput(List<String> output) { 127 TKit.assertTextStream(String.format("jp: %s", echoText)) 128 .predicate(String::equals) 129 .apply(output.stream()); |