mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestAssetGetCommandMgrImpl.java
@Test
    public void testCommandHandler() throws InvalidProtocolBufferException, ObjectConverterException
    {
        CommandEventHandler eventHandler = m_SUT.new CommandEventHandler();
        
        AssetModel asset = mock(AssetModel.class);
        UUID uuid = UUID.randomUUID();
        when(asset.getControllerId()).thenReturn(CONTROLLER_ID);
        when(asset.getUuid()).thenReturn(uuid);
        
        AssetCapabilities assetCaps = mock(AssetCapabilities.class);
        CommandCapabilities capabilities = mock(CommandCapabilities.class);
        AssetFactoryModel fModel = mock(AssetFactoryModel.class);
        when(m_AssetTypesMgr.getAssetFactoryForClassAsync(eq(CONTROLLER_ID), Mockito.anyString()))
            .thenReturn(fModel);
        
        when(fModel.getFactoryCaps()).thenReturn(assetCaps);
        when(assetCaps.getCommandCapabilities()).thenReturn(capabilities);
        
        List<CommandTypeEnum> list = new ArrayList<CommandTypeEnum>();
        list.add(CommandTypeEnum.GET_VERSION_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        
        m_SUT.getAssetCommands(asset);
        
        Response theResponse = mock(Response.class);
        when(m_CommandConverter.getJavaResponseType(Mockito.any(byte[].class), 
                Mockito.any(CommandResponseEnum.class))).thenReturn(theResponse);
        when(m_CommandConverter.getCommandTypeFromResponseType(
                Mockito.any(CommandResponseEnum.class))).thenReturn(CommandTypeEnum.GET_VERSION_COMMAND);
        
        ExecuteCommandResponseData dataMsg = createVersionResponseMessage(uuid);
        
        Map<String, Object> map = new HashMap<>();
        map.put(RemoteConstants.EVENT_PROP_SOURCE_ID, CONTROLLER_ID);
        map.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, dataMsg);
        
        Event event = new Event("topic", map);
        
        eventHandler.handleEvent(event);
        
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        
        Event capturedEvent = eventCaptor.getValue();
        assertThat(capturedEvent, notNullValue());
        assertThat(capturedEvent.getTopic(), is(AssetGetCommandMgr.TOPIC_GET_RESPONSE_RECEIVED));
    }
/*
     * Verify command handler processes response data correctly.
     */
