added savePlaylist and revertEditedPlaylist

This commit is contained in:
fgerlits 2004-10-20 06:16:31 +00:00
parent 7c23b18f91
commit 27ac235d06
8 changed files with 1200 additions and 0 deletions

View File

@ -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/RevertEditedPlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "XmlRpcTools.h"
#include "RevertEditedPlaylistMethod.h"
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of this XML-RPC method.
*----------------------------------------------------------------------------*/
const std::string RevertEditedPlaylistMethod::methodName
= "revertEditedPlaylist";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int RevertEditedPlaylistMethod::errorId = 800;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
RevertEditedPlaylistMethod :: RevertEditedPlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
RevertEditedPlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
Ptr<UniqueId>::Ref id;
try{
id = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "argument is not a playlist ID",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(id);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "playlist not found",
returnValue);
return;
}
try {
playlist->revertToSavedCopy();
}
catch (std::logic_error) {
XmlRpcTools::markError(errorId+4, "could not revert playlist",
returnValue);
return;
}
}

View File

@ -0,0 +1,149 @@
/*------------------------------------------------------------------------------
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/RevertEditedPlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef RevertEditedPlaylistMethod_h
#define RevertEditedPlaylistMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Playlist.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to revert a playlist (specified by its playlist id)
* to its previous state, before we started editing it.
*
* The name of the method when called through XML-RPC is
* "revertEditedPlaylist".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>playlistId - int - the unique id of the playlist requested.</li>
* </ul>
*
* In case of an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>errorCode - int - the id of the error condition</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>801 - invalid argument format </li>
* <li>802 - argument is not a playlist ID </li>
* <li>803 - playlist not found </li>
* <li>804 - could not revert playlist </li>
* </ul>
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class RevertEditedPlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
private:
/**
* The name of this method, as it will be registered into the
* XML-RPC server.
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**
* A default constructor, for testing purposes.
*/
RevertEditedPlaylistMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
RevertEditedPlaylistMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule command on the Scheduler daemon.
*
* @param parameters XML-RPC function call parameters
* @param returnValue the return value of the call (out parameter)
*/
void
execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // RevertEditedPlaylistMethod_h

View File

@ -0,0 +1,188 @@
/*------------------------------------------------------------------------------
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/RevertEditedPlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "OpenPlaylistForEditingMethod.h"
#include "RemoveAudioClipFromPlaylistMethod.h"
#include "SavePlaylistMethod.h"
#include "RevertEditedPlaylistMethod.h"
#include "RevertEditedPlaylistMethodTest.h"
using namespace std;
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(RevertEditedPlaylistMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string RevertEditedPlaylistMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string RevertEditedPlaylistMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
RevertEditedPlaylistMethodTest :: configure(
Ptr<Configurable>::Ref configurable,
const std::string fileName)
throw (std::invalid_argument,
xmlpp::exception)
{
Ptr<xmlpp::DomParser>::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
RevertEditedPlaylistMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
RevertEditedPlaylistMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
RevertEditedPlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<OpenPlaylistForEditingMethod>::Ref
openMethod(new OpenPlaylistForEditingMethod);
Ptr<RemoveAudioClipFromPlaylistMethod>::Ref
removeMethod(new RemoveAudioClipFromPlaylistMethod);
Ptr<SavePlaylistMethod>::Ref
saveMethod(new SavePlaylistMethod);
Ptr<RevertEditedPlaylistMethod>::Ref
revertMethod(new RevertEditedPlaylistMethod);
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 1;
parameter["relativeOffset"] = 0;
revertMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // no saved copy yet
result.clear();
openMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode")); // can't remove it twice
result.clear();
revertMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
removeMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // but now we can again
result.clear();
saveMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
revertMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode")); // saved copy has been
CPPUNIT_ASSERT(int(result["errorCode"]) == 804); // discarded
}

View File

@ -0,0 +1,135 @@
/*------------------------------------------------------------------------------
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/RevertEditedPlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef RevertEditedPlaylistMethodTest_h
#define RevertEditedPlaylistMethodTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the RevertEditedPlaylistMethod class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see RevertEditedPlaylistMethod
*/
class RevertEditedPlaylistMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(RevertEditedPlaylistMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* 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<Configurable>::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 // RevertEditedPlaylistMethodTest_h

View File

@ -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/SavePlaylistMethod.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#ifdef HAVE_TIME_H
#include <time.h>
#else
#error need time.h
#endif
#include <string>
#include "LiveSupport/Core/StorageClientInterface.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "XmlRpcTools.h"
#include "SavePlaylistMethod.h"
using namespace LiveSupport;
using namespace LiveSupport::Core;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
/*------------------------------------------------------------------------------
* The name of this XML-RPC method.
*----------------------------------------------------------------------------*/
const std::string SavePlaylistMethod::methodName
= "savePlaylist";
/*------------------------------------------------------------------------------
* The ID of this method for error reporting purposes.
*----------------------------------------------------------------------------*/
const int SavePlaylistMethod::errorId = 700;
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Construct the method and register it right away.
*----------------------------------------------------------------------------*/
SavePlaylistMethod :: SavePlaylistMethod (
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer) throw()
: XmlRpc::XmlRpcServerMethod(methodName, xmlRpcServer.get())
{
}
/*------------------------------------------------------------------------------
* Execute the stop XML-RPC function call.
*----------------------------------------------------------------------------*/
void
SavePlaylistMethod :: execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue)
throw ()
{
if (!parameters.valid()) {
XmlRpcTools::markError(errorId+1, "invalid argument format",
returnValue);
return;
}
Ptr<UniqueId>::Ref id;
try{
id = XmlRpcTools::extractPlaylistId(parameters);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+2, "argument is not a playlist ID",
returnValue);
return;
}
Ptr<StorageClientFactory>::Ref scf;
Ptr<StorageClientInterface>::Ref storage;
scf = StorageClientFactory::getInstance();
storage = scf->getStorageClient();
Ptr<Playlist>::Ref playlist;
try {
playlist = storage->getPlaylist(id);
}
catch (std::invalid_argument &e) {
XmlRpcTools::markError(errorId+3, "playlist not found",
returnValue);
return;
}
if (!playlist->setLockedForEditing(false)) {
XmlRpcTools::markError(errorId+4,
"could not save playlist",
returnValue);
return;
}
playlist->deleteSavedCopy();
}

