Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorHenrik Lindberg2009-05-12 00:32:22 +0000
committerHenrik Lindberg2009-05-12 00:32:22 +0000
commit8e6a4c82a49492e4944a7faaea7f37075a3067ad (patch)
tree31f6b0868d48081e21302fe4e91dce2487e407f1 /bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository
parent439559ca7d13e6513f1960675d33bf5205b74b63 (diff)
downloadrt.equinox.p2-8e6a4c82a49492e4944a7faaea7f37075a3067ad.tar.gz
rt.equinox.p2-8e6a4c82a49492e4944a7faaea7f37075a3067ad.tar.xz
rt.equinox.p2-8e6a4c82a49492e4944a7faaea7f37075a3067ad.zip
Added test server based tests
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java39
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileInfoReaderTest.java75
-rw-r--r--bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java54
3 files changed, 168 insertions, 0 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java
new file mode 100644
index 000000000..8a97b4dc7
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java
@@ -0,0 +1,39 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Cloudsmith 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:
+ * Cloudsmith Inc - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.tests.repository;
+
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerSuite;
+
+public class AllTestServerTests extends AbstractTestServerSuite {
+
+ public AllTestServerTests(String testName) {
+ super(testName);
+ }
+
+ public static Test suite() throws Exception {
+ final TestSuite suite = new TestSuite("AllTestServerTests");
+ addToSuite(suite);
+ return suite;
+ }
+
+ public static void addToSuite(TestSuite suite) {
+ suite.addTest(new AbstractTestServerSuite("startServer"));
+
+ suite.addTestSuite(FileInfoReaderTest.class);
+ suite.addTestSuite(FileReaderTest.class);
+
+ suite.addTest(new AbstractTestServerSuite("stopServer"));
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileInfoReaderTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileInfoReaderTest.java
new file mode 100644
index 000000000..cbaeb7f90
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileInfoReaderTest.java
@@ -0,0 +1,75 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Cloudsmith 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:
+ * Cloudsmith Inc - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.tests.repository;
+
+import java.net.ConnectException;
+import java.net.URI;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.repository.AuthenticationFailedException;
+import org.eclipse.equinox.internal.p2.repository.RepositoryTransport;
+import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerClientCase;
+
+/**
+ * Tests FileInfoReader.
+ */
+public class FileInfoReaderTest extends AbstractTestServerClientCase {
+
+ public void testUnknownHost() throws Exception {
+ RepositoryTransport transport = RepositoryTransport.getInstance();
+ URI toDownload = new URI("http://bogus.nowhere/nothing.xml");
+ IStatus status = null;
+ try {
+ transport.getLastModified(toDownload, new NullProgressMonitor());
+ } catch (CoreException e) {
+ status = e.getStatus();
+ }
+ assertEquals("Should be an error", status.getSeverity(), IStatus.ERROR);
+ assertTrue("Should begin with 'Unknown Host'", status.getMessage().startsWith("Unknown Host"));
+ }
+
+ public void testBadPort() throws Exception {
+ RepositoryTransport transport = RepositoryTransport.getInstance();
+ URI toDownload = new URI("http://localhost:1/nothing.xml");
+ IStatus status = null;
+ try {
+ transport.getLastModified(toDownload, new NullProgressMonitor());
+ } catch (CoreException e) {
+ status = e.getStatus();
+ }
+
+ assertEquals("Should be an error", status.getSeverity(), IStatus.ERROR);
+ assertTrue("Should be a connect exception", status.getException() instanceof ConnectException);
+ assertTrue("Should begin with 'Connection refused'", status.getException().getMessage().startsWith("Connection refused"));
+ }
+
+ public void testRedirect() throws Exception {
+ this.setAladdinLoginService();
+ RepositoryTransport transport = RepositoryTransport.getInstance();
+ // apache http client accepts 100 redirects
+ URI toDownload = new URI(getBaseURL() + "/redirect/101/public/index.html");
+ boolean caught = false;
+ try {
+ transport.getLastModified(toDownload, new NullProgressMonitor());
+ } catch (AuthenticationFailedException e) {
+ caught = true;
+ } catch (Throwable t) {
+ failNotEquals("Wrong exception on 'redirected too many times'", AuthenticationFailedException.class, t.getClass());
+ t.printStackTrace();
+ }
+ assertTrue("Should have caught AuthenticationFailedException", caught);
+ }
+ // TODO: test
+ // timeout, cancel of timeout (TimeoutTest)
+ // bad date returned, very old, and in the future
+ // redirected many times = login
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java
new file mode 100644
index 000000000..cbdfab4cd
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java
@@ -0,0 +1,54 @@
+/*******************************************************************************
+ * Copyright (c) 2009 Cloudsmith 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:
+ * Cloudsmith Inc - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.equinox.p2.tests.repository;
+
+import java.io.ByteArrayOutputStream;
+import java.io.OutputStream;
+import java.net.*;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.equinox.internal.p2.repository.RepositoryTransport;
+import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerClientCase;
+
+/**
+ * Tests FileReader.
+ */
+public class FileReaderTest extends AbstractTestServerClientCase {
+
+ public void testUnknownHost() throws URISyntaxException {
+ RepositoryTransport transport = RepositoryTransport.getInstance();
+ URI toDownload = new URI("http://bogus.nowhere/nothing.xml");
+ OutputStream target = new ByteArrayOutputStream();
+ IStatus status = transport.download(toDownload, target, new NullProgressMonitor());
+
+ assertEquals("Should be an error", status.getSeverity(), IStatus.ERROR);
+ assertTrue("Should begin with 'Unknown Host'", status.getMessage().startsWith("Unknown Host"));
+ }
+
+ public void testBadPort() throws URISyntaxException {
+ RepositoryTransport transport = RepositoryTransport.getInstance();
+ URI toDownload = new URI("http://localhost:1/nothing.xml");
+ OutputStream target = new ByteArrayOutputStream();
+ IStatus status = transport.download(toDownload, target, new NullProgressMonitor());
+
+ assertEquals("Should be an error", status.getSeverity(), IStatus.ERROR);
+ assertTrue("Should be a connect exception", status.getException() instanceof ConnectException);
+ assertTrue("Should begin with 'Connection refused'", status.getException().getMessage().startsWith("Connection refused"));
+ }
+ // TODO: test
+ // timeout, cancel of timeout (TimeoutTest)
+ // bad date returned, very old, and in the future
+ // redirected many times = login
+
+ // handling of incorrect file size
+ //
+}

Back to the top