<?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">

<!--
Release 1.0 - 2011-03-30
FIXED: 
- sent event to child for disconnect
-->

	<!--
      <conf:fail reason="'Unexpected Event ' + event$.name"/>
-->
	<conf:docsetup/>
	<var name="ConnectionID" expr="undefined"/>
	<var name="VxmlFile2" expr="'TWO_2.vxml'"/>
	<var name="param1" expr="1"/>
	<var name="param2" expr="'hello'"/>
	<var name="chld_reason"/>
	<var name="send_id_1"/>
	<var name="DialogID"/>
	<var name="i_success"/>
	<var name="move_child_id"/>
	<var name="move_unexisting" expr="'something random'"/>
	<var name="this_session_id"/>
	<var name="child_id"/>
	<var name="ccxm_kill_chld" expr="'ccxml.terminate.chld'"/>
	<var name="MY_BLANK" expr="''"/>
	<var name="WKR_STRING"/>
	<script><![CDATA[
	   function GetMilliseconds() {
     var d = new Date();
     return d.getTime();  // ms from midnight on Jan 1, 2000.
   }

var t_start, t_end, t_delay = 2000, t_delta, t_delta_e = 0.05 * t_delay;
		   ]]></script>
	<script><![CDATA[

var i=0;
assertions[i++] = init_assertion('536');
assertions[i++] = init_assertion('537');
assertions[i++] = init_assertion('539');
assertions[i++] = init_assertion('545');
assertions[i++] = init_assertion('541');

add_2_assert_trace('540');
add_2_assert_trace('546');
add_2_assert_trace('549');
add_2_assert_trace('583');
add_2_assert_trace('585');
add_2_assert_trace('586');
add_2_assert_trace('587');
add_2_assert_trace('577');
add_2_assert_trace('579');


var ASSERT_ID;
var ASSERT_PASS_FAIL;
var EVENT_NAME;
var EVENT_NAME_PREFIX = 'EVENT_';

var assert_last = i - 1;
var assert_index = -1;
//
// out of the loop assertions (children?)
//
//
s_ASSERTIONS_LEFT = show_remained_assertions();
var b_in_test = false;


]]></script>
	<eventprocessor statevariable="current_state">
		<conf:setup type="alerting"/>
		<transition event="connection.alerting" state="init">
			<send targettype="'ccxml'" target="session.id" name="'user.timeout'" delay="TEST_LONG_TIMEOUT"/>
			<accept connectionid="event$.connectionid"/>
		</transition>
		<transition event="connection.connected" state="init">
			<assign name="ConnectionID" expr="event$.connectionid"/>
			<createccxml next="'9_2_4_A_move_target.ccxml'" sessionid="child_id"/>
		</transition>
		<transition event="ccxml.created">
			<conf:comment expr="'Event: ' + event$.name + ' Starting the script.'"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="error.createccxml">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name + ' reason=' + event$.reason"/>
			<conf:uncond_exit expr="'Was not able to execute Create CCXML.'"/>
		</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>t_ASSERT_REASON = assertions[assert_index].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>
		<transition event="user.START_ASSERTION_536" state="ASSERTION_NMBR_536">
			<conf:comment expr="'Event: ' + event$.name"/>
			<!--			
536  	
9.2.4 &lt;move&gt;  	
A <move> attempt MUST fail if the referenced event source does not exist, or is not owned by the session performing the <move>  	mscott@voicegenie.com  	Accepted  	

-->
			<move source="move_unexisting" sessionid="child_id"/>
		</transition>
		<transition event="error.move" state="ASSERTION_NMBR_536">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
<!--
540 		(9_4_A)
9.2.4 &lt;move&gt; 	If a <move> attempt fails, an error.move event MUST be generated 	mscott@voicegenie.com 	Accepted 	
-->
			<assign name="ASSERTION_NUM" expr="'540'"/>
			<conf:pass/>
<!--
583  	
9.3.9 error.move  	
An error.move event MUST be thrown when a move request performed by a session fails to complete successfully  	mscott@voicegenie.com  	Accepted  	
-->
			<assign name="ASSERTION_NUM" expr="'583'"/>
			<conf:pass/>

