mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/namespace/TestEventAdminNamespace.java
@Test
    public void testTwoConnectionCleanup() throws UnknownHostException, IOException, InterruptedException
    {
        /////////////////////////
        // Setup for the test. //
        ////////////////////////

        //will hold the create assets UUID
        final SharedMessages.UUID assetUuid;
        
        //create the asset
        CreateAssetResponseData assetCreation = AssetNamespaceUtils.createAsset(m_Socket, ExampleAsset.class.getName(),
                "event_Test_Asset", null);
        
        //get the UUID of the asset
        assetUuid = assetCreation.getInfo().getUuid();
        
        //used to register for events
        MessageListener listener = new MessageListener(m_Socket);
        
        //will only register to the default system credentials
        RemoteEventRegistration.regRemoteEventMessages(m_Socket, Asset.TOPIC_DATA_CAPTURED, 
            String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "event_Test_Asset"));
        
        //create additional connection
        try (Socket additionalSystemSock = SocketHostHelper.connectToController())
        {
            //will only register for the additional system
            RemoteEventRegistration.regRemoteEventMessagesAlternavtiveSystem(
                additionalSystemSock, new String[]{Asset.TOPIC_DATA_CAPTURED}, 
                    String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "event_Test_Asset"));
    
            ///////////////////////////////////
            // Actual testing of the system. //
            //////////////////////////////////
            
            //listen for messages in response to the asset capturing data
            MessageDualListener dualListener = new MessageDualListener(m_Socket, additionalSystemSock);
            
            //ask the asset to capture data
            AssetNamespaceUtils.requestDataCapture(m_Socket, assetUuid);
            
            dualListener.waitForMessagesTwoSockets(9000);
            
            //verify messages were received on both channels
            dualListener.assertMessagesReceivedByTypeSocketOne(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
            dualListener.assertMessagesReceivedByTypeSocketTwo(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
    
            //Clean up request on original channel
            TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.CleanupRequest, null);
            
            //send out the request
            message.writeDelimitedTo(m_Socket.getOutputStream());
            
            //listen for response message 
            listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.CleanupResponse, 1000);
            
            //ask the asset to capture data again
            AssetNamespaceUtils.requestDataCapture(m_Socket, assetUuid);
    
            //listen for messages in response to the asset capturing data
            dualListener.waitForMessages(2000);
            
            //verify a message was only received across the channel for the additional system
            dualListener.assertMessagesReceivedByTypeSocketTwo(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
            //assertion should fail
            try
            {
                dualListener.assertMessagesReceivedByTypeSocketOne(Namespace.EventAdmin, 
                        EventAdminMessageType.SendEvent);
                fail("Expected to not get a send event because cleanup was previously requested.");
            }
            catch (AssertionError e)
            {
                //expected exception because there should NOT be messages of this type received
            }
        }
        finally
        {
            //clean up
            AssetNamespaceUtils.removeAsset(m_Socket, assetUuid);
        }
    }
/**
     * Test sending and receiving a response from two represented systems.
     * This test is lengthy: First the test will connect to the controller with the default connection
     * properties used for most of the integration tests. Then an asset is created, the test will register to get
     * notifications when that asset captures data. Then an additional connection is setup NOT using the default 
     * system information. Then the asset will be requested to capture data, both connections will be listening
     * to the data captured event. Once verified that both connections received the event, the first connection will 
     * request cleanup, which should remove event registrations for that connection. After confirmation of the cleanup
     * the asset will again capture data and it will be verified that the connection that requested clean up DOES not
     * receive notifications. Meanwhile the other connection will be confirmed to have still gotten the notification.
     *
     */
