<html>
<head>
<base href="https://wiki.asterisk.org/wiki">
<link rel="stylesheet" href="/wiki/s/en/2172/18/9/_/styles/combined.css?spaceKey=AST&forWysiwyg=true" type="text/css">
</head>
<body style="background: white;" bgcolor="white" class="email-body">
<div id="pageContent">
<div id="notificationFormat">
<div class="wiki-content">
<div class="email">
<h2><a href="https://wiki.asterisk.org/wiki/display/AST/SimpleTestCase">SimpleTestCase</a></h2>
<h4>Page <b>edited</b> by <a href="https://wiki.asterisk.org/wiki/display/~mjordan">Matt Jordan</a>
</h4>
<br/>
<h4>Changes (6)</h4>
<div id="page-diffs">
<table class="diff" cellpadding="0" cellspacing="0">
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >* It can originate _n_ calls into Asterisk in a successive sequence. <br>* It can determine the success of an originated call either by a UserEvent or by a Hangup event. <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">* Pass/failure is typically determined by other modules, or by classes that derive from SimpleTestCase. Classes that derive from SimpleTestCase can override the verify_event method, which is called when all channels have hung up (or all expected UserEvents have been received). <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">* If UserEvents are used, the test is assumed to pass if a configurable number of events are received. <br>* Pass/failure of the test is can be determined by other modules, or by classes that derive from SimpleTestCase. Classes that derive from SimpleTestCase can override the verify_event method, which is called for each UserEvent received. <br></td></tr>
<tr><td class="diff-unchanged" > <br>h1. Class Description <br></td></tr>
<tr><td class="diff-snipped" >...<br></td></tr>
<tr><td class="diff-unchanged" >| | ami | The starpy AMI object | | <br>|hangup| A twisted deferred callback function that is called when all channels have hung up <br></td></tr>
<tr><td class="diff-changed-lines" >| | result | <span class="diff-added-words"style="background-color: #dfd;">Object passed back from the result of the hangup AMI command | |</span> <br></td></tr>
<tr><td class="diff-deleted-lines" style="color:#999;background-color:#fdd;text-decoration:line-through;">|verify_event| <br>| | event | <br>|run| <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;">|verify_event| Virtual method that can be overriden by a derived class to provide additional logic on reception of a UserEvent. Returning true from this method will cause the SimpleTestCase class to process the next call; false will cause the test to fail. | | <br>| | event | The UserEvent object | | <br>|run| Override of TestCase.run. Creates the AMI factory. | | <br></td></tr>
<tr><td class="diff-unchanged" > <br>h1. Configuration <br></td></tr>
<tr><td class="diff-added-lines" style="background-color: #dfd;"> <br>||Keyword||Description||Required||Default|| <br>|expected-events|The expected number of UserEvents that should be received.|No| 1 | <br>|spawn-after-hangup|If true, Hangup events will cause the next call in the sequence to be originated. Otherwise, reception of UserEvents will trigger the next call in the sequence. Note that it is expected that if UserEvents are present, this value should be false.|No|False| <br>|ignore-originate-failures|Do not report an error if an originate fails.|No|False| <br>|test-iterations|A sequence of items that specify calls to originate.|No| | <br> <br>{note} <br>While you do not technically have to define any calls to originate in test-iterations, failing to do so will cause the reactor to timeout and the test to fail, unless some other mechanism is used to provide pass/fail status checking. <br>{note} <br> <br>h4. test-iterations <br> <br>||Keyword||Description||Required||Default|| <br>|channel|The channel to originate|Yes| | <br>|application| The application to connect to | *See Note | | <br>|context| The context in the dialplan to connect the originated call to | *See Note | | <br>|extension|The extension in the dialplan to connect the originated call to | *See Note | | <br>|priority|The priority in the dialplan to connect the originated call to | *See Note | | <br> <br>{note} <br>application is mutually exclusive with the context, extension, and priority settings. If context, extension, and priority are used, all three must be specified. Note that at least one of the two options must be specified. <br>{note} <br> <br>h1. Examples <br> <br>h4. cdr_accountcode <br> <br>{code} <br> <br>test-modules: <br> test-object: <br> config-section: test-object-config <br> typename: 'SimpleTestCase.SimpleTestCase' <br> <br>test-object-config: <br> spawn-after-hangup: True <br> test-iterations: <br> - <br> channel: 'Local/1@default' <br> application: 'Echo' <br>{code} <br> <br>h4. batch_cdrs <br> <br>{code} <br> <br>test-modules: <br> test-object: <br> config-section: test-object-config <br> typename: 'SimpleTestCase.SimpleTestCase' <br> <br>test-object-config: <br> spawn-after-hangup: True <br> ignore-originate-failures: True <br> test-iterations: <br> - <br> channel: 'Local/dial_busy@default' <br> application: 'Echo' <br> - <br> channel: 'Local/dial_busy@default' <br> application: 'Echo' <br> - <br> channel: 'Local/dial_answer@default' <br> application: 'Echo' <br> - <br> channel: 'Local/dial_answer@default' <br> application: 'Echo' <br>{code} <br></td></tr>
</table>
</div> <h4>Full Content</h4>
<div class="notificationGreySide">
<h1><a name="SimpleTestCase-Description"></a>Description</h1>
<p>SimpleTestCase is a class that inherits from TestCase and acts as a test object in the pluggable framework. SimpleTestCase has the following characteristics:</p>
<ul>
        <li>It controls a single instance of Asterisk.</li>
        <li>It can originate <em>n</em> calls into Asterisk in a successive sequence.</li>
        <li>It can determine the success of an originated call either by a UserEvent or by a Hangup event.</li>
        <li>If UserEvents are used, the test is assumed to pass if a configurable number of events are received.</li>
        <li>Pass/failure of the test is can be determined by other modules, or by classes that derive from SimpleTestCase. Classes that derive from SimpleTestCase can override the verify_event method, which is called for each UserEvent received.</li>
