From 8e6a4c82a49492e4944a7faaea7f37075a3067ad Mon Sep 17 00:00:00 2001 From: Henrik Lindberg Date: Tue, 12 May 2009 00:32:22 +0000 Subject: Added test server based tests --- .../p2/tests/repository/AllTestServerTests.java | 39 +++++++++++ .../p2/tests/repository/FileInfoReaderTest.java | 75 ++++++++++++++++++++++ .../p2/tests/repository/FileReaderTest.java | 54 ++++++++++++++++ 3 files changed, 168 insertions(+) create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTestServerTests.java create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileInfoReaderTest.java create mode 100644 bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/FileReaderTest.java (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository') 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 + // +} -- cgit v1.2.3