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,141 @@
/*******************************************************************************
* 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.swt.api.TableItem;
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 EnvironmentLaunchConfigurationTab extends LaunchConfigurationTab {
jkopriva marked this conversation as resolved.
Show resolved Hide resolved

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

/**
* Return the list of all environment variables
*
* @return list of items
*/
public List<TableItem> get_variables() {
odockal marked this conversation as resolved.
Show resolved Hide resolved
return new DefaultTable().getItems();
}

/**
* Add new environment variable
*
* @param Name variable name
* @param Value variable value
*/
public void add(String Name, String Value) {
odockal marked this conversation as resolved.
Show resolved Hide resolved
new PushButton("Add...").click();
new LabeledText("Name:").setText(Name);
new LabeledText("Value:").setText(Value);
new OkButton().click();
}

/**
* Select environment variable by name
*
* @param Name variable name
*/
public void select(String Name) {
Copy link
Contributor

Choose a reason for hiding this comment

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

I would suggest to use better name: like selectVariable

Copy link
Contributor Author

Choose a reason for hiding this comment

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

fixed

new PushButton("Select...").click();
new DefaultTableItem(Name).setChecked(true);
new OkButton().click();
}

/**
* Select environment variable by id
*
* @param id variable index
*/
public void select(int id) {
new PushButton("Select...").click();
new DefaultTable().getItem(id).setChecked(true);
new OkButton().click();
}

/**
* Select/deselect all environment variables in select button list
*
* @param id variable index
odockal marked this conversation as resolved.
Show resolved Hide resolved
*/
public void select(boolean selectAllBool) {
new PushButton("Select...").click();
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();
odockal marked this conversation as resolved.
Show resolved Hide resolved
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
*/
public void append() {
odockal marked this conversation as resolved.
Show resolved Hide resolved
new RadioButton("Append environment to native environment").click();
}

/**
* Replace native environment with specified environment
*/
public void replace() {
new RadioButton("Replace native environment with specified environment").click();
}
}
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.EnvironmentLaunchConfigurationTab;
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);

EnvironmentLaunchConfigurationTab envTab = new EnvironmentLaunchConfigurationTab();
envTab.activate();
int should_be_var_count = envTab.get_variables().size();

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

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

new DefaultTable().select(0);
envTab.remove();
should_be_var_count--;
int remove_env_count = envTab.get_variables().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.get_variables().size();
assertTrue(should_be_var_count == copy_env_count);
envTab.paste();
should_be_var_count++;
int paste_env_count = envTab.get_variables().size();
assertTrue(should_be_var_count == paste_env_count);

envTab.replace();
assertTrue(new RadioButton("Replace native environment with specified environment").isSelected());
envTab.append();
assertTrue(new RadioButton("Append environment to native environment").isSelected());
}
}