mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testRestoreAllObjects_MissingDepProperty() throws Exception
    {
        //mock behavior for creating object
        FactoryObjectInternal factoryObject = stubFactoryObject(m_FactoryDescriptor, "product-type", 1).get(0);
        FactoryObjectProxy factoryObjectProxy = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.create()).thenReturn(factoryObjectProxy);
        UUID uuid = factoryObject.getUuid();

        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});
        Dictionary<String, Object> props = new Hashtable<>();
        when(config.getProperties()).thenReturn(props);

        //data manager behavior
        PersistentData dataOne = mock(PersistentData.class);
        when(dataOne.getUUID()).thenReturn(uuid);
        //collection of data to return
        List<PersistentData> factDatas = new ArrayList<PersistentData>();
        factDatas.add(dataOne);

        when(m_FactoryObjectDataManager.getAllObjectData(m_FactoryDescriptor)).thenReturn(factDatas);

        RegistryDependency dep = mock(RegistryDependency.class);
        when(dep.getObjectNameProperty()).thenReturn("some-prop");
        when(dep.isRequired()).thenReturn(true);

        when(m_Callback.retrieveRegistryDependencies()).thenReturn(Lists.newArrayList(dep));
        m_SUT.initialize(m_FactoryService, m_ServiceProxy, m_Callback);

        //restore the objects
        m_SUT.restoreAllObjects(m_FactoryDescriptor);

        // verify object not in registry
        assertThat(m_SUT.getObjects(), not(hasItem(factoryObject)));

        // make sure data manager and configuration is cleaned up
        verify(m_FactoryObjectDataManager).tryRemove(uuid);
        verify(config).delete();
    }
/**
     * Verify restored objects that have a missing dependency property are removed from config admin and data manager
     * as they will never be satisfied.
     */
Verify restored objects that have a missing dependency property are removed from config admin and data manager
as they will never be satisfied.
Verify restored objects that have a missing dependency property are removed from config admin and data manager as they will never be satisfied .
@Test
    public void testRestoreAllObjects_MissingDepProperty() throws Exception
    {
        FactoryObjectInternal factoryObject = stubFactoryObject(m_FactoryDescriptor, "product-type", 1).get(0);
        FactoryObjectProxy factoryObjectProxy = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.create()).thenReturn(factoryObjectProxy);
        UUID uuid = factoryObject.getUuid();
        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});
        Dictionary<String, Object> props = new Hashtable<>();
        when(config.getProperties()).thenReturn(props);
        PersistentData dataOne = mock(PersistentData.class);
        when(dataOne.getUUID()).thenReturn(uuid);
        List<PersistentData> factDatas = new ArrayList<PersistentData>();
        factDatas.add(dataOne);
        when(m_FactoryObjectDataManager.getAllObjectData(m_FactoryDescriptor)).thenReturn(factDatas);
        RegistryDependency dep = mock(RegistryDependency.class);
        when(dep.getObjectNameProperty()).thenReturn("some-prop");
        when(dep.isRequired()).thenReturn(true);
        when(m_Callback.retrieveRegistryDependencies()).thenReturn(Lists.newArrayList(dep));
        m_SUT.initialize(m_FactoryService, m_ServiceProxy, m_Callback);
        m_SUT.restoreAllObjects(m_FactoryDescriptor);
        assertThat(m_SUT.getObjects(), not(hasItem(factoryObject)));
        verify(m_FactoryObjectDataManager).tryRemove(uuid);
        verify(config).delete();
    }
@ Test public void testRestoreAllObjects_MissingDepProperty ( ) throws Exception { FactoryObjectInternal factoryObject = stubFactoryObject ( m_FactoryDescriptor , "product-type" , 1 ) . get ( 0 ) ; FactoryObjectProxy factoryObjectProxy = mock ( FactoryObjectProxy . class ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( factoryObjectProxy ) ; UUID uuid = factoryObject . getUuid ( ) ; 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 } ) ; Dictionary < String , Object > props = new Hashtable < > ( ) ; when ( config . getProperties ( ) ) . thenReturn ( props ) ; PersistentData dataOne = mock ( PersistentData . class ) ; when ( dataOne . getUUID ( ) ) . thenReturn ( uuid ) ; List < PersistentData > factDatas = new ArrayList < PersistentData > ( ) ; factDatas . add ( dataOne ) ; when ( m_FactoryObjectDataManager . getAllObjectData ( m_FactoryDescriptor ) ) . thenReturn ( factDatas ) ; RegistryDependency dep = mock ( RegistryDependency . class ) ; when ( dep . getObjectNameProperty ( ) ) . thenReturn ( "some-prop" ) ; when ( dep . isRequired ( ) ) . thenReturn ( true ) ; when ( m_Callback . retrieveRegistryDependencies ( ) ) . thenReturn ( Lists . newArrayList ( dep ) ) ; m_SUT . initialize ( m_FactoryService , m_ServiceProxy , m_Callback ) ; m_SUT . restoreAllObjects ( m_FactoryDescriptor ) ; assertThat ( m_SUT . getObjects ( ) , not ( hasItem ( factoryObject ) ) ) ; verify ( m_FactoryObjectDataManager ) . tryRemove ( uuid ) ; verify ( config ) . delete ( ) ; }
Verify restored objects that have a missing dependency property are removed from config admin and data manager
 as they will never be satisfied.
Verify restored objects that have a missing dependency property are removed from config admin and data manager as they will never be satisfied .
//mock behavior for creating object //data manager behavior //collection of data to return //restore the objects // verify object not in registry // make sure data manager and configuration is cleaned up