mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testCreateConfigurationIoException() throws IllegalArgumentException,
        FactoryException, FactoryObjectInformationException, IOException
    {
        // mock config admin to be returned
        doThrow(new IOException()).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());

        // mock a factory object
        ComponentInstance instance = mockComponentInstance(UUID.randomUUID(), "DefaultName", null);
        FactoryObjectProxy testObjProxy = mock(FactoryObjectProxy.class);
        UUID testUuid = UUID.randomUUID();

        // set up fake object factory
        when(m_FactoryDescriptor.create()).thenReturn(testObjProxy);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance);

        // replay
        FactoryObject obj = m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid);

        //expecting exception
        try
        {
            m_SUT.createConfiguration(testUuid, "fact_pid",(FactoryObjectInternal)obj);
            fail("Expecting Exception, config should throw IOexception.");
        }
        catch (FactoryException e)
        {
            //expecting exception
        }
    }
/**
     * Test exception if unable to create a configuration.
     */
Test exception if unable to create a configuration.
Test exception if unable to create a configuration .
@Test
    public void testCreateConfigurationIoException() throws IllegalArgumentException,
        FactoryException, FactoryObjectInformationException, IOException
    {
        doThrow(new IOException()).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());
        ComponentInstance instance = mockComponentInstance(UUID.randomUUID(), "DefaultName", null);
        FactoryObjectProxy testObjProxy = mock(FactoryObjectProxy.class);
        UUID testUuid = UUID.randomUUID();
        when(m_FactoryDescriptor.create()).thenReturn(testObjProxy);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance);
        FactoryObject obj = m_SUT.createOrRestoreObject(m_FactoryDescriptor, testUuid);
        try
        {
            m_SUT.createConfiguration(testUuid, "fact_pid",(FactoryObjectInternal)obj);
            fail("Expecting Exception, config should throw IOexception.");
        }
        catch (FactoryException e)
        {
        }
    }
@ Test public void testCreateConfigurationIoException ( ) throws IllegalArgumentException , FactoryException , FactoryObjectInformationException , IOException { doThrow ( new IOException ( ) ) . when ( m_ConfigAdmin ) . createFactoryConfiguration ( anyString ( ) , anyString ( ) ) ; ComponentInstance instance = mockComponentInstance ( UUID . randomUUID ( ) , "DefaultName" , null ) ; FactoryObjectProxy testObjProxy = mock ( FactoryObjectProxy . class ) ; UUID testUuid = UUID . randomUUID ( ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( testObjProxy ) ; when ( m_ServiceProxy . createFactoryObjectInternal ( m_FactoryDescriptor ) ) . thenReturn ( instance ) ; FactoryObject obj = m_SUT . createOrRestoreObject ( m_FactoryDescriptor , testUuid ) ; try { m_SUT . createConfiguration ( testUuid , "fact_pid" , ( FactoryObjectInternal ) obj ) ; fail ( "Expecting Exception, config should throw IOexception." ) ; } catch ( FactoryException e ) { } }
Test exception if unable to create a configuration.
Test exception if unable to create a configuration .
// mock config admin to be returned // mock a factory object // set up fake object factory // replay //expecting exception //expecting exception