mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testCreateNewObject_MissingDepProperty() throws Exception
    {
        Configuration config = mock(Configuration.class);
        doReturn(config).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());
        when(m_FactoryObjectDataManager.getPid(Mockito.any(UUID.class))).thenReturn("some-pid");
        when(m_ConfigAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] {config});

        // make exception occur after configuration and data manager objects have been created
        when(m_FactoryObjectDataManager.getName(Mockito.any(UUID.class))).thenThrow(new IllegalStateException());

        Map<String, Object> props = new HashMap<>();
        props.put("some-props", "some-value");
        try
        {
            m_SUT.createNewObject(m_FactoryDescriptor, "blah", props);
            fail("Expecting exception as inner call is mocked to throw exception");
        }
        catch (IllegalStateException e)
        {

        }

        ArgumentCaptor<UUID> uuidCapture = ArgumentCaptor.forClass(UUID.class);
        verify(m_FactoryObjectDataManager).persistNewObjectData(uuidCapture.capture(), eq(m_FactoryDescriptor),
                eq("blah"));

        // make sure persisted data is removed since creation failed
        verify(m_FactoryObjectDataManager).tryRemove(uuidCapture.getValue());
        verify(config).delete();
    }
/**
     * Verify if there is an exception while creating object, the factory object data and configuration are cleaned up.
     */
Verify if there is an exception while creating object, the factory object data and configuration are cleaned up.
Verify if there is an exception while creating object the factory object data and configuration are cleaned up .
@Test
    public void testCreateNewObject_MissingDepProperty() throws Exception
    {
        Configuration config = mock(Configuration.class);
        doReturn(config).when(m_ConfigAdmin).createFactoryConfiguration(anyString(), anyString());
        when(m_FactoryObjectDataManager.getPid(Mockito.any(UUID.class))).thenReturn("some-pid");
        when(m_ConfigAdmin.listConfigurations(anyString())).thenReturn(new Configuration[] {config});
        when(m_FactoryObjectDataManager.getName(Mockito.any(UUID.class))).thenThrow(new IllegalStateException());
        Map<String, Object> props = new HashMap<>();
        props.put("some-props", "some-value");
        try
        {
            m_SUT.createNewObject(m_FactoryDescriptor, "blah", props);
            fail("Expecting exception as inner call is mocked to throw exception");
        }
        catch (IllegalStateException e)
        {
        }
        ArgumentCaptor<UUID> uuidCapture = ArgumentCaptor.forClass(UUID.class);
        verify(m_FactoryObjectDataManager).persistNewObjectData(uuidCapture.capture(), eq(m_FactoryDescriptor),
                eq("blah"));
        verify(m_FactoryObjectDataManager).tryRemove(uuidCapture.getValue());
        verify(config).delete();
    }
@ Test public void testCreateNewObject_MissingDepProperty ( ) throws Exception { Configuration config = mock ( Configuration . class ) ; doReturn ( config ) . when ( m_ConfigAdmin ) . createFactoryConfiguration ( anyString ( ) , anyString ( ) ) ; when ( m_FactoryObjectDataManager . getPid ( Mockito . any ( UUID . class ) ) ) . thenReturn ( "some-pid" ) ; when ( m_ConfigAdmin . listConfigurations ( anyString ( ) ) ) . thenReturn ( new Configuration [ ] { config } ) ; when ( m_FactoryObjectDataManager . getName ( Mockito . any ( UUID . class ) ) ) . thenThrow ( new IllegalStateException ( ) ) ; Map < String , Object > props = new HashMap < > ( ) ; props . put ( "some-props" , "some-value" ) ; try { m_SUT . createNewObject ( m_FactoryDescriptor , "blah" , props ) ; fail ( "Expecting exception as inner call is mocked to throw exception" ) ; } catch ( IllegalStateException e ) { } ArgumentCaptor < UUID > uuidCapture = ArgumentCaptor . forClass ( UUID . class ) ; verify ( m_FactoryObjectDataManager ) . persistNewObjectData ( uuidCapture . capture ( ) , eq ( m_FactoryDescriptor ) , eq ( "blah" ) ) ; verify ( m_FactoryObjectDataManager ) . tryRemove ( uuidCapture . getValue ( ) ) ; verify ( config ) . delete ( ) ; }
Verify if there is an exception while creating object, the factory object data and configuration are cleaned up.
Verify if there is an exception while creating object the factory object data and configuration are cleaned up .
// make exception occur after configuration and data manager objects have been created // make sure persisted data is removed since creation failed