mil.dod.th.ose.core/test/mil/dod/th/ose/core/ConfigurationAdminMocker.java
@SuppressWarnings({"rawtypes", "unchecked"})
    private static Configuration createMockConfiguration(final String factoryPid, final String pid) throws IOException,
            ConfigurationException
    {
        Preconditions.checkNotNull(factoryPid);
        Preconditions.checkNotNull(pid);
        
        //configuration to return
        Configuration config = mock(Configuration.class);

        //store the mock config with the associated PID
        m_Configs.put(pid, config);

        //mock config behavior
        when(config.getFactoryPid()).thenReturn(factoryPid);
        when(config.getPid()).thenReturn(pid);

        //the pid is not known, then add the properties to the property map... mapped by PID
        if (m_Properties.get(pid) == null)
        {
            final Dictionary<String, Object> properties = new Hashtable<String, Object>();
            m_Properties.put(pid, properties);
        }
        else
        {
            // This configuration is being restored, so notify the ManagedServiceFactory
            ManagedServiceFactory msf = m_MSF.get(factoryPid);
            if (msf != null)
            {
                try
                {
                    //update the configuration map with the properties from the prop map
                    msf.updated(pid, m_Properties.get(pid));
                }
                catch (final ConfigurationException e)
                {
                    e.printStackTrace();
                }
            }
        }

        //configuration mocking behavior, when getProps is called return the most up to date properties from the
        // map of properties... the props are stored by PID
        when(config.getProperties()).thenAnswer(new Answer<Dictionary>()
        {
            @Override
            public Dictionary answer(InvocationOnMock invocation) throws Throwable
            {

                return m_Properties.get(pid);
            }
        });

        //when update is called capture the new properties, and store them in the property map, then call update 
        //from the factory service
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                Dictionary newProps = (Dictionary)invocation.getArguments()[0];

                m_Properties.put(pid, newProps);

                ManagedServiceFactory msf = m_MSF.get(factoryPid);
                if (msf != null)
                {
                    try
                    {
                        msf.updated(pid, newProps);
                    }
                    catch (ConfigurationException e)
                    {
                        e.printStackTrace();
                    }
                }
                return null;
            }
        }).when(config).update(Mockito.any(Dictionary.class));

        //delete properties and mock config from maps, then call factory service delete
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                m_Configs.remove(pid);
                m_Properties.remove(pid);

                ManagedServiceFactory msf = m_MSF.get(factoryPid);
                if (msf != null)
                {
                    msf.deleted(pid);
                }

                return null;
            }
        }).when(config).delete();

        return config;
    }
/**
     * Create a configuration
     * @param factoryPid
     *      the PID of the factory to which the configuration belongs
     * @param pid
     *      the PID to assign to the configuration
     * @return
     *      created configuration
     */
Create a configuration
@param factoryPid
the PID of the factory to which the configuration belongs
@param pid
the PID to assign to the configuration
@return
created configuration
Create a configuration @param factoryPid the PID of the factory to which the configuration belongs @param pid the PID to assign to the configuration @return created configuration
@SuppressWarnings({"rawtypes", "unchecked"})
    private static Configuration createMockConfiguration(final String factoryPid, final String pid) throws IOException,
            ConfigurationException
    {
        Preconditions.checkNotNull(factoryPid);
        Preconditions.checkNotNull(pid);
        Configuration config = mock(Configuration.class);
        m_Configs.put(pid, config);
        when(config.getFactoryPid()).thenReturn(factoryPid);
        when(config.getPid()).thenReturn(pid);
        if (m_Properties.get(pid) == null)
        {
            final Dictionary<String, Object> properties = new Hashtable<String, Object>();
            m_Properties.put(pid, properties);
        }
        else
        {
            ManagedServiceFactory msf = m_MSF.get(factoryPid);
            if (msf != null)
            {
                try
                {
                    msf.updated(pid, m_Properties.get(pid));
                }
                catch (final ConfigurationException e)
                {
                    e.printStackTrace();
                }
            }
        }
        when(config.getProperties()).thenAnswer(new Answer<Dictionary>()
        {
            @Override
            public Dictionary answer(InvocationOnMock invocation) throws Throwable
            {
                return m_Properties.get(pid);
            }
        });
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                Dictionary newProps = (Dictionary)invocation.getArguments()[0];
                m_Properties.put(pid, newProps);
                ManagedServiceFactory msf = m_MSF.get(factoryPid);
                if (msf != null)
                {
                    try
                    {
                        msf.updated(pid, newProps);
                    }
                    catch (ConfigurationException e)
                    {
                        e.printStackTrace();
                    }
                }
                return null;
            }
        }).when(config).update(Mockito.any(Dictionary.class));
        doAnswer(new Answer<Object>()
        {
            @Override
            public Object answer(final InvocationOnMock invocation) throws Throwable
            {
                m_Configs.remove(pid);
                m_Properties.remove(pid);
                ManagedServiceFactory msf = m_MSF.get(factoryPid);
                if (msf != null)
                {
                    msf.deleted(pid);
                }
                return null;
            }
        }).when(config).delete();
        return config;
    }
