001/*
002 * Copyright 2002-2016 the original author or authors.
003 *
004 * Licensed under the Apache License; Version 2.0 (the "License");
005 * you may not use this file except in compliance with the License.
006 * You may obtain a copy of the License at
007 *
008 *      https://www.apache.org/licenses/LICENSE-2.0
009 *
010 * Unless required by applicable law or agreed to in writing; software
011 * distributed under the License is distributed on an "AS IS" BASIS;
012 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND; either express or implied.
013 * See the License for the specific language governing permissions and
014 * limitations under the License.
015 */
016
017package org.springframework.test.web.servlet;
018
019import org.springframework.mock.web.MockHttpServletRequest;
020import org.springframework.mock.web.MockHttpServletResponse;
021import org.springframework.web.servlet.FlashMap;
022import org.springframework.web.servlet.HandlerExceptionResolver;
023import org.springframework.web.servlet.HandlerInterceptor;
024import org.springframework.web.servlet.ModelAndView;
025
026/**
027 * Provides access to the result of an executed request.
028 *
029 * @author Rossen Stoyanchev
030 * @since 3.2
031 */
032public interface MvcResult {
033
034        /**
035         * Return the performed request.
036         * @return the request, never {@code null}
037         */
038        MockHttpServletRequest getRequest();
039
040        /**
041         * Return the resulting response.
042         * @return the response, never {@code null}
043         */
044        MockHttpServletResponse getResponse();
045
046        /**
047         * Return the executed handler.
048         * @return the handler, possibly {@code null} if none were executed
049         */
050        Object getHandler();
051
052        /**
053         * Return interceptors around the handler.
054         * @return interceptors, or {@code null} if none were selected
055         */
056        HandlerInterceptor[] getInterceptors();
057
058        /**
059         * Return the {@code ModelAndView} prepared by the handler.
060         * @return a {@code ModelAndView}, or {@code null}
061         */
062        ModelAndView getModelAndView();
063
064        /**
065         * Return any exception raised by a handler and successfully resolved
066         * through a {@link HandlerExceptionResolver}.
067         * @return an exception, possibly {@code null}
068         */
069        Exception getResolvedException();
070
071        /**
072         * Return the "output" flash attributes saved during request processing.
073         * @return the {@code FlashMap}, possibly empty
074         */
075        FlashMap getFlashMap();
076
077        /**
078         * Get the result of async execution. This method will wait for the async result
079         * to be set for up to the amount of time configured on the async request,
080         * i.e. {@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
081         * @throws IllegalStateException if the async result was not set
082         */
083        Object getAsyncResult();
084
085        /**
086         * Get the result of async execution. This method will wait for the async result
087         * to be set for up to the specified amount of time.
088         * @param timeToWait how long to wait for the async result to be set, in
089         *      milliseconds; if -1, then the async request timeout value is used,
090         *  i.e.{@link org.springframework.mock.web.MockAsyncContext#getTimeout()}.
091         * @throws IllegalStateException if the async result was not set
092         */
093        Object getAsyncResult(long timeToWait);
094
095}