// Path: src/main/java/com/rmn/qa/AutomationConstants.java
// public interface AutomationConstants {
// 
//     // These NODE_CONFIG_* constants represent key names in the node configs
//     String CONFIG_CREATED_DATE = "createdDate";
//     String CONFIG_MAX_SESSION = "maxSession";
//     String CONFIG_BROWSER = "createdBrowser";
//     String CONFIG_OS = "createdOs";
//     // This is the value that will be in the desired capabilities that our node registers with
//     // Runtime value of the hub instance id that gets passed in as a system property.  Also used in the node config
//     String INSTANCE_ID = "instanceId";
//     // IP address of the hub that will be passed in as a system property
//     String IP_ADDRESS = "ipAddress";
//     // Test run UUID
//     String UUID = "uuid";
//     String WINDOWS_PROPERTY_NAME="node.windows.json";
//     String LINUX_PROPERTY_NAME="node.linux.json";
//     String EXTRA_CAPABILITIES_PROPERTY_NAME="extraCapabilities";
//     String AWS_ACCESS_KEY="awsAccessKey";
//     String AWS_PRIVATE_KEY="awsSecretKey";
//     String AWS_DEFAULT_RESOURCE_NAME= "aws.properties.default";
//     String REAPER_THREAD_CONFIG = "useReaperThread";
// }
// 
// Path: src/main/java/com/rmn/qa/NodesCouldNotBeStartedException.java
// public class NodesCouldNotBeStartedException extends Exception {
//     public NodesCouldNotBeStartedException(String msg) {
//         super(msg);
//     }
// 
//     public NodesCouldNotBeStartedException(String msg, Throwable t) {
//         super(msg,t);
//     }
// }


import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.InstanceState;
import com.amazonaws.services.ec2.model.InstanceStateChange;
import com.amazonaws.services.ec2.model.Reservation;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.amazonaws.services.ec2.model.RunInstancesResult;
import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
import com.amazonaws.services.ec2.model.TerminateInstancesResult;
import com.rmn.qa.AutomationConstants;
import com.rmn.qa.NodesCouldNotBeStartedException;
import junit.framework.Assert;
import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;
        properties.setProperty(region + "_key_name", keyName);
        properties.setProperty(region + "_windows_node_ami", windowsImage);
        manageEC2.setUserData(userData);
        try{
            manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
        } catch(NodesCouldNotBeStartedException e) {
            Assert.assertTrue("Failure message should be correct",e.getMessage().contains("Sufficient resources were not available in any of the availability zones"));
            return;
        }
        Assert.fail("Call should fail due to insufficient resources");
    }

    @Test
    //Tests that the client is initialized and exception is not thrown
    public void testClientInitialized(){
        AwsVmManager manageEC2 = new AwsVmManager();
        String region = "east";
        try{
            manageEC2.launchNodes("foo", "bar", 4, "userData", false);
        } catch(Exception e) {
            Assert.assertFalse("The client should be initialized",e.getMessage().contains("The client is not initialized"));
        }
    }

    @Test
    //Tests that if the client is not initialized, an exception with appropriate message is thrown
    public void testClientNotInitializedError(){
        String accessKey = "foo",privateKey = "bar";
        Properties properties = new Properties();
        properties.setProperty(AutomationConstants.AWS_ACCESS_KEY,accessKey);
// Path: src/main/java/com/rmn/qa/AutomationConstants.java
// public interface AutomationConstants {
// 
//     // These NODE_CONFIG_* constants represent key names in the node configs
//     String CONFIG_CREATED_DATE = "createdDate";
//     String CONFIG_MAX_SESSION = "maxSession";
//     String CONFIG_BROWSER = "createdBrowser";
//     String CONFIG_OS = "createdOs";
//     // This is the value that will be in the desired capabilities that our node registers with
//     // Runtime value of the hub instance id that gets passed in as a system property.  Also used in the node config
//     String INSTANCE_ID = "instanceId";
//     // IP address of the hub that will be passed in as a system property
//     String IP_ADDRESS = "ipAddress";
//     // Test run UUID
//     String UUID = "uuid";
//     String WINDOWS_PROPERTY_NAME="node.windows.json";
//     String LINUX_PROPERTY_NAME="node.linux.json";
//     String EXTRA_CAPABILITIES_PROPERTY_NAME="extraCapabilities";
//     String AWS_ACCESS_KEY="awsAccessKey";
//     String AWS_PRIVATE_KEY="awsSecretKey";
//     String AWS_DEFAULT_RESOURCE_NAME= "aws.properties.default";
//     String REAPER_THREAD_CONFIG = "useReaperThread";
// }
// 
// Path: src/main/java/com/rmn/qa/NodesCouldNotBeStartedException.java
// public class NodesCouldNotBeStartedException extends Exception {
//     public NodesCouldNotBeStartedException(String msg) {
//         super(msg);
//     }
// 
//     public NodesCouldNotBeStartedException(String msg, Throwable t) {
//         super(msg,t);
//     }
// }


// Path: src/test/java/com/rmn/qa/aws/VmManagerTest.java
import com.amazonaws.AmazonServiceException;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.services.ec2.model.Instance;
import com.amazonaws.services.ec2.model.InstanceState;
import com.amazonaws.services.ec2.model.InstanceStateChange;
import com.amazonaws.services.ec2.model.Reservation;
import com.amazonaws.services.ec2.model.RunInstancesRequest;
import com.amazonaws.services.ec2.model.RunInstancesResult;
import com.amazonaws.services.ec2.model.TerminateInstancesRequest;
import com.amazonaws.services.ec2.model.TerminateInstancesResult;
import com.rmn.qa.AutomationConstants;
import com.rmn.qa.NodesCouldNotBeStartedException;
import junit.framework.Assert;
import org.apache.commons.collections.CollectionUtils;
import org.junit.After;
import org.junit.Test;
import java.io.File;
import java.io.FileInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Properties;

        properties.setProperty(region + "_key_name", keyName);
        properties.setProperty(region + "_windows_node_ami", windowsImage);
        manageEC2.setUserData(userData);
        try{
            manageEC2.launchNodes(uuid,os,browser,null,threadCount,maxSessions);
        } catch(NodesCouldNotBeStartedException e) {
            Assert.assertTrue("Failure message should be correct",e.getMessage().contains("Sufficient resources were not available in any of the availability zones"));
            return;
        }
        Assert.fail("Call should fail due to insufficient resources");
    }

    @Test
    //Tests that the client is initialized and exception is not thrown
    public void testClientInitialized(){
        AwsVmManager manageEC2 = new AwsVmManager();
        String region = "east";
        try{
            manageEC2.launchNodes("foo", "bar", 4, "userData", false);
        } catch(Exception e) {
            Assert.assertFalse("The client should be initialized",e.getMessage().contains("The client is not initialized"));
        }
    }

    @Test
    //Tests that if the client is not initialized, an exception with appropriate message is thrown
    public void testClientNotInitializedError(){
        String accessKey = "foo",privateKey = "bar";
        Properties properties = new Properties();
        properties.setProperty(AutomationConstants.AWS_ACCESS_KEY,accessKey);
        properties.setProperty(AutomationConstants.AWS_PRIVATE_KEY,privateKey);