mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/osgi/TestMetatypeMessageService.java
@Test
    public void testGetAttributKeysInvalid() 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});
       
        //send message
        GetAttributeKeysRequestData request = GetAttributeKeysRequestData.newBuilder().
            setBundleId(900).
            setPid("my 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, verify error code
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        verify(m_ResponseWrapper).queue(channel);
        
        // verify event is posted for get attribute key request
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.MetaType.
                toString()));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(MetaTypeMessageType.GetAttributeKeyRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((MetaTypeNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(getNamespaceMessage(message)));
    }
/**
    * Test that if the bundle id/pid do not return attributes that the GetAttributeKeysRequest is handled properly.
    * 
    * Verify message with generic error code INVALID_VALUE is sent in response to the request.
    * 
    * Verify event is posted with correct data message.
    */
Test that if the bundle id/pid do not return attributes that the GetAttributeKeysRequest is handled properly.

Verify message with generic error code INVALID_VALUE is sent in response to the request.

Verify event is posted with correct data message.
Test that if the bundle id / pid do not return attributes that the GetAttributeKeysRequest is handled properly . Verify message with generic error code INVALID_VALUE is sent in response to the request . Verify event is posted with correct data message .
@Test
    public void testGetAttributKeysInvalid() 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});
        GetAttributeKeysRequestData request = GetAttributeKeysRequestData.newBuilder().
            setBundleId(900).
            setPid("my 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);
        verify(m_MessageFactory).createBaseErrorMessage(eq(message), eq(ErrorCode.INVALID_VALUE), Mockito.anyString());
        verify(m_ResponseWrapper).queue(channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event postedEvent = eventCaptor.getValue();
        assertThat(postedEvent.getTopic(), is(RemoteConstants.TOPIC_MESSAGE_RECEIVED));
        assertThat((TerraHarvestMessage)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE), is(message));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_SOURCE_ID), is(0));
        assertThat((Integer)postedEvent.getProperty(RemoteConstants.EVENT_PROP_DEST_ID), is(1));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE), is(Namespace.MetaType.
                toString()));
        assertThat((String)postedEvent.getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
                is(MetaTypeMessageType.GetAttributeKeyRequest.toString()));
        assertThat((RemoteChannel)postedEvent.getProperty(RemoteConstants.EVENT_PROP_CHANNEL), is(channel));
        assertThat((MetaTypeNamespace)postedEvent.getProperty(RemoteConstants.EVENT_PROP_NAMESPACE_MESSAGE), 
                is(getNamespaceMessage(message)));
    }
@ Test public void testGetAttributKeysInvalid ( ) 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 } ) ; GetAttributeKeysRequestData request = GetAttributeKeysRequestData . newBuilder ( ) . setBundleId ( 900 ) . setPid ( "my 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 ) ; verify ( m_MessageFactory ) . createBaseErrorMessage ( eq ( message ) , eq ( ErrorCode . INVALID_VALUE ) , Mockito . anyString ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event postedEvent = eventCaptor . getValue ( ) ; assertThat ( postedEvent . getTopic ( ) , is ( RemoteConstants . TOPIC_MESSAGE_RECEIVED ) ) ; assertThat ( ( TerraHarvestMessage ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE ) , is ( message ) ) ; assertThat ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_SOURCE_ID ) , is ( 0 ) ) ; assertThat ( ( Integer ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_DEST_ID ) , is ( 1 ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE ) , is ( Namespace . MetaType . toString ( ) ) ) ; assertThat ( ( String ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( MetaTypeMessageType . GetAttributeKeyRequest . toString ( ) ) ) ; assertThat ( ( RemoteChannel ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_CHANNEL ) , is ( channel ) ) ; assertThat ( ( MetaTypeNamespace ) postedEvent . getProperty ( RemoteConstants . EVENT_PROP_NAMESPACE_MESSAGE ) , is ( getNamespaceMessage ( message ) ) ) ; }
Test that if the bundle id/pid do not return attributes that the GetAttributeKeysRequest is handled properly.
Test that if the bundle id / pid do not return attributes that the GetAttributeKeysRequest is handled properly .
//mock bundles //send message //mock the channel the message came from // handle the message //capture the message, verify error code // verify event is posted for get attribute key request