Skip to content

Commit b25d125

Browse files
author
Hong Fang Han
committed
GERONIMODEVTOOLS-679 TestSuite not working on branch 2.1.7: second commit for test cases upgrade.
git-svn-id: https://svn.apache.org/repos/asf/geronimo/devtools/eclipse-plugin/branches/2.1@1041362 13f79535-47bb-0310-9956-ffa450edef68
1 parent 9584d3a commit b25d125

File tree

15 files changed

+265
-174
lines changed

15 files changed

+265
-174
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
1+
package org.apache.geronimo.testsuite.common;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
import org.eclipse.swt.widgets.Widget;
7+
8+
import abbot.swt.finder.WidgetFinder;
9+
import abbot.swt.finder.WidgetFinderImpl;
10+
import abbot.swt.finder.WidgetHierarchy;
11+
import abbot.swt.finder.WidgetHierarchyImpl;
12+
import abbot.swt.finder.generic.Matcher;
13+
import abbot.swt.finder.generic.MultipleFoundException;
14+
import abbot.swt.finder.generic.NotFoundException;
15+
import abbot.swt.hierarchy.Visitable.Visitor;
16+
17+
public class MultiWidgetFinderImpl extends WidgetFinderImpl {
18+
private final WidgetHierarchy hierarchy;
19+
private static MultiWidgetFinderImpl Default;
20+
21+
public MultiWidgetFinderImpl(WidgetHierarchy hierarchy) {
22+
super(hierarchy);
23+
this.hierarchy = hierarchy;
24+
// TODO Auto-generated constructor stub
25+
}
26+
27+
public static synchronized MultiWidgetFinderImpl getDefault() {
28+
if (Default == null)
29+
Default = new MultiWidgetFinderImpl(WidgetHierarchyImpl.getDefault());
30+
return Default;
31+
}
32+
33+
public List<Widget> findMulti(final Matcher<Widget> matcher) throws NotFoundException,
34+
MultipleFoundException {
35+
36+
// Collect matches.
37+
final List<Widget> found = new ArrayList<Widget>();
38+
hierarchy.accept(new Visitor<Widget>() {
39+
public Result visit(Widget candidate) {
40+
if (matcher.matches(candidate))
41+
found.add(candidate);
42+
return Result.ok;
43+
}
44+
});
45+
46+
return found;
47+
}
48+
49+
public List<Widget> findMulti(Widget widget, final Matcher<Widget> matcher) throws NotFoundException,
50+
MultipleFoundException {
51+
52+
// Collect matches.
53+
final List<Widget> found = new ArrayList<Widget>();
54+
hierarchy.accept(widget, new Visitor<Widget>() {
55+
public Result visit(Widget candidate) {
56+
if (matcher.matches(candidate))
57+
found.add(candidate);
58+
return Result.ok;
59+
}
60+
});
61+
62+
return found;
63+
}
64+
65+
}

testsuite/plugins/org.apache.geronimo.testsuite.common/src/main/java/org/apache/geronimo/testsuite/common/selenium/EclipseSelenium.java

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -17,11 +17,8 @@
1717

1818
package org.apache.geronimo.testsuite.common.selenium;
1919

20-
import org.apache.geronimo.testsuite.common.ui.AbbotHelper;
21-
import org.eclipse.swt.widgets.Shell;
2220

2321
import com.thoughtworks.selenium.DefaultSelenium;
24-
import com.thoughtworks.selenium.Selenium;
2522

