[RFC][icedtea-web]: Reproducer for DownloadService

Adam Domurad adomurad at redhat.com
Wed Oct 31 06:35:25 PDT 2012


On 10/30/2012 02:55 PM, Saad Mohammad wrote:
> Ping?
>
> This post is slowly getting lost.. It would be nice to get this reviewed quickly
> as DownloadService implementation patch is waiting on this to be pushed.
>
>
> On 10/11/2012 04:30 PM, Saad Mohammad wrote:
>> On 10/01/2012 04:41 PM, Adam Domurad wrote:
>>> There's a few general concerns here (Mostly a result of this being hard to test):
>>>
>>> 1. this generally looks like a unit test
>>> 	- As discussed on IRC, this is probably OK considering that its quite difficult to unit test DownloadService in isolation.
>>>
>>> 2. checking for 'true' or 'false' is a bit brittle, it'd be better if you could print all the cached resources and having the test check
>>> 	- Also discussed on IRC, this would be difficult to do with the given API for handling cached resources
>>>
>>> 3. its all one interdependent test, ran as one process. I think a
>>> slightly better approach would be to take an argument to
>>> DownloadServiceRunner that determines the test run type, and run the
>>> minimal commands needed to test that component. For example,
>>> loadExternalResource could be tested in isolation from loadPart.
>> Hi Adam,
>>
>> Thanks for the review. Updated patch is attached.
>>
>> As we discussed on IRC, satisfying #1 & #2 would be very difficult at the
>> moment. However, I did make some changes for #3.
>>
>> What's new?
>>         * Runs three different instances of DownloadServiceRunner to avoid
>>           dependency of one process to output results. Checking cache, managing
>>           jnlp resources, and managing external jnlps are verified by the stdout
>>           of the three instances.
>>         * Added two test which checks repeated calls of unloading and loading
>>           a single resource
>>
>> ========================================================================
>> CHANGELOG
>> ========================================================================
>> 2012-10-11  Saad Mohammad  <smohammad at redhat.com>
>>
>> 	Added reproducer for DownloadService.
>> 	* tests/reproducers/signed/DownloadService/resources/DownloadService.jnlp:
>> 	Launching jnlp file that contains extension jnlp and jars marked with part names.
>> 	* tests/reproducers/signed/DownloadService/resources/DownloadServiceExtension.jnlp:
>> 	DownloadService extension jnlp file with jars marked with part names.
>> 	* tests/reproducers/signed/DownloadService/srcs/DownloadServiceRunner.java:
>> 	A simple class that uses DownloadService to complete tasks and outputs the results.
>> 	* tests/reproducers/signed/DownloadService/testcases/DownloadServiceTest.java:
>> 	Testcase for DownloadService.
>>
>>
>
> diff --git 
> a/tests/reproducers/signed/DownloadService/resources/DownloadService.jnlp 
> b/tests/reproducers/signed/DownloadService/resources/DownloadService.jnlp
> new file mode 100644
> --- /dev/null
> +++ 
> b/tests/reproducers/signed/DownloadService/resources/DownloadService.jnlp
> @@ -0,0 +1,64 @@
> +<!--
> +
> +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; either version 2, or (at your option)
> +any later version.
> +
> +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.
> +
> +***********************************************************************
> +This launching jnlp file has jars and an extension jnlp as its resources.
> +***********************************************************************
> + -->
> +<?xml version="1.0" encoding="utf-8"?>
> +<jnlp spec="1.0" href="DownloadService.jnlp" codebase=".">
> +  <information>
> +    <title>DownloadService</title>
> +    <vendor>IcedTea</vendor>
> +    <homepage 
> href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
> +    <description>DownloadService</description>
> +    <offline/>
> +  </information>
> +
> +  <security>
> +      <all-permissions/>
> +  </security>
> +
> +  <resources>
> +    <j2se version="1.6+"/>
> +    <jar href="DownloadService.jar" part="one"/>
> +    <jar href="SignedJnlpResource.jar" part="two"/>
> +   <extension name="DownloadServiceExtension" 
> href="./DownloadServiceExtension.jnlp"/>
> +  </resources>
> +
> +  <application-desc main-class="DownloadServiceRunner">
> +  </application-desc>
> +</jnlp>
> diff --git 
> a/tests/reproducers/signed/DownloadService/resources/DownloadServiceExtension.jnlp 
> b/tests/reproducers/signed/DownloadService/resources/DownloadServiceExtension.jnlp
> new file mode 100644
> --- /dev/null
> +++ 
> b/tests/reproducers/signed/DownloadService/resources/DownloadServiceExtension.jnlp
> @@ -0,0 +1,58 @@
> +<!--
> +
> +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; either version 2, or (at your option)
> +any later version.
> +
> +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.
> +
> +***********************************************************************
> +This extension jnlp file contains jars and is used by 
> DownloadService.jnlp
> +***********************************************************************
> + -->
> +<?xml version="1.0" encoding="utf-8"?>
> +<jnlp spec="1.0" href="DownloadServiceExtension.jnlp" codebase=".">
> +  <information>
> +    <title>DownloadServiceExtension</title>
> +    <vendor>IcedTea</vendor>
> +    <homepage 
> href="http://icedtea.classpath.org/wiki/IcedTea-Web#Testing_IcedTea-Web"/>
> + <description>DownloadServiceExtension</description>
> +    <offline/>
> +  </information>
> +
> +  <resources>
> +    <j2se version="1.6+"/>
> +    <jar href="SignedJarResource.jar" part="extOne"/>
> +    <jar href="MultiJar-NoSignedJnlp.jar" part="extOne"/>
> +  </resources>
> +
> +  <component-desc />
> +</jnlp>
> diff --git 
> a/tests/reproducers/signed/DownloadService/srcs/DownloadServiceRunner.java 
> b/tests/reproducers/signed/DownloadService/srcs/DownloadServiceRunner.java
> new file mode 100644
> --- /dev/null
> +++ 
> b/tests/reproducers/signed/DownloadService/srcs/DownloadServiceRunner.java
> @@ -0,0 +1,351 @@
> +/* DownloadService.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.IOException;
> +import java.net.MalformedURLException;
> +import java.net.URL;
> +
> +import javax.jnlp.DownloadService;
> +import javax.jnlp.ServiceManager;
> +import javax.jnlp.UnavailableServiceException;
> +
> +public class DownloadServiceRunner {
> +
> +    URL serverUrl = null;
> +    URL extensionUrl = null;
> +    URL NonExistingUrl = null;
> +
> +    URL urlToExternalResource = null;
> +
> +    /**
> +     * Launching jnlp and extension jnlp PARTS
> +     */
> +    final String launchPartOne = "one";
> +    final String launchPartTwo = "two";
> +    final String extensionPartOne = "extOne";
> +    final String nonExistingPart = "random";
> +
> +    /**
> +     * Parts in Array
> +     */
> +    final String[] validLaunchParts = { launchPartOne, launchPartTwo };
> +    final String[] halfValidLaunchParts = { launchPartOne, 
> nonExistingPart };
> +    final String[] validExtensionParts = { extensionPartOne };
> +    final String[] halfValidExtensionParts = { extensionPartOne, 
> nonExistingPart };
> +    final String[] invalidParts = { nonExistingPart, "random2" };
> +
> +    private static DownloadService downloadService;
> +    static {
> +        try {
> +            downloadService = (DownloadService) 
> ServiceManager.lookup("javax.jnlp.DownloadService");
> +        } catch (UnavailableServiceException ex) {
> +            System.err.println("DownloadService is not available.");
> +        }
> +    }
> +
> +    public DownloadServiceRunner(String urlToServer) throws 
> MalformedURLException, InterruptedException {
> +        serverUrl = new URL(urlToServer);
> +        extensionUrl = new URL(urlToServer + 
> "DownloadServiceExtension.jnlp");
> +        NonExistingUrl = new URL(urlToServer + "NONEXISTINGFILE.JNLP");
> +
> +        urlToExternalResource = new URL(urlToServer + 
> "EmptySignedJar.jar");
> +
> +        System.out.println(urlToExternalResource.toString());
> +
> +    }
> +
> +    /**
> +     * Checks the cache status of resources using isPartCached()
> +     */
> +    private void checkCache() throws MalformedURLException {
> +        System.out.println("CHECKCACHE-isPartCached: LaunchPartOne: " 
> + downloadService.isPartCached(launchPartOne));
> +        System.out.println("CHECKCACHE-isPartCached: LaunchPartTwo: " 
> + downloadService.isPartCached(launchPartTwo));
> +        System.out.println("CHECKCACHE-isPartCached: NonExistingPart: 
> " + downloadService.isPartCached(nonExistingPart));
> +    }
> +
> +    /**
> +     * Checks the cache status of resources using isPartCached([]) - 
> an array with part names
> +     */
> +    private void checkCacheUsingMultipleParts() throws 
> MalformedURLException {
> + System.out.println("CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): 
> ValidLaunchParts: " + downloadService.isPartCached(validLaunchParts));
> + System.out.println("CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): 
> HalfValidLaunchParts: " + 
> downloadService.isPartCached(halfValidLaunchParts));
> + System.out.println("CHECKCACHEUSINGMUTIPLEPARTS-isPartCached(Array): 
> InvalidParts: " + downloadService.isPartCached(invalidParts));
> +    }
> +
> +    /**
> +     * Checks the cache status of extension resources using 
> isExtensionPartCached()
> +     */
> +    private void checkExtensionCache() throws MalformedURLException {
> + System.out.println("CHECKEXTENSIONCACHE-isExtensionPartCached: 
> ExtensionPartOne: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> + System.out.println("CHECKEXTENSIONCACHE-isExtensionPartCached: 
> NonExistingPart: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, nonExistingPart));
> + System.out.println("CHECKEXTENSIONCACHE-isExtensionPartCached: 
> NonExistingUrl: "
> +                + 
> downloadService.isExtensionPartCached(NonExistingUrl, null, 
> extensionPartOne));
> +    }
> +
> +    /**
> +     * Checks the cache status of extension resources using 
> isExtensionPartCached([]) - an array with part names
> +     */
> +    private void checkExtensionCacheUsingMultipleParts() throws 
> MalformedURLException {
> + 
> System.out.println("CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): 
> ValidExtensionParts: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, validExtensionParts));
> + 
> System.out.println("CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): 
> HalfValidExtensionParts: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, halfValidExtensionParts));
> + 
> System.out.println("CHECKEXTENSIONCACHEUSINGMUTIPLEPARTS-isExtensionPartCached(Array): 
> InvalidParts: "
> +                + 
> downloadService.isExtensionPartCached(NonExistingUrl, null, 
> invalidParts));
> +    }
> +
> +    /**
> +     * Checks the cache status of external (not mentioned in jnlps) 
> resources using isResourceCached()
> +     */
> +    private void checkExternalCache() {
> +        System.out.println("CHECKEXTERNALCACHE-isResourceCached: 
> UrlToExternalResource: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +        System.out.println("CHECKEXTERNALCACHE-isResourceCached: 
> NonExistingUrl: " + downloadService.isResourceCached(NonExistingUrl, 
> null));
> +    }
> +
> +    /**
> +     * Removes resources from cache using removePart()
> +     */
> +    private void removePart() throws IOException {
> +        System.out.println("REMOVEPART-removePart: 
> LaunchPartOne-BEFORE: " + downloadService.isPartCached(launchPartOne));
> +        downloadService.removePart(launchPartOne);
> +        System.out.println("REMOVEPART-removePart: 
> LaunchPartOne-AFTER: " + downloadService.isPartCached(launchPartOne));
> +
> +        System.out.println("REMOVEPART-removePart: 
> LaunchPartTwo-BEFORE: " + downloadService.isPartCached(launchPartTwo));
> +        downloadService.removePart(launchPartTwo);
> +        System.out.println("REMOVEPART-removePart: 
> LaunchPartTwo-AFTER: " + downloadService.isPartCached(launchPartTwo));
> +    }
> +
> +    /**
> +     * Removes extension resources from cache using 
> isExtensionPartCached()
> +     */
> +    private void removeExtensionPart() throws IOException {
> + System.out.println("REMOVEEXTENSIONPART-removeExtensionPart: 
> ExtensionPartOne-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +        downloadService.removeExtensionPart(extensionUrl, null, 
> extensionPartOne);
> + System.out.println("REMOVEEXTENSIONPART-removeExtensionPart: 
> ExtensionPartOne-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +    }
> +
> +    /**
> +     * Removes extension resources using part array (all parts exist) 
> from cache using isExtensionPartCached()
> +     */
> +    private void removeExtensionUsingValidPartInArray() throws 
> IOException {
> + 
> System.out.println("REMOVEEXTENSIONUSINGVALIDPARTINARRAY-removeExtensionPart(Array): 
> ValidExtensionParts-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +        downloadService.removeExtensionPart(extensionUrl, null, 
> validExtensionParts);
> +
> + 
> System.out.println("REMOVEEXTENSIONUSINGVALIDPARTINARRAY-removeExtensionPart(Array): 
> ValidExtensionParts-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +    }
> +
> +    /**
> +     * Removes extension resources using part array (one part exists, 
> the other one does not) from cache using isExtensionPartCached()
> +     */
> +    private void removeExtensionUsingHalfValidPartInArray() throws 
> IOException {
> + 
> System.out.println("REMOVEEXTENSIONUSINGHALFVALIDPARTINARRAY-removeExtensionPart(Array): 
> HalfValidExtensionParts-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +        downloadService.removeExtensionPart(extensionUrl, null, 
> halfValidExtensionParts);
> +
> + 
> System.out.println("REMOVEEXTENSIONUSINGHALFVALIDPARTINARRAY-removeExtensionPart(Array): 
> HalfValidExtensionParts-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +    }
> +
> +    /**
> +     * Removes external (not mentioned in jnlps) resources from cache 
> using removeResource()
> +     */
> +    private void removeExternalResource() throws IOException {
> +        System.out.println("REMOVEEXTERNALPART-removeResource: 
> UrlToExternalResource-BEFORE: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +        downloadService.removeResource(urlToExternalResource, null);
> +        System.out.println("REMOVEEXTERNALPART-removeResource: 
> UrlToExternalResource-AFTER: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +    }
> +
> +    /**
> +     * Loads resources from cache using loadPart()
> +     */
> +    private void loadPart() throws IOException {
> +        System.out.println("LOADPART-loadPart: LaunchPartOne-BEFORE: 
> " + downloadService.isPartCached(launchPartOne));
> +        downloadService.loadPart(launchPartOne, null);
> +        System.out.println("LOADPART-loadPart: LaunchPartOne-AFTER: " 
> + downloadService.isPartCached(launchPartOne));
> +
> +        System.out.println("LOADPART-loadPart: LaunchPartTwo-BEFORE: 
> " + downloadService.isPartCached(launchPartTwo));
> +        downloadService.loadPart(launchPartTwo, null);
> +        System.out.println("LOADPART-loadPart: LaunchPartTwo-AFTER: " 
> + downloadService.isPartCached(launchPartTwo));
> +    }
> +
> +    /**
> +     * Load extension resources from cache using loadExtensionPart()
> +     */
> +    private void loadExtensionPart() throws IOException {
> +        System.out.println("LOADEXTENSIONPART-loadExtensionPart: 
> ExtensionPartOne-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +        downloadService.loadExtensionPart(extensionUrl, null, 
> extensionPartOne, null);
> +        System.out.println("LOADEXTENSIONPART-loadExtensionPart: 
> ExtensionPartOne-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +    }
> +
> +    /**
> +     * Loads extension resources using part array (all parts exist) 
> from cache using isExtensionPartCached()
> +     */
> +    private void loadExtensionUsingValidPartInArray() throws 
> IOException {
> + 
> System.out.println("LOADEXTENSIONUSINGVALIDPARTINARRAY-loadExtensionPart(Array): 
> ValidExtensionParts-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +        downloadService.loadExtensionPart(extensionUrl, null, 
> validExtensionParts, null);
> +
> + 
> System.out.println("LOADEXTENSIONUSINGVALIDPARTINARRAY-loadExtensionPart(Array): 
> ValidExtensionParts-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +    }
> +
> +    /**
> +     * Loads extension resources using part array (one part exists, 
> the other one does not) from cache using isExtensionPartCached()
> +     */
> +    private void loadExtensionUsingHalfValidPartInArray() throws 
> IOException {
> + 
> System.out.println("LOADEXTENSIONUSINGHALFVALIDPARTINARRAY-loadExtensionPart(Array): 
> HalfValidExtensionParts-BEFORE: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +
> +        downloadService.loadExtensionPart(extensionUrl, null, 
> halfValidExtensionParts, null);
> +
> + 
> System.out.println("LOADEXTENSIONUSINGHALFVALIDPARTINARRAY-loadExtensionPart(Array): 
> HalfValidExtensionParts-AFTER: "
> +                + downloadService.isExtensionPartCached(extensionUrl, 
> null, extensionPartOne));
> +    }
> +
> +    /**
> +     * Loads external (not mentioned in jnlps) resources from cache 
> using removeResource()
> +     */
> +    private void loadExternalResource() throws IOException {
> +        System.out.println("LOADEXTERNALRESOURCE-loadResource: 
> UrlToExternalResource-BEFORE: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +        downloadService.loadResource(urlToExternalResource, null, null);
> +        System.out.println("LOADEXTERNALRESOURCE-loadResource: 
> UrlToExternalResource-AFTER: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +    }
> +
> +    /**
> +     * Repeatedly unloads and loads jars
> +     */
> +    private void repeatedlyLoadingAndUnloadingJars() throws IOException {
> +        downloadService.removePart(launchPartOne);
> +        downloadService.loadPart(launchPartOne, null);
> +
> +        downloadService.removePart(launchPartOne);
> +        System.out.println("MULTIPLEMETHODCALLS - removePart: 
> LaunchPartOne: " + downloadService.isPartCached(launchPartOne));
> +
> +        downloadService.loadPart(launchPartOne, null);
> +        System.out.println("MULTIPLEMETHODCALLS - loadPart: 
> LaunchPartOne: " + downloadService.isPartCached(launchPartOne));
> +    }
> +
> +    /**
> +     * Repeatedly unloads and loads external jars
> +     */
> +    private void repeatedlyLoadingAndUnloadingExternalJars() throws 
> IOException {
> +        downloadService.removeResource(urlToExternalResource, null);
> +        downloadService.loadResource(urlToExternalResource, null, null);
> +
> +        downloadService.removeResource(urlToExternalResource, null);
> +        System.out.println("MULTIPLEMETHODCALLS - removeResource: 
> UrlToExternalResource: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +
> +        downloadService.loadResource(urlToExternalResource, null, null);
> +        System.out.println("MULTIPLEMETHODCALLS - loadResource: 
> UrlToExternalResource: " + 
> downloadService.isResourceCached(urlToExternalResource, null));
> +    }
> +
> +    /**
> +     * Loads external jar as preparation for external resource testing
> +     */
> +    private void prepareExternalResourceTests() {
> +        try {
> +            if 
> (!downloadService.isResourceCached(urlToExternalResource, null))
> + downloadService.loadResource(urlToExternalResource, null, null);
> +        } catch (Exception e) {
> +            //Continue testing
> +            // This is okay to ignore as it may be a problem with 
> loadResouce( ), which will be identified within tests
> +        }
> +    }
> +
> +    public static void main(String[] args) throws IOException, 
> InterruptedException {
> +        System.out.println("Running DownloadService..");
> +
> +        if (args.length < 2) {
> +            System.out.println("Requires 2 arguments: [server_url] 
> [checkCache | manageJars | manageExternalJars]");
> +            System.out.println("Exiting..");
> +            return;
> +        }
> +
> +        DownloadServiceRunner ds = new DownloadServiceRunner(args[0]);
> +
> +        if (args[1].equals("checkCache")) {
> +            //Cache Resources
> +            ds.checkCache();
> +            ds.checkCacheUsingMultipleParts();
> +            ds.checkExtensionCache();
> +            ds.checkExtensionCacheUsingMultipleParts();
> +        }
> +
> +        if (args[1].equals("manageJnlpJars")) {
> +            //Remove Resources
> +            ds.removePart();
> +            ds.removeExtensionPart();
> +
> +            //Load Resources
> +            ds.loadPart();
> +            ds.loadExtensionPart();
> +
> +            //Manage using multiple part arrays
> +            ds.removeExtensionUsingValidPartInArray();
> +            ds.loadExtensionUsingValidPartInArray();
> +            ds.removeExtensionUsingHalfValidPartInArray();
> +            ds.loadExtensionUsingHalfValidPartInArray();
> +
> +            //Unloads and loads jars repeatedly
> +            ds.repeatedlyLoadingAndUnloadingJars();
> +
> +        } else if (args[1].equals("manageExternalJars")) {
> +            ds.prepareExternalResourceTests();
> +            ds.checkExternalCache();
> +            ds.removeExternalResource();
> +            ds.loadExternalResource();
> +
> +            //Unloads and loads jars repeatedly
> +            ds.repeatedlyLoadingAndUnloadingExternalJars();
> +        }
> +
> +        System.out.println("Exiting DownloadService..");
> +    }
> +}
> diff --git 
> a/tests/reproducers/signed/DownloadService/testcases/DownloadServiceTest.java 
> b/tests/reproducers/signed/DownloadService/testcases/DownloadServiceTest.java
> new file mode 100644
> --- /dev/null
> +++ 
> b/tests/reproducers/signed/DownloadService/testcases/DownloadServiceTest.java
> @@ -0,0 +1,335 @@
> +/* 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.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 static String stderr;
> +
> +    private static String stdoutCheckCache;
> +    private static String stdoutJnlpResources;
> +    private static String stdoutExternalResources;
> +
> +    private static List<String> checkCache = new ArrayList<String>();
> +    static {
> +        try {
> +            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");

Perhaps these 'static' blocks should be in a set-up method / test 
constructor.

> +        } catch (Exception e) {
> +            System.out.println(e.getMessage());
> +        }
> +    }
> +
> +    private static List<String> manageJnlpResources = new 
> ArrayList<String>();
> +    static {
> +        try {
> +            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");
> +        } catch (Exception e) {
> +            System.out.println(e.getMessage());
> +        }
> +    }
> +
> +    private static List<String> manageExternalResources = new 
> ArrayList<String>();
> +    static {
> +        try {
> + 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");
> +        } catch (Exception e) {
> +            System.out.println(e.getMessage());
> +        }
> +    }
> +
> +    @BeforeClass
> +    public static void initializeClass() throws Exception {
> +        ProcessResult processResult;
> +
> +        //Check cache tests
> +        processResult = ServerAccess.executeProcess(checkCache);
> +        stdoutCheckCache = processResult.stdout;
> +        stderr = processResult.stderr;
> +
> +        //Jnlp resource tests
> +        processResult = ServerAccess.executeProcess(manageJnlpResources);
> +        stdoutJnlpResources = processResult.stdout;
> +        stderr += "\n" + processResult.stderr;
> +
> +        //External resource tests
> +        processResult = 
> ServerAccess.executeProcess(manageExternalResources);
> +        stdoutExternalResources = processResult.stdout;
> +        stderr += "\n" + processResult.stderr;

These shouldn't all be run before the tests imo

> +    }
> +
> +    @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 checkIfMainFinishedCorrectly() {
> +        String s = "Exiting DownloadService..";
> +        Assert.assertTrue("CheckCache - DownloadServiceRunner 
> instance did not close as expected, this may cause other tests to fail.",
> +                stdoutCheckCache.contains(s));
> +        Assert.assertTrue("ManageJnlpResources - 
> DownloadServiceRunner instance did not close as expected, this may 
> cause other tests to fail.",
> +                stdoutJnlpResources.contains(s));
> +        Assert.assertTrue("ManageExternalResources - 
> DownloadServiceRunner instance did not close as expected, this may 
> cause other tests to fail.",
> +                stdoutExternalResources.contains(s));
> +    }
> +
> +    @Test
> +    public void testDownloadServiceAvailability() {
> +        String s = "DownloadService is not available.";
> +        Assert.assertFalse(stderr.contains(s));
> +    }
> +
> +    @Test
> +    public void testcheckCaches() {
> +        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() {
> +        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() {
> +        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() {
> +        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() {
> +        //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() {
> +        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() {
> +        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() {
> +        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()
> +    {
> +        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() {
> +        //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() {
> +        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() {
> +        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() {
> +        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() {
> +        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() {
> +        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));
> +    }
> +}

While it isn't ideal because it checks true/false values being printed, 
which can accidentally turn out to be correct, it is indeed a test of 
DownloadService. As you explained it can't be done any other way really, 
so looks good to me.

Other than the setup code changes I have no real further issues with 
this going into HEAD.

Thanks for the ping (you should have prodded me a lot sooner! :),
- Adam



More information about the distro-pkg-dev mailing list