TEST_F(LibJoynrDbusCommunicationTests, transmit_message) { QString ccMessagingAddress("local:joynr.messaging:cc.message6"); // register skeletons MockMessaging* msgMock = new MockMessaging(); EXPECT_CALL(*msgMock, transmit(A<JoynrMessage&>())).Times(1); auto msgSkeleton = new IDbusSkeletonWrapper<DbusMessagingSkeleton, IMessaging>(*msgMock, ccMessagingAddress); // get stub DbusMessagingStubAdapter* msgStub = new DbusMessagingStubAdapter(ccMessagingAddress); ASSERT_TRUE(msgStub->isProxyAvailable()); // create message JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_ONE_WAY); msg.setHeaderTo(QString("local")); msg.setPayload("This is a test"); // create messaging qos msgStub->transmit(msg); // delete skeleton delete msgSkeleton; // error on transmission msgStub->transmit(msg); // stub not availabe ASSERT_FALSE(msgStub->isProxyAvailable()); delete msgStub; delete msgMock; }
TEST_F(LibJoynrDbusCommunicationTests, dbus_skeletonwrapper_register_unregister) { QString ccMessagingAddress("local:cc.messaging:cc.messaging8"); // craete mock and expect 2 calls MockMessaging* msgMock = new MockMessaging(); EXPECT_CALL(*msgMock, transmit(A<JoynrMessage&>())).Times(2); // create the skeleton LOG_INFO(logger, "Register skeleton"); auto msgSkeleton = new IDbusSkeletonWrapper<DbusMessagingSkeleton, IMessaging>(*msgMock, ccMessagingAddress); // create message JoynrMessage msg; msg.setType(JoynrMessage::VALUE_MESSAGE_TYPE_ONE_WAY); msg.setHeaderTo(QString("local")); msg.setPayload("This is a test"); // get stub DbusMessagingStubAdapter* msgStub = new DbusMessagingStubAdapter(ccMessagingAddress); ASSERT_TRUE(msgStub->isProxyAvailable()); // call method LOG_INFO(logger, "Transmit message: should work"); msgStub->transmit(msg); // delete skeleton LOG_INFO(logger, "Delete skeleton"); delete msgSkeleton; // call method LOG_INFO(logger, "Transmit message: should fail"); msgStub->transmit(msg); // register skeleton LOG_INFO(logger, "Register skeleton"); msgSkeleton = new IDbusSkeletonWrapper<DbusMessagingSkeleton, IMessaging>(*msgMock, ccMessagingAddress); // call method LOG_INFO(logger, "Transmit message: should work"); msgStub->transmit(msg); delete msgSkeleton; delete msgMock; }
TEST_F(MessageQueueTest, queueDequeueMultipleMessagesForOneParticipant) { // add messages to the queue JoynrMessage msg; msg.setHeaderTo("TEST"); msg.setHeaderExpiryDate(expiryDate); messageQueue.queueMessage(msg); messageQueue.queueMessage(msg); EXPECT_EQ(messageQueue.getQueueLength(), 2); // get messages from queue MessageQueueItem* item = messageQueue.getNextMessageForParticipant("TEST"); EXPECT_EQ(item->getContent(), msg); EXPECT_EQ(messageQueue.getQueueLength(), 1); item = messageQueue.getNextMessageForParticipant("TEST"); EXPECT_EQ(item->getContent(), msg); EXPECT_EQ(messageQueue.getQueueLength(), 0); }
void JoynrMessageFactory::initMsg(JoynrMessage& msg, const std::string& senderParticipantId, const std::string& receiverParticipantId, const std::int64_t ttl, const std::string& payload) const { msg.setHeaderCreatorUserId(securityManager->getCurrentProcessUserId()); msg.setHeaderFrom(senderParticipantId); msg.setHeaderTo(receiverParticipantId); // calculate expiry date JoynrTimePoint expiryDate = DispatcherUtils::convertTtlToAbsoluteTime(ttl); msg.setHeaderExpiryDate(expiryDate); // add content type and class msg.setHeaderContentType(JoynrMessage::VALUE_CONTENT_TYPE_APPLICATION_JSON); // set payload msg.setPayload(payload); }