1 19 20 package org.apache.tools.ant.module.api; 21 22 import java.io.File ; 23 import java.util.Arrays ; 24 import java.util.Collections ; 25 import java.util.Map ; 26 import org.netbeans.junit.MockServices; 27 import org.netbeans.junit.NbTestCase; 28 import org.openide.modules.InstalledFileLocator; 29 30 33 37 public class IntrospectedInfoTest extends NbTestCase { 38 39 public IntrospectedInfoTest(String name) { 40 super(name); 41 } 42 43 private IntrospectedInfo ii; 44 45 @Override 46 protected void setUp() throws Exception { 47 MockServices.setServices(IFL.class); 48 ii = IntrospectedInfo.getDefaults(); 49 } 50 51 public void testBasicDefinitions() throws Exception { 52 Map <String ,String > tasks = ii.getDefs("task"); 53 assertEquals("binding for javac", "org.apache.tools.ant.taskdefs.Javac", tasks.get("javac")); 54 assertEquals("binding for sql", "org.apache.tools.ant.taskdefs.SQLExec", tasks.get("sql")); 55 Map <String ,String > types = ii.getDefs("type"); 56 assertEquals("binding for path", "org.apache.tools.ant.types.FileSet", types.get("fileset")); 57 assertEquals("binding for path", "org.apache.tools.ant.types.Path", types.get("path")); 58 } 59 60 public void testBasicAttributes() throws Exception { 61 Map <String ,String > attrs = ii.getAttributes("org.apache.tools.ant.taskdefs.Javac"); 62 assertEquals("right type for destdir", "java.io.File", attrs.get("destdir")); 63 74 80 } 81 82 public void testEnumeratedAttributes() throws Exception { 83 ii.register("enumtask", EnumTask.class, "task"); 84 String k1 = EnumTask.class.getName(); 85 assertEquals(k1, ii.getDefs("task").get("enumtask")); 86 String k2 = EnumTask.E.class.getName(); 87 assertEquals(Collections.singletonMap("attr", k2), ii.getAttributes(k1)); 88 assertEquals("[chocolate, vanilla, strawberry]", Arrays.toString(ii.getTags(k2))); 89 } 90 91 public static class EnumTask { 92 public enum E {chocolate, vanilla, strawberry} 93 public void setAttr(E e) {} 94 } 95 96 public static final class IFL extends InstalledFileLocator { 97 public IFL() { 98 } 100 @Override 101 public File locate(String relativePath, String codeNameBase, boolean localized) { 102 if (relativePath.equals("ant/nblib/bridge.jar")) { 103 String path = System.getProperty("test.bridge.jar"); 104 assertNotNull("must set test.bridge.jar", path); 105 return new File (path); 106 } else if (relativePath.equals("ant")) { 107 String path = System.getProperty("test.ant.home"); 108 assertNotNull("must set test.ant.home", path); 109 return new File (path); 110 } else if (relativePath.startsWith("ant/")) { 111 String path = System.getProperty("test.ant.home"); 112 assertNotNull("must set test.ant.home", path); 113 return new File (path, relativePath.substring(4).replace('/', File.separatorChar)); 114 } else { 115 return null; 116 } 117 } 118 } 119 120 } 121 | Popular Tags |