<!--
586   (9_4_A)	
9.3.9 error.move 	
An error.move event MUST have a sessionid property that is the identifier of the CCXML session to which it was attempted to move the event source 	mscott@voicegenie.com 	Accepted 	
-->
			<assign name="ASSERTION_NUM" expr="'586'"/>
			<if cond="event$.sessionid==child_id">
				<conf:pass/>
			<else/>
			
				<log label="s_TA+ASSERTION_NUM" expr="'FAILED.  Expected SessionID=' +child_id + ' Got SessionID=' + event$.sessionid"/>
				<conf:fail/>
			</if>
<!--
587 	
9.3.9 error.move 	
An error.move event MUST have a reason property that describes the reason the <move> request failed 	mscott@voicegenie.com 	Accepted
-->
			<assign name="ASSERTION_NUM" expr="'587'"/>
			<if cond="event$.reason==undefined">			
				<log label="s_TA+ASSERTION_NUM" expr="'FAILED.  Reason is undefined'"/>
				<conf:fail/>
			<else/>
				<conf:pass/>
			</if>

			<assign name="ASSERTION_NUM" expr="'536'"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="move.successful" state="ASSERTION_NMBR_536">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
			<script>
			assertions[assert_index].P_F = s_FAIL;
			assertions[assert_index].reason = 'Move should have failed.';
			 </script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_537" state="ASSERTION_NMBR_537">
			<conf:comment expr="'Event: ' + event$.name"/>
			<!--			
537 	
9.2.4 &lt;move&gt; 	
A <move> attempt MUST fail if the referenced event source is immovable 		
the CCXML session itself and various external event I/O processors are examples of this

-->
			<move source="session.id" sessionid="move_child_id"/>
		</transition>
		<transition event="error.move" state="ASSERTION_NMBR_537">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<assign name="ASSERTION_NUM" expr="'585'"/>
<!--
585 	
9.3.9 error.move 	
An error.move event MUST have a sourceid property that is the ID of the event source that was the target of the <move> 	mscott@voicegenie.com 	Accepted 	
-->
			<if cond="session.id == event$.sourceid">
			<conf:pass/>
			<else/>
			<log label="s_TA+ASSERTION_NUM" expr="'FAILED '+'expected ID=' + session.id + ' Got ID=' + event$.sourceid"/>
			<conf:fail/>
			</if>
			<assign name="ASSERTION_NUM" expr="'537'"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="move.successful" state="ASSERTION_NMBR_537">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
			<script>
			assertions[assert_index].P_F = s_FAIL;
			assertions[assert_index].reason = 'Move should have failed.';
			 </script>
			<send targettype="'ccxml'" target="child_id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_539" state="ASSERTION_NMBR_539">
			<conf:comment expr="'Event: ' + event$.name"/>
			<!--			
539 	
9.2.4 &lt;move&gt; 	
A <move> attempt MUST fail if the target session does not exist or cannot accept the event source being moved 	mscott@voicegenie.com 	Accepted 	

-->
			<move source="ConnectionID" sessionid="move_unexisting"/>
		</transition>
		<transition event="error.move" state="ASSERTION_NMBR_539">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name + ' reason=' + event$.reason"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="move.successful" state="ASSERTION_NMBR_539">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
			<script>
			assertions[assert_index].P_F = s_FAIL;
			assertions[assert_index].reason = 'Move should have failed.';
			 </script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_545" state="ASSERTION_NMBR_545">
			<!--

545 	
9.2.4 &lt;move&gt; 	
The <move> element MUST contain either an event attribute, or a source attribute, but not both, or else an error.fetch event will be thrown 	mscott@voicegenie.com 	Accepted 	

