문제

I am trying to set a session property on a DefaultMuleMessage from within a FunctionalTestCase method as follows:

    @Test
public void ProcessActivityTest() throws Exception{

    MuleClient client = new MuleClient(muleContext);

    Activity activity = new Activity(EdusTestService.buildActivity().toString());

    DefaultMuleMessage message = new DefaultMuleMessage(activity, muleContext);
    message.setSessionProperty("edusKey", "1234567890");

    MuleMessage result = client.send("vm://processActivity?connector=inMemoryVMQueue",  message);

    System.out.println(result.getPayload().getClass().toString());
    System.out.println(result.getPayloadAsString());
    System.out.println(result.getExceptionPayload().getException().getMessage());

    assertEquals("{\"activity\":{}}", result.getPayloadAsString());

}

However, I keep getting the following IllegalStateException:

java.lang.IllegalStateException: Detected an attempt to set a invocation 
or session property, but a MuleEvent hasn't been created using this message 
yet. Key/value: edusKey=1234567890

How can I set a Session property to be used in this FunctionalTestCase method?

도움이 되었습니까?

해결책

You can use use a test event and process that with your flow:

DefaultMuleMessage message = new DefaultMuleMessage(activity, muleContext);
MuleEvent event = getTestEvent(message);
event.setSessionVariable("edusKey", "1234567890");
Flow flow = (Flow) getFlowConstruct("my-flow");
MuleEvent responseEvent = flow.process(event);
responseEvent.getMessageAsString();

다른 팁

SESSION scoped properties are intended for use between Mule flows internally rather than externally such as through clients. By setting the property scope to OUTBOUND, Mule will copy the property to the INBOUND properties of the message once it has been received.

HTH

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top