Author: ozizka(a)redhat.com
Date: 2009-01-08 08:05:56 -0500 (Thu, 08 Jan 2009)
New Revision: 102
Added:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Removed:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTest.java
Log:
Moved DatasourceTest to ...as5 package
Deleted: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTest.java 2009-01-08
11:57:04 UTC (rev 101)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTest.java 2009-01-08
13:05:56 UTC (rev 102)
@@ -1,394 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source.
- * Copyright 2008, Red Hat Middleware LLC, and individual contributors
- * as indicated by the @author tags. See the copyright.txt file in the
- * distribution for a full listing of individual contributors.
- *
- * This is free software; you can redistribute it and/or modify it
- * under the terms of the GNU Lesser General Public License as
- * published by the Free Software Foundation; either version 2.1 of
- * the License, or (at your option) any later version.
- *
- * This software is distributed in the hope that it will be useful,
- * but WITHOUT ANY WARRANTY; without even the implied warranty of
- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- * Lesser General Public License for more details.
- *
- * You should have received a copy of the GNU Lesser General Public
- * License along with this software; if not, write to the Free
- * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
- * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
- */
-
-package org.jboss.jopr.jsfunit;
-
-import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
-import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
-import com.gargoylesoftware.htmlunit.html.HtmlForm;
-import com.gargoylesoftware.htmlunit.html.HtmlImage;
-import com.gargoylesoftware.htmlunit.html.HtmlSelect;
-import com.gargoylesoftware.htmlunit.html.HtmlInput;
-import java.io.IOException;
-import junit.framework.Test;
-import junit.framework.TestSuite;
-import org.jboss.mx.util.MBeanServerLocator;
-import javax.management.MBeanServer;
-import javax.management.ObjectName;
-import java.util.Set;
-import java.util.Iterator;
-import org.jdom.Document;
-import org.jdom.Element;
-import org.jdom.input.SAXBuilder;
-import org.jdom.JDOMException;
-import java.io.File;
-import java.util.Map;
-import java.util.HashMap;
-import javax.naming.InitialContext;
-import java.sql.Connection;
-import javax.sql.DataSource;
-import javax.naming.Context;
-import java.sql.SQLException;
-import org.jboss.jopr.jsfunit.EmbjoprTestCase;
-
-/**
- * When complete, this class will contain tests for creating,
- * configuring, and deleting various types of datasources. This
- * test class should be run against JBAS 5.x.
- *
- * @author Farah Juma
- *
- */
-public class DatasourceTest extends EmbjoprTestCase {
-
- // Datasource types, as they appear in the left nav
- private final String LOCAL_TX_DATASOURCE="Local TX Datasources";
- private final String NO_TX_DATASOURCE="No TX Datasources";
- private final String XA_DATASOURCE="XA Datasources";
-
- /**
- * Create a new datasource using the given type, template, and properties.
- *
- * @param datasourceType must be the name of a datasource type, as it
- * appears in the left nav (eg. "Local TX Datasources")
- */
- private void createDatasource(String datasourceType,
- String datasourceTemplate,
- Map<String, String> propertiesMap) throws
IOException {
-
- // Expand the "Datasources" tree node
- HtmlImage resourceNodeImage = getNavTreeArrow("Datasources");
- resourceNodeImage.click();
-
- HtmlAnchor datasourceLink = getNavTreeLink(datasourceType);
- datasourceLink.click();
-
- // Add a new datasource
- client.click("actionHeaderForm:addNewNotContent");
- HtmlSelect menu = (HtmlSelect)client.getElement("selectedTemplate");
- menu.setSelectedAttribute(datasourceTemplate, Boolean.TRUE);
- client.click("resourceCreateForm:addButton");
-
- // Configure the properties associated with this datasource
- fillOutForm(propertiesMap);
- }
-
- /**
- * Delete the datasource given by datasourceName.
- */
- private void deleteDatasource(String datasourceName) throws IOException {
- HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
- datasourceLink.click();
- HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm",
- datasourceName);
- deleteButton.click();
- }
-
- /**
- * Use JMX to check if the datasource given by datasourceName is
- * deployed.
- */
- private boolean isDatasourceDeployed(String jndiName,
- String datasourceType) {
- try {
-
- ObjectName deploymentMBean;
- ObjectName objName;
- Object state;
- Set dsMBeans;
- String service;
-
- // One of the MBeans we will need to inspect depends on
- // the type of datasource
- if(datasourceType.equals(LOCAL_TX_DATASOURCE)) {
- service="LocalTxCM";
- } else if(datasourceType.equals(NO_TX_DATASOURCE)) {
- service="NoTxCM";
- } else {
- service="XATxCM";
- }
-
- String[] dsMBeanServices = {"DataSourceBinding",
- "ManagedConnectionPool",
- "ManagedConnectionFactory",
- service};
-
- // Query the MBean server to check if the datasource is deployed
- MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
-
- // Inspect the following MBeans and make sure that the "State"
attribute
- // is "DEPLOYED":
- // 1)
"jboss.jca:name=TestDS,service=DataSourceBinding",type=Component
- // 2)
"jboss.jca:name=TestDS,service=ManagedConnectionPool",type=Component
- // 3)
"jboss.jca:name=TestDS,service=ManagedConnectionFactory",type=Component
- // 4) The fourth MBean inspected depends on the type of datasource
- for(int i = 0; i < dsMBeanServices.length; i++) {
-
- objName = new
ObjectName("jboss.deployment:id=\"jboss.jca:name="
- + jndiName + ",service="
- + dsMBeanServices[i] + "\",type=Component");
-
- dsMBeans = jmxServer.queryNames(objName, null);
- if (dsMBeans.size() != 1) return false;
-
- deploymentMBean = (ObjectName)dsMBeans.iterator().next();
- state = jmxServer.getAttribute(deploymentMBean, "State");
- if(!("DEPLOYED".equals(state.toString()))) return false;
- }
-
- return true;
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
-
- /**
- * checkProperties reads the *-ds.xml file corresponding to the datasource
- * given by jndiName and compares the property values in this file to the
- * given expected values. checkProperties returns true if all the given
- * properties are correctly set in the *-ds.xml file and false otherwise.
- */
- private boolean checkProperties(String jndiName,
- String datasourceType,
- Map<String, String> expectedValuesMap) {
-
- Map<String, String> actualValuesMap = new HashMap<String, String>();
- String datasourceElementName;
-
- try {
-
- // Parse the *-ds.xml file
- File file = new File(System.getProperty("jsfunit.deploy.dir")
- + "/" + jndiName + "-ds.xml");
-
- SAXBuilder builder = new SAXBuilder();
- Document doc = builder.build(file);
-
- Element root = doc.getRootElement();
- assertTrue(root.getName().equals("datasources"));
-
- // Get the datasource element
- if(datasourceType.equals(LOCAL_TX_DATASOURCE)) {
- datasourceElementName="local-tx-datasource";
- } else if(datasourceType.equals(NO_TX_DATASOURCE)) {
- datasourceElementName="no-tx-datasource";
- } else {
- datasourceElementName="xa-datasource";
- }
- Element datasource = root.getChild(datasourceElementName);
-
- // Create actualValuesMap by mapping property names to
- // property values
- Iterator itr = (datasource.getChildren()).iterator();
- while(itr.hasNext()) {
- Element property = (Element)itr.next();
- actualValuesMap.put(property.getName(), property.getValue());
- }
-
- // Compare the actual values to the expected ones
- itr = expectedValuesMap.keySet().iterator();
- while(itr.hasNext()) {
- String key = (String)itr.next();
- if(actualValuesMap.containsKey(key)) {
- if(!expectedValuesMap.get(key).equals(actualValuesMap.get(key))) {
- return false; // incorrect value
- }
- } else {
- return false; // value was not set
- }
- }
-
- return true;
-
- } catch (Exception e) {
- throw new RuntimeException(e);
- }
- }
-
- /**
- * Connect to the database identified by the given JNDI name,
- * using the given username and password. Return the Connection
- * object.
- */
- public Connection connectDB(String jndiName, String username,
- String password) throws Exception{
- Context ctx = new InitialContext();
- DataSource ds = (DataSource)ctx.lookup(jndiName);
- return ds.getConnection(username, password);
- }
-
- /**
- * Disconnect from the database.
- */
- public void disconnectDB(Connection con) throws SQLException {
- if(con != null) {
- con.close();
- }
- }
-
- /**
- * @return the suite of tests being tested
- */
- public static Test suite()
- {
- return new TestSuite(DatasourceTest.class);
- }
-
- /*
- * Some preliminary creation tests
- */
-
- /**
- * Create a new datasource. Leave some property values that aren't
- * required unset.
- */
- public void testCreateDatasource() throws IOException {
- Map<String, String> propertiesMap = new HashMap<String, String>();
-
- // The properties we want to configure
- propertiesMap.put("jndi-name", "TestDS");
- propertiesMap.put("user-name", "testUser");
- propertiesMap.put("password", "password");
- propertiesMap.put("min-pool-size", "5");
- propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
- propertiesMap.put("connection-url", "jdbc:hsqldb:.");
- propertiesMap.put("idle-timeout-minutes", "20");
- propertiesMap.put("query-timeout", "180");
- propertiesMap.put("prepared-statement-cache-size", "2");
- propertiesMap.put("valid-connection-checker-class-name",
-
"org.jboss.resource.adapter.jdbc.CheckValidConnectionSQL");
- propertiesMap.put("stale-connection-checker-class-name",
-
"org.jboss.resource.adapter.jdbc.StaleConnectionChecker");
- propertiesMap.put("exception-sorter-class-name",
- "org.jboss.resource.adapter.jdbc.ExceptionSorter");
- propertiesMap.put("allocation-retry", "10000");
- propertiesMap.put("allocation-retry-wait-millis", "10000");
- propertiesMap.put("background-validation-millis", "15000");
- propertiesMap.put("use-try-lock", "61000");
- propertiesMap.put("prefill", "true");
- propertiesMap.put("share-prepared-statements", "false");
-
- createDatasource(LOCAL_TX_DATASOURCE,
- "default__Local TX Datasource",
- propertiesMap);
- client.click("resourceConfigurationForm:saveButton");
-
- // Check for the appropriate success messages
- String expectedMessage = "Successfully added new Local TX Datasource";
- checkClientAndServerMessages(expectedMessage, expectedMessage, false);
-
- assertTrue(isDatasourceDeployed(propertiesMap.get("jndi-name"),
- LOCAL_TX_DATASOURCE));
- assertTrue(checkProperties(propertiesMap.get("jndi-name"),
- LOCAL_TX_DATASOURCE,
- propertiesMap));
-
- // TODO: need to verify that appropriate default values were
- // set for properties that were not specified above
-
- // Clean up
- deleteDatasource(propertiesMap.get("jndi-name"));
- expectedMessage = "Successfully deleted Local TX Datasource '"
- + propertiesMap.get("jndi-name") +
"'";
- checkClientAndServerMessages(expectedMessage, expectedMessage, false);
- }
-
- /**
- * Attempt to create a new datasource but leave at least one required
- * value unset. An error should occur.
- */
- public void testCreateDatasourceMissingRequiredValues() throws IOException {
-
- // Leave jndi-name and connection-url unset
- Map<String, String> propertiesMap = new HashMap<String, String>();
- propertiesMap.put("user-name", "testUser");
- propertiesMap.put("max-pool-size", "10");
- propertiesMap.put("prefill", "true");
- propertiesMap.put("idle-timeout-minutes", "20");
- propertiesMap.put("set-tx-query-timeout", "true");
- propertiesMap.put("query-timeout", "1800");
-
- createDatasource(NO_TX_DATASOURCE, "default__No TX Datasource",
- propertiesMap);
- client.click("resourceConfigurationForm:saveButton");
-
- // Check for the appropriate error messages
- checkClientAndServerMessages("An invalid value was specified for one "
- + "or more properties",
- "Value is required",
- true);
- }
-
- /**
- * Attempt to create a new datasource but set a property value
- * beyond its expected range of values. An error should occur.
- */
- public void testCreateDatasourcePropertyOutOfRange() throws IOException {
- Map<String, String> propertiesMap = new HashMap<String, String>();
- propertiesMap.put("jndi-name", "InvalidDS");
- propertiesMap.put("user-name", "testUser");
- propertiesMap.put("password", "password");
- propertiesMap.put("xa-datasource-class",
"org.postgresql.xa.PGXADataSource");
- propertiesMap.put("xa-resource-timeout", "36000");
-
- // This number is too big
- propertiesMap.put("max-pool-size", "100000000000000");
-
- createDatasource(XA_DATASOURCE, "default__XA Datasource",
- propertiesMap);
- client.click("resourceConfigurationForm:saveButton");
-
- // Check for the appropriate error messages
- checkClientAndServerMessages("An invalid value was specified for one or more
properties",
- "Specified attribute is not between the
expected values",
- true);
- }
-
- /**
- * Attempt to create a new datasource but set a property value
- * to an invalid type. An error should occur.
- */
- public void testCreateDatasourceInvalidPropertyType() throws IOException {
- Map<String, String> propertiesMap = new HashMap<String, String>();
- propertiesMap.put("jndi-name", "InvalidDS");
- propertiesMap.put("min-pool-size", "10");
- propertiesMap.put("max-pool-size", "20");
- propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
- propertiesMap.put("connection-url", "jdbc:hsqldb:.");
- propertiesMap.put("share-prepared-statements", "false");
-
- // This property value is supposed to be an integer
- propertiesMap.put("background-validation-millis", "abcde");
-
- createDatasource(LOCAL_TX_DATASOURCE,
- "default__Local TX Datasource",
- propertiesMap);
- client.click("resourceConfigurationForm:saveButton");
-
- // Check for the appropriate error messages
- checkClientAndServerMessages("An invalid value was specified for one or more
properties",
- "Value is not a valid integer",
- true);
- }
-}
-
Copied: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java (from
rev 100, trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTest.java)
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
(rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java 2009-01-08
13:05:56 UTC (rev 102)
@@ -0,0 +1,395 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site:
http://www.fsf.org.
+ */
+
+package org.jboss.jopr.jsfunit.as5;
+
+import org.jboss.jopr.jsfunit.*;
+import com.gargoylesoftware.htmlunit.html.HtmlAnchor;
+import com.gargoylesoftware.htmlunit.html.HtmlButtonInput;
+import com.gargoylesoftware.htmlunit.html.HtmlForm;
+import com.gargoylesoftware.htmlunit.html.HtmlImage;
+import com.gargoylesoftware.htmlunit.html.HtmlSelect;
+import com.gargoylesoftware.htmlunit.html.HtmlInput;
+import java.io.IOException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import org.jboss.mx.util.MBeanServerLocator;
+import javax.management.MBeanServer;
+import javax.management.ObjectName;
+import java.util.Set;
+import java.util.Iterator;
+import org.jdom.Document;
+import org.jdom.Element;
+import org.jdom.input.SAXBuilder;
+import org.jdom.JDOMException;
+import java.io.File;
+import java.util.Map;
+import java.util.HashMap;
+import javax.naming.InitialContext;
+import java.sql.Connection;
+import javax.sql.DataSource;
+import javax.naming.Context;
+import java.sql.SQLException;
+import org.jboss.jopr.jsfunit.EmbjoprTestCase;
+
+/**
+ * When complete, this class will contain tests for creating,
+ * configuring, and deleting various types of datasources. This
+ * test class should be run against JBAS 5.x.
+ *
+ * @author Farah Juma
+ *
+ */
+public class DatasourceTest extends EmbjoprTestCase {
+
+ // Datasource types, as they appear in the left nav
+ private final String LOCAL_TX_DATASOURCE="Local TX Datasources";
+ private final String NO_TX_DATASOURCE="No TX Datasources";
+ private final String XA_DATASOURCE="XA Datasources";
+
+ /**
+ * Create a new datasource using the given type, template, and properties.
+ *
+ * @param datasourceType must be the name of a datasource type, as it
+ * appears in the left nav (eg. "Local TX Datasources")
+ */
+ private void createDatasource(String datasourceType,
+ String datasourceTemplate,
+ Map<String, String> propertiesMap) throws
IOException {
+
+ // Expand the "Datasources" tree node
+ HtmlImage resourceNodeImage = getNavTreeArrow("Datasources");
+ resourceNodeImage.click();
+
+ HtmlAnchor datasourceLink = getNavTreeLink(datasourceType);
+ datasourceLink.click();
+
+ // Add a new datasource
+ client.click("actionHeaderForm:addNewNotContent");
+ HtmlSelect menu = (HtmlSelect)client.getElement("selectedTemplate");
+ menu.setSelectedAttribute(datasourceTemplate, Boolean.TRUE);
+ client.click("resourceCreateForm:addButton");
+
+ // Configure the properties associated with this datasource
+ fillOutForm(propertiesMap);
+ }
+
+ /**
+ * Delete the datasource given by datasourceName.
+ */
+ private void deleteDatasource(String datasourceName) throws IOException {
+ HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
+ datasourceLink.click();
+ HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm",
+ datasourceName);
+ deleteButton.click();
+ }
+
+ /**
+ * Use JMX to check if the datasource given by datasourceName is
+ * deployed.
+ */
+ private boolean isDatasourceDeployed(String jndiName,
+ String datasourceType) {
+ try {
+
+ ObjectName deploymentMBean;
+ ObjectName objName;
+ Object state;
+ Set dsMBeans;
+ String service;
+
+ // One of the MBeans we will need to inspect depends on
+ // the type of datasource
+ if(datasourceType.equals(LOCAL_TX_DATASOURCE)) {
+ service="LocalTxCM";
+ } else if(datasourceType.equals(NO_TX_DATASOURCE)) {
+ service="NoTxCM";
+ } else {
+ service="XATxCM";
+ }
+
+ String[] dsMBeanServices = {"DataSourceBinding",
+ "ManagedConnectionPool",
+ "ManagedConnectionFactory",
+ service};
+
+ // Query the MBean server to check if the datasource is deployed
+ MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
+
+ // Inspect the following MBeans and make sure that the "State"
attribute
+ // is "DEPLOYED":
+ // 1)
"jboss.jca:name=TestDS,service=DataSourceBinding",type=Component
+ // 2)
"jboss.jca:name=TestDS,service=ManagedConnectionPool",type=Component
+ // 3)
"jboss.jca:name=TestDS,service=ManagedConnectionFactory",type=Component
+ // 4) The fourth MBean inspected depends on the type of datasource
+ for(int i = 0; i < dsMBeanServices.length; i++) {
+
+ objName = new
ObjectName("jboss.deployment:id=\"jboss.jca:name="
+ + jndiName + ",service="
+ + dsMBeanServices[i] + "\",type=Component");
+
+ dsMBeans = jmxServer.queryNames(objName, null);
+ if (dsMBeans.size() != 1) return false;
+
+ deploymentMBean = (ObjectName)dsMBeans.iterator().next();
+ state = jmxServer.getAttribute(deploymentMBean, "State");
+ if(!("DEPLOYED".equals(state.toString()))) return false;
+ }
+
+ return true;
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+
+ /**
+ * checkProperties reads the *-ds.xml file corresponding to the datasource
+ * given by jndiName and compares the property values in this file to the
+ * given expected values. checkProperties returns true if all the given
+ * properties are correctly set in the *-ds.xml file and false otherwise.
+ */
+ private boolean checkProperties(String jndiName,
+ String datasourceType,
+ Map<String, String> expectedValuesMap) {
+
+ Map<String, String> actualValuesMap = new HashMap<String, String>();
+ String datasourceElementName;
+
+ try {
+
+ // Parse the *-ds.xml file
+ File file = new File(System.getProperty("jsfunit.deploy.dir")
+ + "/" + jndiName + "-ds.xml");
+
+ SAXBuilder builder = new SAXBuilder();
+ Document doc = builder.build(file);
+
+ Element root = doc.getRootElement();
+ assertTrue(root.getName().equals("datasources"));
+
+ // Get the datasource element
+ if(datasourceType.equals(LOCAL_TX_DATASOURCE)) {
+ datasourceElementName="local-tx-datasource";
+ } else if(datasourceType.equals(NO_TX_DATASOURCE)) {
+ datasourceElementName="no-tx-datasource";
+ } else {
+ datasourceElementName="xa-datasource";
+ }
+ Element datasource = root.getChild(datasourceElementName);
+
+ // Create actualValuesMap by mapping property names to
+ // property values
+ Iterator itr = (datasource.getChildren()).iterator();
+ while(itr.hasNext()) {
+ Element property = (Element)itr.next();
+ actualValuesMap.put(property.getName(), property.getValue());
+ }
+
+ // Compare the actual values to the expected ones
+ itr = expectedValuesMap.keySet().iterator();
+ while(itr.hasNext()) {
+ String key = (String)itr.next();
+ if(actualValuesMap.containsKey(key)) {
+ if(!expectedValuesMap.get(key).equals(actualValuesMap.get(key))) {
+ return false; // incorrect value
+ }
+ } else {
+ return false; // value was not set
+ }
+ }
+
+ return true;
+
+ } catch (Exception e) {
+ throw new RuntimeException(e);
+ }
+ }
+
+ /**
+ * Connect to the database identified by the given JNDI name,
+ * using the given username and password. Return the Connection
+ * object.
+ */
+ public Connection connectDB(String jndiName, String username,
+ String password) throws Exception{
+ Context ctx = new InitialContext();
+ DataSource ds = (DataSource)ctx.lookup(jndiName);
+ return ds.getConnection(username, password);
+ }
+
+ /**
+ * Disconnect from the database.
+ */
+ public void disconnectDB(Connection con) throws SQLException {
+ if(con != null) {
+ con.close();
+ }
+ }
+
+ /**
+ * @return the suite of tests being tested
+ */
+ public static Test suite()
+ {
+ return new TestSuite(DatasourceTest.class);
+ }
+
+ /*
+ * Some preliminary creation tests
+ */
+
+ /**
+ * Create a new datasource. Leave some property values that aren't
+ * required unset.
+ */
+ public void testCreateDatasource() throws IOException {
+ Map<String, String> propertiesMap = new HashMap<String, String>();
+
+ // The properties we want to configure
+ propertiesMap.put("jndi-name", "TestDS");
+ propertiesMap.put("user-name", "testUser");
+ propertiesMap.put("password", "password");
+ propertiesMap.put("min-pool-size", "5");
+ propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
+ propertiesMap.put("connection-url", "jdbc:hsqldb:.");
+ propertiesMap.put("idle-timeout-minutes", "20");
+ propertiesMap.put("query-timeout", "180");
+ propertiesMap.put("prepared-statement-cache-size", "2");
+ propertiesMap.put("valid-connection-checker-class-name",
+
"org.jboss.resource.adapter.jdbc.CheckValidConnectionSQL");
+ propertiesMap.put("stale-connection-checker-class-name",
+
"org.jboss.resource.adapter.jdbc.StaleConnectionChecker");
+ propertiesMap.put("exception-sorter-class-name",
+ "org.jboss.resource.adapter.jdbc.ExceptionSorter");
+ propertiesMap.put("allocation-retry", "10000");
+ propertiesMap.put("allocation-retry-wait-millis", "10000");
+ propertiesMap.put("background-validation-millis", "15000");
+ propertiesMap.put("use-try-lock", "61000");
+ propertiesMap.put("prefill", "true");
+ propertiesMap.put("share-prepared-statements", "false");
+
+ createDatasource(LOCAL_TX_DATASOURCE,
+ "default__Local TX Datasource",
+ propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate success messages
+ String expectedMessage = "Successfully added new Local TX Datasource";
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+
+ assertTrue(isDatasourceDeployed(propertiesMap.get("jndi-name"),
+ LOCAL_TX_DATASOURCE));
+ assertTrue(checkProperties(propertiesMap.get("jndi-name"),
+ LOCAL_TX_DATASOURCE,
+ propertiesMap));
+
+ // TODO: need to verify that appropriate default values were
+ // set for properties that were not specified above
+
+ // Clean up
+ deleteDatasource(propertiesMap.get("jndi-name"));
+ expectedMessage = "Successfully deleted Local TX Datasource '"
+ + propertiesMap.get("jndi-name") +
"'";
+ checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+ }
+
+ /**
+ * Attempt to create a new datasource but leave at least one required
+ * value unset. An error should occur.
+ */
+ public void testCreateDatasourceMissingRequiredValues() throws IOException {
+
+ // Leave jndi-name and connection-url unset
+ Map<String, String> propertiesMap = new HashMap<String, String>();
+ propertiesMap.put("user-name", "testUser");
+ propertiesMap.put("max-pool-size", "10");
+ propertiesMap.put("prefill", "true");
+ propertiesMap.put("idle-timeout-minutes", "20");
+ propertiesMap.put("set-tx-query-timeout", "true");
+ propertiesMap.put("query-timeout", "1800");
+
+ createDatasource(NO_TX_DATASOURCE, "default__No TX Datasource",
+ propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages("An invalid value was specified for one "
+ + "or more properties",
+ "Value is required",
+ true);
+ }
+
+ /**
+ * Attempt to create a new datasource but set a property value
+ * beyond its expected range of values. An error should occur.
+ */
+ public void testCreateDatasourcePropertyOutOfRange() throws IOException {
+ Map<String, String> propertiesMap = new HashMap<String, String>();
+ propertiesMap.put("jndi-name", "InvalidDS");
+ propertiesMap.put("user-name", "testUser");
+ propertiesMap.put("password", "password");
+ propertiesMap.put("xa-datasource-class",
"org.postgresql.xa.PGXADataSource");
+ propertiesMap.put("xa-resource-timeout", "36000");
+
+ // This number is too big
+ propertiesMap.put("max-pool-size", "100000000000000");
+
+ createDatasource(XA_DATASOURCE, "default__XA Datasource",
+ propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages("An invalid value was specified for one or more
properties",
+ "Specified attribute is not between the
expected values",
+ true);
+ }
+
+ /**
+ * Attempt to create a new datasource but set a property value
+ * to an invalid type. An error should occur.
+ */
+ public void testCreateDatasourceInvalidPropertyType() throws IOException {
+ Map<String, String> propertiesMap = new HashMap<String, String>();
+ propertiesMap.put("jndi-name", "InvalidDS");
+ propertiesMap.put("min-pool-size", "10");
+ propertiesMap.put("max-pool-size", "20");
+ propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
+ propertiesMap.put("connection-url", "jdbc:hsqldb:.");
+ propertiesMap.put("share-prepared-statements", "false");
+
+ // This property value is supposed to be an integer
+ propertiesMap.put("background-validation-millis", "abcde");
+
+ createDatasource(LOCAL_TX_DATASOURCE,
+ "default__Local TX Datasource",
+ propertiesMap);
+ client.click("resourceConfigurationForm:saveButton");
+
+ // Check for the appropriate error messages
+ checkClientAndServerMessages("An invalid value was specified for one or more
properties",
+ "Value is not a valid integer",
+ true);
+ }
+}
+