mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetMessageService.java
@Test
    public final void testCaptureData_ObsUuidOnly() throws Exception
    {
        // build request
        CaptureDataRequestData request = CaptureDataRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid))
                .setObservationFormat(RemoteTypesGen.LexiconFormat.Enum.UUID_ONLY).build();        
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.CaptureDataRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);

        //mock necessary objects/actions
        Asset asset = mock(Asset.class);
        Observation obs = mock(Observation.class);

        UUID obsGenUuid = UUID.randomUUID();
        UUID obsUuid = UUID.randomUUID();
        //Observation proto message
        Message obsGen = ObservationGen.
                Observation.newBuilder().
                setSystemInTestMode(true).
                setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setAssetName("AssetOne").
                setCreatedTimestamp(System.currentTimeMillis()).
                setAssetType("AssetTwo").
                setVersion(Version.newBuilder().setMajorNumber(1).setMinorNumber(2).build()).
                setSystemId(0).
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(obsGenUuid)).build();

        when(asset.captureData()).thenReturn(obs);
        when(obs.getUuid()).thenReturn(obsUuid);
        when(m_Converter.convertToProto(obs)).thenReturn(obsGen);
        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);

        //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((CaptureDataRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));

        //capture and verify response
        ArgumentCaptor<CaptureDataResponseData> messageCaptor = ArgumentCaptor.forClass(CaptureDataResponseData.class); 
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.CaptureDataResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);

        CaptureDataResponseData response = messageCaptor.getValue();
        assertThat(response.isInitialized(), is(true));
        verify(asset).captureData();
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
        assertThat(response.getObservationCase(), is(ObservationCase.OBSERVATIONUUID));        
        assertThat(response.getObservationUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(obsUuid)));
    }
/**
     * Test capture data request/response message system for assets. 
     * Specifically, the following behaviors are tested: 
     *      Verify incoming request message is posted to event admin.
     *      Verify asset captures data upon request.
     *      Verify response (containing correct data) is sent after completing request. 
     */
Test capture data request/response message system for assets.
Specifically, the following behaviors are tested:
Verify incoming request message is posted to event admin.
Verify asset captures data upon request.
Verify response (containing correct data) is sent after completing request.
Test capture data request / response message system for assets . Specifically the following behaviors are tested : Verify incoming request message is posted to event admin . Verify asset captures data upon request . Verify response ( containing correct data ) is sent after completing request .
@Test
    public final void testCaptureData_ObsUuidOnly() throws Exception
    {
        CaptureDataRequestData request = CaptureDataRequestData.newBuilder()
                .setUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid))
                .setObservationFormat(RemoteTypesGen.LexiconFormat.Enum.UUID_ONLY).build();        
        AssetNamespace assetMessage = AssetNamespace.newBuilder().
                setType(AssetMessageType.CaptureDataRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetMessage);
        TerraHarvestMessage message = createMessage(assetMessage);
        Asset asset = mock(Asset.class);
        Observation obs = mock(Observation.class);
        UUID obsGenUuid = UUID.randomUUID();
        UUID obsUuid = UUID.randomUUID();
        Message obsGen = ObservationGen.
                Observation.newBuilder().
                setSystemInTestMode(true).
                setAssetUuid(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)).
                setAssetName("AssetOne").
                setCreatedTimestamp(System.currentTimeMillis()).
                setAssetType("AssetTwo").
                setVersion(Version.newBuilder().setMajorNumber(1).setMinorNumber(2).build()).
                setSystemId(0).
                setUuid(SharedMessageUtils.convertUUIDToProtoUUID(obsGenUuid)).build();
        when(asset.captureData()).thenReturn(obs);
        when(obs.getUuid()).thenReturn(obsUuid);
        when(m_Converter.convertToProto(obs)).thenReturn(obsGen);
        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((CaptureDataRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        ArgumentCaptor<CaptureDataResponseData> messageCaptor = ArgumentCaptor.forClass(CaptureDataResponseData.class); 
        verify(m_MessageFactory).createAssetResponseMessage(eq(message), 
                eq(AssetMessageType.CaptureDataResponse), messageCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        CaptureDataResponseData response = messageCaptor.getValue();
        assertThat(response.isInitialized(), is(true));
        verify(asset).captureData();
        assertThat(response.getAssetUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(m_AssetUuid)));
        assertThat(response.getObservationCase(), is(ObservationCase.OBSERVATIONUUID));        
        assertThat(response.getObservationUuid(), is(SharedMessageUtils.convertUUIDToProtoUUID(obsUuid)));
    }
@ Test public final void testCaptureData_ObsUuidOnly ( ) throws Exception { CaptureDataRequestData request = CaptureDataRequestData . newBuilder ( ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . setObservationFormat ( RemoteTypesGen . LexiconFormat . Enum . UUID_ONLY ) . build ( ) ; AssetNamespace assetMessage = AssetNamespace . newBuilder ( ) . setType ( AssetMessageType . CaptureDataRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetMessage ) ; TerraHarvestMessage message = createMessage ( assetMessage ) ; Asset asset = mock ( Asset . class ) ; Observation obs = mock ( Observation . class ) ; UUID obsGenUuid = UUID . randomUUID ( ) ; UUID obsUuid = UUID . randomUUID ( ) ; Message obsGen = ObservationGen . Observation . newBuilder ( ) . setSystemInTestMode ( true ) . setAssetUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) . setAssetName ( "AssetOne" ) . setCreatedTimestamp ( System . currentTimeMillis ( ) ) . setAssetType ( "AssetTwo" ) . setVersion ( Version . newBuilder ( ) . setMajorNumber ( 1 ) . setMinorNumber ( 2 ) . build ( ) ) . setSystemId ( 0 ) . setUuid ( SharedMessageUtils . convertUUIDToProtoUUID ( obsGenUuid ) ) . build ( ) ; when ( asset . captureData ( ) ) . thenReturn ( obs ) ; when ( obs . getUuid ( ) ) . thenReturn ( obsUuid ) ; when ( m_Converter . convertToProto ( obs ) ) . thenReturn ( obsGen ) ; 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 ( ( CaptureDataRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; ArgumentCaptor < CaptureDataResponseData > messageCaptor = ArgumentCaptor . forClass ( CaptureDataResponseData . class ) ; verify ( m_MessageFactory ) . createAssetResponseMessage ( eq ( message ) , eq ( AssetMessageType . CaptureDataResponse ) , messageCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; CaptureDataResponseData response = messageCaptor . getValue ( ) ; assertThat ( response . isInitialized ( ) , is ( true ) ) ; verify ( asset ) . captureData ( ) ; assertThat ( response . getAssetUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( m_AssetUuid ) ) ) ; assertThat ( response . getObservationCase ( ) , is ( ObservationCase . OBSERVATIONUUID ) ) ; assertThat ( response . getObservationUuid ( ) , is ( SharedMessageUtils . convertUUIDToProtoUUID ( obsUuid ) ) ) ; }
Test capture data request/response message system for assets.
Test capture data request / response message system for assets .
// build request //mock necessary objects/actions //Observation proto message // mock the channel the message came from // replay //capture and verify event has been posted locally //capture and verify response