| 1 67 package com.ivata.groupware.business.addressbook; 68 69 import java.io.File ; 70 import java.util.ArrayList ; 71 import java.util.Date ; 72 import java.util.HashSet ; 73 import java.util.Iterator ; 74 import java.util.List ; 75 import java.util.Properties ; 76 import java.util.Set ; 77 78 import net.sf.hibernate.HibernateException; 79 import net.sf.hibernate.cfg.Configuration; 80 81 import com.ivata.groupware.admin.AdminTestCase; 82 import com.ivata.groupware.admin.security.server.SecuritySession; 83 import com.ivata.groupware.admin.security.user.UserDO; 84 import com.ivata.groupware.admin.setting.SettingsImpl; 85 import com.ivata.groupware.business.addressbook.address.AddressDO; 86 import com.ivata.groupware.business.addressbook.address.country.CountryDO; 87 import com.ivata.groupware.business.addressbook.person.PersonDO; 88 import com.ivata.groupware.business.addressbook.person.employee.EmployeeDO; 89 import com.ivata.groupware.business.addressbook.person.group.GroupDO; 90 import com.ivata.groupware.business.addressbook.right.AddressBookRightsImpl; 91 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressConstants; 92 import com.ivata.groupware.business.addressbook.telecomaddress.TelecomAddressDO; 93 import com.ivata.groupware.container.persistence.hibernate.HibernateManager; 94 import com.ivata.mask.DefaultMaskFactory; 95 import com.ivata.mask.field.DefaultFieldValueConvertorFactory; 96 import com.ivata.mask.persistence.PersistenceSession; 97 import com.ivata.mask.util.SystemException; 98 import com.ivata.mask.validation.ValidationErrors; 99 100 111 public class AddressBookImplTest extends AdminTestCase { 112 private final static String DEFAULT_GROUP_ID = "7"; 114 123 private static Configuration getHibernateConfiguration() throws HibernateException { 124 Configuration hibernateConfiguration = new Configuration(); 125 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/admin/setting/SettingDO.hbm.xml")); 126 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/admin/security/user/UserDO.hbm.xml")); 127 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/address/AddressDO.hbm.xml")); 128 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/address/country/CountryDO.hbm.xml")); 129 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/person/PersonDO.hbm.xml")); 130 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/person/group/right/RightDO.hbm.xml")); 131 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/person/group/right/detail/RightDetailDO.hbm.xml")); 132 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/person/group/GroupDO.hbm.xml")); 133 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/person/employee/EmployeeDO.hbm.xml")); 134 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/business/addressbook/telecomaddress/TelecomAddressDO.hbm.xml")); 135 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/navigation/menu/MenuDO.hbm.xml")); 136 hibernateConfiguration.addFile(new File ("../hibernate/target/xdoclet/hibernatedoclet/com/ivata/groupware/navigation/menu/item/MenuItemDO.hbm.xml")); 137 138 Properties hibernateProperties = new Properties (); 139 hibernateProperties.setProperty("hibernate.connection.driver_class", "org.postgresql.Driver"); 140 hibernateProperties.setProperty("hibernate.connection.URL", "jdbc:postgresql://localhost:5432/portal"); 141 hibernateProperties.setProperty("hibernate.connection.username", "postgres"); 142 hibernateProperties.setProperty("hibernate.connection.password", ""); 143 hibernateProperties.setProperty("hibernate.dialect", "net.sf.hibernate.dialect.PostgreSQLDialect"); 144 hibernateProperties.setProperty("hibernate.show_sql", "true"); 145 hibernateConfiguration.setProperties(hibernateProperties); 146 147 return hibernateConfiguration; 149 } 150 151 156 private AddressBookImpl addressBook; 157 GroupDO defaultGroup; 158 163 List newGroups = new ArrayList (); 164 165 170 List newPeople = new ArrayList (); 171 172 176 public AddressBookImplTest(String arg0) throws HibernateException { 177 super(arg0); 178 } 179 180 181 189 private GroupDO createTestGroup(final GroupDO parent, 190 final int number) throws SystemException { 191 SecuritySession securitySession = getSecuritySession(); 192 193 PersonDO groupHead = createTestPerson(number); 194 groupHead.setFileAs("head of group " + number); 195 addressBook.amendPerson(securitySession, groupHead); 196 197 Set groupPeople = new HashSet (); 198 groupPeople.add(groupHead); 199 200 GroupDO group = new GroupDO(); 201 group.setDescription("test description " + number); 203 group.setParent(parent); 204 group.setPeople(groupPeople); 205 group.setName("test group " + number); 206 group.setHead(groupHead); 207 208 group = addressBook.addGroup(getSecuritySession(), group); 209 assertNotNull(group.getId()); 210 group = addressBook.findGroupByPrimaryKey(securitySession, group.getId()); 211 newGroups.add(group); 212 213 return group; 214 } 215 216 217 225 private PersonDO createTestPerson(final int number) throws SystemException { 226 SecuritySession securitySession = getSecuritySession(); 227 PersonDO person = new PersonDO(); 228 person.setUser(null); 229 person.setGroup(defaultGroup); 230 person.setCompany("test company " + number); 231 person.setFileAs("file as " + number); 232 person.setFirstNames("first names " + number); 233 person.setLastName("last name " + number); 234 person.setSalutation("Mr " + number); 235 236 person = addressBook.addPerson(getSecuritySession(), person); 237 assertNotNull(person.getId()); 238 person = addressBook.findPersonByPrimaryKey(securitySession, person.getId()); 239 newPeople.add(person); 240 241 return person; 242 } 243 246 protected synchronized void setUp() throws Exception { 247 super.setUp(); 248 SecuritySession securitySession = getSecuritySession(); 249 addressBook = new AddressBookImpl(getHibernateManager(), 250 new DefaultMaskFactory(new DefaultFieldValueConvertorFactory()), 251 new AddressBookRightsImpl(getHibernateManager()), 252 new SettingsImpl(getHibernateManager())); 253 defaultGroup = addressBook.findGroupByPrimaryKey(securitySession, 254 DEFAULT_GROUP_ID); 255 } 256 257 260 protected void tearDown() throws Exception { 261 super.tearDown(); 262 SecuritySession securitySession = getSecuritySession(); 263 264 Iterator groupIterator = newGroups.iterator(); 266 while(groupIterator.hasNext()) { 267 GroupDO group = (GroupDO) groupIterator.next(); 268 if (group.getId() == null) { 269 throw new NullPointerException ("Group " 270 + group 271 + " has a null id"); 272 } else { 273 addressBook.removeGroup(securitySession, group.getId()); 274 } 275 } 276 } 277 278 public void testAddAddressBook() { 279 } 280 281 290 public void testAddGroup() throws SystemException { 291 SecuritySession securitySession = getSecuritySession(); 292 293 int totalGroups = 3; 295 GroupDO parentGroup = defaultGroup; 296 Set groupPeople = new HashSet (); 297 298 for (int i = 0; i < totalGroups; ++i) { 299 GroupDO group = createTestGroup(parentGroup, i); 300 301 assertNotNull(group.getCreated()); 302 assertNotNull(group.getModified()); 303 assertNotNull(group.getCreatedBy()); 304 assertNotNull(group.getModifiedBy()); 305 assertEquals(group.getCreated(), group.getModified()); 306 assertEquals(group.getCreatedBy(), group.getModifiedBy()); 307 assertEquals("test description " + i, group.getDescription()); 308 assertEquals("test group " + i, group.getName()); 309 assertNotNull(group.getHead()); 310 assertTrue(group.getPeople().size() == 1); 311 assertTrue(group.getPeople().contains(group.getHead())); 312 313 if (i==0) { 315 parentGroup = group; 316 } 317 } 318 } 319 320 329 public void testAddPerson() throws SystemException { 330 SecuritySession securitySession = getSecuritySession(); 332 333 334 PersonDO person = createTestPerson(0); 335 assertNotNull(person.getCreated()); 336 assertNotNull(person.getModified()); 337 assertNotNull(person.getCreatedBy()); 338 assertNotNull(person.getModifiedBy()); 339 assertEquals(person.getCreated(), person.getModified()); 340 assertEquals(person.getCreatedBy(), person.getModifiedBy()); 341 assertEquals("test company 0", person.getCompany()); 342 assertEquals("file as 0", person.getFileAs()); 343 assertEquals("first names 0", person.getFirstNames()); 344 assertEquals("last name 0", person.getLastName()); 345 assertEquals("Mr 0", person.getSalutation()); 346 } 347 348 public void testAddUserGroup() { 349 } 351 352 public void testAmendGroup() throws SystemException { 353 SecuritySession securitySession = getSecuritySession(); 354 355 GroupDO group = createTestGroup(defaultGroup.getParent(), 0); 357 group.setDescription("new test description"); 358 group.setName("new name"); 359 String id = group.getId(); 360 group = addressBook.amendGroup(securitySession, group); 361 assertEquals(id, group.getId()); 362 group = addressBook.findGroupByPrimaryKey(securitySession, id); 363 assertEquals("new test description", group.getDescription()); 364 assertEquals("new name", group.getName()); 365 366 Set people = new HashSet (); 367 PersonDO person0 = createTestPerson(0); 368 people.add(person0); 369 group.setHead(person0); 370 group.setPeople(people); 371 group = addressBook.amendGroup(securitySession, group); 372 group = addressBook.findGroupByPrimaryKey(securitySession, id); 373 assertEquals(person0, group.getHead()); 374 assertTrue(group.getPeople().size() == 1); 375 assertTrue(group.getPeople().contains(person0)); 376 377 } 379 380 public void testAmendPerson() throws SystemException { 381 SecuritySession securitySession = getSecuritySession(); 382 HibernateManager hibernateManager = getHibernateManager(); 383 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 384 try { 385 PersonDO person = createTestPerson(0); 387 388 person.setCompany("new company"); 390 person.setFileAs("another file as"); 391 person.setFirstNames("new first names"); 392 person.setJobTitle("another title"); 393 person.setLastName("another last name"); 394 person.setSalutation("Mister"); 395 String id = person.getId(); 396 person = addressBook.amendPerson(securitySession, person); 397 assertEquals(id, person.getId()); 398 person = addressBook.findPersonByPrimaryKey(securitySession, id); 399 assertEquals("new company", person.getCompany()); 400 assertEquals("another file as", person.getFileAs()); 401 assertEquals("new first names", person.getFirstNames()); 402 assertEquals("another title", person.getJobTitle()); 403 assertEquals("another last name", person.getLastName()); 404 assertEquals("Mister", person.getSalutation()); 405 406 CountryDO unitedKingdom = (CountryDO) hibernateManager.findInstance(persistenceSession, 408 "addressBookCountryByCode", 409 new Object []{"UK"}); 410 CountryDO slovakia = (CountryDO) hibernateManager.findInstance(persistenceSession, 411 "addressBookCountryByCode", 412 new Object []{"SK"}); 413 414 AddressDO address = new AddressDO(); 416 address.setCountry(slovakia); 417 address.setPostCode("346436"); 418 address.setRegion("Niekeho"); 419 address.setStreetAddress("Sturova 47"); 420 address.setTown("Banska Bystrica"); 421 person.setAddress(address); 422 addressBook.amendPerson(securitySession, person); 423 person = addressBook.findPersonByPrimaryKey(securitySession, id); 424 assertNotNull(person.getAddress()); 425 address = person.getAddress(); 426 assertEquals(slovakia, address.getCountry()); 427 assertEquals("346436", address.getPostCode()); 428 assertEquals("Niekeho", address.getRegion()); 429 assertEquals("Sturova 47", address.getStreetAddress()); 430 assertEquals("Banska Bystrica", address.getTown()); 431 432 Date now = new Date (); 434 person.setDateOfBirth(now); 435 person = addressBook.amendPerson(securitySession, person); 436 person = addressBook.findPersonByPrimaryKey(securitySession, id); 437 assertEquals(now, person.getDateOfBirth()); 438 439 EmployeeDO employee = new EmployeeDO(); 441 employee.setCountry(unitedKingdom); 442 employee.setNumber("pp12344667"); 443 employee.setVacationDays(new Integer (22)); 444 person.setEmployee(employee); 445 person = addressBook.amendPerson(securitySession, person); 446 person = addressBook.findPersonByPrimaryKey(securitySession, id); 447 assertNotNull(person.getEmployee()); 448 assertEquals(employee, person.getEmployee()); 449 assertEquals(unitedKingdom, person.getEmployee().getCountry()); 450 assertEquals("pp12344667", person.getEmployee().getNumber()); 451 assertEquals(new Integer (22), person.getEmployee().getVacationDays()); 452 453 GroupDO newGroup = createTestGroup(defaultGroup, 99); 455 person.setGroup(newGroup); 456 person = addressBook.amendPerson(securitySession, person); 457 person = addressBook.findPersonByPrimaryKey(securitySession, id); 458 assertNotNull(person.getGroup()); 459 assertEquals(newGroup, person.getGroup()); 460 461 Set telecomAddresses = new HashSet (); 464 TelecomAddressDO telecomAddress = new TelecomAddressDO(); 465 telecomAddress.setAddress("(020)12334545"); 466 telecomAddress.setType(TelecomAddressConstants.TYPE_HOME); 467 telecomAddress.setNumber(0); 468 telecomAddresses.add(telecomAddress); 469 telecomAddress = new TelecomAddressDO(); 470 telecomAddress.setAddress("nobody@home.com"); 471 telecomAddress.setType(TelecomAddressConstants.TYPE_EMAIL); 472 telecomAddress.setNumber(1); 473 telecomAddresses.add(telecomAddress); 474 person.setTelecomAddresses(telecomAddresses); 475 person = addressBook.amendPerson(securitySession, person); 476 person = addressBook.findPersonByPrimaryKey(securitySession, id); 477 assertNotNull(person.getTelecomAddresses()); 478 assertTrue(person.getTelecomAddresses().size() == 2); 479 Iterator telecomAddressIterator = person.getTelecomAddresses().iterator(); 480 while (telecomAddressIterator.hasNext()) { 481 telecomAddress = (TelecomAddressDO) telecomAddressIterator.next(); 482 int number = telecomAddress.getNumber(); 483 assertTrue((number >= 0) && (number < 2)); 484 switch (number) { 485 case 0: 486 assertEquals("(020)12334545", telecomAddress.getAddress()); 487 assertTrue(telecomAddress.getType() == TelecomAddressConstants.TYPE_HOME); 488 break; 489 case 1: 490 assertEquals("nobody@home.com", telecomAddress.getAddress()); 491 assertTrue(telecomAddress.getType() == TelecomAddressConstants.TYPE_EMAIL); 492 break; 493 default: 494 assertTrue(false); 496 break; 497 } 498 } 499 500 UserDO user = new UserDO(); 502 user.setDeleted(false); 503 user.setEnabled(true); 504 user.setName("test user"); 505 user.setPassword("test password"); 506 person.setUser(user); 507 person = addressBook.amendPerson(securitySession, person); 508 person = addressBook.findPersonByPrimaryKey(securitySession, id); 509 assertNotNull(person.getUser()); 510 assertFalse(user.isDeleted()); 511 assertTrue(user.isEnabled()); 512 assertEquals("test user", person.getUser().getName()); 513 assertEquals("test password", person.getUser().getPassword()); 514 } catch (Exception e) { 515 persistenceSession.cancel(); 516 throw new SystemException(e); 517 } finally { 518 persistenceSession.close(); 519 } 520 } 521 522 public void testFindAddressBooks() throws SystemException { 523 SecuritySession securitySession = getSecuritySession(); 524 HibernateManager hibernateManager = getHibernateManager(); 525 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 526 527 try { 528 GroupDO privateAddressBook = (GroupDO) 529 hibernateManager.findByPrimaryKey(persistenceSession, 530 GroupDO.class, new Integer (501)); 531 List allAddressBooks = addressBook.findAddressBooks(securitySession, true); 532 assertTrue(allAddressBooks.size() > 0); 533 assertTrue(allAddressBooks.contains(privateAddressBook)); 534 allAddressBooks = addressBook.findAddressBooks(securitySession, false); 535 assertTrue(allAddressBooks.size() > 0); 536 assertFalse(allAddressBooks.contains(privateAddressBook)); 537 } catch (Exception e) { 538 persistenceSession.cancel(); 539 throw new SystemException(e); 540 } finally { 541 persistenceSession.close(); 542 } 543 } 544 545 public void testFindAllCountries() throws SystemException { 546 SecuritySession securitySession = getSecuritySession(); 547 HibernateManager hibernateManager = getHibernateManager(); 548 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 549 550 try { 551 CountryDO germany = (CountryDO) hibernateManager.findInstance(persistenceSession, 552 "addressBookCountryByCode", 553 new Object []{"DE"}); 554 CountryDO slovakia = (CountryDO) hibernateManager.findInstance(persistenceSession, 555 "addressBookCountryByCode", 556 new Object []{"SK"}); 557 CountryDO unitedKingdom = (CountryDO) hibernateManager.findInstance(persistenceSession, 558 "addressBookCountryByCode", 559 new Object []{"UK"}); 560 561 List allCountries = addressBook.findAllCountries(securitySession); 562 assertTrue(allCountries.size() > 0); 563 assertTrue(allCountries.contains(germany)); 564 assertTrue(allCountries.contains(slovakia)); 565 assertTrue(allCountries.contains(unitedKingdom)); 566 } catch (Exception e) { 567 persistenceSession.cancel(); 568 throw new SystemException(e); 569 } finally { 570 persistenceSession.close(); 571 } 572 } 573 574 public void testFindAllPeopleInGroup() throws SystemException { 575 SecuritySession securitySession = getSecuritySession(); 576 PersonDO adminPerson = addressBook.findPersonByUserName(securitySession, 577 securitySession.getUser().getName()); 578 579 List allPeople = addressBook.findAllPeopleInGroup(securitySession, defaultGroup, null); 580 assertTrue(allPeople.size() > 0); 581 assertTrue(allPeople.contains(adminPerson)); 582 583 allPeople = addressBook.findAllPeopleInGroup(securitySession, defaultGroup, "a"); 584 assertTrue(allPeople.size() > 0); 585 assertTrue(allPeople.contains(adminPerson)); 586 } 587 588 public void testFindCountryByCode() throws SystemException { 589 SecuritySession securitySession = getSecuritySession(); 590 HibernateManager hibernateManager = getHibernateManager(); 591 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 592 try { 593 CountryDO germany = (CountryDO) hibernateManager.findInstance(persistenceSession, 594 "addressBookCountryByCode", 595 new Object []{"DE"}); 596 CountryDO slovakia = (CountryDO) hibernateManager.findInstance(persistenceSession, 597 "addressBookCountryByCode", 598 new Object []{"SK"}); 599 CountryDO unitedKingdom = (CountryDO) hibernateManager.findInstance(persistenceSession, 600 "addressBookCountryByCode", 601 new Object []{"UK"}); 602 603 CountryDO germanyCheck = addressBook.findCountryByCode(securitySession, "DE"); 604 assertNotNull(germanyCheck); 605 assertEquals(germany, germanyCheck); 606 assertEquals("country.DE", germanyCheck.getName()); 607 CountryDO slovakiaCheck = addressBook.findCountryByCode(securitySession, "SK"); 608 assertNotNull(slovakiaCheck); 609 assertEquals(slovakia, slovakiaCheck); 610 assertEquals("country.SK", slovakiaCheck.getName()); 611 CountryDO unitedKingdomCheck = addressBook.findCountryByCode(securitySession, "UK"); 612 assertNotNull(unitedKingdomCheck); 613 assertEquals(unitedKingdom, unitedKingdomCheck); 614 assertEquals("country.UK", unitedKingdomCheck.getName()); 615 } catch (Exception e) { 616 persistenceSession.cancel(); 617 throw new SystemException(e); 618 } finally { 619 persistenceSession.close(); 620 } 621 } 622 623 public void testFindGroupByPrimaryKey() throws SystemException { 624 SecuritySession securitySession = getSecuritySession(); 625 GroupDO checkGroup = addressBook.findGroupByPrimaryKey(securitySession, defaultGroup.getId()); 626 assertEquals(defaultGroup, checkGroup); 627 } 628 629 public void testFindGroupsByParent() throws SystemException { 630 SecuritySession securitySession = getSecuritySession(); 631 List children = addressBook.findGroupsByParent(securitySession, defaultGroup.getParent().getId()); 632 assertTrue(children.size() > 0); 633 assertTrue(children.contains(defaultGroup)); 634 } 635 636 public void testFindPersonalAddressBook() throws SystemException { 637 SecuritySession securitySession = getSecuritySession(); 638 HibernateManager hibernateManager = getHibernateManager(); 639 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 640 try { 641 GroupDO privateAddressBook = (GroupDO) 642 hibernateManager.findByPrimaryKey(persistenceSession, 643 GroupDO.class, new Integer (501)); 644 GroupDO checkAddressBook = addressBook.findPersonalAddressBook(securitySession); 645 assertEquals(privateAddressBook, checkAddressBook); 646 } catch (Exception e) { 647 persistenceSession.cancel(); 648 throw new SystemException(e); 649 } finally { 650 persistenceSession.close(); 651 } 652 } 653 654 public void testFindPersonByPrimaryKey() throws SystemException { 655 SecuritySession securitySession = getSecuritySession(); 656 PersonDO userPerson = addressBook.findPersonByUserName(securitySession, 657 securitySession.getUser().getName()); 658 PersonDO checkPerson = addressBook.findPersonByPrimaryKey(securitySession, 659 userPerson.getId()); 660 assertEquals(userPerson, checkPerson); 661 } 662 663 public void testFindUserGroups() throws SystemException { 664 SecuritySession securitySession = getSecuritySession(); 665 HibernateManager hibernateManager = getHibernateManager(); 666 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 667 try { 668 List userGroups = addressBook.findUserGroups(securitySession, true); 669 670 GroupDO privateUserGroup = (GroupDO) 672 hibernateManager.findByPrimaryKey(persistenceSession, 673 GroupDO.class, new Integer (500)); 674 assertTrue(userGroups.size() > 0); 675 userGroups.add(privateUserGroup); 676 assertTrue(userGroups.containsAll(securitySession.getUser().getGroups())); 677 } catch (Exception e) { 678 persistenceSession.cancel(); 679 throw new SystemException(e); 680 } finally { 681 persistenceSession.close(); 682 } 683 } 684 685 688 public void testValidateSecuritySessionAddressDO() throws SystemException { 689 SecuritySession securitySession = getSecuritySession(); 690 HibernateManager hibernateManager = getHibernateManager(); 691 PersistenceSession persistenceSession = hibernateManager.openSession(securitySession); 692 try { 693 AddressDO testAddress = new AddressDO(); 694 ValidationErrors validationErrors = addressBook.validate(securitySession, 695 testAddress); 696 assertNotNull(validationErrors); 697 assertFalse(validationErrors.isEmpty()); 698 699 710 711 CountryDO germany = (CountryDO) hibernateManager.findInstance(persistenceSession, 712 "addressBookCountryByCode", 713 new Object []{"DE"}); 714 testAddress.setCountry(germany); 715 testAddress.setStreetAddress("nothing"); 716 testAddress.setTown("test"); 717 718 validationErrors = addressBook.validate(securitySession, 719 testAddress); 720 assertTrue((validationErrors == null) || validationErrors.isEmpty()); 721 } catch (Exception e) { 722 persistenceSession.cancel(); 723 throw new SystemException(e); 724 } finally { 725 persistenceSession.close(); 726 } 727 } 728 729 732 public void testValidateSecuritySessionGroupDO() throws SystemException { 733 SecuritySession securitySession = getSecuritySession(); 734 735 GroupDO testGroup = new GroupDO(); 736 ValidationErrors validationErrors = addressBook.validate(securitySession, 737 testGroup); 738 assertNotNull(validationErrors); 739 assertFalse(validationErrors.isEmpty()); 740 741 746 747 testGroup.setName("test"); 748 validationErrors = addressBook.validate(securitySession, 749 testGroup); 750 assertTrue((validationErrors == null) || validationErrors.isEmpty()); 751 } 752 753 756 public void testValidateSecuritySessionPersonDO() { 757 SecuritySession securitySession = getSecuritySession(); 758 759 PersonDO testPerson = new PersonDO(); 760 testPerson.setUser(new UserDO()); 762 ValidationErrors validationErrors = addressBook.validate(securitySession, 763 testPerson); 764 assertNotNull(validationErrors); 765 assertFalse(validationErrors.isEmpty()); 766 767 788 789 790 testPerson.setFileAs("test"); 791 testPerson.setFirstNames("test"); 792 testPerson.setLastName("test"); 793 testPerson.setGroup(defaultGroup); 794 testPerson.getUser().setName("test"); 795 Set telecomAddresses = new HashSet (); 796 TelecomAddressDO emailAddress = new TelecomAddressDO(); 797 emailAddress.setAddress("test@test.com"); 798 emailAddress.setType(TelecomAddressConstants.TYPE_EMAIL); 799 telecomAddresses.add(emailAddress); 800 testPerson.setTelecomAddresses(telecomAddresses); 801 802 validationErrors = addressBook.validate(securitySession, 803 testPerson); 804 assertTrue((validationErrors == null) || validationErrors.isEmpty()); 805 } 806 807 } 808 | Popular Tags |