mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestAssetGetCommandMgrImpl.java
@Test
    public void testCommandResponseHandler()
    {
        AsyncCommandResponseEventHandler eventHandler = m_SUT.new AsyncCommandResponseEventHandler();
        
        AssetModel asset = mock(AssetModel.class);
        UUID uuid = UUID.randomUUID();
        when(asset.getControllerId()).thenReturn(CONTROLLER_ID);
        when(asset.getUuid()).thenReturn(uuid);
        
        //set up the command map
        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);
        
        //initializing...
        m_SUT.getAssetCommands(asset);
        
        //converter mocking
        when(m_CommandConverter.getCommandResponseEnumFromClassName(GetVersionResponse.class.getName())).
            thenReturn(CommandResponseEnum.GET_VERSION_RESPONSE);
        when(m_CommandConverter.getCommandTypeFromResponseType(CommandResponseEnum.GET_VERSION_RESPONSE)).
            thenReturn(CommandTypeEnum.GET_VERSION_COMMAND);
        
        GetVersionResponse versionResponse = new GetVersionResponse(null, null, "version");
        Map<String, Object> map = new HashMap<>();
        map.put(RemoteConstants.REMOTE_EVENT_PROP_CONTROLLER_ID, CONTROLLER_ID);
        map.put(FactoryDescriptor.EVENT_PROP_OBJ_UUID, uuid.toString());
        map.put(Asset.EVENT_PROP_ASSET_COMMAND_RESPONSE_TYPE, GetVersionResponse.class.getName());
        map.put(Asset.EVENT_PROP_ASSET_COMMAND_RESPONSE, versionResponse);
        
        Event event = new Event("topic", map);
        
        eventHandler.handleEvent(event);
        
        //verify data
        AssetGetCommandModel getModel = m_SUT.getAssetCommands(asset);
        assertThat(getModel.getCommandResponseByType(CommandTypeEnum.GET_VERSION_COMMAND), is(notNullValue()));
        assertThat(getModel.getCommandResponseByType(CommandTypeEnum.GET_VERSION_COMMAND).printResponseMessage(), 
                is(versionResponse.toString()));
    }
/**
     * Verify command response handler processes event data correctly.
     */
Verify command response handler processes event data correctly.
Verify command response handler processes event data correctly .
@Test
    public void testCommandResponseHandler()
    {
        AsyncCommandResponseEventHandler eventHandler = m_SUT.new AsyncCommandResponseEventHandler();
        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);
        when(m_CommandConverter.getCommandResponseEnumFromClassName(GetVersionResponse.class.getName())).
            thenReturn(CommandResponseEnum.GET_VERSION_RESPONSE);
        when(m_CommandConverter.getCommandTypeFromResponseType(CommandResponseEnum.GET_VERSION_RESPONSE)).
            thenReturn(CommandTypeEnum.GET_VERSION_COMMAND);
        GetVersionResponse versionResponse = new GetVersionResponse(null, null, "version");
        Map<String, Object> map = new HashMap<>();
        map.put(RemoteConstants.REMOTE_EVENT_PROP_CONTROLLER_ID, CONTROLLER_ID);
        map.put(FactoryDescriptor.EVENT_PROP_OBJ_UUID, uuid.toString());
        map.put(Asset.EVENT_PROP_ASSET_COMMAND_RESPONSE_TYPE, GetVersionResponse.class.getName());
        map.put(Asset.EVENT_PROP_ASSET_COMMAND_RESPONSE, versionResponse);
        Event event = new Event("topic", map);
        eventHandler.handleEvent(event);
        AssetGetCommandModel getModel = m_SUT.getAssetCommands(asset);
        assertThat(getModel.getCommandResponseByType(CommandTypeEnum.GET_VERSION_COMMAND), is(notNullValue()));
        assertThat(getModel.getCommandResponseByType(CommandTypeEnum.GET_VERSION_COMMAND).printResponseMessage(), 
                is(versionResponse.toString()));
    }
@ Test public void testCommandResponseHandler ( ) { AsyncCommandResponseEventHandler eventHandler = m_SUT . new AsyncCommandResponseEventHandler ( ) ; 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 ) ; when ( m_CommandConverter . getCommandResponseEnumFromClassName ( GetVersionResponse . class . getName ( ) ) ) . thenReturn ( CommandResponseEnum . GET_VERSION_RESPONSE ) ; when ( m_CommandConverter . getCommandTypeFromResponseType ( CommandResponseEnum . GET_VERSION_RESPONSE ) ) . thenReturn ( CommandTypeEnum . GET_VERSION_COMMAND ) ; GetVersionResponse versionResponse = new GetVersionResponse ( null , null , "version" ) ; Map < String , Object > map = new HashMap < > ( ) ; map . put ( RemoteConstants . REMOTE_EVENT_PROP_CONTROLLER_ID , CONTROLLER_ID ) ; map . put ( FactoryDescriptor . EVENT_PROP_OBJ_UUID , uuid . toString ( ) ) ; map . put ( Asset . EVENT_PROP_ASSET_COMMAND_RESPONSE_TYPE , GetVersionResponse . class . getName ( ) ) ; map . put ( Asset . EVENT_PROP_ASSET_COMMAND_RESPONSE , versionResponse ) ; Event event = new Event ( "topic" , map ) ; eventHandler . handleEvent ( event ) ; AssetGetCommandModel getModel = m_SUT . getAssetCommands ( asset ) ; assertThat ( getModel . getCommandResponseByType ( CommandTypeEnum . GET_VERSION_COMMAND ) , is ( notNullValue ( ) ) ) ; assertThat ( getModel . getCommandResponseByType ( CommandTypeEnum . GET_VERSION_COMMAND ) . printResponseMessage ( ) , is ( versionResponse . toString ( ) ) ) ; }
Verify command response handler processes event data correctly.
Verify command response handler processes event data correctly .
//set up the command map //initializing... //converter mocking //verify data