mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testPerformBit() throws Exception
    {
        //build request
        PerformBitRequestData request = PerformBitRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).build();
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.PerformBitRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);

        //mock necessary objects/actions
        Asset asset = mock(Asset.class);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        Observation jaxbStatus = mock(Observation.class);
        when(asset.performBit()).thenReturn(jaxbStatus);

        //make a proto status observation to be returned from converter
        ObservationGen.Observation stat = TerraHarvestMessageHelper.getProtoObs().toBuilder().
                setStatus(Status.newBuilder().
                        setSummaryStatus(OperatingStatus.newBuilder().
                        setDescription("asdf").
                        setSummary(StatusTypesGen.SummaryStatus.Enum.OFF).build()).build()).build();
        
        when(m_Converter.convertToProto(jaxbStatus)).thenReturn(stat);
        
        // 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((PerformBitRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        //capture and verify response
        ArgumentCaptor<PerformBitResponseData> messageCaptor = ArgumentCaptor.forClass(PerformBitResponseData.class);  
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.PerformBitResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        PerformBitResponseData response = messageCaptor.getValue();       
        assertThat(response.getStatusObservationCase(), is(StatusObservationCase.STATUSOBSERVATIONNATIVE));
        assertThat(response.getStatusObservationNative(), is(stat));
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
        verify(asset).performBit();
    }
/**
     * Test perform built-in-test request/response message system for assets.  
     * Specifically, the following behaviors are tested: 
     *      Verify incoming request message is posted to event admin.
     *      Verify asset performs BIT upon request.
     *      Verify response (containing correct data) is sent after completing request. 
     * 
     */
Test perform built-in-test request/response message system for assets.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to event admin.
Verify asset performs BIT upon request.
Verify response (containing correct data) is sent after completing request.
Test perform built - in - test request / response message system for assets . Specifically the following behaviors are tested : Verify incoming request message is posted to event admin . Verify asset performs BIT upon request . Verify response ( containing correct data ) is sent after completing request .
@Test
    public final void testPerformBit() throws Exception
    {
        PerformBitRequestData request = PerformBitRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).build();
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.PerformBitRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Asset asset = mock(Asset.class);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        Observation jaxbStatus = mock(Observation.class);
        when(asset.performBit()).thenReturn(jaxbStatus);
        ObservationGen.Observation stat = TerraHarvestMessageHelper.getProtoObs().toBuilder().
                setStatus(Status.newBuilder().
                        setSummaryStatus(OperatingStatus.newBuilder().
                        setDescription("asdf").
                        setSummary(StatusTypesGen.SummaryStatus.Enum.OFF).build()).build()).build();
        when(m_Converter.convertToProto(jaxbStatus)).thenReturn(stat);
        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((PerformBitRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<PerformBitResponseData> messageCaptor = ArgumentCaptor.forClass(PerformBitResponseData.class);  
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.PerformBitResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        PerformBitResponseData response = messageCaptor.getValue();       
        assertThat(response.getStatusObservationCase(), is(StatusObservationCase.STATUSOBSERVATIONNATIVE));
        assertThat(response.getStatusObservationNative(), is(stat));
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
        verify(asset).performBit();
    }
@ Test public final void testPerformBit ( ) throws Exception { PerformBitRequestData request = PerformBitRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . PerformBitRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Asset asset = mock ( Asset . class ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; Observation jaxbStatus = mock ( Observation . class ) ; when ( asset . performBit ( ) ) . thenReturn ( jaxbStatus ) ; ObservationGen . Observation stat = TerraHarvestMessageHelper . getProtoObs ( ) . toBuilder ( ) . setStatus ( Status . newBuilder ( ) . setSummaryStatus ( OperatingStatus . newBuilder ( ) . setDescription ( "asdf" ) . setSummary ( StatusTypesGen . SummaryStatus . Enum . OFF ) . build ( ) ) . build ( ) ) . build ( ) ; when ( m_Converter . convertToProto ( jaxbStatus ) ) . thenReturn ( stat ) ; 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 ( ( PerformBitRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < PerformBitResponseData > messageCaptor = ArgumentCaptor . forClass ( PerformBitResponseData . class ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . PerformBitResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; PerformBitResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getStatusObservationCase ( ) , is ( StatusObservationCase . STATUSOBSERVATIONNATIVE ) ) ; assertThat ( response . getStatusObservationNative ( ) , is ( stat ) ) ; assertThat ( response . getAssetUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) ) ; verify ( asset ) . performBit ( ) ; }
Test perform built-in-test request/response message system for assets.
Test perform built - in - test request / response message system for assets .
//build request //mock necessary objects/actions //make a proto status observation to be returned from converter // mock the channel the message came from // replay //capture and verify event has been posted locally //capture and verify response