Merge test folder of test branch
[iotivity.git] / test / src / tc / ic / gtest / src / btc / ICMessageQueueTest.cpp
1 /******************************************************************
2 *
3 * Copyright 2017 Samsung Electronics All Rights Reserved.
4 *
5 *
6 *
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
10 *
11 * http://www.apache.org/licenses/LICENSE-2.0
12 *
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 *
19 ******************************************************************/
20
21 #include "ICHelper.h"
22
23 using namespace OC;
24
25 class ICMessageQueueTest_btc: public ::testing::Test{
26
27 public:
28     std::vector< std::string > m_types = { "oic.ps" };
29     std::vector< std::string > m_iFaces = { DEFAULT_INTERFACE };
30
31     OC::OCResource::Ptr m_OCResource ;
32
33     QueryParamsMap m_queryParametersMap;
34     QualityOfService m_qos;
35     OCRepresentation m_rep;
36     ObserveType m_observe;
37     QueryParamsMap m_query;
38
39     static void foundResource(const int ecode, const string &originUri,
40             shared_ptr< OC::OCResource > topic)
41     {
42
43     }
44
45     static void observeHandler(const HeaderOptions&, const OCRepresentation&, const int, const int)
46     {
47
48     }
49
50     static void attributeHandler(const HeaderOptions&, const OCRepresentation&, const int)
51     {
52
53     }
54
55 protected:
56     std::string m_errorMsg;
57
58     virtual void SetUp()
59     {
60         m_OCResource = OCPlatform::constructResourceObject(HOST, URI, CT_DEFAULT, true, m_types, m_iFaces);
61         m_query = {};
62         m_qos = QualityOfService::LowQos;
63     }
64
65     virtual void TearDown()
66     {
67     }
68 };
69
70 /**
71  * @since 2016-08-25
72  * @see None
73  * @objective Test createMQTopic function with valid OCRepresentation, topicURI QueryMap, createCallback and QOS
74  * @target createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback)
75  * @test_data OCRepresentation, topic uri, query params, createCallback and qos
76  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
77  * @procedure Perform createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback) API
78  * @post_condition None
79  * @expected createMQTopic should return OC_STACK_OK
80  **/
81 #if defined(__LINUX__) || defined(__TIZEN__)
82 TEST_F(ICMessageQueueTest_btc, CreateMQTopic_SRC_P)
83 {
84     EXPECT_EQ(OC_STACK_OK, m_OCResource->createMQTopic(m_rep, TOPIC_URI, m_queryParametersMap, &foundResource, m_qos))<<"CreateMQTopic is not creating Topic into MQ Broker";
85 }
86 #endif
87
88 /**
89  * @since 2016-08-25
90  * @see None
91  * @objective Test createMQTopic function with NULL callback
92  * @target createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback)
93  * @test_data OCRepresentation, topic uri, query params, NULL createCallback and qos
94  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
95  * @procedure Perform createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback) API
96  * @post_condition None
97  * @expected createMQTopic will throw Exception.
98  **/
99 #if defined(__LINUX__) || defined(__TIZEN__)
100 TEST_F(ICMessageQueueTest_btc, CreateMQTopicNULLCallback_NV_N)
101 {
102     EXPECT_ANY_THROW(m_OCResource->createMQTopic(m_rep, TOPIC_URI, m_queryParametersMap, nullptr, m_qos))<<"CreateMQTopic is creating Topic into MQ Broker with NULL callback";
103 }
104 #endif
105
106 /**
107  * @since 2016-08-26
108  * @see None
109  * @objective Test createMQTopic function with empt topicURI
110  * @target createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback)
111  * @test_data OCRepresentation, empty topic uri, query params, createCallback and qos
112  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
113  * @procedure Perform createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback) API
114  * @post_condition None
115  * @expected createMQTopic will throw Exception.
116  **/
117 #if defined(__LINUX__) || defined(__TIZEN__)
118 TEST_F(ICMessageQueueTest_btc, CreateMQTopic_ESV_N)
119 {
120     EXPECT_ANY_THROW(m_OCResource->createMQTopic(m_rep, EMPTY_STRING, m_queryParametersMap, &foundResource, m_qos))<<"CreateMQTopic is creating Topic into MQ Broker with empty string as topic uri";
121 }
122 #endif
123
124 /**
125  * @since 2016-08-26
126  * @see None
127  * @objective Test createMQTopic function with invalid topicURI
128  * @target createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback)
129  * @test_data OCRepresentation, invalid topic uri, query params, createCallback and qos
130  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
131  * @procedure Perform createMQTopic(const OCRepresentation& rep, const std::string& topicUri, const QueryParamsMap& queryParametersMap, &createCallback) API
132  * @post_condition None
133  * @expected createMQTopic will throw Exception.
134  **/
135 #if defined(__LINUX__) || defined(__TIZEN__)
136 TEST_F(ICMessageQueueTest_btc, CreateMQTopic_USV_N)
137 {
138     EXPECT_ANY_THROW(m_OCResource->createMQTopic(m_rep, INVALID, m_queryParametersMap, &foundResource, m_qos))<<"CreateMQTopic is creating Topic into MQ Broker with invalid string as topic uri";
139 }
140 #endif
141
142 /**
143  * @since 2016-08-25
144  * @see None
145  * @objective Test 'discoveryMQTopics' function with valid QueryParameterMap, createCallback and QOS
146  * @target discoveryMQTopics(const QueryParamsMap& queryParametersMap, &findCallback)
147  * @test_data queryParameterMap, findCallback and qos
148  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
149  * @procedure Perform discoveryMQTopics(const QueryParamsMap& queryParametersMap, &findCallback) API
150  * @post_condition None
151  * @expected discoveryMQTopics that provide OC_STACK_OK
152  **/
153 #if defined(__LINUX__) || defined(__TIZEN__)
154 TEST_F(ICMessageQueueTest_btc, DiscoveryMQTopics_SRC_P)
155 {
156     EXPECT_EQ(OC_STACK_OK,m_OCResource->discoveryMQTopics(m_queryParametersMap, &foundResource, m_qos))<<"DiscoveryMQTopics is not to discovery Topics from MQ Broker.";
157 }
158 #endif
159
160 /**
161  * @since 2016-08-25
162  * @see None
163  * @objective Test 'discoveryMQTopics' function with NULL Callback
164  * @target discoveryMQTopics(const QueryParamsMap& queryParametersMap, &findCallback)
165  * @test_data queryParameterMap, NULL findCallback and qos
166  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
167  * @procedure Perform discoveryMQTopics(const QueryParamsMap& queryParametersMap, &findCallback) API
168  * @post_condition None
169  * @expected discoveryMQTopics will throw Exception.
170  **/
171 #if defined(__LINUX__) || defined(__TIZEN__)
172 TEST_F(ICMessageQueueTest_btc, DiscoveryMQTopicsCallback_NV_N)
173 {
174     EXPECT_ANY_THROW(m_OCResource->discoveryMQTopics(m_queryParametersMap, nullptr, m_qos))<<"DiscoveryMQTopics is to discovery Topics from MQ Broker with NULL callback.";
175 }
176 #endif
177
178 /**
179  * @since 2016-08-25
180  * @see None
181  * @objective Test requestMQPublish API with valid QueryParameterMap, publishCallback and QOS
182  * @target requestMQPublish(const QueryParamsMap& queryParametersMap, &publishCallback)
183  * @test_data queryParameterMap, publishCallback and qos
184  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
185  * @procedure Perform requestMQPublish(const QueryParamsMap& queryParametersMap, &publishCallback) API
186  * @post_condition None
187  * @expected requestMQPublish should return OC_STACK_OK
188  **/
189 #if defined(__LINUX__) || defined(__TIZEN__)
190 TEST_F(ICMessageQueueTest_btc, RequestMQPublish_SRC_P)
191 {
192     EXPECT_EQ(OC_STACK_OK, m_OCResource->requestMQPublish(m_queryParametersMap, &attributeHandler, m_qos))<<"RequestMQPublish is not to request publish to MQ publisher.";
193 }
194 #endif
195
196 /**
197  * @since 2016-08-25
198  * @see None
199  * @objective Test requestMQPublish API with NULL Callback
200  * @target requestMQPublish(const QueryParamsMap& queryParametersMap, &publishCallback)
201  * @test_data queryParameterMap, NULL publishCallback and qos
202  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
203  * @procedure Perform requestMQPublish(const QueryParamsMap& queryParametersMap, &publishCallback) API
204  * @post_condition None
205  * @expected requestMQPublish will throw Exception.
206  **/
207 #if defined(__LINUX__) || defined(__TIZEN__)
208 TEST_F(ICMessageQueueTest_btc, RequestMQPublishNULLCallback_NV_N)
209 {
210     EXPECT_ANY_THROW(m_OCResource->requestMQPublish(m_queryParametersMap, nullptr, m_qos))<<"RequestMQPublish is to request publish to MQ publisher with NULL callback.";
211 }
212 #endif
213
214 /**
215  * @since 2016-08-25
216  * @see None
217  * @objective Test subscribeMQTopic API with valid observer, QueryParameterMap, observeCallback and QOS
218  * @target subscribeMQTopic(ObserveType observeType, const QueryParamsMap& queryParametersMap, &observeCallback)
219  * @test_data observeType, queryParameterMap, observeCallback and qos
220  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
221  * @procedure Perform subscribeMQTopic(ObserveType observeType, const QueryParamsMap& queryParametersMap, &observeCallback) API
222  * @post_condition None
223  * @expected subscribeMQTopic should return OC_STACK_OK
224  **/
225 #if defined(__LINUX__) || defined(__TIZEN__)
226 TEST_F(ICMessageQueueTest_btc, SubscribeMQTopic_SRC_P)
227 {
228     EXPECT_EQ(OC_STACK_OK, m_OCResource->subscribeMQTopic(m_observe, m_queryParametersMap, &observeHandler, m_qos))<<"SubscribeMQTopic is not to subscribe Topic to MQ Broker.";
229 }
230 #endif
231
232 /**
233  * @since 2016-08-25
234  * @see None
235  * @objective Test subscribeMQTopic API with NULL Callback
236  * @target subscribeMQTopic(ObserveType observeType, const QueryParamsMap& queryParametersMap, &observeCallback)
237  * @test_data observeType, queryParameterMap, NULL observeCallback and qos
238  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
239  * @procedure Perform subscribeMQTopic(ObserveType observeType, const QueryParamsMap& queryParametersMap, &observeCallback) API
240  * @post_condition None
241  * @expected subscribeMQTopic will throw Exception.
242  **/
243 #if defined(__LINUX__) || defined(__TIZEN__)
244 TEST_F(ICMessageQueueTest_btc, SubscribeMQTopicNULLCallback_NV_N)
245 {
246     EXPECT_ANY_THROW(m_OCResource->subscribeMQTopic(m_observe, m_queryParametersMap, nullptr, m_qos))<<"SubscribeMQTopic is to subscribe Topic to MQ Broker with NULL callback.";
247 }
248 #endif
249
250 /**
251  * @since 2016-08-25
252  * @see None
253  * @objective Test unsubscribeMQTopic API with valid QOS
254  * @target unsubscribeMQTopic()
255  * @test_data qos
256  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
257  * @procedure Perform unsubscribeMQTopic() API
258  * @post_condition None
259  * @expected unsubscribeMQTopic should return OC_STACK_OK
260  **/
261 #if defined(__LINUX__) || defined(__TIZEN__)
262 TEST_F(ICMessageQueueTest_btc, UnsubscribeMQTopic_SRC_P)
263 {
264     EXPECT_EQ(OC_STACK_OK,m_OCResource->subscribeMQTopic(m_observe, m_queryParametersMap, observeHandler, m_qos))<<"SubscribeMQTopic is NOT to subscribe Topic to MQ Broker with NULL callback.";
265     EXPECT_EQ(OC_STACK_OK, m_OCResource->unsubscribeMQTopic(m_qos))<<"UnsubscribeMQTopic is not to unsubscribe Topic to MQ Broker.";
266 }
267 #endif
268
269 /**
270  * @since 2016-08-25
271  * @see None
272  * @objective Test publishMQTopic API with valid OCRepresentation, QueryParameterMap, publishCallback and QOS
273  * @target publishMQTopic(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, &publishCallback)
274  * @test_data OCRepresentation, queryParameterMap, publishCallback and qos
275  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
276  * @procedure Perform publishMQTopic(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, &publishCallback) API
277  * @post_condition None
278  * @expected publishMQTopic should return OC_STACK_OK
279  **/
280 #if defined(__LINUX__) || defined(__TIZEN__)
281 TEST_F(ICMessageQueueTest_btc, PublishMQTopic_SRC_P)
282 {
283     EXPECT_EQ(OC_STACK_OK, m_OCResource->publishMQTopic(m_rep, m_queryParametersMap, &attributeHandler, m_qos))<<"PublishMQTopic is not to publish Topic information into MQ Broker.";
284 }
285 #endif
286
287 /**
288  * @since 2016-08-25
289  * @see None
290  * @objective Test publishMQTopic API with NULL Callback
291  * @target publishMQTopic(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, &publishCallback)
292  * @test_data OCRepresentation, queryParameterMap, NULL publishCallback and qos
293  * @pre_condition constructResourceObject(host, uri, connectivity type, true, types, iFaces) API
294  * @procedure Perform publishMQTopic(const OCRepresentation& rep, const QueryParamsMap& queryParametersMap, &publishCallback) API
295  * @post_condition None
296  * @expected publishMQTopic will throw Exception.
297  **/
298 #if defined(__LINUX__) || defined(__TIZEN__)
299 TEST_F(ICMessageQueueTest_btc, PublishMQTopicNULLCall_NV_N)
300 {
301     EXPECT_ANY_THROW(m_OCResource->publishMQTopic(m_rep, m_queryParametersMap, nullptr, m_qos))<<"PublishMQTopic is to publish Topic information into MQ Broker with NULL callback.";
302 }
303 #endif