[embjopr-commits] EMBJOPR SVN: r118 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as5 and 1 other directory.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Tue Jan 20 18:02:22 EST 2009


Author: ozizka at redhat.com
Date: 2009-01-20 18:02:22 -0500 (Tue, 20 Jan 2009)
New Revision: 118

Added:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Changing DatasourceTest subclasses. Since now, they should cover differences between DatasourceTestBase and EmbJopr for AS 4 / 5.

Added: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	                        (rev 0)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	2009-01-20 23:02:22 UTC (rev 118)
@@ -0,0 +1,244 @@
+/*
+ * 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.as4;
+
+import java.util.logging.Level;
+import java.util.logging.Logger;
+import org.jboss.jopr.jsfunit.*;
+import com.gargoylesoftware.htmlunit.html.*;
+import java.io.IOException;
+import junit.framework.Test;
+import junit.framework.TestSuite;
+import javax.management.ObjectName;
+import java.util.Map;
+import javax.management.JMException;
+
+
+
+
+/**
+ * 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 org.jboss.jopr.jsfunit.DatasourceTestBase {
+
+
+		@Override
+		public void setUp() throws IOException {
+			super.setUp();
+		}
+
+
+    
+    /**
+     * Create a new datasource using the given template and properties.
+     * 
+     * @param datasourceType is not used.
+		 * @param datasourceTemplate is the value of the HTML select option.
+     */
+    protected void createDatasource(DatasourceType datasourceType, // unused here, left for API compat.
+                                  String datasourceTemplate,
+                                  Map<String, String> propertiesMap) throws IOException {
+        
+        // Expand the "Datasources" tree node
+        HtmlAnchor warLink = getNavTreeLink("Datasources");
+				warLink.click();
+        
+				// Click on the "Add new resource" button
+				client.click("actionHeaderForm:addNewNotContent");  // 404 if setThrowExceptionOnFailingStatusCode(true) above
+
+				// Select the default datasource (other options: Oracle)
+				HtmlSelect menu = (HtmlSelect)client.getElement("resourceCreateForm:selectedTemplate");
+
+				menu.setSelectedAttribute(datasourceTemplate, true);
+
+				// Submit the form.    [Continue]
+				//HtmlSubmitInput submit = (HtmlSubmitInput) util.getFirstElementByXPath(util.getTabMenuBoxElement(), ".//input[@type='submit']");
+				//if( null == submit ){  fail("\"Continue\" button not found."); }
+				//submit.click();
+
+        client.click("resourceCreateForm:addButton");
+
+        // Configure the properties associated with this datasource
+        fillOutForm(propertiesMap);  
+    }
+
+		
+		/**
+		 * Properties for the datasource for AS4.
+		 *
+		 * AS 4 has Type selection as radio buttons ("Type")
+		 *
+		 * @returns the default properties from the base class overriden by properties for AS4.
+		 */
+		@Override
+		protected Map<String, String> createDatasourceProperties()
+		{
+				Map<String, String> propertiesMap = super.createDatasourceProperties();
+
+				// Additional or different properties for AS 4
+
+
+				return propertiesMap;
+
+		}
+
+
+
+
+		
+    /**
+     * Delete the datasource given by datasourceName.
+     */
+    protected void deleteDatasource(String datasourceName) throws IOException {
+        HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
+        datasourceLink.click();
+			//HtmlButtonInput deleteButton = getDeleteButton("resourceSummaryForm", datasourceName); /*categorySummaryForm*/
+			//deleteButton.click();
+			try {
+				((HtmlInput) getFirstElementByXPath(getRowByName(datasourceName), ".//input[text()='Delete']")).click();
+			} catch (AssertException ex) {
+				Logger.getLogger(DatasourceTest.class.getName()).log(Level.SEVERE, null, ex);
+			}
+    }
+    
+
+
+
+		
+		/**
+		 * AS 4 lowercases the file name.
+		 * @return
+		 */
+		@Override
+		protected String getDatasourceConfigFile() {
+			String jndiName = this.getDatasourceProperties().get("jndi-name");
+			return System.getProperty("jsfunit.deploy.dir") + "/" + jndiName.toLowerCase() + "-ds.xml";
+		}
+
+
+		/**
+		 * AS 4 has it simplier than AS 5.
+		 * @param jndiName
+		 * @param serviceName
+		 * @return
+		 */
+		@Override
+		protected String getMBeanName( String jndiName, String serviceName ){
+			return "jboss.jca:name="+jndiName+",service="+serviceName;
+		}
+
+    
+    
+    
+    /*
+     * 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 = getDatasourceProperties();
+
+				/*  AS 4: 
+					<option value="Oracle Local TX__Datasource">Oracle Local TX (Datasource)</option>
+					<option value="Oracle XA__Datasource">Oracle XA (Datasource)</option>
+					<option value="default__Datasource">default (Datasource)</option>
+				/**/
+        createDatasource(DatasourceType.LOCAL_TX_DATASOURCE, // unsued for AS 4
+                         "default__Datasource", // TODO: Differs! Split DatasourceType accordingly...
+                         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"), 
+                                        DatasourceType.LOCAL_TX_DATASOURCE));
+        assertTrue(checkProperties(propertiesMap.get("jndi-name"), 
+                                   DatasourceType.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);
+    }
+    
+
+
+
+
+
+
+
+
+		/**
+		 * @return the suite of tests being tested
+		 */
+		public static Test suite()
+		{
+			 return new TestSuite(DatasourceTest.class);
+		}
+
+
+
+
+
+
+		/**
+		 * AS 4 uses State and StateString attributes.
+		 * @param deploymentMBean
+		 * @return
+		 * @throws javax.management.JMException
+		 * @throws java.io.IOException
+		 */
+		@Override
+		protected boolean isMBeanStateDeployedImpl(ObjectName deploymentMBean)  throws JMException, IOException {
+
+			JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
+
+			Object state = jmxUtils.getMBeanAttribute(deploymentMBean, "StateString");
+			//if(!("3".equals(state.toString()))) return false; // started state
+			return !( "Started".equals(state.toString()) );
+
+		}
+
+		
+}// DatasourceTest.java for AS 4
+

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-01-20 22:51:51 UTC (rev 117)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java	2009-01-20 23:02:22 UTC (rev 118)
@@ -22,35 +22,15 @@
 
 package org.jboss.jopr.jsfunit.as5;
 
