KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hivemind > test > ant > TestManifestClassPath


1 // Copyright 2004, 2005 The Apache Software Foundation
2
//
3
// Licensed under the Apache License, Version 2.0 (the "License");
4
// you may not use this file except in compliance with the License.
5
// You may obtain a copy of the License at
6
//
7
// http://www.apache.org/licenses/LICENSE-2.0
8
//
9
// Unless required by applicable law or agreed to in writing, software
10
// distributed under the License is distributed on an "AS IS" BASIS,
11
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
// See the License for the specific language governing permissions and
13
// limitations under the License.
14

15 package hivemind.test.ant;
16
17 import hivemind.test.FrameworkTestCase;
18
19 import java.io.File JavaDoc;
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 /**
28  * Tests the {@link org.apache.hivemind.ant.ManifestClassPath}
29  * Ant task.
30  *
31  * @author Howard Lewis Ship
32  */

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 JavaDoc
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 JavaDoc("src/META-INF/hivemodule.xml"));
62
63         pe = path.createPathElement();
64
65         pe.setLocation(new File JavaDoc("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 JavaDoc
73     {
74         ManifestClassPath mcp = create();
75
76         mcp.setProperty("output");
77
78         assertEquals("output", mcp.getProperty());
79
80         File JavaDoc dir = new File JavaDoc("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 JavaDoc("src/META-INF/hivemodule.xml"));
91
92         pe = path.createPathElement();
93
94         pe.setLocation(new File JavaDoc("src/java/org/apache/commons/hivemind/HiveMind.properties"));
95
96         pe = path.createPathElement();
97
98         pe.setLocation(new File JavaDoc("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 JavaDoc
108     {
109         ManifestClassPath mcp = create();
110
111         mcp.setProperty("output");
112
113         File JavaDoc dir = new File JavaDoc("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 JavaDoc("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 JavaDoc
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 JavaDoc
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 JavaDoc
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