mil.dod.th.ose.remote/test/mil/dod/th/ose/remote/base/TestBaseMessageService.java
@Test
    public final void testGetControllerCapRequest() throws UnmarshalException, IOException, ObjectConverterException
    {
        
        BundleContext bundleContext = mock(BundleContext.class);
        when(bundleContext.getBundle(0)).thenReturn(Mockito.any(Bundle.class));
        m_SUT.activate(bundleContext);
        ControllerCapabilities capsProto = ControllerCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setProductName("something").
                    setDescription("someDescription")).
                setLowPowerModeSupported(false).setVoltageReported(false).
                setBatteryAmpHourReported(false).
                build();

        mil.dod.th.core.controller.capability.ControllerCapabilities capabilities = 
                mock (mil.dod.th.core.controller.capability.ControllerCapabilities.class);
        when(m_TerraHarvestController.getCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(capabilities)).thenReturn(capsProto);

        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.GetControllerCapabilitiesRequest).build();
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
        
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        
        // mock the channel the message came from
        RemoteChannel channel = mock(RemoteChannel.class);

        m_SUT.handleMessage(message, payload, channel);

        // verify event is posted
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        assertThat((String)eventCaptor.getValue().getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(baseNamespaceMessage.getType().toString()));
        
        ArgumentCaptor<GetControllerCapabilitiesResponseData> responseCaptor =
                ArgumentCaptor.forClass(GetControllerCapabilitiesResponseData.class);
        verify(m_MessageFactory).createBaseMessageResponse(eq(message), 
                eq(BaseMessageType.GetControllerCapabilitiesResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetControllerCapabilitiesResponseData response = responseCaptor.getValue();
        assertThat(response.getControllerCapabilitiesCase(), 
                is(ControllerCapabilitiesCase.CONTROLLERCAPABILITIESNATIVE));
        assertThat(response.getControllerCapabilitiesNative(), is(capsProto));  
    }
/**
     * Verify handling of get controller capabilities request.
     */
Verify handling of get controller capabilities request.
Verify handling of get controller capabilities request .
@Test
    public final void testGetControllerCapRequest() throws UnmarshalException, IOException, ObjectConverterException
    {
        BundleContext bundleContext = mock(BundleContext.class);
        when(bundleContext.getBundle(0)).thenReturn(Mockito.any(Bundle.class));
        m_SUT.activate(bundleContext);
        ControllerCapabilities capsProto = ControllerCapabilities.newBuilder().
                setBase(BaseCapabilitiesGen.BaseCapabilities.newBuilder().
                    setProductName("something").
                    setDescription("someDescription")).
                setLowPowerModeSupported(false).setVoltageReported(false).
                setBatteryAmpHourReported(false).
                build();
        mil.dod.th.core.controller.capability.ControllerCapabilities capabilities = 
                mock (mil.dod.th.core.controller.capability.ControllerCapabilities.class);
        when(m_TerraHarvestController.getCapabilities()).thenReturn(capabilities);
        when(m_Converter.convertToProto(capabilities)).thenReturn(capsProto);
        BaseNamespace baseNamespaceMessage = BaseNamespace.newBuilder().
                setType(BaseMessageType.GetControllerCapabilitiesRequest).build();
        TerraHarvestPayload payload = createPayload(baseNamespaceMessage);
        TerraHarvestMessage message = createBaseMessage(baseNamespaceMessage);
        RemoteChannel channel = mock(RemoteChannel.class);
        m_SUT.handleMessage(message, payload, channel);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        assertThat((String)eventCaptor.getValue().getProperty(RemoteConstants.EVENT_PROP_MESSAGE_TYPE), 
            is(baseNamespaceMessage.getType().toString()));
        ArgumentCaptor<GetControllerCapabilitiesResponseData> responseCaptor =
                ArgumentCaptor.forClass(GetControllerCapabilitiesResponseData.class);
        verify(m_MessageFactory).createBaseMessageResponse(eq(message), 
                eq(BaseMessageType.GetControllerCapabilitiesResponse), responseCaptor.capture());
        verify(m_ResponseWrapper).queue(channel);
        GetControllerCapabilitiesResponseData response = responseCaptor.getValue();
        assertThat(response.getControllerCapabilitiesCase(), 
                is(ControllerCapabilitiesCase.CONTROLLERCAPABILITIESNATIVE));
        assertThat(response.getControllerCapabilitiesNative(), is(capsProto));  
    }
@ Test public final void testGetControllerCapRequest ( ) throws UnmarshalException , IOException , ObjectConverterException { BundleContext bundleContext = mock ( BundleContext . class ) ; when ( bundleContext . getBundle ( 0 ) ) . thenReturn ( Mockito . any ( Bundle . class ) ) ; m_SUT . activate ( bundleContext ) ; ControllerCapabilities capsProto = ControllerCapabilities . newBuilder ( ) . setBase ( BaseCapabilitiesGen . BaseCapabilities . newBuilder ( ) . setProductName ( "something" ) . setDescription ( "someDescription" ) ) . setLowPowerModeSupported ( false ) . setVoltageReported ( false ) . setBatteryAmpHourReported ( false ) . build ( ) ; mil . dod . th . core . controller . capability . ControllerCapabilities capabilities = mock ( mil . dod . th . core . controller . capability . ControllerCapabilities . class ) ; when ( m_TerraHarvestController . getCapabilities ( ) ) . thenReturn ( capabilities ) ; when ( m_Converter . convertToProto ( capabilities ) ) . thenReturn ( capsProto ) ; BaseNamespace baseNamespaceMessage = BaseNamespace . newBuilder ( ) . setType ( BaseMessageType . GetControllerCapabilitiesRequest ) . build ( ) ; TerraHarvestPayload payload = createPayload ( baseNamespaceMessage ) ; TerraHarvestMessage message = createBaseMessage ( baseNamespaceMessage ) ; RemoteChannel channel = mock ( RemoteChannel . class ) ; m_SUT . handleMessage ( message , payload , channel ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; assertThat ( ( String ) eventCaptor . getValue ( ) . getProperty ( RemoteConstants . EVENT_PROP_MESSAGE_TYPE ) , is ( baseNamespaceMessage . getType ( ) . toString ( ) ) ) ; ArgumentCaptor < GetControllerCapabilitiesResponseData > responseCaptor = ArgumentCaptor . forClass ( GetControllerCapabilitiesResponseData . class ) ; verify ( m_MessageFactory ) . createBaseMessageResponse ( eq ( message ) , eq ( BaseMessageType . GetControllerCapabilitiesResponse ) , responseCaptor . capture ( ) ) ; verify ( m_ResponseWrapper ) . queue ( channel ) ; GetControllerCapabilitiesResponseData response = responseCaptor . getValue ( ) ; assertThat ( response . getControllerCapabilitiesCase ( ) , is ( ControllerCapabilitiesCase . CONTROLLERCAPABILITIESNATIVE ) ) ; assertThat ( response . getControllerCapabilitiesNative ( ) , is ( capsProto ) ) ; }
Verify handling of get controller capabilities request.
Verify handling of get controller capabilities request .
// mock the channel the message came from // verify event is posted