mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestMissionProgramManagerImpl.java
@Test
    public void testAddProgram() 
        throws IllegalArgumentException, PersistenceFailedException, MissionProgramException
    {
        // mock
        setScriptEngineAndActivate();
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(0));
        
        // replay        
        MissionProgramTemplate program = new MissionProgramTemplate().withName("blah").withSource("test");
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(false).
            withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withParameters().withTemplateName("blah").
            withSchedule(schedule).withProgramName("heyssdf");
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);
        doReturn(program).when(m_TemplateManager).getTemplate("blah");
        
        // verify each call once
        Program program1 = m_SUT.loadParameters(params);
        verify(m_PersistentDataStore).persist(eq(MissionProgramManagerImpl.class), (UUID)Mockito.any(),
                eq("blah"), (Serializable)Mockito.any());
        
        // verify
        assertThat(program1, is(notNullValue()));
        assertThat(program1.getTemplateName(), is("blah"));
        assertThat(program1.getSource(), is("test"));
        assertThat(program1.getProgramName(), is("heyssdf"));
        
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(1));        
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("blah"));
        
        // mock
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);

        // replay
        params = new MissionProgramParameters().withParameters().withTemplateName("hello").withSchedule(schedule).
                withProgramName("hey");
        schedule = new MissionProgramSchedule().withImmediately(false).
                withIndefiniteInterval(false);
        MissionProgramTemplate missionProgram = new MissionProgramTemplate().withName("hello").withSource("test");
        //add the name to the mocked list of templates.
        templateNames.add("hello");
        doReturn(missionProgram).when(m_TemplateManager).getTemplate("hello");
        
        ArgumentCaptor<Event> eventCap = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(3)).postEvent(eventCap.capture());
        
        assertThat((String)eventCap.getValue().getProperty(Program.EVENT_PROP_PROGRAM_NAME), is("heyssdf"));
                
        m_SUT.loadParameters(params);
        // verify that the new program was persisted, in addition to the other.
        verify(m_PersistentDataStore, times(1)).persist(eq(MissionProgramManagerImpl.class), (UUID)Mockito.any(),
                eq("hello"), (Serializable)Mockito.any());
        
        //check that the programs are in the set of programs managed.
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("blah"));
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("hello"));
        
        //check that there are ONLY two programs present.
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(2));
    }
/**
     * Verify program can be added.
     */
Verify program can be added.
Verify program can be added .
@Test
    public void testAddProgram() 
        throws IllegalArgumentException, PersistenceFailedException, MissionProgramException
    {
        setScriptEngineAndActivate();
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(0));
        MissionProgramTemplate program = new MissionProgramTemplate().withName("blah").withSource("test");
        MissionProgramSchedule schedule = new MissionProgramSchedule().withImmediately(false).
            withIndefiniteInterval(false).withActive(true);
        MissionProgramParameters params = new MissionProgramParameters().withParameters().withTemplateName("blah").
            withSchedule(schedule).withProgramName("heyssdf");
        Set<String> templateNames = new HashSet<String>();
        templateNames.add("blah");
        when(m_TemplateManager.getMissionTemplateNames()).thenReturn(templateNames);
        doReturn(program).when(m_TemplateManager).getTemplate("blah");
        Program program1 = m_SUT.loadParameters(params);
        verify(m_PersistentDataStore).persist(eq(MissionProgramManagerImpl.class), (UUID)Mockito.any(),
                eq("blah"), (Serializable)Mockito.any());
        assertThat(program1, is(notNullValue()));
        assertThat(program1.getTemplateName(), is("blah"));
        assertThat(program1.getSource(), is("test"));
        assertThat(program1.getProgramName(), is("heyssdf"));
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(1));        
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("blah"));
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);
        params = new MissionProgramParameters().withParameters().withTemplateName("hello").withSchedule(schedule).
                withProgramName("hey");
        schedule = new MissionProgramSchedule().withImmediately(false).
                withIndefiniteInterval(false);
        MissionProgramTemplate missionProgram = new MissionProgramTemplate().withName("hello").withSource("test");
        templateNames.add("hello");
        doReturn(missionProgram).when(m_TemplateManager).getTemplate("hello");
        ArgumentCaptor<Event> eventCap = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(3)).postEvent(eventCap.capture());
        assertThat((String)eventCap.getValue().getProperty(Program.EVENT_PROP_PROGRAM_NAME), is("heyssdf"));
        m_SUT.loadParameters(params);
         that the new program was persisted, in addition to the other.
        verify(m_PersistentDataStore, times(1)).persist(eq(MissionProgramManagerImpl.class), (UUID)Mockito.any(),
                eq("hello"), (Serializable)Mockito.any());
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("blah"));
        assertThat(m_SUT.getActiveProgramTemplateNames(), hasItem("hello"));
        assertThat(m_SUT.getActiveProgramTemplateNames().size(), is(2));
    }
