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_REQUEST_FAKE_H_
16#define WEBSERVER_LIBWEBSERV_REQUEST_FAKE_H_
17
18#include <map>
19#include <memory>
20#include <string>
21#include <utility>
22#include <vector>
23
24#include <base/callback_forward.h>
25#include <base/files/file.h>
26#include <base/macros.h>
27#include <base/memory/ref_counted.h>
28#include <brillo/errors/error.h>
29#include <brillo/streams/stream.h>
30#include <libwebserv/export.h>
31#include <libwebserv/request.h>
32
33namespace libwebserv {
34
35// Implementation of Request that allows custom data for testing.
36class RequestFake : public Request {
37 public:
38  RequestFake(const std::string& url, const std::string& method)
39    : Request(url, method) {}
40
41  void SetDataStream(brillo::StreamPtr data_stream) {
42    data_stream_ = std::move(data_stream);
43  }
44
45  void SetFormDataPost(std::multimap<std::string, std::string> post_data) {
46    post_data_ = std::move(post_data);
47  }
48
49  void SetFormDataGet(std::multimap<std::string, std::string> get_data) {
50    get_data_ = std::move(get_data);
51  }
52
53  void SetFileInfo(
54      std::multimap<std::string, std::unique_ptr<FileInfo>> file_info) {
55    file_info_ = std::move(file_info);
56  }
57
58  void SetHeaders(std::multimap<std::string, std::string> headers) {
59    headers_ = std::move(headers);
60  }
61
62  // Overrides from Request.
63  brillo::StreamPtr GetDataStream() override { return std::move(data_stream_); }
64
65 private:
66  brillo::StreamPtr data_stream_;
67
68  DISALLOW_COPY_AND_ASSIGN(RequestFake);
69};
70
71}  // namespace libwebserv
72
73#endif  // WEBSERVER_LIBWEBSERV_REQUEST_FAKE_H_
74