Package org.springframework.ui

Examples of org.springframework.ui.ModelMap


 
  @Test
  public void viewPerson_userid() {
    //creating a mock user
    final UserImpl user = new UserImpl();
    final ModelMap model = new ModelMap();
    final int modelSize = 4;
    final String username="canonical";
        user.setUsername(username);
        user.setId(USER_ID);
    String userProfile = new String(ModelKeys.USER_PROFILE);
        Page personProfile = new PageImpl();
        PageLayout pageLayout = new PageLayoutImpl();
        pageLayout.setCode(VALID_PAGE_LAYOUT_CODE);
        personProfile.setPageLayout(pageLayout);
        List<Person> personObjects = new ArrayList<Person>();

    expect(userService.getUserById(USER_ID)).andReturn(user).once();
        expect(pageService.getPersonProfilePage(user.getId())).andReturn(personProfile);
    expect(userService.getFriendRequestsReceived(username)).andReturn(personObjects);

    replay(userService, pageService);

    String view = profileController.viewProfile(USER_ID, model, null);

    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());

    //assert that the model size is four
    assertThat(model.size(), CoreMatchers.equalTo(modelSize));

    //assert that the model does contain an attribute associated with the authenticated user after setUpForm() is called
    assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true));

    //assert that the model does not contain authenticated user as null
    assertThat(model.get(userProfile), CoreMatchers.notNullValue());

        assertThat(view, is(ViewNames.PERSON_PROFILE + "." + VALID_PAGE_LAYOUT_CODE));

    verify(userService, pageService);
  }
View Full Code Here


    @Test(expected = UsernameNotFoundException.class)
    public void viewPersonProfile_invalidUser() {
        //creating a mock user
        final User user = null;
        final ModelMap model = new ModelMap();
        final int modelSize = 4;
        final String username="Canonical";
        Page personProfile = new PageImpl();
        PageLayout pageLayout = new PageLayoutImpl();
        pageLayout.setCode("person_profile");
View Full Code Here

    }

  @Test
  public void updateProfile_ShouldUpdateAuthenticatedUser() {
    //This test will just show the successful updation of user status
    final ModelMap model = new ModelMap();
    final int modelSize = 2;
    final long referringPageId = 1L;
        final String USERNAME = "canonical";
    String userProfile = new String(ModelKeys.USER_PROFILE);

    //creating a mock authenticated user
    final User authUser = new UserImpl();
        authUser.setUsername(USERNAME);
    //set existing status
    authUser.setStatus("Single");
    //set other paramters
    authUser.setGivenName("Test");
    authUser.setFamilyName("Rave");
    authUser.setAboutMe("Test User");
    authUser.setEmail("testuser@rave.com");

    //creating a mock updated user
    final UserForm updatedUser = new UserForm();
    //set the updated status
    updatedUser.setStatus("Married");
    updatedUser.setGivenName("Test");
    updatedUser.setFamilyName("Rave");
    updatedUser.setAboutMe("Test User");
    updatedUser.setEmail("testuser@rave.com");

    expect(userService.getAuthenticatedUser()).andReturn(authUser).anyTimes();
    userService.updateUserProfile(authUser);
    replay(userService);

    String view = profileController.updateProfile(model, referringPageId, updatedUser);

    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());

    //assert that the model size is three
    assertThat(model.size(), CoreMatchers.equalTo(modelSize));

    //assert that the model does contain an attribute associated with the authenticated user
    assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true));

    //assert that the model does not contain authenticated user as null
    assertThat(model.get(userProfile), CoreMatchers.notNullValue());

    //assert that the status of user is updated
    assertEquals(updatedUser.getStatus(), authUser.getStatus());

        assertThat(view, is("redirect:/app/person/" + USERNAME));
View Full Code Here

    newAccountController = new NewAccountController(newAccountService, newAccountValidator, captchaService);
  }

  @Test
  public void setUpForm_ShouldAddAttributeForUser() {
    final ModelMap model = new ModelMap();
    String User = new String(ModelKeys.NEW_USER);
    newAccountController.setUpForm(model, request);

    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());

    //assert that the model size is two
    assertThat(model.size(), CoreMatchers.equalTo(2));

    //assert that the model does contain an attribute associated with User after setUpForm() is called
    assertThat(model.containsAttribute(User), CoreMatchers.equalTo(true));

    //assert that the model does not contain new user as null
    assertThat(model.get(User), CoreMatchers.notNullValue());
  }
