1
0
Fork 0
mirror of https://github.com/eclipse-cdt/cdt synced 2025-07-16 13:35:22 +02:00

[185925] Add testcases for RSE Synchronization

This commit is contained in:
Martin Oberhuber 2009-02-08 22:42:18 +00:00
parent 4f99dfb0fa
commit 281f2d961e
4 changed files with 366 additions and 1 deletions

View file

@ -10,6 +10,7 @@ Require-Bundle: org.junit,
org.eclipse.core.runtime, org.eclipse.core.runtime,
org.eclipse.core.resources, org.eclipse.core.resources,
org.eclipse.core.filesystem, org.eclipse.core.filesystem,
org.eclipse.team.core,
org.eclipse.ui, org.eclipse.ui,
org.eclipse.ui.views, org.eclipse.ui.views,
org.eclipse.rse.core;bundle-version="[3.0.0,4.0.0)", org.eclipse.rse.core;bundle-version="[3.0.0,4.0.0)",
@ -22,6 +23,7 @@ Require-Bundle: org.junit,
org.eclipse.rse.services.files.ftp;bundle-version="[3.0.0,4.0.0)", org.eclipse.rse.services.files.ftp;bundle-version="[3.0.0,4.0.0)",
org.eclipse.rse.services.ssh;bundle-version="[3.0.0,3.1.0)", org.eclipse.rse.services.ssh;bundle-version="[3.0.0,3.1.0)",
org.eclipse.rse.subsystems.files.ftp;bundle-version="[2.1.0,3.0.0)", org.eclipse.rse.subsystems.files.ftp;bundle-version="[2.1.0,3.0.0)",
org.eclipse.rse.importexport;bundle-version="[1.2.0,1.3.0)",
org.eclipse.rse.files.ui, org.eclipse.rse.files.ui,
org.eclipse.rse.efs, org.eclipse.rse.efs,
org.eclipse.rse.tests.framework;bundle-version="[2.0.0,3.0.0)", org.eclipse.rse.tests.framework;bundle-version="[2.0.0,3.0.0)",

View file