@ Test public void testAddProgram ( ) throws IllegalArgumentException , PersistenceFailedException , MissionProgramException { setScriptEngineAndActivate ( ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) . size ( ) , is ( 0 ) ) ; MissionProgramTemplate program = new MissionProgramTemplate ( ) . withName ( "blah" ) . withSource ( "test" ) ; MissionProgramSchedule schedule = new MissionProgramSchedule ( ) . withImmediately ( false ) . withIndefiniteInterval ( false ) . withActive ( true ) ; MissionProgramParameters params = new MissionProgramParameters ( ) . withParameters ( ) . withTemplateName ( "blah" ) . withSchedule ( schedule ) . withProgramName ( "heyssdf" ) ; Set < String > templateNames = new HashSet < String > ( ) ; templateNames . add ( "blah" ) ; when ( m_TemplateManager . getMissionTemplateNames ( ) ) . thenReturn ( templateNames ) ; doReturn ( program ) . when ( m_TemplateManager ) . getTemplate ( "blah" ) ; Program program1 = m_SUT . loadParameters ( params ) ; verify ( m_PersistentDataStore ) . persist ( eq ( MissionProgramManagerImpl . class ) , ( UUID ) Mockito . any ( ) , eq ( "blah" ) , ( Serializable ) Mockito . any ( ) ) ; assertThat ( program1 , is ( notNullValue ( ) ) ) ; assertThat ( program1 . getTemplateName ( ) , is ( "blah" ) ) ; assertThat ( program1 . getSource ( ) , is ( "test" ) ) ; assertThat ( program1 . getProgramName ( ) , is ( "heyssdf" ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) . size ( ) , is ( 1 ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) , hasItem ( "blah" ) ) ; PersistentData foundData = mock ( PersistentData . class ) ; when ( m_PersistentDataStore . find ( ( UUID ) Mockito . any ( ) ) ) . thenReturn ( foundData ) ; params = new MissionProgramParameters ( ) . withParameters ( ) . withTemplateName ( "hello" ) . withSchedule ( schedule ) . withProgramName ( "hey" ) ; schedule = new MissionProgramSchedule ( ) . withImmediately ( false ) . withIndefiniteInterval ( false ) ; MissionProgramTemplate missionProgram = new MissionProgramTemplate ( ) . withName ( "hello" ) . withSource ( "test" ) ; templateNames . add ( "hello" ) ; doReturn ( missionProgram ) . when ( m_TemplateManager ) . getTemplate ( "hello" ) ; ArgumentCaptor < Event > eventCap = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 3 ) ) . postEvent ( eventCap . capture ( ) ) ; assertThat ( ( String ) eventCap . getValue ( ) . getProperty ( Program . EVENT_PROP_PROGRAM_NAME ) , is ( "heyssdf" ) ) ; m_SUT . loadParameters ( params ) ; verify ( m_PersistentDataStore , times ( 1 ) ) . persist ( eq ( MissionProgramManagerImpl . class ) , ( UUID ) Mockito . any ( ) , eq ( "hello" ) , ( Serializable ) Mockito . any ( ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) , hasItem ( "blah" ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) , hasItem ( "hello" ) ) ; assertThat ( m_SUT . getActiveProgramTemplateNames ( ) . size ( ) , is ( 2 ) ) ; }
Verify program can be added.
Verify program can be added .
// mock // replay         // verify each call once // verify // mock // replay //add the name to the mocked list of templates. // verify that the new program was persisted, in addition to the other. //check that the programs are in the set of programs managed. //check that there are ONLY two programs present.