Author: ozizka(a)redhat.com
Date: 2009-01-28 16:50:27 -0500 (Wed, 28 Jan 2009)
New Revision: 126
Modified:
trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java
Log:
- Added some logging - records go to JBoss AS log
- Changed signature of some test methods - they throw AssertException. More about that on
mail / IRC
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-28
21:41:11 UTC (rev 125)
+++ trunk/jsfunit/src/test/java/org/jboss/jopr/jsfunit/DatasourceTestBase.java 2009-01-28
21:50:27 UTC (rev 126)
@@ -39,7 +39,6 @@
import javax.naming.Context;
import java.sql.SQLException;
import java.util.ArrayList;
-import java.util.logging.Level;
import javax.management.*;
/**
@@ -56,6 +55,7 @@
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");
@@ -70,6 +70,9 @@
protected final String xmlElementName;
public String getXmlElementName() { return xmlElementName; }
+ // Also server as value for HTML Radio for Datasource type selection.
+ public String getHtmlRadioValue() { return xmlElementName; }
+
protected final String templateHtmlSelectValue;
public String getTemplateHtmlSelectValue() { return templateHtmlSelectValue; }
@@ -152,7 +155,7 @@
/**
* Delete the datasource given by datasourceName.
*/
- protected abstract void deleteDatasource(String datasourceName) throws IOException;
+ protected abstract void deleteDatasource(String datasourceName) throws IOException,
AssertException;
/**
* Use JMX to check if the datasource given by datasourceName is deployed.
@@ -186,12 +189,18 @@
// Get the first and only one MBean returned.
ObjectName deploymentMBean = (ObjectName)dsMBeans.iterator().next();
/**/
- ObjectName deploymentMBean = new ObjectName( this.getMBeanName(jndiName,
dsMBeanServices[i]) );
+ 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.isMBeanStateDeployed( deploymentMBean ) )
+ if( this.isMBeanStateDeployedImpl( deploymentMBean ) ){
+ log.info("Found, OK");
+ }else{
+ log.info("Not found.");
return false;
+ }
}
@@ -209,7 +218,8 @@
*/
protected boolean checkProperties(String jndiName,
DatasourceType datasourceType,
- Map<String, String> expectedValuesMap) {
+ Map<String, String> expectedValuesMap)
+ {
Map<String, String> actualValuesMap = new HashMap<String, String>();
@@ -218,7 +228,8 @@
// 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());
+
SAXBuilder builder = new SAXBuilder();
Document doc = builder.build(file);
@@ -236,22 +247,25 @@
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
- }
- }
+ // 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;
+ }
+
+ 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());
throw new RuntimeException(e);
}
}
@@ -298,7 +312,7 @@
* Create a new datasource. Leave some property values, that aren't
* required, unset.
*/
- public void testCreateDatasource() throws IOException {
+ public void testCreateDatasource() throws IOException, AssertException {
// The properties we want to configure
@@ -538,7 +552,7 @@
/**
* Check that the metrics are correct after creating a new datasource.
*/
- public void testMetricsAfterDatasourceCreation() throws IOException {
+ public void testMetricsAfterDatasourceCreation() throws IOException, AssertException
{
// Min pool size will be 5, max pool size will be 20
Map<String, String> propertiesMap =
createLocalTXDatasource("MetricsCreateDS");
@@ -807,6 +821,8 @@
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.
@@ -823,16 +839,16 @@
// This super-exception includes JMX operation failures, including:
// AttributeNotFoundException, InstanceNotFoundException,
MalformedObjectNameException, ServiceNotFoundException
catch (OperationsException ex) {
- log.log(Level.WARNING, "JMX operation error when retrieving MBean
attribute.", ex);
+ log.warn("JMX operation error when retrieving MBean attribute.", ex);
return false;
}
// All other JMX failures...
catch (JMException ex) {
- log.log(Level.WARNING, "JMX error when retrieving MBean attribute.", ex);
+ log.warn("JMX error when retrieving MBean attribute.", ex);
return false;
}
catch (IOException ex) {
- log.log(Level.SEVERE, "I/O error when retrieving MBean attribute.", ex);
+ log.warn("I/O error when retrieving MBean attribute.", ex);
return false;
}