aboutsummaryrefslogtreecommitdiffstats
path: root/tests/reproducers/signed/DownloadService/testcases/DownloadServiceTest.java
blob: 69c573649f895ee7391fad59261efcb3a9e66be1 (plain)
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
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
/* DownloadServiceTest.java
Copyright (C) 2012 Red Hat, Inc.

This file is part of IcedTea.

IcedTea is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License as published by
the Free Software Foundation, version 2.

IcedTea is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
General Public License for more details.

You should have received a copy of the GNU General Public License
along with IcedTea; see the file COPYING.  If not, write to
the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.

Linking this library statically or dynamically with other modules is
making a combined work based on this library.  Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.

As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module.  An independent module is a module which is not derived from
or based on this library.  If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so.  If you do not wish to do so, delete this
exception statement from your version.
 */

import java.io.File;
import java.net.MalformedURLException;
import java.util.ArrayList;
import java.util.List;

import junit.framework.Assert;
import net.sourceforge.jnlp.ProcessResult;
import net.sourceforge.jnlp.ServerAccess;

import org.junit.BeforeClass;
import org.junit.Test;

public class DownloadServiceTest {
    private static ServerAccess server = new ServerAccess();
    private final String exitString = "Exiting DownloadService..";
    private static List<String> checkCache = new ArrayList<String>();
    private static List<String> manageJnlpResources = new ArrayList<String>();
    private static List<String> manageExternalResources = new ArrayList<String>();

    @BeforeClass
    public static void initalizeClass() throws MalformedURLException {
        //Check Cache
        checkCache.add(server.getJavawsLocation());
        checkCache.add("-arg");
        checkCache.add(server.getUrl().toString() + "/");
        checkCache.add("-arg");
        checkCache.add("checkCache");
        checkCache.add("-Xtrustall");
        checkCache.add(ServerAccess.HEADLES_OPTION);
        checkCache.add(server.getUrl() + "/DownloadService.jnlp");

        //Manage Jnlp Resouces
        manageJnlpResources.add(server.getJavawsLocation());
        manageJnlpResources.add("-arg");
        manageJnlpResources.add(server.getUrl().toString() + "/");
        manageJnlpResources.add("-arg");
        manageJnlpResources.add("manageJnlpJars");
        manageJnlpResources.add("-Xtrustall");
        manageJnlpResources.add(ServerAccess.HEADLES_OPTION);
        manageJnlpResources.add(server.getUrl() + "/DownloadService.jnlp");

        //Manage External Resources
        manageExternalResources.add(server.getJavawsLocation());
        manageExternalResources.add("-arg");
        manageExternalResources.add(server.getUrl().toString() + "/");
        manageExternalResources.add("-arg");
        manageExternalResources.add("manageExternalJars");
        manageExternalResources.add("-Xtrustall");
        manageExternalResources.add(ServerAccess.HEADLES_OPTION);
        manageExternalResources.add(server.getUrl() + "/DownloadService.jnlp");
    }

    /**
     * Executes reproducer to checks if DownloadServices's cache checks are working correctly.
     * @return stdout of reproducer.
     */
    private String runCacheCheckTests() throws Exception {
        //Check cache test
        ProcessResult processResult = ServerAccess.executeProcess(checkCache);
        String stdoutCheckCache = processResult.stdout;
        Assert.assertTrue("CheckCache - DownloadServiceRunner instance did not close as expected, this test may fail.",
                stdoutCheckCache.contains(exitString));

        return stdoutCheckCache;
    }

    /**
     * Executes reproducer to checks if DownloadServices's management of external jars are working correctly.
     * @return stdout of reproducer.
     */
    private String runExternalTests() throws Exception {
        ProcessResult processResult = ServerAccess.executeProcess(manageExternalResources);
        String stdoutExternalResources = processResult.stdout;
        Assert.assertTrue("ManageExternalResources - DownloadServiceRunner instance did not close as expected, this test may fail.",
                stdoutExternalResources.contains(exitString));

        return stdoutExternalResources;
    }

