1 19 20 package org.apache.tools.ant.module.spi; 21 22 import java.util.logging.Level ; 23 import java.io.File ; 24 import java.net.URL ; 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 35 public class AutomaticExtraClasspathTest extends NbTestCase { 36 private static URL wd; 37 38 39 FileObject fo, bad; 40 41 public AutomaticExtraClasspathTest(String testName) { 42 super(testName); 43 } 44 45 @Override 46 protected void setUp() throws Exception { 47 URL 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 56 protected Level logLevel() { 57 return Level.INFO; 58 } 59 60 public static URL getWD() { 61 return wd; 62 } 63 64 public void testReadWorkDir() throws Exception { 65 URL u = getWorkDir().toURI().toURL(); 66 wd = u; 67 68 Object value = fo.getAttribute("instanceCreate"); 69 assertTrue("provider created: " + value, value instanceof AutomaticExtraClasspathProvider); 70 71 AutomaticExtraClasspathProvider auto = (AutomaticExtraClasspathProvider)value; 72 File [] 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 { 79 CharSequence log = Log.enable("", Level.WARNING); 80 Object 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 { 89 URL u = new File (getWorkDir(), "does-not-exists.txt").toURI().toURL(); 90 wd = u; 91 92 CharSequence log = Log.enable("", Level.WARNING); 93 Object 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 |