Produced by Araxis Merge on 6/18/2018 3:37: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 | CTT_DM2_v7.zip\CTT_ntrt-jira-ssoi-authenticator\authenticator\src\test\java\gov\vha\ctt\ntrt | SsoiAuthenticatorIT.java | Tue Jun 12 16:41:56 2018 UTC |
| 2 | CTT_DM2_v7.zip\CTT_ntrt-jira-ssoi-authenticator\authenticator\src\test\java\gov\vha\ctt\ntrt | SsoiAuthenticatorIT.java | Fri Jun 15 21:14:29 2018 UTC |
| Description | Between Files 1 and 2 |
|
|---|---|---|
| Text Blocks | Lines | |
| Unchanged | 3 | 836 |
| Changed | 2 | 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.vha.ctt. ntrt; | |
| 2 | ||
| 3 | ||
| 4 | import com .atlassian .jira.util .json.JSON Array; | |
| 5 | import com .atlassian .jira.util .json.JSON Exception; | |
| 6 | import com .atlassian .jira.util .json.JSON Object; | |
| 7 | import com .codeborne .selenide. SelenideEl ement; | |
| 8 | import com .google.co mmon.colle ct.Immutab leMap; | |
| 9 | import okh ttp3.Reque st; | |
| 10 | import okh ttp3.Respo nse; | |
| 11 | import org .junit.*; | |
| 12 | import org .junit.run ners.Metho dSorters; | |
| 13 | import org .openqa.se lenium.log ging.LogTy pe; | |
| 14 | import org .slf4j.Log ger; | |
| 15 | import org .slf4j.Log gerFactory ; | |
| 16 | ||
| 17 | import jav a.io.IOExc eption; | |
| 18 | import jav a.util.*; | |
| 19 | ||
| 20 | import sta tic com.co deborne.se lenide.Con dition.tex t; | |
| 21 | import sta tic com.co deborne.se lenide.Sel enide.$; | |
| 22 | import sta tic com.co deborne.se lenide.Sel enide.open ; | |
| 23 | import sta tic com.co deborne.se lenide.Web DriverRunn er.getWebD river; | |
| 24 | import sta tic gov.vh a.ctt.ntrt .OkHttp.*; | |
| 25 | import sta tic gov.vh a.ctt.ntrt .SelenideT ests.*; | |
| 26 | import sta tic gov.vh a.ctt.ntrt .SsoiAuthe nticator.* ; | |
| 27 | import sta tic gov.vh a.ctt.ntrt .SsoiAuthe nticator.R ole.*; | |
| 28 | import sta tic java.l ang.String .format; | |
| 29 | import sta tic java.u til.Arrays .asList; | |
| 30 | import sta tic org.as sertj.core .api.Asser tions.asse rtThat; | |
| 31 | import sta tic org.ju nit.Assert .fail; | |
| 32 | ||
| 33 | /** | |
| 34 | * Note: t ests which access a non-chrome Profile vi ew immedia tely after user crea tion rely on the dis abling of JIRA's | |
| 35 | * onboard ing facili ty. To dis able this feature, t he propert y '-Datlas sian.darkf eature.jir a.onboardi ng.feature .disabled= true' | |
| 36 | * is pass ed to JIRA on startu p. See src /test/dock er/conf/se tenv.sh. | |
| 37 | */ | |
| 38 | @FixMethod Order(Meth odSorters. NAME_ASCEN DING) | |
| 39 | public cla ss SsoiAut henticator IT { | |
| 40 | ||
| 41 | privat e static c lass TestU ser { | |
| 42 | St ring usern ame; | |
| 43 | St ring email Address; | |
| 44 | ||
| 45 | Te stUser() { | |
| 46 | username = UUID.ra ndomUUID() .toString( ); | |
| 47 | emailAdd ress = use rname + "@ test.com"; | |
| 48 | } | |
| 49 | ||
| 50 | Te stUser(Str ing userna me, String emailAddr ess) { | |
| 51 | this.use rname = us ername == null ? UUI D.randomUU ID().toStr ing() : us ername; | |
| 52 | this.ema ilAddress = emailAdd ress; | |
| 53 | } | |
| 54 | } | |
| 55 | ||
| 56 | privat e static f inal Logge r LOG = Lo ggerFactor y.getLogge r(SsoiAuth enticatorT est.class) ; | |
| 57 | ||
| 58 | private st atic final String BA SE_URL = " https:// DNS /ntrt"; | |
| 59 | privat e static f inal Strin g DASHBOAR D_URI = "/ secure/Das hboard.jsp a"; | |
| 60 | privat e static f inal Strin g PROFILE_ URI = "/se cure/ViewP rofile.jsp a"; | |
| 61 | privat e static f inal Strin g REST_URI = "/rest/ api/2"; | |
| 62 | ||
| 63 | privat e final Te stUser cus tomerUser = new Test User("ntrt _customer" , "ntrt_cu stomer@tes t.com"); | |
| 64 | privat e final Te stUser tea mUser = ne w TestUser ("ntrt_tea m", "ntrt_ team@test. com"); | |
| 65 | privat e final Te stUser adm inUser = n ew TestUse r("ntrt_ad min", "ntr t_admin@te st.com"); | |
| 66 | ||
| 67 | ||
| 68 | @Befor eClass | |
| 69 | public static vo id setUpOn ce() throw s Exceptio n { | |
| 70 | in itDriverSe rvice(); | |
| 71 | } | |
| 72 | ||
| 73 | @Befor e | |
| 74 | public void setU p() throws Exception { | |
| 75 | st artChromeD river(); | |
| 76 | } | |
| 77 | ||
| 78 | @After | |
| 79 | public void tear Down() { | |
| 80 | du mpSelenium Logs(LOG, LogType.BR OWSER); | |
| 81 | du mpSelenium Logs(LOG, LogType.CL IENT); | |
| 82 | st opChromeDr iver(); | |
| 83 | } | |
| 84 | ||
| 85 | @After Class | |
| 86 | public static vo id tearDow nOnce() { | |
| 87 | st opDriverSe rvice(); | |
| 88 | } | |
| 89 | ||
| 90 | @Test | |
| 91 | public void _chr omeDriverS mokeCheck( ) throws J SONExcepti on { | |
| 92 | se tHeadersFo r(customer User, NTRT _USER); | |
| 93 | op en(BASE_UR L + PROFIL E_URI); | |
| 94 | $( "#up-user- title-name ").shouldH ave(text(" NTRT Custo mer")); | |
| 95 | } | |
| 96 | ||
| 97 | @Test | |
| 98 | public void newU sersAreCre atedWithRo leAndVisib leInProfil eView() th rows Excep tion { | |
| 99 | Te stUser use r = new Te stUser(); | |
| 100 | as sertUserCr eatedOnFir stAccessWi thRole(use r, NTRT_US ER); | |
| 101 | as sertUserVi sibleInPro fileView(u ser, NTRT_ USER); | |
| 102 | ||
| 103 | us er = new T estUser(); | |
| 104 | as sertUserCr eatedOnFir stAccessWi thRole(use r, NTRT_ST AFF); | |
| 105 | as sertUserVi sibleInPro fileView(u ser, NTRT_ STAFF); | |
| 106 | ||
| 107 | us er = new T estUser(); | |
| 108 | as sertUserCr eatedOnFir stAccessWi thRole(use r, NTRT_AD MIN); | |
| 109 | as sertUserVi sibleInPro fileView(u ser, NTRT_ ADMIN); | |
| 110 | } | |
| 111 | ||
| 112 | @Test | |
| 113 | public void exis tingUsersC anSeeDashb oardView() throws Ex ception { | |
| 114 | as sertUserCa nSeeDashbo ardView(cu stomerUser , NTRT_USE R); | |
| 115 | as sertUserCa nSeeDashbo ardView(te amUser, NT RT_STAFF); | |
| 116 | as sertUserCa nSeeDashbo ardView(ad minUser, N TRT_ADMIN) ; | |
| 117 | } | |
| 118 | ||
| 119 | @Test | |
| 120 | public void exis tingUsersC anSeeProfi leView() t hrows Exce ption { | |
| 121 | as sertUserVi sibleInPro fileView(c ustomerUse r, NTRT_US ER); | |
| 122 | as sertUserVi sibleInPro fileView(t eamUser, N TRT_STAFF) ; | |
| 123 | as sertUserVi sibleInPro fileView(a dminUser, NTRT_ADMIN ); | |
| 124 | } | |
| 125 | ||
| 126 | @Test | |
| 127 | public void modi fiedRoleSh ouldBeUpda ted() thro ws Excepti on { | |
| 128 | Te stUser use r = new Te stUser(); | |
| 129 | as sertUserCr eatedOnFir stAccessWi thRole(use r, NTRT_US ER); | |
| 130 | as sertUserRo leIsUpdate dAfterExte rnalChange (user, NTR T_ADMIN); | |
| 131 | as sertUserRo leIsUpdate dAfterExte rnalChange (user, NTR T_STAFF); | |
| 132 | as sertUserRo leIsUpdate dAfterExte rnalChange (user, NTR T_USER); | |
| 133 | } | |
| 134 | ||
| 135 | @Test | |
| 136 | public void newU serIsCreat edWithMult ipleProjec tRoles() t hrows Exce ption { | |
| 137 | Te stUser thr eeRolesUse r = new Te stUser(); | |
| 138 | se nd(newRequ est(BASE_U RL, threeR olesUser, NTRT_ADMIN , NTRT_STA FF, NTRT_U SER)); | |
| 139 | as sertUserHa sProjectRo le(threeRo lesUser, p rojectRole For(NTRT_A DMIN)); | |
| 140 | as sertUserHa sProjectRo le(threeRo lesUser, p rojectRole For(NTRT_S TAFF)); | |
| 141 | as sertUserHa sProjectRo le(threeRo lesUser, p rojectRole For(NTRT_U SER)); | |
| 142 | ||
| 143 | Te stUser two RolesUser = new Test User(); | |
| 144 | se nd(newRequ est(BASE_U RL, twoRol esUser, NT RT_STAFF, NTRT_USER) ); | |
| 145 | as sertUserHa sProjectRo le(twoRole sUser, pro jectRoleFo r(NTRT_STA FF)); | |
| 146 | as sertUserHa sProjectRo le(twoRole sUser, pro jectRoleFo r(NTRT_USE R)); | |
| 147 | as sertUserDo esNotHaveP rojectRole (twoRolesU ser, proje ctRoleFor( NTRT_ADMIN )); | |
| 148 | } | |
| 149 | ||
| 150 | @Test | |
| 151 | public void mult ipleNtrtRo leChangesA reReflecte dInProject Roles() th rows Excep tion { | |
| 152 | Te stUser use r = new Te stUser(); | |
| 153 | ||
| 154 | // create th e user as a customer | |
| 155 | se nd(newRequ est(BASE_U RL, user, NTRT_USER) ); | |
| 156 | as sertUserHa sProjectRo le(user, p rojectRole For(NTRT_U SER)); | |
| 157 | as sertUserDo esNotHaveP rojectRole (user, pro jectRoleFo r(NTRT_STA FF)); | |
| 158 | as sertUserDo esNotHaveP rojectRole (user, pro jectRoleFo r(NTRT_ADM IN)); | |
| 159 | ||
| 160 | // replace c ustomer wi th team an d admin in one reque st | |
| 161 | se nd(newRequ est(BASE_U RL, user, NTRT_ADMIN , NTRT_STA FF)); | |
| 162 | as sertUserHa sProjectRo le(user, p rojectRole For(NTRT_A DMIN)); | |
| 163 | as sertUserHa sProjectRo le(user, p rojectRole For(NTRT_S TAFF)); | |
| 164 | as sertUserDo esNotHaveP rojectRole (user, pro jectRoleFo r(NTRT_USE R)); | |
| 165 | } | |
| 166 | ||
| 167 | /** | |
| 168 | * Thi s test is meant to c apture the case wher e a user's username has change d after cr eation, an d thus dif fers | |
| 169 | * fro m their ke y. There w as a bug w hich would prevent a dding a pr oject role for such a user, fo r which th is | |
| 170 | * ser ves as a r egression test. | |
| 171 | */ | |
| 172 | @Test | |
| 173 | public void user nameChange DoesNotPre ventRoleCh ange() thr ows Except ion { | |
| 174 | ||
| 175 | // create th e user wit h the admi n role | |
| 176 | Te stUser use r = new Te stUser(); | |
| 177 | as sertUserCr eatedOnFir stAccessWi thRole(use r, NTRT_AD MIN); | |
| 178 | ||
| 179 | St ring origi nalName = user.usern ame; | |
| 180 | us er.usernam e = user.u sername + "-2"; | |
| 181 | ||
| 182 | JS ONObject j son = new JSONObject (); | |
| 183 | js on.put("na me", user. username); | |
| 184 | ||
| 185 | Re sponse res ponse = se ndRestPut( BASE_URL + REST_URI + "/user?u sername=" + original Name, json ); | |
| 186 | as sertThat(r esponse.is Successful ()).isTrue (); | |
| 187 | as sertUserEx ists(user) ; | |
| 188 | ||
| 189 | // change ro le to user | |
| 190 | as sertUserRo leIsUpdate dAfterExte rnalChange (user, NTR T_USER); | |
| 191 | as sertUserDo esNotHaveP rojectRole (user, pro jectRoleFo r(NTRT_ADM IN)); | |
| 192 | as sertUserDo esNotHaveP rojectRole (user, pro jectRoleFo r(NTRT_STA FF)); | |
| 193 | ||
| 194 | // verify us er views | |
| 195 | as sertUserVi sibleInPro fileView(u ser, NTRT_ USER); | |
| 196 | as sertUserCa nSeeDashbo ardView(us er, NTRT_U SER); | |
| 197 | } | |
| 198 | ||
| 199 | @Test | |
| 200 | public void cust omLogoutUr lIsHonored () throws Exception { | |
| 201 | se tHeadersFo r(customer User, NTRT _USER); | |
| 202 | op en(BASE_UR L + PROFIL E_URI); | |
| 203 | ||
| 204 | // click the user menu to expose the log o ut option | |
| 205 | $( "#header-d etails-use r-fullname > span > span > img ").click() ; | |
| 206 | ||
| 207 | // now click the log o ut button | |
| 208 | $( "#log_out" ).click(); | |
| 209 | ||
| 210 | assertThat (getWebDri ver().getC urrentUrl( )).startsW ith("https :// DNS /centrallo gin/centra llanding.a spx"); | |
| 211 | } | |
| 212 | ||
| 213 | privat e void ass ertUserRol eIsUpdated AfterExter nalChange( TestUser u ser, Role newNtrtRol e) throws Exception { | |
| 214 | ||
| 215 | // simulate the first request af ter a role change in PRISME | |
| 216 | se nd(newRequ est(BASE_U RL, user, newNtrtRol e)); | |
| 217 | ||
| 218 | // verify th e user's n ew role ro le has bee n added an d old role (s) remove d | |
| 219 | fo r (Map.Ent ry<Role, S tring> ent ry : PROJE CT_ROLES.e ntrySet()) { | |
| 220 | Role ntr tRole = en try.getKey (); | |
| 221 | String p rojectRole = entry.g etValue(); | |
| 222 | ||
| 223 | if (newN trtRole == ntrtRole) | |
| 224 | asse rtUserHasP rojectRole (user, pro jectRole); | |
| 225 | else | |
| 226 | asse rtUserDoes NotHavePro jectRole(u ser, proje ctRole); | |
| 227 | } | |
| 228 | } | |
| 229 | ||
| 230 | privat e void ass ertUserCan SeeDashboa rdView(Tes tUser user , Role... ntrtRoles) throws Ex ception { | |
| 231 | se tHeadersFo r(user, nt rtRoles); | |
| 232 | op en(BASE_UR L + DASHBO ARD_URI); | |
| 233 | ||
| 234 | // page head er | |
| 235 | $( "#dashboar d-content > div.aui- page-heade r > div > div.aui-pa ge-header- main > h1" ) | |
| 236 | .sho uldHave(te xt("System Dashboard ")); | |
| 237 | ||
| 238 | // introduct ion sectio n | |
| 239 | $( "#gadget-1 0000 > div > div > h 3").should Have(text( "Welcome t o NTRT")); | |
| 240 | ||
| 241 | as sertThat($ ("#footer > fieldset > input[t ype=\"hidd en\"]:nth- child(1)") | |
| 242 | .att r("value") ).isEqualT o(user.use rname); | |
| 243 | } | |
| 244 | ||
| 245 | privat e void ass ertUserVis ibleInProf ileView(Te stUser use r, Role nt rtRole) th rows Excep tion { | |
| 246 | se tHeadersFo r(user, nt rtRole); | |
| 247 | op en(BASE_UR L + PROFIL E_URI); | |
| 248 | ||
| 249 | // user name | |
| 250 | as sertThat($ ("#footer > fieldset > input[t ype=\"hidd en\"]:nth- child(1)") .attr("val ue")).isEq ualTo(user .username) ; | |
| 251 | $( "#up-d-use rname").sh ouldHave(t ext(user.u sername)); | |
| 252 | ||
| 253 | // email add ress | |
| 254 | Se lenideElem ent email = $("#up-d -email > a "); | |
| 255 | em ail.should Have(text( user.email Address)); | |
| 256 | as sertThat(e mail.attr( "href")).i sEqualTo(" mailto:" + user.emai lAddress); | |
| 257 | ||
| 258 | // user shou ld be a me mber of th e service desk user' s group | |
| 259 | as sertThat($ ("#details -profile-f ragment > div.mod-co ntent > ul > li > dl :nth-child (7) > dd") .text()) | |
| 260 | .con tains("jir a-serviced esk-users" ); | |
| 261 | } | |
| 262 | ||
| 263 | privat e void ass ertUserCre atedOnFirs tAccessWit hRole(Test User user, Role ntrt Role) thro ws Excepti on { | |
| 264 | as sertUserNo tFound(use r.username ); | |
| 265 | se nd(newRequ est(BASE_U RL, user, ntrtRole)) ; | |
| 266 | as sertUserEx ists(user) ; | |
| 267 | as sertUserHa sProjectRo le(user, p rojectRole For(ntrtRo le)); | |
| 268 | } | |
| 269 | ||
| 270 | privat e void ass ertUserDoe sNotHavePr ojectRole( TestUser u ser, Strin g projectR ole) throw s Exceptio n { | |
| 271 | as sertProjec tRoleActor (user, pro jectRole, false); | |
| 272 | } | |
| 273 | ||
| 274 | privat e void ass ertUserHas ProjectRol e(TestUser user, Str ing projec tRole) thr ows Except ion { | |
| 275 | as sertProjec tRoleActor (user, pro jectRole, true); | |
| 276 | } | |
| 277 | ||
| 278 | privat e void ass ertProject RoleActor( TestUser u ser, Strin g projectR ole, boole an expectU serIsActor ) throws E xception { | |
| 279 | JS ONArray ac tors = get ProjectRol eActors(pr ojectRole) ; | |
| 280 | bo olean didF indActor = false; | |
| 281 | ||
| 282 | fo r (int i = 0; i < ac tors.lengt h(); i++) { | |
| 283 | JSONObje ct actor = actors.ge tJSONObjec t(i); | |
| 284 | if (user .username. equals(act or.getStri ng("name") )) { | |
| 285 | didF indActor = true; | |
| 286 | brea k; | |
| 287 | } | |
| 288 | } | |
| 289 | ||
| 290 | if (expectUs erIsActor && !didFin dActor) | |
| 291 | fail(for mat("The u ser '%s' w as expecte d but was not found among the actors for project r ole '%s', found acto rs: %s", u ser.userna me, projec tRole, act ors)); | |
| 292 | el se if (!ex pectUserIs Actor && d idFindActo r) | |
| 293 | fail(for mat("The u ser '%s' w as not exp ected but was found among the actors for project r ole '%s', found acto rs: %s", u ser.userna me, projec tRole, act ors)); | |
| 294 | } | |
| 295 | ||
| 296 | privat e JSONArra y getProje ctRoleActo rs(String projectRol e) throws Exception { | |
| 297 | Re sponse pro jectRoleRe sponse = s endRestGet (getProjec tRoleUri(p rojectRole )); | |
| 298 | JS ONObject r ole = new JSONObject (assertRes ponseNotEm pty(projec tRoleRespo nse)); | |
| 299 | re turn role. getJSONArr ay("actors "); | |
| 300 | } | |
| 301 | ||
| 302 | privat e Map<Stri ng, String > projectR oleUris = new HashMa p<>(3); | |
| 303 | ||
| 304 | privat e String g etProjectR oleUri(Str ing projec tRole) thr ows Except ion { | |
| 305 | St ring roleU ri = proje ctRoleUris .get(proje ctRole); | |
| 306 | ||
| 307 | if (roleUri == null) { | |
| 308 | Response response = sendRest Get(BASE_U RL + "/res t/api/2/pr oject/NTRT /role"); | |
| 309 | JSONObje ct roles = new JSONO bject(asse rtResponse NotEmpty(r esponse)); | |
| 310 | ||
| 311 | roleUri = roles.ge tString(pr ojectRole) ; | |
| 312 | assertTh at(roleUri ).isNotEmp ty(); | |
| 313 | projectR oleUris.pu t(projectR ole, roleU ri); | |
| 314 | } | |
| 315 | ||
| 316 | re turn roleU ri; | |
| 317 | } | |
| 318 | ||
| 319 | privat e String a ssertRespo nseNotEmpt y(Response response) throws IO Exception { | |
| 320 | St ring body = response .body().st ring(); | |
| 321 | as sertThat(b ody).isNot Empty(); | |
| 322 | re turn body; | |
| 323 | } | |
| 324 | ||
| 325 | privat e void ass ertUserNot Found(Stri ng usernam e) throws Exception { | |
| 326 | Re sponse res tResponse = sendRest Get(BASE_U RL + "/res t/api/2/us er?usernam e=" + user name); | |
| 327 | JS ONObject j son = new JSONObject (assertRes ponseNotEm pty(restRe sponse)); | |
| 328 | JS ONArray er rorMessage s = json.g etJSONArra y("errorMe ssages"); | |
| 329 | as sertThat(e rrorMessag es.length( )).isEqual To(1); | |
| 330 | as sertThat(e rrorMessag es.getStri ng(0)).isE qualTo(for mat("The u ser named '%s' does not exist" , username )); | |
| 331 | } | |
| 332 | ||
| 333 | privat e void ass ertUserExi sts(TestUs er user) t hrows Exce ption { | |
| 334 | Re sponse res ponse = se ndRestGet( BASE_URL + "/rest/ap i/2/user?u sername=" + user.use rname); | |
| 335 | JS ONObject j son = new JSONObject (assertRes ponseNotEm pty(respon se)); | |
| 336 | ||
| 337 | as sertThat(j son.getStr ing("name" )).isEqual To(user.us ername); | |
| 338 | as sertThat(j son.getStr ing("email Address")) .isEqualTo (user.emai lAddress); | |
| 339 | } | |
| 340 | ||
| 341 | privat e void sen d(Request request) t hrows Exce ption { | |
| 342 | Re sponse res ponse = un safeClient ().newCall (request). execute(); | |
| 343 | ||
| 344 | if (!respons e.isSucces sful()) { | |
| 345 | fail(for mat("Reque st for url '%s' fail ed with st atus %d an d body %s" , | |
| 346 | request.ur l(), respo nse.code() , response .body().st ring())); | |
| 347 | } | |
| 348 | } | |
| 349 | ||
| 350 | privat e Request newRequest (String ur l, TestUse r user, Ro le... role s) { | |
| 351 | re turn new R equest.Bui lder() | |
| 352 | .url (url) | |
| 353 | .hea der(HEADER _PRISME_RO LES, roles String(rol es)) | |
| 354 | .hea der(HEADER _ADEMAIL, user.email Address) | |
| 355 | .hea der(HEADER _ADSAMACCO UNTNAME, u ser.userna me) | |
| 356 | .bui ld(); | |
| 357 | } | |
| 358 | ||
| 359 | privat e String r olesString (Role... r oles) { | |
| 360 | St ring roleS tring; | |
| 361 | ||
| 362 | if (roles.le ngth == 1) { | |
| 363 | roleStri ng = norma lizeRoleSt ring(roles [0]); | |
| 364 | ||
| 365 | } else { | |
| 366 | StringBu ilder buil der = new StringBuil der(); | |
| 367 | Iterator <Role> it = asList(r oles).iter ator(); | |
| 368 | ||
| 369 | while (i t.hasNext( )) { | |
| 370 | Role role = it .next(); | |
| 371 | buil der.append (normalize RoleString (role)); | |
| 372 | ||
| 373 | if ( it.hasNext ()) | |
| 374 | builder.ap pend(","); | |
| 375 | } | |
| 376 | ||
| 377 | roleStri ng = build er.toStrin g(); | |
| 378 | } | |
| 379 | re turn roleS tring; | |
| 380 | } | |
| 381 | ||
| 382 | privat e String n ormalizeRo leString(R ole role) { | |
| 383 | re turn role. toString() .toLowerCa se(); | |
| 384 | } | |
| 385 | ||
| 386 | privat e String p rojectRole For(Role n trtRole) { | |
| 387 | re turn PROJE CT_ROLES.g et(ntrtRol e); | |
| 388 | } | |
| 389 | ||
| 390 | privat e String p rofilesStr ingFor(Tes tUser user , Role... ntrtRoles) throws JS ONExceptio n { | |
| 391 | ||
| 392 | JS ONObject p rofile = n ew JSONObj ect(Immuta bleMap.of( | |
| 393 | "tit le", "Sele nium", | |
| 394 | "app endMode", "", | |
| 395 | "hid eComment", true, | |
| 396 | "res pHeaders", new JSONA rray(), | |
| 397 | "fil ters", new JSONArray ())); | |
| 398 | ||
| 399 | JS ONArray he aders = ne w JSONArra y(); | |
| 400 | he aders.put( header(HEA DER_PRISME _ROLES, ro lesString( ntrtRoles) )); | |
| 401 | he aders.put( header(HEA DER_ADEMAI L, user.em ailAddress )); | |
| 402 | he aders.put( header(HEA DER_ADSAMA CCOUNTNAME , user.use rname)); | |
| 403 | pr ofile.put( "headers", headers); | |
| 404 | ||
| 405 | re turn new J SONArray(C ollections .singleton (profile)) .toString( ); | |
| 406 | } | |
| 407 | ||
| 408 | privat e JSONObje ct header( String nam e, String value) thr ows JSONEx ception { | |
| 409 | JS ONObject h eader = ne w JSONObje ct(); | |
| 410 | he ader.put(" enabled", true); | |
| 411 | he ader.put(" name", nam e); | |
| 412 | he ader.put(" value", va lue); | |
| 413 | he ader.put(" comment", ""); | |
| 414 | re turn heade r; | |
| 415 | } | |
| 416 | ||
| 417 | privat e void set HeadersFor (TestUser user, Role ... ntrtRo les) throw s JSONExce ption { | |
| 418 | se tModHeader Profiles(p rofilesStr ingFor(use r, ntrtRol es)); | |
| 419 | } | |
| 420 | } |
Araxis Merge (but not the data content of this report) is Copyright © 1993-2016 Araxis Ltd (www.araxis.com). All rights reserved.