@ SuppressWarnings ( { "rawtypes" , "unchecked" } ) private static Configuration createMockConfiguration ( final String factoryPid , final String pid ) throws IOException , ConfigurationException { Preconditions . checkNotNull ( factoryPid ) ; Preconditions . checkNotNull ( pid ) ; Configuration config = mock ( Configuration . class ) ; m_Configs . put ( pid , config ) ; when ( config . getFactoryPid ( ) ) . thenReturn ( factoryPid ) ; when ( config . getPid ( ) ) . thenReturn ( pid ) ; if ( m_Properties . get ( pid ) == null ) { final Dictionary < String , Object > properties = new Hashtable < String , Object > ( ) ; m_Properties . put ( pid , properties ) ; } else { ManagedServiceFactory msf = m_MSF . get ( factoryPid ) ; if ( msf != null ) { try { msf . updated ( pid , m_Properties . get ( pid ) ) ; } catch ( final ConfigurationException e ) { e . printStackTrace ( ) ; } } } when ( config . getProperties ( ) ) . thenAnswer ( new Answer < Dictionary > ( ) { @ Override public Dictionary answer ( InvocationOnMock invocation ) throws Throwable { return m_Properties . get ( pid ) ; } } ) ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( final InvocationOnMock invocation ) throws Throwable { Dictionary newProps = ( Dictionary ) invocation . getArguments ( ) [ 0 ] ; m_Properties . put ( pid , newProps ) ; ManagedServiceFactory msf = m_MSF . get ( factoryPid ) ; if ( msf != null ) { try { msf . updated ( pid , newProps ) ; } catch ( ConfigurationException e ) { e . printStackTrace ( ) ; } } return null ; } } ) . when ( config ) . update ( Mockito . any ( Dictionary . class ) ) ; doAnswer ( new Answer < Object > ( ) { @ Override public Object answer ( final InvocationOnMock invocation ) throws Throwable { m_Configs . remove ( pid ) ; m_Properties . remove ( pid ) ; ManagedServiceFactory msf = m_MSF . get ( factoryPid ) ; if ( msf != null ) { msf . deleted ( pid ) ; } return null ; } } ) . when ( config ) . delete ( ) ; return config ; }
Create a configuration
 @param factoryPid
      the PID of the factory to which the configuration belongs
 @param pid
      the PID to assign to the configuration
 @return
      created configuration
Create a configuration @param factoryPid the PID of the factory to which the configuration belongs @param pid the PID to assign to the configuration @return created configuration
//configuration to return //store the mock config with the associated PID //mock config behavior //the pid is not known, then add the properties to the property map... mapped by PID // This configuration is being restored, so notify the ManagedServiceFactory //update the configuration map with the properties from the prop map //configuration mocking behavior, when getProps is called return the most up to date properties from the // map of properties... the props are stored by PID //when update is called capture the new properties, and store them in the property map, then call update  //from the factory service //delete properties and mock config from maps, then call factory service delete