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
|
/*******************************************************************************
* 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
}
|