如何测试Spring Webflow?

时间:2013-11-19 19:51:10

标签: spring spring-webflow

我正在尝试对spring webflow进行单元测试。

流程定义:

<view-state id="chooseCompany" view="convertWizard/chooseCompany">  
<on-entry>
    <set name="viewScope.companys" value="TrialCompanyWebFlowService.getTrialCompanys()" />
</on-entry> 
        <transition on="success" to="checkWipe">
            <set name="flowScope.company" value="TrialCompanyWebFlowService.getTrialCompany(requestParameters.companyId)" />
            <set name="flowScope.companyOldId" value="requestParameters.companyId" />
        </transition>
</view-state>

在流程中,我调用了方法getTrialCompanys()getTrialCompany(requestParameters.companyId)

    @Transactional
    @Service(value = "TrialCompanyWebFlowService")
    public class TrialCompanyWebFlowService {

        @Autowired
        CompanyService companyService;

    public List<Company> getTrialCompanys() {
        List<Company> companys = Company.findTrialCompanyEntries();
        return companys;
    }

    public Company getTrialCompany(Long companyId) {
        Company company = Company.findCompany(companyId);

        return company;
    }
}

我的测试代码是:

@Test
public void testFlowStarts() {      
    FlowExecution flowExecution = getFlowExecutionFactory().createFlowExecution(getFlowDefinition());
    Company company = Company.findCompany(1l);
    flowExecution.getConversationScope().put("company", company);

    MockExternalContext context = new MockExternalContext();

    flowExecution.start(null, context);
    assertCurrentStateEquals("checkWipe");
}

当我运行测试时,它给了我错误消息:

org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@279f2eb0 targetAction = [SetAction@43b23922 name = viewScope.companys, value = TrialCompanyWebFlowService.getTrialCompanys()], attributes = map[[empty]]] in state 'chooseCompany' of flow 'convert_flow' -- action execution attributes were 'map[[empty]]'
    at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:60)
    at org.springframework.webflow.engine.ActionList.execute(ActionList.java:155)
    at org.springframework.webflow.engine.State.enter(State.java:193)
    at org.springframework.webflow.engine.Flow.start(Flow.java:535)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:366)
    at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:222)
    at com.wombat.platform.admin.webflow.action.test.ConvertWizardActionTests.testFlowStarts(ConvertWizardActionTests.java:46)
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57)
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
    at java.lang.reflect.Method.invoke(Method.java:601)
    at org.junit.runners.model.FrameworkMethod$1.runReflectiveCall(FrameworkMethod.java:45)
    at org.junit.internal.runners.model.ReflectiveCallable.run(ReflectiveCallable.java:15)
    at org.junit.runners.model.FrameworkMethod.invokeExplosively(FrameworkMethod.java:42)
    at org.junit.internal.runners.statements.InvokeMethod.evaluate(InvokeMethod.java:20)
    at org.springframework.test.context.junit4.statements.RunBeforeTestMethodCallbacks.evaluate(RunBeforeTestMethodCallbacks.java:74)
    at org.springframework.test.context.junit4.statements.RunAfterTestMethodCallbacks.evaluate(RunAfterTestMethodCallbacks.java:83)
    at org.springframework.test.context.junit4.statements.SpringRepeat.evaluate(SpringRepeat.java:72)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:231)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.runChild(SpringJUnit4ClassRunner.java:88)
    at org.junit.runners.ParentRunner$3.run(ParentRunner.java:231)
    at org.junit.runners.ParentRunner$1.schedule(ParentRunner.java:60)
    at org.junit.runners.ParentRunner.runChildren(ParentRunner.java:229)
    at org.junit.runners.ParentRunner.access$000(ParentRunner.java:50)
    at org.junit.runners.ParentRunner$2.evaluate(ParentRunner.java:222)
    at org.springframework.test.context.junit4.statements.RunBeforeTestClassCallbacks.evaluate(RunBeforeTestClassCallbacks.java:61)
    at org.springframework.test.context.junit4.statements.RunAfterTestClassCallbacks.evaluate(RunAfterTestClassCallbacks.java:71)
    at org.junit.runners.ParentRunner.run(ParentRunner.java:300)
    at org.springframework.test.context.junit4.SpringJUnit4ClassRunner.run(SpringJUnit4ClassRunner.java:174)
    at org.eclipse.jdt.internal.junit4.runner.JUnit4TestReference.run(JUnit4TestReference.java:50)
    at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:467)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:683)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:390)
    at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:197)
Caused by: org.springframework.binding.expression.PropertyNotFoundException: Property not found
    at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:87)
    at org.springframework.webflow.action.SetAction.doExecute(SetAction.java:55)
    at org.springframework.webflow.action.AbstractAction.execute(AbstractAction.java:188)
    at org.springframework.webflow.execution.AnnotatedAction.execute(AnnotatedAction.java:145)
    at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:51)
    ... 34 more
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Field or property 'TrialCompanyWebFlowService' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestControlContextImpl'
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:246)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:112)
    at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:107)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueRef(CompoundExpression.java:49)
    at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:82)
    at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:102)
    at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:98)
    at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84)
    ... 38 more

任何人都可以帮我搞清楚吗?

0 个答案:

没有答案