Test sending and receiving a response from two represented systems.
This test is lengthy: First the test will connect to the controller with the default connection
properties used for most of the integration tests. Then an asset is created, the test will register to get
notifications when that asset captures data. Then an additional connection is setup NOT using the default
system information. Then the asset will be requested to capture data, both connections will be listening
to the data captured event. Once verified that both connections received the event, the first connection will
request cleanup, which should remove event registrations for that connection. After confirmation of the cleanup
the asset will again capture data and it will be verified that the connection that requested clean up DOES not
receive notifications. Meanwhile the other connection will be confirmed to have still gotten the notification.
Test sending and receiving a response from two represented systems . This test is lengthy : First the test will connect to the controller with the default connection properties used for most of the integration tests . Then an asset is created the test will register to get notifications when that asset captures data . Then an additional connection is setup NOT using the default system information . Then the asset will be requested to capture data both connections will be listening to the data captured event . Once verified that both connections received the event the first connection will request cleanup which should remove event registrations for that connection . After confirmation of the cleanup the asset will again capture data and it will be verified that the connection that requested clean up DOES not receive notifications . Meanwhile the other connection will be confirmed to have still gotten the notification .
@Test
    public void testTwoConnectionCleanup() throws UnknownHostException, IOException, InterruptedException
    {
        final SharedMessages.UUID assetUuid;
        CreateAssetResponseData assetCreation = AssetNamespaceUtils.createAsset(m_Socket, ExampleAsset.class.getName(),
                "event_Test_Asset", null);
        assetUuid = assetCreation.getInfo().getUuid();
        MessageListener listener = new MessageListener(m_Socket);
        RemoteEventRegistration.regRemoteEventMessages(m_Socket, Asset.TOPIC_DATA_CAPTURED, 
            String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "event_Test_Asset"));
        try (Socket additionalSystemSock = SocketHostHelper.connectToController())
        {
            RemoteEventRegistration.regRemoteEventMessagesAlternavtiveSystem(
                additionalSystemSock, new String[]{Asset.TOPIC_DATA_CAPTURED}, 
                    String.format("(%s=%s)", FactoryDescriptor.EVENT_PROP_OBJ_NAME, "event_Test_Asset"));
            //////////
            /////////
            MessageDualListener dualListener = new MessageDualListener(m_Socket, additionalSystemSock);
            AssetNamespaceUtils.requestDataCapture(m_Socket, assetUuid);
            dualListener.waitForMessagesTwoSockets(9000);
            dualListener.assertMessagesReceivedByTypeSocketOne(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
            dualListener.assertMessagesReceivedByTypeSocketTwo(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
            TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.CleanupRequest, null);
            message.writeDelimitedTo(m_Socket.getOutputStream());
            listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.CleanupResponse, 1000);
             again
            AssetNamespaceUtils.requestDataCapture(m_Socket, assetUuid);
            dualListener.waitForMessages(2000);
            dualListener.assertMessagesReceivedByTypeSocketTwo(Namespace.EventAdmin, EventAdminMessageType.SendEvent);
            try
            {
                dualListener.assertMessagesReceivedByTypeSocketOne(Namespace.EventAdmin, 
                        EventAdminMessageType.SendEvent);
                fail("Expected to not get a send event because cleanup was previously requested.");
            }
            catch (AssertionError e)
            {
            }
        }
        finally
        {
            AssetNamespaceUtils.removeAsset(m_Socket, assetUuid);
        }
    }
@ Test public void testTwoConnectionCleanup ( ) throws UnknownHostException , IOException , InterruptedException { final SharedMessages . UUID assetUuid ; CreateAssetResponseData assetCreation = AssetNamespaceUtils . createAsset ( m_Socket , ExampleAsset . class . getName ( ) , "event_Test_Asset" , null ) ; assetUuid = assetCreation . getInfo ( ) . getUuid ( ) ; MessageListener listener = new MessageListener ( m_Socket ) ; RemoteEventRegistration . regRemoteEventMessages ( m_Socket , Asset . TOPIC_DATA_CAPTURED , String . format ( "(%s=%s)" , FactoryDescriptor . EVENT_PROP_OBJ_NAME , "event_Test_Asset" ) ) ; try ( Socket additionalSystemSock = SocketHostHelper . connectToController ( ) ) { RemoteEventRegistration . regRemoteEventMessagesAlternavtiveSystem ( additionalSystemSock , new String [ ] { Asset . TOPIC_DATA_CAPTURED } , String . format ( "(%s=%s)" , FactoryDescriptor . EVENT_PROP_OBJ_NAME , "event_Test_Asset" ) ) ; MessageDualListener dualListener = new MessageDualListener ( m_Socket , additionalSystemSock ) ; AssetNamespaceUtils . requestDataCapture ( m_Socket , assetUuid ) ; dualListener . waitForMessagesTwoSockets ( 9000 ) ; dualListener . assertMessagesReceivedByTypeSocketOne ( Namespace . EventAdmin , EventAdminMessageType . SendEvent ) ; dualListener . assertMessagesReceivedByTypeSocketTwo ( Namespace . EventAdmin , EventAdminMessageType . SendEvent ) ; TerraHarvestMessage message = createEventAdminMessage ( EventAdminMessageType . CleanupRequest , null ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . EventAdmin , EventAdminMessageType . CleanupResponse , 1000 ) ; AssetNamespaceUtils . requestDataCapture ( m_Socket , assetUuid ) ; dualListener . waitForMessages ( 2000 ) ; dualListener . assertMessagesReceivedByTypeSocketTwo ( Namespace . EventAdmin , EventAdminMessageType . SendEvent ) ; try { dualListener . assertMessagesReceivedByTypeSocketOne ( Namespace . EventAdmin , EventAdminMessageType . SendEvent ) ; fail ( "Expected to not get a send event because cleanup was previously requested." ) ; } catch ( AssertionError e ) { } } finally { AssetNamespaceUtils . removeAsset ( m_Socket , assetUuid ) ; } }
Test sending and receiving a response from two represented systems.
Test sending and receiving a response from two represented systems .
///////////////////////// // Setup for the test. // //////////////////////// //will hold the create assets UUID //create the asset //get the UUID of the asset //used to register for events //will only register to the default system credentials //create additional connection //will only register for the additional system /////////////////////////////////// // Actual testing of the system. // ////////////////////////////////// //listen for messages in response to the asset capturing data //ask the asset to capture data //verify messages were received on both channels //Clean up request on original channel //send out the request //listen for response message  //ask the asset to capture data again //listen for messages in response to the asset capturing data //verify a message was only received across the channel for the additional system //assertion should fail //expected exception because there should NOT be messages of this type received //clean up