Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
Bug 144610 - Add test for import of nested projects
  • Loading branch information
mhurne authored and Matt Hurne committed May 25, 2012
1 parent b63a12f commit 3b2cc26
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 13 deletions.
Expand Up @@ -1676,4 +1676,14 @@ public void saveWidgetValues() {
public Button getCopyCheckbox() {
return copyCheckbox;
}

/**
* Method used for test suite.
*
* @return Button nested projects checkbox
*/
public Button getNestedProjectsCheckbox() {
return nestedProjectsCheckbox;
}

}
Expand Up @@ -60,6 +60,7 @@ public class ImportExistingProjectsWizardTest extends UITestCase {
private static final String DATA_PATH_PREFIX = "data/org.eclipse.datatransferArchives/";
private static final String WS_DATA_PREFIX = "data/workspaces";
private static final String WS_DATA_LOCATION = "importExistingFromDirTest";
private static final String WS_NESTED_DATA_LOCATION = "importExistingNestedTest";
private static final String ARCHIVE_HELLOWORLD = "helloworld";
private static final String ARCHIVE_FILE_WITH_EMPTY_FOLDER = "EmptyFolderInArchive";
private static final String PROJECTS_ARCHIVE = "ProjectsArchive";
Expand Down Expand Up @@ -117,7 +118,7 @@ protected void doTearDown() throws Exception {
super.doTearDown();
IWorkspaceRoot wsRoot = ResourcesPlugin.getWorkspace().getRoot();
IProject[] projects = wsRoot.getProjects();
for (int i = 0; i < projects.length; i++) {
for (int i = projects.length - 1; i >= 0; i--) {
FileUtil.deleteProject(projects[i]);
}
// clean up any data directories created
Expand Down Expand Up @@ -226,7 +227,7 @@ public void testFindSingleTar() {

public void testFindSingleDirectory() {
try {
dataLocation = copyDataLocation();
dataLocation = copyDataLocation(WS_DATA_LOCATION);
IPath wsPath = new Path(dataLocation).append("HelloWorld");
WizardProjectsImportPage wpip = getNewWizard();
HashSet projects = new HashSet();
Expand All @@ -251,7 +252,7 @@ public void testFindSingleDirectory() {

public void testDoNotShowProjectWithSameName() {
try {
dataLocation = copyDataLocation();
dataLocation = copyDataLocation(WS_DATA_LOCATION);
IPath wsPath = new Path(dataLocation);

FileUtil.createProject("HelloWorld");
Expand Down Expand Up @@ -502,7 +503,7 @@ public void testImportSingleDirectory() {
for (int i = 0; i < workspaceProjects.length; i++)
FileUtil.deleteProject(workspaceProjects[i]);

dataLocation = copyDataLocation();
dataLocation = copyDataLocation(WS_DATA_LOCATION);
wsPath = new Path(dataLocation).append("HelloWorld");
WizardProjectsImportPage wpip = getNewWizard();
HashSet projects = new HashSet();
Expand Down Expand Up @@ -551,7 +552,7 @@ public void testImportSingleDirectoryWithCopy() {
for (int i = 0; i < workspaceProjects.length; i++)
FileUtil.deleteProject(workspaceProjects[i]);

dataLocation = copyDataLocation();
dataLocation = copyDataLocation(WS_DATA_LOCATION);
wsPath = new Path(dataLocation).append("HelloWorld");
WizardProjectsImportPage wpip = getNewWizard();
HashSet projects = new HashSet();
Expand Down Expand Up @@ -604,7 +605,7 @@ public void testImportSingleDirectoryWithCopyDeleteProjectKeepContents() {
for (int i = 0; i < workspaceProjects.length; i++)
FileUtil.deleteProject(workspaceProjects[i]);

dataLocation = copyDataLocation();
dataLocation = copyDataLocation(WS_DATA_LOCATION);
wsPath = new Path(dataLocation).append("HelloWorld");
WizardProjectsImportPage wpip = getNewWizard();
HashSet projects = new HashSet();
Expand Down Expand Up @@ -802,12 +803,83 @@ public void testImportZipDeleteContentsImportAgain() {

}

public void testImportDirectoryNested() {
IPath wsPath = null;
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();

IProject[] workspaceProjects = root.getProjects();
for (int i = 0; i < workspaceProjects.length; i++) {
FileUtil.deleteProject(workspaceProjects[i]);
}

dataLocation = copyDataLocation(WS_NESTED_DATA_LOCATION);
wsPath = new Path(dataLocation).append("A");
WizardProjectsImportPage wpip = getNewWizard();
HashSet projects = new HashSet();
projects.add("A");
projects.add("B");
projects.add("C");

wpip.getProjectFromDirectoryRadio().setSelection(true);
wpip.getNestedProjectsCheckbox().setSelection(true);
wpip.getCopyCheckbox().setSelection(false);
wpip.saveWidgetValues();
wpip.restoreWidgetValues();

wpip.updateProjectsList(wsPath.toOSString());
ProjectRecord[] selectedProjects = wpip.getProjectRecords();
ArrayList projectNames = new ArrayList();
for (int i = 0; i < selectedProjects.length; i++) {
projectNames.add(selectedProjects[i].getProjectName());
}

assertTrue("Not all projects were found correctly in directory",
projectNames.containsAll(projects));

CheckboxTreeViewer projectsList = wpip.getProjectsList();
projectsList.setCheckedElements(selectedProjects);
wpip.createProjects(); // Try importing all the projects we found
waitForRefresh();

// "A", "B", and "C" should be the only projects in the workspace
workspaceProjects = root.getProjects();
if (workspaceProjects.length != 3) {
fail("Incorrect number of projects imported");
}

IFolder aFolder = workspaceProjects[0].getFolder("A");
if (aFolder.exists()) {
fail("Project A was imported as a folder into itself");
}

IFolder bFolder = workspaceProjects[1].getFolder("B");
if (bFolder.exists()) {
fail("Project B was imported as a folder into itself");
}

IFolder cFolder = workspaceProjects[2].getFolder("C");
if (cFolder.exists()) {
fail("Project C was imported as a folder into itself");
}

workspaceProjects[0].refreshLocal(IResource.DEPTH_INFINITE, null);

verifyProjectInWorkspace(false, workspaceProjects[0], FILE_LIST, true);
verifyProjectInWorkspace(false, workspaceProjects[1], FILE_LIST, true);
verifyProjectInWorkspace(false, workspaceProjects[2], FILE_LIST, true);
} catch (IOException e) {
fail(e.toString());
} catch (CoreException e) {
fail(e.toString());
}
}

public void testInitialValue() {

try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
zipLocation = copyZipLocation();
zipLocation = copyZipLocation(WS_DATA_LOCATION);
IProject[] workspaceProjects = root.getProjects();
for (int i = 0; i < workspaceProjects.length; i++)
FileUtil.deleteProject(workspaceProjects[i]);
Expand Down Expand Up @@ -841,7 +913,7 @@ public void testInitialValue() {
public void testImportArchiveMultiProject() {
try {
IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
zipLocation = copyZipLocation();
zipLocation = copyZipLocation(WS_DATA_LOCATION);

IProject[] workspaceProjects = root.getProjects();
for (int i = 0; i < workspaceProjects.length; i++)
Expand Down Expand Up @@ -931,7 +1003,7 @@ private void verifyProjectInWorkspace(final boolean inWorkspace,
if (!res.exists())
filesNotImported.append(res.getName() + ", ");
}
assertTrue("Files expected but not in workspace: "
assertTrue("Files expected but not in workspace for project \"" + project.getName() + "\": "
+ filesNotImported.toString(), filesNotImported.length() == 0);
}

Expand All @@ -940,14 +1012,14 @@ private void verifyProjectInWorkspace(final boolean inWorkspace,
*
* @return the location
*/
private String copyDataLocation() throws IOException {
private String copyDataLocation(String dataLocation) throws IOException {
TestPlugin plugin = TestPlugin.getDefault();
if (plugin == null)
throw new IllegalStateException(
"TestPlugin default reference is null");

URL fullPathString = plugin.getDescriptor().find(
new Path(WS_DATA_PREFIX).append(WS_DATA_LOCATION + ".zip"));
new Path(WS_DATA_PREFIX).append(dataLocation + ".zip"));

if (fullPathString == null)
throw new IllegalArgumentException();
Expand All @@ -966,14 +1038,14 @@ private String copyDataLocation() throws IOException {
return destination.getAbsolutePath();
}

private String copyZipLocation() throws IOException {
private String copyZipLocation(String zipLocation) throws IOException {
TestPlugin plugin = TestPlugin.getDefault();
if (plugin == null)
throw new IllegalStateException(
"TestPlugin default reference is null");

URL fullPathString = plugin.getDescriptor().find(
new Path(WS_DATA_PREFIX).append(WS_DATA_LOCATION + ".zip"));
new Path(WS_DATA_PREFIX).append(zipLocation + ".zip"));

if (fullPathString == null)
throw new IllegalArgumentException();
Expand Down
Binary file not shown.

0 comments on commit 3b2cc26

Please sign in to comment.