示例#1
0
 @Test
 public void testDuplicates() {
   makeUser("*****@*****.**");
   DefaultRole role = persistenceService.findById(DefaultRole.class, 1);
   DefaultUser user = new DefaultUser();
   user.setUsername("*****@*****.**");
   user.setEmail("*****@*****.**");
   user.setGuid("test uid");
   user.setPassword("blah blah");
   user.addRole(role);
   try {
     persistenceService.persist(user);
     fail("Should have failed");
   } catch (Exception e) {
     // Expected
   }
 }
示例#2
0
  @Test
  public void testContactInfo() {
    DefaultRole role = persistenceService.findById(DefaultRole.class, 1);
    DefaultUser user = new DefaultUser();
    user.setUsername("*****@*****.**");
    user.setEmail("*****@*****.**");
    user.setGuid("test uid");
    user.setPassword("blah blah");
    user.addRole(role);
    user.setCompanyName("Company");
    user.addEmailAddress(new EmailAddress("*****@*****.**", "home"));
    user.setName(new Name());
    user.getName().setFirstName("Brian");
    user.getName().setLastName("Pontarelli");

    Address address =
        new Address(
            "13275 Elk Mountain Way", "Broomfield", "Colorado", null, "US", "80020", "Home");
    Address workAddress =
        new Address("1600 Pearl St.", "Boulder", "Colorado", null, "US", "80302", "Work");
    user.addAddress(address);
    user.addAddress(workAddress);

    PhoneNumber home = new PhoneNumber("303-954-0394", "Home");
    PhoneNumber cell = new PhoneNumber("720-352-1193", "Cell");
    user.addPhoneNumber(home);
    user.addPhoneNumber(cell);

    persistenceService.persist(user);

    persistenceService.clearCache();

    user =
        persistenceService.queryFirst(
            DefaultUser.class,
            "select u from DefaultUser u where u.username = ?1",
            "*****@*****.**");
    Assert.assertEquals("test uid", user.getGuid());
    Assert.assertEquals("blah blah", user.getPassword());
    Assert.assertEquals(1, user.getRoles().size());
    Assert.assertEquals("user", user.getRoles().iterator().next().getName());
    Assert.assertFalse(user.isDeleted());
    Assert.assertFalse(user.isAdmin());
    Assert.assertFalse(user.isExpired());
    Assert.assertFalse(user.isLocked());
    Assert.assertFalse(user.isPasswordExpired());
    Assert.assertEquals("Company", user.getCompanyName());
    Assert.assertEquals(
        new EmailAddress("*****@*****.**", "home"), user.getEmailAddresses().get("home"));
    Assert.assertEquals("Brian", user.getName().getFirstName());
    Assert.assertEquals("Pontarelli", user.getName().getLastName());
    Assert.assertEquals("Broomfield", user.getAddresses().get("Home").getCity());
    Assert.assertEquals("US", user.getAddresses().get("Home").getCountry());
    Assert.assertEquals("80020", user.getAddresses().get("Home").getPostalCode());
    Assert.assertEquals("Colorado", user.getAddresses().get("Home").getState());
    Assert.assertEquals("13275 Elk Mountain Way", user.getAddresses().get("Home").getStreet());
    Assert.assertEquals("Home", user.getAddresses().get("Home").getType());

    Assert.assertEquals("Boulder", user.getAddresses().get("Work").getCity());
    Assert.assertEquals("US", user.getAddresses().get("Work").getCountry());
    Assert.assertEquals("80302", user.getAddresses().get("Work").getPostalCode());
    Assert.assertEquals("Colorado", user.getAddresses().get("Work").getState());
    Assert.assertEquals("1600 Pearl St.", user.getAddresses().get("Work").getStreet());
    Assert.assertEquals("Work", user.getAddresses().get("Work").getType());

    Assert.assertEquals("303-954-0394", user.getPhoneNumbers().get("Home").getNumber());
    Assert.assertEquals("Home", user.getPhoneNumbers().get("Home").getType());

    Assert.assertEquals("720-352-1193", user.getPhoneNumbers().get("Cell").getNumber());
    Assert.assertEquals("Cell", user.getPhoneNumbers().get("Cell").getType());
  }