tests/libjava-mauve/src/gnu/testlet/java/net/URLConnection/Jar.java
branchjk_new_structure
changeset 1541 75c2e24dea9a
parent 1540 92ac284961c1
child 1542 be11db817bcf
equal deleted inserted replaced
1540:92ac284961c1 1541:75c2e24dea9a
     1 // Tags: JDK1.2
       
     2 
       
     3 /* Jar.java -- Tests Jar URL connection
       
     4 
       
     5    Copyright (c) 2005, 2006 by Free Software Foundation, Inc.
       
     6    Written by Tom Tromey <tromey@redhat.com>
       
     7    Extended by Wolfgang Baer <WBaer@gmx.de>
       
     8 
       
     9    This program is free software; you can redistribute it and/or modify
       
    10    it under the terms of the GNU General Public License as published
       
    11    by the Free Software Foundation, version 2. (see COPYING)
       
    12 
       
    13    This program is distributed in the hope that it will be useful, but
       
    14    WITHOUT ANY WARRANTY; without even the implied warranty of
       
    15    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
       
    16    GNU General Public License for more details.
       
    17 
       
    18    You should have received a copy of the GNU General Public License
       
    19    along with this program; if not, write to the Free Software Foundation,
       
    20    51 Franklin Street, Fifth Floor, Boston, MA, 02110-1301 USA. */
       
    21 
       
    22 package gnu.testlet.java.net.URLConnection;
       
    23 
       
    24 import gnu.testlet.TestHarness;
       
    25 import gnu.testlet.Testlet;
       
    26 
       
    27 import java.io.File;
       
    28 import java.io.FileNotFoundException;
       
    29 import java.net.JarURLConnection;
       
    30 import java.net.URL;
       
    31 
       
    32 public class Jar implements Testlet
       
    33 {
       
    34   public void test(TestHarness harness)
       
    35   {
       
    36     harness.checkPoint("jar: URL with missing entry");
       
    37     try
       
    38       {
       
    39 	File jarfile = harness.getResourceFile("gnu#testlet#java#util#jar#JarFile#jartest.jar");
       
    40 	String filename = jarfile.toString();
       
    41 
       
    42 	URL url = new URL("jar:file:" + filename + "!/nosuchfile.txt");
       
    43 
       
    44         // Test via JarURLConnection
       
    45         // FileNotFoundException must already be thrown in connect
       
    46         JarURLConnection connection = null;
       
    47         try 
       
    48           {
       
    49             connection = (JarURLConnection) url.openConnection();
       
    50             connection.connect();
       
    51             harness.check(false);
       
    52           }
       
    53         catch (FileNotFoundException e)
       
    54           {
       
    55             harness.check(true);
       
    56           }
       
    57         catch (Exception e)
       
    58           {
       
    59             harness.check(false);
       
    60           }
       
    61 
       
    62         // Test via direct opening of the stream on the URL object
       
    63         try
       
    64           {
       
    65             url.openStream();
       
    66             harness.check(false);
       
    67           }
       
    68         catch (FileNotFoundException e)
       
    69           {
       
    70             harness.check(true);
       
    71           }
       
    72         catch (Exception e)
       
    73           {
       
    74             harness.check(false);
       
    75           }
       
    76         
       
    77       }   
       
    78     catch (Throwable e)
       
    79       {
       
    80         harness.debug("Unexpected exception in testcase.");
       
    81 	harness.debug(e);
       
    82       }
       
    83   }
       
    84 }