Skip to content
Snippets Groups Projects
KafkaTopicSubscriberTest.h 2.44 KiB
Newer Older
#ifndef MANTID_LIVEDATA_KAFKATOPICSUBSCRIBERTEST_H_
#define MANTID_LIVEDATA_KAFKATOPICSUBSCRIBERTEST_H_

#include "MantidKernel/make_unique.h"
#include "MantidLiveData/Kafka/KafkaTopicSubscriber.h"
#include <cxxtest/TestSuite.h>
#include <memory>

class KafkaTopicSubscriberTest : public CxxTest::TestSuite {
public:
  // This pair of boilerplate methods prevent the suite being created statically
  // This means the constructor isn't called when running other tests
  static KafkaTopicSubscriberTest *createSuite() {
    return new KafkaTopicSubscriberTest();
  }
  static void destroySuite(KafkaTopicSubscriberTest *suite) { delete suite; }

  // ---------------------------------------------------------------------------
  // Success cases
  // ---------------------------------------------------------------------------
  void test_Connection_Properties_Returned_As_Expected() {
    using Mantid::LiveData::KafkaTopicSubscriber;
Matthew D Jones's avatar
Matthew D Jones committed
    using Mantid::LiveData::subscribeAtOption;
    std::string broker("badhost"), topic("topicstring");
    // This won't connect yet
Matthew D Jones's avatar
Matthew D Jones committed
    std::vector<std::string> topics = {topic};
    auto subscriber = Mantid::Kernel::make_unique<KafkaTopicSubscriber>(
        broker, topics, subscribeAtOption::LATEST);
Matthew D Jones's avatar
Matthew D Jones committed
    TS_ASSERT_EQUALS(topic, subscriber->topic()[0]);
  void xtest_Unknown_Topic_Throws_Error() {
    using Mantid::LiveData::KafkaTopicSubscriber;
Matthew D Jones's avatar
Matthew D Jones committed
    using Mantid::LiveData::subscribeAtOption;
    std::string broker("sakura"), topic("__NOT_A_TOPIC_LETS_NOT_FIND_THIS");
    // This won't connect yet
Matthew D Jones's avatar
Matthew D Jones committed
    std::vector<std::string> topics = {topic};
    auto subscriber = Mantid::Kernel::make_unique<KafkaTopicSubscriber>(
        broker, topics, subscribeAtOption::LATEST);
    TS_ASSERT_THROWS(subscriber->subscribe(), std::runtime_error);
  // ---------------------------------------------------------------------------
  // Failure cases
  // ---------------------------------------------------------------------------
  void xtest_BadHost_Throws_Error() {
    using Mantid::LiveData::KafkaTopicSubscriber;
Matthew D Jones's avatar
Matthew D Jones committed
    using Mantid::LiveData::subscribeAtOption;
    std::string broker("badhost"), topic("topic");

    // This won't connect yet
Matthew D Jones's avatar
Matthew D Jones committed
    std::vector<std::string> topics = {topic};
    auto subscriber = Mantid::Kernel::make_unique<KafkaTopicSubscriber>(
        broker, topics, subscribeAtOption::LATEST);

    TS_ASSERT_THROWS(subscriber->subscribe(), std::runtime_error);
  }
};

#endif /* MANTID_LIVEDATA_KAFKATOPICSUBSCRIBERTEST_H_ */