    /**
     * Executes reproducer to checks if DownloadServices's management of jnlp jars are working correctly.
     * @return stdout of reproducer.
     */
    private String runJnlpResourceTests() throws Exception {
        ProcessResult processResult = ServerAccess.executeProcess(manageJnlpResources);
        String stdoutJnlpResources = processResult.stdout;
        Assert.assertTrue("ManageJnlpResources - DownloadServiceRunner instance did not close as expected, this test may fail.",
                stdoutJnlpResources.contains(exitString));

        return stdoutJnlpResources;
    }

    @Test
    public void checkIfRequiredResourcesExist() {
        //Jnlp files
        Assert.assertTrue("DownloadService.jnlp is a required resource that's missing.",
                new File(server.getDir().getAbsolutePath() + "/DownloadService.jnlp").isFile());
        Assert.assertTrue("DownloadServiceExtension.jnlp is a required resource that's missing.", new File(server.getDir().getAbsolutePath()
                + "/DownloadServiceExtension.jnlp").isFile());

        //Jar files
        Assert.assertTrue("DownloadService.jar is a required resource that's missing.",
                new File(server.getDir().getAbsolutePath() + "/DownloadService.jar").isFile());
        Assert.assertTrue("SignedJnlpResource.jar is a required resource that's missing.", new File(server.getDir().getAbsolutePath()
                + "/SignedJnlpResource.jar").isFile());
        Assert.assertTrue("SignedJarResource.jar is a required resource that's missing.",
                new File(server.getDir().getAbsolutePath() + "/SignedJarResource.jar").isFile());
        Assert.assertTrue("MultiJar-NoSignedJnlp.jar is a required resource that's missing.", new File(server.getDir().getAbsolutePath()
                + "/MultiJar-NoSignedJnlp.jar").isFile());
    }

    @Test
    public void testcheckCaches() throws Exception {
        String stdoutCheckCache = runCacheCheckTests();

        //Stdout validations
        String s = "CHECKCACHE-isPartCached: LaunchPartOne: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKCACHE-isPartCached: LaunchPartTwo: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKCACHE-isPartCached: NonExistingPart: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));
    }

    @Test
    public void testcheckCachesUsingArray() throws Exception {
        String stdoutCheckCache = runCacheCheckTests();

        //Stdout validations
        String s = "CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): ValidLaunchParts: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): HalfValidLaunchParts: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): InvalidParts: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));
    }

    @Test
    public void testExtensioncheckCaches() throws Exception {
        String stdoutCheckCache = runCacheCheckTests();

        //Stdout validations
        String s = "CHECKEXTENSIONCACHE-isExtensionPartCached: ExtensionPartOne: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKEXTENSIONCACHE-isExtensionPartCached: NonExistingPart: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKEXTENSIONCACHE-isExtensionPartCached: NonExistingUrl: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));
    }

    @Test
    public void testExtensioncheckCachesUsingArray() throws Exception {
        String stdoutCheckCache = runCacheCheckTests();

        //Stdout validations
        String s = "CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): ValidExtensionParts: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): HalfValidExtensionParts: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

        s = "CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): InvalidParts: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutCheckCache.contains(s));

    }

    @Test
    public void testExternalResourceChecks() throws Exception {
        runCacheCheckTests();
        String stdoutExternalResources = runExternalTests();

        //Stdout validations
        //This is automatically cached from the test engine because the .jar exists
        String s = "CHECKEXTERNALCACHE-isResourceCached: UrlToExternalResource: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

        s = "CHECKEXTERNALCACHE-isResourceCached: NonExistingUrl: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));
    }

