2 * Samsung Ukraine R&D Center (SRK under a contract between)
3 * LLC "Samsung Electronics Co", Ltd (Seoul, Republic of Korea)
4 * Copyright (C) 2018 Samsung Electronics Co., Ltd. All rights reserved.
6 * Licensed under the Apache License, Version 2.0 (the "License");
7 * you may not use this file except in compliance with the License.
8 * You may obtain a copy of the License at
10 * http://www.apache.org/licenses/LICENSE-2.0
12 * Unless required by applicable law or agreed to in writing, software
13 * distributed under the License is distributed on an "AS IS" BASIS,
14 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15 * See the License for the specific language governing permissions and
16 * limitations under the License
18 #include <gmock/gmock.h>
20 #include <jsoncpp/json/value.h>
22 #include "connection.h"
23 #include "restservicemock.h"
24 #include "servicerequest.h"
29 using ::testing::Return;
30 using ::testing::Throw;
31 using ::testing::DoAll;
32 using ::testing::Invoke;
33 using ::testing::WithArgs;
34 using ::testing::TypedEq;
38 const std::chrono::milliseconds TEST_TIMEOUT_INTERVAL{1};
39 const std::string TEST_DEVICE_ID{"device-id"};
42 TEST(TestServiceRequest, test_registerDevice)
45 auto& settings = agent::Settings::instance();
46 settings.setKeepAliveTimeout(TEST_TIMEOUT_INTERVAL);
47 settings.setDeviceId("");
48 settings.setSaveFileName("/dev/null");
50 communication::Connection conn("", TEST_TIMEOUT_INTERVAL, &rest);
52 EXPECT_CALL(rest, registerDevice(_, _))
53 .WillOnce(Throw(std::runtime_error("")))
54 .WillOnce(Return(TEST_DEVICE_ID));
57 agent::ServiceRequest::registerDevice(conn);
58 EXPECT_EQ(TEST_DEVICE_ID, settings.getDeviceId());
59 } catch (std::exception& e) {
64 TEST(TestServiceRequest, test_updateRules)
67 auto& settings = agent::Settings::instance();
68 settings.setKeepAliveTimeout(TEST_TIMEOUT_INTERVAL);
70 communication::Connection conn("", TEST_TIMEOUT_INTERVAL, &rest);
72 check["type"] = std::string{"request-rules"};
74 EXPECT_CALL(rest, sendData(_, TypedEq<const Json::Value&>(check)))
75 .WillOnce(Throw(std::runtime_error("")))
78 agent::ServiceRequest::updateRules(conn);
79 EXPECT_EQ(TEST_DEVICE_ID, settings.getDeviceId());
80 } catch (std::exception& e) {