001/*
002 * Copyright 2002-2018 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.lang.Nullable;
020import org.springframework.mock.web.MockHttpServletRequest;
021import org.springframework.mock.web.MockHttpServletResponse;
022import org.springframework.web.servlet.FlashMap;
023import org.springframework.web.servlet.HandlerExceptionResolver;
024import org.springframework.web.servlet.HandlerInterceptor;
025import org.springframework.web.servlet.ModelAndView;
026
027/**
028 * Provides access to the result of an executed request.
029 *
030 * @author Rossen Stoyanchev
031 * @since 3.2
032 */
033public interface MvcResult {
034
035        /**
036         * Return the performed request.
037         * @return the request, never {@code null}
038         */
039        MockHttpServletRequest getRequest();
040
041        /**
042         * Return the resulting response.
043         * @return the response, never {@code null}
044         */
045        MockHttpServletResponse getResponse();
046
047        /**
048         * Return the executed handler.
049         * @return the handler, possibly {@code null} if none were executed
050         */
051        @Nullable
052        Object getHandler();
053
054        /**
055         * Return interceptors around the handler.
056         * @return interceptors, or {@code null} if none were selected
057         */
058        @Nullable
059        HandlerInterceptor[] getInterceptors();
060
061        /**
062         * Return the {@code ModelAndView} prepared by the handler.
063         * @return a {@code ModelAndView}, or {@code null} if none
064         */
065        @Nullable
066        ModelAndView getModelAndView();
067
068        /**
069         * Return any exception raised by a handler and successfully resolved
070         * through a {@link HandlerExceptionResolver}.
071         * @return an exception, or {@code null} if none
072         */
073        @Nullable
074        Exception getResolvedException();
075
076        /**
077         * Return the "output" flash attributes saved during request processing.
078         * @return the {@code FlashMap}, possibly empty
079         */
080        FlashMap getFlashMap();
081
082        /**
083         * Get the result of async execution.
084         * <p>This method will wait for the async result to be set within the
085         * timeout value associated with the async request, see
086         * {@link org.springframework.mock.web.MockAsyncContext#setTimeout
087         * MockAsyncContext#setTimeout}. Alternatively, use
088         * {@link #getAsyncResult(long)} to specify the amount of time to wait.
089         * @throws IllegalStateException if the async result was not set
090         */
091        Object getAsyncResult();
092
093        /**
094         * Get the result of async execution and wait if necessary.
095         * @param timeToWait how long to wait for the async result to be set, in
096         *      milliseconds; if -1, then fall back on the timeout value associated with
097         *      the async request, see
098         *      {@link org.springframework.mock.web.MockAsyncContext#setTimeout
099         *      MockAsyncContext#setTimeout} for more details.
100         * @throws IllegalStateException if the async result was not set
101         */
102        Object getAsyncResult(long timeToWait);
103
104}