List of usage examples for org.springframework.ui ModelMap containsAttribute
public boolean containsAttribute(String attributeName)
From source file:org.jasig.portlet.blackboardvcportlet.mvc.sessionmngr.ManageTelephonyController.java
@RenderMapping(params = "action=configureTelephony") public String manageTelephony(@RequestParam long sessionId, @RequestParam(required = false) String error, RenderRequest request, ModelMap model) { Session session = sessionService.getSession(sessionId); if (!model.containsAttribute("telephonyForm")) { SessionTelephony telephony = sessionService.getSessionTelephony(session); if (null == telephony) { telephony = new TelephonyForm(sessionId); }/*from ww w . j a va 2 s .c o m*/ model.addAttribute("telephonyForm", telephony); } model.addAttribute("session", session); model.addAttribute("error", error); return "configureTelephony"; }
From source file:se.vgregion.portal.patientcontext.ConfigurationControllerTest.java
@Test public void testView() throws Exception { ModelMap model = new ModelMap(); MockPortletPreferences mockPrefs = new MockPortletPreferences(); String result = controller.view(model, mockPrefs); assertTrue(model.containsAttribute("configure")); ConfigurationFormBean formBean = (ConfigurationFormBean) model.get("configure"); assertEquals(formBean.getGroupCode(), PatientEvent.DEFAULT_GROUP_CODE); assertEquals(result, ConfigurationController.EDIT_JSP); }
From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java
@Test public void shouldRenderNewOptionForms() { ModelMap model = new ModelMap(); String viewName = controller.newOption(model); assertEquals("option/new", viewName); assertTrue(model.containsAttribute("newForm")); }
From source file:com.trenako.web.controllers.AuthControllerTests.java
@Test public void shouldRedirectAfterAccountValidationErrors() { when(mockResult.hasErrors()).thenReturn(true); ModelMap model = new ExtendedModelMap(); String viewName = controller.createUser(newAccount(), mockResult, model); assertEquals("auth/signup", viewName); assertTrue(model.containsAttribute("account")); }
From source file:com.trenako.web.controllers.AuthControllerTests.java
@Test public void shouldRedirectAfterDatabaseErrors() { doThrow(new DuplicateKeyException("E11000 duplicate key error index")).when(mockService) .createAccount(eq(newAccount())); when(mockResult.hasErrors()).thenReturn(false); ModelMap model = new ExtendedModelMap(); String viewName = controller.createUser(newAccount(), mockResult, model); assertEquals("auth/signup", viewName); assertTrue(model.containsAttribute("account")); assertTrue(model.containsAttribute("message")); assertEquals(AuthController.EMAIL_ADDRESS_OR_DISPLAY_NAME_ALREADY_TAKEN, model.get("message")); verify(mockService, times(0)).authenticate(eq(newAccount())); }
From source file:ControllersTest.HomeControllerTest.java
@Test public void homeControllerTest() throws Exception { session = new MockHttpSession(); ModelMap modelMap = new ModelMap(); String viewName = controller.showForm(modelMap, session); assertEquals("index", viewName); String theme = session.getAttribute("theme").toString(); assertEquals("bright", theme); assertTrue(modelMap.containsAttribute("tags")); assertTrue(modelMap.containsAttribute("topUsers")); assertTrue(modelMap.containsAttribute("topAds")); }
From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java
@Test public void shouldShowTheOptionsList() { ModelMap model = new ModelMap(); String viewName = controller.list(model); assertEquals("option/list", viewName); assertTrue("Coupler options not found", model.containsAttribute("couplerOptions")); assertTrue("DCC options not found", model.containsAttribute("dccOptions")); assertTrue("Headlight options not found", model.containsAttribute("headlightsOptions")); assertTrue("Transmission options not found", model.containsAttribute("transmissionOptions")); }
From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java
@Test public void shouldRedirectAfterValidationErrorsCreatingNewOptions() { ModelMap model = new ModelMap(); when(bindingResult.hasErrors()).thenReturn(true); String viewName = controller.create(postedForm(), bindingResult, model, redirectAtts); assertEquals("option/new", viewName); assertTrue(model.containsAttribute("newForm")); verify(service, times(0)).save(isA(Option.class)); }
From source file:sample.portlet.TestBooksPortlet.java
public void testBookController() throws Exception { BooksController controller = (BooksController) booksPortletContext.getBean("booksController"); ModelMap model = new ExtendedModelMap(); // ask the controller to handle the request String view = controller.viewBook(Integer.valueOf(1), (Model) model); // show the viewname logger.info("view: " + view); assertEquals("incorrect view", "bookView", view); // show the model includes the book assertTrue("model should contain a book", model.containsAttribute("book")); Book book = (Book) model.get("book"); // check the book's details logger.info("book.author: " + book.getAuthor()); assertEquals("incorrect author", "Neal Stephenson", book.getAuthor()); logger.info("book.title: " + book.getTitle()); assertEquals("incorrect title", "Snow Crash", book.getTitle()); logger.info("book.count: " + book.getCount()); assertEquals("incorrect count", Integer.valueOf(50), book.getCount()); }
From source file:com.trenako.web.controllers.admin.AdminOptionsControllerTests.java
@Test public void shouldRedirectAfterIOExceptionCreatingNewOptions() throws IOException { ModelMap model = new ModelMap(); when(bindingResult.hasErrors()).thenReturn(false); OptionForm mockForm = mock(OptionForm.class); doThrow(new IOException()).when(mockForm).buildOption(); String viewName = controller.create(mockForm, bindingResult, model, redirectAtts); assertEquals("option/new", viewName); assertTrue(model.containsAttribute("newForm")); verify(service, times(0)).save(isA(Option.class)); }