Skip to content
This repository was archived by the owner on Nov 15, 2022. It is now read-only.

Commit 6d6e26c

Browse files
sumauppayaminikb
authored andcommitted
Fixes #21981 : Fixed intermittent failures in admin GUI dev tests (#21982)
1 parent fb3731e commit 6d6e26c

File tree

8 files changed

+108
-44
lines changed

8 files changed

+108
-44
lines changed

appserver/admingui/cluster/src/main/resources/cluster/clusterResources.jsf

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@
4545
<!initPage
4646
setResourceBundle(key="i18ncs" bundle="org.glassfish.cluster.admingui.Strings")
4747
setResourceBundle(key="i18nc" bundle="org.glassfish.common.admingui.Strings")
48+
setResourceBundle(key="i18n" bundle="org.glassfish.admingui.core.Strings")
4849
setResourceBundle(key="help_cluster" bundle="org.glassfish.cluster.admingui.Helplinks");
4950
/>
5051
<!composition template="/templates/default.layout" guiTitle="$resource{i18ncs.cluster.ResourcesTitle}" >

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/AvailabilityServiceTest.java

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,8 +73,7 @@ public void testAvailabilityService() {
7373
clickAndWait("propertyForm:propertyContentPage:topButtons:saveButton", TRIGGER_NEW_VALUES_SAVED);
7474
}
7575

