Ec2IaasHandler extends AbstractThreadedTargetHandler { static void parseProperties( Map<String, String> targetProperties ) throws TargetException { String[] properties = { Ec2Constants.EC2_ENDPOINT, Ec2Constants.EC2_ACCESS_KEY, Ec2Constants.EC2_SECRET_KEY, Ec2Constants.AMI_VM_NODE, Ec2Constants.VM_INSTANCE_TYPE, Ec2Constants.SSH_KEY_NAME, Ec2Constants.SECURITY_GROUP_NAME }; for( String property : properties ) { if( StringUtils.isBlank( targetProperties.get( property ))) throw new TargetException( "The value for " + property + " cannot be null or empty." ); } }  @Override String getTargetId(); @Override String createMachine( TargetHandlerParameters parameters ); @Override MachineConfigurator machineConfigurator( TargetHandlerParameters parameters, String machineId ); @Override boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ); @Override void terminateMachine( TargetHandlerParameters parameters, String machineId ); @Override String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ); static AmazonEC2 createEc2Client( Map<String,String> targetProperties ); static final String TARGET_ID; }
@Test( expected = TargetException.class ) public void testInvalidConfiguration() throws Exception { Ec2IaasHandler.parseProperties( new HashMap<String,String> ()); }
@Test public void testValidConfiguration() throws Exception { Map<String, String> targetProperties = new HashMap<String,String> (); targetProperties.put( Ec2Constants.EC2_ENDPOINT, "127.0.0.1" ); targetProperties.put( Ec2Constants.EC2_ACCESS_KEY, "my access key" ); targetProperties.put( Ec2Constants.EC2_SECRET_KEY, "my secret key" ); targetProperties.put( Ec2Constants.AMI_VM_NODE, "the node" ); targetProperties.put( Ec2Constants.VM_INSTANCE_TYPE, "tiny" ); targetProperties.put( Ec2Constants.SSH_KEY_NAME, "secret_key" ); targetProperties.put( Ec2Constants.SECURITY_GROUP_NAME, "WorldWideVisible" ); Ec2IaasHandler.parseProperties( targetProperties ); }