mil.dod.th.ose.core/test/mil/dod/th/ose/core/impl/mp/TestTemplateProgramManagerImpl.java
@Test
    public void testPersistTemplate() throws IllegalArgumentException, PersistenceFailedException
    {
        //mock the stored templates
        mockTemplateProgramManagerTemplates();
        m_SUT.activate(context);
        
        MissionProgramTemplate template = new MissionProgramTemplate().withName("MyTemplate").withSource("Source");
        m_SUT.loadMissionTemplate(template);
        //need to capture the UUID so it is known for removal
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        ArgumentCaptor<byte[]> templateCap = ArgumentCaptor.forClass(byte[].class);
        verify(m_PersistentDataStore).persist(eq(TemplateProgramManagerImpl.class), uuid.capture(), 
            eq("MyTemplate"), templateCap.capture());
        
        MissionProgramTemplate template2 = (MissionProgramTemplate)XmlUtils.fromXML(templateCap.getValue(), 
                MissionProgramTemplate.class);
        //check that the persisted template is the template expected
        assertThat(template2, is(template));
        //check that the new template is managed
        assertThat(m_SUT.getMissionTemplateNames(), hasItem("MyTemplate"));
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);
        when(foundData.getEntity()).thenReturn(templateCap.getValue());
        template = m_SUT.getTemplate("MyTemplate");
                
        m_SUT.removeTemplate("MyTemplate");
        //verify the data store removes the template
        verify(m_PersistentDataStore).remove(uuid.getValue());
        assertThat(m_SUT.getMissionTemplateNames(), not(hasItem("MyTemplate")));
    }
/**
     * Test that templates are persisted.
     */
Test that templates are persisted.
Test that templates are persisted .
@Test
    public void testPersistTemplate() throws IllegalArgumentException, PersistenceFailedException
    {
        mockTemplateProgramManagerTemplates();
        m_SUT.activate(context);
        MissionProgramTemplate template = new MissionProgramTemplate().withName("MyTemplate").withSource("Source");
        m_SUT.loadMissionTemplate(template);
        ArgumentCaptor<UUID> uuid = ArgumentCaptor.forClass(UUID.class);
        ArgumentCaptor<byte[]> templateCap = ArgumentCaptor.forClass(byte[].class);
        verify(m_PersistentDataStore).persist(eq(TemplateProgramManagerImpl.class), uuid.capture(), 
            eq("MyTemplate"), templateCap.capture());
        MissionProgramTemplate template2 = (MissionProgramTemplate)XmlUtils.fromXML(templateCap.getValue(), 
                MissionProgramTemplate.class);
        assertThat(template2, is(template));
        assertThat(m_SUT.getMissionTemplateNames(), hasItem("MyTemplate"));
        PersistentData foundData = mock(PersistentData.class);
        when(m_PersistentDataStore.find((UUID)Mockito.any())).thenReturn(foundData);
        when(foundData.getEntity()).thenReturn(templateCap.getValue());
        template = m_SUT.getTemplate("MyTemplate");
        m_SUT.removeTemplate("MyTemplate");
        verify(m_PersistentDataStore).remove(uuid.getValue());
        assertThat(m_SUT.getMissionTemplateNames(), not(hasItem("MyTemplate")));
    }
@ Test public void testPersistTemplate ( ) throws IllegalArgumentException , PersistenceFailedException { mockTemplateProgramManagerTemplates ( ) ; m_SUT . activate ( context ) ; MissionProgramTemplate template = new MissionProgramTemplate ( ) . withName ( "MyTemplate" ) . withSource ( "Source" ) ; m_SUT . loadMissionTemplate ( template ) ; ArgumentCaptor < UUID > uuid = ArgumentCaptor . forClass ( UUID . class ) ; ArgumentCaptor < byte [ ] > templateCap = ArgumentCaptor . forClass ( byte [ ] . class ) ; verify ( m_PersistentDataStore ) . persist ( eq ( TemplateProgramManagerImpl . class ) , uuid . capture ( ) , eq ( "MyTemplate" ) , templateCap . capture ( ) ) ; MissionProgramTemplate template2 = ( MissionProgramTemplate ) XmlUtils . fromXML ( templateCap . getValue ( ) , MissionProgramTemplate . class ) ; assertThat ( template2 , is ( template ) ) ; assertThat ( m_SUT . getMissionTemplateNames ( ) , hasItem ( "MyTemplate" ) ) ; PersistentData foundData = mock ( PersistentData . class ) ; when ( m_PersistentDataStore . find ( ( UUID ) Mockito . any ( ) ) ) . thenReturn ( foundData ) ; when ( foundData . getEntity ( ) ) . thenReturn ( templateCap . getValue ( ) ) ; template = m_SUT . getTemplate ( "MyTemplate" ) ; m_SUT . removeTemplate ( "MyTemplate" ) ; verify ( m_PersistentDataStore ) . remove ( uuid . getValue ( ) ) ; assertThat ( m_SUT . getMissionTemplateNames ( ) , not ( hasItem ( "MyTemplate" ) ) ) ; }
Test that templates are persisted.
Test that templates are persisted .
//mock the stored templates //need to capture the UUID so it is known for removal //check that the persisted template is the template expected //check that the new template is managed //verify the data store removes the template