Skip to main content
aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTobias Oberlies2012-10-30 13:07:09 -0400
committerTobias Oberlies2012-11-07 07:21:31 -0500
commit99d7eb61f20739c313031de8ecfca64ec0275e99 (patch)
tree344a51570cef4d023b2895961070759bb30a388d /bundles/org.eclipse.equinox.p2.tests.ui
parent55c435adaef265c23a67f26ba8a251f05691a5a3 (diff)
downloadrt.equinox.p2-99d7eb61f20739c313031de8ecfca64ec0275e99.tar.gz
rt.equinox.p2-99d7eb61f20739c313031de8ecfca64ec0275e99.tar.xz
rt.equinox.p2-99d7eb61f20739c313031de8ecfca64ec0275e99.zip
393177 Move tests with UI dependency out of org.eclipse.equinox.p2.testsv20121107-122131I20121113-0800integration
Diffstat (limited to 'bundles/org.eclipse.equinox.p2.tests.ui')
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.ui/META-INF/MANIFEST.MF3
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/AllTests.java17
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportRemoteTests.java118
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportTests.java118
-rw-r--r--bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/AutomatedTests.java1
5 files changed, 256 insertions, 1 deletions
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/META-INF/MANIFEST.MF b/bundles/org.eclipse.equinox.p2.tests.ui/META-INF/MANIFEST.MF
index 3e98acbc5..58bdb37bd 100644
--- a/bundles/org.eclipse.equinox.p2.tests.ui/META-INF/MANIFEST.MF
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/META-INF/MANIFEST.MF
@@ -18,7 +18,8 @@ Require-Bundle: org.eclipse.core.runtime;bundle-version="3.4.100",
org.junit;bundle-version="3.8.0",
org.eclipse.equinox.p2.repository;bundle-version="1.0.0",
org.eclipse.equinox.p2.tests;bundle-version="1.2.0",
- org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.200"
+ org.eclipse.equinox.p2.ui.sdk;bundle-version="1.0.200",
+ org.eclipse.equinox.p2.ui.importexport;bundle-version="1.0.1"
Bundle-RequiredExecutionEnvironment: J2SE-1.5
Import-Package: org.eclipse.equinox.internal.p2.operations,
org.eclipse.equinox.p2.operations;version="[2.0.0,3.0.0)"
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/AllTests.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/AllTests.java
new file mode 100644
index 000000000..5eec62a57
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/AllTests.java
@@ -0,0 +1,17 @@
+package org.eclipse.equinox.p2.tests.importexport;
+
+import junit.framework.*;
+
+/**
+ * Performs all automated importexport tests.
+ */
+public class AllTests extends TestCase {
+
+ public static Test suite() {
+ TestSuite suite = new TestSuite(AllTests.class.getName());
+ suite.addTestSuite(ImportExportTests.class);
+ // suite.addTestSuite(ImportExportRemoteTests.class);
+ return suite;
+ }
+
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportRemoteTests.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportRemoteTests.java
new file mode 100644
index 000000000..616116f97
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportRemoteTests.java
@@ -0,0 +1,118 @@
+package org.eclipse.equinox.p2.tests.importexport;
+
+import java.io.*;
+import java.net.*;
+import java.util.List;
+import org.eclipse.core.runtime.*;
+import org.eclipse.equinox.internal.p2.importexport.IUDetail;
+import org.eclipse.equinox.internal.p2.importexport.P2ImportExport;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.repository.IRepositoryManager;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.TestActivator;
+import org.eclipse.equinox.p2.tests.metadata.repository.ServerBasedTestCase;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ImportExportRemoteTests extends ServerBasedTestCase {
+
+ private P2ImportExport importexportService;
+
+ private URI getTestRepository() throws URISyntaxException {
+ return new URI(getBaseURL() + "/importexport/");
+ }
+
+ @Override
+ public void setUp() throws Exception {
+ super.setUp();
+ ServiceTracker<P2ImportExport, P2ImportExport> tracker = new ServiceTracker<P2ImportExport, P2ImportExport>(TestActivator.getContext(), P2ImportExport.class, null);
+ tracker.open();
+ importexportService = tracker.getService();
+ assertNotNull("Fail to get ImportExport service", importexportService);
+ tracker.close();
+ }
+
+ @Override
+ public void tearDown() throws Exception {
+ super.tearDown();
+ importexportService = null;
+ IMetadataRepositoryManager repoMan = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ URI[] urls = repoMan.getKnownRepositories(IRepositoryManager.REPOSITORIES_ALL);
+ for (int i = 0; i < urls.length; i++) {
+ repoMan.removeRepository(urls[i]);
+ }
+ }
+
+ public void testExportFeaturesFromRemoteRepository() throws URISyntaxException, IOException, ProvisionException, OperationCanceledException {
+ File testFile = File.createTempFile("test", "p2f");
+ URI uri = getTestRepository();
+ try {
+ IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ IMetadataRepository repo = metaManager.loadRepository(uri, null);
+ assertNotNull("Fail to load remote repo", repo);
+ IInstallableUnit iu = AbstractProvisioningTest.createIU("A", Version.create("1.0.0"));
+ OutputStream output = new FileOutputStream(testFile);
+ IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] {iu}, null);
+ assertTrue("Not expected return result.", status.isOK());
+ output.close();
+ InputStream input = new FileInputStream(testFile);
+ List<IUDetail> ius = importexportService.importP2F(input);
+ assertEquals("Exported the number of features is not expected.", 1, ius.size());
+ assertTrue("Exported feature is not expected.", iu.equals(ius.get(0).getIU()));
+ assertEquals("Exported the number of referred repositories is not expected.", 1, ius.get(0).getReferencedRepositories().size());
+ assertEquals("Exported referred repository is not expected.", uri, ius.get(0).getReferencedRepositories().get(0));
+ input.close();
+ } finally {
+ testFile.delete();
+ }
+ }
+
+ protected File getTestData(String message, String entry) {
+ if (entry == null)
+ fail(message + " entry is null.");
+ URL base = TestActivator.getContext().getBundle().getEntry(entry);
+ if (base == null)
+ fail(message + " entry not found in bundle: " + entry);
+ try {
+ String osPath = new Path(FileLocator.toFileURL(base).getPath()).toOSString();
+ File result = new File(osPath);
+ if (!result.getCanonicalPath().equals(result.getPath()))
+ fail(message + " result path: " + result.getPath() + " does not match canonical path: " + result.getCanonicalFile().getPath());
+ return result;
+ } catch (IOException e) {
+ fail(message);
+ }
+ // avoid compile error... should never reach this code
+ return null;
+ }
+
+ public void testExportFeaturesFromBothRemoteRepositoryAndLocalRepository() throws URISyntaxException, IOException, ProvisionException, OperationCanceledException {
+ File testFile = File.createTempFile("test", "p2f");
+ URI uri = getTestRepository();
+ try {
+ IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ File localRepoFile = getTestData("Error load data", "testData/importexport/repo1");
+ IMetadataRepository localRepo = metaManager.loadRepository(localRepoFile.toURI(), null);
+ assertNotNull("Fail to load local repo", localRepo);
+ IMetadataRepository repo = metaManager.loadRepository(uri, null);
+ assertNotNull("Fail to load remote repo", repo);
+ IInstallableUnit iu = AbstractProvisioningTest.createIU("A", Version.create("1.0.0"));
+ OutputStream output = new FileOutputStream(testFile);
+ IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] {iu}, null);
+ assertTrue("Not expected return result.", status.isOK());
+ output.close();
+ InputStream input = new FileInputStream(testFile);
+ List<IUDetail> ius = importexportService.importP2F(input);
+ assertEquals("Exported the number of features is not expected.", 1, ius.size());
+ assertTrue("Exported feature is not expected.", iu.equals(ius.get(0).getIU()));
+ assertEquals("Exported the number of referred repositories is not expected.", 1, ius.get(0).getReferencedRepositories().size());
+ assertEquals("Exported referred repository is not expected.", uri, ius.get(0).getReferencedRepositories().get(0));
+ input.close();
+ } finally {
+ testFile.delete();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportTests.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportTests.java
new file mode 100644
index 000000000..b6ae1a5fb
--- /dev/null
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/importexport/ImportExportTests.java
@@ -0,0 +1,118 @@
+package org.eclipse.equinox.p2.tests.importexport;
+
+import java.io.*;
+import java.util.ArrayList;
+import java.util.List;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.OperationCanceledException;
+import org.eclipse.equinox.internal.p2.importexport.*;
+import org.eclipse.equinox.internal.p2.importexport.internal.ImportExportImpl;
+import org.eclipse.equinox.p2.core.ProvisionException;
+import org.eclipse.equinox.p2.metadata.IInstallableUnit;
+import org.eclipse.equinox.p2.metadata.Version;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepository;
+import org.eclipse.equinox.p2.repository.metadata.IMetadataRepositoryManager;
+import org.eclipse.equinox.p2.tests.AbstractProvisioningTest;
+import org.eclipse.equinox.p2.tests.TestActivator;
+import org.osgi.util.tracker.ServiceTracker;
+
+public class ImportExportTests extends AbstractProvisioningTest {
+
+ private P2ImportExport importexportService;
+
+ private List<IStatus> getChildren(IStatus s) {
+ List<IStatus> rt = new ArrayList<IStatus>();
+ if (s.isMultiStatus()) {
+ for (IStatus child : s.getChildren()) {
+ rt.addAll(getChildren(child));
+ }
+ }
+ rt.add(s);
+ return rt;
+ }
+
+ @Override
+ protected void setUp() throws Exception {
+ super.setUp();
+ ServiceTracker<P2ImportExport, P2ImportExport> tracker = new ServiceTracker<P2ImportExport, P2ImportExport>(TestActivator.getContext(), P2ImportExport.class, null);
+ tracker.open();
+ importexportService = tracker.getService();
+ assertNotNull("Fail to get ImportExport service", importexportService);
+ tracker.close();
+ }
+
+ @Override
+ protected void tearDown() throws Exception {
+ super.tearDown();
+ importexportService = null;
+ }
+
+ public void testLoadP2f() throws IOException {
+ File p2fFile = getTestData("Error load test file.", "testData/importexport/test.p2f");
+ InputStream input = new FileInputStream(p2fFile);
+ try {
+ List<IUDetail> iuDetails = importexportService.importP2F(input);
+ assertTrue("Should load two features from the p2f file.", iuDetails.size() == 2);
+ int counter = 0;
+ for (IUDetail iu : iuDetails) {
+ if ("org.polarion.eclipse.team.svn.connector.feature.group".equals(iu.getIU().getId())) {
+ counter++;
+ assertTrue("Should have two referred repository.", iu.getReferencedRepositories().size() == 2);
+ } else if ("org.polarion.eclipse.team.svn.connector.svnkit16.feature.group".equals(iu.getIU().getId())) {
+ counter++;
+ assertTrue("Should have one referred repository", iu.getReferencedRepositories().size() == 1);
+ }
+ }
+ assertEquals("Load unexpected content.", 2, counter);
+ } finally {
+ input.close();
+ }
+ }
+
+ public void testLoadUnknownP2f() throws IOException {
+ File p2fFile = getTestData("Error load test file.", "testData/importexport/unknownformat.p2f");
+ InputStream input = new FileInputStream(p2fFile);
+ try {
+ List<IUDetail> iuDetails = importexportService.importP2F(input);
+ assertEquals("Should not load any detail.", 0, iuDetails.size());
+ } finally {
+ input.close();
+ }
+ }
+
+ public void testIncompatibleP2f() throws IOException {
+ File p2fFile = getTestData("Error load test file.", "testData/importexport/incompatible.p2f");
+ InputStream input = new FileInputStream(p2fFile);
+ try {
+ importexportService.importP2F(input);
+ assertTrue("Didn't complain the given file is not supported by current version.", false);
+ } catch (VersionIncompatibleException e) {
+ // expected
+ } finally {
+ input.close();
+ }
+ }
+
+ public void testExportFeaturesInstalledFromLocal() throws ProvisionException, OperationCanceledException, IOException {
+ File testFile = File.createTempFile("test", "p2f");
+ try {
+ IMetadataRepositoryManager metaManager = (IMetadataRepositoryManager) getAgent().getService(IMetadataRepositoryManager.SERVICE_NAME);
+ File localRepoFile = getTestData("Error load data", "testData/importexport/repo1");
+ IMetadataRepository repo = metaManager.loadRepository(localRepoFile.toURI(), null);
+ assertNotNull("Fail to load local repo", repo);
+ IInstallableUnit iu = createIU("A", Version.create("1.0.0"));
+ OutputStream output = new FileOutputStream(testFile);
+ IStatus status = importexportService.exportP2F(output, new IInstallableUnit[] {iu}, null);
+ assertFalse("Not expected return result.", status.isOK());
+ assertTrue("Should be a multiple status", status.isMultiStatus());
+ boolean hasFeaturesIgnored = false;
+ for (IStatus s : getChildren(status))
+ if (s.getCode() == ImportExportImpl.IGNORE_LOCAL_REPOSITORY)
+ hasFeaturesIgnored = true;
+ assertTrue("Should have features ignored due to they're installed from local repository.", hasFeaturesIgnored);
+ output.close();
+ } finally {
+ testFile.delete();
+ }
+ }
+}
diff --git a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/AutomatedTests.java b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/AutomatedTests.java
index c2418a48b..5ddade740 100644
--- a/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/AutomatedTests.java
+++ b/bundles/org.eclipse.equinox.p2.tests.ui/src/org/eclipse/equinox/p2/tests/ui/AutomatedTests.java
@@ -25,6 +25,7 @@ public class AutomatedTests extends TestCase {
suite.addTest(org.eclipse.equinox.p2.tests.ui.dialogs.AllTests.suite());
suite.addTest(org.eclipse.equinox.p2.tests.ui.misc.AllTests.suite());
suite.addTest(org.eclipse.equinox.p2.tests.ui.repohandling.AllTests.suite());
+ suite.addTest(org.eclipse.equinox.p2.tests.importexport.AllTests.suite());
return suite;
}
}

Back to the top