Produced by Araxis Merge on 4/2/2019 1:06:56 PM Central 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 | C:\AraxisMergeCompare\Pri_un\ARS_Backend\ars_app\src\test\java\gov\va\med\ars\controller | FileOperationsControllerTest.java | Wed Mar 27 19:21:15 2019 UTC |
2 | C:\AraxisMergeCompare\Pri_re\ARS_Backend\ars_app\src\test\java\gov\va\med\ars\controller | FileOperationsControllerTest.java | Thu Mar 28 17:51:08 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 2 | 518 |
Changed | 1 | 2 |
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.med.a rs.control ler; | |
2 | ||
3 | import sta tic org.mo ckito.Mock ito.when; | |
4 | import sta tic org.sp ringframew ork.test.w eb.servlet .request.M ockMvcRequ estBuilder s.post; | |
5 | import sta tic org.sp ringframew ork.test.w eb.servlet .result.Mo ckMvcResul tHandlers. print; | |
6 | import sta tic org.sp ringframew ork.test.w eb.servlet .result.Mo ckMvcResul tMatchers. status; | |
7 | import sta tic org.sp ringframew ork.test.w eb.servlet .result.Mo ckMvcResul tMatchers. content; | |
8 | import sta tic org.mo ckito.Matc hers.*; // any, ve rify, cont ent, | |
9 | //import s tatic org. mockito.Ma tchers.any ; | |
10 | //import s tatic org. mockito.Mo ckito.veri fy; | |
11 | ||
12 | import jav a.util.Arr ays; | |
13 | import jav a.util.Lis t; | |
14 | import jav a.util.str eam.Stream ; | |
15 | ||
16 | import org .apache.ht tp.protoco l.HTTP; | |
17 | import org .junit.Bef ore; | |
18 | import org .junit.Tes t; | |
19 | import org .junit.run ner.RunWit h; | |
20 | import org .mockito.I njectMocks ; | |
21 | import org .mockito.M ock; | |
22 | import org .mockito.M ockitoAnno tations; | |
23 | import org .mockito.r unners.Moc kitoJUnitR unner; | |
24 | import org .springfra mework.htt p.MediaTyp e; | |
25 | import org .springfra mework.tes t.web.serv let.MockMv c; | |
26 | import org .springfra mework.tes t.web.serv let.MvcRes ult; | |
27 | import org .springfra mework.tes t.web.serv let.setup. MockMvcBui lders; | |
28 | ||
29 | import com .fasterxml .jackson.d atabind.Ob jectMapper ; | |
30 | import com .fasterxml .jackson.d atabind.Ob jectWriter ; | |
31 | import com .fasterxml .jackson.d atabind.Se rializatio nFeature; | |
32 | ||
33 | import gov .va.med.ar s.exceptio ns.Generic Exception; | |
34 | import gov .va.med.ar s.file.Fil eOperation s; | |
35 | import gov .va.med.ar s.filter.C ORSFilter; | |
36 | import gov .va.med.ar s.model.re quest.Audi tLogger; | |
37 | import gov .va.med.ar s.model.re quest.Expo rtAsPDF; | |
38 | import gov .va.med.ar s.service. IAuditLogg erService; | |
39 | ||
40 | @RunWith(M ockitoJUni tRunner.cl ass) | |
41 | public cla ss FileOpe rationsCon trollerTes t { | |
42 | pr ivate Stri ng thisSrc = "src/te st/java/go v/va/med/a rs/control ler/FileOp erationsCo ntrollerTe st.java"; // our own source sh ould exist ?? | |
43 | // Status ex pect <415> , HTTP Sta tus 415 - Unsupporte d Media Ty pe | |
44 | // | |
45 | pr ivate Stri ng[] testI mages = { | |
46 | "src/t est/resour ces/images /bmp-400x4 00.bmp", | |
47 | "src/t est/resour ces/images /bmp-1420x 1420.bmp", | |
48 | "src/t est/resour ces/images /gif-400x4 00.gif", | |
49 | "src/t est/resour ces/images /gif-1420x 1420.gif", | |
50 | "src/t est/resour ces/images /jpg-400x4 00.jpg", | |
51 | "src/t est/resour ces/images /jpg-1420x 1420.jpg", | |
52 | "src/t est/resour ces/images /png-400x4 00.png", | |
53 | "src/t est/resour ces/images /png-1420x 1420.png", | |
54 | "src/t est/resour ces/images /tif-400x4 00.tif", | |
55 | "src/t est/resour ces/images /tif-1420x 1420.tif", | |
56 | }; | |
57 | pr ivate Stri ng vhaName = "VHANAM E"; | |
58 | ||
59 | pr ivate Mock Mvc mockMv c; | |
60 | ||
61 | @M ock | |
62 | pr ivate IAud itLoggerSe rvice audi tLoggerSer vice; | |
63 | ||
64 | @I njectMocks | |
65 | pr ivate File Operations fileOpera tionsContr oller; | |
66 | ||
67 | @B efore | |
68 | pu blic void init() thr ows Except ion { | |
69 | Mock itoAnnotat ions.initM ocks(this) ; | |
70 | mock Mvc = Mock MvcBuilder s | |
71 | .standal oneSetup(f ileOperati onsControl ler) | |
72 | .addFilt ers(new CO RSFilter() ) | |
73 | .build() ; | |
74 | } | |
75 | ||
76 | // viewAttac hment | |
77 | // exportAtt achment | |
78 | // exportAsP DF | |
79 | ||
80 | @T est | |
81 | pu blic void testSucces sControlle r_file_vie w_images() throws Ex ception { | |
82 | // T he inaptly named Aud itLogger i s the requ est for an attachmen t. But it also conta ins identi fication f or auditin g | |
83 | // List <String> i mgList = A rrays.asLi st(images) ; | |
84 | // Stre am<String> imgStream = imgList .stream(); | |
85 | // imgS tream.forE ach( (img) -> { | |
86 | Syst em.out.pri ntln("File Operations Controller Test:testS uccessCont roller_fil e_view_ima ges"); | |
87 | ||
88 | for( String im g : testIm ages ) { | |
89 | AuditL ogger requ est = new AuditLogge r(vhaName, "86753303 .001", fal se); // d oesn't mat ter | |
90 | when(a uditLogger Service.ge tPathForTh eAttachmen t(any(Audi tLogger.cl ass))).the nReturn(im g); // always return our image nam e | |
91 | System .out.print ln("getPat hForTheAtt achment re turns " + img); | |
92 | ||
93 | Object Mapper map per = new ObjectMapp er(); | |
94 | mapper .configure (Serializa tionFeatur e.WRAP_ROO T_VALUE, f alse); | |
95 | Object Writer ow = mapper.w riter().wi thDefaultP rettyPrint er(); | |
96 | String jsonReque st = ow.wr iteValueAs String(req uest); | |
97 | ||
98 | System .out.print ln("jsonRe quest=" + jsonReques t); | |
99 | ||
100 | mockMv c.perform( | |
101 | post("/a pi/v1/file ").content Type(Media Type.APPLI CATION_JSO N).content (jsonReque st)) | |
102 | // .andDo(p rint()) | |
103 | .andExpe ct(status( ).isOk()) | |
104 | ; | |
105 | } | |
106 | } | |
107 | ||
108 | @T est | |
109 | pu blic void testSucces sControlle r_file_vie w() throws Exception { | |
110 | // T he inaptly named Aud itLogger i s the requ est for an attachmen t. But it also conta ins identi fication f or auditin g | |
111 | ||
112 | Audi tLogger re quest = ne w AuditLog ger(vhaNam e, "867533 03.001", f alse); | |
113 | when (auditLogg erService. getPathFor TheAttachm ent(any(Au ditLogger. class))).t henReturn( thisSrc); | |
114 | ||
115 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
116 | mapp er.configu re(Seriali zationFeat ure.WRAP_R OOT_VALUE, false); | |
117 | Obje ctWriter o w = mapper .writer(). withDefaul tPrettyPri nter(); | |
118 | Stri ng jsonReq uest = ow. writeValue AsString(r equest); | |
119 | ||
120 | mock Mvc.perfor m( | |
121 | post(" /api/v1/fi le").conte ntType(Med iaType.APP LICATION_J SON).conte nt(jsonReq uest)) | |
122 | // .andDo (print()) | |
123 | .andEx pect(statu s().isOk() ) | |
124 | ; | |
125 | } | |
126 | ||
127 | @T est | |
128 | pu blic void testSucces sControlle r_file_Dow nload() th rows Excep tion, Asse rtionError { | |
129 | Bool ean isDown load = tru e; | |
130 | Audi tLogger re quest = ne w AuditLog ger(vhaNam e, "867533 03.001", i sDownload) ; // autob oxing inse rts new Bo olean(true ) | |
131 | when (auditLogg erService. getPathFor TheAttachm ent(any(Au ditLogger. class))).t henReturn( thisSrc); | |
132 | ||
133 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
134 | mapp er.configu re(Seriali zationFeat ure.WRAP_R OOT_VALUE, false); | |
135 | Obje ctWriter o w = mapper .writer(). withDefaul tPrettyPri nter(); | |
136 | Stri ng jsonReq uest = ow. writeValue AsString(r equest); | |
137 | ||
138 | mock Mvc.perfor m( | |
139 | post(" /api/v1/fi le").conte ntType(Med iaType.APP LICATION_J SON).conte nt(jsonReq uest)) | |
140 | // .andDo (print()) | |
141 | .andEx pect(statu s().isOk() ) | |
142 | ; | |
143 | } | |
144 | ||
145 | // @T est(expect ed = Excep tion.class ) | |
146 | // @T est(expect ed = Asser tionError. class) | |
147 | @T est(expect ed = org.s pringframe work.web.u til.Nested ServletExc eption.cla ss) // just so | |
148 | pu blic void testExcept ionFileCan notBeAcces sedControl ler_view() throws Ex ception, A ssertionEr ror { | |
149 | Bool ean isDown load = fal se; | |
150 | Audi tLogger re quest=new AuditLogge r(vhaName, "86753303 .001", isD ownload); | |
151 | when (auditLogg erService. getPathFor TheAttachm ent(reques t)).thenRe turn(null) ; | |
152 | ||
153 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
154 | mapp er.configu re(Seriali zationFeat ure.WRAP_R OOT_VALUE, false); | |
155 | Obje ctWriter o w = mapper .writer(). withDefaul tPrettyPri nter(); | |
156 | Stri ng jsonReq uest = ow. writeValue AsString(r equest); | |
157 | ||
158 | mock Mvc.perfor m( | |
159 | post(" /api/v1/fi le").conte ntType(Med iaType.APP LICATION_J SON).conte nt(jsonReq uest)) | |
160 | // .andDo (print()) | |
161 | .andEx pect(statu s().isOk() ) | |
162 | ; | |
163 | } | |
164 | ||
165 | // @T est(expect ed = Excep tion.class ) | |
166 | // @T est(expect ed = Asser tionError. class) | |
167 | @T est(expect ed = org.s pringframe work.web.u til.Nested ServletExc eption.cla ss) | |
168 | pu blic void testExcept ionFileCan notBeAcces sedControl ler_Downlo ad() throw s Exceptio n, Asserti onError { | |
169 | Bool ean isDown load = fal se; | |
170 | Audi tLogger re quest=new AuditLogge r(vhaName, "86753303 .001", isD ownload); | |
171 | when (auditLogg erService. getPathFor TheAttachm ent(reques t)).thenRe turn(null) ; | |
172 | ||
173 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
174 | mapp er.configu re(Seriali zationFeat ure.WRAP_R OOT_VALUE, false); | |
175 | Obje ctWriter o w = mapper .writer(). withDefaul tPrettyPri nter(); | |
176 | Stri ng jsonReq uest = ow. writeValue AsString(r equest); | |
177 | ||
178 | mock Mvc.perfor m( | |
179 | post(" /api/v1/fi le").conte ntType(Med iaType.APP LICATION_J SON).conte nt(jsonReq uest)) | |
180 | // .andDo (print()) | |
181 | .andEx pect(statu s().isOk() ) | |
182 | ; | |
183 | } | |
184 | ||
185 | @T est | |
186 | pu blic void testNOTFOU NDControll er_file_Ex portAsPDF( ) throws E xception { | |
187 | // List <String> i mgList = A rrays.asLi st(images) ; | |
188 | // Stre am<String> imgStream = imgList .stream(); | |
189 | // imgS tream.forE ach( (img) -> { | |
190 | Stri ng[] badbo ys = {"NOT FOUND.bmp" , "uglydog .jpg"}; | |
191 | for( String im g : badboy s ) { | |
192 | Export AsPDF requ est = new ExportAsPD F(vhaName, "86753303 .001"); | |
193 | when(a uditLogger Service.ge tPathForEx portAsPDF( any(Export AsPDF.clas s))).thenR eturn(img) ; | |
194 | ||
195 | Object Mapper map per = new ObjectMapp er(); | |
196 | mapper .configure (Serializa tionFeatur e.WRAP_ROO T_VALUE, f alse); | |
197 | Object Writer ow = mapper.w riter().wi thDefaultP rettyPrint er(); | |
198 | String jsonReque st = ow.wr iteValueAs String(req uest); | |
199 | ||
200 | mockMv c.perform( | |
201 | post("/api /v1/Export AsPDF") | |
202 | .content Type(Media Type.APPLI CATION_JSO N) | |
203 | .content (jsonReque st)) | |
204 | // .andDo(p rint()) | |
205 | .andExpe ct(status( ).is(404)) | |
206 | ; | |
207 | } | |
208 | } | |
209 | ||
210 | @T est | |
211 | pu blic void testSucces sControlle r_file_Exp ortAsPDF_i mages() th rows Excep tion { | |
212 | // List <String> i mgList = A rrays.asLi st(images) ; | |
213 | // Stre am<String> imgStream = imgList .stream(); | |
214 | // imgS tream.forE ach( (img) -> { | |
215 | ||
216 | Syst em.err.pri ntln("BERN IE: " + "t estSuccess Controller _file_Expo rtAsPDF_im ages"); // tes ting the t est | |
217 | ||
218 | for( String im g : testIm ages ) { | |
219 | Export AsPDF requ est = new ExportAsPD F(vhaName, "86753303 .001"); | |
220 | when(a uditLogger Service.ge tPathForEx portAsPDF( any(Export AsPDF.clas s))).thenR eturn(img) ; | |
221 | ||
222 | Object Mapper map per = new ObjectMapp er(); | |
223 | mapper .configure (Serializa tionFeatur e.WRAP_ROO T_VALUE, f alse); | |
224 | Object Writer ow = mapper.w riter().wi thDefaultP rettyPrint er(); | |
225 | String jsonReque st = ow.wr iteValueAs String(req uest); | |
226 | ||
227 | System .err.print ln("jsonRe quest = " + jsonRequ est); // testing the test | |
228 | ||
229 | mockMv c.perform( | |
230 | post("/a pi/v1/expo rtAsPDF") | |
231 | .content Type(Media Type.APPLI CATION_JSO N) | |
232 | .content (jsonReque st)) | |
233 | // .andDo(p rint()) // way too v erbose! | |
234 | .andExpe ct(status( ).isOk()) | |
235 | // .andExpe ct(content ().content Type(Media Type.APPLI CATION_OCT ET_STREAM) ) | |
236 | .andExpe ct(content ().content Type(Media Type.value Of("applic ation/pdf" ))) | |
237 | ; | |
238 | } | |
239 | } | |
240 | ||
241 | @T est(expect ed = java. io.IOExcep tion.class ) // W e get an e xception, instead of 415! Coul d be impro ved. | |
242 | pu blic void testSucces sControlle r_file_Exp ortAsPDF_n on_image() throws Ex ception { | |
243 | ||
244 | Expo rtAsPDF re quest = ne w ExportAs PDF(vhaNam e, "867533 03.001"); // ignored by mock g etPathForE xportAsPDF | |
245 | when (auditLogg erService. getPathFor ExportAsPD F(any(Expo rtAsPDF.cl ass))).the nReturn(th isSrc); | |
246 | //file:/C: /Users/ DNS BadgeB/ecl ipse/trm-o xygen/ars_ app/src/te st/java/go v/va/med/a rs/control ler/FileOp erationsCo ntrollerTe st.java is not a rec ognized im ageformat. | |
247 | ||
248 | Obje ctMapper m apper = ne w ObjectMa pper(); | |
249 | mapp er.configu re(Seriali zationFeat ure.WRAP_R OOT_VALUE, false); | |
250 | Obje ctWriter o w = mapper .writer(). withDefaul tPrettyPri nter(); | |
251 | Stri ng jsonReq uest = ow. writeValue AsString(r equest); | |
252 | ||
253 | mock Mvc.perfor m( | |
254 | post(" /api/v1/ex portAsPDF" ).contentT ype(MediaT ype.APPLIC ATION_JSON ).content( jsonReques t)) | |
255 | .andDo (print()) | |
256 | .andEx pect(statu s().is(415 )) | |
257 | // Sta tus expect ed: <415>, HTTP Stat us 415 - U nsupported Media Typ e. Actuall y, we get an excepti on! | |
258 | ; | |
259 | } | |
260 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.