[embjopr-commits] EMBJOPR SVN: r124 - 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
Wed Jan 28 10:03:55 EST 2009


Author: fjuma
Date: 2009-01-28 10:03:55 -0500 (Wed, 28 Jan 2009)
New Revision: 124

Modified:
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
   trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java
Log:
Added datasource configuration tests for AS5.


Modified: trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
===================================================================
--- trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java	2009-01-22 20:27:10 UTC (rev 123)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java	2009-01-28 15:03:55 UTC (rev 124)
@@ -42,13 +42,8 @@
 import java.util.logging.Level;
 import javax.management.*;
 
-
-
-
 /**
- * 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.
+ * This is the base test class for Embedded Jopr Datasource tests.
  * 
  * @author Farah Juma
  * @author Ondrej Zizka
@@ -162,7 +157,7 @@
     /**
      * 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",
@@ -174,7 +169,7 @@
             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
@@ -205,9 +200,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 
@@ -215,8 +208,8 @@
      * properties are correctly set in the *-ds.xml file and false otherwise.
      */
     protected boolean checkProperties(String jndiName,
-                                    DatasourceType datasourceType,
-                                    Map<String, String> expectedValuesMap) {
+                                      DatasourceType datasourceType,
+                                      Map<String, String> expectedValuesMap) {
         
         Map<String, String> actualValuesMap = new HashMap<String, String>();
         
@@ -224,7 +217,7 @@
         try {
             
             // Parse the *-ds.xml file; create appropriate file name for AS 4 or 5.
-						File file = new File( this.getDatasourceConfigFile( jndiName ));
+            File file = new File(this.getDatasourceConfigFile(jndiName));
          
             SAXBuilder builder = new SAXBuilder();
             Document doc = builder.build(file);
@@ -233,7 +226,7 @@
             assertTrue(root.getName().equals("datasources"));
             
             // Get the datasource element 
-            Element datasource = root.getChild( datasourceType.getXmlElementName() );
+            Element datasource = root.getChild(datasourceType.getXmlElementName());
             
             // Create actualValuesMap by mapping property names to 
             // property values
@@ -298,11 +291,9 @@
 		
     
     /*
-     * --- Some preliminary creation tests ---
+     * CREATION TESTS
      */
-
-
-		
+    
     /**
      * Create a new datasource. Leave some property values, that aren't
      * required, unset.
@@ -334,17 +325,8 @@
 
         // Clean up
         deleteDatasource(propertiesMap.get("jndi-name"));
-        expectedMessage = "Successfully deleted Local TX Datasource '"
-                          + propertiesMap.get("jndi-name") + "'";
-        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
     }
 
-
-
-
-
-
-		
     /**
      * Attempt to create a new datasource but leave at least one required
      * value unset. An error should occur.
@@ -402,7 +384,6 @@
                                      true);
     }
     
-    
     /**
      * Attempt to create a new datasource but set a property value
      * to an invalid type. An error should occur.
@@ -432,9 +413,6 @@
                                      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
@@ -510,7 +488,7 @@
 						propertiesMap.get("jndi-name"),
             DatasourceType.LOCAL_TX_DATASOURCE.getXmlElementName() )); //"local-tx-datasource"
     }
-
+    
     /**
      * Remove a No TX Datasource.
      */
@@ -729,26 +707,13 @@
         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("query-timeout", "180"); // AS 5 only - moved there
         propertiesMap.put("prepared-statement-cache-size", "2");
-				// Share Prepared Statements - AS 5
-        //propertiesMap.put("share-prepared-statements", "false"); // AS 5
-
         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"); // AS 5
         propertiesMap.put("exception-sorter-class-name",
                           "org.jboss.resource.adapter.jdbc.ExceptionSorter");
-        //propertiesMap.put("allocation-retry", "10000"); // AS 5
-        //propertiesMap.put("allocation-retry-wait-millis", "10000"); // AS 5
-
-        //propertiesMap.put("background-validation-millis", "15000"); // AS 5
-        //propertiesMap.put("prefill", "true");                       // AS 5
-        //propertiesMap.put("use-try-lock", "61000");                 // AS 5
-
+       
 				return propertiesMap;
-
 		}
 
 
@@ -819,6 +784,8 @@
         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",
@@ -876,13 +843,10 @@
     /**
      * containsElement returns whether or not the *-ds.xml file corresponding
      * to the datasource given by jndiName contains the given element.
-		 * TODO: Refactor.
      */
     protected boolean containsElement(String jndiName, String elementName) {
         try {
-            File file = new File(System.getProperty("jsfunit.deploy.dir")
-                                 + "/" + jndiName + "-ds.xml");
-
+            File file = new File(this.getDatasourceConfigFile(jndiName));
             SAXBuilder builder = new SAXBuilder();
             Document doc = builder.build(file);
 
@@ -940,40 +904,6 @@
         }
     }
 
-
-		
-
-    /**
-     * Perform the given operation on the given datasource.
-     */
-    protected void performDatasourceOperation(String datasourceName,
-                                            String datasourceType,
-                                            String operationName) throws IOException {
-
-        refreshTreeNode("Datasources");
-        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType);
-        datasourceTypeArrow.click();
-
-        HtmlAnchor datasourceLink = getNavTreeLink(datasourceName);
-        datasourceLink.click();
-
-        HtmlAnchor controlLink = (HtmlAnchor)client.getElement("controlTab");
-        controlLink.click();
-
-        HtmlForm form = (HtmlForm)client.getElement("operation_form");
-        String xpath = ".//input[@value=\"" + operationName + "\"]";
-
-        HtmlButtonInput operationButton = (HtmlButtonInput)form.getFirstByXPath(xpath);
-        operationButton.click();
-    }
-
-
-
-
-
-
-
-
 		/**
 		 * 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.

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-22 20:27:10 UTC (rev 123)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/as5/DatasourceTest.java	2009-01-28 15:03:55 UTC (rev 124)
@@ -42,27 +42,27 @@
  */
 public class DatasourceTest extends DatasourceTestBase {
 
-	  private final String MAX_ITEMS_PER_PAGE="20";
+    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.
+     *
+     * AS 5 version differs in menu tree structure - one more step.
+     * Thus, this method is overriden from the Base class.
      * 
-     * @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.
-		 *
+     * @param datasourceType must be a datasource type from DatasourceType enum.
+     * It's label from the left nav (eg. "Local TX Datasources") is in getLabel() property.
+     *
      */
-		@Override
+    @Override
     protected void createDatasource(DatasourceType datasourceType,
-                                  String datasourceTemplate,
-                                  Map<String, String> propertiesMap) throws IOException {
-        
+                                    String datasourceTemplate,
+                                    Map<String, String> propertiesMap) throws IOException {
+
         // Expand the "Datasources" tree node
         ClickableElement datasourcesArrow = getNavTreeArrow("Datasources");
         datasourcesArrow.click();
+
         HtmlAnchor datasourceLink = getNavTreeLink(datasourceType.getLabel());
         datasourceLink.click();
         
@@ -77,37 +77,73 @@
     }
 
 
-		/**
-		 * 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();
+    /**
+     * Properties needed for testCreateDatasource for AS 5.
+     * @returns the properties from the base class overriden by properties for AS 5.
+     */
+    @Override
+    protected Map<String, String> createDatasourceProperties()
+    {
+        Map<String, String> propertiesMap = super.createDatasourceProperties();
 
-				// Additional or different properties for AS 5
-				propertiesMap.put("query-timeout", "180");
-				propertiesMap.put("share-prepared-statements", "false");
+        // 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");
-
-        propertiesMap.put("allocation-retry", "10000");
-        propertiesMap.put("allocation-retry-wait-millis", "10000");
-
         propertiesMap.put("background-validation-millis", "15000");
         propertiesMap.put("prefill", "true");
         propertiesMap.put("use-try-lock", "61000");                
 
-				return propertiesMap;
+        return propertiesMap;
+    }
+    
+    /**
+     * Perform the given operation on the given datasource.
+     * 
+     * performDatasourceOperation() assumes that the "Datasources"
+     * tree node is already expanded when this method is called.
+     */
+    protected void performDatasourceOperation(String datasourceName,
+                                              DatasourceType datasourceType,
+                                              String operationName) throws IOException {
 
-		}
+        navigateToPage(datasourceName, datasourceType, "controlTab");
 
+        HtmlForm form = (HtmlForm)client.getElement("operation_form");
+        String xpath = ".//input[@value=\"" + operationName + "\"]";
 
+        HtmlButtonInput operationButton = (HtmlButtonInput)form.getFirstByXPath(xpath);
+        operationButton.click();
+    }
 
