[embjopr-commits] EMBJOPR SVN: r198 - in trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit: as4 and 1 other directories.

embjopr-commits at lists.jboss.org embjopr-commits at lists.jboss.org
Tue Mar 10 11:41:53 EDT 2009


Author: fjuma
Date: 2009-03-10 11:41:53 -0400 (Tue, 10 Mar 2009)
New Revision: 198

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Moved the datasource deletion tests from DatasourceTestBase.java to as5/DatasourceTest.java.
Corrected spacing, indentation, and formatting in DatasourceTestBase.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-09 23:36:10 UTC (rev 197)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java	2009-03-10 15:41:53 UTC (rev 198)
@@ -52,51 +52,45 @@
  *
  */
 public abstract class DatasourceTestBase extends EmbjoprTestCase {
-
    
     // Datasource types, as they appear in the left nav
-		protected enum DatasourceType {
+    protected enum DatasourceType {
 
-			// Some of these values are specific for AS 5.  TODO: Think up some way to split nicely.
-			//                  // label                serviceName  xml-element-name       template <select>
-			LOCAL_TX_DATASOURCE("Local TX Datasources", "LocalTxCM", "local-tx-datasource", "default__Local TX Datasource"),
-			NO_TX_DATASOURCE(   "No TX Datasources",    "NoTxCM",    "no-tx-datasource",    "default__No TX Datasource"),  
-			XA_DATASOURCE(      "XA Datasources",       "XATxCM",    "xa-datasource",       "default__XA Datasource");
+        // Some of these values are specific for AS 5.  TODO: Think up some way to split nicely.
+        //                  // label                serviceName  xml-element-name       template <select>
+        LOCAL_TX_DATASOURCE("Local TX Datasources", "LocalTxCM", "local-tx-datasource", "default__Local TX Datasource"),
+        NO_TX_DATASOURCE(   "No TX Datasources",    "NoTxCM",    "no-tx-datasource",    "default__No TX Datasource"),  
+        XA_DATASOURCE(      "XA Datasources",       "XATxCM",    "xa-datasource",       "default__XA Datasource");
 
-			protected String label;
-			public String getLabel() { return label; }
-			//public void setLabel(String label) {		this.label = label;	}
+        protected String label;
+        public String getLabel() { return label; }
+        
+        protected final String serviceName;
+        public String getServiceName() { return serviceName; }
 
-			protected final String serviceName;
-			public String getServiceName() {				return serviceName;			}
 
+        protected final String xmlElementName;
+        public String getXmlElementName() {	return xmlElementName; }
+        // Also serves as value for HTML Radio for Datasource type selection.
+        public String getHtmlRadioValue() {	return xmlElementName; }
 
-			protected final String xmlElementName;
-			public String getXmlElementName() {				return xmlElementName;			}
-			// Also serves as value for HTML Radio for Datasource type selection.
-			public String getHtmlRadioValue() {				return xmlElementName;			}
-			
 
-			protected final String templateHtmlSelectValue;
-			public String getTemplateHtmlSelectValue() {				return templateHtmlSelectValue;			}
+        protected final String templateHtmlSelectValue;
+        public String getTemplateHtmlSelectValue() { return templateHtmlSelectValue; }
 
+        private DatasourceType(String label, String serviceName, 
+                               String xmlElementName, String htmlSelectValue)
+        {
+            this.label = label;
+            this.serviceName = serviceName;
+            this.xmlElementName = xmlElementName;
+            this.templateHtmlSelectValue = htmlSelectValue;
+        }
 
+    }// DatasourceTypes
 
-			private DatasourceType(String label, String serviceName, 
-								String xmlElementName, String htmlSelectValue)
-			{
-				this.label = label;
-				this.serviceName = serviceName;
-				this.xmlElementName = xmlElementName;
-				this.templateHtmlSelectValue = htmlSelectValue;
-			}
-
-		}// DatasourceTypes
-
-
-
-		// --- Datasource Templates --- //
-		/*
+    // --- Datasource Templates --- //
+    /*
 			AS 4:
 			<select id="resourceCreateForm:selectedTemplate" size="1" name="resourceCreateForm:selectedTemplate">
 				<option value="">Select Template</option>
@@ -120,59 +114,44 @@
 				<option value="default__XA Datasource">default (XA Datasource)</option>
 			</select>
 
-		 */
-		protected enum DatasourceTemplate {
+     */
+    protected enum DatasourceTemplate {
 
-			/** AS 4 */
-			AS4_ORACLE_LOCAL_TX("Oracle Local TX__Datasource"),
-			AS4_ORACLE_XA("Oracle XA__Datasource"),
-			AS4_DEFAULT("default__Datasource"),
+        /** AS 4 */
+        AS4_ORACLE_LOCAL_TX("Oracle Local TX__Datasource"),
+        AS4_ORACLE_XA("Oracle XA__Datasource"),
+        AS4_DEFAULT("default__Datasource"),
 
-			/** AS 5 */
-			AS5_ORACLE_LOCAL_TX("Oracle Local TX__Local TX Datasource"),
-			AS5_DEFAULT_LOCAL_TX("default__Local TX Datasource"),
-			AS5_ORACLE_NO_TX("Oracle No TX__No TX Datasource"),
-			AS5_DEFAULT_NO_TX("default__No TX Datasource"),
-			AS5_ORACLE_XA("Oracle XA__XA Datasource"),
-			AS5_DEFAULT_XA("default__XA Datasource");
+        /** AS 5 */
+        AS5_ORACLE_LOCAL_TX("Oracle Local TX__Local TX Datasource"),
+        AS5_DEFAULT_LOCAL_TX("default__Local TX Datasource"),
+        AS5_ORACLE_NO_TX("Oracle No TX__No TX Datasource"),
+        AS5_DEFAULT_NO_TX("default__No TX Datasource"),
+        AS5_ORACLE_XA("Oracle XA__XA Datasource"),
+        AS5_DEFAULT_XA("default__XA Datasource");
 
+        protected final String templateHtmlSelectValue;
 
+        private DatasourceTemplate(String templateHtmlSelectValue) {
+            this.templateHtmlSelectValue = templateHtmlSelectValue;
+        }
 
-			protected final String templateHtmlSelectValue;
+        /**
+         * Value of HTML select option for this template.
+         */
+        public String getTemplateHtmlSelectValue() {
+            return templateHtmlSelectValue;
+        }
+    }
 
+    // Datasource properties
+    private Map<String, String> datasourceProperties = createDatasourceProperties();
 
-			private DatasourceTemplate(String templateHtmlSelectValue) {
-				this.templateHtmlSelectValue = templateHtmlSelectValue;
-			}
+    /**
+     * @returns a set of properties created upon initialization by overriden createDatasourceProperties().
+     */
+    public Map<String, String> getDatasourceProperties() { return datasourceProperties; }
 
-
-
-			/**
-			 * Value of HTML select option for this template.
-			 */
-			public String getTemplateHtmlSelectValue() {
-				return templateHtmlSelectValue;
-			}
-
-		}
-
-
-		
-
-
-		// Datasource properties
-
-		private Map<String, String> datasourceProperties = createDatasourceProperties();
-
-		/**
-		 * @returns a set of properties created upon initialization by overriden createDatasourceProperties().
-		 */
-		public Map<String, String> getDatasourceProperties() { return datasourceProperties; }
-
-
-
-
-
     /**
      * Create a new datasource using the given type, template, and properties.
      * 
@@ -182,36 +161,36 @@
     protected abstract void createDatasource(DatasourceType datasourceType,
                                              String datasourceTemplate,
                                              Map<String, String> propertiesMap) throws IOException;
-    
+
     /**
      * 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) {
+    protected boolean isDatasourceDeployed(String jndiName,  DatasourceType datasourceType) {
         try {
 
             String[] dsMBeanServices = {"DataSourceBinding",
                                         "ManagedConnectionPool",
                                         "ManagedConnectionFactory",
-                                        datasourceType.getServiceName() };
+                                        datasourceType.getServiceName()};
 
             // Query the MBean server to check if the datasource is deployed
             MBeanServer jmxServer = MBeanServerLocator.locateJBoss();
 
             // Inspect these MBeans and make sure that the their state indicates successful deployment
-		    // (e.g. for AS 5, "State" attribute is "DEPLOYED"):
+            // (e.g. for AS 5, "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++) {
 
-								// Is this necessary? Can't we just query? See InstanceNotFoundException;
-							  // And AFAIK, full MBean name is unique. I vote for minimalistic code.
+                // Is this necessary? Can't we just query? See InstanceNotFoundException;
+                // And AFAIK, full MBean name is unique. I vote for minimalistic code.
                 /*ObjectName objName = new ObjectName( this.getMBeanName(jndiName, dsMBeanServices[i]));
 
                 Set dsMBeans = jmxServer.queryNames(objName, null);
@@ -220,18 +199,16 @@
 								// Get the first and only one MBean returned.
                 ObjectName deploymentMBean = (ObjectName)dsMBeans.iterator().next(); /**/
 
-								String mBeanName = this.getMBeanName(jndiName, dsMBeanServices[i]);
-								log.info("Looking for MBean "+mBeanName+"...");
-								ObjectName deploymentMBean = new ObjectName( mBeanName );
+                String mBeanName = this.getMBeanName(jndiName, dsMBeanServices[i]);
+                log.info("Looking for MBean "+mBeanName+"...");
+                ObjectName deploymentMBean = new ObjectName( mBeanName );
 
-                ///Object state = jmxServer.getAttribute(deploymentMBean, "State");
-                ///if(!("DEPLOYED".equals(state.toString()))) return false;
-								if( this.isMBeanStateDeployedImpl( deploymentMBean ) ){
-									log.info("Found, OK");
-								}else{
-									log.info("Not found.");
-									return false;
-								}
+                if( this.isMBeanStateDeployedImpl( deploymentMBean ) ){
+                    log.info("Found, OK");
+                }else{
+                    log.info("Not found.");
+                    return false;
+                }
 
             }
 