</ul>
<h1><a name="SimpleTestCase-ClassDescription"></a>Class Description</h1>
<ul>
        <li><b>Module:</b> SimpleTestCase</li>
        <li><b>Class:</b> SimpleTestCase : TestCase</li>
</ul>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Name</th>
<th class='confluenceTh'>Parameter</th>
<th class='confluenceTh'>Description</th>
<th class='confluenceTh'>Default</th>
</tr>
<tr>
<td class='confluenceTd'>_<em>init</em>_</td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> Constructor </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> </td>
<td class='confluenceTd'>test_path</td>
<td class='confluenceTd'> Optional. Full path to the directory executing the test. If used in the pluggable framework, this value will be populated.</td>
<td class='confluenceTd'> ''</td>
</tr>
<tr>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> test_config </td>
<td class='confluenceTd'> Optional. An object populated with values from the YAML configuration file. If used in the pluggable framework, this value will be populated.</td>
<td class='confluenceTd'>None</td>
</tr>
<tr>
<td class='confluenceTd'>ami_connect</td>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> Called when an AMI connection is made with the instance of Asterisk </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> ami </td>
<td class='confluenceTd'> The starpy AMI object </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>hangup</td>
<td class='confluenceTd'> A twisted deferred callback function that is called when all channels have hung up</td>
</tr>
<tr>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> result </td>
<td class='confluenceTd'> Object passed back from the result of the hangup AMI command </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>verify_event</td>
<td class='confluenceTd'> Virtual method that can be overriden by a derived class to provide additional logic on reception of a UserEvent. Returning true from this method will cause the SimpleTestCase class to process the next call; false will cause the test to fail. </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'> </td>
<td class='confluenceTd'> event </td>
<td class='confluenceTd'> The UserEvent object </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>run</td>
<td class='confluenceTd'> Override of TestCase.run. Creates the AMI factory. </td>
<td class='confluenceTd'> </td>
</tr>
</tbody></table>
</div>
<h1><a name="SimpleTestCase-Configuration"></a>Configuration</h1>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Keyword</th>
<th class='confluenceTh'>Description</th>
<th class='confluenceTh'>Required</th>
<th class='confluenceTh'>Default</th>
</tr>
<tr>
<td class='confluenceTd'>expected-events</td>
<td class='confluenceTd'>The expected number of UserEvents that should be received.</td>
<td class='confluenceTd'>No</td>
<td class='confluenceTd'> 1 </td>
</tr>
<tr>
<td class='confluenceTd'>spawn-after-hangup</td>
<td class='confluenceTd'>If true, Hangup events will cause the next call in the sequence to be originated. Otherwise, reception of UserEvents will trigger the next call in the sequence. Note that it is expected that if UserEvents are present, this value should be false.</td>
<td class='confluenceTd'>No</td>
<td class='confluenceTd'>False</td>
</tr>
<tr>
<td class='confluenceTd'>ignore-originate-failures</td>
<td class='confluenceTd'>Do not report an error if an originate fails.</td>
<td class='confluenceTd'>No</td>
<td class='confluenceTd'>False</td>
</tr>
<tr>
<td class='confluenceTd'>test-iterations</td>
<td class='confluenceTd'>A sequence of items that specify calls to originate.</td>
<td class='confluenceTd'>No</td>
<td class='confluenceTd'> </td>
</tr>
</tbody></table>
</div>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>While you do not technically have to define any calls to originate in test-iterations, failing to do so will cause the reactor to timeout and the test to fail, unless some other mechanism is used to provide pass/fail status checking.</td></tr></table></div>
<h4><a name="SimpleTestCase-testiterations"></a>test-iterations</h4>
<div class='table-wrap'>
<table class='confluenceTable'><tbody>
<tr>
<th class='confluenceTh'>Keyword</th>
<th class='confluenceTh'>Description</th>
<th class='confluenceTh'>Required</th>
<th class='confluenceTh'>Default</th>
</tr>
<tr>
<td class='confluenceTd'>channel</td>
<td class='confluenceTd'>The channel to originate</td>
<td class='confluenceTd'>Yes</td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>application</td>
<td class='confluenceTd'> The application to connect to </td>
<td class='confluenceTd'> *See Note </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>context</td>
<td class='confluenceTd'> The context in the dialplan to connect the originated call to </td>
<td class='confluenceTd'> *See Note </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>extension</td>
<td class='confluenceTd'>The extension in the dialplan to connect the originated call to </td>
<td class='confluenceTd'> *See Note </td>
<td class='confluenceTd'> </td>
</tr>
<tr>
<td class='confluenceTd'>priority</td>
<td class='confluenceTd'>The priority in the dialplan to connect the originated call to </td>
<td class='confluenceTd'> *See Note </td>
<td class='confluenceTd'> </td>
</tr>
</tbody></table>
</div>
<div class='panelMacro'><table class='noteMacro'><colgroup><col width='24'><col></colgroup><tr><td valign='top'><img src="/wiki/images/icons/emoticons/warning.gif" width="16" height="16" align="absmiddle" alt="" border="0"></td><td>application is mutually exclusive with the context, extension, and priority settings. If context, extension, and priority are used, all three must be specified. Note that at least one of the two options must be specified.</td></tr></table></div>
<h1><a name="SimpleTestCase-Examples"></a>Examples</h1>
<h4><a name="SimpleTestCase-cdraccountcode"></a>cdr_accountcode</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">test-modules:
test-object:
config-section: test-object-config
typename: 'SimpleTestCase.SimpleTestCase'
test-object-config:
spawn-after-hangup: True
test-iterations:
-
channel: 'Local/1@default'
application: 'Echo'</pre>
</div></div>
<h4><a name="SimpleTestCase-batchcdrs"></a>batch_cdrs</h4>
<div class="code panel" style="border-width: 1px;"><div class="codeContent panelContent">
<pre class="theme: Confluence; brush: java; gutter: false">test-modules:
test-object:
config-section: test-object-config
typename: 'SimpleTestCase.SimpleTestCase'
test-object-config:
spawn-after-hangup: True
ignore-originate-failures: True
test-iterations:
-
channel: 'Local/dial_busy@default'
application: 'Echo'
-
channel: 'Local/dial_busy@default'
application: 'Echo'
-
channel: 'Local/dial_answer@default'
application: 'Echo'
-
channel: 'Local/dial_answer@default'
application: 'Echo'</pre>
</div></div>
</div>
<div id="commentsSection" class="wiki-content pageSection">
<div style="float: right;" class="grey">
<a href="https://wiki.asterisk.org/wiki/users/removespacenotification.action?spaceKey=AST">Stop watching space</a>
<span style="padding: 0px 5px;">|</span>
<a href="https://wiki.asterisk.org/wiki/users/editmyemailsettings.action">Change email notification preferences</a>
</div>
<a href="https://wiki.asterisk.org/wiki/display/AST/SimpleTestCase">View Online</a>
|
<a href="https://wiki.asterisk.org/wiki/pages/diffpagesbyversion.action?pageId=20185614&revisedVersion=2&originalVersion=1">View Changes</a>
|
<a href="https://wiki.asterisk.org/wiki/display/AST/SimpleTestCase?showComments=true&showCommentArea=true#addcomment">Add Comment</a>
</div>
</div>
</div>
</div>
</div>
</body>
</html>