Commit ecb41b14 authored by Oana-Eliza Alexa's avatar Oana-Eliza Alexa
Browse files

write 2 more tests

1 merge request!73Draft: Resolve "Create unitests for orchestrator"
Pipeline #32490 failed with stages
in 33 seconds
Showing with 92 additions and 0 deletions
+92 -0
......@@ -255,4 +255,96 @@ class NotificationsTest extends TestCase
$result = $notifications->processEndPointPost();
$this->assertEmpty($result);
}
public function testProcessNotificationsOneTaskToProcessOneMatchingAttributes ()
{
$taskData = [
'status' => 1,
'fdtasksgranularmaster' => ['main task'],
'maintask' => [
[
'fdtasksnotificationslistofrecipientsmails' => ['abc@yahoo.com', 'def@gmail.com'],
'fdtasksnotificationsemailsender' => ['sender@fd.com', 'sender@email.com'],
'fdtasksnotificationsmailtemplate' => ['template1'],
'mailInfos' => [],
'fdtasksnotificationsattributes' => ['resource2', 'resource3'],
'fdtasksnotificationsresource' => ['test resource'],
'fdtasksnotificationsstate' => ['test state'],
'fdtasksnotificationssubstate' => ['test substate'],
]
],
'fdtasksgranularref' => ['resource1'],
'fdtasksgranulardn' => ['granulardn'],
'dn' => 'testdn',
'cn' => ['mycn'],
'monitoredattrs' => [
[
'fdauditattributes' => [json_encode(['resource2' => 'value2'])],
]
]
];
$taskGateway = $this->createMock(TaskGateway::class);
$taskGateway->expects($this->once())->method('statusAndScheduleCheck')->willReturnCallback(function ($task) {
return $task['status'] == 1;
});
$taskGateway->expects($this->exactly(2))->method('getLdapTasks')->willReturnCallback(function ($filter, $attrs, $attachmentsCN, $dn) use ($taskData) {
if ($dn == 'resource1') {
return $taskData['monitoredattrs'];
}
return $taskData['maintask'][0]['mailInfos'];
});
$notifications = $this->getMockBuilder(Notifications::class)->setConstructorArgs([$taskGateway])->onlyMethods(['getNotificationsMainTask', 'sendNotificationsMail'])->getMock();
$notifications->expects($this->once())->method('getNotificationsMainTask')->willReturn($taskData['maintask']);
$notifications->expects($this->once())->method('sendNotificationsMail')->willReturn([TRUE]);
$task = new NotificationsTask($taskData);
$result = $notifications->processNotifications([$task->toArray()]);
$expectedOutput = [[TRUE]];
$this->assertEquals($expectedOutput, $result);
}
public function testProcessNotificationsOneTaskToProcessSupannMatchingAttributes ()
{
$taskData = [
'status' => 1,
'fdtasksgranularmaster' => ['main task'],
'maintask' => [
[
'fdtasksnotificationslistofrecipientsmails' => ['abc@yahoo.com', 'def@gmail.com'],
'fdtasksnotificationsemailsender' => ['sender@fd.com', 'sender@email.com'],
'fdtasksnotificationsmailtemplate' => ['template1'],
'mailInfos' => [],
'fdtasksnotificationsattributes' => ['resource2', 'resource3'],
'fdtasksnotificationsresource' => ['test resource'],
'fdtasksnotificationsstate' => ['test state'],
'fdtasksnotificationssubstate' => ['test substate'],
]
],
'fdtasksgranularref' => ['resource1'],
'fdtasksgranulardn' => ['granulardn'],
'dn' => 'testdn',
'cn' => ['mycn'],
'monitoredattrs' => [
[
'fdauditattributes' => [json_encode(['resource2' => '{test resource}test state:test substate'])],
]
]
];
$taskGateway = $this->createMock(TaskGateway::class);
$taskGateway->expects($this->once())->method('statusAndScheduleCheck')->willReturnCallback(function ($task) {
return $task['status'] == 1;
});
$taskGateway->expects($this->exactly(2))->method('getLdapTasks')->willReturnCallback(function ($filter, $attrs, $attachmentsCN, $dn) use ($taskData) {
if ($dn == 'resource1') {
return $taskData['monitoredattrs'];
}
return $taskData['maintask'][0]['mailInfos'];
});
$notifications = $this->getMockBuilder(Notifications::class)->setConstructorArgs([$taskGateway])->onlyMethods(['getNotificationsMainTask', 'sendNotificationsMail'])->getMock();
$notifications->expects($this->once())->method('getNotificationsMainTask')->willReturn($taskData['maintask']);
$notifications->expects($this->once())->method('sendNotificationsMail')->willReturn([TRUE]);
$task = new NotificationsTask($taskData);
$result = $notifications->processNotifications([$task->toArray()]);
$expectedOutput = [[TRUE]];
$this->assertEquals($expectedOutput, $result);
}
}
\ No newline at end of file
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment