Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2016-08-30 18:42:08 -0400
committerSam Davis2016-09-01 13:44:21 -0400
commit49c3cb0bfe61796f484b52c629a98172bb7eefee (patch)
tree6cf64b92cf670282ac5661d5bd893388a5083191
parentb4c722e53591c523bb4ca240b0aa87c5a153804c (diff)
downloadorg.eclipse.mylyn.tasks-49c3cb0bfe61796f484b52c629a98172bb7eefee.tar.gz
org.eclipse.mylyn.tasks-49c3cb0bfe61796f484b52c629a98172bb7eefee.tar.xz
org.eclipse.mylyn.tasks-49c3cb0bfe61796f484b52c629a98172bb7eefee.zip
replace testValidateOnFinishInvalidUserId with unit test
This test is running forever in http://ci.mylyn.org/job/mylyn-3.21.x/ and I can't figure out why. This is an integration test whose main purpose is to verify that the settings page remains open when validate on finish fails. This really ought to be verified by a unit test of the page instead. Change-Id: I55813566e3707f082904001750c065285ed5c3e0
-rw-r--r--org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaRepositorySettingsPageTest.java29
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPageTest.java (renamed from org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java)107
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java6
3 files changed, 108 insertions, 34 deletions
diff --git a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaRepositorySettingsPageTest.java b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaRepositorySettingsPageTest.java
index 69b1a3f04..9056bfce9 100644
--- a/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaRepositorySettingsPageTest.java
+++ b/org.eclipse.mylyn.bugzilla.tests/src/org/eclipse/mylyn/bugzilla/tests/ui/BugzillaRepositorySettingsPageTest.java
@@ -13,8 +13,6 @@ package org.eclipse.mylyn.bugzilla.tests.ui;
import java.net.MalformedURLException;
-import junit.framework.TestCase;
-
import org.eclipse.core.runtime.CoreException;
import org.eclipse.jface.wizard.WizardDialog;
import org.eclipse.mylyn.bugzilla.tests.support.BugzillaFixture;
@@ -37,6 +35,8 @@ import org.eclipse.mylyn.tasks.ui.TasksUi;
import org.eclipse.mylyn.tests.util.TasksUiTestUtil;
import org.eclipse.ui.PlatformUI;
+import junit.framework.TestCase;
+
/**
* @author Rob Elves
*/
@@ -53,7 +53,8 @@ public class BugzillaRepositorySettingsPageTest extends TestCase {
super.setUp();
manager = TasksUiPlugin.getRepositoryManager();
manager.clearRepositories(TasksUiPlugin.getDefault().getRepositoriesFilePath());
- repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND, BugzillaFixture.current().getRepositoryUrl());
+ repository = new TaskRepository(BugzillaCorePlugin.CONNECTOR_KIND,
+ BugzillaFixture.current().getRepositoryUrl());
UserCredentials credentials = CommonTestUtil.getCredentials(PrivilegeLevel.USER);
repository.setCredentials(AuthenticationType.REPOSITORY,
new AuthenticationCredentials(credentials.getUserName(), credentials.getPassword()), false);
@@ -74,7 +75,8 @@ public class BugzillaRepositorySettingsPageTest extends TestCase {
taskRepository.setCredentials(AuthenticationType.HTTP, webCredentials, false);
taskRepository.setCharacterEncoding(encoding);
- BugzillaRepositoryConnector connector = (BugzillaRepositoryConnector) TasksUi.getRepositoryConnector(repository.getConnectorKind());
+ BugzillaRepositoryConnector connector = (BugzillaRepositoryConnector) TasksUi
+ .getRepositoryConnector(repository.getConnectorKind());
return BugzillaClientFactory.createClient(taskRepository, connector);
}
@@ -164,23 +166,4 @@ public class BugzillaRepositorySettingsPageTest extends TestCase {
assertEquals(tempUid, repositoryTest.getUserName());
assertEquals(tempPass, repositoryTest.getPassword());
}
-
- public void testValidateOnFinishInvalidUserId() throws Exception {
- assertEquals(1, manager.getAllRepositories().size());
- WizardDialog dialog = new WizardDialog(PlatformUI.getWorkbench().getDisplay().getActiveShell(), wizard);
- dialog.create();
- BugzillaRepositorySettingsPage page = (BugzillaRepositorySettingsPage) wizard.getSettingsPage();
- BugzillaClient client = createClient(page.getRepositoryUrl(), page.getUserName(), page.getPassword(),
- page.getHttpAuthUserId(), page.getHttpAuthPassword(), page.getCharacterEncoding());
- client.validate(null);
- String oldUserId = page.getUserName();
- page.setUserId("bogus");
- boolean finished = wizard.performFinish();
- assertFalse(finished);
- assertEquals(1, manager.getAllRepositories().size());
- TaskRepository repositoryTest = manager.getRepository(BugzillaCorePlugin.CONNECTOR_KIND,
- BugzillaFixture.current().getRepositoryUrl());
- assertEquals(oldUserId, repositoryTest.getCredentials(AuthenticationType.REPOSITORY).getUserName());
- }
-
}
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/AbstractRepositorySettingsPageTest.java
index 6c35ee5fa..824afdea1 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/AbstractRepositorySettingsPageTest.java
@@ -15,6 +15,9 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Matchers.any;
+import static org.mockito.Matchers.anyBoolean;
+import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
@@ -22,9 +25,14 @@ import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.lang.reflect.InvocationTargetException;
+
import org.eclipse.core.runtime.CoreException;
import org.eclipse.core.runtime.IProgressMonitor;
+import org.eclipse.core.runtime.IStatus;
+import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.core.runtime.Status;
+import org.eclipse.jface.operation.IRunnableWithProgress;
import org.eclipse.jface.preference.StringFieldEditor;
import org.eclipse.jface.wizard.IWizard;
import org.eclipse.jface.wizard.IWizardContainer;
@@ -35,15 +43,32 @@ import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.ui.PlatformUI;
import org.junit.Test;
+import org.mockito.invocation.InvocationOnMock;
+import org.mockito.stubbing.Answer;
+
+import com.google.common.base.Throwables;
@SuppressWarnings("restriction")
-public class RepositorySettingsPageTest {
+public class AbstractRepositorySettingsPageTest {
public static class TestRepositorySettingsPage extends AbstractRepositorySettingsPage {
- public TestRepositorySettingsPage(TaskRepository taskRepository) {
+ private final boolean shouldValidateOnFinish;
+
+ private final IStatus validationStatus;
+
+ private boolean ranValidator;
+
+ public TestRepositorySettingsPage(TaskRepository taskRepository, boolean shouldValidateOnFinish,
+ IStatus validationStatus) {
super("Title", "Description", taskRepository, MockRepositoryConnector.getDefault());
setNeedsProxy(true);
+ this.shouldValidateOnFinish = shouldValidateOnFinish;
+ this.validationStatus = validationStatus;
+ }
+
+ public TestRepositorySettingsPage(TaskRepository taskRepository) {
+ this(taskRepository, false, Status.OK_STATUS);
}
@Override
@@ -52,9 +77,10 @@ public class RepositorySettingsPageTest {
@Override
public void run(IProgressMonitor monitor) throws CoreException {
+ ranValidator = true;
}
};
- validator.setStatus(Status.OK_STATUS);
+ validator.setStatus(validationStatus);
return validator;
}
@@ -72,6 +98,14 @@ public class RepositorySettingsPageTest {
return serverUrlCombo;
}
+ @Override
+ public boolean shouldValidateOnFinish() {
+ return shouldValidateOnFinish;
+ }
+
+ public boolean ranValidator() {
+ return ranValidator;
+ }
}
public static class RepositorySettingsPageWithNoCredentials extends TestRepositorySettingsPage {
@@ -124,7 +158,7 @@ public class RepositorySettingsPageTest {
public void applyToNewRepository() {
TaskRepository repository = createTaskRepository();
repository.removeProperty(ITasksCoreConstants.PROPERTY_BRAND_ID);
- AbstractRepositorySettingsPage page = createPage(null);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(null);
assertNull(repository.getProperty(ITasksCoreConstants.PROPERTY_BRAND_ID));
page.applyTo(repository);
@@ -139,7 +173,7 @@ public class RepositorySettingsPageTest {
public void applyToExistingRepository() {
TaskRepository repository = createTaskRepository();
repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, "existing.brand");
- AbstractRepositorySettingsPage page = createPage(repository);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(repository);
page.setBrand("org.mylyn");
page.applyTo(repository);
@@ -150,7 +184,7 @@ public class RepositorySettingsPageTest {
public void applyNullBrandToExistingRepository() {
TaskRepository repository = createTaskRepository();
repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, "existing.brand");
- AbstractRepositorySettingsPage page = createPage(repository);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(repository);
page.setBrand(null);
page.applyTo(repository);
@@ -159,7 +193,7 @@ public class RepositorySettingsPageTest {
@Test
public void setsTitleFromBrand() {
- AbstractRepositorySettingsPage page = createPage(null);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(null);
assertEquals("Title", page.getTitle());
page.setBrand("org.mylyn");
assertEquals("Label for org.mylyn", page.getTitle());
@@ -169,7 +203,7 @@ public class RepositorySettingsPageTest {
public void setsTitleFromBrandedRepository() {
TaskRepository repository = createTaskRepository();
repository.setProperty(ITasksCoreConstants.PROPERTY_BRAND_ID, "org.mylyn");
- AbstractRepositorySettingsPage page = createPage(repository);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(repository);
assertEquals("Label for org.mylyn", page.getTitle());
}
@@ -177,7 +211,7 @@ public class RepositorySettingsPageTest {
public void setsTitleFromUnbrandedRepository() {
TaskRepository repository = createTaskRepository();
repository.removeProperty(ITasksCoreConstants.PROPERTY_BRAND_ID);
- AbstractRepositorySettingsPage page = createPage(repository);
+ AbstractRepositorySettingsPage page = createPageWithNoCredentials(repository);
assertEquals("Title", page.getTitle());
}
@@ -291,7 +325,60 @@ public class RepositorySettingsPageTest {
assertFalse(page.isUrlReadOnly());
}
- private AbstractRepositorySettingsPage createPage(TaskRepository repository) {
+ @Test
+ public void preFinish() {
+ TaskRepository repository = createTaskRepository();
+ TestRepositorySettingsPage page = createPage(repository, false, Status.OK_STATUS);
+ assertTrue(page.preFinish(repository));
+ assertFalse(page.ranValidator());
+
+ page = createPage(repository, false, Status.CANCEL_STATUS);
+ assertTrue(page.preFinish(repository));
+ assertFalse(page.ranValidator());
+ }
+
+ @Test
+ public void preFinishValidateOnFinish() {
+ TaskRepository repository = createTaskRepository();
+ TestRepositorySettingsPage page = createPage(repository, true, Status.OK_STATUS);
+ assertTrue(page.preFinish(repository));
+ assertTrue(page.ranValidator());
+
+ page = createPage(repository, true, Status.CANCEL_STATUS);
+ assertFalse(page.preFinish(repository));
+ assertTrue(page.ranValidator());
+ }
+
+ private TestRepositorySettingsPage createPage(TaskRepository repository, boolean shouldValidateOnFinish,
+ IStatus validationStatus) {
+ TestRepositorySettingsPage page = spy(
+ new TestRepositorySettingsPage(repository, shouldValidateOnFinish, validationStatus));
+ IWizard wizard = mock(IWizard.class);
+ IWizardContainer container = mock(IWizardContainer.class);
+ try {
+ doAnswer(new Answer<Void>() {
+
+ @Override
+ public Void answer(InvocationOnMock invocation) throws Throwable {
+ IRunnableWithProgress runnable = (IRunnableWithProgress) invocation.getArguments()[2];
+ runnable.run(new NullProgressMonitor());
+ return null;
+ }
+ }).when(container).run(anyBoolean(), anyBoolean(), any());
+ } catch (InvocationTargetException | InterruptedException e) {
+ Throwables.propagate(e);
+ }
+ when(wizard.getContainer()).thenReturn(container);
+ page.setWizard(wizard);
+ doReturn("http://mock/").when(page).getRepositoryUrl();
+ doReturn("label").when(page).getRepositoryLabel();
+ doReturn(false).when(page).needsAdvanced();
+ doReturn(false).when(page).needsProxy();
+ doReturn(false).when(page).needsRepositoryCredentials();
+ return page;
+ }
+
+ private AbstractRepositorySettingsPage createPageWithNoCredentials(TaskRepository repository) {
AbstractRepositorySettingsPage page = spy(new RepositorySettingsPageWithNoCredentials(repository));
doReturn("label").when(page).getRepositoryLabel();
when(page.needsProxy()).thenReturn(false);
diff --git a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
index 330051107..c511bdc2e 100644
--- a/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
+++ b/org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java
@@ -2237,7 +2237,7 @@ public abstract class AbstractRepositorySettingsPage extends AbstractTaskReposit
@Override
public boolean preFinish(TaskRepository repository) {
- if (validateOnFinishButton != null && validateOnFinishButton.getSelection() && !propertiesUnchanged()) {
+ if (shouldValidateOnFinish() && !propertiesUnchanged()) {
isValid = false;
validateSettings();
} else {
@@ -2249,6 +2249,10 @@ public abstract class AbstractRepositorySettingsPage extends AbstractTaskReposit
return isValid;
}
+ boolean shouldValidateOnFinish() {
+ return validateOnFinishButton != null && validateOnFinishButton.getSelection();
+ }
+
@Override
protected ExpandableComposite createSection(Composite parentControl, String title) {
if (parentControl instanceof SectionComposite) {

Back to the top