I add new UnitTest for REST classes

This commit is contained in:
jennylee
2012-10-05 17:27:46 -04:00
parent 5ac4358d80
commit 3e135b4ac3
9 changed files with 871 additions and 4 deletions

View File

@@ -61,5 +61,77 @@ class Services_Rest_AppOwner
return $result;
}
/**
* Implementation for 'POST' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function post($appUid, $ownUid, $usrUid)
{
try {
$result = array();
$obj = new AppOwner();
$obj->setAppUid($appUid);
$obj->setOwnUid($ownUid);
$obj->setUsrUid($usrUid);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'PUT' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function put($appUid, $ownUid, $usrUid)
{
try {
$obj = AppOwnerPeer::retrieveByPK($appUid, $ownUid, $usrUid);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'DELETE' method for Rest API
*
* @param mixed $appUid, $ownUid, $usrUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function delete($appUid, $ownUid, $usrUid)
{
$conn = Propel::getConnection(AppOwnerPeer::DATABASE_NAME);
try {
$conn->begin();
$obj = AppOwnerPeer::retrieveByPK($appUid, $ownUid, $usrUid);
if (! is_object($obj)) {
throw new RestException(412, 'Record does not exist.');
}
$obj->delete();
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw new RestException(412, $e->getMessage());
}
}
}

View File

@@ -74,5 +74,105 @@ class Services_Rest_Application
return $result;
}
/**
* Implementation for 'POST' method for Rest API
*
* @param mixed $appUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function post($appUid, $appNumber, $appParent, $appStatus, $proUid, $appProcStatus, $appProcCode, $appParallel, $appInitUser, $appCurUser, $appCreateDate, $appInitDate, $appFinishDate, $appUpdateDate, $appData, $appPin)
{
try {
$result = array();
$obj = new Application();
$obj->setAppUid($appUid);
$obj->setAppNumber($appNumber);
$obj->setAppParent($appParent);
$obj->setAppStatus($appStatus);
$obj->setProUid($proUid);
$obj->setAppProcStatus($appProcStatus);
$obj->setAppProcCode($appProcCode);
$obj->setAppParallel($appParallel);
$obj->setAppInitUser($appInitUser);
$obj->setAppCurUser($appCurUser);
$obj->setAppCreateDate($appCreateDate);
$obj->setAppInitDate($appInitDate);
$obj->setAppFinishDate($appFinishDate);
$obj->setAppUpdateDate($appUpdateDate);
$obj->setAppData($appData);
$obj->setAppPin($appPin);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'PUT' method for Rest API
*
* @param mixed $appUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function put($appUid, $appNumber, $appParent, $appStatus, $proUid, $appProcStatus, $appProcCode, $appParallel, $appInitUser, $appCurUser, $appCreateDate, $appInitDate, $appFinishDate, $appUpdateDate, $appData, $appPin)
{
try {
$obj = ApplicationPeer::retrieveByPK($appUid);
$obj->setAppNumber($appNumber);
$obj->setAppParent($appParent);
$obj->setAppStatus($appStatus);
$obj->setProUid($proUid);
$obj->setAppProcStatus($appProcStatus);
$obj->setAppProcCode($appProcCode);
$obj->setAppParallel($appParallel);
$obj->setAppInitUser($appInitUser);
$obj->setAppCurUser($appCurUser);
$obj->setAppCreateDate($appCreateDate);
$obj->setAppInitDate($appInitDate);
$obj->setAppFinishDate($appFinishDate);
$obj->setAppUpdateDate($appUpdateDate);
$obj->setAppData($appData);
$obj->setAppPin($appPin);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'DELETE' method for Rest API
*
* @param mixed $appUid Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function delete($appUid)
{
$conn = Propel::getConnection(ApplicationPeer::DATABASE_NAME);
try {
$conn->begin();
$obj = ApplicationPeer::retrieveByPK($appUid);
if (! is_object($obj)) {
throw new RestException(412, 'Record does not exist.');
}
$obj->delete();
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw new RestException(412, $e->getMessage());
}
}
}

View File

@@ -63,5 +63,81 @@ class Services_Rest_Translation
return $result;
}
/**
* Implementation for 'POST' method for Rest API
*
* @param mixed $trnCategory, $trnId, $trnLang Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function post($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
{
try {
$result = array();
$obj = new Translation();
$obj->setTrnCategory($trnCategory);
$obj->setTrnId($trnId);
$obj->setTrnLang($trnLang);
$obj->setTrnValue($trnValue);
$obj->setTrnUpdateDate($trnUpdateDate);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'PUT' method for Rest API
*
* @param mixed $trnCategory, $trnId, $trnLang Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function put($trnCategory, $trnId, $trnLang, $trnValue, $trnUpdateDate)
{
try {
$obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
$obj->setTrnValue($trnValue);
$obj->setTrnUpdateDate($trnUpdateDate);
$obj->save();
} catch (Exception $e) {
throw new RestException(412, $e->getMessage());
}
}
/**
* Implementation for 'DELETE' method for Rest API
*
* @param mixed $trnCategory, $trnId, $trnLang Primary key
*
* @return array $result Returns array within multiple records or a single record depending if
* a single selection was requested passing id(s) as param
*/
protected function delete($trnCategory, $trnId, $trnLang)
{
$conn = Propel::getConnection(TranslationPeer::DATABASE_NAME);
try {
$conn->begin();
$obj = TranslationPeer::retrieveByPK($trnCategory, $trnId, $trnLang);
if (! is_object($obj)) {
throw new RestException(412, 'Record does not exist.');
}
$obj->delete();
$conn->commit();
} catch (Exception $e) {
$conn->rollback();
throw new RestException(412, $e->getMessage());
}
}
}