mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/advanced/TestBundleMgrImpl.java
@Test
    public void testHandleEventBundleInfo()
    {
        m_SUT.getBundlesAsync(25);
        
        GetBundleInfoRequestData req = GetBundleInfoRequestData.newBuilder().setBundleId(0).build();
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createTerraHarvestMessage(25, 0, Namespace.Bundle, 0,
                req);

        GetBundleInfoResponseData.Builder infoBuilder = GetBundleInfoResponseData.newBuilder();

        BundleInfoType bundleID1 = BundleInfoType.newBuilder().setBundleName("Test Bundle 1").setBundleId(1L).
                setBundleLocation("location").addPackageExport("").addPackageImport("").build();
        
        BundleInfoType bundleID2 = BundleInfoType.newBuilder().setBundleName("Test Bundle 2").setBundleId(2L).
                setBundleLocation("location 2").addPackageExport("").addPackageImport("").build();
        
        BundleInfoType bundleID3 = BundleInfoType.newBuilder().setBundleName("Test Bundle 3").setBundleId(3L).
                setBundleLocation("location 3").addPackageExport("").addPackageImport("").build();
        
        List<BundleInfoType> bundleInfo = new ArrayList<BundleInfoType>();
        bundleInfo.add(bundleID1);
        bundleInfo.add(bundleID2);
        bundleInfo.add(bundleID3);
        infoBuilder.addAllInfoData(bundleInfo);
        
        Map<String, Object> props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, BundleMessageType.GetBundleInfoResponse.toString());
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, infoBuilder.build());
        m_Event = new Event(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED, props);
       
        m_BundleHelper.handleEvent(m_Event);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        
        Event event = eventCaptor.getValue();
        assertThat(event.getTopic(), is(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED));
        assertThat((Integer)event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is(25));
        assertThat((Long)event.getProperty(EventConstants.BUNDLE_ID), is(nullValue()));
        
        List<BundleModel> bundles = m_SUT.getBundlesAsync(25);
        assertThat(bundles.size(), is(3));
        assertThat(bundles.get(0).getBundleName(), is("Test Bundle 1"));
        assertThat(bundles.get(1).getBundleName(), is("Test Bundle 2"));
        assertThat(bundles.get(2).getBundleName(), is("Test Bundle 3"));
        
        BundleInfoType typeModified = BundleInfoType.newBuilder().setBundleName("Altered").setBundleId(1L).
                addPackageExport("").addPackageImport("").build();
        
        bundleInfo.clear();
        bundleInfo.add(typeModified);
        infoBuilder.clearInfoData();
        infoBuilder.addAllInfoData(bundleInfo);
        
        props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, BundleMessageType.GetBundleInfoResponse.toString());
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, infoBuilder.build());
        m_Event = new Event(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED, props);
        
        m_BundleHelper.handleEvent(m_Event);
        
        bundles = m_SUT.getBundlesAsync(25);
        assertThat(bundles.size(), is(3));
        assertThat(bundles.get(0).getBundleName(), is("Altered"));
        assertThat(bundles.get(1).getBundleName(), is("Test Bundle 2"));
        assertThat(bundles.get(2).getBundleName(), is("Test Bundle 3"));
        
        ArgumentCaptor<Event> eventCaptorAlt = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptorAlt.capture());
        
        Event eventAlt = eventCaptorAlt.getAllValues().get(1);
        assertThat(eventAlt.getTopic(), is(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED));
        assertThat((Integer)eventAlt.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is(25));
        assertThat((Long)eventAlt.getProperty(EventConstants.BUNDLE_ID), is(1L));
        assertThat((String)eventAlt.getProperty(BundleMgr.EVENT_PROP_BUNDLE_LOCATION), is(""));
    }
/**
     * Test the local event handler handling bundle info response messages.
     * Verify that the handler takes appropriate actions to handle a bundle info response message.
     */