-import com.gargoylesoftware.htmlunit.html.ClickableElement;
 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 com.gargoylesoftware.htmlunit.html.*;
 import java.io.IOException;
+import java.util.*;
 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 java.util.ArrayList;
-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 javax.management.JMException;
 
 /**
  * When complete, this class will contain tests for creating, 
@@ -60,29 +40,30 @@
  * @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";
-    
-    private final String MAX_ITEMS_PER_PAGE="20";
-    
-    /**
+public class DatasourceTest extends DatasourceTestBase {
+
+	  private final String MAX_ITEMS_PER_PAGE="20";
+
+
+		/**
      * Create a new datasource using the given type, template, and properties.
+		 *
+		 * AS 5 version differs in menu tree structure - one more step.
+		 * Thus, this test is overriden from the Base class.
      * 
-     * @param datasourceType must be the name of a datasource type, as it 
-     * appears in the left nav (eg. "Local TX Datasources")
+     * @param datasourceType must be the a datasource type from DatasourceType enum.
+		 * It's label from the left nav (eg. "Local TX Datasources") is in getLabel() property.
+		 *
      */
-    private void createDatasource(String datasourceType, 
+		@Override
+    protected void createDatasource(DatasourceType datasourceType,
                                   String datasourceTemplate,
                                   Map<String, String> propertiesMap) throws IOException {
         
         // Expand the "Datasources" tree node
         ClickableElement datasourcesArrow = getNavTreeArrow("Datasources");
         datasourcesArrow.click();
-        HtmlAnchor datasourceLink = getNavTreeLink(datasourceType);
+        HtmlAnchor datasourceLink = getNavTreeLink(datasourceType.getLabel());
         datasourceLink.click();
         
         // Add a new datasource 
@@ -94,726 +75,119 @@
         // 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();
-        
-        HtmlSelect menu = (HtmlSelect)client.getElement("currentPageSize");
-        if(menu != null) {
-            menu.setSelectedAttribute(MAX_ITEMS_PER_PAGE, Boolean.TRUE);
-        }
-        
-        HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm", 
-                                                       datasourceName);
-        deleteButton.click();
-    }
-    
-    /**
-     * Make sure that the metrics corresponding to the given datasource 
-     * are correct. 
-     * 
-     * @param metricsMap maps metric names to the expected metric values.
-     */
-    private void checkMetrics(String datasourceName,
-                              String datasourceType,
-                              Map<String, String> metricsMap) throws IOException {
 
-        refreshTreeNode("Datasources");
-        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType);
-        datasourceTypeArrow.click();
 
