summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Perron2013-09-06 12:05:26 (EDT)
committerFrancois Chouinard2013-09-19 09:43:14 (EDT)
commit69b61281adba5ef55e342d1ad3dbd6d2e7943c44 (patch)
treed4fd12e68f2defb8ceb8c6b5d9ca680b71d9ad77
parentb7e78d34ad8f1889d499b05b72f1efdaecc2fd19 (diff)
downloadorg.eclipse.mylyn.reviews.r4e-69b61281adba5ef55e342d1ad3dbd6d2e7943c44.zip
org.eclipse.mylyn.reviews.r4e-69b61281adba5ef55e342d1ad3dbd6d2e7943c44.tar.gz
org.eclipse.mylyn.reviews.r4e-69b61281adba5ef55e342d1ad3dbd6d2e7943c44.tar.bz2
Add test case for the r4e-gerrit-uirefs/changes/97/16597/1
Change-Id: Ia7c19dc6e36c133251ccdf9c3181166b9ec32dad Signed-off-by: Guy Perron <guy.perron@ericsson.com>
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.classpath10
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.project28
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.settings/org.eclipse.jdt.core.prefs11
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/META-INF/MANIFEST.MF40
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/build.properties6
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/plugin.xml30
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/Activator.java61
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritServerUtilityTest.java228
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritTableViewTest.java155
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui/META-INF/MANIFEST.MF5
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/internal/utils/R4EGerritServerUtility.java38
-rw-r--r--org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4egerrit/ui/views/R4EGerritTableView.java26
12 files changed, 620 insertions, 18 deletions
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.classpath b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.classpath
new file mode 100644
index 0000000..4aa921f
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.classpath
@@ -0,0 +1,10 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<classpath>
+ <classpathentry exported="true" kind="lib" path="C:/gitPatch/guy/javassist-3.9.0.GA.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/gitPatch/guy/mockito-all-1.9.5.jar"/>
+ <classpathentry exported="true" kind="lib" path="C:/gitPatch/guy/powermock-mockito-1.5.1-full.jar"/>
+ <classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/JavaSE-1.6"/>
+ <classpathentry kind="con" path="org.eclipse.pde.core.requiredPlugins"/>
+ <classpathentry kind="src" path="src"/>
+ <classpathentry kind="output" path="bin"/>
+</classpath>
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.project b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.project
new file mode 100644
index 0000000..07e7afd
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.project
@@ -0,0 +1,28 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<projectDescription>
+ <name>org.eclipse.mylyn.reviews.r4e-gerrit.ui.test</name>
+ <comment></comment>
+ <projects>
+ </projects>
+ <buildSpec>
+ <buildCommand>
+ <name>org.eclipse.jdt.core.javabuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.ManifestBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ <buildCommand>
+ <name>org.eclipse.pde.SchemaBuilder</name>
+ <arguments>
+ </arguments>
+ </buildCommand>
+ </buildSpec>
+ <natures>
+ <nature>org.eclipse.pde.PluginNature</nature>
+ <nature>org.eclipse.jdt.core.javanature</nature>
+ </natures>
+</projectDescription>
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.settings/org.eclipse.jdt.core.prefs b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.settings/org.eclipse.jdt.core.prefs
new file mode 100644
index 0000000..8000cd6
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/.settings/org.eclipse.jdt.core.prefs
@@ -0,0 +1,11 @@
+eclipse.preferences.version=1
+org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
+org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.6
+org.eclipse.jdt.core.compiler.codegen.unusedLocal=preserve
+org.eclipse.jdt.core.compiler.compliance=1.6
+org.eclipse.jdt.core.compiler.debug.lineNumber=generate
+org.eclipse.jdt.core.compiler.debug.localVariable=generate
+org.eclipse.jdt.core.compiler.debug.sourceFile=generate
+org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
+org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
+org.eclipse.jdt.core.compiler.source=1.6
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/META-INF/MANIFEST.MF b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/META-INF/MANIFEST.MF
new file mode 100644
index 0000000..fb7e3e3
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/META-INF/MANIFEST.MF
@@ -0,0 +1,40 @@
+Manifest-Version: 1.0
+Bundle-ManifestVersion: 2
+Bundle-Name: Test
+Bundle-SymbolicName: org.eclipse.mylyn.reviews.r4e-gerrit.ui.test;singleton:=true
+Bundle-Version: 0.21.0.qualifier
+Bundle-Activator: org.eclipse.mylyn.reviews.r4e_gerrit.ui.test.Activator
+Require-Bundle: org.eclipse.core.runtime,
+ org.eclipse.core.resources;bundle-version="3.5.0",
+ org.eclipse.jgit,
+ org.eclipse.egit.core,
+ org.eclipse.jdt.core;bundle-version="3.5.0",
+ org.eclipse.jdt.launching;bundle-version="3.5.200",
+ org.eclipse.cdt.core;bundle-version="5.2.1",
+ org.eclipse.ui.views.properties.tabbed;bundle-version="3.5.0",
+ org.eclipse.emf.ecore;bundle-version="2.5.0",
+ org.mockito,
+ org.eclipse.ui.navigator.resources;bundle-version="3.4.202",
+ org.eclipse.ui.navigator;bundle-version="3.5.0",
+ org.eclipse.mylyn.versions.ui;bundle-version="0.9.0",
+ org.eclipse.mylyn.versions.core;bundle-version="0.9.0",
+ org.eclipse.team.core;bundle-version="3.5.101",
+ org.eclipse.team.ui;bundle-version="3.5.102",
+ org.eclipse.compare;bundle-version="3.5.101",
+ org.eclipse.mylyn.reviews.notifications;bundle-version="0.9.0",
+ org.hamcrest;bundle-version="[1.0.0,2.0.0)",
+ org.eclipse.mylyn.git.ui;bundle-version="0.9.1",
+ org.eclipse.mylyn.git.core;bundle-version="0.9.1",
+ org.eclipse.mylyn.reviews.ldap;bundle-version="0.10.0",
+ org.eclipse.mylyn.reviews.r4e.ui,
+ org.eclipse.mylyn.reviews.frame.core,
+ org.eclipse.mylyn.reviews.r4e.core,
+ org.eclipse.mylyn.reviews.r4e.upgrade,
+ org.junit,
+ org.eclipse.mylyn.reviews.r4e-gerrit.ui,
+ org.eclipse.mylyn.tasks.core;bundle-version="3.10.0",
+ org.eclipse.mylyn.gerrit.core,
+ org.eclipse.mylyn.reviews.r4e-gerrit,
+ org.eclipse.mylyn.tasks.ui
+Bundle-RequiredExecutionEnvironment: JavaSE-1.6
+Bundle-ActivationPolicy: lazy
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/build.properties b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/build.properties
new file mode 100644
index 0000000..0d3d3a7
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/build.properties
@@ -0,0 +1,6 @@
+source.. = src/
+output.. = bin/
+bin.includes = plugin.xml,\
+ META-INF/,\
+ .,\
+ icons/
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/plugin.xml b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/plugin.xml
new file mode 100644
index 0000000..f3efb18
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/plugin.xml
@@ -0,0 +1,30 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<?eclipse version="3.4"?>
+<plugin>
+
+ <extension
+ point="org.eclipse.ui.actionSets">
+ <actionSet
+ label="Sample Action Set"
+ visible="true"
+ id="org.eclipse.mylyn.reviews.r4e-gerrit.ui.test.actionSet">
+ <menu
+ label="Sample &amp;Menu"
+ id="sampleMenu">
+ <separator
+ name="sampleGroup">
+ </separator>
+ </menu>
+ <action
+ label="&amp;Sample Action"
+ icon="icons/sample.gif"
+ class="org.eclipse.mylyn.reviews.r4egerrit.ui.test.actions.SampleAction"
+ tooltip="Hello, Eclipse world"
+ menubarPath="sampleMenu/sampleGroup"
+ toolbarPath="sampleGroup"
+ id="org.eclipse.mylyn.reviews.r4egerrit.ui.test.actions.SampleAction">
+ </action>
+ </actionSet>
+ </extension>
+
+</plugin>
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/Activator.java b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/Activator.java
new file mode 100644
index 0000000..59a5937
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/Activator.java
@@ -0,0 +1,61 @@
+package org.eclipse.mylyn.reviews.r4e_gerrit.ui.test;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.ui.plugin.AbstractUIPlugin;
+import org.osgi.framework.BundleContext;
+
+/**
+ * The activator class controls the plug-in life cycle
+ */
+public class Activator extends AbstractUIPlugin {
+
+ // The plug-in ID
+ public static final String PLUGIN_ID = "org.eclipse.mylyn.reviews.r4e-gerrit.ui.test"; //$NON-NLS-1$
+
+ // The shared instance
+ private static Activator plugin;
+
+ /**
+ * The constructor
+ */
+ public Activator() {
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#start(org.osgi.framework.BundleContext)
+ */
+ public void start(BundleContext context) throws Exception {
+ super.start(context);
+ plugin = this;
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see org.eclipse.ui.plugin.AbstractUIPlugin#stop(org.osgi.framework.BundleContext)
+ */
+ public void stop(BundleContext context) throws Exception {
+ plugin = null;
+ super.stop(context);
+ }
+
+ /**
+ * Returns the shared instance
+ *
+ * @return the shared instance
+ */
+ public static Activator getDefault() {
+ return plugin;
+ }
+
+ /**
+ * Returns an image descriptor for the image file at the given
+ * plug-in relative path
+ *
+ * @param path the path
+ * @return the image descriptor
+ */
+ public static ImageDescriptor getImageDescriptor(String path) {
+ return imageDescriptorFromPlugin(PLUGIN_ID, path);
+ }
+}
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritServerUtilityTest.java b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritServerUtilityTest.java
new file mode 100644
index 0000000..b459334
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritServerUtilityTest.java
@@ -0,0 +1,228 @@
+package org.eclipse.mylyn.reviews.r4e_gerrit.ui.test;
+
+import static org.junit.Assert.*;
+
+import java.util.Map;
+import java.util.Set;
+
+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.mockito.Mock;
+import org.mockito.Mockito;
+
+import static org.mockito.Matchers.anyString;
+import static org.mockito.Mockito.*;
+
+import org.mockito.*;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import static org.junit.Assert.assertEquals;
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+import org.eclipse.mylyn.internal.gerrit.core.GerritConnector;
+import org.eclipse.mylyn.internal.tasks.core.RepositoryTemplateManager;
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.utils.R4EGerritServerUtility;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+
+//@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
+@PrepareForTest(TasksUiPlugin.class)
+
+public class R4EGerritServerUtilityTest {
+
+ @BeforeClass
+ public static void setUpBeforeClass() throws Exception {
+ }
+
+ @AfterClass
+ public static void tearDownAfterClass() throws Exception {
+ }
+
+ @Before
+ public void setUp() throws Exception {
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+ @Test
+ public void testR4EGerritServerUtility() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(null);
+
+ R4EGerritServerUtility r4eGerritServerUtility = R4EGerritServerUtility.getInstance();
+
+ assertNotNull(r4eGerritServerUtility);
+ }
+
+// @Test
+ public void testMapConfiguredGerritServerNoRepoManager() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(null);
+ R4EGerritServerUtility r4eGerritServerUtility = R4EGerritServerUtility.getInstance();
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(null);
+
+
+ Map<TaskRepository, String> ret;
+
+ ret = r4eGerritServerUtility.getGerritMapping();
+
+ assertEquals(ret,null);
+ }
+
+// @Test
+ public void testMapConfiguredGerritServer() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+// Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(null);
+ R4EGerritServerUtility r4eGerritServerUtility = R4EGerritServerUtility.getInstance();
+
+// TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+// repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+ Map<TaskRepository, String> ret;
+
+ ret = r4eGerritServerUtility.getGerritMapping();
+
+ assertNotNull(ret);
+
+
+ }
+
+ @Test
+ public void testGetGerritMappingOneServer() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+
+ RepositoryTemplateManager templateManager = new RepositoryTemplateManager();
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(templateManager);
+
+
+ Map<TaskRepository, String> ret;
+
+ ret = R4EGerritServerUtility.getInstance().getGerritMapping();
+
+ assertEquals(ret.size(),1);
+ }
+
+
+ @Test
+ public void testGetGerritMappingRepoManagerNull() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(null);
+
+ Map<TaskRepository, String> ret;
+
+ ret = R4EGerritServerUtility.getInstance().getGerritMapping();
+
+ assertEquals(ret.size(),0);
+ }
+
+// @Test
+ public void testGetGerritMappingRepositoriesNull() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+
+
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ TaskRepositoryManager repoManager = mock(TaskRepositoryManager.class);
+
+ Mockito.when(repoManager.getRepositories(anyString())).thenReturn(null);
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+
+ Map<TaskRepository, String> ret;
+
+ ret = R4EGerritServerUtility.getInstance().getGerritMapping();
+
+ assertEquals(ret.size(),0);
+ }
+
+// @Test
+ public void testSaveLastGerritServer() {
+ fail("Not yet implemented");
+ }
+
+// @Test
+ public void testGetLastSavedGerritServer() {
+ fail("Not yet implemented");
+ }
+
+ @Test
+ public void testGetMenuSelectionURL() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+
+ RepositoryTemplateManager templateManager = new RepositoryTemplateManager();
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(templateManager);
+
+
+ Map<TaskRepository, String> ret;
+
+ ret = R4EGerritServerUtility.getInstance().getGerritMapping();
+
+ assertEquals(ret.size(),1);
+
+ String res = R4EGerritServerUtility.getInstance().getMenuSelectionURL("http://repository");
+
+ assertTrue(res.compareTo( new String ("http://repository")) == 0);
+
+ }
+
+ @Test
+ public void testGetTaskRepo() {
+ PowerMockito.mockStatic(TasksUiPlugin.class);
+ TaskRepositoryManager repositoryManager = new TaskRepositoryManager();
+ repositoryManager.addRepository(new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"));
+
+ Mockito.when(TasksUiPlugin.getRepositoryManager()).thenReturn(repositoryManager);
+
+ RepositoryTemplateManager templateManager = new RepositoryTemplateManager();
+ Mockito.when(TasksUiPlugin.getRepositoryTemplateManager()).thenReturn(templateManager);
+
+
+ Map<TaskRepository, String> ret;
+
+ ret = R4EGerritServerUtility.getInstance().getGerritMapping();
+
+ assertEquals(ret.size(),1);
+
+ TaskRepository res = R4EGerritServerUtility.getInstance().getTaskRepo("http://repository");
+
+ assertTrue(res.getRepositoryUrl().compareTo( new String ("http://repository")) == 0);
+ }
+
+}
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritTableViewTest.java b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritTableViewTest.java
new file mode 100644
index 0000000..eb5bd6d
--- /dev/null
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui.test/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/test/R4EGerritTableViewTest.java
@@ -0,0 +1,155 @@
+package org.eclipse.mylyn.reviews.r4e_gerrit.ui.test;
+
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.Map;
+
+import org.eclipse.mylyn.reviews.r4e_gerrit.ui.R4EGerritUi;
+import org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.model.ReviewTableData;
+import org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.utils.R4EGerritServerUtility;
+import org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.utils.UIUtils;
+import org.eclipse.mylyn.reviews.r4egerrit.ui.views.R4EGerritTableView;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.internal.gerrit.core.GerritConnector;
+import org.eclipse.mylyn.internal.gerrit.core.GerritCorePlugin;
+import org.eclipse.mylyn.internal.gerrit.core.GerritQuery;
+import org.junit.After;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.mockito.Mock;
+
+import static org.mockito.Mockito.*;
+
+import org.mockito.*;
+import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
+
+import static org.junit.Assert.assertEquals;
+
+import org.powermock.modules.junit4.PowerMockRunner;
+
+
+//@RunWith(MockitoJUnitRunner.class)
+@RunWith(PowerMockRunner.class)
+//
+@PrepareForTest(R4EGerritServerUtility.class)
+
+
+public class R4EGerritTableViewTest {
+
+
+ private R4EGerritTableView r4eGerritTableView;
+ @Mock
+ private R4EGerritServerUtility fServerUtil;
+
+
+ @Test
+ public void setUp() throws Exception {
+
+ }
+
+ @After
+ public void tearDown() throws Exception {
+ }
+
+// @Test
+ public void testProcessCommandsNoSavedServer() {
+ r4eGerritTableView = new R4EGerritTableView();
+ GerritConnector fConnector = mock(GerritConnector.class);
+ ReviewTableData fReviewTable = mock(ReviewTableData.class);
+ R4EGerritServerUtility fServerUtil = mock(R4EGerritServerUtility.class);
+ r4eGerritTableView.setConnector(fConnector);
+ r4eGerritTableView.setReviewTableData(fReviewTable);
+ r4eGerritTableView.setGerritServerUtility(fServerUtil);
+
+ String ret = null;
+ when(fServerUtil.getLastSavedGerritServer()).thenReturn(ret);
+
+ // Last saved is null, a repository must be defined.
+ r4eGerritTableView.processCommands(GerritQuery.CUSTOM);
+
+ assertEquals(r4eGerritTableView.getTaskRepository(),null);
+
+
+
+
+ }
+
+// @Test
+ public void testProcessCommandsNoGerritRepo() {
+ PowerMockito.mockStatic(R4EGerritServerUtility.class);
+ PowerMockito.mockStatic(GerritCorePlugin.class);
+
+ Mockito.when(GerritCorePlugin.getDefault().getConnector()).thenReturn(null);
+
+ r4eGerritTableView = new R4EGerritTableView();
+ GerritConnector fConnector = mock(GerritConnector.class);
+ ReviewTableData fReviewTable = mock(ReviewTableData.class);
+ R4EGerritServerUtility fServerUtil = mock(R4EGerritServerUtility.class);
+ r4eGerritTableView.setConnector(fConnector);
+ r4eGerritTableView.setReviewTableData(fReviewTable);
+ r4eGerritTableView.setGerritServerUtility(fServerUtil);
+
+
+ // last saved exists
+ fReviewTable = new ReviewTableData();
+ r4eGerritTableView.setReviewTableData(fReviewTable);
+ when(fServerUtil.getLastSavedGerritServer()).thenReturn("lastSavedGerritServer");
+
+
+ when(fServerUtil.getTaskRepo(anyString())).thenReturn( new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository") );
+
+ // no server defined
+ Map<TaskRepository, String> fMapRepoServer = new HashMap<TaskRepository, String>();
+ Mockito.when(R4EGerritServerUtility.getInstance().getGerritMapping()).thenReturn(fMapRepoServer);
+
+ r4eGerritTableView.processCommands(GerritQuery.CUSTOM);
+
+ // check what now ?
+
+ }
+
+// @Test
+ public void testProcessCommandsOneGerritRepo() {
+
+ PowerMockito.mockStatic(R4EGerritServerUtility.class);
+ String msg = "testProcessCommands2";
+ String reason = "testProcessCommands2.";
+ R4EGerritUi.Ftracer.traceInfo(msg );
+ UIUtils.showErrorDialog(msg, reason);
+
+ r4eGerritTableView = new R4EGerritTableView();
+ GerritConnector fConnector = mock(GerritConnector.class);
+ ReviewTableData fReviewTable = mock(ReviewTableData.class);
+ R4EGerritServerUtility fServerUtil = mock(R4EGerritServerUtility.class);
+ r4eGerritTableView.setConnector(fConnector);
+ r4eGerritTableView.setReviewTableData(fReviewTable);
+ r4eGerritTableView.setGerritServerUtility(fServerUtil);
+
+
+ // last saved exists, so there is a repository, then the table gets updated
+ fReviewTable = new ReviewTableData();
+ r4eGerritTableView.setReviewTableData(fReviewTable);
+ Mockito.when(fServerUtil.getLastSavedGerritServer()).thenReturn( (String) "lastSavedGerritServer");
+
+ when(fServerUtil.getTaskRepo(anyString())).thenReturn( new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository") );
+
+ // one server defined
+ Map<TaskRepository, String> fMapRepoServer = new HashMap<TaskRepository, String>();
+ fMapRepoServer.put( new TaskRepository(GerritConnector.CONNECTOR_KIND, "http://repository"), " ");
+ Mockito.when(R4EGerritServerUtility.getInstance().getGerritMapping()).thenReturn(fMapRepoServer);
+
+ r4eGerritTableView.processCommands(GerritQuery.CUSTOM);
+
+ Iterator it = fMapRepoServer.entrySet().iterator();
+ while (it.hasNext()) {
+ assertEquals(r4eGerritTableView.getTaskRepository(),((Map.Entry) it.next()).getKey());
+ }
+
+
+
+ }
+
+
+
+}
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/META-INF/MANIFEST.MF b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/META-INF/MANIFEST.MF
index 7394c16..5191069 100644
--- a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/META-INF/MANIFEST.MF
@@ -21,6 +21,9 @@ Require-Bundle: org.eclipse.ui,
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-1.6
Bundle-Vendor: %providerName
-Export-Package: org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.commands,
+Export-Package: org.eclipse.mylyn.reviews.r4e_gerrit.ui,
+ org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.commands,
+ org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.model,
+ org.eclipse.mylyn.reviews.r4e_gerrit.ui.internal.utils,
org.eclipse.mylyn.reviews.r4egerrit.ui.views
Import-Package: org.eclipse.mylyn.internal.gerrit.ui.editor
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/internal/utils/R4EGerritServerUtility.java b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/internal/utils/R4EGerritServerUtility.java
index 1652e2e..004d3be 100644
--- a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/internal/utils/R4EGerritServerUtility.java
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4e_gerrit/ui/internal/utils/R4EGerritServerUtility.java
@@ -168,21 +168,27 @@ public class R4EGerritServerUtility {
private void printRepositoryTemplate() {
RepositoryTemplateManager templateManager = TasksUiPlugin.getRepositoryTemplateManager();
- for (RepositoryTemplate template : templateManager.getTemplates(GerritConnector.CONNECTOR_KIND)) {
- R4EGerritPlugin.Ftracer.traceInfo("------------======================------------------");
- Set<Entry<String, String>> value = template.getAttributes().entrySet();
- for (Map.Entry <String, String> entry: value) {
- R4EGerritPlugin.Ftracer.traceInfo("key: " + entry.getKey() + "\tvalue: " +
- entry.getValue());
+ if (templateManager != null) {
+ for (RepositoryTemplate template : templateManager.getTemplates(GerritConnector.CONNECTOR_KIND)) {
+ R4EGerritPlugin.Ftracer.traceInfo("------------======================------------------");
+ Set<Entry<String, String>> value = template.getAttributes().entrySet();
+ if (value != null) {
+ for (Map.Entry <String, String> entry: value) {
+ R4EGerritPlugin.Ftracer.traceInfo("key: " + entry.getKey() + "\tvalue: " +
+ entry.getValue());
+ }
+ }
}
}
}
private void printTaskRepository(TaskRepository aTask) {
Set<Entry<String, String>> value = aTask.getProperties().entrySet();
- for (Map.Entry<String, String> entry : value) {
- R4EGerritPlugin.Ftracer.traceInfo("TaskRepo key: " + entry.getKey()
- + "\tvalue: " + entry.getValue());
+ if ( value != null) {
+ for (Map.Entry<String, String> entry : value) {
+ R4EGerritPlugin.Ftracer.traceInfo("TaskRepo key: " + entry.getKey()
+ + "\tvalue: " + entry.getValue());
+ }
}
R4EGerritPlugin.Ftracer.traceInfo(" UserName: " + aTask.getUserName());
R4EGerritPlugin.Ftracer
@@ -336,12 +342,14 @@ public class R4EGerritServerUtility {
//Only get the TaskRepository related to Gerrit review connnector
R4EGerritPlugin.Ftracer.traceInfo("--------Review repo ---------------");
Set<TaskRepository> reviewRepo = repositoryManager.getRepositories(GerritConnector.CONNECTOR_KIND);
- for (TaskRepository taskRepo: reviewRepo) {
- R4EGerritPlugin.Ftracer.traceInfo("Add Gerrit Review repo: " + taskRepo.getRepositoryLabel() + "\t url: " + taskRepo.getRepositoryUrl());
- fResultTask.put(taskRepo, taskRepo.getRepositoryUrl());
- if (null != taskRepo.getRepositoryUrl() ) {
- adjustTemplatemanager(taskRepo);
- }
+ if (reviewRepo !=null) {
+ for (TaskRepository taskRepo: reviewRepo) {
+ R4EGerritPlugin.Ftracer.traceInfo("Add Gerrit Review repo: " + taskRepo.getRepositoryLabel() + "\t url: " + taskRepo.getRepositoryUrl());
+ fResultTask.put(taskRepo, taskRepo.getRepositoryUrl());
+ if (null != taskRepo.getRepositoryUrl() ) {
+ adjustTemplatemanager(taskRepo);
+ }
+ }
}
//Print a the end the info for all Gerrit
printRepositoryTemplate();
diff --git a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4egerrit/ui/views/R4EGerritTableView.java b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4egerrit/ui/views/R4EGerritTableView.java
index e09493c..2259df0 100644
--- a/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4egerrit/ui/views/R4EGerritTableView.java
+++ b/org.eclipse.mylyn.reviews.r4e-gerrit.ui/src/org/eclipse/mylyn/reviews/r4egerrit/ui/views/R4EGerritTableView.java
@@ -148,7 +148,7 @@ public class R4EGerritTableView extends ViewPart implements ITaskListChangeListe
// Member variables
// ------------------------------------------------------------------------
- private GerritConnector fConnector;
+ private GerritConnector fConnector = GerritCorePlugin.getDefault().getConnector();;
private TaskRepository fTaskRepository;
@@ -216,9 +216,27 @@ public class R4EGerritTableView extends ViewPart implements ITaskListChangeListe
public R4EGerritTableView() {
super();
rtv = this;
- fConnector = GerritCorePlugin.getDefault().getConnector();
}
+
+ public void setConnector (GerritConnector connector)
+ {
+ fConnector = connector;
+ }
+
+
+ public void setReviewTableData (ReviewTableData ReviewTable)
+ {
+ fReviewTable = ReviewTable;
+ }
+
+
+ public void setGerritServerUtility (R4EGerritServerUtility ServerUtil)
+ {
+ fServerUtil = ServerUtil;
+
+ }
+
/* (non-Javadoc)
* @see org.eclipse.ui.part.WorkbenchPart#dispose()
*/
@@ -483,6 +501,10 @@ public class R4EGerritTableView extends ViewPart implements ITaskListChangeListe
return fViewer;
}
+ public TaskRepository getTaskRepository() {
+ return fTaskRepository;
+ }
+
public static R4EGerritTableView getActiveView() {
IViewPart viewPart = null;
if (rtv != null) {