diff options
8 files changed, 492 insertions, 396 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java index f8ee9b171..fbd4754e9 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaHeadlessStandaloneTests.java @@ -16,10 +16,14 @@ import junit.framework.TestSuite; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaClientTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaConfigurationTest; +import org.eclipse.mylyn.bugzilla.tests.core.BugzillaCustomFieldsTest; +import org.eclipse.mylyn.bugzilla.tests.core.BugzillaFlagsTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaRepositoryConnectorConfigurationTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaRepositoryConnectorStandaloneTest; +import org.eclipse.mylyn.bugzilla.tests.core.BugzillaTaskCompletionTest; import org.eclipse.mylyn.bugzilla.tests.core.BugzillaVersionTest; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; /** * @author Steffen Pingel @@ -37,6 +41,12 @@ public class AllBugzillaHeadlessStandaloneTests { // only run certain tests against head to avoid spurious failures if (fixture != BugzillaFixture.BUGS_HEAD) { fixture.add(BugzillaClientTest.class); + + // Only run these tests on > 3.2 repositories + if (!fixture.getBugzillaVersion().isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { + fixture.add(BugzillaCustomFieldsTest.class); + fixture.add(BugzillaFlagsTest.class); + } // XXX: re-enable when webservice is used for retrieval of history // fixture.add(fixtureSuite, BugzillaTaskHistoryTest.class); fixture.add(BugzillaRepositoryConnectorStandaloneTest.class); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java index be68f4d03..67cea36ac 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/AllBugzillaTests.java @@ -19,6 +19,7 @@ import org.eclipse.mylyn.bugzilla.tests.ui.BugzillaRepositorySettingsPageTest; import org.eclipse.mylyn.bugzilla.tests.ui.BugzillaSearchPageTest; import org.eclipse.mylyn.bugzilla.tests.ui.BugzillaTaskHyperlinkDetectorTest; import org.eclipse.mylyn.bugzilla.tests.ui.TaskEditorTest; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; /** * @author Mik Kersten @@ -37,9 +38,11 @@ public class AllBugzillaTests { // only run certain tests against head to avoid spurious failures if (fixture != BugzillaFixture.BUGS_HEAD) { - //Failing - fixture.add(BugzillaRepositoryConnectorTest.class); - fixture.add(BugzillaAttachmentHandlerTest.class); + // Only run these tests on > 3.2 repositories + if (!fixture.getBugzillaVersion().isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { + fixture.add(BugzillaRepositoryConnectorTest.class); + fixture.add(BugzillaAttachmentHandlerTest.class); + } // Passing fixture.add(BugzillaTaskDataHandlerTest.class); fixture.add(RepositoryReportFactoryTest.class); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java index d3a27d780..53c4e0f25 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaRepositoryConnectorTest.java @@ -27,6 +27,7 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaOperation; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaTaskDataHandler; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; import org.eclipse.mylyn.internal.bugzilla.core.IBugzillaConstants; import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylyn.internal.context.core.ContextCorePlugin; @@ -693,55 +694,6 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { } } - ITask fruitTask; - - TaskData fruitTaskData; - - private void setFruitValueTo(String newValue) throws Exception { - Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); - TaskAttribute cf_fruit = fruitTaskData.getRoot().getAttribute("cf_fruit"); - cf_fruit.setValue(newValue); - assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_fruit").getValue()); - changed.add(cf_fruit); - BugzillaFixture.current().submitTask(fruitTaskData, client); - TasksUiInternal.synchronizeTask(connector, fruitTask, true, null); - fruitTaskData = TasksUiPlugin.getTaskDataManager().getTaskData(repository, fruitTask.getTaskId()); - assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_fruit").getValue()); - - } - - public void testCustomFields() throws Exception { - - String taskNumber = "1"; - - // Get the task - fruitTask = generateLocalTaskAndDownload(taskNumber); - assertNotNull(fruitTask); - TaskDataModel model = createModel(fruitTask); - fruitTaskData = model.getTaskData(); - assertNotNull(fruitTaskData); - - if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("---")) { - setFruitValueTo("apple"); - setFruitValueTo("orange"); - setFruitValueTo("---"); - } else if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("apple")) { - setFruitValueTo("orange"); - setFruitValueTo("apple"); - setFruitValueTo("---"); - } else if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("orange")) { - setFruitValueTo("apple"); - setFruitValueTo("orange"); - setFruitValueTo("---"); - } - if (fruitTask != null) { - fruitTask = null; - } - if (fruitTaskData != null) { - fruitTaskData = null; - } - } - public void testAnonymousRepositoryAccess() throws Exception { assertNotNull(repository); AuthenticationCredentials anonymousCreds = new AuthenticationCredentials("", ""); @@ -759,8 +711,13 @@ public class BugzillaRepositoryConnectorTest extends AbstractBugzillaTest { assertTrue(config.getComponents().size() > 0); } - public void testTimeTracker() throws Exception { + + BugzillaVersion version = new BugzillaVersion(BugzillaFixture.current().getVersion()); + if (version.isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { + return; + } + boolean enableDeadline = true; TaskData data = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); assertNotNull(data); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java index 43227dfbd..493c550a7 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaClientTest.java @@ -13,11 +13,7 @@ package org.eclipse.mylyn.bugzilla.tests.core; import java.net.InetSocketAddress; import java.net.Proxy; -import java.util.ArrayList; -import java.util.Collection; import java.util.HashSet; -import java.util.List; -import java.util.Map; import java.util.Set; import junit.framework.TestCase; @@ -25,13 +21,10 @@ import junit.framework.TestCase; import org.eclipse.core.runtime.NullProgressMonitor; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.commons.net.AbstractWebLocation; -import org.eclipse.mylyn.commons.net.AuthenticationCredentials; -import org.eclipse.mylyn.commons.net.AuthenticationType; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttributeMapper; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; -import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; import org.eclipse.mylyn.internal.bugzilla.core.RepositoryConfiguration; import org.eclipse.mylyn.internal.tasks.core.RepositoryQuery; import org.eclipse.mylyn.tasks.core.RepositoryResponse; @@ -39,7 +32,6 @@ import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.TaskAttribute; import org.eclipse.mylyn.tasks.core.data.TaskData; import org.eclipse.mylyn.tasks.core.data.TaskDataCollector; -import org.eclipse.mylyn.tasks.core.data.TaskMapper; import org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel; /** @@ -141,334 +133,6 @@ public class BugzillaClientTest extends TestCase { assertEquals(bugid, returnedData.iterator().next().getTaskId()); } - @SuppressWarnings("null") - public void testFlags() throws Exception { - BugzillaVersion version = new BugzillaVersion(BugzillaFixture.current().getVersion()); - if (version.isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { - return; - } - String taskNumber = "10"; - TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); - assertNotNull(taskData); - - Collection<TaskAttribute> a = taskData.getRoot().getAttributes().values(); - TaskAttribute flagA = null; - TaskAttribute flagB = null; - TaskAttribute flagC = null; - TaskAttribute flagD = null; - TaskAttribute stateA = null; - TaskAttribute stateB = null; - TaskAttribute stateC = null; - TaskAttribute stateD = null; - for (TaskAttribute taskAttribute : a) { - if (taskAttribute.getId().startsWith("task.common.kind.flag")) { - TaskAttribute state = taskAttribute.getAttribute("state"); - if (state.getMetaData().getLabel().equals("BugFlag1")) { - flagA = taskAttribute; - stateA = state; - } else if (state.getMetaData().getLabel().equals("BugFlag2")) { - flagB = taskAttribute; - stateB = state; - } else if (state.getMetaData().getLabel().equals("BugFlag3")) { - flagC = taskAttribute; - stateC = state; - } else if (state.getMetaData().getLabel().equals("BugFlag4")) { - flagD = taskAttribute; - stateD = state; - } - } - } - assertNotNull(flagA); - assertNotNull(flagB); - assertNotNull(flagC); - assertNotNull(flagD); - assertNotNull(stateA); - assertNotNull(stateB); - assertNotNull(stateC); - assertNotNull(stateD); - assertEquals("flagA is set(wrong precondidion)", " ", stateA.getValue()); - assertEquals("flagB is set(wrong precondidion)", " ", stateB.getValue()); - assertEquals("flagC is set(wrong precondidion)", " ", stateC.getValue()); - assertEquals("flagD is set(wrong precondidion)", " ", stateD.getValue()); - assertEquals("task.common.kind.flag_type1", flagA.getId()); - assertEquals("task.common.kind.flag_type2", flagB.getId()); - assertEquals("task.common.kind.flag_type5", flagC.getId()); - assertEquals("task.common.kind.flag_type6", flagD.getId()); - Map<String, String> optionA = stateA.getOptions(); - Map<String, String> optionB = stateB.getOptions(); - Map<String, String> optionC = stateC.getOptions(); - Map<String, String> optionD = stateD.getOptions(); - assertEquals(true, optionA.containsKey("")); - assertEquals(false, optionA.containsKey("?")); - assertEquals(true, optionA.containsKey("+")); - assertEquals(true, optionA.containsKey("-")); - assertEquals(true, optionB.containsKey("")); - assertEquals(true, optionB.containsKey("?")); - assertEquals(true, optionB.containsKey("+")); - assertEquals(true, optionB.containsKey("-")); - assertEquals(true, optionC.containsKey("")); - assertEquals(true, optionC.containsKey("?")); - assertEquals(true, optionC.containsKey("+")); - assertEquals(true, optionC.containsKey("-")); - assertEquals(true, optionD.containsKey("")); - assertEquals(true, optionD.containsKey("?")); - assertEquals(true, optionD.containsKey("+")); - assertEquals(true, optionD.containsKey("-")); - Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); - stateA.setValue("+"); - stateB.setValue("?"); - stateC.setValue("?"); - stateD.setValue("?"); - TaskAttribute requesteeD = flagD.getAttribute("requestee"); - requesteeD.setValue("guest@mylyn.eclipse.org"); - changed.add(flagA); - changed.add(flagB); - changed.add(flagC); - changed.add(flagD); - - BugzillaFixture.current().submitTask(taskData, client); - taskData = BugzillaFixture.current().getTask(taskNumber, client); - assertNotNull(taskData); - a = taskData.getRoot().getAttributes().values(); - flagA = null; - flagB = null; - flagC = null; - TaskAttribute flagC2 = null; - flagD = null; - stateA = null; - stateB = null; - stateC = null; - TaskAttribute stateC2 = null; - stateD = null; - for (TaskAttribute taskAttribute : a) { - if (taskAttribute.getId().startsWith("task.common.kind.flag")) { - TaskAttribute state = taskAttribute.getAttribute("state"); - if (state.getMetaData().getLabel().equals("BugFlag1")) { - flagA = taskAttribute; - stateA = state; - } else if (state.getMetaData().getLabel().equals("BugFlag2")) { - flagB = taskAttribute; - stateB = state; - } else if (state.getMetaData().getLabel().equals("BugFlag3")) { - if (flagC == null) { - flagC = taskAttribute; - stateC = state; - } else { - flagC2 = taskAttribute; - stateC2 = state; - } - } else if (state.getMetaData().getLabel().equals("BugFlag4")) { - flagD = taskAttribute; - stateD = state; - } - } - } - assertNotNull(flagA); - assertNotNull(flagB); - assertNotNull(flagC); - assertNotNull(flagC2); - assertNotNull(flagD); - assertNotNull(stateA); - assertNotNull(stateB); - assertNotNull(stateC); - assertNotNull(stateC2); - assertNotNull(stateD); - assertEquals("+", stateA.getValue()); - assertEquals("?", stateB.getValue()); - assertEquals("?", stateC.getValue()); - assertEquals(" ", stateC2.getValue()); - assertEquals("?", stateD.getValue()); - requesteeD = flagD.getAttribute("requestee"); - assertNotNull(requesteeD); - assertEquals("guest@mylyn.eclipse.org", requesteeD.getValue()); - stateA.setValue(" "); - stateB.setValue(" "); - stateC.setValue(" "); - stateD.setValue(" "); - changed.add(flagA); - changed.add(flagB); - changed.add(flagC); - changed.add(flagD); - - BugzillaFixture.current().submitTask(taskData, client); - taskData = BugzillaFixture.current().getTask(taskNumber, client); - assertNotNull(taskData); - a = taskData.getRoot().getAttributes().values(); - flagA = null; - flagB = null; - flagC = null; - flagC2 = null; - flagD = null; - stateA = null; - stateB = null; - stateC = null; - stateC2 = null; - stateD = null; - for (TaskAttribute taskAttribute : a) { - if (taskAttribute.getId().startsWith("task.common.kind.flag")) { - TaskAttribute state = taskAttribute.getAttribute("state"); - if (state.getMetaData().getLabel().equals("BugFlag1")) { - flagA = taskAttribute; - stateA = state; - } else if (state.getMetaData().getLabel().equals("BugFlag2")) { - flagB = taskAttribute; - stateB = state; - } else if (state.getMetaData().getLabel().equals("BugFlag3")) { - if (flagC == null) { - flagC = taskAttribute; - stateC = state; - } else { - flagC2 = taskAttribute; - stateC2 = state; - } - } else if (state.getMetaData().getLabel().equals("BugFlag4")) { - flagD = taskAttribute; - stateD = state; - } - } - } - assertNotNull(flagA); - assertNotNull(flagB); - assertNotNull(flagC); - assertNull(flagC2); - assertNotNull(flagD); - assertNotNull(stateA); - assertNotNull(stateB); - assertNotNull(stateC); - assertNull(stateC2); - assertNotNull(stateD); - assertEquals(" ", stateA.getValue()); - assertEquals(" ", stateB.getValue()); - assertEquals(" ", stateC.getValue()); - assertEquals(" ", stateD.getValue()); - requesteeD = flagD.getAttribute("requestee"); - assertNotNull(requesteeD); - assertEquals("", requesteeD.getValue()); - } - - public void testCustomAttributes() throws Exception { - - BugzillaVersion version = new BugzillaVersion(BugzillaFixture.current().getVersion()); - if (version.isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { - return; - } - - String taskNumber = "1"; - TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); - assertNotNull(taskData); - TaskMapper mapper = new TaskMapper(taskData); - assertEquals(taskNumber, taskData.getTaskId()); - -// SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); -// assertEquals(format1.parse("2009-09-16 14:11"), mapper.getCreationDate()); - - AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY); - assertNotNull("credentials are null", credentials); - assertNotNull("Repositor User not set", credentials.getUserName()); - assertNotNull("no password for Repository", credentials.getPassword()); - - TaskAttribute colorAttribute = mapper.getTaskData().getRoot().getAttribute("cf_multiselect"); - assertNotNull("TaskAttribute Color did not exists", colorAttribute); - List<String> theColors = colorAttribute.getValues(); - assertNotNull(theColors); - assertFalse("no colors set", theColors.isEmpty()); - - boolean red = false; - boolean green = false; - boolean yellow = false; - boolean blue = false; - - for (Object element : theColors) { - String string = (String) element; - - if (!red && string.compareTo("Red") == 0) { - red = true; - } else if (!green && string.compareTo("Green") == 0) { - green = true; - } else if (!yellow && string.compareTo("Yellow") == 0) { - yellow = true; - } else if (!blue && string.compareTo("Blue") == 0) { - blue = true; - } - } - changeCollorAndSubmit(taskData, colorAttribute, red, green, yellow, blue); - taskData = BugzillaFixture.current().getTask(taskNumber, client); - assertNotNull(taskData); - mapper = new TaskMapper(taskData); - - colorAttribute = mapper.getTaskData().getRoot().getAttribute("cf_multiselect"); - assertNotNull("TaskAttribute Color did not exists", colorAttribute); - theColors = colorAttribute.getValues(); - assertNotNull(theColors); - assertFalse("no colors set", theColors.isEmpty()); - boolean red_new = false; - boolean green_new = false; - boolean yellow_new = false; - boolean blue_new = false; - - for (Object element : theColors) { - String string = (String) element; - - if (!red_new && string.compareTo("Red") == 0) { - red_new = true; - } else if (!green_new && string.compareTo("Green") == 0) { - green_new = true; - } else if (!yellow_new && string.compareTo("Yellow") == 0) { - yellow_new = true; - } else if (!blue_new && string.compareTo("Blue") == 0) { - blue_new = true; - } - } - assertTrue("wrong change", - (!red && green && !yellow && !blue && red_new && green_new && !yellow_new && !blue_new) - || (red && green && !yellow && !blue && !red_new && green_new && !yellow_new && !blue_new)); - changeCollorAndSubmit(taskData, colorAttribute, red_new, green_new, yellow_new, blue_new); - - } - - private void changeCollorAndSubmit(TaskData taskData, TaskAttribute colorAttribute, boolean red, boolean green, - boolean yellow, boolean blue) throws Exception { - if (!red && green && !yellow && !blue) { - List<String> newValue = new ArrayList<String>(2); - newValue.add("Red"); - newValue.add("Green"); - colorAttribute.setValues(newValue); - Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); - changed.add(colorAttribute); - // Submit changes - BugzillaFixture.current().submitTask(taskData, client); - } else if (red && green && !yellow && !blue) { - List<String> newValue = new ArrayList<String>(2); - newValue.add("Green"); - colorAttribute.setValues(newValue); - Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); - changed.add(colorAttribute); - // Submit changes - BugzillaFixture.current().submitTask(taskData, client); - } - } - - public void testCustomAttributesNewTask() throws Exception { - TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); - assertNotNull(taskData); - assertNotNull(taskData.getRoot().getAttribute("token")); - TaskAttribute productAttribute = taskData.getRoot().getAttribute(BugzillaAttribute.PRODUCT.getKey()); - assertNotNull(productAttribute); - assertEquals("ManualTest" + "", productAttribute.getValue()); - TaskAttribute cfAttribute1 = taskData.getRoot().getAttribute("cf_freetext"); - assertNotNull(cfAttribute1); - TaskAttribute cfAttribute2 = taskData.getRoot().getAttribute("cf_dropdown"); - assertNotNull(cfAttribute2); - TaskAttribute cfAttribute3 = taskData.getRoot().getAttribute("cf_largetextbox"); - assertNotNull(cfAttribute3); - TaskAttribute cfAttribute4 = taskData.getRoot().getAttribute("cf_multiselect"); - assertNotNull(cfAttribute4); - TaskAttribute cfAttribute5 = taskData.getRoot().getAttribute("cf_datetime"); - assertNotNull(cfAttribute5); - TaskAttribute cfAttribute6 = taskData.getRoot().getAttribute("cf_bugid"); - assertNotNull(cfAttribute6); - } - public void testLeadingZeros() throws Exception { String taskNumber = "0010"; TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java new file mode 100644 index 000000000..822857a2a --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaCustomFieldsTest.java @@ -0,0 +1,211 @@ +/******************************************************************************* + * Copyright (c) 2010 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.bugzilla.tests.core; + +import java.util.ArrayList; +import java.util.HashSet; +import java.util.List; +import java.util.Set; + +import junit.framework.TestCase; + +import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; +import org.eclipse.mylyn.commons.net.AuthenticationCredentials; +import org.eclipse.mylyn.commons.net.AuthenticationType; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; +import org.eclipse.mylyn.tasks.core.TaskRepository; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskData; +import org.eclipse.mylyn.tasks.core.data.TaskMapper; +import org.eclipse.mylyn.tests.util.TestUtil.PrivilegeLevel; + +/** + * Tests should be run against Bugzilla 3.2.4 or greater + * + * @author Frank Becker + * @author Robert Elves + */ +public class BugzillaCustomFieldsTest extends TestCase { + + private BugzillaClient client; + + private TaskRepository repository; + + @Override + protected void setUp() throws Exception { + repository = BugzillaFixture.current().repository(); + client = BugzillaFixture.current().client(); + } + + public void testCustomAttributes() throws Exception { + + String taskNumber = "1"; + TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(taskData); + TaskMapper mapper = new TaskMapper(taskData); + assertEquals(taskNumber, taskData.getTaskId()); + +// SimpleDateFormat format1 = new SimpleDateFormat("yyyy-MM-dd HH:mm"); +// assertEquals(format1.parse("2009-09-16 14:11"), mapper.getCreationDate()); + + AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY); + assertNotNull("credentials are null", credentials); + assertNotNull("Repositor User not set", credentials.getUserName()); + assertNotNull("no password for Repository", credentials.getPassword()); + + TaskAttribute colorAttribute = mapper.getTaskData().getRoot().getAttribute("cf_multiselect"); + assertNotNull("TaskAttribute Color did not exists", colorAttribute); + List<String> theColors = colorAttribute.getValues(); + assertNotNull(theColors); + assertFalse("no colors set", theColors.isEmpty()); + + boolean red = false; + boolean green = false; + boolean yellow = false; + boolean blue = false; + + for (Object element : theColors) { + String string = (String) element; + + if (!red && string.compareTo("Red") == 0) { + red = true; + } else if (!green && string.compareTo("Green") == 0) { + green = true; + } else if (!yellow && string.compareTo("Yellow") == 0) { + yellow = true; + } else if (!blue && string.compareTo("Blue") == 0) { + blue = true; + } + } + changeCollorAndSubmit(taskData, colorAttribute, red, green, yellow, blue); + taskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(taskData); + mapper = new TaskMapper(taskData); + + colorAttribute = mapper.getTaskData().getRoot().getAttribute("cf_multiselect"); + assertNotNull("TaskAttribute Color did not exists", colorAttribute); + theColors = colorAttribute.getValues(); + assertNotNull(theColors); + assertFalse("no colors set", theColors.isEmpty()); + boolean red_new = false; + boolean green_new = false; + boolean yellow_new = false; + boolean blue_new = false; + + for (Object element : theColors) { + String string = (String) element; + + if (!red_new && string.compareTo("Red") == 0) { + red_new = true; + } else if (!green_new && string.compareTo("Green") == 0) { + green_new = true; + } else if (!yellow_new && string.compareTo("Yellow") == 0) { + yellow_new = true; + } else if (!blue_new && string.compareTo("Blue") == 0) { + blue_new = true; + } + } + assertTrue("wrong change", + (!red && green && !yellow && !blue && red_new && green_new && !yellow_new && !blue_new) + || (red && green && !yellow && !blue && !red_new && green_new && !yellow_new && !blue_new)); + changeCollorAndSubmit(taskData, colorAttribute, red_new, green_new, yellow_new, blue_new); + + } + + private void changeCollorAndSubmit(TaskData taskData, TaskAttribute colorAttribute, boolean red, boolean green, + boolean yellow, boolean blue) throws Exception { + if (!red && green && !yellow && !blue) { + List<String> newValue = new ArrayList<String>(2); + newValue.add("Red"); + newValue.add("Green"); + colorAttribute.setValues(newValue); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + changed.add(colorAttribute); + // Submit changes + BugzillaFixture.current().submitTask(taskData, client); + } else if (red && green && !yellow && !blue) { + List<String> newValue = new ArrayList<String>(2); + newValue.add("Green"); + colorAttribute.setValues(newValue); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + changed.add(colorAttribute); + // Submit changes + BugzillaFixture.current().submitTask(taskData, client); + } + } + + public void testCustomAttributesNewTask() throws Exception { + + BugzillaVersion version = new BugzillaVersion(BugzillaFixture.current().getVersion()); + if (version.isSmallerOrEquals(BugzillaVersion.BUGZILLA_3_2)) { + return; + } + + TaskData taskData = BugzillaFixture.current().createTask(PrivilegeLevel.USER, null, null); + assertNotNull(taskData); + assertNotNull(taskData.getRoot().getAttribute("token")); + TaskAttribute productAttribute = taskData.getRoot().getAttribute(BugzillaAttribute.PRODUCT.getKey()); + assertNotNull(productAttribute); + assertEquals("ManualTest" + "", productAttribute.getValue()); + TaskAttribute cfAttribute1 = taskData.getRoot().getAttribute("cf_freetext"); + assertNotNull(cfAttribute1); + TaskAttribute cfAttribute2 = taskData.getRoot().getAttribute("cf_dropdown"); + assertNotNull(cfAttribute2); + TaskAttribute cfAttribute3 = taskData.getRoot().getAttribute("cf_largetextbox"); + assertNotNull(cfAttribute3); + TaskAttribute cfAttribute4 = taskData.getRoot().getAttribute("cf_multiselect"); + assertNotNull(cfAttribute4); + TaskAttribute cfAttribute5 = taskData.getRoot().getAttribute("cf_datetime"); + assertNotNull(cfAttribute5); + TaskAttribute cfAttribute6 = taskData.getRoot().getAttribute("cf_bugid"); + assertNotNull(cfAttribute6); + } + + public void testCustomFields() throws Exception { + + String taskNumber = "1"; + + TaskData fruitTaskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(fruitTaskData); + + if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("---")) { + setFruitValueTo(fruitTaskData, "apple"); + setFruitValueTo(fruitTaskData, "orange"); + setFruitValueTo(fruitTaskData, "---"); + } else if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("apple")) { + setFruitValueTo(fruitTaskData, "orange"); + setFruitValueTo(fruitTaskData, "apple"); + setFruitValueTo(fruitTaskData, "---"); + } else if (fruitTaskData.getRoot().getAttribute("cf_multiselect").getValue().equals("orange")) { + setFruitValueTo(fruitTaskData, "apple"); + setFruitValueTo(fruitTaskData, "orange"); + setFruitValueTo(fruitTaskData, "---"); + } + if (fruitTaskData != null) { + fruitTaskData = null; + } + } + + private void setFruitValueTo(TaskData fruitTaskData, String newValue) throws Exception { + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + TaskAttribute cf_fruit = fruitTaskData.getRoot().getAttribute("cf_fruit"); + cf_fruit.setValue(newValue); + assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_fruit").getValue()); + changed.add(cf_fruit); + BugzillaFixture.current().submitTask(fruitTaskData, client); + fruitTaskData = BugzillaFixture.current().getTask(fruitTaskData.getTaskId(), client); + assertEquals(newValue, fruitTaskData.getRoot().getAttribute("cf_fruit").getValue()); + } + +} diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaFlagsTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaFlagsTest.java new file mode 100644 index 000000000..1d7fff6a1 --- /dev/null +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaFlagsTest.java @@ -0,0 +1,242 @@ +/******************************************************************************* + * Copyright (c) 2010 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.bugzilla.tests.core; + +import java.util.Collection; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +import junit.framework.TestCase; + +import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; +import org.eclipse.mylyn.tasks.core.data.TaskAttribute; +import org.eclipse.mylyn.tasks.core.data.TaskData; + +/** + * Tests should be run against Bugzilla 3.2.4 or greater + * + * @author Frank Becker + * @author Robert Elves + */ +public class BugzillaFlagsTest extends TestCase { + + private BugzillaClient client; + + @Override + protected void setUp() throws Exception { + client = BugzillaFixture.current().client(); + } + + @SuppressWarnings("null") + public void testFlags() throws Exception { + String taskNumber = "10"; + TaskData taskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(taskData); + + Collection<TaskAttribute> a = taskData.getRoot().getAttributes().values(); + TaskAttribute flagA = null; + TaskAttribute flagB = null; + TaskAttribute flagC = null; + TaskAttribute flagD = null; + TaskAttribute stateA = null; + TaskAttribute stateB = null; + TaskAttribute stateC = null; + TaskAttribute stateD = null; + for (TaskAttribute taskAttribute : a) { + if (taskAttribute.getId().startsWith("task.common.kind.flag")) { + TaskAttribute state = taskAttribute.getAttribute("state"); + if (state.getMetaData().getLabel().equals("BugFlag1")) { + flagA = taskAttribute; + stateA = state; + } else if (state.getMetaData().getLabel().equals("BugFlag2")) { + flagB = taskAttribute; + stateB = state; + } else if (state.getMetaData().getLabel().equals("BugFlag3")) { + flagC = taskAttribute; + stateC = state; + } else if (state.getMetaData().getLabel().equals("BugFlag4")) { + flagD = taskAttribute; + stateD = state; + } + } + } + assertNotNull(flagA); + assertNotNull(flagB); + assertNotNull(flagC); + assertNotNull(flagD); + assertNotNull(stateA); + assertNotNull(stateB); + assertNotNull(stateC); + assertNotNull(stateD); + assertEquals("flagA is set(wrong precondidion)", " ", stateA.getValue()); + assertEquals("flagB is set(wrong precondidion)", " ", stateB.getValue()); + assertEquals("flagC is set(wrong precondidion)", " ", stateC.getValue()); + assertEquals("flagD is set(wrong precondidion)", " ", stateD.getValue()); + assertEquals("task.common.kind.flag_type1", flagA.getId()); + assertEquals("task.common.kind.flag_type2", flagB.getId()); + assertEquals("task.common.kind.flag_type5", flagC.getId()); + assertEquals("task.common.kind.flag_type6", flagD.getId()); + Map<String, String> optionA = stateA.getOptions(); + Map<String, String> optionB = stateB.getOptions(); + Map<String, String> optionC = stateC.getOptions(); + Map<String, String> optionD = stateD.getOptions(); + assertEquals(true, optionA.containsKey("")); + assertEquals(false, optionA.containsKey("?")); + assertEquals(true, optionA.containsKey("+")); + assertEquals(true, optionA.containsKey("-")); + assertEquals(true, optionB.containsKey("")); + assertEquals(true, optionB.containsKey("?")); + assertEquals(true, optionB.containsKey("+")); + assertEquals(true, optionB.containsKey("-")); + assertEquals(true, optionC.containsKey("")); + assertEquals(true, optionC.containsKey("?")); + assertEquals(true, optionC.containsKey("+")); + assertEquals(true, optionC.containsKey("-")); + assertEquals(true, optionD.containsKey("")); + assertEquals(true, optionD.containsKey("?")); + assertEquals(true, optionD.containsKey("+")); + assertEquals(true, optionD.containsKey("-")); + Set<TaskAttribute> changed = new HashSet<TaskAttribute>(); + stateA.setValue("+"); + stateB.setValue("?"); + stateC.setValue("?"); + stateD.setValue("?"); + TaskAttribute requesteeD = flagD.getAttribute("requestee"); + requesteeD.setValue("guest@mylyn.eclipse.org"); + changed.add(flagA); + changed.add(flagB); + changed.add(flagC); + changed.add(flagD); + + BugzillaFixture.current().submitTask(taskData, client); + taskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(taskData); + a = taskData.getRoot().getAttributes().values(); + flagA = null; + flagB = null; + flagC = null; + TaskAttribute flagC2 = null; + flagD = null; + stateA = null; + stateB = null; + stateC = null; + TaskAttribute stateC2 = null; + stateD = null; + for (TaskAttribute taskAttribute : a) { + if (taskAttribute.getId().startsWith("task.common.kind.flag")) { + TaskAttribute state = taskAttribute.getAttribute("state"); + if (state.getMetaData().getLabel().equals("BugFlag1")) { + flagA = taskAttribute; + stateA = state; + } else if (state.getMetaData().getLabel().equals("BugFlag2")) { + flagB = taskAttribute; + stateB = state; + } else if (state.getMetaData().getLabel().equals("BugFlag3")) { + if (flagC == null) { + flagC = taskAttribute; + stateC = state; + } else { + flagC2 = taskAttribute; + stateC2 = state; + } + } else if (state.getMetaData().getLabel().equals("BugFlag4")) { + flagD = taskAttribute; + stateD = state; + } + } + } + assertNotNull(flagA); + assertNotNull(flagB); + assertNotNull(flagC); + assertNotNull(flagC2); + assertNotNull(flagD); + assertNotNull(stateA); + assertNotNull(stateB); + assertNotNull(stateC); + assertNotNull(stateC2); + assertNotNull(stateD); + assertEquals("+", stateA.getValue()); + assertEquals("?", stateB.getValue()); + assertEquals("?", stateC.getValue()); + assertEquals(" ", stateC2.getValue()); + assertEquals("?", stateD.getValue()); + requesteeD = flagD.getAttribute("requestee"); + assertNotNull(requesteeD); + assertEquals("guest@mylyn.eclipse.org", requesteeD.getValue()); + stateA.setValue(" "); + stateB.setValue(" "); + stateC.setValue(" "); + stateD.setValue(" "); + changed.add(flagA); + changed.add(flagB); + changed.add(flagC); + changed.add(flagD); + + BugzillaFixture.current().submitTask(taskData, client); + taskData = BugzillaFixture.current().getTask(taskNumber, client); + assertNotNull(taskData); + a = taskData.getRoot().getAttributes().values(); + flagA = null; + flagB = null; + flagC = null; + flagC2 = null; + flagD = null; + stateA = null; + stateB = null; + stateC = null; + stateC2 = null; + stateD = null; + for (TaskAttribute taskAttribute : a) { + if (taskAttribute.getId().startsWith("task.common.kind.flag")) { + TaskAttribute state = taskAttribute.getAttribute("state"); + if (state.getMetaData().getLabel().equals("BugFlag1")) { + flagA = taskAttribute; + stateA = state; + } else if (state.getMetaData().getLabel().equals("BugFlag2")) { + flagB = taskAttribute; + stateB = state; + } else if (state.getMetaData().getLabel().equals("BugFlag3")) { + if (flagC == null) { + flagC = taskAttribute; + stateC = state; + } else { + flagC2 = taskAttribute; + stateC2 = state; + } + } else if (state.getMetaData().getLabel().equals("BugFlag4")) { + flagD = taskAttribute; + stateD = state; + } + } + } + assertNotNull(flagA); + assertNotNull(flagB); + assertNotNull(flagC); + assertNull(flagC2); + assertNotNull(flagD); + assertNotNull(stateA); + assertNotNull(stateB); + assertNotNull(stateC); + assertNull(stateC2); + assertNotNull(stateD); + assertEquals(" ", stateA.getValue()); + assertEquals(" ", stateB.getValue()); + assertEquals(" ", stateC.getValue()); + assertEquals(" ", stateD.getValue()); + requesteeD = flagD.getAttribute("requestee"); + assertNotNull(requesteeD); + assertEquals("", requesteeD.getValue()); + } + +} diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskCompletionTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaTaskCompletionTest.java index 8c47a3cba..5085912ed 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/BugzillaTaskCompletionTest.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/core/BugzillaTaskCompletionTest.java @@ -9,13 +9,14 @@ * Tasktop Technologies - initial API and implementation *******************************************************************************/ -package org.eclipse.mylyn.bugzilla.tests; +package org.eclipse.mylyn.bugzilla.tests.core; import java.text.SimpleDateFormat; import java.util.Date; import junit.framework.TestCase; +import org.eclipse.mylyn.bugzilla.tests.BugzillaTestConstants; import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaAttribute; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java index f629cc8c0..cc158bd80 100644 --- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java +++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/support/BugzillaFixture.java @@ -26,6 +26,7 @@ import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClient; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaClientManager; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaCorePlugin; import org.eclipse.mylyn.internal.bugzilla.core.BugzillaRepositoryConnector; +import org.eclipse.mylyn.internal.bugzilla.core.BugzillaVersion; import org.eclipse.mylyn.tasks.core.RepositoryResponse; import org.eclipse.mylyn.tasks.core.TaskRepository; import org.eclipse.mylyn.tasks.core.data.AbstractTaskDataHandler; @@ -99,6 +100,19 @@ public class BugzillaFixture extends TestFixture { private final String version; + private final BugzillaVersion bugzillaVersion; + + public BugzillaFixture(String url, String version, String info) { + super(BugzillaCorePlugin.CONNECTOR_KIND, url); + this.version = version; + this.bugzillaVersion = new BugzillaVersion(version); + setInfo("Bugzilla", version, info); + } + + public BugzillaVersion getBugzillaVersion() { + return bugzillaVersion; + } + public static void cleanup010() throws Exception { } @@ -113,12 +127,6 @@ public class BugzillaFixture extends TestFixture { return current(DEFAULT); } - public BugzillaFixture(String url, String version, String info) { - super(BugzillaCorePlugin.CONNECTOR_KIND, url); - this.version = version; - setInfo("Bugzilla", version, info); - } - @Override public BugzillaFixture activate() { current = this; |