我是初次使用弹簧webflow并开始为webflow编写单元测试用例并收到以下错误。我正在努力编写测试用例,因为它与决策状态,操作状态视图状态和子流程混合我没有找到到目前为止任何合适的参考。我已经尝试了很多可能的方法,并努力获得这个概念,请你帮我理解我在做什么错误
错误
org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@1d8e2eea targetAction = [SetAction@240139e1 name = sourceSiteId, value = flowScope.regform.sid], attributes = map[[empty]]] in state 'ssoerrorredirect' of flow 'regEnroll-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:154)
at org.springframework.webflow.engine.State.enter(State.java:193)
at org.springframework.webflow.engine.Transition.execute(Transition.java:228)
at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:51)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Transition.execute(Transition.java:228)
at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:51)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Flow.start(Flow.java:527)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:368)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:223)
at org.springframework.webflow.test.execution.AbstractFlowExecutionTests.startFlow(AbstractFlowExecutionTests.java:121)
at com.shc.ecom.test.usr.TestRegEnroll.testStartFlow(TestRegEnroll.java:84)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
Caused by: org.springframework.binding.expression.EvaluationException: An ELException occurred getting the value for expression 'flowScope.regform.sid' on context [class org.springframework.webflow.engine.impl.RequestControlContextImpl]
at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:92)
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)
... 31 more
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1007E:(pos 0): Property or field 'sid' cannot be found on null
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:220)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.access$000(PropertyOrFieldReference.java:46)
at org.springframework.expression.spel.ast.PropertyOrFieldReference$AccessorLValue.getValue(PropertyOrFieldReference.java:374)
at org.springframework.expression.spel.ast.CompoundExpression.getValueInternal(CompoundExpression.java:88)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299)
at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84)
... 35 more
webflow xml>
<?xml version="1.0" encoding="UTF-8"?>
<flow xmlns="http://www.springframework.org/schema/webflow"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="
http://www.springframework.org/schema/webflow
http://www.springframework.org/schema/webflow/spring-webflow-2.4.xsd"
start-state="confirmsuccess">
<var name="regform" class="com.test.ecoms.user.form.Regform" />
<!-- <input-mapper> <input-attribute name="service" /> <input-attribute
name="regform" /> <input-attribute name="success" /> </input-mapper> <start-state
idref="confirmsuccess" /> -->
<input name="service" />
<input name="regform" />
<input name="success" />
<decision-state id="confirmsuccess">
<if test="flowScope.success!=null" then="serviceticketvalidation"
else="saveQueryParamInSession" />
</decision-state>
<decision-state id="serviceticketvalidation">
<if test="flowScope.success=='yes'" then="sywNumAction" else="ssoerrorredirect" />
</decision-state>
<!-- <action-state id="enterCustInfo"> <action bean="regEnrollFormAction"
method="setupForm" > </action> <transition on="success" to="renderform"/>
</action-state> -->
<!-- save query parameter in session -->
<action-state id="saveQueryParamInSession">
<evaluate expression="saveQueryParamInSession" />
<transition on="success" to="renderform" />
</action-state>
......
</flow>
测试用例
public class TestRegEnroll extends AbstractXmlFlowExecutionTests {
private SavingQueryParamInSessionAction savingQueryParamInSession;
private Event event;
RequestContext contextRequest;
protected void setUp() {
savingQueryParamInSession = EasyMock.createMock("savingQueryParamInSession",
SavingQueryParamInSessionAction.class);
event = EasyMock.createMock("event",Event.class);
contextRequest = EasyMock.createMock("request",RequestContext.class);
}
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("src/main/webapp/WEB-INF/usr/flows/regEnroll-flow.xml");
}
@Override
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
builderContext.registerBean("savingQueryParamInSession", savingQueryParamInSession);
}
public void testStartFlow() throws Exception {
MockExternalContext externalContext = new MockExternalContext();
MockRequestContext context=new MockRequestContext();
MutableAttributeMap input = new LocalAttributeMap();
input.put("success", "renderform");
input.put("flowScope.regform.sid", 3);
input.put("clienthost", "qa.ecom.sears.com:4380");
EasyMock.expect(savingQueryParamInSession.doExecute(contextRequest)).andReturn(event );
EasyMock.replay(savingQueryParamInSession);
startFlow(input, externalContext);
assertCurrentStateEquals("renderform");
}
public void testStartRenderFormFlow() throws Exception {
}
private Regform createRegistrationForm() {
Regform regform = new Regform();
regform.setEmail("20130410111@gmail.com");
regform.setLname("mike");
regform.setFname("sun");
regform.setPassword("test11");
regform.setSid("3");
regform.setZip("60179");
return regform;
}
}
ModifyTestCase
public class TestRegEnrollFlow extends AbstractXmlFlowExecutionTests {
SavingQueryParamInSessionAction savingQueryParamInSessionAction = new SavingQueryParamInSessionAction();
@Override
protected FlowDefinitionResource getResource(FlowDefinitionResourceFactory resourceFactory) {
return resourceFactory.createFileResource("src/main/webapp/WEB-INF/usr/flows/regEnroll-flow.xml");
}
@Override
protected void configureFlowBuilderContext(MockFlowBuilderContext builderContext) {
//I Have tried even mocking using Easy Mock
/*savingQueryParamInSession = EasyMock.createMock("savingQueryParamInSession",
SavingQueryParamInSessionAction.class);
event = EasyMock.createMock("event",Event.class);
contextRequest = EasyMock.createMock("request",RequestContext.class);*/
builderContext.registerBean("savingQueryParamInSession", savingQueryParamInSessionAction);
builderContext.registerBean("sywNumSetupAction", new SywNumSetupAction());
builderContext.registerBean("ssoGatewayService", new SSOGatewayServiceImpl());
builderContext.registerBean("regEnrollFormAction", new RegEnrollFormAction());
}
public void testAction() {
MockExternalContext ctx = new MockExternalContext();
MutableAttributeMap input = new LocalAttributeMap();
input.put("service", "");
input.put("regForm", createRegistrationForm());
//this is the line where we are changing the state flow
input.put("success", "success");
startFlow(input, ctx);
assertFlowExecutionActive();
assertCurrentStateEquals("renderform");
Object regForm = getFlowAttribute("regForm");
assertTrue(regForm instanceof Regform);
assertTrue(((Regform) regForm).getLname().equals("mike"));
}
private Regform createRegistrationForm() {
Regform regform = new Regform();
regform.setEmail("20130410111@gmail.com");
regform.setLname("mike");
regform.setFname("sun");
regform.setPassword("test11");
regform.setSid("3");
regform.setZip("60179");
return regform;
}
}
错误
org.springframework.webflow.execution.ActionExecutionException: Exception thrown executing [AnnotatedAction@376a0d86 targetAction = [EvaluateAction@62656be4 expression = saveQueryParamInSession, resultExpression = [null]], attributes = map[[empty]]] in state 'saveQueryParamInSession' of flow 'regEnroll-flow' -- action execution attributes were 'map[[empty]]'
at org.springframework.webflow.execution.ActionExecutor.execute(ActionExecutor.java:60)
at org.springframework.webflow.engine.ActionState.doEnter(ActionState.java:101)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Transition.execute(Transition.java:228)
at org.springframework.webflow.engine.DecisionState.doEnter(DecisionState.java:51)
at org.springframework.webflow.engine.State.enter(State.java:194)
at org.springframework.webflow.engine.Flow.start(Flow.java:527)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:368)
at org.springframework.webflow.engine.impl.FlowExecutionImpl.start(FlowExecutionImpl.java:223)
at org.springframework.webflow.test.execution.AbstractFlowExecutionTests.startFlow(AbstractFlowExecutionTests.java:121)
at com.shc.ecom.test.usr.TestRegEnrollFlow.testAction(TestRegEnrollFlow.java:52)
at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
at java.lang.reflect.Method.invoke(Method.java:483)
at junit.framework.TestCase.runTest(TestCase.java:154)
at junit.framework.TestCase.runBare(TestCase.java:127)
at junit.framework.TestResult$1.protect(TestResult.java:106)
at junit.framework.TestResult.runProtected(TestResult.java:124)
at junit.framework.TestResult.run(TestResult.java:109)
at junit.framework.TestCase.run(TestCase.java:118)
at junit.framework.TestSuite.runTest(TestSuite.java:208)
at junit.framework.TestSuite.run(TestSuite.java:203)
at org.eclipse.jdt.internal.junit.runner.junit3.JUnit3TestReference.run(JUnit3TestReference.java:131)
at org.eclipse.jdt.internal.junit.runner.TestExecution.run(TestExecution.java:38)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:459)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.runTests(RemoteTestRunner.java:675)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.run(RemoteTestRunner.java:382)
at org.eclipse.jdt.internal.junit.runner.RemoteTestRunner.main(RemoteTestRunner.java:192)
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.EvaluateAction.doExecute(EvaluateAction.java:75)
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)
... 28 more
Caused by: org.springframework.expression.spel.SpelEvaluationException: EL1008E:(pos 0): Property or field 'saveQueryParamInSession' cannot be found on object of type 'org.springframework.webflow.engine.impl.RequestControlContextImpl' - maybe not public?
at org.springframework.expression.spel.ast.PropertyOrFieldReference.readProperty(PropertyOrFieldReference.java:224)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:94)
at org.springframework.expression.spel.ast.PropertyOrFieldReference.getValueInternal(PropertyOrFieldReference.java:81)
at org.springframework.expression.spel.ast.SpelNodeImpl.getTypedValue(SpelNodeImpl.java:131)
at org.springframework.expression.spel.standard.SpelExpression.getValue(SpelExpression.java:299)
at org.springframework.binding.expression.spel.SpringELExpression.getValue(SpringELExpression.java:84)
... 32 more
答案 0 :(得分:0)
替换
input.put("flowScope.regform.sid", 3);
通过
input.put("regform", createRegistrationForm());