mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/asset/TestScannerManager.java
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testScanForAllAssets() throws InterruptedException, IllegalArgumentException, AssetException
    {
        final Semaphore waitSemaphore = new Semaphore(0);
        doAnswer(new Answer()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                Event event = (Event)invocation.getArguments()[0];
                if (event.getTopic().equals(AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE))
                {
                    for (String key : event.getPropertyNames())
                    {
                        if (key.equals(FactoryDescriptor.EVENT_PROP_OBJ_TYPE))
                        {
                            return null;
                        }
                    }
                    waitSemaphore.release();  // found event without asset type property set
                }
                return null;
            }
        }).when(m_EventAdmin).postEvent(Mockito.any(Event.class));
        
        m_SUT.scanForAllAssets(m_ADS);
        
        verify(m_WakeLock).activate();
        assertThat(waitSemaphore.tryAcquire(1, TimeUnit.SECONDS), is(true));
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, atLeastOnce()).postEvent(eventCaptor.capture());
        
        verify(m_ADS).createAsset(AssetType2.class.getName(), ASSET_NAME, m_Props);
        verify(m_ADS).createAsset(AssetType1.class.getName(), null, Collections.EMPTY_MAP);
        
        for (String assetType : m_SUT.getScannableAssetTypes())
        {
            EventAdminVerifier.assertEventByTopicAssetType(eventCaptor, 
                    AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS, assetType);

            EventAdminVerifier.assertEventByTopicAssetType(eventCaptor, 
                    AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE, assetType);
        }
        
        // should get null to signify all have completed
        EventAdminVerifier.assertEventByTopicNoAssetType(eventCaptor, 
                AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE);

        Thread.sleep(1000);
        verify(m_WakeLock).cancel();
    }
/**
     * Verify the scanning of all asset scanners.
     */
Verify the scanning of all asset scanners.
Verify the scanning of all asset scanners .
@SuppressWarnings({"rawtypes", "unchecked"})
    @Test
    public void testScanForAllAssets() throws InterruptedException, IllegalArgumentException, AssetException
    {
        final Semaphore waitSemaphore = new Semaphore(0);
        doAnswer(new Answer()
        {
            @Override
            public Object answer(InvocationOnMock invocation) throws Throwable
            {
                Event event = (Event)invocation.getArguments()[0];
                if (event.getTopic().equals(AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE))
                {
                    for (String key : event.getPropertyNames())
                    {
                        if (key.equals(FactoryDescriptor.EVENT_PROP_OBJ_TYPE))
                        {
                            return null;
                        }
                    }
                    waitSemaphore.release();  
                }
                return null;
            }
        }).when(m_EventAdmin).postEvent(Mockito.any(Event.class));
        m_SUT.scanForAllAssets(m_ADS);
        verify(m_WakeLock).activate();
        assertThat(waitSemaphore.tryAcquire(1, TimeUnit.SECONDS), is(true));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, atLeastOnce()).postEvent(eventCaptor.capture());
        verify(m_ADS).createAsset(AssetType2.class.getName(), ASSET_NAME, m_Props);
        verify(m_ADS).createAsset(AssetType1.class.getName(), null, Collections.EMPTY_MAP);
        for (String assetType : m_SUT.getScannableAssetTypes())
        {
            EventAdminVerifier.assertEventByTopicAssetType(eventCaptor, 
                    AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS, assetType);
            EventAdminVerifier.assertEventByTopicAssetType(eventCaptor, 
                    AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE, assetType);
        }
        EventAdminVerifier.assertEventByTopicNoAssetType(eventCaptor, 
                AssetDirectoryService.TOPIC_SCANNING_FOR_ASSETS_COMPLETE);
        Thread.sleep(1000);
        verify(m_WakeLock).cancel();
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) @ Test public void testScanForAllAssets ( ) throws InterruptedException , IllegalArgumentException , AssetException { final Semaphore waitSemaphore = new Semaphore ( 0 ) ; doAnswer ( new Answer ( ) { @ Override public Object answer ( InvocationOnMock invocation ) throws Throwable { Event event = ( Event ) invocation . getArguments ( ) [ 0 ] ; if ( event . getTopic ( ) . equals ( AssetDirectoryService . TOPIC_SCANNING_FOR_ASSETS_COMPLETE ) ) { for ( String key : event . getPropertyNames ( ) ) { if ( key . equals ( FactoryDescriptor . EVENT_PROP_OBJ_TYPE ) ) { return null ; } } waitSemaphore . release ( ) ; } return null ; } } ) . when ( m_EventAdmin ) . postEvent ( Mockito . any ( Event . class ) ) ; m_SUT . scanForAllAssets ( m_ADS ) ; verify ( m_WakeLock ) . activate ( ) ; assertThat ( waitSemaphore . tryAcquire ( 1 , TimeUnit . SECONDS ) , is ( true ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , atLeastOnce ( ) ) . postEvent ( eventCaptor . capture ( ) ) ; verify ( m_ADS ) . createAsset ( AssetType2 . class . getName ( ) , ASSET_NAME , m_Props ) ; verify ( m_ADS ) . createAsset ( AssetType1 . class . getName ( ) , null , Collections . EMPTY_MAP ) ; for ( String assetType : m_SUT . getScannableAssetTypes ( ) ) { EventAdminVerifier . assertEventByTopicAssetType ( eventCaptor , AssetDirectoryService . TOPIC_SCANNING_FOR_ASSETS , assetType ) ; EventAdminVerifier . assertEventByTopicAssetType ( eventCaptor , AssetDirectoryService . TOPIC_SCANNING_FOR_ASSETS_COMPLETE , assetType ) ; } EventAdminVerifier . assertEventByTopicNoAssetType ( eventCaptor , AssetDirectoryService . TOPIC_SCANNING_FOR_ASSETS_COMPLETE ) ; Thread . sleep ( 1000 ) ; verify ( m_WakeLock ) . cancel ( ) ; }
Verify the scanning of all asset scanners.
Verify the scanning of all asset scanners .
// found event without asset type property set // should get null to signify all have completed