mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestMetatypeMessageService.java
@Test
    public void testGetBundlePidsRequestValid() throws IOException
    {
        //mock bundles
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        Bundle bundleB = mock(Bundle.class);
        when(bundleB.getBundleId()).thenReturn(2L);
        Bundle bundleC = mock(Bundle.class);
        when(bundleC.getBundleId()).thenReturn(3L);
        Bundle bundleD = mock(Bundle.class);
        when(bundleD.getBundleId()).thenReturn(4L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { bundleA, bundleC, bundleB, bundleD});
        //mock meta type information for the bundles
        MetaTypeInformation infoA = mock(MetaTypeInformation.class);
        when(infoA.getPids()).thenReturn(new String[] {"configA", "configF"});
        when(infoA.getFactoryPids()).thenReturn(new String[] {"FactoryconfigA", "FactoryconfigF"});
        MetaTypeInformation infoB = mock(MetaTypeInformation.class);
        when(infoB.getPids()).thenReturn(new String[] {});
        when(infoB.getFactoryPids()).thenReturn(new String[] {"FactoryConfigG"});
        MetaTypeInformation infoC = mock(MetaTypeInformation.class);
        when(infoC.getPids()).thenReturn(new String[] {"configZ", "configD"});
        when(infoC.getFactoryPids()).thenReturn(new String[] {});
        //behavior for mocked meta information
        when(m_MetaTypeService.getMetaTypeInformation(bundleA)).thenReturn(infoA);
        when(m_MetaTypeService.getMetaTypeInformation(bundleB)).thenReturn(infoB);
        when(m_MetaTypeService.getMetaTypeInformation(bundleC)).thenReturn(infoC);
        
        //replay/verify
        GetBundlePidsRequestData request = GetBundlePidsRequestData.newBuilder().setBundleId(1).build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);

        //mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        // handle the message
        m_SUT.handleMessage(message, payload, channel);

        //capture the message
        ArgumentCaptor<GetBundlePidsResponseData> captor = ArgumentCaptor.forClass(GetBundlePidsResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        verify(m_ResponseWrapper).queue(channel);

        GetBundlePidsResponseData response = captor.getValue();
        //verify that lists of pids is not empty        
        assertThat(response.getPidsCount(), is(2));
        assertThat(response.getPidsList(), hasItem("configA"));
        assertThat(response.getPidsList(), hasItem("configF"));
        assertThat(response.getBundleId(), is(1L));
        //verify that factory pids list is empty
        assertThat(response.getFactoryPidsCount(), is(2));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryconfigA"));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryconfigF"));

        //new request with different bundle id
        request = GetBundlePidsRequestData.newBuilder().setBundleId(2).build();
        payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);

        // handle the message
        m_SUT.handleMessage(message, payload, channel);

        //capture the message
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        //reused channel
        verify(m_ResponseWrapper, times(2)).queue(channel);

        //parse response
        response = captor.getValue();
        //verify that lists of pids is empty  
        assertThat(response.getBundleId(), is(2L));
        assertThat(response.getPidsCount(), is(0));
        //verify that factory pids list is NOT empty
        assertThat(response.getFactoryPidsCount(), is(1));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryConfigG"));
        
        //new request with different bundle id
        request = GetBundlePidsRequestData.newBuilder().setBundleId(3).build();
        payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);

        //handle message
        m_SUT.handleMessage(message, payload, channel);

        //capture the message
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        verify(m_ResponseWrapper, times(3)).queue(channel);
        response = captor.getValue();
        //verify that lists of pids is not empty
        assertThat(response.getBundleId(), is(3L));
        assertThat(response.getPidsCount(), is(2));
        assertThat(response.getPidsList(), hasItem("configZ"));
        assertThat(response.getPidsList(), hasItem("configD"));
        //verify that factory pids list is empty
        assertThat(response.getFactoryPidsCount(), is(0));
    }
/**
     * Test that if the bundle id is found that the GetBundlePidsRequest is properly handled.
     * 
     * Verify lists of bundle Pids are returned with correct pids types.
     * 
     */
Test that if the bundle id is found that the GetBundlePidsRequest is properly handled.