@ -1,5 +1,5 @@
/******************************************************************************* /*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others. * Copyright (c) 2006, 2009 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials * All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0 * are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at * which accompanies this distribution, and is available at
@ -56,6 +56,7 @@ public class RSECombinedTestSuite extends DelegatingTestSuiteHolder {
suite.addTest(org.eclipse.rse.tests.subsystems.files.RSEFileSubsystemTestSuite.suite()); suite.addTest(org.eclipse.rse.tests.subsystems.files.RSEFileSubsystemTestSuite.suite());
suite.addTest(org.eclipse.rse.tests.subsystems.shells.RSEShellSubsystemTestSuite.suite()); suite.addTest(org.eclipse.rse.tests.subsystems.shells.RSEShellSubsystemTestSuite.suite());
suite.addTest(org.eclipse.rse.tests.subsystems.testsubsystem.RSETestSubsystemTestSuite.suite()); suite.addTest(org.eclipse.rse.tests.subsystems.testsubsystem.RSETestSubsystemTestSuite.suite());
suite.addTestSuite(org.eclipse.rse.tests.synchronize.RSESynchronizeTest.class);
suite.addTest(org.eclipse.rse.tests.ui.mnemonics.MnemonicsTestSuite.suite()); suite.addTest(org.eclipse.rse.tests.ui.mnemonics.MnemonicsTestSuite.suite());
suite.addTest(org.eclipse.rse.tests.ui.preferences.PreferencesTestSuite.suite()); suite.addTest(org.eclipse.rse.tests.ui.preferences.PreferencesTestSuite.suite());
// //Manual test below -- cannot be run in unattended builds // //Manual test below -- cannot be run in unattended builds

View file

@ -0,0 +1,139 @@
/*******************************************************************************
* Copyright (c) 2006, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Oberhuber (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - Adapted from org.eclipse.rse.tests / FileServiceTest
*******************************************************************************/
package org.eclipse.rse.tests.synchronize;
import java.lang.reflect.Method;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.rse.internal.synchronize.SynchronizeData;
import org.eclipse.rse.internal.synchronize.provisional.ISynchronizeConnectionManager;
import org.eclipse.rse.internal.synchronize.provisional.ISynchronizer;
import org.eclipse.rse.internal.synchronize.provisional.SynchronizeConnectionManager;
import org.eclipse.rse.internal.synchronize.provisional.SynchronizeOperation;
import org.eclipse.rse.internal.synchronize.provisional.Synchronizer;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
public class RSESynchronizeTest extends SynchronizeTestBase {
/**
* Constructor with specific test name.
*
* @param name test to execute
*/
public RSESynchronizeTest(String name) {
super(name);
}
/**
* Constructor with connection type and specific test name.
*
* @param name test to execute
* @param propertiesFileName file with connection properties to use
*/
public RSESynchronizeTest(String name, String propertiesFileName) {
super(name, propertiesFileName);
}
public static Test suite() {
String baseName = RSESynchronizeTest.class.getName();
TestSuite suite = new TestSuite(baseName);
// // Add a test suite for each connection type
// String[] connTypes = { "local", "ssh", "ftpWindows", "ftp", "linux",
// "windows" };
String[] connTypes = { "local" };
// String[] connTypes = { "ssh" };
for (int i = 0; i < connTypes.length; i++) {
String suiteName = connTypes[i] == null ? "EFS" : connTypes[i];
String propFileName = connTypes[i] == null ? null : connTypes[i] + "Connection.properties";
TestSuite subSuite = new TestSuite(baseName + "." + suiteName);
Method[] m = RSESynchronizeTest.class.getMethods();
for (int j = 0; j < m.length; j++) {
String testName = m[j].getName();
if (testName.startsWith("test")) {
subSuite.addTest(new RSESynchronizeTest(testName, propFileName));
}
}
suite.addTest(subSuite);
}
return suite;
}
public void testConnectDisconnect() throws Exception {
// -test-author-:MartinOberhuber
if (isTestDisabled())
return;
// Create a local test project with some files and folders in it
IProject project = getProject(getUniqueString());
IResource[] resources = new IResource[] { project };
ensureExistsInWorkspace(resources, true);
ISynchronizeConnectionManager connection = new SynchronizeConnectionManager();
assertTrue("1.1", !connection.isConnected(project));
// FIXME not a good idea to throw TeamException here -- this is the only
// reason why I need to import org.eclipse.team.core here
connection.connect(project);
assertTrue("1.2", connection.isConnected(project));
connection.disconnect(project);
assertTrue("1.3", !connection.isConnected(project));
// What happens if a connected project is deleted?
ensureDoesNotExistInWorkspace(project);
assertTrue("2.1", !connection.isConnected(project));
}
public void testExport() throws Exception {
// -test-author-:MartinOberhuber
if (isTestDisabled())
return;
// Create a local test project with some files and folders in it
IProject project = getProject(getUniqueString());
IFolder folder = project.getFolder("folder");
IFile file = project.getFile("file.txt");
IFile subFile = folder.getFile("subfile.txt");
IResource[] resources = new IResource[] { project, folder, file, subFile };
ensureExistsInWorkspace(resources, true);
// Initial export of test project to remote folder
SynchronizeData sd = new SynchronizeData();
// //What to do here?
// sd.addChild(new SynchronizeDataNode());
ISynchronizer synchronizer = new Synchronizer(sd);
synchronizer.run(new SynchronizeOperation());
// Check file files and folders exist on the remote
IRemoteFile rFolder = fss.getRemoteFileObject(remoteTempDir, "folder", getDefaultProgressMonitor());
assertTrue("1.1", rFolder.exists());
assertTrue("1.2", rFolder.isDirectory());
IRemoteFile rFile = fss.getRemoteFileObject(remoteTempDir, "file.txt", getDefaultProgressMonitor());
assertTrue("2.1", rFile.exists());
assertTrue("2.2", rFile.isFile());
IRemoteFile rSubFile = fss.getRemoteFileObject(rFolder, "subfile.txt", getDefaultProgressMonitor());
assertTrue("3.1", rSubFile.exists());
assertTrue("3.2", rSubFile.isFile());
// TODO: Check file contents, timestamp etc
}
}

View file

