mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testPerformBit_ObjectConverterException() throws IOException, ObjectConverterException
    {
        //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);

        when(m_Converter.convertToProto(jaxbStatus)).thenThrow(new ObjectConverterException("exception"));
        
        // 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));

        //verify error message
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.CONVERTER_ERROR), 
                anyString());
        verify(m_ResponseWrapper).queue(channel);
    }
/**
     * Test perform built-in-test request/response when there is an object converter exception.
     * Verify error message is sent. 
     */
Test perform built-in-test request/response when there is an object converter exception.
Verify error message is sent.
Test perform built - in - test request / response when there is an object converter exception . Verify error message is sent .
@Test
    public final void testPerformBit_ObjectConverterException() throws IOException, ObjectConverterException
    {
        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);
        when(m_Converter.convertToProto(jaxbStatus)).thenThrow(new ObjectConverterException("exception"));
        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));
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.CONVERTER_ERROR), 
                anyString());
        verify(m_ResponseWrapper).queue(channel);
    }
@ Test public final void testPerformBit_ObjectConverterException ( ) throws IOException , ObjectConverterException { 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 ) ; when ( m_Converter . convertToProto ( jaxbStatus ) ) . thenThrow ( new ObjectConverterException ( "exception" ) ) ; 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 ) ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( eq ( message ) , eq ( ErrorCode . CONVERTER_ERROR ) , anyString ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; }
Test perform built-in-test request/response when there is an object converter exception.
Test perform built - in - test request / response when there is an object converter exception .
//build request //mock necessary objects/actions // mock the channel the message came from // replay //capture and verify event has been posted locally //verify error message