Added
Link Here
|
1 |
/* |
2 |
* (c) 2005 Red Hat, Inc. |
3 |
* |
4 |
* This program is open source software licensed under the |
5 |
* Eclipse Public License ver. 1 |
6 |
*/ |
7 |
package org.eclipse.cdt.rpm.core.internal.tests; |
8 |
|
9 |
import java.io.File; |
10 |
import java.io.StringBufferInputStream; |
11 |
import java.net.URL; |
12 |
import java.text.SimpleDateFormat; |
13 |
import java.util.Date; |
14 |
|
15 |
import junit.framework.TestCase; |
16 |
import junit.framework.TestSuite; |
17 |
|
18 |
import org.eclipse.cdt.rpm.core.IRPMConstants; |
19 |
import org.eclipse.cdt.rpm.core.IRPMProject; |
20 |
import org.eclipse.cdt.rpm.core.ISpecFile; |
21 |
import org.eclipse.cdt.rpm.core.RPMCorePlugin; |
22 |
import org.eclipse.cdt.rpm.core.RPMExportDelta; |
23 |
import org.eclipse.cdt.rpm.core.RPMProjectFactory; |
24 |
import org.eclipse.cdt.rpm.core.RPMProjectNature; |
25 |
import org.eclipse.cdt.rpm.core.tests.RPMCoreTestsPlugin; |
26 |
import org.eclipse.core.resources.IFile; |
27 |
import org.eclipse.core.resources.IFolder; |
28 |
import org.eclipse.core.resources.IProject; |
29 |
import org.eclipse.core.resources.IResource; |
30 |
import org.eclipse.core.resources.IWorkspace; |
31 |
import org.eclipse.core.resources.IWorkspaceDescription; |
32 |
import org.eclipse.core.resources.IWorkspaceRoot; |
33 |
import org.eclipse.core.resources.ResourcesPlugin; |
34 |
import org.eclipse.core.runtime.NullProgressMonitor; |
35 |
import org.eclipse.core.runtime.Path; |
36 |
import org.eclipse.core.runtime.Platform; |
37 |
import org.eclipse.core.runtime.QualifiedName; |
38 |
|
39 |
public class RPMProjectTest extends TestCase { |
40 |
|
41 |
IWorkspace workspace; |
42 |
IWorkspaceRoot root; |
43 |
NullProgressMonitor monitor; |
44 |
String pluginRoot; |
45 |
|
46 |
final String file_sep = System.getProperty("file.separator"); //$NON-NLS-1$ |
47 |
private final String line_sep = System.getProperty("line.separator"); //$NON-NLS-1$ |
48 |
|
49 |
/* |
50 |
* @see TestCase#setUp() |
51 |
*/ |
52 |
protected void setUp() throws Exception { |
53 |
super.setUp(); |
54 |
IWorkspaceDescription desc; |
55 |
workspace = ResourcesPlugin.getWorkspace(); |
56 |
root = workspace.getRoot(); |
57 |
monitor = new NullProgressMonitor(); |
58 |
if(workspace == null) { |
59 |
fail("Workspace was not setup"); |
60 |
} |
61 |
if(root == null) { |
62 |
fail("Workspace root was not setup"); |
63 |
} |
64 |
desc = workspace.getDescription(); |
65 |
desc.setAutoBuilding(false); |
66 |
workspace.setDescription(desc); |
67 |
} |
68 |
|
69 |
public static TestSuite suite() { |
70 |
return new TestSuite(RPMProjectTest.class); |
71 |
} |
72 |
|
73 |
public void testImportHelloWorld() throws Exception { |
74 |
// Create a project for the test |
75 |
IProject testProject = root.getProject("testHelloWorld"); |
76 |
testProject.create(monitor); |
77 |
testProject.open(monitor); |
78 |
if(testProject == null) { |
79 |
fail("Unable to create test project"); |
80 |
} |
81 |
|
82 |
// Instantiate an RPMProject |
83 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
84 |
|
85 |
// Find the test SRPM and install it |
86 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
87 |
"helloworld-2-2.src.rpm")); |
88 |
if (url == null) { |
89 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
90 |
"helloworld-2-2.src.rpm"); |
91 |
} |
92 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
93 |
rpmProject.importSourceRPM(foo); |
94 |
|
95 |
// Make sure the original SRPM got copied into the workspace |
96 |
IFile srpm = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-2.src.rpm"); |
97 |
assertTrue(srpm.exists()); |
98 |
assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, |
99 |
IRPMConstants.SRPM_PROPERTY))); |
100 |
|
101 |
// Make sure everything got installed properly |
102 |
IFile spec = rpmProject.getConfiguration().getSpecsFolder().getFile("helloworld.spec"); |
103 |
assertTrue(spec.exists()); |
104 |
IFile sourceBall = rpmProject.getConfiguration().getSourcesFolder().getFile("helloworld-2.tar.bz2"); |
105 |
assertTrue(sourceBall.exists()); |
106 |
|
107 |
// Make sure we got the spec file |
108 |
ISpecFile specFile = rpmProject.getSpecFile(); |
109 |
assertTrue(specFile != null); |
110 |
assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, |
111 |
IRPMConstants.SPEC_FILE_PROPERTY))); |
112 |
|
113 |
// Make sure the sources got copied from BUILD to the project root |
114 |
IResource[] sources = rpmProject.getConfiguration().getBuildFolder().members(); |
115 |
// If there is one folder, assume it contains all the sources |
116 |
if(sources.length == 1 && sources[0].getType() == IResource.FOLDER) { |
117 |
IFolder foo1 = rpmProject.getProject().getFolder(sources[0].getProjectRelativePath()); |
118 |
sources = foo1.members(); |
119 |
} |
120 |
for(int i=0; i < sources.length; i++) { |
121 |
if(sources[i].getType() == IResource.FILE) { |
122 |
assertTrue(testProject.getFile(sources[i].getName()).exists()); |
123 |
} |
124 |
else if(sources[i].getType() == IResource.FOLDER) { |
125 |
assertTrue(testProject.getFolder(sources[i].getName()).exists()); |
126 |
} |
127 |
} |
128 |
|
129 |
// Make sure the checksum was stored |
130 |
assertNotNull(rpmProject.getProject().getPersistentProperty(new QualifiedName(RPMCorePlugin.ID, |
131 |
IRPMConstants.CHECKSUM_PROPERTY))); |
132 |
|
133 |
// Make sure the RPM nature was added |
134 |
assertTrue(rpmProject.getProject().hasNature(RPMProjectNature.RPM_NATURE_ID)); |
135 |
|
136 |
// Clean up |
137 |
testProject.delete(true, false, monitor); |
138 |
} |
139 |
|
140 |
public void testBuildPrepHelloWorld() throws Exception { |
141 |
// Create a project for the test |
142 |
IProject testProject = root.getProject("testBuildPrepHelloWorld"); |
143 |
testProject.create(monitor); |
144 |
testProject.open(monitor); |
145 |
if(testProject == null) { |
146 |
fail("Unable to create test project"); |
147 |
} |
148 |
|
149 |
// Instantiate an RPMProject |
150 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
151 |
|
152 |
// Find the test SRPM, install, and build-prep it |
153 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
154 |
"helloworld-2-2.src.rpm")); |
155 |
if (url == null) { |
156 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
157 |
"helloworld-2-2.src.rpm"); |
158 |
} |
159 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
160 |
rpmProject.importSourceRPM(foo); |
161 |
rpmProject.buildPrep(); |
162 |
|
163 |
// Make sure we got everything in the build directory |
164 |
IFolder builddir = rpmProject.getConfiguration().getBuildFolder(); |
165 |
IFolder helloworldFolder = builddir.getFolder("helloworld-2"); |
166 |
assertTrue(helloworldFolder.exists()); |
167 |
|
168 |
// Clean up |
169 |
testProject.delete(true, false, monitor); |
170 |
} |
171 |
|
172 |
public void testIsChangedHelloWorld() throws Exception { |
173 |
// Create a project for the test |
174 |
IProject testProject = root.getProject("testIsChangedHelloWorld"); |
175 |
testProject.create(monitor); |
176 |
testProject.open(monitor); |
177 |
if(testProject == null) { |
178 |
fail("Unable to create test project"); |
179 |
} |
180 |
|
181 |
// Instantiate an RPMProject |
182 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
183 |
|
184 |
// Find the test SRPM and install it |
185 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
186 |
"helloworld-2-2.src.rpm")); |
187 |
if (url == null) { |
188 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
189 |
"helloworld-2-2.src.rpm"); |
190 |
} |
191 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
192 |
rpmProject.importSourceRPM(foo); |
193 |
assertFalse(rpmProject.isChanged()); |
194 |
|
195 |
testProject.delete(true, false, null); |
196 |
} |
197 |
|
198 |
public void testIsChangedHelloWorld1() throws Exception { |
199 |
// Create a project for the test |
200 |
IProject testProject = root.getProject("testIsChangedHelloWorld1"); |
201 |
testProject.create(monitor); |
202 |
testProject.open(monitor); |
203 |
if(testProject == null) { |
204 |
fail("Unable to create test project"); |
205 |
} |
206 |
|
207 |
// Instantiate an RPMProject |
208 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
209 |
|
210 |
// Find the test SRPM and install it |
211 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
212 |
"helloworld-2-2.src.rpm")); |
213 |
if (url == null) { |
214 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
215 |
"helloworld-2-2.src.rpm"); |
216 |
} |
217 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
218 |
rpmProject.importSourceRPM(foo); |
219 |
IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp"); |
220 |
StringBufferInputStream foo1 = new StringBufferInputStream("/* */"); |
221 |
sourceFile.appendContents(foo1, false, false, null); |
222 |
assertTrue(rpmProject.isChanged()); |
223 |
|
224 |
testProject.delete(true, false, null); |
225 |
} |
226 |
|
227 |
public void testBuildSourceRPMHelloWorld() throws Exception { |
228 |
// Create a project for the test |
229 |
IProject testProject = root.getProject("testBuildSourceRPMHelloWorld1"); |
230 |
testProject.create(monitor); |
231 |
testProject.open(monitor); |
232 |
if(testProject == null) { |
233 |
fail("Unable to create test project"); |
234 |
} |
235 |
|
236 |
// Instantiate an RPMProject |
237 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
238 |
|
239 |
// Find the test SRPM and install it |
240 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
241 |
"helloworld-2-2.src.rpm")); |
242 |
if (url == null) { |
243 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
244 |
"helloworld-2-2.src.rpm"); |
245 |
} |
246 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
247 |
rpmProject.importSourceRPM(foo); |
248 |
RPMExportDelta export = new RPMExportDelta(); |
249 |
export.setSpecFile(rpmProject.getSpecFile().getFile()); |
250 |
export.setVersion("2"); |
251 |
export.setRelease("3"); |
252 |
rpmProject.buildSourceRPM(export); |
253 |
|
254 |
IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-3.src.rpm"); |
255 |
assertTrue(foo2.exists()); |
256 |
|
257 |
testProject.delete(true, false, null); |
258 |
} |
259 |
|
260 |
public void testBuildSourceRPMHelloWorld1() throws Exception { |
261 |
// Create a project for the test |
262 |
IProject testProject = root.getProject("testBuildSourceRPMHelloWorld"); |
263 |
testProject.create(monitor); |
264 |
testProject.open(monitor); |
265 |
if(testProject == null) { |
266 |
fail("Unable to create test project"); |
267 |
} |
268 |
|
269 |
// Instantiate an RPMProject |
270 |
IRPMProject rpmProject = RPMProjectFactory.getRPMProject(testProject); |
271 |
|
272 |
// Find the test SRPM and install it |
273 |
URL url = RPMCoreTestsPlugin.getDefault().find(new Path("resources" + file_sep + "srpms" + file_sep + //$NON-NLS-1$ //$NON-NLS-2$ |
274 |
"helloworld-2-2.src.rpm")); |
275 |
if (url == null) { |
276 |
fail("Unable to find resource" + file_sep + "srpms" + file_sep + |
277 |
"helloworld-2-2.src.rpm"); |
278 |
} |
279 |
File foo = new File(Platform.asLocalURL(url).getPath()); |
280 |
rpmProject.importSourceRPM(foo); |
281 |
IFile sourceFile = rpmProject.getProject().getFile("helloworld.cpp"); |
282 |
StringBufferInputStream foo1 = new StringBufferInputStream("/* */"); |
283 |
sourceFile.appendContents(foo1, false, false, null); |
284 |
RPMExportDelta export = new RPMExportDelta(); |
285 |
export.setSpecFile(rpmProject.getSpecFile().getFile()); |
286 |
export.setVersion("2"); |
287 |
export.setRelease("4"); |
288 |
export.setPatchName("myPatchFFFFF.patch"); |
289 |
Date today = new Date(); |
290 |
SimpleDateFormat df = new SimpleDateFormat("E MMM dd yyyy"); //$NON-NLS-1$ |
291 |
export.setChangelogEntry("* " + df.format(today) + " Foo Bot <bot@foo.bar> 2-4" + line_sep + |
292 |
"- Made test change" + line_sep); |
293 |
rpmProject.buildSourceRPM(export); |
294 |
|
295 |
// Make sure patch was created |
296 |
assertTrue(rpmProject.getConfiguration().getSourcesFolder().getFile(export.getPatchName()).exists()); |
297 |
|
298 |
IFile foo2 = rpmProject.getConfiguration().getSrpmsFolder().getFile("helloworld-2-4.src.rpm"); |
299 |
assertTrue(foo2.exists()); |
300 |
} |
301 |
} |