mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestMetatypeMessageService.java
@Test
    public void testGetAttributeDefinitionValidWithKey() 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 coreBundle = mock(Bundle.class);
        when(coreBundle.getBundleId()).thenReturn(0L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { bundleA, bundleC, bundleB, coreBundle});
        //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[] {});
        //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
        GetAttributeDefinitionRequestData request = GetAttributeDefinitionRequestData.newBuilder().
            setBundleId(0).
            setPid("core-pid").
            setKey("test").build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetAttributeDefinitionRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.
            GetAttributeDefinitionRequest);

        //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<GetAttributeDefinitionResponseData> captor = 
                ArgumentCaptor.forClass(GetAttributeDefinitionResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
                eq(MetaTypeMessageType.GetAttributeDefinitionResponse), captor.capture());
        verify(m_ResponseWrapper).queue(channel);
        //parse response
        GetAttributeDefinitionResponseData response = captor.getValue();
        //verify that list of attribute is NOT empty
        assertThat(response.getBundleId(), is(0L));
        assertThat(response.getPid(), is("core-pid"));
        assertThat(response.getAttributeDefinitionCount(), is(1));
        
        //verify return values
        AttributeDefinitionType definition = response.getAttributeDefinitionList().get(0);
        assertThat(definition.getName(), is("Item1"));
        assertThat(definition.getId(), is("test"));
        assertThat(definition.getDescription(), is("description"));
        assertThat(definition.getDefaultValueCount(), is(1));
        assertThat(definition.getDefaultValueList().get(0), is("default"));
        assertThat(definition.getAttributeType(), is(AttributeDefinition.STRING));
        assertThat(definition.getCardinality(), is(1));
        assertThat(definition.getOptionLabelCount(), is(1));
        assertThat(definition.getOptionLabelList().get(0), is ("Item1Label"));
        assertThat(definition.getOptionValueList(), is(Arrays.asList("item1")));
    }
/**
     * Test that if the bundle id/pid return attributes that GetAttributeDefinitionRequest is properly handled.
     * This test is with a key.
     * 
     * Verify attributes fitting the bundle/pid pair and key is returned.
     */
Test that if the bundle id/pid return attributes that GetAttributeDefinitionRequest is properly handled.
This test is with a key.

Verify attributes fitting the bundle/pid pair and key is returned.
Test that if the bundle id / pid return attributes that GetAttributeDefinitionRequest is properly handled . This test is with a key . Verify attributes fitting the bundle / pid pair and key is returned .
@Test
    public void testGetAttributeDefinitionValidWithKey() 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 coreBundle = mock(Bundle.class);
        when(coreBundle.getBundleId()).thenReturn(0L);
        when(m_Context.getBundles()).thenReturn(new Bundle[] { bundleA, bundleC, bundleB, coreBundle});
        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[] {});
        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);
        GetAttributeDefinitionRequestData request = GetAttributeDefinitionRequestData.newBuilder().
            setBundleId(0).
            setPid("core-pid").
            setKey("test").build();
        TerraHarvestPayload payload = createPayload(request, MetaTypeMessageType.GetAttributeDefinitionRequest);
        TerraHarvestMessage message = createTerraHarvestMessage(request, MetaTypeMessageType.
            GetAttributeDefinitionRequest);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<GetAttributeDefinitionResponseData> captor = 
                ArgumentCaptor.forClass(GetAttributeDefinitionResponseData.class);
        verify(m_MessageFactory).createMetaTypeResponseMessage(eq(message), 
                eq(MetaTypeMessageType.GetAttributeDefinitionResponse), captor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetAttributeDefinitionResponseData response = captor.getValue();
        assertThat(response.getBundleId(), is(0L));
        assertThat(response.getPid(), is("core-pid"));
        assertThat(response.getAttributeDefinitionCount(), is(1));
        AttributeDefinitionType definition = response.getAttributeDefinitionList().get(0);
        assertThat(definition.getName(), is("Item1"));
        assertThat(definition.getId(), is("test"));
        assertThat(definition.getDescription(), is("description"));
        assertThat(definition.getDefaultValueCount(), is(1));
        assertThat(definition.getDefaultValueList().get(0), is("default"));
        assertThat(definition.getAttributeType(), is(AttributeDefinition.STRING));
        assertThat(definition.getCardinality(), is(1));
        assertThat(definition.getOptionLabelCount(), is(1));
        assertThat(definition.getOptionLabelList().get(0), is ("Item1Label"));
        assertThat(definition.getOptionValueList(), is(Arrays.asList("item1")));
    }
@ Test public void testGetAttributeDefinitionValidWithKey ( ) 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 coreBundle = mock ( Bundle . class ) ; when ( coreBundle . getBundleId ( ) ) . thenReturn ( 0L ) ; when ( m_Context . getBundles ( ) ) . thenReturn ( new Bundle [ ] { bundleA , bundleC , bundleB , coreBundle } ) ; 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 [ ] { } ) ; 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 ) ; GetAttributeDefinitionRequestData request = GetAttributeDefinitionRequestData . newBuilder ( ) . setBundleId ( 0 ) . setPid ( "core-pid" ) . setKey ( "test" ) . build ( ) ; TerraHarvestPayload payload = createPayload ( request , MetaTypeMessageType . GetAttributeDefinitionRequest ) ; TerraHarvestMessage message = createTerraHarvestMessage ( request , MetaTypeMessageType . GetAttributeDefinitionRequest ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < GetAttributeDefinitionResponseData > captor = ArgumentCaptor . forClass ( GetAttributeDefinitionResponseData . class ) ; verify ( m_MessageFactory ) . createMetaTypeResponseMessage ( eq ( message ) , eq ( MetaTypeMessageType . GetAttributeDefinitionResponse ) , captor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetAttributeDefinitionResponseData response = captor . getValue ( ) ; assertThat ( response . getBundleId ( ) , is ( 0L ) ) ; assertThat ( response . getPid ( ) , is ( "core-pid" ) ) ; assertThat ( response . getAttributeDefinitionCount ( ) , is ( 1 ) ) ; AttributeDefinitionType definition = response . getAttributeDefinitionList ( ) . get ( 0 ) ; assertThat ( definition . getName ( ) , is ( "Item1" ) ) ; assertThat ( definition . getId ( ) , is ( "test" ) ) ; assertThat ( definition . getDescription ( ) , is ( "description" ) ) ; assertThat ( definition . getDefaultValueCount ( ) , is ( 1 ) ) ; assertThat ( definition . getDefaultValueList ( ) . get ( 0 ) , is ( "default" ) ) ; assertThat ( definition . getAttributeType ( ) , is ( AttributeDefinition . STRING ) ) ; assertThat ( definition . getCardinality ( ) , is ( 1 ) ) ; assertThat ( definition . getOptionLabelCount ( ) , is ( 1 ) ) ; assertThat ( definition . getOptionLabelList ( ) . get ( 0 ) , is ( "Item1Label" ) ) ; assertThat ( definition . getOptionValueList ( ) , is ( Arrays . asList ( "item1" ) ) ) ; }
Test that if the bundle id/pid return attributes that GetAttributeDefinitionRequest is properly handled.
Test that if the bundle id / pid return attributes that GetAttributeDefinitionRequest is properly handled .
//mock bundles //mock meta type information for the bundles //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 attribute is NOT empty //verify return values