<?xml version="1.0" encoding="UTF-8"?>
<ccxml xmlns="http://www.w3.org/2002/09/ccxml" xmlns:conf="http://www.w3.org/2005/ccxml-conformance" version="1.0">
<!--
Serguei's infrastructure performs a loop on the 'assertions' Ecma array, based on "name_prepare_new" event for doing the "loop".

Mainly we have to different levels of assertions: 

- Main assertions, stored in 'assertions' array
- Children assertions, stored into 'assert_trace'

An assertion is a child assertion if it does not need to perform any action, but it is sufficient to test its father assertion result to determine if it passes or fails.

The test finishes when all the main assertions have been tested. Children assertions are tested after the father itself.

If an unexpected event is caught by the <transition event"*"/> a comment is printed and the loop continues with the next iteration.

An hang up event causes the interruption of test: session exits.

All the send.successful events are caught and ignored (they are generated by the loop mechanism).
-->

	<conf:docsetup/>

	<var name="mySendID"/>
	<var name="myConnectionID"/>

 	

	<script><![CDATA[
		var i=0;
		
		assertions[i++] = init_assertion('23');		
		assertions[i++] = init_assertion('1088');		
		assertions[i++] = init_assertion('24');		
		assertions[i++] = init_assertion('21');		
		
			
		var assert_last = i - 1;
		var assert_index = -1;
	
		// out of the loop assertions (children)

		// Children of 21
		add_2_assert_trace('27');
		add_2_assert_trace('28');
		add_2_assert_trace('19');
		add_2_assert_trace('201');
		add_2_assert_trace('1118');

		
		s_ASSERTIONS_LEFT = show_remained_assertions();
		var b_in_test = false;
	]]></script>
	
	
	<eventprocessor statevariable="current_state">
		<conf:setup type="connected"/>

		<transition event="connection.connected" state="init">
			<conf:comment expr="'Event: ' + event$.name"/>
	    <assign name="myConnectionID" expr="event$.connectionid"/>			
	    <send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_VERY_LONG_TIMEOUT"/>			
			<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>

    	      			
<!--
23.
redirect
If the connection id attribute value is invalid or there is no valid default value, an error.semantic event must be thrown.

-->

		<transition event="user.START_ASSERTION_23" state="ASSERTION_NMBR_23">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
      <redirect connectionid="'I am a fake conenctionid'" dest="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[0]"/>
		</transition>
		

		<transition event="error.semantic" state="ASSERTION_NMBR_23">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_PASS;</script>					
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
		<transition event="send.successful" state="ASSERTION_NMBR_23">
		</transition>
		    
		<transition event="*" state="ASSERTION_NMBR_23">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<assign name="t_ASSERT_REASON" expr="'error.semantic expected, '+ event$.name + ' received.'"/>			 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>


<!--
1088.
redirect
If the platform is unable to redirect the call this MUST result in the generation of an connection.redirect.failed event.
-->

		<transition event="user.START_ASSERTION_1088" state="ASSERTION_NMBR_1088">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
      <redirect connectionid="myConnectionID" dest="'sip:1.1.1.345'"/>
		</transition>
		

		<transition event="connection.redirect.failed" state="ASSERTION_NMBR_1088">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_PASS;</script>					
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
		<transition event="send.successful" state="ASSERTION_NMBR_1088">
		</transition>
		    
		<transition event="*" state="ASSERTION_NMBR_1088">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<assign name="t_ASSERT_REASON" expr="'connection.redirect.failed expected, '+ event$.name + ' received.'"/>			 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>

<!--
24.
A <redirect> must have a dest attribute which is an ECMAScript expression which returns a string that is the address where the call should be redirected to.
-->

		<transition event="user.START_ASSERTION_24" state="ASSERTION_NMBR_24">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
      <assign name="application.myConnectionID" expr="myConnectionID"/>
      <fetch next="'ccxml_ko_redirect.ccxml'"/>
		</transition>
		

		<transition event="error.fetch" state="ASSERTION_NMBR_24">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_PASS;</script>					
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
		<transition event="send.successful" state="ASSERTION_NMBR_24">
		</transition>
		    
		<transition event="*" state="ASSERTION_NMBR_24">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<assign name="t_ASSERT_REASON" expr="'error.fetch expected, '+ event$.name + ' received.'"/>			 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
<!--
21.
redirect
A <redirect> may have a connectionid attribute which is an ECMAScript expression which returns a string that is the identifier of a Connection on which a call is active or on which an incoming call is being signaled.


 	
27.
A <redirect> may have a reason attribute which is an ECMAScript expression which returns a string that is the reason the call is being redirected.

28.
A <redirect> may have a hints attribute which is the ECMAScript object returned contains information which may be used by the implementing platform or passed to the network redirecting the connection. This information may consist of protocol-specific parameters.

19.
When a CCXML document executes a <redirect> within the <transition> block, this MUST cause the underlying platform to signal the telephony system to send the call to a specified destination.


201.
section 10.6.6  	
This connection.redirect event MUST be emitted to indicate a successful redirection of a connection.

1118.
section 10.6.6  	
The connection.redirected event is a transition to state DISCONNECTED.


-->

		<transition event="user.START_ASSERTION_21" state="ASSERTION_NMBR_21">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>					
      <var name="hints" expr="new Object()"/>
      <assign name="hints.test" expr="'test'"/>			
      <redirect connectionid="myConnectionID" dest="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[0]" reason="'reason'" hints="hints"/>
		</transition>
		

		<transition event="connection.redirected" state="ASSERTION_NMBR_21">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		 	<script>assertions[assert_index].P_F = s_PASS;</script>					
		 	
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'27'"/>		
			<conf:pass/>
			<assign name="ASSERTION_NUM" expr="'28'"/>		
			<conf:pass/>			
			<assign name="ASSERTION_NUM" expr="'19'"/>		
			<conf:pass/>						
			<assign name="ASSERTION_NUM" expr="'201'"/>		
			<conf:pass/>						
			
			<assign name="ASSERTION_NUM" expr="'1118'"/>		
			<if cond="event$.connection.state == Connection.DISCONNECTED">
				<conf:pass/>
			<else/>
				<conf:fail/>
			</if>
							
  		<!-- End Related Tests -->
		 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    
		<transition event="send.successful" state="ASSERTION_NMBR_21">
		</transition>
		    
		<transition event="*" state="ASSERTION_NMBR_21">		
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
  		<!-- Begin Related Tests -->
			<assign name="ASSERTION_NUM" expr="'27'"/>		
			<conf:fail/>
			<assign name="ASSERTION_NUM" expr="'28'"/>		
			<conf:fail/>			
			<assign name="ASSERTION_NUM" expr="'19'"/>		
			<conf:fail/>			
			<assign name="ASSERTION_NUM" expr="'201'"/>		
			<conf:fail/>			
			
  		<!-- End Related Tests -->
  					
		 	<script>assertions[assert_index].P_F = s_FAIL;</script>					
			<assign name="t_ASSERT_REASON" expr="'connection.redirected expected, '+ event$.name + ' received.'"/>			 	
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>				 	    		 	
    </transition>
    

    
	<!--  ***************** COMMON ******************************** -->
		<transition event="send.successful">
		</transition>


    <transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
		</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>
