Mantid
Loading...
Searching...
No Matches
ONCatHelper.h
Go to the documentation of this file.
1// Mantid Repository : https://github.com/mantidproject/mantid
2//
3// Copyright © 2018 ISIS Rutherford Appleton Laboratory UKRI,
4// NScD Oak Ridge National Laboratory, European Spallation Source,
5// Institut Laue - Langevin & CSNS, Institute of High Energy Physics, CAS
6// SPDX - License - Identifier: GPL - 3.0 +
7#pragma once
8
9#include "MantidCatalog/ONCat.h"
12
13#include <map>
14#include <memory>
15
16using Mantid::Catalog::OAuth::IOAuthTokenStore;
17using Mantid::Catalog::OAuth::IOAuthTokenStore_uptr;
18using Mantid::Catalog::OAuth::OAuthToken;
19using Mantid::Catalog::ONCat::ONCat;
22
23namespace Mantid {
24namespace FrameworkTestHelpers {
25
26using MockResponseMap = std::map<std::string, std::pair<InternetHelper::HTTPStatus, std::string>>;
27using MockResponseCallCounts = std::map<std::string, unsigned int>;
28using MockResponseCallMapping = std::pair<const std::basic_string<char>, unsigned int>;
29
31public:
32 MockONCatAPI() = delete;
33 MockONCatAPI(const MockResponseMap &responseMap);
35
36 bool allResponsesCalledOnce() const;
37 bool allResponsesCalled() const;
38
39protected:
40 InternetHelper::HTTPStatus sendHTTPRequest(const std::string &url, std::ostream &responseStream) override;
41 InternetHelper::HTTPStatus sendHTTPSRequest(const std::string &url, std::ostream &responseStream) override;
42
43private:
46};
47
48std::shared_ptr<MockONCatAPI> make_mock_oncat_api(const MockResponseMap &responseMap);
49
50std::unique_ptr<ONCat> make_oncat_with_mock_api(const std::shared_ptr<MockONCatAPI> &mockAPI);
51
52class MockTokenStore : public IOAuthTokenStore {
53public:
55
56 void setToken(const boost::optional<OAuthToken> &token) override;
57 boost::optional<OAuthToken> getToken() override;
58
59private:
60 boost::optional<OAuthToken> m_token;
61};
62
63IOAuthTokenStore_uptr make_mock_token_store();
64IOAuthTokenStore_uptr make_mock_token_store_already_logged_in();
65
66} // namespace FrameworkTestHelpers
67} // namespace Mantid
InternetHelper::HTTPStatus sendHTTPSRequest(const std::string &url, std::ostream &responseStream) override
Performs a request using https.
Definition: ONCatHelper.cpp:42
MockResponseCallCounts m_responseCallCounts
Definition: ONCatHelper.h:45
InternetHelper::HTTPStatus sendHTTPRequest(const std::string &url, std::ostream &responseStream) override
Performs a request using http.
Definition: ONCatHelper.cpp:38
void setToken(const boost::optional< OAuthToken > &token) override
Definition: ONCatHelper.cpp:80
boost::optional< OAuthToken > m_token
Definition: ONCatHelper.h:60
boost::optional< OAuthToken > getToken() override
Definition: ONCatHelper.cpp:82
Exception thrown when error occurs accessing an internet resource.
Definition: Exception.h:321
InternetHelper : A helper class for supporting access to resources through HTTP and HTTPS.
std::shared_ptr< MockONCatAPI > make_mock_oncat_api(const MockResponseMap &responseMap)
std::map< std::string, unsigned int > MockResponseCallCounts
Definition: ONCatHelper.h:27
std::map< std::string, std::pair< InternetHelper::HTTPStatus, std::string > > MockResponseMap
Definition: ONCatHelper.h:26
IOAuthTokenStore_uptr make_mock_token_store()
Definition: ONCatHelper.cpp:84
std::unique_ptr< ONCat > make_oncat_with_mock_api(const std::shared_ptr< MockONCatAPI > &mockAPI)
Definition: ONCatHelper.cpp:72
std::pair< const std::basic_string< char >, unsigned int > MockResponseCallMapping
Definition: ONCatHelper.h:28
IOAuthTokenStore_uptr make_mock_token_store_already_logged_in()
Definition: ONCatHelper.cpp:86
Helper class which provides the Collimation Length for SANS instruments.