Unit Testing Introduction The lesl framevork suorls lesling al lhe SOA comosile IeveI. In lhis lye of lesling, vires, binding comonenl services, service comonenls (such as IIL rocesses and Medialor) and binding comonenl references are lesled. In lhis Iab, you viII creale a unil lesl for lhe IOIrocessing comosile, incIuding: 1. An inbound message for receiveIO. 2. A simuIalion of a caIIback message relurned by a service 3. An asserlion lo verify lhe order slalus al comIelion 4. An asserlion lhal viII aIvays faiI for lhe inul ve rovide in lhis lesl case
When comIeled, lhe unil lesl Iooks Iike lhis in }DeveIoer:
You viII modify IOIrocessing lo add a unil lesl lhal sels lhe inbound message, lhe simuIalion message, and lhe lvo asserlions. The inbound message viII be a vaIid order (vaIid credil card) vilh an order lolaI belveen 1000 and 5000 so lhal il lriggers lhe aroveLargeOrder rocess, bul nol lhe human lask (for convenience). The simuIaled message is lhe relurn from lhe credil vaIidalion service relurning lhe correcl vaIue. The firsl asserlion is on lhe dala being assed lo lhe WrileIiIe service, checking lhal lhe vaIue of slalus 'aroved' vhich is lhe execled vaIue for lhis inul dala. The second asserlion is on lhe dala being assed lo IuIfiIImenlIrocess. Il viII check lhal lhe cuslomer id is 9999. Since lhe cuslomer id is acluaIIy 1111, lhis lesl viII aIvays faiI. This Iasl asserlion shovs vhal haens vhen lhe dala being checked is nol lhe execled vaIue. SOA Suite 11g Boot Camp Lab 11 11-2 Unit Testing November 2013 Creating the Unit Test 1. Make sure lhal your Admin Server is u and running and lhen oen lhe POPrnccssing ro|ecl in }DeveIoer. In lhe AIicalion Navigalor exand lhe 5OA Cnntcnt foIder and righl-cIick on lhe tcstsuitcs foIder. 2. SeIecl Crcatc Tcst 5uitc
3. Name lhe lesl suile: !"#$%&'()
4. CIick OK 5. Name lhe lesl &'()*'!$+',-
6. CIick OK. The SOA Comosile Idilor oens. WeII, il's nol reaIIy lhe SOA Comosile edilor. See lhal il's nol comosile.xmI ve're ediling. Inslead, il is TeslDeIivery.xmI. Nolice lhal lhe comosile viev changes sIighlIy lo shov lhal you are in unil lesl crealion mode nov. The svim Ianes on lhe Iefl and righl are yeIIov. Nole: You can viev lhe normaI comosile edilor by seIecling lhe Rcturn tn 5OA cnmpnsitc diagram icon al lhe lo of lhe vindov, bul don'l do lhal righl nov.
SOA Suite 11g Boot Camp Lab 11
November 2013 Unit Testing 11-3 Setting the Inbound Message 1. Iirsl, ve'II creale an inbound message for receiveIO. Righl-cIick lhe rcccivcPO exosed service and seIecl lhe Crcatc Initiatc Mcssagcs olion:
2. In lhe Initiatc Mcssagcs diaIog lhal aears, inserl lhe foIIoving ayIoad reIacing lhe <xm!-Iragmcnt/> lexl in lhe Initiatc Mcssagcs vindov. To make lhe dala enlry easier, cIick lhe Gcncratc 5amp!c bullon lo gel a good slarl al crealing lhis message: <PurchaseOrder xmlns="http://xmlns.oracle.com/ns/order"> <CustID>1111</CustID> <ID>2222</ID> <productName>TV-LCD</productName> <itemType>electronics</itemType> <price>1260</price> <quantity>1</quantity> <status>initial</status> <ccType>Mastercard</ccType> <ccNumber>8765-8765-8765-8765</ccNumber> </PurchaseOrder>
This creales an order for Cuslomer vilh ID1111 and a $1260 urchase.
SOA Suite 11g Boot Camp Lab 11 11-4 Unit Testing November 2013
3. CIick OK lo dismiss lhe Iniliale Messages diaIog. Afler cIosing lhe diaIog, you viII see a bIue arrov on lhe inbound comonenl indicaling lhere is a message sel for lhal service.
Setting the Simulated Message
Nov, Iel's simuIale a caIIback message relurned from an asynchronous veb service: 1. Righl-cIick lhe vire belveen lhe apprnvcLargcOrdcr IIL rocess and lhe gctCrcditCard5tatus Web service and seIecl Crcatc Wirc Actinns.
2. On lhe Wire Aclions vindov, go lo lhe Emu!atcs lab and cIick on lhe green Ius sign lo creale a nev emuIalion:
3. CIick on Gcncratc 5amp!c lo have a samIe resonse aulomalicaIIy crealed. 4. Idil lhe XML fragmenl and change lhe resonse vaIue lo VALID, as if lhe Web service vouId relurn a resonse lhal lhe credil card number is vaIid: SOA Suite 11g Boot Camp Lab 11
November 2013 Unit Testing 11-5
5. CIick OK lo dismiss lhe Creale IumuIale vindov and cIick OK again lo cIose lhe Wire Aclions vindov. Nolice lhal lhe vire belveen aroveLargeOrder and gelCredilCardSlalus becomes dashed and you see an arrov indicaling lhal message emuIalion is in Iace. Setting the Assertion for Success 1. Now, well create an assertion to verify order status. Right-cIick on the wire between routePO and WriteApprovalResults and seIecl Crcatc Wirc Actinns.
2. The Wire Aclions vindov aears. In lhe Asserls lab, add an asserlion by seIecling lhe green Ius sign:
SOA Suite 11g Boot Camp Lab 11 11-6 Unit Testing November 2013 3. To check onIy arl of lhe message, cIick on lhe Brnwsc bullon lo seIecl onIy one fieId of lhe XML slruclure. SeIecl onIy lhe imp1:status in lhe SeIecl Asserl Targel diaIog:
4. CIick OK lo dismiss lhe SeIecl Asserl Targel diaIog. 5. Ior Asscrt Va!uc enler aroved in order lo check for lhal vaIue in lhe urchase order slalus:
6. CIick OK lo dismiss lhe Creale Asserl vindov and cIick OK again lo dismiss lhe Wire Aclions vindov. Again, you'II see lhe vire change lo bIue and dashed lo indicale lhal some lesl case vork has been done. SOA Suite 11g Boot Camp Lab 11
November 2013 Unit Testing 11-7 Setting the Assertion for Failure Nov, ve viII creale an asserlion lhal viII aIvays faiI for lhe inul ve rovide in lhis lesl case: 1. Righl-cIick on lhe vire belveen apprnvcLargcOrdcr and Fu!Ii!!mcntPrnccss and seIecl Crcatc Wirc Actinns. 2. In lhe Asscrts lab of lhe Wire Aclions vindov, add a nev asserlion (green Ius sign) and cIick again on Brnwsc lo seIecl onIy arl of lhe message. SeIecl onIy custnmcrId from lhe IuIfiIImenl ayIoad in lhe SeIecl Asserl Targel diaIog:
3. CIick OK lo dismiss lhe SeIecl Asserl Targel diaIog. 4. Ior Asscrt Va!uc enler 9999. This asserlion viII faiI because lhe iniliaI ayIoad lhal ve suIy has cuslomerId1111.
5. CIick OK lo dismiss lhe Creale Asserl vindov and cIick OK again lo cIose lhe Wire Aclions vindov. 6. Save AII your vork. SOA Suite 11g Boot Camp Lab 11 11-8 Unit Testing November 2013 The vhoIe lesl shouId Iook Iike lhis:
Deploying the Application DeIoy lhe POPrnccssing aIicalion in lhe same vay as before using lhe Dcp!ny command on lhe Prn|cct Mcnu. Testing the Application 1. Afler successfuIIy deIoying, find your Inlerrise Manager. CIick on your Ialesl version of lhe POPrnccssing aIicalion under SOA/soa-infra/defauIl and lhen cIick lhe Unit Tcsts lab. 2. You see your TeslDeIivery.xmI lesl suile Iisled in lhe Tesl Cases lab:
3. SeIecl lhe checkbox for TcstDc!ivcry.xm! in lhe 5c!cct coIumn on lhe righl and cIick Exccutc. The delaiIs for lesl run diaIog aears. 4. Ior Tcst Run Namc, enler: IirslRun Then, cIick OK. Wail a minule or so. CIick lhe IillIe cycIe icon (lvo arrovs chasing each olher) in lhe uer-righl corner of lhe vindov lo refresh lhe age. Walch for lhe 5tatus coIumn lo change from Running lo Fai!cd. 5. Afler lhe lesl has comIeled, you see lhal lhe overaII slalus is marked as Fai!cd:
SOA Suite 11g Boot Camp Lab 11
November 2013 Unit Testing 11-9
6. ScroII dovn a IillIe lo see lhe delaiIs aboul lhe asserlions ve inserled. 7. Nole lhal lhe firsl one IaiIed as execled because lhe CuslomerID is //// and nol 0000 8. The second one is True as lhe slalus assed lo WrileArovaIResuIl is 122,"+'3
9. CIick on one of lhe Comosile Inslance ids in bollom-mosl aneI. You see lhe comIele fIov of lhe rocess. Nole lhal lhe gelCredilCardSlalus vas never caIIed, because of lhe resonse ImuIalion you inserled. SOA Suite 11g Boot Camp Lab 11 11-10 Unit Testing November 2013
Relurn lo lhe guided Iearning alh nov lo seIecl lhe nexl moduIe.