Package org.springframework.ui

Examples of org.springframework.ui.ModelMap


        verify(service, sessionStatus);
    }
   
    @Test(expected = SecurityException.class)
    public void testUpdatePreferences_invalidToken() {
        ModelMap model = new ExtendedModelMap();
        String invalidToken = AdminControllerUtil.generateSessionToken();
        PortalPreferenceForm form = new PortalPreferenceForm(new HashMap<String, PortalPreference>());
        final BindingResult errors = new BeanPropertyBindingResult(form, "form");
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        sessionStatus.setComplete();
View Full Code Here


        verify(service, sessionStatus);
    }

    @Test
    public void testUpdatePreferences_invalidPageSizeValue() {
        ModelMap model = new ExtendedModelMap();
        HashMap<String, PortalPreference> preferenceMap = new HashMap<String, PortalPreference>();
        PortalPreference pageSizePref = new PortalPreferenceImpl(PortalPreferenceKeys.PAGE_SIZE, "invalid");
        preferenceMap.put(PortalPreferenceKeys.PAGE_SIZE, pageSizePref);
        PortalPreferenceForm form = new PortalPreferenceForm(preferenceMap);
        final BindingResult errors = new BeanPropertyBindingResult(form, "form");
        SessionStatus sessionStatus = createMock(SessionStatus.class);

        replay(service, sessionStatus);
        String view = controller.updatePreferences(form, errors, validToken, validToken,REFERRER_ID, model, sessionStatus);

        assertEquals(ViewNames.ADMIN_PREFERENCE_DETAIL, view);
        assertTrue(errors.hasErrors());
        assertTrue(model.containsAttribute("topnav"));
        assertTrue(model.containsAttribute("tabs"));
        assertFalse("Model has not been cleared", model.isEmpty());

        verify(service, sessionStatus);
    }
View Full Code Here

        widget.setTitle("WidgetImpl 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() {
        WidgetImpl widget = new WidgetImpl();
        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() {
        WidgetImpl widget = new WidgetImpl("123", "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,REFERRER_ID, modelMap, sessionStatus);

        assertTrue("Errors", errors.hasErrors());
        assertEquals(ViewNames.ADMIN_WIDGETDETAIL, view);
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);
        List<Person> personObjects = new ArrayList<Person>();

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

    replay(userService, pageService);

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

    //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
  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, response);

    //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
    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 viewProfile_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 String referringPageId = "1";
        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

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.