mil.dod.th.ose.gui.webapp/test/mil/dod/th/ose/gui/webapp/asset/TestAssetGetCommandMgrImpl.java
@Test
    public void testGetAssetCommands()
    {
        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);
        list.add(CommandTypeEnum.GET_TUNE_SETTINGS_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        
        AssetGetCommandModel commandModel = m_SUT.getAssetCommands(asset);
        assertThat(commandModel, notNullValue());
        assertThat(commandModel.getUuid(), is(uuid));
        assertThat(commandModel.getSupportedCommands().size(), is(2));
        
        //Update list of supported commands
        list.remove(CommandTypeEnum.GET_VERSION_COMMAND);
        list.add(CommandTypeEnum.GET_PROFILES_COMMAND);
        list.add(CommandTypeEnum.GET_MODE_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        
        //Verify model contains appropriate set of commands after being updated.
        commandModel = m_SUT.getAssetCommands(asset);
        assertThat(commandModel, notNullValue());
        assertThat(commandModel.getUuid(), is(uuid));
        assertThat(commandModel.getSupportedCommands().size(), is(2));
        assertThat(commandModel.getSupportedCommands(), containsInAnyOrder(CommandTypeEnum.GET_TUNE_SETTINGS_COMMAND,
                CommandTypeEnum.GET_PROFILES_COMMAND));
        
        AssetModel anotherAsset = mock(AssetModel.class);
        UUID uuid2 = UUID.randomUUID();
        when(anotherAsset.getControllerId()).thenReturn(CONTROLLER_ID);
        when(anotherAsset.getUuid()).thenReturn(uuid2);
        
        AssetGetCommandModel anotherModel = m_SUT.getAssetCommands(anotherAsset);
        assertThat(anotherModel, notNullValue());
        assertThat(anotherModel.getUuid(), is(uuid2));
        
        list.clear();
        list.add(CommandTypeEnum.SET_CAMERA_SETTINGS_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        
        anotherModel = m_SUT.getAssetCommands(anotherAsset);
        assertThat(anotherModel, nullValue());
    }
/**
     * Verify that correct command model is retrieved.
     */
Verify that correct command model is retrieved.
Verify that correct command model is retrieved .
@Test
    public void testGetAssetCommands()
    {
        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);
        list.add(CommandTypeEnum.GET_TUNE_SETTINGS_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        AssetGetCommandModel commandModel = m_SUT.getAssetCommands(asset);
        assertThat(commandModel, notNullValue());
        assertThat(commandModel.getUuid(), is(uuid));
        assertThat(commandModel.getSupportedCommands().size(), is(2));
        list.remove(CommandTypeEnum.GET_VERSION_COMMAND);
        list.add(CommandTypeEnum.GET_PROFILES_COMMAND);
        list.add(CommandTypeEnum.GET_MODE_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        commandModel = m_SUT.getAssetCommands(asset);
        assertThat(commandModel, notNullValue());
        assertThat(commandModel.getUuid(), is(uuid));
        assertThat(commandModel.getSupportedCommands().size(), is(2));
        assertThat(commandModel.getSupportedCommands(), containsInAnyOrder(CommandTypeEnum.GET_TUNE_SETTINGS_COMMAND,
                CommandTypeEnum.GET_PROFILES_COMMAND));
        AssetModel anotherAsset = mock(AssetModel.class);
        UUID uuid2 = UUID.randomUUID();
        when(anotherAsset.getControllerId()).thenReturn(CONTROLLER_ID);
        when(anotherAsset.getUuid()).thenReturn(uuid2);
        AssetGetCommandModel anotherModel = m_SUT.getAssetCommands(anotherAsset);
        assertThat(anotherModel, notNullValue());
        assertThat(anotherModel.getUuid(), is(uuid2));
        list.clear();
        list.add(CommandTypeEnum.SET_CAMERA_SETTINGS_COMMAND);
        when(capabilities.getSupportedCommands()).thenReturn(list);
        anotherModel = m_SUT.getAssetCommands(anotherAsset);
        assertThat(anotherModel, nullValue());
    }
@ Test public void testGetAssetCommands ( ) { 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 ) ; list . add ( CommandTypeEnum . GET_TUNE_SETTINGS_COMMAND ) ; when ( capabilities . getSupportedCommands ( ) ) . thenReturn ( list ) ; AssetGetCommandModel commandModel = m_SUT . getAssetCommands ( asset ) ; assertThat ( commandModel , notNullValue ( ) ) ; assertThat ( commandModel . getUuid ( ) , is ( uuid ) ) ; assertThat ( commandModel . getSupportedCommands ( ) . size ( ) , is ( 2 ) ) ; list . remove ( CommandTypeEnum . GET_VERSION_COMMAND ) ; list . add ( CommandTypeEnum . GET_PROFILES_COMMAND ) ; list . add ( CommandTypeEnum . GET_MODE_COMMAND ) ; when ( capabilities . getSupportedCommands ( ) ) . thenReturn ( list ) ; commandModel = m_SUT . getAssetCommands ( asset ) ; assertThat ( commandModel , notNullValue ( ) ) ; assertThat ( commandModel . getUuid ( ) , is ( uuid ) ) ; assertThat ( commandModel . getSupportedCommands ( ) . size ( ) , is ( 2 ) ) ; assertThat ( commandModel . getSupportedCommands ( ) , containsInAnyOrder ( CommandTypeEnum . GET_TUNE_SETTINGS_COMMAND , CommandTypeEnum . GET_PROFILES_COMMAND ) ) ; AssetModel anotherAsset = mock ( AssetModel . class ) ; UUID uuid2 = UUID . randomUUID ( ) ; when ( anotherAsset . getControllerId ( ) ) . thenReturn ( CONTROLLER_ID ) ; when ( anotherAsset . getUuid ( ) ) . thenReturn ( uuid2 ) ; AssetGetCommandModel anotherModel = m_SUT . getAssetCommands ( anotherAsset ) ; assertThat ( anotherModel , notNullValue ( ) ) ; assertThat ( anotherModel . getUuid ( ) , is ( uuid2 ) ) ; list . clear ( ) ; list . add ( CommandTypeEnum . SET_CAMERA_SETTINGS_COMMAND ) ; when ( capabilities . getSupportedCommands ( ) ) . thenReturn ( list ) ; anotherModel = m_SUT . getAssetCommands ( anotherAsset ) ; assertThat ( anotherModel , nullValue ( ) ) ; }
Verify that correct command model is retrieved.
Verify that correct command model is retrieved .
//Update list of supported commands //Verify model contains appropriate set of commands after being updated.