Skip to content

Commit

Permalink
Fixed tests
Browse files Browse the repository at this point in the history
Signed-off-by: Lennart Sauerbeck <lennart.sauerbeck@sevencs.com>
  • Loading branch information
Lennart Sauerbeck committed Aug 31, 2017
1 parent e018320 commit 41a896a
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 16 deletions.
22 changes: 14 additions & 8 deletions test/qttptest/qttptest.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,16 +198,18 @@ void QttpTest::initTestCase()
QVERIFY(httpSvr->initialize() == true);

auto action = httpSvr->createAction("", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "C++ FTW";
data.getResponse().getJson().setObject(json);
});

httpSvr->addProcessor<SampleProcessor>();

action = httpSvr->createAction("echo", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
auto& query = data.getRequest().getQuery();
json["response"] = "C++ FTW " + query.queryItemValue("id");
data.getResponse().getJson().setObject(json);
});

auto result = httpSvr->registerRoute("get", "", "/echo/:id");
Expand All @@ -217,8 +219,9 @@ void QttpTest::initTestCase()
QVERIFY(result == true);

action = httpSvr->createAction("echobody", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
json["response"] = data.getRequest().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = data.getRequest().getJson().object();
data.getResponse().getJson().setObject(json);
});

result = httpSvr->registerRoute("post", "echobody", "/echobody");
Expand Down Expand Up @@ -257,8 +260,9 @@ void QttpTest::initTestCase()

// Uses a raw std::function based callback.
action = httpSvr->createAction("test", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Test C++ FTW";
data.getResponse().getJson().setObject(json);

// NOTE: This terminates early so we should not expect any post-processing.
data.getResponse().finish();
Expand All @@ -272,8 +276,9 @@ void QttpTest::initTestCase()
QVERIFY(result == true);

action = httpSvr->createAction("terminates", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Test C++ FTW";
data.getResponse().getJson().setObject(json);
// NOTE: This terminates early so we should not expect any post-processing.
data.getResponse().terminate();
});
Expand All @@ -283,9 +288,10 @@ void QttpTest::initTestCase()
QVERIFY(result == true);

action = httpSvr->createAction("regex", [](HttpData& data) {
QJsonObject& json = data.getResponse().getJson();
QString name = data.getRequest().getJson()["name"].toString();
QJsonObject json = data.getResponse().getJson().object();
QString name = data.getRequest().getJson().object()["name"].toString();
json["response"] = name;
data.getResponse().getJson().setObject(json);
});

result = httpSvr->registerRoute(qttp::GET, "regex", "/regex/:name([A-Za-z]+)");
Expand Down
26 changes: 18 additions & 8 deletions test/qttptest/qttptest.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,9 @@ class SampleAction : public Action
void onAction(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW";
data.getResponse().getJson().setObject(json);
}

const char* getName() const
Expand All @@ -36,29 +37,33 @@ class SampleActionWithHttpMethods : public Action
void onGet(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW Get";
data.getResponse().getJson().setObject(json);
}

void onPost(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW Post";
data.getResponse().getJson().setObject(json);
}

void onPut(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW Put";
data.getResponse().getJson().setObject(json);
}

void onDelete(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW Delete";
data.getResponse().getJson().setObject(json);
}

const char* getName() const
Expand All @@ -77,8 +82,9 @@ class ActionWithParameter : public Action
void onAction(HttpData& data)
{
TEST_TRACE;
QJsonObject& json = data.getResponse().getJson();
QJsonObject json = data.getResponse().getJson().object();
json["response"] = "Sample C++ FTW With Parameter " + m_Param;
data.getResponse().getJson().setObject(json);
}

const char* getName() const
Expand All @@ -100,13 +106,17 @@ class SampleProcessor : public Processor
void preprocess(HttpData& data)
{
TEST_TRACE;
data.getResponse().getJson()["preprocess"] = true;
QJsonObject obj = data.getResponse().getJson().object();
obj["preprocess"] = true;
data.getResponse().getJson().setObject(obj);
}

void postprocess(HttpData& data)
{
TEST_TRACE;
data.getResponse().getJson()["postprocess"] = true;
QJsonObject obj = data.getResponse().getJson().object();
obj["postprocess"] = true;
data.getResponse().getJson().setObject(obj);
}
};

Expand Down

0 comments on commit 41a896a

Please sign in to comment.