Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Simplify test functionality for creating resource hierarchies #903 #914

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,11 +44,6 @@

public class FileSystemResourceManagerTest extends LocalStoreTest implements ICoreConstants {

@Override
public String[] defineHierarchy() {
return new String[] {"/Folder1/", "/Folder1/File1", "/Folder1/Folder2/", "/Folder1/Folder2/File2", "/Folder1/Folder2/Folder3/"};
}

@Test
public void testBug440110() throws Exception {
String projectName = getUniqueString();
Expand Down Expand Up @@ -168,7 +163,8 @@ public void testIsLocal() throws CoreException {
final IProject project = projects[0];

// create resources
IResource[] resources = buildResources(project, defineHierarchy());
IResource[] resources = buildResources(project, new String[] { "/Folder1/", "/Folder1/File1",
"/Folder1/Folder2/", "/Folder1/Folder2/File2", "/Folder1/Folder2/Folder3/" });
ensureExistsInWorkspace(resources, true);
ensureDoesNotExistInFileSystem(resources);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,6 @@ public void assertExistsInFileSystemWithNoContent(IFile target) {
assertTrue(existsInFileSystemWithNoContent(target));
}

@Override
public String[] defineHierarchy() {
return new String[] {"/File1", "/Folder1/", "/Folder1/File1", "/Folder1/Folder2/"};
}

private boolean existsInFileSystemWithNoContent(IResource resource) {
IPath path = resource.getLocation();
return path.toFile().exists() && path.toFile().length() == 0;
Expand All @@ -48,7 +43,8 @@ public void testProjectDeletion() throws CoreException {
TestingSupport.waitForSnapshot();

// create resources
IResource[] resources = buildResources(project, defineHierarchy());
IResource[] resources = buildResources(project,
new String[] { "/File1", "/Folder1/", "/Folder1/File1", "/Folder1/Folder2/" });
ensureExistsInWorkspace(resources, true);

// delete project's default directory
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,11 +42,6 @@
@RunWith(JUnit4.class)
public class MoveTest extends LocalStoreTest {

@Override
public String[] defineHierarchy() {
return new String[] {"/", "/file1", "/file2", "/folder1/", "/folder1/file3", "/folder1/file4", "/folder2/", "/folder2/file5", "/folder2/file6", "/folder1/folder3/", "/folder1/folder3/file7", "/folder1/folder3/file8"};
}

/**
* This test has Windows as the target OS. Drives C: and D: should be available.
*/
Expand Down Expand Up @@ -266,7 +261,9 @@ public void testMoveHierarchy() throws Exception {
ensureExistsInWorkspace(folderSource, true);

// create hierarchy
String[] hierarchy = defineHierarchy();
String[] hierarchy = new String[] { "/", "/file1", "/file2", "/folder1/", "/folder1/file3",
"/folder1/file4", "/folder2/", "/folder2/file5", "/folder2/file6", "/folder1/folder3/",
"/folder1/folder3/file7", "/folder1/folder3/file8" };
IResource[] resources = buildResources(folderSource, hierarchy);
ensureExistsInWorkspace(resources, true);

Expand Down Expand Up @@ -337,7 +334,9 @@ public void testMoveHierarchyBetweenProjects() throws Exception {
ensureExistsInWorkspace(folderSource, true);

// build hierarchy
String[] hierarchy = defineHierarchy();
String[] hierarchy = new String[] { "/", "/file1", "/file2", "/folder1/", "/folder1/file3", "/folder1/file4",
"/folder2/", "/folder2/file5", "/folder2/file6", "/folder1/folder3/", "/folder1/folder3/file7",
"/folder1/folder3/file8" };
IResource[] resources = buildResources(folderSource, hierarchy);
ensureExistsInWorkspace(resources, true);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -63,15 +63,6 @@ protected void assertEquals(String message, byte[] b1, byte[] b2) {
}
}

/**
* Return a string array which defines the hierarchy of a tree.
* Folder resources must have a trailing slash.
*/
@Override
public String[] defineHierarchy() {
return new String[] {"/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/"};
}

/*
* Internal method used for flushing all sync information for a particular resource
* and its children.
Expand All @@ -96,7 +87,9 @@ protected void flushAllSyncInfo(final IResource root) throws CoreException {
@Override
public void setUp() throws Exception {
super.setUp();
resources = createHierarchy();
resources = buildResources(getWorkspace().getRoot(),
new String[] { "/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/" });
ensureExistsInWorkspace(resources, true);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -58,9 +58,13 @@

public class IWorkspaceTest extends ResourceTest {

@Override
public String[] defineHierarchy() {
return new String[] {"/", "/Project/", "/Project/Folder/", "/Project/Folder/File",};
private IResource[] buildResourceHierarchy() throws CoreException {
return buildResources(getWorkspace().getRoot(),
new String[] { "/", "/Project/", "/Project/Folder/", "/Project/Folder/File", });
}

private void ensureResourceHierarchyExist() throws CoreException {
ensureExistsInWorkspace(buildResourceHierarchy(), true);
}

/**
Expand Down Expand Up @@ -96,7 +100,7 @@ public void testCancelRunnable() {
* See also testMultiCopy()
*/
public void testCopy() throws CoreException {
IResource[] resources = buildResources();
IResource[] resources = buildResourceHierarchy();
IProject project = (IProject) resources[1];
IFolder folder = (IFolder) resources[2];
IFile file = (IFile) resources[3];
Expand All @@ -113,7 +117,7 @@ public void testCopy() throws CoreException {
assertThrows(CoreException.class,
() -> getWorkspace().copy(new IResource[] { file }, folder.getFullPath(), false, getMonitor()));

createHierarchy();
ensureResourceHierarchyExist();

//copy to bogus destination
assertThrows(CoreException.class, () -> getWorkspace().copy(new IResource[] { file },
Expand Down Expand Up @@ -212,7 +216,7 @@ public void testCopy() throws CoreException {
* IStatus delete([IResource, boolean, IProgressMonitor)
*/
public void testDelete() throws CoreException {
IResource[] resources = buildResources();
IResource[] resources = buildResourceHierarchy();
IProject project = (IProject) resources[1];
IFolder folder = (IFolder) resources[2];
IFile file = (IFile) resources[3];
Expand All @@ -221,14 +225,14 @@ public void testDelete() throws CoreException {
assertTrue(getWorkspace().delete(new IResource[] {project, folder, file}, false, getMonitor()).isOK());
assertTrue(getWorkspace().delete(new IResource[] {file}, false, getMonitor()).isOK());
assertTrue(getWorkspace().delete(new IResource[] {}, false, getMonitor()).isOK());
createHierarchy();
ensureResourceHierarchyExist();

//delete existing resources
resources = new IResource[] {file, project, folder};
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
// assertDoesNotExistInFileSystem(resources);
assertDoesNotExistInWorkspace(resources);
createHierarchy();
ensureResourceHierarchyExist();
resources = new IResource[] {file};
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
assertDoesNotExistInFileSystem(resources);
Expand All @@ -238,7 +242,7 @@ public void testDelete() throws CoreException {
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
assertDoesNotExistInFileSystem(resources);
assertDoesNotExistInWorkspace(resources);
createHierarchy();
ensureResourceHierarchyExist();

//delete a combination of existing and non-existent resources
IProject fakeProject = getWorkspace().getRoot().getProject("pigment");
Expand All @@ -247,7 +251,7 @@ public void testDelete() throws CoreException {
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
// assertDoesNotExistInFileSystem(resources);
assertDoesNotExistInWorkspace(resources);
createHierarchy();
ensureResourceHierarchyExist();
resources = new IResource[] {fakeProject, file};
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
assertDoesNotExistInFileSystem(resources);
Expand All @@ -257,7 +261,7 @@ public void testDelete() throws CoreException {
assertTrue(getWorkspace().delete(resources, false, getMonitor()).isOK());
// assertDoesNotExistInFileSystem(resources);
assertDoesNotExistInWorkspace(resources);
createHierarchy();
ensureResourceHierarchyExist();
}

/**
Expand Down Expand Up @@ -542,7 +546,7 @@ public void testMove() throws CoreException {
*/
public void testMultiCopy() throws CoreException {
/* create common objects */
IResource[] resources = buildResources();
IResource[] resources = buildResourceHierarchy();
IProject project = (IProject) resources[1];
IFolder folder = (IFolder) resources[2];

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -170,19 +170,12 @@ public void createProblem(IResource host, int severity) throws CoreException {
marker.setAttribute(IMarker.SEVERITY, severity);
}

/**
* Return a string array which defines the hierarchy of a tree.
* Folder resources must have a trailing slash.
*/
@Override
public String[] defineHierarchy() {
return new String[] {"/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/"};
}

@Override
public void setUp() throws Exception {
super.setUp();
resources = createHierarchy();
resources = buildResources(getWorkspace().getRoot(),
new String[] { "/", "1/", "1/1", "1/2/", "1/2/1", "1/2/2/", "2/", "2/1", "2/2/", "2/2/1", "2/2/2/" });
ensureExistsInWorkspace(resources, true);

// disable autorefresh an wait till that is finished
IEclipsePreferences prefs = InstanceScope.INSTANCE.getNode(ResourcesPlugin.PI_RESOURCES);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -235,7 +235,6 @@ private String getExpectedMarkerMessage() {
}

private void buildAndWaitForBuildFinish() {
buildResources();
waitForBuild();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -265,18 +265,11 @@ public void assertExistsInWorkspace(IResource[] resources, boolean phantom) {
}
}

/**
* Return a collection of resources the hierarchy defined by defineHeirarchy().
*/
public IResource[] buildResources() {
return buildResources(getWorkspace().getRoot(), defineHierarchy());
}

/**
* Return a collection of resources for the given hierarchy at
* the given root.
*/
public IResource[] buildResources(IContainer root, String[] hierarchy) {
public IResource[] buildResources(IContainer root, String[] hierarchy) throws CoreException {
IResource[] result = new IResource[hierarchy.length];
for (int i = 0; i < hierarchy.length; i++) {
IPath path = IPath.fromOSString(hierarchy[i]);
Expand Down Expand Up @@ -425,27 +418,6 @@ public void createFileInFileSystem(IPath path, InputStream contents) throws Core
}
}

public IResource[] createHierarchy() throws CoreException {
IResource[] result = buildResources();
ensureExistsInWorkspace(result, true);
return result;
}

/**
* Returns a collection of string paths describing the standard
* resource hierarchy for this test. In the string forms, folders are
* represented as having trailing separators ('/'). All other resources
* are files. It is generally assumed that this hierarchy will be
* inserted under some project structure.
* For example,
* <pre>
* return new String[] {"/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1"};
* </pre>
*/
public String[] defineHierarchy() {
return new String[0];
}

/**
* Delete the given resource from the local store. Use the resource
* manager to ensure that we have a correct Path -&gt; File mapping.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,9 @@
* Test suites for {@link org.eclipse.core.internal.resources.PlatformURLResourceConnection}
*/
public class ResourceURLTest extends ResourceTest {
private final String[] resourcePaths = new String[] { "/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2",
"/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5" };

private static final String CONTENT = "content";
protected static IPath[] interestingPaths;
protected static IResource[] interestingResources;
Expand All @@ -56,18 +59,6 @@ private void checkURL(IResource resource) throws Throwable {
assertEquals(metric, file);
}

/**
* Returns a collection of string paths describing the standard
* resource hierarchy for this test. In the string forms, folders are
* represented as having trailing separators ('/'). All other resources
* are files. It is generally assumed that this hierarchy will be
* inserted under some solution and project structure.
*/
@Override
public String[] defineHierarchy() {
return new String[] {"/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2", "/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5"};
}

protected IProject getTestProject() {
return getWorkspace().getRoot().getProject("testProject");
}
Expand All @@ -85,7 +76,7 @@ private URL getURL(IResource resource) throws Throwable {
}

public void testBasicURLs() throws Throwable {
IResource[] resources = buildResources();
IResource[] resources = buildResources(getWorkspace().getRoot(), resourcePaths);
ensureExistsInWorkspace(resources, true);
for (IResource resource : resources) {
checkURL(resource);
Expand All @@ -98,15 +89,15 @@ public void testExternalURLs() throws Throwable {
desc.setLocation(Platform.getLocation().append("../testproject"));
project.create(desc, null);
project.open(null);
IResource[] resources = buildResources(project, defineHierarchy());
IResource[] resources = buildResources(project, resourcePaths);
ensureExistsInWorkspace(resources, true);
for (IResource resource : resources) {
checkURL(resource);
}
}

public void testNonExistantURLs() throws Throwable {
IResource[] resources = buildResources();
IResource[] resources = buildResources(getWorkspace().getRoot(), resourcePaths);
for (int i = 1; i < resources.length; i++) {
final int index = i;
assertThrows(IOException.class, () -> checkURL(resources[index]));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,18 +37,6 @@
* solution, project, folder and file.
*/
public class WorkspaceTest extends ResourceTest {
/**
* Returns a collection of string paths describing the standard
* resource hierarchy for this test. In the string forms, folders are
* represented as having trailing separators ('/'). All other resources
* are files. It is generally assumed that this hierarchy will be
* inserted under some solution and project structure.
*/
@Override
public String[] defineHierarchy() {
return new String[] {"/", "/1/", "/1/1", "/1/2", "/1/3", "/2/", "/2/1", "/2/2", "/2/3", "/3/", "/3/1", "/3/2", "/3/3", "/4/", "/5"};
}

protected IProject getTestProject() {
return getWorkspace().getRoot().getProject("testProject");
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,6 @@ private void addProblems(final int problemCount) {
}
}

@Override
public String[] defineHierarchy() {
//define a hierarchy with NUM_FOLDERS folders, NUM_FILES files.
String[] names = new String[NUM_FOLDERS * (FILES_PER_FOLDER + 1)];
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

import java.util.ArrayList;
import java.util.Collection;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IResourceVisitor;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IPath;
Expand All @@ -40,18 +41,18 @@ private Collection<String> createChildren(int breadth, int depth, IPath prefix)
return result;
}

@Override
public String[] defineHierarchy() {
private void createResourceHierarchy() throws CoreException {
int depth = 3;
int breadth = 3;
IPath prefix = IPath.fromOSString("/a/");
Collection<String> result = createChildren(breadth, depth, prefix);
result.add(prefix.toString());
return result.toArray(new String[0]);
IResource[] resources = buildResources(getWorkspace().getRoot(), result.toArray(new String[0]));
ensureExistsInWorkspace(resources, true);
}

public void test() throws CoreException {
createHierarchy();
createResourceHierarchy();
final QualifiedName key = new QualifiedName("local", getUniqueString());
final String value = getUniqueString();
IResourceVisitor visitor = resource -> {
Expand Down
Loading
Loading