mirror of
https://gitlab.com/spaceti-app/integrations/acs/colnod-connector.git
synced 2026-07-12 20:50:37 +02:00
172 lines
6.2 KiB
C++
172 lines
6.2 KiB
C++
#include "unittest.h"
|
|
|
|
void UnitTest::loginSuccessfully()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QJsonDocument config = testAccess->getConfig();
|
|
QSignalSpy spy(testAccess, SIGNAL(successLogin()));
|
|
testAccess->login(host, email, password);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString json = testAccess->getResponse();
|
|
qDebug() << json;
|
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
QVERIFY2(doc.object().value("id").isString(), "No parameter 'id' in response");
|
|
}
|
|
|
|
//POST request w/o datas
|
|
void UnitTest::getSubjects()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getSubjects();
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString json = testAccess->getResponse();
|
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
QVERIFY(doc.isObject());
|
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
|
qDebug() << doc.object().value("items").toArray()[0].toObject()["id"].toString();
|
|
QVERIFY2(doc.object().value("items").toArray()[0].toObject()["id"].isString(), "ada");
|
|
|
|
}
|
|
|
|
void UnitTest::getTokens()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getTokens();
|
|
QCOMPARE(spy.count(), 0);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString json = testAccess->getResponse();
|
|
QJsonDocument doc = QJsonDocument::fromJson(json.toUtf8());
|
|
QVERIFY(doc.isObject());
|
|
QVERIFY2(doc.object().value("items").isArray(), "No parameter 'id' in response");
|
|
qDebug() << doc.object().value("items").toArray()[0].toObject()["id"].toString();
|
|
QVERIFY2(doc.object().value("items").toArray()[0].toObject()["id"].isString(), "ada");
|
|
}
|
|
|
|
void UnitTest::getTokenSubject()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getTokenSubject();
|
|
QCOMPARE(spy.count(), 0);
|
|
spy.wait();
|
|
QVERIFY(spy.isValid());
|
|
QCOMPARE(spy.count(), 1);
|
|
QString response = testAccess->getResponse();
|
|
qDebug() << response;
|
|
QVERIFY(!response.isEmpty());
|
|
}
|
|
|
|
void UnitTest::subjectJSONParser()
|
|
{
|
|
/*
|
|
QFile jsonData(QDir::current().filePath("subjects.json"));
|
|
|
|
if (!jsonData.open(QIODevice::ReadOnly)) {
|
|
qCritical() << "Couldn't open config file config.json" << QDir::current().filePath("subjects.json");
|
|
QCoreApplication::exit(-1);
|
|
return;
|
|
}
|
|
|
|
QJsonDocument doc = QJsonDocument::fromJson(jsonData.readAll());
|
|
QJsonObject obj = doc.object();
|
|
QJsonArray arr = obj["items"].toArray();
|
|
*/
|
|
|
|
RequestManager* testAccess = new RequestManager();
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getSubjects();
|
|
spy.wait();
|
|
QString response = testAccess->getResponse();
|
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
|
QJsonArray arr = doc.object()["items"].toArray();
|
|
auto testSubject = new Subject();
|
|
testSubject->fromJSON(arr[1].toObject());
|
|
qDebug() << testSubject->getName() << " Size: " << arr.size();
|
|
QVERIFY(!testSubject->getName().isEmpty());
|
|
}
|
|
|
|
void UnitTest::tokenJSONParser()
|
|
{
|
|
RequestManager* testAccess = new RequestManager();
|
|
QSignalSpy spy(testAccess, SIGNAL(responseReady()));
|
|
testAccess->getTokens();
|
|
spy.wait();
|
|
QString response = testAccess->getResponse();
|
|
QJsonDocument doc = QJsonDocument::fromJson(response.toUtf8());
|
|
QJsonArray arr = doc.object()["items"].toArray();
|
|
auto testToken = new Token();
|
|
testToken->fromJSON(arr[5].toObject());
|
|
qDebug() << testToken->getName() << " Size: " << arr.size();
|
|
QVERIFY(!testToken->getName().isEmpty());
|
|
}
|
|
|
|
void UnitTest::connectToDB()
|
|
{
|
|
DatabaseManager *db = new DatabaseManager("192.168.1.94", "deloitte", "postgres", "34rjkciea12");
|
|
QVERIFY(db->getOpened());
|
|
qDebug() << db->getTestMessage(1);
|
|
QVERIFY(true);
|
|
QCOMPARE(db->getTestMessage(1), QStringLiteral("Hello world"));
|
|
db->createTestRecord("Now it's diffrent");
|
|
QCOMPARE(db->getTestMessage(2), QStringLiteral("Does it work?"));
|
|
}
|
|
|
|
void UnitTest::debugConnection()
|
|
{
|
|
QSslSocket ssl;// = new QSslSocket();
|
|
ssl.connectToHostEncrypted("192.168.1.3", 8443);
|
|
ssl.ignoreSslErrors();
|
|
if (!ssl.waitForEncrypted())
|
|
{
|
|
qDebug() << ssl.errorString();
|
|
}
|
|
QString tmp = "POST /AaaManager/authSession HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic c3BhY2V0aTpFN0ZFQTA3REJDODJGQjlCQTM0QjJFNDUzRTJFRkU4OUYwNTgzRTcxODc1NDM1MDdFRjExRTg0NzI2MDcxRkU0Mjg0NDUzNzJGMkU0NkI0NTVFQjBDNzk3NDdDNTFFMzYyRjQwM0NFMzk0NzNBMkE4QzJERkEwQ0U1Qzk4MjZDMA==\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\nContent-Type: application/json\r\nContent-Length: 164\r\n\r\n{\"password\":\"E7FEA07DBC82FB9BA34B2E453E2EFE89F0583E7187543507EF11E84726071FE428445372F2E46B455EB0C79747C51E362F403CE39473A2A8C2DFA0CE5C9826C0\",\"username\":\"spaceti\"}";
|
|
qDebug().noquote() << tmp.toUtf8();
|
|
ssl.write(tmp.toUtf8());
|
|
QString data;
|
|
while (ssl.waitForReadyRead() && data.isEmpty())
|
|
{
|
|
data.append(ssl.readAll().data());
|
|
}
|
|
qDebug().noquote() << data;
|
|
int index = data.lastIndexOf("id");
|
|
QString tkn = data.mid( index + 5, 36);
|
|
tkn = tkn + ":";
|
|
qDebug() << "parsed token : " <<tkn;
|
|
tmp = "POST /SubjectManager/getSubjects HTTP/1.1\r\nHost: 192.168.1.3:8443\r\nAuthorization: Basic " + tkn.toUtf8().toBase64() + "\r\nUser-Agent: curl/7.65.3\r\nAccept: */*\r\n\r\n";
|
|
QFile file("output1234.txt");
|
|
file.open(QIODevice::ReadWrite);
|
|
QTextStream st(&file);
|
|
st << tmp;
|
|
file.close();
|
|
qDebug().noquote() << tmp.toUtf8();
|
|
ssl.write(tmp.toUtf8());
|
|
while (ssl.waitForReadyRead())
|
|
{
|
|
qDebug() << ssl.readAll().data();
|
|
}
|
|
qDebug() << ssl.errorString();
|
|
|
|
QVERIFY(true);
|
|
}
|
|
|
|
void UnitTest::saveDataToDB()
|
|
{
|
|
DataManager* dataMan = new DataManager();
|
|
|
|
// dataMan->localSaveTokens();
|
|
QVERIFY(true);
|
|
|
|
}
|
|
|
|
|
|
QTEST_MAIN(UnitTest)
|