mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/asset/TestAssetServiceProxy.java
@Test
    public void testOnRemoveFactory() throws Exception
    {
        AssetInternal asset1 = mock(AssetInternal.class);
        stubDeactivationAsset(asset1, AssetActiveStatus.ACTIVATED, 5);
        AssetInternal asset2 = mock(AssetInternal.class);
        stubDeactivationAsset(asset2, AssetActiveStatus.DEACTIVATED, 0);
        AssetInternal asset3 = mock(AssetInternal.class);
        // will take 100 seconds but total time should only be 10 seconds as that is the max
        stubDeactivationAsset(asset3, AssetActiveStatus.ACTIVATED, 100); 
        
        Set<AssetInternal> assets = new HashSet<>();
        assets.add(asset1);
        assets.add(asset2);
        assets.add(asset3);
                
        // use of mockito to tell what an injected service should do when called
        when(factoryServiceContext.getRegistry()).thenReturn(factoryRegistry);
        when(factoryServiceContext.getDirectoryService()).thenReturn(assetDirectoryService);
        when(factory.getProductType()).thenReturn("product-type");
        when(factoryRegistry.getObjectsByProductType("product-type")).thenReturn(assets);
        
        // replay
        long timeBefore = System.currentTimeMillis();
        m_SUT.onRemoveFactory(factoryServiceContext, factory);
        long timeDelta = System.currentTimeMillis() - timeBefore;
        
        // waits a total of 10 seconds, so the thread that takes 100 seconds should not keep this running longer
        assertThat((int)timeDelta, is(lessThanOrEqualTo(12 * 1000)));
        
        // verify
        ArgumentCaptor<AssetActivationListener[]> listenersCap = 
                ArgumentCaptor.forClass(AssetActivationListener[].class);
        verify(asset1).internalDeactivate(listenersCap.capture());
        verify(asset2, never()).internalDeactivate(listenersCap.capture());
        verify(asset3).internalDeactivate(listenersCap.capture());
        
        for (AssetActivationListener[] listeners : listenersCap.getAllValues())
        {
            assertThat(listeners[0], is(instanceOf(ActivationListenerBridge.class)));
            assertThat(listeners[1], is(instanceOf(OnAssetDeactivateListener.class)));
        }
    }
/**
     * Test to verify that when an asset factory removed, all assets are deactivated first.
     */
Test to verify that when an asset factory removed, all assets are deactivated first.
Test to verify that when an asset factory removed all assets are deactivated first .
@Test
    public void testOnRemoveFactory() throws Exception
    {
        AssetInternal asset1 = mock(AssetInternal.class);
        stubDeactivationAsset(asset1, AssetActiveStatus.ACTIVATED, 5);
        AssetInternal asset2 = mock(AssetInternal.class);
        stubDeactivationAsset(asset2, AssetActiveStatus.DEACTIVATED, 0);
        AssetInternal asset3 = mock(AssetInternal.class);
        stubDeactivationAsset(asset3, AssetActiveStatus.ACTIVATED, 100); 
        Set<AssetInternal> assets = new HashSet<>();
        assets.add(asset1);
        assets.add(asset2);
        assets.add(asset3);
        when(factoryServiceContext.getRegistry()).thenReturn(factoryRegistry);
        when(factoryServiceContext.getDirectoryService()).thenReturn(assetDirectoryService);
        when(factory.getProductType()).thenReturn("product-type");
        when(factoryRegistry.getObjectsByProductType("product-type")).thenReturn(assets);
        long timeBefore = System.currentTimeMillis();
        m_SUT.onRemoveFactory(factoryServiceContext, factory);
        long timeDelta = System.currentTimeMillis() - timeBefore;
        assertThat((int)timeDelta, is(lessThanOrEqualTo(12 * 1000)));
        ArgumentCaptor<AssetActivationListener[]> listenersCap = 
                ArgumentCaptor.forClass(AssetActivationListener[].class);
        verify(asset1).internalDeactivate(listenersCap.capture());
        verify(asset2, never()).internalDeactivate(listenersCap.capture());
        verify(asset3).internalDeactivate(listenersCap.capture());
        for (AssetActivationListener[] listeners : listenersCap.getAllValues())
        {
            assertThat(listeners[0], is(instanceOf(ActivationListenerBridge.class)));
            assertThat(listeners[1], is(instanceOf(OnAssetDeactivateListener.class)));
        }
    }
@ Test public void testOnRemoveFactory ( ) throws Exception { AssetInternal asset1 = mock ( AssetInternal . class ) ; stubDeactivationAsset ( asset1 , AssetActiveStatus . ACTIVATED , 5 ) ; AssetInternal asset2 = mock ( AssetInternal . class ) ; stubDeactivationAsset ( asset2 , AssetActiveStatus . DEACTIVATED , 0 ) ; AssetInternal asset3 = mock ( AssetInternal . class ) ; stubDeactivationAsset ( asset3 , AssetActiveStatus . ACTIVATED , 100 ) ; Set < AssetInternal > assets = new HashSet < > ( ) ; assets . add ( asset1 ) ; assets . add ( asset2 ) ; assets . add ( asset3 ) ; when ( factoryServiceContext . getRegistry ( ) ) . thenReturn ( factoryRegistry ) ; when ( factoryServiceContext . getDirectoryService ( ) ) . thenReturn ( assetDirectoryService ) ; when ( factory . getProductType ( ) ) . thenReturn ( "product-type" ) ; when ( factoryRegistry . getObjectsByProductType ( "product-type" ) ) . thenReturn ( assets ) ; long timeBefore = System . currentTimeMillis ( ) ; m_SUT . onRemoveFactory ( factoryServiceContext , factory ) ; long timeDelta = System . currentTimeMillis ( ) - timeBefore ; assertThat ( ( int ) timeDelta , is ( lessThanOrEqualTo ( 12 * 1000 ) ) ) ; ArgumentCaptor < AssetActivationListener [ ] > listenersCap = ArgumentCaptor . forClass ( AssetActivationListener [ ] . class ) ; verify ( asset1 ) . internalDeactivate ( listenersCap . capture ( ) ) ; verify ( asset2 , never ( ) ) . internalDeactivate ( listenersCap . capture ( ) ) ; verify ( asset3 ) . internalDeactivate ( listenersCap . capture ( ) ) ; for ( AssetActivationListener [ ] listeners : listenersCap . getAllValues ( ) ) { assertThat ( listeners [ 0 ] , is ( instanceOf ( ActivationListenerBridge . class ) ) ) ; assertThat ( listeners [ 1 ] , is ( instanceOf ( OnAssetDeactivateListener . class ) ) ) ; } }
Test to verify that when an asset factory removed, all assets are deactivated first.
Test to verify that when an asset factory removed all assets are deactivated first .
// will take 100 seconds but total time should only be 10 seconds as that is the max // use of mockito to tell what an injected service should do when called // replay // waits a total of 10 seconds, so the thread that takes 100 seconds should not keep this running longer // verify