    @Test
    public void testRemovePart() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        String s = "REMOVEPART-removePart: LaunchPartOne-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
        s = "REMOVEPART-removePart: LaunchPartOne-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "REMOVEPART-removePart: LaunchPartTwo-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
        s = "REMOVEPART-removePart: LaunchPartTwo-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testRemoveExtensionPart() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        String s = "REMOVEEXTENSIONPART-removeExtensionPart: ExtensionPartOne-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "REMOVEEXTENSIONPART-removeExtensionPart: ExtensionPartOne-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testRemoveExtensionPartUsingArray() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        String s = "REMOVEEXTENSIONUSINGVALIDPARTINARRAY-removeExtensionPart(Array): ValidExtensionParts-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "REMOVEEXTENSIONUSINGVALIDPARTINARRAY-removeExtensionPart(Array): ValidExtensionParts-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "REMOVEEXTENSIONUSINGHALFVALIDPARTINARRAY-removeExtensionPart(Array): HalfValidExtensionParts-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "REMOVEEXTENSIONUSINGHALFVALIDPARTINARRAY-removeExtensionPart(Array): HalfValidExtensionParts-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testRemoveExternalResource() throws Exception {
        runCacheCheckTests();
        String stdoutExternalResources = runExternalTests();

        //Stdout validations
        String s = "REMOVEEXTERNALPART-removeResource: UrlToExternalResource-BEFORE: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

        s = "REMOVEEXTERNALPART-removeResource: UrlToExternalResource-AFTER: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

    }

    @Test
    public void testLoadPart() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        //Part 'one'
        String s = "LOADPART-loadPart: LaunchPartOne-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
        s = "LOADPART-loadPart: LaunchPartOne-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        //Part 'two'
        s = "LOADPART-loadPart: LaunchPartTwo-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
        s = "LOADPART-loadPart: LaunchPartTwo-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testLoadExtensionPart() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        String s = "LOADEXTENSIONPART-loadExtensionPart: ExtensionPartOne-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "LOADEXTENSIONPART-loadExtensionPart: ExtensionPartOne-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testLoadExtensionPartUsingArray() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        String s = "LOADEXTENSIONUSINGVALIDPARTINARRAY-loadExtensionPart(Array): ValidExtensionParts-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "LOADEXTENSIONUSINGVALIDPARTINARRAY-loadExtensionPart(Array): ValidExtensionParts-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "LOADEXTENSIONUSINGHALFVALIDPARTINARRAY-loadExtensionPart(Array): HalfValidExtensionParts-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "LOADEXTENSIONUSINGHALFVALIDPARTINARRAY-loadExtensionPart(Array): HalfValidExtensionParts-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));
    }

    @Test
    public void testLoadExternalResource() throws Exception {
        runCacheCheckTests();
        String stdoutExternalResources = runExternalTests();

        //Stdout validations
        String s = "LOADEXTERNALRESOURCE-loadResource: UrlToExternalResource-BEFORE: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

        s = "LOADEXTERNALRESOURCE-loadResource: UrlToExternalResource-AFTER: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

    }

    @Test
    public void testRepeatedlyLoadingAndUnloadingJnlpResources() throws Exception {
        runCacheCheckTests();
        String stdoutJnlpResources = runJnlpResourceTests();

        //Stdout validations
        String s = "MULTIPLEMETHODCALLS - removePart: LaunchPartOne: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

        s = "MULTIPLEMETHODCALLS - loadPart: LaunchPartOne: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutJnlpResources.contains(s));

    }

    @Test
    public void testRepeatedlyLoadingAndUnloadingExternalResources() throws Exception {
        runCacheCheckTests();
        String stdoutExternalResources = runExternalTests();

        //Stdout validations
        String s = "MULTIPLEMETHODCALLS - removeResource: UrlToExternalResource: false";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));

        s = "MULTIPLEMETHODCALLS - loadResource: UrlToExternalResource: true";
        Assert.assertTrue("stdout should contain \"" + s + "\" but did not.", stdoutExternalResources.contains(s));
    }
}