diff --git a/composer.lock b/composer.lock index c88ab87b8679253ce81d50b768201639ceff2ab7..adccc389c7bf515952704c159226a9066b345f52 100644 --- a/composer.lock +++ b/composer.lock @@ -8,11 +8,11 @@ "packages": [ { "name": "jards/eventsapiclient", - "version": "v2.2", + "version": "v2.4", "source": { "type": "git", "url": "https://gitlab.version.fz-juelich.de/jards/EventsAPIClient.git", - "reference": "69d8a58854ea6a7cd822a568ba3b6aab70719f7d" + "reference": "b36657b4f7bdf30e8f4f9c0ecf1d77af1a6bc085" }, "require": { "ext-curl": "*", @@ -53,7 +53,7 @@ "sdk", "swagger" ], - "time": "2017-11-06T10:22:24+00:00" + "time": "2018-01-15T15:34:22+00:00" }, { "name": "phpmailer/phpmailer", diff --git a/configs/myurl.cnf b/configs/myurl.cnf new file mode 100644 index 0000000000000000000000000000000000000000..92ddf559c1ddfe15532505ae681523662b4b9b26 --- /dev/null +++ b/configs/myurl.cnf @@ -0,0 +1 @@ +https://<hostname>/<path to events> \ No newline at end of file diff --git a/rest/events/events_api.json b/rest/events/events_api.json index 5557b690ae59e56a476891f14b84fd706b104998..ad18ec194329dc4bc500f5bc18f9ede5e321f9c3 100644 --- a/rest/events/events_api.json +++ b/rest/events/events_api.json @@ -1,7 +1,7 @@ { "swagger": "2.0", "info": { - "version": "0.0.1", + "version": "0.1", "title": "Event receiver service. Send any events, which should be handled by this service." }, "consumes": [ @@ -76,17 +76,71 @@ ], "properties": { "date": { + "description": "Date when the event happened.", "type": "string", "format": "date-time" }, "name": { + "description": "Name of the event", "type": "string" }, "description": { + "description": "Detailled description on what happened during this event", "type": "string" }, "id":{ + "description": "Internal event ID, differs for every EventsAPI instance", "type": "integer" + }, + "source": { + "description": "Who has triggered the event?", + "type": "string" + }, + "newState": { + "description": "The new state for the project or application caused by the event", + "type": "string" + }, + "triggerType": { + "description": "Name of the trigger which is activated by this event", + "type": "string" + }, + "project" : { + "$ref": "#/definitions/Project" + }, + "application" : { + "$ref": "#/definitions/Application" + } + } + }, + "Project": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "description": "Project ID", + "type": "string" + }, + "type": { + "description": "Project type such as regular, gcs, test, large-scale", + "type": "string" + } + } + }, + "Application": { + "type": "object", + "required": [ + "id" + ], + "properties": { + "id": { + "description": "Application / Proposal ID", + "type": "integer" + }, + "type": { + "description": "Proposal type such as extension or new", + "type": "string" } } } diff --git a/tests/EventManagementTest.php b/tests/EventManagementTest.php index cc0d10261b3fcd16363b3cfe544ddfcf7515793f..38bd75272ebdc5626cacbbd1710b56b379679153 100644 --- a/tests/EventManagementTest.php +++ b/tests/EventManagementTest.php @@ -22,4 +22,53 @@ class EventManagementTest extends TestCase{ $this->assertTrue(is_array($eventsArray) || is_empty($eventsArray), "Result of event management is not an array." ); } + protected function getExistingEventIDs(){ + $eventManagement = new EventManagement(); + $events = $eventManagement->getEvents(); + + $content = $events->getContent(); + $eventsArray = json_decode($content); + + $oldEventIDs = array(); + + foreach($eventsArray as $event){ + $id = $event->id; + $oldEventIDs[] = $id; + } + + sort($oldEventIDs); + + return $oldEventIDs; + } + + /** + * Send an event. Deletes all new created event objects + */ + public function testSendEvent(){ + echo "testSendEvent\n"; + + $eventManagement = new EventManagement(); + + $oldEventIDs = $this->getExistingEventIDs(); + + $url = file_get_contents(__DIR__.'/../configs/myurl.cnf'); + + $eventManagement->sendEvent('test event', 'This is only a test', $url); + + $newEventIDs = $this->getExistingEventIDs(); + + $this->assertNotEquals(join('|', $oldEventIDs), join('|', $newEventIDs), "No event seems to be sent"); + + foreach($newEventIDs as $newID){ + if(! in_array($newID, $oldEventIDs)){ + $toDelete = __DIR__.'/../data/'.$newID.'.obj'; + unlink($toDelete); + } + } + + $newEventIDs = $this->getExistingEventIDs(); + + $this->assertEquals(join('|', $oldEventIDs), join('|', $newEventIDs), "Could not revert new created events"); + } + } \ No newline at end of file