summaryrefslogtreecommitdiffstats
path: root/framework/actions/tests/actiontest.cpp
diff options
context:
space:
mode:
authorChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-01 13:37:19 +0100
committerChristian Mollekopf <chrigi_1@fastmail.fm>2017-01-02 00:31:41 +0100
commitba7128b30850594c7efb258d1794e377eede364a (patch)
treef805d511f6d12b0799c05b414054db8b8635bfc9 /framework/actions/tests/actiontest.cpp
parent431c257dd29e2e3d8878db200f0de4d452bffe92 (diff)
downloadkube-ba7128b30850594c7efb258d1794e377eede364a.tar.gz
kube-ba7128b30850594c7efb258d1794e377eede364a.zip
Instead of using the action system we use controllers only.
It's simpler, and the action system was just too complex to use in a typesafe way.
Diffstat (limited to 'framework/actions/tests/actiontest.cpp')
-rw-r--r--framework/actions/tests/actiontest.cpp102
1 files changed, 102 insertions, 0 deletions
diff --git a/framework/actions/tests/actiontest.cpp b/framework/actions/tests/actiontest.cpp
new file mode 100644
index 00000000..a4ec4432
--- /dev/null
+++ b/framework/actions/tests/actiontest.cpp
@@ -0,0 +1,102 @@
1#include <QTest>
2#include <QDebug>
3#include <QSignalSpy>
4
5#include <actions/action.h>
6#include <actions/context.h>
7#include <actions/actionhandler.h>
8
9#include <sink/log.h>
10
11SINK_DEBUG_AREA("actiontest")
12
13class HandlerContext : public Kube::Context {
14 Q_OBJECT
15 KUBE_CONTEXT_PROPERTY(QString, Property1, property1)
16 KUBE_CONTEXT_PROPERTY(QString, Property2, property2)
17};
18
19class HandlerContextWrapper : public Kube::ContextWrapper {
20 using Kube::ContextWrapper::ContextWrapper;
21 KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property1, property1)
22 KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property2, property2)
23};
24
25
26
27class Handler : public Kube::ActionHandlerBase<HandlerContextWrapper>
28{
29public:
30 Handler() : Kube::ActionHandlerBase<HandlerContextWrapper>{"org.kde.kube.test.action1"}
31 {}
32
33 //TODO default implementation checks that all defined properties are available in the context
34 // bool isReady() override {
35 // auto accountId = context->property("accountId").value<QByteArray>();
36 // return !accountId.isEmpty();
37 // }
38
39 KAsync::Job<void> execute(HandlerContextWrapper &context)
40 {
41 SinkLog() << "Executing action1";
42 SinkLog() << context;
43 executions.append(context.context);
44 return KAsync::null<void>();
45 }
46 mutable QList<Kube::Context> executions;
47};
48
49class Context1 : public Kube::ContextWrapper {
50 using Kube::ContextWrapper::ContextWrapper;
51 KUBE_CONTEXTWRAPPER_PROPERTY(QString, Property1, property1)
52 KUBE_CONTEXTWRAPPER_PROPERTY(QByteArray, Property2, property2)
53};
54
55class Context2 : public Kube::ContextWrapper {
56 using Kube::ContextWrapper::ContextWrapper;
57 KUBE_CONTEXTWRAPPER_PROPERTY(QByteArray, Property2, property2)
58};
59
60
61class ActionTest : public QObject
62{
63 Q_OBJECT
64private slots:
65
66 void initTestCase()
67 {
68 }
69
70 void testActionExecution()
71 {
72 Handler actionHandler;
73
74 HandlerContext context;
75 //Kube::Context context;
76 HandlerContextWrapper{context}.setProperty1(QString("property1"));
77 context.setProperty("property2", QVariant::fromValue(QString("property2")));
78 auto future = Kube::Action("org.kde.kube.test.action1", context).executeWithResult();
79
80 QTRY_VERIFY(future.isDone());
81 QVERIFY(!future.error());
82
83 QCOMPARE(actionHandler.executions.size(), 1);
84 QCOMPARE(actionHandler.executions.first().availableProperties().size(), 2);
85 }
86
87 void testContextCasting()
88 {
89 Kube::Context c;
90
91 Context1 context1{c};
92 context1.setProperty1("property1");
93 context1.setProperty2("property2");
94
95 auto context2 = Context2{c};
96 QCOMPARE(context2.getProperty2(), QByteArray("property2"));
97 }
98
99};
100
101QTEST_GUILESS_MAIN(ActionTest)
102#include "actiontest.moc"