<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" backgroundColor="#ffffff"
    creationComplete="onCreationComplete()" viewSourceURL="srcview/index.html">

    <mx:Script>        
    <![CDATA[
        import mx.collections.ArrayCollection;  
        import mx.rpc.remoting.RemoteObject;
        import mx.controls.Alert;  
        import mx.rpc.events.ResultEvent
        import mx.rpc.events.FaultEvent
        import tests.*; 

        private var primitiveTest:PrimitiveTest;
        private var stringsTest:StringTest;
        private var primitiveArrayTest:ArrayOfPrimitivesTest;
        private var complexTypesTest:ComplexTypeTest;
        private var multipleArgsTest:MultipleArgsTest;
        private var dataAccessTest:DatabaseTest;
        private var secureInvokeTest:SecureInvocationTest;
        
        [Bindable]
        private var log:ArrayCollection = new ArrayCollection();
        
        //[Bindable]
        //private var summaryList:Array = new Array(); 
        
        public function onCreationComplete():void 
           {
               primitiveTest = new PrimitiveTest( this);
               stringsTest = new StringTest(this);
               primitiveArrayTest = new ArrayOfPrimitivesTest(this);
               complexTypesTest = new ComplexTypeTest(this);
               multipleArgsTest = new MultipleArgsTest(this);
               dataAccessTest = new DatabaseTest(this);
               secureInvokeTest = new SecureInvocationTest( this );
           } 
           
        public function onEchoInt(event:ResultEvent):void 
        {
            Alert.show( event.result.toString() , "Echo Int Result"); 
        }

        public function onFault (event:FaultEvent):void 
        {
            Alert.show(event.fault.faultString, 'Error');
        }
        
        public function runPrimitiveTests():void
        {
            log.removeAll();
            primitiveTest.runPrimitiveTests(log);
        }
        
        public function runStringsTests():void
        {
            summary.dataProvider = new Array();
            stringsTest.runStringTests();
        }
        
        public function runPrimitiveArraysTests():void
        {
            summary.dataProvider = new Array();
            primitiveArrayTest.runPrimitiveArraysTests();
        }
        
        public function runComplexTypesTests():void
        {
            summary.dataProvider = new Array();
            complexTypesTest.runComplexTypeTests();
        }
        
        public function runMultipleArgsTests():void
        {
            summary.dataProvider = new Array();
            multipleArgsTest.runMultipleArgsTests();
        }
        
        public function runDataAccessTest():void
        {
            summary.dataProvider = new Array();
            dataAccessTest.runTests();
        }
        
        public function runSecureInvocation():void
        {
            summary.dataProvider = new Array();
            secureInvokeTest.runSecureTests();            
        }
        
        public function setSummary(array:Array):void
        {
            log = new ArrayCollection(array);
        }
        
        public function setDataOutput(array:Array):void
        {
            dataOutput.dataProvider = array;
        }
        
           
    ]]>  
    </mx:Script>
    <mx:Panel x="10" y="11" width="711" height="464" layout="absolute" title="WebORB Flex RPC Test Suite" backgroundColor="#8bb6a0">
        <mx:Button x="10" y="23" label="Run Primitive Tests" click="runPrimitiveTests()"  width="183" id="primitiveTestButton" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="53" label="Run Strings Tests" click="runStringsTests()"  width="183" id="primitiveTestButton0" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="83" label="Run Primitive Array Tests" click="runPrimitiveArraysTests()"  width="183" id="primitiveTestButton1" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="113" label="Run Complex Type Tests" click="runComplexTypesTests()"  width="183" id="primitiveTestButton2" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="143" label="Run Multiple Args Tests" click="runMultipleArgsTests()"  width="183" id="primitiveTestButton3" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="173" label="Run Data Access Test" click="runDataAccessTest()"  width="183" id="primitiveTestButton4" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:Button x="10" y="203" label="Run Secure Invocation" click="runSecureInvocation()"  width="183" id="primitiveTestButton5" fillColors="[#ffffff, #ffffff]" fillAlphas="[0.82, 1.0]"/>
        <mx:DataGrid x="10" y="279" width="671" id="dataOutput" height="135">
            <mx:columns>
                <mx:DataGridColumn headerText="CustomerID" dataField="CustomerID"/>
                <mx:DataGridColumn headerText="Company Name" dataField="CompanyName"/>
                <mx:DataGridColumn headerText="Name" dataField="ContactName"/>
                <mx:DataGridColumn headerText="Title" dataField="ContactTitle"/>
                <mx:DataGridColumn headerText="Address" dataField="Address"/>
                <mx:DataGridColumn headerText="City" dataField="City"/>
                <mx:DataGridColumn headerText="Region" dataField="Region"/>
                <mx:DataGridColumn headerText="Postal Code" dataField="PostalCode"/>
                <mx:DataGridColumn headerText="Country" dataField="Country"/>
                <mx:DataGridColumn headerText="Phone" dataField="Phone"/>
                <mx:DataGridColumn headerText="Fax" dataField="Fax"/>
            </mx:columns>
        </mx:DataGrid>
        <mx:DataGrid x="201" y="10" width="480" height="261" dataProvider="{log}" id="summary" horizontalScrollPolicy="on">
            <mx:columns>
                <mx:DataGridColumn headerText="Results" wordWrap="true"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:Panel>   
</mx:Application>