View File

@ -0,0 +1,150 @@
/*------------------------------------------------------------------------------
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/SavePlaylistMethod.h,v $
------------------------------------------------------------------------------*/
#ifndef SavePlaylistMethod_h
#define SavePlaylistMethod_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <stdexcept>
#include <string>
#include <XmlRpcServerMethod.h>
#include <XmlRpcValue.h>
#include "LiveSupport/Core/Ptr.h"
#include "LiveSupport/Core/Playlist.h"
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* An XML-RPC method object to save a playlist (specified by its playlist id)
* after editing. It releases the "locked for editing" lock and discards the
* copy of the playlist which was saved for reverting to.
*
* The name of the method when called through XML-RPC is
* "savePlaylist".
* The expected parameter is an XML-RPC structure, with the following
* member:
* <ul>
* <li>playlistId - int - the unique id of the playlist to save.</li>
* </ul>
*
* In case of an error, an XML-RPC structure is returned, with the following
* fields:
* <ul>
* <li>errorCode - int - the id of the error condition</li>
* <li>errorMessage - string - a description of the error</li>
* </ul>
* The possible error codes are:
* <ul>
* <li>701 - invalid argument format </li>
* <li>702 - argument is not a playlist ID </li>
* <li>703 - playlist not found </li>
* <li>704 - could not save playlist </li>
* </ul>
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
*/
class SavePlaylistMethod : public XmlRpc::XmlRpcServerMethod
{
private:
/**
* The name of this method, as it will be registered into the
* XML-RPC server.
*/
static const std::string methodName;
/**
* The ID of this method for error reporting purposes.
*/
static const int errorId;
public:
/**
* A default constructor, for testing purposes.
*/
SavePlaylistMethod(void) throw ()
: XmlRpc::XmlRpcServerMethod(methodName)
{
}
/**
* Constuctor that registers the method with the server right away.
*
* @param xmlRpcServer the XML-RPC server to register with.
*/
SavePlaylistMethod(
Ptr<XmlRpc::XmlRpcServer>::Ref xmlRpcServer)
throw ();
/**
* Execute the display schedule command on the Scheduler daemon.
*
* @param parameters XML-RPC function call parameters
* @param returnValue the return value of the call (out parameter)
*/
void
execute(XmlRpc::XmlRpcValue & parameters,
XmlRpc::XmlRpcValue & returnValue) throw ();
};
/* ================================================= external data structures */
/* ====================================================== function prototypes */
} // namespace Scheduler
} // namespace LiveSupport
#endif // SavePlaylistMethod_h

View File

