aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-10 13:01:17 (EST)
committerAlexander Kurtakov2013-12-18 03:04:21 (EST)
commitaba9bdfb8819e1ecc253a044e213454d3d07d804 (patch)
tree8a4caab43cb6bd2b307b02533f459ec9927ba54a
parent2e8735a3df881a23bdcfa70ad3b0cb4937095438 (diff)
downloadorg.eclipse.linuxtools-aba9bdfb8819e1ecc253a044e213454d3d07d804.zip
org.eclipse.linuxtools-aba9bdfb8819e1ecc253a044e213454d3d07d804.tar.gz
org.eclipse.linuxtools-aba9bdfb8819e1ecc253a044e213454d3d07d804.tar.bz2
RPM: createrepo tests for repo form editorrefs/changes/14/19614/9
Testing classes within: o org.eclipse.linuxtools.internal.rpm.createrepo.form Uses SWTBot tests to verify that the pages widgets work. Change-Id: I699c75af635bce8a998571175afa81e99e9a15c0 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19614 Reviewed-by: Alexander Kurtakov <akurtako@redhat.com> IP-Clean: Alexander Kurtakov <akurtako@redhat.com> Tested-by: Alexander Kurtakov <akurtako@redhat.com>
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java198
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java289
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoRepoFormEditorTest.java101
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java8
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java6
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java11
6 files changed, 604 insertions, 9 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
new file mode 100644
index 0000000..8018c8b
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoImportRPMsPageTest.java
@@ -0,0 +1,198 @@
+/*******************************************************************************
+ * 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.form.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.io.File;
+import java.io.IOException;
+import java.net.URL;
+
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.FileLocator;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.Path;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Createrepo;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils;
+import org.eclipse.linuxtools.rpm.createrepo.tests.CreaterepoProjectTest;
+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.Display;
+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.SWTBot;
+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.waits.Conditions;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
+import org.eclipse.swtbot.swt.finder.widgets.SWTBotTree;
+import org.junit.AfterClass;
+import org.junit.Assume;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.framework.FrameworkUtil;
+
+/**
+ * SWTBot tests for ImportRPMsPage. Import RPMs cannot be tested due to
+ * SWTBot not supporting native dialogs (File dialogs).
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CreaterepoImportRPMsPageTest {
+
+ private static final String TEST_RPM1 = "eclipse-egit-github-3.0.0-2.fc19.noarch.rpm"; //$NON-NLS-1$
+ private static final String TEST_RPM_LOC1 = ICreaterepoTestConstants.RPM_RESOURCE_LOC
+ .concat(TEST_RPM1);
+
+ private static TestCreaterepoProject testProject;
+ private CreaterepoProject project;
+ private static SWTWorkbenchBot bot;
+ private SWTBot importPageBot;
+
+ /**
+ * Initialize the test project. Will close the welcome view.
+ *
+ * @throws CoreException
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CoreException {
+ testProject = new TestCreaterepoProject();
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate();
+ } catch (WidgetNotFoundException e) {
+ // cannot activate main shell, continue anyways
+ }
+ }
+
+ /**
+ * Delete the project when tests are done.
+ *
+ * @throws CoreException
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws CoreException {
+ testProject.dispose();
+ }
+
+ /**
+ * Get the CreaterepoProject at the beginning of each test, as
+ * well as import some test RPMs.
+ *
+ * @throws CoreException
+ * @throws IOException
+ */
+ @Before
+ public void setUp() throws CoreException, IOException {
+ project = testProject.getCreaterepoProject();
+ URL rpmURL = FileLocator.find(FrameworkUtil
+ .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null);
+ File rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath());
+ project.importRPM(rpmFile);
+ // there should be 1 rpm every setup
+ assertEquals(1, project.getRPMs().size());
+ initializeImportPage();
+ }
+
+ /**
+ * Test out the remove RPMs button.
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void testRemoveRPMs() throws CoreException {
+ // 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));
+ // current item count should be 1 (from the imported RPM)
+ assertEquals(1, tree.getItemCount());
+ importPageBot.button(Messages.ImportRPMsPage_buttonRemoveRPMs).click();
+ // not selecting a treeitem should do nothing to the tree contents
+ assertEquals(1, tree.getItemCount());
+ tree.select(tree.getItem(0));
+ importPageBot.button(Messages.ImportRPMsPage_buttonRemoveRPMs).click();
+ // item count should be 0 after selecting a tree item and pressing remove
+ assertEquals(0, tree.getItemCount());
+ try {
+ // make sure that the RPM was actually deleted from the project
+ assertEquals(0, project.getRPMs().size());
+ } catch (CoreException e) {
+ fail("Failed to get the RPMs from project"); //$NON-NLS-1$
+ }
+ }
+ });
+ }
+
+ /**
+ * Test to see if createrepo executed.
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void testCreaterepo() throws CoreException {
+ // assume that there is creatrepo version of >= 0.9.8
+ IStatus validVersion = Createrepo.isCorrectVersion(CreaterepoUtils.findConsole("test").newMessageStream()); //$NON-NLS-1$
+ Assume.assumeTrue(validVersion.isOK());
+ importPageBot.button(Messages.ImportRPMsPage_buttonCreateRepo).click();
+ // make the bot wait until the download job shell closes before proceeding the tests
+ bot.waitUntil(Conditions.shellCloses(bot.shell(Messages.Createrepo_jobName)));
+ // assert that the content folder has more than just the RPM inside it
+ assertTrue(project.getContentFolder().members().length > 1);
+ // assert that the repodata folder exists within the content folder
+ assertTrue(project.getContentFolder().findMember(ICreaterepoTestConstants.REPODATA_FOLDER).exists());
+ // assert that the repomd.xml file was created (successful createrepo execution)
+ IFolder repodata = (IFolder) project.getContentFolder().findMember(ICreaterepoTestConstants.REPODATA_FOLDER);
+ assertTrue(repodata.findMember(ICreaterepoTestConstants.REPO_MD_NAME).exists());
+ }
+
+ /**
+ * Helper method to help setup the test by opening the .repo file.
+ */
+ private void initializeImportPage() {
+ // 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.JAVA_NODE).select(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ bot.button(ICreaterepoTestConstants.OK_BUTTON).click();
+ SWTBotView view = bot.viewByTitle(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ view.show();
+ // select the repo file from the package explorer and open it
+ Composite packageExplorer = (Composite)view.getWidget();
+ Tree swtTree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorer);
+ SWTBotTree botTree = new SWTBotTree(swtTree);
+ botTree.expandNode(TestCreaterepoProject.PROJECT_NAME).select(TestCreaterepoProject.REPO_NAME);
+ bot.menu(ICreaterepoTestConstants.OPEN).click();
+ // get a handle on the multipage editor that was opened
+ SWTBotMultiPageEditor editor = bot.multipageEditorByTitle(TestCreaterepoProject.REPO_NAME);
+ editor.show();
+ // 3 = repository form page, metadata form page, repo file
+ assertEquals(3, editor.getPageCount());
+ // activate the pages to make sure they exist and work
+ editor.activatePage(Messages.ImportRPMsPage_title);
+ // make sure correct page is active
+ assertEquals(Messages.ImportRPMsPage_title, editor.getActivePageTitle());
+ importPageBot = editor.bot();
+ }
+
+}
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
new file mode 100644
index 0000000..070e4a2
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoMetadataPageTest.java
@@ -0,0 +1,289 @@
+/*******************************************************************************
+ * 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.form.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+
+import java.io.IOException;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.preference.IPreferenceStore;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Activator;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoPreferenceConstants;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+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.Display;
+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.SWTBot;
+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.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * SWTBot tests for MetadataPage.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CreaterepoMetadataPageTest {
+
+ private static TestCreaterepoProject testProject;
+ private CreaterepoProject project;
+ private static SWTWorkbenchBot bot;
+ private SWTBot metadataPageBot;
+
+ /**
+ * Initialize the test project. Will close the welcome view.
+ *
+ * @throws CoreException
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CoreException {
+ testProject = new TestCreaterepoProject();
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate();
+ } catch (WidgetNotFoundException e) {
+ // cannot activate main shell, continue anyways
+ }
+ }
+
+ /**
+ * Delete the project when tests are done.
+ *
+ * @throws CoreException
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws CoreException {
+ testProject.dispose();
+ }
+
+ /**
+ * Get the CreaterepoProject at the beginning of each test, as
+ * well as import some test RPMs.
+ *
+ * @throws CoreException
+ * @throws IOException
+ */
+ @Before
+ public void setUp() throws CoreException, IOException {
+ project = testProject.getCreaterepoProject();
+ initializeMetadataPage();
+ }
+
+ /**
+ * Clear the project preferences.
+ *
+ * @throws BackingStoreException
+ */
+ @After
+ public void tearDown() throws BackingStoreException {
+ IEclipsePreferences pref = project.getEclipsePreferences();
+ pref.clear();
+ pref.flush();
+ }
+
+ /**
+ * Test if tags are adding properly. Tags should be unique per category.
+ */
+ @Test
+ public void testAddTags() {
+ // run in UI thread because accessing the tree in the metadata page
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ String tagName = "testTag"; //$NON-NLS-1$
+ String newTagName = "newUniqueTag"; //$NON-NLS-1$
+ String prefValueToBe = ""; //$NON-NLS-1$
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(tagName);
+ Tree tree = metadataPageBot.widget(WidgetMatcherFactory.widgetOfType(Tree.class));
+ // 0 = distro, 1 = content, 2 = repo
+ int category = 0;
+ tree.select(tree.getItem(category));
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ CreaterepoTreeCategory test = (CreaterepoTreeCategory) tree.getItem(category).getData();
+ assertEquals(1, test.getTags().size());
+ // it should be distro = {testTag} now
+ prefValueToBe = tagName;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_DISTRO_TAG, prefValueToBe));
+ // try adding the same tag to the same category again, it should not work
+ tree.select(tree.getItem(category));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(tagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ assertEquals(1, test.getTags().size());
+ // it should still be distro = {testTag}
+ prefValueToBe = tagName;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_DISTRO_TAG, prefValueToBe));
+ // try adding a new unique tag to the same category, it should work
+ tree.select(tree.getItem(category));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(newTagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ assertEquals(2, test.getTags().size());
+ // it should be distro = {testTag, newUniqueTag} now
+ prefValueToBe = tagName + ICreaterepoConstants.DELIMITER + newTagName;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_DISTRO_TAG, prefValueToBe));
+ }
+ });
+ }
+
+ /**
+ * Test if tags can be edited correctly.
+ */
+ @Test
+ public void testEditTags() {
+ // run in UI thread because accessing the tree in the metadata page
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ String tagName = "testTag"; //$NON-NLS-1$
+ String tagName2 = "testTag2"; //$NON-NLS-1$
+ String newTagName = "renameTag"; //$NON-NLS-1$
+ String prefValueToBe = ""; //$NON-NLS-1$
+ Tree tree = metadataPageBot.widget(WidgetMatcherFactory.widgetOfType(Tree.class));
+ // 0 = distro, 1 = content, 2 = repo
+ int category = 1;
+ // select the category and the test tags to it
+ tree.select(tree.getItem(category));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(tagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(tagName2);
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ CreaterepoTreeCategory test = (CreaterepoTreeCategory) tree.getItem(category).getData();
+ assertEquals(2, test.getTags().size());
+ // it should be content = {testTag1, testTag2} now
+ prefValueToBe = tagName + ICreaterepoConstants.DELIMITER + tagName2;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_CONTENT_TAG, prefValueToBe));
+ // select the first test tag that was created and edit it with a new unique tag
+ tree.select(tree.getItem(category).getItem(0));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(newTagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonEditTag).click();
+ assertEquals(2, test.getTags().size());
+ assertEquals(newTagName, test.getTags().get(0));
+ // it should be content = {renameTag, testTag2} now
+ prefValueToBe = newTagName + ICreaterepoConstants.DELIMITER + tagName2;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_CONTENT_TAG, prefValueToBe));
+ // select the second test tag and try to rename it as the same name as the first tag, this should not happen
+ tree.select(tree.getItem(category).getItem(1));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(newTagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonEditTag).click();
+ assertEquals(2, test.getTags().size());
+ assertNotEquals(newTagName, test.getTags().get(1));
+ // it should still be content = {renameTag, testTag2}
+ prefValueToBe = newTagName + ICreaterepoConstants.DELIMITER + tagName2;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_CONTENT_TAG, prefValueToBe));
+ }
+ });
+ }
+
+ /**
+ * Test if tags can be removed.
+ */
+ @Test
+ public void testRemoveTags() {
+ // run in UI thread because accessing the tree in the metadata page
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ String tagName = "testTag"; //$NON-NLS-1$
+ String prefValueToBe = ""; //$NON-NLS-1$
+ Tree tree = metadataPageBot.widget(WidgetMatcherFactory.widgetOfType(Tree.class));
+ // 0 = distro, 1 = content, 2 = repo
+ int category = 2;
+ // select the category and the test tags to it
+ tree.select(tree.getItem(category));
+ metadataPageBot.textWithLabel(Messages.MetadataPage_labelTags).setText(tagName);
+ metadataPageBot.button(Messages.MetadataPage_buttonAddTag).click();
+ CreaterepoTreeCategory test = (CreaterepoTreeCategory) tree.getItem(category).getData();
+ assertEquals(1, test.getTags().size());
+ // it should be repo = {testTag} now
+ prefValueToBe = tagName;
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_REPO_TAG, prefValueToBe));
+ // select the first item and delete it
+ tree.select(tree.getItem(category).getItem(0));
+ metadataPageBot.button(Messages.MetadataPage_buttonRemoveTag).click();
+ assertEquals(0, test.getTags().size());
+ // it should be repo = {} now
+ prefValueToBe = ""; //$NON-NLS-1$
+ assertTrue(isPreferencesCorrect(CreaterepoPreferenceConstants.PREF_REPO_TAG, prefValueToBe));
+ // try to remove the category
+ tree.select(tree.getItem(category));
+ metadataPageBot.button(Messages.MetadataPage_buttonRemoveTag).click();
+ // it should still be there
+ assertNotNull(tree.getItem(category));
+ }
+ });
+ }
+
+ /**
+ * Get the current project preference for the category tag and check if the values
+ * stored are the same as the values passed in.
+ *
+ * @param category The preference category to check.
+ * @param value The value to check.
+ * @return True if the value is same as what is stored, false otherwise.
+ */
+ private boolean isPreferencesCorrect(String category, String value) {
+ IEclipsePreferences pref = project.getEclipsePreferences();
+ IPreferenceStore prefStore = Activator.getDefault().getPreferenceStore();
+ String actual = pref.get(category, prefStore.getDefaultString(category));
+ return actual.equals(value);
+ }
+
+ /**
+ * Helper method to help setup the test by opening the .repo file.
+ */
+ private void initializeMetadataPage() {
+ // 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.JAVA_NODE).select(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ bot.button(ICreaterepoTestConstants.OK_BUTTON).click();
+ SWTBotView view = bot.viewByTitle(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ view.show();
+ // select the repo file from the package explorer and open it
+ Composite packageExplorer = (Composite)view.getWidget();
+ Tree swtTree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorer);
+ SWTBotTree botTree = new SWTBotTree(swtTree);
+ botTree.expandNode(TestCreaterepoProject.PROJECT_NAME).select(TestCreaterepoProject.REPO_NAME);
+ bot.menu(ICreaterepoTestConstants.OPEN).click();
+ // get a handle on the multipage editor that was opened
+ SWTBotMultiPageEditor editor = bot.multipageEditorByTitle(TestCreaterepoProject.REPO_NAME);
+ editor.show();
+ // 3 = repository form page, metadata form page, repo file
+ assertEquals(3, editor.getPageCount());
+ // activate the pages to make sure they exist and work
+ editor.activatePage(Messages.MetadataPage_title);
+ // make sure correct page is active
+ assertEquals(Messages.MetadataPage_title, editor.getActivePageTitle());
+ metadataPageBot = editor.bot();
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoRepoFormEditorTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoRepoFormEditorTest.java
new file mode 100644
index 0000000..2bbbca7
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/form/tests/CreaterepoRepoFormEditorTest.java
@@ -0,0 +1,101 @@
+/*******************************************************************************
+ * 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.form.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
+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.AfterClass;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+
+/**
+ * SWTBot tests for RepoFormEditor.
+ */
+@RunWith(SWTBotJunit4ClassRunner.class)
+public class CreaterepoRepoFormEditorTest {
+
+ private static TestCreaterepoProject testProject;
+ private static SWTWorkbenchBot bot;
+
+ /**
+ * Initialize the test project. Will close the welcome view.
+ *
+ * @throws CoreException
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CoreException {
+ testProject = new TestCreaterepoProject();
+ bot = new SWTWorkbenchBot();
+ try {
+ bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate();
+ } catch (WidgetNotFoundException e) {
+ // cannot activate main shell, continue anyways
+ }
+ }
+
+ /**
+ * Delete the project when tests are done.
+ *
+ * @throws CoreException
+ */
+ @AfterClass
+ public static void tearDownAfterClass() throws CoreException {
+ testProject.dispose();
+ }
+
+ /**
+ * Test if the multi page editor is properly created. Make sure there are 3
+ * pages (Repository, Metadata, repo file), and that all of them can be switched
+ * to.
+ */
+ @Test
+ public void testFormEditorCreation() {
+ // 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.JAVA_NODE).select(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ bot.button(ICreaterepoTestConstants.OK_BUTTON).click();
+ SWTBotView view = bot.viewByTitle(ICreaterepoTestConstants.PACKAGE_EXPLORER);
+ view.show();
+ // select the repo file from the package explorer and open it
+ Composite packageExplorer = (Composite)view.getWidget();
+ Tree swtTree = bot.widget(WidgetMatcherFactory.widgetOfType(Tree.class), packageExplorer);
+ SWTBotTree botTree = new SWTBotTree(swtTree);
+ botTree.expandNode(TestCreaterepoProject.PROJECT_NAME).select(TestCreaterepoProject.REPO_NAME);
+ bot.menu(ICreaterepoTestConstants.OPEN).click();
+ // get a handle on the multipage editor that was opened
+ SWTBotMultiPageEditor editor = bot.multipageEditorByTitle(TestCreaterepoProject.REPO_NAME);
+ editor.show();
+ // 3 = repository form page, metadata form page, repo file
+ assertEquals(3, editor.getPageCount());
+ // activate the pages to make sure they exist and work
+ editor.activatePage(Messages.MetadataPage_title);
+ editor.activatePage(TestCreaterepoProject.REPO_NAME);
+ editor.activatePage(Messages.ImportRPMsPage_title);
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java
index c693689..9e76011 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java
@@ -35,7 +35,6 @@ import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.junit.After;
-import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -69,13 +68,6 @@ public class CreaterepoWizardTest {
bot = new SWTWorkbenchBot();
root = ResourcesPlugin.getWorkspace().getRoot();
monitor = new NullProgressMonitor();
- }
-
- /**
- * Focus on main eclipse platform shell before continue SWTBot tests.
- */
- @Before
- public void setUp() {
try {
bot.shell(ICreaterepoTestConstants.MAIN_SHELL).activate();
} catch (WidgetNotFoundException e) {
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 0fd830e..3dbaa4d 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
@@ -10,6 +10,9 @@
*******************************************************************************/
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.preference.tests.CreaterepoPreferenceInitializationTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.tests.CreaterepoTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.tree.tests.CreaterepoTreeCategoryTest;
@@ -22,6 +25,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({CreaterepoProjectCreatorTest.class, CreaterepoUtilsTest.class,
CreaterepoProjectTest.class, CreaterepoTreeCategoryTest.class, CreaterepoTreeTest.class,
- CreaterepoWizardTest.class, CreaterepoTest.class, CreaterepoPreferenceInitializationTest.class})
+ CreaterepoWizardTest.class, CreaterepoTest.class, CreaterepoPreferenceInitializationTest.class,
+ CreaterepoRepoFormEditorTest.class, CreaterepoImportRPMsPageTest.class, CreaterepoMetadataPageTest.class})
public class AllTests {
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java
index f6d0f3b..c9f14a9 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java
@@ -27,6 +27,17 @@ public interface ICreaterepoTestConstants {
String BACK_BUTTON = "< Back"; //$NON-NLS-1$
String FINISH_BUTTON = "Finish"; //$NON-NLS-1$
String CANCEL_BUTTON = "Cancel"; //$NON-NLS-1$
+ String WINDOW = "Window"; //$NON-NLS-1$
+ String SHOW_VIEW = "Show View"; //$NON-NLS-1$
+ String OK_BUTTON = "OK"; //$NON-NLS-1$
+ String OPEN = "Open"; //$NON-NLS-1$
+
+ /*
+ * Views
+ */
+ String WELCOME_VIEW = "Welcome"; //$NON-NLS-1$
+ String JAVA_NODE = "Java"; //$NON-NLS-1$
+ String PACKAGE_EXPLORER = "Package Explorer"; //$NON-NLS-1$
/*
* Project Wizard Specific Stuff