Skip to content
This repository has been archived by the owner on Dec 5, 2024. It is now read-only.

Create plugin for Environment Tab in LC #2120

Merged
merged 15 commits into from
May 25, 2021
Merged
Original file line number Diff line number Diff line change
@@ -0,0 +1,156 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations;

import java.util.List;

import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.swt.condition.ShellIsAvailable;
import org.eclipse.reddeer.swt.impl.button.OkButton;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.button.RadioButton;
import org.eclipse.reddeer.swt.impl.table.DefaultTable;
import org.eclipse.reddeer.swt.impl.table.DefaultTableItem;
import org.eclipse.reddeer.swt.impl.text.LabeledText;

/**
* Represents Environment tab in Launch Configuration
*
* @author Oleksii Korniienko [email protected]
*
*/
public class EnvironmentTab extends LaunchConfigurationTab {

private static final String ADD_SHELL_TITLE = "New Environment Variable";
private static final String SELECT_SHELL_TITLE = "Select Environment Variables";
private static final String EDIT_SHELL_TITLE = "Edit Environment Variable";

public EnvironmentTab() {
super("Environment");
}

/**
* Return the list of all environment variables
*
* @return list of items
*/
public List<TableItem> getVariables() {
return new DefaultTable().getItems();
}

/**
* Add new environment variable
*
* @param Name variable name
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please also update the javadoc after changing variable names

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

* @param Value variable value
*/
public void add(String name, String nalue) {
odockal marked this conversation as resolved.
Show resolved Hide resolved
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can instead of basically rewriting the method that follows with boolean params, simply call the later implementation with default boolean value. And I would go with default overwrite = true instead of false...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

new PushButton("Add...").click();
new WaitUntil(new ShellIsAvailable(ADD_SHELL_TITLE));
olkornii marked this conversation as resolved.
Show resolved Hide resolved
new LabeledText("Name:").setText(name);
new LabeledText("Value:").setText(nalue);
new OkButton().click();
}

/**
* Select environment variable by name
*
* @param selectVariable variable name for select
*/
public void select(String selectVariable) {
odockal marked this conversation as resolved.
Show resolved Hide resolved
new PushButton("Select...").click();
Copy link
Collaborator

@odockal odockal May 24, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be nice to have this similarities in implementation write only once. Like maybe using functional interface to pass specific code into repeated passages? Ie:

	public void versionOne(String param) {
		versionImpl(() -> {
			System.out.println("I am String!");
		});
	}
	
	public void versionTwo(int param) {
		versionImpl(() -> {
			System.out.println("I am int!");
		});
	}
	
	private void versionImpl(Runnable mySpecificImpl) {
		System.out.println("Actions before my functional interface call");
		mySpecificImpl.run();
		System.out.println("Actions after my functional interface call");
	}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
new DefaultTableItem(selectVariable).setChecked(true);
new OkButton().click();
}

/**
* Select environment variable by id
*
* @param id variable index
*/
public void select(int id) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you please also add methods for selecting variables in EnvironmentTab? you have method getAllVariables, but how do I select one variable by name in this tab? Can you please also change name of current methods select(...) to selectEnvironmentVariable?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

done

new PushButton("Select...").click();
new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
new DefaultTable().getItem(id).setChecked(true);
new OkButton().click();
}

/**
* Select/deselect all environment variables in select button list
*
* @param selectAllBool true if need to select all variables, false for deselect
*/
public void select(boolean selectAllBool) {
new PushButton("Select...").click();
new WaitUntil(new ShellIsAvailable(SELECT_SHELL_TITLE));
if (selectAllBool) {
new PushButton("Select All").click();
} else {
new PushButton("Deselect All").click();
}
new OkButton().click();
}

/**
* edit environment variable
*
* @param name new variable name
* @param value new variable value
*/
public void edit(String name, String value) {
new PushButton("Edit...").click();
new WaitUntil(new ShellIsAvailable(EDIT_SHELL_TITLE));
new LabeledText("Name:").setText(name);
new LabeledText("Value:").setText(value);
new OkButton().click();
}

