From f02280993fde9f37c50ad077b7a9e5873a991c35 Mon Sep 17 00:00:00 2001 From: Martin Oberhuber < martin.oberhuber@windriver.com> Date: Tue, 3 Jun 2008 20:20:53 +0000 Subject: [PATCH] [tests] Add testGetRootProperties to FileServiceTest and make it run on local, ssh, ftpWindows, ftpLinux, dstoreLinux, dstoreWindows --- .../subsystems/files/FileServiceTest.java | 177 ++++++++++++------ 1 file changed, 122 insertions(+), 55 deletions(-) diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileServiceTest.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileServiceTest.java index dc723697d3f..e99c51b6ed7 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileServiceTest.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileServiceTest.java @@ -1,78 +1,118 @@ /******************************************************************************* * 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: + * 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) - [168975] Move RSE Events API to Core * Martin Oberhuber (Wind River) - [186128] Move IProgressMonitor last in all API - * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() + * Martin Oberhuber (Wind River) - [186640] Add IRSESystemType.testProperty() * Martin Oberhuber (Wind River) - organize, enable and tag test cases + * Martin Oberhuber (Wind River) - [235360][ftp][ssh] Return proper "Root" IHostFile *******************************************************************************/ package org.eclipse.rse.tests.subsystems.files; import java.io.File; -import java.io.IOException; +import java.lang.reflect.Method; + +import junit.framework.Test; +import junit.framework.TestSuite; import org.eclipse.core.runtime.IProgressMonitor; import org.eclipse.core.runtime.NullProgressMonitor; -import org.eclipse.rse.core.RSECorePlugin; import org.eclipse.rse.core.model.IHost; -import org.eclipse.rse.core.model.ISystemRegistry; -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.services.files.IHostFile; +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.RSETestsPlugin; import org.eclipse.rse.tests.core.connection.RSEBaseConnectionTestCase; public class FileServiceTest extends RSEBaseConnectionTestCase { + private String fPropertiesFileName; + // For testing the test: verify methods on Local + public static String fDefaultPropertiesFile = "local.properties"; + private IFileServiceSubSystem fss; private IFileService fs; - private File tempDir; + private IRemoteFile fHomeDirectory; + private IRemoteFile remoteTempDir; private String tempDirPath; private IProgressMonitor mon = new NullProgressMonitor(); - + + /** + * Constructor with specific test name. + * + * @param name test to execute + */ + public FileServiceTest(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 FileServiceTest(String name, String propertiesFileName) { + super(name); + fPropertiesFileName = propertiesFileName; + } + + public static Test suite() { + String baseName = FileServiceTest.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 = FileServiceTest.class.getMethods(); + for (int j = 0; j < m.length; j++) { + String testName = m[j].getName(); + if (testName.startsWith("test")) { + subSuite.addTest(new FileServiceTest(testName, propFileName)); + } + } + suite.addTest(subSuite); + } + return suite; + } + + public void setUp() throws Exception { super.setUp(); - IHost localHost = getLocalSystemConnection(); - ISystemRegistry sr = RSECorePlugin.getTheSystemRegistry(); - ISubSystem[] ss = sr.getServiceSubSystems(localHost, IFileService.class); - for (int i=0; i"; //$NON-NLS-1$ } //Fallback: Windows TODO: test unicode - return "a !@#${a}'` file%^&()_ =[]~+-;,."; //$NON-NLS-1$ + //Note: The trailing dot ('.') is really unfair on Windows because the file + //system doesn't seem to ever store trailing dots + //return "a !@#${a}'` file%^&()_ =[]~+-;,."; //$NON-NLS-1$ + return "a !@#${a}'` file%^&()_ =[]~+-;.,"; //$NON-NLS-1$ } - + + public void testGetRootProperties() throws Exception { + //-test-author-:MartinOberhuber + IHostFile[] roots = fs.getRoots(new NullProgressMonitor()); + assertNotNull(roots); + assertTrue(roots.length > 0); + for (int i = 0; i < roots.length; i++) { + assertTrue(roots[i].isRoot()); + assertTrue(roots[i].exists()); + assertNull(roots[i].getParentPath()); + String rootName = roots[i].getName(); + assertNotNull(rootName); + System.out.println(rootName); + IHostFile newHf = fs.getFile(null, rootName, new NullProgressMonitor()); + assertTrue(newHf.isRoot()); + assertTrue(newHf.exists()); + assertEquals(newHf.getName(), rootName); + newHf = fs.getFile("", rootName, new NullProgressMonitor()); + assertTrue(newHf.isRoot()); + assertTrue(newHf.exists()); + assertEquals(newHf.getName(), rootName); + } + } + public void testCaseSensitive() { //-test-author-:MartinOberhuber if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCaseSensitive")) return; //$NON-NLS-1$ - + if (isWindows()) { - assertFalse(fss.getSubSystemConfiguration().isCaseSensitive()); + assertFalse(fs.isCaseSensitive()); assertFalse(fss.isCaseSensitive()); - assertFalse(fs.isCaseSensitive()); //FAIL due to bug 168586 + assertFalse(fss.getSubSystemConfiguration().isCaseSensitive()); } else { - assertTrue(fss.getSubSystemConfiguration().isCaseSensitive()); - assertTrue(fss.isCaseSensitive()); //FAIL due to bug 168596 assertTrue(fs.isCaseSensitive()); + assertTrue(fss.isCaseSensitive()); + assertTrue(fss.getSubSystemConfiguration().isCaseSensitive()); } } - + public void testCreateFile() throws SystemMessageException { //-test-author-:MartinOberhuber if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateFile")) return; //$NON-NLS-1$ - + String testName = getTestFileName(); IHostFile hf = fs.createFile(tempDirPath, testName, mon); assertTrue(hf.exists()); @@ -112,16 +178,17 @@ public class FileServiceTest extends RSEBaseConnectionTestCase { assertEquals(hf.getSize(), 0); long modDate = hf.getModifiedDate(); assertTrue(modDate > 0); - - File theFile = new File(tempDir, testName); - assertTrue(theFile.exists()); - assertTrue(modDate == theFile.lastModified()); + if (fss.getHost().getSystemType().isLocal()) { + File theFile = new File(remoteTempDir.getAbsolutePath(), testName); + assertTrue(theFile.exists()); + assertTrue(modDate == theFile.lastModified()); + } } - + public void testCreateCaseSensitive() throws SystemMessageException { //-test-author-:MartinOberhuber if (!RSETestsPlugin.isTestCaseEnabled("FileServiceTest.testCreateCaseSensitive")) return; //$NON-NLS-1$ - + String testName = getTestFileName(); String testName2 = testName.toUpperCase(); IHostFile hf = fs.createFile(tempDirPath, testName, mon);