Produced by Araxis Merge on 3/12/2019 4:22:12 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\CC CC SEOC 1.7\seocapi-release1.7@25b9376983d\seoc-reactor\seoc-rest-api\src\test\java\gov\va\oneconsult\seoc\api\controller | UserControllerIntTest.java | Wed Jan 30 19:31:26 2019 UTC |
2 | C:\AraxisMergeCompare\Pri_re\Community Care Care Coordination SEOC 1.7-redacted\CC CC SEOC 1.7\seocapi-release1.7@25b9376983d\seoc-reactor\seoc-rest-api\src\test\java\gov\va\oneconsult\seoc\api\controller | UserControllerIntTest.java | Tue Mar 12 20:37:26 2019 UTC |
Description | Between Files 1 and 2 |
|
---|---|---|
Text Blocks | Lines | |
Unchanged | 1 | 1296 |
Changed | 0 | 0 |
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.oneco nsult.seoc .api.contr oller; | |
2 | ||
3 | import sta tic org.as sertj.core .api.Asser tions.asse rtThat; | |
4 | import sta tic org.ju nit.Assert .assertEqu als; | |
5 | import sta tic org.ju nit.Assert .assertTru e; | |
6 | ||
7 | import jav a.util.Set ; | |
8 | import jav a.util.str eam.Collec tors; | |
9 | ||
10 | import org .apache.lo g4j.Logger ; | |
11 | import org .junit.Aft er; | |
12 | import org .junit.Bef ore; | |
13 | import org .junit.Tes t; | |
14 | import org .junit.run ner.RunWit h; | |
15 | import org .springfra mework.boo t.context. embedded.L ocalServer Port; | |
16 | import org .springfra mework.boo t.test.con text.Sprin gBootTest; | |
17 | import org .springfra mework.boo t.test.web .client.Te stRestTemp late; | |
18 | import org .springfra mework.htt p.HttpEnti ty; | |
19 | import org .springfra mework.htt p.HttpHead ers; | |
20 | import org .springfra mework.htt p.HttpMeth od; | |
21 | import org .springfra mework.htt p.HttpStat us; | |
22 | import org .springfra mework.htt p.MediaTyp e; | |
23 | import org .springfra mework.htt p.Response Entity; | |
24 | import org .springfra mework.tes t.context. junit4.Spr ingRunner; | |
25 | ||
26 | import gov .va.onecon sult.seoc. api.Applic ation; | |
27 | import gov .va.onecon sult.seoc. api.json.C reateUserR equest; | |
28 | import gov .va.onecon sult.seoc. api.model. User; | |
29 | import gov .va.onecon sult.seoc. api.util.C onstants; | |
30 | import gov .va.onecon sult.seoc. api.util.D eserialize Test; | |
31 | import gov .va.onecon sult.seoc. api.util.E ncodeLogge rFactory; | |
32 | ||
33 | /** | |
34 | * Integra tion Test Cases for User Manag ement end points | |
35 | * | |
36 | * @author AbleVets | |
37 | */ | |
38 | @RunWith(S pringRunne r.class) | |
39 | @SpringBoo tTest(clas ses = Appl ication.cl ass, webEn vironment = SpringBo otTest.Web Environmen t.RANDOM_P ORT) | |
40 | public cla ss UserCon trollerInt Test | |
41 | { | |
42 | @L ocalServer Port | |
43 | pr ivate int port; | |
44 | ||
45 | pr ivate Test RestTempla te restTem plate = ne w TestRest Template() ; | |
46 | ||
47 | pr ivate Http Headers he aders = ne w HttpHead ers(); | |
48 | ||
49 | pu blic stati c final Lo gger logge r = Encode LoggerFact ory.getLog ger(UserCo ntrollerIn tTest.clas s); | |
50 | ||
51 | pu blic stati c final De serializeT est deseri alize = ne w Deserial izeTest(); | |
52 | ||
53 | pu blic stati c final St ring ROOT = "/v1/use r/"; | |
54 | ||
55 | pu blic stati c final St ring GET_A LL = "all" ; | |
56 | ||
57 | pu blic stati c final St ring SAVE = "save"; | |
58 | ||
59 | pu blic stati c final St ring DELET E = "delet e/"; | |
60 | ||
61 | pu blic stati c final St ring MAINT ENANCE = " maint/"; | |
62 | ||
63 | pr ivate int initialSiz e = 0; | |
64 | ||
65 | pu blic stati c final St ring vaUse rId = "Sys tem"; | |
66 | ||
67 | @B efore | |
68 | pu blic void setup() | |
69 | { | |
70 | setH eaders(); | |
71 | /*== ========== ========== ======Get All Users= ========== ========== ========== ===*/ | |
72 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(nul l, headers ); | |
73 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+GET_A LL), | |
74 | HttpMeth od.GET, en tity, Stri ng.class); | |
75 | ||
76 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
77 | if(u sers!=null ) { | |
78 | initia lSize = us ers.size() ; | |
79 | } | |
80 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
81 | } | |
82 | ||
83 | @A fter | |
84 | pu blic void tearDown() | |
85 | { | |
86 | ||
87 | } | |
88 | ||
89 | /* * | |
90 | * Descripti on: add ne w User - g et all to see new us er is adde d | |
91 | * / | |
92 | @T est | |
93 | pu blic void testSaveNe w() | |
94 | { | |
95 | ||
96 | Stri ng role = "Role"; | |
97 | Stri ng userNam e = "UserN ame"; | |
98 | Stri ng vaNetwo rkId = "Ne tworkId"; | |
99 | Stri ng domain = "Domain" ; | |
100 | ||
101 | /*== ========== ========== ======Crea te New Use r========= ========== ========== =====*/ | |
102 | Crea teUserRequ est userRe quset = Cr eateUserRe quest.Buil der.create () | |
103 | .withDom ain(domain ) | |
104 | .withRol e(role) | |
105 | .withUse rName(user Name) | |
106 | .withVaN etworkId(v aNetworkId ) | |
107 | .build() ; | |
108 | ||
109 | Stri ng request Json = Seo cObjectGen erator.asJ sonString( userRequse t); | |
110 | ||
111 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(req uestJson, headers); | |
112 | ||
113 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ SAVE ), | |
114 | HttpMeth od.PUT, en tity, Stri ng.class); | |
115 | ||
116 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
117 | Stri ng expecte dStatus = Constants. CREATED; | |
118 | ||
119 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
120 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.CREATE D); | |
121 | ||
122 | //Ch eck if new User is i n the get all Users list | |
123 | /*== ========== ========== ======Get All Users= ========== ========== ========== ===*/ | |
124 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
125 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
126 | HttpMeth od.GET, en tity, Stri ng.class); | |
127 | ||
128 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
129 | ||
130 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
131 | ||
132 | int currentSiz e = users! =null?user s.size():0 ; | |
133 | ||
134 | asse rtThat(cur rentSize). isEqualTo( initialSiz e+1); | |
135 | //Fo und saved user | |
136 | user s.forEach( user -> { | |
137 | if(use r.getUserN ame().equa lsIgnoreCa se(userNam e)) { | |
138 | user.get Domain().e qualsIgnor eCase(doma in); | |
139 | user.get VaNetworkI d().equals IgnoreCase (vaNetwork Id); | |
140 | user.get Role().equ alsIgnoreC ase(role); | |
141 | } | |
142 | }); | |
143 | ||
144 | ||
145 | } | |
146 | ||
147 | /* * | |
148 | * Descripti on: Add ne w user - g et all use rs check t o find new user - up date the u ser - get all users to see the data is u pdated | |
149 | * / | |
150 | @T est | |
151 | pu blic void testUpdate () | |
152 | { | |
153 | ||
154 | Stri ng role = "Role1"; | |
155 | Stri ng userNam e = "UserN ame1"; | |
156 | Stri ng vaNetwo rkId = "Ne tworkId1"; | |
157 | Stri ng domain = "Domain1 "; | |
158 | User userBefor e = null; | |
159 | User userAfter Update = n ull; | |
160 | ||
161 | /*== ========== ========== ======Crea te New Use r========= ========== ========== =====*/ | |
162 | Crea teUserRequ est userRe quset = Cr eateUserRe quest.Buil der.create () | |
163 | .withDom ain(domain ) | |
164 | .withRol e(role) | |
165 | .withUse rName(user Name) | |
166 | .withVaN etworkId(v aNetworkId ) | |
167 | .build() ; | |
168 | ||
169 | Stri ng request Json = Seo cObjectGen erator.asJ sonString( userRequse t); | |
170 | ||
171 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(req uestJson, headers); | |
172 | ||
173 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ SAVE ), | |
174 | HttpMeth od.PUT, en tity, Stri ng.class); | |
175 | ||
176 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
177 | Stri ng expecte dStatus = Constants. CREATED; | |
178 | ||
179 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
180 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.CREATE D); | |
181 | ||
182 | ||
183 | //Ch eck if new User is i n the get all Users list | |
184 | /*== ========== ========== ======Get All Users After crea te======== ========== ========== ======*/ | |
185 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
186 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
187 | HttpMeth od.GET, en tity, Stri ng.class); | |
188 | ||
189 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
190 | ||
191 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
192 | ||
193 | Set< User> matc hedUsers = users.str eam() | |
194 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
195 | .collect (Collector s.toSet()) ; | |
196 | ||
197 | asse rtThat(mat chedUsers) .isNotEmpt y(); | |
198 | asse rtThat(mat chedUsers. size()).is EqualTo(1) ; | |
199 | ||
200 | for( User user : matchedU sers) { | |
201 | userBe fore = use r; | |
202 | } | |
203 | ||
204 | ||
205 | /*== ========== ========== ======Upda te User=== ========== ========== ========== =*/ | |
206 | Stri ng newDoma in = "NewD omain"; | |
207 | Stri ng newUser Name = "Ne wRole"; | |
208 | Stri ng newRole = "newRol e"; | |
209 | user Requset = CreateUser Request.Bu ilder.crea te() | |
210 | .withDom ain(newDom ain) | |
211 | .withRol e(newRole) | |
212 | .withUse rName(newU serName) | |
213 | .withVaN etworkId(v aNetworkId ) | |
214 | .withPre vNetworkId (vaNetwork Id) | |
215 | .build() ; | |
216 | ||
217 | requ estJson = SeocObject Generator. asJsonStri ng(userReq uset); | |
218 | ||
219 | enti ty = new H ttpEntity< String>(re questJson, headers); | |
220 | ||
221 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ SAVE), | |
222 | HttpMeth od.PUT, en tity, Stri ng.class); | |
223 | ||
224 | actu alStatus = deseriali ze.generic Response(r esponse.ge tBody()).g etStatus() ; | |
225 | expe ctedStatus = Constan ts.UPDATED ; | |
226 | ||
227 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
228 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
229 | ||
230 | //Ch eck if upd ated User is in the get all Us ers list a nd check i f the valu es are upd ated | |
231 | /*== ========== ========== ======Get All Users after upda te======== ========== ========== ======*/ | |
232 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
233 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
234 | HttpMeth od.GET, en tity, Stri ng.class); | |
235 | ||
236 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
237 | ||
238 | user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
239 | ||
240 | matc hedUsers = users.str eam() | |
241 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
242 | .collect (Collector s.toSet()) ; | |
243 | ||
244 | asse rtThat(mat chedUsers) .isNotEmpt y(); | |
245 | asse rtThat(mat chedUsers. size()).is EqualTo(1) ; | |
246 | ||
247 | for( User user : matchedU sers) { | |
248 | userAf terUpdate = user; | |
249 | } | |
250 | ||
251 | //sa me user ha s been upd ated asser t that | |
252 | //ne tworkID wa s not chan ged but ot her detail s are chan ged | |
253 | asse rtThat(use rBefore.ge tVaNetwork Id()).isEq ualTo(user AfterUpdat e.getVaNet workId()); | |
254 | asse rtThat(use rBefore.ge tDomain()) .isNotEqua lTo(userAf terUpdate. getDomain( )); | |
255 | asse rtThat(use rBefore.ge tUserName( )).isNotEq ualTo(user AfterUpdat e.getUserN ame()); | |
256 | asse rtThat(use rBefore.ge tRole()).i sNotEqualT o(userAfte rUpdate.ge tRole()); | |
257 | } | |
258 | ||
259 | /* * | |
260 | * Descripti on: add ne w user - g et all to find new u ser - dele te user - get all to see user is not in the list | |
261 | * / | |
262 | @T est | |
263 | pu blic void testDelete () | |
264 | { | |
265 | ||
266 | Stri ng role = "Role2"; | |
267 | Stri ng userNam e = "UserN ame2"; | |
268 | Stri ng vaNetwo rkId = "Ne tworkId2"; | |
269 | Stri ng domain = "Domain2 "; | |
270 | ||
271 | /*== ========== ========== ======Crea te New Use r========= ========== ========== =====*/ | |
272 | Crea teUserRequ est userRe quset = Cr eateUserRe quest.Buil der.create () | |
273 | .withDom ain(domain ) | |
274 | .withRol e(role) | |
275 | .withUse rName(user Name) | |
276 | .withVaN etworkId(v aNetworkId ) | |
277 | .build() ; | |
278 | ||
279 | Stri ng request Json = Seo cObjectGen erator.asJ sonString( userRequse t); | |
280 | ||
281 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(req uestJson, headers); | |
282 | ||
283 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ SAVE ), | |
284 | HttpMeth od.PUT, en tity, Stri ng.class); | |
285 | ||
286 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
287 | Stri ng expecte dStatus = Constants. CREATED; | |
288 | ||
289 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
290 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.CREATE D); | |
291 | ||
292 | ||
293 | //Ch eck if new User is i n the get all Users list | |
294 | /*== ========== ========== ======Get All Users After crea te======== ========== ========== ======*/ | |
295 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
296 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
297 | HttpMeth od.GET, en tity, Stri ng.class); | |
298 | ||
299 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
300 | ||
301 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
302 | ||
303 | Set< User> matc hedUsers = users.str eam() | |
304 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
305 | .collect (Collector s.toSet()) ; | |
306 | ||
307 | asse rtThat(mat chedUsers) .isNotEmpt y(); | |
308 | asse rtThat(mat chedUsers. size()).is EqualTo(1) ; | |
309 | ||
310 | ||
311 | /*== ========== ========== ======Dele te User=== ========== ========== ========== =*/ | |
312 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
313 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ DELETE + vaNetwor kId), | |
314 | HttpMeth od.DELETE, entity, S tring.clas s); | |
315 | ||
316 | ||
317 | actu alStatus = deseriali ze.generic Response(r esponse.ge tBody()).g etStatus() ; | |
318 | expe ctedStatus = Constan ts.SUCCESS ; | |
319 | ||
320 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
321 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
322 | ||
323 | //Ch eck if upd ated User is in the get all Us ers list a nd check i f the valu es are upd ated | |
324 | /*== ========== ========== ======Get All Users after upda te======== ========== ========== ======*/ | |
325 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
326 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
327 | HttpMeth od.GET, en tity, Stri ng.class); | |
328 | ||
329 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
330 | ||
331 | user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
332 | ||
333 | matc hedUsers = users.str eam() | |
334 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
335 | .collect (Collector s.toSet()) ; | |
336 | ||
337 | //No user foun d with mat ching netw orkID. Use r deleted | |
338 | asse rtThat(mat chedUsers) .isEmpty() ; | |
339 | ||
340 | } | |
341 | ||
342 | /* * | |
343 | * Descripti on: try to delete a user that never exis ts | |
344 | * / | |
345 | @T est | |
346 | pu blic void testDelete NonExistin gUser() | |
347 | { | |
348 | Stri ng vaNetwo rkId = "Ne tworkId"; | |
349 | ||
350 | /*== ========== ========== ======tryi ng to Dele te a User which neve r existed ========== ========== ========== ====*/ | |
351 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(nul l, headers ); | |
352 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ DELE TE + vaNet workId), | |
353 | HttpMeth od.DELETE, entity, S tring.clas s); | |
354 | ||
355 | ||
356 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
357 | Stri ng expecte dStatus = Constants. FAILURE; | |
358 | ||
359 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
360 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.NOT_FO UND); | |
361 | ||
362 | } | |
363 | ||
364 | /* * | |
365 | * Descripti on: networ kId passed during de lete is em pty | |
366 | * / | |
367 | @T est | |
368 | pu blic void testDelete UserNetwor kIdEmpty() | |
369 | { | |
370 | Stri ng vaNetwo rkId = " " ; | |
371 | ||
372 | /*== ========== ========== ======tryi ng to Dele te a User which neve r existed ========== ========== ========== ====*/ | |
373 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(nul l, headers ); | |
374 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ DELE TE + vaNet workId), | |
375 | HttpMeth od.DELETE, entity, S tring.clas s); | |
376 | ||
377 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.BAD_RE QUEST); | |
378 | ||
379 | } | |
380 | ||
381 | ||
382 | /* * | |
383 | * Descripti on: add ne w user - g et all to find new u ser - dele te user - get all to see user not in the list - ad d user wit h same use rname and networkId | |
384 | * System sh ould not s top from a dding new user with same detai ls as the deleted us er. | |
385 | * / | |
386 | @T est | |
387 | pu blic void testAddUse rWithDetai lsOfDelete dUser() | |
388 | { | |
389 | ||
390 | Stri ng role = "Role3"; | |
391 | Stri ng userNam e = "UserN ame3"; | |
392 | Stri ng vaNetwo rkId = "Ne tworkId3"; | |
393 | Stri ng domain = "Domain3 "; | |
394 | User userBefor e = null; | |
395 | User userWithS ameInfo = null; | |
396 | ||
397 | /*== ========== ========== ======Crea te New Use r========= ========== ========== =====*/ | |
398 | Crea teUserRequ est userRe quset = Cr eateUserRe quest.Buil der.create () | |
399 | .withDom ain(domain ) | |
400 | .withRol e(role) | |
401 | .withUse rName(user Name) | |
402 | .withVaN etworkId(v aNetworkId ) | |
403 | .build() ; | |
404 | ||
405 | Stri ng request Json = Seo cObjectGen erator.asJ sonString( userRequse t); | |
406 | ||
407 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(req uestJson, headers); | |
408 | ||
409 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ SAVE ), | |
410 | HttpMeth od.PUT, en tity, Stri ng.class); | |
411 | ||
412 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
413 | Stri ng expecte dStatus = Constants. CREATED; | |
414 | ||
415 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
416 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.CREATE D); | |
417 | ||
418 | ||
419 | //Ch eck if new User is i n the get all Users list | |
420 | /*== ========== ========== ======Get All Users After crea te======== ========== ========== ======*/ | |
421 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
422 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
423 | HttpMeth od.GET, en tity, Stri ng.class); | |
424 | ||
425 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
426 | ||
427 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
428 | ||
429 | Set< User> matc hedUsers = users.str eam() | |
430 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
431 | .collect (Collector s.toSet()) ; | |
432 | ||
433 | asse rtThat(mat chedUsers) .isNotEmpt y(); | |
434 | asse rtThat(mat chedUsers. size()).is EqualTo(1) ; | |
435 | ||
436 | for( User user : matchedU sers) { | |
437 | userBe fore = use r; | |
438 | } | |
439 | ||
440 | //as sert that all fields have valu es as expe cted | |
441 | asse rtThat(use rBefore.ge tVaNetwork Id()).isEq ualTo(vaNe tworkId); | |
442 | asse rtThat(use rBefore.ge tDomain()) .isEqualTo (domain); | |
443 | asse rtThat(use rBefore.ge tUserName( )).isEqual To(userNam e); | |
444 | asse rtThat(use rBefore.ge tRole()).i sEqualTo(r ole); | |
445 | ||
446 | ||
447 | /*== ========== ========== ======Dele te User=== ========== ========== ========== =*/ | |
448 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
449 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ DELETE + vaNetwor kId), | |
450 | HttpMeth od.DELETE, entity, S tring.clas s); | |
451 | ||
452 | ||
453 | actu alStatus = deseriali ze.generic Response(r esponse.ge tBody()).g etStatus() ; | |
454 | expe ctedStatus = Constan ts.SUCCESS ; | |
455 | ||
456 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
457 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
458 | ||
459 | //Ch eck if the deleted u ser no lon ger exists in the ge t all user list | |
460 | /*== ========== ========== ======Get All Users after dele te======== ========== ========== ======*/ | |
461 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
462 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
463 | HttpMeth od.GET, en tity, Stri ng.class); | |
464 | ||
465 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
466 | ||
467 | user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
468 | ||
469 | matc hedUsers = users.str eam() | |
470 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
471 | .collect (Collector s.toSet()) ; | |
472 | ||
473 | //No user foun d with mat ching netw orkID. Use r deleted | |
474 | asse rtThat(mat chedUsers) .isEmpty() ; | |
475 | ||
476 | ||
477 | /*== ========== ========== ======Crea te New Use r with sam e details as deleted user===== ========== ========== =========* / | |
478 | user Requset = CreateUser Request.Bu ilder.crea te() | |
479 | .withDom ain(domain ) | |
480 | .withRol e(role) | |
481 | .withUse rName(user Name) | |
482 | .withVaN etworkId(v aNetworkId ) | |
483 | .build() ; | |
484 | ||
485 | requ estJson = SeocObject Generator. asJsonStri ng(userReq uset); | |
486 | ||
487 | enti ty = new H ttpEntity< String>(re questJson, headers); | |
488 | ||
489 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ SAVE), | |
490 | HttpMeth od.PUT, en tity, Stri ng.class); | |
491 | ||
492 | actu alStatus = deseriali ze.generic Response(r esponse.ge tBody()).g etStatus() ; | |
493 | expe ctedStatus = Constan ts.CREATED ; | |
494 | ||
495 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
496 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.CREATE D); | |
497 | ||
498 | ||
499 | //Ch eck if new User is i n the get all Users list | |
500 | /*== ========== ========== ======Get All Users After crea te======== ========== ========== ======*/ | |
501 | enti ty = new H ttpEntity< String>(nu ll, header s); | |
502 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+GET_ALL) , | |
503 | HttpMeth od.GET, en tity, Stri ng.class); | |
504 | ||
505 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
506 | ||
507 | user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
508 | ||
509 | matc hedUsers = users.str eam() | |
510 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
511 | .collect (Collector s.toSet()) ; | |
512 | ||
513 | asse rtThat(mat chedUsers) .isNotEmpt y(); | |
514 | asse rtThat(mat chedUsers. size()).is EqualTo(1) ; | |
515 | ||
516 | for( User user : matchedU sers) { | |
517 | userWi thSameInfo = user; | |
518 | } | |
519 | //as sert that all fields have same values | |
520 | asse rtThat(use rWithSameI nfo.getVaN etworkId() ).isEqualT o(vaNetwor kId); | |
521 | asse rtThat(use rWithSameI nfo.getDom ain()).isE qualTo(dom ain); | |
522 | asse rtThat(use rWithSameI nfo.getUse rName()).i sEqualTo(u serName); | |
523 | asse rtThat(use rWithSameI nfo.getRol e()).isEqu alTo(role) ; | |
524 | ||
525 | } | |
526 | ||
527 | ||
528 | /* * | |
529 | * Descripti on: Add ne w user - g et all use rs check t o find new user - up date the u ser - user to be upd ated is no t found | |
530 | * / | |
531 | @T est | |
532 | pu blic void testUpdate _UserNotFo und() | |
533 | { | |
534 | Stri ng vaNetwo rkId = "Ne tworkId4"; | |
535 | ||
536 | //Ch eck if new User is i n the get all Users list | |
537 | /*== ========== ========== ======Get All Users After crea te======== ========== ========== ======*/ | |
538 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(nul l, headers ); | |
539 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+GET_A LL), | |
540 | HttpMeth od.GET, en tity, Stri ng.class); | |
541 | ||
542 | asse rtEquals(H ttpStatus. OK, respon se.getStat usCode()); | |
543 | ||
544 | Set< User> user s = deseri alize.getU sersFromRe sponse(res ponse.getB ody()); | |
545 | ||
546 | Set< User> matc hedUsers = users.str eam() | |
547 | .filter( u -> u.get VaNetworkI d().equals IgnoreCase (vaNetwork Id)) | |
548 | .collect (Collector s.toSet()) ; | |
549 | ||
550 | asse rtThat(mat chedUsers) .isEmpty() ; | |
551 | ||
552 | ||
553 | /*== ========== ========== ======Upda te User=== ========== ========== ========== =*/ | |
554 | Stri ng newDoma in = "NewD omain"; | |
555 | Stri ng newUser Name = "Ne wRole"; | |
556 | Stri ng newRole = "newRol e"; | |
557 | Crea teUserRequ est userRe quset = Cr eateUserRe quest.Buil der.create () | |
558 | .withDom ain(newDom ain) | |
559 | .withRol e(newRole) | |
560 | .withUse rName(newU serName) | |
561 | .withVaN etworkId(v aNetworkId ) | |
562 | .withPre vNetworkId (vaNetwork Id) | |
563 | .build() ; | |
564 | ||
565 | Stri ng request Json = Seo cObjectGen erator.asJ sonString( userRequse t); | |
566 | ||
567 | enti ty = new H ttpEntity< String>(re questJson, headers); | |
568 | ||
569 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ SAVE), | |
570 | HttpMeth od.PUT, en tity, Stri ng.class); | |
571 | ||
572 | Stri ng actualS tatus = de serialize. genericRes ponse(resp onse.getBo dy()).getS tatus(); | |
573 | Stri ng expecte dStatus = Constants. FAILURE; | |
574 | ||
575 | asse rtThat(act ualStatus) .isEqualTo (expectedS tatus); | |
576 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.BAD_RE QUEST); | |
577 | ||
578 | } | |
579 | ||
580 | /* * | |
581 | * Descripti on:Test re ad mainten anceMode | |
582 | * / | |
583 | @T est | |
584 | pu blic void testMainte nanceMode( ) | |
585 | { | |
586 | Stri ng user = null; | |
587 | ||
588 | //Se tting main tenance mo de ON | |
589 | Stri ng request Json = "tr ue"; | |
590 | ||
591 | Http Entity<Str ing> entit y = new Ht tpEntity<S tring>(req uestJson, headers); | |
592 | ||
593 | Resp onseEntity <String> r esponse = restTempla te.exchang e(createUR LWithPort( ROOT+ MAIN TENANCE), | |
594 | HttpMeth od.PUT, en tity, Stri ng.class); | |
595 | //As sert that after sett ing the ma intenance mode respo nse is the vaUserId who reques ted to set maintenan ace | |
596 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
597 | asse rtThat(des erialize.g enericResp onse(respo nse.getBod y()).getIn Maintenanc eBy()).con tains(vaUs erId); | |
598 | ||
599 | //Ge t Maintena nce mode a fter ON | |
600 | resp onse = res tTemplate. exchange( | |
601 | createUR LWithPort( ROOT + MAI NTENANCE), HttpMetho d.GET, ent ity, Strin g.class); | |
602 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
603 | asse rtThat(des erialize.g enericResp onse(respo nse.getBod y()).getIn Maintenanc eBy()).con tains(vaUs erId); | |
604 | ||
605 | //Se tting main tenance mo de OFF | |
606 | requ estJson = "false"; | |
607 | ||
608 | enti ty = new H ttpEntity< String>(re questJson, headers); | |
609 | resp onse = res tTemplate. exchange(c reateURLWi thPort(ROO T+ MAINTEN ANCE), | |
610 | HttpMeth od.PUT, en tity, Stri ng.class); | |
611 | ||
612 | //As sert that after unse tting the maintenanc e mode res ponse is b lank | |
613 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
614 | user = ""; | |
615 | asse rtThat(des erialize.g enericResp onse(respo nse.getBod y()).getIn Maintenanc eBy()).con tains(user ); | |
616 | ||
617 | //Ge t Maintena nce mode a fter OFF | |
618 | resp onse = res tTemplate. exchange( | |
619 | createUR LWithPort( ROOT + MAI NTENANCE), HttpMetho d.GET, ent ity, Strin g.class); | |
620 | asse rtThat(res ponse.getS tatusCode( )).isEqual To(HttpSta tus.OK); | |
621 | user = ""; | |
622 | asse rtThat(des erialize.g enericResp onse(respo nse.getBod y()).getIn Maintenanc eBy()).con tains(user ); | |
623 | } | |
624 | ||
625 | ||
626 | /* * | |
627 | * | |
628 | * Descripti on: Set th e headers | |
629 | * / | |
630 | pr ivate void setHeader s() { | |
631 | head ers.setCon tentType(M ediaType.A PPLICATION _JSON_UTF8 ); | |
632 | head ers.set(Co nstants.US ERID, vaUs erId); | |
633 | } | |
634 | ||
635 | ||
636 | /* * | |
637 | * Descripti on: Test u rl | |
638 | * | |
639 | * @param ur i | |
640 | * @return r eturns tes t url | |
641 | * / | |
642 | pr ivate Stri ng createU RLWithPort (String ur i) | |
643 | { | |
644 | ||
645 | retu rn "http:/ /localhost :" + port + uri; | |
646 | } | |
647 | ||
648 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.