TEST(BroadcastSubscriptionRequestTest, assertsWhenWrongQosTypeIsPassed)
{
    using namespace joynr;
    BroadcastSubscriptionRequest subscriptionRequest;
    auto qos = std::make_shared<PeriodicSubscriptionQos>();
    EXPECT_DEATH(subscriptionRequest.setQos(qos), "Assertion.*");
}
/**
  * Trigger:    The dispatcher receives a Publication from a broadcast with multiple output parameters.
  * Expected:   The SubscriptionManager retrieves the correct SubscriptionCallback and the
  *             Interpreter executes it correctly
  */
TEST_F(BroadcastSubscriptionTest, receive_publication_multipleOutputParameters ) {

    qRegisterMetaType<SubscriptionPublication>("SubscriptionPublication");

    // Use a semaphore to count and wait on calls to the mockSubscriptionListener
    QSemaphore semaphore(0);
    EXPECT_CALL(*mockSubscriptionListenerTwo, onReceive(A<const types::QtGpsLocation&>(), A<const double&>()))
            .WillRepeatedly(ReleaseSemaphore(&semaphore));

    //register the subscription on the consumer side
    QString subscribeToName = "locationUpdateWithSpeed";
    auto subscriptionQos = QSharedPointer<QtOnChangeSubscriptionQos>(new QtOnChangeWithKeepAliveSubscriptionQos(
                80, // validity_ms
                100, // minInterval_ms
                200, // maxInterval_ms
                80 // alertInterval_ms
    ));

    BroadcastSubscriptionRequest subscriptionRequest;
    //construct a reply containing a QtGpsLocation
    SubscriptionPublication subscriptionPublication;
    subscriptionPublication.setSubscriptionId(subscriptionRequest.getSubscriptionId());
    QList<QVariant> response;
    response.append(QVariant::fromValue(gpsLocation1));
    response.append(QVariant::fromValue(speed1));
    subscriptionPublication.setResponse(response);

    QSharedPointer<SubscriptionCallback<types::QtGpsLocation, double>> subscriptionCallback(
            new SubscriptionCallback<types::QtGpsLocation, double>(mockSubscriptionListenerTwo));

    // subscriptionRequest is an out param
    subscriptionManager->registerSubscription(
                subscribeToName,
                subscriptionCallback,
                subscriptionQos,
                subscriptionRequest);
    // incoming publication from the provider
    JoynrMessage msg = messageFactory.createSubscriptionPublication(
                providerParticipantId,
                proxyParticipantId,
                qos,
                subscriptionPublication);

    dispatcher.receive(msg);

    // Assert that only one subscription message is received by the subscription listener
    ASSERT_TRUE(semaphore.tryAcquire(1, 1000));
    ASSERT_FALSE(semaphore.tryAcquire(1, 250));
}
void ClassDeserializerImpl<BroadcastSubscriptionRequest>::deserialize(
        BroadcastSubscriptionRequest& request,
        IObject& o)
{
    while (o.hasNextField()) {
        IField& field = o.nextField();
        if (field.name() == "subscriptionId") {
            request.setSubscriptionId(field.value());
        } else if (field.name() == "subscribedToName") {
            request.setSubscribeToName(field.value());
        } else if (field.name() == "qos") {
            request.setQos(convertVariant(field.value()).get<OnChangeSubscriptionQos>());
        } else if (field.name() == "filterParameters") {
            ClassDeserializer<BroadcastFilterParameters> filterParametersDeserializer;
            BroadcastFilterParameters filterParameters;
            filterParametersDeserializer.deserialize(filterParameters, field.value());
            request.setFilterParameters(filterParameters);
        }
    }
}