1// Copyright 2015 The Android Open Source Project
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//      http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15#ifndef WEBSERVER_LIBWEBSERV_MOCK_RESPONSE_H_
16#define WEBSERVER_LIBWEBSERV_MOCK_RESPONSE_H_
17
18#include <base/macros.h>
19#include <gmock/gmock.h>
20
21#include <libwebserv/response.h>
22
23namespace libwebserv {
24
25// Mock Response implementation for testing.
26class MockResponse : public Response {
27 public:
28  MockResponse() = default;
29
30  MOCK_METHOD2(AddHeader, void(const std::string&, const std::string&));
31  MOCK_METHOD1(AddHeaders,
32               void(const std::vector<std::pair<std::string, std::string>>&));
33
34  // Workaround for mocking with move-only StreamPtr.
35  MOCK_METHOD3(MockReply, void(int, brillo::Stream*, const std::string&));
36
37  MOCK_METHOD3(ReplyWithText,
38               void(int, const std::string&, const std::string&));
39  MOCK_METHOD2(ReplyWithJson, void(int, const base::Value*));
40  MOCK_METHOD2(ReplyWithJson,
41               void(int, const std::map<std::string, std::string>&));
42  MOCK_METHOD2(Redirect, void(int, const std::string&));
43  MOCK_METHOD2(ReplyWithError, void(int, const std::string&));
44  MOCK_METHOD0(ReplyWithErrorNotFound, void());
45
46 private:
47  void Reply(int status_code,
48             brillo::StreamPtr data_stream,
49             const std::string &mime_type) override {
50    return MockReply(status_code, data_stream.get(), mime_type);
51  }
52
53  DISALLOW_COPY_AND_ASSIGN(MockResponse);
54};
55
56}  // namespace libwebserv
57
58#endif  // WEBSERVER_LIBWEBSERV_MOCK_RESPONSE_H_
59