Examples of ModelMap


Examples of org.springframework.ui.ModelMap

   * @param request current HTTP request
   * @param response current HTTP response
   * @return a ModelAndView to render the response
   */
  public Map vetsHandler(HttpServletRequest request, HttpServletResponse response) {
    return new ModelMap(this.clinic.getVets());
  }
View Full Code Here

Examples of org.springframework.ui.ModelMap

 
  @Test
  public void viewPerson_ShouldAddAttributeForUser() {
    //creating a mock user
    final User user = new User();
    final ModelMap model = new ModelMap();
    final int modelSize = 3;
    final String username="Canonical";
        user.setUsername(username);
        user.setEntityId(USER_ID);
    String userProfile = new String(ModelKeys.USER_PROFILE);
        Page personProfile = new Page();
        PageLayout pageLayout = new PageLayout();
        pageLayout.setCode(VALID_PAGE_LAYOUT_CODE);
        personProfile.setPageLayout(pageLayout);
   
    expect(userService.getUserByUsername(username)).andReturn(user).once();
        expect(pageService.getPersonProfilePage(user.getEntityId())).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 three
    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

Examples of org.springframework.ui.ModelMap

    @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 Page();
        PageLayout pageLayout = new PageLayout();
        pageLayout.setCode("person_profile");
View Full Code Here

Examples of org.springframework.ui.ModelMap

    }

  @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 User();
        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 User updatedUser = new User();
    //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

Examples of org.springframework.ui.ModelMap

    newAccountController = new NewAccountController(newAccountService, newAccountValidator, captchaService);
  }
 
  @Test
  public void setUpForm_ShouldAddAttributeForNewUser() {
    final ModelMap model = new ModelMap();
    String newUser = 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 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

Examples of org.springframework.ui.ModelMap


    @Test
    public void testInitialize() throws Exception {
        // test is model is added:
        final ModelMap model = new ModelMap();
        controller.initialize(model, request);
        assertThat(model, CoreMatchers.notNullValue());
        // captcha & user mode should be
        assertEquals("Expected Captcha and NewUser model", 2, model.size());
        assertThat(model.containsAttribute(ModelKeys.NEW_USER), CoreMatchers.equalTo(true));
        assertThat(model.containsAttribute(ModelKeys.CAPTCHA_HTML), CoreMatchers.equalTo(true));
        assertThat(model.get(ModelKeys.NEW_USER), CoreMatchers.notNullValue());
        assertThat(model.get(ModelKeys.CAPTCHA_HTML), CoreMatchers.notNullValue());
        assertThat(captchaService.isValid(request), CoreMatchers.equalTo(true));

    }
View Full Code Here

Examples of org.springframework.ui.ModelMap

    }

    @Override
    public void postHandle(HttpServletRequest request, HttpServletResponse response, Object handler, ModelAndView modelAndView) throws Exception {
        if (modelAndView != null) {
            ModelMap map = modelAndView.getModelMap();
            map.addAttribute(ModelKeys.PORTAL_SETTINGS, preferenceService.getPreferencesAsMap());
        }
        super.postHandle(request, response, handler, modelAndView);
    }
View Full Code Here

Examples of org.springframework.ui.ModelMap

    @SuppressWarnings("unchecked")
    public void setUp() throws Exception {

        initProvider(new ErrorsProvider());

        ModelMap modelMap = new ModelMap();
        modelMap.put(BindingResult.MODEL_KEY_PREFIX + "test", mock(BindingResult.class));
        when(modelAndView.getModel()).thenReturn(modelMap);
    }
View Full Code Here

Examples of org.springframework.ui.ModelMap

     * <p>Tests the {@link ErrorsProvider#canProvide(Class)} method when the provided resource is null.</p>
     */
    @Test
    public void testCanProvideResourceNull() {

        when(modelAndView.getModel()).thenReturn(new ModelMap());

        assertFalse("The provider incorrectly handles null values.", instance.canProvide(Errors.class));
    }
View Full Code Here

Examples of org.springframework.ui.ModelMap

        widget.setTitle("Widget title");
        widget.setType("OpenSocial");
        widget.setDescription("Lorem ipsum");
        BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        ModelMap modelMap = new ExtendedModelMap();

        expect(service.getWidgetByUrl(widgetUrl)).andReturn(widget);
        service.updateWidget(widget);
        sessionStatus.setComplete();
        expectLastCall();
View Full Code Here
TOP
Copyright © 2018 www.massapi.com. 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.