1 15 package hivemind.test.ant; 16 17 import hivemind.test.FrameworkTestCase; 18 19 import java.io.File ; 20 21 import org.apache.hivemind.ant.ManifestClassPath; 22 import org.apache.tools.ant.BuildException; 23 import org.apache.tools.ant.Project; 24 import org.apache.tools.ant.Target; 25 import org.apache.tools.ant.types.Path; 26 27 33 public class TestManifestClassPath extends FrameworkTestCase 34 { 35 protected Project _project = new Project(); 36 37 protected ManifestClassPath create() 38 { 39 Target t = new Target(); 40 41 ManifestClassPath result = new ManifestClassPath(); 42 result.setProject(_project); 43 result.setOwningTarget(t); 44 result.setTaskName("manifestClassPath"); 45 46 return result; 47 } 48 49 public void testSimple() throws Exception 50 { 51 ManifestClassPath mcp = create(); 52 53 mcp.setProperty("output"); 54 55 assertEquals("output", mcp.getProperty()); 56 57 Path path = mcp.createClasspath(); 58 59 Path.PathElement pe = path.createPathElement(); 60 61 pe.setLocation(new File ("src/META-INF/hivemodule.xml")); 62 63 pe = path.createPathElement(); 64 65 pe.setLocation(new File ("src/java/org/apache/commons/hivemind/HiveMind.properties")); 66 67 mcp.execute(); 68 69 assertEquals("hivemodule.xml HiveMind.properties", _project.getProperty("output")); 70 } 71 72 public void testDirectory() throws Exception 73 { 74 ManifestClassPath mcp = create(); 75 76 mcp.setProperty("output"); 77 78 assertEquals("output", mcp.getProperty()); 79 80 File dir = new File ("src").getAbsoluteFile(); 81 82 mcp.setDirectory(dir); 83 84 assertEquals(dir, mcp.getDirectory()); 85 86 Path path = mcp.createClasspath(); 87 88 Path.PathElement pe = path.createPathElement(); 89 90 pe.setLocation(new File ("src/META-INF/hivemodule.xml")); 91 92 pe = path.createPathElement(); 93 94 pe.setLocation(new File ("src/java/org/apache/commons/hivemind/HiveMind.properties")); 95 96 pe = path.createPathElement(); 97 98 pe.setLocation(new File ("common/links.xml")); 99 100 mcp.execute(); 101 102 assertEquals( 103 "META-INF/hivemodule.xml java/org/apache/commons/hivemind/HiveMind.properties", 104 _project.getProperty("output")); 105 } 106 107 public void testDirectoryInClasspath() throws Exception 108 { 109 ManifestClassPath mcp = create(); 110 111 mcp.setProperty("output"); 112 113 File dir = new File ("src").getAbsoluteFile(); 114 115 mcp.setDirectory(dir); 116 117 Path path = mcp.createClasspath(); 118 119 Path.PathElement pe = path.createPathElement(); 120 121 pe.setLocation(dir); 122 123 pe = path.createPathElement(); 124 125 pe.setLocation(new File ("src/META-INF/hivemodule.xml")); 126 127 mcp.execute(); 128 129 assertEquals("META-INF/hivemodule.xml", _project.getProperty("output")); 130 } 131 132 public void testEmpty() throws Exception 133 { 134 ManifestClassPath mcp = create(); 135 136 mcp.setProperty("zap"); 137 138 assertEquals("zap", mcp.getProperty()); 139 140 mcp.createClasspath(); 141 142 mcp.execute(); 143 144 assertEquals("", _project.getProperty("zap")); 145 146 } 147 148 public void testNoProperty() throws Exception 149 { 150 ManifestClassPath mcp = create(); 151 152 mcp.createClasspath(); 153 154 try 155 { 156 mcp.execute(); 157 158 unreachable(); 159 } 160 catch (BuildException ex) 161 { 162 assertExceptionSubstring( 163 ex, 164 "You must specify a property to assign the manifest classpath to"); 165 } 166 167 } 168 169 public void testNoClasspath() throws Exception 170 { 171 ManifestClassPath mcp = create(); 172 173 mcp.setProperty("bar"); 174 175 try 176 { 177 mcp.execute(); 178 179 unreachable(); 180 } 181 catch (BuildException ex) 182 { 183 assertExceptionSubstring( 184 ex, 185 "You must specify a classpath to generate the manifest entry from"); 186 } 187 188 } 189 } 190 | Popular Tags |