diff --git a/livesupport/products/scheduler/etc/Makefile.in b/livesupport/products/scheduler/etc/Makefile.in index dc8b9a7a5..5ac186089 100644 --- a/livesupport/products/scheduler/etc/Makefile.in +++ b/livesupport/products/scheduler/etc/Makefile.in @@ -20,8 +20,8 @@ # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA # # -# Author : $Author: maroy $ -# Version : $Revision: 1.31 $ +# Author : $Author: fgerlits $ +# Version : $Revision: 1.32 $ # Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/etc/Makefile.in,v $ # # @configure_input@ @@ -193,6 +193,7 @@ TEST_RUNNER_OBJS = ${SCHEDULER_OBJS} \ ${TMP_DIR}/RpcDisplayPlaylistTest.o \ ${TMP_DIR}/RpcRemoveFromScheduleTest.o \ ${TMP_DIR}/RpcRescheduleTest.o \ + ${TMP_DIR}/RpcAddAudioClipToPlaylistTest.o \ ${TMP_DIR}/XmlRpcToolsTest.o \ ${TMP_DIR}/GetVersionMethodTest.o \ ${TMP_DIR}/RpcGetVersionTest.o \ diff --git a/livesupport/products/scheduler/etc/scheduler.xml b/livesupport/products/scheduler/etc/scheduler.xml index 06336a053..a3a6f1f45 100644 --- a/livesupport/products/scheduler/etc/scheduler.xml +++ b/livesupport/products/scheduler/etc/scheduler.xml @@ -13,13 +13,27 @@ - + - + + + + + + + + + + + + + + + @@ -48,7 +62,20 @@ - + + + + + + + + + + diff --git a/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.cxx b/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.cxx new file mode 100644 index 000000000..8542ef8e0 --- /dev/null +++ b/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.cxx @@ -0,0 +1,220 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.cxx,v $ + +------------------------------------------------------------------------------*/ + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#if HAVE_UNISTD_H +#include +#else +#error "Need unistd.h" +#endif + + +#include +#include +#include +#include + +#include "SchedulerDaemon.h" +#include "LiveSupport/Storage/StorageClientFactory.h" +#include "LiveSupport/Authentication/AuthenticationClientFactory.h" +#include "XmlRpcTools.h" + +#include "OpenPlaylistForEditingMethod.h" +#include "AddAudioClipToPlaylistMethod.h" +#include "RpcAddAudioClipToPlaylistTest.h" + +using namespace std; +using namespace LiveSupport::Storage; +using namespace LiveSupport::Authentication; +using namespace LiveSupport::Scheduler; + +/* =================================================== local data structures */ + + +/* ================================================ local constants & macros */ + +CPPUNIT_TEST_SUITE_REGISTRATION(RpcAddAudioClipToPlaylistTest); + +/** + * The name of the configuration file for the scheduler daemon. + */ +static const std::string schedulerDaemonConfig = + "etc/scheduler.xml"; + +/** + * The name of the configuration file for the storage client factory. + */ +static const std::string storageClientConfig = + "etc/storageClient.xml"; +/** + * The name of the configuration file for the authentication client factory. + */ +static const std::string authenticationClientConfig = + "etc/authenticationClient.xml"; + + +/* =============================================== local function prototypes */ + + +/* ============================================================= module code */ + +/*------------------------------------------------------------------------------ + * Configure a Configurable with an XML file. + *----------------------------------------------------------------------------*/ +void +RpcAddAudioClipToPlaylistTest :: configure( + Ptr::Ref configurable, + const std::string fileName) + throw (std::invalid_argument, + xmlpp::exception) +{ + Ptr::Ref parser(new xmlpp::DomParser(fileName, true)); + const xmlpp::Document * document = parser->get_document(); + const xmlpp::Element * root = document->get_root_node(); + + configurable->configure(*root); +} + + +/*------------------------------------------------------------------------------ + * Set up the test environment + *----------------------------------------------------------------------------*/ +void +RpcAddAudioClipToPlaylistTest :: setUp(void) throw () +{ + Ptr::Ref daemon = SchedulerDaemon::getInstance(); + if (!daemon->isConfigured()) { + try { + configure(daemon, schedulerDaemonConfig); + } catch (std::invalid_argument &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("semantic error in scheduler configuration file"); + } catch (xmlpp::exception &e) { + std::cerr << e.what() << std::endl; + CPPUNIT_FAIL("error parsing scheduler configuration file"); + } + } + daemon->install(); +// daemon->start(); +// sleep(2); + + try { + Ptr::Ref scf + = StorageClientFactory::getInstance(); + configure(scf, storageClientConfig); + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in storage configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing storage configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } + + Ptr::Ref acf; + try { + acf = AuthenticationClientFactory::getInstance(); + configure(acf, authenticationClientConfig); + } catch (std::invalid_argument &e) { + CPPUNIT_FAIL("semantic error in authentication configuration file"); + } catch (xmlpp::exception &e) { + CPPUNIT_FAIL("error parsing authentication configuration file"); + } catch (std::exception &e) { + CPPUNIT_FAIL(e.what()); + } + + authentication = acf->getAuthenticationClient(); + if (!(sessionId = authentication->login("root", "q"))) { + CPPUNIT_FAIL("could not log in to authentication server"); + } +} + + +/*------------------------------------------------------------------------------ + * Clean up the test environment + *----------------------------------------------------------------------------*/ +void +RpcAddAudioClipToPlaylistTest :: tearDown(void) throw () +{ + authentication->logout(sessionId); + sessionId.reset(); + authentication.reset(); + + Ptr::Ref daemon = SchedulerDaemon::getInstance(); +// daemon->stop(); +// sleep(2); + daemon->uninstall(); +} + + +/*------------------------------------------------------------------------------ + * Just a very simple smoke test + *----------------------------------------------------------------------------*/ +void +RpcAddAudioClipToPlaylistTest :: firstTest(void) + throw (CPPUNIT_NS::Exception) +{ + Ptr::Ref + openPlaylistMethod(new OpenPlaylistForEditingMethod()); + Ptr::Ref + addAudioClipMethod(new AddAudioClipToPlaylistMethod()); + + XmlRpcClient xmlRpcClient("localhost", 3344, "/RPC2", false); + XmlRpc::XmlRpcValue parameters; + XmlRpc::XmlRpcValue result; + + parameters["sessionId"] = sessionId->getId(); + parameters["playlistId"] = 1; + parameters["audioClipId"] = 10001; + parameters["relativeOffset"] = 0; + + result.clear(); + xmlRpcClient.execute("openPlaylistForEditing", parameters, result); + CPPUNIT_ASSERT(!xmlRpcClient.isFault()); + CPPUNIT_ASSERT(result.hasMember("id")); + CPPUNIT_ASSERT(int(result["id"]) == 1); + + result.clear(); + xmlRpcClient.execute("addAudioClipToPlaylist", parameters, result); + CPPUNIT_ASSERT(xmlRpcClient.isFault()); + + parameters.clear(); + parameters["sessionId"] = sessionId->getId(); + parameters["playlistId"] = 1; + parameters["audioClipId"] = 10001; + parameters["relativeOffset"] = 90*60; + + result.clear(); + xmlRpcClient.execute("addAudioClipToPlaylist", parameters, result); + CPPUNIT_ASSERT(!xmlRpcClient.isFault()); +} diff --git a/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.h b/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.h new file mode 100644 index 000000000..f930be274 --- /dev/null +++ b/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.h @@ -0,0 +1,138 @@ +/*------------------------------------------------------------------------------ + + Copyright (c) 2004 Media Development Loan Fund + + This file is part of the LiveSupport project. + http://livesupport.campware.org/ + To report bugs, send an e-mail to bugs@campware.org + + LiveSupport is free software; you can redistribute it and/or modify + it under the terms of the GNU General Public License as published by + the Free Software Foundation; either version 2 of the License, or + (at your option) any later version. + + LiveSupport is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with LiveSupport; if not, write to the Free Software + Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + + + Author : $Author: fgerlits $ + Version : $Revision: 1.1 $ + Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcAddAudioClipToPlaylistTest.h,v $ + +------------------------------------------------------------------------------*/ +#ifndef RpcAddAudioClipToPlaylistTest_h +#define RpcAddAudioClipToPlaylistTest_h + +#ifndef __cplusplus +#error This is a C++ include file +#endif + + +/* ============================================================ include files */ + +#ifdef HAVE_CONFIG_H +#include "configure.h" +#endif + +#include + +#include "LiveSupport/Core/AuthenticationClientInterface.h" +#include "LiveSupport/Core/SessionId.h" + +namespace LiveSupport { +namespace Scheduler { + +using namespace LiveSupport; +using namespace LiveSupport::Core; + +/* ================================================================ constants */ + + +/* =================================================================== macros */ + + +/* =============================================================== data types */ + +/** + * Unit test for the AddAudioClipToPlaylistMethod class. + * + * @author $Author: fgerlits $ + * @version $Revision: 1.1 $ + * @see AddAudioClipToPlaylistMethod + */ +class RpcAddAudioClipToPlaylistTest : public CPPUNIT_NS::TestFixture +{ + CPPUNIT_TEST_SUITE(RpcAddAudioClipToPlaylistTest); + CPPUNIT_TEST(firstTest); + CPPUNIT_TEST_SUITE_END(); + + private: + + /** + * The authentication client produced by the factory. + */ + Ptr::Ref authentication; + + /** + * A session ID from the authentication client login() method. + */ + Ptr::Ref sessionId; + + /** + * Configure a configurable with an XML file. + * + * @param configurable configure this + * @param fileName the name of the XML file to configure with. + * @exception std::invalid_argument on configuration errors. + * @exception xmlpp::exception on XML parsing errors. + */ + void + configure(Ptr::Ref configurable, + std::string fileName) + throw (std::invalid_argument, + xmlpp::exception); + + protected: + + /** + * A simple test. + * + * @exception CPPUNIT_NS::Exception on test failures. + */ + void + firstTest(void) throw (CPPUNIT_NS::Exception); + + + public: + + /** + * Set up the environment for the test case. + */ + void + setUp(void) throw (); + + /** + * Clean up the environment after the test case. + */ + void + tearDown(void) throw (); +}; + + +/* ================================================= external data structures */ + + +/* ====================================================== function prototypes */ + + +} // namespace Scheduler +} // namespace LiveSupport + +#endif // RpcAddAudioClipToPlaylistTest_h + diff --git a/livesupport/products/scheduler/src/RpcDisplayPlaylistTest.cxx b/livesupport/products/scheduler/src/RpcDisplayPlaylistTest.cxx index 48047ab83..d0c0a3e34 100644 --- a/livesupport/products/scheduler/src/RpcDisplayPlaylistTest.cxx +++ b/livesupport/products/scheduler/src/RpcDisplayPlaylistTest.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.1 $ + Version : $Revision: 1.2 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/RpcDisplayPlaylistTest.cxx,v $ ------------------------------------------------------------------------------*/ @@ -176,7 +176,7 @@ RpcDisplayPlaylistTest :: simpleTest(void) xmlRpcClient.execute("displayPlaylist", parameters, result); CPPUNIT_ASSERT(!xmlRpcClient.isFault()); CPPUNIT_ASSERT(((int) result["id"]) == 1); - CPPUNIT_ASSERT(((int) result["playlength"]) == (60 * 60)); + CPPUNIT_ASSERT(((int) result["playlength"]) == (90 * 60)); } diff --git a/livesupport/products/scheduler/src/SchedulerDaemon.cxx b/livesupport/products/scheduler/src/SchedulerDaemon.cxx index 7b102c5cc..41d30986a 100644 --- a/livesupport/products/scheduler/src/SchedulerDaemon.cxx +++ b/livesupport/products/scheduler/src/SchedulerDaemon.cxx @@ -22,7 +22,7 @@ Author : $Author: fgerlits $ - Version : $Revision: 1.12 $ + Version : $Revision: 1.13 $ Location : $Source: /home/paul/cvs2svn-livesupport/newcvsrepo/livesupport/products/scheduler/src/SchedulerDaemon.cxx,v $ ------------------------------------------------------------------------------*/ @@ -108,8 +108,8 @@ SchedulerDaemon :: SchedulerDaemon (void) throw () displayPlaylistMethod.reset(new DisplayPlaylistMethod()); removeFromScheduleMethod.reset(new RemoveFromScheduleMethod()); rescheduleMethod.reset(new RescheduleMethod()); - openPlaylistForEditingMethod.reset(new OpenPlaylistForEditingMethod()); addAudioClipToPlaylistMethod.reset(new AddAudioClipToPlaylistMethod()); + openPlaylistForEditingMethod.reset(new OpenPlaylistForEditingMethod()); } @@ -237,8 +237,12 @@ SchedulerDaemon :: install(void) throw (std::exception) { // TODO: check if we have already been configured Ptr::Ref sf = ScheduleFactory::getInstance(); - sf->install(); - + try { + sf->install(); + } + catch (std::exception &e) { + std::cerr << e.what() << std::endl; + } Ptr::Ref plf = PlayLogFactory::getInstance(); plf->install(); } @@ -251,8 +255,8 @@ void SchedulerDaemon :: uninstall(void) throw (std::exception) { // TODO: check if we have already been configured + Ptr::Ref plf = PlayLogFactory::getInstance(); try { - Ptr::Ref plf = PlayLogFactory::getInstance(); plf->uninstall(); } catch (std::exception &e) {