@ -0,0 +1,167 @@
/*------------------------------------------------------------------------------
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/SavePlaylistMethodTest.cxx,v $
------------------------------------------------------------------------------*/
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#if HAVE_UNISTD_H
#include <unistd.h>
#else
#error "Need unistd.h"
#endif
#include <string>
#include <iostream>
#include <XmlRpcValue.h>
#include "LiveSupport/Db/ConnectionManagerFactory.h"
#include "LiveSupport/Storage/StorageClientFactory.h"
#include "OpenPlaylistForEditingMethod.h"
#include "SavePlaylistMethod.h"
#include "SavePlaylistMethodTest.h"
using namespace std;
using namespace LiveSupport::Db;
using namespace LiveSupport::Storage;
using namespace LiveSupport::Scheduler;
/* =================================================== local data structures */
/* ================================================ local constants & macros */
CPPUNIT_TEST_SUITE_REGISTRATION(SavePlaylistMethodTest);
/**
* The name of the configuration file for the storage client factory.
*/
const std::string SavePlaylistMethodTest::storageClientConfig =
"etc/storageClient.xml";
/**
* The name of the configuration file for the connection manager factory.
*/
const std::string SavePlaylistMethodTest::connectionManagerConfig =
"etc/connectionManagerFactory.xml";
/* =============================================== local function prototypes */
/* ============================================================= module code */
/*------------------------------------------------------------------------------
* Configure a Configurable with an XML file.
*----------------------------------------------------------------------------*/
void
SavePlaylistMethodTest :: configure(
Ptr<Configurable>::Ref configurable,
const std::string fileName)
throw (std::invalid_argument,
xmlpp::exception)
{
Ptr<xmlpp::DomParser>::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
SavePlaylistMethodTest :: setUp(void) throw ()
{
try {
Ptr<StorageClientFactory>::Ref scf
= StorageClientFactory::getInstance();
configure(scf, storageClientConfig);
Ptr<ConnectionManagerFactory>::Ref cmf
= ConnectionManagerFactory::getInstance();
configure(cmf, connectionManagerConfig);
} catch (std::invalid_argument &e) {
CPPUNIT_FAIL("semantic error in configuration file");
} catch (xmlpp::exception &e) {
CPPUNIT_FAIL("error parsing configuration file");
} catch (std::exception &e) {
CPPUNIT_FAIL(e.what());
}
}
/*------------------------------------------------------------------------------
* Clean up the test environment
*----------------------------------------------------------------------------*/
void
SavePlaylistMethodTest :: tearDown(void) throw ()
{
}
/*------------------------------------------------------------------------------
* Just a very simple smoke test
*----------------------------------------------------------------------------*/
void
SavePlaylistMethodTest :: firstTest(void)
throw (CPPUNIT_NS::Exception)
{
Ptr<OpenPlaylistForEditingMethod>::Ref
openMethod(new OpenPlaylistForEditingMethod());
Ptr<SavePlaylistMethod>::Ref saveMethod(new SavePlaylistMethod());
XmlRpc::XmlRpcValue parameter;
XmlRpc::XmlRpcValue result;
parameter["playlistId"] = 9999;
saveMethod->execute(parameter, result);
CPPUNIT_ASSERT(result.hasMember("errorCode"));
CPPUNIT_ASSERT(int(result["errorCode"]) == 703); // playlist not found
parameter["playlistId"] = 1;
result.clear();
openMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode"));
result.clear();
saveMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // open then save OK
result.clear();
openMethod->execute(parameter, result);
CPPUNIT_ASSERT(!result.hasMember("errorCode")); // save then open OK
}

View File

@ -0,0 +1,135 @@
/*------------------------------------------------------------------------------
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/SavePlaylistMethodTest.h,v $
------------------------------------------------------------------------------*/
#ifndef SavePlaylistMethodTest_h
#define SavePlaylistMethodTest_h
#ifndef __cplusplus
#error This is a C++ include file
#endif
/* ============================================================ include files */
#ifdef HAVE_CONFIG_H
#include "configure.h"
#endif
#include <cppunit/extensions/HelperMacros.h>
namespace LiveSupport {
namespace Scheduler {
using namespace LiveSupport;
using namespace LiveSupport::Core;
/* ================================================================ constants */
/* =================================================================== macros */
/* =============================================================== data types */
/**
* Unit test for the SavePlaylistMethod class.
*
* @author $Author: fgerlits $
* @version $Revision: 1.1 $
* @see SavePlaylistMethod
*/
class SavePlaylistMethodTest : public CPPUNIT_NS::TestFixture
{
CPPUNIT_TEST_SUITE(SavePlaylistMethodTest);
CPPUNIT_TEST(firstTest);
CPPUNIT_TEST_SUITE_END();
/**
* The name of the configuration file for the storage client factory.
*/
static const std::string storageClientConfig;
/**
* The name of the configuration file for the connection manager
* factory.
*/
static const std::string connectionManagerConfig;
/**
* 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<Configurable>::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 // SavePlaylistMethodTest_h