Skip to content

Commit

Permalink
Fix eclipse.test tests, add DisableOomphRecorder Requirement
Browse files Browse the repository at this point in the history
Signed-off-by: Ondrej Dockal <odockal@redhat.com>
  • Loading branch information
odockal committed Aug 24, 2022
1 parent 9a289e9 commit 12bb86b
Show file tree
Hide file tree
Showing 6 changed files with 174 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.common.wait.WaitWhile;
import org.eclipse.reddeer.core.condition.WidgetIsFound;
import org.eclipse.reddeer.core.exception.CoreLayerException;
import org.eclipse.reddeer.core.matcher.TreeItemTextMatcher;
import org.eclipse.reddeer.core.matcher.WithMnemonicTextMatcher;
import org.eclipse.reddeer.core.reference.ReferencedComposite;
Expand All @@ -30,6 +31,7 @@
import org.eclipse.reddeer.swt.impl.button.OkButton;
import org.eclipse.reddeer.swt.impl.button.PushButton;
import org.eclipse.reddeer.swt.impl.button.YesButton;
import org.eclipse.reddeer.swt.impl.ctab.DefaultCTabItem;
import org.eclipse.reddeer.swt.impl.shell.DefaultShell;
import org.eclipse.reddeer.swt.impl.tab.DefaultTabItem;
import org.eclipse.reddeer.swt.impl.table.DefaultTableItem;
Expand Down Expand Up @@ -65,7 +67,13 @@ public BuildPathsPropertyPage(ReferencedComposite referencedComposite) {
* Activates Source tab.
*/
public BuildPathsPropertyPage activateSourceTab() {
new DefaultTabItem(this, "Source").activate();
try {
new DefaultCTabItem(this, "Source").activate();
}
catch (CoreLayerException exc) {
// fallback for Eclipse older than 2022-09 where DefaultTabItem must be used
new DefaultTabItem(this, "Source").activate();
}
new WaitWhile(new JobIsRunning());
return this;
}
Expand All @@ -74,7 +82,13 @@ public BuildPathsPropertyPage activateSourceTab() {
* Activates Projects tab.
*/
public BuildPathsPropertyPage activateProjectsTab() {
new DefaultTabItem(this, "Projects").activate();
try {
new DefaultCTabItem(this, "Projects").activate();
}
catch (CoreLayerException exc) {
// fallback for Eclipse older than 2022-09 where DefaultTabItem must be used
new DefaultTabItem(this, "Projects").activate();
}
new WaitWhile(new JobIsRunning());
return this;
}
Expand All @@ -83,7 +97,13 @@ public BuildPathsPropertyPage activateProjectsTab() {
* Activates Libraries tab.
*/
public BuildPathsPropertyPage activateLibrariesTab() {
new DefaultTabItem(this, "Libraries").activate();
try {
new DefaultCTabItem(this, "Libraries").activate();
}
catch (CoreLayerException exc) {
// fallback for Eclipse older than 2022-09 where DefaultTabItem must be used
new DefaultTabItem(this, "Libraries").activate();
}
new WaitWhile(new JobIsRunning());
return this;
}
Expand All @@ -92,7 +112,13 @@ public BuildPathsPropertyPage activateLibrariesTab() {
* Activates Order and Export tab.
*/
public BuildPathsPropertyPage activateOrderAndExportTab() {
new DefaultTabItem(this, "Order and Export").activate();
try {
new DefaultCTabItem(this, "Order and Export").activate();
}
catch (CoreLayerException exc) {
// fallback for Eclipse older than 2022-09 where DefaultTabItem must be used
new DefaultTabItem(this, "Order and Export").activate();
}
new WaitWhile(new JobIsRunning());
return this;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ Export-Package: org.eclipse.reddeer.requirements.autobuilding,
org.eclipse.reddeer.requirements.exception,
org.eclipse.reddeer.requirements.jre,
org.eclipse.reddeer.requirements.openperspective,
org.eclipse.reddeer.requirements.preferences,
org.eclipse.reddeer.requirements.property,
org.eclipse.reddeer.requirements.server,
org.eclipse.reddeer.requirements.server.apache.tomcat,
Expand Down
1 change: 1 addition & 0 deletions plugins/org.eclipse.reddeer.requirements/plugin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@
<requirement class="org.eclipse.reddeer.requirements.db.DatabaseRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.jre.JRERequirement"/>
<requirement class="org.eclipse.reddeer.requirements.openperspective.OpenPerspectiveRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.preferences.OomphRecorderRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.property.PropertyRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.securestorage.SecureStorageRequirement"/>
<requirement class="org.eclipse.reddeer.requirements.server.apache.tomcat.ApacheTomcatServerRequirement"/>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.requirements.preferences;

import java.lang.annotation.ElementType;
import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;

import org.eclipse.reddeer.direct.preferences.Preferences;
import org.eclipse.reddeer.common.logging.Logger;
import org.eclipse.reddeer.junit.requirement.AbstractRequirement;
import org.eclipse.reddeer.requirements.preferences.OomphRecorderRequirement.DisableOomphRecorder;

/**
* Disables oomph recorder using Direct API.
*
* @author odockal@redhat.com
*
*/
public class OomphRecorderRequirement extends AbstractRequirement<DisableOomphRecorder> {

private static final Logger log = Logger.getLogger(OomphRecorderRequirement.class);

private static final String OOMPH_PLUGIN_ID = "org.eclipse.oomph.setup.ui";

private static final String OOMPH_ENABLE_RECORDER_KEY = "enable.preference.recorder";

@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.TYPE)
public @interface DisableOomphRecorder {

/**
* Sets whether Oomph recorder is disabled or not.
*
* @return false if disabled
*/
boolean enabled() default false;
}

@Override
public void fulfill() {
log.info(annotation.enabled() ? "Disabling" : "Enabling" + " Oomph preferences recorder");
Preferences.set(OOMPH_PLUGIN_ID, OOMPH_ENABLE_RECORDER_KEY, Boolean.toString(annotation.enabled()));
}

@Override
public void cleanUp() {
// nothing to do
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@
import org.eclipse.reddeer.junit.execution.annotation.RunIf;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.requirements.openperspective.OpenPerspectiveRequirement.OpenPerspective;
import org.eclipse.reddeer.requirements.preferences.OomphRecorderRequirement.DisableOomphRecorder;
import org.eclipse.reddeer.workbench.core.condition.JobIsRunning;
import org.junit.After;
import org.junit.AfterClass;
Expand All @@ -51,6 +52,7 @@
*/
@RunWith(RedDeerSuite.class)
@OpenPerspective(JavaPerspective.class)
@DisableOomphRecorder
public class BuildPathsPropertyPageTest {

private static final String TEST_PROJECT_NAME = "buildpathspropertypagetest";
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
/*******************************************************************************
* Copyright (c) 2022 Red Hat, Inc and others.
* This program and the accompanying materials are made available under the
* terms of the Eclipse Public License 2.0 which is available at
* http://www.eclipse.org/legal/epl-2.0.
*
* SPDX-License-Identifier: EPL-2.0
*
* Contributors:
* Red Hat, Inc - initial API and implementation
*******************************************************************************/
package org.eclipse.reddeer.requirements.test.preferences;

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

import java.lang.annotation.Annotation;

import org.eclipse.reddeer.direct.preferences.Preferences;
import org.eclipse.reddeer.junit.runner.RedDeerSuite;
import org.eclipse.reddeer.requirements.preferences.OomphRecorderRequirement;
import org.eclipse.reddeer.requirements.preferences.OomphRecorderRequirement.DisableOomphRecorder;
import org.eclipse.reddeer.swt.impl.toolbar.DefaultToolBar;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;

@RunWith(RedDeerSuite.class)
public class OomphRecorderRequirementTest {

private static final String OOMPH_PLUGIN_ID = "org.eclipse.oomph.setup.ui";
private static final String OOMPH_ENABLE_RECORDER_KEY = "enable.preference.recorder";

private OomphRecorderRequirement requirementEnabled;
private OomphRecorderRequirement requirementDisabled;

@Before
public void setupRequirement() {
requirementEnabled = new OomphRecorderRequirement();
requirementEnabled.setDeclaration(createDisableOomphRecorderInstance(true));
requirementDisabled = new OomphRecorderRequirement();
requirementDisabled.setDeclaration(createDisableOomphRecorderInstance(false));
}

public DefaultToolBar getPreferencesToolBar() {
return new DefaultToolBar();
}

@Test
public void testEnableOomphRecorder() {
requirementEnabled.fulfill();
String actualValue = Preferences.get(OOMPH_PLUGIN_ID, OOMPH_ENABLE_RECORDER_KEY);
assertTrue(Boolean.valueOf(actualValue));
}

@Test
public void testDisableOomphRecorder() {
requirementDisabled.fulfill();
String actualValue = Preferences.get(OOMPH_PLUGIN_ID, OOMPH_ENABLE_RECORDER_KEY);
assertFalse(Boolean.valueOf(actualValue));
}

private DisableOomphRecorder createDisableOomphRecorderInstance(boolean enabled) {
return new DisableOomphRecorder() {

@Override
public Class<? extends Annotation> annotationType() {
return DisableOomphRecorder.class;
}

@Override
public boolean enabled() {
return enabled;
}
};
}


}

0 comments on commit 12bb86b

Please sign in to comment.