mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestMetatypeMessageService.java
@Test
    public void testGetAttributKeysValid() throws IOException
    {
        //mock bundle
        Bundle coreBundle = mock(Bundle.class);
        when(coreBundle.getBundleId()).thenReturn(0L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { coreBundle});
        //mock core meta information
        MetaTypeInformation infoCore = mock(MetaTypeInformation.class);
        when(infoCore.getPids()).thenReturn(new String[] {"core-pid", "configD"});
        when(infoCore.getFactoryPids()).thenReturn(new String[] {});
        when(m_MetaTypeService.getMetaTypeInformation(coreBundle)).thenReturn(infoCore);
        ObjectClassDefinition ocd = mock(ObjectClassDefinition.class);
        when(infoCore.getObjectClassDefinition("core-pid", null)).thenReturn(ocd);
        stubAttributeDefs(ocd);
        
        //send message
        GetAttributeKeysRequestData request = GetAttributeKeysRequestData.newBuilder().
            setBundleId(0).
            setPid("core-pid").build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetAttributeKeyRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.GetAttributeKeyRequest);
 
        //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<GetAttributeKeysResponseData> captor = 
                ArgumentCaptor.forClass(GetAttributeKeysResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetAttributeKeyResponse), 
                captor.capture());
        verify(m_ResponseWrapper).queue(channel);
        //parse response
        GetAttributeKeysResponseData response = captor.getValue();
        //verify that list of keys is NOT empty
        assertThat(response.getBundleId(), is(0L));
        assertThat(response.getPid(), is("core-pid"));
        assertThat(response.getKeyCount(), is(5));

        //verify return values
        List<String> keys = response.getKeyList();
        assertThat(keys, hasItem("test"));
        assertThat(keys, hasItem("not-set-prop"));
        assertThat(keys, hasItem("unused"));
        assertThat(keys, hasItem("int-test"));
        assertThat(keys, hasItem("nullString"));
    }
/**
     * Test that if the bundle id/pid do return attributes that the GetAttributeKeysRequest is handled properly.
     * 
     * Verify list of attribute key is sent in response to the request.
     */
Test that if the bundle id/pid do return attributes that the GetAttributeKeysRequest is handled properly.

Verify list of attribute key is sent in response to the request.
Test that if the bundle id / pid do return attributes that the GetAttributeKeysRequest is handled properly . Verify list of attribute key is sent in response to the request .
@Test
    public void testGetAttributKeysValid() throws IOException
    {
        Bundle coreBundle = mock(Bundle.class);
        when(coreBundle.getBundleId()).thenReturn(0L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { coreBundle});
        MetaTypeInformation infoCore = mock(MetaTypeInformation.class);
        when(infoCore.getPids()).thenReturn(new String[] {"core-pid", "configD"});
        when(infoCore.getFactoryPids()).thenReturn(new String[] {});
        when(m_MetaTypeService.getMetaTypeInformation(coreBundle)).thenReturn(infoCore);
        ObjectClassDefinition ocd = mock(ObjectClassDefinition.class);
        when(infoCore.getObjectClassDefinition("core-pid", null)).thenReturn(ocd);
        stubAttributeDefs(ocd);
        GetAttributeKeysRequestData request = GetAttributeKeysRequestData.newBuilder().
            setBundleId(0).
            setPid("core-pid").build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetAttributeKeyRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.GetAttributeKeyRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<GetAttributeKeysResponseData> captor = 
                ArgumentCaptor.forClass(GetAttributeKeysResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
            eq(MetaTypeMessageType.GetAttributeKeyResponse), 
                captor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetAttributeKeysResponseData response = captor.getValue();
        assertThat(response.getBundleId(), is(0L));
        assertThat(response.getPid(), is("core-pid"));
        assertThat(response.getKeyCount(), is(5));
        List<String> keys = response.getKeyList();
        assertThat(keys, hasItem("test"));
        assertThat(keys, hasItem("not-set-prop"));
        assertThat(keys, hasItem("unused"));
        assertThat(keys, hasItem("int-test"));
        assertThat(keys, hasItem("nullString"));
    }
@ Test public void testGetAttributKeysValid ( ) throws IOException { Bundle coreBundle = mock ( Bundle . class ) ; when ( coreBundle . getBundleId ( ) ) . thenReturn ( 0L ) ; when ( m_Context . getBundles ( ) ) . thenReturn ( new Bundle [ ] { coreBundle } ) ; MetaTypeInformation infoCore = mock ( MetaTypeInformation . class ) ; when ( infoCore . getPids ( ) ) . thenReturn ( new String [ ] { "core-pid" , "configD" } ) ; when ( infoCore . getFactoryPids ( ) ) . thenReturn ( new String [ ] { } ) ; when ( m_MetaTypeService . getMetaTypeInformation ( coreBundle ) ) . thenReturn ( infoCore ) ; ObjectClassDefinition ocd = mock ( ObjectClassDefinition . class ) ; when ( infoCore . getObjectClassDefinition ( "core-pid" , null ) ) . thenReturn ( ocd ) ; stubAttributeDefs ( ocd ) ; GetAttributeKeysRequestData request = GetAttributeKeysRequestData . newBuilder ( ) . setBundleId ( 0 ) . setPid ( "core-pid" ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , MetaTypeMessageType . GetAttributeKeyRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , MetaTypeMessageType . GetAttributeKeyRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < GetAttributeKeysResponseData > captor = ArgumentCaptor . forClass ( GetAttributeKeysResponseData . class ) ; verify ( m_MessageFactory ) . createMetaTypeResponseMessage ( eq ( message ) , eq ( MetaTypeMessageType . GetAttributeKeyResponse ) , captor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetAttributeKeysResponseData response = captor . getValue ( ) ; assertThat ( response . getBundleId ( ) , is ( 0L ) ) ; assertThat ( response . getPid ( ) , is ( "core-pid" ) ) ; assertThat ( response . getKeyCount ( ) , is ( 5 ) ) ; List < String > keys = response . getKeyList ( ) ; assertThat ( keys , hasItem ( "test" ) ) ; assertThat ( keys , hasItem ( "not-set-prop" ) ) ; assertThat ( keys , hasItem ( "unused" ) ) ; assertThat ( keys , hasItem ( "int-test" ) ) ; assertThat ( keys , hasItem ( "nullString" ) ) ; }
Test that if the bundle id/pid do return attributes that the GetAttributeKeysRequest is handled properly.
Test that if the bundle id / pid do return attributes that the GetAttributeKeysRequest is handled properly .
//mock bundle //mock core meta information //send message //mock the channel the message came from // handle the message //capture the message //parse response //verify that list of keys is NOT empty //verify return values