Skip to content
Snippets Groups Projects
Commit 9be98972 authored by Carsten Karbach's avatar Carsten Karbach
Browse files

Allow to send events as Model objects

parent a0802ea9
No related branches found
No related tags found
No related merge requests found
......@@ -178,6 +178,27 @@ class EventManagement{
*/
public function sendEvent($name, $description, $baseURL='http://localhost/myapps/EventsAPI/rest/events', $certFile = null, $certKey = null, $certPassphrase = null){
$event = new Event();
$event->setName($name);
$event->setDescription($description);
$event->setDate(new \DateTime());
return $this->sendEventObject($event, $baseURL, $certFile, $certKey, $certPassphrase);
}
/**
* Send an event according to swagger API model.
* Prepare any event you like, then send it with this function.
*
* @param Event $eventObject the event object you would like to send
* @param string $baseURL the root URL of the event receiver REST API
* @param string $certFile path to certificate file to use or null to call URL without certificate
* @param string $certKey path to certificate key file, null to avoid usage of key
* @param string $certPassphrase path to passphrase file for key file, null for no passphrase
*
* @return boolean true on success, false on error
*/
public function sendEventObject($eventObject, $baseURL='http://localhost/myapps/EventsAPI/rest/events', $certFile = null, $certKey = null, $certPassphrase = null){
date_default_timezone_set ( 'Europe/Amsterdam' );
$apiClient = new \jards\eventsapiclient\Swagger\Client\ApiClient ();
$apiClient->getConfig ()->setHost ( $baseURL );
......@@ -194,13 +215,8 @@ class EventManagement{
$eventsApi = new EventsApi($apiClient);
$event = new Event();
$event->setName($name);
$event->setDescription($description);
$event->setDate(new \DateTime());
try{
$eventsApi->eventsPost($event);
$eventsApi->eventsPost($eventObject);
}
catch(\jards\eventsapiclient\Swagger\Client\ApiException $e){
return false;
......
......@@ -4,6 +4,7 @@ namespace jards\eventsapi\tests;
use PHPUnit\Framework\TestCase;
use jards\eventsapi\EventManagement;
use jards\eventsapiclient\Swagger\Client\Model\Event;
class EventManagementTest extends TestCase{
......@@ -54,13 +55,26 @@ class EventManagementTest extends TestCase{
$url = file_get_contents(__DIR__.'/../configs/myurl.cnf');
$success = $eventManagement->sendEvent('test event', 'This is only a test', $url);
$this->assertTrue($success, "Event sending was not successful");
$newEventIDs = $this->getExistingEventIDs();
$this->assertNotEquals(join('|', $oldEventIDs), join('|', $newEventIDs), "No event seems to be sent");
//Send event directly
$event = new Event();
$event->setName('My event');
$event->setDescription('Good event for testing');
$event->setNewState('none');
$event->setDate(new \DateTime());
$success = $eventManagement->sendEventObject($event, $url);
$this->assertTrue($success, "Event sending was not successful");
$newEventIDs2 = $this->getExistingEventIDs();
$this->assertNotEquals(join('|', $newEventIDs), join('|', $newEventIDs2), "No event seems to be sent when sending event object");
$newEventIDs = $newEventIDs2;
foreach($newEventIDs as $newID){
if(! in_array($newID, $oldEventIDs)){
$toDelete = __DIR__.'/../data/'.$newID.'.obj';
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment