diff --git a/test/config/modules/businessprocess/processes/broken_wrong-operator.conf b/test/config/modules/businessprocess/processes/broken_wrong-operator.conf new file mode 100644 index 0000000..9a58f23 --- /dev/null +++ b/test/config/modules/businessprocess/processes/broken_wrong-operator.conf @@ -0,0 +1 @@ +hostsAnd = host1;Hoststatus + host2;Hoststatus \ No newline at end of file diff --git a/test/config/modules/businessprocess/processes/simple_with-header.conf b/test/config/modules/businessprocess/processes/simple_with-header.conf new file mode 100644 index 0000000..7c986bb --- /dev/null +++ b/test/config/modules/businessprocess/processes/simple_with-header.conf @@ -0,0 +1,12 @@ +############################################ +# +# Title: Simple with header +# +############################################ + +hostsAnd = host1;Hoststatus & host2;Hoststatus +servicesOr = host1;ping | host2;ping | host3;ping +singleHost = host1;Hoststatus +minTwo = 2 of: hostsAnd + servicesOr + singleHost +top = minTwo & hostsAnd & servicesOr +display 1;top;Top Node \ No newline at end of file diff --git a/test/config/modules/businessprocess/processes/simple_without-header.conf b/test/config/modules/businessprocess/processes/simple_without-header.conf new file mode 100644 index 0000000..7d4efc6 --- /dev/null +++ b/test/config/modules/businessprocess/processes/simple_without-header.conf @@ -0,0 +1,6 @@ +hostsAnd = host1;Hoststatus & host2;Hoststatus +servicesOr = host1;ping | host2;ping | host3;ping +singleHost = host1;Hoststatus +minTwo = 2 of: hostsAnd + servicesOr + singleHost +top = minTwo & hostsAnd & servicesOr +display 1;top;Top Node \ No newline at end of file diff --git a/test/php/library/Businessprocess/Storage/LegacyStorageTest.php b/test/php/library/Businessprocess/Storage/LegacyStorageTest.php new file mode 100644 index 0000000..985ddf3 --- /dev/null +++ b/test/php/library/Businessprocess/Storage/LegacyStorageTest.php @@ -0,0 +1,112 @@ +assertInstanceOf( + $baseClass, + new LegacyStorage(Config::module('businessprocess')->getSection('global')) + ); + } + + public function testWhetherDefaultConfigDirIsDetermined() + { + $this->assertEquals( + $this->getTestsBaseDir('config/modules/businessprocess/processes'), + $this->makeInstance()->getConfigDir() + ); + } + + public function testWhetherAllProcessesAreListed() + { + $keys = array_keys($this->makeInstance()->listProcesses()); + sort($keys); + $this->assertEquals( + $keys, + array( + 'broken_wrong-operator', + 'simple_with-header', + 'simple_without-header', + ) + ); + } + + public function testWhetherHeadersAreRespectedInProcessList() + { + $keys = array_values($this->makeInstance()->listProcesses()); + sort($keys); + $this->assertEquals( + $keys, + array( + 'Simple with header (simple_with-header)', + 'broken_wrong-operator', + 'simple_without-header', + ) + ); + } + + public function testWhetherProcessFilenameIsReturned() + { + $this->assertEquals( + $this->getTestsBaseDir('config/modules/businessprocess/processes/simple_with-header.conf'), + $this->makeInstance()->getFilename('simple_with-header') + ); + } + + public function testWhetherExistingProcessExists() + { + $this->assertTrue( + $this->makeInstance()->hasProcess('simple_with-header') + ); + } + + public function testWhetherMissingProcessIsMissing() + { + $this->assertFalse( + $this->makeInstance()->hasProcess('simple_with-headerx') + ); + } + + public function testWhetherValidProcessCanBeLoaded() + { + $processClass = 'Icinga\\Module\\Businessprocess\\BusinessProcess'; + $this->assertInstanceOf( + $processClass, + $this->makeInstance()->loadProcess('simple_with-header') + ); + } + + public function testWhetherConfigCanBeLoadedFromAString() + { + $processClass = 'Icinga\\Module\\Businessprocess\\BusinessProcess'; + $this->assertInstanceOf( + $processClass, + $this->makeInstance()->loadFromString('dummy', 'a = Host1;ping & Host2;ping') + ); + } + + public function testWhetherProcessSourceCanBeFetched() + { + $this->assertEquals( + file_get_contents($this->getTestsBaseDir('config/modules/businessprocess/processes/simple_with-header.conf')), + $this->makeInstance()->getSource('simple_with-header') + ); + } + + /** + * @return LegacyStorage + */ + protected function makeInstance() + { + return new LegacyStorage(Config::module('businessprocess')->getSection('global')); + } +} \ No newline at end of file