mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/impl/TestFactoryServiceContextImpl.java
@SuppressWarnings("rawtypes")
    @Test
    public void testAddPluginFactory_ThreadException() throws InvalidSyntaxException
    {
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, m_FactoryInternalFactory);
        FactoryInternal factory = component.getObject();
        
        ServiceReference proxyServiceRef = mock(ServiceReference.class);
        when(proxyServiceRef.getProperty(ComponentConstants.COMPONENT_NAME)).thenReturn(PRODUCT_TYPE);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);

        doThrow(RuntimeException.class).when(factory).makeAvailable();
        
        // replay
        m_ServiceListenerAdpator.addService(proxyServiceRef, m_ProxyComponentFactory);
        
        verify(factory, timeout(100)).registerServices();
        verify(factory, timeout(100)).makeUnavailable();
        
        verify(factory, timeout(100)).cleanup();
        
        verify(component.getInstance(), timeout(100)).dispose();
        
        verify(factory, timeout(100)).dispose(m_ObjectProxy1);
        verify(factory, timeout(100)).dispose(m_ObjectProxy2);
        verify(m_FactoryRegistry, timeout(100)).removeObject(m_ObjectUuid1);
        verify(m_FactoryRegistry, timeout(100)).removeObject(m_ObjectUuid2);
        
        verify(m_CoreBundleContext, timeout(100)).ungetService(proxyServiceRef);
        
        assertThat(m_SUT.getFactories().isEmpty(), is(true));
    }
/**
     * Verify if an exception in thread is thrown, factory registration is cleaned up.
     */
Verify if an exception in thread is thrown, factory registration is cleaned up.
Verify if an exception in thread is thrown factory registration is cleaned up .
@SuppressWarnings("rawtypes")
    @Test
    public void testAddPluginFactory_ThreadException() throws InvalidSyntaxException
    {
        ComponentInfo<FactoryInternal> component = 
                ComponentFactoryMocker.mockSingleComponent(FactoryInternal.class, m_FactoryInternalFactory);
        FactoryInternal factory = component.getObject();
        ServiceReference proxyServiceRef = mock(ServiceReference.class);
        when(proxyServiceRef.getProperty(ComponentConstants.COMPONENT_NAME)).thenReturn(PRODUCT_TYPE);
        when(factory.getProductType()).thenReturn(PRODUCT_TYPE);
        doThrow(RuntimeException.class).when(factory).makeAvailable();
        m_ServiceListenerAdpator.addService(proxyServiceRef, m_ProxyComponentFactory);
        verify(factory, timeout(100)).registerServices();
        verify(factory, timeout(100)).makeUnavailable();
        verify(factory, timeout(100)).cleanup();
        verify(component.getInstance(), timeout(100)).dispose();
        verify(factory, timeout(100)).dispose(m_ObjectProxy1);
        verify(factory, timeout(100)).dispose(m_ObjectProxy2);
        verify(m_FactoryRegistry, timeout(100)).removeObject(m_ObjectUuid1);
        verify(m_FactoryRegistry, timeout(100)).removeObject(m_ObjectUuid2);
        verify(m_CoreBundleContext, timeout(100)).ungetService(proxyServiceRef);
        assertThat(m_SUT.getFactories().isEmpty(), is(true));
    }
@ SuppressWarnings ( "rawtypes" ) @ Test public void testAddPluginFactory_ThreadException ( ) throws InvalidSyntaxException { ComponentInfo < FactoryInternal > component = ComponentFactoryMocker . mockSingleComponent ( FactoryInternal . class , m_FactoryInternalFactory ) ; FactoryInternal factory = component . getObject ( ) ; ServiceReference proxyServiceRef = mock ( ServiceReference . class ) ; when ( proxyServiceRef . getProperty ( ComponentConstants . COMPONENT_NAME ) ) . thenReturn ( PRODUCT_TYPE ) ; when ( factory . getProductType ( ) ) . thenReturn ( PRODUCT_TYPE ) ; doThrow ( RuntimeException . class ) . when ( factory ) . makeAvailable ( ) ; m_ServiceListenerAdpator . addService ( proxyServiceRef , m_ProxyComponentFactory ) ; verify ( factory , timeout ( 100 ) ) . registerServices ( ) ; verify ( factory , timeout ( 100 ) ) . makeUnavailable ( ) ; verify ( factory , timeout ( 100 ) ) . cleanup ( ) ; verify ( component . getInstance ( ) , timeout ( 100 ) ) . dispose ( ) ; verify ( factory , timeout ( 100 ) ) . dispose ( m_ObjectProxy1 ) ; verify ( factory , timeout ( 100 ) ) . dispose ( m_ObjectProxy2 ) ; verify ( m_FactoryRegistry , timeout ( 100 ) ) . removeObject ( m_ObjectUuid1 ) ; verify ( m_FactoryRegistry , timeout ( 100 ) ) . removeObject ( m_ObjectUuid2 ) ; verify ( m_CoreBundleContext , timeout ( 100 ) ) . ungetService ( proxyServiceRef ) ; assertThat ( m_SUT . getFactories ( ) . isEmpty ( ) , is ( true ) ) ; }
Verify if an exception in thread is thrown, factory registration is cleaned up.
Verify if an exception in thread is thrown factory registration is cleaned up .
// replay