mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestAssetMgrImpl.java
@Test
    public void testHandlePerformBitResponse() throws ObjectConverterException
    {
        //make some assets
        Event getAssetsReponse = mockGetAssetsResponse(systemId1);
        
        //this should render two assets for the system id
        m_AssetDirHelper.handleEvent(getAssetsReponse);

        //verify assets added
        assertThat(m_SUT.getAssetsForControllerAsync(systemId1).size(), is(2));

        //create asset appropriate event for the asset status update
        Event bitUpdate = mockPerformBITResponse(systemId1);

        //status
        Observation obs = mock(Observation.class);
        when(obs.getStatus()).thenReturn(new Status().withSummaryStatus(
            new mil.dod.th.core.types.status.OperatingStatus(SummaryStatusEnum.OFF, "zoom")));
        //mock converter behavior
        when(m_Converter.convertToJaxb(Mockito.any(Message.class))).thenReturn(obs);
        
        //handle event
        m_AssetHelper.handleEvent(bitUpdate);

        verify(m_GrowlUtil).createGlobalFacesMessage(FacesMessage.SEVERITY_INFO, "Asset completed BIT test.", 
            String.format("Asset %s from controller 0x%08x, updated status to %s.", 
                "Unknown (" + uuid1.toString() + ")", systemId1, SummaryStatusEnum.OFF));

        //verify
        List<AssetModel> models = m_SUT.getAssetsForControllerAsync(systemId1);
        
        //verify that the asset with uuid1 is updated with appropriate status
        boolean verified = false;
        boolean verified2 = false;
        for (AssetModel model : models)
        {
            if (model.getUuid().equals(uuid1))
            {
                assertThat(model.getPid(), is(pid1));
                assertThat(model.getSummaryStatus(), is(SummaryStatusEnum.OFF));
                assertThat(model.getSummaryDescription(), is("zoom"));
                verified = true;
            }
            //check that the default is unknown, as only asset with uuid1 is updated with the event
            else
            {
                assertThat(model.getUuid(), is(uuid2));
                assertThat(model.getPid(), is(pid2));
                assertThat(model.getSummaryStatus(), is(nullValue()));
                verified2 = true;
            }
        }
        
        //verify both assets were checked
        assertThat(verified, is(true));
        assertThat(verified2, is(true));
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        
        Event firstPushEvent = eventCaptor.getValue();
        assertThat(firstPushEvent, notNullValue());
        assertThat(firstPushEvent.getTopic(), is(AssetMgr.TOPIC_ASSET_STATUS_UPDATED));
        assertThat((String)firstPushEvent.getProperty(Asset.EVENT_PROP_ASSET_STATUS_SUMMARY), 
                is(SummaryStatusEnum.OFF.toString()));
        assertThat((String)firstPushEvent.getProperty(Asset.EVENT_PROP_ASSET_STATUS_DESCRIPTION), 
                is("zoom"));
        assertThat((String)firstPushEvent.getProperty(AssetModel.EVENT_PROP_UUID), is(uuid1.toString()));
    }
/**
     * Test the handling of perform BIT request event.
     * Verify the status is updated. (The mock message only updates the asset with uuid1).
     */
Test the handling of perform BIT request event.
Verify the status is updated. (The mock message only updates the asset with uuid1).
Test the handling of perform BIT request event . Verify the status is updated . ( The mock message only updates the asset with uuid1 ) .
@Test
    public void testHandlePerformBitResponse() throws ObjectConverterException
    {
        Event getAssetsReponse = mockGetAssetsResponse(systemId1);
        m_AssetDirHelper.handleEvent(getAssetsReponse);
        assertThat(m_SUT.getAssetsForControllerAsync(systemId1).size(), is(2));
        Event bitUpdate = mockPerformBITResponse(systemId1);
        Observation obs = mock(Observation.class);
        when(obs.getStatus()).thenReturn(new Status().withSummaryStatus(
            new mil.dod.th.core.types.status.OperatingStatus(SummaryStatusEnum.OFF, "zoom")));
        when(m_Converter.convertToJaxb(Mockito.any(Message.class))).thenReturn(obs);
        m_AssetHelper.handleEvent(bitUpdate);
        verify(m_GrowlUtil).createGlobalFacesMessage(FacesMessage.SEVERITY_INFO, "Asset completed BIT test.", 
            String.format("Asset %s from controller 0x%08x, updated status to %s.", 
                "Unknown (" + uuid1.toString() + ")", systemId1, SummaryStatusEnum.OFF));
        List<AssetModel> models = m_SUT.getAssetsForControllerAsync(systemId1);
         that the asset with uuid1 is updated with appropriate status
        boolean verified = false;
        boolean verified2 = false;
        for (AssetModel model : models)
        {
            if (model.getUuid().equals(uuid1))
            {
                assertThat(model.getPid(), is(pid1));
                assertThat(model.getSummaryStatus(), is(SummaryStatusEnum.OFF));
                assertThat(model.getSummaryDescription(), is("zoom"));
                verified = true;
            }
            else
            {
                assertThat(model.getUuid(), is(uuid2));
                assertThat(model.getPid(), is(pid2));
                assertThat(model.getSummaryStatus(), is(nullValue()));
                verified2 = true;
            }
        }
         both assets were checked
        assertThat(verified, is(true));
        assertThat(verified2, is(true));
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event firstPushEvent = eventCaptor.getValue();
        assertThat(firstPushEvent, notNullValue());
        assertThat(firstPushEvent.getTopic(), is(AssetMgr.TOPIC_ASSET_STATUS_UPDATED));
        assertThat((String)firstPushEvent.getProperty(Asset.EVENT_PROP_ASSET_STATUS_SUMMARY), 
                is(SummaryStatusEnum.OFF.toString()));
        assertThat((String)firstPushEvent.getProperty(Asset.EVENT_PROP_ASSET_STATUS_DESCRIPTION), 
                is("zoom"));
        assertThat((String)firstPushEvent.getProperty(AssetModel.EVENT_PROP_UUID), is(uuid1.toString()));
    }
