crafterm 2002/10/08 03:39:38
Modified: xfc/src/test/org/apache/excalibur/xfc/test/util
ECMTestRig.java
xfc/src/test/org/apache/excalibur/xfc/test xfcTestCase.java
Added: xfc/src/test/org/apache/excalibur/xfc/test/util
FortressTestRig.java
xfc/src/test/org/apache/excalibur/xfc/test fortress.roles
Log:
Added tests for the Fortress conversion module
Revision Changes Path
1.2 +1 -13
jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/util/ECMTestRig.java
Index: ECMTestRig.java
===================================================================
RCS file:
/home/cvs/jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/util/ECMTestRig.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- ECMTestRig.java 7 Oct 2002 17:06:21 -0000 1.1
+++ ECMTestRig.java 8 Oct 2002 10:39:37 -0000 1.2
@@ -50,21 +50,9 @@
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
1.1
jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/util/FortressTestRig.java
Index: FortressTestRig.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.excalibur.xfc.model.RoleRef;
import org.apache.excalibur.xfc.modules.Fortress;
/**
* Fortress Module Test Rig. This class extends Fortress and provides several
accessor
* methods to internal Fortress methods that are otherwise not available from the
normal
* Module API.
*
* @author <a href="mailto:[EMAIL PROTECTED]">Marcus Crafter</a>
* @version CVS $Id: FortressTestRig.java,v 1.1 2002/10/08 10:39:37 crafterm Exp $
*/
public final class FortressTestRig extends Fortress
{
public Configuration buildRole( final RoleRef roleref )
throws Exception
{
return super.buildRole( roleref );
}
}
1.3 +113 -5
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.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- xfcTestCase.java 7 Oct 2002 17:06:22 -0000 1.2
+++ xfcTestCase.java 8 Oct 2002 10:39:38 -0000 1.3
@@ -65,6 +65,7 @@
import org.apache.excalibur.xfc.Module;
import org.apache.excalibur.xfc.test.util.ECMTestRig;
+import org.apache.excalibur.xfc.test.util.FortressTestRig;
import junit.framework.TestCase;
import junit.textui.TestRunner;
@@ -77,10 +78,17 @@
*/
public final class xfcTestCase extends TestCase
{
+ // location of ECM roles/xconf configuration data
private static final String ECM_ROLES =
"../testclasses/org/apache/excalibur/xfc/test/ecm.roles";
private static final String ECM_XCONF = "ecm.xconf";
+ // location of Fortress roles/xconf configuration data
+ private static final String FORTRESS_ROLES =
+ "../testclasses/org/apache/excalibur/xfc/test/fortress.roles";
+ private static final String FORTRESS_XCONF = "fortress.xconf";
+
+ // misc internals
private DefaultConfigurationBuilder m_builder = new
DefaultConfigurationBuilder();
private Logger m_logger = new NullLogger();
@@ -223,9 +231,111 @@
// all done, good show
}
- public void testXFC_Fortress()
+ /**
+ * Method to test the XFC Fortress 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_Fortress_generate()
+ throws Exception
{
- // REVISIT
+ // create an ECM module test rig instance
+ FortressTestRig ecm = new FortressTestRig();
+ ecm.enableLogging( m_logger );
+
+ // generate model from predefined configuration
+ Model model = ecm.generate( FORTRESS_ROLES + ":" + FORTRESS_XCONF );
+
+ // load the same config and manually verify that model is correct
+ Configuration[] rolesREAL =
+ m_builder.buildFromFile( FORTRESS_ROLES ).getChildren( "role" );
+ RoleRef[] rolesMODEL = model.getDefinitions();
+
+ // check that the generated model has the right number of roles
+ assertEquals(
+ "Model contains incorrect number of roles",
+ rolesREAL.length, rolesMODEL.length
+ );
+
+ // check each role has the right values, compared against the master copy
+ for ( int i = 0; i < rolesMODEL.length; ++i )
+ {
+ String modelRoleName = rolesMODEL[i].getRole();
+ Configuration masterRoleConfig = null;
+
+ // get the real role configuration object
+ for ( int j = 0; j < rolesREAL.length; ++j )
+ {
+ if ( modelRoleName.equals( rolesREAL[j].getAttribute( "name" ) ) )
+ {
+ masterRoleConfig = rolesREAL[j];
+ break;
+ }
+ }
+
+ // 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 )
+ );
+ }
+
+ // all done, good show
+ }
+
+ /**
+ * Method to test the XFC Fortress 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_Fortress_serialize()
+ throws Exception
+ {
+ String FORTRESS_ROLES_GENERATED = "fortress-generated.roles";
+
+ // create an ECM module test rig instance
+ FortressTestRig ecm = new FortressTestRig();
+ ecm.enableLogging( m_logger );
+
+ // generate model from predefined configuration
+ Model model = ecm.generate( FORTRESS_ROLES + ":" + FORTRESS_XCONF );
+
+ // serialize the model out to a temporary file
+ ecm.serialize( model, FORTRESS_ROLES_GENERATED + ":" + FORTRESS_XCONF );
+
+ // compare original with generated copy, they should be equal
+ Configuration master = m_builder.buildFromFile( FORTRESS_ROLES );
+ Configuration generated = m_builder.buildFromFile( FORTRESS_ROLES_GENERATED
);
+
+ assertTrue(
+ "Generated roles file differs from master " +
+ "master: " + FORTRESS_ROLES + ", generated: " +
FORTRESS_ROLES_GENERATED,
+ ConfigurationUtil.equals( master, generated )
+ );
+
+ // all done, good show
}
public static final void main( String[] args )
@@ -233,5 +343,3 @@
TestRunner.run( xfcTestCase.class );
}
}
-
-
1.1
jakarta-avalon-excalibur/xfc/src/test/org/apache/excalibur/xfc/test/fortress.roles
Index: fortress.roles
===================================================================
<role-list>
<role name="org.apache.excalibur.fortress.examples.components.Translator">
<component shorthand="translator"
class="org.apache.excalibur.fortress.examples.components.TranslatorImpl"
handler="org.apache.excalibur.fortress.handler.ThreadSafeComponentHandler"/>
</role>
</role-list>
--
To unsubscribe, e-mail: <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>