From 0c6cf390261a0ed9c8830766d50366acc33c0ddb Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Tue, 3 Jan 2017 20:48:06 +0000 Subject: Introduce to mock mail server --- gentoobrowse-api/unittests/Jamfile.jam | 7 +++++++ gentoobrowse-api/unittests/mockDefs.cpp | 25 +++++++++++++++++++++--- gentoobrowse-api/unittests/mockDefs.h | 15 ++++++++++++++ gentoobrowse-api/unittests/mocks.ice | 15 ++++++++++++++ gentoobrowse-api/unittests/testNotifications.cpp | 2 +- 5 files changed, 60 insertions(+), 4 deletions(-) create mode 100644 gentoobrowse-api/unittests/mocks.ice diff --git a/gentoobrowse-api/unittests/Jamfile.jam b/gentoobrowse-api/unittests/Jamfile.jam index 70fa90f..60ee5e6 100644 --- a/gentoobrowse-api/unittests/Jamfile.jam +++ b/gentoobrowse-api/unittests/Jamfile.jam @@ -15,6 +15,7 @@ alias test-data : lib testCommon : mockDefs.cpp + mocks.ice : dbpp-postgresql ..//dbppcore @@ -63,6 +64,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testChangeLog ; run @@ -79,6 +81,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testMaintenance ; run @@ -87,6 +90,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testPortage ; run @@ -95,6 +99,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testUsers ; run @@ -103,6 +108,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testNotifications ; run @@ -111,6 +117,7 @@ run ../db/schema.sql BOOST_TEST_DYN_LINK testCommon + testCommon : testBugs ; explicit testPerf ; diff --git a/gentoobrowse-api/unittests/mockDefs.cpp b/gentoobrowse-api/unittests/mockDefs.cpp index eeab5f2..cfe426b 100644 --- a/gentoobrowse-api/unittests/mockDefs.cpp +++ b/gentoobrowse-api/unittests/mockDefs.cpp @@ -1,14 +1,25 @@ #include "mockDefs.h" #include +#include + +void +MockMailServerImpl::sendEmail(const Gentoo::EmailPtr & e, const Ice::Current &) +{ + sentEmails.push_back(e); +} + +Gentoo::Emails +MockMailServerImpl::getSentEmails(const Ice::Current &) +{ + return sentEmails; +} Service::Service() : - IceTray::DryIce({ - "--GentooBrowseAPI.MailServer=smtp.random.lan:25", - }), PQ::Mock("user=postgres dbname=postgres", "GentooBrowseAPI", { rootDir.parent_path() / "db" / "schema.sql", rootDir / "data.sql" }) { + replace("mailserver", new MockMailServerImpl()); } Maintenance::Maintenance() : @@ -19,6 +30,14 @@ Maintenance::Maintenance() : PQ::Mock("user=postgres dbname=postgres", "GentooBrowseAPI", { rootDir.parent_path() / "db" / "schema.sql", rootDir / "basedata.sql" }) +{ + replace("mailserver", new MockMailServerImpl()); +} + +Mail::Mail() : + IceTray::DryIce({ + "--GentooBrowseAPI.MailServer=smtp.random.lan:25", + }) { } diff --git a/gentoobrowse-api/unittests/mockDefs.h b/gentoobrowse-api/unittests/mockDefs.h index a0c044a..5bb1cd5 100644 --- a/gentoobrowse-api/unittests/mockDefs.h +++ b/gentoobrowse-api/unittests/mockDefs.h @@ -8,8 +8,18 @@ #include #include #include +#include #include +class MockMailServerImpl : public Gentoo::MockMailServer { + public: + void sendEmail(const Gentoo::EmailPtr & msg, const Ice::Current &) override; + Gentoo::Emails getSentEmails(const Ice::Current &) override; + + private: + Gentoo::Emails sentEmails; +}; + class DLL_PUBLIC Service : public IceTray::DryIce, PQ::Mock { public: Service(); @@ -20,6 +30,11 @@ class DLL_PUBLIC Maintenance : public IceTray::DryIce, PQ::Mock { Maintenance(); }; +class DLL_PUBLIC Mail : public IceTray::DryIce { + public: + Mail(); +}; + class DLL_PUBLIC TestClient : public IceTray::DryIceClient { public: TestClient(); diff --git a/gentoobrowse-api/unittests/mocks.ice b/gentoobrowse-api/unittests/mocks.ice new file mode 100644 index 0000000..f780d59 --- /dev/null +++ b/gentoobrowse-api/unittests/mocks.ice @@ -0,0 +1,15 @@ +#ifndef GENTOO_MOCKS +#define GENTOO_MOCKS + +#include + +module Gentoo { + sequence Emails; + + interface MockMailServer extends MailServer { + Emails getSentEmails(); + }; +}; + +#endif + diff --git a/gentoobrowse-api/unittests/testNotifications.cpp b/gentoobrowse-api/unittests/testNotifications.cpp index 5596e62..21a76a5 100644 --- a/gentoobrowse-api/unittests/testNotifications.cpp +++ b/gentoobrowse-api/unittests/testNotifications.cpp @@ -5,7 +5,7 @@ #include #include -BOOST_GLOBAL_FIXTURE( Service ); +BOOST_GLOBAL_FIXTURE( Mail ); BOOST_FIXTURE_TEST_SUITE(tp, TestClient); -- cgit v1.2.3