mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@SuppressWarnings("unchecked")
    @Test
    public void testUpdateConfigurationIoException() throws IllegalArgumentException,
        FactoryException, FactoryObjectInformationException, IOException
    {
        Configuration config = mock(Configuration.class);
        // mock config admin to be returned
        doReturn(config).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());

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

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

        //mock exception when updating the configuration
        doThrow(new IOException("Error")).when(config).update(Mockito.any(Dictionary.class));

        //dictionary of props that will trigger a configuration to be made
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("someKey", "we like the values");

        // create object
        try
        {
            m_SUT.createNewObject(m_FactoryDescriptor, "someName", props);
            fail("Expected Exception when updating the created configuration");
        }
        catch (FactoryException e)
        {
            //expected exception
        }
    }
/**
     * Test exception if unable to update a configuration.
     */
Test exception if unable to update a configuration.
Test exception if unable to update a configuration .
@SuppressWarnings("unchecked")
    @Test
    public void testUpdateConfigurationIoException() throws IllegalArgumentException,
        FactoryException, FactoryObjectInformationException, IOException
    {
        Configuration config = mock(Configuration.class);
        doReturn(config).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());
        ComponentInstance instance = mockComponentInstance(UUID.randomUUID(), "DefaultName", null);
        FactoryObjectProxy testObjProxy = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.getProductType()).thenReturn("product type");
        when(m_FactoryDescriptor.create()).thenReturn(testObjProxy);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance);
        doThrow(new IOException("Error")).when(config).update(Mockito.any(Dictionary.class));
        Map<String, Object> props = new HashMap<String, Object>();
        props.put("someKey", "we like the values");
        try
        {
            m_SUT.createNewObject(m_FactoryDescriptor, "someName", props);
            fail("Expected Exception when updating the created configuration");
        }
        catch (FactoryException e)
        {
        }
    }
@ SuppressWarnings ( "unchecked" ) @ Test public void testUpdateConfigurationIoException ( ) throws IllegalArgumentException , FactoryException , FactoryObjectInformationException , IOException { Configuration config = mock ( Configuration . class ) ; doReturn ( config ) . when ( m_ConfigAdmin ) . createFactoryConfiguration ( anyString ( ) , anyString ( ) ) ; ComponentInstance instance = mockComponentInstance ( UUID . randomUUID ( ) , "DefaultName" , null ) ; FactoryObjectProxy testObjProxy = mock ( FactoryObjectProxy . class ) ; when ( m_FactoryDescriptor . getProductType ( ) ) . thenReturn ( "product type" ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( testObjProxy ) ; when ( m_ServiceProxy . createFactoryObjectInternal ( m_FactoryDescriptor ) ) . thenReturn ( instance ) ; doThrow ( new IOException ( "Error" ) ) . when ( config ) . update ( Mockito . any ( Dictionary . class ) ) ; Map < String , Object > props = new HashMap < String , Object > ( ) ; props . put ( "someKey" , "we like the values" ) ; try { m_SUT . createNewObject ( m_FactoryDescriptor , "someName" , props ) ; fail ( "Expected Exception when updating the created configuration" ) ; } catch ( FactoryException e ) { } }
Test exception if unable to update a configuration.
Test exception if unable to update a configuration .
// mock config admin to be returned // mock a factory object // set up fake object factory //mock exception when updating the configuration //dictionary of props that will trigger a configuration to be made // create object //expected exception