<commit_before>/*******************************************************************************
 * Copyright (c) 2015 UT-Battelle, LLC.
 * 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:
 *   <NAME> - Initial API and implementation and/or initial documentation 
 *   
 *******************************************************************************/
package org.eclipse.ice.client.widgets.test.utils;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.ice.client.widgets.ICEFormEditor;
import org.eclipse.ice.client.widgets.ICEFormInput;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.resource.ICEResource;
import org.eclipse.ice.datastructures.resource.VizResource;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.MultiPartInitException;
import org.eclipse.ui.PlatformUI;
import org.junit.BeforeClass;

/**
 * This abstract class provides a basic framework for performing SWTBot tests
 * for Eclipse UI plug-ins inside a JUnit test framework. As such, test classes
 * sub-classing this abstract class can be run as JUnit plug-in tests <b>(off
 * the UI thread)</b> or SWTBot tests, but <i>not plain JUnit tests</i>, as the
 * workbench is required.
 * <p>
 * This class provides helpful methods to help navigate the ICE workbench and
 * open editors, views, or perspectives for testing.
 * </p>
 * <p>
 * An {@link SWTWorkbenchBot} is opened for each test class instance and should
 * be used for the actual UI tests. The bot can be acquired via
 * {@link #getBot()}.
 * </p>
 * <p>
 * <b>Note:</b> Changes to the UI must be coordinated with the main UI thread
 * using {@link Display#syncExec(Runnable)} or
 * {@link Display#asyncExec(Runnable)}. To get the shell's display, you may call
 * {@link #getDisplay()}.
 * </p>
 * 
 * @author <NAME>
 *
 */
public abstract class AbstractWorkbenchTester extends
		AbstractICEUITester<SWTWorkbenchBot> {

	/**
	 * The {@code SWTBot} for this test class instance. This bot is to aid in
	 * performing UI tests that simulate user interaction with workbench-based
	 * plug-ins.
	 */
	private static SWTWorkbenchBot bot;

	/**
	 * Tries to close the "Welcome" view if it is open. This only needs to be
	 * done once, and nothing needs to be disposed afterward.
	 */
	@BeforeClass
	public static void beforeWorkbenchClass() {

		// Close the welcome view using a temporary SWTBot.
		SWTWorkbenchBot bot = new SWTWorkbenchBot();
		try {
			bot.viewByTitle("Welcome").close();
		} catch (WidgetNotFoundException e) {
			// Nothing to do.
		}

		return;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ice.client.widgets.test.AbstractUITester#getBot()
	 */
	@Override
	protected SWTWorkbenchBot getBot() {
		return bot;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ice.client.widgets.test.AbstractUITester#beforeAllTests()
	 */
	@Override
	public void beforeAllTests() {
		super.beforeAllTests();

		// Initialize static or otherwise shared resources here.

		// Set up the SWTBot for the workbench.
		bot = new SWTWorkbenchBot();
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ice.client.widgets.test.AbstractUITester#beforeEachTest()<commit_msg>Increased AbstractWorkbenchTester timeout<commit_after>/*******************************************************************************
 * Copyright (c) 2015 UT-Battelle, LLC.
 * 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:
 *   <NAME> - Initial API and implementation and/or initial documentation 
 *   
 *******************************************************************************/
package org.eclipse.ice.client.widgets.test.utils;

import java.io.File;
import java.io.IOException;
import java.util.concurrent.atomic.AtomicReference;

import org.eclipse.ice.client.widgets.ICEFormEditor;
import org.eclipse.ice.client.widgets.ICEFormInput;
import org.eclipse.ice.datastructures.form.Form;
import org.eclipse.ice.datastructures.resource.ICEResource;
import org.eclipse.ice.datastructures.resource.VizResource;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
import org.eclipse.swtbot.swt.finder.exceptions.WidgetNotFoundException;
import org.eclipse.swtbot.swt.finder.utils.SWTBotPreferences;
import org.eclipse.ui.IEditorInput;
import org.eclipse.ui.IEditorReference;
import org.eclipse.ui.IWorkbenchPage;
import org.eclipse.ui.IWorkbenchWindow;
import org.eclipse.ui.MultiPartInitException;
import org.eclipse.ui.PlatformUI;
import org.junit.BeforeClass;

/**
 * This abstract class provides a basic framework for performing SWTBot tests
 * for Eclipse UI plug-ins inside a JUnit test framework. As such, test classes
 * sub-classing this abstract class can be run as JUnit plug-in tests <b>(off
 * the UI thread)</b> or SWTBot tests, but <i>not plain JUnit tests</i>, as the
 * workbench is required.
 * <p>
 * This class provides helpful methods to help navigate the ICE workbench and
 * open editors, views, or perspectives for testing.
 * </p>
 * <p>
 * An {@link SWTWorkbenchBot} is opened for each test class instance and should
 * be used for the actual UI tests. The bot can be acquired via
 * {@link #getBot()}.
 * </p>
 * <p>
 * <b>Note:</b> Changes to the UI must be coordinated with the main UI thread
 * using {@link Display#syncExec(Runnable)} or
 * {@link Display#asyncExec(Runnable)}. To get the shell's display, you may call
 * {@link #getDisplay()}.
 * </p>
 * 
 * @author <NAME>
 *
 */
public abstract class AbstractWorkbenchTester extends
		AbstractICEUITester<SWTWorkbenchBot> {

	/**
	 * The {@code SWTBot} for this test class instance. This bot is to aid in
	 * performing UI tests that simulate user interaction with workbench-based
	 * plug-ins.
	 */
	private static SWTWorkbenchBot bot;

	/**
	 * Tries to close the "Welcome" view if it is open. This only needs to be
	 * done once, and nothing needs to be disposed afterward.
	 */
	@BeforeClass
	public static void beforeWorkbenchClass() {

		// Close the welcome view using a temporary SWTBot.
		SWTWorkbenchBot bot = new SWTWorkbenchBot();
		try {
			bot.viewByTitle("Welcome").close();
		} catch (WidgetNotFoundException e) {
			// Nothing to do.
		}

		return;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see org.eclipse.ice.client.widgets.test.AbstractUITester#getBot()
	 */
	@Override
	protected SWTWorkbenchBot getBot() {
		return bot;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ice.client.widgets.test.AbstractUITester#beforeAllTests()
	 */
	@Override
	public void beforeAllTests() {
		super.beforeAllTests();

		// Initialize static or otherwise shared resources here.

		// Set up the SWTBot for the workbench.
		bot = new SWTWorkbenchBot();
		SWTBotPreferences.TIMEOUT = 2000;
	}

	/*
	 * (non-Javadoc)
	 * 
	 * @see
	 * org.eclipse.ice.client.widgets.test.AbstractUITester#beforeEachTest()
{'fraction_non_alphanumeric': 0.14367219917012447, 'fraction_numerical': 0.0025933609958506223, 'mean_word_length': 4.264846416382253, 'pattern_counts': {'":': 0, '<': 33, '<?xml version=': 0, '>': 33, 'https://': 0, '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': '2660089', 'n_tokens_mistral': 2437, 'n_tokens_neox': 2241, 'n_words': 687}