2623
/**
2724
* EclipseSelenium
@@ -32,7 +29,7 @@ public class EclipseSelenium extends DefaultSelenium {
3229

3330
private static String serverHost = "localhost";
3431
private static int serverPort = 4444;
35-
private static String browserStartCommand = "*EclipseBrowser";
32+
private static String browserStartCommand = "*firefox";
3633
private static String browserURL = "http://localhost:4444";
3734

3835
public EclipseSelenium() {

testsuite/plugins/org.apache.geronimo.testsuite.common/src/main/java/org/apache/geronimo/testsuite/common/selenium/EclipseSeleniumServer.java

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,16 +17,13 @@
1717

1818
package org.apache.geronimo.testsuite.common.selenium;
1919

20-
import java.io.File;
21-
import java.io.FileNotFoundException;
22-
import java.io.PrintStream;
2320

2421
import org.apache.geronimo.testsuite.common.ui.AbbotHelper;
2522
import org.eclipse.core.runtime.ISafeRunnable;
26-
import org.eclipse.core.runtime.Platform;
2723
import org.eclipse.swt.widgets.Shell;
2824
import org.openqa.selenium.server.SeleniumServer;
2925
import org.openqa.selenium.server.browserlaunchers.BrowserLauncherFactory;
26+
import org.openqa.selenium.server.browserlaunchers.MockBrowserLauncher;
3027

3128
/**
3229
* EclipseSeleniumServer
@@ -63,7 +60,7 @@ public void handleException(Throwable arg0) {
6360
}
6461

6562
public void run() throws Exception {
66-
BrowserLauncherFactory.addBrowserLauncher("EclipseBrowser", EclipseBrowserLauncher.class);
63+
BrowserLauncherFactory.addBrowserLauncher("MockBrowser", MockBrowserLauncher.class);
6764
SeleniumServer.setDebugMode( true );
6865
server = new SeleniumServer();
6966
server.start();

testsuite/plugins/org.apache.geronimo.testsuite.common/src/main/java/org/apache/geronimo/testsuite/common/ui/AbbotHelper.java

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,8 +17,10 @@
1717

1818
package org.apache.geronimo.testsuite.common.ui;
1919

20+
import java.util.ArrayList;
2021
import java.util.List;
2122

23+
import org.apache.geronimo.testsuite.common.MultiWidgetFinderImpl;
2224
import org.eclipse.swt.widgets.Button;
2325
import org.eclipse.swt.widgets.Combo;
2426
import org.eclipse.swt.widgets.Item;
@@ -57,9 +59,11 @@
5759
public class AbbotHelper {
5860
Shell workbenchShell;
5961
WidgetFinder finder;
62+
MultiWidgetFinderImpl mulFinder;
6063

6164
public AbbotHelper (Shell aShell) {
6265
finder = WidgetFinderImpl.getDefault();
66+
mulFinder = MultiWidgetFinderImpl.getDefault();
6367
workbenchShell = aShell;
6468
}
6569

@@ -184,6 +188,7 @@ public void setCombo (Shell aShell, String newText) throws MultipleFoundExceptio
184188
//helper method when there are multiple text boxes
185189
public void setTextFieldForMulti (Shell aShell, String oldText, String newText) throws MultipleFoundException, NotFoundException {
186190
Text text = (Text) finder.find (aShell, new TextMultipleMatcher(oldText, Text.class, true));
191+
187192
if (oldText.length() > 0)
188193
{
189194
TextTester.getTextTester().actionSelect (text, 0, oldText.length());
@@ -194,6 +199,29 @@ public void setTextFieldForMulti (Shell aShell, String oldText, String newText)
194199
waitTime( 1500 );
195200
}
196201

202+
// helper method to get MultiTextFields
203+
public List<Text> getMultiTextFiled(Shell aShell, String text) throws MultipleFoundException, NotFoundException {
204+
List<Text> retList = new ArrayList<Text>();
205+
206+
List<Widget> founds = this.mulFinder.findMulti(aShell, new TextMultipleMatcher(text, Text.class, true));
207+
for(int i=0; i<founds.size(); ++i) {
208+
retList.add((Text)founds.get(i));
209+
}
210+
return retList;
211+
}
212+
213+
// helper method to update TextField
214+
public void updateTextField(Text text, String oldText, String newText) {
215+
if (oldText.length() > 0)
216+
{
217+
TextTester.getTextTester().actionSelect (text, 0, oldText.length());
218+
TextTester.getTextTester().actionKeyString (newText);
219+
} else {
220+
TextTester.getTextTester().actionKeyString (text, newText);
221+
}
222+
waitTime( 1500 );
223+
}
224+
197225
//helper method to select a Tab
198226
public void selectTabItem(Shell aShell, String newText)throws MultipleFoundException,NotFoundException
199227
{
@@ -238,7 +266,8 @@ public void waitForServerStatus (Shell aShell, String itemText, String desiredSt
238266

239267
while (statusGood == false && countdown > 0) {
240268
TreeItem item = (TreeItem) finder.find (aShell, new WidgetTextMatcher (itemText, TreeItem.class));
241-
if (desiredState.equals (TreeItemTester.getTreeItemTester().getText (item, 1)))
269+
String serverStatus = TreeItemTester.getTreeItemTester().getText (item, 0);
270+
if (serverStatus.contains(desiredState))
242271
statusGood = true;
243272

244273
countdown--;

testsuite/plugins/org.apache.geronimo.testsuite.common/src/main/java/org/apache/geronimo/testsuite/common/ui/ServerTasks.java

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -64,16 +64,16 @@ public void createServer() throws MultipleFoundException, NotFoundException {
6464
}
6565

6666
public void editServer()throws MultipleFoundException, NotFoundException {
67-
String serverDisplay = Constants.getConstant(serverVersion, Constants.SERVERDISPLAY);
67+
String serverDisplay = "/" + Constants.getConstant(serverVersion, Constants.SERVERDISPLAY) + ".*/";
6868
aHelper.clickMenuItem (workbenchShell,
69-
new String[] {"&Window", "Show &View", "Servers"});
69+
new String[] {"&Window", "Show View", "Servers"});
7070
aHelper.doubleClickItem(workbenchShell, serverDisplay);
7171
}
7272

