Mule - Which code snippet would you recommend for FunctionalTestCase, and what are their differences? -


i come across 2 seemingly similar yet different variations of codes functional testing. recommended 1 , differences?

=== snippet 1 ===

@override     protected string getconfigresources() {         return "src\\main\\app\\simplejunittest.xml";     }      @test     public void testhelloworldflow2returns2() throws exception     {         runflowwithpayloadandexpect("simplejunittestflow1", "sometextxxxx", "pass");     }       ///////////////////////////// helpers ////////////////////////////////////////     /**     * run flow specified name using specified payload , assert     * equality on expected output     *     * @param flowname name of flow run     * @param expect expected output     * @param payload payload of input event     */     protected <u, t> void runflowwithpayloadandexpect(string flowname, u payload, t expect) throws exception     {         flow flow = lookupflowconstruct(flowname);         muleevent event = functionaltestcase.gettestevent(payload);         muleevent responseevent = flow.process(event);          assertequals(expect, responseevent.getmessage().getpayload());     }      /**      * retrieve flow name registry      *      * @param name name of flow retrieve      */     protected flow lookupflowconstruct(string name)     {         return (flow) functionaltestcase.mulecontext.getregistry().lookupflowconstruct(name);     } 

=== snippet 2 ===

@override protected string getconfigresources() {     return "./src/main/app/simplejunittest.xml"; }  @test public void testclient2personmigration() throws exception {     muleclient client = mulecontext.getclient();     string payload = "sometextxxxx";     map<string, object> messageproperties = null;     mulemessage result = client.send("http://localhost:8081/", payload, messageproperties); //url, payload, messageproperties      assertnotnull(result);     assertnull(result.getexceptionpayload());     assertfalse(result.getpayload() instanceof nullpayload);     assertequals("pass", result.getpayloadasstring()); //if comment works } 

=== configuration xml of snippet 1 & 2 ===

<flow name="simplejunittestflow1" doc:name="simplejunittestflow1">     <http:inbound-endpoint exchange-pattern="request-response" host="localhost" port="8081" doc:name="http"/>     <set-payload value="#['fail']" doc:name="set payload"/>     <flow-ref name="simplejunittestflow2" doc:name="flow reference"/> </flow> <sub-flow name="simplejunittestflow2" doc:name="simplejunittestflow2">     <set-payload value="#['pass']" doc:name="set payload"/> </sub-flow> 

question: there recommended 1 between snippet 1 , 2?

the big difference in snippet 1 send message not represent actual message hit service, what's done in snippet 2. indeed, you're missing inbound message properties set http transport. use string payload instead of inputstream one, http transport does.

therefore, suggest using snippet 2 have realistic test conditions. btw in snippet 2, you'd rather use generic http client ensure service working fine non-mule clients well. should use dynamic port feature instead of hard-coding 8081 avoid collisions when running tests.

i reserve snippet 1 private flows or flows inbound endpoint type doesn't have natural inbound properties, vm.


Comments

Popular posts from this blog

Android layout hidden on keyboard show -

google app engine - 403 Forbidden POST - Flask WTForms -

c - Why would PK11_GenerateRandom() return an error -8023? -