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.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.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF3
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java138
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java46
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-2x2.gifbin0 -> 43 bytes
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-3x3.gifbin0 -> 51 bytes
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-4x4.gifbin0 -> 67 bytes
-rw-r--r--org.eclipse.mylyn.tasks.tests/testdata/icons/mock-5x5.gifbin0 -> 99 bytes
7 files changed, 181 insertions, 6 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
index 2c194a032..237045a3f 100644
--- a/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
+++ b/org.eclipse.mylyn.tasks.tests/META-INF/MANIFEST.MF
@@ -31,7 +31,8 @@ Require-Bundle: org.junit;bundle-version="4.8.2",
org.eclipse.mylyn.tasks.ui,
org.eclipse.mylyn.tests.util,
org.eclipse.mylyn.commons.repositories.core,
- org.eclipse.core.runtime.compatibility.auth;resolution:=optional
+ org.eclipse.core.runtime.compatibility.auth;resolution:=optional,
+ com.google.guava;bundle-version="15.0.0"
Export-Package: org.eclipse.mylyn.tasks.tests;x-internal:=true,
org.eclipse.mylyn.tasks.tests.bugs;x-internal:=true,
org.eclipse.mylyn.tasks.tests.connector;x-friends:="org.eclipse.mylyn.tasks.ui.tests",
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
index 4c6e19b89..609147457 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/RepositoryConnectorContributorTest.java
@@ -11,20 +11,80 @@
package org.eclipse.mylyn.tasks.tests.core;
+import java.util.HashMap;
+import java.util.Map;
+
import junit.framework.TestCase;
import org.eclipse.jface.resource.ImageDescriptor;
+import org.eclipse.mylyn.commons.ui.CommonImages;
+import org.eclipse.mylyn.internal.tasks.core.ITasksCoreConstants;
+import org.eclipse.mylyn.internal.tasks.core.TaskRepositoryManager;
+import org.eclipse.mylyn.internal.tasks.core.TaskTask;
+import org.eclipse.mylyn.internal.tasks.ui.IBrandManager;
import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
import org.eclipse.mylyn.tasks.core.AbstractRepositoryConnector;
+import org.eclipse.mylyn.tasks.core.ITask;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
import org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorAdapter.DynamicMockRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.tests.support.MockRepositoryConnectorDescriptor.DynamicMockRepositoryConnector;
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.swt.graphics.Image;
+import org.junit.After;
+import org.junit.Before;
import org.junit.Test;
+import com.google.common.collect.ImmutableSet;
+
public class RepositoryConnectorContributorTest extends TestCase {
+ private final IBrandManager manager = TasksUiPlugin.getDefault().getBrandManager();
+
+ private final DynamicMockRepositoryConnector connector = new DynamicMockRepositoryConnector();
+
+ private final Map<String, TaskRepository> repositories = new HashMap<>();
+
+ private final Map<String, ITask> tasks = new HashMap<>();
+
+ private TaskRepository repositoryForConnectorWithNoBrands;
+
+ private TaskTask taskForConnectorWithNoBrands;
+
+ @Before
+ @Override
+ protected void setUp() throws Exception {
+ setUpBrand("org.mylyn");
+ setUpBrand("org.eclipse");
+ setUpBrand("unknown");
+ setUpBrand("exceptional");
+ setUpBrand(null);
+
+ String repositoryUrl = "http://mock-connector-with-no-brands";
+ repositoryForConnectorWithNoBrands = new TaskRepository("mock-connector-with-no-brands", repositoryUrl);
+ repositoryForConnectorWithNoBrands.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, "org.mylyn");
+ TasksUi.getRepositoryManager().addRepository(repositoryForConnectorWithNoBrands);
+ taskForConnectorWithNoBrands = new TaskTask("mock-connector-with-no-brands", repositoryUrl, "1");
+ }
+
+ private void setUpBrand(String brand) {
+ String repositoryUrl = "http://mock-" + brand;
+ TaskRepository repository = new TaskRepository(connector.getConnectorKind(), repositoryUrl);
+ repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, brand);
+ TasksUi.getRepositoryManager().addRepository(repository);
+ repositories.put(brand, repository);
+ tasks.put(brand, new TaskTask(connector.getConnectorKind(), repositoryUrl, "1"));
+ }
+
+ @Override
+ @After
+ protected void tearDown() throws Exception {
+ for (TaskRepository repository : repositories.values()) {
+ ((TaskRepositoryManager) TasksUi.getRepositoryManager()).removeRepository(repository);
+ }
+ ((TaskRepositoryManager) TasksUi.getRepositoryManager()).removeRepository(repositoryForConnectorWithNoBrands);
+ }
+
@Test
public void testConnectorContributed() {
AbstractRepositoryConnector connector = TasksUi.getRepositoryConnector(DynamicMockRepositoryConnector.CONNECTOR_KIND);
@@ -42,17 +102,85 @@ public class RepositoryConnectorContributorTest extends TestCase {
}
@Test
- public void testMockBrandingIcon() {
- Image brandingImage = TasksUiPlugin.getDefault().getBrandingIcon(DynamicMockRepositoryConnector.CONNECTOR_KIND);
+ public void testDefaultBrandingIcon() {
+ Image brandingImage = TasksUiPlugin.getDefault()
+ .getBrandManager()
+ .getDefaultBrandingIcon(DynamicMockRepositoryConnector.CONNECTOR_KIND);
assertNotNull("Expected branding image contributed by MockRepositoryConnectorAdapter", brandingImage);
+ assertEquals(16, brandingImage.getImageData().height);
}
@Test
- public void testMockOverlayIcon() {
- ImageDescriptor overlay = TasksUiPlugin.getDefault().getOverlayIcon(
- DynamicMockRepositoryConnector.CONNECTOR_KIND);
+ public void testDefaultOverlayIcon() {
+ ImageDescriptor overlay = TasksUiPlugin.getDefault()
+ .getBrandManager()
+ .getDefaultOverlayIcon(DynamicMockRepositoryConnector.CONNECTOR_KIND);
assertNotNull("Expected overlay image contributed by MockRepositoryConnectorAdapter", overlay);
assertEquals(8, overlay.getImageData().height);
}
+ @Test
+ public void testGetBrands() throws Exception {
+ assertEquals(ImmutableSet.of("org.mylyn", "org.eclipse"), manager.getBrands(connector.getConnectorKind()));
+ }
+
+ @Test
+ public void testGetConnectorLabel() {
+ assertEquals("Label for org.mylyn", manager.getConnectorLabel(connector, "org.mylyn"));
+ assertEquals("Label for org.eclipse", manager.getConnectorLabel(connector, "org.eclipse"));
+ assertEquals(connector.getLabel(), manager.getConnectorLabel(connector, "unknown"));
+ assertEquals(connector.getLabel(), manager.getConnectorLabel(connector, "exceptional"));
+ assertEquals(connector.getLabel(), manager.getConnectorLabel(connector, null));
+ AbstractRepositoryConnector mockConnector = new DynamicMockRepositoryConnector() {
+ @Override
+ public String getConnectorKind() {
+ return "mock-connector-with-no-brands";
+ };
+ };
+ assertEquals(connector.getLabel(), manager.getConnectorLabel(mockConnector, "org.mylyn"));
+ }
+
+ @Test
+ public void testGetBrandingIcon() {
+ assertBrandingIconHeight(3, "org.mylyn");
+ assertBrandingIconHeight(2, "org.eclipse");
+ assertBrandingIconHeight(16, "unknown");
+ assertBrandingIconHeight(16, "exceptional");
+ assertBrandingIconHeight(16, null);
+
+ assertNull(manager.getBrandingIcon(repositoryForConnectorWithNoBrands.getConnectorKind(), "org.mylyn"));
+ assertNull(manager.getBrandingIcon(repositoryForConnectorWithNoBrands));
+ }
+
+ private void assertBrandingIconHeight(int expectedHeight, String brand) {
+ assertIconHeight(expectedHeight, manager.getBrandingIcon(connector.getConnectorKind(), brand));
+ assertIconHeight(expectedHeight, manager.getBrandingIcon(repositories.get(brand)));
+ }
+
+ @Test
+ public void testGetOverlayIcon() {
+ assertOverlayIconHeight(5, "org.mylyn");
+ assertOverlayIconHeight(4, "org.eclipse");
+ assertOverlayIconHeight(8, "unknown");
+ assertOverlayIconHeight(8, "exceptional");
+ assertOverlayIconHeight(8, null);
+
+ assertNull(manager.getOverlayIcon(repositoryForConnectorWithNoBrands.getConnectorKind(), "org.mylyn"));
+ assertNull(manager.getOverlayIcon(repositoryForConnectorWithNoBrands));
+ assertNull(manager.getOverlayIcon(taskForConnectorWithNoBrands));
+ }
+
+ private void assertOverlayIconHeight(int expectedHeight, String brand) {
+ assertIconHeight(expectedHeight, manager.getOverlayIcon(connector.getConnectorKind(), brand));
+ assertIconHeight(expectedHeight, manager.getOverlayIcon(repositories.get(brand)));
+ assertIconHeight(expectedHeight, manager.getOverlayIcon(tasks.get(brand)));
+ }
+
+ private void assertIconHeight(int expectedHeight, Image image) {
+ assertEquals(expectedHeight, image.getImageData().height);
+ }
+
+ private void assertIconHeight(int expectedHeight, ImageDescriptor descriptor) {
+ assertEquals(expectedHeight, CommonImages.getImage(descriptor).getImageData().height);
+ }
}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java
index e4a26c25a..994438985 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/support/MockRepositoryConnectorAdapter.java
@@ -13,6 +13,8 @@ package org.eclipse.mylyn.tasks.tests.support;
import java.io.IOException;
import java.io.InputStream;
+import java.util.ArrayList;
+import java.util.List;
import org.eclipse.core.runtime.IAdapterFactory;
import org.eclipse.mylyn.commons.sdk.util.CommonTestUtil;
@@ -22,6 +24,8 @@ import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnectorUi;
import org.eclipse.mylyn.tasks.ui.AbstractRepositoryConnectorUi;
+import com.google.common.collect.ImmutableList;
+
public class MockRepositoryConnectorAdapter implements IAdapterFactory {
public final static class DynamicMockRepositoryConnectorUi extends MockRepositoryConnectorUi {
@@ -58,6 +62,48 @@ public class MockRepositoryConnectorAdapter implements IAdapterFactory {
public InputStream getBrandingImageData() throws IOException {
return CommonTestUtil.getResource(this, "testdata/icons/mock-repository.gif");
}
+
+ @Override
+ public List<String> getBrands() {
+ ArrayList<String> brands = new ArrayList<String>(ImmutableList.of("org.mylyn", "org.eclipse",
+ "exceptional"));
+ brands.add(1, null);
+ return brands;
+ }
+
+ @Override
+ public String getConnectorLabel(String brand) {
+ if ("exceptional".equals(brand)) {
+ throw new NullPointerException();
+ } else if (getBrands().contains(brand)) {
+ return "Label for " + brand;
+ }
+ return super.getConnectorLabel(brand);
+ }
+
+ @Override
+ public InputStream getOverlayImageData(final String brand) throws IOException {
+ if ("org.mylyn".equals(brand)) {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-5x5.gif");
+ } else if ("org.eclipse".equals(brand)) {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-4x4.gif");
+ } else if ("exceptional".equals(brand)) {
+ throw new NullPointerException();
+ }
+ return super.getOverlayImageData(brand);
+ }
+
+ @Override
+ public InputStream getBrandingImageData(final String brand) throws IOException {
+ if ("org.mylyn".equals(brand)) {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-3x3.gif");
+ } else if ("org.eclipse".equals(brand)) {
+ return CommonTestUtil.getResource(this, "testdata/icons/mock-2x2.gif");
+ } else if ("exceptional".equals(brand)) {
+ throw new NullPointerException();
+ }
+ return super.getBrandingImageData(brand);
+ }
};
}
}
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-2x2.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-2x2.gif
new file mode 100644
index 000000000..b73642636
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-2x2.gif
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-3x3.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-3x3.gif
new file mode 100644
index 000000000..294ad2a7a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-3x3.gif
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-4x4.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-4x4.gif
new file mode 100644
index 000000000..2985fd086
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-4x4.gif
Binary files differ
diff --git a/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-5x5.gif b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-5x5.gif
new file mode 100644
index 000000000..69ddf257a
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/testdata/icons/mock-5x5.gif
Binary files differ

Back to the top