// Path: legacy-amazon/src/main/java/org/pentaho/amazon/client/ClientFactoriesManager.java
// public class ClientFactoriesManager {
// 
//   private Map<ClientType, AbstractClientFactory> clientFactoryMap;
//   private static ClientFactoriesManager instance;
// 
//   private ClientFactoriesManager() {
//     clientFactoryMap = new HashMap<>();
//     clientFactoryMap.put( ClientType.S3, new S3ClientFactory() );
//     clientFactoryMap.put( ClientType.EMR, new EmrClientFactory() );
//     clientFactoryMap.put( ClientType.AIM, new AimClientFactory() );
//     clientFactoryMap.put( ClientType.PRICING, new PricingClientFactory() );
//   }
// 
//   public static ClientFactoriesManager getInstance() {
//     if ( instance == null ) {
//       instance = new ClientFactoriesManager();
//     }
//     return instance;
//   }
// 
//   public <T> T createClient( String accessKey, String secretKey, String sessionToken, String region, ClientType clientType ) {
//     AbstractClientFactory clientFactory = getClientFactory( clientType );
//     T amazonClient = (T) clientFactory.createClient( accessKey, secretKey, sessionToken, region );
//     return amazonClient;
//   }
// 
//   private AbstractClientFactory getClientFactory( ClientType clientType ) {
//     if ( clientFactoryMap.containsKey( clientType ) ) {
//       return clientFactoryMap.get( clientType );
//     }
//     return null;
//   }
// }


import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.pentaho.amazon.client.ClientFactoriesManager;
import org.pentaho.amazon.client.ClientType;
import org.pentaho.amazon.client.api.PricingClient;
import org.pentaho.amazon.client.impl.AimClientImpl;
import org.pentaho.amazon.client.impl.PricingClientImpl;
import org.pentaho.amazon.hive.job.AmazonHiveJobExecutor;
import org.pentaho.amazon.hive.ui.AmazonHiveJobExecutorController;
import org.pentaho.di.ui.core.database.dialog.tags.ExtTextbox;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.binding.BindingFactory;
import org.pentaho.ui.xul.components.XulButton;
import org.pentaho.ui.xul.util.AbstractModelList;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
    AmazonHiveJobExecutorController hiveJobExecutorController =
      PowerMockito.spy( new AmazonHiveJobExecutorController( container, jobEntry, bindingFactory ) );

    when( hiveJobExecutorController.getXulDomContainer() ).thenReturn( container );
    when( container.getDocumentRoot().getElementById( "access-key" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "secret-key" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "session-token" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "emr-settings" ) ).thenReturn( btn );

    doNothing().when( btn ).setDisabled( true );
    doNothing().when( hiveJobExecutorController ).showErrorDialog( anyString(), anyString() );

    hiveJobExecutorController.getEmrSettings();

    verify( hiveJobExecutorController, times( 1 ) ).showErrorDialog( anyString(), anyString() );
  }

  @Test
  public void testGetEmrSettings_catchExceptionWhenRegionIsNull() {

    ExtTextbox textBox = mock( ExtTextbox.class );
    XulButton btn = mock( XulButton.class );

    XulDomContainer container = mock( XulDomContainer.class, RETURNS_DEEP_STUBS );

    AmazonHiveJobExecutorController hiveJobExecutorController =
      PowerMockito.spy( new AmazonHiveJobExecutorController( container, jobEntry, bindingFactory ) );

    when( hiveJobExecutorController.getXulDomContainer() ).thenReturn( container );
    when( container.getDocumentRoot().getElementById( "access-key" ) ).thenReturn( textBox );
// Path: legacy-amazon/src/main/java/org/pentaho/amazon/client/ClientFactoriesManager.java
// public class ClientFactoriesManager {
// 
//   private Map<ClientType, AbstractClientFactory> clientFactoryMap;
//   private static ClientFactoriesManager instance;
// 
//   private ClientFactoriesManager() {
//     clientFactoryMap = new HashMap<>();
//     clientFactoryMap.put( ClientType.S3, new S3ClientFactory() );
//     clientFactoryMap.put( ClientType.EMR, new EmrClientFactory() );
//     clientFactoryMap.put( ClientType.AIM, new AimClientFactory() );
//     clientFactoryMap.put( ClientType.PRICING, new PricingClientFactory() );
//   }
// 
//   public static ClientFactoriesManager getInstance() {
//     if ( instance == null ) {
//       instance = new ClientFactoriesManager();
//     }
//     return instance;
//   }
// 
//   public <T> T createClient( String accessKey, String secretKey, String sessionToken, String region, ClientType clientType ) {
//     AbstractClientFactory clientFactory = getClientFactory( clientType );
//     T amazonClient = (T) clientFactory.createClient( accessKey, secretKey, sessionToken, region );
//     return amazonClient;
//   }
// 
//   private AbstractClientFactory getClientFactory( ClientType clientType ) {
//     if ( clientFactoryMap.containsKey( clientType ) ) {
//       return clientFactoryMap.get( clientType );
//     }
//     return null;
//   }
// }


// Path: legacy-amazon/src/test/java/org/pentaho/amazon/AbstractAmazonJobExecutorControllerTest.java
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.pentaho.amazon.client.ClientFactoriesManager;
import org.pentaho.amazon.client.ClientType;
import org.pentaho.amazon.client.api.PricingClient;
import org.pentaho.amazon.client.impl.AimClientImpl;
import org.pentaho.amazon.client.impl.PricingClientImpl;
import org.pentaho.amazon.hive.job.AmazonHiveJobExecutor;
import org.pentaho.amazon.hive.ui.AmazonHiveJobExecutorController;
import org.pentaho.di.ui.core.database.dialog.tags.ExtTextbox;
import org.pentaho.ui.xul.XulDomContainer;
import org.pentaho.ui.xul.binding.BindingFactory;
import org.pentaho.ui.xul.components.XulButton;
import org.pentaho.ui.xul.util.AbstractModelList;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PowerMockIgnore;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;

    AmazonHiveJobExecutorController hiveJobExecutorController =
      PowerMockito.spy( new AmazonHiveJobExecutorController( container, jobEntry, bindingFactory ) );

    when( hiveJobExecutorController.getXulDomContainer() ).thenReturn( container );
    when( container.getDocumentRoot().getElementById( "access-key" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "secret-key" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "session-token" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "emr-settings" ) ).thenReturn( btn );

    doNothing().when( btn ).setDisabled( true );
    doNothing().when( hiveJobExecutorController ).showErrorDialog( anyString(), anyString() );

    hiveJobExecutorController.getEmrSettings();

    verify( hiveJobExecutorController, times( 1 ) ).showErrorDialog( anyString(), anyString() );
  }

  @Test
  public void testGetEmrSettings_catchExceptionWhenRegionIsNull() {

    ExtTextbox textBox = mock( ExtTextbox.class );
    XulButton btn = mock( XulButton.class );

    XulDomContainer container = mock( XulDomContainer.class, RETURNS_DEEP_STUBS );

    AmazonHiveJobExecutorController hiveJobExecutorController =
      PowerMockito.spy( new AmazonHiveJobExecutorController( container, jobEntry, bindingFactory ) );

    when( hiveJobExecutorController.getXulDomContainer() ).thenReturn( container );
    when( container.getDocumentRoot().getElementById( "access-key" ) ).thenReturn( textBox );
    when( container.getDocumentRoot().getElementById( "secret-key" ) ).thenReturn( textBox );