source: src/tests/siwebserviceclienttest.cpp

Last change on this file was 93ea008, checked in by Joachim Langenbach <joachim.langenbach@…>, 11 years ago

Command line client is now (nearly) able to register a station

  • Property mode set to 100644
File size: 4.0 KB
RevLine 
[915dc18]1/*
2 Copyright (C) 2015 EngSaS - Engineering Solutions and Services Langenbach. All rights reserved.
3
4 This library is free software; you can redistribute it and/or
5 modify it under the terms of the GNU Lesser General Public
6 License as published by the Free Software Foundation; either
7 version 2.1 of the License, or (at your option) any later version.
8
9 This library is distributed in the hope that it will be useful,
10 but WITHOUT ANY WARRANTY; without even the implied warranty of
11 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 Lesser General Public License for more details.
13
14 You should have received a copy of the GNU Lesser General Public
15 License along with this library; if not, write to the Free Software
16 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
17 MA 02110-1301 USA.
18*/
19
20#include "siwebserviceclient.h"
21#include "moc_siwebserviceclienttest.cpp"
22
23#include <siwebserviceclient.h>
24#include <siweatherstation.h>
25
26#include <webserverprocess.h>
27
28#include <QTest>
29#include <QSignalSpy>
30
31using namespace SiWeather::Library;
32
33void SiWebserviceClientTest::initTestCase()
34{
35 _webserverProcess = new WebserverProcess(this);
[a2330fc]36 QCOMPARE(_webserverProcess->start(), true);
37 QCOMPARE(_webserverProcess->isRunning(), true);
38 QCOMPARE(_webserverProcess->setup(), true);
[915dc18]39}
40
[a2330fc]41void SiWebserviceClientTest::cleanupTestCase()
[915dc18]42{
43 QVERIFY(_webserverProcess);
[a2330fc]44 QCOMPARE(_webserverProcess->stop(), true);
[915dc18]45}
46
47void SiWebserviceClientTest::apiVersion()
48{
49 QVERIFY(_webserverProcess);
50 QCOMPARE(_webserverProcess->isRunning(), true);
51
52 SiWebserviceClient *client = new SiWebserviceClient(_webserverProcess->webserviceBaseUrl(), this);
53 QCOMPARE(client->apiVersion(), _webserverProcess->webserviceApiVersion());
54
55 delete client;
56}
57
58void SiWebserviceClientTest::stationsRegister()
59{
60 QVERIFY(_webserverProcess);
61 QCOMPARE(_webserverProcess->isRunning(), true);
62
63 SiWebserviceClient *client = new SiWebserviceClient(_webserverProcess->webserviceBaseUrl(), this);
64 QSignalSpy spyError(client, SIGNAL(error(SiWeather::Library::SiWebserviceClient::ReplyType, const QString&)));
65 QSignalSpy spyFinished(client, SIGNAL(finished(SiWeather::Library::SiWebserviceClient::ReplyType, bool, const QByteArray&)));
66 QSignalSpy spyFinishedStationsRegister(client, SIGNAL(finishedStationsRegister(bool, const QUuid&, const QString&)));
67 QString errorMessage;
68
69 SiWeatherStation station;
70 QCOMPARE(client->stationsRegister(station, errorMessage), SiWebserviceClient::Error);
71 QCOMPARE(errorMessage.isEmpty(), false);
72 QCOMPARE(spyError.count(), 0);
73 QCOMPARE(spyFinished.count(), 0);
74 QCOMPARE(spyFinishedStationsRegister.count(), 0);
75
76 spyError.clear();
77 spyFinished.clear();
78 spyFinishedStationsRegister.clear();
79 errorMessage.clear();
80 station.setName("Test Station Name");
81 station.setCity("New York");
82 station.setEMail("test@example.org");
83 station.setLatitude(40.712778);
84 station.setLongitude(-74.005833);
85 station.setType("Test Type");
86
[93ea008]87 QCOMPARE(station.isValidForRegister(), true);
[915dc18]88 QCOMPARE(client->stationsRegister(station, errorMessage), SiWebserviceClient::StationsRegister);
89 QTest::qWarn(errorMessage.toUtf8());
90 QCOMPARE(errorMessage.isEmpty(), true);
91
92 // use long timeout to allow webservice query for geolocation!
93 QTime dieTime = QTime::currentTime().addSecs(10);
94 while(QTime::currentTime() < dieTime){
95 QCoreApplication::processEvents(QEventLoop::ExcludeUserInputEvents, 100);
96 if(spyError.count() != 0 || spyFinished.count() != 0)
97 break;
98 }
99
100 if(spyError.count() > 0){
101 QVariantList data = spyError.takeFirst();
102 QCOMPARE(data.count(), 2);
103 QWARN(data[1].toString().toUtf8());
104 }
105 QCOMPARE(spyError.count(), 0);
106 QCOMPARE(spyFinished.count(), 1);
107 QCOMPARE(spyFinishedStationsRegister.count(), 1);
108 QVariantList data = spyFinishedStationsRegister.takeFirst();
109 QCOMPARE(data.count(), 3);
[a2330fc]110 if(!data[0].toBool()){
111 QTest::qWarn(data[2].toString().toUtf8());
112 }
[915dc18]113 QCOMPARE(data[0].toBool(), true);
114 QCOMPARE(data[1].toUuid().isNull(), false);
115 QCOMPARE(data[2].toString().isEmpty(), false);
116
117 delete client;
118}
119
120QTEST_MAIN(SiWebserviceClientTest)
Note: See TracBrowser for help on using the repository browser.