Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2015-05-13 16:09:29 -0400
committerSam Davis2015-06-09 01:42:26 -0400
commit7d62d00eab65b37124ad0736054996d0ceecb3fe (patch)
treed61218840d7e203b4ce217319ee055ffd010e25c /org.eclipse.mylyn.tasks.ui.tests
parent4343077ef897a5781485c44251f5246dcf20c77d (diff)
downloadorg.eclipse.mylyn.tasks-7d62d00eab65b37124ad0736054996d0ceecb3fe.tar.gz
org.eclipse.mylyn.tasks-7d62d00eab65b37124ad0736054996d0ceecb3fe.tar.xz
org.eclipse.mylyn.tasks-7d62d00eab65b37124ad0736054996d0ceecb3fe.zip
467045: Connectors can register different brandings
Change-Id: Ibf2872214ec3d314dd09cf3c04368eac7f7168da Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=467045
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui.tests')
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/BrandManagerTest.java145
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoryLabelProviderTest.java58
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/ConnectorBrandContentProviderTest.java74
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java41
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java41
5 files changed, 359 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/BrandManagerTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/BrandManagerTest.java
new file mode 100644
index 000000000..3aee07402
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/BrandManagerTest.java
@@ -0,0 +1,145 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.graphics.ImageData;
+import org.eclipse.swt.graphics.PaletteData;
+import org.eclipse.swt.widgets.Display;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableSet;
+
+@SuppressWarnings("restriction")
+public class BrandManagerTest {
+ private final BrandManager brandManager = new BrandManager();
+
+ @Test
+ public void testGetConnectorLabel() {
+ MockRepositoryConnector mock1 = connector("mock1");
+ MockRepositoryConnector mock2 = connector("mock2");
+ brandManager.addConnectorLabel("mock1", "org.mylyn", "Mylyn");
+ brandManager.addConnectorLabel("mock1", "org.eclipse", "Eclipse");
+ brandManager.addConnectorLabel("mock2", "org.mylyn", "Mylyn");
+ brandManager.addConnectorLabel("mock2", "com.acme", "ACME");
+
+ assertBrands();
+ assertEquals("Mylyn", brandManager.getConnectorLabel(mock1, "org.mylyn"));
+ assertEquals("Eclipse", brandManager.getConnectorLabel(mock1, "org.eclipse"));
+ assertEquals("Mylyn", brandManager.getConnectorLabel(mock2, "org.mylyn"));
+ assertEquals("ACME", brandManager.getConnectorLabel(mock2, "com.acme"));
+ assertEquals(mock2.getLabel(), brandManager.getConnectorLabel(mock2, "org.eclipse"));
+ assertEquals(mock2.getLabel(), brandManager.getConnectorLabel(mock2, null));
+ }
+
+ @Test
+ public void testGetBrandingIcon() {
+ brandManager.addBrandingIcon("mock1", "org.mylyn", image(1));
+ brandManager.addBrandingIcon("mock1", "org.eclipse", new Image(Display.getCurrent(), 2, 2));
+ brandManager.addBrandingIcon("mock2", "org.mylyn", new Image(Display.getCurrent(), 3, 3));
+ brandManager.addBrandingIcon("mock2", "com.acme", new Image(Display.getCurrent(), 4, 4));
+
+ assertBrands();
+ assertBrandingIconHeight(1, "mock1", "org.mylyn");
+ assertBrandingIconHeight(2, "mock1", "org.eclipse");
+ assertBrandingIconHeight(3, "mock2", "org.mylyn");
+ assertBrandingIconHeight(4, "mock2", "com.acme");
+
+ assertEquals(null, brandManager.getBrandingIcon("mock2", "org.eclipse"));
+ assertEquals(null, brandManager.getBrandingIcon(repository("mock2", "org.eclipse")));
+ assertEquals(null, brandManager.getBrandingIcon("mock2", null));
+ assertEquals(null, brandManager.getBrandingIcon(repository("mock2", null)));
+
+ brandManager.addDefaultBrandingIcon("mock2", new Image(Display.getCurrent(), 5, 5));
+ assertEquals(5, brandManager.getBrandingIcon("mock2", "org.eclipse").getImageData().height);
+ assertEquals(5, brandManager.getBrandingIcon(repository("mock2", "org.eclipse")).getImageData().height);
+ assertEquals(5, brandManager.getBrandingIcon("mock2", null).getImageData().height);
+ assertEquals(5, brandManager.getBrandingIcon(repository("mock2", null)).getImageData().height);
+ }
+
+ private void assertBrandingIconHeight(int expectedHeight, String connectorKind, String brand) {
+ assertEquals(expectedHeight, brandManager.getBrandingIcon(connectorKind, brand).getImageData().height);
+ assertEquals(expectedHeight,
+ brandManager.getBrandingIcon(repository(connectorKind, brand)).getImageData().height);
+ }
+
+ private TaskRepository repository(String connectorKind, String brand) {
+ TaskRepository repository = new TaskRepository(connectorKind, "http://mock");
+ repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, brand);
+ return repository;
+ }
+
+ @Test
+ public void testGetOverlayIcon() {
+ brandManager.addOverlayIcon("mock1", "org.mylyn", imageDescriptor(1));
+ brandManager.addOverlayIcon("mock1", "org.eclipse", imageDescriptor(2));
+ brandManager.addOverlayIcon("mock2", "org.mylyn", imageDescriptor(3));
+ brandManager.addOverlayIcon("mock2", "com.acme", imageDescriptor(4));
+
+ assertBrands();
+ assertOverlayIconHeight(1, "mock1", "org.mylyn");
+ assertOverlayIconHeight(2, "mock1", "org.eclipse");
+ assertOverlayIconHeight(3, "mock2", "org.mylyn");
+ assertOverlayIconHeight(4, "mock2", "com.acme");
+
+ assertEquals(null, brandManager.getOverlayIcon("mock2", "org.eclipse"));
+ assertEquals(null, brandManager.getOverlayIcon(repository("mock2", "org.eclipse")));
+ assertEquals(null, brandManager.getOverlayIcon("mock2", null));
+ assertEquals(null, brandManager.getOverlayIcon(repository("mock2", null)));
+
+ brandManager.addDefaultOverlayIcon("mock2", imageDescriptor(5));
+ assertEquals(5, brandManager.getOverlayIcon("mock2", "org.eclipse").getImageData().height);
+ assertEquals(5, brandManager.getOverlayIcon(repository("mock2", "org.eclipse")).getImageData().height);
+ assertEquals(5, brandManager.getOverlayIcon("mock2", null).getImageData().height);
+ assertEquals(5, brandManager.getOverlayIcon(repository("mock2", null)).getImageData().height);
+ }
+
+ private void assertOverlayIconHeight(int expectedHeight, String connectorKind, String brand) {
+ assertEquals(expectedHeight, brandManager.getOverlayIcon(connectorKind, brand).getImageData().height);
+ assertEquals(expectedHeight,
+ brandManager.getOverlayIcon(repository(connectorKind, brand)).getImageData().height);
+ }
+
+ private void assertBrands() {
+ assertEquals(ImmutableSet.of("org.mylyn", "org.eclipse"), brandManager.getBrands("mock1"));
+ assertEquals(ImmutableSet.of("org.mylyn", "com.acme"), brandManager.getBrands("mock2"));
+ assertEquals(ImmutableSet.of(), brandManager.getBrands("unknown"));
+ }
+
+ private Image image(int size) {
+ return new Image(Display.getCurrent(), size, size);
+ }
+
+ private ImageDescriptor imageDescriptor(int size) {
+ ImageDescriptor mock = mock(ImageDescriptor.class);
+ ImageData data = new ImageData(size, size, 1, new PaletteData(1, 1, 1));
+ when(mock.getImageData()).thenReturn(data);
+ return mock;
+ }
+
+ private MockRepositoryConnector connector(final String kind) {
+ return new MockRepositoryConnector() {
+ @Override
+ public String getConnectorKind() {
+ return kind;
+ }
+ };
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoryLabelProviderTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoryLabelProviderTest.java
new file mode 100644
index 000000000..1a4b4d659
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/views/TaskRepositoryLabelProviderTest.java
@@ -0,0 +1,58 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.views;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.when;
+
+import org.eclipse.mylyn.commons.ui.CommonImages;
+import org.eclipse.mylyn.internal.tasks.ui.ConnectorBrand;
+import org.eclipse.mylyn.internal.tasks.ui.IBrandManager;
+import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.ui.TasksUiImages;
+import org.eclipse.swt.graphics.Image;
+import org.eclipse.swt.widgets.Display;
+import org.junit.Test;
+import org.mockito.Matchers;
+
+public class TaskRepositoryLabelProviderTest {
+ private final IBrandManager manager = mock(IBrandManager.class);;
+
+ private final TaskRepositoryLabelProvider labelProvider = new TaskRepositoryLabelProvider() {
+ @Override
+ protected org.eclipse.mylyn.internal.tasks.ui.IBrandManager getBrandManager() {
+ return manager;
+ };
+ };
+
+ @Test
+ public void testGetImage() {
+ Image brandingImage = new Image(Display.getCurrent(), 1, 1);
+ when(manager.getBrandingIcon("mock", "a")).thenReturn(brandingImage);
+ assertEquals(brandingImage, labelProvider.getImage(new ConnectorBrand(new MockRepositoryConnector(), "a")));
+ assertEquals(CommonImages.getImage(TasksUiImages.REPOSITORY),
+ labelProvider.getImage(new ConnectorBrand(new MockRepositoryConnector(), "b")));
+ }
+
+ @Test
+ public void testGetText() {
+ when(manager.getConnectorLabel(any(AbstractRepositoryConnector.class), Matchers.eq("a"))).thenReturn(
+ "Mock Brand");
+ when(manager.getConnectorLabel(any(AbstractRepositoryConnector.class), Matchers.eq("b"))).thenReturn(
+ "Mock Brand B");
+ assertEquals("Mock Brand", labelProvider.getText(new ConnectorBrand(new MockRepositoryConnector(), "a")));
+ assertEquals("Mock Brand B", labelProvider.getText(new ConnectorBrand(new MockRepositoryConnector(), "b")));
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/ConnectorBrandContentProviderTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/ConnectorBrandContentProviderTest.java
new file mode 100644
index 000000000..bf68245aa
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/ConnectorBrandContentProviderTest.java
@@ -0,0 +1,74 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.wizards;
+
+import static org.junit.Assert.assertEquals;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
+import static org.mockito.Mockito.when;
+
+import java.util.Arrays;
+import java.util.Collection;
+
+import org.eclipse.mylyn.internal.tasks.ui.BrandManager;
+import org.eclipse.mylyn.internal.tasks.ui.ConnectorBrand;
+import org.eclipse.mylyn.internal.tasks.ui.wizards.SelectRepositoryConnectorPage.ConnectorBrandContentProvider;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.junit.Test;
+
+import com.google.common.collect.ImmutableList;
+
+public class ConnectorBrandContentProviderTest {
+
+ @Test
+ public void testGetElementsNoConnectors() {
+ Collection<MockRepositoryConnector> connectors = ImmutableList.of();
+ BrandManager brandManager = mock(BrandManager.class);
+ ConnectorBrandContentProvider provider = new ConnectorBrandContentProvider(brandManager, connectors);
+
+ assertEquals(0, provider.getElements(null).length);
+ }
+
+ @Test
+ public void testGetElementsMultipleConnectors() {
+ MockRepositoryConnector cantCreateRepository = mockConnector("cantCreateRepository");
+ when(cantCreateRepository.canCreateRepository()).thenReturn(false);
+ MockRepositoryConnector notUserManaged = mockConnector("notUserManaged");
+ when(notUserManaged.isUserManaged()).thenReturn(false);
+ MockRepositoryConnector c1 = mockConnector("c1");
+ MockRepositoryConnector c2 = mockConnector("c2");
+ MockRepositoryConnector c3 = mockConnector("c3");
+ Collection<MockRepositoryConnector> connectors = ImmutableList.of(c1, c2, notUserManaged, cantCreateRepository,
+ c3);
+ BrandManager brandManager = mock(BrandManager.class);
+ ConnectorBrandContentProvider provider = new ConnectorBrandContentProvider(brandManager, connectors);
+
+ assertBrands(provider, new ConnectorBrand(c1, null), new ConnectorBrand(c2, null), new ConnectorBrand(c3, null));
+
+ when(brandManager.getBrands(c1.getConnectorKind())).thenReturn(ImmutableList.of("a", "b", "c"));
+ when(brandManager.getBrands(c2.getConnectorKind())).thenReturn(ImmutableList.<String> of());
+ when(brandManager.getBrands(c3.getConnectorKind())).thenReturn(ImmutableList.of("d"));
+ assertBrands(provider, new ConnectorBrand(c1, null), new ConnectorBrand(c1, "a"), new ConnectorBrand(c1, "b"),
+ new ConnectorBrand(c1, "c"), new ConnectorBrand(c2, null), new ConnectorBrand(c3, null),
+ new ConnectorBrand(c3, "d"));
+ }
+
+ protected MockRepositoryConnector mockConnector(String kind) {
+ MockRepositoryConnector spy = spy(new MockRepositoryConnector());
+ when(spy.getConnectorKind()).thenReturn(kind);
+ return spy;
+ }
+
+ protected void assertBrands(ConnectorBrandContentProvider provider, ConnectorBrand... brands) {
+ assertEquals(Arrays.asList(brands), Arrays.asList(provider.getElements(null)));
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java
new file mode 100644
index 000000000..23ea56b83
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/wizards/NewRepositoryWizardTest.java
@@ -0,0 +1,41 @@
+/*******************************************************************************
+ * Copyright (c) 2015 Tasktop Technologies 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:
+ * Tasktop Technologies - initial API and implementation
+ *******************************************************************************/
+
+package org.eclipse.mylyn.internal.tasks.ui.wizards;
+
+import static org.eclipse.mylyn.internal.tasks.ui.wizards.Messages.SelectRepositoryConnectorPage_Select_a_task_repository_type;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.junit.Assert.assertTrue;
+
+import org.eclipse.mylyn.internal.tasks.ui.ConnectorBrand;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.junit.Test;
+
+public class NewRepositoryWizardTest {
+
+ @Test
+ public void testGetNextPageIWizardPage() {
+ NewRepositoryWizard wizard = new NewRepositoryWizard(null);
+ wizard.addPages();
+ SelectRepositoryConnectorPage page = (SelectRepositoryConnectorPage) wizard.getPage(SelectRepositoryConnectorPage_Select_a_task_repository_type);
+ page.setConnectorBrand(new ConnectorBrand(new MockRepositoryConnector(), "org.mylyn"));
+
+ wizard.getNextPage(null);
+ assertNull(wizard.getBrand());
+ try {
+ wizard.getNextPage(page);
+ } catch (RuntimeException e) {
+ assertTrue(e.getMessage().startsWith("The connector implementation is incomplete"));
+ }
+ assertEquals("org.mylyn", wizard.getBrand());
+ }
+}
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
index cad3e5a8e..6b416ceea 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java
@@ -12,7 +12,10 @@
package org.eclipse.mylyn.tasks.ui.wizards;
import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNull;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -22,12 +25,17 @@ import org.eclipse.core.runtime.IProgressMonitor;
import org.eclipse.core.runtime.Status;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardContainer;
+import org.eclipse.jface.wizard.Wizard;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
+import org.eclipse.mylyn.internal.tasks.ui.wizards.EditRepositoryWizard;
+import org.eclipse.mylyn.internal.tasks.ui.wizards.NewRepositoryWizard;
import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.junit.Test;
+@SuppressWarnings("restriction")
public class RepositorySettingsPageTest {
public static class TestRepositorySettingsPage extends AbstractRepositorySettingsPage {
@@ -106,6 +114,39 @@ public class RepositorySettingsPageTest {
assertEquals("", page.getRepositoryLabel());
}
+ @Test
+ public void applyToNewRepository() {
+ NewRepositoryWizard wizard = mock(NewRepositoryWizard.class);
+ when(wizard.getBrand()).thenReturn("org.mylyn");
+ AbstractRepositorySettingsPage page = createPage(wizard);
+ TaskRepository repository = createTaskRepository();
+
+ page.applyTo(repository);
+ assertEquals("org.mylyn", repository.getProperty(ITasksCoreConstants.PROPERTY_BRAND_ID));
+ }
+
+ @Test
+ public void applyToExistingRepository() {
+ EditRepositoryWizard wizard = mock(EditRepositoryWizard.class);
+ AbstractRepositorySettingsPage page = createPage(wizard);
+ TaskRepository repository = createTaskRepository();
+
+ page.applyTo(repository);
+ assertNull(repository.getProperty(ITasksCoreConstants.PROPERTY_BRAND_ID));
+
+ repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, "org.mylyn");
+ page.applyTo(repository);
+ assertEquals("org.mylyn", repository.getProperty(ITasksCoreConstants.PROPERTY_BRAND_ID));
+ }
+
+ protected AbstractRepositorySettingsPage createPage(Wizard wizard) {
+ AbstractRepositorySettingsPage page = spy(new RepositorySettingsPageWithNoCredentials(null));
+ doReturn("label").when(page).getRepositoryLabel();
+ when(page.needsProxy()).thenReturn(false);
+ when(page.getWizard()).thenReturn(wizard);
+ return page;
+ }
+
private IWizardContainer applyWizardContainer(TestRepositorySettingsPage page) {
IWizard wizard = mock(IWizard.class);
IWizardContainer container = mock(IWizardContainer.class);

Back to the top