<commit_before>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
/*
 * Created on Dec 21, 2004
 */
package org.eclipse.mylar.tasklist.tests;

import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import junit.framework.TestCase;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryQuery;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
import org.eclipse.mylar.internal.tasklist.AbstractRepositoryQuery;
import org.eclipse.mylar.internal.tasklist.AbstractRepositoryTask;
import org.eclipse.mylar.internal.tasklist.ITask;
import org.eclipse.mylar.internal.tasklist.ITaskContainer;
import org.eclipse.mylar.internal.tasklist.ITaskListElement;
import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin;
import org.eclipse.mylar.internal.tasklist.ScheduledTaskListRefreshJob;
import org.eclipse.mylar.internal.tasklist.Task;
import org.eclipse.mylar.internal.tasklist.TaskCategory;
import org.eclipse.mylar.internal.tasklist.TaskList;
import org.eclipse.mylar.internal.tasklist.TaskListManager;
import org.eclipse.mylar.internal.tasklist.TaskRepository;
import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager;

/**
 * @author <NAME>
 */
public class TaskListManagerTest extends TestCase {

	private TaskListManager manager;

	private TaskRepository repository;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		manager = MylarTaskListPlugin.getTaskListManager();
		manager.createNewTaskList();

		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
				new URL(IBugzillaConstants.ECLIPSE_BUGZILLA_URL));
		MylarTaskListPlugin.getRepositoryManager().addRepository(repository);
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
		manager.createNewTaskList();
		MylarTaskListPlugin.getDefault().getTaskListSaveManager().saveTaskListAndContexts();
		MylarTaskListPlugin.getRepositoryManager().removeRepository(repository);
	}

	public void testLegacyTaskListReading() {
		File originalFile = manager.getTaskListFile();
		File legacyListFile = TaskTestUtil.getLocalFile("testdata/legacy/tasklist_0_4_8.xml");
		
		assertEquals(362445, legacyListFile.length());
		assertTrue(legacyListFile.exists());
		 
		manager.setTaskListFile(legacyListFile);
		manager.readExistingOrCreateNewList();
		manager.setTaskListFile(originalFile);
		
		Set<ITask> allTasks = manager.getTaskList().getAllTasks();
		Set<ITask> allRootTasks = manager.getTaskList().getRootTasks();
		Set<ITaskContainer> allCategories = manager.getTaskList().getCategories();
		Set<ITaskListElement> allRoots = manager.getTaskList().getRootElements();

		System.err.println(">>> " + allRootTasks.size()); 
		assertEquals(0, allRootTasks.size());
		
		manager.saveTaskList();<commit_msg>Progress on: Bug 126775: >fix task archive and category duplication https://bugs.eclipse.org/bugs/show_bug.cgi?id=126775<commit_after>/*******************************************************************************
 * Copyright (c) 2004 - 2006 University Of British Columbia 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:
 *     University Of British Columbia - initial API and implementation
 *******************************************************************************/
/*
 * Created on Dec 21, 2004
 */
package org.eclipse.mylar.tasklist.tests;

import java.io.File;
import java.net.URL;
import java.util.HashSet;
import java.util.Iterator;
import java.util.Set;

import junit.framework.TestCase;

import org.eclipse.core.runtime.NullProgressMonitor;
import org.eclipse.mylar.internal.bugzilla.core.BugzillaPlugin;
import org.eclipse.mylar.internal.bugzilla.core.IBugzillaConstants;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaRepositoryQuery;
import org.eclipse.mylar.internal.bugzilla.ui.tasklist.BugzillaTask;
import org.eclipse.mylar.internal.tasklist.AbstractRepositoryQuery;
import org.eclipse.mylar.internal.tasklist.AbstractRepositoryTask;
import org.eclipse.mylar.internal.tasklist.ITask;
import org.eclipse.mylar.internal.tasklist.ITaskContainer;
import org.eclipse.mylar.internal.tasklist.ITaskListElement;
import org.eclipse.mylar.internal.tasklist.MylarTaskListPlugin;
import org.eclipse.mylar.internal.tasklist.ScheduledTaskListRefreshJob;
import org.eclipse.mylar.internal.tasklist.Task;
import org.eclipse.mylar.internal.tasklist.TaskCategory;
import org.eclipse.mylar.internal.tasklist.TaskList;
import org.eclipse.mylar.internal.tasklist.TaskListManager;
import org.eclipse.mylar.internal.tasklist.TaskRepository;
import org.eclipse.mylar.internal.tasklist.TaskRepositoryManager;

/**
 * @author <NAME>
 */
public class TaskListManagerTest extends TestCase {

	private TaskListManager manager;

	private TaskRepository repository;

	@Override
	protected void setUp() throws Exception {
		super.setUp();
		manager = MylarTaskListPlugin.getTaskListManager();
		manager.createNewTaskList();

		repository = new TaskRepository(BugzillaPlugin.REPOSITORY_KIND,
				new URL(IBugzillaConstants.ECLIPSE_BUGZILLA_URL));
		MylarTaskListPlugin.getRepositoryManager().addRepository(repository);
	}

	@Override
	protected void tearDown() throws Exception {
		super.tearDown();
		manager.createNewTaskList();
		MylarTaskListPlugin.getDefault().getTaskListSaveManager().saveTaskListAndContexts();
		MylarTaskListPlugin.getRepositoryManager().removeRepository(repository);
	}

	public void testLegacyTaskListReading() {
		File previousFile = manager.getTaskListFile();
		File legacyListFile = TaskTestUtil.getLocalFile("testdata/legacy/tasklist_0_4_8.xml");
		
		assertEquals(362445, legacyListFile.length());
		assertTrue(legacyListFile.exists());
		 
		manager.setTaskListFile(legacyListFile);
		manager.readExistingOrCreateNewList();
		manager.setTaskListFile(previousFile);
		
		Set<ITask> allTasks = manager.getTaskList().getAllTasks();
		Set<ITask> allRootTasks = manager.getTaskList().getRootTasks();
		Set<ITaskContainer> allCategories = manager.getTaskList().getCategories();
		Set<ITaskListElement> allRoots = manager.getTaskList().getRootElements();

		System.err.println(">>> " + allRootTasks.size()); 
		assertEquals(0, allRootTasks.size());
		
		manager.saveTaskList();
{'fraction_non_alphanumeric': 0.14540638505506762, 'fraction_numerical': 0.009479994423532692, 'mean_word_length': 6.395876288659794, 'pattern_counts': {'":': 0, '<': 13, '<?xml version=': 0, '>': 20, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4560191', 'n_tokens_mistral': 2203, 'n_tokens_neox': 2057, 'n_words': 361}