KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > tools > ant > module > spi > AutomaticExtraClasspathTest


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.apache.tools.ant.module.spi;
21
22 import java.util.logging.Level JavaDoc;
23 import java.io.File JavaDoc;
24 import java.net.URL JavaDoc;
25 import org.netbeans.junit.Log;
26 import org.netbeans.junit.NbTestCase;
27 import org.openide.filesystems.FileObject;
28 import org.openide.filesystems.FileSystem;
29 import org.openide.filesystems.XMLFileSystem;
30
31 /**
32  *
33  * @author Jaroslav Tulach
34  */

35 public class AutomaticExtraClasspathTest extends NbTestCase {
36     private static URL JavaDoc wd;
37     
38     
39     FileObject fo, bad;
40     
41     public AutomaticExtraClasspathTest(String JavaDoc testName) {
42         super(testName);
43     }
44
45     @Override JavaDoc
46     protected void setUp() throws Exception JavaDoc {
47         URL JavaDoc u = getClass().getResource("AutomaticExtraClasspathTest.xml");
48         FileSystem fs = new XMLFileSystem(u);
49         fo = fs.findResource("testAutoProvider");
50         assertNotNull("There is the resource", fo);
51         bad = fs.findResource("brokenURL");
52         assertNotNull("There is the bad", bad);
53     }
54
55     @Override JavaDoc
56     protected Level JavaDoc logLevel() {
57         return Level.INFO;
58     }
59
60     public static URL JavaDoc getWD() {
61         return wd;
62     }
63     
64     public void testReadWorkDir() throws Exception JavaDoc {
65         URL JavaDoc u = getWorkDir().toURI().toURL();
66         wd = u;
67         
68         Object JavaDoc value = fo.getAttribute("instanceCreate");
69         assertTrue("provider created: " + value, value instanceof AutomaticExtraClasspathProvider);
70         
71         AutomaticExtraClasspathProvider auto = (AutomaticExtraClasspathProvider)value;
72         File JavaDoc[] arr = auto.getClasspathItems();
73         assertNotNull(arr);
74         assertEquals("One item", 1, arr.length);
75         assertEquals("It is our work dir", getWorkDir(), arr[0]);
76     }
77
78     public void testBadURL() throws Exception JavaDoc {
79         CharSequence JavaDoc log = Log.enable("", Level.WARNING);
80         Object JavaDoc value = bad.getAttribute("instanceCreate");
81         assertNull("no provider created: " + value, value);
82         
83         if (log.toString().indexOf("IllegalArgumentException") == -1) {
84             fail("IllegalArgumentException shall be thrown:\n" + log);
85         }
86     }
87
88     public void testFailIfTheFileDoesNotExists() throws Exception JavaDoc {
89         URL JavaDoc u = new File JavaDoc(getWorkDir(), "does-not-exists.txt").toURI().toURL();
90         wd = u;
91         
92         CharSequence JavaDoc log = Log.enable("", Level.WARNING);
93         Object JavaDoc value = fo.getAttribute("instanceCreate");
94         assertNull("no provider created: " + value, value);
95         
96         if (log.toString().indexOf("FileNotFoundException") == -1) {
97             fail("FileNotFoundException shall be thrown:\n" + log);
98         }
99     }
100     
101 }
102
Popular Tags