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

        // Register Event
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED);
        // add required fields
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, 
                requestMessage.build());
        //send out message
        message.writeDelimitedTo(m_Socket.getOutputStream());

        // check for response
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.EventRegistrationResponse, 500);
        
        // don't use util method as we need to listen for the event which may be swallowed up by the helper method
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType(ExampleAsset.class.getName()).setName("EventCleanupAsset").build();
        AssetDirectoryServiceNamespace.Builder assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request.toByteString());
        message = TerraHarvestMessageHelper.
                createTerraHarvestMsg(Namespace.AssetDirectoryService, assetDirMessage);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        
        // verify registered event is received
        listener.waitForRemoteEvent(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, 1000);
        
        AssetNamespaceUtils.removeAllAssets(m_Socket);
        
        //create cleanup request
        message = createEventAdminMessage(EventAdminMessageType.CleanupRequest, null);
        message.writeDelimitedTo(m_Socket.getOutputStream());

        //listen for messages
        //assert cleanup response received
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.CleanupResponse, 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 messages
        //assert event registration response received
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.EventRegistrationResponse, 500);
        
        // verify that log events are no longer being posted as a result of "cleaning up" the
        // log event registration
        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 cleaning up registered events.  
     */
Test sending and receiving a response for cleaning up registered events.
Test sending and receiving a response for cleaning up registered events .
@Test
    public void testCleanup() throws UnknownHostException, IOException, InterruptedException
    {
        MessageListener listener = new MessageListener(m_Socket);
        EventRegistrationRequestData.Builder requestMessage = EventRegistrationRequestData.newBuilder()
                .addTopic(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED);
        requestMessage = RemoteUtils.appendRequiredFields(requestMessage, false);
        TerraHarvestMessage message = createEventAdminMessage(EventAdminMessageType.EventRegistrationRequest, 
                requestMessage.build());
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.EventRegistrationResponse, 500);
        CreateAssetRequestData request = CreateAssetRequestData.newBuilder().
                setProductType(ExampleAsset.class.getName()).setName("EventCleanupAsset").build();
        AssetDirectoryServiceNamespace.Builder assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.CreateAssetRequest).
                setData(request.toByteString());
        message = TerraHarvestMessageHelper.
                createTerraHarvestMsg(Namespace.AssetDirectoryService, assetDirMessage);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForRemoteEvent(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED, 1000);
        AssetNamespaceUtils.removeAllAssets(m_Socket);
        message = createEventAdminMessage(EventAdminMessageType.CleanupRequest, null);
        message.writeDelimitedTo(m_Socket.getOutputStream());
        listener.waitForMessage(Namespace.EventAdmin, EventAdminMessageType.CleanupResponse, 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 testCleanup ( ) throws UnknownHostException , IOException , InterruptedException { MessageListener listener = new MessageListener ( m_Socket ) ; EventRegistrationRequestData . Builder requestMessage = EventRegistrationRequestData . newBuilder ( ) . addTopic ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED ) ; requestMessage = RemoteUtils . appendRequiredFields ( requestMessage , false ) ; TerraHarvestMessage message = createEventAdminMessage ( EventAdminMessageType . EventRegistrationRequest , requestMessage . build ( ) ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . EventAdmin , EventAdminMessageType . EventRegistrationResponse , 500 ) ; CreateAssetRequestData request = CreateAssetRequestData . newBuilder ( ) . setProductType ( ExampleAsset . class . getName ( ) ) . setName ( "EventCleanupAsset" ) . build ( ) ; AssetDirectoryServiceNamespace . Builder assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . CreateAssetRequest ) . setData ( request . toByteString ( ) ) ; message = TerraHarvestMessageHelper . createTerraHarvestMsg ( Namespace . AssetDirectoryService , assetDirMessage ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForRemoteEvent ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED , 1000 ) ; AssetNamespaceUtils . removeAllAssets ( m_Socket ) ; message = createEventAdminMessage ( EventAdminMessageType . CleanupRequest , null ) ; message . writeDelimitedTo ( m_Socket . getOutputStream ( ) ) ; listener . waitForMessage ( Namespace . EventAdmin , EventAdminMessageType . CleanupResponse , 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 cleaning up registered events.
Test sending and receiving a response for cleaning up registered events .
// Register Event // add required fields //send out message // check for response // don't use util method as we need to listen for the event which may be swallowed up by the helper method // verify registered event is received //create cleanup request //listen for messages //assert cleanup response received //Register another event // add required fields //send out message //listen for messages //assert event registration response received // verify that log events are no longer being posted as a result of "cleaning up" the // log event registration