Package org.springframework.ui

Examples of org.springframework.ui.Model


    @Test
    public void doAddWidget_invalid() {
        final WidgetImpl widget = new WidgetImpl();
        widget.setTitle("Not enough data");
        final Model model = new ExtendedModelMap();
        final BindingResult errors = new BeanPropertyBindingResult(widget, "widget");
        String view = controller.viewAddWidgetResult(widget, errors, model,REFERRER_ID);
        assertTrue("Invalid widget data", errors.hasErrors());
        assertEquals(ViewNames.ADD_WIDGET_FORM, view);
        assertEquals(widget, model.asMap().get(ModelKeys.WIDGET));
    }
View Full Code Here


    public void getCategories_valid(){
        List<Category> categories = new ArrayList<Category>();
        expect(categoryService.getAll()).andReturn(categories);
        replay(categoryService);

        Model model = new ExtendedModelMap();

        String viewName = controller.getCategories("",REFERRER_ID, model);
        verify(categoryService);

        assertEquals(ViewNames.ADMIN_CATEGORIES, viewName);
        assertEquals(categories, model.asMap().get("categories"));
        assertFalse(model.containsAttribute("actionresult"));
        assertTrue(model.containsAttribute("category"));
        assertEquals("Check that the category object available", new CategoryImpl(), model.asMap().get("category"));
        assertTrue(model.containsAttribute("topnav"));
        assertTrue(model.containsAttribute("tabs"));
        assertTrue("verify tokencheck", model.asMap().containsKey(ModelKeys.TOKENCHECK));
        assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID)));
    }
View Full Code Here

    public void getCategory_valid_update() {
        List<Category> categories = new ArrayList<Category>();
        expect(categoryService.getAll()).andReturn(categories);
        replay(categoryService);

        Model model = new ExtendedModelMap();

        String viewName = controller.getCategories(UPDATE,REFERRER_ID, model);
        verify(categoryService);

        assertEquals(ViewNames.ADMIN_CATEGORIES, viewName);
        assertEquals(categories, model.asMap().get("categories"));
        assertTrue(model.containsAttribute("actionresult"));
        assertEquals(UPDATE, model.asMap().get("actionresult"));
        assertTrue(model.containsAttribute("category"));
        assertEquals("Check that the category object available", new CategoryImpl(), model.asMap().get("category"));
        assertTrue(model.containsAttribute("topnav"));
        assertTrue(model.containsAttribute("tabs"));
        assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID)));
    }
View Full Code Here

    public void getCategory_valid_delete(){
        List<Category> categories = new ArrayList<Category>();
        expect(categoryService.getAll()).andReturn(categories);
        replay(categoryService);

        Model model = new ExtendedModelMap();

        String viewName = controller.getCategories(DELETE,REFERRER_ID, model);
        verify(categoryService);

        assertEquals(ViewNames.ADMIN_CATEGORIES, viewName);
        assertEquals(categories, model.asMap().get("categories"));
        assertTrue(model.containsAttribute("actionresult"));
        assertEquals(DELETE, model.asMap().get("actionresult"));
        assertTrue(model.containsAttribute("category"));
        assertEquals("Check that the category object available", new CategoryImpl(), model.asMap().get("category"));
        assertTrue(model.containsAttribute("topnav"));
        assertTrue(model.containsAttribute("tabs"));
        assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID)));
    }
View Full Code Here

    public void getCategory_valid_create(){
        List<Category> categories = new ArrayList<Category>();
        expect(categoryService.getAll()).andReturn(categories);
        replay(categoryService);

        Model model = new ExtendedModelMap();

        String viewName = controller.getCategories(CREATE,REFERRER_ID, model);
        verify(categoryService);

        assertEquals(ViewNames.ADMIN_CATEGORIES, viewName);
        assertEquals(categories, model.asMap().get("categories"));
        assertTrue(model.containsAttribute("actionresult"));
        assertEquals(CREATE, model.asMap().get("actionresult"));
        assertTrue(model.containsAttribute("category"));
        assertEquals("Check category object available", new CategoryImpl(), model.asMap().get("category"));
        assertTrue(model.containsAttribute("topnav"));
        assertTrue(model.containsAttribute("tabs"));
        assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID)));
    }
