1 /****************************************************************************** 2 3 This source file is part of the MoleQueue project. 4 5 Copyright 2012 Kitware, Inc. 6 7 This source code is released under the New BSD License, (the "License"). 8 9 Unless required by applicable law or agreed to in writing, software 10 distributed under the License is distributed on an "AS IS" BASIS, 11 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 12 See the License for the specific language governing permissions and 13 limitations under the License. 14 15 ******************************************************************************/ 16 17 #include <QtTest> 18 #include <QtXmlPatterns/QXmlQuery> 19 #include <QtCore/QList> 20 #include <QtNetwork/QSslSocket> 21 #include <QtNetwork/QNetworkRequest> 22 #include <QtNetwork/QNetworkReply> 23 #include <QtNetwork/QSslConfiguration> 24 25 #include "queues/uit/sslsetup.h" 26 #include "queues/queueuit.h" 27 #include "dummyserver.h" 28 #include "xmlutils.h" 29 #include "referencestring.h" 30 #include "queues/uit/jobeventlist.h" 31 #include "jobmanager.h" 32 33 class QueueUitTest : public QObject 34 { 35 Q_OBJECT 36 37 private slots: 38 void testSslSetup(); 39 void testJobIdRegex(); 40 void testHandleQueueUpdate(); 41 }; 42 testSslSetup()43void QueueUitTest::testSslSetup() 44 { 45 qRegisterMetaType<QList<QSslError> >("QList<QSslError>"); 46 47 MoleQueue::Uit::SslSetup::init(); 48 49 QSslSocket socket; 50 51 // Does our Qt have SSL support? 52 QVERIFY(socket.supportsSsl()); 53 54 socket.connectToHostEncrypted( "www.uit.hpc.mil", 443 ); 55 56 socket.write( "GET / HTTP/1.1\r\n" \ 57 "Host: www.uit.hpc.mil\r\n" \ 58 "Connection: Close\r\n\r\n" ); 59 60 QSignalSpy spy (&socket, SIGNAL(sslErrors(const QList<QSslError>&))); 61 62 while ( socket.waitForReadyRead() ) { 63 qDebug() << socket.readAll().data(); 64 } 65 66 // If SSL certificates are setup correctly we shouldn't get any errors ... 67 QCOMPARE(spy.count(), 0); 68 } 69 testJobIdRegex()70void QueueUitTest::testJobIdRegex() 71 { 72 QString submissionOutput = "Job <75899> is submitted to debug queue."; 73 QRegExp parser ("^Job <(\\d+)> .*"); 74 75 parser.indexIn(submissionOutput); 76 QCOMPARE(parser.cap(1), QString("75899")); 77 } 78 testHandleQueueUpdate()79void QueueUitTest::testHandleQueueUpdate() 80 { 81 DummyServer server; 82 83 MoleQueue::JobManager *jobManager = server.jobManager(); 84 MoleQueue::Job jobQueuedRemote = jobManager->newJob(); 85 jobQueuedRemote.setMoleQueueId(100535); 86 jobQueuedRemote.setQueueId(100535); 87 88 MoleQueue::Job jobRunningRemote = jobManager->newJob(); 89 jobRunningRemote.setMoleQueueId(100536); 90 jobRunningRemote.setQueueId(100536); 91 92 93 MoleQueue::QueueUit queue(server.queueManager()); 94 queue.m_jobs[100535] = 100535; 95 queue.m_jobs[100536] = 100536; 96 97 QString m_jobEventXml 98 = XmlUtils::stripWhitespace( 99 ReferenceString("uit-ref/jobeventlist.xml")); 100 101 MoleQueue::Uit::JobEventList list 102 = MoleQueue::Uit::JobEventList::fromXml(m_jobEventXml); 103 104 QVERIFY(jobQueuedRemote.jobState() != MoleQueue::QueuedRemote); 105 QVERIFY(jobRunningRemote.jobState() != MoleQueue::RunningRemote); 106 queue.handleQueueUpdate(list.jobEvents()); 107 108 QVERIFY(jobQueuedRemote.jobState() == MoleQueue::QueuedRemote); 109 QVERIFY(jobRunningRemote.jobState() == MoleQueue::RunningRemote); 110 } 111 112 QTEST_MAIN(QueueUitTest) 113 114 #include "uittest.moc" 115