View Full Code Here

      HttpServletResponse response, @PathVariable int userId) {
    User user = userService.loginByCookie(request, response);
    logger.debug("user:["+user+"]");
    if(user != null){
      userService.follow(userId, user.getId());
      ModelMap model = new ModelMap();
      model.put("code", "200");
      return new ModelAndView(new MappingJacksonJsonView(), model);
    }
   
    ModelMap model = new ModelMap();
    model.put("code", "302");
    model.put("data", "���ȵ�¼");
    model.put("url", "/user/index");
    return new ModelAndView(new MappingJacksonJsonView(), model);
  }
View Full Code Here

    User user = userService.loginByCookie(request, response);
    logger.debug("user:["+user+"]");
    if(user != null){
      userService.notFollow(userId, user.getId());
      //ModelAndView mav = new ModelAndView("redirect:/user/follow");
      ModelMap model = new ModelMap();
      model.put("code", "200");
      return new ModelAndView(new MappingJacksonJsonView(), model);
    }
   
    ModelMap model = new ModelMap();
    model.put("code", "302");
    model.put("data", "���ȵ�¼");
    model.put("url", "/user/index");
    return new ModelAndView(new MappingJacksonJsonView(), model);
  }
View Full Code Here

    if(user != null){
      message.setUser(user);
      message.setStatus(1);
      messageService.save(message);
      System.out.println("message.getUser().getId():["+message.getUser().getId()+"]");
      ModelMap model = new ModelMap();
      model.put("code", "200");
      return new ModelAndView(new MappingJacksonJsonView(), model);
      //return new ModelAndView("/message/index");
    }
   
    ModelMap model = new ModelMap();
    model.put("code", "302");
    model.put("data", "���ȵ�¼");
    model.put("url", "/user/index");
    return new ModelAndView(new MappingJacksonJsonView(), model);
  }
View Full Code Here

    newAccountController = new NewAccountController(newAccountService, newAccountValidator);
  }
 
  @Test
  public void setUpForm_ShouldAddAttributeForNewUser() {
    final ModelMap model = new ModelMap();
    String newUser = new String(ModelKeys.NEW_USER);
    newAccountController.setUpForm(model);
   
    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());
   
    //assert that the model size is one
    assertThat(model.size(), CoreMatchers.equalTo(1));
   
    //assert that the model does contain an attribute associated with newUser after setUpForm() is called
    assertThat(model.containsAttribute(newUser), CoreMatchers.equalTo(true));
   
    //assert that the model does not contain new user as null
    assertThat(model.get(newUser), CoreMatchers.notNullValue());
  }
View Full Code Here

  @Test
  public void viewPerson_ShouldAddAttributeForUser() {
    //creating a mock user
    final UserImpl user = new UserImpl();
    final ModelMap model = new ModelMap();
    final int modelSize = 4;
    final String username="Canonical";
        user.setUsername(username);
        user.setId(USER_ID);
    String userProfile = new String(ModelKeys.USER_PROFILE);
        Page personProfile = new PageImpl();
        PageLayout pageLayout = new PageLayoutImpl();
        pageLayout.setCode(VALID_PAGE_LAYOUT_CODE);
        personProfile.setPageLayout(pageLayout);

    expect(userService.getUserByUsername(username)).andReturn(user).once();
        expect(pageService.getPersonProfilePage(user.getId())).andReturn(personProfile);

    replay(userService, pageService);

    String view = profileController.viewProfile(username, model, null);

    //assert that the model is not null
    assertThat(model, CoreMatchers.notNullValue());

    //assert that the model size is four
    assertThat(model.size(), CoreMatchers.equalTo(modelSize));

    //assert that the model does contain an attribute associated with the authenticated user after setUpForm() is called
    assertThat(model.containsAttribute(userProfile), CoreMatchers.equalTo(true));

    //assert that the model does not contain authenticated user as null
    assertThat(model.get(userProfile), CoreMatchers.notNullValue());

        assertThat(view, is(ViewNames.PERSON_PROFILE + "." + VALID_PAGE_LAYOUT_CODE));

    verify(userService, pageService);
  }
View Full Code Here

    @Test(expected = UsernameNotFoundException.class)
    public void viewPersonProfile_invalidUser() {
        //creating a mock user
        final User user = null;
        final ModelMap model = new ModelMap();
        final int modelSize = 4;
        final String username="Canonical";
        Page personProfile = new PageImpl();
        PageLayout pageLayout = new PageLayoutImpl();
        pageLayout.setCode("person_profile");
View Full Code Here

TOP

Related Classes of org.springframework.ui.ModelMap

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.