Skip to main content
aboutsummaryrefslogtreecommitdiffstats
blob: 41eae21f90594982cf5cd226f7366aa360c2e6b1 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
/*******************************************************************************
 * Copyright (c) 2009, 2010 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.*;
import java.net.*;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.internal.p2.transport.ecf.RepositoryTransport;
import org.eclipse.equinox.p2.tests.testserver.helper.AbstractTestServerClientCase;

/**
 * Tests FileReader.
 */
public class FileReaderTest extends AbstractTestServerClientCase {

	public void testUnknownHost() throws URISyntaxException {
		RepositoryTransport transport = new RepositoryTransport();
		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 = new RepositoryTransport();
		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"));
	}

	/**
	 * Tests a successful read.
	 */
	public void testReadStream() throws URISyntaxException, CoreException, IOException {
		RepositoryTransport transport = new RepositoryTransport();
		URI toDownload = new URI("http://localhost:8080/public/index.html");
		final NullProgressMonitor monitor = new NullProgressMonitor();
		InputStream stream = transport.stream(toDownload, monitor);
		stream.close();
		assertFalse("1.0", monitor.isCanceled());
	}

	/**
	 * Tests a successful read.
	 */
	public void testRead() throws URISyntaxException, CoreException, IOException {
		RepositoryTransport transport = new RepositoryTransport();
		URI toDownload = new URI("http://localhost:8080/public/index.html");
		OutputStream target = new ByteArrayOutputStream();
		final NullProgressMonitor monitor = new NullProgressMonitor();
		IStatus result = transport.download(toDownload, target, monitor);
		assertTrue("1.0", result.isOK());
	}
	// 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