@ -0,0 +1,223 @@
/*******************************************************************************
* Copyright (c) 2000, 2008 Wind River Systems, Inc. and others.
* All rights reserved. This program and the accompanying materials
* are made available under the terms of the Eclipse Public License v1.0
* which accompanies this distribution, and is available at
* http://www.eclipse.org/legal/epl-v10.html
*
* Contributors:
* Martin Oberhuber (Wind River) - initial API and implementation
* Martin Oberhuber (Wind River) - Adapted from org.eclipse.rse.tests / FileServiceTest
* - Portions adapted from org.eclipse.core.tests.resources / ResourceTest
* - Portions adapted from org.eclipse.core.tests.harness / CoreTest
*******************************************************************************/
package org.eclipse.rse.tests.synchronize;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.OutputStream;
import java.io.PrintStream;
import org.eclipse.core.internal.utils.UniversalUniqueIdentifier;
import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.resources.IWorkspace;
import org.eclipse.core.resources.IWorkspaceRunnable;
import org.eclipse.core.resources.ResourcesPlugin;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
import org.eclipse.rse.core.model.IHost;
import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.subsystems.files.core.model.RemoteFileUtility;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
/**
* Base class for RSE Synchronization Tests. Contains utility methods copied
* from org.eclipse.core.resources.tests
*/
public class SynchronizeTestBase extends RSEBaseConnectionTestCase {
private String fPropertiesFileName;
// For testing the test: verify methods on Local
public static String fDefaultPropertiesFile = "localConnection.properties";
protected IFileServiceSubSystem fss;
protected IFileService fs;
private IRemoteFile fHomeDirectory;
protected IRemoteFile remoteTempDir;
private String tempDirPath;
/**
* Constructor with specific test name.
*
* @param name test to execute
*/
public SynchronizeTestBase(String name) {
this(name, fDefaultPropertiesFile);
}
/**
* Constructor with connection type and specific test name.
*
* @param name test to execute
* @param propertiesFileName file with connection properties to use
*/
public SynchronizeTestBase(String name, String propertiesFileName) {
super(name);
fPropertiesFileName = propertiesFileName;
if (propertiesFileName != null) {
int idx = propertiesFileName.indexOf("Connection.properties");
String targetName = propertiesFileName.substring(0, idx);
setTargetName(targetName);
}
}
public void setUp() throws Exception {
super.setUp();
IHost host = getHost(fPropertiesFileName);
fss = (IFileServiceSubSystem) RemoteFileUtility.getFileSubSystem(host);
fs = fss.getFileService();
fss.checkIsConnected(getDefaultProgressMonitor());
fHomeDirectory = fss.getRemoteFileObject(".", getDefaultProgressMonitor());
remoteTempDir = fss.getRemoteFileObject(fHomeDirectory, "rsetest" + System.currentTimeMillis(), getDefaultProgressMonitor());
fss.createFolder(remoteTempDir, getDefaultProgressMonitor());
tempDirPath = remoteTempDir.getAbsolutePath();
}
public void tearDown() throws Exception {
fss.delete(remoteTempDir, getDefaultProgressMonitor());
super.tearDown();
}
public boolean isWindows() {
return fss.getHost().getSystemType().isWindows();
}
public IProgressMonitor getMonitor() {
return getDefaultProgressMonitor();
}
public String getTempDirPath() {
return tempDirPath;
}
// <Copied from org.eclipse.core.tests.harness / CoreTest>
/**
* Fails the test due to the given throwable.
*/
public static void fail(String message, Throwable e) {
// If the exception is a CoreException with a multistatus
// then print out the multistatus so we can see all the info.
if (e instanceof CoreException) {
IStatus status = ((CoreException) e).getStatus();
//if the status does not have an exception, print the stack for this one
if (status.getException() == null)
e.printStackTrace();
write(status, 0);
} else
e.printStackTrace();
fail(message + ": " + e);
}
private static void write(IStatus status, int indent) {
PrintStream output = System.out;
indent(output, indent);
output.println("Severity: " + status.getSeverity());
indent(output, indent);
output.println("Plugin ID: " + status.getPlugin());
indent(output, indent);
output.println("Code: " + status.getCode());
indent(output, indent);
output.println("Message: " + status.getMessage());
if (status.getException() != null) {
indent(output, indent);
output.print("Exception: ");
status.getException().printStackTrace(output);
}
if (status.isMultiStatus()) {
IStatus[] children = status.getChildren();
for (int i = 0; i < children.length; i++)
write(children[i], indent + 1);
}
}
private static void indent(OutputStream output, int indent) {
for (int i = 0; i < indent; i++)
try {
output.write("\t".getBytes());
} catch (IOException e) {
// ignore
}
}
// </Copied from org.eclipse.core.tests.harness / CoreTest (Copyright (c) IBM)>
// <Copied from org.eclipse.core.tests.resources / ResourceTest (Copyright (c) IBM)>
public String getUniqueString() {
return new UniversalUniqueIdentifier().toString();
}
protected void create(final IResource resource, boolean local) throws CoreException {
if (resource == null || resource.exists())
return;
if (!resource.getParent().exists())
create(resource.getParent(), local);
switch (resource.getType()) {
case IResource.FILE :
((IFile) resource).create(local ? new ByteArrayInputStream(new byte[0]) : null, true, getMonitor());
break;
case IResource.FOLDER :
((IFolder) resource).create(true, local, getMonitor());
break;
case IResource.PROJECT :
((IProject) resource).create(getMonitor());
((IProject) resource).open(getMonitor());
break;
}
}
/**
* Create each element of the resource array in the workspace resource
* info tree.
*/
public void ensureExistsInWorkspace(final IResource[] resources, final boolean local) {
IWorkspaceRunnable body = new IWorkspaceRunnable() {
public void run(IProgressMonitor monitor) throws CoreException {
for (int i = 0; i < resources.length; i++)
create(resources[i], local);
}
};
try {
getWorkspace().run(body, null);
} catch (CoreException e) {
fail("#ensureExistsInWorkspace(IResource[])", e);
}
}
/**
* Delete the given resource from the workspace resource tree.
*/
public void ensureDoesNotExistInWorkspace(IResource resource) {
try {
if (resource.exists())
resource.delete(true, null);
} catch (CoreException e) {
fail("#ensureDoesNotExistInWorkspace(IResource): " + resource.getFullPath(), e);
}
}
// </Copied from org.eclipse.core.tests.resources / ResourceTest>
// <Copied from org.eclipse.core.tests.resources / ProjectPreferencesTest (Copyright (c) IBM)>
public static IWorkspace getWorkspace() {
return ResourcesPlugin.getWorkspace();
}
protected static IProject getProject(String name) {
return getWorkspace().getRoot().getProject(name);
}
// </Copied from org.eclipse.core.tests.resources / ProjectPreferencesTest (Copyright (c) IBM)>
}