mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/asset/TestAssetDirectoryMessageService.java
@Test
    public void testScanForNewAssets() throws IOException
    {
        ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData.newBuilder().build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        
        // 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((ScanForNewAssetsRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        verify(m_AssetDirectoryService).scanForNewAssets();
        
        //capture and verify response
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.ScanForNewAssetsResponse), Mockito.any(Message.class));
        verify(m_ResponseWrapper).queue(channel);
        
        //New request with set product type
        AssetFactory factory = mock(AssetFactory.class);
        Set<AssetFactory> factorySet = new HashSet<>();
        factorySet.add(factory);
        
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factorySet);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        
        request = ScanForNewAssetsRequestData.newBuilder().setProductType(AssetProxy.class.getName()).build();
        assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        payload = createPayload(assetDirMessage);
        message = createMessage(assetDirMessage); 
        
        // replay
        m_SUT.handleMessage(message, payload, channel);
        
        eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, Mockito.times(2)).postEvent(eventCaptor.capture());
        event = eventCaptor.getValue();
        assertThat((ScanForNewAssetsRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        verify(m_AssetDirectoryService).scanForNewAssets(AssetProxy.class.getName());
        
        //capture and verify response
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.ScanForNewAssetsResponse), Mockito.any(Message.class));
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
/**
     * Test the scan for new assets 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 new assets are scanned for upon request (with and without specified asset type).
     *      Verify response is sent after request.
     */
Test the scan for new assets 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 new assets are scanned for upon request (with and without specified asset type).
Verify response is sent after request.
Test the scan for new assets 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 new assets are scanned for upon request ( with and without specified asset type ) . Verify response is sent after request .
@Test
    public void testScanForNewAssets() throws IOException
    {
        ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData.newBuilder().build();
        AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        TerraHarvestPayload payload = createPayload(assetDirMessage);
        TerraHarvestMessage message = createMessage(assetDirMessage);
        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((ScanForNewAssetsRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        verify(m_AssetDirectoryService).scanForNewAssets();
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.ScanForNewAssetsResponse), Mockito.any(Message.class));
        verify(m_ResponseWrapper).queue(channel);
        AssetFactory factory = mock(AssetFactory.class);
        Set<AssetFactory> factorySet = new HashSet<>();
        factorySet.add(factory);
        when(m_AssetDirectoryService.getAssetFactories()).thenReturn(factorySet);
        doReturn(AssetProxy.class.getName()).when(factory).getProductType();
        request = ScanForNewAssetsRequestData.newBuilder().setProductType(AssetProxy.class.getName()).build();
        assetDirMessage = AssetDirectoryServiceNamespace.newBuilder().
                setType(AssetDirectoryServiceMessageType.ScanForNewAssetsRequest).
                setData(request.toByteString()).build();
        payload = createPayload(assetDirMessage);
        message = createMessage(assetDirMessage); 
        m_SUT.handleMessage(message, payload, channel);
        eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, Mockito.times(2)).postEvent(eventCaptor.capture());
        event = eventCaptor.getValue();
        assertThat((ScanForNewAssetsRequestData)event.getProperty(RemoteConstants.EVENT_PROP_DATA_MESSAGE),
                is(request));
        verify(m_AssetDirectoryService).scanForNewAssets(AssetProxy.class.getName());
        verify(m_MessageFactory).createAssetDirectoryServiceResponseMessage(eq(message), 
                eq(AssetDirectoryServiceMessageType.ScanForNewAssetsResponse), Mockito.any(Message.class));
        verify(m_ResponseWrapper, times(2)).queue(channel);
    }
@ Test public void testScanForNewAssets ( ) throws IOException { ScanForNewAssetsRequestData request = ScanForNewAssetsRequestData . newBuilder ( ) . build ( ) ; AssetDirectoryServiceNamespace assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . ScanForNewAssetsRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; TerraHarvestPayload payload = createPayload ( assetDirMessage ) ; TerraHarvestMessage message = createMessage ( assetDirMessage ) ; 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 ( ( ScanForNewAssetsRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; verify ( m_AssetDirectoryService ) . scanForNewAssets ( ) ; verify ( m_MessageFactory ) . createAssetDirectoryServiceResponseMessage ( eq ( message ) , eq ( AssetDirectoryServiceMessageType . ScanForNewAssetsResponse ) , Mockito . any ( Message . class ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; AssetFactory factory = mock ( AssetFactory . class ) ; Set < AssetFactory > factorySet = new HashSet < > ( ) ; factorySet . add ( factory ) ; when ( m_AssetDirectoryService . getAssetFactories ( ) ) . thenReturn ( factorySet ) ; doReturn ( AssetProxy . class . getName ( ) ) . when ( factory ) . getProductType ( ) ; request = ScanForNewAssetsRequestData . newBuilder ( ) . setProductType ( AssetProxy . class . getName ( ) ) . build ( ) ; assetDirMessage = AssetDirectoryServiceNamespace . newBuilder ( ) . setType ( AssetDirectoryServiceMessageType . ScanForNewAssetsRequest ) . setData ( request . toByteString ( ) ) . build ( ) ; payload = createPayload ( assetDirMessage ) ; message = createMessage ( assetDirMessage ) ; m_SUT . handleMessage ( message , payload , channel ) ; eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , Mockito . times ( 2 ) ) . postEvent ( eventCaptor . capture ( ) ) ; event = eventCaptor . getValue ( ) ; assertThat ( ( ScanForNewAssetsRequestData ) event . getProperty ( RemoteConstants . EVENT_PROP_DATA_MESSAGE ) , is ( request ) ) ; verify ( m_AssetDirectoryService ) . scanForNewAssets ( AssetProxy . class . getName ( ) ) ; verify ( m_MessageFactory ) . createAssetDirectoryServiceResponseMessage ( eq ( message ) , eq ( AssetDirectoryServiceMessageType . ScanForNewAssetsResponse ) , Mockito . any ( Message . class ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; }
Test the scan for new assets request/response remote message system for the asset directory service.
Test the scan for new assets 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 //New request with set product type // replay //capture and verify response //reused channel