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
|
/*******************************************************************************
* Copyright (c) 2012 SAP AG 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:
* SAP AG - initial API and implementation
*******************************************************************************/
package org.eclipse.equinox.p2.tests.repository;
import static org.hamcrest.CoreMatchers.sameInstance;
import static org.junit.Assert.assertThat;
import java.net.URI;
import java.util.Map;
import org.eclipse.core.runtime.*;
import org.eclipse.equinox.p2.core.ProvisionException;
import org.eclipse.equinox.p2.repository.artifact.IArtifactRepository;
import org.eclipse.equinox.p2.repository.artifact.spi.ArtifactRepositoryFactory;
import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
import org.eclipse.equinox.p2.repository.metadata.spi.MetadataRepositoryFactory;
import org.eclipse.equinox.p2.tests.*;
public class RepositoryExtensionPointTest extends AbstractProvisioningTest {
/**
* A non-URL URI, e.g. for identifying a repository in a registry.
*/
static URI repositoryKey = URI.create("testregistry:repo");
static IMetadataRepository metadataRepositoryInstance = new TestMetadataRepository(getAgent());
static IArtifactRepository artifactRepositoryInstance = new TestArtifactRepository(getAgent(), repositoryKey);
public static class TestMetadataRepositoryRegistry extends MetadataRepositoryFactory {
@Override
public IMetadataRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException {
// none of the codes defined in ProvisionException really fit
int errorCode = 0;
Status status = new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, errorCode, "Creating repositories of type " + type + " is not supported", null);
throw new ProvisionException(status);
}
@Override
public IMetadataRepository load(URI location, int flags, IProgressMonitor monitor) {
if (repositoryKey.equals(location)) {
return metadataRepositoryInstance;
}
return null;
}
}
public static class TestArtifactRepositoryRegistry extends ArtifactRepositoryFactory {
@Override
public IArtifactRepository create(URI location, String name, String type, Map<String, String> properties) throws ProvisionException {
// none of the codes defined in ProvisionException really fit
int errorCode = 0;
Status status = new Status(IStatus.ERROR, TestActivator.PI_PROV_TESTS, errorCode, "Creating repositories of type " + type + " is not supported", null);
throw new ProvisionException(status);
}
@Override
public IArtifactRepository load(URI location, int flags, IProgressMonitor monitor) {
if (repositoryKey.equals(location)) {
return artifactRepositoryInstance;
}
return null;
}
}
public void testLoadMetadataRepositoryFromURIWithCustomScheme() throws Exception {
IMetadataRepository repo = loadMetadataRepository(repositoryKey);
assertThat(repo, sameInstance(metadataRepositoryInstance));
}
public void testLoadArtifactRepositoryFromURIWithCustomScheme() throws Exception {
IArtifactRepository repo = loadArtifactRepository(repositoryKey);
assertThat(repo, sameInstance(artifactRepositoryInstance));
}
}
|