Test the local event handler handling bundle info response messages.
Verify that the handler takes appropriate actions to handle a bundle info response message.
Test the local event handler handling bundle info response messages . Verify that the handler takes appropriate actions to handle a bundle info response message .
@Test
    public void testHandleEventBundleInfo()
    {
        m_SUT.getBundlesAsync(25);
        GetBundleInfoRequestData req = GetBundleInfoRequestData.newBuilder().setBundleId(0).build();
        TerraHarvestMessage thMessage = TerraHarvestMessageHelper.createTerraHarvestMessage(25, 0, Namespace.Bundle, 0,
                req);
        GetBundleInfoResponseData.Builder infoBuilder = GetBundleInfoResponseData.newBuilder();
        BundleInfoType bundleID1 = BundleInfoType.newBuilder().setBundleName("Test Bundle 1").setBundleId(1L).
                setBundleLocation("location").addPackageExport("").addPackageImport("").build();
        BundleInfoType bundleID2 = BundleInfoType.newBuilder().setBundleName("Test Bundle 2").setBundleId(2L).
                setBundleLocation("location 2").addPackageExport("").addPackageImport("").build();
        BundleInfoType bundleID3 = BundleInfoType.newBuilder().setBundleName("Test Bundle 3").setBundleId(3L).
                setBundleLocation("location 3").addPackageExport("").addPackageImport("").build();
        List<BundleInfoType> bundleInfo = new ArrayList<BundleInfoType>();
        bundleInfo.add(bundleID1);
        bundleInfo.add(bundleID2);
        bundleInfo.add(bundleID3);
        infoBuilder.addAllInfoData(bundleInfo);
        Map<String, Object> props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, BundleMessageType.GetBundleInfoResponse.toString());
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, infoBuilder.build());
        m_Event = new Event(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED, props);
        m_BundleHelper.handleEvent(m_Event);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(1)).postEvent(eventCaptor.capture());
        Event event = eventCaptor.getValue();
        assertThat(event.getTopic(), is(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED));
        assertThat((Integer)event.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is(25));
        assertThat((Long)event.getProperty(EventConstants.BUNDLE_ID), is(nullValue()));
        List<BundleModel> bundles = m_SUT.getBundlesAsync(25);
        assertThat(bundles.size(), is(3));
        assertThat(bundles.get(0).getBundleName(), is("Test Bundle 1"));
        assertThat(bundles.get(1).getBundleName(), is("Test Bundle 2"));
        assertThat(bundles.get(2).getBundleName(), is("Test Bundle 3"));
        BundleInfoType typeModified = BundleInfoType.newBuilder().setBundleName("Altered").setBundleId(1L).
                addPackageExport("").addPackageImport("").build();
        bundleInfo.clear();
        bundleInfo.add(typeModified);
        infoBuilder.clearInfoData();
        infoBuilder.addAllInfoData(bundleInfo);
        props = new HashMap<>();
        props.put(RemoteConstants.EVENT_PROP_MESSAGE, thMessage);
        props.put(RemoteConstants.EVENT_PROP_MESSAGE_TYPE, BundleMessageType.GetBundleInfoResponse.toString());
        props.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, infoBuilder.build());
        m_Event = new Event(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED, props);
        m_BundleHelper.handleEvent(m_Event);
        bundles = m_SUT.getBundlesAsync(25);
        assertThat(bundles.size(), is(3));
        assertThat(bundles.get(0).getBundleName(), is("Altered"));
        assertThat(bundles.get(1).getBundleName(), is("Test Bundle 2"));
        assertThat(bundles.get(2).getBundleName(), is("Test Bundle 3"));
        ArgumentCaptor<Event> eventCaptorAlt = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin, times(2)).postEvent(eventCaptorAlt.capture());
        Event eventAlt = eventCaptorAlt.getAllValues().get(1);
        assertThat(eventAlt.getTopic(), is(BundleMgr.TOPIC_BUNDLE_INFO_RECEIVED));
        assertThat((Integer)eventAlt.getProperty(SharedPropertyConstants.EVENT_PROP_CONTROLLER_ID), is(25));
        assertThat((Long)eventAlt.getProperty(EventConstants.BUNDLE_ID), is(1L));
        assertThat((String)eventAlt.getProperty(BundleMgr.EVENT_PROP_BUNDLE_LOCATION), is(""));
    }
