| 1 |
|
| 2 |
|
| 3 |
|
| 4 |
|
| 5 |
|
| 6 |
|
| 7 |
|
| 8 |
|
| 9 |
|
| 10 |
|
| 11 |
|
| 12 |
|
| 13 |
|
| 14 |
|
| 15 |
|
| 16 |
|
| 17 |
|
| 18 |
|
| 19 |
|
| 20 |
|
| 21 |
|
| 22 |
|
| 23 |
|
| 24 |
|
| 25 |
|
| 26 |
|
| 27 |
|
| 28 |
|
| 29 |
|
| 30 |
|
| 31 |
|
| 32 |
|
| 33 |
|
| 34 |
|
| 35 |
|
| 36 |
|
| 37 |
|
| 38 |
import java.io.File; |
| 39 |
import java.io.IOException; |
| 40 |
import java.util.AbstractMap; |
| 41 |
import java.util.Arrays; |
| 42 |
import net.sourceforge.jnlp.OptionsDefinitions; |
| 43 |
import net.sourceforge.jnlp.browsertesting.BrowserTest; |
| 44 |
|
| 45 |
import net.sourceforge.jnlp.ProcessResult; |
| 46 |
import net.sourceforge.jnlp.ProcessWrapper; |
| 47 |
import net.sourceforge.jnlp.ServerAccess; |
| 48 |
import net.sourceforge.jnlp.annotations.Bug; |
| 49 |
import net.sourceforge.jnlp.annotations.KnownToFail; |
| 50 |
import net.sourceforge.jnlp.closinglisteners.StringBasedClosingListener; |
| 51 |
import net.sourceforge.jnlp.config.DeploymentConfiguration; |
| 52 |
import net.sourceforge.jnlp.runtime.ManifestAttributesChecker; |
| 53 |
import net.sourceforge.jnlp.security.appletextendedsecurity.AppletSecurityLevel; |
| 54 |
import net.sourceforge.jnlp.tools.DeploymentPropertiesModifier; |
| 55 |
import net.sourceforge.jnlp.util.FileUtils; |
| 56 |
|
| 57 |
import org.junit.Assert; |
| 58 |
import org.junit.BeforeClass; |
| 59 |
|
| 60 |
import org.junit.Test; |
| 61 |
|
| 62 |
@Bug(id = {"PR3350"}) |
| 63 |
|
| 64 |
|
| 65 |
|
| 66 |
|
| 67 |
public class KemtrakTests extends BrowserTest { |
| 68 |
|
| 69 |
private static final ServerAccess SERVER = new ServerAccess(); |
| 70 |
private static final String JNLP_APPLET_ORIG = "Kemtrak.jnlp"; |
| 71 |
private static final String JNLP_APP_ORIG = "Kemtrak_javaws.jnlp"; |
| 72 |
|
| 73 |
private static final String JNLP_APPLET_CODEBASED = "Kemtrak_cb.jnlp"; |
| 74 |
private static final String JNLP_APP_CODEBASED = "Kemtrak_javaws_cb.jnlp"; |
| 75 |
|
| 76 |
@BeforeClass |
| 77 |
public static void prepareCodebasedFiles() throws IOException { |
| 78 |
|
| 79 |
|
| 80 |
|
| 81 |
|
| 82 |
File dir = SERVER.getDir(); |
| 83 |
File jnlp1 = new File(dir, JNLP_APPLET_ORIG); |
| 84 |
File jnlp2 = new File(dir, JNLP_APP_ORIG); |
| 85 |
|
| 86 |
File jnlp12 = new File(dir, JNLP_APPLET_CODEBASED); |
| 87 |
File jnlp22 = new File(dir, JNLP_APP_CODEBASED); |
| 88 |
String file1 = FileUtils.loadFileAsString(jnlp1); |
| 89 |
String file2 = FileUtils.loadFileAsString(jnlp2); |
| 90 |
file1=addCodebase(file1); |
| 91 |
file2=addCodebase(file2); |
| 92 |
file1 = file1.replaceAll(JNLP_APPLET_ORIG, JNLP_APPLET_CODEBASED); |
| 93 |
file2 = file2.replaceAll(JNLP_APP_ORIG, JNLP_APP_CODEBASED); |
| 94 |
FileUtils.saveFile(file1, jnlp12); |
| 95 |
FileUtils.saveFile(file2, jnlp22); |
| 96 |
} |
| 97 |
|
| 98 |
private static String addCodebase(String s){ |
| 99 |
return s.replaceFirst("version=\"1.302.1.29\"", "version=\"1.302.1.29\" codebase=\".\""); |
| 100 |
} |
| 101 |
|
| 102 |
@Bug(id = "PR3350") |
| 103 |
@Test |
| 104 |
public void KemtrakTest1() throws Exception { |
| 105 |
DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier dm |
| 106 |
= new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier( |
| 107 |
new AbstractMap.SimpleEntry<>( |
| 108 |
DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, |
| 109 |
ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL.name()), |
| 110 |
new AbstractMap.SimpleEntry<>( |
| 111 |
DeploymentConfiguration.KEY_SECURITY_LEVEL, |
| 112 |
AppletSecurityLevel.ASK_UNSIGNED.name())); |
| 113 |
try { |
| 114 |
dm.setProperties(); |
| 115 |
ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ServerAccess.HEADLES_OPTION}), SERVER.getUrl(JNLP_APPLET_ORIG)); |
| 116 |
pw.setWriter("YES\nYES\n"); |
| 117 |
pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished")); |
| 118 |
ProcessResult pr = pw.execute(); |
| 119 |
Assert.assertTrue("Stdout should contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1")); |
| 120 |
Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2")); |
| 121 |
Assert.assertTrue("Stdout should contain jcalendar1 but did not", pr.stdout.contains("jcalendar1")); |
| 122 |
} finally { |
| 123 |
dm.restoreProperties(); |
| 124 |
} |
| 125 |
} |
| 126 |
|
| 127 |
@Bug(id = "PR3351") |
| 128 |
@KnownToFail |
| 129 |
@Test |
| 130 |
public void KemtrakTest2() throws Exception { |
| 131 |
ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ |
| 132 |
ServerAccess.HEADLES_OPTION, OptionsDefinitions.OPTIONS.PARAM.option, "closeJar=closeJar", OptionsDefinitions.OPTIONS.JNLP.option}), SERVER.getUrl(JNLP_APPLET_CODEBASED)); |
| 133 |
pw.setWriter("YES\nYES\n"); |
| 134 |
pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished")); |
| 135 |
ProcessResult pr = pw.execute(); |
| 136 |
Assert.assertTrue("Stdout should contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1")); |
| 137 |
Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2")); |
| 138 |
Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2")); |
| 139 |
} |
| 140 |
|
| 141 |
@Test |
| 142 |
public void KemtrakTest_javaws1() throws Exception { |
| 143 |
DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier dm |
| 144 |
= new DeploymentPropertiesModifier.MultipleDeploymentPropertiesModifier( |
| 145 |
new AbstractMap.SimpleEntry<>( |
| 146 |
DeploymentConfiguration.KEY_ENABLE_MANIFEST_ATTRIBUTES_CHECK, |
| 147 |
ManifestAttributesChecker.MANIFEST_ATTRIBUTES_CHECK.ALL.name()), |
| 148 |
new AbstractMap.SimpleEntry<>( |
| 149 |
DeploymentConfiguration.KEY_SECURITY_LEVEL, |
| 150 |
AppletSecurityLevel.ASK_UNSIGNED.name())); |
| 151 |
try { |
| 152 |
dm.setProperties(); |
| 153 |
ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ServerAccess.HEADLES_OPTION}), SERVER.getUrl(JNLP_APP_ORIG)); |
| 154 |
pw.setWriter("YES\nYES\n"); |
| 155 |
pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished")); |
| 156 |
ProcessResult pr = pw.execute(); |
| 157 |
Assert.assertFalse("Stdout must nor contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1")); |
| 158 |
Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2")); |
| 159 |
Assert.assertTrue("Stdout should contain jcalendar1 but did not", pr.stdout.contains("jcalendar1")); |
| 160 |
} finally { |
| 161 |
dm.restoreProperties(); |
| 162 |
} |
| 163 |
} |
| 164 |
|
| 165 |
@Bug(id = "PR3351") |
| 166 |
@KnownToFail |
| 167 |
@Test |
| 168 |
public void KemtrakTest_javaws2() throws Exception { |
| 169 |
ProcessWrapper pw = new ProcessWrapper(SERVER.getJavawsLocation(), Arrays.asList(new String[]{ |
| 170 |
ServerAccess.HEADLES_OPTION, OptionsDefinitions.OPTIONS.ARG.option, "closeJar", SERVER.getUrl().toExternalForm()+"/", OptionsDefinitions.OPTIONS.JNLP.option}), SERVER.getUrl(JNLP_APP_CODEBASED)); |
| 171 |
pw.setWriter("YES\nYES\n"); |
| 172 |
pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished")); |
| 173 |
ProcessResult pr = pw.execute(); |
| 174 |
Assert.assertFalse("Stdout must not contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1")); |
| 175 |
Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2")); |
| 176 |
Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2")); |
| 177 |
} |
| 178 |
|
| 179 |
|
| 180 |
@Test |
| 181 |
|
| 182 |
|
| 183 |
|
| 184 |
public void KemtrakTest_java() throws Exception { |
| 185 |
ProcessWrapper pw = new ProcessWrapper(System.getProperty("java.home")+"/bin/java", Arrays.asList(new String[]{ |
| 186 |
"-cp", |
| 187 |
new File(SERVER.getDir(), "jcalendar.jar").getAbsolutePath()+File.pathSeparator+new File(SERVER.getDir(), "Kemtrakpro.jar").getAbsolutePath(), |
| 188 |
"Kemtrak", |
| 189 |
"closeJar", |
| 190 |
}), SERVER.getDir().toURI().toURL().toExternalForm()+"/"); |
| 191 |
pw.setWriter("YES\nYES\n"); |
| 192 |
pw.addStdOutListener(new StringBasedClosingListener("kemtrak finished")); |
| 193 |
ProcessResult pr = pw.execute(); |
| 194 |
Assert.assertFalse("Stdout must not contain Kemtrak1 but did not", pr.stdout.contains("Kemtrak1")); |
| 195 |
Assert.assertTrue("Stdout should contain Kemtrak2 but did not", pr.stdout.contains("Kemtrak2")); |
| 196 |
Assert.assertTrue("Stdout should contain jcalendar2 but did not", pr.stdout.contains("jcalendar2")); |
| 197 |
} |
| 198 |
|
| 199 |
} |