crafterm 2002/10/07 10:06:22
Modified: xfc/src/test/org/apache/excalibur/xfc/test xfcTestCase.java
Added: xfc/src/test/org/apache/excalibur/xfc/test/util
ECMTestRig.java
Log:
* Updated XFC test case to test the generation and serialization stages of the
ECM module.
* Added a new ECMTestRig utility class which lets the testcase class use itself
for checking it's internals.
Revision Changes Path
1.1
jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/util/ECMTestRig.java
Index: ECMTestRig.java
===================================================================
/*
============================================================================
The Apache Software License, Version 1.1
============================================================================
Copyright (C) @year@ The Apache Software Foundation. All rights reserved.
Redistribution and use in source and binary forms, with or without modifica-
tion, are permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.
3. The end-user documentation included with the redistribution, if any, must
include the following acknowledgment: "This product includes software
developed by the Apache Software Foundation (http://www.apache.org/)."
Alternately, this acknowledgment may appear in the software itself, if
and wherever such third-party acknowledgments normally appear.
4. The names "Jakarta", "Avalon", "Excalibur" and "Apache Software Foundation"
must not be used to endorse or promote products derived from this software
without prior written permission. For written permission, please contact
[EMAIL PROTECTED]
5. Products derived from this software may not be called "Apache", nor may
"Apache" appear in their name, without prior written permission of the
Apache Software Foundation.
THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED WARRANTIES,
INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
APACHE SOFTWARE FOUNDATION OR ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLU-
DING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS
OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
(INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
This software consists of voluntary contributions made by many individuals
on behalf of the Apache Software Foundation. For more information on the
Apache Software Foundation, please see <http://www.apache.org/>.
*/
package org.apache.excalibur.xfc.test.util;
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.logger.ConsoleLogger;
import org.apache.avalon.framework.logger.NullLogger;
import org.apache.excalibur.configuration.ConfigurationUtil;
import org.apache.excalibur.xfc.modules.ECM;
import org.apache.excalibur.xfc.model.Definition;
import org.apache.excalibur.xfc.model.Model;
import org.apache.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.Main;
import org.apache.excalibur.xfc.Module;
import junit.framework.TestCase;
import junit.textui.TestRunner;
/**
* ECM Module Test Rig. This class extends ECM and provides several accessor methods
to
* internal ECM methods that are otherwise not available from the normal Module API.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: ECMTestRig.java,v 1.1 2002/10/07 17:06:21 crafterm Exp $
*/
public final class ECMTestRig extends ECM
{
public Configuration buildRole( final RoleRef roleref )
throws Exception
{
return super.buildRole( roleref );
}
}
1.2 +88 -59
jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/xfcTestCase.java
Index: xfcTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/xfcTestCase.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- xfcTestCase.java 7 Oct 2002 14:31:20 -0000 1.1
+++ xfcTestCase.java 7 Oct 2002 17:06:22 -0000 1.2
@@ -52,9 +52,10 @@
import org.apache.avalon.framework.configuration.Configuration;
import org.apache.avalon.framework.configuration.DefaultConfigurationBuilder;
import org.apache.avalon.framework.logger.ConsoleLogger;
+import org.apache.avalon.framework.logger.Logger;
import org.apache.avalon.framework.logger.NullLogger;
-//import org.apache.excalibur.configuration.ConfigurationUtil;
+import org.apache.excalibur.configuration.ConfigurationUtil;
import org.apache.excalibur.xfc.modules.ECM;
import org.apache.excalibur.xfc.model.Definition;
@@ -63,11 +64,13 @@
import org.apache.excalibur.xfc.Main;
import org.apache.excalibur.xfc.Module;
+import org.apache.excalibur.xfc.test.util.ECMTestRig;
+
import junit.framework.TestCase;
import junit.textui.TestRunner;
/**
- * XFC TestCase
+ * XFC TestCase.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id$
@@ -79,6 +82,7 @@
private static final String ECM_XCONF = "ecm.xconf";
private DefaultConfigurationBuilder m_builder = new
DefaultConfigurationBuilder();
+ private Logger m_logger = new NullLogger();
public xfcTestCase()
{
@@ -100,7 +104,8 @@
{
try
{
- Module ecm = getModule( ECM.class );
+ Module ecm = new ECM();
+ ecm.enableLogging( m_logger );
Model model = ecm.generate( "just-roles-no-xconf" );
fail( "Context validation failed" );
@@ -112,91 +117,115 @@
}
/**
- * Method to test the ECM XFC module.
+ * Method to test the XFC ECM module, generation stage.
+ *
+ * <p>
+ * This test case compares a generated {@link Model} instance with
+ * the configuration file that was used to create it. If any differences
+ * are found, assertions should occur.
+ * </p>
*
* @exception Exception if an error occurs
*/
- public void testXFC_ECM()
+ public void testXFC_ECM_generate()
throws Exception
{
- Module ecm = getModule( ECM.class );
+ // create an ECM module test rig instance
+ ECMTestRig ecm = new ECMTestRig();
+ ecm.enableLogging( m_logger );
+
+ // generate model from predefined configuration
Model model = ecm.generate( ECM_ROLES + ":" + ECM_XCONF );
- Configuration[] real_roles =
+
+ // load the same config and manually verify that model is correct
+ Configuration[] rolesREAL =
m_builder.buildFromFile( ECM_ROLES ).getChildren( "role" );
- RoleRef[] model_roles = model.getDefinitions();
+ RoleRef[] rolesMODEL = model.getDefinitions();
// check that the generated model has the right number of roles
assertEquals(
"Model contains incorrect number of roles",
- real_roles.length,
- model_roles.length
+ rolesREAL.length, rolesMODEL.length
);
- // check each role has the right values
- for ( int i = 0; i < model_roles.length; ++i )
+ // check each role has the right values, compared against the master copy
+ for ( int i = 0; i < rolesMODEL.length; ++i )
{
- RoleRef r = model_roles[i];
- String roleName = r.getRole();
- Configuration realRole = null;
+ String modelRoleName = rolesMODEL[i].getRole();
+ Configuration masterRoleConfig = null;
// get the real role configuration object
- for ( int j = 0; j < real_roles.length; ++j )
+ for ( int j = 0; j < rolesREAL.length; ++j )
{
- if ( roleName.equals( real_roles[j].getAttribute( "name" ) ) )
+ if ( modelRoleName.equals( rolesREAL[j].getAttribute( "name" ) ) )
{
- realRole = real_roles[j];
+ masterRoleConfig = rolesREAL[j];
break;
}
}
- assertNotNull( "Configuration for role " + roleName + " not found",
realRole );
+ // check that we found a Configuration fragment for the role in the
model
+ assertNotNull(
+ "Master Configuration for role '" + modelRoleName + "' not found",
+ masterRoleConfig
+ );
+
+ // convert our RoleRef object into a Configuration and compare with the
master
+ Configuration modelRoleConfig = ecm.buildRole( rolesMODEL[i] );
+
+ assertTrue(
+ "Role configuration trees differ\n" +
+ "(master)" + ConfigurationUtil.list( masterRoleConfig ) +
+ "(model)" + ConfigurationUtil.list( modelRoleConfig ),
+ ConfigurationUtil.equals( masterRoleConfig, modelRoleConfig )
+ );
+ }
- Definition[] providers = model_roles[i].getProviders();
+ // all done, good show
+ }
- if ( providers.length > 1 )
- {
- // component selector
- // REVISIT.
- }
- else
- {
- // single component
+ /**
+ * Method to test the XFC ECM module, serialization stage.
+ *
+ * <p>
+ * This test case serializes a given {@link Model} instance to a
+ * temporary file, and the resultant file is compared against the
+ * original. If any differences are found, assertions should occur.
+ * </p>
+ *
+ * @exception Exception if an error occurs
+ */
+ public void testXFC_ECM_serialize()
+ throws Exception
+ {
+ String ECM_ROLES_GENERATED = "ecm-generated.roles";
- // check that the role name from the model is correct
- assertEquals(
- "Role names not equal",
- model_roles[i].getRole(),
- realRole.getAttribute( "name" )
- );
-
- // check that the shorthand name from the model is correct
- assertEquals(
- "Shorthand names not equal",
- providers[0].getShorthand(),
- realRole.getAttribute( "shorthand" )
- );
-
- // check that the default-class name from the model is correct
- assertEquals(
- "Default-class names not equal",
- providers[0].getDefaultClass(),
- realRole.getAttribute( "default-class" )
- );
- }
- }
+ // create an ECM module test rig instance
+ ECMTestRig ecm = new ECMTestRig();
+ ecm.enableLogging( m_logger );
+
+ // generate model from predefined configuration
+ Model model = ecm.generate( ECM_ROLES + ":" + ECM_XCONF );
+
+ // serialize the model out to a temporary file
+ ecm.serialize( model, ECM_ROLES_GENERATED + ":" + ECM_XCONF );
+
+ // compare original with generated copy, they should be equal
+ Configuration master = m_builder.buildFromFile( ECM_ROLES );
+ Configuration generated = m_builder.buildFromFile( ECM_ROLES_GENERATED );
+
+ assertTrue(
+ "Generated roles file differs from master " +
+ "master: " + ECM_ROLES + ", generated: " + ECM_ROLES_GENERATED,
+ ConfigurationUtil.equals( master, generated )
+ );
+
+ // all done, good show
}
public void testXFC_Fortress()
{
// REVISIT
- }
-
- private Module getModule( final Class clazz )
- throws Exception
- {
- Module module = (Module) clazz.newInstance();
- module.enableLogging( new NullLogger() /*ConsoleLogger()*/ );
- return module;
}
public static final void main( String[] args )
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>