mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testGetStatus_NullStatus() throws IOException, ObjectConverterException
    {
        //Build get status request message
        GetLastStatusRequestData request = GetLastStatusRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).build();    
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetLastStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);

        // mock necessary objects/actions
        Asset asset = mock(Asset.class);
        when(asset.getLastStatus()).thenReturn(null);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);

        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

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

        // verify the event contains the data message
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat((GetLastStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        ArgumentCaptor<GetLastStatusResponseData> messageCaptor = 
                ArgumentCaptor.forClass(GetLastStatusResponseData.class);
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), eq(AssetMessageType.GetLastStatusResponse), 
                messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        verify (m_Converter, never()).convertToProto(Mockito.any(Observation.class));
        
        //verify message data
        GetLastStatusResponseData response = messageCaptor.getValue();
        assertThat(response.getStatusObservationCase(), 
                is(GetLastStatusResponseData.StatusObservationCase.STATUSOBSERVATION_NOT_SET));
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
    }
/**
     * Test get status request/response message system for assets.  
     * Verify response even if status is null.
     */
Test get status request/response message system for assets.
Verify response even if status is null.
Test get status request / response message system for assets . Verify response even if status is null .
@Test
    public final void testGetStatus_NullStatus() throws IOException, ObjectConverterException
    {
        GetLastStatusRequestData request = GetLastStatusRequestData.newBuilder().
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).build();    
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.GetLastStatusRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Asset asset = mock(Asset.class);
        when(asset.getLastStatus()).thenReturn(null);
        when(m_AssetDirectoryService.getAssetByUuid(m_AssetUuid)).thenReturn(asset);
        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((GetLastStatusRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<GetLastStatusResponseData> messageCaptor = 
                ArgumentCaptor.forClass(GetLastStatusResponseData.class);
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), eq(AssetMessageType.GetLastStatusResponse), 
                messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        verify (m_Converter, never()).convertToProto(Mockito.any(Observation.class));
        GetLastStatusResponseData response = messageCaptor.getValue();
        assertThat(response.getStatusObservationCase(), 
                is(GetLastStatusResponseData.StatusObservationCase.STATUSOBSERVATION_NOT_SET));
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
    }
@ Test public final void testGetStatus_NullStatus ( ) throws IOException , ObjectConverterException { GetLastStatusRequestData request = GetLastStatusRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . GetLastStatusRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Asset asset = mock ( Asset . class ) ; when ( asset . getLastStatus ( ) ) . thenReturn ( null ) ; when ( m_AssetDirectoryService . getAssetByUuid ( m_AssetUuid ) ) . thenReturn ( asset ) ; 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 ( ( GetLastStatusRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < GetLastStatusResponseData > messageCaptor = ArgumentCaptor . forClass ( GetLastStatusResponseData . class ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . GetLastStatusResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; verify ( m_Converter , never ( ) ) . convertToProto ( Mockito . any ( Observation . class ) ) ; GetLastStatusResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . getStatusObservationCase ( ) , is ( GetLastStatusResponseData . StatusObservationCase . STATUSOBSERVATION_NOT_SET ) ) ; assertThat ( response . getAssetUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) ) ; }
Test get status request/response message system for assets.
Test get status request / response message system for assets .
//Build get status request message // mock necessary objects/actions // mock the channel the message came from // replay // verify the event contains the data message //verify message data