blob: a6835a1de7ea2bfd2a1a93c4d1a4c364e50ef233 (
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
77
78
79
80
81
82
83
84
|
/*******************************************************************************
* Copyright (c) 2007, 2017 IBM Corporation and others.
*
* This program and the accompanying materials
* are made available under the terms of the Eclipse Public License 2.0
* which accompanies this distribution, and is available at
* https://www.eclipse.org/legal/epl-2.0/
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* IBM Corporation - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.tests.metadata.repository;
import java.io.File;
import java.net.URI;
import java.net.URISyntaxException;
import java.util.*;
import junit.framework.Test;
import junit.framework.TestSuite;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.equinox.internal.p2.metadata.repository.SimpleMetadataRepositoryFactory;
import org.eclipse.equinox.internal.p2.updatesite.metadata.UpdateSiteMetadataRepositoryFactory;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;
import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
/**
* Tests for API of {@link IMetadataRepositoryManager}.
*/
public class MetadataRepositoryManagerExceptionsTest extends AbstractProvisioningTest {
protected IMetadataRepositoryManager manager;
/**
* Contains temp File handles that should be deleted at the end of the test.
*/
private final List<File> toDelete = new ArrayList<>();
public static Test suite() {
return new TestSuite(MetadataRepositoryManagerExceptionsTest.class);
}
@Override
protected void setUp() throws Exception {
super.setUp();
manager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
}
@Override
protected void tearDown() throws Exception {
super.tearDown();
for (Iterator<File> it = toDelete.iterator(); it.hasNext();)
delete(it.next());
toDelete.clear();
}
/**
* Adds a repository for a non existing site, should
* return REPOSITORY_NOT_FOUND, since any other status code gets logged.
*
* @throws URISyntaxException
*/
public void testFailedConnection() throws URISyntaxException {
// URI location = new URI("invalid://example");
URI location = new URI("http://bogus.nowhere");
MetadataRepositoryFactory factory;
factory = new SimpleMetadataRepositoryFactory();
factory.setAgent(getAgent());
try {
factory.load(location, 0, new NullProgressMonitor());
} catch (ProvisionException e) {
assertEquals(ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode());
}
factory = new UpdateSiteMetadataRepositoryFactory();
try {
factory.load(location, 0, new NullProgressMonitor());
} catch (ProvisionException e) {
assertEquals(ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode());
}
}
}
|