-        HtmlAnchor datasource = getNavTreeLink(datasourceName);
-        datasource.click();
+		/**
+		 * Properties for the datasource for AS 5.
+		 * @returns the default properties from the base class overriden by properties for AS 5.
+		 */
+		@Override
+		protected Map<String, String> createDatasourceProperties()
+		{
+				Map<String, String> propertiesMap = super.createDatasourceProperties();
 
-        // Check values under the "Metrics" tab
-        HtmlAnchor metricsLink = (HtmlAnchor)client.getElement("metricsTab");
-        metricsLink.click();
+				// Additional or different properties for AS 5
+				propertiesMap.put("query-timeout", "180");
+				propertiesMap.put("share-prepared-statements", "false");
+        propertiesMap.put("stale-connection-checker-class-name",
+                          "org.jboss.resource.adapter.jdbc.StaleConnectionChecker");
+        propertiesMap.put("allocation-retry", "10000");
+        propertiesMap.put("allocation-retry-wait-millis", "10000");
 
-        for(Iterator i = metricsMap.keySet().iterator(); i.hasNext();) {
-            String metricName = (String)i.next();
-            assertEquals("Incorrect metric value for: " + metricName,
-                         metricsMap.get(metricName), 
-                         getMetricValueFromTable(metricName, "dataTable"));
-        }
+        propertiesMap.put("allocation-retry", "10000");
+        propertiesMap.put("allocation-retry-wait-millis", "10000");
 
-        // Check values under the "Summary" tab
-        HtmlAnchor summaryLink = (HtmlAnchor)client.getElement("summaryTab");
-        summaryLink.click();
+        propertiesMap.put("background-validation-millis", "15000");
+        propertiesMap.put("prefill", "true");
+        propertiesMap.put("use-try-lock", "61000");                
 
-        ArrayList<String> summaryMetrics = new ArrayList<String>();
-        summaryMetrics.add("Available Connection Count");
-        summaryMetrics.add("Connection Count");
-        
-        for(Iterator i = summaryMetrics.iterator(); i.hasNext();) {
-            String metricName = (String)i.next();
-            assertEquals("Incorrect metric value for: " + metricName,
-                         metricsMap.get(metricName), 
-                         getMetricValueFromTable(metricName, "dataTable"));
-        }
-    }
-        
-    /**
-     * Use JMX to check if the datasource given by datasourceName is 
-     * deployed.
-     */
-    private boolean isDatasourceDeployed(String jndiName, 
-                                         String datasourceType) {
-        try {
+				return propertiesMap;
 
-            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);
-        }
-    }
-    
-    /**
-     * containsElement returns whether or not the *-ds.xml file corresponding
-     * to the datasource given by jndiName contains the given element.
-     */
-    private boolean containsElement(String jndiName, String elementName) {
-        try {
-            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"));
-            return root.getChild(elementName) != null;   
-        } catch(Exception e) {
-            throw new RuntimeException(e);
-        }
-    }
-      
-    /**
-     * Perform the given operation on the given datasource.
-     */
-    private void performDatasourceOperation(String datasourceName,
-                                            String datasourceType,
-                                            String operationName) throws IOException {
-
-        refreshTreeNode("Datasources"); 
-        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType);
-        datasourceTypeArrow.click();
-
-        HtmlAnchor datasourceLink = getNavTreeLink(datasourceName);
+    
+    @Override
+    protected void deleteDatasource(String datasourceName) throws IOException {
+        HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
         datasourceLink.click();
 
-        HtmlAnchor controlLink = (HtmlAnchor)client.getElement("controlTab");
-        controlLink.click();
+        HtmlSelect menu = (HtmlSelect)client.getElement("currentPageSize");
+        if(menu != null) {
+            menu.setSelectedAttribute(MAX_ITEMS_PER_PAGE, Boolean.TRUE);
+        }
 
-        HtmlForm form = (HtmlForm)client.getElement("operation_form");
-        String xpath = ".//input[@value=\"" + operationName + "\"]";
-
-        HtmlButtonInput operationButton = (HtmlButtonInput)form.getFirstByXPath(xpath);
-        operationButton.click();
+        HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm", datasourceName);
+        deleteButton.click();
     }
 
