unit tests for registry destroy enhancement

This commit is contained in:
Keith Donald
2008-11-05 12:18:41 +00:00
parent d8af9185d4
commit 12efaf3499
4 changed files with 47 additions and 3 deletions

View File

@@ -15,6 +15,10 @@ public class FlowRegistryFactoryBeanTests extends TestCase {
factoryBean = new FlowRegistryFactoryBean();
}
public void tearDown() throws Exception {
factoryBean.destroy();
}
public void testGetFlowRegistry() throws Exception {
HashSet attributes = new HashSet();
attributes.add(new FlowElementAttribute("foo", "bar", null));

View File

@@ -29,9 +29,9 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
private FlowDefinitionRegistryImpl registry = new FlowDefinitionRegistryImpl();
private FlowDefinition fooFlow;
private FooFlow fooFlow;
private FlowDefinition barFlow;
private BarFlow barFlow;
protected void setUp() {
fooFlow = new FooFlow();
@@ -101,9 +101,23 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
assertEquals(barFlow, child.getFlowDefinition("bar"));
}
public void testDestroy() {
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(fooFlow));
registry.registerFlowDefinition(new StaticFlowDefinitionHolder(barFlow));
assertEquals(fooFlow, registry.getFlowDefinition("foo"));
assertEquals(barFlow, registry.getFlowDefinition("bar"));
assertFalse(fooFlow.destroyed);
assertFalse(barFlow.destroyed);
registry.destroy();
assertTrue(fooFlow.destroyed);
assertTrue(barFlow.destroyed);
}
private static class FooFlow implements FlowDefinition {
private String id = "foo";
private boolean destroyed;
public MutableAttributeMap getAttributes() {
return null;
}
@@ -145,6 +159,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
}
public void destroy() {
destroyed = true;
}
}
@@ -152,6 +167,8 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
private static class BarFlow implements FlowDefinition {
private String id = "bar";
private boolean destroyed;
public MutableAttributeMap getAttributes() {
return null;
}
@@ -193,6 +210,7 @@ public class FlowDefinitionRegistryImplTests extends TestCase {
}
public void destroy() {
destroyed = true;
}
}

View File

@@ -24,6 +24,7 @@ import org.springframework.binding.expression.ExpressionParser;
import org.springframework.binding.expression.support.FluentParserContext;
import org.springframework.binding.mapping.impl.DefaultMapper;
import org.springframework.binding.mapping.impl.DefaultMapping;
import org.springframework.context.support.GenericApplicationContext;
import org.springframework.webflow.TestException;
import org.springframework.webflow.action.TestMultiAction;
import org.springframework.webflow.core.collection.AttributeMap;
@@ -348,6 +349,15 @@ public class FlowTests extends TestCase {
}
}
public void testDestroy() {
GenericApplicationContext context = new GenericApplicationContext();
context.refresh();
flow.setApplicationContext(context);
assertTrue(context.isActive());
flow.destroy();
assertFalse(context.isActive());
}
public TransitionCriteria on(String eventId) {
return new MockTransitionCriteria(eventId);
}

View File

@@ -2,6 +2,7 @@ package org.springframework.webflow.engine.builder;
import junit.framework.TestCase;
import org.springframework.context.support.StaticApplicationContext;
import org.springframework.core.io.FileSystemResource;
import org.springframework.core.io.Resource;
import org.springframework.webflow.definition.FlowDefinition;
@@ -15,7 +16,9 @@ public class DefaultFlowHolderTests extends TestCase {
private FlowAssembler assembler;
protected void setUp() {
FlowAssembler assembler = new FlowAssembler(new SimpleFlowBuilder(), new MockFlowBuilderContext("flowId"));
MockFlowBuilderContext context = new MockFlowBuilderContext("flowId");
context.getFlowBuilderServices().setApplicationContext(new StaticApplicationContext());
FlowAssembler assembler = new FlowAssembler(new SimpleFlowBuilder(), context);
holder = new DefaultFlowHolder(assembler);
}
@@ -34,6 +37,15 @@ public class DefaultFlowHolderTests extends TestCase {
assertEquals("end", flow.getStartState().getId());
}
public void testDestroyNotInitialized() {
holder.destroy();
}
public void testDestroy() {
holder.getFlowDefinition();
holder.destroy();
}
public class SimpleFlowBuilder extends AbstractFlowBuilder implements FlowBuilder {
public void buildStates() throws FlowBuilderException {