7373
public void startServer () throws MultipleFoundException, NotFoundException {
74-
String serverDisplay = Constants.getConstant(serverVersion, Constants.SERVERDISPLAY);
74+
String serverDisplay = "/" + Constants.getConstant(serverVersion, Constants.SERVERDISPLAY) + ".*/";
7575
aHelper.clickMenuItem (workbenchShell,
76-
new String[] {"&Window", "Show &View", "Servers"});
76+
new String[] {"&Window", "Show View", "Servers"});
7777

7878
aHelper.rightClickItem (workbenchShell, serverDisplay,
7979
new String[] {"&Start"});
@@ -83,9 +83,9 @@ public void startServer () throws MultipleFoundException, NotFoundException {
8383
}
8484

8585
public void stopServer () throws MultipleFoundException, NotFoundException {
86-
String serverDisplay = Constants.getConstant(serverVersion, Constants.SERVERDISPLAY);
86+
String serverDisplay = "/" + Constants.getConstant(serverVersion, Constants.SERVERDISPLAY) + ".*/";
8787
aHelper.clickMenuItem (workbenchShell,
88-
new String[] {"&Window", "Show &View", "Servers"});
88+
new String[] {"&Window", "Show View", "Servers"});
8989

9090
aHelper.rightClickItem (workbenchShell, serverDisplay,
9191
new String[] {"S&top"});
@@ -111,12 +111,12 @@ public void removeServer () throws MultipleFoundException, NotFoundException {
111111
}
112112

113113
public void publishAllProjects () throws MultipleFoundException, NotFoundException {
114-
String serverDisplay = Constants.getConstant(serverVersion, Constants.SERVERDISPLAY);
114+
String serverDisplay = "/" + Constants.getConstant(serverVersion, Constants.SERVERDISPLAY) + ".*/";
115115

116116
aHelper.clickMenuItem (workbenchShell,
117-
new String[] {"&Window", "Show &View", "Servers"});
117+
new String[] {"&Window", "Show View", "Servers"});
118118
Shell deployShell = aHelper.rightClickItem (workbenchShell, serverDisplay,
119-
new String[] {"Add and Remove &Projects..."}, "Add and Remove Projects");
119+
new String[] {"&Add and Remove..."}, "Add and Remove...");
120120
aHelper.clickButton (deployShell, "Add A&ll >>");
121121

122122
aHelper.clickButton (deployShell, IDialogConstants.FINISH_LABEL);

testsuite/plugins/org.apache.geronimo.testsuite.common/src/main/java/org/apache/geronimo/testsuite/common/ui/WorkbenchTasks.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public void showJEEPerspective() throws MultipleFoundException, NotFoundExceptio
4040
Shell perspectiveShell = aHelper.clickMenuItem (workbenchShell,
4141
new String[] {"&Window", "&Open Perspective", "&Other..." },
4242
"Open Perspective");
43-
aHelper.clickItem (perspectiveShell, "Java EE (default)");
43+
aHelper.clickItem (perspectiveShell, "Java EE");
4444
aHelper.clickButton (perspectiveShell, IDialogConstants.OK_LABEL);
4545
}
4646
}

