mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public void testGetLastStatus() throws IOException
    {
        GetActiveStatusRequestData request = GetActiveStatusRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetActiveStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        
        Asset asset = mock(Asset.class);
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // replay
        m_SUT.handleMessage(message, payload, channel);

        //capture and verify event has been posted locally
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetActiveStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        //capture and verify response
        ArgumentCaptor<GetActiveStatusResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetActiveStatusResponseData response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.ACTIVATED));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        
        //Change status
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATING);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(2)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.ACTIVATING));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        
        //Change status
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.DEACTIVATED);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(3)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(3)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.DEACTIVATED));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        
        //Change status
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.DEACTIVATING);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(4)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(4)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.DEACTIVATING));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
/**
     * Test the get asset status request/response remote message system for the asset directory service.
     * Specifically, the following behaviors are tested: 
     *      Verify incoming request message is posted to event admin.
     *      Verify asset status is returned upon request.
     *      Verify response (containing correct data) is sent after completing request. 
     */
Test the get asset status request/response remote message system for the asset directory service.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to event admin.
Verify asset status is returned upon request.
Verify response (containing correct data) is sent after completing request.
Test the get asset status request / response remote message system for the asset directory service . Specifically the following behaviors are tested : Verify incoming request message is posted to event admin . Verify asset status is returned upon request . Verify response ( containing correct data ) is sent after completing request .
@Test
    public void testGetLastStatus() throws IOException
    {
        GetActiveStatusRequestData request = GetActiveStatusRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)).build();
        AssetNamespace assetDirMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetActiveStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        Asset asset = mock(Asset.class);
        when(m_AssetDirectoryService.getAssetByUuid(testUuid)).thenReturn(asset);
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATED);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetActiveStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetActiveStatusResponseData> messageCaptor = ArgumentCaptor.
                forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetActiveStatusResponseData response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.ACTIVATED));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.ACTIVATING);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(2)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.ACTIVATING));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.DEACTIVATED);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(3)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(3)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.DEACTIVATED));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
        when(asset.getActiveStatus()).thenReturn(AssetActiveStatus.DEACTIVATING);
        m_SUT.handleMessage(message, payload, channel);        
        messageCaptor = ArgumentCaptor.forClass(GetActiveStatusResponseData.class); 
        verify(m_MessageFactory, Mockito.times(4)).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.GetActiveStatusResponse), messageCaptor.capture());
        verify(m_ResponseWrapper, times(4)).queue(channel);
        response = messageCaptor.getValue();
        assertThat(response.getStatus(), is(AssetMessages.AssetActiveStatus.DEACTIVATING));
        assertThat(response.getUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(testUuid)));
    }
@ Test public void testGetLastStatus ( ) throws IOException { GetActiveStatusRequestData request = GetActiveStatusRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) . build ( ) ; AssetNamespace assetDirMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . GetActiveStatusRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetDirMessage ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; Asset asset = mock ( Asset . class ) ; when ( m_AssetDirectoryService . getAssetByUuid ( testUuid ) ) . thenReturn ( asset ) ; when ( asset . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . ACTIVATED ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( ( GetActiveStatusRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetActiveStatusResponseData > messageCaptor = ArgumentCaptor . forClass ( GetActiveStatusResponseData . class ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetActiveStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetActiveStatusResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getStatus ( ) , is ( AssetMessages . AssetActiveStatus . ACTIVATED ) ) ; assertThat ( response . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; when ( asset . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . ACTIVATING ) ; m_SUT . handleMessage ( message , payload , channel ) ; messageCaptor = ArgumentCaptor . forClass ( GetActiveStatusResponseData . class ) ; verify ( m_MessageFactory , Mockito . times ( 2 ) ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetActiveStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; response = messageCaptor . getValue ( ) ; assertThat ( response . getStatus ( ) , is ( AssetMessages . AssetActiveStatus . ACTIVATING ) ) ; assertThat ( response . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; when ( asset . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . DEACTIVATED ) ; m_SUT . handleMessage ( message , payload , channel ) ; messageCaptor = ArgumentCaptor . forClass ( GetActiveStatusResponseData . class ) ; verify ( m_MessageFactory , Mockito . times ( 3 ) ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetActiveStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 3 ) ) . queue ( channel ) ; response = messageCaptor . getValue ( ) ; assertThat ( response . getStatus ( ) , is ( AssetMessages . AssetActiveStatus . DEACTIVATED ) ) ; assertThat ( response . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; when ( asset . getActiveStatus ( ) ) . thenReturn ( AssetActiveStatus . DEACTIVATING ) ; m_SUT . handleMessage ( message , payload , channel ) ; messageCaptor = ArgumentCaptor . forClass ( GetActiveStatusResponseData . class ) ; verify ( m_MessageFactory , Mockito . times ( 4 ) ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetActiveStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 4 ) ) . queue ( channel ) ; response = messageCaptor . getValue ( ) ; assertThat ( response . getStatus ( ) , is ( AssetMessages . AssetActiveStatus . DEACTIVATING ) ) ; assertThat ( response . getUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( testUuid ) ) ) ; }
Test the get asset status request/response remote message system for the asset directory service.
Test the get asset status request / response remote message system for the asset directory service .
// mock the channel the message came from // replay //capture and verify event has been posted locally //capture and verify response //Change status //Change status //Change status