mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/mp/TestMissionImport.java
@Test
    public void testHandleMissionImport() throws IOException, UnmarshalException, IllegalArgumentException, 
        PersistenceFailedException
    {
        UploadedFile testFile = mock(UploadedFile.class);
        FileUploadEvent mockUploadEvent = mock(FileUploadEvent.class);
        
        byte[] testArr = {100, 101, 102, 103, 104 ,105};
        InputStream is = mock(InputStream.class);
        when(testFile.getFileName()).thenReturn("TestMission.xml");
        when(testFile.getContents()).thenReturn(testArr);
        when(testFile.getInputstream()).thenReturn(is);
        
        //return mocked test file when mock upload event is called
        when(mockUploadEvent.getFile()).thenReturn(testFile);
        m_SUT.handleImportMission(mockUploadEvent);
        
        //Verify that load mission template is called with the appropriate template as a parameter.
        verify(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), eq(false));
        
        //Setup argument captor to capture exceptions passed to the faces messages.
        ArgumentCaptor<Exception> testException = ArgumentCaptor.forClass(Exception.class);
        
        //Setup up exception stack for illegal argument exception.
        IllegalArgumentException argException = new IllegalArgumentException();
        //Set mocked template manager to throw exception when called.
        doThrow(argException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        //Verify create faces message called.
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(),
                Mockito.anyString(), testException.capture());
        //Verify exception type is correct.
        assertThat(testException.getValue(), instanceOf(IllegalArgumentException.class));
        
        UnmarshalException unMarshalException = new UnmarshalException("Error");
        doThrow(unMarshalException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_GrowlUtil, times(2)).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(), 
                Mockito.anyString(), testException.capture());
        assertThat(testException.getValue(), instanceOf(UnmarshalException.class));
        
        PersistenceFailedException persistFailException = new PersistenceFailedException();
        doThrow(persistFailException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_GrowlUtil, times(3)).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(), 
                Mockito.anyString(), testException.capture());
        assertThat(testException.getValue(), instanceOf(PersistenceFailedException.class));
    }
/**
     * Test the handleMissionImport method.
     * Verify that {@link TemplateProgramManager} loadMissionTemplate method is called with the appropriate parameters.
     */
Test the handleMissionImport method.
Verify that  TemplateProgramManager loadMissionTemplate method is called with the appropriate parameters.
Test the handleMissionImport method . Verify that TemplateProgramManager loadMissionTemplate method is called with the appropriate parameters .
@Test
    public void testHandleMissionImport() throws IOException, UnmarshalException, IllegalArgumentException, 
        PersistenceFailedException
    {
        UploadedFile testFile = mock(UploadedFile.class);
        FileUploadEvent mockUploadEvent = mock(FileUploadEvent.class);
        byte[] testArr = {100, 101, 102, 103, 104 ,105};
        InputStream is = mock(InputStream.class);
        when(testFile.getFileName()).thenReturn("TestMission.xml");
        when(testFile.getContents()).thenReturn(testArr);
        when(testFile.getInputstream()).thenReturn(is);
        when(mockUploadEvent.getFile()).thenReturn(testFile);
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), eq(false));
        ArgumentCaptor<Exception> testException = ArgumentCaptor.forClass(Exception.class);
        IllegalArgumentException argException = new IllegalArgumentException();
        doThrow(argException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_GrowlUtil).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(),
                Mockito.anyString(), testException.capture());
        assertThat(testException.getValue(), instanceOf(IllegalArgumentException.class));
        UnmarshalException unMarshalException = new UnmarshalException("Error");
        doThrow(unMarshalException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_GrowlUtil, times(2)).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(), 
                Mockito.anyString(), testException.capture());
        assertThat(testException.getValue(), instanceOf(UnmarshalException.class));
        PersistenceFailedException persistFailException = new PersistenceFailedException();
        doThrow(persistFailException).when(m_TemplateProgramManager).loadFromStream(Mockito.any(InputStream.class), 
                eq(false));
        m_SUT.handleImportMission(mockUploadEvent);
        verify(m_GrowlUtil, times(3)).createLocalFacesMessage(eq(FacesMessage.SEVERITY_ERROR), Mockito.anyString(), 
                Mockito.anyString(), testException.capture());
        assertThat(testException.getValue(), instanceOf(PersistenceFailedException.class));
    }
@ Test public void testHandleMissionImport ( ) throws IOException , UnmarshalException , IllegalArgumentException , PersistenceFailedException { UploadedFile testFile = mock ( UploadedFile . class ) ; FileUploadEvent mockUploadEvent = mock ( FileUploadEvent . class ) ; byte [ ] testArr = { 100 , 101 , 102 , 103 , 104 , 105 } ; InputStream is = mock ( InputStream . class ) ; when ( testFile . getFileName ( ) ) . thenReturn ( "TestMission.xml" ) ; when ( testFile . getContents ( ) ) . thenReturn ( testArr ) ; when ( testFile . getInputstream ( ) ) . thenReturn ( is ) ; when ( mockUploadEvent . getFile ( ) ) . thenReturn ( testFile ) ; m_SUT . handleImportMission ( mockUploadEvent ) ; verify ( m_TemplateProgramManager ) . loadFromStream ( Mockito . any ( InputStream . class ) , eq ( false ) ) ; ArgumentCaptor < Exception > testException = ArgumentCaptor . forClass ( Exception . class ) ; IllegalArgumentException argException = new IllegalArgumentException ( ) ; doThrow ( argException ) . when ( m_TemplateProgramManager ) . loadFromStream ( Mockito . any ( InputStream . class ) , eq ( false ) ) ; m_SUT . handleImportMission ( mockUploadEvent ) ; verify ( m_GrowlUtil ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_ERROR ) , Mockito . anyString ( ) , Mockito . anyString ( ) , testException . capture ( ) ) ; assertThat ( testException . getValue ( ) , instanceOf ( IllegalArgumentException . class ) ) ; UnmarshalException unMarshalException = new UnmarshalException ( "Error" ) ; doThrow ( unMarshalException ) . when ( m_TemplateProgramManager ) . loadFromStream ( Mockito . any ( InputStream . class ) , eq ( false ) ) ; m_SUT . handleImportMission ( mockUploadEvent ) ; verify ( m_GrowlUtil , times ( 2 ) ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_ERROR ) , Mockito . anyString ( ) , Mockito . anyString ( ) , testException . capture ( ) ) ; assertThat ( testException . getValue ( ) , instanceOf ( UnmarshalException . class ) ) ; PersistenceFailedException persistFailException = new PersistenceFailedException ( ) ; doThrow ( persistFailException ) . when ( m_TemplateProgramManager ) . loadFromStream ( Mockito . any ( InputStream . class ) , eq ( false ) ) ; m_SUT . handleImportMission ( mockUploadEvent ) ; verify ( m_GrowlUtil , times ( 3 ) ) . createLocalFacesMessage ( eq ( FacesMessage . SEVERITY_ERROR ) , Mockito . anyString ( ) , Mockito . anyString ( ) , testException . capture ( ) ) ; assertThat ( testException . getValue ( ) , instanceOf ( PersistenceFailedException . class ) ) ; }
Test the handleMissionImport method.
Test the handleMissionImport method .
//return mocked test file when mock upload event is called //Verify that load mission template is called with the appropriate template as a parameter. //Setup argument captor to capture exceptions passed to the faces messages. //Setup up exception stack for illegal argument exception. //Set mocked template manager to throw exception when called. //Verify create faces message called. //Verify exception type is correct.