Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDoug Janzen2014-09-16 23:26:18 +0000
committerGerrit Code Review @ Eclipse.org2015-02-14 14:29:07 +0000
commit66369afb5c49a63829059cb2ec1d9663f2159833 (patch)
tree9f57b4b21e7ec49bb179b42955446dc3d00f3e1d
parent8581d940c9d89088455ac601c9bf0d11e5b457e9 (diff)
downloadorg.eclipse.mylyn.tasks-66369afb5c49a63829059cb2ec1d9663f2159833.tar.gz
org.eclipse.mylyn.tasks-66369afb5c49a63829059cb2ec1d9663f2159833.tar.xz
org.eclipse.mylyn.tasks-66369afb5c49a63829059cb2ec1d9663f2159833.zip
Bug 444312 - handle updating and validating repositories that don't
require credentials in AbstractRepositorySettingsPage Change-Id: Id15ef5d52bc450463f14d840e292bc6d95030277 Signed-off-by: Doug Janzen <doug.janzen@tasktop.com> Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=444312
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/tasks/ui/wizards/RepositorySettingsPageTest.java65
-rw-r--r--org.eclipse.mylyn.tasks.ui/src/org/eclipse/mylyn/tasks/ui/wizards/AbstractRepositorySettingsPage.java32
2 files changed, 81 insertions, 16 deletions
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 96281a19c..379bdf913 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
@@ -11,11 +11,15 @@
package org.eclipse.mylyn.tasks.ui.wizards;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import org.eclipse.core.runtime.CoreException;
+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.mylyn.tasks.core.TaskRepository;
@@ -28,15 +32,21 @@ public class RepositorySettingsPageTest {
public static class TestRepositorySettingsPage extends AbstractRepositorySettingsPage {
- public TestRepositorySettingsPage() {
- super("Title", "Description", new TaskRepository("mock", "url"), MockRepositoryConnector.getDefault());
+ public TestRepositorySettingsPage(TaskRepository taskRepository) {
+ super("Title", "Description", taskRepository, MockRepositoryConnector.getDefault());
setNeedsProxy(true);
}
@Override
protected Validator getValidator(TaskRepository repository) {
- // ignore
- return null;
+ Validator validator = new Validator() {
+
+ @Override
+ public void run(IProgressMonitor monitor) throws CoreException {
+ }
+ };
+ validator.setStatus(Status.OK_STATUS);
+ return validator;
}
@Override
@@ -50,15 +60,50 @@ public class RepositorySettingsPageTest {
}
}
+ public static class RepositorySettingsPageWithNoCredentials extends TestRepositorySettingsPage {
+
+ public RepositorySettingsPageWithNoCredentials(TaskRepository taskRepository) {
+ super(taskRepository);
+ setNeedsRepositoryCredentials(false);
+ }
+ }
+
@Test
public void proxyPortTriggersValidation() throws Exception {
- TestRepositorySettingsPage page = new TestRepositorySettingsPage();
+ TestRepositorySettingsPage page = new TestRepositorySettingsPage(createTaskRepository());
IWizardContainer container = applyWizardContainer(page);
page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
- verify(container, times(1)).updateButtons();
+ verify(container, times(2)).updateButtons();
page.proxyPortEditor.setStringValue("123");
- verify(container, times(2)).updateButtons();
+ verify(container, times(3)).updateButtons();
+ }
+
+ @Test
+ public void validatesWithNoCredentials() throws Exception {
+ TestRepositorySettingsPage page = new RepositorySettingsPageWithNoCredentials(createTaskRepository());
+ applyWizardContainer(page);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ page.validateSettings();
+ }
+
+ @Test
+ public void labelAndUrlUpdatedWhenNoCredentials() throws Exception {
+ TaskRepository repository = createTaskRepository();
+ TestRepositorySettingsPage page = new RepositorySettingsPageWithNoCredentials(repository);
+ applyWizardContainer(page);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ assertEquals(repository.getRepositoryUrl(), page.getRepositoryUrl());
+ assertEquals(repository.getRepositoryLabel(), page.getRepositoryLabel());
+ }
+
+ @Test
+ public void labelAndUrlNotUpdatedWhenNoTaskRepository() throws Exception {
+ TestRepositorySettingsPage page = new RepositorySettingsPageWithNoCredentials(null);
+ applyWizardContainer(page);
+ page.createControl(PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell());
+ assertEquals("", page.getRepositoryUrl());
+ assertEquals("", page.getRepositoryLabel());
}
private IWizardContainer applyWizardContainer(TestRepositorySettingsPage page) {
@@ -68,4 +113,10 @@ public class RepositorySettingsPageTest {
page.setWizard(wizard);
return container;
}
+
+ private TaskRepository createTaskRepository() {
+ TaskRepository repository = new TaskRepository("mock", "url");
+ repository.setRepositoryLabel("label");
+ return repository;
+ }
}
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 862a17079..4eb85239f 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
@@ -561,6 +561,8 @@ IAdaptable {
updateHyperlinks();
if (repository != null) {
+ updateLabel();
+ updateUrl();
saveToValidatedProperties(createTaskRepository());
}
GridLayout layout = new GridLayout(3, false);
@@ -647,13 +649,6 @@ IAdaptable {
if (repository != null) {
try {
- String repositoryLabel = repository.getProperty(IRepositoryConstants.PROPERTY_LABEL);
- if (repositoryLabel != null && repositoryLabel.length() > 0) {
- // repositoryLabelCombo.add(repositoryLabel);
- // repositoryLabelCombo.select(0);
- repositoryLabelEditor.setStringValue(repositoryLabel);
- }
- serverUrlCombo.setText(repository.getRepositoryUrl());
AuthenticationCredentials credentials = repository.getCredentials(AuthenticationType.REPOSITORY);
if (credentials != null) {
repositoryUserNameEditor.setStringValue(credentials.getUserName());
@@ -682,6 +677,17 @@ IAdaptable {
RepositoryUiUtil.testCredentialsStore(getRepositoryUrl(), this);
}
+ private void updateLabel() {
+ String repositoryLabel = repository.getProperty(IRepositoryConstants.PROPERTY_LABEL);
+ if (repositoryLabel != null && repositoryLabel.length() > 0) {
+ repositoryLabelEditor.setStringValue(repositoryLabel);
+ }
+ }
+
+ private void updateUrl() {
+ serverUrlCombo.setText(repository.getRepositoryUrl());
+ }
+
private void createAdvancedSection() {
ExpandableComposite section = createSection(innerComposite,
Messages.AbstractRepositorySettingsPage_Additional_Settings);
@@ -1443,14 +1449,22 @@ IAdaptable {
* @since 2.0
*/
public String getUserName() {
- return repositoryUserNameEditor.getStringValue();
+ if (needsRepositoryCredentials()) {
+ return repositoryUserNameEditor.getStringValue();
+ } else {
+ return ""; //$NON-NLS-1$
+ }
}
/**
* @since 2.0
*/
public String getPassword() {
- return repositoryPasswordEditor.getStringValue();
+ if (needsRepositoryCredentials()) {
+ return repositoryPasswordEditor.getStringValue();
+ } else {
+ return ""; //$NON-NLS-1$
+ }
}
/**

Back to the top