hlship 2004/06/21 07:25:45
Modified: framework/src/test/hivemind/test/services
TestEventLinker.java TestEagerLoader.java
TestBuilderFactory.java
library/src/test/hivemind/test/lib
TestSpringLookupFactory.java
TestDefaultImplementationBuilder.java
library/src/java/org/apache/hivemind/lib/pipeline
PipelineStrings.properties PipelineMessages.java
PipelineAssembler.java
framework/src/test/hivemind/test/rules
TestEnumerationTranslator.java
TestConfigurationTranslator.java TestSetModule.java
TestObjectTranslator.java
TestServicePointTranslator.java
TestPushAttributeRule.java
framework/src/java/org/apache/hivemind/test
HiveMindTestCase.java
framework build.xml
library/src/test/org/apache/hivemind/lib/factory
TestBeanTranslator.java TestBeanFactoryImpl.java
framework/src/test/hivemind/test TestMisc.java
framework/src/test/hivemind/test/impl
TestRegistryAssemblyImpl.java
. status.xml
framework/src/test/org/apache/hivemind/impl
TestErrorHandler.java TestSchemaProcessor.java
framework/src/test/org/apache/hivemind/schema/rules
TestIdTranslators.java
library/src/test/org/apache/hivemind/lib/pipeline
TestPipelineAssembler.java TestBridgeBuilder.java
framework/src/test/org/apache/hivemind/order
TestOrderer.java
Log:
Add several methods to HiveMindTestCase to manage MockControl instances.
Revision Changes Path
1.4 +13 -17
jakarta-hivemind/framework/src/test/hivemind/test/services/TestEventLinker.java
Index: TestEventLinker.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestEventLinker.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- TestEventLinker.java 15 Jun 2004 19:26:37 -0000 1.3
+++ TestEventLinker.java 21 Jun 2004 14:25:44 -0000 1.4
@@ -90,8 +90,7 @@
EventProducer p = new EventProducer();
Object c = "NeverwinterNights";
- MockControl control =
MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) control.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -99,7 +98,7 @@
location,
null);
- control.replay();
+ replayControls();
EventLinker l = new EventLinkerImpl(null, eh);
@@ -107,7 +106,7 @@
assertEquals(0, p.getListenerCount());
- control.verify();
+ verifyControls();
}
public void testNoMatchingName() throws Exception
@@ -116,8 +115,7 @@
EventProducer p = new EventProducer();
Object c = "SoulCailiburII";
- MockControl control =
MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) control.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -125,7 +123,7 @@
location,
null);
- control.replay();
+ replayControls();
EventLinker l = new EventLinkerImpl(null, eh);
@@ -133,7 +131,7 @@
assertEquals(0, p.getListenerCount());
- control.verify();
+ verifyControls();
}
public void testIncompatible() throws Exception
@@ -142,8 +140,7 @@
EventProducer p = new EventProducer();
Object c = "SplinterCell";
- MockControl control =
MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) control.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -151,7 +148,7 @@
location,
null);
- control.replay();
+ replayControls();
EventLinker l = new EventLinkerImpl(null, eh);
@@ -159,7 +156,7 @@
assertEquals(0, p.getListenerCount());
- control.verify();
+ verifyControls();
}
public void testNoProducer() throws Exception
@@ -168,8 +165,7 @@
Object p = "DanceDanceRevolution";
Object c = "SplinterCell";
- MockControl control =
MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) control.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -177,13 +173,13 @@
location,
null);
- control.replay();
+ replayControls();
EventLinker l = new EventLinkerImpl(null, eh);
l.addEventListener(p, null, c, location);
- control.verify();
+ verifyControls();
}
public void testInsideBuilderFactory() throws Exception
1.2 +4 -5
jakarta-hivemind/framework/src/test/hivemind/test/services/TestEagerLoader.java
Index: TestEagerLoader.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestEagerLoader.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestEagerLoader.java 19 May 2004 02:30:53 -0000 1.1
+++ TestEagerLoader.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -27,7 +27,6 @@
* Tests for the [EMAIL PROTECTED]
org.apache.hivemind.service.impl.EagerLoader} service.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestEagerLoader extends FrameworkTestCase
{
@@ -36,11 +35,11 @@
EagerLoader el = new EagerLoader();
List l = new ArrayList();
- MockControl control =
MockControl.createStrictControl(ServicePoint.class);
- ServicePoint sp = (ServicePoint) control.getMock();
+ ServicePoint sp = (ServicePoint) newMock(ServicePoint.class);
sp.forceServiceInstantiation();
- control.replay();
+
+ replayControls();
l.add(sp);
@@ -48,7 +47,7 @@
el.run();
- control.verify();
+ verifyControls();
}
public void testEagerLoadSingleton() throws Exception
1.6 +10 -12
jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java
Index: TestBuilderFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/services/TestBuilderFactory.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestBuilderFactory.java 18 Jun 2004 21:39:00 -0000 1.5
+++ TestBuilderFactory.java 21 Jun 2004 14:25:44 -0000 1.6
@@ -72,7 +72,7 @@
public void testBuilderErrorHandlerFacet()
{
- MockControl c = MockControl.createStrictControl(Module.class);
+ MockControl c = newControl(Module.class);
Module m = (Module) c.getMock();
ErrorHandler eh = new DefaultErrorHandler();
@@ -80,7 +80,7 @@
m.getErrorHandler();
c.setReturnValue(eh);
- c.replay();
+ replayControls();
BuilderFacet f = new BuilderErrorHandlerFacet();
@@ -88,7 +88,7 @@
assertSame(eh, actual);
- c.verify();
+ verifyControls();
}
public void testSetErrorHandler() throws Exception
@@ -119,13 +119,13 @@
{
ClassResolver cr = new DefaultClassResolver();
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module module = (Module) control.getMock();
module.getClassResolver();
control.setReturnValue(cr);
- control.replay();
+ replayControls();
BuilderClassResolverFacet fc = new BuilderClassResolverFacet();
@@ -133,7 +133,7 @@
assertSame(cr, result);
- control.verify();
+ verifyControls();
}
public void testSetClassResolver() throws Exception
@@ -172,13 +172,13 @@
p.addProperty(new BuilderErrorHandlerFacet());
p.addProperty(new BuilderServiceIdFacet());
- MockControl c = MockControl.createStrictControl(Module.class);
+ MockControl c = newControl(Module.class);
Module module = (Module) c.getMock();
ErrorHandler eh = new DefaultErrorHandler();
ClassResolver cr = new DefaultClassResolver();
- MockControl messagesControl =
MockControl.createStrictControl(Messages.class);
+ MockControl messagesControl = newControl(Messages.class);
Messages messages = (Messages) messagesControl.getMock();
module.getErrorHandler();
@@ -196,8 +196,7 @@
module.getErrorHandler();
c.setReturnValue(eh);
- c.replay();
- messagesControl.replay();
+ replayControls();
AutowireTarget t =
(AutowireTarget) factory.createCoreServiceImplementation(
@@ -212,7 +211,6 @@
assertSame(LogFactory.getLog("foo.bar.Baz"), t.getLog());
assertEquals("foo.bar.Baz", t.getServiceId());
- c.verify();
- messagesControl.verify();
+ verifyControls();
}
}
1.2 +6 -7
jakarta-hivemind/library/src/test/hivemind/test/lib/TestSpringLookupFactory.java
Index: TestSpringLookupFactory.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/hivemind/test/lib/TestSpringLookupFactory.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestSpringLookupFactory.java 1 Jun 2004 14:17:14 -0000 1.1
+++ TestSpringLookupFactory.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -35,7 +35,6 @@
* service implementation factory.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestSpringLookupFactory extends HiveMindTestCase
{
@@ -64,7 +63,7 @@
{
SpringLookupFactory lf = new SpringLookupFactory();
- MockControl control =
MockControl.createStrictControl(BeanFactory.class);
+ MockControl control = newControl(BeanFactory.class);
BeanFactory beanFactory = (BeanFactory) control.getMock();
lf.setDefaultBeanFactorySource(buildSource(beanFactory));
@@ -76,20 +75,20 @@
beanFactory.getBean("fred", List.class);
control.setReturnValue(fred);
- control.replay();
+ replayControls();
Object actual = lf.createCoreServiceImplementation("fred",
List.class, null, params);
assertSame(fred, actual);
- control.verify();
+ verifyControls();
}
public void testBeanSpecificFactory()
{
SpringLookupFactory lf = new SpringLookupFactory();
- MockControl control =
MockControl.createStrictControl(BeanFactory.class);
+ MockControl control = newControl(BeanFactory.class);
BeanFactory beanFactory = (BeanFactory) control.getMock();
List params = buildParameters("fred", beanFactory);
@@ -99,13 +98,13 @@
beanFactory.getBean("fred", List.class);
control.setReturnValue(fred);
- control.replay();
+ replayControls();
Object actual = lf.createCoreServiceImplementation("fred",
List.class, null, params);
assertSame(fred, actual);
- control.verify();
+ verifyControls();
}
public void testSpringIntegration() throws Exception
1.3 +17 -13
jakarta-hivemind/library/src/test/hivemind/test/lib/TestDefaultImplementationBuilder.java
Index: TestDefaultImplementationBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/hivemind/test/lib/TestDefaultImplementationBuilder.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestDefaultImplementationBuilder.java 9 Jun 2004 14:56:31 -0000
1.2
+++ TestDefaultImplementationBuilder.java 21 Jun 2004 14:25:44 -0000
1.3
@@ -19,8 +19,8 @@
import org.apache.hivemind.internal.Module;
import org.apache.hivemind.internal.RegistryInfrastructure;
import org.apache.hivemind.lib.DefaultImplementationBuilder;
-import org.apache.hivemind.lib.impl.PlaceholderFactory;
import org.apache.hivemind.lib.impl.DefaultImplementationBuilderImpl;
+import org.apache.hivemind.lib.impl.PlaceholderFactory;
import org.apache.hivemind.service.impl.ClassFactoryImpl;
import org.apache.hivemind.test.HiveMindTestCase;
import org.easymock.MockControl;
@@ -35,7 +35,6 @@
{
private DefaultImplementationBuilder _builder;
- private MockControl _moduleControl;
private Module _module;
protected void setUp() throws Exception
@@ -49,22 +48,23 @@
private void setupModule()
{
- _moduleControl = MockControl.createStrictControl(Module.class);
- _module = (Module) _moduleControl.getMock();
+ MockControl c = newControl(Module.class);
+ _module = (Module) c.getMock();
_module.getModuleId();
- _moduleControl.setReturnValue("some.id");
+ c.setReturnValue("some.id");
_module.getClassResolver();
- _moduleControl.setReturnValue(new DefaultClassResolver());
+ c.setReturnValue(new DefaultClassResolver());
- _moduleControl.replay();
}
private Object create(Class interfaceType)
{
setupModule();
+ replayControls();
+
return _builder.buildDefaultImplementation(interfaceType, _module);
}
@@ -76,7 +76,7 @@
assertEquals("<Default implementation of interface
java.lang.Runnable>", r.toString());
- _moduleControl.verify();
+ verifyControls();
}
public void testComplex()
@@ -87,7 +87,7 @@
assertEquals(false, vh.getBooleanValue());
assertEquals(0, vh.getIntValue());
- _moduleControl.verify();
+ verifyControls();
}
public void testToStringInInterface()
@@ -96,7 +96,7 @@
assertNull(ts.toString());
- _moduleControl.verify();
+ verifyControls();
}
public void testCache()
@@ -106,7 +106,7 @@
assertSame(r1, r2);
- _moduleControl.verify();
+ verifyControls();
}
public void testNotInterface()
@@ -133,11 +133,13 @@
setupModule();
+ replayControls();
+
Runnable o = (Runnable)
dib.buildDefaultImplementation(Runnable.class, _module);
o.run();
- _moduleControl.verify();
+ verifyControls();
}
public void testPlaceholderBuilderSimulated() throws Exception
@@ -148,12 +150,14 @@
setupModule();
+ replayControls();
+
Runnable r =
(Runnable) db.createCoreServiceImplementation("foo",
Runnable.class, _module, null);
r.run();
- _moduleControl.verify();
+ verifyControls();
}
public void testPlaceholderFactory() throws Exception
1.2 +2 -2
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineStrings.properties
Index: PipelineStrings.properties
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineStrings.properties,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- PipelineStrings.properties 9 Jun 2004 14:58:16 -0000 1.1
+++ PipelineStrings.properties 21 Jun 2004 14:25:44 -0000 1.2
@@ -19,6 +19,6 @@
unmatched-service-method=Service interface method {0} has no match in filter
interface {1}.
-duplicate-terminator=Terminator {0} (at {1}) for pipeline service {2}
conflicts with previous terminator ({3}, at {4}) and has been ignored.
+duplicate-terminator=Terminator {0} for pipeline service {1} conflicts with
previous terminator ({2}, at {3}) and has been ignored.
-incorrect-interface={0} (at {1}) is not an instance of interface {2}
suitable for use as part of the pipeline for service {3}.
\ No newline at end of file
+incorrect-interface={0} is not an instance of interface {1} suitable for use
as part of the pipeline for service {2}.
\ No newline at end of file
1.4 +4 -12
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineMessages.java
Index: PipelineMessages.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineMessages.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -r1.3 -r1.4
--- PipelineMessages.java 17 Jun 2004 15:16:13 -0000 1.3
+++ PipelineMessages.java 21 Jun 2004 14:25:44 -0000 1.4
@@ -55,7 +55,6 @@
public static String duplicateTerminator(
Object terminator,
- Location terminatorLocation,
String serviceId,
Object existingTerminator,
Location existingLocation)
@@ -64,24 +63,17 @@
"duplicate-terminator",
new Object[] {
terminator,
- HiveMind.getLocationString(terminatorLocation),
serviceId,
existingTerminator,
HiveMind.getLocationString(existingLocation)});
}
- public static String incorrectInterface(
- Object instance,
- Location location,
- Class interfaceType,
- String serviceId)
+ public static String incorrectInterface(Object instance, Class
interfaceType, String serviceId)
{
return _formatter.format(
"incorrect-interface",
- new Object[] {
- instance,
- HiveMind.getLocationString(location),
- interfaceType.getName(),
- serviceId });
+ instance,
+ interfaceType.getName(),
+ serviceId);
}
}
1.3 +1 -2
jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineAssembler.java
Index: PipelineAssembler.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/java/org/apache/hivemind/lib/pipeline/PipelineAssembler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- PipelineAssembler.java 10 Jun 2004 19:49:40 -0000 1.2
+++ PipelineAssembler.java 21 Jun 2004 14:25:44 -0000 1.3
@@ -105,7 +105,6 @@
_log,
PipelineMessages.duplicateTerminator(
terminator,
- terminatorLocation,
_serviceId,
_terminator,
_terminatorLocation),
@@ -135,7 +134,7 @@
_errorHandler.error(
_log,
- PipelineMessages.incorrectInterface(instance, location,
interfaceType, _serviceId),
+ PipelineMessages.incorrectInterface(instance, interfaceType,
_serviceId),
location,
null);
1.7 +26 -34
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestEnumerationTranslator.java
Index: TestEnumerationTranslator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestEnumerationTranslator.java,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- TestEnumerationTranslator.java 25 May 2004 22:31:41 -0000 1.6
+++ TestEnumerationTranslator.java 21 Jun 2004 14:25:44 -0000 1.7
@@ -30,11 +30,21 @@
* Tests for [EMAIL PROTECTED]
org.apache.hivemind.schema.rules.EnumerationTranslator}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestEnumerationTranslator extends FrameworkTestCase
{
+ private Module getModule()
+ {
+ MockControl c = newControl(Module.class);
+ Module result = (Module) c.getMock();
+
+ result.getClassResolver();
+ c.setReturnValue(new DefaultClassResolver());
+
+ return result;
+ }
+
private Element forgeElement()
{
ElementImpl e = new ElementImpl();
@@ -46,28 +56,23 @@
public void testNull()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
+ Module m = (Module) newMock(Module.class);
- c.replay();
+ replayControls();
EnumerationTranslator t =
new
EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
assertEquals(null, t.translate(m, null, null));
- c.verify();
+ verifyControls();
}
public void testMatch()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
+ Module m = getModule();
- m.getClassResolver();
- c.setReturnValue(new DefaultClassResolver());
-
- c.replay();
+ replayControls();
EnumerationTranslator t =
new
EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
@@ -75,18 +80,14 @@
assertEquals(Boolean.TRUE, t.translate(m, null, "true"));
assertEquals(Boolean.FALSE, t.translate(m, null, "false"));
- c.verify();
+ verifyControls();
}
public void testBadClass()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
-
- m.getClassResolver();
- c.setReturnValue(new DefaultClassResolver());
+ Module m = getModule();
- c.replay();
+ replayControls();
EnumerationTranslator t =
new
EnumerationTranslator("lava.jang.Boolean,true=TRUE,false=FALSE");
@@ -102,18 +103,14 @@
assertExceptionSubstring(ex, "Could not load class
lava.jang.Boolean");
}
- c.verify();
+ verifyControls();
}
public void testUnrecognizedValue() throws Exception
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
+ Module m = getModule();
- m.getClassResolver();
- c.setReturnValue(new DefaultClassResolver());
-
- c.replay();
+ replayControls();
EnumerationTranslator t =
new
EnumerationTranslator("java.lang.Boolean,true=TRUE,false=FALSE");
@@ -129,19 +126,14 @@
assertExceptionSubstring(ex, "'fred' is not a recognized
enumerated value.");
}
- c.verify();
-
+ verifyControls();
}
public void testBadField() throws Exception
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
-
- m.getClassResolver();
- c.setReturnValue(new DefaultClassResolver());
+ Module m = getModule();
- c.replay();
+ replayControls();
EnumerationTranslator t =
new
EnumerationTranslator("java.lang.Boolean,true=HONEST_TO_GOD_TRUE,false=FALSE");
@@ -158,7 +150,7 @@
"Unable to obtain value for static field
java.lang.Boolean.HONEST_TO_GOD_TRUE");
}
- c.verify();
+ verifyControls();
}
}
1.10 +4 -7
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestConfigurationTranslator.java
Index: TestConfigurationTranslator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestConfigurationTranslator.java,v
retrieving revision 1.9
retrieving revision 1.10
diff -u -r1.9 -r1.10
--- TestConfigurationTranslator.java 15 Jun 2004 20:35:56 -0000 1.9
+++ TestConfigurationTranslator.java 21 Jun 2004 14:25:44 -0000 1.10
@@ -28,25 +28,22 @@
* Tests for [EMAIL PROTECTED]
org.apache.hivemind.schema.rules.ConfigurationTranslator}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestConfigurationTranslator extends FrameworkTestCase
{
public void testNull()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
-
- c.replay();
+ Module m = (Module) newMock(Module.class);
+ replayControls();
ConfigurationTranslator t = new ConfigurationTranslator();
assertNull(t.translate(m, null, null));
- c.verify();
+ verifyControls();
}
-
+
public void testConfigurationTranslator() throws Exception
{
RegistryInfrastructure r =
buildFrameworkRegistry("ConfigurationTranslator.xml");
1.6 +4 -4
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestSetModule.java
Index: TestSetModule.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestSetModule.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- TestSetModule.java 19 May 2004 15:08:47 -0000 1.5
+++ TestSetModule.java 21 Jun 2004 14:25:44 -0000 1.6
@@ -48,7 +48,7 @@
public void testSetModuleRule()
{
- MockControl control =
MockControl.createStrictControl(SchemaProcessor.class);
+ MockControl control = newControl(SchemaProcessor.class);
SchemaProcessor p = (SchemaProcessor) control.getMock();
Module m = new ModuleImpl();
@@ -60,7 +60,7 @@
p.getContributingModule();
control.setReturnValue(m);
- control.replay();
+ replayControls();
SetModuleRule rule = new SetModuleRule();
@@ -70,6 +70,6 @@
assertSame(m, t.getModule());
- control.verify();
+ verifyControls();
}
}
1.11 +10 -9
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestObjectTranslator.java
Index: TestObjectTranslator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestObjectTranslator.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- TestObjectTranslator.java 25 May 2004 22:31:41 -0000 1.10
+++ TestObjectTranslator.java 21 Jun 2004 14:25:44 -0000 1.11
@@ -35,7 +35,6 @@
* [EMAIL PROTECTED] org.apache.hivemind.schema.rules.ClassTranslator}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestObjectTranslator extends FrameworkTestCase
{
@@ -54,13 +53,13 @@
Location l = new
LocationImpl(getResource("TestObjectTranslator.class"), 50);
e.setLocation(l);
- MockControl c = MockControl.createStrictControl(Module.class);
+ MockControl c = newControl(Module.class);
Module m = (Module) c.getMock();
m.getClassResolver();
c.setReturnValue(new DefaultClassResolver());
- c.replay();
+ replayControls();
try
{
@@ -71,7 +70,7 @@
assertExceptionSubstring(ex, "Could not load class
bad.class.Name");
}
- c.verify();
+ verifyControls();
}
public void testPrivateObject() throws Exception
@@ -81,13 +80,13 @@
Location l = new
LocationImpl(getResource("TestObjectTranslator.class"), 50);
e.setLocation(l);
- MockControl c = MockControl.createStrictControl(Module.class);
+ MockControl c = newControl(Module.class);
Module m = (Module) c.getMock();
m.getClassResolver();
c.setReturnValue(new DefaultClassResolver());
- c.replay();
+ replayControls();
try
{
@@ -101,6 +100,8 @@
"Class org.apache.hivemind.schema.rules.ObjectTranslator can
not access a member "
+ "of class hivemind.test.rules.PrivateObject");
}
+
+ verifyControls();
}
public void testWrongType() throws Exception
@@ -121,13 +122,13 @@
public void testClassTranslator() throws Exception
{
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
m.getClassResolver();
control.setReturnValue(new DefaultClassResolver());
- control.replay();
+ replayControls();
ClassTranslator t = new ClassTranslator();
@@ -135,6 +136,6 @@
assertEquals(getClass(), c);
- control.verify();
+ verifyControls();
}
}
1.2 +11 -14
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestServicePointTranslator.java
Index: TestServicePointTranslator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestServicePointTranslator.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestServicePointTranslator.java 19 May 2004 02:30:54 -0000 1.1
+++ TestServicePointTranslator.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -26,30 +26,27 @@
* Test for the [EMAIL PROTECTED]
org.apache.hivemind.schema.rules.ServicePointTranslator}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestServicePointTranslator extends HiveMindTestCase
{
public void testServicePointTranslator()
{
- // This is my first try using EasyMock. Pretty nifty stuff.
-
- MockControl control = MockControl.createStrictControl(Module.class);
- Module m = (Module)control.getMock();
-
+ MockControl control = newControl(Module.class);
+ Module m = (Module) control.getMock();
+
ServicePoint sp = new ServicePointImpl();
-
+
m.getServicePoint("Fred");
control.setReturnValue(sp);
-
- control.replay();
-
+
+ replayControls();
+
Translator t = new ServicePointTranslator();
-
+
ServicePoint result = (ServicePoint) t.translate(m, null, "Fred");
-
+
assertSame(sp, result);
-
- control.verify();
+
+ verifyControls();
}
}
1.3 +4 -9
jakarta-hivemind/framework/src/test/hivemind/test/rules/TestPushAttributeRule.java
Index: TestPushAttributeRule.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/rules/TestPushAttributeRule.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPushAttributeRule.java 19 May 2004 15:08:47 -0000 1.2
+++ TestPushAttributeRule.java 21 Jun 2004 14:25:44 -0000 1.3
@@ -29,7 +29,7 @@
{
public void testPushAttributeRule()
{
- MockControl control =
MockControl.createStrictControl(SchemaProcessor.class);
+ MockControl control = newControl(SchemaProcessor.class);
ElementImpl element = new ElementImpl();
element.setElementName("myelement");
@@ -49,23 +49,18 @@
mockProcessor.getContributingModule();
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
- Module m = (Module) moduleControl.getMock();
-
- control.setReturnValue(m);
+ control.setReturnValue(newMock(Module.class));
mockProcessor.push("flintstone");
mockProcessor.pop();
control.setReturnValue("flintstone");
- control.replay();
- moduleControl.replay();
+ replayControls();
rule.begin(mockProcessor, element);
rule.end(mockProcessor, element);
- control.verify();
- moduleControl.verify();
+ verifyControls();
}
}
1.6 +70 -1
jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java
Index: HiveMindTestCase.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/java/org/apache/hivemind/test/HiveMindTestCase.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -u -r1.5 -r1.6
--- HiveMindTestCase.java 10 Jun 2004 13:29:30 -0000 1.5
+++ HiveMindTestCase.java 21 Jun 2004 14:25:44 -0000 1.6
@@ -15,6 +15,8 @@
package org.apache.hivemind.test;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.Iterator;
import java.util.List;
import java.util.Locale;
@@ -36,6 +38,7 @@
import org.apache.oro.text.regex.Pattern;
import org.apache.oro.text.regex.Perl5Compiler;
import org.apache.oro.text.regex.Perl5Matcher;
+import org.easymock.MockControl;
/**
* Contains some support for creating HiveMind tests; this is useful enough
that
@@ -54,6 +57,10 @@
private static Perl5Compiler _compiler;
private static Perl5Matcher _matcher;
+ /** List of [EMAIL PROTECTED] org.easymock.MockControl}. */
+
+ private List _controls = new ArrayList();
+
/**
* Returns the given file as a [EMAIL PROTECTED] Resource} from the
classpath. Typically,
* this is to find files in the same folder as the invoking class.
@@ -314,7 +321,7 @@
/**
* Builds a minimal registry, containing only the specified files, plus
- * the master module descriptor.
+ * the master module descriptor (i.e., those visible on the classpath).
* Files are resolved using [EMAIL PROTECTED]
HiveMindTestCase#getResource(String)}.
*/
protected RegistryInfrastructure buildFrameworkRegistry(String[] files)
throws Exception
@@ -348,4 +355,66 @@
return builder.constructRegistry(Locale.getDefault());
}
+ /**
+ * Creates a <em>managed</em> control via
+ * [EMAIL PROTECTED] MockControl#createStrictControl(java.lang.Class)}.
+ * The created control is remembered, and will be
+ * invoked by [EMAIL PROTECTED] #replayControls()} and
+ * [EMAIL PROTECTED] #verifyControls()}.
+ */
+ protected MockControl newControl(Class mockClass)
+ {
+ MockControl result = MockControl.createStrictControl(mockClass);
+
+ addControl(result);
+
+ return result;
+ }
+
+ /**
+ * Adds the control to the list of managed controls used by
+ * [EMAIL PROTECTED] #replayControls()} and [EMAIL PROTECTED]
#verifyControls()}.
+ */
+ protected void addControl(MockControl control)
+ {
+ _controls.add(control);
+ }
+
+ /**
+ * Convienience for invoking [EMAIL PROTECTED] #newControl(Class)} and
then
+ * invoking [EMAIL PROTECTED] MockControl#getMock()} on the result.
+ */
+ protected Object newMock(Class mockClass)
+ {
+ return newControl(mockClass).getMock();
+ }
+
+ /**
+ * Invokes [EMAIL PROTECTED] MockControl#replay()} on all controls
+ * created by [EMAIL PROTECTED] #newControl(Class)}.
+ */
+ protected void replayControls()
+ {
+ Iterator i = _controls.iterator();
+ while (i.hasNext())
+ {
+ MockControl c = (MockControl) i.next();
+ c.replay();
+ }
+ }
+
+ /**
+ * Invokes [EMAIL PROTECTED] org.easymock.MockControl#verify()} on all
+ * controls created by [EMAIL PROTECTED] #newControl(Class)}.
+ */
+
+ protected void verifyControls()
+ {
+ Iterator i = _controls.iterator();
+ while (i.hasNext())
+ {
+ MockControl c = (MockControl) i.next();
+ c.verify();
+ }
+ }
}
1.7 +1 -2 jakarta-hivemind/framework/build.xml
Index: build.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/framework/build.xml,v
retrieving revision 1.6
retrieving revision 1.7
diff -u -r1.6 -r1.7
--- build.xml 17 Jun 2004 15:16:14 -0000 1.6
+++ build.xml 21 Jun 2004 14:25:44 -0000 1.7
@@ -30,8 +30,7 @@
<ibiblio-dependency jar="servletapi-2.3.jar"
group-id="servletapi"/>
<ibiblio-dependency jar="oro-2.0.6.jar" group-id="oro"/>
<ibiblio-dependency jar="log4j-1.2.7.jar" group-id="log4j"/>
-
- <ibiblio-dependency jar="easymock-1.1.jar" group-id="easymock"
use="test"/>
+ <ibiblio-dependency jar="easymock-1.1.jar" group-id="easymock"/>
<run-javacc
input="${javacc.src.dir}/SimpleDataLanguageParser.jj"
package-path="org/apache/hivemind/sdl/parser"/>
1.3 +4 -6
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/factory/TestBeanTranslator.java
Index: TestBeanTranslator.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/factory/TestBeanTranslator.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestBeanTranslator.java 15 Jun 2004 19:26:37 -0000 1.2
+++ TestBeanTranslator.java 21 Jun 2004 14:25:44 -0000 1.3
@@ -73,10 +73,10 @@
{
String result = "Obtained via BeanFactory.";
- MockControl factoryControl =
MockControl.createStrictControl(BeanFactory.class);
+ MockControl factoryControl = newControl(BeanFactory.class);
BeanFactory factory = (BeanFactory) factoryControl.getMock();
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
+ MockControl moduleControl = newControl(Module.class);
Module module = (Module) moduleControl.getMock();
module.getService("factory", BeanFactory.class);
@@ -85,14 +85,12 @@
factory.get("my-bean,initialized");
factoryControl.setReturnValue(result);
- moduleControl.replay();
- factoryControl.replay();
+ replayControls();
Translator t = new BeanTranslator();
assertSame(result, t.translate(module, null,
"factory:my-bean,initialized"));
- moduleControl.verify();
- factoryControl.verify();
+ verifyControls();
}
}
1.2 +9 -12
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/factory/TestBeanFactoryImpl.java
Index: TestBeanFactoryImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/factory/TestBeanFactoryImpl.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBeanFactoryImpl.java 15 Jun 2004 00:45:59 -0000 1.1
+++ TestBeanFactoryImpl.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -56,12 +56,11 @@
{
List l = Collections.singletonList(build(name, objectClass));
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(null, message, null, null);
- c.replay();
+ replayControls();
BeanFactoryImpl f = new BeanFactoryImpl(null, eh, Object.class, l,
true);
@@ -75,7 +74,7 @@
assertEquals(FactoryMessages.unknownContribution(name),
ex.getMessage());
}
- c.verify();
+ verifyControls();
}
public void testInterfaceContribution()
@@ -106,8 +105,7 @@
{
List l = Collections.singletonList(build("array-list",
ArrayList.class));
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -115,7 +113,7 @@
null,
null);
- c.replay();
+ replayControls();
BeanFactoryImpl f = new BeanFactoryImpl(null, eh, Map.class, l,
true);
@@ -129,7 +127,7 @@
assertEquals(FactoryMessages.unknownContribution("array-list"),
ex.getMessage());
}
- c.verify();
+ verifyControls();
}
public void testDupeName()
@@ -138,8 +136,7 @@
l.add(build("list", ArrayList.class));
l.add(build("list", LinkedList.class));
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(
null,
@@ -147,7 +144,7 @@
null,
null);
- c.replay();
+ replayControls();
BeanFactoryImpl f = new BeanFactoryImpl(null, eh, Collection.class,
l, true);
@@ -155,7 +152,7 @@
assertTrue(o instanceof ArrayList);
- c.verify();
+ verifyControls();
}
public void testTranslator()
1.18 +13 -15
jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java
Index: TestMisc.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/TestMisc.java,v
retrieving revision 1.17
retrieving revision 1.18
diff -u -r1.17 -r1.18
--- TestMisc.java 17 Jun 2004 15:16:15 -0000 1.17
+++ TestMisc.java 21 Jun 2004 14:25:44 -0000 1.18
@@ -37,7 +37,6 @@
* Additional tests to fill in minor code coverage gaps.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestMisc extends FrameworkTestCase
{
@@ -100,10 +99,9 @@
public void testCreateClassServiceConstructorAccessors()
{
- MockControl control = MockControl.createStrictControl(Module.class);
- Module m = (Module) control.getMock();
+ Module m = (Module) newMock(Module.class);
- control.replay();
+ replayControls();
CreateClassServiceConstructor c = new
CreateClassServiceConstructor();
@@ -115,18 +113,18 @@
assertEquals("java.util.HashMap", c.getInstanceClassName());
- control.verify();
+ verifyControls();
}
public void testCreateClassServiceConstructorTwice()
{
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
- m.getClassResolver();
- control.setReturnValue(new DefaultClassResolver());
+ m.getClassResolver();
+ control.setReturnValue(new DefaultClassResolver());
- control.replay();
+ replayControls();
CreateClassServiceConstructor c = new
CreateClassServiceConstructor();
@@ -142,18 +140,18 @@
assertTrue(o1 instanceof HashMap);
assertTrue(o2 instanceof HashMap);
- control.verify();
+ verifyControls();
}
public void testCreateClassServiceConstructorFailure()
{
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
- m.getClassResolver();
- control.setReturnValue(new DefaultClassResolver());
+ m.getClassResolver();
+ control.setReturnValue(new DefaultClassResolver());
- control.replay();
+ replayControls();
CreateClassServiceConstructor c = new
CreateClassServiceConstructor();
@@ -173,7 +171,7 @@
"Unable to find a constructor for class
hivemind.test.PrivateBean.");
}
- control.verify();
+ verifyControls();
}
public void testSystemPropertiesSymbolSource()
1.5 +7 -11
jakarta-hivemind/framework/src/test/hivemind/test/impl/TestRegistryAssemblyImpl.java
Index: TestRegistryAssemblyImpl.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/hivemind/test/impl/TestRegistryAssemblyImpl.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestRegistryAssemblyImpl.java 15 Jun 2004 20:48:19 -0000 1.4
+++ TestRegistryAssemblyImpl.java 21 Jun 2004 14:25:44 -0000 1.5
@@ -29,7 +29,6 @@
* Suite of tests for [EMAIL PROTECTED] TestRegistryAssemblyImpl}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestRegistryAssemblyImpl extends HiveMindTestCase
{
@@ -47,23 +46,22 @@
public void testAddSchema()
{
RegistryAssemblyImpl ra = new RegistryAssemblyImpl(new
DefaultErrorHandler());
- MockControl control = MockControl.createStrictControl(Schema.class);
- Schema s = (Schema) control.getMock();
+ Schema s = (Schema) newMock(Schema.class);
- control.replay();
+ replayControls();
ra.addSchema("foo.manchu", s);
assertSame(s, ra.getSchema("foo.manchu"));
- control.verify();
+ verifyControls();
}
public void testAddDupeSchema() throws Exception
{
RegistryAssemblyImpl ra = new RegistryAssemblyImpl(new
DefaultErrorHandler());
- MockControl c1 = MockControl.createStrictControl(Schema.class);
- MockControl c2 = MockControl.createStrictControl(Schema.class);
+ MockControl c1 = newControl(Schema.class);
+ MockControl c2 = newControl(Schema.class);
Schema s1 = (Schema) c1.getMock();
Schema s2 = (Schema) c2.getMock();
@@ -80,8 +78,7 @@
s2.getLocation();
c2.setReturnValue(l2);
- c1.replay();
- c2.replay();
+ replayControls();
ra.addSchema("foo.bar", s1);
ra.addSchema("foo.bar", s2);
@@ -90,8 +87,7 @@
assertSame(s1, ra.getSchema("foo.bar"));
- c1.verify();
- c2.verify();
+ verifyControls();
}
public void testAddPostProcessor()
1.11 +7 -0 jakarta-hivemind/status.xml
Index: status.xml
===================================================================
RCS file: /home/cvs/jakarta-hivemind/status.xml,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -r1.10 -r1.11
--- status.xml 18 Jun 2004 21:39:01 -0000 1.10
+++ status.xml 21 Jun 2004 14:25:44 -0000 1.11
@@ -65,6 +65,13 @@
implementation, and to autowire common properties (log, messages,
serviceId, errorHandler, classResolver) if the properties are
writeable
and of the correct type. </action>
+ <action type="update" dev="HLS">
+ Added methods <code>newControl()</code>, <code>newMock()</code>,
+ <code>addControl()</code>, <code>replayControls()</code>
+ and <code>verifyControls()</code> to <code>HiveMindTestCase</code>
+ to simplify test cases that use multiple
+ <link href="http://www.easymock.org">EasyMock</link> mock objects.
+ </action>
</release>
</changes>
</status>
1.2 +6 -8
jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestErrorHandler.java
Index: TestErrorHandler.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestErrorHandler.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestErrorHandler.java 10 Jun 2004 19:49:40 -0000 1.1
+++ TestErrorHandler.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -32,8 +32,7 @@
{
public void testDefaultErrorHandlerWithLocation()
{
- MockControl c = MockControl.createStrictControl(Log.class);
- Log log = (Log) c.getMock();
+ Log log = (Log) newMock(Log.class);
Resource r = new ClasspathResource(new DefaultClassResolver(),
"/foo/bar/Baz.module");
Location l = new LocationImpl(r, 13);
@@ -42,30 +41,29 @@
log.error("Error at classpath:/foo/bar/Baz.module, line 13: Bad frob
value.", ex);
- c.replay();
+ replayControls();
ErrorHandler eh = new DefaultErrorHandler();
eh.error(log, "Bad frob value.", l, ex);
- c.verify();
+ verifyControls();
}
public void testDefaultErrorHandlerWithNoLocation()
{
- MockControl c = MockControl.createStrictControl(Log.class);
- Log log = (Log) c.getMock();
+ Log log = (Log) newMock(Log.class);
Throwable ex = new IllegalArgumentException();
log.error("Error: Bad frob value.", ex);
- c.replay();
+ replayControls();
ErrorHandler eh = new DefaultErrorHandler();
eh.error(log, "Bad frob value.", null, ex);
- c.verify();
+ verifyControls();
}
}
1.3 +12 -13
jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java
Index: TestSchemaProcessor.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/impl/TestSchemaProcessor.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestSchemaProcessor.java 10 Jun 2004 19:49:40 -0000 1.2
+++ TestSchemaProcessor.java 21 Jun 2004 14:25:44 -0000 1.3
@@ -38,7 +38,6 @@
* [EMAIL PROTECTED] org.apache.hivemind.impl.SchemaElement}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestSchemaProcessor extends HiveMindTestCase
{
@@ -70,7 +69,7 @@
List elements = Collections.singletonList(element);
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
m.getClassResolver();
@@ -82,18 +81,18 @@
m.getTranslator("smart");
control.setReturnValue(new NullTranslator());
- control.replay();
+ replayControls();
p.process(elements, m);
- control.verify();
-
List l = p.getElements();
assertEquals(1, l.size());
StringHolder h = (StringHolder) l.get(0);
assertEquals("flintstone", h.getValue());
+
+ verifyControls();
}
public void testGetContentTranslatorUnspecified()
@@ -123,7 +122,7 @@
List elements = Collections.singletonList(element);
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
m.getClassResolver();
@@ -132,18 +131,18 @@
m.expandSymbols("flintstone", null);
control.setReturnValue("flintstone");
- control.replay();
+ replayControls();
p.process(elements, m);
- control.verify();
-
List l = p.getElements();
assertEquals(1, l.size());
StringHolder h = (StringHolder) l.get(0);
assertEquals("flintstone", h.getValue());
+
+ verifyControls();
}
public void testGetAttributeTranslator()
@@ -178,7 +177,7 @@
List elements = Collections.singletonList(element);
- MockControl control = MockControl.createStrictControl(Module.class);
+ MockControl control = newControl(Module.class);
Module m = (Module) control.getMock();
m.getClassResolver();
@@ -190,17 +189,17 @@
m.getTranslator("service");
control.setReturnValue(new NullTranslator());
- control.replay();
+ replayControls();
p.process(elements, m);
- control.verify();
-
List l = p.getElements();
assertEquals(1, l.size());
StringHolder h = (StringHolder) l.get(0);
assertEquals("wilma", h.getValue());
+
+ verifyControls();
}
}
1.2 +16 -13
jakarta-hivemind/framework/src/test/org/apache/hivemind/schema/rules/TestIdTranslators.java
Index: TestIdTranslators.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/schema/rules/TestIdTranslators.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestIdTranslators.java 9 Jun 2004 14:48:56 -0000 1.1
+++ TestIdTranslators.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -34,21 +34,28 @@
assertNull(t.translate(null, null, null));
}
- public void testNonNullId()
+ private Module getModule()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
+ MockControl c = newControl(Module.class);
+ Module result = (Module) c.getMock();
- m.getModuleId();
+ result.getModuleId();
c.setReturnValue("foo.bar");
- c.replay();
+ return result;
+ }
+
+ public void testNonNullId()
+ {
+ Module m = getModule();
+
+ replayControls();
Translator t = new QualifiedIdTranslator();
assertEquals("foo.bar.Baz", t.translate(m, null, "Baz"));
- c.verify();
+ verifyControls();
}
public void testNullList()
@@ -60,18 +67,14 @@
public void testNonNullList()
{
- MockControl c = MockControl.createStrictControl(Module.class);
- Module m = (Module) c.getMock();
-
- m.getModuleId();
- c.setReturnValue("foo.bar");
+ Module m = getModule();
- c.replay();
+ replayControls();
Translator t = new IdListTranslator();
assertEquals("foo.bar.Baz,zip.Zap", t.translate(m, null,
"Baz,zip.Zap"));
- c.verify();
+ verifyControls();
}
}
1.3 +37 -51
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestPipelineAssembler.java
Index: TestPipelineAssembler.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestPipelineAssembler.java,v
retrieving revision 1.2
retrieving revision 1.3
diff -u -r1.2 -r1.3
--- TestPipelineAssembler.java 10 Jun 2004 19:49:40 -0000 1.2
+++ TestPipelineAssembler.java 21 Jun 2004 14:25:44 -0000 1.3
@@ -37,9 +37,6 @@
*/
public class TestPipelineAssembler extends HiveMindTestCase
{
- private MockControl _logControl;
- private MockControl _errorHandlerControl;
-
private static class StandardInner implements StandardService
{
private String _desciption;
@@ -62,34 +59,29 @@
private Log getLog()
{
- _logControl = MockControl.createStrictControl(Log.class);
- _logControl.replay();
-
- return (Log) _logControl.getMock();
+ return (Log) newMock(Log.class);
}
private ErrorHandler getErrorHandler()
{
- _errorHandlerControl =
MockControl.createStrictControl(ErrorHandler.class);
- _errorHandlerControl.replay();
-
- return (ErrorHandler) _errorHandlerControl.getMock();
+ return (ErrorHandler) newMock(ErrorHandler.class);
}
public void testTerminatorConflict()
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
+ MockControl c = newControl(ErrorHandler.class);
ErrorHandler eh = (ErrorHandler) c.getMock();
Log log = getLog();
eh.error(
log,
- "Terminator ss2 (at unknown location) for pipeline service
foo.bar conflicts with "
+ "Terminator ss2 for pipeline service foo.bar conflicts with "
+ "previous terminator (ss1, at unknown location) and has
been ignored.",
null,
null);
- c.replay();
+
+ replayControls();
PipelineAssembler pa =
new PipelineAssembler(
@@ -110,24 +102,23 @@
assertSame(ss1, pa.getTerminator());
- c.verify();
- _logControl.verify();
+ verifyControls();
}
public void testIncorrectTerminatorType()
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = getErrorHandler();
Log log = getLog();
eh.error(
log,
- "-String- (at unknown location) is not an instance of interface "
+ "-String- is not an instance of interface "
+ "org.apache.hivemind.lib.pipeline.StandardService suitable
for "
+ "use as part of the pipeline for service foo.bar.",
null,
null);
- c.replay();
+
+ replayControls();
PipelineAssembler pa =
new PipelineAssembler(
@@ -144,24 +135,23 @@
assertNull(pa.getTerminator());
- c.verify();
- _logControl.verify();
+ verifyControls();
}
public void testIncorrectFilterType()
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = getErrorHandler();
Log log = getLog();
eh.error(
log,
- "-String- (at unknown location) is not an instance of interface "
+ "-String- is not an instance of interface "
+ "org.apache.hivemind.lib.pipeline.StandardFilter suitable
for "
+ "use as part of the pipeline for service foo.bar.",
null,
null);
- c.replay();
+
+ replayControls();
PipelineAssembler pa =
new PipelineAssembler(
@@ -176,19 +166,17 @@
pa.addFilter("filter-name", null, null, "-String-", null);
- c.verify();
- _logControl.verify();
+ verifyControls();
}
public void testPassThruToPlaceholder()
{
-
ClassFactory cf = new ClassFactoryImpl();
DefaultImplementationBuilderImpl dib = new
DefaultImplementationBuilderImpl();
dib.setClassFactory(cf);
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
+ MockControl moduleControl = newControl(Module.class);
Module module = (Module) moduleControl.getMock();
module.getModuleId();
@@ -197,12 +185,15 @@
module.getClassResolver();
moduleControl.setReturnValue(new DefaultClassResolver());
- moduleControl.replay();
+ ErrorHandler eh = getErrorHandler();
+ Log log = getLog();
+
+ replayControls();
PipelineAssembler pa =
new PipelineAssembler(
- getLog(),
- getErrorHandler(),
+ log,
+ eh,
"foo.bar",
StandardService.class,
StandardFilter.class,
@@ -214,9 +205,7 @@
assertEquals(0, pipeline.run(99));
- moduleControl.verify();
- _logControl.verify();
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testFilterChain()
@@ -226,7 +215,7 @@
dib.setClassFactory(cf);
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
+ MockControl moduleControl = newControl(Module.class);
Module module = (Module) moduleControl.getMock();
module.getModuleId();
@@ -235,8 +224,6 @@
module.getClassResolver();
moduleControl.setReturnValue(new DefaultClassResolver());
- moduleControl.replay();
-
PipelineAssembler pa =
new PipelineAssembler(
getLog(),
@@ -248,6 +235,8 @@
dib,
module);
+ replayControls();
+
pa.setTerminator(new StandardInner("ss"), null);
StandardFilter adder = new StandardFilter()
@@ -284,9 +273,7 @@
assertEquals(14, pipeline.run(5));
assertEquals(24, pipeline.run(10));
- moduleControl.verify();
- _logControl.verify();
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPipelineFactoryWithTerminator()
@@ -296,7 +283,7 @@
dib.setClassFactory(cf);
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
+ MockControl moduleControl = newControl(Module.class);
Module module = (Module) moduleControl.getMock();
module.getModuleId();
@@ -305,7 +292,6 @@
module.getClassResolver();
moduleControl.setReturnValue(new DefaultClassResolver());
- moduleControl.replay();
PipelineFactory factory = new PipelineFactory();
factory.setServiceId("factory-id");
@@ -327,6 +313,8 @@
pp.setPipelineConfiguration(l);
+ replayControls();
+
StandardService s =
(StandardService) factory.createCoreServiceImplementation(
"example",
@@ -337,8 +325,7 @@
assertEquals(24, s.run(12));
assertEquals(18, s.run(9));
- moduleControl.verify();
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPipelineFactoryNoTerminator()
@@ -348,7 +335,7 @@
dib.setClassFactory(cf);
- MockControl moduleControl =
MockControl.createStrictControl(Module.class);
+ MockControl moduleControl = newControl(Module.class);
Module module = (Module) moduleControl.getMock();
module.getModuleId();
@@ -357,8 +344,6 @@
module.getClassResolver();
moduleControl.setReturnValue(new DefaultClassResolver());
- moduleControl.replay();
-
PipelineFactory factory = new PipelineFactory();
factory.setServiceId("factory-id");
factory.setClassFactory(cf);
@@ -383,6 +368,8 @@
pp.setPipelineConfiguration(l);
+ replayControls();
+
StandardService s =
(StandardService) factory.createCoreServiceImplementation(
"example",
@@ -393,8 +380,7 @@
assertEquals(24, s.run(12));
assertEquals(18, s.run(9));
- moduleControl.verify();
- _errorHandlerControl.verify();
+ verifyControls();
}
/**
1.2 +33 -36
jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestBridgeBuilder.java
Index: TestBridgeBuilder.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/library/src/test/org/apache/hivemind/lib/pipeline/TestBridgeBuilder.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -u -r1.1 -r1.2
--- TestBridgeBuilder.java 9 Jun 2004 14:58:16 -0000 1.1
+++ TestBridgeBuilder.java 21 Jun 2004 14:25:44 -0000 1.2
@@ -36,26 +36,25 @@
{
private ClassFactory _classFactory = new ClassFactoryImpl();
- private MockControl _moduleControl;
- private Module _module;
-
- private void setupModule()
+ private Module setupModule()
{
- _moduleControl = MockControl.createStrictControl(Module.class);
- _module = (Module) _moduleControl.getMock();
+ MockControl control = newControl(Module.class);
+ Module result = (Module) control.getMock();
- _module.getModuleId();
- _moduleControl.setReturnValue("foo.bar");
+ result.getModuleId();
+ control.setReturnValue("foo.bar");
- _module.getClassResolver();
- _moduleControl.setReturnValue(new DefaultClassResolver());
+ result.getClassResolver();
+ control.setReturnValue(new DefaultClassResolver());
- _moduleControl.replay();
+ return result;
}
public void testStandard()
{
- setupModule();
+ Module module = setupModule();
+
+ replayControls();
BridgeBuilder bb =
new BridgeBuilder(
@@ -64,7 +63,7 @@
StandardService.class,
StandardFilter.class,
_classFactory,
- _module);
+ module);
StandardFilter sf = new StandardFilter()
{
@@ -96,12 +95,14 @@
"<PipelineBridge for service
foo.bar(org.apache.hivemind.lib.pipeline.StandardService)>",
bridge.toString());
- _moduleControl.verify();
+ verifyControls();
}
public void testToString()
{
- setupModule();
+ Module module = setupModule();
+
+ replayControls();
BridgeBuilder bb =
new BridgeBuilder(
@@ -110,7 +111,7 @@
ToStringService.class,
ToStringFilter.class,
_classFactory,
- _module);
+ module);
ToStringFilter f = new ToStringFilter()
{
@@ -132,20 +133,18 @@
assertEquals("SERVICE", bridge.toString());
- _moduleControl.verify();
+ verifyControls();
}
public void testExtraServiceMethod()
{
- setupModule();
-
- MockControl logControl = MockControl.createStrictControl(Log.class);
- Log log = (Log) logControl.getMock();
+ Module module = setupModule();
+ Log log = (Log) newMock(Log.class);
log.error(
"Service interface method void extraServiceMethod() has no match
in filter interface java.io.Serializable.");
- logControl.replay();
+ replayControls();
BridgeBuilder bb =
new BridgeBuilder(
@@ -154,7 +153,7 @@
ExtraServiceMethod.class,
Serializable.class,
_classFactory,
- _module);
+ module);
ExtraServiceMethod esm = (ExtraServiceMethod)
bb.instantiateBridge(null, null);
@@ -170,23 +169,20 @@
ex.getMessage());
}
- _moduleControl.verify();
- logControl.verify();
+ verifyControls();
}
public void testExtraFilterMethod()
{
- setupModule();
-
- MockControl logControl = MockControl.createStrictControl(Log.class);
- Log log = (Log) logControl.getMock();
+ Module module = setupModule();
+ Log log = (Log) newMock(Log.class);
log.error(
"Method void extraFilterMethod() of filter interface "
+ "org.apache.hivemind.lib.pipeline.ExtraFilterMethod does
not have a matching service "
+ "interface method (in interface java.io.Serializable,
service foo.bar).");
- logControl.replay();
+ replayControls();
BridgeBuilder bb =
new BridgeBuilder(
@@ -195,19 +191,20 @@
Serializable.class,
ExtraFilterMethod.class,
_classFactory,
- _module);
+ module);
Object bridge = bb.instantiateBridge(null, null);
assertEquals(true, bridge instanceof Serializable);
- _moduleControl.verify();
- logControl.verify();
+ verifyControls();
}
public void testServiceInTheMiddle()
{
- setupModule();
+ Module module = setupModule();
+
+ replayControls();
BridgeBuilder bb =
new BridgeBuilder(
@@ -216,7 +213,7 @@
MiddleService.class,
MiddleFilter.class,
_classFactory,
- _module);
+ module);
MiddleFilter mf = new MiddleFilter()
{
@@ -250,6 +247,6 @@
assertEquals("CODE: aaa AAAA", buffer.toString());
- _moduleControl.verify();
+ verifyControls();
}
}
1.5 +35 -30
jakarta-hivemind/framework/src/test/org/apache/hivemind/order/TestOrderer.java
Index: TestOrderer.java
===================================================================
RCS file:
/home/cvs/jakarta-hivemind/framework/src/test/org/apache/hivemind/order/TestOrderer.java,v
retrieving revision 1.4
retrieving revision 1.5
diff -u -r1.4 -r1.5
--- TestOrderer.java 15 Jun 2004 20:35:56 -0000 1.4
+++ TestOrderer.java 21 Jun 2004 14:25:44 -0000 1.5
@@ -33,21 +33,16 @@
* Tests for the [EMAIL PROTECTED] org.apache.hivemind.order.Orderer}.
*
* @author Howard Lewis Ship
- * @version $Id$
*/
public class TestOrderer extends FrameworkTestCase
{
private static final Log LOG = LogFactory.getLog(TestOrderer.class);
- private MockControl _errorHandlerControl;
-
private ErrorHandler getErrorHandler()
{
- _errorHandlerControl =
MockControl.createStrictControl(ErrorHandler.class);
- _errorHandlerControl.replay();
-
- return (ErrorHandler) _errorHandlerControl.getMock();
+ return (ErrorHandler) newMock(ErrorHandler.class);
}
+
public void testNoDependencies() throws Exception
{
Orderer o = new Orderer(getErrorHandler(), "cartoon character");
@@ -57,11 +52,13 @@
o.add("WILMA", "wilma", null, null);
o.add("BETTY", "betty", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "FRED", "BARNEY", "WILMA", "BETTY"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPrereq() throws Exception
@@ -73,11 +70,13 @@
o.add("BETTY", "betty", null, null);
o.add("WILMA", "wilma", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "WILMA", "FRED", "BETTY", "BARNEY"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPostreq() throws Exception
@@ -89,11 +88,13 @@
o.add("BETTY", "betty", null, null);
o.add("WILMA", "wilma", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "FRED", "BARNEY", "BETTY", "WILMA"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPrePostreq() throws Exception
@@ -105,21 +106,22 @@
o.add("BETTY", "betty", null, null);
o.add("WILMA", "wilma", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "FRED", "WILMA", "BARNEY", "BETTY"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testUnknownPrereq() throws Exception
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(LOG, "Unknown cartoon character dependency 'charlie' (for
'fred').", null, null);
- c.replay();
+ replayControls();
Orderer o = new Orderer(LOG, eh, "cartoon character");
@@ -132,17 +134,16 @@
assertListsEqual(new Object[] { "FRED", "WILMA", "BARNEY", "BETTY"
}, l);
- c.verify();
+ verifyControls();
}
public void testUnknownPostreq() throws Exception
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
- ErrorHandler eh = (ErrorHandler) c.getMock();
+ ErrorHandler eh = (ErrorHandler) newMock(ErrorHandler.class);
eh.error(LOG, "Unknown cartoon character dependency 'dino' (for
'betty').", null, null);
- c.replay();
+ replayControls();
Orderer o = new Orderer(LOG, eh, "cartoon character");
@@ -155,7 +156,7 @@
assertListsEqual(new Object[] { "FRED", "WILMA", "BARNEY", "BETTY"
}, l);
- c.verify();
+ verifyControls();
}
private static class ExceptionAwareArgumentsMatcher extends
AbstractMatcher
@@ -172,7 +173,7 @@
public void testCyclePre() throws Exception
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
+ MockControl c = newControl(ErrorHandler.class);
ErrorHandler eh = (ErrorHandler) c.getMock();
eh.error(
@@ -184,7 +185,7 @@
c.setMatcher(new ExceptionAwareArgumentsMatcher());
- c.replay();
+ replayControls();
Orderer o = new Orderer(LOG, eh, "cartoon character");
@@ -197,12 +198,12 @@
assertListsEqual(new Object[] { "WILMA", "FRED", "BETTY", "BARNEY"
}, l);
- c.verify();
+ verifyControls();
}
public void testCyclePost() throws Exception
{
- MockControl c = MockControl.createStrictControl(ErrorHandler.class);
+ MockControl c = newControl(ErrorHandler.class);
ErrorHandler eh = (ErrorHandler) c.getMock();
eh.error(
@@ -213,7 +214,7 @@
c.setMatcher(new ExceptionAwareArgumentsMatcher());
- c.replay();
+ replayControls();
Orderer o = new Orderer(LOG, eh, "cartoon character");
@@ -225,7 +226,7 @@
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "FRED", "BARNEY", "WILMA", "BETTY"
}, l);
- c.verify();
+ verifyControls();
}
public void testDupe() throws Exception
@@ -239,7 +240,7 @@
o.add("WILMA", "flintstone", null, null);
- assertLoggedMessage("Cartoon character 'flintstone' (at unknown
location) duplicates previous value (at unknown location) and is being
ignored.");
+ assertLoggedMessage("Cartoon character 'flintstone' duplicates
previous value (at unknown location) and is being ignored.");
List l = o.getOrderedObjects();
@@ -255,11 +256,13 @@
o.add("WILMA", "wilma", "betty", null);
o.add("BETTY", "betty", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "BETTY", "BARNEY", "WILMA", "FRED"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPreStartDupe() throws Exception
@@ -278,7 +281,7 @@
assertListsEqual(new Object[] { "BARNEY", "BETTY", "WILMA", "FRED"
}, l);
assertLoggedMessage(
- "Cartoon character 'barney' (at unknown location) has been
ordered "
+ "Cartoon character 'barney' has been ordered "
+ "last, conflicting with 'fred' (at unknown location).");
}
@@ -291,11 +294,13 @@
o.add("WILMA", "wilma", null, "betty");
o.add("BETTY", "betty", null, null);
+ replayControls();
+
List l = o.getOrderedObjects();
assertListsEqual(new Object[] { "BARNEY", "FRED", "WILMA", "BETTY"
}, l);
- _errorHandlerControl.verify();
+ verifyControls();
}
public void testPostStarDupe() throws Exception
@@ -314,7 +319,7 @@
assertListsEqual(new Object[] { "BARNEY", "FRED", "WILMA", "BETTY"
}, l);
assertLoggedMessage(
- "Cartoon character 'wilma' (at unknown location) has been
ordered "
+ "Cartoon character 'wilma' has been ordered "
+ "first, conflicting with 'barney' (at unknown location).");
}
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]