@@ -240,7 +217,7 @@
             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 
@@ -250,53 +227,55 @@
     protected boolean checkProperties(String jndiName,
                                       DatasourceType datasourceType,
                                       Map<String, String> expectedValuesMap)
-		{
-        
+    {
+
         Map<String, String> actualValuesMap = new HashMap<String, String>();
-        
-        
+
+
         try {
-            
+
             // Parse the *-ds.xml file; create appropriate file name for AS 4 or 5.
             File file = new File(this.getDatasourceConfigFile(jndiName));
-						log.info("Examining: "+file.getAbsolutePath());
+            log.info("Examining: "+file.getAbsolutePath());
 
             SAXBuilder builder = new SAXBuilder();
             Document doc = builder.build(file);
-            
+
             Element root = doc.getRootElement();
             assertTrue(root.getName().equals("datasources"));
-            
+
             // Get the datasource element 
             Element datasource = root.getChild(datasourceType.getXmlElementName());
-            
+
             // 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());
+                Element property = (Element)itr.next();
+                actualValuesMap.put(property.getName(), property.getValue());
             }
-          
+
             // Compare the actual values to the expected ones.
-						for( String key : expectedValuesMap.keySet() ){
-							if(!actualValuesMap.containsKey(key)){
-								// Value was not set.
-								log.fatal("Property '"+key+"' is not found.");
-								return false;
-							}
+            for( String key : expectedValuesMap.keySet() ){
+                if(!actualValuesMap.containsKey(key)){
+                    
+                    // Value was not set.
+                    log.fatal("Property '" + key + "' is not found.");
+                    return false;
+                }
 
-							if(!expectedValuesMap.get(key).equals(actualValuesMap.get(key))) {
-								// Incorrect value.
-								log.fatal("Property '"+key+"' has unexpected value: '"+actualValuesMap.get(key)+"'");
-								return false;
-							}
-						}
-            
+                if(!expectedValuesMap.get(key).equals(actualValuesMap.get(key))) {
+                    
+                    // Incorrect value.
+                    log.fatal("Property '" + key +"' has unexpected value: '" + actualValuesMap.get(key) + "'");
+                    return false;
+                }
+            }
+
             return true;
-            
+
         } catch (Exception e) {
-						log.fatal("Config file check failed: "+e.getMessage());
+            log.fatal("Config file check failed: "+e.getMessage());
             throw new RuntimeException(e);
         }
     }
