mirror of
https://github.com/Icinga/icingaweb2-module-businessprocess.git
synced 2025-12-27 17:49:35 -05:00
NotOperatorTest: make it easier to understand
This commit is contained in:
parent
8b9716c9b2
commit
d6f1d86ea4
2 changed files with 112 additions and 7 deletions
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
use Icinga\Module\Businessprocess\Test\Bootstrap;
|
||||
|
||||
call_user_func(function() {
|
||||
call_user_func(function () {
|
||||
$basedir = dirname(__DIR__);
|
||||
require_once $basedir . '/library/Businessprocess/Test/Bootstrap.php';
|
||||
Bootstrap::cli($basedir);
|
||||
|
|
|
|||
|
|
@ -1,14 +1,14 @@
|
|||
<?php
|
||||
|
||||
namespace Tests\Icinga\Module\Businessprocess\Storage;
|
||||
namespace Tests\Icinga\Module\Businessprocess\Operator;
|
||||
|
||||
use Icinga\Module\Businessprocess\BpNode;
|
||||
use Icinga\Module\Businessprocess\BusinessProcess;
|
||||
use Icinga\Module\Businessprocess\Test\BaseTestCase;
|
||||
use Icinga\Module\Businessprocess\Storage\LegacyStorage;
|
||||
|
||||
class NotOperatorTest extends BaseTestCase
|
||||
{
|
||||
public function testWhetherNegationsCanBeParsed()
|
||||
public function testNegationOperatorsCanBeParsed()
|
||||
{
|
||||
$storage = new LegacyStorage($this->emptyConfigSection());
|
||||
$expressions = array(
|
||||
|
|
@ -26,7 +26,7 @@ class NotOperatorTest extends BaseTestCase
|
|||
}
|
||||
}
|
||||
|
||||
public function testWhetherNegationsMatch()
|
||||
public function testASimpleNegationGivesTheCorrectResult()
|
||||
{
|
||||
$storage = new LegacyStorage($this->emptyConfigSection());
|
||||
$expression = 'a = !b';
|
||||
|
|
@ -46,7 +46,7 @@ class NotOperatorTest extends BaseTestCase
|
|||
);
|
||||
}
|
||||
|
||||
public function testWhetherNegatingMultipleValuesBehavesLikeNotAnd()
|
||||
public function testAnExpressionGivesTheCorrectResultForVariousStateCombinations()
|
||||
{
|
||||
$storage = new LegacyStorage($this->emptyConfigSection());
|
||||
$expression = 'a = ! b ! c ! d';
|
||||
|
|
@ -81,5 +81,110 @@ class NotOperatorTest extends BaseTestCase
|
|||
$a->getStateName()
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
public function testThreeTimesCriticalIsOk()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 2);
|
||||
$bp->setNodeState('c', 2);
|
||||
$bp->setNodeState('d', 2);
|
||||
|
||||
$this->assertEquals(
|
||||
'OK',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testThreeTimesUnknownIsOk()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 3);
|
||||
$bp->setNodeState('c', 3);
|
||||
$bp->setNodeState('d', 3);
|
||||
|
||||
$this->assertEquals(
|
||||
'OK',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testThreeTimesWarningIsWarning()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 1);
|
||||
$bp->setNodeState('c', 1);
|
||||
$bp->setNodeState('d', 1);
|
||||
|
||||
$this->assertEquals(
|
||||
'WARNING',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testThreeTimesOkIsCritical()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 0);
|
||||
$bp->setNodeState('c', 0);
|
||||
$bp->setNodeState('d', 0);
|
||||
|
||||
$this->assertEquals(
|
||||
'CRITICAL',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testNotOkAndWarningAndCriticalIsOk()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 0);
|
||||
$bp->setNodeState('c', 1);
|
||||
$bp->setNodeState('d', 2);
|
||||
|
||||
$this->assertEquals(
|
||||
'OK',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testNotWarningAndUnknownAndCriticalIsOk()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 3);
|
||||
$bp->setNodeState('c', 2);
|
||||
$bp->setNodeState('d', 1);
|
||||
|
||||
$this->assertEquals(
|
||||
'OK',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
public function testNotTwoTimesWarningAndOkIsWarning()
|
||||
{
|
||||
$bp = $this->getBp();
|
||||
$bp->setNodeState('b', 0);
|
||||
$bp->setNodeState('c', 1);
|
||||
$bp->setNodeState('d', 1);
|
||||
|
||||
$this->assertEquals(
|
||||
'WARNING',
|
||||
$bp->getNode('a')->getStateName()
|
||||
);
|
||||
}
|
||||
|
||||
/**
|
||||
* @return BusinessProcess
|
||||
*/
|
||||
protected function getBp()
|
||||
{
|
||||
$storage = new LegacyStorage($this->emptyConfigSection());
|
||||
$expression = 'a = ! b ! c ! d';
|
||||
$bp = $storage->loadFromString('dummy', $expression);
|
||||
$bp->createBp('b');
|
||||
$bp->createBp('c');
|
||||
$bp->createBp('d');
|
||||
|
||||
return $bp;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue