mil.dod.th.ose.remote.integration/src/mil/dod/th/ose/remote/integration/namespace/TestEventAdminNamespace.java
@Test
    public void testRegisterUnregisterEvent() throws UnknownHostException, IOException, InterruptedException
    {
        //open connection to controller
        MessageListener listener = new MessageListener(m_Socket);

        //construct new message for registering an event
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic(RemoteConstants.TOPIC_MESSAGE_RECEIVED);
        
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);

        //create terra harvest message   
        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, 
                requestMessage.build());

        // send out message
        message.writeDelimitedTo(m_Socket.getOutputStream());

        //listen for messages for a specific time interval
        List<MessageDetails> details = listener.waitForMessages(1000,
                new BasicMessageMatcher(Namespace.EventAdmin, 
                        EventAdminMessageType.EventRegistrationResponse), 
                        new EventMessageMatcher(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        
        EventAdminNamespace response = null;
        for (MessageDetails detail : details)
        {
            if (detail.getNamespaceMessage() instanceof EventAdminNamespace)
            {
                response = (EventAdminNamespace)detail.getNamespaceMessage();
                break;
            }
        }
        
        assertThat(response, notNullValue());
       
        //ensure EventRegistrationResponse type was received, store message data for later use
        EventRegistrationResponseData regResponse = EventRegistrationResponseData.parseFrom(response.getData());
        
        /*Create request to unregister from receiving event notifications for specific remote events.
        Registered events are assigned a unique ID.  When the user no longer wants to receive notifications
        corresponding to a certain registered event, that event's unique ID is used to remove the event 
        from the list of registered events.*/
        UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData.newBuilder()
                .setId(regResponse.getId()).build();
        message = createEventAdminMessage(EventAdminMessageType.UnregisterEventRequest, 
                unregisterRequestMessage);
        // send out message
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        //listen for potential messages as a result of new request
        //assert unregister event response was received
        listener.waitForMessage (Namespace.EventAdmin, EventAdminMessageType.UnregisterEventResponse, 500);        

        // Register another event
        requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic2");
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, requestMessage.build());
        // send out message
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        //listen for new messages of a specific time for a specific time interval
        //assert event registration response was received
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.EventRegistrationResponse, 500);  
        
        //verify that log events are no longer being posted with registration of a new event
        try
        {
            TerraHarvestMessage.parseDelimitedFrom(m_Socket.getInputStream());
            fail("Log event notifications still being captured.");
        }
        catch(Exception e)
        {
            assertThat(e.getMessage(), is("Read timed out"));
        }
    }
/**
     * Test sending and receiving a response for registering and unregistering logging events.
     */
Test sending and receiving a response for registering and unregistering logging events.
Test sending and receiving a response for registering and unregistering logging events .
@Test
    public void testRegisterUnregisterEvent() throws UnknownHostException, IOException, InterruptedException
    {
        MessageListener listener = new MessageListener(m_Socket);
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic(RemoteConstants.TOPIC_MESSAGE_RECEIVED);
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, 
                requestMessage.build());
        message.writeDelimitedTo(m_Socket.getOutputStream());
        List<MessageDetails> details = listener.waitForMessages(1000,
                new BasicMessageMatcher(Namespace.EventAdmin, 
                        EventAdminMessageType.EventRegistrationResponse), 
                        new EventMessageMatcher(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        EventAdminNamespace response = null;
        for (MessageDetails detail : details)
        {
            if (detail.getNamespaceMessage() instanceof EventAdminNamespace)
            {
                response = (EventAdminNamespace)detail.getNamespaceMessage();
                break;
            }
        }
        assertThat(response, notNullValue());
        EventRegistrationResponseData regResponse = EventRegistrationResponseData.parseFrom(response.getData());
        /*Create request to unregister from receiving event notifications for specific remote events.
        Registered events are assigned a unique ID.  When the user no longer wants to receive notifications
        corresponding to a certain registered event, that event's unique ID is used to remove the event 
        from the list of registered events.*/
        UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData.newBuilder()
                .setId(regResponse.getId()).build();
        message = createEventAdminMessage(EventAdminMessageType.UnregisterEventRequest, 
                unregisterRequestMessage);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage (Namespace.EventAdmin, EventAdminMessageType.UnregisterEventResponse, 500);        
        requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic("test-topic2");
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, requestMessage.build());
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.EventRegistrationResponse, 500);  
        try
        {
            TerraHarvestMessage.parseDelimitedFrom(m_Socket.getInputStream());
            fail("Log event notifications still being captured.");
        }
        catch(Exception e)
        {
            assertThat(e.getMessage(), is("Read timed out"));
        }
    }
@ Test public void testRegisterUnregisterEvent ( ) throws UnknownHostException , IOException , InterruptedException { MessageListener listener = new MessageListener ( m_Socket ) ; EventRegistrationRequestData . Builder requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; TerraHarvestMessage message = createEventAdminMessage ( EventAdminMessageType . EventRegistrationRequest , requestMessage . build ( ) ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; List < MessageDetails > details = listener . waitForMessages ( 1000 , new BasicMessageMatcher ( Namespace . EventAdmin , EventAdminMessageType . EventRegistrationResponse ) , new EventMessageMatcher ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; EventAdminNamespace response = null ; for ( MessageDetails detail : details ) { if ( detail . getNamespaceMessage ( ) instanceof EventAdminNamespace ) { response = ( EventAdminNamespace ) detail . getNamespaceMessage ( ) ; break ; } } assertThat ( response , notNullValue ( ) ) ; EventRegistrationResponseData regResponse = EventRegistrationResponseData . parseFrom ( response . getData ( ) ) ; /*Create request to unregister from receiving event notifications for specific remote events.
        Registered events are assigned a unique ID.  When the user no longer wants to receive notifications
        corresponding to a certain registered event, that event's unique ID is used to remove the event 
        from the list of registered events.*/ UnregisterEventRequestData unregisterRequestMessage = UnregisterEventRequestData . newBuilder ( ) . setId ( regResponse . getId ( ) ) . build ( ) ; message = createEventAdminMessage ( EventAdminMessageType . UnregisterEventRequest , unregisterRequestMessage ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . EventAdmin , EventAdminMessageType . UnregisterEventResponse , 500 ) ; requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( "test-topic2" ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; message = createEventAdminMessage ( EventAdminMessageType . EventRegistrationRequest , requestMessage . build ( ) ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . EventAdmin , EventAdminMessageType . EventRegistrationResponse , 500 ) ; try { TerraHarvestMessage . parseDelimitedFrom ( m_Socket . getInputStream ( ) ) ; fail ( "Log event notifications still being captured." ) ; } catch ( Exception e ) { assertThat ( e . getMessage ( ) , is ( "Read timed out" ) ) ; } }
Test sending and receiving a response for registering and unregistering logging events.
Test sending and receiving a response for registering and unregistering logging events .
//open connection to controller //construct new message for registering an event // add required fields //create terra harvest message    // send out message //listen for messages for a specific time interval //ensure EventRegistrationResponse type was received, store message data for later use // send out message //listen for potential messages as a result of new request //assert unregister event response was received // Register another event // add required fields // send out message //listen for new messages of a specific time for a specific time interval //assert event registration response was received //verify that log events are no longer being posted with registration of a new event