76-
//TODO IDCINTER-41 and GLASSFISH-21710
77-
//@Test
76+
@Test
7877
public void testWebContainerAvailability() {
7978
if (!isTextPresent(TRIGGER_AVAILABILTY_SERVICE_NODE)) {
8079
clickAndWait(ID_DEFAULT_CONFIG_TURNER, TRIGGER_AVAILABILTY_SERVICE_NODE);
@@ -92,8 +91,7 @@ public void testWebContainerAvailability() {
9291
clickAndWait("propertyForm:propertyContentPage:topButtons:saveButton", TRIGGER_NEW_VALUES_SAVED);
9392
}
9493

95-
//TODO IDCINTER-41 and GLASSFISH-21710
96-
//@Test
94+
@Test
9795
public void testEjbContainerAvailability() {
9896
if (!isTextPresent(TRIGGER_AVAILABILTY_SERVICE_NODE)) {
9997
clickAndWait(ID_DEFAULT_CONFIG_TURNER, TRIGGER_AVAILABILTY_SERVICE_NODE);

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/BaseSeleniumTestClass.java

Lines changed: 43 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,14 @@
4747

4848
import java.io.*;
4949
import java.math.BigInteger;
50+
import java.net.InetAddress;
5051
import java.net.URL;
5152
import java.security.SecureRandom;
5253
import java.util.*;
5354
import java.util.concurrent.TimeUnit;
5455
import java.util.logging.Level;
5556
import java.util.logging.Logger;
57+
import org.apache.commons.io.FileUtils;
5658
import org.glassfish.admingui.common.util.RestUtil;
5759
import org.glassfish.admingui.devtests.util.ElementFinder;
5860
import org.glassfish.admingui.devtests.util.SeleniumHelper;
@@ -130,7 +132,8 @@ public static void captureLog() {
130132
helper.releaseSeleniumInstance();
131133

132134
if (!currentTestClass.isEmpty() && !DEBUG) {
133-
URL url = new URL("http://localhost:" + SeleniumHelper.getParameter("admin.port", "4848") + "/management/domain/view-log");
135+
String hostName = InetAddress.getLocalHost().getCanonicalHostName();
136+
URL url = new URL("http://" + hostName + ":" + SeleniumHelper.getParameter("admin.port", "4848") + "/management/domain/view-log");
134137
InputStream is = url.openStream();
135138
PrintWriter out = new PrintWriter(new BufferedWriter(new FileWriter("target/surefire-reports/" + currentTestClass + "-server.log")));
136139
BufferedReader in = new BufferedReader(new InputStreamReader(is));
@@ -408,8 +411,22 @@ public void openAndWait(String url, String triggerText, int timeout) {
408411
public void openAndWaitForHomePage(String url, String triggerText, int timeout) {
409412
open(url);
410413
if (IS_SECURE_ADMIN_ENABLED) {
411-
waitForLoginPageLoad(timeout);
412-
handleLogin("admin", "admin", triggerText);
414+
try {
415+
waitForLoginPageLoad(timeout);
416+
String passwordFile = SeleniumHelper.getParameter("passwordfile", "");
417+
String password = FileUtils.readFileToString(new File(passwordFile));
418+
if(password.isEmpty() || !(password.startsWith("AS_ADMIN_PASSWORD=")) || password.length() <= 18) {
419+
throw new Exception("Password is not set correctly.");
420+
} else {
421+
int index = password.indexOf("=");
422+
password = password.substring(index + 1, password.length() - 1);
423+
}
424+
handleLogin("admin", password, triggerText);
425+
} catch (IOException ex) {
426+
Logger.getLogger(BaseSeleniumTestClass.class.getName()).log(Level.SEVERE, null, ex);
427+
} catch (Exception ex) {
428+
Logger.getLogger(BaseSeleniumTestClass.class.getName()).log(Level.SEVERE, null, ex);
429+
}
413430
} else {
414431
waitForPageLoad(triggerText, timeout);
415432
}
@@ -624,7 +641,7 @@ protected String getLinkIdByLinkText(final String baseId, final String value) {
624641
final ExceptionSwallowingLoop<String> loop = new ExceptionSwallowingLoop<String>() {
625642
@Override
626643
public String operation() {
627-
WebElement link = elementFinder.findElement(By.linkText(value), TIMEOUT);
644+
WebElement link = elementFinder.findElement(By.id(baseId).linkText(value), TIMEOUT);
628645
return (link == null) ? null : (String) link.getAttribute("id");
629646
}
630647
};
@@ -806,16 +823,9 @@ protected int addTableRow(String tableId, String buttonId, String countLabel) {
806823
protected void assertTableRowCount(String tableId, int count) {
807824
Assert.assertEquals(count, getTableRowCount(tableId));
808825
}
809-
826+
810827
protected void waitForTableRowCount(String tableID, int count) {
811-
WebDriverWait wait = new WebDriverWait(driver, 5);
812-
wait.until(presenceOfElementLocated(By.id(tableID)));
813-
try {
814-
int tableCount = getTableRowCount(tableID);
815-
} catch (Exception e) {
816-
e.printStackTrace();
817-
}
818-
sleep(500);
828+
waitForLoad(TIMEOUT, new TableRowCountCallBack(tableID, count));
819829
}
820830

821831
// Look at all those params. Maybe this isn't such a hot idea.
@@ -1158,6 +1168,26 @@ public boolean executeTest() {
11581168
}
11591169
};
11601170

1171+
class TableRowCountCallBack implements WaitForLoadCallBack {
1172+
private String tableId;
1173+
private int expectedCount;
1174+
1175+
public TableRowCountCallBack(String tableId, int expectedCount) {
1176+
this.tableId = tableId;
1177+
this.expectedCount = expectedCount;
1178+
}
1179+
1180+
@Override
1181+
public boolean executeTest() {
1182+
try {
1183+
int count = getTableRowCount(tableId);
1184+
return (count == expectedCount);
1185+
} catch (SeleniumException se) {
1186+
return false;
1187+
}
1188+
}
1189+
}
1190+
11611191
class ButtonDisabledStateCallBack implements WaitForLoadCallBack {
11621192
private String buttonId;
11631193
private boolean desiredState;

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/ClusterTest.java

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -326,8 +326,7 @@ public void gotoClusterInstancesPage(String clusterName) {
326326
clickAndWait("propertyForm:clusterTabs:clusterInst", TRIGGER_CLUSTER_INSTANCES_PAGE);
327327
}
328328

329-
//TODO-IDCINTER-41 Intermittent failures
330-
//@Test
329+
@Test
331330
public void testClusterResourcesPage() {
332331
final String jndiName = "jdbcResource" + generateRandomString();
333332
String target = "cluster" + generateRandomString();
@@ -337,9 +336,7 @@ public void testClusterResourcesPage() {
337336
JdbcTest jdbcTest = new JdbcTest();
338337
jdbcTest.createJDBCResource(jndiName, description, target, MonitoringTest.TARGET_CLUSTER_TYPE);
339338

340-
clickAndWait("treeForm:tree:clusterTreeNode:clusterTreeNode_link", TRIGGER_CLUSTER_PAGE);
341-
clickAndWait(getLinkIdByLinkText(ID_CLUSTERS_TABLE, target), TRIGGER_CLUSTER_GENERAL_PAGE);
342-
clickAndWait("propertyForm:clusterTabs:clusterResources", TRIGGER_CLUSTER_RESOURCES_PAGE);
339+
goToClusterResourcesPage(target);
343340
assertTrue(isTextPresent(jndiName));
344341

345342
int jdbcCount = getTableRowCountByValue(tableID, "JDBC Resources", "col3:type");
@@ -348,13 +345,16 @@ public void testClusterResourcesPage() {
348345
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "Custom Resources");
349346
waitForTableRowCount(tableID, customCount);
350347

348+
goToClusterResourcesPage(target);
349+
351350
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "JDBC Resources");
352351
waitForTableRowCount(tableID, jdbcCount);
353352

353+
goToClusterResourcesPage(target);
354+
354355
selectTableRowByValue("propertyForm:resourcesTable", jndiName);
355-
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
356356
pressButton("propertyForm:resourcesTable:topActionsGroup1:button1");
357-
waitForButtonDisabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
357+
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
358358
jdbcTest.deleteJDBCResource(jndiName, target, MonitoringTest.TARGET_CLUSTER_TYPE);
359359
}
360360

@@ -464,4 +464,10 @@ public void stopAllClusterInstances(String clusterName) {
464464
this.waitForButtonDisabled("propertyForm:instancesTable:topActionsGroup1:button3");
465465
}
466466
}
467+
private void goToClusterResourcesPage(String clusterName) {
468+
reset();
469+
clickAndWait("treeForm:tree:clusterTreeNode:clusterTreeNode_link", TRIGGER_CLUSTER_PAGE);
470+
clickAndWait(getLinkIdByLinkText(ID_CLUSTERS_TABLE, clusterName), TRIGGER_CLUSTER_GENERAL_PAGE);
471+
clickAndWait("propertyForm:clusterTabs:clusterResources", TRIGGER_CLUSTER_RESOURCES_PAGE);
472+
}
467473
}

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/EnterpriseServerTest.java

Lines changed: 16 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,7 @@ public void testSystemProperties() {
116116
assertTableRowCount("propertyForm:sysPropsTable", count);
117117
}
118118

119-
//TODO IDCINTER-41 Intermittent failures
120-
//@Test
119+
@Test
121120
public void testServerResourcesPage() {
122121
final String jndiName = "jdbcResource"+generateRandomString();
123122
final String description = "devtest test for server->resources page- " + jndiName;
@@ -126,8 +125,7 @@ public void testServerResourcesPage() {
126125
JdbcTest jdbcTest = new JdbcTest();
127126
jdbcTest.createJDBCResource(jndiName, description, "server", MonitoringTest.TARGET_SERVER_TYPE);
128127

129-
gotoDasPage();
130-
clickAndWait("propertyForm:serverInstTabs:resources", TRIGGER_RESOURCES);
128+
gotoServerResourcesPage();
131129
assertTrue(isTextPresent(jndiName));
132130

133131
int jdbcCount = getTableRowCountByValue(tableID, "JDBC Resources", "col3:type");
@@ -136,12 +134,19 @@ public void testServerResourcesPage() {
136134
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "Custom Resources");
137135
waitForTableRowCount(tableID, customCount);
138136

137+
gotoServerResourcesPage();
138+
139139
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "JDBC Resources");
140140
waitForTableRowCount(tableID, jdbcCount);
141141

142+
gotoServerResourcesPage();
142143
selectTableRowByValue("propertyForm:resourcesTable", jndiName);
143-
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
144144
pressButton("propertyForm:resourcesTable:topActionsGroup1:button1");
145+
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
146+
147+
gotoServerResourcesPage();
148+
selectTableRowByValue("propertyForm:resourcesTable", jndiName);
149+
pressButton("propertyForm:resourcesTable:topActionsGroup1:button2");
145150
waitForButtonDisabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
146151

147152
/*selenium.select("propertyForm:resourcesTable:topActionsGroup1:actions", "JDBC Resources");
@@ -154,4 +159,10 @@ public void testServerResourcesPage() {
154159
public void gotoDasPage() {
155160
clickAndWait("treeForm:tree:applicationServer:applicationServer_link", TRIGGER_GENERAL_INFORMATION);
156161
}
162+
163+
private void gotoServerResourcesPage() {
164+
reset();
165+
gotoDasPage();
166+
clickAndWait("propertyForm:serverInstTabs:resources", TRIGGER_RESOURCES);
167+
}
157168
}

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/JavaMessageServiceTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -146,18 +146,23 @@ public void testJmsHostInNonServerConfig() {
146146
sat.deleteAllStandaloneInstances();
147147
}
148148

149-
//TODO IDCINTER-41 Intermittent failures
150-
//@Test
149+
@Test
151150
public void testJmsPhysicalDestinations() {
152151
final String name = "dest" + generateRandomString();
153152
final String maxUnconsumed = Integer.toString(generateRandomNumber(100));
154153
final String maxMessageSize = Integer.toString(generateRandomNumber(100));
155154
final String maxTotalMemory = Integer.toString(generateRandomNumber(100));
156155
final String maxProducers = Integer.toString(generateRandomNumber(500));
157156
final String consumerFlowLimit = Integer.toString(generateRandomNumber(5000));
157+
final String instanceName = "in" + generateRandomString();
158+
159+
StandaloneTest sat = new StandaloneTest();
160+
sat.deleteAllStandaloneInstances();
161+
sat.createStandAloneInstance(instanceName);
162+
sat.startInstance(instanceName);
158163

159-
clickAndWait("treeForm:tree:applicationServer:applicationServer_link", TRIGGER_GENERAL_INFORMATION);
160-
clickAndWait("propertyForm:serverInstTabs:jmsPhysDest", TRIGGER_JMS_PHYSICAL_DESTINATIONS);
164+
clickAndWait(getLinkIdByLinkText(sat.ID_INSTANCE_TABLE, instanceName), sat.TRIGGER_GENERAL_INFO_PAGE);
165+
clickAndWait("propertyForm:standaloneInstanceTabs:jmsPhysDest", TRIGGER_JMS_PHYSICAL_DESTINATIONS);
161166
clickAndWait("propertyForm:configs:topActionsGroup1:newButton", TRIGGER_NEW_JMS_PHYSICAL_DESTINATION);
162167

163168
setFieldValue("jmsPhysDestForm:propertySheet:propertSectionTextField:NameTextProp:NameText", name);
@@ -192,9 +197,9 @@ public void testJmsPhysicalDestinations() {
192197
clickAndWait("propertyForm:configs:topActionsGroup1:flushButton", TRIGGER_FLUSH);
193198
// this.selectTableRowByValue("propertyForm:configs", name); // Deselect row. This is ugly, but will have to stay this way for now
194199

195-
reset();
196-
clickAndWait("treeForm:tree:applicationServer:applicationServer_link", TRIGGER_GENERAL_INFORMATION);
197-
clickAndWait("propertyForm:serverInstTabs:jmsPhysDest", TRIGGER_JMS_PHYSICAL_DESTINATIONS);
200+
sat.gotoStandaloneInstancesPage();
201+
clickAndWait(getLinkIdByLinkText(sat.ID_INSTANCE_TABLE, instanceName), sat.TRIGGER_GENERAL_INFO_PAGE);
202+
clickAndWait("propertyForm:standaloneInstanceTabs:jmsPhysDest", TRIGGER_JMS_PHYSICAL_DESTINATIONS);
198203
deleteRow("propertyForm:configs:topActionsGroup1:deleteButton", "propertyForm:configs", name);
199204
}
200205

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/StandaloneTest.java

Lines changed: 12 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,7 @@ public void testProperties() {
138138
deleteStandAloneInstance(instanceName);
139139
}
140140

141-
//TODO IDCINTER-41 Intermittent failures
142-
//@Test
141+
@Test
143142
public void testStandaloneInstanceResourcesPage() {
144143
final String jndiName = "jdbcResource"+generateRandomString();
145144
String target = INSTANCE_PREFIX + generateRandomString();
@@ -149,9 +148,7 @@ public void testStandaloneInstanceResourcesPage() {
149148
JdbcTest jdbcTest = new JdbcTest();
150149
jdbcTest.createJDBCResource(jndiName, description, target, MonitoringTest.TARGET_STANDALONE_TYPE);
151150

152-
clickAndWait("treeForm:tree:standaloneTreeNode:standaloneTreeNode_link", TRIGGER_INSTANCES_PAGE);
153-
clickAndWait(getLinkIdByLinkText(ID_INSTANCE_TABLE, target), TRIGGER_GENERAL_INFO_PAGE);
154-
clickAndWait("propertyForm:standaloneInstanceTabs:resources", EnterpriseServerTest.TRIGGER_RESOURCES);
151+
gotoStandAloneInstanceResourcesPage(target);
155152
assertTrue(isTextPresent(jndiName));
156153

157154
int jdbcCount = getTableRowCountByValue(tableID, "JDBC Resources", "col3:type");
@@ -160,13 +157,15 @@ public void testStandaloneInstanceResourcesPage() {
160157
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "Custom Resources");
161158
waitForTableRowCount(tableID, customCount);
162159

160+
gotoStandAloneInstanceResourcesPage(target);
161+
163162
selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:filter_list", "JDBC Resources");
164163
waitForTableRowCount(tableID, jdbcCount);
165164

165+
gotoStandAloneInstanceResourcesPage(target);
166166
selectTableRowByValue("propertyForm:resourcesTable", jndiName);
167-
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
168167
pressButton("propertyForm:resourcesTable:topActionsGroup1:button1");
169-
waitForButtonDisabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
168+
waitForButtonEnabledMessage("propertyForm:resourcesTable:topActionsGroup1:button1");
170169

171170
/*selectDropdownOption("propertyForm:resourcesTable:topActionsGroup1:actions", "JDBC Resources");
172171
waitForPageLoad(JdbcTest.TRIGGER_NEW_JDBC_RESOURCE, true);
@@ -244,4 +243,10 @@ public void gotoStandaloneInstancesPage() {
244243
clickAndWait("treeForm:tree:standaloneTreeNode:standaloneTreeNode_link", TRIGGER_INSTANCES_PAGE);
245244
}
246245

246+
private void gotoStandAloneInstanceResourcesPage(String instanceName) {
247+
reset();
248+
clickAndWait("treeForm:tree:standaloneTreeNode:standaloneTreeNode_link", TRIGGER_INSTANCES_PAGE);
249+
clickAndWait(getLinkIdByLinkText(ID_INSTANCE_TABLE, instanceName), TRIGGER_GENERAL_INFO_PAGE);
250+
clickAndWait("propertyForm:standaloneInstanceTabs:resources", EnterpriseServerTest.TRIGGER_RESOURCES);
251+
}
247252
}

appserver/admingui/devtests/src/test/java/org/glassfish/admingui/devtests/util/SeleniumHelper.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
import com.thoughtworks.selenium.Selenium;
4343
import java.io.File;
4444
import java.io.FileOutputStream;
45+
import java.net.InetAddress;
46+
import java.net.UnknownHostException;
4547
import java.util.Random;
4648
import java.util.logging.Level;
4749
import java.util.logging.Logger;
@@ -114,7 +116,13 @@ public void releaseSeleniumInstance() {
114116
}
115117

116118
public String getBaseUrl() {
117-
return "http://localhost:" + getParameter("admin.port", "4848");
119+
String hostName = null;
120+
try {
121+
hostName = InetAddress.getLocalHost().getCanonicalHostName();
122+
} catch (UnknownHostException ex) {
123+
Logger.getLogger(SeleniumHelper.class.getName()).log(Level.SEVERE, null, ex);
124+
}
125+
return "http://" + hostName + ":" + getParameter("admin.port", "4848");
118126
}
119127

120128
public WebDriver getDriver() {

0 commit comments

Comments
 (0)