Author: fjuma
Date: 2009-03-26 15:06:21 -0400 (Thu, 26 Mar 2009)
New Revision: 259
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Made sure that all connections get closed during the datasource tests.
Made a minor change to deleteDatasource() in as5/DatasourceTest.java.
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-26
14:57:02 UTC (rev 258)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-03-26
19:06:21 UTC (rev 259)
@@ -176,11 +176,6 @@
throws IOException, EmbJoprTestException;
/**
- * Delete the datasource given by datasourceName.
- */
- protected abstract void deleteDatasource(String datasourceName) throws IOException,
EmbJoprTestException;
-
- /**
* Use JMX to check if the datasource given by datasourceName is deployed.
*/
protected boolean isDatasourceDeployed(String jndiName, DatasourceType
datasourceType) {
@@ -330,8 +325,10 @@
* Close each Connection in the given ArrayList of Connections.
*/
public void closeConnections(ArrayList<Connection> connections) throws
SQLException {
- for(int i = 0; i < connections.size(); i++) {
- disconnectDB(connections.get(i));
+ if(connections != null) {
+ for(int i = 0; i < connections.size(); i++) {
+ disconnectDB(connections.get(i));
+ }
}
}
@@ -555,7 +552,7 @@
protected void checkMetrics(String datasourceName,
DatasourceType datasourceType,
Map<String, String> metricsMap) throws IOException,
EmbJoprTestException {
-
+
//refreshTreeNode(DS_NAV_LABEL);
ClickableElement datasourceTypeArrow =
getNavTreeArrow(datasourceType.getLabel());
datasourceTypeArrow.click();
@@ -588,7 +585,7 @@
String expected = metricsMap.get(metricName);
String actual = getMetricValueFromTable(metricName, "dataTable");
actual = normalizeIfDoubleExpected(expected, actual); // Some LOCALEs encode
doubles with coma.
- assertEquals("Incorrect summary metric value for
'"+metricName+"'='"+actual+"'," +
+ assertEquals("Incorrect summary metric value for '" +
metricName + "'='" + actual + "'," +
" expected '"+expected+"'",
expected, actual);
}
}
Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-26
14:57:02 UTC (rev 258)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-03-26
19:06:21 UTC (rev 259)
@@ -37,6 +37,7 @@
import org.jboss.managed.api.ComponentType;
import org.jboss.metatype.api.values.SimpleValueSupport;
import org.jboss.metatype.api.values.MetaValue;
+import org.jboss.jopr.jsfunit.exceptions.HtmlElementNotFoundException;
/**
* When complete, this class will contain tests for creating,
@@ -152,9 +153,14 @@
/**
* Delete the datasource given by datasourceName.
*/
- @Override
- protected void deleteDatasource(String datasourceName) throws IOException {
- HtmlAnchor datasourceLink = getNavTreeLink(DS_NAV_LABEL);
+ protected void deleteDatasource(String datasourceName,
+ DatasourceType datasourceType) throws IOException,
+ HtmlElementNotFoundException, EmbJoprTestException {
+ if(!ejtt.getNavTree().getNodeByLabel(DS_NAV_LABEL).isExpanded()) {
+ expandNavTreeArrow(DS_NAV_LABEL);
+ }
+
+ HtmlAnchor datasourceLink = getNavTreeLink(datasourceType.getLabel());
datasourceLink.click();
HtmlSelect menu = (HtmlSelect)client.getElement("currentPageSize");
@@ -164,13 +170,13 @@
HtmlButtonInput deleteButton;
try {
- deleteButton = getDeleteButton("categorySummaryForm",
datasourceName);
+ deleteButton = getDeleteButton("resourceSummaryForm",
datasourceName);
deleteButton.click();
} catch (IllegalStateException e) {
// The delete button was not found on this page
client.click("nextPage");
- deleteButton = getDeleteButton("categorySummaryForm",
datasourceName);
+ deleteButton = getDeleteButton("resourceSummaryForm",
datasourceName);
deleteButton.click();
}
}
@@ -258,7 +264,7 @@
// set for properties that were not specified above
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
}
/*
@@ -339,7 +345,7 @@
String expectedMessage = "Successfully deleted " +
datasourceType.getTypeName()
+ " '" +
propertiesMap.get("jndi-name") + "'";
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"), datasourceType);
checkClientAndServerMessages(expectedMessage, expectedMessage, false);
@@ -366,7 +372,7 @@
// MultipleDatasources-ds.xml contains two Local TX Datasources and
// a No TX Datasource. We will delete the No TX Datasource
(NoTXDeletionTest-ds.xml).
- deleteDatasource(jndiName);
+ deleteDatasource(jndiName, DatasourceType.NO_TX_DATASOURCE);
// Check for the appropriate success messages
String expectedMessage = "Successfully deleted "
@@ -427,7 +433,7 @@
DatasourceType.XA_DATASOURCE));
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.XA_DATASOURCE);
}
/**
@@ -469,7 +475,7 @@
DatasourceType.LOCAL_TX_DATASOURCE));
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
}
/**
@@ -503,7 +509,7 @@
DatasourceType.NO_TX_DATASOURCE));
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE);
}
/*
@@ -534,7 +540,7 @@
checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.XA_DATASOURCE, expectedMetrics);
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.XA_DATASOURCE);
}
/**
@@ -576,6 +582,7 @@
ArrayList<Connection> connections = createConnections(5,
propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
propertiesMap.get("password"));
+
closeConnections(connections);
performDatasourceOperation(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE, "Flush");
@@ -592,9 +599,9 @@
expectedMetrics.put("Min Size", "5.0");
checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE, expectedMetrics);
-
+
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
}
/**
@@ -640,7 +647,7 @@
actualResult.contains(expectedResult));
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE);
}
/**
@@ -681,42 +688,44 @@
ArrayList<Connection> connections = createConnections(4,
propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
propertiesMap.get("password"));
-
- performDatasourceOperation(propertiesMap.get("jndi-name"),
- DatasourceType.LOCAL_TX_DATASOURCE,
- "List Formatted Sub Pool Statistics");
-
- // Use the default formatter
- client.click("parametersForm:okButton");
+ try {
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
+ DatasourceType.LOCAL_TX_DATASOURCE,
+ "List Formatted Sub Pool Statistics");
- HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
- "(Show/Hide Details)");
- detailsLink.click();
+ // Use the default formatter
+ client.click("parametersForm:okButton");
- // Get the result of the operation
- HtmlForm form = (HtmlForm)client.getElement("operationHistoryForm");
- HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
- String actualResult = resultTextBox.getText();
+ HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
+ "(Show/Hide Details)");
+ detailsLink.click();
- String expectedResult = "Sub Pool Statistics: \nSub Pool Count: 1\n"
- +
"------------------------------------------------------\n\n"
- + "Track By Transaction: true\n"
- + "Available Connections Count: 16\n"
- + "Max Connections In Use Count:4\n"
- + "Connections Destroyed Count:0\n"
- + "Connections In Use Count:4\n"
- + "Total Block Time:0\n"
- + "Average Block Time For Sub Pool:0\n"
- + "Maximum Wait Time For Sub Pool:0\n"
- + "Total Timed Out:0";
-
- assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
- + "\n\nbut was:\n\n" + actualResult,
- actualResult.contains(expectedResult));
+ // Get the result of the operation
+ HtmlForm form =
(HtmlForm)client.getElement("operationHistoryForm");
+ HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
+ String actualResult = resultTextBox.getText();
- // Clean up
- closeConnections(connections);
- deleteDatasource(propertiesMap.get("jndi-name"));
+ String expectedResult = "Sub Pool Statistics: \nSub Pool Count:
1\n"
+ +
"------------------------------------------------------\n\n"
+ + "Track By Transaction: true\n"
+ + "Available Connections Count: 16\n"
+ + "Max Connections In Use Count:4\n"
+ + "Connections Destroyed Count:0\n"
+ + "Connections In Use Count:4\n"
+ + "Total Block Time:0\n"
+ + "Average Block Time For Sub Pool:0\n"
+ + "Maximum Wait Time For Sub Pool:0\n"
+ + "Total Timed Out:0";
+
+ assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
+ + "\n\nbut was:\n\n" + actualResult,
+ actualResult.contains(expectedResult));
+ } finally {
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
+ }
}
/**
@@ -756,45 +765,47 @@
ArrayList<Connection> connections = createConnections(10,
propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
propertiesMap.get("password"));
+ try {
+
+ // Close some connections
+ for(int i = 0; i < 2; i++) {
+ disconnectDB(connections.get(i));
+ connections.set(i, null);
+ }
- // Close some connections
- disconnectDB(connections.get(0));
- disconnectDB(connections.get(1));
-
- performDatasourceOperation(propertiesMap.get("jndi-name"),
- DatasourceType.LOCAL_TX_DATASOURCE,
- "List Formatted Sub Pool Statistics");
-
- // Use the default formatter
- client.click("parametersForm:okButton");
+ performDatasourceOperation(propertiesMap.get("jndi-name"),
+ DatasourceType.LOCAL_TX_DATASOURCE,
+ "List Formatted Sub Pool Statistics");
- HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
- "(Show/Hide Details)");
- detailsLink.click();
+ // Use the default formatter
+ client.click("parametersForm:okButton");
- // Get the result of the operation
- HtmlForm form = (HtmlForm)client.getElement("operationHistoryForm");
- HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
- String actualResult = resultTextBox.getText();
+ HtmlAnchor detailsLink = getLinkInsideForm("operationHistoryForm",
+ "(Show/Hide Details)");
+ detailsLink.click();
- String expectedResult = "Sub Pool Statistics: \nSub Pool Count: 1\n"
- +
"------------------------------------------------------\n\n"
- + "Track By Transaction: true\n"
- + "Available Connections Count: 12\n"
- + "Max Connections In Use Count:10\n"
- + "Connections Destroyed Count:0\n"
- + "Connections In Use Count:8";
-
- assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
- + "\n\nbut was:\n\n" + actualResult.substring(0,
actualResult.lastIndexOf("Total Block Time")),
- actualResult.contains(expectedResult));
+ // Get the result of the operation
+ HtmlForm form =
(HtmlForm)client.getElement("operationHistoryForm");
+ HtmlTextArea resultTextBox =
(HtmlTextArea)form.getFirstByXPath(".//textarea");
+ String actualResult = resultTextBox.getText();
- // Clean up
- for(int i = 2; i <=9; i++) {
- disconnectDB(connections.get(i));
+ String expectedResult = "Sub Pool Statistics: \nSub Pool Count:
1\n"
+ +
"------------------------------------------------------\n\n"
+ + "Track By Transaction: true\n"
+ + "Available Connections Count: 12\n"
+ + "Max Connections In Use Count:10\n"
+ + "Connections Destroyed Count:0\n"
+ + "Connections In Use Count:8";
+
+ assertTrue("Incorrect sub pool statistics - \nexpected:\n\n" +
expectedResult
+ + "\n\nbut was:\n\n" + actualResult.substring(0,
actualResult.lastIndexOf("Total Block Time")),
+ actualResult.contains(expectedResult));
+ } finally {
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
}
-
- deleteDatasource(propertiesMap.get("jndi-name"));
}
@@ -824,7 +835,7 @@
checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE, expectedMetrics);
// Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
}
/**
@@ -862,27 +873,31 @@
private void checkMetricsAfterInitialDBConnection(Map<String, String>
propertiesMap) throws Exception {
// Create the first connection
- Connection con = connectDB(propertiesMap.get("jndi-name"),
- propertiesMap.get("user-name"),
- propertiesMap.get("password"));
- assertNotNull(con);
+ ArrayList<Connection> connections = createConnections(1,
propertiesMap.get("jndi-name"),
+
propertiesMap.get("user-name"),
+
propertiesMap.get("password"));
+
+ try {
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put("Available Connection Count",
"19.0");
+ expectedMetrics.put("Connection Count", "5.0");
+ expectedMetrics.put("Connection Created Count", "5.0");
+ expectedMetrics.put("Connection Destroyed Count",
"0.0");
+ expectedMetrics.put("In Use Connection Count", "1.0");
+ expectedMetrics.put("Max Connections In Use Count",
"1.0");
+ expectedMetrics.put("Max Size", "20.0");
+ expectedMetrics.put("Min Size", "5.0");
- // Set up the expected values
- Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
- expectedMetrics.put("Available Connection Count", "19.0");
- expectedMetrics.put("Connection Count", "5.0");
- expectedMetrics.put("Connection Created Count", "5.0");
- expectedMetrics.put("Connection Destroyed Count", "0.0");
- expectedMetrics.put("In Use Connection Count", "1.0");
- expectedMetrics.put("Max Connections In Use Count", "1.0");
- expectedMetrics.put("Max Size", "20.0");
- expectedMetrics.put("Min Size", "5.0");
-
- checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE, expectedMetrics);
-
- // Clean up
- disconnectDB(con);
- deleteDatasource(propertiesMap.get("jndi-name"));
+ checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE, expectedMetrics);
+
+ } finally {
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.LOCAL_TX_DATASOURCE);
+ }
}
/**
@@ -923,23 +938,26 @@
ArrayList<Connection> connections = createConnections(6,
propertiesMap.get("jndi-name"),
propertiesMap.get("user-name"),
propertiesMap.get("password"));
+ try {
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put("Available Connection Count",
"14.0");
+ expectedMetrics.put("Connection Count", "6.0");
+ expectedMetrics.put("Connection Created Count", "6.0");
+ expectedMetrics.put("Connection Destroyed Count",
"0.0");
+ expectedMetrics.put("In Use Connection Count", "6.0");
+ expectedMetrics.put("Max Connections In Use Count",
"6.0");
+ expectedMetrics.put("Max Size", "20.0");
+ expectedMetrics.put("Min Size", "5.0");
- // Set up the expected values
- Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
- expectedMetrics.put("Available Connection Count", "14.0");
- expectedMetrics.put("Connection Count", "6.0");
- expectedMetrics.put("Connection Created Count", "6.0");
- expectedMetrics.put("Connection Destroyed Count", "0.0");
- expectedMetrics.put("In Use Connection Count", "6.0");
- expectedMetrics.put("Max Connections In Use Count", "6.0");
- expectedMetrics.put("Max Size", "20.0");
- expectedMetrics.put("Min Size", "5.0");
-
- checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE, expectedMetrics);
-
- // Clean up
- closeConnections(connections);
- deleteDatasource(propertiesMap.get("jndi-name"));
+ checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE, expectedMetrics);
+ } finally {
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE);
+ }
}
/**
@@ -981,29 +999,33 @@
propertiesMap.get("user-name"),
propertiesMap.get("password"));
- // Close some connections
- disconnectDB(connections.get(0));
- disconnectDB(connections.get(1));
+ try {
+
+ // Close some connections
+ for(int i = 0; i < 2; i++) {
+ disconnectDB(connections.get(i));
+ connections.set(i, null);
+ }
+
+ // Set up the expected values
+ Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
+ expectedMetrics.put("Available Connection Count",
"17.0");
+ expectedMetrics.put("Connection Count", "3.0");
+ expectedMetrics.put("Connection Created Count", "5.0");
+ expectedMetrics.put("Connection Destroyed Count", "0.0");
+ expectedMetrics.put("In Use Connection Count", "3.0");
+ expectedMetrics.put("Max Connections In Use Count",
"5.0");
+ expectedMetrics.put("Max Size", "20.0");
+ expectedMetrics.put("Min Size", "5.0");
- // Set up the expected values
- Map<String, String> expectedMetrics = new LinkedHashMap<String,
String>();
- expectedMetrics.put("Available Connection Count", "17.0");
- expectedMetrics.put("Connection Count", "3.0");
- expectedMetrics.put("Connection Created Count", "5.0");
- expectedMetrics.put("Connection Destroyed Count", "0.0");
- expectedMetrics.put("In Use Connection Count", "3.0");
- expectedMetrics.put("Max Connections In Use Count", "5.0");
- expectedMetrics.put("Max Size", "20.0");
- expectedMetrics.put("Min Size", "5.0");
-
- checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE, expectedMetrics);
-
- // Clean up
- for(int i = 2; i <= 4; i++) {
- disconnectDB(connections.get(i));
+ checkMetrics(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE, expectedMetrics);
+
+ } finally {
+
+ // Clean up
+ closeConnections(connections);
+ deleteDatasource(propertiesMap.get("jndi-name"),
DatasourceType.NO_TX_DATASOURCE);
}
-
- deleteDatasource(propertiesMap.get("jndi-name"));
}
}