@ Test public void testHandleEventBundleInfo ( ) { m_SUT . getBundlesAsync ( 25 ) ; GetBundleInfoRequestData req = GetBundleInfoRequestData . newBuilder ( ) . setBundleId ( 0 ) . build ( ) ; TerraHarvestMessage thMessage = TerraHarvestMessageHelper . createTerraHarvestMessage ( 25 , 0 , Namespace . Bundle , 0 , req ) ; GetBundleInfoResponseData . Builder infoBuilder = GetBundleInfoResponseData . newBuilder ( ) ; BundleInfoType bundleID1 = BundleInfoType . newBuilder ( ) . setBundleName ( "Test Bundle 1" ) . setBundleId ( 1L ) . setBundleLocation ( "location" ) . addPackageExport ( "" ) . addPackageImport ( "" ) . build ( ) ; BundleInfoType bundleID2 = BundleInfoType . newBuilder ( ) . setBundleName ( "Test Bundle 2" ) . setBundleId ( 2L ) . setBundleLocation ( "location 2" ) . addPackageExport ( "" ) . addPackageImport ( "" ) . build ( ) ; BundleInfoType bundleID3 = BundleInfoType . newBuilder ( ) . setBundleName ( "Test Bundle 3" ) . setBundleId ( 3L ) . setBundleLocation ( "location 3" ) . addPackageExport ( "" ) . addPackageImport ( "" ) . build ( ) ; List < BundleInfoType > bundleInfo = new ArrayList < BundleInfoType > ( ) ; bundleInfo . add ( bundleID1 ) ; bundleInfo . add ( bundleID2 ) ; bundleInfo . add ( bundleID3 ) ; infoBuilder . addAllInfoData ( bundleInfo ) ; Map < String , Object > props = new HashMap < > ( ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE , thMessage ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE , BundleMessageType . GetBundleInfoResponse . toString ( ) ) ; props . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , infoBuilder . build ( ) ) ; m_Event = new Event ( BundleMgr . TOPIC_BUNDLE_INFO_RECEIVED , props ) ; m_BundleHelper . handleEvent ( m_Event ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 1 ) ) . postEvent ( eventCaptor . capture ( ) ) ; Event event = eventCaptor . getValue ( ) ; assertThat ( event . getTopic ( ) , is ( BundleMgr . TOPIC_BUNDLE_INFO_RECEIVED ) ) ; assertThat ( ( Integer ) event . getProperty ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID ) , is ( 25 ) ) ; assertThat ( ( Long ) event . getProperty ( EventConstants . BUNDLE_ID ) , is ( nullValue ( ) ) ) ; List < BundleModel > bundles = m_SUT . getBundlesAsync ( 25 ) ; assertThat ( bundles . size ( ) , is ( 3 ) ) ; assertThat ( bundles . get ( 0 ) . getBundleName ( ) , is ( "Test Bundle 1" ) ) ; assertThat ( bundles . get ( 1 ) . getBundleName ( ) , is ( "Test Bundle 2" ) ) ; assertThat ( bundles . get ( 2 ) . getBundleName ( ) , is ( "Test Bundle 3" ) ) ; BundleInfoType typeModified = BundleInfoType . newBuilder ( ) . setBundleName ( "Altered" ) . setBundleId ( 1L ) . addPackageExport ( "" ) . addPackageImport ( "" ) . build ( ) ; bundleInfo . clear ( ) ; bundleInfo . add ( typeModified ) ; infoBuilder . clearInfoData ( ) ; infoBuilder . addAllInfoData ( bundleInfo ) ; props = new HashMap < > ( ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE , thMessage ) ; props . put ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE , BundleMessageType . GetBundleInfoResponse . toString ( ) ) ; props . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , infoBuilder . build ( ) ) ; m_Event = new Event ( BundleMgr . TOPIC_BUNDLE_INFO_RECEIVED , props ) ; m_BundleHelper . handleEvent ( m_Event ) ; bundles = m_SUT . getBundlesAsync ( 25 ) ; assertThat ( bundles . size ( ) , is ( 3 ) ) ; assertThat ( bundles . get ( 0 ) . getBundleName ( ) , is ( "Altered" ) ) ; assertThat ( bundles . get ( 1 ) . getBundleName ( ) , is ( "Test Bundle 2" ) ) ; assertThat ( bundles . get ( 2 ) . getBundleName ( ) , is ( "Test Bundle 3" ) ) ; ArgumentCaptor < Event > eventCaptorAlt = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin , times ( 2 ) ) . postEvent ( eventCaptorAlt . capture ( ) ) ; Event eventAlt = eventCaptorAlt . getAllValues ( ) . get ( 1 ) ; assertThat ( eventAlt . getTopic ( ) , is ( BundleMgr . TOPIC_BUNDLE_INFO_RECEIVED ) ) ; assertThat ( ( Integer ) eventAlt . getProperty ( SharedPropertyConstants . EVENT_PROP_CONTROLLER_ID ) , is ( 25 ) ) ; assertThat ( ( Long ) eventAlt . getProperty ( EventConstants . BUNDLE_ID ) , is ( 1L ) ) ; assertThat ( ( String ) eventAlt . getProperty ( BundleMgr . EVENT_PROP_BUNDLE_LOCATION ) , is ( "" ) ) ; }
Test the local event handler handling bundle info response messages.
Test the local event handler handling bundle info response messages .