Ejemplo n.º 1
0
  /**
   * Serve model with signupForm.
   *
   * @param principal the logged in principal.
   * @return a signupForm with filled name and biography fields.
   */
  @ModelAttribute("signupForm")
  public SignupForm getSignupForm(Principal principal) {
    User user = userService.getPrincipalUser();

    SignupForm form = new SignupForm();
    form.setFirstName(user.getFirstName());
    form.setLastName(user.getLastName());
    form.setBiography(user.getBiography());

    try {
      AutoPopulatingList<UserCourseFormAttribute> userCourseList =
          new AutoPopulatingList<UserCourseFormAttribute>(new UserCourseFormAttributeFactory());
      Iterator<UserCourse> itr = userCourseDao.findByUser(user).iterator();
      while (itr.hasNext()) {
        UserCourse tmpUserCourse = itr.next();
        UserCourseFormAttribute formAttr = new UserCourseFormAttribute();
        formAttr.setUniversity(tmpUserCourse.getCourse().getSubject().getUniversity().toString());
        formAttr.setSubject(tmpUserCourse.getCourse().getSubject().toString());
        formAttr.setCourse(tmpUserCourse.getCourse().toString());
        formAttr.setGrade(String.valueOf(tmpUserCourse.getGrade()));
        formAttr.setTeaching(tmpUserCourse.isTeaching());
        userCourseList.add(formAttr);
      }
      form.setUserCourseList(userCourseList);
    } catch (Exception e) {
    }

    try {
      AutoPopulatingList<TimeSlot> timeSlotList =
          new AutoPopulatingList<TimeSlot>(new TimeSlotFactory());
      ListIterator<TimeSlot> iter = user.getTimeSlots().listIterator();
      while (iter.hasNext()) {
        timeSlotList.add(iter.next());
      }
      form.setTimeSlots(timeSlotList);
    } catch (Exception e) {
    }

    return form;
  }
Ejemplo n.º 2
0
  @Test
  public void testTheBasicUserServiceUserSaving() {
    updatedUser = userService.saveFrom(signupForm);
    Iterator<UserRole> roleItr = updatedUser.getUserRole().iterator();

    assertEquals("Capitain", updatedUser.getFirstName());
    assertEquals("Awesome", updatedUser.getLastName());
    assertEquals("*****@*****.**", updatedUser.getEmail());
    assertEquals("I try to be .......... awesome...", updatedUser.getBiography());

    assertTrue(roleItr.hasNext());
    assertEquals("ROLE_USER", roleItr.next().getRole());
    assertFalse(roleItr.hasNext());

    assertTrue(updatedUser.isEnabled());
    assertTrue(passwordEncoder.matches("123456", updatedUser.getPassword()));

    assertEquals(
        expectedTimeSlotArrayList.toString(),
        updatedUser
            .getTimeSlots()
            .toString()); // don't compare references but string representation
  }