diff options
12 files changed, 520 insertions, 18 deletions
diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/META-INF/MANIFEST.MF b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/META-INF/MANIFEST.MF index 06a75093e6..7f5e815f1f 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/META-INF/MANIFEST.MF +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/META-INF/MANIFEST.MF @@ -6,4 +6,9 @@ Bundle-Version: 1.0.0.qualifier Fragment-Host: org.eclipse.linuxtools.rpm.createrepo;bundle-version="1.0.0" Bundle-RequiredExecutionEnvironment: JavaSE-1.6 Bundle-Vendor: %Bundle-Vendor -Require-Bundle: org.junit;bundle-version="4.8.1" +Require-Bundle: org.junit;bundle-version="4.8.1", + org.eclipse.swtbot.eclipse.finder, + org.eclipse.swtbot.junit4_x, + org.hamcrest.core, + org.apache.log4j, + org.eclipse.ui diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/plugin.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/OSGI-INF/l10n/bundle.properties index 7f665ff8a1..7f665ff8a1 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/plugin.properties +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/OSGI-INF/l10n/bundle.properties diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/build.properties b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/build.properties index aa1a008269..2d14ac2498 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/build.properties +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/build.properties @@ -2,4 +2,6 @@ source.. = src/ output.. = bin/ bin.includes = META-INF/,\ .,\ - plugin.properties + resources/,\ + OSGI-INF/ +src.includes = resources/ diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/pom.xml b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/pom.xml index 2a391f2b87..3d0322cc22 100644 --- a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/pom.xml +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/pom.xml @@ -31,7 +31,7 @@ <version>${tycho-version}</version> <configuration> <useUIHarness>true</useUIHarness> - <useUIThread>true</useUIThread> + <useUIThread>false</useUIThread> <product>org.eclipse.platform.ide</product> </configuration> </plugin> diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/eclipse-egit-github-3.0.0-2.fc19.noarch.rpm b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/eclipse-egit-github-3.0.0-2.fc19.noarch.rpm Binary files differnew file mode 100644 index 0000000000..3c68336c8c --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/eclipse-egit-github-3.0.0-2.fc19.noarch.rpm diff --git a/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/hello-2.8-1.fc19.src.rpm b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/hello-2.8-1.fc19.src.rpm Binary files differnew file mode 100644 index 0000000000..9b3cea8262 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/resources/rpms/hello-2.8-1.fc19.src.rpm 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 new file mode 100644 index 0000000000..71b404d3cd --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/internal/rpm/createrepo/wizard/tests/CreaterepoWizardTest.java @@ -0,0 +1,118 @@ +/******************************************************************************* + * 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.wizard.tests; + +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; +import static org.junit.Assert.assertTrue; + +import java.io.BufferedReader; +import java.io.InputStreamReader; + +import org.eclipse.core.resources.IFile; +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.NullProgressMonitor; +import org.eclipse.linuxtools.internal.rpm.createrepo.Messages; +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectNature; +import org.eclipse.linuxtools.rpm.createrepo.ICreaterepoConstants; +import org.eclipse.linuxtools.rpm.createrepo.IRepoFileConstants; +import org.eclipse.linuxtools.rpm.createrepo.tests.ICreaterepoTestConstants; +import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot; +import org.eclipse.swtbot.swt.finder.junit.SWTBotJunit4ClassRunner; +import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; +import org.junit.runner.RunWith; + +/** + * SWTBot tests for CreaterepoWizard. + */ +@RunWith(SWTBotJunit4ClassRunner.class) +public class CreaterepoWizardTest { + + private static final String PROJECT_NAME = "createrepo-test-project"; //$NON-NLS-1$ + private static final String REPO_ID = "createrepo-test-repo"; //$NON-NLS-1$ + private static final String REPO_FILE = REPO_ID.concat(".repo"); //$NON-NLS-1$ + + private static final String REPO_WIZARD_NAME = "Test repository for createrepo plugin"; //$NON-NLS-1$ + private static final String REPO_WIZARD_URL = "http://www.example.com/test"; //$NON-NLS-1$ + private static final String REPO_FILE_CONTENTS = + String.format("[%s]%s=%s%s=%s", REPO_ID, IRepoFileConstants.NAME, //$NON-NLS-1$ + REPO_WIZARD_NAME, IRepoFileConstants.BASE_URL, REPO_WIZARD_URL); + + private static SWTWorkbenchBot bot; + private static IWorkspaceRoot root; + private static NullProgressMonitor monitor; + private IProject project; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + bot = new SWTWorkbenchBot(); + root = ResourcesPlugin.getWorkspace().getRoot(); + monitor = new NullProgressMonitor(); + } + + @After + public void tearDown() throws Exception { + if (project != null && project.exists()) { + project.delete(true, monitor); + } + } + + @Test + public void testCreaterepoWizardProjectCreation() throws Exception { + // 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); + shell.activate(); + bot.tree().expandNode(ICreaterepoTestConstants.CREATEREPO_CATEGORY).select(ICreaterepoTestConstants.CREATEREPO_PROJECT_WIZARD); + bot.button(ICreaterepoTestConstants.NEXT_BUTTON).click(); + bot.textWithLabel(ICreaterepoTestConstants.PROJECT_NAME_LABEL).setText(PROJECT_NAME); + bot.button(ICreaterepoTestConstants.NEXT_BUTTON).click(); + bot.textWithLabel(Messages.CreaterepoNewWizardPageTwo_labelID).setText(REPO_ID); + bot.textWithLabel(Messages.CreaterepoNewWizardPageTwo_labelName).setText(REPO_WIZARD_NAME); + bot.textWithLabel(Messages.CreaterepoNewWizardPageTwo_labelURL).setText(REPO_WIZARD_URL); + bot.button(ICreaterepoTestConstants.FINISH_BUTTON).click(); + + // verify that project has been initialized properly + project = root.getProject(PROJECT_NAME); + assertTrue(project.exists()); + assertTrue(project.hasNature(CreaterepoProjectNature.CREATEREPO_NATURE_ID)); + // 3 = .project + content folder + .repo file + assertEquals(3, project.members().length); + + // contains the content folder and repo file + assertTrue(project.findMember(ICreaterepoConstants.CONTENT_FOLDER).exists()); + assertTrue(project.findMember(REPO_FILE).exists()); + + // content folder has nothing in it + IFolder contentFolder = (IFolder) project.findMember(ICreaterepoConstants.CONTENT_FOLDER); + assertEquals(0, contentFolder.members().length); + + // get the created .repo file contents + IFile repoFile = (IFile) project.findMember(REPO_FILE); + // repo file should not be empty + assertNotEquals(repoFile.getContents().available(), 0); + StringBuilder sb = new StringBuilder(); + BufferedReader br = new BufferedReader(new InputStreamReader(repoFile.getContents())); + String line; + while ((line = br.readLine()) != null) { + // disregards newline + sb.append(line); + } + assertEquals(REPO_FILE_CONTENTS, sb.toString()); + } + +} 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 fb0524be79..86e4846225 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,11 +10,13 @@ *******************************************************************************/ package org.eclipse.linuxtools.rpm.createrepo.tests; +import org.eclipse.linuxtools.internal.rpm.createrepo.wizard.tests.CreaterepoWizardTest; import org.junit.runner.RunWith; import org.junit.runners.Suite; import org.junit.runners.Suite.SuiteClasses; @RunWith(Suite.class) -@SuiteClasses({CreaterepoProjectCreatorTest.class}) +@SuiteClasses({CreaterepoProjectCreatorTest.class, CreaterepoUtilsTest.class, + CreaterepoWizardTest.class, CreaterepoProjectTest.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 c9082b529d..3721008a3d 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 @@ -16,13 +16,13 @@ import static org.junit.Assert.assertTrue; import java.io.IOException; import org.eclipse.core.resources.IFile; -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.rpm.createrepo.CreaterepoProjectCreator; +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectNature; import org.junit.After; import org.junit.Before; import org.junit.BeforeClass; @@ -30,14 +30,14 @@ import org.junit.Test; /** * Test case for project creation with CreaterepoProjectCreatorTest class. - * This checks if the project creator is working and creating a project with - * an empty content folder and un-initialized .repo file. + * This checks if the project creator is working, but does not check for + * initializing of .repo file contents and the content folder. These are done + * via the wizard (SWTBot test should handle this). */ public class CreaterepoProjectCreatorTest { private static final String PROJECT_NAME = "createrepo-test-project"; //$NON-NLS-1$ private static final String REPO_NAME = "createrepo-test-repo.repo"; //$NON-NLS-1$ - private static final String CONTENT_FOLDER = "content"; //$NON-NLS-1$ private static IWorkspaceRoot root; private static NullProgressMonitor monitor; @@ -79,8 +79,9 @@ public class CreaterepoProjectCreatorTest { } /** - * Test to see if the project has been properly created and the contents - * initialized. + * Test to see if the project has been properly created. Content folder + * should not appear due to CreaterepoWizard handling its creation. Repo + * file should be empty for the same reason. * * @throws CoreException * @throws IOException @@ -88,21 +89,26 @@ public class CreaterepoProjectCreatorTest { @Test public void testProjectContents() throws CoreException, IOException { assertTrue(project.exists()); - // 3 = .project + content folder + .repo file - assertEquals(3, project.members().length); + // 3 = .project + .repo file + assertEquals(2, project.members().length); - // contains content folder and repo file - assertTrue(project.findMember(CONTENT_FOLDER).exists()); + // contains the repo file assertTrue(project.findMember(REPO_NAME).exists()); - IFolder contentFolder = (IFolder) project.findMember(CONTENT_FOLDER); - // content folder should be empty - assertEquals(0, contentFolder.members().length); - IFile repoFile = (IFile) project.findMember(REPO_NAME); // repo file should be empty because test did not go through project creation // to initialize .repo contents assertEquals(repoFile.getContents().available(), 0); } + /** + * Test to see if the project has the proper nature. + * + * @throws CoreException + */ + @Test + public void testProjectNature() throws CoreException { + assertTrue(project.hasNature(CreaterepoProjectNature.CREATEREPO_NATURE_ID)); + } + } 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 new file mode 100644 index 0000000000..d0bd674ae0 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoProjectTest.java @@ -0,0 +1,228 @@ +/******************************************************************************* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertFalse; +import static org.junit.Assert.assertTrue; + +import java.io.File; +import java.io.IOException; +import java.net.URL; +import java.util.List; + +import org.eclipse.core.resources.IFile; +import org.eclipse.core.resources.IFolder; +import org.eclipse.core.resources.IProject; +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.FileLocator; +import org.eclipse.core.runtime.IStatus; +import org.eclipse.core.runtime.NullProgressMonitor; +import org.eclipse.core.runtime.Path; +import org.eclipse.core.runtime.Status; +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProject; +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoProjectCreator; +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils; +import org.junit.After; +import org.junit.Before; +import org.junit.BeforeClass; +import org.junit.Test; +import org.osgi.framework.FrameworkUtil; +import org.osgi.service.prefs.BackingStoreException; + +/** + * Tests for CreaterepoProject. + */ +public class CreaterepoProjectTest { + + private static final String PROJECT_NAME = "createrepo-test-project"; //$NON-NLS-1$ + private static final String REPO_NAME = "createrepo-test-repo.repo"; //$NON-NLS-1$ + + 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 final String TEST_RPM2 = "hello-2.8-1.fc19.src.rpm"; //$NON-NLS-1$ + private static final String TEST_RPM_LOC2 = ICreaterepoTestConstants.RPM_RESOURCE_LOC + .concat(TEST_RPM2); + + private static IWorkspaceRoot root; + private static NullProgressMonitor monitor; + private IProject project; + + /** + * Initialize workspace root and progress monitor. + * + * @throws Exception + */ + @BeforeClass + public static void setUpBeforeClass() throws Exception { + root = ResourcesPlugin.getWorkspace().getRoot(); + monitor = new NullProgressMonitor(); + } + + /** + * Create the project using CreaterepoProjectCreator. + * + * @throws Exception + */ + @Before + public void setUp() throws Exception { + if (project == null || !project.exists()) { + project = CreaterepoProjectCreator.create(PROJECT_NAME, root.getLocation(), REPO_NAME, monitor); + } + } + + /** + * Forcefully delete the project if it exists. + * + * @throws Exception + */ + @After + public void tearDown() throws Exception { + if (project != null && project.exists()) { + project.delete(true, monitor); + } + } + + /** + * Test if initializing createrepo project is successful. This means that + * content folder is initialized but not created (done by wizard, import, or + * execute commands) and that .repo file exists. + * + * @throws CoreException + */ + @Test + public void testInitialize() throws CoreException { + assertTrue(project.exists()); + CreaterepoProject createrepoProject = new CreaterepoProject(project, (IFile)project.findMember(REPO_NAME)); + // content folder is defined, but not created (wizard does that) + assertTrue(createrepoProject.getContentFolder() != null); + assertFalse(createrepoProject.getContentFolder().exists()); + // repo file is found and exists + assertTrue(createrepoProject.getRepoFile() != null); + assertTrue(createrepoProject.getRepoFile().exists()); + assertEquals(REPO_NAME, createrepoProject.getRepoFile().getName()); + } + + /** + * Test if initializing createrepo project is successful + * without specifying .repo file. + * + * @throws CoreException + * @throws BackingStoreException + */ + @Test + public void testInitializeNoRepoFileSpecfied() throws CoreException, BackingStoreException { + assertTrue(project.exists()); + // repo file will be found rather than initialized + CreaterepoProject createrepoProject = new CreaterepoProject(project); + // content folder is defined, but not created (wizard does that) + assertTrue(createrepoProject.getContentFolder() != null); + assertFalse(createrepoProject.getContentFolder().exists()); + // repo file is found and exists + assertTrue(createrepoProject.getRepoFile() != null); + assertTrue(createrepoProject.getRepoFile().exists()); + assertEquals(REPO_NAME, createrepoProject.getRepoFile().getName()); + } + + /** + * Test if importing RPMs from external source successfully saves into + * the "content" folder. + * + * @throws CoreException + * @throws IOException + */ + @Test + public void testImportRPM() throws CoreException, IOException { + CreaterepoProject createrepoProject = new CreaterepoProject(project); + + // test for file + URL rpmURL = FileLocator.find(FrameworkUtil + .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null); + File rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath()); + createrepoProject.importRPM(rpmFile); + assertTrue(createrepoProject.getContentFolder() != null); + assertTrue(createrepoProject.getContentFolder().exists()); + assertEquals(1, createrepoProject.getContentFolder().members().length); + assertTrue(createrepoProject.getContentFolder().findMember(TEST_RPM1).exists()); + + // test for duplicate file + rpmURL = FileLocator.find(FrameworkUtil + .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null); + rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath()); + createrepoProject.importRPM(rpmFile); + assertEquals(1, createrepoProject.getContentFolder().members().length); + assertTrue(createrepoProject.getContentFolder().findMember(TEST_RPM1).exists()); + + // test for new file + rpmURL = FileLocator.find(FrameworkUtil + .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC2), null); + rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath()); + createrepoProject.importRPM(rpmFile); + assertEquals(2, createrepoProject.getContentFolder().members().length); + assertTrue(createrepoProject.getContentFolder().findMember(TEST_RPM2).exists()); + } + + /** + * Test if getting the RPMs is successful. + * + * @throws CoreException + * @throws IOException + */ + @Test + public void testGetRPMs() throws CoreException, IOException { + CreaterepoProject createrepoProject = new CreaterepoProject(project); + URL rpmURL = FileLocator.find(FrameworkUtil + .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC1), null); + File rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath()); + createrepoProject.importRPM(rpmFile); + rpmURL = FileLocator.find(FrameworkUtil + .getBundle(CreaterepoProjectTest.class), new Path(TEST_RPM_LOC2), null); + rpmFile = new File(FileLocator.toFileURL(rpmURL).getPath()); + createrepoProject.importRPM(rpmFile); + + List<IResource> rpms = createrepoProject.getRPMs(); + assertEquals(2, rpms.size()); + } + + /** + * Simple test execution of createrepo. This checks to see if the "content" folder + * was created while executing and that the execution is successful if repomd.xml was created + * under the repodata folder. + * + * @throws CoreException + */ + @Test + public void testSimpleExecute() throws CoreException { + CreaterepoProject createrepoProject = new CreaterepoProject(project); + assertTrue(!createrepoProject.getContentFolder().exists()); + IStatus status = createrepoProject.createrepo(CreaterepoUtils.findConsole("test").newMessageStream()); //$NON-NLS-1$ + + // check if executing has an OK status and that content folder is created with the repodata contents + assertEquals(Status.OK_STATUS, status); + assertTrue(createrepoProject.getContentFolder().exists()); + assertTrue(createrepoProject.getContentFolder().members().length > 0); + + // check if the repodata folder exists and repomd.xml exists within it + assertTrue(createrepoProject.getContentFolder().findMember( + ICreaterepoTestConstants.REPODATA_FOLDER).exists()); + IFolder repodataFolder = (IFolder) createrepoProject.getContentFolder() + .findMember(ICreaterepoTestConstants.REPODATA_FOLDER); + // repodata should have at least more than 1 file: repomd.xml + archives + assertTrue(repodataFolder.members().length > 1); + assertTrue(repodataFolder.findMember(ICreaterepoTestConstants.REPO_MD_NAME) + .exists()); + } + +} 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 new file mode 100644 index 0000000000..c41e739711 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/CreaterepoUtilsTest.java @@ -0,0 +1,92 @@ +/******************************************************************************* + * 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 static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotEquals; + +import org.eclipse.linuxtools.rpm.createrepo.CreaterepoUtils; +import org.eclipse.ui.console.ConsolePlugin; +import org.eclipse.ui.console.IConsole; +import org.eclipse.ui.console.IConsoleManager; +import org.eclipse.ui.console.MessageConsole; +import org.junit.After; +import org.junit.BeforeClass; +import org.junit.Test; + +/** + * Tests for CreaterepoUtils. + */ +public class CreaterepoUtilsTest { + + private static final String CONSOLE_NAME = "CreaterepoConsole"; //$NON-NLS-1$ + + private static ConsolePlugin plugin; + private static IConsoleManager manager; + + @BeforeClass + public static void setUpBeforeClass() throws Exception { + plugin = ConsolePlugin.getDefault(); + manager = plugin.getConsoleManager(); + } + + /** + * Find any consoles and remove them. + * + * @throws Exception + */ + @After + public void tearDown() throws Exception { + if (manager != null) { + manager.removeConsoles(manager.getConsoles()); + } + } + + /** + * Test if findConsole method finds correct console. + */ + @Test + public void testFindConsoleSameObject() { + MessageConsole createrepoConsole = new MessageConsole(CONSOLE_NAME, null, null, true); + manager.addConsoles(new IConsole[] { + new MessageConsole("DummyConsole1", null, null, true), //$NON-NLS-1$ + createrepoConsole, + new MessageConsole("DummyConsole2", null, null, true) //$NON-NLS-1$ + }); + assertEquals(createrepoConsole, CreaterepoUtils.findConsole(CONSOLE_NAME)); + } + + /** + * Test if findConsole finds correct console by name. + */ + @Test + public void testFindConsoleByName() { + MessageConsole createrepoConsole = new MessageConsole(CONSOLE_NAME, null, null, true); + manager.addConsoles(new IConsole[] { + new MessageConsole("DummyConsole1", null, null, true), //$NON-NLS-1$ + new MessageConsole(CONSOLE_NAME, null, null, true), + new MessageConsole("DummyConsole2", null, null, true) //$NON-NLS-1$ + }); + assertNotEquals(createrepoConsole, CreaterepoUtils.findConsole(CONSOLE_NAME)); + assertEquals(CONSOLE_NAME, CreaterepoUtils.findConsole(CONSOLE_NAME).getName()); + } + + /** + * Test if findConsole creates a console with correct name. + */ + @Test + public void testCreateConsoleIfNotFound() { + MessageConsole console = CreaterepoUtils.findConsole(CONSOLE_NAME); + assertNotEquals(null, console); + assertEquals(CONSOLE_NAME, console.getName()); + } + +} 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 new file mode 100644 index 0000000000..2b6d4908e5 --- /dev/null +++ b/rpm/org.eclipse.linuxtools.rpm.createrepo.tests/src/org/eclipse/linuxtools/rpm/createrepo/tests/ICreaterepoTestConstants.java @@ -0,0 +1,49 @@ +/******************************************************************************* + * 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; + + +/** + * Constants used for SWTBot testing. + */ +public interface ICreaterepoTestConstants { + + /* + * Dialog specific stuff + */ + String FILE = "File"; //$NON-NLS-1$ + String NEW = "New"; //$NON-NLS-1$ + String OTHER = "Other..."; //$NON-NLS-1$ + String NEXT_BUTTON = "Next >"; //$NON-NLS-1$ + String BACK_BUTTON = "< Back"; //$NON-NLS-1$ + String FINISH_BUTTON = "Finish"; //$NON-NLS-1$ + String CANCEL_BUTTON = "Cancel"; //$NON-NLS-1$ + + /* + * Project Wizard Specific Stuff + */ + String PROJECT_NAME_LABEL = "Project name:"; //$NON-NLS-1$ + String CREATEREPO_CATEGORY = "Createrepo"; //$NON-NLS-1$ + String CREATEREPO_PROJECT_WIZARD = "Createrepo Wizard"; //$NON-NLS-1$ + + /* + * Resources + */ + String RPM_RESOURCE_LOC = "resources" + System.getProperty("file.separator") //$NON-NLS-1$//$NON-NLS-2$ + + "rpms" + System.getProperty("file.separator"); //$NON-NLS-1$ //$NON-NLS-2$ + + /* + * Common createrepo files + */ + String REPODATA_FOLDER = "repodata"; //$NON-NLS-1$ + String REPO_MD_NAME = "repomd.xml"; //$NON-NLS-1$ + +} |