Skip to content

Commit 7196f30

Browse files
committed
Adds capability to display warnings in LaunchBar Launch Config Dialog
Add SWTBot to test that the Launch Configuration, when opened via the Launch Bar, displays a warning in the message area.
1 parent 9e1be51 commit 7196f30

File tree

3 files changed

+125
-2
lines changed

3 files changed

+125
-2
lines changed

launchbar/org.eclipse.launchbar.ui.tests/plugin.xml

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,15 @@
1212
after="org.eclipse.debug.ui.prototypeTab">
1313
</placement>
1414
</tab>
15+
<!-- Test for Launch Bar Launch Configuration Warnings -->
16+
<tab
17+
class="org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab"
18+
group="org.eclipse.pde.ui.launcher.WorkbenchLauncherTabGroup"
19+
id="org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab"
20+
name="Warning Tab">
21+
<placement
22+
after="my.custom.tab">
23+
</placement>
24+
</tab>
1525
</extension>
16-
1726
</plugin>

launchbar/org.eclipse.launchbar.ui.tests/src/org/eclipse/launchbar/ui/tests/internal/CreateLaunchConfigTests.java

Lines changed: 50 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*******************************************************************************
2-
* Copyright (c) 2017, 2021 QNX Software Systems and others.
2+
* Copyright (c) 2017, 2024 Renesas Electronics Europe and others.
33
*
44
* This program and the accompanying materials
55
* are made available under the terms of the Eclipse Public License 2.0
@@ -11,9 +11,11 @@
1111
package org.eclipse.launchbar.ui.tests.internal;
1212

1313
import static org.eclipse.swtbot.eclipse.finder.matchers.WidgetMatcherFactory.withPartName;
14+
import static org.eclipse.swtbot.swt.finder.matchers.WidgetMatcherFactory.widgetOfType;
1415
import static org.junit.jupiter.api.Assertions.fail;
1516

1617
import java.util.concurrent.TimeUnit;
18+
import java.util.concurrent.atomic.AtomicReference;
1719

1820
import org.eclipse.core.runtime.CoreException;
1921
import org.eclipse.debug.core.DebugPlugin;
@@ -24,6 +26,7 @@
2426
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector;
2527
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector.EditConfigDialog;
2628
import org.eclipse.launchbar.ui.tests.SWTBotConfigSelector.NewConfigDialog;
29+
import org.eclipse.swt.widgets.Text;
2730
import org.eclipse.swtbot.eclipse.finder.SWTWorkbenchBot;
2831
import org.eclipse.swtbot.eclipse.finder.widgets.SWTBotView;
2932
import org.eclipse.swtbot.swt.finder.SWTBot;
@@ -139,4 +142,50 @@ public String getFailureMessage() {
139142
}
140143
});
141144
}
145+
146+
/**
147+
* Tests that the Launch Configuration, when opened via the Launch Bar, displays a warning
148+
* in the message area.
149+
* @see {@link WarningLaunchConfigTab}
150+
* @see {@code org.eclipse.launchbar.ui.tests/plugin.xml}
151+
*/
152+
@Test
153+
@Timeout(value = 2, unit = TimeUnit.MINUTES)
154+
public void createNewLaunchConfigWithWarning() throws Exception {
155+
// Test message. Needs to be effectively final.
156+
AtomicReference<String> errorMessage = new AtomicReference<>();
157+
158+
// Create config with launchbar
159+
bot.waitUntil(new ICondition() {
160+
@Override
161+
public void init(SWTBot bot) {
162+
/*
163+
* Use the Launch Bar new Launch Config and create an Eclipse Application Launch Config.
164+
* This will include a WarningLaunchConfigTab tab which has a warning set in it.
165+
*/
166+
NewConfigDialog dialog = new SWTBotConfigSelector(bot).newConfigDialog();
167+
dialog.setMode("Debug").setType("Eclipse Application").next();
168+
169+
// Select the warning tab, which sets the Launch Config message area to contain a warning.
170+
dialog.bot().cTabItem(WarningLaunchConfigTab.TAB_NAME).activate();
171+
172+
// Get the Launch Config message area and stash the warning message for testing later
173+
int indexOfErrorLabel = dialog.bot().widgets(widgetOfType(Text.class)).size() - 1;
174+
errorMessage.set(dialog.bot().text(indexOfErrorLabel).getText());
175+
176+
dialog.finish();
177+
}
178+
179+
@Override
180+
public boolean test() throws Exception {
181+
return errorMessage.get() != null && errorMessage.get().equals(WarningLaunchConfigTab.WARNING_MESSAGE);
182+
}
183+
184+
@Override
185+
public String getFailureMessage() {
186+
return String.format("Incorrect warning message; expected=%s, actual=%s",
187+
WarningLaunchConfigTab.WARNING_MESSAGE, errorMessage.get());
188+
}
189+
});
190+
}
142191
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
/*******************************************************************************
2+
* Copyright (c) 2024 Renesas Electronics Europe and others.
3+
*
4+
* This program and the accompanying materials
5+
* are made available under the terms of the Eclipse Public License 2.0
6+
* which accompanies this distribution, and is available at
7+
* https://www.eclipse.org/legal/epl-2.0/
8+
*
9+
* SPDX-License-Identifier: EPL-2.0
10+
*******************************************************************************/
11+
package org.eclipse.launchbar.ui.tests.internal;
12+
13+
import org.eclipse.debug.core.ILaunchConfiguration;
14+
import org.eclipse.debug.core.ILaunchConfigurationWorkingCopy;
15+
import org.eclipse.debug.ui.AbstractLaunchConfigurationTab;
16+
import org.eclipse.swt.SWT;
17+
import org.eclipse.swt.layout.RowLayout;
18+
import org.eclipse.swt.widgets.Composite;
19+
import org.eclipse.swt.widgets.Label;
20+
21+
/**
22+
* Creates a tab to test that the Launch Configuration, when opened via the Launch Bar,
23+
* displays a warning in the message area.
24+
* @see {@link CreateLaunchConfigTests}
25+
*/
26+
public class WarningLaunchConfigTab extends AbstractLaunchConfigurationTab {
27+
public static final String WARNING_MESSAGE = "This is a warning";
28+
public static final String TAB_NAME = "Warning Tab";
29+
30+
@Override
31+
public void createControl(Composite parent) {
32+
parent.setLayout(new RowLayout());
33+
Label label = new Label(parent, SWT.NONE);
34+
label.setText("The Launch Configuration message area should show a warning message!");
35+
setControl(label);
36+
}
37+
38+
@Override
39+
public void setDefaults(ILaunchConfigurationWorkingCopy configuration) {
40+
}
41+
42+
@Override
43+
public void initializeFrom(ILaunchConfiguration configuration) {
44+
}
45+
46+
@Override
47+
public void performApply(ILaunchConfigurationWorkingCopy configuration) {
48+
}
49+
50+
@Override
51+
public String getName() {
52+
return TAB_NAME;
53+
}
54+
55+
@Override
56+
public String getId() {
57+
return "org.eclipse.launchbar.ui.tests.internal.WarningLaunchConfigTab";
58+
}
59+
60+
@Override
61+
public boolean isValid(ILaunchConfiguration launchConfig) {
62+
setWarningMessage(WARNING_MESSAGE);
63+
return true;
64+
}
65+
}

0 commit comments

Comments
 (0)