aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-17 15:09:08 (EST)
committerGerrit Code Review @ Eclipse.org2013-12-18 04:26:47 (EST)
commit78dfcacb5a36be9ac0bc5dd1aac5b0212cdc4f1c (patch)
treeca61a2e03e236acb658c803b57b735254672ccfc
parentf37efc3778e600ea29d4fe95bff1c0698c721037 (diff)
downloadorg.eclipse.linuxtools-78dfcacb5a36be9ac0bc5dd1aac5b0212cdc4f1c.zip
org.eclipse.linuxtools-78dfcacb5a36be9ac0bc5dd1aac5b0212cdc4f1c.tar.gz
org.eclipse.linuxtools-78dfcacb5a36be9ac0bc5dd1aac5b0212cdc4f1c.tar.bz2
RPM: createrepo tests for resource change listenerrefs/changes/34/19734/5
Testing classes within: o org.eclipse.linuxtools.internal.rpm.createrepo.listener Also testing the Import RPMs page listener. Change-Id: I87b9931c54bd41c98e0effe4205b5ae160886894 Signed-off-by: Neil Guzman <nguzman@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java47
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java2
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/tests/CreaterepoResourceListenerTest.java146
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java4
4 files changed, 196 insertions, 3 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java
index beba6b5..5b87fe2 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java
@@ -21,9 +21,11 @@ import java.io.IOException;
import java.net.URL;
import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IResource;
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.FileLocator;
import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Path;
import org.eclipse.linuxtools.internal.rpm.createrepo.Createrepo;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
@@ -67,9 +69,10 @@ public class CreaterepoImportRPMsPageTest {
private CreaterepoProject project;
private static SWTWorkbenchBot bot;
private SWTBot importPageBot;
+ private static NullProgressMonitor monitor;
/**
- * Initialize the test project. Will close the welcome view.
+ * Initialize the test project.
*
* @throws CoreException
*/
@@ -83,6 +86,7 @@ public class CreaterepoImportRPMsPageTest {
} catch (WidgetNotFoundException e) {
// cannot activate main shell, continue anyways
}
+ monitor = new NullProgressMonitor();
}
/**
@@ -173,6 +177,47 @@ public class CreaterepoImportRPMsPageTest {
}
/**
+ * Test if deleting/adding an RPM into content folder updates the RPM list.
+ *
+ * @throws CoreException
+ * @throws IOException
+ */
+ @Test
+ public void testResourceChangeListener() throws CoreException, IOException {
+ // delete the contents of the content folder
+ for (IResource resource : project.getContentFolder().members()) {
+ resource.delete(true, monitor);
+ }
+ // run in UI thread because accessing the tree in the import RPMs page
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ Tree tree = importPageBot.widget(WidgetMatcherFactory.widgetOfType(Tree.class));
+ assertNotNull(tree);
+ // check items in tree are gone
+ assertEquals(0, tree.getItemCount());
+ }
+ });
+ // import a file again into the content folder
+ URL rpmURL = FileLocator.find(FrameworkUtil
+ .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null);
+ final File rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath());
+ assertTrue(rpmFile.exists());
+ project.importRPM(rpmFile);
+ // run in UI thread because accessing the tree in the import RPMs page
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ Tree tree = importPageBot.widget(WidgetMatcherFactory.widgetOfType(Tree.class));
+ assertNotNull(tree);
+ // check if items are in tree
+ assertEquals(1, tree.getItemCount());
+ assertEquals(rpmFile.getName(), tree.getItem(0).getText());
+ }
+ });
+ }
+
+ /**
* Helper method to help setup the test by opening the .repo file.
*/
private void initializeImportPage() {
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java
index 673b892..fc82d93 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java
@@ -61,7 +61,7 @@ public class CreaterepoMetadataPageTest {
private SWTBot metadataPageBot;
/**
- * Initialize the test project. Will close the welcome view.
+ * Initialize the test project.
*
* @throws CoreException
*/
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/tests/CreaterepoResourceListenerTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/tests/CreaterepoResourceListenerTest.java
new file mode 100644
index 0000000..32eebd4
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/listener/tests/CreaterepoResourceListenerTest.java
@@ -0,0 +1,146 @@
+/*******************************************************************************
+ * Copyright (c) 2013 Red Hat 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:
+ * Neil Guzman - initial API and implementation
+ *******************************************************************************/
+package org.eclipse.linuxtools.internal.rpm.createrepo.listener.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.linuxtools.rpm.createrepo.tests.ICreaterepoTestConstants;
+import org.eclipse.linuxtools.rpm.createrepo.tests.TestCreaterepoProject;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotMultiPageEditor;
+import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
+import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
+import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
+import org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.After;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * SWTBot tests for CreaterepoResourceChangeListener. Simply create a project,
+ * close/delete it, and test if the activator is also closed.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CreaterepoResourceListenerTest {
+
+ private TestCreaterepoProject testProject;
+ private static SWTWorkbenchBot bot;
+ private static NullProgressMonitor monitor;
+
+ /**
+ * Initialize the bot.
+ *
+ * @throws CoreException
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CoreException {
+ bot = new SWTWorkbenchBot();
+ monitor = new NullProgressMonitor();
+ try {
+ bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate();
+ } catch (WidgetNotFoundException e) {
+ // cannot activate main shell, continue anyways
+ }
+ }
+
+ /**
+ * Create a new test project and open the .repo file.
+ *
+ * @throws Exception
+ */
+ @Before
+ public void setUp() throws Exception {
+ testProject = new TestCreaterepoProject();
+ assertTrue(testProject.getProject().exists());
+ openRepoFile();
+ }
+
+ /**
+ * Delete the project when tests are done.
+ *
+ * @throws CoreException
+ */
+ @After
+ public void tearDown() throws CoreException {
+ testProject.dispose();
+ assertFalse(testProject.getProject().exists());
+ }
+
+ /**
+ * Test if editor is still open after closing the project.
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void testCloseProjectCloseEditor() throws CoreException {
+ assertFalse(bot.editors().isEmpty());
+ assertEquals(1, bot.editors().size());
+ assertNotNull(bot.multipageEditorByTitle(ICreaterepoTestConstants.REPO_NAME));
+ assertTrue(bot.multipageEditorByTitle(ICreaterepoTestConstants.REPO_NAME).isActive());
+ testProject.getProject().close(monitor);
+ assertFalse(testProject.getProject().isOpen());
+ assertTrue(bot.editors().isEmpty());
+ }
+
+ /**
+ * Test if editor is still open after deleting the project.
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void testDeleteProjectCloseEditor() throws CoreException {
+ assertFalse(bot.editors().isEmpty());
+ assertEquals(1, bot.editors().size());
+ assertNotNull(bot.multipageEditorByTitle(ICreaterepoTestConstants.REPO_NAME));
+ assertTrue(bot.multipageEditorByTitle(ICreaterepoTestConstants.REPO_NAME).isActive());
+ testProject.dispose();
+ assertFalse(testProject.getProject().exists());
+ assertTrue(bot.editors().isEmpty());
+ }
+
+ /**
+ * Helper method to help setup the test by opening the .repo file.
+ */
+ private void openRepoFile() {
+ // open the package explorer view
+ bot.menu(ICreaterepoTestConstants.WINDOW).menu(ICreaterepoTestConstants.SHOW_VIEW)
+ .menu(ICreaterepoTestConstants.OTHER).click();
+ SWTBotShell shell = bot.shell(ICreaterepoTestConstants.SHOW_VIEW);
+ shell.activate();
+ bot.tree().expandNode(ICreaterepoTestConstants.GENERAL_NODE).select(ICreaterepoTestConstants.NAVIGATOR);
+ bot.button(ICreaterepoTestConstants.OK_BUTTON).click();
+ SWTBotView view = bot.viewByTitle(ICreaterepoTestConstants.NAVIGATOR);
+ view.show();
+ // select the .repo file from the package explorer and open it
+ Composite packageExplorer = (Composite)view.getWidget();
+ assertNotNull(packageExplorer);
+ Tree swtTree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorer);
+ assertNotNull(swtTree);
+ SWTBotTree botTree = new SWTBotTree(swtTree);
+ botTree.expandNode(ICreaterepoTestConstants.PROJECT_NAME).getNode(ICreaterepoTestConstants.REPO_NAME)
+ .contextMenu(ICreaterepoTestConstants.OPEN).click();
+ // get a handle on the multipage editor that was opened
+ SWTBotMultiPageEditor editor = bot.multipageEditorByTitle(ICreaterepoTestConstants.REPO_NAME);
+ editor.show();
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java
index 3dbaa4d..cb1ae03 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java
@@ -13,6 +13,7 @@ package org.eclipse.linuxtools.rpm.createrepo.tests;
import org.eclipse.linuxtools.internal.rpm.createrepo.form.tests.CreaterepoImportRPMsPageTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.form.tests.CreaterepoMetadataPageTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.form.tests.CreaterepoRepoFormEditorTest;
+import org.eclipse.linuxtools.internal.rpm.createrepo.listener.tests.CreaterepoResourceListenerTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.preference.tests.CreaterepoPreferenceInitializationTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.tests.CreaterepoTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.tree.tests.CreaterepoTreeCategoryTest;
@@ -26,6 +27,7 @@ import org.junit.runners.Suite.SuiteClasses;
@SuiteClasses({CreaterepoProjectCreatorTest.class, CreaterepoUtilsTest.class,
CreaterepoProjectTest.class, CreaterepoTreeCategoryTest.class, CreaterepoTreeTest.class,
CreaterepoWizardTest.class, CreaterepoTest.class, CreaterepoPreferenceInitializationTest.class,
- CreaterepoRepoFormEditorTest.class, CreaterepoImportRPMsPageTest.class, CreaterepoMetadataPageTest.class})
+ CreaterepoRepoFormEditorTest.class, CreaterepoImportRPMsPageTest.class, CreaterepoMetadataPageTest.class,
+ CreaterepoResourceListenerTest.class})
public class AllTests {
}