Changeset View
Changeset View
Standalone View
Standalone View
src/bugzillaintegration/libbugzilla/autotests/producttest.cpp
- This file was added.
1 | #include <QDebug> | ||||
---|---|---|---|---|---|
2 | #include <QTest> | ||||
3 | | ||||
4 | #include "../product.h" | ||||
5 | | ||||
6 | namespace Bugzilla | ||||
7 | { | ||||
8 | | ||||
9 | #warning fixme move to utils file | ||||
10 | class JobDouble : public APIJob | ||||
11 | { | ||||
12 | Q_OBJECT | ||||
13 | public: | ||||
14 | using APIJob::APIJob; | ||||
15 | | ||||
16 | JobDouble(QString fixture) | ||||
17 | : m_fixture(fixture) | ||||
18 | { | ||||
19 | } | ||||
20 | | ||||
21 | virtual QByteArray data() const override | ||||
22 | { | ||||
23 | Q_ASSERT(!m_fixture.isEmpty()); | ||||
24 | QFile file(m_fixture); | ||||
25 | Q_ASSERT(file.open(QFile::ReadOnly | QFile::Text)); | ||||
26 | QTextStream in(&file); | ||||
27 | return in.readAll().toUtf8(); | ||||
28 | } | ||||
29 | | ||||
30 | QString m_fixture; | ||||
31 | }; | ||||
32 | | ||||
33 | #warning fixme see if we can maybe share across tests | ||||
34 | class ConnectionDouble : public Connection | ||||
35 | { | ||||
36 | public: | ||||
37 | using Connection::Connection; | ||||
38 | | ||||
39 | virtual void setToken(const QString &) override | ||||
40 | { | ||||
41 | Q_UNREACHABLE(); | ||||
42 | } | ||||
43 | | ||||
44 | virtual APIJob *get(const QString &path, | ||||
45 | const QUrlQuery &query = QUrlQuery()) const override | ||||
46 | { | ||||
47 | if (path == "/product/dragonplayer") { | ||||
48 | return new JobDouble { QFINDTESTDATA("data/product.dragonplayer.json") }; | ||||
49 | } | ||||
50 | Q_ASSERT_X(false, "get", | ||||
51 | qUtf8Printable(QStringLiteral("unmapped: %1; %2").arg(path, query.toString()))); | ||||
52 | return nullptr; | ||||
53 | } | ||||
54 | | ||||
55 | virtual APIJob *post(const QString &path, | ||||
56 | const QByteArray &data, | ||||
57 | const QUrlQuery &query = QUrlQuery()) const override | ||||
58 | { | ||||
59 | qDebug() << path << query.toString(); | ||||
60 | Q_UNREACHABLE(); | ||||
61 | return nullptr; | ||||
62 | } | ||||
63 | | ||||
64 | virtual APIJob *put(const QString &, | ||||
65 | const QByteArray &, | ||||
66 | const QUrlQuery & = QUrlQuery()) const override | ||||
67 | { | ||||
68 | Q_UNREACHABLE(); | ||||
69 | } | ||||
70 | }; | ||||
71 | | ||||
72 | class ProductTest : public QObject | ||||
73 | { | ||||
74 | Q_OBJECT | ||||
75 | private Q_SLOTS: | ||||
76 | void initTestCase() | ||||
77 | { | ||||
78 | Bugzilla::setConnection(m_doubleConnection); | ||||
79 | } | ||||
80 | | ||||
81 | void testProduct() | ||||
82 | { | ||||
83 | KJob *job = Bugzilla::ProductClient().get("dragonplayer"); | ||||
84 | Q_ASSERT(job); | ||||
85 | job->start(); | ||||
86 | Product::Ptr product = Bugzilla::ProductClient().get(job); | ||||
87 | QCOMPARE(product->isActive(), true); | ||||
88 | Q_ASSERT(!product->components().isEmpty()); | ||||
89 | Q_ASSERT(!product->versions().isEmpty()); | ||||
90 | } | ||||
91 | | ||||
92 | private: | ||||
93 | Bugzilla::ConnectionDouble *m_doubleConnection = new Bugzilla::ConnectionDouble; | ||||
94 | }; | ||||
95 | | ||||
96 | } // namespace Bugzilla | ||||
97 | | ||||
98 | QTEST_MAIN(Bugzilla::ProductTest) | ||||
99 | | ||||
100 | #include "producttest.moc" |