+    /**
+     * Navigate to the given tab (eg. "configurationTab", "controlTab") for 
+     * the given datasource.
+     * 
+     * navigateToPage() assumes that the "Datasources" tree node is already 
+     * expanded when this method is called.
+     */
+    private void navigateToPage(String datasourceName,
+                                DatasourceType datasourceType,
+                                String tabName) throws IOException {
+
+        refreshTreeNode("Datasources");
+        ClickableElement datasourceTypeArrow = getNavTreeArrow(datasourceType.getLabel());
+        datasourceTypeArrow.click();
+
+        HtmlAnchor datasource = getNavTreeLink(datasourceName);
+        datasource.click();
+
+        HtmlAnchor tabLink = (HtmlAnchor)client.getElement(tabName);
+        tabLink.click();
+    }
     
+    /**
+     * Delete the datasource given by datasourceName.
+     */
     @Override
     protected void deleteDatasource(String datasourceName) throws IOException {
         HtmlAnchor datasourceLink = getNavTreeLink("Datasources");
@@ -118,76 +154,183 @@
             menu.setSelectedAttribute(MAX_ITEMS_PER_PAGE, Boolean.TRUE);
         }
 
-        HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm", datasourceName);
+        HtmlButtonInput deleteButton = getDeleteButton("categorySummaryForm", 
+                                                       datasourceName);
         deleteButton.click();
     }
 
