<?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).
-->
<!--
Release 1.1 - 2010-06-15
FIXED: 
ISSUE-711, TA 420. 
-->
<!--
Release 1.2 - 2010-10-21
FIXED: ISSUE-740: -  TA 425: managed the prepare_new event in both cases: dialog.exit and conference.unjoined events. 
-->
<!--
Release 1.3 - 2011-03-25
FIXED: TA 427: dtmfclamp set to false added in join on ConnectionID and ConferenceID to allow DTMF termination 
-->

	<conf:docsetup/>

	<var name="DialogID" expr="undefined"/>
	<var name="ConnectionID" expr="undefined"/>
	<var name="OutConnectionID" expr="undefined"/>
	<var name="mySendId"/>
		
	<var name="vxmlFile" expr="'7_3_1.vxml'"/>

	<var name="chld_reason"/>
	
	<var name="SIP_string" expr="'sip:'"/>
	<var name="TEL_string" expr="'tel:'"/>
	
	<var name="OutAai" expr="undefined"/>
	<var name="OutConnectTimeout" expr="'10s'"/>
	<var name="OutURI" expr="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[0]"/>

	<var name="ConferenceID" expr="undefined"/>
	<var name="myConfName" expr="'SimpleConference'"/>


	<!-- FIXED ISSUE-740:  TA 425: managed the prepare_new event in both cases: dialog.exit and conference.unjoined events.-->
	<!-- use of a boolean value -->
	<var name="bDialogExitAlreadyOccurred" expr="false"/>
	<var name="bAlreadyUnjoined" expr="false"/>
				
	<script><![CDATA[
		var i=0;
		// connection
		assertions[i++] = init_assertion('408');
		assertions[i++] = init_assertion('838');
		assertions[i++] = init_assertion('425');
		//conference		
		assertions[i++] = init_assertion('412');
		assertions[i++] = init_assertion('427');
		
		
		var assert_last = i - 1;
		var assert_index = -1;
		//
		// out of the loop assertions (children)
		
		// Child of 408 dialog.transfer event 
		add_2_assert_trace('410');
		add_2_assert_trace('411');
		add_2_assert_trace('414');
		add_2_assert_trace('415');
		add_2_assert_trace('416');
		add_2_assert_trace('419');
		add_2_assert_trace('420');
		add_2_assert_trace('421');
		add_2_assert_trace('422');	
		add_2_assert_trace('1195');
	
		// Child of 425 dialog.terminatetransfer event 
		add_2_assert_trace('426');
		add_2_assert_trace('429');
		add_2_assert_trace('430');
		add_2_assert_trace('1197');
		
		// Child of 412, dialog.transfer event with conference
		add_2_assert_trace('413');		
		
		// Child of 427 dialog.terminatetransfer event with conference
		add_2_assert_trace('428');
		
		
		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">
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="'60s'"/>
			<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>

		<!-- TA 408: check of dialog.tranfer event  -->
		<transition event="user.START_ASSERTION_408" state="ASSERTION_NMBR_408">
			<dialogstart src="vxmlFile" dialogid="DialogID" connectionid="ConnectionID"/>
		</transition>
		
		<transition event="dialog.started" state="ASSERTION_NMBR_408">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		</transition>	
		
		<transition event="dialog.transfer" state="ASSERTION_NMBR_408">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="OutAai" expr="event$.aai"/>
			<assign name="OutConnectTimeout" expr="event$.connecttimeout"/>
				
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<!-- Children management -->
			<!-- check of dialogid-->
			<assign name="ASSERTION_NUM" expr="'410'"/>
			<if cond="event$.dialogid == DialogID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect dialogid on dialog.transfer event ' "/>	
			</if>
			<!-- check of connectionid-->
			<assign name="ASSERTION_NUM" expr="'411'"/>
			<if cond="event$.connectionid != undefined &amp;&amp; event$.connectionid == ConnectionID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect connectionid on dialog.transfer event ' "/>	
			</if>
			<!-- check of conferenceid: it MUST be undefined -->
			<assign name="ASSERTION_NUM" expr="'414'"/>
			<if cond="event$.conferenceid == undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect value for conferenceid on dialog.tranfer event: it MUSt be undefined ! ' "/>	
			</if>
			<!-- check of type  -->
			<assign name="ASSERTION_NUM" expr="'415'"/>
			<if cond="event$.type == 'bridge' || event$.type == 'blind' || event$.type == 'consultation'">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect value type on dialog.transfer event. ' "/>	
			</if>
			
			<!-- check of uri  -->
			<assign name="ASSERTION_NUM" expr="'416'"/>
			<if cond="event$.uri.search(SIP_string) >=-1 || event$.uri.search(TEL_string) >=-1 ">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect uri on dialog.transfer event. ' "/>	
			</if>
			
			<!-- check of mandatory maxtime -->
			<assign name="ASSERTION_NUM" expr="'419'"/>
			<if cond="event$.maxtime != undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined maxtime on dialog.transfer event! ' "/>	
			</if>
			<!-- check of maxtime = 0s-->
			<assign name="ASSERTION_NUM" expr="'420'"/>
			<!-- FIXED ISSUE-711:  check on also '0ms' added  -->
			<if cond="event$.maxtime == '0s' || event$.maxtime == '0ms'">
				<conf:pass/>
			<else/>
				<conf:fail reason="' maxtime MUST be equal to 0s while is equal to ' + event$.maxtime+   'on dialog.tranfer event! ' "/>	
			</if>	
			<!-- check of mandatory connecttimeout -->
			<assign name="ASSERTION_NUM" expr="'421'"/>
			<if cond="event$.connecttimeout != undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined connecttimeout on dialog.transfer event! ' "/>	
			</if>
			
			<!-- check of aai  -->
			<assign name="ASSERTION_NUM" expr="'422'"/>
			<if cond="event$.aai != undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined aai on dialog.transfer event! ' "/>	
			</if>
			
			<!-- check of mandatory dialog object  -->
			<assign name="ASSERTION_NUM" expr="'1195'"/>
			<if cond="event$.dialog != undefined &amp;&amp; event$.dialog.objecttype == 'dialog'">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined dialog object on dialog.transfer event! ' "/>	
			</if>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>	
			
		<!-- TA 838: aai towards the network -->
		<transition event="user.START_ASSERTION_838" state="ASSERTION_NMBR_838">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<createcall dest="OutURI" connectionid="OutConnectionID" aai="OutAai" timeout="OutConnectTimeout"/>
		</transition>
		
		<transition event="connection.progressing" state="ASSERTION_NMBR_838">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
        </transition>
         
        <transition event="connection.connected" state="ASSERTION_NMBR_838">
       		<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>

		<!-- TA 425: check of dialog.terminatetranfer event so we must before place the outbound call -->
   		<transition event="user.START_ASSERTION_425" state="ASSERTION_NMBR_425">
      		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<!-- Unjoin the calls before it can be connected to other call -->
            <join id1="DialogID" id2="ConnectionID" duplex="'half'" /> 
         </transition>
        
         <transition event="conference.joined" state="ASSERTION_NMBR_425">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<assign name="current_state" expr="'ASSERTION_NMBR_425_JOIN_CONNECTIONS'"/>
            <!-- Join the two calls together -->      
            <join id1="ConnectionID" id2="OutConnectionID" duplex="'full'" />
        </transition>

         <transition event="conference.joined" state="ASSERTION_NMBR_425_JOIN_CONNECTIONS">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="current_state" expr="'ASSERTION_NMBR_425'"/>
        </transition>

		 <transition event="dialog.terminatetransfer" state="ASSERTION_NMBR_425">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<if cond="event$.dialogid == DialogID">
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>	
				<assign name="t_ASSERT_REASON" expr="'Invalid dialogid on dialog.terminatetransfer, STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>	
       		</if>
       		<!-- check of connectionid-->
			<assign name="ASSERTION_NUM" expr="'426'"/>
			<if cond="event$.connectionid != undefined &amp;&amp; event$.connectionid == ConnectionID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect connectionid on dialog.terminatetransfer event ' "/>	
			</if>
			<!-- check of conferenceid: it MUST be undefined -->
			<assign name="ASSERTION_NUM" expr="'429'"/>
			<if cond="event$.conferenceid == undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect value for conferenceid on dialog.terminatetranfer event: it MUSt be undefined ! ' "/>	
			</if>
			<!-- check of mandatory reason -->
			<assign name="ASSERTION_NUM" expr="'430'"/>
			<if cond="event$.reason != undefined">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined reason on dialog.terminatetransfer event! ' "/>	
			</if>
			<!-- check of mandatory dialog object  -->
			<assign name="ASSERTION_NUM" expr="'1197'"/>
			<if cond="event$.dialog != undefined &amp;&amp; event$.dialog.objecttype == 'dialog'">
				<conf:pass/>
			<else/>
				<conf:fail reason="'undefined dialog object on dialog.terminatetransfer event! ' "/>	
			</if>
			<!-- Disconnecting the callee ... -->
			<disconnect connectionid="OutConnectionID"/>
		</transition>
   		<transition event="connection.disconnected" state="ASSERTION_NMBR_425">
   			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
   			<dialogterminate dialogid="DialogID"/>
        </transition>


		<!-- FIXED ISSUE-740:  TA 425: managed the prepare_new event in both cases: dialog.exit and conference.unjoined events.-->
		<transition event="conference.unjoined" state="ASSERTION_NMBR_425" cond="bDialogExitAlreadyOccurred">
   			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>   			
   		</transition>
   		<transition event="conference.unjoined" state="ASSERTION_NMBR_425" cond="!bDialogExitAlreadyOccurred">
   			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
   			<assign name="bAlreadyUnjoined" expr="true"/>
       	</transition>
        
        <transition event="dialog.exit" state="ASSERTION_NMBR_425" cond="!bAlreadyUnjoined">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<assign name="bDialogExitAlreadyOccurred" expr="true"/>
		</transition>
		
        <transition event="dialog.exit" state="ASSERTION_NMBR_425" cond="bAlreadyUnjoined">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>   	
		</transition>
		<!-- END FIXED ISSUE-723-->	
		
		<!-- TA 412: dialog.transfer with conference -->		
		<transition event="user.START_ASSERTION_412" state="ASSERTION_NMBR_412">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<createconference conferenceid="ConferenceID" confname="myConfName"/>
		</transition>
		<!-- Starting dialog in a conference-->
		<transition event="conference.created" state="ASSERTION_NMBR_412">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<dialogstart src="vxmlFile" dialogid="DialogID" conferenceid="ConferenceID"/>
		</transition>
		<transition event="dialog.started" state="ASSERTION_NMBR_412">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		</transition>
		<transition event="dialog.transfer" state="ASSERTION_NMBR_412">
			<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="OutAai" expr="event$.aai"/>
			<assign name="OutConnectTimeout" expr="event$.connecttimeout"/>
			<if cond="event$.conferenceid != undefined &amp;&amp; event$.connectionid == undefined">
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>	
				<assign name="t_ASSERT_REASON" expr="'connectionid must be undefined, STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>	
       		</if>
			<!-- Child management -->
			<!-- check of conferenceid equal to conferenceid on dialogstart-->
			<assign name="ASSERTION_NUM" expr="'413'"/>
			<if cond="event$.conferenceid == ConferenceID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect conferenceid on dialog.transfer event ' "/>	
			</if>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>					
		
		<!-- TA 427: dialog.terminatetransfer with conference -->		
		<transition event="user.START_ASSERTION_427" state="ASSERTION_NMBR_427">
			<createcall dest="OutURI" connectionid="OutConnectionID" aai="OutAai" timeout="OutConnectTimeout"/>
		</transition>
		
		<transition event="connection.progressing" state="ASSERTION_NMBR_427">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
        </transition>
         
        <transition event="connection.connected" state="ASSERTION_NMBR_427">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
     		 <!-- Unjoin the calls before it can be connected to other call -->
            <join id1="DialogID" id2="ConferenceID" duplex="'half'" /> 
        </transition>
         <transition event="conference.joined" state="ASSERTION_NMBR_427">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<assign name="current_state" expr="'ASSERTION_NMBR_427_JOIN_CONNECTIONS'"/>
            <!-- Join the new connectionid to the conference id  --> 
<!--
FIXED: TA 427: dtmfclamp set to false added in join on ConnectionID and ConferenceID to allow DTMF termination 
-->		
            <join id1="ConnectionID" id2="ConferenceID" duplex="'full'" dtmfclamp="false"/> <!-- Chris Davis modified -->
        </transition>
         <transition event="conference.joined" state="ASSERTION_NMBR_427_JOIN_CONNECTIONS">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
			<assign name="current_state" expr="'ASSERTION_NMBR_427'"/>
        </transition>
		 <transition event="dialog.terminatetransfer" state="ASSERTION_NMBR_427">
       		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
       		<if cond="event$.conferenceid != undefined &amp;&amp; event$.connectionid == undefined">
				<script>assertions[assert_index].P_F = s_PASS;</script>
			<else/>	
				<assign name="t_ASSERT_REASON" expr="'connectionid must be undefined on dialog.terminatetransfer, STATE ' + current_state"/>
				<script>
                    [assert_index].P_F = s_FAIL;
                    [assert_index].reason = t_ASSERT_REASON;  
				</script>	
       		</if>
       		<!-- Child management -->
       		<!-- check of conferenceid -->
			<assign name="ASSERTION_NUM" expr="'428'"/>
			<if cond="event$.conferenceid != undefined &amp;&amp; event$.conferenceid == ConferenceID">
				<conf:pass/>
			<else/>
				<conf:fail reason="'Incorrect conferenceid on dialog.terminatetransfer event ' "/>	
			</if>
			
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>

		<!-- Safety timeout -->					
		 <transition event="user.timeout">
			<assign name="current_state" expr="'GEN'"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT.' + show_remained_assertions()"/>
        </transition>			
			
		<transition event="send.successful">
		</transition>

		<transition event="connection.signal">
		</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>
