Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMichael Valenta2002-05-15 21:31:25 +0000
committerMichael Valenta2002-05-15 21:31:25 +0000
commitad7b094e181cfb593c53084802700d7702b7f09d (patch)
treea233313480fa151d0f731f4b82d95614ad5eff8a /tests/org.eclipse.team.tests.core
parent7f036f87efd92979679797069dfea83a6995d004 (diff)
downloadeclipse.platform.team-ad7b094e181cfb593c53084802700d7702b7f09d.tar.gz
eclipse.platform.team-ad7b094e181cfb593c53084802700d7702b7f09d.tar.xz
eclipse.platform.team-ad7b094e181cfb593c53084802700d7702b7f09d.zip
*** empty log message ***
Diffstat (limited to 'tests/org.eclipse.team.tests.core')
-rw-r--r--tests/org.eclipse.team.tests.core/.classpath1
-rw-r--r--tests/org.eclipse.team.tests.core/.project1
-rw-r--r--tests/org.eclipse.team.tests.core/plugin.xml21
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java1
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/StreamTests.java87
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/ClientTest.java8
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/FTPTestSetup.java36
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/TestApplication.java190
8 files changed, 334 insertions, 11 deletions
diff --git a/tests/org.eclipse.team.tests.core/.classpath b/tests/org.eclipse.team.tests.core/.classpath
index 1cdf36089..60fd55a00 100644
--- a/tests/org.eclipse.team.tests.core/.classpath
+++ b/tests/org.eclipse.team.tests.core/.classpath
@@ -14,5 +14,6 @@
<classpathentry kind="var" path="JRE_LIB" rootpath="JRE_SRCROOT" sourcepath="JRE_SRC"/>
<classpathentry kind="src" path="/org.eclipse.core.runtime"/>
<classpathentry kind="src" path="/org.eclipse.team.ftp"/>
+ <classpathentry kind="src" path="/org.eclipse.core.boot"/>
<classpathentry kind="output" path="bin"/>
</classpath>
diff --git a/tests/org.eclipse.team.tests.core/.project b/tests/org.eclipse.team.tests.core/.project
index 228a6b1a8..984829fd3 100644
--- a/tests/org.eclipse.team.tests.core/.project
+++ b/tests/org.eclipse.team.tests.core/.project
@@ -5,6 +5,7 @@
<projects>
<project>org.apache.xerces</project>
<project>org.eclipse.compare</project>
+ <project>org.eclipse.core.boot</project>
<project>org.eclipse.core.resources</project>
<project>org.eclipse.core.runtime</project>
<project>org.eclipse.core.tests.harness</project>
diff --git a/tests/org.eclipse.team.tests.core/plugin.xml b/tests/org.eclipse.team.tests.core/plugin.xml
index a404ca9da..b3c274ca5 100644
--- a/tests/org.eclipse.team.tests.core/plugin.xml
+++ b/tests/org.eclipse.team.tests.core/plugin.xml
@@ -15,10 +15,12 @@
<import plugin="org.apache.xerces"/>
<import plugin="org.eclipse.core.tests.harness"/>
<import plugin="org.eclipse.core.resources"/>
+ <import plugin="org.eclipse.core.boot"/>
<import plugin="org.eclipse.team.core"/>
<import plugin="org.eclipse.team.cvs.core"/>
<import plugin="org.eclipse.team.ui"/>
<import plugin="org.eclipse.team.cvs.ui"/>
+ <import plugin="org.eclipse.team.ftp"/>
<import plugin="org.eclipse.compare"/>
<import plugin="org.eclipse.ui"/>
<import plugin="org.junit"/>
@@ -43,6 +45,15 @@
</run>
</test>
</extension>
+ <extension
+ point="org.eclipse.core.tests.harness.tests">
+ <test
+ id="team.ftp">
+ <run
+ class="org.eclipse.team.tests.ftp.ClientTest">
+ </run>
+ </test>
+ </extension>
<extension
@@ -85,4 +96,14 @@
</one-of-nature>
</extension>
+ <extension
+ id="testapplication"
+ point="org.eclipse.core.runtime.applications">
+ <application>
+ <run
+ class="org.eclipse.team.tests.ftp.TestApplication">
+ </run>
+ </application>
+ </extension>
+
</plugin>
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java
index deabf4dd6..6b3edb2fc 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTeamTests.java
@@ -30,6 +30,7 @@ public class AllTeamTests extends EclipseWorkspaceTest {
public static Test suite() {
TestSuite suite = new TestSuite();
suite.addTest(RepositoryProviderTests.suite());
+ suite.addTest(StreamTests.suite());
return suite;
}
}
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/StreamTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/StreamTests.java
new file mode 100644
index 000000000..b423aebe3
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/StreamTests.java
@@ -0,0 +1,87 @@
+/*******************************************************************************
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM - Initial implementation
+ ******************************************************************************/
+package org.eclipse.team.tests.core;
+
+import java.io.ByteArrayInputStream;
+import java.io.IOException;
+import java.io.InputStream;
+
+import junit.framework.Test;
+import junit.framework.TestCase;
+import junit.framework.TestSuite;
+import org.eclipse.team.internal.core.streams.CRLFtoLFInputStream;
+import org.eclipse.team.internal.core.streams.LFtoCRLFInputStream;
+
+public class StreamTests extends TestCase {
+ private static final byte[] EMPTY_SEQ = new byte[] { };
+ private static final byte[] LF_SEQ = new byte[] { '\n' };
+ private static final byte[] CRLF_SEQ = new byte[] { '\r', '\n' };
+
+ public StreamTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ return new TestSuite(StreamTests.class);
+ }
+
+ public void testCRLFtoLFInputStream() throws IOException {
+ testCRLFtoLFTranslation("", "");
+ testCRLFtoLFTranslation("a", "a");
+ testCRLFtoLFTranslation("abc", "abc");
+ testCRLFtoLFTranslation("\n", "\n");
+ testCRLFtoLFTranslation("\r", "\r");
+ testCRLFtoLFTranslation("\r\n", "\n");
+ testCRLFtoLFTranslation("x\r\r\n\rx", "x\r\n\rx");
+ testCRLFtoLFTranslation("The \r\n quick brown \n fox \r\n\n\r\r\n jumped \n\n over \r\n the \n lazy dog.\r\n",
+ "The \n quick brown \n fox \n\n\r\n jumped \n\n over \n the \n lazy dog.\n");
+ }
+
+ private void testCRLFtoLFTranslation(String pre, String post) throws IOException {
+ ByteArrayInputStream bin = new ByteArrayInputStream(pre.getBytes());
+ InputStream in = new CRLFtoLFInputStream(bin);
+ InputStream inExpected = new ByteArrayInputStream(post.getBytes());
+ assertStreamEquals(inExpected, in);
+ }
+
+ public void testLFtoCRLFInputStream() throws IOException {
+ testLFtoCRLFTranslation("", "");
+ testLFtoCRLFTranslation("a", "a");
+ testLFtoCRLFTranslation("abc", "abc");
+ testLFtoCRLFTranslation("\n", "\r\n");
+ testLFtoCRLFTranslation("\r", "\r");
+ testLFtoCRLFTranslation("\r\n", "\r\r\n");
+ testLFtoCRLFTranslation("x\r\r\n\rx", "x\r\r\r\n\rx");
+ testLFtoCRLFTranslation("The \r\n quick brown \n fox \r\n\n\r\r\n jumped \n\n over \r\n the \n lazy dog.\r\n",
+ "The \r\r\n quick brown \r\n fox \r\r\n\r\n\r\r\r\n jumped \r\n\r\n over \r\r\n the \r\n lazy dog.\r\r\n");
+ }
+
+ private void testLFtoCRLFTranslation(String pre, String post) throws IOException {
+ ByteArrayInputStream bin = new ByteArrayInputStream(pre.getBytes());
+ InputStream in = new LFtoCRLFInputStream(bin);
+ InputStream inExpected = new ByteArrayInputStream(post.getBytes());
+ assertStreamEquals(inExpected, in);
+ }
+
+ private void assertStreamEquals(InputStream in1, InputStream in2) throws IOException {
+ try {
+ for (;;) {
+ int byte1 = in1.read();
+ int byte2 = in2.read();
+ assertEquals("Streams not equal", byte1, byte2);
+ if (byte1 == -1) break;
+ }
+ } finally {
+ in1.close();
+ in2.close();
+ }
+ }
+}
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/ClientTest.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/ClientTest.java
index ecfa571ef..7dc9f2908 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/ClientTest.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/ClientTest.java
@@ -17,7 +17,6 @@ import junit.framework.TestSuite;
import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.internal.ftp.FTPException;
-import org.eclipse.team.internal.ftp.FTPServerLocation;
import org.eclipse.team.internal.ftp.client.FTPClient;
import org.eclipse.team.tests.core.TeamTest;
@@ -46,12 +45,11 @@ public class ClientTest extends TeamTest {
}
public FTPClient openFTPConnection() throws FTPException {
- FTPServerLocation location = FTPServerLocation.fromURL(getURL(), false);
- FTPClient client = new FTPClient(location, null, null);
- client.open(DEFAULT_PROGRESS_MONITOR);
- return client;
+ return FTPTestSetup.openFTPConnection(getURL());
}
+
+
public void testCreateDirectory() throws FTPException {
FTPClient client = openFTPConnection();
try {
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/FTPTestSetup.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/FTPTestSetup.java
index 0c2c7ab68..c61853945 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/FTPTestSetup.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/FTPTestSetup.java
@@ -18,9 +18,12 @@ import java.io.FileReader;
import junit.extensions.TestSetup;
import junit.framework.Test;
+import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.team.internal.ftp.FTPException;
import org.eclipse.team.internal.ftp.FTPServerLocation;
import org.eclipse.team.internal.ftp.client.FTPClient;
+import org.eclipse.team.internal.ftp.client.IFTPClientListener;
/**
* Provides the FTP tests with a host to ftp to.
@@ -30,6 +33,8 @@ public class FTPTestSetup extends TestSetup {
public static final String FTP_URL;
public static final boolean SCRUB_URL;
+ private static final IProgressMonitor DEFAULT_PROGRESS_MONITOR = new NullProgressMonitor();
+
public static URL ftpURL;
// Static initializer for constants
@@ -86,12 +91,8 @@ public class FTPTestSetup extends TestSetup {
// is important for the UI tests.
URL url = new URL(urlString);
FTPServerLocation location = FTPServerLocation.fromURL(url, false);
- FTPClient client = new FTPClient(location, null, null);
- try {
- client.open(null);
- } finally {
- client.close(null);
- }
+ FTPClient client = openFTPConnection(url);
+ client.close(DEFAULT_PROGRESS_MONITOR);
// Initialize the repo if requested (requires rsh access)
if( SCRUB_URL ) {
@@ -104,4 +105,27 @@ public class FTPTestSetup extends TestSetup {
public void tearDown() {
// Nothing to do here
}
+
+ public static FTPClient openFTPConnection(URL url) throws FTPException {
+ FTPServerLocation location = FTPServerLocation.fromURL(url, false);
+ FTPClient client = new FTPClient(location, null, getListener());
+ client.open(DEFAULT_PROGRESS_MONITOR);
+ return client;
+ }
+
+ public static IFTPClientListener getListener() {
+ return new IFTPClientListener() {
+ public void responseReceived(int responseCode, String responseText) {
+ System.out.println(responseText);
+ }
+ public void requestSent(String command, String argument) {
+ if (argument != null) {
+ System.out.println(command + " " + argument);
+ } else {
+ System.out.println(command);
+ }
+ }
+ };
+ }
+
}
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/TestApplication.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/TestApplication.java
new file mode 100644
index 000000000..e65f1ff67
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/ftp/TestApplication.java
@@ -0,0 +1,190 @@
+/*******************************************************************************
+ * Copyright (c) 2002 IBM Corporation and others.
+ * All rights reserved. This program and the accompanying materials
+ * are made available under the terms of the Common Public License v0.5
+ * which accompanies this distribution, and is available at
+ * http://www.eclipse.org/legal/cpl-v05.html
+ *
+ * Contributors:
+ * IBM - Initial API and implementation
+ ******************************************************************************/
+package org.eclipse.team.tests.ftp;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStreamReader;
+import java.io.OutputStreamWriter;
+import java.io.PrintWriter;
+import java.util.StringTokenizer;
+
+import org.eclipse.core.boot.IPlatformRunnable;
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.ResourcesPlugin;
+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.team.internal.ftp.*;
+import org.eclipse.team.internal.ftp.FTPException;
+import org.eclipse.team.internal.ftp.FTPProxyLocation;
+import org.eclipse.team.internal.ftp.FTPServerLocation;
+import org.eclipse.team.internal.ftp.client.*;
+import org.eclipse.team.internal.ftp.client.FTPClient;
+import org.eclipse.team.internal.ftp.client.FTPCommunicationException;
+import org.eclipse.team.internal.ftp.client.FTPDirectoryEntry;
+import org.eclipse.team.internal.ftp.client.IFTPClientListener;
+
+public class TestApplication implements IPlatformRunnable {
+ protected PrintWriter out;
+ protected BufferedReader in;
+ protected FTPServerLocation location;
+ protected FTPProxyLocation proxy;
+ protected FTPClient client;
+ protected IFTPClientListener listener;
+ protected IProject project;
+
+ public Object run(Object args) {
+ /*** initialize ***/
+ out = new PrintWriter(new OutputStreamWriter(System.out), true);
+ in = new BufferedReader(new InputStreamReader(System.in));
+ listener = new IFTPClientListener() {
+ public void responseReceived(int responseCode, String responseText) {
+ out.println(responseText);
+ }
+ public void requestSent(String command, String argument) {
+ if (argument != null) {
+ out.println(command + " " + argument);
+ } else {
+ out.println(command);
+ }
+ }
+ };
+
+ // we'll dump downloaded files into
+ project = ResourcesPlugin.getWorkspace().getRoot().getProject("FTP-test");
+ try {
+ if (! project.exists()) {
+ project.create(null);
+ }
+ if (! project.isOpen()) {
+ project.open(null);
+ }
+ } catch (CoreException e) {
+ e.printStackTrace();
+ }
+
+ /*** run ***/
+ printHelp();
+ for (;;) {
+ String line;
+ try {
+ line = in.readLine();
+ } catch (IOException e) {
+ break;
+ }
+ StringTokenizer tok = new StringTokenizer(line);
+ if (! tok.hasMoreTokens()) continue;
+ String command = tok.nextToken().toLowerCase();
+ try {
+ if (command.equals("proxy") && tok.countTokens() >= 2 && tok.countTokens() <= 4) {
+ proxy = new FTPProxyLocation(
+ tok.nextToken(),
+ Integer.parseInt(tok.nextToken(), 10),
+ tok.hasMoreTokens() ? tok.nextToken() : null,
+ tok.hasMoreTokens() ? tok.nextToken() : null);
+ } else if (command.equals("open") && tok.countTokens() == 5) {
+ location = new FTPServerLocation(
+ tok.nextToken(),
+ Integer.parseInt(tok.nextToken(), 10),
+ tok.nextToken(),
+ tok.nextToken(),
+ tok.nextToken().equals("true"));
+ client = new FTPClient(location, proxy, listener);
+ client.open(getProgressMonitor());
+ } else if (command.equals("close")) {
+ client.close(getProgressMonitor());
+ } else if (command.equals("quit")) {
+ break;
+ } else if (command.equals("cd") && tok.countTokens() == 1) {
+ client.changeDirectory(tok.nextToken(), getProgressMonitor());
+ } else if (command.equals("ls") && tok.countTokens() == 0) {
+ FTPDirectoryEntry[] infos = client.listFiles(null, getProgressMonitor());
+ printFileList(infos);
+ } else if (command.equals("ls") && tok.countTokens() == 1) {
+ FTPDirectoryEntry[] infos = client.listFiles(tok.nextToken(), getProgressMonitor());
+ printFileList(infos);
+ } else if (command.equals("mkdir") && tok.countTokens() == 1) {
+ client.createDirectory(tok.nextToken(), getProgressMonitor());
+ } else if (command.equals("rmdir") && tok.countTokens() == 1) {
+ client.deleteDirectory(tok.nextToken(), getProgressMonitor());
+ } else if (command.equals("get") && tok.countTokens() == 3) {
+ String remoteFilePath = tok.nextToken();
+ boolean binary = tok.nextToken().equals("true");
+ boolean resume = tok.nextToken().equals("true");
+ IFile file = project.getFile(new Path(remoteFilePath).lastSegment());
+ client.getFile(remoteFilePath, file, binary, resume, getProgressMonitor());
+ } else if (command.equals("put") && tok.countTokens() == 2) {
+ String remoteFilePath = tok.nextToken();
+ boolean binary = tok.nextToken().equals("true");
+ IFile file = project.getFile(new Path(remoteFilePath).lastSegment());
+ client.putFile(remoteFilePath, file, binary, getProgressMonitor());
+ } else if (command.equals("rm") && tok.countTokens() == 1) {
+ client.deleteFile(tok.nextToken(), getProgressMonitor());
+ } else {
+ printHelp();
+ }
+ } catch (FTPException e) {
+ out.println("error: " + e.toString());
+ }
+ }
+ out.println("Terminated.");
+ return null;
+ }
+
+ private IProgressMonitor getProgressMonitor() {
+ return new NullProgressMonitor();
+ }
+
+ private void printHelp() {
+ out.println("--- Interactive Test FTP Client ---");
+ out.println("Commands:");
+ out.println(" proxy <hostname> <port> <username> <password>");
+ out.println(" open <hostname> <port> <username> <password> <passive true/false>");
+ out.println(" close");
+ out.println(" help");
+ out.println(" quit");
+ out.println(" cd <dir>");
+ out.println(" ls <dir>");
+ out.println(" mkdir <dir>");
+ out.println(" rmdir <dir>");
+ out.println(" get <file> <binary true/false> <resume true/false>");
+ out.println(" put <file> <binary true/false>");
+ out.println(" rm <file>");
+ out.println();
+ }
+
+ private void printFileList(FTPDirectoryEntry[] infos) {
+ for (int i = 0; i < infos.length; i++) {
+ FTPDirectoryEntry info = infos[i];
+ out.print(info.hasDirectorySemantics() ? "d" : "-");
+ out.print(info.hasFileSemantics() ? "f" : "-");
+ out.print(' ');
+ out.print(pad("\"" + info.getName() + "\"", 40));
+ out.print(' ');
+ out.print(pad(info.getSize() != info.UNKNOWN_SIZE ? Long.toString(info.getSize()) : "?", 12));
+ out.print(' ');
+ if (info.getModTime() != null) out.print(info.getModTime().toGMTString());
+ else out.println("?");
+ out.println();
+ }
+ }
+
+ private String pad(String string, int len) {
+ int count = len - string.length();
+ if (count <= 0) return string;
+ StringBuffer buf = new StringBuffer(string);
+ while (count-- > 0) buf.append(' ');
+ return buf.toString();
+ }
+}

Back to the top