Skip to main content
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSam Davis2016-08-15 19:30:10 -0400
committerSam Davis2016-08-30 17:21:44 -0400
commitb4c722e53591c523bb4ca240b0aa87c5a153804c (patch)
tree58f5a0af964b3b11405de7586cebb475b67e97a7 /org.eclipse.mylyn.tasks.ui.tests
parent5e84bcb5f7dadf1fc737b6d861686b7e22d7eddd (diff)
downloadorg.eclipse.mylyn.tasks-b4c722e53591c523bb4ca240b0aa87c5a153804c.tar.gz
org.eclipse.mylyn.tasks-b4c722e53591c523bb4ca240b0aa87c5a153804c.tar.xz
org.eclipse.mylyn.tasks-b4c722e53591c523bb4ca240b0aa87c5a153804c.zip
498906: connector migration can migrate queries
Change-Id: I0459a07552ab6fdc9b5d9b19e707d3d8c19699da Task-Url: https://bugs.eclipse.org/bugs/show_bug.cgi?id=498906
Diffstat (limited to 'org.eclipse.mylyn.tasks.ui.tests')
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/CompleteConnectorMigrationWizardTest.java67
-rw-r--r--org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/ConnectorMigratorTest.java96
2 files changed, 141 insertions, 22 deletions
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/CompleteConnectorMigrationWizardTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/CompleteConnectorMigrationWizardTest.java
index 580224e31..9729a3b70 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/CompleteConnectorMigrationWizardTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/CompleteConnectorMigrationWizardTest.java
@@ -11,6 +11,7 @@ package org.eclipse.mylyn.internal.tasks.ui.migrator;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.Matchers.any;
import static org.mockito.Mockito.doNothing;
@@ -60,15 +61,23 @@ public class CompleteConnectorMigrationWizardTest {
private ConnectorMigrationUi migrationUi;
+ private DefaultTasksState tasksState;
+
@SuppressWarnings("unchecked")
@Before
public void setUp() {
- DefaultTasksState tasksState = new DefaultTasksState();
+ tasksState = new DefaultTasksState();
migrationUi = spy(new ConnectorMigrationUi(TaskListView.getFromActivePerspective(),
TasksUiPlugin.getBackupManager(), tasksState));
- doNothing().when(migrationUi).warnOfValidationFailure((List<TaskRepository>) any(List.class));
+ doNothing().when(migrationUi).warnOfValidationFailure(any(List.class));
doNothing().when(migrationUi).notifyMigrationComplete();
- migrator = spy(new ConnectorMigrator(ImmutableMap.of("mock", "mock.new"), "", tasksState, migrationUi));
+ migrator = createMigrator(ImmutableMap.of("mock", "mock.new"));
+ }
+
+ private ConnectorMigrator createMigrator(ImmutableMap<String, String> kinds) {
+ ConnectorMigrator migrator = spy(new ConnectorMigrator(kinds, "", tasksState, migrationUi));
+ when(migrator.allQueriesMigrated()).thenReturn(false);
+ return migrator;
}
@After
@@ -100,11 +109,39 @@ public class CompleteConnectorMigrationWizardTest {
assertTrue(control.getChildren()[3] instanceof Tree);
}
+ @Test
+ public void firstPageSomeQueriesMigrated() {
+ when(migrator.anyQueriesMigrated()).thenReturn(true);
+ IWizardContainer container = createWizard(new CompleteConnectorMigrationWizard(migrator));
+ IWizardPage firstPage = container.getCurrentPage();
+ assertEquals("Have You Recreated Your Queries?", firstPage.getTitle());
+ assertEquals(
+ "Migration will remove your old queries. Some queries could not be automatically migrated. "
+ + "Please review your old and new queries and edit or create new ones as needed. "
+ + "Your old and new queries are shown below and you can edit them by double-clicking.",
+ firstPage.getMessage());
+ assertTrue(firstPage.getControl() instanceof Composite);
+ Composite control = (Composite) firstPage.getControl();
+ assertEquals(4, control.getChildren().length);
+ assertTrue(control.getChildren()[0] instanceof Label);
+ assertTrue(control.getChildren()[1] instanceof Label);
+ assertTrue(control.getChildren()[2] instanceof Tree);
+ assertTrue(control.getChildren()[3] instanceof Tree);
+ }
+
+ @Test
+ public void firstPageAllQueriesMigrated() {
+ when(migrator.allQueriesMigrated()).thenReturn(true);
+ IWizardContainer container = createWizard(new CompleteConnectorMigrationWizard(migrator));
+ IWizardPage firstPage = container.getCurrentPage();
+ assertEquals("Complete Migration", firstPage.getTitle());
+ assertNull(firstPage.getNextPage());
+ }
+
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void queryTreeShowsOnlySelectedConnectors() {
- migrator = new ConnectorMigrator(ImmutableMap.of("mock", "mock.new", "kind", "kind.new"), "",
- new DefaultTasksState(), migrationUi);
+ migrator = createMigrator(ImmutableMap.of("mock", "mock.new", "kind", "kind.new"));
migrator.setConnectorsToMigrate(ImmutableList.of("kind"));
createWizard(new CompleteConnectorMigrationWizard(migrator));
ArgumentCaptor<Collection> captor = ArgumentCaptor.forClass(Collection.class);
@@ -112,8 +149,7 @@ public class CompleteConnectorMigrationWizardTest {
assertEquals(ImmutableSet.of("kind"), ImmutableSet.copyOf(captor.getAllValues().get(0)));
assertEquals(ImmutableSet.of("kind.new"), ImmutableSet.copyOf(captor.getAllValues().get(1)));
- migrator = new ConnectorMigrator(ImmutableMap.of("mock", "mock.new", "kind", "kind.new"), "",
- new DefaultTasksState(), migrationUi);
+ migrator = createMigrator(ImmutableMap.of("mock", "mock.new", "kind", "kind.new"));
migrator.setConnectorsToMigrate(ImmutableList.of("mock", "kind"));
createWizard(new CompleteConnectorMigrationWizard(migrator));
captor = ArgumentCaptor.forClass(Collection.class);
@@ -137,10 +173,11 @@ public class CompleteConnectorMigrationWizardTest {
String text = ((Text) control.getChildren()[0]).getText();
assertTrue(text.contains("When you click finish, your context, scheduled dates, private notes and other data "
+ "will be migrated to the new connectors. Any tasks in your task list that are not included in the new "
- + "queries you created will be downloaded using the new connectors. The old tasks, "
+ + "queries will be downloaded using the new connectors. The old tasks, "
+ "queries, and repositories will be deleted."));
- assertTrue(text.contains("This may take a while. You should not use the task list or task editor while this is happening. "
- + "You will be prompted when migration is complete."));
+ assertTrue(text.contains(
+ "This may take a while. You should not use the task list or task editor while this is happening. "
+ + "You will be prompted when migration is complete."));
assertTrue(text.contains("You will be able to "
+ "undo the migration by selecting \"Restore Tasks from History\" in the Task List view menu and choosing the "
+ "connector-migration-*.zip file stored in <workspace>/.metadata/.mylyn/backup. This will restore your task "
@@ -196,7 +233,7 @@ public class CompleteConnectorMigrationWizardTest {
RepositoryQuery query4 = createQuery(repository2);
Map<TaskRepository, Set<RepositoryQuery>> map = //
- new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
+ new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
assertEquals(repositories, map.keySet());
assertEquals(ImmutableSet.of(query1, query2), map.get(repository1));
assertEquals(ImmutableSet.of(query3, query4), map.get(repository2));
@@ -209,7 +246,7 @@ public class CompleteConnectorMigrationWizardTest {
RepositoryQuery query = createQuery(repository);
Map<TaskRepository, Set<RepositoryQuery>> map = //
- new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
+ new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
assertEquals(ImmutableSet.of(repository), map.keySet());
assertEquals(ImmutableSet.of(query), map.get(repository));
}
@@ -222,7 +259,7 @@ public class CompleteConnectorMigrationWizardTest {
RepositoryQuery migratedQuery = createQuery(migratedRepository);
Map<TaskRepository, Set<RepositoryQuery>> map = //
- new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
+ new CompleteConnectorMigrationWizard(migrator).createRepositoryQueryMap(ImmutableList.of("mock"));
assertEquals(ImmutableSet.of(repository), map.keySet());
assertEquals(ImmutableSet.of(query), map.get(repository));
@@ -238,8 +275,8 @@ public class CompleteConnectorMigrationWizardTest {
}
protected RepositoryQuery createQuery(TaskRepository repository) {
- RepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(), repository.getConnectorKind()
- + repository.getRepositoryUrl() + Math.random());
+ RepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(),
+ repository.getConnectorKind() + repository.getRepositoryUrl() + Math.random());
query.setRepositoryUrl(repository.getRepositoryUrl());
TasksUiPlugin.getTaskList().addQuery(query);
return query;
diff --git a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/ConnectorMigratorTest.java b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/ConnectorMigratorTest.java
index a49c07034..ea4052458 100644
--- a/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/ConnectorMigratorTest.java
+++ b/org.eclipse.mylyn.tasks.ui.tests/src/org/eclipse/mylyn/internal/tasks/ui/migrator/ConnectorMigratorTest.java
@@ -22,6 +22,7 @@ import static org.mockito.Matchers.any;
import static org.mockito.Matchers.argThat;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.doNothing;
+import static org.mockito.Mockito.doReturn;
import static org.mockito.Mockito.inOrder;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
@@ -167,7 +168,7 @@ public class ConnectorMigratorTest {
@SuppressWarnings("unchecked")
@Before
public void setUp() {
- doNothing().when(migrationUi).warnOfValidationFailure((List<TaskRepository>) any(List.class));
+ doNothing().when(migrationUi).warnOfValidationFailure(any(List.class));
doNothing().when(migrationUi).notifyMigrationComplete();
}
@@ -393,8 +394,8 @@ public class ConnectorMigratorTest {
ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
TaskData taskData2 = new TaskData(mock(TaskAttributeMapper.class), "mock.new", repository.getRepositoryUrl(),
"2.migrated");
- when(migrator.getTaskData(eq("key2"), eq(newConnector), any(TaskRepository.class), any(IProgressMonitor.class)))
- .thenReturn(taskData2);
+ doReturn(taskData2).when(migrator).getTaskData(eq("key2"), eq(newConnector), any(TaskRepository.class),
+ any(IProgressMonitor.class));
ITask task1 = new TaskTask("mock", "http://mock", "1");
task1.setTaskKey("key1");
((AbstractTask) task1).setSynchronizationState(SynchronizationState.INCOMING_NEW);
@@ -450,12 +451,12 @@ public class ConnectorMigratorTest {
ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
TaskData taskData1 = new TaskData(mock(TaskAttributeMapper.class), "mock.new", repository.getRepositoryUrl(),
"1");
- when(migrator.getTaskData(eq("key1"), eq(newConnector), any(TaskRepository.class), any(IProgressMonitor.class)))
- .thenReturn(taskData1);
+ doReturn(taskData1).when(migrator).getTaskData(eq("key1"), eq(newConnector), any(TaskRepository.class),
+ any(IProgressMonitor.class));
TaskData taskData2 = new TaskData(mock(TaskAttributeMapper.class), "mock.new", repository.getRepositoryUrl(),
"2");
- when(migrator.getTaskData(eq("key2"), eq(newConnector), any(TaskRepository.class), any(IProgressMonitor.class)))
- .thenReturn(taskData2);
+ doReturn(taskData2).when(migrator).getTaskData(eq("key2"), eq(newConnector), any(TaskRepository.class),
+ any(IProgressMonitor.class));
ITask task1 = new TaskTask("mock", "http://mock", "1");
task1.setTaskKey("key1");
((AbstractTask) task1).setSynchronizationState(SynchronizationState.INCOMING_NEW);
@@ -569,6 +570,87 @@ public class ConnectorMigratorTest {
assertEquals(expected, migrator.getCategories());
}
+ @Test
+ public void migrateNoQueries() {
+ ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
+ RepositoryQuery q1 = createQuery("q1", repository, migrator, false);
+ RepositoryQuery q2 = createQuery("q2", repository, migrator, false);
+
+ migrator.migrateQueries(repository, migratedRepository, new NullProgressMonitor());
+ assertFalse(migrator.anyQueriesMigrated());
+ assertFalse(migrator.allQueriesMigrated());
+ }
+
+ @Test
+ public void migrateSomeQueries() {
+ ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
+ RepositoryQuery q1 = createQuery("q1", repository, migrator, true);
+ RepositoryQuery q2 = createQuery("q2", repository, migrator, false);
+
+ assertFalse(migrator.anyQueriesMigrated());
+ assertTrue(migrator.allQueriesMigrated());
+
+ migrator.migrateQueries(repository, migratedRepository, new NullProgressMonitor());
+ assertTrue(migrator.anyQueriesMigrated());
+ assertFalse(migrator.allQueriesMigrated());
+ }
+
+ @Test
+ public void migrateAllQueries() {
+ ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
+ RepositoryQuery q1 = createQuery("q1", repository, migrator, true);
+ RepositoryQuery q2 = createQuery("q2", repository, migrator, true);
+
+ migrator.migrateQueries(repository, migratedRepository, new NullProgressMonitor());
+ assertTrue(migrator.anyQueriesMigrated());
+ assertTrue(migrator.allQueriesMigrated());
+ }
+
+ @Test
+ public void migrateSomeQueriesMultipleRepositories() {
+ TaskRepository otherRepository = new TaskRepository("mock", "http://other-mock");
+ ConnectorMigrator migrator = spy(
+ createMigrator(true, true, kinds, ImmutableSet.of(repository, otherRepository), false));
+ RepositoryQuery q1 = createQuery("q1", repository, migrator, true);
+ RepositoryQuery q2 = createQuery("q2", repository, migrator, true);
+ RepositoryQuery q3 = createQuery("q3", otherRepository, migrator, false);
+ RepositoryQuery q4 = createQuery("q4", otherRepository, migrator, false);
+
+ migrator.migrateQueries(repository, migratedRepository, new NullProgressMonitor());
+ migrator.migrateQueries(otherRepository, migratedRepository, new NullProgressMonitor());
+ assertTrue(migrator.anyQueriesMigrated());
+ assertFalse(migrator.allQueriesMigrated());
+ }
+
+ @Test
+ public void migrateAllQueriesMultipleRepositories() {
+ TaskRepository otherRepository = new TaskRepository("mock", "http://other-mock");
+ ConnectorMigrator migrator = spy(createMigrator(true, true, kinds, ImmutableSet.of(repository), false));
+ RepositoryQuery q1 = createQuery("q1", repository, migrator, true);
+ RepositoryQuery q2 = createQuery("q2", repository, migrator, true);
+ RepositoryQuery q3 = createQuery("q3", otherRepository, migrator, true);
+ RepositoryQuery q4 = createQuery("q4", otherRepository, migrator, true);
+
+ migrator.migrateQueries(repository, migratedRepository, new NullProgressMonitor());
+ migrator.migrateQueries(otherRepository, migratedRepository, new NullProgressMonitor());
+ assertTrue(migrator.anyQueriesMigrated());
+ assertTrue(migrator.allQueriesMigrated());
+ }
+
+ private RepositoryQuery createQuery(String handle, TaskRepository repository, ConnectorMigrator migrator,
+ boolean shouldMigrate) {
+ RepositoryQuery query = new RepositoryQuery(repository.getConnectorKind(), handle);
+ query.setRepositoryUrl(repository.getRepositoryUrl());
+ tasksState.getTaskList().addQuery(query);
+ if (shouldMigrate) {
+ RepositoryQuery migratedQuery = new RepositoryQuery(repository.getConnectorKind(), handle + ".migrated");
+ migratedQuery.setRepositoryUrl(repository.getRepositoryUrl() + "/migrated");
+ when(migrator.migrateQuery(eq(query), any(TaskRepository.class), any(TaskRepository.class),
+ any(IProgressMonitor.class))).thenReturn(migratedQuery);
+ }
+ return query;
+ }
+
private AbstractTaskCategory getCategory(AbstractTask newTask) {
for (AbstractTaskCategory category : tasksState.getTaskList().getCategories()) {
Optional<ITask> task = Iterables.tryFind(category.getChildren(), Predicates.<ITask> equalTo(newTask));

Back to the top