From d6f1d86ea4bf35cef8cb49b4cb5f44c83eb48ffc Mon Sep 17 00:00:00 2001 From: Thomas Gelf Date: Wed, 23 Nov 2016 23:02:32 +0100 Subject: [PATCH] NotOperatorTest: make it easier to understand --- test/bootstrap.php | 2 +- .../Operators/NotOperatorTest.php | 117 +++++++++++++++++- 2 files changed, 112 insertions(+), 7 deletions(-) diff --git a/test/bootstrap.php b/test/bootstrap.php index 9a0fe64..40c16cf 100644 --- a/test/bootstrap.php +++ b/test/bootstrap.php @@ -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); diff --git a/test/php/library/Businessprocess/Operators/NotOperatorTest.php b/test/php/library/Businessprocess/Operators/NotOperatorTest.php index d1fcbe9..0185d59 100644 --- a/test/php/library/Businessprocess/Operators/NotOperatorTest.php +++ b/test/php/library/Businessprocess/Operators/NotOperatorTest.php @@ -1,14 +1,14 @@ 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; + } +}