Skip to content
This repository has been archived by the owner on Dec 13, 2022. It is now read-only.

Commit

Permalink
test(traps): add SNMP trap group tests.
Browse files Browse the repository at this point in the history
  • Loading branch information
mariegallardo authored and loiclau committed Oct 24, 2017
1 parent 4cce9ee commit b83c870
Show file tree
Hide file tree
Showing 3 changed files with 138 additions and 0 deletions.
4 changes: 4 additions & 0 deletions behat.yml
Original file line number Diff line number Diff line change
Expand Up @@ -296,3 +296,7 @@ default:
test_clapi:
paths: [ %paths.base%/features/Clapi.feature ]
contexts: [ ClapiContext ]

traps_snmp_group_configuration:
paths: [ %paths.base%/features/TrapsSNMPGroupConfiguration.feature ]
contexts: [ TrapsSNMPGroupConfigurationContext ]
20 changes: 20 additions & 0 deletions features/TrapsSNMPGroupConfiguration.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
Feature: Edit a trap group
As a Centreon user
I want to manipulate a trap group
To see if all simples manipulations work

Background:
Given I am logged in a Centreon server
And a trap group is configured

Scenario: Change the properties of a trap group
When I change the properties of a trap group
Then the properties are updated

Scenario: Duplicate one existing trap group
When I duplicate a trap group
Then the new object has the same properties

Scenario: Delete one existing trap group
When I delete a trap group
Then the deleted object is not displayed in the list
114 changes: 114 additions & 0 deletions features/bootstrap/TrapsSNMPGroupConfigurationContext.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
<?php

use Centreon\Test\Behat\CentreonContext;
use Centreon\Test\Behat\Configuration\SnmpTrapGroupConfigurationPage;
use Centreon\Test\Behat\Configuration\SnmpTrapGroupConfigurationListingPage;

class TrapsSNMPGroupConfigurationContext extends CentreonContext
{
protected $currentPage;
protected $initialProperties = array(
'name' => 'trapGroupName',
'traps' => array(
'3com - secureViolation2',
'Dell - adRebuildFailed'
)
);
protected $updatedProperties = array(
'name' => 'trapGroupNameChanged',
'traps' => array(
'Generic - coldStart',
'HP - snTrapChasFanFailed'
)
);

/**
* @Given a trap group is configured
*/
public function aTrapGroupIsConfigured()
{
$this->currentPage = new SnmpTrapGroupConfigurationPage($this);
$this->currentPage->setProperties($this->initialProperties);
$this->currentPage->save();
}

/**
* @When I change the properties of a trap group
*/
public function iChangeThePropertiesOfATrapGroup()
{
$this->currentPage = new SnmpTrapGroupConfigurationListingPage($this);
$this->currentPage = $this->currentPage->inspect($this->initialProperties['name']);
$this->currentPage->setProperties($this->updatedProperties);
$this->currentPage->save();
}

/**
* @Then the properties are updated
*/
public function thePropertiesAreUpdated()
{
// No need to visit listing page, already loaded.
$this->currentPage = new SnmpTrapGroupConfigurationListingPage($this, false);
$this->currentPage = $this->currentPage->inspect($this->updatedProperties['name']);
$object = $this->currentPage->getProperties();
foreach ($this->updatedProperties as $key => $value) {
$expected = is_array($value) ? implode(' ', $value) : $value;
if ($expected != $object[$key]) {
throw new \Exception(
'Property ' . $key . ' was not updated: got ' .
$object[$key] . ', expected ' . $expected
);
}
}
}

/**
* @When I duplicate a trap group
*/
public function iDuplicateATrapGroup()
{
$this->currentPage = new SnmpTrapGroupConfigurationListingPage($this);
$object = $this->currentPage->getEntry($this->initialProperties['name']);
$this->assertFind('css', 'input[type="checkbox"][name="select[' . $object['id'] . ']"]')->check();
$this->setConfirmBox(true);
$this->selectInList('select[name="o1"]', 'Duplicate');
}

/**
* @Then the new object has the same properties
*/
public function theNewObjectHasTheSameProperties()
{
$this->updatedProperties = $this->initialProperties;
$this->updatedProperties['name'] .= '_1';
$this->thePropertiesAreUpdated();
}

/**
* @When I delete a trap group
*/
public function iDeleteATrapGroup()
{
$this->currentPage = new SnmpTrapGroupConfigurationListingPage($this);
$object = $this->currentPage->getEntry($this->initialProperties['name']);
$this->assertFind('css', 'input[type="checkbox"][name="select[' . $object['id'] . ']"]')->check();
$this->setConfirmBox(true);
$this->selectInList('select[name="o1"]', 'Delete');
}

/**
* @Then the deleted object is not displayed in the list
*/
public function theDeletedObjectIsNotDisplayedInTheList()
{
$this->currentPage = new SnmpTrapGroupConfigurationListingPage($this, false);
$this->spin(
function ($context) {
$object = $context->currentPage->getEntries();
return !array_key_exists($context->initialProperties['name'], $object);
},
'Service ' . $this->initialProperties['name'] . ' is not being deleted.'
);
}
}

0 comments on commit b83c870

Please sign in to comment.