diff options
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox')
5 files changed, 92 insertions, 8 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java index fc3a7c1fd..aaa764170 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/TestMetadataRepository.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2010 IBM Corporation and others. + * Copyright (c) 2007, 2012 IBM Corporation 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 @@ -48,7 +48,7 @@ public class TestMetadataRepository extends AbstractMetadataRepository { return null; } - public TestMetadataRepository(IProvisioningAgent agent, IInstallableUnit[] ius) { + public TestMetadataRepository(IProvisioningAgent agent, IInstallableUnit... ius) { super(agent, NAME, TYPE, VERSION, createLocation(), DESCRIPTION, PROVIDER, null); units.addAll(Arrays.asList(ius)); } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java index 02bc38cd3..903f59fc3 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/ant/MirrorTaskTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2009, 2011 IBM Corporation and others. + * Copyright (c) 2009, 2012 IBM Corporation 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 @@ -290,7 +290,7 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest { * Test the handling of invalid destinations with the mirror task */ public void testMirrorWithInvalidSource() throws URISyntaxException { - URI location = new URI("invalid:/scheme2"); + URI location = new URI("unknown:/scheme2"); AntTaskElement mirror = createMirrorTask(TYPE_BOTH); mirror.addElement(createSourceElement(location, location)); @@ -308,7 +308,7 @@ public class MirrorTaskTest extends AbstractAntProvisioningTest { while (exception.getCause() != null && !(exception instanceof ProvisionException)) exception = exception.getCause(); assertTrue("Expecting a CoreException", exception instanceof CoreException); - assertEquals("Unexpected error code.", ProvisionException.REPOSITORY_FAILED_READ, ((CoreException) exception).getStatus().getCode()); + assertEquals("Unexpected error code.", ProvisionException.REPOSITORY_NOT_FOUND, ((CoreException) exception).getStatus().getCode()); } /* diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java index ed751887c..93a0bd5a4 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/metadata/repository/MetadataRepositoryManagerTest.java @@ -1,5 +1,5 @@ /******************************************************************************* - * Copyright (c) 2007, 2011 IBM Corporation and others. + * Copyright (c) 2007, 2012 IBM Corporation 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 @@ -126,14 +126,14 @@ public class MetadataRepositoryManagerTest extends AbstractProvisioningTest { try { factory.load(location, 0, new NullProgressMonitor()); } catch (ProvisionException e) { - assertEquals(ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode()); + assertEquals(ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); } factory = new UpdateSiteMetadataRepositoryFactory(); factory.setAgent(getAgent()); try { factory.load(location, 0, new NullProgressMonitor()); } catch (ProvisionException e) { - assertEquals(ProvisionException.REPOSITORY_FAILED_READ, e.getStatus().getCode()); + assertEquals(ProvisionException.REPOSITORY_NOT_FOUND, e.getStatus().getCode()); } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTests.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTests.java index 8022be168..41c85aeda 100644 --- a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTests.java +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/AllTests.java @@ -21,6 +21,7 @@ public class AllTests extends TestCase { TestSuite suite = new TestSuite(AllTests.class.getName()); suite.addTestSuite(RepositoryHelperTest.class); // suite.addTestSuite(FileReaderTest2.class); + suite.addTestSuite(RepositoryExtensionPointTest.class); return suite; } } diff --git a/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/RepositoryExtensionPointTest.java b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/RepositoryExtensionPointTest.java new file mode 100644 index 000000000..0e39a8562 --- /dev/null +++ b/bundles/org.eclipse.equinox.p2.tests/src/org/eclipse/equinox/p2/tests/repository/RepositoryExtensionPointTest.java @@ -0,0 +1,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)); + } +} |