1 /* ****************************************************************
3 * Copyright 2016 Samsung Electronics All Rights Reserved.
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
11 * http://www.apache.org/licenses/LICENSE-2.0
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.
19 ******************************************************************/
22 #include <OCPlatform.h>
24 #include <gtest/gtest.h>
28 namespace OCMQResourceTest
33 void onObserve(const HeaderOptions, const OCRepresentation&, const int&, const int&)
39 void onGetPut(const HeaderOptions&, const OCRepresentation& , const int eCode)
44 void foundResource(std::shared_ptr<OCResource>)
48 void createdTopic(const HeaderOptions &, const OCRepresentation &, const int,
49 std::shared_ptr<OCResource>)
54 OCResource::Ptr ConstructResourceObject(std::string host, std::string uri)
56 OCConnectivityType connectivityType = CT_DEFAULT;
57 std::vector<std::string> types = {"tkss.wk"};
58 std::vector<std::string> ifaces = {DEFAULT_INTERFACE};
60 auto ret = OCPlatform::constructResourceObject(host, uri,
61 connectivityType, false, types, ifaces);
65 ADD_FAILURE() << "ConstructResourceObject result was null";
73 TEST(MessageQueueTest, DiscoveryMQTopicsValid)
75 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
76 EXPECT_TRUE(resource != NULL);
77 QueryParamsMap query = {};
78 EXPECT_EQ(OC_STACK_OK, resource->discoveryMQTopics(query, &foundResource));
81 TEST(MessageQueueTest, CreateMQTopicValid)
83 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
84 EXPECT_TRUE(resource != NULL);
86 QueryParamsMap query = {};
87 EXPECT_EQ(OC_STACK_OK, resource->createMQTopic(rep, "/ps/nweTopic", query, &createdTopic));
91 TEST(MessageQueueTest, PublishMQTopicValid)
93 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
94 EXPECT_TRUE(resource != NULL);
96 QueryParamsMap query = {};
97 EXPECT_EQ(OC_STACK_OK, resource->publishMQTopic(rep, query, &onGetPut));
102 TEST(MessageQueueTest, SubscribeMQTopicValid)
104 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
105 EXPECT_TRUE(resource != NULL);
106 QueryParamsMap query = {};
107 EXPECT_EQ(OC_STACK_OK, resource->subscribeMQTopic(ObserveType::Observe, query, &onObserve));
110 TEST(MessageQueueTest, RequestMQPublishValid)
112 OCResource::Ptr resource = ConstructResourceObject("coap://192.168.1.2:5000", "/resource");
113 EXPECT_TRUE(resource != NULL);
114 QueryParamsMap query = {};
115 EXPECT_EQ(OC_STACK_OK, resource->requestMQPublish(query, &onGetPut));