/**
* Remove environment variable
*/
public void remove() {
new PushButton("Remove").click();
}

/**
* Copy environment variable
*/
public void copy() {
new PushButton("Copy").click();
}

/**
* Paste environment variable
*/
public void paste() {
new PushButton("Paste").click();
}

/**
* Append environment to native environment
*
* @return append radio button
*/
public RadioButton getAppendRadioButton() {
return new RadioButton("Append environment to native environment");
}

/**
* Replace native environment with specified environment
*
* @return replace radio button
*/
public RadioButton getReplaceRadioButton() {
return new RadioButton("Replace native environment with specified environment");
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,103 @@
/*******************************************************************************
* Copyright (c) 2021 Red Hat, Inc.
* Distributed under license by Red Hat, Inc. All rights reserved.
* This program is 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:
* Red Hat, Inc. - initial API and implementation
******************************************************************************/
package org.eclipse.reddeer.eclipse.test.jdt.environment.launcher;

import static org.junit.Assert.assertTrue;

import org.eclipse.reddeer.common.exception.RedDeerException;
import org.eclipse.reddeer.common.wait.TimePeriod;
import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations.EnvironmentTab;
import org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations.JUnitLaunchConfiguration;
import org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations.LaunchConfigurationsDialog;
import org.eclipse.reddeer.eclipse.debug.ui.launchConfigurations.RunConfigurationsDialog;
import org.eclipse.reddeer.eclipse.ui.perspectives.JavaPerspective;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective;
import org.eclipse.reddeer.swt.condition.ShellIsAvailable;
import org.eclipse.reddeer.swt.impl.button.RadioButton;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.table.DefaultTable;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(RedDeerSuite.class)
@OpenPerspective(JavaPerspective.class)
public class EnvironmentLaunchConfigurationTabTest {

private static final String CONFIGURATION_NAME = EnvironmentLaunchConfigurationTabTest.class + "_test_config";

protected LaunchConfigurationsDialog dialog;

@Before
public void openDialog() {
dialog = new RunConfigurationsDialog();
dialog.open();
}

@After
public void closeDialog() {
try {
new WaitUntil(new ShellIsAvailable(dialog.getTitle()), TimePeriod.NONE);
new DefaultShell(dialog.getTitle()).close();
} catch (RedDeerException e) {
// already closed
}
}

@Test
public void testEnvironmentTab() {
dialog.create(new JUnitLaunchConfiguration(), CONFIGURATION_NAME);

EnvironmentTab envTab = new EnvironmentTab();
envTab.activate();
int should_be_var_count = envTab.getVariables().size();

envTab.add("test_name", "test_value");
should_be_var_count++;
int add_env_count = envTab.getVariables().size();
assertTrue(should_be_var_count == add_env_count);

envTab.select(0);
should_be_var_count++;
int select_env_count = envTab.getVariables().size();
assertTrue(should_be_var_count == select_env_count);

new DefaultTable().select(0);
envTab.remove();
should_be_var_count--;
int remove_env_count = envTab.getVariables().size();
assertTrue(should_be_var_count == remove_env_count);

new DefaultTable().select(0);
envTab.edit("test_new", "test_new");
String item_text = new DefaultTable().getItem(0).getText();
assertTrue(item_text.contains("test_new"));

new DefaultTable().select(0);
envTab.copy();
envTab.remove();
should_be_var_count--;
int copy_env_count = envTab.getVariables().size();
assertTrue(should_be_var_count == copy_env_count);
envTab.paste();
should_be_var_count++;
int paste_env_count = envTab.getVariables().size();
assertTrue(should_be_var_count == paste_env_count);

envTab.getReplaceRadioButton().click();
assertTrue(new RadioButton("Replace native environment with specified environment").isSelected());
envTab.getAppendRadioButton().click();
assertTrue(new RadioButton("Append environment to native environment").isSelected());
}
}