+    /**
+     * 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.
+     */
+    @Override
+    protected boolean isMBeanStateDeployedImpl(ObjectName deploymentMBean)  throws JMException, IOException {
 
+        JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
 
+        Object state = jmxUtils.getMBeanAttribute(deploymentMBean, "State");
+        return !("DEPLOYED".equals( state.toString() ));
 
-		
+    }
 
+    /**
+     * Return the location of the -ds.xml file that corresponds to the 
+     * datasource given by jndiName.
+     */
+    @Override
+    protected String getDatasourceConfigFile( String jndiName ) {
+        return System.getProperty("jsfunit.deploy.dir") + "/" + jndiName + "-ds.xml";
+    }
 
+    /**
+     * Return the name of the MBean that corresponds to the given
+     * JNDI name and service.
+     */
+    @Override
+    protected String getMBeanName( String jndiName, String serviceName ){
+        return "jboss.deployment:id=\"jboss.jca:name=" + jndiName + "," +
+        "service=" + serviceName + "\",type=Component";
+    }
 
-		@Override
-		protected boolean isMBeanStateDeployedImpl(ObjectName deploymentMBean)  throws JMException, IOException {
+    /**
+     * @return the suite of tests being tested
+     */
+    public static Test suite()
+    {
+        return new TestSuite(DatasourceTest.class);
+    }
+    
+    /*
+     * CONFIGURATION TESTS
+     */
+    
+    /**
+     * Change the value of some already set properties.
+     */
+    public void testConfigureDatasourceChangeSetProperties() throws IOException {
+        Map<String, String> propertiesMap = createXADatasource("ChangeSetPropertiesDS");
+        assertTrue("Error creating datasource", 
+                   client.getPageAsText().contains("Successfully added"));
 
-			JMXUtils jmxUtils = JMXUtils.getInstanceForLocalJBoss();
+        // Change some property values that are already set
+        Map<String, String> propertiesMapChanges = new HashMap<String, String>();
+        propertiesMapChanges.put("xa-resource-timeout", "60000");
+        propertiesMapChanges.put("set-tx-query-timeout", "true");
+        propertiesMapChanges.put("user-name", "newUser");
 
-			Object state = jmxUtils.getMBeanAttribute(deploymentMBean, "State");
-			return !("DEPLOYED".equals( state.toString() ));
+        navigateToPage(propertiesMap.get("jndi-name"), 
+                       DatasourceType.XA_DATASOURCE, 
+                       "configurationTab");
+        assertFalse("The configuration page could not be displayed",
+                    client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
-		}
+        fillOutForm(propertiesMapChanges);
+        client.click("resourceConfigurationForm:saveButton");
 
-    
-    
-		@Override
-    protected Map<String, String> createLocalTXDatasource(String datasourceName) throws IOException {
-			return super.createLocalTXDatasource(datasourceName);
-    }
+        // Update our expected property values
+        propertiesMap.putAll(propertiesMapChanges);
 
-		@Override
-    protected Map<String, String> createNoTXDatasource(String datasourceName) throws IOException {
-			return super.createNoTXDatasource(datasourceName);
-    }
+        // Check for the appropriate success messages
+        String expectedMessage = "Successfully updated XA Datasource '" 
+                                 + propertiesMap.get("jndi-name") + "'";
+        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
 
-		@Override
-    protected Map<String, String> createXADatasource(String datasourceName) throws IOException {
-			return super.createXADatasource(datasourceName);
+        assertTrue(isDatasourceDeployed(propertiesMap.get("jndi-name"), 
+                                        DatasourceType.XA_DATASOURCE)); 
+        assertTrue(checkProperties(propertiesMap.get("jndi-name"), 
+                                   DatasourceType.XA_DATASOURCE, 
+                                   propertiesMap));
+
+        // Clean up
+        deleteDatasource(propertiesMap.get("jndi-name"));  
     }
+    
+    /**
+     * Change the value of some previously unset properties.
+     */
+    public void testConfigureDatasourceChangeUnsetProperties() throws IOException {
+        Map<String, String> propertiesMap = createLocalTXDatasource("ChangeUnsetPropertiesDS");
+        assertTrue("Error creating datasource", 
+                   client.getPageAsText().contains("Successfully added"));
 
+        // Set some property values that were previously unset
+        Map<String, String> propertiesMapChanges = new HashMap<String, String>();
+        propertiesMapChanges.put("valid-connection-checker-class-name", 
+                                 "org.jboss.resource.adapter.jdbc.CheckValidConnectionSQL");
+        propertiesMapChanges.put("set-tx-query-timeout", "true");
+        propertiesMapChanges.put("background-validation", "false");
+        propertiesMapChanges.put("allocation-retry", "10000");
 
+        navigateToPage(propertiesMap.get("jndi-name"), 
+                       DatasourceType.LOCAL_TX_DATASOURCE, 
+                       "configurationTab");
+        assertFalse("The configuration page could not be displayed",
+                    client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
+        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") + "'";
+        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));
 
-		
-
-    /**
-     * @return the suite of tests being tested
-     */
-    public static Test suite()
-    {
-       return new TestSuite(DatasourceTest.class);
+        // Clean up
+        deleteDatasource(propertiesMap.get("jndi-name"));   
     }
- 
 
-		@Override
-		protected String getDatasourceConfigFile( String jndiName ) {
-			//String jndiName = this.getDatasourceProperties().get("jndi-name");
-			return System.getProperty("jsfunit.deploy.dir") + "/" + jndiName + "-ds.xml";
-		}
+   /**
+    * Unset the value of some previously set properties. 
+    */ 
+    public void testConfigureDatasourceUnsetProperties() throws IOException {
+        Map<String, String> propertiesMap = createNoTXDatasource("UnsetPropertiesDS");
+        assertTrue("Error creating datasource", 
+                   client.getPageAsText().contains("Successfully added"));
 
+        // Unset some property values
+        navigateToPage(propertiesMap.get("jndi-name"), 
+                       DatasourceType.NO_TX_DATASOURCE, 
+                       "configurationTab");
+        assertFalse("The configuration page could not be displayed",
+                    client.getPageAsText().contains("There was an error retrieving the configuration for this resource"));
 
-		@Override
-		protected String getMBeanName( String jndiName, String serviceName ){
-			return "jboss.deployment:id=\"jboss.jca:name=" + jndiName + "," +
-							"service=" + serviceName + "\",type=Component";
-		}
+        enableOrDisableFormInput("user-name", Boolean.FALSE);
+        enableOrDisableFormInput("idle-timeout-minutes", Boolean.FALSE);
+        enableOrDisableFormInput("prefill", Boolean.FALSE);
+        client.click("resourceConfigurationForm:saveButton");
 
+        // Update our expected property values
+        propertiesMap.remove("user-name");
+        propertiesMap.remove("idle-timeout-minutes");
+        propertiesMap.remove("prefill");
 
+        // Check for the appropriate success messages
+        String expectedMessage = "Successfully updated No TX Datasource '" 
+                                 + propertiesMap.get("jndi-name") + "'";
+        checkClientAndServerMessages(expectedMessage, expectedMessage, false);
 
+        assertTrue(isDatasourceDeployed(propertiesMap.get("jndi-name"), 
+                                        DatasourceType.NO_TX_DATASOURCE)); 
+        assertTrue(checkProperties(propertiesMap.get("jndi-name"), 
+                                   DatasourceType.NO_TX_DATASOURCE, 
+                                   propertiesMap));
 
-}// DatasourceTest.java for AS 5
+        // Clean up
+        deleteDatasource(propertiesMap.get("jndi-name"));   
+    } 
+}
 




More information about the embjopr-commits mailing list