Package org.springframework.ui

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


    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


    @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

    }

    @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

    @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

     * <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

        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

    @Test(expected = SecurityException.class)
    public void updateWidget_wrongToken() {
        Widget widget = new Widget();
        BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        ModelMap modelMap = new ExtendedModelMap();

        sessionStatus.setComplete();
        expectLastCall();
        replay(sessionStatus);
View Full Code Here

    @Test
    public void updateWidget_invalid() {
        Widget widget = new Widget(123L, "http://broken/url");
        BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        ModelMap modelMap = new ExtendedModelMap();

        String view = controller.updateWidgetDetail(widget, errors, validToken, validToken, modelMap, sessionStatus);

        assertTrue("Errors", errors.hasErrors());
        assertEquals(ViewNames.ADMIN_WIDGETDETAIL, view);
View Full Code Here

 
  public ModelAndView listBill(HttpServletRequest request, HttpServletResponse response)throws Exception
 
    long billId;
    billId= Long.parseLong(request.getSession().getAttribute("billId").toString());
    ModelMap modelMap = new ModelMap();
    modelMap.addAttribute("items", salesDAO.getSalesEntries(billId));
    modelMap.addAttribute("bill", new Sales());
    return new ModelAndView("newBill",modelMap);
  }
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.