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

[198859] add/update the JUnit testcases for archive handlers.

This commit is contained in:
Xuan Chen 2007-08-04 16:03:52 +00:00
parent 7f4ceccfea
commit 9477539b58
7 changed files with 2181 additions and 280 deletions

View file

@ -18,7 +18,9 @@ Require-Bundle: org.junit,
org.eclipse.ui.views,
org.eclipse.rse.services;bundle-version="[2.0.0,3.0.0)",
org.eclipse.rse.services.files.ftp;bundle-version="[2.0.0,3.0.0)",
org.eclipse.rse.subsystems.files.ftp;bundle-version="[2.0.0,3.0.0)"
org.eclipse.rse.subsystems.files.ftp;bundle-version="[2.0.0,3.0.0)",
org.eclipse.core.filesystem,
org.eclipse.rse.files.ui
Eclipse-LazyStart: true
Bundle-RequiredExecutionEnvironment: J2SE-1.4
Export-Package: org.eclipse.rse.tests,

View file

@ -9,6 +9,7 @@
* David Dykstal (IBM) - initial contribution.
* Uwe Stieber (Wind River) - refactoring and cleanup.
* Martin Oberhuber (Wind River) - [184095] Replace systemTypeName by IRSESystemType
* Xuan Chen (IBM) - [198859] Update the API doc for getRemoteSystemConnection.
********************************************************************************/
package org.eclipse.rse.tests.core.connection;
@ -86,10 +87,14 @@ public class RSEBaseConnectionTestCase extends RSECoreTestCase {
}
/**
* Lookup and return the local system type connection. This connection
* should be usually available on all systems.
* Lookup/create and return the remote system connection according to the list of system parameters.
* @param systemTypeID The type id string of the remote system.
* @param systemAddress The address of the remote system.
* @param systemName The connection name.
* @param userID The user id used to logon to the remote system.
* @param password The password of the user id to logon to the remote system.
*
* @return The local system type connection or <code>null</code> if the lookup fails.
* @return The remote system connection or <code>null</code> if the lookup/creation fails.
*/
protected IHost getRemoteSystemConnection(String systemTypeID, String systemAddress, String systemName, String userID, String password) {

View file

@ -10,6 +10,8 @@
*******************************************************************************/
package org.eclipse.rse.tests.subsystems.files;
import junit.framework.TestSuite;
import org.eclipse.jface.preference.IPreferenceStore;
import org.eclipse.rse.core.IRSESystemType;
import org.eclipse.rse.core.model.IHost;
@ -20,22 +22,46 @@ import org.eclipse.rse.core.subsystems.ISubSystem;
import org.eclipse.rse.services.clientserver.messages.SystemMessageException;
import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
import org.eclipse.rse.ui.ISystemPreferencesConstants;
import org.eclipse.rse.ui.RSEUIPlugin;
public class FileServiceArchiveTestDStoreWindows extends FileServiceArchiveTest {
public static junit.framework.Test suite() {
TestSuite suite = new TestSuite("FileServiceArchiveTestDStoreWindows");
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyBatchToArchiveFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyBatchToVirtualFileLevelOne")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyBatchToVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyBatchVirtualFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyBatchVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyToArchiveFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyToVirtualFileLevelOne")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyToVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyVirtualBatchToArchiveFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyVirtualBatchToVirtualFileLevelOne")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyVirtualBatchToVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyVirtualFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCopyVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testCreateZipFile")); //$NON-NLS-1$
//suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testDeleteVirtualFileBigZip")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testMoveToArchiveFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testMoveToVirtualFileLevelOne")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testMoveToVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testMoveVirtualFile")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testMoveVirtualFileLevelTwo")); //$NON-NLS-1$
suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testRenameVirtualFile")); //$NON-NLS-1$
//suite.addTest(TestSuite.createTest(FileServiceArchiveTestDStoreWindows.class, "testRenameVirtualFileBigZip")); //$NON-NLS-1$
return suite;
}
public void setUp() {
//We need to delay if it is first case run after a workspace startup
SYSTEM_TYPE_ID = IRSESystemType.SYSTEMTYPE_WINDOWS_ID;
TMP_DIR_PARENT = "D:\\tmp\\junit_test\\";
ZIP_SOURCE_DIR = "D:\\tmp\\junit_source\\";
SYSTEM_ADDRESS = "LOCALHOST";
SYSTEM_NAME = "LOCALHOST_ds";
//We need to delay if it is first case run after a workspace startup
if (!classBeenRunBefore)
{
@ -67,7 +93,18 @@ public class FileServiceArchiveTestDStoreWindows extends FileServiceArchiveTest
fs = fss.getFileService();
}
}
try {
IHost localHost = getLocalSystemConnection();
sr = SystemStartHere.getSystemRegistry();
ss = sr.getServiceSubSystems(localHost, IFileService.class);
for (int i=0; i<ss.length; i++) {
if (ss[i] instanceof IFileServiceSubSystem) {
localFss = (IFileServiceSubSystem)ss[i];
}
}
try
{
IConnectorService connectionService = fss.getConnectorService();
//If you want to change the daemon to another port, uncomment following statements
/*
@ -92,17 +129,24 @@ public class FileServiceArchiveTestDStoreWindows extends FileServiceArchiveTest
fss.getSubSystemConfiguration().updateSubSystem(fss, false, "xuanchen", true, 4033);
}
*/
//End here.
connectionService.connect(mon);
tempDirPath = TMP_DIR_PARENT;
long currentTime = System.currentTimeMillis();
tempDir = createFileOrFolder(tempDirPath, "rsetest" + currentTime, true);
assertTrue(tempDir != null);
assertTrue(tempDir.exists());
assertTrue(tempDir.canRead());
assertTrue(tempDir.canWrite());
assertTrue(tempDir.isDirectory());
tempDirPath = tempDir.getAbsolutePath();
//Create a temparory directory in My Home
try
{
IRemoteFile homeDirectory = fss.getRemoteFileObject(".", mon);
String baseFolderName = "rsetest";
String homeFolderName = homeDirectory.getAbsolutePath();
String testFolderName = FileServiceHelper.getRandomLocation(fss, homeFolderName, baseFolderName, mon);
tempDir = createFileOrFolder(homeFolderName, testFolderName, true);
tempDirPath = tempDir.getAbsolutePath();
}
catch (Exception e)
{
fail("Problem encountered: " + e.getStackTrace().toString());
}
} catch(Exception e) {
assertTrue("Exception creating temp dir " + e.getStackTrace().toString(), false); //$NON-NLS-1$

View file

@ -7,13 +7,24 @@
*
* Contributors:
* Xuan Chen (IBM) - initial API and implementation
* - <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
* - <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
*******************************************************************************/
package org.eclipse.rse.tests.subsystems.files;
import java.io.ByteArrayInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.OutputStream;
import java.util.HashMap;
import org.eclipse.core.filesystem.EFS;
import org.eclipse.core.filesystem.IFileInfo;
import org.eclipse.core.filesystem.IFileStore;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.rse.services.clientserver.archiveutils.ArchiveHandlerManager;
import org.eclipse.rse.services.files.IFileService;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
@ -24,6 +35,7 @@ import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase;
public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
protected IFileServiceSubSystem fss;
protected IFileServiceSubSystem localFss;
protected IFileService fs;
protected IRemoteFile tempDir;
protected String tempDirPath;
@ -48,6 +60,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
return "a !@#${a}'` file%^&()_ =[]~+-;,."; //$NON-NLS-1$
}
public IRemoteFile copySourceFileOrFolder(String sourceFullName, String sourceName, String targetFolderFullName)
{
boolean ok = false;
@ -65,7 +78,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
//Need to call resolveFilterString of the parent to make sure the newly copied child
//is added to the DStore map. Otherwise, next time when query it, it will just created a
//default filter string. And the dstore server cannot handler it correctly.
Object[] children = fss.resolveFilterString(targetFolder, null, mon);
fss.resolveFilterString(targetFolder, null, mon);
}
catch(Exception e)
{
@ -99,7 +112,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
//Need to call resolveFilterString of the parent to make sure the newly created child
//is added to the DStore map. Otherwise, next time when query it, it will just created a
//default filter string. And the dstore server cannot handler it correctly.
Object[] children = fss.resolveFilterString(targetFolder, null, mon);
fss.resolveFilterString(targetFolder, null, mon);
}
catch (Exception e)
{
@ -141,6 +154,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
//We need to call getRemoteFileObject to get its attribute updated.
//Otherwise, will get error "directory not readable"
folderToCheck = fss.getRemoteFileObject(folderToCheck.getAbsolutePath(), mon);
System.out.println("verifying the contents for folder: " + folderToCheck.getAbsolutePath());
Object[] children = fss.resolveFilterString(folderToCheck, null, mon);
//Make sure the children array includes the copied folder.
HashMap childrenMap = new HashMap();
@ -154,7 +168,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
for (int i=0; i<names.length; i++)
{
IRemoteFile found = (IRemoteFile)(childrenMap.get(names[i]));
assertTrue(found != null);
assertTrue("Could not find " + names[i], found != null);
assertTrue(found.exists());
if (types != null && types.length != 0)
{
@ -192,9 +206,7 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
sep = '/';
parentFolderPath = parentFolderPath + ArchiveHandlerManager.VIRTUAL_SEPARATOR;
}
// hack by Phil to fix bug when trying to create file inside root "/"... it
// tried to create "//file.ext".
if ((parentFolderPath.length()==1) && (parentFolderPath.charAt(0)=='/') &&
(parentFolderPath.charAt(0)==sep))
newAbsName = sep + newName;
@ -202,5 +214,100 @@ public class FileServiceBaseTest extends RSEBaseConnectionTestCase {
newAbsName = parentFolderPath + sep + newName;
return newAbsName;
}
//----------------------------------------------------------------------
// <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
//----------------------------------------------------------------------
protected IFileStore createDir(IFileStore store, boolean clear) throws CoreException {
if (clear && store.fetchInfo().exists())
store.delete(EFS.NONE, null);
store.mkdir(EFS.NONE, null);
IFileInfo info = store.fetchInfo();
assertTrue("createDir.1", info.exists());
assertTrue("createDir.1", info.isDirectory());
return store;
}
//----------------------------------------------------------------------
// <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
//----------------------------------------------------------------------
protected IFileStore createDir(String string, boolean clear) throws CoreException {
return createDir(EFS.getFileSystem(EFS.SCHEME_FILE).getStore(new Path(string)), clear);
}
/**
* Create a file with random content. If a resource exists in the same path,
* the resource is deleted.
* <copied code from org.eclipse.core.tests.internal.localstore/LocalStoreTest (Copyright IBM)>
*
* @param target the file to create
* @param content content of the new file
* @throws CoreException
*/
protected void createFile(IFileStore target, String content) throws CoreException {
target.delete(EFS.NONE, null);
InputStream input = new ByteArrayInputStream(content.getBytes());
transferData(input, target.openOutputStream(EFS.NONE, null));
IFileInfo info = target.fetchInfo();
assertTrue(info.exists() && !info.isDirectory());
}
/**
* Copy the data from the input stream to the output stream.
* Close both streams when finished.
* <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
*
* @param input input stream
* @param output output stream
*/
protected void transferData(InputStream input, OutputStream output) {
try {
try {
int c = 0;
while ((c = input.read()) != -1)
output.write(c);
} finally {
input.close();
output.close();
}
} catch (IOException e) {
e.printStackTrace();
assertTrue(e.toString(), false);
}
}
/**
* Return String with some random text to use
* as contents for a file resource.
* <copied code from org.eclipse.core.tests.harness/CoreTest (Copyright IBM)>
*
* @return the result random string
*/
protected String getRandomString() {
switch ((int) Math.round(Math.random() * 10)) {
case 0 :
return "este e' o meu conteudo (portuguese)";
case 1 :
return "ho ho ho";
case 2 :
return "I'll be back";
case 3 :
return "don't worry, be happy";
case 4 :
return "there is no imagination for more sentences";
case 5 :
return "customize yours";
case 6 :
return "foo";
case 7 :
return "bar";
case 8 :
return "foobar";
case 9 :
return "case 9";
default :
return "these are my contents";
}
}
}

View file

@ -0,0 +1,86 @@
/*******************************************************************************
* Copyright (c) 2004, 2007 IBM Corporation 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:
* Xuan Chen (IBM) - copied and adapted from org.eclipse.core.tests.harness/FileSystemHelper
*******************************************************************************/
package org.eclipse.rse.tests.subsystems.files;
import java.io.IOException;
import org.eclipse.core.runtime.IPath;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.rse.subsystems.files.core.servicesubsystem.IFileServiceSubSystem;
import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile;
/**
* Home for file system-related utility methods.
*/
public class FileServiceHelper {
/** counter for generating unique random file system locations */
protected static int nextLocationCounter = 0;
private static final long MASK = 0x00000000FFFFFFFFL;
/*
* Return the root directory for the temp dir.
*/
public static IPath getTempDir() {
String tempPath = System.getProperty("java.io.tmpdir");
try {
tempPath = new java.io.File(tempPath).getCanonicalPath();
} catch (IOException e) {
//ignore and use non-canonical path
}
return new Path(tempPath);
}
/**
* Returns a unique location on the remote file system. It is guaranteed that no file currently
* exists at that location. The returned location will be unique with respect
* to all other locations generated by this method in the current session.
* If the caller creates a folder or file at this location, they are responsible for
* deleting it when finished.
* @param fss The FileServiceSubSystem where we want to get this location
* @param parentPath The path of the parent folder
* @param baseName the name where the calculated extension will be appended to
* @param mon Progress Monitor needed for necessary remote query
* @return the generated name of this location
*/
public static String getRandomLocation(IFileServiceSubSystem fss, String parentPath, String baseName, IProgressMonitor mon) {
String resultName = computeRandomLocation(fss, baseName);
try
{
IRemoteFile remoteFile = fss.getRemoteFileObject(parentPath + fss.getSeparator() + resultName, mon);
boolean fileExist = (remoteFile != null) && remoteFile.exists();
while (fileExist)
{
try
{
Thread.sleep(10);
} catch (InterruptedException e) {
// ignore
}
resultName = computeRandomLocation(fss, baseName);
remoteFile = fss.getRemoteFileObject(parentPath + fss.getSeparator() + resultName, mon);
fileExist = (remoteFile != null) && remoteFile.exists();
}
}
catch (Exception e)
{
return null;
}
return resultName;
}
public static String computeRandomLocation(IFileServiceSubSystem fss, String path) {
long segment = (((long) ++nextLocationCounter) << 32) | (System.currentTimeMillis() & MASK);
return path +(Long.toString(segment));
}
}