added uploadPlaylist, displaySchedule and removeFromSchedule methods
added proper XML-RPC error handling
This commit is contained in:
parent
4eac8957fd
commit
c11f956563
|
@ -21,7 +21,7 @@
|
|||
#
|
||||
#
|
||||
# Author : $Author: maroy $
|
||||
# Version : $Revision: 1.3 $
|
||||
# Version : $Revision: 1.4 $
|
||||
# Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/etc/Makefile.in,v $
|
||||
#
|
||||
# @configure_input@
|
||||
|
@ -159,10 +159,10 @@ depclean: clean
|
|||
distclean: clean docclean
|
||||
${RMDIR} ${TMP_DIR}/config* ${TMP_DIR}/autom4te*
|
||||
|
||||
check: all ${TEST_RUNNER} start run_tests stop
|
||||
check: all ${TEST_RUNNER} install start run_tests stop uninstall
|
||||
|
||||
run_tests: ${TEST_RUNNER}
|
||||
${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
-${TEST_RUNNER} -o ${TEST_RESULTS} -s ${TEST_XSLT}
|
||||
|
||||
install: ${SCHEDULER_EXE}
|
||||
${MAKE} -C ${SCHEDULER_DIR} install
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/include/LiveSupport/SchedulerClient/SchedulerClientInterface.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -44,7 +44,10 @@
|
|||
#include "boost/date_time/posix_time/posix_time.hpp"
|
||||
|
||||
#include "LiveSupport/Core/Ptr.h"
|
||||
#include "LiveSupport/Core/UniqueId.h"
|
||||
#include "LiveSupport/Core/SessionId.h"
|
||||
#include "LiveSupport/Core/ScheduleEntry.h"
|
||||
#include "LiveSupport/Core/XmlRpcException.h"
|
||||
|
||||
namespace LiveSupport {
|
||||
namespace SchedulerClient {
|
||||
|
@ -64,7 +67,7 @@ using namespace LiveSupport::Core;
|
|||
* An interface to access the scheduler daemon as a client.
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
*/
|
||||
class SchedulerClientInterface
|
||||
{
|
||||
|
@ -74,19 +77,68 @@ class SchedulerClientInterface
|
|||
* is connected to.
|
||||
*
|
||||
* @return the version string of the scheduler daemon.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<const std::string>::Ref
|
||||
getVersion(void) throw ()
|
||||
= 0;
|
||||
getVersion(void) throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Return the current time at the scheduler server.
|
||||
*
|
||||
* @return the current time at the scheduler server.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<const boost::posix_time::ptime>::Ref
|
||||
getSchedulerTime(void) throw ()
|
||||
= 0;
|
||||
getSchedulerTime(void) throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Schedule a playlist at a given time.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param playlistId the id of the playlist to schedule.
|
||||
* @param playtime the time for which to schedule.
|
||||
* @return the schedule entry id for which the playlist has been
|
||||
* scheduled.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<UniqueId>::Ref
|
||||
uploadPlaylist(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref playlistId,
|
||||
Ptr<boost::posix_time::ptime>::Ref playtime)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Return the scheduled entries for a specified time interval.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param from the start of the interval, inclusive
|
||||
* @param to the end of the interval, exclusive
|
||||
* @return a vector of the schedule entries for the time period.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
|
||||
displaySchedule(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<boost::posix_time::ptime>::Ref from,
|
||||
Ptr<boost::posix_time::ptime>::Ref to)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
/**
|
||||
* Remove a scheduled item.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param scheduledEntryId the id of the scheduled entry to remove.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual void
|
||||
removeFromSchedule(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref scheduleEntryId)
|
||||
throw (XmlRpcException)
|
||||
= 0;
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.4 $
|
||||
Version : $Revision: 1.5 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -40,6 +40,11 @@
|
|||
#include <XmlRpcValue.h>
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
#include "LiveSupport/Core/XmlRpcTools.h"
|
||||
#include "LiveSupport/Core/XmlRpcInvalidArgumentException.h"
|
||||
#include "LiveSupport/Core/XmlRpcCommunicationException.h"
|
||||
#include "LiveSupport/Core/XmlRpcMethodFaultException.h"
|
||||
#include "LiveSupport/Core/XmlRpcMethodResponseException.h"
|
||||
#include "SchedulerDaemonXmlRpcClient.h"
|
||||
|
||||
using namespace boost::posix_time;
|
||||
|
@ -130,7 +135,8 @@ SchedulerDaemonXmlRpcClient :: configure(const xmlpp::Element & element)
|
|||
* Get the version string from the scheduler daemon
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<const std::string>::Ref
|
||||
SchedulerDaemonXmlRpcClient :: getVersion(void) throw ()
|
||||
SchedulerDaemonXmlRpcClient :: getVersion(void)
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
XmlRpcValue xmlRpcParams;
|
||||
XmlRpcValue xmlRpcResult;
|
||||
|
@ -142,12 +148,28 @@ SchedulerDaemonXmlRpcClient :: getVersion(void) throw ()
|
|||
false);
|
||||
|
||||
xmlRpcResult.clear();
|
||||
xmlRpcClient.execute("getVersion", xmlRpcParams, xmlRpcResult);
|
||||
|
||||
if (xmlRpcResult.hasMember("version")) {
|
||||
result.reset(new std::string(xmlRpcResult["version"]));
|
||||
if (!xmlRpcClient.execute("getVersion", xmlRpcParams, xmlRpcResult)) {
|
||||
throw XmlRpcCommunicationException(
|
||||
"cannot execute XML-RPC method 'getVersion'");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'getVersion' returned error message:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
if (!xmlRpcResult.hasMember("version")
|
||||
|| xmlRpcResult["version"].getType() != XmlRpcValue::TypeString) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'getVersion' returned unexpected value:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
|
||||
result.reset(new std::string(xmlRpcResult["version"]));
|
||||
|
||||
xmlRpcClient.close();
|
||||
|
||||
return result;
|
||||
|
@ -159,7 +181,7 @@ SchedulerDaemonXmlRpcClient :: getVersion(void) throw ()
|
|||
*----------------------------------------------------------------------------*/
|
||||
Ptr<const ptime>::Ref
|
||||
SchedulerDaemonXmlRpcClient :: getSchedulerTime(void)
|
||||
throw ()
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
XmlRpcValue xmlRpcParams;
|
||||
XmlRpcValue xmlRpcResult;
|
||||
|
@ -171,17 +193,32 @@ SchedulerDaemonXmlRpcClient :: getSchedulerTime(void)
|
|||
false);
|
||||
|
||||
xmlRpcResult.clear();
|
||||
xmlRpcClient.execute("getSchedulerTime", xmlRpcParams, xmlRpcResult);
|
||||
if (!xmlRpcClient.execute("getSchedulerTime", xmlRpcParams, xmlRpcResult)) {
|
||||
throw XmlRpcCommunicationException(
|
||||
"cannot execute XML-RPC method 'getSchedulerTime'");
|
||||
}
|
||||
|
||||
if (xmlRpcResult.hasMember("schedulerTime")) {
|
||||
struct tm time = xmlRpcResult["schedulerTime"];
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'getSchedulerTime' returned error message:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
try {
|
||||
result = TimeConversion::tmToPtime(&time);
|
||||
} catch (std::out_of_range &e) {
|
||||
// TODO: report error, for some reason the returned time is wrong
|
||||
}
|
||||
if (!xmlRpcResult.hasMember("schedulerTime")
|
||||
|| xmlRpcResult["schedulerTime"].getType() != XmlRpcValue::TypeDateTime) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'getSchedulerTime' returned unexpected value:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodResponseException(eMsg.str());
|
||||
}
|
||||
|
||||
struct tm time = xmlRpcResult["schedulerTime"];
|
||||
|
||||
try {
|
||||
result = TimeConversion::tmToPtime(&time);
|
||||
} catch (std::out_of_range &e) {
|
||||
throw XmlRpcException("time conversion error", e);
|
||||
}
|
||||
|
||||
xmlRpcClient.close();
|
||||
|
@ -189,3 +226,141 @@ SchedulerDaemonXmlRpcClient :: getSchedulerTime(void)
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Schedule a playlist in the scheduler.
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<UniqueId>::Ref
|
||||
SchedulerDaemonXmlRpcClient :: uploadPlaylist(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref playlistId,
|
||||
Ptr<boost::posix_time::ptime>::Ref playtime)
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
Ptr<UniqueId>::Ref scheduleEntryId;
|
||||
|
||||
XmlRpcValue xmlRpcParams;
|
||||
XmlRpcValue xmlRpcResult;
|
||||
Ptr<const ptime>::Ref result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||
xmlRpcPort,
|
||||
xmlRpcUri->c_str(),
|
||||
false);
|
||||
|
||||
XmlRpcTools::sessionIdToXmlRpcValue(sessionId, xmlRpcParams);
|
||||
XmlRpcTools::playlistIdToXmlRpcValue(playlistId, xmlRpcParams);
|
||||
XmlRpcTools::playtimeToXmlRpcValue(playtime, xmlRpcParams);
|
||||
|
||||
xmlRpcResult.clear();
|
||||
if (!xmlRpcClient.execute("uploadPlaylist", xmlRpcParams, xmlRpcResult)) {
|
||||
throw XmlRpcCommunicationException(
|
||||
"cannot execute XML-RPC method 'uploadPlaylist'");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'uploadPlaylist' returned error message:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
try {
|
||||
scheduleEntryId = XmlRpcTools::extractScheduleEntryId(xmlRpcResult);
|
||||
} catch (std::invalid_argument &e) {
|
||||
throw XmlRpcInvalidArgumentException(e);
|
||||
}
|
||||
|
||||
xmlRpcClient.close();
|
||||
|
||||
return scheduleEntryId;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Return the scheduled items for a time interval
|
||||
*----------------------------------------------------------------------------*/
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
|
||||
SchedulerDaemonXmlRpcClient :: displaySchedule(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<ptime>::Ref from,
|
||||
Ptr<ptime>::Ref to)
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
|
||||
|
||||
XmlRpcValue xmlRpcParams;
|
||||
XmlRpcValue xmlRpcResult;
|
||||
Ptr<const ptime>::Ref result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||
xmlRpcPort,
|
||||
xmlRpcUri->c_str(),
|
||||
false);
|
||||
|
||||
XmlRpcTools::sessionIdToXmlRpcValue(sessionId, xmlRpcParams);
|
||||
XmlRpcTools::fromTimeToXmlRpcValue(from, xmlRpcParams);
|
||||
XmlRpcTools::toTimeToXmlRpcValue(to, xmlRpcParams);
|
||||
|
||||
xmlRpcResult.clear();
|
||||
if (!xmlRpcClient.execute("displaySchedule", xmlRpcParams, xmlRpcResult)) {
|
||||
throw XmlRpcCommunicationException(
|
||||
"cannot execute XML-RPC method 'displaySchedule'");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'displaySchedule' returned error message:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
|
||||
try {
|
||||
entries = XmlRpcTools::extractScheduleEntries(xmlRpcResult);
|
||||
} catch (std::invalid_argument &e) {
|
||||
throw XmlRpcInvalidArgumentException(e);
|
||||
}
|
||||
|
||||
xmlRpcClient.close();
|
||||
|
||||
return entries;
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Remove a scheduled entry from the schedule.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerDaemonXmlRpcClient :: removeFromSchedule(
|
||||
Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref scheduleEntryId)
|
||||
throw (Core::XmlRpcException)
|
||||
{
|
||||
XmlRpcValue xmlRpcParams;
|
||||
XmlRpcValue xmlRpcResult;
|
||||
Ptr<const ptime>::Ref result;
|
||||
|
||||
XmlRpcClient xmlRpcClient(xmlRpcHost->c_str(),
|
||||
xmlRpcPort,
|
||||
xmlRpcUri->c_str(),
|
||||
false);
|
||||
|
||||
XmlRpcTools::sessionIdToXmlRpcValue(sessionId, xmlRpcParams);
|
||||
XmlRpcTools::scheduleEntryIdToXmlRpcValue(scheduleEntryId, xmlRpcParams);
|
||||
|
||||
xmlRpcResult.clear();
|
||||
if (!xmlRpcClient.execute("removeFromSchedule",
|
||||
xmlRpcParams,
|
||||
xmlRpcResult)) {
|
||||
throw XmlRpcCommunicationException(
|
||||
"cannot execute XML-RPC method 'removeFromSchedule'");
|
||||
}
|
||||
|
||||
if (xmlRpcClient.isFault()) {
|
||||
std::stringstream eMsg;
|
||||
eMsg << "XML-RPC method 'removeFromSchedule' returned error message:\n"
|
||||
<< xmlRpcResult;
|
||||
throw XmlRpcMethodFaultException(eMsg.str());
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClient.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -42,6 +42,7 @@
|
|||
|
||||
#include <stdexcept>
|
||||
#include <string>
|
||||
#include <vector>
|
||||
|
||||
#include <XmlRpcClient.h>
|
||||
|
||||
|
@ -90,7 +91,7 @@ using namespace LiveSupport::Core;
|
|||
* </code></pre>
|
||||
*
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.3 $
|
||||
* @version $Revision: 1.4 $
|
||||
*/
|
||||
class SchedulerDaemonXmlRpcClient :
|
||||
virtual public Configurable,
|
||||
|
@ -159,17 +160,63 @@ class SchedulerDaemonXmlRpcClient :
|
|||
* is connected to.
|
||||
*
|
||||
* @return the version string of the scheduler daemon.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<const std::string>::Ref
|
||||
getVersion(void) throw ();
|
||||
getVersion(void) throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Return the current time at the scheduler server.
|
||||
*
|
||||
* @return the current time at the scheduler server.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<const boost::posix_time::ptime>::Ref
|
||||
getSchedulerTime(void) throw ();
|
||||
getSchedulerTime(void) throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Schedule a playlist at a given time.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param playlistId the id of the playlist to schedule.
|
||||
* @param playtime the time for which to schedule.
|
||||
* @return the schedule entry id for which the playlist has been
|
||||
* scheduled.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<UniqueId>::Ref
|
||||
uploadPlaylist(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref playlistId,
|
||||
Ptr<boost::posix_time::ptime>::Ref playtime)
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Return the scheduled entries for a specified time interval.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param from the start of the interval, inclusive
|
||||
* @param to the end of the interval, exclusive
|
||||
* @return a vector of the schedule entries for the time period.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref
|
||||
displaySchedule(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<boost::posix_time::ptime>::Ref from,
|
||||
Ptr<boost::posix_time::ptime>::Ref to)
|
||||
throw (XmlRpcException);
|
||||
|
||||
/**
|
||||
* Remove a scheduled item.
|
||||
*
|
||||
* @param sessionId a valid, authenticated session id.
|
||||
* @param scheduledEntryId the id of the scheduled entry to remove.
|
||||
* @exception XmlRpcException in case of XML-RPC errors.
|
||||
*/
|
||||
virtual void
|
||||
removeFromSchedule(Ptr<SessionId>::Ref sessionId,
|
||||
Ptr<UniqueId>::Ref scheduleEntryId)
|
||||
throw (XmlRpcException);
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.3 $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.cxx,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -45,6 +45,7 @@
|
|||
#include <iostream>
|
||||
|
||||
#include "LiveSupport/Core/TimeConversion.h"
|
||||
#include "LiveSupport/Core/XmlRpcMethodFaultException.h"
|
||||
#include "LiveSupport/Authentication/AuthenticationClientFactory.h"
|
||||
#include "SchedulerDaemonXmlRpcClientTest.h"
|
||||
|
||||
|
@ -156,9 +157,13 @@ void
|
|||
SchedulerDaemonXmlRpcClientTest :: getVersionTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<const std::string>::Ref version = schedulerClient->getVersion();
|
||||
try {
|
||||
Ptr<const std::string>::Ref version = schedulerClient->getVersion();
|
||||
|
||||
CPPUNIT_ASSERT(version.get());
|
||||
CPPUNIT_ASSERT(version.get());
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
@ -169,12 +174,168 @@ void
|
|||
SchedulerDaemonXmlRpcClientTest :: getSchedulerTimeTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<const ptime>::Ref time = schedulerClient->getSchedulerTime();
|
||||
Ptr<const ptime>::Ref now = TimeConversion::now();
|
||||
try {
|
||||
Ptr<const ptime>::Ref time = schedulerClient->getSchedulerTime();
|
||||
Ptr<const ptime>::Ref now = TimeConversion::now();
|
||||
|
||||
CPPUNIT_ASSERT(time.get());
|
||||
// assume that the scheduler and the client is in the same year
|
||||
// this can break at new year's eve - so don't run the test then :)
|
||||
CPPUNIT_ASSERT(time->date().year() == now->date().year());
|
||||
CPPUNIT_ASSERT(time.get());
|
||||
// assume that the scheduler and the client is in the same year
|
||||
// this can break at new year's eve - so don't run the test then :)
|
||||
CPPUNIT_ASSERT(time->date().year() == now->date().year());
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test the displaySchedule XML-RPC method, when the schedule is empty
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerDaemonXmlRpcClientTest :: displayScheduleEmptyTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
try {
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
|
||||
Ptr<ptime>::Ref from;
|
||||
Ptr<ptime>::Ref to;
|
||||
|
||||
// check from now until 1 hour later
|
||||
from = TimeConversion::now();
|
||||
to.reset(new ptime(*from + hours(1)));
|
||||
|
||||
entries = schedulerClient->displaySchedule(sessionId, from, to);
|
||||
CPPUNIT_ASSERT(entries->empty());
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test playlist management functions.
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerDaemonXmlRpcClientTest :: playlistMgmtTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
try {
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
|
||||
Ptr<ScheduleEntry>::Ref entry;
|
||||
Ptr<UniqueId>::Ref entryId;
|
||||
Ptr<UniqueId>::Ref playlistId;
|
||||
Ptr<ptime>::Ref now;
|
||||
Ptr<ptime>::Ref playtime;
|
||||
Ptr<ptime>::Ref from;
|
||||
Ptr<ptime>::Ref to;
|
||||
|
||||
now = TimeConversion::now();
|
||||
// make sure now is only second resolution, not micro-second
|
||||
long fsec = now->time_of_day().fractional_seconds();
|
||||
now.reset(new ptime(*now - microsec(fsec)));
|
||||
|
||||
// the test assumes that there's a playlist with the id of 1 in
|
||||
// the storage accessed by the scheduler
|
||||
|
||||
// schedule playlist #1 for one hour from now
|
||||
playlistId.reset(new UniqueId(1));
|
||||
playtime.reset(new ptime(*now + hours(1)));
|
||||
|
||||
entryId = schedulerClient->uploadPlaylist(sessionId,
|
||||
playlistId,
|
||||
playtime);
|
||||
|
||||
// now check if our playlist has indeed been scheduled
|
||||
from = now;
|
||||
to.reset(new ptime(*from + hours(2)));
|
||||
|
||||
entries = schedulerClient->displaySchedule(sessionId, from, to);
|
||||
CPPUNIT_ASSERT(entries->size() == 1);
|
||||
entry = (*entries)[0];
|
||||
CPPUNIT_ASSERT(*entry->getId() == *entryId);
|
||||
CPPUNIT_ASSERT(*entry->getPlaylistId() == *playlistId);
|
||||
CPPUNIT_ASSERT(*entry->getStartTime() == *playtime);
|
||||
|
||||
|
||||
// and now, remove the entry, and see that it's not there anymore
|
||||
schedulerClient->removeFromSchedule(sessionId, entryId);
|
||||
entries = schedulerClient->displaySchedule(sessionId, from, to);
|
||||
CPPUNIT_ASSERT(entries->empty());
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/*------------------------------------------------------------------------------
|
||||
* Test for some XML-RPC error conditions
|
||||
*----------------------------------------------------------------------------*/
|
||||
void
|
||||
SchedulerDaemonXmlRpcClientTest :: xmlRpcErrorTest(void)
|
||||
throw (CPPUNIT_NS::Exception)
|
||||
{
|
||||
Ptr<std::vector<Ptr<ScheduleEntry>::Ref> >::Ref entries;
|
||||
Ptr<ScheduleEntry>::Ref entry;
|
||||
Ptr<UniqueId>::Ref entryId;
|
||||
Ptr<UniqueId>::Ref playlistId;
|
||||
Ptr<ptime>::Ref now;
|
||||
Ptr<ptime>::Ref playtime;
|
||||
bool gotException;
|
||||
|
||||
try {
|
||||
now = TimeConversion::now();
|
||||
// make sure now is only second resolution, not micro-second
|
||||
long fsec = now->time_of_day().fractional_seconds();
|
||||
now.reset(new ptime(*now - microsec(fsec)));
|
||||
|
||||
// the test assumes that there's a playlist with the id of 1 in
|
||||
// the storage accessed by the scheduler
|
||||
|
||||
// schedule playlist #1 for one hour from now
|
||||
playlistId.reset(new UniqueId(1));
|
||||
playtime.reset(new ptime(*now + hours(1)));
|
||||
|
||||
entryId = schedulerClient->uploadPlaylist(sessionId,
|
||||
playlistId,
|
||||
playtime);
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
gotException = false;
|
||||
try {
|
||||
// try to upload the same entry again, for the same time
|
||||
// this should result in an error
|
||||
schedulerClient->uploadPlaylist(sessionId, playlistId, playtime);
|
||||
} catch (LiveSupport::Core::XmlRpcMethodFaultException &e) {
|
||||
gotException = true;
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(gotException);
|
||||
|
||||
try {
|
||||
// and now, remove the entry, and see that it's not there anymore
|
||||
Ptr<ptime>::Ref from = now;
|
||||
Ptr<ptime>::Ref to(new ptime(*from + hours(2)));
|
||||
|
||||
schedulerClient->removeFromSchedule(sessionId, entryId);
|
||||
entries = schedulerClient->displaySchedule(sessionId, from, to);
|
||||
CPPUNIT_ASSERT(entries->empty());
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
|
||||
gotException = false;
|
||||
try {
|
||||
// and now, try to remove it again, which should result in an
|
||||
// exception
|
||||
schedulerClient->removeFromSchedule(sessionId, entryId);
|
||||
} catch (LiveSupport::Core::XmlRpcMethodFaultException &e) {
|
||||
gotException = true;
|
||||
} catch (XmlRpcException &e) {
|
||||
CPPUNIT_FAIL(e.what());
|
||||
}
|
||||
CPPUNIT_ASSERT(gotException);
|
||||
}
|
||||
|
||||
|
|
|
@ -21,8 +21,8 @@
|
|||
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
|
||||
|
||||
|
||||
Author : $Author: fgerlits $
|
||||
Version : $Revision: 1.3 $
|
||||
Author : $Author: maroy $
|
||||
Version : $Revision: 1.4 $
|
||||
Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/modules/schedulerClient/src/SchedulerDaemonXmlRpcClientTest.h,v $
|
||||
|
||||
------------------------------------------------------------------------------*/
|
||||
|
@ -62,8 +62,8 @@ using namespace LiveSupport::Authentication;
|
|||
/**
|
||||
* Unit test for the SchedulerDaemonXmlRpcClient class.
|
||||
*
|
||||
* @author $Author: fgerlits $
|
||||
* @version $Revision: 1.3 $
|
||||
* @author $Author: maroy $
|
||||
* @version $Revision: 1.4 $
|
||||
* @see SchedulerDaemonXmlRpcClient
|
||||
*/
|
||||
class SchedulerDaemonXmlRpcClientTest : public CPPUNIT_NS::TestFixture
|
||||
|
@ -71,6 +71,9 @@ class SchedulerDaemonXmlRpcClientTest : public CPPUNIT_NS::TestFixture
|
|||
CPPUNIT_TEST_SUITE(SchedulerDaemonXmlRpcClientTest);
|
||||
CPPUNIT_TEST(getVersionTest);
|
||||
CPPUNIT_TEST(getSchedulerTimeTest);
|
||||
CPPUNIT_TEST(displayScheduleEmptyTest);
|
||||
CPPUNIT_TEST(playlistMgmtTest);
|
||||
CPPUNIT_TEST(xmlRpcErrorTest);
|
||||
CPPUNIT_TEST_SUITE_END();
|
||||
|
||||
private:
|
||||
|
@ -122,6 +125,31 @@ class SchedulerDaemonXmlRpcClientTest : public CPPUNIT_NS::TestFixture
|
|||
void
|
||||
getSchedulerTimeTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* A test to check the displaySchedule XML-RPC method, when
|
||||
* the schedule is empty.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
displayScheduleEmptyTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test playlist management.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
playlistMgmtTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
/**
|
||||
* Test for some XML-RPC error conditions.
|
||||
*
|
||||
* @exception CPPUNIT_NS::Exception on test failures.
|
||||
*/
|
||||
void
|
||||
xmlRpcErrorTest(void) throw (CPPUNIT_NS::Exception);
|
||||
|
||||
|
||||
public:
|
||||
|
||||
|
|
Loading…
Reference in New Issue