You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@beehive.apache.org by ek...@apache.org on 2005/10/25 19:09:34 UTC
svn commit: r328426 - in
/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder:
client/MasterTestRecorderJUnitTest.java shared/xmlbeans/XMLHelper.java
Author: ekoneil
Date: Tue Oct 25 10:09:29 2005
New Revision: 328426
URL: http://svn.apache.org/viewcvs?rev=328426&view=rev
Log:
Fixup the use of the TestDefinitionsDocument before switching it to XMLBeans.
BB: self
Test: NetUI DRT pass
Modified:
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/MasterTestRecorderJUnitTest.java
beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/MasterTestRecorderJUnitTest.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/MasterTestRecorderJUnitTest.java?rev=328426&r1=328425&r2=328426&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/MasterTestRecorderJUnitTest.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/client/MasterTestRecorderJUnitTest.java Tue Oct 25 10:09:29 2005
@@ -272,31 +272,14 @@
config = XMLHelper.getConfig( is, Constants.CONFIG_FILE );
}
catch ( Exception e ) {
- String msg = "ERROR: encountered exception processing resource( " + Constants.CONFIG_FILE + " )";
- log.fatal( msg, e );
- if ( e instanceof ConfigException ) {
- throw (ConfigException) e;
- }
- throw new ConfigException( msg, e );
+ String msg = "Encountered exception processing resource( " + Constants.CONFIG_FILE + " )";
+ throw new ConfigException(msg, e);
}
finally {
- try {
- if ( is != null ) {
- is.close();
- }
- }
- catch ( IOException e ) {
- if ( log.isWarnEnabled() ) {
- log.warn( "WARNING: received exception closing HTTP stream for( " + Constants.CONFIG_FILE +
- " )", e );
- }
- //ignore
- }
+ try {if ( is != null ) {is.close();}}catch(IOException ignore) {}
method.releaseConnection();
}
- if ( log.isInfoEnabled() ) {
- log.info( "config( " + config + " )" );
- }
+ log.info( "config( " + config + " )" );
method = new GetMethod( uri );
queryParams[2] = webappParam;
@@ -307,31 +290,14 @@
webapps = XMLHelper.getWebapps( is, Constants.WEBAPPS_FILE, config );
}
catch ( Exception e ) {
- String msg = "ERROR: encountered exception processing resource( " + Constants.WEBAPPS_FILE + " )";
- log.fatal( msg, e );
- if ( e instanceof ConfigException ) {
- throw (ConfigException) e;
- }
- throw new ConfigException( msg, e );
+ String msg = "Encountered exception processing resource( " + Constants.WEBAPPS_FILE + " )";
+ throw new ConfigException(msg, e);
}
finally {
- try {
- if ( is != null ) {
- is.close();
- }
- }
- catch ( IOException e ) {
- if ( log.isWarnEnabled() ) {
- log.warn( "WARNING: received exception closing HTTP stream for( " + Constants.WEBAPPS_FILE +
- " )", e );
- }
- // ignore
- }
+ try {if ( is != null ) is.close();}catch(IOException io) {}
method.releaseConnection();
}
- if ( log.isInfoEnabled() ) {
- log.info( "webapps( " + webapps + " )" );
- }
+ log.info( "webapps( " + webapps + " )" );
method = new GetMethod( uri );
queryParams[2] = testsParam;
@@ -339,35 +305,21 @@
is = executeXMLRequest( method, uri, Constants.TESTS_FILE );
TestDefinitions testDefinitions = null;
try {
- testDefinitions = XMLHelper.getTestDefinitionsInstance( is, Constants.TESTS_FILE, webapps,
- config.getBaseDirectory().getAbsolutePath() );
+ testDefinitions = XMLHelper.getTestDefinitionsInstance(is,
+ Constants.TESTS_FILE,
+ webapps,
+ config.getBaseDirectory().getAbsolutePath());
}
catch ( Exception e ) {
- String msg = "ERROR: encountered exception processing resource( " + Constants.TESTS_FILE + " )";
- log.fatal( msg, e );
- if ( e instanceof ConfigException ) {
- throw (ConfigException) e;
- }
- throw new ConfigException( msg, e );
+ String msg = "Encountered exception processing resource( " + Constants.TESTS_FILE + " )";
+ throw new ConfigException(msg, e);
}
finally {
- try {
- if ( is != null ) {
- is.close();
- }
- }
- catch ( IOException e ) {
- if ( log.isWarnEnabled() ) {
- log.warn( "WARNING: received exception closing HTTP stream for( " + Constants.TESTS_FILE +
- " )", e );
- }
- // ignore
- }
+ try {if (is != null) is.close();} catch(IOException ignore) {}
+
method.releaseConnection();
}
- if ( log.isDebugEnabled() ) {
-// log.debug( "testDefinitions( " + testDefinitions + " )" );
- }
+
return testDefinitions;
}
@@ -510,7 +462,6 @@
private static String getWebappsProperty() {
return getProperty( WEBAPPS_PROPERTY );
}
-
private static String getProperty( String prop ) {
String value = null;
Modified: beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java
URL: http://svn.apache.org/viewcvs/beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java?rev=328426&r1=328425&r2=328426&view=diff
==============================================================================
--- beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java (original)
+++ beehive/trunk/netui/src/testRecorder/org/apache/beehive/netui/tools/testrecorder/shared/xmlbeans/XMLHelper.java Tue Oct 25 10:09:29 2005
@@ -151,10 +151,11 @@
return server;
}
- public static RecordSessionBean getRecordSessionBean(File file) throws SessionXMLException, IOException {
- if (LOGGER.isInfoEnabled()) {
+ public static RecordSessionBean getRecordSessionBean(File file)
+ throws SessionXMLException, IOException {
+ if (LOGGER.isInfoEnabled())
LOGGER.info("file( " + file.getAbsolutePath() + " )");
- }
+
String resourceIdentifier = file.getAbsolutePath();
InputStream is = new FileInputStream(file);
@@ -446,16 +447,15 @@
public static TestDefinitions getTestDefinitionsInstance(ClassLoader loader) {
InputStream is = loader.getResourceAsStream(Constants.CONFIG_FILE);
- if (is == null) {
- throw new RuntimeConfigException("ERROR: unable to obtain the resource stream for resource( " +
- Constants.CONFIG_FILE + " )");
- }
+ if (is == null)
+ throw new RuntimeConfigException("ERROR: unable to obtain the resource stream for resource(" + Constants.CONFIG_FILE + ")");
+
Config config = null;
try {
config = getConfig(is, Constants.CONFIG_FILE);
}
finally {
- try {is.close();} catch (IOException ignore) {}
+ try{is.close();}catch(IOException ignore) {}
}
LOGGER.info("config( " + config + " )");
@@ -464,16 +464,21 @@
if (is == null)
throw new RuntimeConfigException("ERROR: unable to obtain the resource stream for resource( " + Constants.WEBAPPS_FILE + " )");
- Webapps webapps = XMLHelper.getWebapps(is, Constants.WEBAPPS_FILE, config);
+ Webapps webapps = null;
+ try {
+ webapps = getWebapps(is, Constants.WEBAPPS_FILE, config);
+ }
+ finally {
+ try{if(is != null)is.close();}catch(IOException ignore) {}
+ }
if (LOGGER.isInfoEnabled())
LOGGER.info("webapps( " + webapps + " )");
is = loader.getResourceAsStream(Constants.TESTS_FILE);
- if (is == null) {
- throw new RuntimeConfigException("ERROR: unable to obtain the resource stream for resource( " +
- Constants.TESTS_FILE + " )");
- }
+ if (is == null)
+ throw new RuntimeConfigException("Unable to obtain the resource stream for resource(" + Constants.TESTS_FILE + ")");
+
TestDefinitions testDefinitions = null;
try {
testDefinitions = getTestDefinitionsInstance(is,
@@ -485,9 +490,8 @@
throw new RuntimeConfigException(e.getMessage(), e);
}
catch (IOException e) {
- LOGGER.fatal("ERROR: encountered IOException processing resource( " + Constants.TESTS_FILE + " )", e);
- throw new RuntimeConfigException("ERROR: encountered IOException processing resource( " +
- Constants.TESTS_FILE + " ), message( " + e.getMessage(), e);
+ LOGGER.fatal("Encountered IOException processing resource(" + Constants.TESTS_FILE + ")", e);
+ throw new RuntimeConfigException("Encountered IOException processing resource(" + Constants.TESTS_FILE + " ). Cause: " + e, e);
}
finally {
try {is.close();} catch (IOException e) {}
@@ -671,81 +675,53 @@
doc = TestDefinitionsDocument.Factory.parse(is, loadOptions);
}
catch (XmlException e) {
- LOGGER.fatal("test recorder parse exception", e);
- ConfigException ce = new ConfigException("ERROR: parsing of test recorder test document failed, file( " +
- resourceIdentifier + " )", e);
- LOGGER.fatal(ce);
- throw ce;
+ throw new ConfigException("ERROR: parsing of test recorder test document failed, file(" + resourceIdentifier + ")", e);
}
finally {
- if (is != null) {
- is.close();
- }
+ try{if(is != null) {is.close();}}catch(IOException ignore) {}
}
assert doc != null;
- // may throw ConfigException
- validate(doc, resourceIdentifier,
- "ERROR: test recorder test definitions document is not valid against the schema");
+
+ validate(doc, resourceIdentifier, "Test Recorder test definitions document is not valid against the schema");
+
CategoryType[] categoryTypes = doc.getTestDefinitions().getCategories().getCategoryArray();
- //Categories categories = getCategoriesInstance(categoryTypes, baseDirPath);
- List list = new ArrayList();
- Category category = null;
- CategoryType type = null;
+ Category[] categoryArray = new Category[categoryTypes.length];
for (int i = 0; i < categoryTypes.length; i++) {
- type = categoryTypes[i];
- category = new Category(type.getName().trim(), type.getDescription().trim(), baseDirPath);
- list.add(category);
+ CategoryType type = categoryTypes[i];
+ categoryArray[i] = new Category(type.getName(), type.getDescription(), baseDirPath);
}
- Categories categories = new Categories((Category[]) list.toArray(new Category[list.size()]));
+ Categories categories = new Categories(categoryArray);
TestType[] testTypes = doc.getTestDefinitions().getTests().getTestArray();
- return getTestDefinitionsInstance(testTypes, categories, webapps);
- }
-
- private static TestDefinitions getTestDefinitionsInstance(TestType[] testTypes,
- Categories categories,
- Webapps webapps)
- throws ConfigException {
- List list = new ArrayList();
- TestDefinition testDef = null;
- TestType type = null;
- WebappConfig webapp = null;
+ ArrayList testDefinitions = new ArrayList();
for (int i = 0; i < testTypes.length; i++) {
- type = testTypes[i];
+ TestType testType = testTypes[i];
LinkedList testCategories = new LinkedList();
- if (type.getCategories() != null) {
- String[] testCategoryStrings = type.getCategories().getCategoryArray();
+ if (testType.getCategories() != null) {
+ String[] testCategoryStrings = testType.getCategories().getCategoryArray();
- String name = null;
- Category category = null;
for (int k = 0; k < testCategoryStrings.length; k++) {
- name = testCategoryStrings[k];
- category = categories.getCategory(name);
- if (category == null) {
- ConfigException ce = new ConfigException("ERROR: unable to determine test recorder category for name( " + name + " )");
- LOGGER.fatal(ce);
- throw ce;
- }
- testCategories.add(category);
+ Category testCategory = categories.getCategory(testCategoryStrings[k]);
+
+ if (testCategory == null)
+ throw new ConfigException("Unable to determine test recorder category for name(" + testCategoryStrings[k] + ")");
+
+ testCategories.add(testCategory);
}
}
- else testCategories = new LinkedList();
- webapp = webapps.getWebapp(type.getWebapp());
- if (webapp == null) {
- ConfigException ce = new ConfigException("ERROR: unable to find test recorder webapp with name( " +
- type.getWebapp() +
- " ) referenced in test definition( " + type.getName() + " )");
- LOGGER.fatal(ce);
- throw ce;
- }
- testDef = new TestDefinition(type.getName().trim(), type.getDescription().trim(), webapp, testCategories);
+ WebappConfig webapp = webapps.getWebapp(testType.getWebapp());
+ if (webapp == null)
+ throw new ConfigException("Unable to find test recorder webapp with name( " +testType.getWebapp() + " ) " +
+ "referenced in test definition( " + testType.getName() + " )");
+
+ TestDefinition testDef = new TestDefinition(testType.getName(), testType.getDescription(), webapp, testCategories);
categories.addTest(testDef);
- list.add(testDef);
+ testDefinitions.add(testDef);
}
- return new TestDefinitions(list, categories, webapps);
+ return new TestDefinitions(testDefinitions, categories, webapps);
}
private static void validate(XmlObject doc, String resourceIdentifier, String errorMsg)