-    
-    /**
-     * 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();  
-        } 
-    }
-    
-    /**
-     * Create a basic Local TX Datasource. Return the mapping of property
-     * names to property values.
-     */
-    private Map<String, String> createLocalTXDatasource(String datasourceName) throws IOException {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        propertiesMap.put("jndi-name", datasourceName);
-        propertiesMap.put("max-pool-size", "20");
-        propertiesMap.put("min-pool-size", "5");
-        propertiesMap.put("user-name", "sa");
-        propertiesMap.put("password", "");
-        propertiesMap.put("domain", "HsqlDbRealm");
-        propertiesMap.put("blocking-timeout-millis", "35000");
-        propertiesMap.put("idle-timeout-minutes", "20");
-        propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
-        propertiesMap.put("connection-url", "jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB");
 
-        createDatasource(LOCAL_TX_DATASOURCE, "default__Local TX Datasource", 
-                         propertiesMap);
-        client.click("resourceConfigurationForm:saveButton");
 
-        return propertiesMap;
-    }
 
-    /**
-     * Create a basic No TX Datasource. Return the mapping of property
-     * names to property values.
-     */
-    private Map<String, String> createNoTXDatasource(String datasourceName) throws IOException {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        propertiesMap.put("jndi-name", datasourceName);
-        propertiesMap.put("prefill", "true");
-        propertiesMap.put("track-connection-by-tx", "false");
-        propertiesMap.put("max-pool-size", "20");
-        propertiesMap.put("min-pool-size", "5");
-        propertiesMap.put("blocking-timeout-millis", "55000");
-        propertiesMap.put("idle-timeout-minutes", "60");
-        propertiesMap.put("noTxSeparatePools", "true");
-        propertiesMap.put("user-name", "sa");
-        propertiesMap.put("password", "");
-        propertiesMap.put("domain", "HsqlDbRealm");
-        propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
-        propertiesMap.put("connection-url", "jdbc:hsqldb:${jboss.server.data.dir}${/}hypersonic${/}localDB");
+		
 
-        createDatasource(NO_TX_DATASOURCE, "default__No TX Datasource", 
-                         propertiesMap);
-        client.click("resourceConfigurationForm:saveButton");
 
-        return propertiesMap;
-    }
 