Verify command handler processes response data correctly.
Verify command handler processes response data correctly .
@Test
    public void testCommandHandler() throws InvalidProtocolBufferException, ObjectConverterException
    {
        CommandEventHandler eventHandler = m_SUT.new CommandEventHandler();
        AssetModel asset = mock(AssetModel.class);
        UUID uuid = UUID.randomUUID();
        when(asset.getControllerId()).thenReturn(CONTROLLER_ID);
        when(asset.getUuid()).thenReturn(uuid);
        AssetCapabilities assetCaps = mock(AssetCapabilities.class);
        CommandCapabilities capabilities = mock(CommandCapabilities.class);
        AssetFactoryModel fModel = mock(AssetFactoryModel.class);
        when(m_AssetTypesMgr.getAssetFactoryForClassAsync(eq(CONTROLLER_ID), Mockito.anyString()))
            .thenReturn(fModel);
        when(fModel.getFactoryCaps()).thenReturn(assetCaps);
        when(assetCaps.getCommandCapabilities()).thenReturn(capabilities);
        List<CommandTypeEnum> list = new ArrayList<CommandTypeEnum>();
        list.add(CommandTypeEnum.GET_VERSION_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        m_SUT.getAssetCommands(asset);
        Response theResponse = mock(Response.class);
        when(m_CommandConverter.getJavaResponseType(Mockito.any(byte[].class), 
                Mockito.any(CommandResponseEnum.class))).thenReturn(theResponse);
        when(m_CommandConverter.getCommandTypeFromResponseType(
                Mockito.any(CommandResponseEnum.class))).thenReturn(CommandTypeEnum.GET_VERSION_COMMAND);
        ExecuteCommandResponseData dataMsg = createVersionResponseMessage(uuid);
        Map<String, Object> map = new HashMap<>();
        map.put(RemoteConstants.EVENT_PROP_SOURCE_ID, CONTROLLER_ID);
        map.put(RemoteConstants.EVENT_PROP_DATA_MESSAGE, dataMsg);
        Event event = new Event("topic", map);
        eventHandler.handleEvent(event);
        ArgumentCaptor<Event> eventCaptor = ArgumentCaptor.forClass(Event.class);
        verify(m_EventAdmin).postEvent(eventCaptor.capture());
        Event capturedEvent = eventCaptor.getValue();
        assertThat(capturedEvent, notNullValue());
        assertThat(capturedEvent.getTopic(), is(AssetGetCommandMgr.TOPIC_GET_RESPONSE_RECEIVED));
    }
@ Test public void testCommandHandler ( ) throws InvalidProtocolBufferException , ObjectConverterException { CommandEventHandler eventHandler = m_SUT . new CommandEventHandler ( ) ; AssetModel asset = mock ( AssetModel . class ) ; UUID uuid = UUID . randomUUID ( ) ; when ( asset . getControllerId ( ) ) . thenReturn ( CONTROLLER_ID ) ; when ( asset . getUuid ( ) ) . thenReturn ( uuid ) ; AssetCapabilities assetCaps = mock ( AssetCapabilities . class ) ; CommandCapabilities capabilities = mock ( CommandCapabilities . class ) ; AssetFactoryModel fModel = mock ( AssetFactoryModel . class ) ; when ( m_AssetTypesMgr . getAssetFactoryForClassAsync ( eq ( CONTROLLER_ID ) , Mockito . anyString ( ) ) ) . thenReturn ( fModel ) ; when ( fModel . getFactoryCaps ( ) ) . thenReturn ( assetCaps ) ; when ( assetCaps . getCommandCapabilities ( ) ) . thenReturn ( capabilities ) ; List < CommandTypeEnum > list = new ArrayList < CommandTypeEnum > ( ) ; list . add ( CommandTypeEnum . GET_VERSION_COMMAND ) ; when ( capabilities . getSupportedCommands ( ) ) . thenReturn ( list ) ; m_SUT . getAssetCommands ( asset ) ; Response theResponse = mock ( Response . class ) ; when ( m_CommandConverter . getJavaResponseType ( Mockito . any ( byte [ ] . class ) , Mockito . any ( CommandResponseEnum . class ) ) ) . thenReturn ( theResponse ) ; when ( m_CommandConverter . getCommandTypeFromResponseType ( Mockito . any ( CommandResponseEnum . class ) ) ) . thenReturn ( CommandTypeEnum . GET_VERSION_COMMAND ) ; ExecuteCommandResponseData dataMsg = createVersionResponseMessage ( uuid ) ; Map < String , Object > map = new HashMap < > ( ) ; map . put ( RemoteConstants . EVENT_PROP_SOURCE_ID , CONTROLLER_ID ) ; map . put ( RemoteConstants . EVENT_PROP_DATA_MESSAGE , dataMsg ) ; Event event = new Event ( "topic" , map ) ; eventHandler . handleEvent ( event ) ; ArgumentCaptor < Event > eventCaptor = ArgumentCaptor . forClass ( Event . class ) ; verify ( m_EventAdmin ) . postEvent ( eventCaptor . capture ( ) ) ; Event capturedEvent = eventCaptor . getValue ( ) ; assertThat ( capturedEvent , notNullValue ( ) ) ; assertThat ( capturedEvent . getTopic ( ) , is ( AssetGetCommandMgr . TOPIC_GET_RESPONSE_RECEIVED ) ) ; }
Verify command handler processes response data correctly.
Verify command handler processes response data correctly .