List of usage examples for org.springframework.ui Model asMap
Map<String, Object> asMap();
From source file:org.kew.rmf.matchconf.web.CustomReporterController.java
@RequestMapping(value = "/{configType}_configs/{configName}/reporters", method = RequestMethod.PUT, produces = "text/html") public String update(@PathVariable("configType") String configType, @PathVariable("configName") String configName, @Valid Reporter reporter, BindingResult bindingResult, Model uiModel, HttpServletRequest httpServletRequest) { this.customValidation(configName, reporter, bindingResult); if (bindingResult.hasErrors()) { populateEditForm(uiModel, configType, configName, reporter); return String.format("%s_config_reporters/update", configType); }// w w w . j a v a2 s . co m uiModel.asMap().clear(); reporter.setConfig(Configuration.findConfigurationsByNameEquals(configName).getSingleResult()); reporter.merge(); return String.format("redirect:/%s_configs/", configType) + encodeUrlPathSegment(configName, httpServletRequest) + "/reporters/" + encodeUrlPathSegment(reporter.getName(), httpServletRequest); }
From source file:com.comcast.video.dawg.controller.park.ParkControllerTest.java
@SuppressWarnings("unchecked") @Test(dataProvider = "testUserFrontWithValidTokenData") public void testUserFrontWithValidToken(String token, String tag, String q, String[] sort, String[] otherTagsExp) {// w w w .j av a 2 s . c om ParkController controller = new ParkController(); Map<String, Object>[] filteredStbs = new HashMap[1]; Map<String, Object>[] allStbs = new HashMap[2]; Map<String, Object> stb1 = new HashMap<String, Object>(); stb1.put(MetaStb.ID, "sample"); stb1.put(MetaStb.TAGS, Arrays.asList("tag1")); stb1.put(MetaStb.MACADDRESS, "00:00:00:00:00"); Map<String, Object> stb2 = new HashMap<String, Object>(); stb2.put(MetaStb.ID, "otherDevice"); stb2.put(MetaStb.TAGS, Arrays.asList("tag2", "tag3")); stb2.put(MetaStb.MACADDRESS, "00:00:00:00:01"); filteredStbs[0] = stb1; allStbs[0] = stb1; allStbs[1] = stb2; ReflectionTestUtils.setField(controller, "serverUtils", utils); ParkService mockService = EasyMock.createMock(ParkService.class); if (q == null) { EasyMock.expect(mockService.findAll((Pageable) EasyMock.anyObject())).andReturn(allStbs); } else { EasyMock.expect( mockService.findByKeys((String[]) EasyMock.anyObject(), (Pageable) EasyMock.anyObject())) .andReturn(filteredStbs); EasyMock.expect(mockService.findAll()).andReturn(allStbs); } if (tag != null) { EasyMock.expect( mockService.findByCriteria((Criteria) EasyMock.anyObject(), (Pageable) EasyMock.anyObject())) .andReturn(filteredStbs); } EasyMock.replay(mockService); ReflectionTestUtils.setField(controller, "service", mockService); ReflectionTestUtils.setField(controller, "config", createConfig()); Integer page = Integer.valueOf(1); Integer size = Integer.valueOf(1); Boolean asc = Boolean.TRUE; try { Model model = new BindingAwareModelMap(); MockHttpSession session = new MockHttpSession(); Assert.assertEquals("index", controller.userFront(token, tag, q, page, size, asc, sort, model, session)); Assert.assertEquals(model.asMap().get("search"), q == null ? "" : q); String otherTagsJson = (String) model.asMap().get("otherTags"); String deviceTagsJson = (String) model.asMap().get("deviceTags"); JsonCerealEngine engine = new JsonCerealEngine(); List<String> otherTags = engine.readFromString(otherTagsJson, List.class); Map<String, List<String>> deviceTags = engine.readFromString(deviceTagsJson, Map.class); Assert.assertEquals(otherTags.size(), otherTagsExp.length); for (String tags : otherTagsExp) { Assert.assertTrue(otherTags.contains(tags)); } Assert.assertEquals(deviceTags.size(), q != null ? 1 : 2); Assert.assertTrue(deviceTags.containsKey("sample")); Assert.assertTrue(deviceTags.get("sample").contains("tag1")); } catch (CerealException e) { Assert.fail(e.getMessage()); } }
From source file:com.google.code.trapo.controller.ForumControllerTests.java
@Test public void should_put_a_message_in_model_when_trying_edit_a_forum_that_not_exists() { Model model = model(); ForumsController controller = controllerForNonExistentForum(); controller.edit("to edit", model); Message message = (Message) model.asMap().get("message"); assertThat(message.getText(), equalTo("Forum to edit was not found.")); }
From source file:com.google.code.trapo.controller.ForumControllerTests.java
@Test public void should_redirect_to_list_with_message_when_trying_to_delete_a_non_existent_forum() { ForumRepository repository = repository(); when(repository.get("1234")).thenReturn(null); ForumsController controller = controllerWith(repository); Model model = model(); String result = controller.delete("1234", model); assertThat(result, equalTo("forums/list")); Message message = (Message) model.asMap().get("message"); assertThat(message.isWarning(), is(true)); }
From source file:com.google.code.trapo.controller.ForumControllerTests.java
@Test public void should_delete_a_existent_forum() { ForumRepository repository = repository(); when(repository.get("1234")).thenReturn(forum()); ForumsController controller = controllerWith(repository); Model model = model(); String result = controller.delete("1234", model); assertThat(result, equalTo("forums/list")); Message message = (Message) model.asMap().get("message"); assertThat(message.isInformation(), is(true)); }
From source file:net.triptech.buildulator.web.AdminController.java
@RequestMapping(method = RequestMethod.PUT) @PreAuthorize("hasRole('ROLE_ADMIN')") public String update(@Valid Preferences preferences, BindingResult bindingResult, Model uiModel, HttpServletRequest request) {/*from w w w . j a v a 2 s.co m*/ if (bindingResult.hasErrors()) { uiModel.addAttribute("preferences", preferences); FlashScope.appendMessage(getMessage("buildulator_object_validation", Preferences.class), request); return "admin/update"; } uiModel.asMap().clear(); if (preferences.getId() != null) { // Updating existing preferences preferences.merge(); } else { // No preferences exist yet preferences.persist(); preferences.flush(); } request.getSession().getServletContext().setAttribute("Preferences", preferences); FlashScope.appendMessage(getMessage("preferences_edited"), request); return "redirect:/admin"; }
From source file:com.google.code.trapo.controller.ForumControllerTests.java
@Test public void should_warning_the_user_when_trying_to_show_a_forum_that_not_exists() { ForumRepository repository = repository(); when(repository.byName("non existent forum")).thenReturn(null); Model model = model(); ForumsController controller = controllerWith(repository); controller.show("non existent forum", model); Message message = (Message) model.asMap().get("message"); assertThat(message.isWarning(), is(true)); }
From source file:no.dusken.barweb.plugin.liquidityplugin.control.admin.TestAdminController.java
@Test public void voidTestUpdate() { when(pluginStoreProvider.getString("valuesinbar", "0")).thenReturn("50"); when(pluginStoreProvider.getString("valuesinbank", "0")).thenReturn("50"); when(barPersonService.getSumPersonBalances((Gjeng) anyObject())).thenReturn(100l); Model model = new ExtendedModelMap(); String view = controller.update(50 + "", 50 + "", model); assertEquals("Wrong view", "no/dusken/barweb/plugin/liquidityplugin/admin/status", view); verify(pluginStoreProvider, times(1)).setString("valuesinbar", "50"); verify(pluginStoreProvider, times(1)).setString("valuesinbank", "50"); // bankbalance - summed balance assertEquals("wrong value", model.asMap().get("sum"), 0l); assertEquals("wrong value", model.asMap().get("valuesinbar"), 50); assertEquals("wrong value", model.asMap().get("valuesinbank"), 50); assertEquals("wrong value", model.asMap().get("sumPersonBalance"), 100l); }
From source file:com.utbm.formation.controller.ListCourseSessionController.java
/** * Retourne la liste des sessions avec leur location et le nom du cours * @param model contient la listes des sessions * @return la listes des sessions/*from w w w . j a v a 2 s. c o m*/ */ @RequestMapping(value = "", method = GET) public ModelAndView listCourse(Model model) { Iterable<Course_session> listSession = courseSessionService.getAllCoursesSession(); Iterable<Course> listCourse = courseService.getAllCourses(); Iterable<Location_course> listLocation = locationService.getAllLocation(); model.addAttribute("listCourse", listCourse); model.addAttribute("listLocation", listLocation); model.addAttribute("listCourseSession", listSession); return new ModelAndView("listCourse", model.asMap()); }
From source file:org.fenixedu.qubdocs.ui.documentpurposetypes.DocumentPurposeTypeInstanceController.java
private DocumentPurposeTypeInstance getDocumentPurposeTypeInstance(Model model) { return (DocumentPurposeTypeInstance) model.asMap().get("documentPurposeTypeInstance"); }