示例#1
0
void RestClientTests::testGet() {
    RestClient client;
    QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors")));
    QCOMPARE(client.statusCode(), 200);

    QJsonObject jsonRootObject = jsonResponse->object();

    QJsonValue value = jsonRootObject.value("data");
    QJsonArray jsonArray = value.toArray();

    QCOMPARE(jsonArray.count(), 6);

    foreach (const QJsonValue& current, jsonArray) {
        QVERIFY(!current.toObject().value("name").toString().isEmpty());
        QVERIFY(!current.toObject().value("value").toString().isEmpty());
    }
示例#2
0
void getColors() {
    qDebug() << "########## GET REQUEST TEST ##########";
    qDebug() << "########## GET LIST ##########";

    RestClient client;
    QJsonDocument* jsonResponse = client.getJson(QUrl(QString("http://localhost:5000/api/colors")));

    qDebug() << "Response: " << jsonResponse->toJson();

    QJsonObject jsonRootObject = jsonResponse->object();

    QJsonValue value = jsonRootObject.value("data");
    QJsonArray jsonArray = value.toArray();

    foreach (const QJsonValue& current, jsonArray) {
        qDebug() << "Name: " << current.toObject().value("name").toString();
        qDebug() << "Value: " << current.toObject().value("value").toString();
    }