@@ -374,6 +353,8 @@
         assertTrue("Missing line in -ds.xml file: " + expectedLine, expectedLine == null);
     }
     
+    
+    
     /**
      * @return the suite of tests being tested
 		 * @throws UnsupportedOperationException - you have to override this.
@@ -384,7 +365,229 @@
       throw new UnsupportedOperationException("This has to be overriden.");
     }
 
+    /**
+     * Creates the default properties for the datasource - shared by AS4 and AS5.
+     * Overriding method should get result of this method and overwrite it with it's custom properties.
+     * @returns a set of default properties.
+     */
+    protected Map<String, String> createDatasourceProperties()
+    {
+        Map<String, String> propertiesMap = new HashMap();
 
+        // 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:."); // Store data current working dir.
+        propertiesMap.put("idle-timeout-minutes", "20");
+        propertiesMap.put("prepared-statement-cache-size", "2");
+        propertiesMap.put("valid-connection-checker-class-name",
+                          "org.jboss.resource.adapter.jdbc.CheckValidConnectionSQL");
+        propertiesMap.put("exception-sorter-class-name",
+                          "org.jboss.resource.adapter.jdbc.ExceptionSorter");
+
+        return propertiesMap;
+    }
+
+
+    /**
+     * Create a basic Local TX Datasource. Return the mapping of property
+     * names to property values.
+     */
+    protected 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(DatasourceType.LOCAL_TX_DATASOURCE,
+                         DatasourceType.LOCAL_TX_DATASOURCE.getTemplateHtmlSelectValue(), // "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.
+     */
+    protected 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(DatasourceType.NO_TX_DATASOURCE,
+                         DatasourceType.NO_TX_DATASOURCE.getTemplateHtmlSelectValue(), //"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.
+     */
+    protected 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");
+        propertiesMap.put("set-tx-query-timeout", "false");
+        propertiesMap.put("user-name", "testUser");
+
+        createDatasource(DatasourceType.XA_DATASOURCE,
+                         DatasourceType.XA_DATASOURCE.getTemplateHtmlSelectValue(), //"default__XA Datasource",
+                         propertiesMap);
+        client.click("resourceConfigurationForm:saveButton");
+
+        return propertiesMap;
+    }
+
+    /**
+     *
+     * @returns a name of the Datasource's config file to check the properties in.
+     */
+    protected abstract String getDatasourceConfigFile( String jndiName );
+
+    protected abstract String getMBeanName( String jndiName, String serviceName );
+
+
+
+    /**
+     * This method is wrapper that handles JMX exceptions at Base level.
+     * Intended to keep AS-version-specific method, isMBeanStateDeployedImpl(), as small as possible.
+     * @param deploymentMBean
+     * @return
+     * @throws javax.management.JMException
+     * @throws java.io.IOException
+     */
+    protected boolean isMBeanStateDeployed( ObjectName deploymentMBean ) {
+
+        try {
+            return this.isMBeanStateDeployedImpl(deploymentMBean);
+        }
+        // This super-exception includes JMX operation failures, including:
+        // AttributeNotFoundException, InstanceNotFoundException, MalformedObjectNameException, ServiceNotFoundException
+        catch (OperationsException ex) {
+            log.warn("JMX operation error when retrieving MBean attribute.", ex);
+            return false;
+        }
+        // All other JMX failures...
+        catch (JMException ex) {
+            log.warn("JMX error when retrieving MBean attribute.", ex);
+            return false;
+        }
+        catch (IOException ex) {
+            log.warn("I/O error when retrieving MBean attribute.", ex);
+            return false;
+        }
+
+    }// isMBeanStateDeployed()
+
+
+    /**
+     * containsElement returns whether or not the *-ds.xml file corresponding
+     * to the datasource given by jndiName contains the given element.
+     */
+    protected boolean containsElement(String jndiName, String elementName) {
+        try {
+            File file = new File(this.getDatasourceConfigFile(jndiName));
+            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);
+        }
+    }
+
+
+
+    /**
+     * Make sure that the metrics corresponding to the given datasource
+     * are correct.
+     *
+     * @param metricsMap maps metric names to the expected metric values.
+     */
+    protected void checkMetrics(String datasourceName,
+                                DatasourceType datasourceType,
+                                Map<String, String> metricsMap) throws IOException, EmbJoprTestException {
+
+        refreshTreeNode("Datasources");
+        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
+        datasourceTypeArrow.click();
+
+        HtmlAnchor datasource = getNavTreeLink(datasourceName);
+        datasource.click();
+
+        // Check values under the "Metrics" tab
+        HtmlAnchor metricsLink = (HtmlAnchor)client.getElement("metricsTab");
+        metricsLink.click();
+
+        for(Iterator i = metricsMap.keySet().iterator(); i.hasNext();) {
+            String metricName = (String)i.next();
+            String expected = metricsMap.get(metricName);
+            String actual = getMetricValueFromTable(metricName, "dataTable");
+            actual = normalizeIfDoubleExpected(expected, actual); // Some LOCALEs encode doubles with coma.
+            assertEquals("Incorrect metric value for '" + metricName + "'", expected, actual);
+        }
+
+        // Check values under the "Summary" tab
+        HtmlAnchor summaryLink = (HtmlAnchor)client.getElement("summaryTab");
+        summaryLink.click();
+
+        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();
+            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+"'," +
+                         " expected '"+expected+"'", expected, actual);
+        }
+    }
+
+    /**
+     * This method should query the JMX server and decide whether the given MBean displays deployed resource.
+     * @param deploymentMBean  Name of the MBean to examine. Differs between AS4 and 5.
+     * @return true  if the MBean indicates that the resource is deployed, false otherwise.
+     * @throws javax.management.JMException  upon JMX related error, including invalid
+     *                 or non-existent MBean / attribute name.
+     * @throws java.io.IOException  upon I/O error.
+     */
+    protected abstract boolean isMBeanStateDeployedImpl( ObjectName deploymentMBean ) throws JMException, IOException;
 		
     
     /*
@@ -562,73 +765,6 @@
     }
 
     /*
-     * 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"),
-                                         DatasourceType.LOCAL_TX_DATASOURCE));
-
-        // Make sure the entry was removed from the -ds.xml file (See JOPR-44)
-        assertFalse(containsElement(propertiesMap.get("jndi-name"),
-                                    DatasourceType.LOCAL_TX_DATASOURCE.getXmlElementName())); 
-    }
-    
-    /**
-     * 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"),
-                                         DatasourceType.NO_TX_DATASOURCE));
-
-        // Make sure the entry was removed from the -ds.xml file (See JOPR-44)
-        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"),
-                                         DatasourceType.XA_DATASOURCE));
-
-        // Make sure the entry was removed from the -ds.xml file (See JOPR-44)
-        assertFalse(containsElement(propertiesMap.get("jndi-name"),
-                                    "xa-datasource"));
-    }
-    
-    /*
      * METRICS TESTS
      */
 