testsuite/plugins/org.apache.geronimo.testsuite.v20/src/main/java/org/apache/geronimo/testsuite/v20/ui/EclipseUITest.java

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,18 @@ public void testEclipseUI()
4545
{
4646
boolean success = false;
4747
try {
48+
// About Eclipse Test Case. There are three Shell newShell, nextShell and nextNextShell
49+
//used because we need to save the states for newShell and nextShell
50+
//newShell->nextShell->nextNextShell this is the order in which shell comes up
51+
aShell = WorkbenchUtilities.getWorkbenchWindow().getShell();
52+
aHelper = new AbbotHelper(aShell);
53+
Shell newShell = aHelper.clickMenuItem(aShell, new String[]{"&Help","&About Eclipse Platform"},"About Eclipse Platform");
54+
Shell nextShell = aHelper.clickImageButton(newShell, "Apache Software Foundation","About Eclipse Platform Features");
55+
Shell nextNextShell = aHelper.clickButton(nextShell, "&Plug-in Details", "Feature Plug-ins");
56+
aHelper.clickButton(nextNextShell, IDialogConstants.CLOSE_LABEL);
57+
aHelper.clickButton(nextShell, IDialogConstants.CLOSE_LABEL);
58+
aHelper.clickButton(newShell, IDialogConstants.OK_LABEL);
59+
4860
success = true;
4961
}
5062
catch(Exception e)

testsuite/plugins/org.apache.geronimo.testsuite.v20/src/main/java/org/apache/geronimo/testsuite/v20/ui/NewServerTest.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717

1818
package org.apache.geronimo.testsuite.v20.ui;
1919

20-
import org.apache.geronimo.testsuite.common.selenium.EclipseSelenium;
2120
import org.apache.geronimo.testsuite.common.ui.AbbotHelper;
2221
import org.apache.geronimo.testsuite.common.ui.Constants;
2322
import org.apache.geronimo.testsuite.common.ui.ServerTasks;
@@ -65,20 +64,23 @@ public void testAllGeronimoGUI() {
6564

6665
serverTasks.startServer();
6766

68-
EclipseSelenium selenium = new EclipseSelenium();
69-
selenium.start();
67+
// EclipseSelenium selenium = new EclipseSelenium();
68+
// selenium.start();
7069

71-
selenium.open( "http://localhost:8080/console/" );
72-
selenium.waitForPageToLoad( "2000" );
73-
selenium.type("j_username", "system");
74-
selenium.type("j_password", "manager");
75-
selenium.click("submit");
7670

71+
// selenium.open( "http://localhost:8080/console/" );
72+
// selenium.waitForPageToLoad( "2000" );
73+
// selenium.type("j_username", "system");
74+
// selenium.type("j_password", "manager");
75+
// selenium.click("submit");
76+
//
7777
serverTasks.stopServer();
78-
79-
// remove the server
78+
//
79+
// // remove the server
8080
serverTasks.removeServer();
81-
selenium.stop();
81+
82+
//selenium.stop();
83+
//ds.stop();
8284

8385
success = true;
8486
}

testsuite/plugins/org.apache.geronimo.testsuite.v20/src/main/java/org/apache/geronimo/testsuite/v20/ui/RunOnServerTest.java

Lines changed: 1 addition & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,6 @@
1919

2020
import java.io.FileInputStream;
2121

22-
import org.apache.geronimo.testsuite.common.AssertUtil;
23-
import org.apache.geronimo.testsuite.common.selenium.EclipseSelenium;
2422
import org.apache.geronimo.testsuite.common.ui.AbbotHelper;
2523
import org.apache.geronimo.testsuite.common.ui.Constants;
2624
import org.apache.geronimo.testsuite.common.ui.ProjectTasks;
@@ -60,7 +58,6 @@ protected void tearDown() throws Exception {
6058

6159
public void testRunOnServer() {
6260
createServer();
63-
startServer();
6461
createProject();
6562
copyCodeToProject();
6663
deployProject();
@@ -85,19 +82,6 @@ private void createServer() {
8582
}
8683

8784

88-
private void startServer() {
89-
success = false;
90-
try {
91-
ServerTasks serverTasks = new ServerTasks(workbenchShell, abbotHelper, Constants.SERVER_V20 );
92-
success = true;
93-
}
94-
catch (Exception e) {
95-
e.printStackTrace();
96-
}
97-
assertTrue( success );
98-
}
99-
100-
10185
private void createProject() {
10286
success = false;
10387
try {
@@ -124,7 +108,7 @@ private void copyCodeToProject() {
124108
try {
125109
IWorkspaceRoot aWSRoot = ResourcesPlugin.getWorkspace().getRoot();
126110
IProject aProject = aWSRoot.getProject ("DynamicWebProject");
127-
String fileDir = aWSRoot.getLocation().toOSString() + "/src/main/resources/run-on-server";
111+
String fileDir = aWSRoot.getLocation().toOSString() + "/src/main/resources/run-on-server";// when run in eclipse, you should change
128112
IFile aFile = aProject.getFile("WebContent/index.jsp");
129113
aFile.create(new FileInputStream (fileDir + "/index.jsp"), true, null);
130114
abbotHelper.waitTime( 1500 );

0 commit comments

Comments
 (0)