<?xml version="1.0" encoding="UTF-8"?>
	<!--
	Test: 10.2.2 1292 1295 (optional assertions not tested 286 296 297 298 299 300 301 302 303 304 305 306 307 308)
    Test: 10.2.3 1292 1295 (optional assertions not tested 309 1293 1294)
    require 'ALERTING'
	-->
	
<!--
Release 1.1 - 2011-03-25
FIXED:  
  TA 1292 added comment: Double PASS in logs is mandatory to consider TA 1292 passed 
  TA 1295 added comment: Double PASS in logs is mandatory to consider TA 1295 passed 
-->	
	
<ccxml xmlns="http://www.w3.org/2002/09/ccxml" xmlns:conf="http://www.w3.org/2005/ccxml-conformance" version="1.0">

  <conf:docsetup/>
  <var name="ConnectionID"/>
  <var name="results" expr="new Object()"/>
<var name="result_1292" expr="new Object();"/>
<var name="result_1295" expr="new Object();"/>
  <script>
<![CDATA[
		var i=0;
		assertions[i++] = init_assertion('1292');
		assertions[i++] = init_assertion('1295');

		var assert_last = i - 1;
		var assert_index = -1;
	
		
		s_ASSERTIONS_LEFT = show_remained_assertions();
		var b_in_test = false;

		// return false if any test failed
		
		function setResult(condition, assertion) {
			if ( condition ) {
				if (assertion.P_F != "FAIL") {
					assertion.P_F = "PASS";
				}
			}
			else {
				assertion.P_F = "FAIL";
			}
		}
		
		
		function checkConnection(event, session, result1, result2 ) {
			setResult( event.connectionid == event.connection.connectionid, result1);
							
			setResult( session.connections[event.connectionid] == event.connection, result2 );
							
			return true;
		}
]]> </script>
	
  <eventprocessor statevariable="current_state">
	  <conf:setup type="alerting"/>

	  	<transition event="connection.alerting" state="init">
		 	<if cond="checkConnection(event$, session, result_1292, result_1295)">
			</if>
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>

		<transition event="user.PREPARE_NEW">
			<conf:comment expr="'Event: ' + event$.name"/>
			<if cond="assert_index &gt;= 0">
				<assign name="ASSERTION_NUM" expr="assertions[assert_index].number"/>
				<assign name="t_ASSERT_RESULT" expr="assertions[assert_index].P_F"/>
				<script>assertions[assert_index].reason = t_ASSERT_REASON;</script>
				<if cond="t_ASSERT_RESULT == s_PASS">
					<conf:pass reason="t_ASSERT_REASON"/>
					<elseif cond="t_ASSERT_RESULT == s_FAIL"/>
					<conf:fail reason="t_ASSERT_REASON"/>
					<else/>
					<conf:not_exec reason="t_ASSERT_REASON"/>
				</if>
			</if>
			<assign name="assert_index" expr="assert_index + 1"/>
			<if cond="assert_index &gt; assert_last">
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<conf:uncond_exit expr="'DONE'"/>
				<else/>
				<log label="s_TA" expr="s_ASSERTIONS_LEFT"/>
				<assign name="ASSERTION_NUM" expr=" assertions[assert_index].number"/>
				<assign name="t_ASSERT_REASON" expr="''"/>
				<script>assertions[assert_index].P_F = s_FAIL;</script>
				<assign name="current_state" expr="state_prefix + ASSERTION_NUM"/>
				<send targettype="'ccxml'" target="session.id" name="start_name_prefix + ASSERTION_NUM"/>
			</if>
		</transition>
	
	<!--================== Test Stage: TEST_INTBOUND_REJECTED =================-->
	
	<transition event="user.START_ASSERTION_1292" state="ASSERTION_NMBR_1292">
		<!--
1292	
10.2.3 &lt;assign&gt; and &lt;var&gt; 	
All Connection events MUST have a property named connectionid containing the ID of the Connection associated with the event. 	mscott@voicegenie.com	Accepted 
-->
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<reject connectionid="ConnectionID"/>
	</transition>
	
	<transition state="ASSERTION_NMBR_1292" event="connection.disconnected">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
			<if cond="result_1292.P_F == 'PASS'">
			    <conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name + ' - Double PASS in logs is mandatory to consider TA 1292 passed'"/>
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<else/>
				<script>
				assertions[assert_index].P_F = s_FAIL;
				assertions[assert_index].reason = 'Connection ID of a connection object is incorrect.';
				</script>
			</if>
		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
	</transition>

	<transition event="user.START_ASSERTION_1295" state="ASSERTION_NMBR_1295">
		<!--
1295	
10.2.3 &lt;assign&gt; and &lt;var&gt; 	
All Connection events MUST have a property named connection containing a reference to the Connection object identified by the connectionid property of this event.	mscott@voicegenie.com	Accepted 
-->
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="result_1295.P_F == 'PASS'">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name + ' - Double PASS in logs is mandatory to consider TA 1295 passed'"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
				<else/>
				<script>
				assertions[assert_index].P_F = s_FAIL;
				assertions[assert_index].reason = 'A connection is not referenced properly.';
				</script>
		</if>
		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
	</transition>
		
	<!--  ***************** COMMON ******************************** -->
	
	<transition event="send.successful">
	</transition>
	
	<transition event="connection.disconnected">
			<conf:uncond_exit expr="'CONNECTION-DISCONNECTED'"/>
		</transition>

	<transition event="*">
			<assign name="t_ASSERT_REASON" expr="'UNEXPECTED EVENT ' + event$.name + ' IN STATE ' + current_state"/>
				<conf:comment expr="t_ASSERT_REASON"/>
				<if cond="current_state == 'init'">
					<conf:uncond_exit expr="'Did not come out from init state.'"/>
				<else/>
					<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
				</if>  
    </transition>
    
  </eventprocessor>
</ccxml>