@@ -760,248 +896,5 @@
         
         deleteDatasource(propertiesMap.get("jndi-name"));
     }
-
-
-
-
-		
-
-
-		/*
-		 *   ---  Various support methods. ---
-		 */
-
-
-
-
-		/**
-		 * Creates the default properties for the datasource - shared by AS4 and AS5.
-		 * Overriding method should get result of this method and overwrite it with it's custom properties.
-		 * @returns a set of default properties.
-		 */
-		protected Map<String, String> createDatasourceProperties()
-		{
-		    Map<String, String> propertiesMap = new HashMap();
-
-        // 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:."); // Store data current working dir.
-        propertiesMap.put("idle-timeout-minutes", "20");
-        propertiesMap.put("prepared-statement-cache-size", "2");
-        propertiesMap.put("valid-connection-checker-class-name",
-                          "org.jboss.resource.adapter.jdbc.CheckValidConnectionSQL");
-        propertiesMap.put("exception-sorter-class-name",
-                          "org.jboss.resource.adapter.jdbc.ExceptionSorter");
-       
-				return propertiesMap;
-		}
-
-
-    /**
-     * Create a basic Local TX Datasource. Return the mapping of property
-     * names to property values.
-     */
-    protected 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(DatasourceType.LOCAL_TX_DATASOURCE,
-								         DatasourceType.LOCAL_TX_DATASOURCE.getTemplateHtmlSelectValue(), // "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.
-     */
-    protected 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(DatasourceType.NO_TX_DATASOURCE,
-												 DatasourceType.NO_TX_DATASOURCE.getTemplateHtmlSelectValue(), //"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.
-     */
-    protected 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");
-        propertiesMap.put("set-tx-query-timeout", "false");
-        propertiesMap.put("user-name", "testUser");
-
-        createDatasource(DatasourceType.XA_DATASOURCE,
-								         DatasourceType.XA_DATASOURCE.getTemplateHtmlSelectValue(), //"default__XA Datasource",
-                         propertiesMap);
-        client.click("resourceConfigurationForm:saveButton");
-
-        return propertiesMap;
-    }
-
-
-
-		
-		
-		/**
-		 *
-		 * @returns a name of the Datasource's config file to check the properties in.
-		 */
-		protected abstract String getDatasourceConfigFile( String jndiName );
-
-		protected abstract String getMBeanName( String jndiName, String serviceName );
-
-
-
-		/**
-		 * This method is wrapper that handles JMX exceptions at Base level.
-		 * Intended to keep AS-version-specific method, isMBeanStateDeployedImpl(), as small as possible.
-		 * @param deploymentMBean
-		 * @return
-		 * @throws javax.management.JMException
-		 * @throws java.io.IOException
-		 */
-		protected boolean isMBeanStateDeployed( ObjectName deploymentMBean ) {
-
-			try {
-				return this.isMBeanStateDeployedImpl(deploymentMBean);
-			}
-			// This super-exception includes JMX operation failures, including:
-			// AttributeNotFoundException, InstanceNotFoundException, MalformedObjectNameException, ServiceNotFoundException
-			catch (OperationsException ex) {
-				log.warn("JMX operation error when retrieving MBean attribute.", ex);
-				return false;
-			}
-			// All other JMX failures...
-			catch (JMException ex) {
-				log.warn("JMX error when retrieving MBean attribute.", ex);
-				return false;
-			}
-			catch (IOException ex) {
-				log.warn("I/O error when retrieving MBean attribute.", ex);
-				return false;
-			}
-
-	  }// isMBeanStateDeployed()
-
-
-
-    /**
-     * containsElement returns whether or not the *-ds.xml file corresponding
-     * to the datasource given by jndiName contains the given element.
-     */
-    protected boolean containsElement(String jndiName, String elementName) {
-        try {
-            File file = new File(this.getDatasourceConfigFile(jndiName));
-            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);
-        }
-    }
-
-
-
-    /**
-     * Make sure that the metrics corresponding to the given datasource
-     * are correct.
-     *
-     * @param metricsMap maps metric names to the expected metric values.
-     */
-    protected void checkMetrics(String datasourceName,
-                                DatasourceType datasourceType,
-                                Map<String, String> metricsMap) throws IOException, EmbJoprTestException {
-
-        refreshTreeNode("Datasources");
-        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
-        datasourceTypeArrow.click();
-
-        HtmlAnchor datasource = getNavTreeLink(datasourceName);
-        datasource.click();
-
-        // Check values under the "Metrics" tab
-        HtmlAnchor metricsLink = (HtmlAnchor)client.getElement("metricsTab");
-        metricsLink.click();
-
-        for(Iterator i = metricsMap.keySet().iterator(); i.hasNext();) {
-            String metricName = (String)i.next();
-            String expected = metricsMap.get(metricName);
-            String actual = getMetricValueFromTable(metricName, "dataTable");
-						actual = normalizeIfDoubleExpected(expected, actual); // Some LOCALEs encode doubles with coma.
-            assertEquals("Incorrect metric value for '" + metricName + "'", expected, actual);
-        }
-
-        // Check values under the "Summary" tab
-        HtmlAnchor summaryLink = (HtmlAnchor)client.getElement("summaryTab");
-        summaryLink.click();
-
-        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();
-            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+"'," +
-										" expected '"+expected+"'", expected, actual);
-        }
-    }
-
-		/**
-		 * This method should query the JMX server and decide whether the given MBean displays deployed resource.
-		 * @param deploymentMBean  Name of the MBean to examine. Differs between AS4 and 5.
-		 * @return true  if the MBean indicates that the resource is deployed, false otherwise.
-		 * @throws javax.management.JMException  upon JMX related error, including invalid
-		 *                 or non-existent MBean / attribute name.
-		 * @throws java.io.IOException  upon I/O error.
-		 */
-		protected abstract boolean isMBeanStateDeployedImpl( ObjectName deploymentMBean ) throws JMException, IOException;
-
 }
 

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-03-09 23:36:10 UTC (rev 197)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/EmbjoprTestCase.java	2009-03-10 15:41:53 UTC (rev 198)
@@ -173,7 +173,7 @@
             if (linkText.contains(linkLabel)) return link;
         }
 
