Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBenjamin Muskalla2012-04-29 16:18:23 +0000
committerGerrit Code Review @ Eclipse.org2013-12-17 22:02:56 +0000
commit461cb61c85d4f7872c0faf5b9174d999bfcc98f5 (patch)
treec36be495374ed35a321c65beb44e6adc45f06f70 /org.eclipse.mylyn.tasks.tests
parent20324679c2367c793f27095c4ac89ebe7b725bf4 (diff)
downloadorg.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.tar.gz
org.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.tar.xz
org.eclipse.mylyn.tasks-461cb61c85d4f7872c0faf5b9174d999bfcc98f5.zip
NEW - bug 378032: provide support for required attributes
https://bugs.eclipse.org/bugs/show_bug.cgi?id=378032 Change-Id: Ib3cfcb8c8cb489fab5afbb0565f6da0643ab4b97 Signed-off-by: Benjamin Muskalla <benjamin.muskalla@tasktop.com>
Diffstat (limited to 'org.eclipse.mylyn.tasks.tests')
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java4
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskAttributeMetaDataTest.java50
-rw-r--r--org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java209
3 files changed, 263 insertions, 0 deletions
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
index 1c4070d98..88730ef7f 100644
--- a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/AllTasksTests.java
@@ -23,6 +23,7 @@ import org.eclipse.mylyn.tasks.tests.core.PriorityLevelTest;
import org.eclipse.mylyn.tasks.tests.core.RepositoryClientManagerTest;
import org.eclipse.mylyn.tasks.tests.core.RepositoryConnectorContributorTest;
import org.eclipse.mylyn.tasks.tests.core.SynchronizeTasksJobTest;
+import org.eclipse.mylyn.tasks.tests.core.TaskAttributeMetaDataTest;
import org.eclipse.mylyn.tasks.tests.core.TaskInitializationDataTest;
import org.eclipse.mylyn.tasks.tests.core.TaskListUnmatchedContainerTest;
import org.eclipse.mylyn.tasks.tests.core.TaskRepositoryLocationTest;
@@ -33,6 +34,7 @@ import org.eclipse.mylyn.tasks.tests.data.TaskDataDiffTest;
import org.eclipse.mylyn.tasks.tests.data.TaskDataExternalizerTest;
import org.eclipse.mylyn.tasks.tests.data.Xml11InputStreamTest;
import org.eclipse.mylyn.tasks.tests.ui.AbstractRepositoryConnectorUiTest;
+import org.eclipse.mylyn.tasks.tests.ui.AttributeEditorTest;
import org.eclipse.mylyn.tasks.tests.ui.MultipleTaskHyperlinkDetectorTest;
import org.eclipse.mylyn.tasks.tests.ui.ScheduledTaskContainerTest;
import org.eclipse.mylyn.tasks.tests.ui.TaskAttachmentPropertyTesterTest;
@@ -150,6 +152,8 @@ public class AllTasksTests {
suite.addTestSuite(TaskAttributeTest.class);
suite.addTestSuite(TaskAttributeMapperTest.class);
suite.addTestSuite(SupportHandlerManagerTest.class);
+ suite.addTestSuite(TaskAttributeMetaDataTest.class);
+ suite.addTestSuite(AttributeEditorTest.class);
suite.addTestSuite(RepositoryClientManagerTest.class);
suite.addTestSuite(AbstractRepositoryConnectorUiTest.class);
suite.addTestSuite(SynchronizeTasksJobTest.class);
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskAttributeMetaDataTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskAttributeMetaDataTest.java
new file mode 100644
index 000000000..a63364ff9
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/core/TaskAttributeMetaDataTest.java
@@ -0,0 +1,50 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tasks.tests.core;
+
+import junit.framework.TestCase;
+
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+
+/**
+ * @author Benjamin Muskalla
+ */
+public class TaskAttributeMetaDataTest extends TestCase {
+
+ private TaskData data;
+
+ @Override
+ protected void setUp() throws Exception {
+ TaskRepository taskRepository = new TaskRepository("kind", "url");
+ data = new TaskData(new TaskAttributeMapper(taskRepository), MockRepositoryConnector.CONNECTOR_KIND,
+ MockRepositoryConnector.REPOSITORY_URL, "taskid");
+ }
+
+ public void testInitialRequiredAttribute() {
+ TaskAttribute attribute = new TaskAttribute(data.getRoot(), "attributeId");
+ boolean required = attribute.getMetaData().isRequired();
+ assertFalse(required);
+ }
+
+ public void testLifecycleRequiredAttribute() {
+ TaskAttribute attribute = new TaskAttribute(data.getRoot(), "attributeId");
+ attribute.getMetaData().setRequired(true);
+ assertTrue(attribute.getMetaData().isRequired());
+ attribute.getMetaData().setRequired(false);
+ assertFalse(attribute.getMetaData().isRequired());
+ }
+
+}
diff --git a/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java
new file mode 100644
index 000000000..77f3a15a1
--- /dev/null
+++ b/org.eclipse.mylyn.tasks.tests/src/org/eclipse/mylyn/tasks/tests/ui/AttributeEditorTest.java
@@ -0,0 +1,209 @@
+/*******************************************************************************
+ * Copyright (c) 2012 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.tasks.tests.ui;
+
+import junit.framework.TestCase;
+
+import org.eclipse.core.runtime.CoreException;
+import org.eclipse.mylyn.commons.workbench.WorkbenchUtil;
+import org.eclipse.mylyn.internal.tasks.core.data.TaskDataState;
+import org.eclipse.mylyn.internal.tasks.ui.TasksUiPlugin;
+import org.eclipse.mylyn.tasks.core.TaskRepository;
+import org.eclipse.mylyn.tasks.core.data.TaskAttribute;
+import org.eclipse.mylyn.tasks.core.data.TaskAttributeMapper;
+import org.eclipse.mylyn.tasks.core.data.TaskData;
+import org.eclipse.mylyn.tasks.core.data.TaskDataModel;
+import org.eclipse.mylyn.tasks.tests.connector.MockRepositoryConnector;
+import org.eclipse.mylyn.tasks.tests.connector.MockTask;
+import org.eclipse.mylyn.tasks.ui.editors.AbstractAttributeEditor;
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.widgets.Composite;
+import org.eclipse.swt.widgets.Label;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.ui.forms.widgets.FormToolkit;
+
+/**
+ * @author Benjamin Muskalla
+ */
+public class AttributeEditorTest extends TestCase {
+
+ private class MockAttributeEditor extends AbstractAttributeEditor {
+
+ private MockAttributeEditor(TaskDataModel manager, TaskAttribute taskAttribute) throws CoreException {
+ super(manager, taskAttribute);
+ setControl(new Shell());
+ }
+
+ @Override
+ public void createControl(Composite parent, FormToolkit toolkit) {
+ // ignore
+ }
+
+ @Override
+ public boolean isRequired() {
+ return super.isRequired();
+ }
+
+ @Override
+ public void refresh() {
+ // ignore
+ }
+
+ @Override
+ public Label getLabelControl() {
+ return new Label(new Shell(), SWT.NONE);
+ }
+
+ @Override
+ protected boolean shouldAutoRefresh() {
+ return true;
+ }
+ }
+
+ private TaskRepository repository;
+
+ private TaskData taskData;
+
+ private TaskDataModel manager;
+
+ @Override
+ protected void setUp() throws Exception {
+ repository = new TaskRepository(MockRepositoryConnector.CONNECTOR_KIND, MockRepositoryConnector.REPOSITORY_URL);
+ TasksUiPlugin.getRepositoryManager().addRepository(repository);
+
+ taskData = new TaskData(new TaskAttributeMapper(repository), MockRepositoryConnector.CONNECTOR_KIND,
+ MockRepositoryConnector.REPOSITORY_URL, "1");
+
+ manager = createManager();
+ }
+
+ public void testDetermineNotRequired() throws Exception {
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "not.required.field");
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute);
+ assertFalse(editor.isRequired());
+ attribute.setValue("");
+ assertFalse(editor.isRequired());
+ attribute.setValue("abc");
+ assertFalse(editor.isRequired());
+ }
+
+ public void testDetermineRequired() throws Exception {
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
+ attribute.getMetaData().setRequired(true);
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute);
+ assertTrue(editor.isRequired());
+ attribute.setValue("");
+ assertTrue(editor.isRequired());
+ attribute.setValue("abc");
+ assertFalse(editor.isRequired());
+ }
+
+ public void testDecorateRequired() throws Exception {
+ final StringBuilder eventLog = new StringBuilder();
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute) {
+ @Override
+ protected void decorateRequired() {
+ eventLog.append("decorateRequired");
+ }
+
+ };
+
+ assertEquals("", eventLog.toString());
+ Color someColor = WorkbenchUtil.getShell().getDisplay().getSystemColor(SWT.COLOR_CYAN);
+ editor.decorate(someColor);
+ assertEquals("", eventLog.toString());
+
+ attribute.getMetaData().setRequired(true);
+ editor.decorate(someColor);
+ assertEquals("decorateRequired", eventLog.toString());
+ eventLog.setLength(0);
+
+ attribute.getMetaData().setRequired(false);
+ editor.decorate(someColor);
+ assertEquals("", eventLog.toString());
+ }
+
+ public void testDecorateRequiredOnChange() throws Exception {
+ final StringBuilder eventLog = new StringBuilder();
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute) {
+
+ @Override
+ protected void decorateRequired() {
+ eventLog.append("decorateRequired");
+ }
+
+ @Override
+ public boolean isRequired() {
+ eventLog.append("asked");
+ return super.isRequired();
+ }
+
+ };
+
+ assertEquals("", eventLog.toString());
+ Color someColor = WorkbenchUtil.getShell().getDisplay().getSystemColor(SWT.COLOR_CYAN);
+
+ attribute.getMetaData().setRequired(true);
+ editor.decorate(someColor);
+ assertEquals("askeddecorateRequired", eventLog.toString());
+ eventLog.setLength(0);
+
+ attribute.setValue("someValue");
+ manager.attributeChanged(attribute);
+
+ assertEquals("asked", eventLog.toString());
+ }
+
+ public void testDecorateRequiredReal() throws Exception {
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute);
+
+ Color someColor = WorkbenchUtil.getShell().getDisplay().getSystemColor(SWT.COLOR_CYAN);
+
+ attribute.getMetaData().setRequired(true);
+ editor.decorate(someColor);
+
+ attribute.getMetaData().setRequired(false);
+ manager.attributeChanged(attribute);
+ }
+
+ public void testNoDecorateWithoutLabel() throws Exception {
+ TaskAttribute attribute = new TaskAttribute(taskData.getRoot(), "a.required.field");
+ MockAttributeEditor editor = new MockAttributeEditor(manager, attribute) {
+ @Override
+ public Label getLabelControl() {
+ return null;
+ }
+ };
+
+ Color someColor = WorkbenchUtil.getShell().getDisplay().getSystemColor(SWT.COLOR_CYAN);
+
+ attribute.getMetaData().setRequired(true);
+ editor.decorate(someColor);
+
+ attribute.getMetaData().setRequired(false);
+ manager.attributeChanged(attribute);
+ }
+
+ private TaskDataModel createManager() throws Exception {
+ MockTask task = new MockTask("taskId");
+ TaskDataState state = new TaskDataState("kind", "url", "taskId");
+ state.setEditsData(taskData);
+ state.setLocalTaskData(taskData);
+ TaskDataModel manager = new TaskDataModel(repository, task, state);
+ return manager;
+ }
+
+}

Back to the top