aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorNeil Guzman2013-12-09 14:51:41 (EST)
committerAlexander Kurtakov2013-12-13 03:21:18 (EST)
commit9adc1b072e06560da3c2999377bdc8d0cb14f391 (patch)
tree61fd111fe698c54895c8b62350b205be47891ef2
parent0b1a3c2b8e7109705deb5489a3665bab29b2664b (diff)
downloadorg.eclipse.linuxtools-9adc1b072e06560da3c2999377bdc8d0cb14f391.zip
org.eclipse.linuxtools-9adc1b072e06560da3c2999377bdc8d0cb14f391.tar.gz
org.eclipse.linuxtools-9adc1b072e06560da3c2999377bdc8d0cb14f391.tar.bz2
RPM: createrepo tests for category treerefs/changes/30/19530/6
Testing classes within: o org.eclipse.linuxtools.internal.rpm.createrepo.tree Change-Id: I0ee4c84ceb421638f0ac8e87591ba464defb8119 Signed-off-by: Neil Guzman <nguzman@redhat.com> Reviewed-on: https://git.eclipse.org/r/19530 Tested-by: Hudson CI 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/tree/tests/CreaterepoTreeCategoryTest.java51
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeTest.java244
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java23
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/AllTests.java5
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectCreatorTest.java12
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java12
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java9
-rw-r--r--rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/TestCreaterepoProject.java166
8 files changed, 500 insertions, 22 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeCategoryTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeCategoryTest.java
new file mode 100644
index 0000000..695d95c
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeCategoryTest.java
@@ -0,0 +1,51 @@
+/*******************************************************************************
+ * 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.tree.tests;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory;
+import org.junit.Test;
+
+/**
+ * Test the CreaterepoTreeCategory class.
+ */
+public class CreaterepoTreeCategoryTest {
+
+ private static final String CATEGORY_NAME = "test"; //$NON-NLS-1$
+ private static final String TAG1 = "tag1"; //$NON-NLS-1$
+ private static final String TAG2 = "tag2"; //$NON-NLS-1$
+
+ /**
+ * Test the tree category to make sure it initializes and stores tags properly.
+ * Tags must be unique, so the category should not add tags that already exist
+ * within the category.
+ */
+ @Test
+ public void testCreaterepoTreeCategory() {
+ List<String> tagsToCheck = new ArrayList<String>();
+ tagsToCheck.add(TAG1);
+ tagsToCheck.add(TAG2);
+ CreaterepoTreeCategory categoryTest = new CreaterepoTreeCategory(CATEGORY_NAME);
+ assertEquals(0, categoryTest.getTags().size());
+ assertEquals(CATEGORY_NAME, categoryTest.getName());
+ categoryTest.addTag(TAG2);
+ assertEquals(1, categoryTest.getTags().size());
+ assertEquals(TAG2, categoryTest.getTags().get(0));
+ categoryTest.addAllTags(tagsToCheck);
+ // TAG2 should not be added again, hence size should = 2
+ assertEquals(2, categoryTest.getTags().size());
+ }
+
+}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeTest.java
new file mode 100644
index 0000000..585498e
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/tree/tests/CreaterepoTreeTest.java
@@ -0,0 +1,244 @@
+/*******************************************************************************
+ * 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.tree.tests;
+
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertTrue;
+import static org.junit.Assert.fail;
+
+import java.util.Arrays;
+import java.util.Collections;
+import java.util.HashMap;
+import java.util.Map;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.preferences.IEclipsePreferences;
+import org.eclipse.jface.viewers.TreeViewer;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoCategoryModel;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeCategory;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeContentProvider;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.CreaterepoTreeLabelProvider;
+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.TestCreaterepoProject;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Tree;
+import org.eclipse.swt.widgets.TreeItem;
+import org.eclipse.ui.PlatformUI;
+import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Before;
+import org.junit.BeforeClass;
+import org.junit.Test;
+import org.osgi.service.prefs.BackingStoreException;
+
+/**
+ * Tests for tag category tree. Make sure that preferences are properly loaded
+ * into the treeviewer and that the categories are the correct ones.
+ */
+public class CreaterepoTreeTest {
+
+ /*
+ * Tags being used to test with.
+ */
+ private static final String[] DISTRO_TAGS =
+ {"tag1","tag2","tag3","tag4","tag5"}; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$ //$NON-NLS-5$
+ private static final String[] CONTENT_TAGS = {};
+ private static final String[] REPO_TAGS = {"tag1"}; //$NON-NLS-1$
+
+ /*
+ * Categories being used to test with.
+ */
+ private static final Map<String, Integer> CORRECT_CATEGORIES;
+ static {
+ Map<String, Integer> temp = new HashMap<String, Integer>();
+ temp.put(CreaterepoPreferenceConstants.PREF_DISTRO_TAG, DISTRO_TAGS.length);
+ temp.put(CreaterepoPreferenceConstants.PREF_CONTENT_TAG, CONTENT_TAGS.length);
+ temp.put(CreaterepoPreferenceConstants.PREF_REPO_TAG, REPO_TAGS.length);
+ CORRECT_CATEGORIES = Collections.unmodifiableMap(temp);
+ }
+
+ private static TestCreaterepoProject testProject;
+ private CreaterepoProject project;
+ private TreeViewer viewer;
+ private Tree tree;
+
+ /**
+ * Initialize the test project.
+ *
+ * @throws CoreException
+ */
+ @BeforeClass
+ public static void setUpBeforeClass() throws CoreException {
+ testProject = new TestCreaterepoProject();
+ }
+
+ /**
+ * 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.
+ *
+ * @throws CoreException
+ */
+ @Before
+ public void setUp() throws CoreException {
+ project = testProject.getCreaterepoProject();
+ }
+
+ /**
+ * Clear the preferences after each test.
+ *
+ * @throws BackingStoreException
+ */
+ @After
+ public void tearDown() throws BackingStoreException {
+ IEclipsePreferences pref = project.getEclipsePreferences();
+ pref.clear();
+ pref.flush();
+ }
+
+ /**
+ * Test if the treeviewer is initialized properly with the correct labels.
+ *
+ * @throws CoreException
+ */
+ @Test
+ public void testTreeViewerInitialization() throws CoreException {
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ initViewer();
+ } catch (CoreException e) {
+ fail();
+ }
+ // there should only be 3 categories
+ assertEquals(3, tree.getItemCount());
+ // and these should be the correct categories
+ for (TreeItem treeItem : tree.getItems()) {
+ assertTrue(inCategory(treeItem.getText()));
+ }
+ }
+ });
+ }
+
+ /**
+ * Test if the treeviewer properly loads the preferences.
+ *
+ * @throws CoreException
+ * @throws BackingStoreException
+ */
+ @Test
+ public void testTreeViewerPreferences() throws CoreException, BackingStoreException {
+ addTestPreferences();
+ Display.getDefault().syncExec(new Runnable() {
+ @Override
+ public void run() {
+ try {
+ initViewer();
+ } catch (CoreException e) {
+ fail();
+ }
+ for (TreeItem treeItem : tree.getItems()) {
+ if (treeItem.getData() instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
+ // make sure the categories are still correct
+ assertTrue(CORRECT_CATEGORIES.containsKey(category.getName()));
+ // assert that the number of tags stored is the correct amount
+ assertEquals(CORRECT_CATEGORIES.get(category.getName()).intValue(), category.getTags().size());
+ }
+ }
+ // do 1 test to make sure the tags were properly stored/loaded
+ for (TreeItem treeItem : tree.getItems()) {
+ if (treeItem.getData() instanceof CreaterepoTreeCategory) {
+ CreaterepoTreeCategory category = (CreaterepoTreeCategory) treeItem.getData();
+ // only check 1 category's tags, as all are loaded the same way
+ if (category.getName().equals(CreaterepoPreferenceConstants.PREF_DISTRO_TAG)) {
+ assertTrue(Arrays.equals(DISTRO_TAGS, category.getTags().toArray()));
+ break;
+ }
+ }
+ }
+ }
+ });
+ }
+
+ /**
+ * Initialize the treeviewer and tree. Needs access to UI thread when using
+ * SWTBot tests. Need to wrap tests in Display.getDefault().syncExec().
+ *
+ * @throws CoreException
+ */
+ private void initViewer() throws CoreException {
+ viewer = new TreeViewer(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ viewer.setContentProvider(new CreaterepoTreeContentProvider());
+ viewer.setLabelProvider(new CreaterepoTreeLabelProvider());
+ CreaterepoCategoryModel model = new CreaterepoCategoryModel(project);
+ viewer.setInput(model);
+ tree = viewer.getTree();
+ }
+
+ /**
+ * Add some test tags in the preferences.
+ *
+ * @throws BackingStoreException
+ * @throws CoreException
+ */
+ private void addTestPreferences() throws BackingStoreException, CoreException {
+ IEclipsePreferences pref = project.getEclipsePreferences();
+ pref.put(CreaterepoPreferenceConstants.PREF_DISTRO_TAG, preparePrefValue(DISTRO_TAGS));
+ pref.put(CreaterepoPreferenceConstants.PREF_CONTENT_TAG, preparePrefValue(CONTENT_TAGS));
+ pref.put(CreaterepoPreferenceConstants.PREF_REPO_TAG, preparePrefValue(REPO_TAGS));
+ pref.flush();
+ }
+
+ /**
+ * Helper method to prepare the tags the way it should be stored in preferences.
+ *
+ * @param values The values to store.
+ * @return The string as it should be stored.
+ */
+ private String preparePrefValue(String[] values) {
+ String str = ICreaterepoConstants.EMPTY_STRING;
+ if (values.length > 0) {
+ for (String temp : values) {
+ str = str.concat(temp+ICreaterepoConstants.DELIMITER);
+ }
+ str = str.substring(0, str.length()-1);
+ }
+ return str;
+ }
+
+ /**
+ * Helper method to check if the item is one of the correct categories.
+ *
+ * @param itemToCheck The item to check.
+ * @return True if the item should exist, false otherwise.
+ */
+ private boolean inCategory(String itemToCheck) {
+ for (String str : CORRECT_CATEGORIES.keySet()) {
+ if (str.equals(itemToCheck)) {
+ return true;
+ }
+ }
+ return false;
+ }
+
+}
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 71b404d..9fdc848 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
@@ -15,6 +15,7 @@ import static org.junit.Assert.assertNotEquals;
import static org.junit.Assert.assertTrue;
import java.io.BufferedReader;
+import java.io.IOException;
import java.io.InputStreamReader;
import org.eclipse.core.resources.IFile;
@@ -22,6 +23,7 @@ import org.eclipse.core.resources.IFolder;
import org.eclipse.core.resources.IProject;
import org.eclipse.core.resources.IWorkspaceRoot;
import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.linuxtools.internal.rpm.createrepo.Messages;
import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectNature;
@@ -57,22 +59,37 @@ public class CreaterepoWizardTest {
private static NullProgressMonitor monitor;
private IProject project;
+ /**
+ * Setup the bot, monitor and workspace root.
+ */
@BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ public static void setUpBeforeClass() {
bot = new SWTWorkbenchBot();
root = ResourcesPlugin.getWorkspace().getRoot();
monitor = new NullProgressMonitor();
}
+ /**
+ * Delete the project and its contents for each test itereation.
+ *
+ * @throws CoreException
+ */
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws CoreException {
if (project != null && project.exists()) {
project.delete(true, monitor);
}
}
+ /**
+ * Go through the project creation wizard process of creating a new
+ * createrepo project.
+ *
+ * @throws CoreException
+ * @throws IOException
+ */
@Test
- public void testCreaterepoWizardProjectCreation() throws Exception {
+ public void testCreaterepoWizardProjectCreation() throws CoreException, IOException {
// go through the process of creating a new createrepo project
bot.menu(ICreaterepoTestConstants.FILE).menu(ICreaterepoTestConstants.NEW).menu(ICreaterepoTestConstants.OTHER).click();
SWTBotShell shell = bot.shell(ICreaterepoTestConstants.NEW);
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 86e4846..14b7dc7 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,8 @@
*******************************************************************************/
package org.eclipse.linuxtools.rpm.createrepo.tests;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.tests.CreaterepoTreeCategoryTest;
+import org.eclipse.linuxtools.internal.rpm.createrepo.tree.tests.CreaterepoTreeTest;
import org.eclipse.linuxtools.internal.rpm.createrepo.wizard.tests.CreaterepoWizardTest;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
@@ -17,6 +19,7 @@ import org.junit.runners.Suite.SuiteClasses;
@RunWith(Suite.class)
@SuiteClasses({CreaterepoProjectCreatorTest.class, CreaterepoUtilsTest.class,
- CreaterepoWizardTest.class, CreaterepoProjectTest.class})
+ CreaterepoProjectTest.class, CreaterepoTreeCategoryTest.class, CreaterepoTreeTest.class,
+ CreaterepoWizardTest.class})
public class AllTests {
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectCreatorTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectCreatorTest.java
index 3721008..f8c434a 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectCreatorTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectCreatorTest.java
@@ -45,11 +45,9 @@ public class CreaterepoProjectCreatorTest {
/**
* Initialize workspace root and progress monitor.
- *
- * @throws Exception
*/
@BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ public static void setUpBeforeClass() {
root = ResourcesPlugin.getWorkspace().getRoot();
monitor = new NullProgressMonitor();
}
@@ -57,10 +55,10 @@ public class CreaterepoProjectCreatorTest {
/**
* Create the project using CreaterepoProjectCreator.
*
- * @throws Exception
+ * @throws CoreException
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws CoreException{
if (project == null || !project.exists()) {
project = CreaterepoProjectCreator.create(PROJECT_NAME, root.getLocation(), REPO_NAME, monitor);
}
@@ -69,10 +67,10 @@ public class CreaterepoProjectCreatorTest {
/**
* Forcefully delete the project if it exists.
*
- * @throws Exception
+ * @throws CoreException
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws CoreException {
if (project != null && project.exists()) {
project.delete(true, monitor);
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java
index d0bd674..ce13ae0 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java
@@ -62,11 +62,9 @@ public class CreaterepoProjectTest {
/**
* Initialize workspace root and progress monitor.
- *
- * @throws Exception
*/
@BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ public static void setUpBeforeClass() {
root = ResourcesPlugin.getWorkspace().getRoot();
monitor = new NullProgressMonitor();
}
@@ -74,10 +72,10 @@ public class CreaterepoProjectTest {
/**
* Create the project using CreaterepoProjectCreator.
*
- * @throws Exception
+ * @throws CoreException
*/
@Before
- public void setUp() throws Exception {
+ public void setUp() throws CoreException {
if (project == null || !project.exists()) {
project = CreaterepoProjectCreator.create(PROJECT_NAME, root.getLocation(), REPO_NAME, monitor);
}
@@ -86,10 +84,10 @@ public class CreaterepoProjectTest {
/**
* Forcefully delete the project if it exists.
*
- * @throws Exception
+ * @throws CoreException
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() throws CoreException{
if (project != null && project.exists()) {
project.delete(true, monitor);
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java
index c41e739..1d16848 100644
--- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java
@@ -32,19 +32,20 @@ public class CreaterepoUtilsTest {
private static ConsolePlugin plugin;
private static IConsoleManager manager;
+ /**
+ * Setup the console manager.
+ */
@BeforeClass
- public static void setUpBeforeClass() throws Exception {
+ public static void setUpBeforeClass() {
plugin = ConsolePlugin.getDefault();
manager = plugin.getConsoleManager();
}
/**
* Find any consoles and remove them.
- *
- * @throws Exception
*/
@After
- public void tearDown() throws Exception {
+ public void tearDown() {
if (manager != null) {
manager.removeConsoles(manager.getConsoles());
}
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/TestCreaterepoProject.java b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/TestCreaterepoProject.java
new file mode 100644
index 0000000..87397e7
--- /dev/null
+++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/TestCreaterepoProject.java
@@ -0,0 +1,166 @@
+/*******************************************************************************
+ * 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.rpm.createrepo.tests;
+
+import java.io.ByteArrayInputStream;
+import java.io.InputStream;
+
+import org.eclipse.core.resources.IFile;
+import org.eclipse.core.resources.IFolder;
+import org.eclipse.core.resources.IProject;
+import org.eclipse.core.resources.IProjectDescription;
+import org.eclipse.core.resources.IResource;
+import org.eclipse.core.resources.IWorkspaceRoot;
+import org.eclipse.core.resources.ResourcesPlugin;
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.core.runtime.NullProgressMonitor;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject;
+import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectNature;
+import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants;
+import org.eclipse.linuxtools.rpm.createrepo.IRepoFileConstants;
+
+/**
+ * A class to create a test createrepo project. This will create the repo file
+ * and content folder without having to go through the project wizard. It also
+ * initializes the project nature and initializes the repo file's contents to
+ * being empty.
+ */
+public class TestCreaterepoProject {
+
+ /*
+ * Test names for the project and .repo file.
+ */
+ public static final String PROJECT_NAME = "createrepo-test-project"; //$NON-NLS-1$
+ public static final String REPO_NAME = "createrepo-test-repo.repo"; //$NON-NLS-1$
+
+ private static NullProgressMonitor monitor;
+ private IProject project;
+
+ /**
+ * Instantiating class creates project, content folder, and .repo file.
+ *
+ * @throws CoreException
+ */
+ public TestCreaterepoProject() throws CoreException {
+ monitor = new NullProgressMonitor();
+ IWorkspaceRoot root = ResourcesPlugin.getWorkspace().getRoot();
+ project = root.getProject(PROJECT_NAME);
+ IProjectDescription description = ResourcesPlugin.getWorkspace()
+ .newProjectDescription(PROJECT_NAME);
+ description.setNatureIds(new String[] {CreaterepoProjectNature.CREATEREPO_NATURE_ID});
+ if (!project.exists()) {
+ project.create(description, monitor);
+ }
+ project.open(monitor);
+ init();
+ }
+
+ /**
+ * Create the content folder and the .repo file.
+ *
+ * @throws CoreException
+ */
+ private void init() throws CoreException {
+ createFolder(ICreaterepoConstants.CONTENT_FOLDER);
+ createFile(REPO_NAME);
+ }
+
+ /**
+ * Create a folder in the project.
+ *
+ * @param folderName The name of the folder.
+ * @return The folder that was created.
+ * @throws CoreException
+ */
+ public IFolder createFolder(String folderName) throws CoreException {
+ IFolder folder = project.getFolder(folderName);
+ if (!folder.exists()) {
+ folder.create(false, true, monitor);
+ }
+ return folder;
+ }
+
+ /**
+ * Create a file in the project. Initialize empty content.
+ *
+ * @param fileName The name of the file.
+ * @return The file that was created.
+ * @throws CoreException
+ */
+ public IFile createFile(String fileName) throws CoreException {
+ IFile file = project.getFile(fileName);
+ InputStream stream = new ByteArrayInputStream(ICreaterepoConstants.EMPTY_STRING.getBytes());
+ if (!file.exists()) {
+ file.create(stream, true, monitor);
+ }
+ return file;
+ }
+
+ /**
+ * Delete the project and all its contents.
+ *
+ * @throws CoreException
+ */
+ public void dispose() throws CoreException {
+ project.delete(true, true, monitor);
+ }
+
+ /**
+ * Refresh the project.
+ *
+ * @throws CoreException
+ */
+ public void refresh() throws CoreException {
+ project.refreshLocal(IResource.DEPTH_INFINITE, null);
+ }
+
+ /**
+ * Return a new instance of a CreaterepoProject.
+ *
+ * @return A new CreaterepoProject.
+ * @throws CoreException
+ */
+ public CreaterepoProject getCreaterepoProject() throws CoreException {
+ return new CreaterepoProject(project, project.getFile(REPO_NAME));
+ }
+
+ /**
+ * Return the current project instance;
+ *
+ * @return The current project instance.
+ */
+ public IProject getProject() {
+ return project;
+ }
+
+ /**
+ * Set the file contents of the repofile if it exists, or create a repofile
+ * with the specified contents if it does not exist.
+ *
+ * @param id The repository ID.
+ * @param name The human-readable description of the repository.
+ * @param url The baseurl of the repository.
+ * @throws CoreException
+ */
+ public void setRepoFileContents(String id, String name, String url) throws CoreException {
+ String contents = String.format("[%s]\n", id); //$NON-NLS-1$
+ contents = contents.concat(String.format("%s=%s\n", IRepoFileConstants.NAME, name)); //$NON-NLS-1$
+ contents = contents.concat(String.format("%s=%s\n", IRepoFileConstants.BASE_URL, url)); //$NON-NLS-1$
+ InputStream stream = new ByteArrayInputStream(contents.getBytes());
+ IFile repoFile = project.getFile(REPO_NAME);
+ if (repoFile.exists()) {
+ repoFile.setContents(stream, true, true, monitor);
+ } else {
+ repoFile.create(stream, true, monitor);
+ }
+ }
+
+}