-        throw new IllegalStateException("Nav Tree link for '" 
+        throw new IllegalStateException("Link for '" 
                                         + linkLabel 
                                         + "' not found.");
     }

Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	2009-03-09 23:36:10 UTC (rev 197)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as4/DatasourceTest.java	2009-03-10 15:41:53 UTC (rev 198)
@@ -39,11 +39,10 @@
 
 /**
  * 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.
+ * configuring, and deleting various types of datasources. 
  * 
- * @author Farah Juma
- *
+ * @author Ondrej Zizka
+ * 
  */
 public class DatasourceTest extends org.jboss.jopr.jsfunit.DatasourceTestBase {
 

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-09 23:36:10 UTC (rev 197)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java	2009-03-10 15:41:53 UTC (rev 198)
@@ -33,6 +33,8 @@
 import javax.management.JMException;
 import java.sql.Connection;
 import org.jboss.jopr.jsfunit.exceptions.EmbJoprTestException;
+import org.jboss.deployers.spi.management.KnownComponentTypes;
+import org.jboss.managed.api.ComponentType;
 
 /**
  * When complete, this class will contain tests for creating, 
@@ -45,6 +47,10 @@
 public class DatasourceTest extends DatasourceTestBase {
 
     private final String MAX_ITEMS_PER_PAGE="20";
+    
+    private static final ComponentType LOCAL_TX_COMPONENT_TYPE = KnownComponentTypes.DataSourceTypes.LocalTx.getType();
+    private static final ComponentType NO_TX_COMPONENT_TYPE = KnownComponentTypes.DataSourceTypes.NoTx.getType();
+    private static final ComponentType XA_COMPONENT_TYPE = KnownComponentTypes.DataSourceTypes.XA.getType();
 
     /**
      * Create a new datasource using the given type, template, and properties.
@@ -156,9 +162,17 @@
             menu.setSelectedAttribute(MAX_ITEMS_PER_PAGE, Boolean.TRUE);
         }
 
-        HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm", 
-                                                       datasourceName);
-        deleteButton.click();
+        HtmlButtonInput deleteButton;
+        try {
+            deleteButton = getDeleteButton("categorySummaryForm", datasourceName);
+            deleteButton.click();
+        } catch (IllegalStateException e) { 
+            
+            // The delete button was not found on this page
+            client.click("nextPage");
+            deleteButton = getDeleteButton("categorySummaryForm", datasourceName);
+            deleteButton.click();
+        }  
     }
 
     /**
@@ -206,12 +220,77 @@
     {
         return new TestSuite(DatasourceTest.class);
     }
-    
+      
     /*
      * DELETION TESTS
      */
+
+    /**
+     * Remove a Local TX Datasource.
+     */
+    public void testDeleteLocalTXDatasource() throws Exception {
+        Map<String, String> propertiesMap = createLocalTXDatasource("DeleteLocalTXDS");
+
+        // The message we expect to see
+        String expectedMessage = "Successfully deleted Local TX Datasource '"
+                                 + propertiesMap.get("jndi-name") + "'";
+        
+        deleteDS(expectedMessage, propertiesMap, 
+                 LOCAL_TX_COMPONENT_TYPE, DatasourceType.LOCAL_TX_DATASOURCE);
+    }
     
     /**
+     * Remove a No TX Datasource.
+     */
+    public void testDeleteNoTXDatasource() throws Exception {
+        Map<String, String> propertiesMap = createNoTXDatasource("DeleteNoTXDS");
+
+        // The message we expect to see
+        String expectedMessage = "Successfully deleted No TX Datasource '"
+                                 + propertiesMap.get("jndi-name") + "'";
+        
+        deleteDS(expectedMessage, propertiesMap, NO_TX_COMPONENT_TYPE, 
+                 DatasourceType.NO_TX_DATASOURCE);
+    }
+
+    /**
+     * Remove an XA Datasource.
+     */
+    public void testDeleteXADatasource() throws Exception {
+        Map<String, String> propertiesMap = createXADatasource("DeleteXADS");
+        
+        // The message we should see
+        String expectedMessage = "Successfully deleted XA Datasource '"
+                                 + propertiesMap.get("jndi-name") + "'";
+        
+        deleteDS(expectedMessage, propertiesMap, 
+                 XA_COMPONENT_TYPE, DatasourceType.XA_DATASOURCE);
+    }
+    
+    /**
+     * Common code for the testDelete* tests.
+     */
+    private void deleteDS(String expectedMessage, Map<String, String> propertiesMap, 
+                          ComponentType componentType, DatasourceType datasourceType) throws Exception {
+        
+        deleteDatasource(propertiesMap.get("jndi-name"));
+
+        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+
+        // Make sure the ManagedComponent was removed
+        assertNull("The datasource was not removed after deletion (the ManagedComponent is non-null)",
+                   getManagedComponent(propertiesMap.get("jndi-name"), componentType));
+        
+        // Make sure the entry was removed from the -ds.xml file (See JOPR-44)
+        assertFalse(containsElement(propertiesMap.get("jndi-name"),
+                                    datasourceType.getXmlElementName()));
+        
+        assertFalse("According to JMX view, the deleted datasource is still deployed",
+                    isDatasourceDeployed(propertiesMap.get("jndi-name"),
+                                         datasourceType));
+    }
+    
+    /**
      * Test the case in which the -ds.xml file that contains the datasource
      * to be deleted contains more than one datasource. Make sure the entire
      * -ds.xml file does not get deleted. (See JBAS-6227.)
@@ -225,6 +304,10 @@
         // Check for the appropriate success messages
         String expectedMessage = "Successfully deleted No TX Datasource 'NoTX'";
         checkClientAndServerMessages(expectedMessage, expectedMessage, false);
+        
+        // Make sure the ManagedComponent was removed
+        assertNull("The datasource was not removed after deletion (the ManagedComponent is non-null)",
+                   getManagedComponent("NoTX", NO_TX_COMPONENT_TYPE));
 
         // Make sure only the No TX Datasource entry was removed 
         // from the -ds.xml file
@@ -262,9 +345,6 @@
         fillOutForm(propertiesMapChanges);
         client.click("resourceConfigurationForm:saveButton");
 
-        // Update our expected property values
-        propertiesMap.putAll(propertiesMapChanges);
-
         // Check for the appropriate success messages
         String expectedMessage = "Successfully updated XA Datasource '" 
                                  + propertiesMap.get("jndi-name") + "'";
@@ -274,7 +354,7 @@
                                         DatasourceType.XA_DATASOURCE)); 
         assertTrue(checkProperties(propertiesMap.get("jndi-name"), 
                                    DatasourceType.XA_DATASOURCE, 
-                                   propertiesMap));
+                                   propertiesMapChanges));
 
         // Clean up
         deleteDatasource(propertiesMap.get("jndi-name"));  
@@ -305,9 +385,6 @@
         fillOutForm(propertiesMapChanges);
         client.click("resourceConfigurationForm:saveButton");
 
-        // Update our expected property values
-        propertiesMap.putAll(propertiesMapChanges);
-
         // Check for the appropriate success messages
         String expectedMessage = "Successfully updated Local TX Datasource '" 
                                  + propertiesMap.get("jndi-name") + "'";
@@ -317,7 +394,7 @@
                                         DatasourceType.LOCAL_TX_DATASOURCE)); 
         assertTrue(checkProperties(propertiesMap.get("jndi-name"), 
                                    DatasourceType.LOCAL_TX_DATASOURCE, 
-                                   propertiesMap));
+                                   propertiesMapChanges));
 
         // Clean up
         deleteDatasource(propertiesMap.get("jndi-name"));   
@@ -340,13 +417,17 @@
 
         enableOrDisableFormInput("user-name", Boolean.FALSE);
         enableOrDisableFormInput("idle-timeout-minutes", Boolean.FALSE);
-        enableOrDisableFormInput("prefill", Boolean.FALSE);
+        enableOrDisableFormInput("track-connection-by-tx", Boolean.FALSE);
+        enableOrDisableFormInput("domain", Boolean.FALSE);
+        enableOrDisableFormInput("noTxSeparatePools", Boolean.FALSE);
         client.click("resourceConfigurationForm:saveButton");
 
         // Update our expected property values
         propertiesMap.remove("user-name");
         propertiesMap.remove("idle-timeout-minutes");
-        propertiesMap.remove("prefill");
+        propertiesMap.remove("track-connection-by-tx");
+        propertiesMap.remove("domain");
+        propertiesMap.remove("noTxSeparatePools");
 
         // Check for the appropriate success messages
         String expectedMessage = "Successfully updated No TX Datasource '" 




More information about the embjopr-commits mailing list