1 /* SimpleTest1Test.java
2 Copyright (C) 2011 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.FileInputStream;
40 import java.io.IOException;
41 import java.net.MalformedURLException;
42 import java.net.URL;
43 import java.util.Arrays;
44 import java.util.Collections;
45 import java.util.List;
46 import net.sourceforge.jnlp.ProcessResult;
47 import net.sourceforge.jnlp.ServerAccess;
48 import net.sourceforge.jnlp.ServerLauncher;
49 import net.sourceforge.jnlp.annotations.Bug;
50 import net.sourceforge.jnlp.annotations.TestInBrowsers;
51 import net.sourceforge.jnlp.browsertesting.BrowserTest;
52 import net.sourceforge.jnlp.browsertesting.Browsers;
53 import org.junit.Assert;
54 
55 import org.junit.Test;
56 
57 public class ParametrizedJarUrlTests extends BrowserTest{
58 
59     private final List<String> l = Collections.unmodifiableList(Arrays.asList(new String[]{"-Xtrustall"}));
60 
61     @Test
62     @TestInBrowsers(testIn = Browsers.one)
63     @Bug(id = "PR905")
parametrizedAppletTestSignedBrowserTest_hardcodedDifferentCodeBase()64     public void parametrizedAppletTestSignedBrowserTest_hardcodedDifferentCodeBase() throws Exception {
65         ServerLauncher server2 = ServerAccess.getIndependentInstance();
66         String originalResourceName = "ParametrizedJarUrlSigned.html";
67         String newResourceName = "ParametrizedJarUrlSigned_COPY2.html";
68         createCodeBase(originalResourceName, newResourceName, server2.getUrl(""));
69         //set codebase to second server
70         ProcessResult pr = server.executeBrowser(newResourceName);
71         server2.stop();
72         evaluateSignedApplet(pr);
73     }
74 
75     @Test
76     @TestInBrowsers(testIn = Browsers.one)
77     @Bug(id = "PR905")
parametrizedAppletTestSignedBrowserTest_hardcodedCodeBase()78     public void parametrizedAppletTestSignedBrowserTest_hardcodedCodeBase() throws Exception {
79         String originalResourceName = "ParametrizedJarUrlSigned.html";
80         String newResourceName = "ParametrizedJarUrlSigned_COPY1.html";
81         createCodeBase(originalResourceName, newResourceName, server.getUrl(""));
82         ProcessResult pr = server.executeBrowser(newResourceName);
83         evaluateSignedApplet(pr);
84     }
85 
createCodeBase(String originalResourceName, String newResourceName, URL codebase)86     private void createCodeBase(String originalResourceName, String newResourceName, URL codebase) throws MalformedURLException, IOException {
87         String originalContent = ServerAccess.getContentOfStream(new FileInputStream(new File(server.getDir(), originalResourceName)));
88         String nwContent = originalContent.replaceAll("codebase=\".\"", "codebase=\"" + codebase + "\"");
89         ServerAccess.saveFile(nwContent, new File(server.getDir(), newResourceName));
90     }
91 
92     @Test
93     @TestInBrowsers(testIn = Browsers.one)
94     @Bug(id = "PR905")
parametrizedAppletTestSignedBrowserTest()95     public void parametrizedAppletTestSignedBrowserTest() throws Exception {
96         ProcessResult pr = server.executeBrowser("/ParametrizedJarUrlSigned.html");
97         evaluateSignedApplet(pr);
98     }
99 
100     @Test
101     @TestInBrowsers(testIn=Browsers.one)
parametrizedAppletInBrowserWithParamTest()102     public void parametrizedAppletInBrowserWithParamTest() throws Exception {
103         ProcessResult pr = server.executeBrowser("/ParametrizedJarUrl.html?giveMeMore?orNot");
104         evaluateApplet(pr);
105     }
106 
107     @Test
parametrizedAppletJavawsTest()108     public void parametrizedAppletJavawsTest() throws Exception {
109         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarAppletUrl2.jnlp");
110         evaluateApplet(pr);
111     }
112 
113     @Test
parametrizedAppletJavawsTest2()114     public void parametrizedAppletJavawsTest2() throws Exception {
115         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarAppletUrl2.jnlp?test=123456");
116         evaluateApplet(pr);
117     }
118 
119     @Test
parametrizedAppletJavawsTest3()120     public void parametrizedAppletJavawsTest3() throws Exception {
121         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarAppletUrl.jnlp");
122         evaluateApplet(pr);
123     }
124 
125     @Test
parametrizedAppletJavawsTestSignedTest()126     public void parametrizedAppletJavawsTestSignedTest() throws Exception {
127         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarAppletUrlSigned2.jnlp");
128         evaluateSignedApplet(pr);
129     }
130 
131     @Test
parametrizedAppletJavawsTestSigned2Test()132     public void parametrizedAppletJavawsTestSigned2Test() throws Exception {
133         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarAppletUrlSigned2.jnlp?test=123456");
134         evaluateSignedApplet(pr);
135     }
136 
137     @Test
parametrizedAppletJavawsTestSignedTest4()138     public void parametrizedAppletJavawsTestSignedTest4() throws Exception {
139         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarAppletUrlSigned.jnlp");
140         evaluateSignedApplet(pr);
141     }
142 
evaluateSignedApplet(ProcessResult pr)143     private void evaluateSignedApplet(ProcessResult pr) {
144         String s3 = "AppletTestSigned was initialised";
145         Assert.assertTrue("AppletTestSigned stdout should contain " + s3 + " but didn't", pr.stdout.contains(s3));
146         String s0 = "AppletTestSigned was started";
147         Assert.assertTrue("AppletTestSigned stdout should contain " + s0 + " but didn't", pr.stdout.contains(s0));
148         String s1 = "value1";
149         Assert.assertTrue("AppletTestSigned stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
150         String s2 = "value2";
151         Assert.assertTrue("AppletTestSigned stdout should contain " + s2 + " but didn't", pr.stdout.contains(s2));
152         String s7 = "AppletTestSigned killing himself after 2000 ms of life";
153         Assert.assertTrue("AppletTestSigned stdout should contain " + s7 + " but didn't", pr.stdout.contains(s7));
154     }
155 
156 
157     @Test
testParametrizedJarUrlSigned1()158     public void testParametrizedJarUrlSigned1() throws Exception {
159         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarUrlSigned1.jnlp");
160         String s = "Good simple javaws exapmle";
161         Assert.assertTrue("ParametrizedJarUrlSigned1 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
162     }
163 
164     @Test
testParametrizedJarUrlSigned2()165     public void testParametrizedJarUrlSigned2() throws Exception {
166         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarUrlSigned2.jnlp");
167         String s = "Good simple javaws exapmle";
168         Assert.assertTrue("ParametrizedJarUrlSigned2 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
169     }
170 
171     @Test
testParametrizedJarUrlSigned3()172     public void testParametrizedJarUrlSigned3() throws Exception {
173         ProcessResult pr = server.executeJavawsHeadless(l, "/ParametrizedJarUrlSigned2.jnlp?test=123456");
174         String s = "Good simple javaws exapmle";
175         Assert.assertTrue("ParametrizedJarUrlSigned2 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
176     }
177 
178     @Test
testParametrizedJarUrl1()179     public void testParametrizedJarUrl1() throws Exception {
180         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarUrl1.jnlp");
181         String s = "Good simple javaws exapmle";
182         Assert.assertTrue("ParametrizedJarUrl1 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
183     }
184 
185     @Test
testParametrizedJarUrl2()186     public void testParametrizedJarUrl2() throws Exception {
187         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarUrl2.jnlp");
188         String s = "Good simple javaws exapmle";
189         Assert.assertTrue("ParametrizedJarUrl2 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
190     }
191 
192     @Test
testParametrizedJarUrl3()193     public void testParametrizedJarUrl3() throws Exception {
194         ProcessResult pr = server.executeJavawsHeadless(null, "/ParametrizedJarUrl2.jnlp?test=123456");
195         String s = "Good simple javaws exapmle";
196         Assert.assertTrue("ParametrizedJarUrl2 stdout should contain " + s + " but didn't", pr.stdout.contains(s));
197 ;
198     }
199 
evaluateApplet(ProcessResult pr)200     private void evaluateApplet(ProcessResult pr) {
201         String s3 = "applet was initialised";
202         Assert.assertTrue("AppletTest stdout should contain " + s3 + " but didn't", pr.stdout.contains(s3));
203         String s0 = "applet was started";
204         Assert.assertTrue("AppletTest stdout should contain " + s0 + " but didn't", pr.stdout.contains(s0));
205         String s1 = "value1";
206         Assert.assertTrue("AppletTest stdout should contain " + s1 + " but didn't", pr.stdout.contains(s1));
207         String s2 = "value2";
208         Assert.assertTrue("AppletTest stdout should contain " + s2 + " but didn't", pr.stdout.contains(s2));
209         String s7 = "Aplet killing himself after 2000 ms of life";
210         Assert.assertTrue("AppletTest stdout should contain " + s7 + " but didn't", pr.stdout.contains(s7));
211     }
212 
213     @Test
214     @TestInBrowsers(testIn=Browsers.one)
parametrizedAppletInBrowserTest()215     public void parametrizedAppletInBrowserTest() throws Exception {
216         ProcessResult pr = server.executeBrowser("/ParametrizedJarUrl.html");
217         pr.process.destroy();
218         evaluateApplet(pr);
219     }
220 }
221