1 16 17 18 package com.opensourcestrategies.crmsfa.test; 19 20 import org.ofbiz.base.util.UtilMisc; 21 22 import org.ofbiz.entity.GenericDelegator; 23 import org.ofbiz.entity.GenericEntityException; 24 import org.ofbiz.entity.GenericValue; 25 import org.ofbiz.security.Security; 26 import org.ofbiz.security.SecurityFactory; 27 28 import junit.framework.TestCase; 29 30 import com.opensourcestrategies.crmsfa.security.CrmsfaSecurity; 31 32 53 public class SecurityTests extends TestCase { 54 55 public static final String module = SecurityTests.class.getName(); 56 public static final String DELEGATOR = "test"; 57 private GenericDelegator delegator = null; 58 private Security security = null; 59 60 public SecurityTests (String name) { 61 super(name); 62 } 63 64 protected void setUp() throws Exception { 65 this.delegator = GenericDelegator.getGenericDelegator(DELEGATOR); 66 this.security = SecurityFactory.getInstance(delegator); 67 } 68 69 71 76 public void testDemoAccount1DemoSalesManagerUpdate() throws Exception { 77 try { 78 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 79 boolean hasPermission = false; 80 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) { 81 hasPermission = true; 82 } 83 TestCase.assertEquals("DemoSalesManager has update permission for DemoAccount1", true, hasPermission); 84 } catch (GenericEntityException ex) { 85 TestCase.fail(ex.getMessage()); 86 } 87 } 88 public void testDemoAccount1DemoSalesManagerView() throws Exception { 89 try { 90 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 91 boolean hasPermission = false; 92 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) { 93 hasPermission = true; 94 } 95 TestCase.assertEquals("DemoSalesManager has view permission for DemoAccount1", true, hasPermission); 96 } catch (GenericEntityException ex) { 97 TestCase.fail(ex.getMessage()); 98 } 99 } 100 public void testDemoAccount1DemoSalesManagerDeactivate() throws Exception { 101 try { 102 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 103 boolean hasPermission = false; 104 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) { 105 hasPermission = true; 106 } 107 TestCase.assertEquals("DemoSalesManager has deactivate permission for DemoAccount1", true, hasPermission); 108 } catch (GenericEntityException ex) { 109 TestCase.fail(ex.getMessage()); 110 } 111 } 112 public void testDemoAccount1DemoSalesManagerReassign() throws Exception { 113 try { 114 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 115 boolean hasPermission = false; 116 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) { 117 hasPermission = true; 118 } 119 TestCase.assertEquals("DemoSalesManager has reassign permission for DemoAccount1", true, hasPermission); 120 } catch (GenericEntityException ex) { 121 TestCase.fail(ex.getMessage()); 122 } 123 } 124 125 public void testDemoAccount1DemoSalesRep1View() throws Exception { 127 try { 128 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 129 boolean hasPermission = false; 130 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) { 131 hasPermission = true; 132 } 133 TestCase.assertEquals("DemoSalesRep1 has view permission for DemoAccount1", true, hasPermission); 134 } catch (GenericEntityException ex) { 135 TestCase.fail(ex.getMessage()); 136 } 137 } 138 public void testDemoAccount1DemoSalesRep1Update() throws Exception { 139 try { 140 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 141 boolean hasPermission = false; 142 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) { 143 hasPermission = true; 144 } 145 TestCase.assertEquals("DemoSalesRep1 has update permission for DemoAccount1", false, hasPermission); 146 } catch (GenericEntityException ex) { 147 TestCase.fail(ex.getMessage()); 148 } 149 } 150 public void testDemoAccount1DemoSalesRep1Deactivate() throws Exception { 151 try { 152 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 153 boolean hasPermission = false; 154 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) { 155 hasPermission = true; 156 } 157 TestCase.assertEquals("DemoSalesRep1 has deactivate permission for DemoAccount1", false, hasPermission); 158 } catch (GenericEntityException ex) { 159 TestCase.fail(ex.getMessage()); 160 } 161 } 162 public void testDemoAccount1DemoSalesRep1Reassign() throws Exception { 163 try { 164 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 165 boolean hasPermission = false; 166 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) { 167 hasPermission = true; 168 } 169 TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoAccount1", false, hasPermission); 170 } catch (GenericEntityException ex) { 171 TestCase.fail(ex.getMessage()); 172 } 173 } 174 175 public void testDemoAccount1DemoSalesRep2View() throws Exception { 177 try { 178 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 179 boolean hasPermission = false; 180 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) { 181 hasPermission = true; 182 } 183 TestCase.assertEquals("DemoSalesRep2 has view permission for DemoAccount1", true, hasPermission); 184 } catch (GenericEntityException ex) { 185 TestCase.fail(ex.getMessage()); 186 } 187 } 188 public void testDemoAccount1DemoSalesRep2Update() throws Exception { 189 try { 190 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 191 boolean hasPermission = false; 192 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) { 193 hasPermission = true; 194 } 195 TestCase.assertEquals("DemoSalesRep2 has update permission for DemoAccount1", true, hasPermission); 196 } catch (GenericEntityException ex) { 197 TestCase.fail(ex.getMessage()); 198 } 199 } 200 public void testDemoAccount1DemoSalesRep2Deactivate() throws Exception { 201 try { 202 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 203 boolean hasPermission = false; 204 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) { 205 hasPermission = true; 206 } 207 TestCase.assertEquals("DemoSalesRep2 has deactivate permission for DemoAccount1", false, hasPermission); 208 } catch (GenericEntityException ex) { 209 TestCase.fail(ex.getMessage()); 210 } 211 } 212 public void testDemoAccount1DemoSalesRep2Reassign() throws Exception { 213 try { 214 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 215 boolean hasPermission = false; 216 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) { 217 hasPermission = true; 218 } 219 TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoAccount1", false, hasPermission); 220 } catch (GenericEntityException ex) { 221 TestCase.fail(ex.getMessage()); 222 } 223 } 224 225 public void testDemoAccount1DemoSalesRep3View() throws Exception { 227 try { 228 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 229 boolean hasPermission = false; 230 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_VIEW", userLogin, "DemoAccount1")) { 231 hasPermission = true; 232 } 233 TestCase.assertEquals("DemoSalesRep3 has view permission for DemoAccount1", true, hasPermission); 234 } catch (GenericEntityException ex) { 235 TestCase.fail(ex.getMessage()); 236 } 237 } 238 public void testDemoAccount1DemoSalesRep3Update() throws Exception { 239 try { 240 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 241 boolean hasPermission = false; 242 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_UPDATE", userLogin, "DemoAccount1")) { 243 hasPermission = true; 244 } 245 TestCase.assertEquals("DemoSalesRep3 has update permission for DemoAccount1", true, hasPermission); 246 } catch (GenericEntityException ex) { 247 TestCase.fail(ex.getMessage()); 248 } 249 } 250 public void testDemoAccount1DemoSalesRep3Deactivate() throws Exception { 251 try { 252 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 253 boolean hasPermission = false; 254 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_DEACTIVATE", userLogin, "DemoAccount1")) { 255 hasPermission = true; 256 } 257 TestCase.assertEquals("DemoSalesRep3 has deactivate permission for DemoAccount1", true, hasPermission); 258 } catch (GenericEntityException ex) { 259 TestCase.fail(ex.getMessage()); 260 } 261 } 262 public void testDemoAccount1DemoSalesRep3Reassign() throws Exception { 263 try { 264 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 265 boolean hasPermission = false; 266 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_ACCOUNT", "_REASSIGN", userLogin, "DemoAccount1")) { 267 hasPermission = true; 268 } 269 TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoAccount1", true, hasPermission); 270 } catch (GenericEntityException ex) { 271 TestCase.fail(ex.getMessage()); 272 } 273 } 274 275 public void testDemoContact1DemoSalesManagerView() throws Exception { 277 try { 278 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 279 boolean hasPermission = false; 280 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) { 281 hasPermission = true; 282 } 283 TestCase.assertEquals("DemoSalesManager has view permission for DemoContact1", true, hasPermission); 284 } catch (GenericEntityException ex) { 285 TestCase.fail(ex.getMessage()); 286 } 287 } 288 public void testDemoContact1DemoSalesManagerUpdate() throws Exception { 289 try { 290 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 291 boolean hasPermission = false; 292 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) { 293 hasPermission = true; 294 } 295 TestCase.assertEquals("DemoSalesManager has update permission for DemoContact1", true, hasPermission); 296 } catch (GenericEntityException ex) { 297 TestCase.fail(ex.getMessage()); 298 } 299 } 300 public void testDemoContact1DemoSalesManagerDeactivate() throws Exception { 301 try { 302 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 303 boolean hasPermission = false; 304 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) { 305 hasPermission = true; 306 } 307 TestCase.assertEquals("DemoSalesManager has deactivate permission for DemoContact1", true, hasPermission); 308 } catch (GenericEntityException ex) { 309 TestCase.fail(ex.getMessage()); 310 } 311 } 312 public void testDemoContact1DemoSalesManagerReassign() throws Exception { 313 try { 314 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 315 boolean hasPermission = false; 316 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) { 317 hasPermission = true; 318 } 319 TestCase.assertEquals("DemoSalesManager has reassign permission for DemoContact1", true, hasPermission); 320 } catch (GenericEntityException ex) { 321 TestCase.fail(ex.getMessage()); 322 } 323 } 324 public void testDemoContact2DemoSalesManagerReassign() throws Exception { 325 try { 326 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 327 boolean hasPermission = false; 328 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) { 329 hasPermission = true; 330 } 331 TestCase.assertEquals("DemoSalesManager has reassign permission for DemoContact2", true, hasPermission); 332 } catch (GenericEntityException ex) { 333 TestCase.fail(ex.getMessage()); 334 } 335 } 336 337 public void testDemoContact1DemoSalesRep1View() throws Exception { 339 try { 340 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 341 boolean hasPermission = false; 342 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) { 343 hasPermission = true; 344 } 345 TestCase.assertEquals("DemoSalesRep1 has view permission for DemoContact1", true, hasPermission); 346 } catch (GenericEntityException ex) { 347 TestCase.fail(ex.getMessage()); 348 } 349 } 350 public void testDemoContact1DemoSalesRep1Update() throws Exception { 351 try { 352 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 353 boolean hasPermission = false; 354 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) { 355 hasPermission = true; 356 } 357 TestCase.assertEquals("DemoSalesRep1 has update permission for DemoContact1", false, hasPermission); 358 } catch (GenericEntityException ex) { 359 TestCase.fail(ex.getMessage()); 360 } 361 } 362 public void testDemoContact1DemoSalesRep1Deactivate() throws Exception { 363 try { 364 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 365 boolean hasPermission = false; 366 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) { 367 hasPermission = true; 368 } 369 TestCase.assertEquals("DemoSalesRep1 has deactivate permission for DemoContact1", false, hasPermission); 370 } catch (GenericEntityException ex) { 371 TestCase.fail(ex.getMessage()); 372 } 373 } 374 public void testDemoContact1DemoSalesRep1Reassign() throws Exception { 375 try { 376 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 377 boolean hasPermission = false; 378 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) { 379 hasPermission = true; 380 } 381 TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoContact1", false, hasPermission); 382 } catch (GenericEntityException ex) { 383 TestCase.fail(ex.getMessage()); 384 } 385 } 386 public void testDemoContact2DemoSalesRep1Reassign() throws Exception { 387 try { 388 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 389 boolean hasPermission = false; 390 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) { 391 hasPermission = true; 392 } 393 TestCase.assertEquals("DemoSalesRep1 has reassign permission for DemoContact2", false, hasPermission); 394 } catch (GenericEntityException ex) { 395 TestCase.fail(ex.getMessage()); 396 } 397 } 398 public void testDemoContact1DemoSalesRep2View() throws Exception { 400 try { 401 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 402 boolean hasPermission = false; 403 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) { 404 hasPermission = true; 405 } 406 TestCase.assertEquals("DemoSalesRep2 has view permission for DemoContact1", true, hasPermission); 407 } catch (GenericEntityException ex) { 408 TestCase.fail(ex.getMessage()); 409 } 410 } 411 public void testDemoContact1DemoSalesRep2Update() throws Exception { 412 try { 413 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 414 boolean hasPermission = false; 415 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) { 416 hasPermission = true; 417 } 418 TestCase.assertEquals("DemoSalesRep2 has update permission for DemoContact1", true, hasPermission); 419 } catch (GenericEntityException ex) { 420 TestCase.fail(ex.getMessage()); 421 } 422 } 423 public void testDemoContact1DemoSalesRep2Deactivate() throws Exception { 424 try { 425 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 426 boolean hasPermission = false; 427 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) { 428 hasPermission = true; 429 } 430 TestCase.assertEquals("DemoSalesRep2 has deactivate permission for DemoContact1", false, hasPermission); 431 } catch (GenericEntityException ex) { 432 TestCase.fail(ex.getMessage()); 433 } 434 } 435 public void testDemoContact1DemoSalesRep2Reassign() throws Exception { 436 try { 437 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 438 boolean hasPermission = false; 439 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) { 440 hasPermission = true; 441 } 442 TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoContact1", false, hasPermission); 443 } catch (GenericEntityException ex) { 444 TestCase.fail(ex.getMessage()); 445 } 446 } 447 public void testDemoContact2DemoSalesRep2Reassign() throws Exception { 448 try { 449 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep2")); 450 boolean hasPermission = false; 451 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) { 452 hasPermission = true; 453 } 454 TestCase.assertEquals("DemoSalesRep2 has reassign permission for DemoContact2", false, hasPermission); 455 } catch (GenericEntityException ex) { 456 TestCase.fail(ex.getMessage()); 457 } 458 } 459 460 public void testDemoContact1DemoSalesRep3View() throws Exception { 462 try { 463 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 464 boolean hasPermission = false; 465 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_VIEW", userLogin, "DemoContact1")) { 466 hasPermission = true; 467 } 468 TestCase.assertEquals("DemoSalesRep3 has view permission for DemoContact1", true, hasPermission); 469 } catch (GenericEntityException ex) { 470 TestCase.fail(ex.getMessage()); 471 } 472 } 473 public void testDemoContact1DemoSalesRep3Update() throws Exception { 474 try { 475 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 476 boolean hasPermission = false; 477 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_UPDATE", userLogin, "DemoContact1")) { 478 hasPermission = true; 479 } 480 TestCase.assertEquals("DemoSalesRep3 has update permission for DemoContact1", true, hasPermission); 481 } catch (GenericEntityException ex) { 482 TestCase.fail(ex.getMessage()); 483 } 484 } 485 public void testDemoContact1DemoSalesRep3Deactivate() throws Exception { 486 try { 487 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 488 boolean hasPermission = false; 489 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_DEACTIVATE", userLogin, "DemoContact1")) { 490 hasPermission = true; 491 } 492 TestCase.assertEquals("DemoSalesRep3 has deactivate permission for DemoContact1", false, hasPermission); 493 } catch (GenericEntityException ex) { 494 TestCase.fail(ex.getMessage()); 495 } 496 } 497 public void testDemoContact1DemoSalesRep3Reassign() throws Exception { 498 try { 499 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 500 boolean hasPermission = false; 501 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact1")) { 502 hasPermission = true; 503 } 504 TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoContact1", false, hasPermission); 505 } catch (GenericEntityException ex) { 506 TestCase.fail(ex.getMessage()); 507 } 508 } 509 public void testDemoContact2DemoSalesRep3Reassign() throws Exception { 510 try { 511 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep3")); 512 boolean hasPermission = false; 513 if (CrmsfaSecurity.hasPartyRelationSecurity(security, "CRMSFA_CONTACT", "_REASSIGN", userLogin, "DemoContact2")) { 514 hasPermission = true; 515 } 516 TestCase.assertEquals("DemoSalesRep3 has reassign permission for DemoContact2", false, hasPermission); 517 } catch (GenericEntityException ex) { 518 TestCase.fail(ex.getMessage()); 519 } 520 } 521 522 525 public void testDemoTask1DemoSalesManagerView() throws Exception { 526 try { 527 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 528 boolean hasPermission = false; 529 if (CrmsfaSecurity.hasActivityPermission(security, "_VIEW", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 530 hasPermission = true; 531 } 532 TestCase.assertEquals("DemoSalesManager can view DemoTask1 which is associated with DemoAccount1", true, hasPermission); 533 } catch (GenericEntityException ex) { 534 TestCase.fail(ex.getMessage()); 535 } 536 } 537 public void testDemoTask1DemoSalesManagerUpdate() throws Exception { 538 try { 539 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 540 boolean hasPermission = false; 541 if (CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 542 hasPermission = true; 543 } 544 TestCase.assertEquals("DemoSalesManager can update DemoTask1 which is associated with DemoAccount1", true, hasPermission); 545 } catch (GenericEntityException ex) { 546 TestCase.fail(ex.getMessage()); 547 } 548 } 549 public void testDemoTask1DemoSalesManagerClose() throws Exception { 550 try { 551 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 552 boolean hasPermission = false; 553 if (CrmsfaSecurity.hasActivityPermission(security, "_CLOSE", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 554 hasPermission = true; 555 } 556 TestCase.assertEquals("DemoSalesManager can close DemoTask1 which is associated with DemoAccount1", true, hasPermission); 557 } catch (GenericEntityException ex) { 558 TestCase.fail(ex.getMessage()); 559 } 560 } 561 public void testDemoTask1DemoSalesRep1View() throws Exception { 562 try { 563 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 564 boolean hasPermission = false; 565 if (CrmsfaSecurity.hasActivityPermission(security, "_VIEW", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 566 hasPermission = true; 567 } 568 TestCase.assertEquals("DemoSalesRep1 can view DemoTask1 which is associated with DemoAccount1", true, hasPermission); 569 } catch (GenericEntityException ex) { 570 TestCase.fail(ex.getMessage()); 571 } 572 } 573 public void testDemoTask1DemoSalesRep1Update() throws Exception { 574 try { 575 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 576 boolean hasPermission = false; 577 if (CrmsfaSecurity.hasActivityPermission(security, "_UPDATE", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 578 hasPermission = true; 579 } 580 TestCase.assertEquals("DemoSalesRep1 can update DemoTask1 which is associated with DemoAccount1", false, hasPermission); 581 } catch (GenericEntityException ex) { 582 TestCase.fail(ex.getMessage()); 583 } 584 } 585 public void testDemoTask1DemoSalesRep1Close() throws Exception { 586 try { 587 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 588 boolean hasPermission = false; 589 if (CrmsfaSecurity.hasActivityPermission(security, "_CLOSE", userLogin, "DemoTask1", "DemoAccount1", null, null)) { 590 hasPermission = true; 591 } 592 TestCase.assertEquals("DemoSalesRep1 can close DemoTask1 which is associated with DemoAccount1", false, hasPermission); 593 } catch (GenericEntityException ex) { 594 TestCase.fail(ex.getMessage()); 595 } 596 } 597 598 601 public void testDemoCase1DemoSalesManagerView() throws Exception { 602 try { 603 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 604 boolean hasPermission = false; 605 if (CrmsfaSecurity.hasCasePermission(security, "_VIEW", userLogin, "DemoCase1")) { 606 hasPermission = true; 607 } 608 TestCase.assertEquals("DemoSalesManager can view DemoCase1", true, hasPermission); 609 } catch (GenericEntityException ex) { 610 TestCase.fail(ex.getMessage()); 611 } 612 } 613 public void testDemoCase1DemoSalesManagerUpdate() throws Exception { 614 try { 615 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 616 boolean hasPermission = false; 617 if (CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, "DemoCase1")) { 618 hasPermission = true; 619 } 620 TestCase.assertEquals("DemoSalesManager can update DemoCase1", true, hasPermission); 621 } catch (GenericEntityException ex) { 622 TestCase.fail(ex.getMessage()); 623 } 624 } 625 626 public void testDemoCase1DemoSalesManagerClose() throws Exception { 627 try { 628 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesManager")); 629 boolean hasPermission = false; 630 if (CrmsfaSecurity.hasCasePermission(security, "_CLOSE", userLogin, "DemoCase1")) { 631 hasPermission = true; 632 } 633 TestCase.assertEquals("DemoSalesManager can close DemoCase1", true, hasPermission); 634 } catch (GenericEntityException ex) { 635 TestCase.fail(ex.getMessage()); 636 } 637 } 638 public void testDemoCase1DemoSalesRep1View() throws Exception { 639 try { 640 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 641 boolean hasPermission = false; 642 if (CrmsfaSecurity.hasCasePermission(security, "_VIEW", userLogin, "DemoCase1")) { 643 hasPermission = true; 644 } 645 TestCase.assertEquals("DemoSalesRep1 can view DemoCase1", true, hasPermission); 646 } catch (GenericEntityException ex) { 647 TestCase.fail(ex.getMessage()); 648 } 649 } 650 public void testDemoCase1DemoSalesRep1Update() throws Exception { 651 try { 652 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 653 boolean hasPermission = false; 654 if (CrmsfaSecurity.hasCasePermission(security, "_UPDATE", userLogin, "DemoCase1")) { 655 hasPermission = true; 656 } 657 TestCase.assertEquals("DemoSalesRep1 can update DemoCase1", false, hasPermission); 658 } catch (GenericEntityException ex) { 659 TestCase.fail(ex.getMessage()); 660 } 661 } 662 public void testDemoCase1DemoSalesRep1Close() throws Exception { 663 try { 664 GenericValue userLogin = delegator.findByPrimaryKeyCache("UserLogin", UtilMisc.toMap("userLoginId", "DemoSalesRep1")); 665 boolean hasPermission = false; 666 if (CrmsfaSecurity.hasCasePermission(security, "_CLOSE", userLogin, "DemoCase1")) { 667 hasPermission = true; 668 } 669 TestCase.assertEquals("DemoSalesRep1 can close DemoCase1", false, hasPermission); 670 } catch (GenericEntityException ex) { 671 TestCase.fail(ex.getMessage()); 672 } 673 } 674 } 675 | Popular Tags |