Verify lists of bundle Pids are returned with correct pids types.
Test that if the bundle id is found that the GetBundlePidsRequest is properly handled . Verify lists of bundle Pids are returned with correct pids types .
@Test
    public void testGetBundlePidsRequestValid() throws IOException
    {
        Bundle bundleA = mock(Bundle.class);
        when(bundleA.getBundleId()).thenReturn(1L);
        Bundle bundleB = mock(Bundle.class);
        when(bundleB.getBundleId()).thenReturn(2L);
        Bundle bundleC = mock(Bundle.class);
        when(bundleC.getBundleId()).thenReturn(3L);
        Bundle bundleD = mock(Bundle.class);
        when(bundleD.getBundleId()).thenReturn(4L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { bundleA, bundleC, bundleB, bundleD});
        MetaTypeInformation infoA = mock(MetaTypeInformation.class);
        when(infoA.getPids()).thenReturn(new String[] {"configA", "configF"});
        when(infoA.getFactoryPids()).thenReturn(new String[] {"FactoryconfigA", "FactoryconfigF"});
        MetaTypeInformation infoB = mock(MetaTypeInformation.class);
        when(infoB.getPids()).thenReturn(new String[] {});
        when(infoB.getFactoryPids()).thenReturn(new String[] {"FactoryConfigG"});
        MetaTypeInformation infoC = mock(MetaTypeInformation.class);
        when(infoC.getPids()).thenReturn(new String[] {"configZ", "configD"});
        when(infoC.getFactoryPids()).thenReturn(new String[] {});
        when(m_MetaTypeService.getMetaTypeInformation(bundleA)).thenReturn(infoA);
        when(m_MetaTypeService.getMetaTypeInformation(bundleB)).thenReturn(infoB);
        when(m_MetaTypeService.getMetaTypeInformation(bundleC)).thenReturn(infoC);
        GetBundlePidsRequestData request = GetBundlePidsRequestData.newBuilder().setBundleId(1).build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<GetBundlePidsResponseData> captor = ArgumentCaptor.forClass(GetBundlePidsResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetBundlePidsResponseData response = captor.getValue();
        assertThat(response.getPidsCount(), is(2));
        assertThat(response.getPidsList(), hasItem("configA"));
        assertThat(response.getPidsList(), hasItem("configF"));
        assertThat(response.getBundleId(), is(1L));
        assertThat(response.getFactoryPidsCount(), is(2));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryconfigA"));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryconfigF"));
        request = GetBundlePidsRequestData.newBuilder().setBundleId(2).build();
        payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        verify(m_ResponseWrapper, times(2)).queue(channel);
        response = captor.getValue();
        assertThat(response.getBundleId(), is(2L));
        assertThat(response.getPidsCount(), is(0));
        assertThat(response.getFactoryPidsCount(), is(1));
        assertThat(response.getFactoryPidsList(), hasItem("FactoryConfigG"));
        request = GetBundlePidsRequestData.newBuilder().setBundleId(3).build();
        payload = createPayload(request, MetaTypeMessageType.GetBundlePidsRequest);
        message = createTerraHarvestMessage(request, MetaTypeMessageType.GetBundlePidsRequest);
        m_SUT.handleMessage(message, payload, channel);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetBundlePidsResponse), 
                captor.capture());
        verify(m_ResponseWrapper, times(3)).queue(channel);
        response = captor.getValue();
        assertThat(response.getBundleId(), is(3L));
        assertThat(response.getPidsCount(), is(2));
        assertThat(response.getPidsList(), hasItem("configZ"));
        assertThat(response.getPidsList(), hasItem("configD"));
        assertThat(response.getFactoryPidsCount(), is(0));
    }
