Frage

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?

War es hilfreich?

Lösung

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();

Andere Tipps

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

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top