-->
			<conf:comment expr="'Event: ' + event$.name"/>
			<fetch next="'try_move_source.ccxml'"/>
		</transition>
		<transition event="error.fetch" state="ASSERTION_NMBR_545">
			<conf:comment expr="'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="fetch.done" state="ASSERTION_NMBR_545">
			<conf:comment expr="'Event: ' + event$.name"/>
			<script>assertions[assert_index].P_F = s_FAIL;
			assertions[assert_index].reason = 'fetch of the document ' + event$.uri + ' should have failed.'  

				</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.START_ASSERTION_541" state="ASSERTION_NMBR_541">
			<conf:comment expr="'Event: ' + event$.name"/>
			<!--			
541 	
9.2.4 &lt;move&gt; 	
If a <move> attempt succeeds, a move.successful event MUST be generated against the session that performed the <move> 	mscott@voicegenie.com 	Accepted 	

-->
			<move source="ConnectionID" sessionid="child_id"/>
			<!-- send an event to the child so he can disconnect the call -->
            <send target="child_id" name="'user.move'" namelist="ConnectionID"/>
		</transition>
		<transition event="error.move" state="ASSERTION_NMBR_541">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name + ' reason=' + event$.reason"/>
			<assign name="ASSERTION_NUM" expr="'541'"/>
			<conf:fail/>
			<send targettype="'ccxml'" target="child_id" name="ccxm_kill_chld"/>
			<conf:uncond_exit expr="'Move of Connection Object Failed'"/>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="move.successful" state="ASSERTION_NMBR_541">
			<log label="s_TA+ASSERTION_NUM" expr="'Comment: '+'Event: ' + event$.name"/>
			<!--
546 	(together with move.success)
9.2.4 &lt;move&gt; 	
The <move> element MAY contain a source attribute that is an ECMAScript expression that returns a connection ID or a dialog ID identifying the event source to be moved to the target session 	mscott@voicegenie.com 	Accepted 	
-->
			<assign name="ASSERTION_NUM" expr="'546'"/>
			<conf:pass/>
			<!--
549 	(9_4_A)
9.2.4 &lt;move&gt; 	The <move> element MUST contain a sessionid attribute that is an ECMAScript expression which identifies the session to which the event source must be moved 	mscott@voicegenie.com 	Accepted 	
-->
			<assign name="ASSERTION_NUM" expr="'549'"/>
			<conf:pass/>
<!--
577  	
9.3.7 move.successful  	
An move.successful event MUST be thrown when an event source is successfully moved to a CCXML session  	mscott@voicegenie.com  	Accepted  	
			-->			
			<assign name="ASSERTION_NUM" expr="'577'"/>
			<conf:pass/>

<!--
579 	
9.3.7 move.successful 	
An move.successful event MUST have a sourceid that specifies the identifier of the event source that was moved 	mscott@voicegenie.com 	Accepted
-->
			
			<assign name="ASSERTION_NUM" expr="'579'"/>
			<if cond="ConnectionID==event$.sourceid">
			<conf:pass/>
			<else/>
			<log label="s_TA+ASSERTION_NUM" expr="'FAIL Got ID=' + $event.sourceid + ' expected=' + ConnectionID"/>
			<conf:fail/>

			</if>
			
			<assign name="ASSERTION_NUM" expr="'541'"/>
			<script>assertions[assert_index].P_F = s_PASS;</script>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</transition>
		<transition event="user.timeout">
			<send targettype="'ccxml'" target="child_id" name="ccxm_kill_chld"/>
			<conf:uncond_exit expr="'TEST-TIMEOUT'"/>
		</transition>
		<transition event="send.successful">
			<conf:comment expr="'Event: ' + event$.name + ' sendid=' + event$.sendid"/>
		</transition>
		<transition event="error.send.failed.">
			<conf:comment expr="'Event: ' + event$.name + ' sendid=' + event$.sendid"/>
			<if cond="event$.sendid == assert_1230_eventID">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			</if>
			<if cond="event$.sendid == assert_1232_eventID">
				<script>assertions[assert_index].P_F = s_PASS;</script>
				<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
			</if>
		</transition>
		<transition event="send.*">
			<conf:comment expr="'Event (send*): ' + event$.name"/>
		</transition>
		<transition event="*">
			<conf:comment expr="'Event: ' + event$.name"/>
			<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>
