Commit a16d2be9bb501ae7e40f180e243dbd8b03df04fd
Committed by
Moritz Wirger
1 parent
a675e68a
Fix unittests for HueCommandAPI
Showing
1 changed file
with
22 additions
and
22 deletions
hueplusplus/test/test_HueCommandAPI.cpp
| ... | ... | @@ -30,35 +30,35 @@ TEST(HueCommandAPI, PUTRequest) |
| 30 | 30 | using namespace ::testing; |
| 31 | 31 | std::shared_ptr<MockHttpHandler> httpHandler = std::make_shared<MockHttpHandler>(); |
| 32 | 32 | |
| 33 | - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); | |
| 33 | + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); | |
| 34 | 34 | Json::Value request; |
| 35 | 35 | Json::Value result = Json::objectValue; |
| 36 | 36 | result["ok"] = true; |
| 37 | 37 | |
| 38 | 38 | //empty path |
| 39 | 39 | { |
| 40 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 40 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 41 | 41 | EXPECT_EQ(result, api.PUTRequest("", request)); |
| 42 | 42 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 43 | 43 | } |
| 44 | 44 | //not empty path, starting with slash |
| 45 | 45 | { |
| 46 | 46 | const std::string path = "/test"; |
| 47 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 47 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 48 | 48 | EXPECT_EQ(result, api.PUTRequest(path, request)); |
| 49 | 49 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 50 | 50 | } |
| 51 | 51 | //not empty path, not starting with slash |
| 52 | 52 | { |
| 53 | 53 | const std::string path = "test"; |
| 54 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 54 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 55 | 55 | EXPECT_EQ(result, api.PUTRequest(path, request)); |
| 56 | 56 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 57 | 57 | } |
| 58 | 58 | //recoverable error |
| 59 | 59 | { |
| 60 | 60 | const std::string path = "/test"; |
| 61 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 61 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 62 | 62 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 63 | 63 | .WillOnce(Return(result)); |
| 64 | 64 | EXPECT_EQ(result, api.PUTRequest(path, request)); |
| ... | ... | @@ -67,7 +67,7 @@ TEST(HueCommandAPI, PUTRequest) |
| 67 | 67 | //recoverable error x2 |
| 68 | 68 | { |
| 69 | 69 | const std::string path = "/test"; |
| 70 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 70 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 71 | 71 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 72 | 72 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); |
| 73 | 73 | EXPECT_THROW(api.PUTRequest(path, request), std::system_error); |
| ... | ... | @@ -76,7 +76,7 @@ TEST(HueCommandAPI, PUTRequest) |
| 76 | 76 | //unrecoverable error |
| 77 | 77 | { |
| 78 | 78 | const std::string path = "/test"; |
| 79 | - EXPECT_CALL(*httpHandler, PUTJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 79 | + EXPECT_CALL(*httpHandler, PUTJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 80 | 80 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); |
| 81 | 81 | EXPECT_THROW(api.PUTRequest(path, request), std::system_error); |
| 82 | 82 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| ... | ... | @@ -88,35 +88,35 @@ TEST(HueCommandAPI, GETRequest) |
| 88 | 88 | using namespace ::testing; |
| 89 | 89 | std::shared_ptr<MockHttpHandler> httpHandler = std::make_shared<MockHttpHandler>(); |
| 90 | 90 | |
| 91 | - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); | |
| 91 | + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); | |
| 92 | 92 | Json::Value request; |
| 93 | 93 | Json::Value result = Json::objectValue; |
| 94 | 94 | result["ok"] = true; |
| 95 | 95 | |
| 96 | 96 | //empty path |
| 97 | 97 | { |
| 98 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 98 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 99 | 99 | EXPECT_EQ(result, api.GETRequest("", request)); |
| 100 | 100 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 101 | 101 | } |
| 102 | 102 | //not empty path, starting with slash |
| 103 | 103 | { |
| 104 | 104 | const std::string path = "/test"; |
| 105 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 105 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 106 | 106 | EXPECT_EQ(result, api.GETRequest(path, request)); |
| 107 | 107 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 108 | 108 | } |
| 109 | 109 | //not empty path, not starting with slash |
| 110 | 110 | { |
| 111 | 111 | const std::string path = "test"; |
| 112 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 112 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 113 | 113 | EXPECT_EQ(result, api.GETRequest(path, request)); |
| 114 | 114 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 115 | 115 | } |
| 116 | 116 | //recoverable error |
| 117 | 117 | { |
| 118 | 118 | const std::string path = "/test"; |
| 119 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 119 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 120 | 120 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 121 | 121 | .WillOnce(Return(result)); |
| 122 | 122 | EXPECT_EQ(result, api.GETRequest(path, request)); |
| ... | ... | @@ -125,7 +125,7 @@ TEST(HueCommandAPI, GETRequest) |
| 125 | 125 | //recoverable error x2 |
| 126 | 126 | { |
| 127 | 127 | const std::string path = "/test"; |
| 128 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 128 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 129 | 129 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 130 | 130 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); |
| 131 | 131 | EXPECT_THROW(api.GETRequest(path, request), std::system_error); |
| ... | ... | @@ -134,7 +134,7 @@ TEST(HueCommandAPI, GETRequest) |
| 134 | 134 | //unrecoverable error |
| 135 | 135 | { |
| 136 | 136 | const std::string path = "/test"; |
| 137 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 137 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 138 | 138 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); |
| 139 | 139 | EXPECT_THROW(api.GETRequest(path, request), std::system_error); |
| 140 | 140 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| ... | ... | @@ -146,35 +146,35 @@ TEST(HueCommandAPI, DELETERequest) |
| 146 | 146 | using namespace ::testing; |
| 147 | 147 | std::shared_ptr<MockHttpHandler> httpHandler = std::make_shared<MockHttpHandler>(); |
| 148 | 148 | |
| 149 | - HueCommandAPI api(bridge_ip, bridge_username, httpHandler); | |
| 149 | + HueCommandAPI api(getBridgeIp(), getBridgeUsername(), httpHandler); | |
| 150 | 150 | Json::Value request; |
| 151 | 151 | Json::Value result = Json::objectValue; |
| 152 | 152 | result["ok"] = true; |
| 153 | 153 | |
| 154 | 154 | //empty path |
| 155 | 155 | { |
| 156 | - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 156 | + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername(), request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 157 | 157 | EXPECT_EQ(result, api.DELETERequest("", request)); |
| 158 | 158 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 159 | 159 | } |
| 160 | 160 | //not empty path, starting with slash |
| 161 | 161 | { |
| 162 | 162 | const std::string path = "/test"; |
| 163 | - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 163 | + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 164 | 164 | EXPECT_EQ(result, api.DELETERequest(path, request)); |
| 165 | 165 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 166 | 166 | } |
| 167 | 167 | //not empty path, not starting with slash |
| 168 | 168 | { |
| 169 | 169 | const std::string path = "test"; |
| 170 | - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + '/' + path, request, bridge_ip, 80)).WillOnce(Return(result)); | |
| 170 | + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + '/' + path, request, getBridgeIp(), 80)).WillOnce(Return(result)); | |
| 171 | 171 | EXPECT_EQ(result, api.DELETERequest(path, request)); |
| 172 | 172 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 173 | 173 | } |
| 174 | 174 | //recoverable error |
| 175 | 175 | { |
| 176 | 176 | const std::string path = "/test"; |
| 177 | - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 177 | + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 178 | 178 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 179 | 179 | .WillOnce(Return(result)); |
| 180 | 180 | EXPECT_EQ(result, api.DELETERequest(path, request)); |
| ... | ... | @@ -183,7 +183,7 @@ TEST(HueCommandAPI, DELETERequest) |
| 183 | 183 | //recoverable error x2 |
| 184 | 184 | { |
| 185 | 185 | const std::string path = "/test"; |
| 186 | - EXPECT_CALL(*httpHandler, DELETEJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 186 | + EXPECT_CALL(*httpHandler, DELETEJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 187 | 187 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))) |
| 188 | 188 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::connection_reset)))); |
| 189 | 189 | EXPECT_THROW(api.DELETERequest(path, request), std::system_error); |
| ... | ... | @@ -192,9 +192,9 @@ TEST(HueCommandAPI, DELETERequest) |
| 192 | 192 | //unrecoverable error |
| 193 | 193 | { |
| 194 | 194 | const std::string path = "/test"; |
| 195 | - EXPECT_CALL(*httpHandler, GETJson("/api/" + bridge_username + path, request, bridge_ip, 80)) | |
| 195 | + EXPECT_CALL(*httpHandler, GETJson("/api/" + getBridgeUsername() + path, request, getBridgeIp(), 80)) | |
| 196 | 196 | .WillOnce(Throw(std::system_error(std::make_error_code(std::errc::not_enough_memory)))); |
| 197 | 197 | EXPECT_THROW(api.GETRequest(path, request), std::system_error); |
| 198 | 198 | Mock::VerifyAndClearExpectations(httpHandler.get()); |
| 199 | 199 | } |
| 200 | -} | |
| 201 | 200 | \ No newline at end of file |
| 201 | +} | ... | ... |