List of usage examples for org.springframework.ui ExtendedModelMap containsAttribute
public boolean containsAttribute(String attributeName)
From source file:org.ngrinder.operation.SystemConfigControllerTest.java
@Test public void testGetSystemConfiguration() { ExtendedModelMap model = new ExtendedModelMap(); controller.getOne(model);/* w w w .j av a 2s. com*/ assertThat(model.containsAttribute("content"), is(true)); }
From source file:com.mtt.myapp.operation.SystemConfigControllerTest.java
@Test public void testGetSystemConfiguration() { ExtendedModelMap model = new ExtendedModelMap(); controller.getOne(model);/* ww w. j a v a 2 s . c o m*/ assertThat(model.containsAttribute("content")).isTrue(); }
From source file:com.github.carlomicieli.nerdmovies.controllers.MovieControllerTests.java
@Test public void newInitializeTheModel() { ExtendedModelMap model = new ExtendedModelMap(); movieController.newMovie(model);//from w ww. ja va 2s .co m assertTrue("Model doesn't contain the movie", model.containsAttribute("movie")); assertTrue("The model is not a movie", model.get("movie") instanceof Movie); }
From source file:com.github.carlomicieli.nerdmovies.controllers.MovieControllerTests.java
@Test public void actionEditFillTheModel() { ExtendedModelMap model = new ExtendedModelMap(); String slug = "movie-slug"; Movie movie = new Movie(); when(mockService.findBySlug(slug)).thenReturn(movie); movieController.edit(slug, model);/*from ww w . j a v a 2 s . c o m*/ assertTrue("The model doesn't contain the movie that failed the validation", model.containsAttribute("movie")); assertTrue("The model doesn't contain a movie", model.get("movie") instanceof Movie); verify(mockService, times(1)).findBySlug(eq(slug)); }
From source file:com.github.carlomicieli.nerdmovies.controllers.MovieControllerTests.java
@Test public void listPaginateTheResults() { List<Movie> movies = new ArrayList<Movie>(); PaginatedResult<Movie> results = new PaginatedResult<Movie>(movies, 100, 10); ExtendedModelMap model = new ExtendedModelMap(); when(mockService.getAllMovies(eq(1), eq(10))).thenReturn(results); String viewName = movieController.list(1, 10, model); assertEquals("movie/list", viewName); verify(mockService).getAllMovies(1, 10); assertTrue("Model doesn't contain the movies", model.containsAttribute("results")); assertSame(results, model.get("results")); }
From source file:com.github.carlomicieli.nerdmovies.controllers.MovieControllerTests.java
@Test public void saveRedirectAfterValidationError() throws IOException { Movie movie = new Movie(); ExtendedModelMap model = new ExtendedModelMap(); when(mockResult.hasErrors()).thenReturn(true); when(mockFile.isEmpty()).thenReturn(true); String viewName = movieController.save(movie, mockFile, mockResult, model); assertEquals("movie/new", viewName); assertTrue("The model doesn't contain the movie that failed the validation", model.containsAttribute("movie")); assertTrue("The model doesn't contain a movie", model.get("movie") instanceof Movie); verify(mockService, times(0)).save(eq(movie)); }
From source file:org.springframework.data.document.web.bind.annotation.support.HandlerMethodInvoker.java
public final Object invokeHandlerMethod(Method handlerMethod, Object handler, NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception { Method handlerMethodToInvoke = BridgeMethodResolver.findBridgedMethod(handlerMethod); try {// w w w.j a va 2s. c o m boolean debug = logger.isDebugEnabled(); for (String attrName : this.methodResolver.getActualSessionAttributeNames()) { Object attrValue = this.sessionAttributeStore.retrieveAttribute(webRequest, attrName); if (attrValue != null) { implicitModel.addAttribute(attrName, attrValue); } } for (Method attributeMethod : this.methodResolver.getModelAttributeMethods()) { Method attributeMethodToInvoke = BridgeMethodResolver.findBridgedMethod(attributeMethod); Object[] args = resolveHandlerArguments(attributeMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking model attribute method: " + attributeMethodToInvoke); } String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value(); if (!"".equals(attrName) && implicitModel.containsAttribute(attrName)) { continue; } ReflectionUtils.makeAccessible(attributeMethodToInvoke); Object attrValue = attributeMethodToInvoke.invoke(handler, args); if ("".equals(attrName)) { Class resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass()); attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue); } if (!implicitModel.containsAttribute(attrName)) { implicitModel.addAttribute(attrName, attrValue); } } Object[] args = resolveHandlerArguments(handlerMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking request handler method: " + handlerMethodToInvoke); } ReflectionUtils.makeAccessible(handlerMethodToInvoke); return handlerMethodToInvoke.invoke(handler, args); } catch (IllegalStateException ex) { // Internal assertion failed (e.g. invalid signature): // throw exception with full handler method context... throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex); } catch (InvocationTargetException ex) { // User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception... ReflectionUtils.rethrowException(ex.getTargetException()); return null; } }
From source file:org.springframework.web.bind.annotation.support.HandlerMethodInvoker.java
public final Object invokeHandlerMethod(Method handlerMethod, Object handler, NativeWebRequest webRequest, ExtendedModelMap implicitModel) throws Exception { Method handlerMethodToInvoke = BridgeMethodResolver.findBridgedMethod(handlerMethod); try {//w ww.j a va 2s. c om boolean debug = logger.isDebugEnabled(); for (String attrName : this.methodResolver.getActualSessionAttributeNames()) { Object attrValue = this.sessionAttributeStore.retrieveAttribute(webRequest, attrName); if (attrValue != null) { implicitModel.addAttribute(attrName, attrValue); } } for (Method attributeMethod : this.methodResolver.getModelAttributeMethods()) { Method attributeMethodToInvoke = BridgeMethodResolver.findBridgedMethod(attributeMethod); Object[] args = resolveHandlerArguments(attributeMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking model attribute method: " + attributeMethodToInvoke); } String attrName = AnnotationUtils.findAnnotation(attributeMethod, ModelAttribute.class).value(); if (!"".equals(attrName) && implicitModel.containsAttribute(attrName)) { continue; } ReflectionUtils.makeAccessible(attributeMethodToInvoke); Object attrValue = attributeMethodToInvoke.invoke(handler, args); if ("".equals(attrName)) { Class<?> resolvedType = GenericTypeResolver.resolveReturnType(attributeMethodToInvoke, handler.getClass()); attrName = Conventions.getVariableNameForReturnType(attributeMethodToInvoke, resolvedType, attrValue); } if (!implicitModel.containsAttribute(attrName)) { implicitModel.addAttribute(attrName, attrValue); } } Object[] args = resolveHandlerArguments(handlerMethodToInvoke, handler, webRequest, implicitModel); if (debug) { logger.debug("Invoking request handler method: " + handlerMethodToInvoke); } ReflectionUtils.makeAccessible(handlerMethodToInvoke); return handlerMethodToInvoke.invoke(handler, args); } catch (IllegalStateException ex) { // Internal assertion failed (e.g. invalid signature): // throw exception with full handler method context... throw new HandlerMethodInvocationException(handlerMethodToInvoke, ex); } catch (InvocationTargetException ex) { // User-defined @ModelAttribute/@InitBinder/@RequestMapping method threw an exception... ReflectionUtils.rethrowException(ex.getTargetException()); return null; } }