Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--tests/org.eclipse.team.tests.core/.classpath37
-rw-r--r--tests/org.eclipse.team.tests.core/.project1
-rw-r--r--tests/org.eclipse.team.tests.core/ftp.properties8
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTargetTests.java40
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/RemoteResourceTests.java100
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetProviderTests.java325
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetTestSetup.java96
-rw-r--r--tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java151
-rw-r--r--tests/org.eclipse.team.tests.core/webdav.properties7
9 files changed, 611 insertions, 154 deletions
diff --git a/tests/org.eclipse.team.tests.core/.classpath b/tests/org.eclipse.team.tests.core/.classpath
index b5763b2c4..bd3ae99ec 100644
--- a/tests/org.eclipse.team.tests.core/.classpath
+++ b/tests/org.eclipse.team.tests.core/.classpath
@@ -1,18 +1,19 @@
-<?xml version="1.0" encoding="UTF-8"?>
-<classpath>
- <classpathentry kind="src" path="src/"/>
- <classpathentry kind="src" path="/org.apache.xerces"/>
- <classpathentry kind="src" path="/org.eclipse.core.tests.harness"/>
- <classpathentry kind="src" path="/org.eclipse.core.resources"/>
- <classpathentry kind="src" path="/org.eclipse.team.core"/>
- <classpathentry kind="src" path="/org.eclipse.team.cvs.core"/>
- <classpathentry kind="src" path="/org.eclipse.team.ui"/>
- <classpathentry kind="src" path="/org.eclipse.team.cvs.ui"/>
- <classpathentry kind="src" path="/org.eclipse.compare"/>
- <classpathentry kind="src" path="/org.eclipse.ui"/>
- <classpathentry kind="src" path="/org.junit"/>
- <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.core.boot"/>
- <classpathentry kind="output" path="bin"/>
-</classpath>
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry kind="src" path="src/"/>
+ <classpathentry kind="src" path="/org.apache.xerces"/>
+ <classpathentry kind="src" path="/org.eclipse.core.tests.harness"/>
+ <classpathentry kind="src" path="/org.eclipse.core.resources"/>
+ <classpathentry kind="src" path="/org.eclipse.team.core"/>
+ <classpathentry kind="src" path="/org.eclipse.team.cvs.core"/>
+ <classpathentry kind="src" path="/org.eclipse.team.ui"/>
+ <classpathentry kind="src" path="/org.eclipse.team.cvs.ui"/>
+ <classpathentry kind="src" path="/org.eclipse.compare"/>
+ <classpathentry kind="src" path="/org.eclipse.ui"/>
+ <classpathentry kind="src" path="/org.junit"/>
+ <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.core.boot"/>
+ <classpathentry kind="src" path="/org.eclipse.team.webdav"/>
+ <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 5d3bdfef7..6b81026a4 100644
--- a/tests/org.eclipse.team.tests.core/.project
+++ b/tests/org.eclipse.team.tests.core/.project
@@ -13,6 +13,7 @@
<project>org.eclipse.team.cvs.core</project>
<project>org.eclipse.team.cvs.ui</project>
<project>org.eclipse.team.ui</project>
+ <project>org.eclipse.team.webdav</project>
<project>org.eclipse.ui</project>
<project>org.junit</project>
</projects>
diff --git a/tests/org.eclipse.team.tests.core/ftp.properties b/tests/org.eclipse.team.tests.core/ftp.properties
new file mode 100644
index 000000000..d2eb6c326
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/ftp.properties
@@ -0,0 +1,8 @@
+target=ftp
+test_dir=target
+location=ftp://ftp.server/path
+username=username
+password=password
+proxyURL=proxyURLIfThereIsOne
+connectionTimeout=6000
+passive=true \ No newline at end of file
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTargetTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTargetTests.java
new file mode 100644
index 000000000..34a86df30
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/AllTargetTests.java
@@ -0,0 +1,40 @@
+/*******************************************************************************
+ * 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 junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
+
+public class AllTargetTests extends EclipseWorkspaceTest {
+
+ /**
+ * Constructor for AllTargetTests.
+ */
+ public AllTargetTests() {
+ super();
+ }
+
+ /**
+ * Constructor for AllTargetTests.
+ * @param name
+ */
+ public AllTargetTests(String name) {
+ super(name);
+ }
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite();
+ suite.addTest(TargetProviderTests.suite());
+ suite.addTest(RemoteResourceTests.suite());
+ return new TargetTestSetup(suite);
+ }
+}
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/RemoteResourceTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/RemoteResourceTests.java
new file mode 100644
index 000000000..3eef2b1f8
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/RemoteResourceTests.java
@@ -0,0 +1,100 @@
+/*******************************************************************************
+ * 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.IOException;
+import java.io.InputStream;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.core.target.TargetProvider;
+
+/**
+ * A set of test cases for org.eclipse.team.core.sync.IRemoteResource
+ */
+public class RemoteResourceTests extends TeamTest {
+ public RemoteResourceTests() {
+ super();
+ }
+ public RemoteResourceTests(String name) {
+ super(name);
+ }
+ public static Test suite() {
+ TestSuite suite = new TestSuite(RemoteResourceTests.class);
+ return new TargetTestSetup(suite);
+ }
+
+ protected IProject createAndPut(String projectPrefix, String[] resourceNames) throws CoreException, TeamException {
+ IProject project = getUniqueTestProject(projectPrefix);
+ IResource[] resources = buildResources(project, resourceNames, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ return project;
+ }
+
+ public void testGetName() throws CoreException, TeamException {
+ IProject project = createAndPut("getname", new String[] { "file1.txt", "folder1/", "folder1/b.txt" });
+ TargetProvider target = getProvider(project);
+ IRemoteResource remote = target.getRemoteResource();
+ assertEquals(project.getName(), remote.getName());
+ }
+ public void testIsContainerSuccess() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("iscontainer");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ IRemoteResource remote = target.getRemoteResource();
+ assertTrue(remote.isContainer());
+ }
+ public void testIsContainerFail() throws CoreException, TeamException {
+ IProject project = createAndPut("iscontainer", new String[] { "file1.txt", "folder1/", "folder1/b.txt" });
+ TargetProvider target = getProvider(project);
+ IRemoteResource remote = target.getRemoteResourceFor(project.getFile("file1.txt"));
+ assertTrue(!remote.isContainer());
+ }
+ public void testGetContents() throws CoreException, TeamException {
+ IProject project = createAndPut("getname", new String[] { "file1.txt", "folder1/", "folder1/b.txt" });
+ TargetProvider target = getProvider(project);
+ IRemoteResource remote = target.getRemoteResourceFor(project.getFile("file1.txt"));
+ InputStream jin = remote.getContents(null);
+ try {
+ while (jin.available() > 0) {
+ jin.read();
+ }
+ } catch (IOException e) {
+ System.out.flush();
+ e.printStackTrace(System.err);
+ fail("Couldn't read from the input stream.");
+ }
+ }
+ public void testMembers() throws CoreException, TeamException {
+ IProject project = createAndPut("getname", new String[] { "file1.txt", "folder1/", "folder1/b.txt" });
+ TargetProvider target = getProvider(project);
+ IRemoteResource remote = target.getRemoteResource();
+ IRemoteResource[] altResources = remote.members(null);
+ for (int i = 0; i < altResources.length; i++) {
+ assertEquals(altResources[i], project.findMember(altResources[i].getName()));
+ }
+ }
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ properties=TargetTestSetup.properties;
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetProviderTests.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetProviderTests.java
index 9726604d2..e797f5c26 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetProviderTests.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetProviderTests.java
@@ -1,186 +1,241 @@
+/*******************************************************************************
+ * 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.InputStream;
import java.net.MalformedURLException;
import java.net.URL;
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.List;
-import java.util.Properties;
-import junit.extensions.TestSetup;
import junit.framework.Test;
import junit.framework.TestSuite;
-import org.eclipse.core.resources.IContainer;
-import org.eclipse.core.resources.IFile;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.Path;
import org.eclipse.team.core.TeamException;
-import org.eclipse.team.core.target.ISiteFactory;
-import org.eclipse.team.core.target.Site;
import org.eclipse.team.core.target.TargetManager;
import org.eclipse.team.core.target.TargetProvider;
+/**
+ * A set of test cases for org.eclipse.team.core.target.TargetProvider
+ */
public class TargetProviderTests extends TeamTest {
-
- final String test_url = "http://paris.ott.oti.com/dav/";
+
public TargetProviderTests() {
super();
}
-
public TargetProviderTests(String name) {
super(name);
}
-
public static Test suite() {
TestSuite suite = new TestSuite(TargetProviderTests.class);
- return new TestSetup(suite);
- //return new testSetup(new RepositoryProviderTests("test"));
+ return new TargetTestSetup(suite);
+ //return new TargetTestSetup(new TargetProviderTests("testPutAndGet"));
}
-
- Site getDavSite() {
- try {
- URL url = new URL(test_url);
- return TargetManager.getSite("org.eclipse.team.webdav", url);
- } catch (MalformedURLException e) {
- return null;
+ /**
+ * Tests the link between the target & the site for consistency.
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testProjectMapping() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("projectmapping");
+ TargetProvider target = createProvider(project);
+ assertTrue(getSite().equals(target.getSite()));
+ TargetManager.unmap(project);
+ assertNull(TargetManager.getProvider(project));
+ }
+ /**
+ * Tests the getURL() method on TargetProvider.
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testUrlRetrieval() throws CoreException, TeamException, MalformedURLException {
+ IProject project = getNamedTestProject("urlretrieval");
+ TargetManager.map(project, getSite(), new Path(properties.getProperty("test_dir")));
+ TargetProvider target = TargetManager.getProvider(project);
+ String goodurl =new URL(new URL(properties.getProperty("location")), properties.getProperty("test_dir")).toString();
+ assertEquals(goodurl, target.getURL().toString());
+ }
+ /**
+ * Verifies that the get() and put() methods on the TargetProvider works as expected.
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testPutAndGet() throws CoreException, TeamException {
+ // test put
+ IProject project = getUniqueTestProject("get");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ assertLocalEqualsRemote(project);
+ // test get on a new project
+ project.delete(true, true, null);
+ project.create(null);
+ project.open(null);
+ target = createProvider(project);
+ target.get(new IResource[] { project }, null);
+ assertLocalEqualsRemote(project);
+ }
+ /**
+ * Verifies that canGet() and canPut() returns accurate values.
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testCanGetAndCanPut() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("canget");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ for (int i = 0; i < resources.length; i++) {
+ assertTrue(target.canPut(resources[i]));
}
- }
-
- public IResource[] buildResources(IContainer container, String[] hierarchy, boolean includeContainer) throws CoreException {
- List resources = new ArrayList(hierarchy.length + 1);
- resources.addAll(Arrays.asList(buildResources(container, hierarchy)));
- if (includeContainer)
- resources.add(container);
- IResource[] result = (IResource[]) resources.toArray(new IResource[resources.size()]);
- ensureExistsInWorkspace(result, true);
- for (int i = 0; i < result.length; i++) {
- if (result[i].getType() == IResource.FILE)
- // 3786 bytes is the average size of Eclipse Java files!
- ((IFile) result[i]).setContents(getRandomContents(100), true, false, null);
+ target.put(resources, null);
+ project.delete(true, true, null);
+ project.create(null);
+ project.open(null);
+ target = createProvider(project);
+ for (int i = 0; i < resources.length; i++) {
+ assertTrue(target.canGet(resources[i]));
}
- return result;
+ target.get(new IResource[] { project }, null);
}
-
- protected static InputStream getRandomContents(int sizeAtLeast) {
- StringBuffer randomStuff = new StringBuffer(sizeAtLeast + 100);
- while (randomStuff.length() < sizeAtLeast) {
- randomStuff.append(getRandomSnippet());
+ /**
+ * Tests bahavior of isOutOfDate() for correctness
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testIsOutOfDate() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("outdated");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ sleep(1501);
+ IProject dupeProject = getUniqueTestProject("outdated");
+ IResource[] freshResources = buildResources(dupeProject, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetManager.map(dupeProject, getSite(), new Path(properties.getProperty("test_dir")).append(project.getName()));
+ TargetProvider dupeTarget = TargetManager.getProvider(dupeProject);
+ dupeTarget.put(freshResources, null);
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].getType() == IResource.FILE)
+ assertTrue(target.isOutOfDate(resources[i], DEFAULT_PROGRESS_MONITOR));
}
- return new ByteArrayInputStream(randomStuff.toString().getBytes());
}
-
- public static String getRandomSnippet() {
- switch ((int) Math.round(Math.random() * 10)) {
- case 0 :
- return "este e' o meu conteudo (portuguese)";
- case 1 :
- return "Dann brauchen wir aber auch einen deutschen Satz!";
- 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";
+ /**
+ * Tests bahavior of isDirty() for correctness
+ * @throws CoreException
+ * @throws TeamException
+ */
+ public void testIsDirty() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("dirty");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ sleep(1501);
+ resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].getType()==IResource.FILE) assertTrue(resources[i].getName(),target.isDirty(resources[i]));
}
}
-
- public void testWebDavProjectMapping() throws CoreException, TeamException {
- IProject project = getUniqueTestProject("webdav-projectmapping");
- TargetManager.map(project, getDavSite(), Path.EMPTY);
- TargetProvider target = TargetManager.getProvider(project);
- assertTrue(getDavSite().equals(target.getSite()));
-
- TargetManager.unmap(project);
- assertNull(TargetManager.getProvider(project));
+ public void testOverwrite() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("overwrite");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ target.put(resources, null);
+ //Create resources with the same names but different content & upload them in the same spot:
+ resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ target.put(resources, null);
+
+ IProject dupeProject = getUniqueTestProject("overwrite");
+ TargetManager.map(dupeProject, getSite(), new Path(properties.getProperty("test_dir")).append(project.getName()));
+ IResource[] freshResources = buildEmptyResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider dupeTarget = TargetManager.getProvider(dupeProject);
+ dupeTarget.get(new IResource[] { dupeProject }, null);
+ for (int i = 0; i < resources.length; i++) {
+ assertEquals(resources[i],freshResources[i]);
+ }
}
-
- public void testWebDavPut() throws CoreException, TeamException {
- IProject project = getUniqueTestProject("webdav-put");
- IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt"}, false);
-
- TargetManager.map(project, getDavSite(), new Path("noauth").append(project.getName()));
- TargetProvider target = TargetManager.getProvider(project);
-
+ public void testIsDirtyWhenDeleted() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("dirty");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
target.put(resources, null);
-
- TargetManager.unmap(project);
+ for (int i = 0; i < resources.length; i++) {
+ resources[i].delete(true, null);
+ }
+ sleep(1501);
+ resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ for (int i = 0; i < resources.length; i++) {
+ if (resources[i].getType()==IResource.FILE) assertTrue(resources[i].getName(),target.isDirty(resources[i]));
+ }
}
-
- public void testWebDavGet() throws CoreException, TeamException {
- IProject project = getUniqueTestProject("webdav-get");
- IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt"}, false);
-
- TargetManager.map(project, getDavSite(), new Path("noauth").append(project.getName()));
- TargetProvider target = TargetManager.getProvider(project);
-
+ public void testIsOutOfDateWhenDeleted() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("outdated");
+ IResource[] resources = buildResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
target.put(resources, null);
-
for (int i = 0; i < resources.length; i++) {
resources[i].delete(true, null);
}
-
+ sleep(1501);
+ IProject dupeProject = getUniqueTestProject("outdated");
+ IResource[] freshResources = buildResources(dupeProject, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetManager.map(dupeProject, getSite(), new Path(properties.getProperty("test_dir")).append(project.getName()));
+ TargetProvider dupeTarget = TargetManager.getProvider(dupeProject);
+ dupeTarget.put(freshResources, null);
for (int i = 0; i < resources.length; i++) {
- if(resources[i].getType() == IResource.FILE) {
- assertTrue(!project.getFile(resources[i].getName()).exists());
- } else {
- assertTrue(!project.getFolder(resources[i].getName()).exists());
- }
+ if (resources[i].getType() == IResource.FILE)
+ assertTrue(target.isOutOfDate(resources[i], DEFAULT_PROGRESS_MONITOR));
}
-
- target.get(new IResource[] {project}, null);
- project.refreshLocal(IResource.DEPTH_INFINITE, null);
- IResource[] members = project.members();
+ }
+ public void testPutWithPhantoms() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("put");
+ IResource[] resources = buildEmptyResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
for (int i = 0; i < resources.length; i++) {
- if(resources[i].getType() == IResource.FILE) {
- assertTrue(project.getFile(resources[i].getProjectRelativePath()).exists());
- } else {
- assertTrue(project.getFolder(resources[i].getProjectRelativePath()).exists());
- }
+ resources[i].delete(true, null);
+ }
+ try {
+ target.put(resources, null);
+ fail("Shouldn't be able to put files that don't exist locally.");
+ } catch (TeamException e) {} catch (RuntimeException e) {}
+ }
+ public void testGetWithPhantoms() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("get");
+ IResource[] resources = buildEmptyResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ try {
+ target.get(new IResource[] { project }, null);
+ fail("Shouldn't be able to get files that don't exist");
+ } catch (TeamException e) {}
+ }
+ public void testCanGetWithPhantoms() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("canget");
+ IResource[] resources = buildEmptyResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ for (int i = 0; i < resources.length; i++) {
+ assertTrue("Shouldn't be able to retrieve phantom resources.",!target.canGet(resources[i]));
+ }
+ }
+ public void testCanPutWithPhantoms() throws CoreException, TeamException {
+ IProject project = getUniqueTestProject("canput");
+ IResource[] resources = buildEmptyResources(project, new String[] { "file1.txt", "folder1/", "folder1/b.txt" }, false);
+ TargetProvider target = createProvider(project);
+ for (int i = 0; i < resources.length; i++) {
+ assertTrue("Shouldn't be able to upload phantom resources.",!target.canPut(resources[i]));
}
-
- TargetManager.unmap(project);
- assertNull(TargetManager.getProvider(project));
}
-
/**
* @see TestCase#setUp()
*/
protected void setUp() throws Exception {
super.setUp();
- ISiteFactory factory = TargetManager.getSiteFactory("org.eclipse.team.webdav");
- assertNotNull(factory);
- Properties properties = new Properties();
- properties.put("location", test_url);
- properties.put("httpClient.username", "myUsername");
- properties.put("httpClient.password", "myPassword");
- properties.put("httpClient.proxyURL", "");
- properties.put("httpClient.connectionTimeout", "2000");
-
- Site[] locations = TargetManager.getSites();
- Site location;
- if(locations.length == 0) {
- Site l = factory.newSite(properties);
- TargetManager.addSite(l);
- }
- location = getDavSite();
- TargetProvider target = location.newProvider(new Path("noauth"));
- assertNotNull(target);
+ properties=TargetTestSetup.properties;
}
-}
+} \ No newline at end of file
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetTestSetup.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetTestSetup.java
new file mode 100644
index 000000000..ef7083526
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TargetTestSetup.java
@@ -0,0 +1,96 @@
+/*******************************************************************************
+ * 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.*;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.*;
+
+import junit.extensions.TestSetup;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.core.resources.*;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.core.target.*;
+
+/**
+ * A set of test cases for org.eclipse.team.core.sync.IRemoteResource
+ */
+public class TargetTestSetup extends TestSetup {
+
+ public static Properties properties;
+ static {
+ loadProperties();
+ }
+
+ public static void loadProperties() {
+ properties = new Properties();
+ String propertiesFile = System.getProperty("eclipse.target.properties");
+ if (propertiesFile == null)
+ return;
+ File file = new File(propertiesFile);
+ if (file.isDirectory())
+ file = new File(file, "target.properties");
+ try {
+ BufferedReader reader = new BufferedReader(new FileReader(file));
+ try {
+ for (String line;(line = reader.readLine()) != null;) {
+ int sep = line.indexOf("=");
+ String property = line.substring(0, sep).trim();
+ String value = line.substring(sep + 1).trim();
+ properties.setProperty(property, value);
+ }
+ } finally {
+ reader.close();
+ }
+ } catch (Exception e) {
+ System.err.println("Could not read repository properties file: " + file.getAbsolutePath());
+ }
+ }
+
+ public TargetTestSetup(Test test) {
+ super(test);
+ }
+ /**
+ * Retrieves the Site object that the TargetProvider is contained in.
+ * @return Site
+ */
+ Site getSite() {
+ try {
+ URL url = new URL(properties.getProperty("location"));
+ return TargetManager.getSite(properties.getProperty("target"), url);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ /**
+ * @see TestCase#setUp()
+ */
+ protected void setUp() throws Exception {
+ super.setUp();
+ Site location;
+ ISiteFactory factory = TargetManager.getSiteFactory(properties.getProperty("target"));
+ assertNotNull(factory);
+ Site[] locations = TargetManager.getSites();
+
+ if (locations.length == 0) {
+ Site l = factory.newSite(properties);
+ TargetManager.addSite(l);
+ }
+ location = getSite();
+ TargetProvider target = location.newProvider(new Path(properties.getProperty("test_dir")));
+ assertNotNull(target);
+ }
+} \ No newline at end of file
diff --git a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
index feb37bffa..ac634c418 100644
--- a/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
+++ b/tests/org.eclipse.team.tests.core/src/org/eclipse/team/tests/core/TeamTest.java
@@ -1,12 +1,38 @@
package org.eclipse.team.tests.core;
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+import java.net.MalformedURLException;
+import java.net.URL;
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.List;
+import java.util.Properties;
+
+import org.eclipse.core.resources.IContainer;
+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.runtime.CoreException;
+import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.core.runtime.Path;
import org.eclipse.core.runtime.Status;
import org.eclipse.core.tests.harness.EclipseWorkspaceTest;
+import org.eclipse.team.core.TeamException;
+import org.eclipse.team.core.sync.IRemoteResource;
+import org.eclipse.team.core.target.Site;
+import org.eclipse.team.core.target.TargetManager;
+import org.eclipse.team.core.target.TargetProvider;
public class TeamTest extends EclipseWorkspaceTest {
+
+ protected static final IProgressMonitor DEFAULT_PROGRESS_MONITOR = new NullProgressMonitor();
+
+ Properties properties;
+
public TeamTest() {
super();
}
@@ -18,7 +44,7 @@ public class TeamTest extends EclipseWorkspaceTest {
IProject target = getWorkspace().getRoot().getProject(name);
if (!target.exists()) {
target.create(null);
- target.open(null);
+ target.open(null);
}
assertExistsInFileSystem(target);
return target;
@@ -32,4 +58,127 @@ public class TeamTest extends EclipseWorkspaceTest {
protected IStatus getTeamTestStatus(int severity) {
return new Status(severity, "org.eclipse.team.tests.core", 0, "team status", null);
}
+ /**
+ * Retrieves the Site object that the TargetProvider is contained in.
+ * @return Site
+ */
+ Site getSite() {
+ try {
+ URL url = new URL(properties.getProperty("location"));
+ return TargetManager.getSite(properties.getProperty("target"), url);
+ } catch (MalformedURLException e) {
+ return null;
+ }
+ }
+ /**
+ * Creates filesystem 'resources' with the given names and fills them with random text.
+ * @param container An object that can hold the newly created resources.
+ * @param hierarchy A list of files & folder names to use as resources
+ * @param includeContainer A flag that controls whether the container is included in the list of resources.
+ * @return IResource[] An array of resources filled with variable amounts of random text
+ * @throws CoreException
+ */
+ public IResource[] buildResources(IContainer container, String[] hierarchy, boolean includeContainer) throws CoreException {
+ List resources = new ArrayList(hierarchy.length + 1);
+ if (includeContainer)
+ resources.add(container);
+ resources.addAll(Arrays.asList(buildResources(container, hierarchy)));
+ IResource[] result = (IResource[]) resources.toArray(new IResource[resources.size()]);
+ ensureExistsInWorkspace(result, true);
+ for (int i = 0; i < result.length; i++) {
+ if (result[i].getType() == IResource.FILE) // 3786 bytes is the average size of Eclipse Java files!
+ ((IFile) result[i]).setContents(getRandomContents(100), true, false, null);
+ }
+ return result;
+ }
+ public IResource[] buildEmptyResources(IContainer container, String[] hierarchy, boolean includeContainer) throws CoreException {
+ List resources = new ArrayList(hierarchy.length + 1);
+ resources.addAll(Arrays.asList(buildResources(container, hierarchy)));
+ if (includeContainer)
+ resources.add(container);
+ IResource[] result = (IResource[]) resources.toArray(new IResource[resources.size()]);
+ ensureExistsInWorkspace(result, true);
+ return result;
+ }
+ /**
+ * Creates an InputStream filled with random text in excess of a specified minimum.
+ * @param sizeAtLeast The minimum number of chars to fill the input stream with.
+ * @return InputStream The input stream containing random text.
+ */
+ protected static InputStream getRandomContents(int sizeAtLeast) {
+ StringBuffer randomStuff = new StringBuffer(sizeAtLeast + 100);
+ while (randomStuff.length() < sizeAtLeast) {
+ randomStuff.append(getRandomSnippet());
+ }
+ return new ByteArrayInputStream(randomStuff.toString().getBytes());
+ }
+ /**
+ * Produces a random chunk of text from a finite collection of pre-written phrases.
+ * @return String Some random words.
+ */
+ public static String getRandomSnippet() {
+ switch ((int) Math.round(Math.random() * 10)) {
+ case 0 :
+ return "este e' o meu conteudo (portuguese)";
+ case 1 :
+ return "Dann brauchen wir aber auch einen deutschen Satz!";
+ 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";
+ }
+ }
+ public TargetProvider createProvider(IProject project) throws TeamException {
+ TargetManager.map(project, getSite(), new Path(properties.getProperty("test_dir")).append(project.getName()));
+ TargetProvider target = getProvider(project);
+ return target;
+ }
+
+ public TargetProvider getProvider(IProject project) throws TeamException {
+ return TargetManager.getProvider(project);
+ }
+
+ public void sleep(int ms) {
+ try {
+ Thread.currentThread().sleep(ms);
+ } catch (InterruptedException e) {
+ System.err.println("Testing was rudely interrupted.");
+ }
+ }
+ void assertLocalEqualsRemote(IProject project) throws CoreException, TeamException {
+ IProject newProject = getNamedTestProject("equals");
+ TargetProvider target = TargetManager.getProvider(project);
+ IResource[] localResources = project.members();
+ for (int i = 0; i < localResources.length; i++) {
+ assertEquals(target.getRemoteResourceFor(localResources[i]), localResources[i]);
+ }
+ }
+ // Assert that the two containers have equal contents
+ protected void assertEquals(IRemoteResource container1, IResource container2) throws CoreException, TeamException {
+ if (container2.getType() == IResource.FILE) {
+ // Ignore .project file
+ if (container2.getName().equals(".project")) return;
+ assertTrue(compareContent(container1.getContents(null), ((IFile) container2).getContents()));
+ } else {
+ IRemoteResource[] remoteResources = container1.members(null);
+ IResource[] localResources = ((IFolder) container2).members();
+ for (int i = 0; i < localResources.length; i++) {
+ assertEquals(remoteResources[i],localResources[i]);
+ }
+ }
+ }
}
diff --git a/tests/org.eclipse.team.tests.core/webdav.properties b/tests/org.eclipse.team.tests.core/webdav.properties
new file mode 100644
index 000000000..eb0c9c0ab
--- /dev/null
+++ b/tests/org.eclipse.team.tests.core/webdav.properties
@@ -0,0 +1,7 @@
+target=webdav
+test_dir=target
+location=http://web.dav.server/path
+httpClient.username=username
+httpClient.password=password
+httpClient.proxyURL=proxyURLIfThereIsOne
+httpClient.connectionTimeout=6000 \ No newline at end of file

Back to the top