@ Test public void testGetBundlePidsRequestValid ( ) throws IOException { Bundle bundleA = mock ( Bundle . class ) ; when ( bundleA . getBundleId ( ) ) . thenReturn ( 1L ) ; Bundle bundleB = mock ( Bundle . class ) ; when ( bundleB . getBundleId ( ) ) . thenReturn ( 2L ) ; Bundle bundleC = mock ( Bundle . class ) ; when ( bundleC . getBundleId ( ) ) . thenReturn ( 3L ) ; Bundle bundleD = mock ( Bundle . class ) ; when ( bundleD . getBundleId ( ) ) . thenReturn ( 4L ) ; when ( m_Context . getBundles ( ) ) . thenReturn ( new Bundle [ ] { bundleA , bundleC , bundleB , bundleD } ) ; MetaTypeInformation infoA = mock ( MetaTypeInformation . class ) ; when ( infoA . getPids ( ) ) . thenReturn ( new String [ ] { "configA" , "configF" } ) ; when ( infoA . getFactoryPids ( ) ) . thenReturn ( new String [ ] { "FactoryconfigA" , "FactoryconfigF" } ) ; MetaTypeInformation infoB = mock ( MetaTypeInformation . class ) ; when ( infoB . getPids ( ) ) . thenReturn ( new String [ ] { } ) ; when ( infoB . getFactoryPids ( ) ) . thenReturn ( new String [ ] { "FactoryConfigG" } ) ; MetaTypeInformation infoC = mock ( MetaTypeInformation . class ) ; when ( infoC . getPids ( ) ) . thenReturn ( new String [ ] { "configZ" , "configD" } ) ; when ( infoC . getFactoryPids ( ) ) . thenReturn ( new String [ ] { } ) ; when ( m_MetaTypeService . getMetaTypeInformation ( bundleA ) ) . thenReturn ( infoA ) ; when ( m_MetaTypeService . getMetaTypeInformation ( bundleB ) ) . thenReturn ( infoB ) ; when ( m_MetaTypeService . getMetaTypeInformation ( bundleC ) ) . thenReturn ( infoC ) ; GetBundlePidsRequestData request = GetBundlePidsRequestData . newBuilder ( ) . setBundleId ( 1 ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < GetBundlePidsResponseData > captor = ArgumentCaptor . forClass ( GetBundlePidsResponseData . class ) ; verify ( m_MessageFactory ) . createMetaTypeResponseMessage ( eq ( message ) , eq ( MetaTypeMessageType . GetBundlePidsResponse ) , captor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetBundlePidsResponseData response = captor . getValue ( ) ; assertThat ( response . getPidsCount ( ) , is ( 2 ) ) ; assertThat ( response . getPidsList ( ) , hasItem ( "configA" ) ) ; assertThat ( response . getPidsList ( ) , hasItem ( "configF" ) ) ; assertThat ( response . getBundleId ( ) , is ( 1L ) ) ; assertThat ( response . getFactoryPidsCount ( ) , is ( 2 ) ) ; assertThat ( response . getFactoryPidsList ( ) , hasItem ( "FactoryconfigA" ) ) ; assertThat ( response . getFactoryPidsList ( ) , hasItem ( "FactoryconfigF" ) ) ; request = GetBundlePidsRequestData . newBuilder ( ) . setBundleId ( 2 ) . build ( ) ; payload = createPayload ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; message = createTerraHarvestMessage ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createMetaTypeResponseMessage ( eq ( message ) , eq ( MetaTypeMessageType . GetBundlePidsResponse ) , captor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 2 ) ) . queue ( channel ) ; response = captor . getValue ( ) ; assertThat ( response . getBundleId ( ) , is ( 2L ) ) ; assertThat ( response . getPidsCount ( ) , is ( 0 ) ) ; assertThat ( response . getFactoryPidsCount ( ) , is ( 1 ) ) ; assertThat ( response . getFactoryPidsList ( ) , hasItem ( "FactoryConfigG" ) ) ; request = GetBundlePidsRequestData . newBuilder ( ) . setBundleId ( 3 ) . build ( ) ; payload = createPayload ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; message = createTerraHarvestMessage ( request , MetaTypeMessageType . GetBundlePidsRequest ) ; m_SUT . handleMessage ( message , payload , channel ) ; verify ( m_MessageFactory ) . createMetaTypeResponseMessage ( eq ( message ) , eq ( MetaTypeMessageType . GetBundlePidsResponse ) , captor . capture ( ) ) ; verify ( m_ResponseWrapper , times ( 3 ) ) . queue ( channel ) ; response = captor . getValue ( ) ; assertThat ( response . getBundleId ( ) , is ( 3L ) ) ; assertThat ( response . getPidsCount ( ) , is ( 2 ) ) ; assertThat ( response . getPidsList ( ) , hasItem ( "configZ" ) ) ; assertThat ( response . getPidsList ( ) , hasItem ( "configD" ) ) ; assertThat ( response . getFactoryPidsCount ( ) , is ( 0 ) ) ; }
Test that if the bundle id is found that the GetBundlePidsRequest is properly handled.
Test that if the bundle id is found that the GetBundlePidsRequest is properly handled .
//mock bundles //mock meta type information for the bundles //behavior for mocked meta information //replay/verify //mock the channel the message came from // handle the message //capture the message //verify that lists of pids is not empty         //verify that factory pids list is empty //new request with different bundle id // handle the message //capture the message //reused channel //parse response //verify that lists of pids is empty   //verify that factory pids list is NOT empty //new request with different bundle id //handle message //capture the message //verify that lists of pids is not empty //verify that factory pids list is empty