@ Test public void testHandlePerformBitResponse ( ) throws ObjectConverterException { Event getAssetsReponse = mockGetAssetsResponse ( systemId1 ) ; m_AssetDirHelper . handleEvent ( getAssetsReponse ) ; assertThat ( m_SUT . getAssetsForControllerAsync ( systemId1 ) . size ( ) , is ( 2 ) ) ; Event bitUpdate = mockPerformBITResponse ( systemId1 ) ; Observation obs = mock ( Observation . class ) ; when ( obs . getStatus ( ) ) . thenReturn ( new Status ( ) . withSummaryStatus ( new mil . dod . th . core . types . status . OperatingStatus ( SummaryStatusEnum . OFF , "zoom" ) ) ) ; when ( m_Converter . convertToJaxb ( Mockito . any ( Message . class ) ) ) . thenReturn ( obs ) ; m_AssetHelper . handleEvent ( bitUpdate ) ; verify ( m_GrowlUtil ) . createGlobalFacesMessage ( FacesMessage . SEVERITY_INFO , "Asset completed BIT test." , String . format ( "Asset %s from controller 0x%08x, updated status to %s." , "Unknown (" + uuid1 . toString ( ) + ")" , systemId1 , SummaryStatusEnum . OFF ) ) ; List < AssetModel > models = m_SUT . getAssetsForControllerAsync ( systemId1 ) ; boolean verified = false ; boolean verified2 = false ; for ( AssetModel model : models ) { if ( model . getUuid ( ) . equals ( uuid1 ) ) { assertThat ( model . getPid ( ) , is ( pid1 ) ) ; assertThat ( model . getSummaryStatus ( ) , is ( SummaryStatusEnum . OFF ) ) ; assertThat ( model . getSummaryDescription ( ) , is ( "zoom" ) ) ; verified = true ; } else { assertThat ( model . getUuid ( ) , is ( uuid2 ) ) ; assertThat ( model . getPid ( ) , is ( pid2 ) ) ; assertThat ( model . getSummaryStatus ( ) , is ( nullValue ( ) ) ) ; verified2 = true ; } } assertThat ( verified , is ( true ) ) ; assertThat ( verified2 , is ( true ) ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event firstPushEvent = eventCaptor . getValue ( ) ; assertThat ( firstPushEvent , notNullValue ( ) ) ; assertThat ( firstPushEvent . getTopic ( ) , is ( AssetMgr . TOPIC_ASSET_STATUS_UPDATED ) ) ; assertThat ( ( String ) firstPushEvent . getProperty ( Asset . EVENT_PROP_ASSET_STATUS_SUMMARY ) , is ( SummaryStatusEnum . OFF . toString ( ) ) ) ; assertThat ( ( String ) firstPushEvent . getProperty ( Asset . EVENT_PROP_ASSET_STATUS_DESCRIPTION ) , is ( "zoom" ) ) ; assertThat ( ( String ) firstPushEvent . getProperty ( AssetModel . EVENT_PROP_UUID ) , is ( uuid1 . toString ( ) ) ) ; }
Test the handling of perform BIT request event.
Test the handling of perform BIT request event .
//make some assets //this should render two assets for the system id //verify assets added //create asset appropriate event for the asset status update //status //mock converter behavior //handle event //verify //verify that the asset with uuid1 is updated with appropriate status //check that the default is unknown, as only asset with uuid1 is updated with the event //verify both assets were checked