Skip to content

Commit

Permalink
Added methods for work with Install/Update Available Software Sites p…
Browse files Browse the repository at this point in the history
…reference page

Signed-off-by: lgrossma <lgrossma@redhat.com>
  • Loading branch information
lgrossma authored and odockal committed Nov 15, 2022
1 parent 373943b commit fd29b42
Show file tree
Hide file tree
Showing 4 changed files with 321 additions and 2 deletions.
3 changes: 2 additions & 1 deletion tests/org.eclipse.reddeer.eclipse.test/META-INF/MANIFEST.MF
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ Require-Bundle: org.eclipse.reddeer.go;bundle-version="[2.2.0,4.4.1)",
org.eclipse.datatools.sqltools.result.ui;bundle-version="1.1.3",
org.eclipse.jdt.ui,
org.eclipse.jdt.junit4.runtime,
org.eclipse.jdt.junit
org.eclipse.jdt.junit,
org.eclipse.reddeer.integration.test
Bundle-ActivationPolicy: lazy
Bundle-RequiredExecutionEnvironment: JavaSE-17
Import-Package: org.hamcrest.core
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,210 @@
package org.eclipse.reddeer.eclipse.test.integration;

import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertTrue;

import java.util.LinkedHashMap;
import java.util.Map;

import org.eclipse.reddeer.common.wait.WaitUntil;
import org.eclipse.reddeer.integration.test.installation.common.preferences.AvailableSoftwareSitesPreferencePage;
import org.eclipse.reddeer.jface.preference.PreferenceDialog;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.swt.condition.ShellIsAvailable;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.text.LabeledText;
import org.eclipse.reddeer.workbench.ui.dialogs.WorkbenchPreferenceDialog;
import org.junit.After;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(RedDeerSuite.class)
public class AvailableSoftwareSitesPreferencePageTest {

private PreferenceDialog dialog;
private AvailableSoftwareSitesPreferencePage page;
private DefaultShell shell = null;
private final static String ECLIPSE = "Eclipse";
private final static String ECLIPSE_URL = "https://download.eclipse.org/releases/latest";
private final static String REDDEER = "RedDeer";
private final static String REDDEER_URL = "http://download.eclipse.org/reddeer/releases/latest";

@BeforeClass
public static void setupList() {
Map<String, String> sites = new LinkedHashMap<String, String>();
sites.put(ECLIPSE, ECLIPSE_URL);
sites.put(REDDEER, REDDEER_URL);

PreferenceDialog dialog = new WorkbenchPreferenceDialog();
dialog.open();
AvailableSoftwareSitesPreferencePage page = new AvailableSoftwareSitesPreferencePage(dialog);
dialog.select(page);

for(var site : sites.entrySet()) {
page.clickAdd();
LabeledText name = new LabeledText("Name:");
name.setText(site.getKey());
LabeledText url = new LabeledText("Location:");
url.setText(site.getValue());
new PushButton("Add").click();
}

dialog.ok();

}

@Before
public void openAvailableSoftwareSitesPreferencePage() {
dialog = new WorkbenchPreferenceDialog();
dialog.open();
page = new AvailableSoftwareSitesPreferencePage(dialog);
dialog.select(page);
}

@Test
public void pageIsOpened() {
assertTrue("Page does not have right name", page.getName().contains("Available Software Sites"));
}

@Test
public void getItemsTest() {
assertFalse(page.getItems().isEmpty());
}

@Test
public void getItemTest() {
String itemText = page.getItem(ECLIPSE).getText();
assertTrue("Item has text " + itemText, page.getItem(ECLIPSE).getText().contains(ECLIPSE));
}

@Test
public void getItemAlternateSearchTest() {
String itemText = page.getItem(REDDEER_URL, true).getText(1);
assertTrue("the item has text " + itemText, itemText.contains(REDDEER_URL));
itemText = page.getItem(ECLIPSE, false).getText();
assertTrue("the item has text " + itemText, itemText.contains(ECLIPSE));
TableItem item = page.getItem(ECLIPSE, true);
assertNull("Item is not null", item);

}

@Test
public void toggleAllItemsTest() {
page.toggleAllItems(false);
for(TableItem item : page.getItems()) {
assertFalse(item.isChecked());
}
page.toggleAllItems(true);
for(TableItem item : page.getItems()) {
assertTrue(item.isChecked());
}
}

@Test
public void toggleItemTest() {
page.toggleItem(ECLIPSE, false);
assertFalse(page.getItem(ECLIPSE).isChecked());
page.toggleItem(ECLIPSE, true);
assertTrue(page.getItem(ECLIPSE).isChecked());
}

@Test
public void toggleItemAlternativeSearchTest() {
page.toggleItem(REDDEER_URL, false, true);
assertFalse(page.getItem(REDDEER_URL, true).isChecked());
page.toggleItem(REDDEER_URL, true, true);
assertTrue(page.getItem(REDDEER).isChecked());
}

@Test
public void selectItemTest() {
page.selectItem(REDDEER);
assertTrue(page.isButtonEnabled("Edit"));
}

@Test
public void selectItemAlternativeSearchTest() {
page.selectItem(ECLIPSE_URL, true);
assertTrue(page.isButtonEnabled("Edit"));
}

@Test
public void isItemEnabledTest() {
assertTrue(page.isItemEnabled(ECLIPSE));
page.toggleItem(ECLIPSE, false);
assertFalse(page.isItemEnabled(ECLIPSE));
}

@Test
public void isItemEnabledAlternativeSearchTest() {
assertTrue(page.isItemEnabled(ECLIPSE_URL, true));
page.toggleItem(ECLIPSE, false);
assertFalse(page.isItemEnabled(ECLIPSE_URL, true));
}

@Test
public void isButtonEnabledTest() {
assertTrue(page.isButtonEnabled("Add..."));
assertFalse(page.isButtonEnabled("Edit"));
}

@Test
public void clickAddTest() {
page.clickAdd();
shell = new DefaultShell();
assertTrue("Shell with title Add Site is not opened", shell.getText().contains("Add Site"));
}

@Test
public void clickEditTest() {
page.selectItem(ECLIPSE);
page.clickEdit();
shell = new DefaultShell();
assertTrue("Shell with title Edit Site is not opened", shell.getText().contains("Edit Site"));
}

@Test
public void clickRemoveTest() {
page.selectItem(REDDEER);
page.clickRemove();
shell = new DefaultShell();
assertTrue("Shell with title Remove Sites is not opened", shell.getText().contains("Remove Sites"));
}

@Test
public void clickReloadTest() {
page.selectItem(ECLIPSE);
page.clickRemove();
new WaitUntil(new ShellIsAvailable("Progress Information"));
shell = new DefaultShell();
assertTrue("Shell with title Reload is not opened", shell.getText().contains("Reload"));
}

@Test
public void clickEnableTest() {
page.toggleAllItems(false);
page.selectItem(ECLIPSE);
page.clickEnable();
assertTrue("Item is not enabled",page.isItemEnabled(ECLIPSE));
}

@Test
public void clickDisableTest() {
page.selectItem(REDDEER);
page.clickDisable();
assertFalse("Item is not disabled", page.isItemEnabled(REDDEER));
}

@After
public void closeAllShells() {
if(shell != null) {
shell.close();
}
dialog.cancel();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Bundle-RequiredExecutionEnvironment: JavaSE-17
Export-Package: org.eclipse.reddeer.integration.test.installation.common.condition,
org.eclipse.reddeer.integration.test.installation.common.dialog,
org.eclipse.reddeer.integration.test.installation.common.page,
org.eclipse.reddeer.integration.test.installation.common.preferences,
org.eclipse.reddeer.integration.test.installation.common.util,
org.eclipse.reddeer.integration.test.installation.common.wait
Automatic-Module-Name: org.eclipse.reddeer.integration.test
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import org.eclipse.reddeer.core.reference.ReferencedComposite;
import org.eclipse.reddeer.jface.preference.PreferencePage;
import org.eclipse.reddeer.swt.api.TableItem;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.table.DefaultTable;

/**
Expand All @@ -33,10 +34,116 @@ public List<TableItem> getItems() {
return new DefaultTable().getItems();
}

public TableItem getItem(String name) {
for(TableItem item : getItems()) {
if(item.getText(0).equals(name)) {
return item;
}
}
return null;
}

/**
* If alternate search is set true, the method will search in Address column instead of Name column
* @param url
* @param alternateSearch
* @return specified TableItem
*/
public TableItem getItem(String url, boolean alternateSearch) {
if(!alternateSearch) {
return getItem(url);
} else {
for(TableItem item : getItems()) {
if(item.getText(1).equals(url)) {
return item;
}
}
}
return null;
}

public void toggleAllItems(boolean toggle) {
for(TableItem item: getItems()) {
for(TableItem item : getItems()) {
item.setChecked(toggle);
}
}

public void toggleItem(String name, boolean toggle) {
getItem(name).setChecked(toggle);
}

/**
* If alternateSearch is set true, the method will search in Address column instead of Name column
* @param url
* @param toggle
* @param alternateSearch
*/
public void toggleItem(String url, boolean toggle, boolean alternateSearch) {
getItem(url, alternateSearch).setChecked(toggle);
}

public void selectItem(String name) {
getItem(name).click();
}

/**
* If alternateSearch is set true, the method will search in Address column instead of Name column
* @param url
* @param toggle
* @param alternateSearch
*/
public void selectItem(String url, boolean alternateSearch) {
getItem(url, alternateSearch).click();
}

public boolean isItemEnabled(String name) {
return getItem(name).getText(2).equals("Enabled");
}

/**
* If alternateSearch is set true, the method will search in Address column instead of Name column
* @param url
* @param alternateSearch
* @return True if item in table is enabled
*/
public boolean isItemEnabled(String url, boolean alternateSearch) {
return getItem(url, alternateSearch).getText(2).equals("Enabled");
}

public boolean isButtonEnabled(String buttonName) {
return new PushButton(buttonName).isEnabled();
}

public void clickAdd() {
new PushButton("Add...").click();
}

public void clickEdit() {
new PushButton("Edit").click();
}

public void clickRemove() {
new PushButton("Remove").click();
}

public void clickReload() {
new PushButton("Reload").click();
}

public void clickEnable() {
new PushButton("Enable").click();
}

public void clickDisable() {
new PushButton("Disable").click();
}

public void clickImport() {
new PushButton("Import...").click();
}

public void clickExport() {
new PushButton("Export...").click();
}

}

0 comments on commit fd29b42

Please sign in to comment.