View Full Code Here

        assertThat((String) model.asMap().get(ModelKeys.REFERRING_PAGE_ID), is(equalTo(REFERRER_ID)));
    }

    @Test
    public void createCategory_valid(){
        Model model = new ExtendedModelMap();
        User user = new UserImpl();
        String categoryText = "Social";
        CategoryImpl category = new CategoryImpl();
        category.setText(categoryText);
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        expect(userService.getAuthenticatedUser()).andReturn(user).once();
        expect(categoryService.create(categoryText, user)).andReturn(new CategoryImpl());
        sessionStatus.setComplete();
        expectLastCall();
        replay(userService, categoryService,sessionStatus);
        String view = controller.createCategory(category, validToken, validToken,REFERRER_ID, model, sessionStatus);
        assertEquals("ViewName match", "redirect:/app/admin/categories?action=create&referringPageId=" +REFERRER_ID, view);
        assertTrue("empty model", model.asMap().isEmpty());
        verify(userService, categoryService, sessionStatus);
    }
View Full Code Here

        verify(userService, categoryService, sessionStatus);
    }

    @Test(expected = SecurityException.class)
    public void createCategory_invalidToken(){
        Model model = new ExtendedModelMap();
        String invalidToken =  AdminControllerUtil.generateSessionToken();
        User user = new UserImpl();
        String categoryText = "Social";
        CategoryImpl category = new CategoryImpl();
        category.setText(categoryText);
View Full Code Here

        assertTrue("Test should catch exception and never hit this test", false);
    }

    @Test
    public void createCategory_invalidValidRequest_emptyText(){
        Model model = new ExtendedModelMap();
        User user = new UserImpl();
        String categoryText = "";
        CategoryImpl category = new CategoryImpl();
        category.setText(categoryText);
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        expect(userService.getAuthenticatedUser()).andReturn(user).once();
        replay(userService);
        String view = controller.createCategory(category, validToken, validToken,REFERRER_ID, model, sessionStatus);
        assertEquals("ViewName match", ViewNames.ADMIN_CATEGORIES, view);
        assertFalse("empty model", model.asMap().isEmpty());
        verify(userService);
    }
View Full Code Here

        verify(userService);
    }

    @Test
    public void updateCategory_valid(){
        Model model = new ExtendedModelMap();
        User user = new UserImpl();
        String id = "1";
        String categoryText = "Social";
        CategoryImpl category = new CategoryImpl(id);
        category.setCreatedUserId(user.getId());
        category.setText(categoryText);
        SessionStatus sessionStatus = createMock(SessionStatus.class);
        expect(userService.getAuthenticatedUser()).andReturn(user).once();
        expect(categoryService.get(id)).andReturn(category);
        expect(categoryService.update(id, categoryText, user)).andReturn(category);
        sessionStatus.setComplete();
        expectLastCall();
        replay(userService, categoryService,sessionStatus);
        String view = controller.updateCategory(category, validToken, validToken,REFERRER_ID, model, sessionStatus);
        assertEquals("ViewName match", "redirect:/app/admin/categories?action=update&referringPageId=" + REFERRER_ID, view);
        assertTrue("empty model", model.asMap().isEmpty());
        verify(userService, categoryService, sessionStatus);
    }
View Full Code Here

        verify(userService, categoryService, sessionStatus);
    }

    @Test(expected = SecurityException.class)
    public void updateCategory_invalidToken(){
        Model model = new ExtendedModelMap();
        User user = new UserImpl();
        String id = "1";
        String categoryText = "Social";
        String invalidToken = AdminControllerUtil.generateSessionToken();
        CategoryImpl category = new CategoryImpl();
View Full Code Here

TOP

Related Classes of org.springframework.ui.Model

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.