AzureIaasHandler implements TargetHandler { static AzureProperties buildProperties( Map<String,String> targetProperties ) throws TargetException { String[] properties = { AzureConstants.AZURE_SUBSCRIPTION_ID, AzureConstants.AZURE_KEY_STORE_FILE, AzureConstants.AZURE_KEY_STORE_PASSWORD, AzureConstants.AZURE_CREATE_CLOUD_SERVICE_TEMPLATE, AzureConstants.AZURE_CREATE_DEPLOYMENT_TEMPLATE, AzureConstants.AZURE_LOCATION, AzureConstants.AZURE_VM_SIZE, AzureConstants.AZURE_VM_TEMPLATE }; for( String property : properties ) { if( Utils.isEmptyOrWhitespaces( targetProperties.get( property ))) throw new TargetException( "The value for " + property + " cannot be null or empty." ); } AzureProperties azureProperties = new AzureProperties(); String s = targetProperties.get( AzureConstants.AZURE_SUBSCRIPTION_ID ); azureProperties.setSubscriptionId( s.trim()); s = targetProperties.get( AzureConstants.AZURE_KEY_STORE_FILE ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_KEY_STORE_PASSWORD ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_CREATE_CLOUD_SERVICE_TEMPLATE ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_CREATE_DEPLOYMENT_TEMPLATE ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_LOCATION ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_VM_SIZE ); azureProperties.setKeyStoreFile( s.trim()); s = targetProperties.get( AzureConstants.AZURE_VM_TEMPLATE ); azureProperties.setKeyStoreFile( s.trim()); return azureProperties; }  @Override String getTargetId(); @Override String createMachine( TargetHandlerParameters parameters ); @Override void configureMachine( TargetHandlerParameters parameters, String machineId ); @Override boolean isMachineRunning( TargetHandlerParameters parameters, String machineId ); @Override void terminateMachine( TargetHandlerParameters parameters, String instanceId ); @Override String retrievePublicIpAddress( TargetHandlerParameters parameters, String machineId ); static final String TARGET_ID; }
@Test( expected = TargetException.class ) public void testInvalidConfiguration() throws Exception { AzureIaasHandler.buildProperties( new HashMap<String,String> ()); }
@Test public void testValidConfiguration() throws Exception { Map<String,String> targetProperties = new HashMap<String,String> (); targetProperties.put( AzureConstants.AZURE_SUBSCRIPTION_ID, "my subscription id" ); targetProperties.put( AzureConstants.AZURE_KEY_STORE_FILE, "path to key store file" ); targetProperties.put( AzureConstants.AZURE_KEY_STORE_PASSWORD, "key store password" ); targetProperties.put( AzureConstants.AZURE_CREATE_CLOUD_SERVICE_TEMPLATE, "create cloud service template" ); targetProperties.put( AzureConstants.AZURE_CREATE_DEPLOYMENT_TEMPLATE, "create deployment template" ); targetProperties.put( AzureConstants.AZURE_LOCATION, "azure location" ); targetProperties.put( AzureConstants.AZURE_VM_SIZE, "azure VM size" ); targetProperties.put( AzureConstants.AZURE_VM_TEMPLATE, "azure VM template" ); AzureIaasHandler.buildProperties( targetProperties ); }