Produced by Araxis Merge on 4/18/2019 5:56:03 PM Eastern Daylight Time. See www.araxis.com for information about Merge. This report uses XHTML and CSS2, and is best viewed with a modern standards-compliant browser. For optimum results when printing this report, use landscape orientation and enable printing of background images and colours in your browser.
# | Location | File | Last Modified |
---|---|---|---|
1 | MCCF_EDI_TAS_TASCore v2.0_Build_10.zip\MCCF_EDI_TAS_Vistalink\VAVistaLinkServer\src\test\java\gov\va\tas\resource | MockExecute.java | Wed Apr 3 02:27:48 2019 UTC |
2 | MCCF_EDI_TAS_TASCore v2.0_Build_10.zip\MCCF_EDI_TAS_Vistalink\VAVistaLinkServer\src\test\java\gov\va\tas\resource | MockExecute.java | Wed Apr 17 16:37:25 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 240 |
Changed | 1 | 4 |
Inserted | 0 | 0 |
Removed | 0 | 0 |
Whitespace | |
---|---|
Character case | Differences in character case are significant |
Line endings | Differences in line endings (CR and LF characters) are ignored |
CR/LF characters | Not shown in the comparison detail |
No regular expressions were active.
1 | package go v.va.tas.r esource; | |
2 | ||
3 | import sta tic org.mo ckito.Argu mentMatche rs.any; | |
4 | ||
5 | import jav a.net.Inet Address; | |
6 | import jav a.util.Tre eMap; | |
7 | ||
8 | import gov .va.med.vi stalink.ad apter.cci. VistaLinkA ppProxyCon nectionSpe c; | |
9 | import org .junit.jup iter.api.B eforeAll; | |
10 | import org .mockito.M ockito; | |
11 | import org .w3c.dom.D ocument; | |
12 | ||
13 | import gov .va.med.vi stalink.ad apter.cci. VistaLinkC onnection; | |
14 | import gov .va.med.vi stalink.ad apter.cci. VistaLinkD uzConnecti onSpec; | |
15 | import gov .va.med.vi stalink.ad apter.spi. VistaLinkM anagedConn ectionFact ory; | |
16 | import gov .va.med.vi stalink.ad apter.spi. VistaLinkS erverInfo; | |
17 | import gov .va.med.vi stalink.rp c.RpcRespo nse; | |
18 | import gov .va.tas.ne ttyrest.Ro ute; | |
19 | import gov .va.tas.vi stalink.Vi staLinkPoo lableObjec tFactory; | |
20 | import gov .va.tas.vi stalink.Vi staLinkRpc Connection ; | |
21 | ||
22 | public cla ss MockExe cute exten ds Execute { | |
23 | ||
24 | pu blic stati c VistaLin kRpcConnec tion vlrc; | |
25 | pu blic stati c VistaLin kManagedCo nnectionFa ctory vlmc f; | |
26 | pu blic stati c VistaLin kDuzConnec tionSpec v ldcs; | |
27 | pu blic stati c VistaLin kAppProxyC onnectionS pec vlapcs ; | |
28 | pu blic stati c VistaLin kConnectio n vlc; | |
29 | pu blic stati c VistaLin kConnectio n vlac; | |
30 | pu blic stati c VistaLin kServerInf o vlsi; | |
31 | pu blic stati c RpcRespo nse respon se; | |
32 | pu blic stati c Route ro ute = new Route(); | |
33 | ||
34 | /* * | |
35 | * Sets up a ll the moc ks and stu b objects used in mo cked versi ons of the test. | |
36 | * As much a s possible , I'm tryi ng to mock any objec t that nor mally come s from Vis taLink. | |
37 | * @throws E xception | |
38 | * / | |
39 | @B eforeAll | |
40 | pu blic stati c void set UpMocks() throws Exc eption { | |
41 | // Mock Pool able Objec t Factory | |
42 | vlpo f = Mockit o.mock(Vis taLinkPool ableObject Factory.cl ass); | |
43 | vl rc = new V istaLinkRp cConnectio n(); // Ac tual conne ction, but will be s tocked wit h mocks. | |
44 | Mo ckito.when (vlpof.mak eObject(St ring.value Of(portNum ber))).the nReturn(vl rc); | |
45 | ||
46 | // Replace t he oPool's actual co nnection f actory wit h a mock. | |
47 | st ockOPool(v lpof); | |
48 | ||
49 | // Mock mana ged connec tion facto ry. | |
50 | vl mcf = Mock ito.mock(V istaLinkMa nagedConne ctionFacto ry.class); | |
51 | Mo ckito.when (vlmcf.get PrimarySta tion()).th enReturn(" 652"); | |
52 | vl rc.setVlmc f(vlmcf); // Since w e always u se the sam e VLRpcCon nection, t hey all us e the mock | |
53 | vl dcs = Mock ito.mock(V istaLinkDu zConnectio nSpec.clas s); | |
54 | vl rc.setConn Spec(vldcs ); | |
55 | vl rc.setDuzS pec(vldcs) ; | |
56 | vl apcs = Moc kito.mock( VistaLinkA ppProxyCon nectionSpe c.class); | |
57 | vl rc.setAppS pec(vlapcs ); | |
58 | vl c = Mockit o.mock(Vis taLinkConn ection.cla ss); | |
59 | vl rc.setMyCo nnection(v lc); | |
60 | vl rc.setDuzC on(vlc); | |
61 | vl ac = Mocki to.mock(Vi staLinkCon nection.cl ass); | |
62 | vl rc.setAppP roxyCon(vl ac); | |
63 | vl si = Mocki to.mock(Vi staLinkSer verInfo.cl ass); | |
64 | Mo ckito.when (vlc.getCo nnectionIn fo()).then Return(vls i); | |
65 | Mo ckito.when (vlsi.getA ddress()). thenReturn (InetAddre ss.getLoca lHost()); | |
66 | Mo ckito.when (vlsi.getP ort()).the nReturn(po rtNumber); | |
67 | vl rc.setCfgN ame("loc_0 001"); | |
68 | ||
69 | // Set up th e Sample r oute. | |
70 | // Note: Thi s never ge ts used fo r anything functiona l | |
71 | // It's just to preven t a null p ointer exc eption dur ing mockin g when Tra ce logging is on. | |
72 | ro ute.setCon fig("loc_0 001"); | |
73 | ro ute.setPor t(String.v alueOf(por tNumber)); | |
74 | route.setH ost(" DNS . URL "); | |
75 | route.setR emotePort( " PORT "); | |
76 | ro ute.setAcc ess("fVbQ4 JDHfes="); | |
77 | ro ute.setVer ify("fxZDd tv2COe0VBp LI0cZjA==" ); | |
78 | ro ute.setJnd iname("vis tasources/ loc_0001") ; | |
79 | vl rc.setRm(n ew TreeMap <>()); | |
80 | vl rc.getRm() .put(Strin g.valueOf( portNumber ), route); | |
81 | ||
82 | // Mocked RP CResult ob ject. Miss ing the ra w results, which var y by test. | |
83 | re sponse = M ockito.moc k(RpcRespo nse.class) ; | |
84 | // D ocument on ly used by the logge r. | |
85 | Mock ito.when(r esponse.ge tDocument( )).thenRet urn(Mockit o.mock(Doc ument.clas s)); | |
86 | Mock ito.when(v lc.execute RPC(any()) ).thenRetu rn(respons e); | |
87 | // T his set up is for "s tandard" c ommunicati ons. If yo u want to test the e xception | |
88 | // h andling, y ou would r eset the v lc and re- returen vl si (avoids a null po inter), | |
89 | // t hen replac e .thenRet urn(respon se) with t henReturn. Example: | |
90 | // Mock.r eset(vlc); | |
91 | // Mockit o.when(vlc .getConnec tionInfo() ).thenRetu rn(vlsi); | |
92 | // Mockito.wh en(vlc.exe cuteRPC(an y())).then Throw(new SecurityEx ception("I 'm insecur e!")); | |
93 | } | |
94 | ||
95 | /** | |
96 | * Set s a new fa ctory for the oPool and adds f ive connec tions. Fac tory can b e an actua l | |
97 | * con nection fa ctory or a mock of o ne. Throws an except ion if the re are any connectio ns | |
98 | * sti ll borrowe d. | |
99 | * | |
100 | * @pa ram factor y | |
101 | * @th rows Excep tion | |
102 | */ | |
103 | pr ivate stat ic void st ockOPool(V istaLinkPo olableObje ctFactory factory) t hrows Exce ption { | |
104 | oPoo l.setFacto ry(factory ); | |
105 | for (int i = 1 ; i <= 5; i++) { | |
106 | LOGGER .debug(Str ing.format ("Creating connectio n object f or : %s", portNumber )); | |
107 | oPool. addObject( String.val ueOf(portN umber)); | |
108 | } | |
109 | } | |
110 | ||
111 | // Although the Docume nt is used briefly f or logging , the Resu lts string is the on ly thing | |
112 | // used in r ecreating the messag e. | |
113 | // Ways to m ock errors : Empty re sults stri ng; Result s starting with [}] | |
114 | // results that do n ot start w ith [ and end with ] ; results code that can't be p arsed as | |
115 | // a JSON object. | |
116 | public static vo id setRawR esults(Str ing rawRes ults) thro ws Excepti on { | |
117 | Mo ckito.rese t(response ); | |
118 | Mo ckito.when (response. getDocumen t()).thenR eturn(Mock ito.mock(D ocument.cl ass)); | |
119 | Mo ckito.when (response. getResults ()).thenRe turn(rawRe sults); | |
120 | } | |
121 | ||
122 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.