mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testCreateNewObjectForConfigSetPidException() throws IllegalArgumentException,
        FactoryObjectInformationException, IOException, InvalidSyntaxException
    {
        // mock
        ComponentInstance instance = mockComponentInstance(UUID.randomUUID(), "name", null);
        FactoryObjectProxy proxy = mock(FactoryObjectProxy.class);
        Configuration config = mock(Configuration.class);

        String filter = String.format("(%s=%s)", Constants.SERVICE_PID, "config.pid");

        when(m_FactoryDescriptor.create()).thenReturn(proxy);
        when(m_FactoryDescriptor.getPid()).thenReturn("some.pid");
        when(m_FactoryDescriptor.getProductType()).thenReturn("some.super.AwesomeProduct");
        doThrow(Exception.class).when(m_FactoryObjectDataManager).setPid(Mockito.any(UUID.class), eq("config.pid"));
        when(m_FactoryObjectDataManager.getPid(Mockito.any(UUID.class))).thenReturn(null);
        when(m_FactoryObjectDataManager.getName(Mockito.any(UUID.class))).thenReturn("name");
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance);
        when(config.getPid()).thenReturn("config.pid");
        when(m_ConfigAdmin.listConfigurations(filter)).thenReturn(new Configuration[]{config});

        // replay
        try
        {
            m_SUT.createNewObjectForConfig(m_FactoryDescriptor, "", "config.pid");
            fail("Expecting exception when the factory object data manager tries to set the PID for the created "
                    + "object.");
        }
        catch (final Exception ex)
        {
            //expected exception
        }

        // verify
        verify(m_FactoryObjectDataManager).persistNewObjectData(Mockito.any(UUID.class),
                eq(m_FactoryDescriptor), eq("AwesomeProduct"));

        verify(m_FactoryObjectDataManager).setPid(Mockito.any(UUID.class), eq("config.pid"));
        verify(m_ConfigAdmin).listConfigurations(filter);
        verify(m_ConfigAdmin, never()).createFactoryConfiguration("some.pid", null);
        verify(m_FactoryObjectDataManager).tryRemove(Mockito.any(UUID.class));
    }
/**
     * Verify that there is an attempt to remove the factory object if an exception occurs when setting the PID or
     * creating/restoring the object.
     */
Verify that there is an attempt to remove the factory object if an exception occurs when setting the PID or
creating/restoring the object.
Verify that there is an attempt to remove the factory object if an exception occurs when setting the PID or creating / restoring the object .
@Test
    public void testCreateNewObjectForConfigSetPidException() throws IllegalArgumentException,
        FactoryObjectInformationException, IOException, InvalidSyntaxException
    {
        ComponentInstance instance = mockComponentInstance(UUID.randomUUID(), "name", null);
        FactoryObjectProxy proxy = mock(FactoryObjectProxy.class);
        Configuration config = mock(Configuration.class);
        String filter = String.format("(%s=%s)", Constants.SERVICE_PID, "config.pid");
        when(m_FactoryDescriptor.create()).thenReturn(proxy);
        when(m_FactoryDescriptor.getPid()).thenReturn("some.pid");
        when(m_FactoryDescriptor.getProductType()).thenReturn("some.super.AwesomeProduct");
        doThrow(Exception.class).when(m_FactoryObjectDataManager).setPid(Mockito.any(UUID.class), eq("config.pid"));
        when(m_FactoryObjectDataManager.getPid(Mockito.any(UUID.class))).thenReturn(null);
        when(m_FactoryObjectDataManager.getName(Mockito.any(UUID.class))).thenReturn("name");
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance);
        when(config.getPid()).thenReturn("config.pid");
        when(m_ConfigAdmin.listConfigurations(filter)).thenReturn(new Configuration[]{config});
        try
        {
            m_SUT.createNewObjectForConfig(m_FactoryDescriptor, "", "config.pid");
            fail("Expecting exception when the factory object data manager tries to set the PID for the created "
                    + "object.");
        }
        catch (final Exception ex)
        {
        }
        verify(m_FactoryObjectDataManager).persistNewObjectData(Mockito.any(UUID.class),
                eq(m_FactoryDescriptor), eq("AwesomeProduct"));
        verify(m_FactoryObjectDataManager).setPid(Mockito.any(UUID.class), eq("config.pid"));
        verify(m_ConfigAdmin).listConfigurations(filter);
        verify(m_ConfigAdmin, never()).createFactoryConfiguration("some.pid", null);
        verify(m_FactoryObjectDataManager).tryRemove(Mockito.any(UUID.class));
    }
@ Test public void testCreateNewObjectForConfigSetPidException ( ) throws IllegalArgumentException , FactoryObjectInformationException , IOException , InvalidSyntaxException { ComponentInstance instance = mockComponentInstance ( UUID . randomUUID ( ) , "name" , null ) ; FactoryObjectProxy proxy = mock ( FactoryObjectProxy . class ) ; Configuration config = mock ( Configuration . class ) ; String filter = String . format ( "(%s=%s)" , Constants . SERVICE_PID , "config.pid" ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( proxy ) ; when ( m_FactoryDescriptor . getPid ( ) ) . thenReturn ( "some.pid" ) ; when ( m_FactoryDescriptor . getProductType ( ) ) . thenReturn ( "some.super.AwesomeProduct" ) ; doThrow ( Exception . class ) . when ( m_FactoryObjectDataManager ) . setPid ( Mockito . any ( UUID . class ) , eq ( "config.pid" ) ) ; when ( m_FactoryObjectDataManager . getPid ( Mockito . any ( UUID . class ) ) ) . thenReturn ( null ) ; when ( m_FactoryObjectDataManager . getName ( Mockito . any ( UUID . class ) ) ) . thenReturn ( "name" ) ; when ( m_ServiceProxy . createFactoryObjectInternal ( m_FactoryDescriptor ) ) . thenReturn ( instance ) ; when ( config . getPid ( ) ) . thenReturn ( "config.pid" ) ; when ( m_ConfigAdmin . listConfigurations ( filter ) ) . thenReturn ( new Configuration [ ] { config } ) ; try { m_SUT . createNewObjectForConfig ( m_FactoryDescriptor , "" , "config.pid" ) ; fail ( "Expecting exception when the factory object data manager tries to set the PID for the created " + "object." ) ; } catch ( final Exception ex ) { } verify ( m_FactoryObjectDataManager ) . persistNewObjectData ( Mockito . any ( UUID . class ) , eq ( m_FactoryDescriptor ) , eq ( "AwesomeProduct" ) ) ; verify ( m_FactoryObjectDataManager ) . setPid ( Mockito . any ( UUID . class ) , eq ( "config.pid" ) ) ; verify ( m_ConfigAdmin ) . listConfigurations ( filter ) ; verify ( m_ConfigAdmin , never ( ) ) . createFactoryConfiguration ( "some.pid" , null ) ; verify ( m_FactoryObjectDataManager ) . tryRemove ( Mockito . any ( UUID . class ) ) ; }
Verify that there is an attempt to remove the factory object if an exception occurs when setting the PID or
 creating/restoring the object.
Verify that there is an attempt to remove the factory object if an exception occurs when setting the PID or creating / restoring the object .
// mock // replay //expected exception // verify