From c79b571cca165d4430eafbac52d6cd04fb3f328a Mon Sep 17 00:00:00 2001 From: Kevin Doyle Date: Fri, 30 Nov 2007 20:52:59 +0000 Subject: [PATCH] Test case's for bugs: [208778] - [efs][api] RSEFileStore#getOutputStream() does not support EFS#APPEND [211374] - [ssh] New File on SSH has unnecessary space in its contents --- .../subsystems/files/CreateFileTestCase.java | 162 ++++++++++++++++++ ...ase.java => FileOutputStreamTestCase.java} | 48 ++++-- 2 files changed, 193 insertions(+), 17 deletions(-) create mode 100644 rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/CreateFileTestCase.java rename rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/{FileAppendOutputSteamTestCase.java => FileOutputStreamTestCase.java} (86%) diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/CreateFileTestCase.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/CreateFileTestCase.java new file mode 100644 index 00000000000..e52abab936e --- /dev/null +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/CreateFileTestCase.java @@ -0,0 +1,162 @@ +/******************************************************************************** +* Copyright (c) 2007 IBM Corporation. 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 +* +* Initial Contributors: +* The following IBM employees contributed to the Remote System Explorer +* component that contains this file: Kevin Doyle. +* +* Contributors: +* {Name} (company) - description of contribution. +********************************************************************************/ + +package org.eclipse.rse.tests.subsystems.files; + +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.jface.preference.IPreferenceStore; +import org.eclipse.rse.core.IRSESystemType; +import org.eclipse.rse.core.model.IHost; +import org.eclipse.rse.core.model.ISystemRegistry; +import org.eclipse.rse.core.model.SystemStartHere; +import org.eclipse.rse.core.subsystems.ISubSystem; +import org.eclipse.rse.services.files.IFileService; +import org.eclipse.rse.services.files.IHostFile; +import org.eclipse.rse.subsystems.files.core.servicesubsystem.FileServiceSubSystem; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFile; +import org.eclipse.rse.subsystems.files.core.subsystems.IRemoteFileSubSystem; +import org.eclipse.rse.ui.ISystemPreferencesConstants; +import org.eclipse.rse.ui.RSEUIPlugin; +import org.eclipse.rse.ui.internal.model.SystemRegistry; + +public class CreateFileTestCase extends FileServiceBaseTest { + + private String SYSTEM_ADDRESS = "sles8rm";//"SLES8RM"; + private String USER_ID = "xxxxxx"; + private String PASSWORD = "xxxxxx"; //"xxxxxx"; + private IHost host; + //TODO: See if additional characters in the name should work. + // Also make sure if there are that they can be entered in the New + // File Dialog. This string can be so using this for base test. + private String fileName = "a !@#${a}'%^&()_ =[]~+-'`;,.txt"; //$NON-NLS-1$ + private IRemoteFile tempDirectory = null; + + private IRemoteFileSubSystem getRemoteFileSubSystem(IHost host) { + IRemoteFileSubSystem fss = null; + ISystemRegistry sr = SystemStartHere.getSystemRegistry(); + ISubSystem[] ss = sr.getServiceSubSystems(host, IFileService.class); + for (int i=0; i 0); + + // perform cleanup, so EFS uses the right file service next time + cleanup(); + } + + public void cleanup() throws Exception { + if (host != null) { + if (tempDirectory != null) { + IRemoteFileSubSystem fss = getRemoteFileSubSystem(host); + fss.delete(tempDirectory, new NullProgressMonitor()); + fss.disconnect(); + tempDirectory = null; + } + SystemRegistry.getInstance().deleteHost(host); + host = null; + } + } + + public void tearDown() throws Exception { + cleanup(); + super.tearDown(); + } +} + diff --git a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileAppendOutputSteamTestCase.java b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileOutputStreamTestCase.java similarity index 86% rename from rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileAppendOutputSteamTestCase.java rename to rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileOutputStreamTestCase.java index de1b77fd21d..8fa62cb443a 100644 --- a/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileAppendOutputSteamTestCase.java +++ b/rse/tests/org.eclipse.rse.tests/src/org/eclipse/rse/tests/subsystems/files/FileOutputStreamTestCase.java @@ -37,7 +37,7 @@ import org.eclipse.rse.ui.ISystemPreferencesConstants; import org.eclipse.rse.ui.RSEUIPlugin; import org.eclipse.rse.ui.internal.model.SystemRegistry; -public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { +public class FileOutputStreamTestCase extends FileServiceBaseTest { private String SYSTEM_ADDRESS = "sles8rm";//"SLES8RM"; private String USER_ID = "xxxxxx"; @@ -116,22 +116,34 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { } public void testRSEFileStoreAppendOutputStream() throws Exception { - // Go through each connection type setting it up and calling - // appendToOutputStream(host) host = getLocalHost(); - appendToOutputStream(); + outputStreamFileWriting(EFS.APPEND); host = getFTPHost(); - appendToOutputStream(); + outputStreamFileWriting(EFS.APPEND); host = getDStoreHost(); - appendToOutputStream(); + outputStreamFileWriting(EFS.APPEND); host = getSSHHost(); - appendToOutputStream(); + outputStreamFileWriting(EFS.APPEND); } - public void appendToOutputStream() throws Exception { + public void testRSEFileStoreOverwriteOutputStream() throws Exception { + host = getLocalHost(); + outputStreamFileWriting(EFS.NONE); + + host = getFTPHost(); + outputStreamFileWriting(EFS.NONE); + + host = getDStoreHost(); + outputStreamFileWriting(EFS.NONE); + + host = getSSHHost(); + outputStreamFileWriting(EFS.NONE); + } + + public void outputStreamFileWriting(int options) throws Exception { // RSE URI: rse://SYSTEM_ADDRESS/PATH_TO_FIlE OutputStream outputStream = null; InputStream inputStream = null; @@ -160,9 +172,8 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { IFileStore childFS = parentFS.getChild("append.txt"); - outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor()); - - // Append to an empty file + outputStream = childFS.openOutputStream(options, new NullProgressMonitor()); + String contents = getRandomString(); byte[] readBytes = new byte[contents.length()]; outputStream.write(contents.getBytes()); @@ -173,13 +184,16 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { String input = new String(readBytes); inputStream.close(); - assertTrue(systemType + ": Contents incorrect when appending to an empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input)); + assertTrue(systemType + ": Contents incorrect writing to an empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input)); - outputStream = childFS.openOutputStream(EFS.APPEND, new NullProgressMonitor()); + outputStream = childFS.openOutputStream(options, new NullProgressMonitor()); - // Append to a not empty file String write = " " + getRandomString(); - contents += write; + if ((options & EFS.APPEND) != 0) { + contents += write; + } else { + contents = write; + } outputStream.write(write.getBytes()); outputStream.close(); @@ -189,7 +203,7 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { input = new String(readBytes); inputStream.close(); - assertTrue(systemType + ": Contents incorrect when appending to a non-empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input)); + assertTrue(systemType + ": Contents incorrect writing to a non-empty file. Expected Contents: " + contents + " Actual Contents: " + input, contents.equals(input)); // Cleanup, so IFileStore uses the correct connection next time. cleanup(); } @@ -239,4 +253,4 @@ public class FileAppendOutputSteamTestCase extends FileServiceBaseTest { cleanup(); super.tearDown(); } -} +} \ No newline at end of file