2017-07-03 09:30:10 +02:00
|
|
|
/*!
|
|
|
|
* \brief Unit tests for \ref PaosCreator
|
|
|
|
*
|
2019-05-22 10:08:38 +02:00
|
|
|
* \copyright Copyright (c) 2015-2019 Governikus GmbH & Co. KG, Germany
|
2017-07-03 09:30:10 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
#include "paos/invoke/PaosCreator.h"
|
|
|
|
|
|
|
|
#include "LogHandler.h"
|
|
|
|
|
|
|
|
#include <QtCore>
|
|
|
|
#include <QtTest>
|
|
|
|
|
|
|
|
using namespace governikus;
|
|
|
|
|
|
|
|
namespace
|
|
|
|
{
|
|
|
|
struct test_PaosCreatorDummy
|
|
|
|
: public PaosCreator
|
|
|
|
{
|
|
|
|
QString mText;
|
|
|
|
bool mNamespace = false;
|
2019-01-03 15:06:22 +01:00
|
|
|
const QString mTag = QStringLiteral("content");
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
virtual void createBodyElement() override
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
|
|
|
if (mNamespace)
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
mWriter.writeTextElement(getNamespaceType(Namespace::SOAP, mTag), mText);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
mWriter.writeTextElement(mTag, mText);
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
2019-01-03 15:06:22 +01:00
|
|
|
} // namespace
|
2017-07-03 09:30:10 +02:00
|
|
|
|
|
|
|
|
|
|
|
class test_PaosCreator
|
|
|
|
: public QObject
|
|
|
|
{
|
|
|
|
Q_OBJECT
|
|
|
|
|
|
|
|
private Q_SLOTS:
|
|
|
|
void initTestCase()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<LogHandler>()->init();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void cleanup()
|
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
Env::getSingleton<LogHandler>()->resetBacklog();
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void marshall()
|
|
|
|
{
|
|
|
|
test_PaosCreatorDummy creator;
|
|
|
|
QByteArray elem = creator.marshall();
|
|
|
|
|
|
|
|
QVERIFY(elem.contains("<content></content>"));
|
|
|
|
|
|
|
|
creator.mText = "some test";
|
|
|
|
elem = creator.marshall();
|
|
|
|
QVERIFY(elem.contains("<content></content>")); // marshall() can be called once!
|
|
|
|
|
|
|
|
test_PaosCreatorDummy creator2;
|
|
|
|
creator2.mText = "hello again";
|
|
|
|
creator2.mNamespace = true;
|
|
|
|
elem = creator2.marshall();
|
|
|
|
QVERIFY(elem.contains("<soap:content>hello again</soap:content>"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
void checkRelatesTo_data()
|
2017-07-03 09:30:10 +02:00
|
|
|
{
|
2019-01-03 15:06:22 +01:00
|
|
|
QTest::addColumn<QString>("relatesTo");
|
|
|
|
|
|
|
|
QTest::newRow("empty") << QString();
|
|
|
|
QTest::newRow("related") << QStringLiteral("first one");
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void checkRelatesTo()
|
|
|
|
{
|
|
|
|
QFETCH(QString, relatesTo);
|
|
|
|
|
2017-07-03 09:30:10 +02:00
|
|
|
test_PaosCreatorDummy creator;
|
2019-01-03 15:06:22 +01:00
|
|
|
creator.setRelatedMessageId(relatesTo);
|
|
|
|
QByteArray data = creator.marshall();
|
2017-07-03 09:30:10 +02:00
|
|
|
|
2019-01-03 15:06:22 +01:00
|
|
|
QCOMPARE(data.contains("RelatesTo>"), !relatesTo.isNull());
|
|
|
|
QVERIFY(data.contains("<wsa:MessageID>urn:uuid:"));
|
2017-07-03 09:30:10 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
void namespaces()
|
|
|
|
{
|
|
|
|
static int count = 8;
|
|
|
|
|
|
|
|
QCOMPARE(PaosCreator::mNamespace.count(), count);
|
|
|
|
QCOMPARE(PaosCreator::mNamespacePrefix.count(), count + 1); // + DEFAULT
|
|
|
|
|
|
|
|
QCOMPARE(PaosCreator::mNamespace.value(PaosCreator::Namespace::ADDRESSING), QString("http://www.w3.org/2005/03/addressing"));
|
|
|
|
QCOMPARE(PaosCreator::mNamespacePrefix.value(PaosCreator::Namespace::ADDRESSING), QString("wsa"));
|
|
|
|
|
|
|
|
QCOMPARE(PaosCreator::getNamespace(PaosCreator::Namespace::ADDRESSING), QString("http://www.w3.org/2005/03/addressing"));
|
|
|
|
QCOMPARE(PaosCreator::getNamespacePrefix(PaosCreator::Namespace::ADDRESSING, "suffix"), QString("wsa:suffix"));
|
|
|
|
QCOMPARE(PaosCreator::getNamespacePrefix(PaosCreator::Namespace::ADDRESSING), QString("xmlns:wsa"));
|
|
|
|
QCOMPARE(PaosCreator::getNamespaceType(PaosCreator::Namespace::ADDRESSING, "test"), QString("wsa:test"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
QTEST_GUILESS_MAIN(test_PaosCreator)
|
|
|
|
#include "test_PaosCreator.moc"
|