Lines 11-17
Link Here
|
11 |
*******************************************************************************/ |
11 |
*******************************************************************************/ |
12 |
package org.eclipse.ltk.core.refactoring.tests.resource; |
12 |
package org.eclipse.ltk.core.refactoring.tests.resource; |
13 |
|
13 |
|
|
|
14 |
import java.io.ByteArrayInputStream; |
14 |
import java.io.IOException; |
15 |
import java.io.IOException; |
|
|
16 |
import java.io.InputStream; |
15 |
|
17 |
|
16 |
import junit.framework.Test; |
18 |
import junit.framework.Test; |
17 |
import junit.framework.TestCase; |
19 |
import junit.framework.TestCase; |
Lines 41-46
Link Here
|
41 |
import org.eclipse.ltk.core.refactoring.RefactoringCore; |
43 |
import org.eclipse.ltk.core.refactoring.RefactoringCore; |
42 |
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; |
44 |
import org.eclipse.ltk.core.refactoring.RefactoringDescriptor; |
43 |
import org.eclipse.ltk.core.refactoring.RefactoringStatus; |
45 |
import org.eclipse.ltk.core.refactoring.RefactoringStatus; |
|
|
46 |
import org.eclipse.ltk.core.refactoring.resource.CreateFileChange; |
44 |
import org.eclipse.ltk.core.refactoring.resource.DeleteResourcesDescriptor; |
47 |
import org.eclipse.ltk.core.refactoring.resource.DeleteResourcesDescriptor; |
45 |
import org.eclipse.ltk.core.refactoring.resource.MoveResourceChange; |
48 |
import org.eclipse.ltk.core.refactoring.resource.MoveResourceChange; |
46 |
import org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor; |
49 |
import org.eclipse.ltk.core.refactoring.resource.MoveResourcesDescriptor; |
Lines 95-101
Link Here
|
95 |
Change undoChange= perform(new MoveResourceChange(testFolder, destination)); |
98 |
Change undoChange= perform(new MoveResourceChange(testFolder, destination)); |
96 |
|
99 |
|
97 |
|
100 |
|
98 |
IFolder movedResource= (IFolder) assertMove(testFolder, destination, null); |
101 |
IFolder movedResource= (IFolder)assertMove(testFolder, destination, null); |
99 |
assertTrue(movedResource.getFile("myFile.txt").exists()); |
102 |
assertTrue(movedResource.getFile("myFile.txt").exists()); |
100 |
|
103 |
|
101 |
perform(undoChange); |
104 |
perform(undoChange); |
Lines 137-143
Link Here
|
137 |
IFolder destination= fProject.createFolder("dest"); |
140 |
IFolder destination= fProject.createFolder("dest"); |
138 |
|
141 |
|
139 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
142 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
140 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor) contribution.createDescriptor(); |
143 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor)contribution.createDescriptor(); |
141 |
|
144 |
|
142 |
descriptor.setResourcesToMove(new IResource[] { file }); |
145 |
descriptor.setResourcesToMove(new IResource[] { file }); |
143 |
descriptor.setDestination(destination); |
146 |
descriptor.setDestination(destination); |
Lines 161-174
Link Here
|
161 |
IFolder destination= fProject.createFolder("dest"); |
164 |
IFolder destination= fProject.createFolder("dest"); |
162 |
|
165 |
|
163 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
166 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
164 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor) contribution.createDescriptor(); |
167 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor)contribution.createDescriptor(); |
165 |
|
168 |
|
166 |
descriptor.setResourcesToMove(new IResource[] { testFolder }); |
169 |
descriptor.setResourcesToMove(new IResource[] { testFolder }); |
167 |
descriptor.setDestination(destination); |
170 |
descriptor.setDestination(destination); |
168 |
|
171 |
|
169 |
Change undoChange= perform(descriptor); |
172 |
Change undoChange= perform(descriptor); |
170 |
|
173 |
|
171 |
IFolder movedResource= (IFolder) assertMove(testFolder, destination, null); |
174 |
IFolder movedResource= (IFolder)assertMove(testFolder, destination, null); |
172 |
assertTrue(movedResource.getFile("myFile.txt").exists()); |
175 |
assertTrue(movedResource.getFile("myFile.txt").exists()); |
173 |
|
176 |
|
174 |
perform(undoChange); |
177 |
perform(undoChange); |
Lines 190-196
Link Here
|
190 |
IFile file2= fProject.createFile(destination, "myFile.txt", content2); |
193 |
IFile file2= fProject.createFile(destination, "myFile.txt", content2); |
191 |
|
194 |
|
192 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
195 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(MoveResourcesDescriptor.ID); |
193 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor) contribution.createDescriptor(); |
196 |
MoveResourcesDescriptor descriptor= (MoveResourcesDescriptor)contribution.createDescriptor(); |
194 |
|
197 |
|
195 |
descriptor.setResourcesToMove(new IResource[] { file1 }); |
198 |
descriptor.setResourcesToMove(new IResource[] { file1 }); |
196 |
descriptor.setDestination(destination); |
199 |
descriptor.setDestination(destination); |
Lines 208-214
Link Here
|
208 |
public void testDeleteRefactoring1_bug343584() throws Exception { |
211 |
public void testDeleteRefactoring1_bug343584() throws Exception { |
209 |
IFolder testFolder= fProject.createFolder("test"); |
212 |
IFolder testFolder= fProject.createFolder("test"); |
210 |
fProject.createFile(testFolder, "myFile.txt", "hello"); |
213 |
fProject.createFile(testFolder, "myFile.txt", "hello"); |
211 |
|
214 |
|
212 |
IProject testProject2= ResourcesPlugin.getWorkspace().getRoot().getProject(SimpleTestProject.TEST_PROJECT_NAME + "2"); |
215 |
IProject testProject2= ResourcesPlugin.getWorkspace().getRoot().getProject(SimpleTestProject.TEST_PROJECT_NAME + "2"); |
213 |
try { |
216 |
try { |
214 |
testProject2.create(null); |
217 |
testProject2.create(null); |
Lines 233-239
Link Here
|
233 |
IPath location= fProject.getProject().getLocation(); |
236 |
IPath location= fProject.getProject().getLocation(); |
234 |
IFolder testFolder= fProject.createFolder("test"); |
237 |
IFolder testFolder= fProject.createFolder("test"); |
235 |
fProject.createFile(testFolder, "myFile.txt", "hello"); |
238 |
fProject.createFile(testFolder, "myFile.txt", "hello"); |
236 |
|
239 |
|
237 |
IWorkspace workspace= ResourcesPlugin.getWorkspace(); |
240 |
IWorkspace workspace= ResourcesPlugin.getWorkspace(); |
238 |
String p2Name= "p2"; |
241 |
String p2Name= "p2"; |
239 |
IProjectDescription p2Description= workspace.newProjectDescription(p2Name); |
242 |
IProjectDescription p2Description= workspace.newProjectDescription(p2Name); |
Lines 242-269
Link Here
|
242 |
p2.create(p2Description, null); |
245 |
p2.create(p2Description, null); |
243 |
p2.open(null); |
246 |
p2.open(null); |
244 |
IPath p2Location= p2.getLocation(); |
247 |
IPath p2Location= p2.getLocation(); |
245 |
|
248 |
|
246 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(DeleteResourcesDescriptor.ID); |
249 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(DeleteResourcesDescriptor.ID); |
247 |
DeleteResourcesDescriptor descriptor= (DeleteResourcesDescriptor) contribution.createDescriptor(); |
250 |
DeleteResourcesDescriptor descriptor= (DeleteResourcesDescriptor)contribution.createDescriptor(); |
248 |
|
251 |
|
249 |
descriptor.setDeleteContents(true); |
252 |
descriptor.setDeleteContents(true); |
250 |
descriptor.setResources(new IResource[] { fProject.getProject(), p2 }); |
253 |
descriptor.setResources(new IResource[] { fProject.getProject(), p2 }); |
251 |
|
254 |
|
252 |
perform(descriptor); |
255 |
perform(descriptor); |
253 |
|
256 |
|
254 |
assertFalse(fProject.getProject().exists()); |
257 |
assertFalse(fProject.getProject().exists()); |
255 |
assertFalse(p2.exists()); |
258 |
assertFalse(p2.exists()); |
256 |
|
259 |
|
257 |
assertFalse(location.toFile().exists()); |
260 |
assertFalse(location.toFile().exists()); |
258 |
assertFalse(p2Location.toFile().exists()); |
261 |
assertFalse(p2Location.toFile().exists()); |
259 |
} |
262 |
} |
260 |
|
263 |
|
261 |
public void testDeleteRefactoring3_bug343584() throws Exception { |
264 |
public void testDeleteRefactoring3_bug343584() throws Exception { |
262 |
IPath location= fProject.getProject().getLocation(); |
265 |
IPath location= fProject.getProject().getLocation(); |
263 |
IFolder testFolder= fProject.createFolder("test"); |
266 |
IFolder testFolder= fProject.createFolder("test"); |
264 |
IFile file= fProject.createFile(testFolder, "myFile.txt", "hello"); |
267 |
IFile file= fProject.createFile(testFolder, "myFile.txt", "hello"); |
265 |
IPath fileLocation= file.getLocation(); |
268 |
IPath fileLocation= file.getLocation(); |
266 |
|
269 |
|
267 |
IWorkspace workspace= ResourcesPlugin.getWorkspace(); |
270 |
IWorkspace workspace= ResourcesPlugin.getWorkspace(); |
268 |
String p2Name= "p2"; |
271 |
String p2Name= "p2"; |
269 |
IProjectDescription p2Description= workspace.newProjectDescription(p2Name); |
272 |
IProjectDescription p2Description= workspace.newProjectDescription(p2Name); |
Lines 272-300
Link Here
|
272 |
p2.create(p2Description, null); |
275 |
p2.create(p2Description, null); |
273 |
p2.open(null); |
276 |
p2.open(null); |
274 |
IPath p2Location= p2.getLocation(); |
277 |
IPath p2Location= p2.getLocation(); |
275 |
|
278 |
|
276 |
try { |
279 |
try { |
277 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(DeleteResourcesDescriptor.ID); |
280 |
RefactoringContribution contribution= RefactoringCore.getRefactoringContribution(DeleteResourcesDescriptor.ID); |
278 |
DeleteResourcesDescriptor descriptor= (DeleteResourcesDescriptor) contribution.createDescriptor(); |
281 |
DeleteResourcesDescriptor descriptor= (DeleteResourcesDescriptor)contribution.createDescriptor(); |
279 |
|
282 |
|
280 |
descriptor.setDeleteContents(false); |
283 |
descriptor.setDeleteContents(false); |
281 |
descriptor.setResources(new IResource[] { fProject.getProject(), p2 }); |
284 |
descriptor.setResources(new IResource[] { fProject.getProject(), p2 }); |
282 |
|
285 |
|
283 |
perform(descriptor); |
286 |
perform(descriptor); |
284 |
|
287 |
|
285 |
assertFalse(fProject.getProject().exists()); |
288 |
assertFalse(fProject.getProject().exists()); |
286 |
assertFalse(p2.exists()); |
289 |
assertFalse(p2.exists()); |
287 |
|
290 |
|
288 |
assertTrue(location.toFile().exists()); |
291 |
assertTrue(location.toFile().exists()); |
289 |
assertTrue(fileLocation.toFile().exists()); |
292 |
assertTrue(fileLocation.toFile().exists()); |
290 |
assertTrue(p2Location.toFile().exists()); |
293 |
assertTrue(p2Location.toFile().exists()); |
291 |
|
294 |
|
292 |
} finally { |
295 |
} finally { |
293 |
EFS.getLocalFileSystem().getStore(location).delete(EFS.NONE, null); |
296 |
EFS.getLocalFileSystem().getStore(location).delete(EFS.NONE, null); |
294 |
EFS.getLocalFileSystem().getStore(p2Location).delete(EFS.NONE, null); |
297 |
EFS.getLocalFileSystem().getStore(p2Location).delete(EFS.NONE, null); |
295 |
} |
298 |
} |
296 |
} |
299 |
} |
297 |
|
300 |
|
|
|
301 |
/* |
302 |
* Creates a file in the project's root. |
303 |
*/ |
304 |
public void testCreateFileChange1() throws Exception { |
305 |
String content= "hello"; |
306 |
|
307 |
IFile file= fProject.getProject().getFile("myFile.txt"); |
308 |
InputStream inputStream= new ByteArrayInputStream(content.getBytes()); |
309 |
|
310 |
Change undoChange= perform(new CreateFileChange(file, inputStream)); |
311 |
|
312 |
assertTrue(file.exists()); |
313 |
assertEquals(content, fProject.getContent(file)); |
314 |
|
315 |
perform(undoChange); |
316 |
|
317 |
assertFalse(file.exists()); |
318 |
} |
319 |
|
320 |
/* |
321 |
* Updates an existing file in the project's root. |
322 |
*/ |
323 |
public void testCreateFileChange2() throws Exception { |
324 |
String oldContent= "hi"; |
325 |
String newContent= "hello"; |
326 |
|
327 |
IFile file= fProject.createFile(fProject.getProject(), "myFile.txt", oldContent); |
328 |
InputStream inputStream= new ByteArrayInputStream(newContent.getBytes()); |
329 |
|
330 |
Change undoChange= perform(new CreateFileChange(file, inputStream)); |
331 |
|
332 |
assertTrue(file.exists()); |
333 |
assertEquals(newContent, fProject.getContent(file)); |
334 |
|
335 |
perform(undoChange); |
336 |
|
337 |
assertTrue(file.exists()); |
338 |
assertEquals(oldContent, fProject.getContent(file)); |
339 |
} |
340 |
|
341 |
/* |
342 |
* Updates an existing file in the project's root, but the overwrite flag |
343 |
* is set to false. |
344 |
*/ |
345 |
public void testCreateFileChange3() throws Exception { |
346 |
String oldContent= "hi"; |
347 |
String newContent= "hello"; |
348 |
|
349 |
IFile file= fProject.createFile(fProject.getProject(), "myFile.txt", oldContent); |
350 |
InputStream inputStream= new ByteArrayInputStream(newContent.getBytes()); |
351 |
|
352 |
Change change= new CreateFileChange(file, inputStream, false); |
353 |
assertTrue(change.isValid(null).hasFatalError()); |
354 |
} |
355 |
|
356 |
/* |
357 |
* Creates a file in a deep folder structure where some folders do not |
358 |
* exist yet. |
359 |
*/ |
360 |
public void testCreateFileChange4() throws Exception { |
361 |
String content= "hello"; |
362 |
|
363 |
IFolder existingFolder= fProject.createFolder("test"); |
364 |
IFolder newFolder1= existingFolder.getFolder("foo"); |
365 |
IFolder newFolder2= newFolder1.getFolder("bar"); |
366 |
IFile file= newFolder2.getFile("myFile.txt"); |
367 |
InputStream inputStream= new ByteArrayInputStream(content.getBytes()); |
368 |
|
369 |
Change undoChange= perform(new CreateFileChange(file, inputStream)); |
370 |
|
371 |
assertTrue(existingFolder.exists()); |
372 |
assertTrue(newFolder1.exists()); |
373 |
assertTrue(newFolder2.exists()); |
374 |
assertTrue(file.exists()); |
375 |
assertEquals(content, fProject.getContent(file)); |
376 |
|
377 |
perform(undoChange); |
378 |
|
379 |
assertFalse(file.exists()); |
380 |
assertFalse(newFolder2.exists()); |
381 |
assertFalse(newFolder1.exists()); |
382 |
assertTrue(existingFolder.exists()); |
383 |
} |
384 |
|
298 |
private Change perform(Change change) throws CoreException { |
385 |
private Change perform(Change change) throws CoreException { |
299 |
PerformChangeOperation op= new PerformChangeOperation(change); |
386 |
PerformChangeOperation op= new PerformChangeOperation(change); |
300 |
op.run(null); |
387 |
op.run(null); |
Lines 327-336
Link Here
|
327 |
assertTrue(res.getType() == source.getType()); |
414 |
assertTrue(res.getType() == source.getType()); |
328 |
|
415 |
|
329 |
if (res instanceof IFile) { |
416 |
if (res instanceof IFile) { |
330 |
assertTrue(content.equals(fProject.getContent((IFile) res))); |
417 |
assertTrue(content.equals(fProject.getContent((IFile)res))); |
331 |
} |
418 |
} |
332 |
return res; |
419 |
return res; |
333 |
} |
420 |
} |
334 |
|
|
|
335 |
|
421 |
|
336 |
} |
422 |
} |