-    /**
-     * Create a basic XA Datasource. Return the mapping of property
-     * name to property values.
-     */
-    private Map<String, String> createXADatasource(String datasourceName) throws IOException {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        propertiesMap.put("jndi-name", datasourceName);
-        propertiesMap.put("xa-datasource-class", "org.postgresql.xa.PGXADataSource");
-        propertiesMap.put("xa-resource-timeout", "36000");
-        propertiesMap.put("max-pool-size", "15");
-        propertiesMap.put("min-pool-size", "6");
+		@Override
+		protected boolean isMBeanStateDeployedImpl(ObjectName deploymentMBean)  throws JMException, IOException {
 
-        createDatasource(XA_DATASOURCE, "default__XA Datasource", 
-                         propertiesMap);
-        client.click("resourceConfigurationForm:saveButton");
+			JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
 
-        return propertiesMap;
-    }
+			Object state = jmxUtils.getMBeanAttribute(deploymentMBean, "State");
+			return !("DEPLOYED".equals( state.toString() ));
 
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite()
-    {
-       return new TestSuite(DatasourceTest.class);
-    }
-    
-    /*
-     * 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", "CreationTestDS");
-        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")); 
-    } 
     
-    /**
-     * 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);
+		@Override
+    protected Map<String, String> createLocalTXDatasource(String datasourceName) throws IOException {
+			return super.createLocalTXDatasource(datasourceName);
     }
-    
-    /**
-     * 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);
-    }
 
-    /**
-     * Attempt to create a new datasource but set a property value to a value 
-     * that is the correct type but is not an allowed value for that 
-     * property. An error should occur.
-     */
-    public void testCreateDatasourcePropertyNotAllowed() throws IOException {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        propertiesMap.put("jndi-name", "InvalidDS");
-        propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
-        propertiesMap.put("connection-url", "jdbc:hsqldb:.");
-
-        // This number is a valid integer but is below the
-        // allowable minimum value
-        propertiesMap.put("max-pool-size", "-25");
-
-        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 less than allowable minimum",
-                                     true);  
+		@Override
+    protected Map<String, String> createNoTXDatasource(String datasourceName) throws IOException {
+			return super.createNoTXDatasource(datasourceName);
     }
 
-    /**
-     * Attempt to create a new datasource using a JNDI name that already exists. 
-     * An error should occur.
-     */ 
-    public void testCreateDatasourceDuplicateJNDIName() throws IOException {
-        Map<String, String> propertiesMap = new HashMap<String, String>();
-        propertiesMap.put("jndi-name", "DefaultDS");
-        propertiesMap.put("driver-class", "org.hsqldb.jdbcDriver");
-        propertiesMap.put("connection-url", "jdbc:hsqldb:.");
-
-        createDatasource(LOCAL_TX_DATASOURCE, "default__Local TX Datasource", 
-                         propertiesMap);
-        client.click("resourceConfigurationForm:saveButton");
-
-        // Check for the appropriate error messages
-        String expectedMessage = "Failed to add Resource (see app server log for "
-                                 + "additional details):  A Local TX Datasource named "
-                                 + "'DefaultDS' already exists";
-        checkClientAndServerMessages(expectedMessage, expectedMessage, true);
-    } 
-
-    /*
-     * DELETION TESTS:
-     */
-
-    /**
-     * Remove a Local TX Datasource.
-     */ 
-    public void testDeleteLocalTXDatasource() throws Exception {  
-        Map<String, String> propertiesMap = createLocalTXDatasource("DeleteLocalTXDS");
-       
-        deleteDatasource(propertiesMap.get("jndi-name"));
-
-        // Check for the appropriate success messages
-        String expectedMessage = "Successfully deleted Local TX Datasource '" 
-                                 + propertiesMap.get("jndi-name") + "'";
-        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
-        
-        assertFalse(isDatasourceDeployed(propertiesMap.get("jndi-name"), 
-                                         LOCAL_TX_DATASOURCE));
-
-        // Make sure the entry was removed from the -ds.xml file
-        assertFalse(containsElement(propertiesMap.get("jndi-name"), 
-                                    "local-tx-datasource"));
+		@Override
+    protected Map<String, String> createXADatasource(String datasourceName) throws IOException {
+			return super.createXADatasource(datasourceName);
     }
 
-    /**
-     * Remove a No TX Datasource.
-     */
-    public void testDeleteNoTXDatasource() throws Exception {  
-        Map<String, String> propertiesMap = createNoTXDatasource("DeleteNoTXDS");
 
-        deleteDatasource(propertiesMap.get("jndi-name"));
 
-        // Check for the appropriate success messages
-        String expectedMessage = "Successfully deleted No TX Datasource '" 
-                                 + propertiesMap.get("jndi-name") + "'";
-        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
 
-        assertFalse(isDatasourceDeployed(propertiesMap.get("jndi-name"), 
-                                         NO_TX_DATASOURCE));
 
-        // Make sure the entry was removed from the -ds.xml file
-        assertFalse(containsElement(propertiesMap.get("jndi-name"), 
-                                    "no-tx-datasource"));
-    }
 
-    /**
-     * Remove an XA Datasource.
-     */
-    public void testDeleteXADatasource() throws Exception {  
-        Map<String, String> propertiesMap = createXADatasource("DeleteXADS");
 
-        deleteDatasource(propertiesMap.get("jndi-name"));
+		
 
-        // Check for the appropriate success messages
-        String expectedMessage = "Successfully deleted XA Datasource '" 
-                                 + propertiesMap.get("jndi-name") + "'";
-        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
-
-        assertFalse(isDatasourceDeployed(propertiesMap.get("jndi-name"), 
-                                         XA_DATASOURCE));
-
-        // Make sure the entry was removed from the -ds.xml file
-        assertFalse(containsElement(propertiesMap.get("jndi-name"), 
-                                    "xa-datasource"));
-    }
-    
-    /*
-     * METRICS TESTS
-     */
-
     /**
-     * Check that the metrics are correct after creating a new datasource.
+     * @return the suite of tests being tested
      */
-    public void testMetricsAfterDatasourceCreation() throws IOException {
-
-        // Min pool size will be 5, max pool size will be 20
-        Map<String, String> propertiesMap = createLocalTXDatasource("MetricsCreateDS");
-
-        // Set up the expected values
-        Map<String, String> expectedMetrics = new HashMap<String, String>();
-        expectedMetrics.put("Available Connection Count", "20.0");
-        expectedMetrics.put("Connection Count", "0.0"); 
-        expectedMetrics.put("Connection Created Count", "0.0");
-        expectedMetrics.put("Connection Destroyed Count", "0.0");
-        expectedMetrics.put("In Use Connection Count", "0.0");
-        expectedMetrics.put("Max Connections In Use Count", "0.0");
-        expectedMetrics.put("Max Size", "20.0");
-        expectedMetrics.put("Min Size", "5.0");
-
-        checkMetrics(propertiesMap.get("jndi-name"), LOCAL_TX_DATASOURCE, expectedMetrics);
-
-        // Clean up
-        deleteDatasource(propertiesMap.get("jndi-name"));   
+    public static Test suite()
+    {
+       return new TestSuite(DatasourceTest.class);
     }
+ 
 
-    /**
-     * Make an initial request for a connection to a database. Make
-     * sure the metrics are updated accordingly.
-     */
-    public void testMetricsAfterInitialDBConnection() throws Exception {
+		@Override
+		protected String getDatasourceConfigFile() {
+			String jndiName = this.getDatasourceProperties().get("jndi-name");
+			return System.getProperty("jsfunit.deploy.dir") + "/" + jndiName.toLowerCase() + "-ds.xml";
+		}
 
-        // Min pool size will be 5, max pool size will be 20
-        Map<String, String> propertiesMap = createLocalTXDatasource("MetricsInitalConnectionDS");
 
-        // Create the first connection
-        Connection con = connectDB(propertiesMap.get("jndi-name"), 
-                                   propertiesMap.get("user-name"), 
-                                   propertiesMap.get("password"));
-        assertNotNull(con);
+		@Override
+		protected String getMBeanName( String jndiName, String serviceName ){
+			return "jboss.deployment:id=\"jboss.jca:name=" + jndiName + "," +
+							"service=" + serviceName + "\",type=Component";
+		}
 
-        // Set up the expected values
-        Map<String, String> expectedMetrics = new HashMap<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"), LOCAL_TX_DATASOURCE, expectedMetrics);
 
-        // Clean up
-        disconnectDB(con);
-        deleteDatasource(propertiesMap.get("jndi-name"));
-    }
 
-    /**
-     * Establish multiple connections to a database. Make sure
-     * the metrics are updated accordingly.
-     */
-    public void testMetricsAfterMultipleDBConnections() throws Exception {  
-        
-        // Min pool size will be 5, max pool size will be 20
-        Map<String, String> propertiesMap = createNoTXDatasource("MetricsMultipleConnectionDS");
-        
-        // Establish multiple connections 
-        ArrayList<Connection> connections = new ArrayList<Connection>();
-        for(int i = 0; i <= 5; i++) {
-            Connection con = connectDB(propertiesMap.get("jndi-name"), 
-                                       propertiesMap.get("user-name"), 
-                                       propertiesMap.get("password"));
-            assertNotNull(con);
-            connections.add(con);
-        }
+}// DatasourceTest.java for AS 5
 
-        // Set up the expected values
-        Map<String, String> expectedMetrics = new HashMap<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"), NO_TX_DATASOURCE, expectedMetrics); 
-        
-        // Clean up
-        for(int i = 0; i <= 5; i++) {
-            disconnectDB(connections.get(i));
-        }
-        
-        deleteDatasource(propertiesMap.get("jndi-name"));
-    }
-    
-    /**
-     * Make sure the metrics are updated appropriately after
-     * closing some connections.
-     */
-    public void testMetricsAfterClosingConnections() throws Exception {
-        
-        // Min pool size will be 5, max pool size will be 20
-        Map<String, String> propertiesMap = createNoTXDatasource("MetricsCloseConnectionsDS");
-        
-        // Establish some connections
-        ArrayList<Connection> connections = new ArrayList<Connection>();
-        for(int i = 0; i <= 4; i++) {
-            Connection con = connectDB(propertiesMap.get("jndi-name"), 
-                                       propertiesMap.get("user-name"), 
-                                       propertiesMap.get("password"));
-            assertNotNull(con);
-            connections.add(con);
-        }
-
-        // Close some connections
-        disconnectDB(connections.get(0));
-        disconnectDB(connections.get(1));
-
-        // Set up the expected values
-        Map<String, String> expectedMetrics = new HashMap<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"), NO_TX_DATASOURCE, expectedMetrics); 
-        
-        // Clean up
-        for(int i = 2; i <= 4; i++) {
-            disconnectDB(connections.get(i));
-        }
-        
-        deleteDatasource(propertiesMap.get("jndi-name"));
-    } 
-}
-




More information about the embjopr-commits mailing list