mil.dod.th.ose.core/test/mil/dod/th/ose/core/factory/api/TestFactoryRegistry.java
@Test
    public void testRestoreAllObjects() throws IllegalArgumentException, FactoryException,
        FactoryObjectInformationException
    {
        //UUIDs for objects
        UUID testUuid = UUID.randomUUID();
        UUID testUuid2 = UUID.randomUUID();

        //mock behavior for creating object one and two
        when(m_FactoryDescriptor.getProductType()).thenReturn("product type");
        ComponentInstance instance = mockComponentInstance(testUuid);
        FactoryObjectProxy factoryObjectProxy = mock(FactoryObjectProxy.class);
        ComponentInstance instance2 = mockComponentInstance(testUuid2);
        FactoryObjectProxy factoryObjectProxy2 = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.create()).thenReturn(factoryObjectProxy, factoryObjectProxy2);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance, instance2);

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

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

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

        //get the created Object for inspection
        Set<FactoryObjectInternal> objects = m_SUT.getObjects();
        assertThat(objects.size(), is(2));

        Iterator<FactoryObjectInternal> objIterator = objects.iterator();
        FactoryObjectInternal objOne = objIterator.next();
        FactoryObjectInternal objTwo = objIterator.next();

        //verify objects have been created
        verify(m_FactoryService).postFactoryObjectEvent(eq(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED),
                eq(objOne));
        verify(m_FactoryService).postFactoryObjectEvent(eq(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED),
                eq(objTwo));

        //verify objects have been initialized with restore
        if (objOne.getUuid() == testUuid)
        {
            verify(objOne).initialize(eq(m_SUT),
                    eq(factoryObjectProxy),
                    eq(m_FactoryDescriptor), eq(m_ConfigAdmin),
                    eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
            verify(objTwo).initialize(eq(m_SUT),
                    eq(factoryObjectProxy2),
                    eq(m_FactoryDescriptor),
                    eq(m_ConfigAdmin), eq(m_EventAdmin), eq(m_PowerInternal), eq(testUuid2),
                    Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
        }
        else
        {
            verify(objOne).initialize(eq(m_SUT),
                    eq(factoryObjectProxy2),
                    eq(m_FactoryDescriptor), eq(m_ConfigAdmin),
                    eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid2), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
            verify(objTwo).initialize(eq(m_SUT),
                    eq(factoryObjectProxy),
                    eq(m_FactoryDescriptor),
                    eq(m_ConfigAdmin), eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid),
                    Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
        }

        //check UUIDs are the expected UUIDs from the persistent data mocked out above
        UUID objOneUuid = objOne.getUuid();
        UUID objTwoUuid = objTwo.getUuid();
        assertThat(objOneUuid, is(not(objTwoUuid)));
        assertThat(objOneUuid, isOneOf(testUuid, testUuid2));
        assertThat(objTwoUuid, isOneOf(testUuid, testUuid2));
    }
/**
     * Verify the ability to query the data manager for all factory objects for a given factory.
     */
Verify the ability to query the data manager for all factory objects for a given factory.
Verify the ability to query the data manager for all factory objects for a given factory .
@Test
    public void testRestoreAllObjects() throws IllegalArgumentException, FactoryException,
        FactoryObjectInformationException
    {
        UUID testUuid = UUID.randomUUID();
        UUID testUuid2 = UUID.randomUUID();
        when(m_FactoryDescriptor.getProductType()).thenReturn("product type");
        ComponentInstance instance = mockComponentInstance(testUuid);
        FactoryObjectProxy factoryObjectProxy = mock(FactoryObjectProxy.class);
        ComponentInstance instance2 = mockComponentInstance(testUuid2);
        FactoryObjectProxy factoryObjectProxy2 = mock(FactoryObjectProxy.class);
        when(m_FactoryDescriptor.create()).thenReturn(factoryObjectProxy, factoryObjectProxy2);
        when(m_ServiceProxy.createFactoryObjectInternal(m_FactoryDescriptor)).thenReturn(instance, instance2);
        PersistentData dataOne = mock(PersistentData.class);
        when(dataOne.getUUID()).thenReturn(testUuid);
        PersistentData dataTwo = mock(PersistentData.class);
        when(dataTwo.getUUID()).thenReturn(testUuid2);
        List<PersistentData> factDatas = new ArrayList<PersistentData>();
        factDatas.add(dataOne);
        factDatas.add(dataTwo);
        when(m_FactoryObjectDataManager.getAllObjectData(m_FactoryDescriptor)).thenReturn(factDatas);
        m_SUT.restoreAllObjects(m_FactoryDescriptor);
        Set<FactoryObjectInternal> objects = m_SUT.getObjects();
        assertThat(objects.size(), is(2));
        Iterator<FactoryObjectInternal> objIterator = objects.iterator();
        FactoryObjectInternal objOne = objIterator.next();
        FactoryObjectInternal objTwo = objIterator.next();
        verify(m_FactoryService).postFactoryObjectEvent(eq(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED),
                eq(objOne));
        verify(m_FactoryService).postFactoryObjectEvent(eq(FactoryDescriptor.TOPIC_FACTORY_OBJ_CREATED),
                eq(objTwo));
        if (objOne.getUuid() == testUuid)
        {
            verify(objOne).initialize(eq(m_SUT),
                    eq(factoryObjectProxy),
                    eq(m_FactoryDescriptor), eq(m_ConfigAdmin),
                    eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
            verify(objTwo).initialize(eq(m_SUT),
                    eq(factoryObjectProxy2),
                    eq(m_FactoryDescriptor),
                    eq(m_ConfigAdmin), eq(m_EventAdmin), eq(m_PowerInternal), eq(testUuid2),
                    Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
        }
        else
        {
            verify(objOne).initialize(eq(m_SUT),
                    eq(factoryObjectProxy2),
                    eq(m_FactoryDescriptor), eq(m_ConfigAdmin),
                    eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid2), Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
            verify(objTwo).initialize(eq(m_SUT),
                    eq(factoryObjectProxy),
                    eq(m_FactoryDescriptor),
                    eq(m_ConfigAdmin), eq(m_EventAdmin), eq(m_PowerInternal),
                    eq(testUuid),
                    Mockito.any(String.class), Mockito.any(String.class), Mockito.any(String.class));
        }
        UUID objOneUuid = objOne.getUuid();
        UUID objTwoUuid = objTwo.getUuid();
        assertThat(objOneUuid, is(not(objTwoUuid)));
        assertThat(objOneUuid, isOneOf(testUuid, testUuid2));
        assertThat(objTwoUuid, isOneOf(testUuid, testUuid2));
    }
@ Test public void testRestoreAllObjects ( ) throws IllegalArgumentException , FactoryException , FactoryObjectInformationException { UUID testUuid = UUID . randomUUID ( ) ; UUID testUuid2 = UUID . randomUUID ( ) ; when ( m_FactoryDescriptor . getProductType ( ) ) . thenReturn ( "product type" ) ; ComponentInstance instance = mockComponentInstance ( testUuid ) ; FactoryObjectProxy factoryObjectProxy = mock ( FactoryObjectProxy . class ) ; ComponentInstance instance2 = mockComponentInstance ( testUuid2 ) ; FactoryObjectProxy factoryObjectProxy2 = mock ( FactoryObjectProxy . class ) ; when ( m_FactoryDescriptor . create ( ) ) . thenReturn ( factoryObjectProxy , factoryObjectProxy2 ) ; when ( m_ServiceProxy . createFactoryObjectInternal ( m_FactoryDescriptor ) ) . thenReturn ( instance , instance2 ) ; PersistentData dataOne = mock ( PersistentData . class ) ; when ( dataOne . getUUID ( ) ) . thenReturn ( testUuid ) ; PersistentData dataTwo = mock ( PersistentData . class ) ; when ( dataTwo . getUUID ( ) ) . thenReturn ( testUuid2 ) ; List < PersistentData > factDatas = new ArrayList < PersistentData > ( ) ; factDatas . add ( dataOne ) ; factDatas . add ( dataTwo ) ; when ( m_FactoryObjectDataManager . getAllObjectData ( m_FactoryDescriptor ) ) . thenReturn ( factDatas ) ; m_SUT . restoreAllObjects ( m_FactoryDescriptor ) ; Set < FactoryObjectInternal > objects = m_SUT . getObjects ( ) ; assertThat ( objects . size ( ) , is ( 2 ) ) ; Iterator < FactoryObjectInternal > objIterator = objects . iterator ( ) ; FactoryObjectInternal objOne = objIterator . next ( ) ; FactoryObjectInternal objTwo = objIterator . next ( ) ; verify ( m_FactoryService ) . postFactoryObjectEvent ( eq ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED ) , eq ( objOne ) ) ; verify ( m_FactoryService ) . postFactoryObjectEvent ( eq ( FactoryDescriptor . TOPIC_FACTORY_OBJ_CREATED ) , eq ( objTwo ) ) ; if ( objOne . getUuid ( ) == testUuid ) { verify ( objOne ) . initialize ( eq ( m_SUT ) , eq ( factoryObjectProxy ) , eq ( m_FactoryDescriptor ) , eq ( m_ConfigAdmin ) , eq ( m_EventAdmin ) , eq ( m_PowerInternal ) , eq ( testUuid ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) ) ; verify ( objTwo ) . initialize ( eq ( m_SUT ) , eq ( factoryObjectProxy2 ) , eq ( m_FactoryDescriptor ) , eq ( m_ConfigAdmin ) , eq ( m_EventAdmin ) , eq ( m_PowerInternal ) , eq ( testUuid2 ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) ) ; } else { verify ( objOne ) . initialize ( eq ( m_SUT ) , eq ( factoryObjectProxy2 ) , eq ( m_FactoryDescriptor ) , eq ( m_ConfigAdmin ) , eq ( m_EventAdmin ) , eq ( m_PowerInternal ) , eq ( testUuid2 ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) ) ; verify ( objTwo ) . initialize ( eq ( m_SUT ) , eq ( factoryObjectProxy ) , eq ( m_FactoryDescriptor ) , eq ( m_ConfigAdmin ) , eq ( m_EventAdmin ) , eq ( m_PowerInternal ) , eq ( testUuid ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) , Mockito . any ( String . class ) ) ; } UUID objOneUuid = objOne . getUuid ( ) ; UUID objTwoUuid = objTwo . getUuid ( ) ; assertThat ( objOneUuid , is ( not ( objTwoUuid ) ) ) ; assertThat ( objOneUuid , isOneOf ( testUuid , testUuid2 ) ) ; assertThat ( objTwoUuid , isOneOf ( testUuid , testUuid2 ) ) ; }
Verify the ability to query the data manager for all factory objects for a given factory.
Verify the ability to query the data manager for all factory objects for a given factory .
//UUIDs for objects //mock behavior for creating object one and two //data manager behavior //collection of data to return //restore the objects //get the created Object for inspection //verify objects have been created //verify objects have been initialized with restore //check UUIDs are the expected UUIDs from the persistent data mocked out above