Debian Codegraph @

tests/reproducers/signed/ClasspathManifestTest/testcases/ClasspathManifestTest.java

raw
1 /* ClasspathManifestTest.java
2 Copyright (C) 2012 Red Hat, Inc.
3
4 This file is part of IcedTea.
5
6 IcedTea is free software; you can redistribute it and/or
7 modify it under the terms of the GNU General Public License as published by
8 the Free Software Foundation, version 2.
9
10 IcedTea is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with IcedTea; see the file COPYING. If not, write to
17 the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
18 02110-1301 USA.
19
20 Linking this library statically or dynamically with other modules is
21 making a combined work based on this library. Thus, the terms and
22 conditions of the GNU General Public License cover the whole
23 combination.
24
25 As a special exception, the copyright holders of this library give you
26 permission to link this library with independent modules to produce an
27 executable, regardless of the license terms of these independent
28 modules, and to copy and distribute the resulting executable under
29 terms of your choice, provided that you also meet, for each linked
30 independent module, the terms and conditions of the license of that
31 module. An independent module is a module which is not derived from
32 or based on this library. If you modify this library, you may extend
33 this exception to your version of the library, but you are not
34 obligated to do so. If you do not wish to do so, delete this
35 exception statement from your version.
36 */
37
38 import java.io.File;
39 import java.io.IOException;
40 import java.util.ArrayList;
41 import java.util.List;
42
43 import net.sourceforge.jnlp.ProcessResult;
44 import net.sourceforge.jnlp.ServerAccess;
45 import net.sourceforge.jnlp.annotations.NeedsDisplay;
46 import net.sourceforge.jnlp.annotations.TestInBrowsers;
47 import net.sourceforge.jnlp.browsertesting.BrowserTest;
48 import net.sourceforge.jnlp.browsertesting.Browsers;
49 import net.sourceforge.jnlp.browsertesting.browsers.firefox.FirefoxProfilesOperator;
50 import net.sourceforge.jnlp.util.FileUtils;
51 import org.junit.AfterClass;
52
53 import org.junit.Assert;
54 import org.junit.BeforeClass;
55 import org.junit.Test;
56
57 public class ClasspathManifestTest extends BrowserTest {
58
59 private static final String s1 = "Searching for CheckForClasspath.";
60 private static final String s2 = "CheckForClasspath found on classpath.";
61 private static final String ss = "xception";
62
63 private static final String n1 = "ClasspathManifestJNLPHrefTest.html";
64 private static final String n4 = "ClasspathManifestApplicationTest.jnlp";
65 private static final String n2 = "ClasspathManifestAppletTest.jnlp";
66 private static final String n3 = "ClasspathManifestAppletTest.html";
67 private static final String[] ns = new String[]{n1, n2, n3, n4};
68 private static final String n0 = "ClasspathManifestTest.jar";
69
70 private static File newRoot;
71 private static File newRoot1;
72
73 public void checkAppFails(ProcessResult pr, String testName) {
74 Assert.assertTrue("ClasspathManifest." + testName + " stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
75 Assert.assertFalse("ClasspathManifest." + testName + " stdout should not contain " + s2 + " but did", pr.stdout.contains(s2));
76 Assert.assertTrue("ClasspathManifest." + testName + " stderr should contain " + ss + " but didn't", pr.stderr.contains(ss));
77 }
78
79 public void checkAppPass(ProcessResult pr, String testName) {
80 Assert.assertTrue("ClasspathManifest." + testName + " stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
81 Assert.assertTrue("ClasspathManifest." + testName + " stdout should not contain " + s2 + " but did", pr.stdout.contains(s2));
82 Assert.assertFalse("ClasspathManifest." + testName + " stderr should contain " + ss + " but didn't", pr.stderr.contains(ss));
83 }
84
85 @AfterClass
86 public static void removeAlternativeLocalDirs() throws IOException {
87 FirefoxProfilesOperator.deleteRecursively(newRoot);
88 }
89
90 @BeforeClass
91 public static void createAlternativeLocalDirs() throws IOException {
92 newRoot = File.createTempFile("itw", "ClasspathManifestTest");
93 newRoot.delete();
94 newRoot.mkdirs();
95 newRoot.deleteOnExit();
96 newRoot1 = new File(newRoot, "r1");
97 newRoot1.mkdir();
98 FirefoxProfilesOperator.copyRecursively(new File(server.getDir(), "Classpath"), newRoot);
99
100 for (String n : ns) {
101 copyTextFile(new File(server.getDir(), n), new File(newRoot, n));
102 }
103 FirefoxProfilesOperator.copyFile(new File(server.getDir(), n0), new File(newRoot1, n0));
104 }
105
106 public static void copyTextFile(File from, File to) throws IOException {
107 String s = FileUtils.loadFileAsString(from);
108 // for (String n : ns) {
109 // s = s.replaceAll(n, newRoot1.getName()+"/" + n);
110 // }
111 s = s.replaceAll(n0, newRoot1.getName() + "/" + n0);
112 FileUtils.saveFile(s, to);
113 }
114
115 @NeedsDisplay
116 @Test
117 public void ApplicationJNLPRemoteTest() throws Exception {
118 ProcessResult pr = server.executeJavawsHeadless(null, "/" + n4);
119 checkAppFails(pr, "ApplicationJNLPRemoteTest");
120 }
121
122 /**
123 * See the difference between *LocalTest() and *LocalTest_differentDir().
124 *
125 * Itw always have "." on classpath. So
126 *
127 * ./jnlp or ./html (calling to jar.jar) + ./jar.jar +
128 * ./Codebase/../second.jar are all on classapth but ./jnlp or ./html
129 * (calling to someDir/jar.jar)+ ./someDir/jar.jar +
130 * ./Codebase/../second.jar Is making the jar.jar laodable for startup, but
131 * diapearing after encauntering Class-Path: in Manifest.mf
132 *
133 * @throws Exception
134 */
135 @NeedsDisplay
136 @Test
137 public void ApplicationJNLPLocalTest() throws Exception {
138 List<String> commands = new ArrayList<>(3);
139 commands.add(server.getJavawsLocation());
140 commands.add(ServerAccess.HEADLES_OPTION);
141 commands.add(n4);
142 ProcessResult pr = ServerAccess.executeProcess(commands, server.getDir());
143 checkAppPass(pr, "ApplicationJNLPLocalTest");
144 }
145
146 @NeedsDisplay
147 @Test
148 public void ApplicationJNLPLocalTest_differentDir() throws Exception {
149 List<String> commands = new ArrayList<>(3);
150 commands.add(server.getJavawsLocation());
151 commands.add(ServerAccess.HEADLES_OPTION);
152 commands.add(n4);
153 ProcessResult pr = ServerAccess.executeProcess(commands, newRoot);
154 checkAppFails(pr, "ApplicationJNLPLocalTest_differentDir");
155 }
156
157 @NeedsDisplay
158 @Test
159 public void AppletJNLPRemoteTest() throws Exception {
160 ProcessResult pr = server.executeJavawsHeadless(null, "/" + n2);
161 checkAppFails(pr, "AppletJNLPRemoteTest");
162 }
163
164 @NeedsDisplay
165 @Test
166 public void AppletJNLPRLocalTest() throws Exception {
167 List<String> commands = new ArrayList<>(3);
168 commands.add(server.getJavawsLocation());
169 commands.add(ServerAccess.HEADLES_OPTION);
170 commands.add(n2);
171 ProcessResult pr = ServerAccess.executeProcess(commands, server.getDir());
172 checkAppPass(pr, "AppletJNLPRLocalTest");
173 }
174
175 @NeedsDisplay
176 @Test
177 public void AppletJNLPRLocalTest_differentDir() throws Exception {
178 List<String> commands = new ArrayList<>(3);
179 commands.add(server.getJavawsLocation());
180 commands.add(ServerAccess.HEADLES_OPTION);
181 commands.add(n2);
182 ProcessResult pr = ServerAccess.executeProcess(commands, newRoot);
183 checkAppFails(pr, "AppletJNLPRLocalTest_differentDir");
184 }
185
186 @NeedsDisplay
187 @TestInBrowsers(testIn = {Browsers.one})
188 @Test
189 public void BrowserJNLPHrefRemoteTest() throws Exception {
190 ProcessResult pr = server.executeBrowser("/" + n1);
191 checkAppFails(pr, "BrowserJNLPHrefRemoteTest");
192 }
193
194 @NeedsDisplay
195 @TestInBrowsers(testIn = {Browsers.one})
196 @Test
197 public void BrowserJNLPHrefLocalTest() throws Exception {
198 List<String> commands = new ArrayList<>(2);
199 commands.add(server.getBrowserLocation());
200 commands.add(n1);
201 ProcessResult pr = ServerAccess.executeProcess(commands, server.getDir());
202 checkAppPass(pr, "BrowserJNLPHrefLocalTest");
203 }
204
205 @NeedsDisplay
206 @TestInBrowsers(testIn = {Browsers.one})
207 @Test
208 public void BrowserJNLPHrefLocalTest_differentDir() throws Exception {
209 List<String> commands = new ArrayList<>(2);
210 commands.add(server.getBrowserLocation());
211 commands.add(n1);
212 ProcessResult pr = ServerAccess.executeProcess(commands, newRoot);
213 checkAppFails(pr, "BrowserJNLPHrefLocalTest_differentDir");
214 }
215
216 @NeedsDisplay
217 @TestInBrowsers(testIn = {Browsers.one})
218 @Test
219 public void BrowserAppletRemoteTest() throws Exception {
220 ProcessResult pr = server.executeBrowser("/" + n3);
221 Assert.assertTrue("ClasspathManifest.BrowserAppletRemoteTest stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
222 // Should be the only one to search manifest for classpath.
223 Assert.assertTrue("ClasspathManifest.BrowserAppletRemoteTest stdout should contain " + s2 + " but didn't", pr.stdout.contains(s2));
224 }
225 }