<?xml version="1.0" encoding="UTF-8"?>
<!--
    Test: 10.2.3 1292 1295 (optional assertions not tested 309 1293 1294)
    require 'ALERTING'
	-->
<!--
Release 1.2 - 2010-10-21
FIXED: ISSUE-723: - Do-nothing transition connection.merged added 
-->

<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="OutboundID1"/>
  <var name="OutboundID2"/>
  <var name="OutboundID3"/>
  <var name="OutboundID4"/>
  <var name="DialogID"/>
<var name="result_1292" expr="new Object();"/>
<var name="result_1295" expr="new Object();"/>

<var name="connectionMergedCount" expr="0"/>

  <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].connectionid == event.connection.connectionid, result2 );
							
			return true;
		}
]]> </script>
	
  <eventprocessor statevariable="current_state">
	  <conf:setup type="alerting"/>

	  	<transition event="connection.alerting" state="init">
			<assign name="result_1292.P_F" expr="'PASS'"/>
			<assign name="result_1295.P_F" expr="'PASS'"/>
		 	<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_CONNECTED ==============-->

	<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"/>	
		<accept connectionid="ConnectionID"/>
	</transition>

	<transition state="ASSERTION_NMBR_1292" event="connection.connected">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
		<disconnect 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>
			<assign name="current_state" expr="'ASSERTION_NMBR_1292_OUTBOUND_FAILED'"/>
			<createcall dest="TEST_CREATECALL_DEST_NOANSWER" connectionid="OutboundID3"/>
	</transition>

	<!--=================== Test Stage: TEST_OUTBOUND_FAILED ====================-->
	
	<transition state="ASSERTION_NMBR_1292_OUTBOUND_FAILED" event="connection.progressing">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
	</transition>
	
	<transition state="ASSERTION_NMBR_1292_OUTBOUND_FAILED" event="connection.failed">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
		
	<assign name="current_state" expr="'ASSERTION_NMBR_1292_MERGED'"/>
		<createcall dest="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[0]" connectionid="OutboundID1"/>
		<createcall dest="TEST_CREATECALL_DEST_ANSWER_AND_STAY_ACTIVE[1]" connectionid="OutboundID2"/>

	</transition>

	<!--===================== Test Stage: TEST_MERGED ===========================-->
	
	<transition state="ASSERTION_NMBR_1292_MERGED" event="connection.progressing">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
		<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
	</transition>

	<transition state="ASSERTION_NMBR_1292_MERGED" event="connection.connected">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>		
		<if cond="checkConnection(event$, session, result_1292, result_1295)">
		</if>
		<if cond="session.connections[OutboundID1].state == Connection.CONNECTED">
			<if cond="session.connections[OutboundID2].state == Connection.CONNECTED">
				<merge connectionid1="OutboundID1" connectionid2="OutboundID2"/>
			</if>
		</if>
	</transition>
	
	<transition state="ASSERTION_NMBR_1292_MERGED" event="connection.merged">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>
		
		<if cond="connectionMergedCount == 0">
			<assign name="connectionMergedCount" expr="connectionMergedCount + 1"/>
		<else/> 
			<if cond="checkConnection(event$, session, result_1292, result_1295)">
			</if>
			<if cond="result_1292.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 = 'Connection ID of a connection object is incorrect.';
				</script>
			</if>
			<send targettype="'ccxml'" target="session.id" name="name_prepare_new"/>
		</if>	
	</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'">
			<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>	

	<!--    CatchAll for all statges -->
	
	<transition event="send.successful">
	</transition>

	<!-- FIXED ISSUE-723:  added a do-nothing transition for connection.merged  -->
	<transition event="connection.merged">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
	</transition>
	
	<transition event="connection.disconnected">
		<conf:comment expr=" 'Current state : ' + current_state + ' , Event: ' + event$.name"/>	
	</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>
