|
Added
Link Here
|
| 1 |
/******************************************************************************* |
| 2 |
* Copyright (c) 2012 IBM Corporation and others. |
| 3 |
* All rights reserved. This program and the accompanying materials |
| 4 |
* are made available under the terms of the Eclipse Public License v1.0 |
| 5 |
* which accompanies this distribution, and is available at |
| 6 |
* http://www.eclipse.org/legal/epl-v10.html |
| 7 |
* |
| 8 |
* Contributors: |
| 9 |
* IBM Corporation - initial API and implementation |
| 10 |
*******************************************************************************/ |
| 11 |
package org.eclipse.core.tests.resources.regression; |
| 12 |
|
| 13 |
import java.net.URI; |
| 14 |
import java.net.URISyntaxException; |
| 15 |
import java.util.*; |
| 16 |
import junit.framework.Test; |
| 17 |
import junit.framework.TestSuite; |
| 18 |
import org.eclipse.core.filesystem.EFS; |
| 19 |
import org.eclipse.core.resources.*; |
| 20 |
import org.eclipse.core.runtime.CoreException; |
| 21 |
import org.eclipse.core.tests.internal.filesystem.ram.MemoryTree; |
| 22 |
import org.eclipse.core.tests.internal.filesystem.remote.RemoteFileSystem; |
| 23 |
import org.eclipse.core.tests.resources.ResourceTest; |
| 24 |
|
| 25 |
/** |
| 26 |
* Test for bug 338792 |
| 27 |
*/ |
| 28 |
public class Bug_338792 extends ResourceTest { |
| 29 |
private static final String HOST_A = "hostA.example.com"; |
| 30 |
private static final String HOST_B = "hostB.example.com"; |
| 31 |
private static final String COMMON = "/common"; |
| 32 |
|
| 33 |
private static final String FOLDER_A = "/common/folderA"; |
| 34 |
private static final String FOLDER_B = "/common/folderB"; |
| 35 |
|
| 36 |
public static Test suite() { |
| 37 |
return new TestSuite(Bug_338792.class); |
| 38 |
} |
| 39 |
|
| 40 |
@Override |
| 41 |
protected void setUp() throws Exception { |
| 42 |
super.setUp(); |
| 43 |
MemoryTree.TREE.deleteAll(); |
| 44 |
} |
| 45 |
|
| 46 |
@Override |
| 47 |
protected void tearDown() throws Exception { |
| 48 |
MemoryTree.TREE.deleteAll(); |
| 49 |
super.tearDown(); |
| 50 |
} |
| 51 |
|
| 52 |
public void testBug() throws CoreException, URISyntaxException { |
| 53 |
URI commonA = new URI(RemoteFileSystem.SCHEME_REMOTE, HOST_A, COMMON, null); |
| 54 |
URI commonB = new URI(RemoteFileSystem.SCHEME_REMOTE, HOST_B, COMMON, null); |
| 55 |
URI folderA = new URI(RemoteFileSystem.SCHEME_REMOTE, HOST_A, FOLDER_A, null); |
| 56 |
URI folderB = new URI(RemoteFileSystem.SCHEME_REMOTE, HOST_B, FOLDER_B, null); |
| 57 |
|
| 58 |
final Set<URI> toVisit = new HashSet<URI>(); |
| 59 |
final int toVisitCount[] = new int[] {0}; |
| 60 |
IResourceVisitor visitor = new IResourceVisitor() { |
| 61 |
public boolean visit(IResource resource) { |
| 62 |
toVisit.remove(resource.getLocationURI()); |
| 63 |
toVisitCount[0]--; |
| 64 |
return true; |
| 65 |
} |
| 66 |
}; |
| 67 |
|
| 68 |
EFS.getStore(folderA).mkdir(EFS.NONE, null); |
| 69 |
EFS.getStore(folderB).mkdir(EFS.NONE, null); |
| 70 |
|
| 71 |
IWorkspace workspace = ResourcesPlugin.getWorkspace(); |
| 72 |
|
| 73 |
IProject projectA = workspace.getRoot().getProject("projectA"); |
| 74 |
ensureExistsInWorkspace(projectA, true); |
| 75 |
IFolder linkA = projectA.getFolder("link_to_commonA"); |
| 76 |
linkA.createLink(commonA, IResource.NONE, getMonitor()); |
| 77 |
|
| 78 |
IProject projectB = workspace.getRoot().getProject("projectB"); |
| 79 |
ensureExistsInWorkspace(projectB, true); |
| 80 |
IFolder linkB = projectB.getFolder("link_to_commonB"); |
| 81 |
linkB.createLink(commonB, IResource.NONE, getMonitor()); |
| 82 |
|
| 83 |
toVisit.addAll(Arrays.asList(new URI[] {projectA.getLocationURI(), commonA, folderA, projectA.getFile(".project").getLocationURI()})); |
| 84 |
toVisitCount[0] = 4; |
| 85 |
projectA.accept(visitor); |
| 86 |
assertTrue("1.1", toVisit.isEmpty()); |
| 87 |
assertEquals("1.2", 0, toVisitCount[0]); |
| 88 |
|
| 89 |
toVisit.addAll(Arrays.asList(new URI[] {projectB.getLocationURI(), commonB, folderB, projectB.getFile(".project").getLocationURI()})); |
| 90 |
toVisitCount[0] = 4; |
| 91 |
projectB.accept(visitor); |
| 92 |
assertTrue("2.1", toVisit.isEmpty()); |
| 93 |
assertEquals("2.2", 0, toVisitCount[0]); |
| 94 |
|
| 95 |
projectA.delete(true, getMonitor()); |
| 96 |
projectB.delete(true, getMonitor()); |
| 97 |
} |
| 98 |
} |