<?xml version="1.0" encoding="UTF-8"?>
	<!--
	Test: 10.2.2 283 285 (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'
	-->
	
<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_283" expr="new Object();"/>
<var name="result_285" expr="new Object();"/>
  <script>
<![CDATA[
		var i=0;
		assertions[i++] = init_assertion('283');
		assertions[i++] = init_assertion('285');

		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 ) {
					assertion.P_F = "PASS";
			}
			else {
				assertion.P_F = "FAIL";
			}
		}
		
		
		function checkConnection(event, connectionState, result1, result2 ) {
			setResult( event.connection != null, result1);
							
			setResult( connectionState == event.connection.state, result2);
							
			return true;
		}
]]> </script>
	
  <eventprocessor statevariable="current_state">
	  <conf:setup type="alerting"/>

	  	<transition event="connection.alerting" state="init">
		 	<if cond="checkConnection(event$, Connection.ALERTING, result_283, result_285)">
			</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_283" state="ASSERTION_NMBR_283">
		<!--
283 	
10.2.2 &lt;assign&gt; and &lt;var&gt; 	
An instance of the Connection Object is associated with each telephony event source.	mscott@voicegenie.com	Accepted 
-->
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<reject connectionid="ConnectionID"/>
	</transition>
	
	<transition state="ASSERTION_NMBR_283" event="connection.disconnected">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		 	<if cond="checkConnection(event$, Connection.DISCONNECTED, result_283, result_285)">
		</if>
			<if cond="result_283.P_F == 'PASS'">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<else/>
				<script>
				assertions[assert_index].P_F = s_FAIL;
				assertions[assert_index].reason = 'A connection object was not created during an event.';
				</script>
			</if>
		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
	</transition>

	<transition event="user.START_ASSERTION_285" state="ASSERTION_NMBR_285">
		<!--
285 	
10.2.2 &lt;assign&gt; and &lt;var&gt; 	
A Connection Object must have a state property which identifies the current state of the Connection instance. 	rachel.muller@aspect.com 	Accepted 
-->
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="result_285.P_F == 'PASS'">
			<script>assertions[assert_index].P_F = s_PASS;</script>
				<else/>
				<script>
				assertions[assert_index].P_F = s_FAIL;
				assertions[assert_index].reason = 'Wrong state found during an event.';
				</script>
		</if>
		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
	</transition>
	
	<!--    CatchAll for all statges -->
	
	<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>
