void LongPollingMessageReceiver::processReceivedJsonObjects(const std::string& jsonObject)
{
    JoynrMessage* msg = JsonSerializer::deserialize<JoynrMessage>(jsonObject);
    if (msg == nullptr) {
        JOYNR_LOG_ERROR(logger, "Unable to deserialize message. Raw message: {}", jsonObject);
        return;
    }
    if (msg->getType().empty()) {
        JOYNR_LOG_ERROR(logger, "received empty message - dropping Messages");
        return;
    }
    if (!msg->containsHeaderExpiryDate()) {
        JOYNR_LOG_ERROR(logger,
                        "received message [msgId=[{}] without decay time - dropping message",
                        msg->getHeaderMessageId());
    }

    if (msg->getType() == JoynrMessage::VALUE_MESSAGE_TYPE_REQUEST ||
        msg->getType() == JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST ||
        msg->getType() == JoynrMessage::VALUE_MESSAGE_TYPE_BROADCAST_SUBSCRIPTION_REQUEST) {
        // TODO ca: check if replyTo header info is available?
        std::string replyChannelId = msg->getHeaderReplyChannelId();
        std::shared_ptr<system::RoutingTypes::ChannelAddress> address(
                new system::RoutingTypes::ChannelAddress(replyChannelId));
        messageRouter->addNextHop(msg->getHeaderFrom(), address);
    }

    // messageRouter.route passes the message reference to the MessageRunnable, which copies it.
    // TODO would be nicer if the pointer would be passed to messageRouter, on to MessageRunnable,
    // and runnable should delete it.
    messageRouter->route(*msg);
    delete msg;
}
TEST_F(JoynrMessageFactoryTest, createPublication){
    JoynrMessage joynrMessage = messageFactory.createSubscriptionPublication(
                senderID,
                receiverID,
                qos,
                subscriptionPublication
    );
    checkParticipantIDs(joynrMessage);
    checkSubscriptionPublication(joynrMessage);
    EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_PUBLICATION, joynrMessage.getType());
}
TEST_F(JoynrMessageFactoryTest, createOneWay){
    JoynrMessage joynrMessage = messageFactory.createOneWay(
                senderID,
                receiverID,
                qos,
                reply
    );
    checkParticipantIDs(joynrMessage);
    checkReply(joynrMessage);
    EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_ONE_WAY, joynrMessage.getType());
}
TEST_F(JoynrMessageFactoryTest, createSubscriptionStop){
    QString subscriptionId("TEST-SubscriptionId");
    SubscriptionStop subscriptionStop;
    subscriptionStop.setSubscriptionId(subscriptionId);
    JoynrMessage joynrMessage = messageFactory.createSubscriptionStop(
                senderID,
                receiverID,
                qos,
                subscriptionStop
    );
    checkParticipantIDs(joynrMessage);
    EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_STOP, joynrMessage.getType());
}
void WebSocketLibJoynrMessagingSkeleton::onTextMessageReceived(const std::string& message)
{
    // deserialize message and transmit
    JoynrMessage* joynrMsg = JsonSerializer::deserialize<JoynrMessage>(message);
    if (joynrMsg == nullptr || joynrMsg->getType().empty()) {
        JOYNR_LOG_ERROR(logger, "Unable to deserialize joynr message object from: {}", message);
        return;
    }
    JOYNR_LOG_TRACE(logger, "<<< INCOMING <<< {}", message);
    // message router copies joynr message when scheduling thread that handles
    // message delivery
    transmit(*joynrMsg);
    delete joynrMsg;
}
TEST_F(JoynrMessageFactoryTest, createSubscriptionRequest){
    auto subscriptionQos = QSharedPointer<SubscriptionQos>(new OnChangeSubscriptionQos());
    SubscriptionRequest subscriptionRequest;
    subscriptionRequest.setSubscriptionId(QString("subscriptionId"));
    subscriptionRequest.setAttributeName(QString("attributeName"));
    subscriptionRequest.setQos(subscriptionQos);
    JoynrMessage joynrMessage = messageFactory.createSubscriptionRequest(
                senderID,
                receiverID,
                qos,
                subscriptionRequest
    );
    checkParticipantIDs(joynrMessage);
    EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_SUBSCRIPTION_REQUEST, joynrMessage.getType());
}
TEST_F(JoynrMessageFactoryTest, createRequest){
    JoynrMessage joynrMessage = messageFactory.createRequest(
                senderID,
                receiverID,
                qos,
                request
    );
    //warning if prepareRequest needs to long this assert will fail as it compares absolute timestamps
    QDateTime expectedExpiryDate = QDateTime::currentDateTime().addMSecs(qos.getTtl());
    QDateTime expiryDate = joynrMessage.getHeaderExpiryDate();
    EXPECT_NEAR(expectedExpiryDate.toMSecsSinceEpoch(), expiryDate.toMSecsSinceEpoch(), 100.);
    LOG_DEBUG(logger,
              QString("expiryDate: %1 [%2]")
              .arg(expiryDate.toString())
              .arg(expiryDate.toMSecsSinceEpoch()));
    LOG_DEBUG(logger,
              QString("expectedExpiryDate: %1 [%2]")
              .arg(expectedExpiryDate.toString())
              .arg(expectedExpiryDate.toMSecsSinceEpoch()));

    checkParticipantIDs(joynrMessage);
    checkRequest(joynrMessage);
    EXPECT_QSTREQ(JoynrMessage::VALUE_MESSAGE_TYPE_REQUEST, joynrMessage.getType());
}