<commit_before>/*******************************************************************************
 * Copyright (c) 2009 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.tests.ui.discovery;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.mylyn.tests.ui.util.CompoundCondition;
import org.eclipse.mylyn.tests.ui.util.HasId;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.ui.PlatformUI;
import org.hamcrest.Matcher;
import org.junit.Test;

/**
 * tests that drive the Connector Discovery UI
 * 
 * @author <NAME>
 */
public class DiscoverySystemTest extends SWTBotTestCase {

	private static final String KEY_CONNECTOR_ID = "connectorId";

	private static SWTWorkbenchBot bot = new SWTWorkbenchBot();

	@Override
	public void setUp() throws Exception {
		try {
			bot.viewByTitle("Welcome").close();
		} catch (WidgetNotFoundException e) {
			// ignore
		}
	}

	@Override
	public void tearDown() {
		Shell mainShell = UIThreadRunnable.syncExec(new Result<Shell>() {
			public Shell run() {
				return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
			}
		});
		SWTBotShell[] shells = bot.shells();
		for (SWTBotShell shell : shells) {
			if (shell.widget != mainShell) {
				shell.close();
			}
		}
	}

	@Test
	public void testSelectOneConnectorAndActivateP2Installer() {
		activateDiscoveryUi();
		bot.checkBoxWithId(KEY_CONNECTOR_ID, "org.eclipse.mylyn.trac_feature").click();

		bot.button("&Finish").click();

		// P2 takes over here.  Just verify that the P2 installer is activated and that the selected connector is
		// visible and checked.
		SWTBotShell shell = bot.shell("Install");
		shell.activate();

		final SWTBotTable table = bot.table();
		int rowCount = table.rowCount();
		assertTrue(rowCount > 0);
		int tracRow = -1;
		for (int x = 0; x < rowCount; ++x) {
			String cellData = table.cell(x, 0);
			if (cellData.indexOf("Trac") != -1) {
				tracRow = x;
				break;
			}
		}
		assertTrue("Trac wasn't in the p2 ui", tracRow >= 0);

		bot.button("Cancel").click();
	}

	@Test
	public void testAllConnectorsEnabled() {
		activateDiscoveryUi();<commit_msg>NEW - bug 278319: tests for Discovery https://bugs.eclipse.org/bugs/show_bug.cgi?id=278319<commit_after>/*******************************************************************************
 * Copyright (c) 2009 <NAME> 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.tests.ui.discovery;

import java.util.ArrayList;
import java.util.List;

import org.eclipse.mylyn.tests.ui.util.CompoundCondition;
import org.eclipse.mylyn.tests.ui.util.HasId;
import org.eclipse.swt.SWT;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Widget;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.swt.finder.SWTBotTestCase;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.finders.UIThreadRunnable;
import org.eclipse.swtbot.swt.finder.results.Result;
import org.eclipse.swtbot.swt.finder.waits.Conditions;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotCheckBox;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotShell;
import org.eclipse.swtbot.swt.finder.widgets.SWTBotTable;
import org.eclipse.ui.PlatformUI;
import org.hamcrest.Matcher;
import org.junit.Test;

/**
 * tests that drive the Connector Discovery UI
 * 
 * @author <NAME>
 */
public class DiscoverySystemTest extends SWTBotTestCase {

	private static final String KEY_CONNECTOR_ID = "connectorId";

	private static SWTWorkbenchBot bot = new SWTWorkbenchBot();

	@Override
	public void setUp() throws Exception {
		try {
			bot.viewByTitle("Welcome").close();
		} catch (WidgetNotFoundException e) {
			// ignore
		}
		Shell mainShell = UIThreadRunnable.syncExec(new Result<Shell>() {
			public Shell run() {
				return PlatformUI.getWorkbench().getActiveWorkbenchWindow().getShell();
			}
		});
		SWTBotShell[] shells = bot.shells();
		for (SWTBotShell shell : shells) {
			if (shell.widget != mainShell) {
				shell.close();
			}
		}
	}

	@Override
	public void tearDown() {
	}

	@Test
	public void testSelectOneConnectorAndActivateP2Installer() {
		activateDiscoveryUi();
		bot.checkBoxWithId(KEY_CONNECTOR_ID, "org.eclipse.mylyn.trac_feature").click();

		bot.button("&Finish").click();

		// P2 takes over here.  Just verify that the P2 installer is activated and that the selected connector is
		// visible and checked.
		bot.waitUntil(Conditions.shellIsActive("Install"), 30000L);

		final SWTBotTable table = bot.table();
		int rowCount = table.rowCount();
		assertTrue(rowCount > 0);
		int tracRow = -1;
		for (int x = 0; x < rowCount; ++x) {
			String cellData = table.cell(x, 0);
			if (cellData.indexOf("Trac") != -1) {
				tracRow = x;
				break;
			}
		}
		assertTrue("Trac wasn't in the p2 ui", tracRow >= 0);

		bot.button("Cancel").click();
	}

	@Test
	public void testAllConnectorsEnabled() {
		activateDiscoveryUi();
{'fraction_non_alphanumeric': 0.16419772337439575, 'fraction_numerical': 0.008264462809917356, 'mean_word_length': 4.626315789473685, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 12, 'https://': 1, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, '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': '3321158', 'n_tokens_mistral': 2208, 'n_tokens_neox': 1979, 'n_words': 452}