package de.codecentric.jenkins.dashboard.ec2;

import static org.junit.Assert.assertTrue;

import java.util.List;

import org.junit.Ignore;
import org.junit.Test;
import org.springframework.util.StringUtils;

import com.amazonaws.auth.AWSCredentials;
import com.amazonaws.auth.BasicAWSCredentials;
import com.amazonaws.regions.Region;
import com.amazonaws.regions.Regions;

import de.codecentric.jenkins.dashboard.api.environment.ServerEnvironment;

/**
 * Add your AWS credentials to run these integration tests 
 * 
 * @author marcel.birkner
 * 
 */
@Ignore
public class EC2ConnectorTest {

	// FILL OUT AWS CREDENTIALS BEFORE RUNNING THE INTEGRATION TESTS
	private String awsAccessKey = "";
	private String awsSecretKey = "";
	// END
	
	private AWSCredentials awsCredentials = new BasicAWSCredentials(awsAccessKey, awsSecretKey);
	
	@Test
	public void testGetEnvironments() {
		assertTrue("Please provide your AWS credentials before running the tests.", StringUtils.hasText(awsAccessKey));
		assertTrue("Please provide your AWS credentials before running the tests.", StringUtils.hasText(awsSecretKey));
		
		EC2Connector env = new EC2Connector(awsCredentials);
		Region region = Region.getRegion(Regions.EU_WEST_1);
		List<ServerEnvironment> list = env.getEnvironments(region);
		assertTrue(list.size() > 0);
	}

	@Test
	public void testGetEnvironmentsByTag() {
		assertTrue("Please provide your AWS credentials before running the tests.", StringUtils.hasText(awsAccessKey));
		assertTrue("Please provide your AWS credentials before running the tests.", StringUtils.hasText(awsSecretKey));
		
		EC2Connector env = new EC2Connector(awsCredentials);
		Region region = Region.getRegion(Regions.EU_WEST_1);
		List<ServerEnvironment> list = env.getEnvironmentsByTag(region, "ALE_PROD_A");
		assertTrue(list.size() == 1);

	}
}

@@ -38,19 +38,17 @@
 ard.ec2;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -82,19 +82,17 @@
 ertTrue;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -106,19 +106,17 @@
 il.List;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -132,17 +132,16 @@
 .Ignore;
-%0D
 %0Aimport 
@@ -155,17 +155,16 @@
 it.Test;
-%0D
 %0Aimport 
@@ -200,19 +200,17 @@
 ngUtils;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -235,33 +235,32 @@
 .AWSCredentials;
-%0D
 %0Aimport com.amaz
@@ -290,17 +290,16 @@
 entials;
-%0D
 %0Aimport 
@@ -327,17 +327,16 @@
 .Region;
-%0D
 %0Aimport 
@@ -365,19 +365,17 @@
 Regions;
-%0D%0A%0D
+%0A
 %0Aimport 
@@ -445,16 +445,13 @@
 ent;
-%0D%0A%0D
+%0A
 %0A/**
-%0D
 %0A * 
@@ -506,22 +506,20 @@
 n tests 
-%0D
 %0A * 
-%0D
 %0A * @aut
@@ -540,27 +540,24 @@
 kner
-%0D
 %0A * 
-%0D
 %0A */
-%0D
 %0A@Ignore
 %0D%0Apu
@@ -552,17 +552,16 @@
 %0A@Ignore
-%0D
 %0Apublic 
@@ -584,19 +584,17 @@
 orTest %7B
-%0D%0A%0D
+%0A
 %0A%09// FIL
@@ -651,17 +651,16 @@
 ON TESTS
-%0D
 %0A%09privat
@@ -686,17 +686,16 @@
 ey = %22%22;
-%0D
 %0A%09privat
@@ -725,17 +725,16 @@
  %22%22;
-%0D
 %0A%09// END
 %0D%0A%09%0D
@@ -729,20 +729,18 @@
 %0A%09// END
-%0D
 %0A%09
-%0D
 %0A%09privat
@@ -829,20 +829,17 @@
 ey);
-%0D
 %0A%09
-%0D
 %0A%09@Test
-%0D
 %0A%09pu
@@ -867,25 +867,24 @@
 ronments() %7B
-%0D
 %0A%09%09assertTru
@@ -977,33 +977,32 @@
 (awsAccessKey));
-%0D
 %0A%09%09assertTrue(%22P
@@ -1091,37 +1091,35 @@
 (awsSecretKey));
-%0D
 %0A%09%09
-%0D
 %0A%09%09EC2Connector 
@@ -1149,33 +1149,32 @@
 awsCredentials);
-%0D
 %0A%09%09Region region
@@ -1204,33 +1204,32 @@
 ions.EU_WEST_1);
-%0D
 %0A%09%09List%3CServerEn
@@ -1274,17 +1274,16 @@
 region);
-%0D
 %0A%09%09asser
@@ -1309,23 +1309,19 @@
  0);
-%0D
 %0A%09%7D
-%0D%0A%0D
+%0A
 %0A%09@Test
-%0D
 %0A%09pu
@@ -1358,17 +1358,16 @@
 yTag() %7B
-%0D
 %0A%09%09asser
@@ -1472,17 +1472,16 @@
 ssKey));
-%0D
 %0A%09%09asser
@@ -1590,13 +1590,11 @@
 y));
-%0D
 %0A%09%09
-%0D
 %0A%09%09E
@@ -1644,17 +1644,16 @@
 ntials);
-%0D
 %0A%09%09Regio
@@ -1699,17 +1699,16 @@
 WEST_1);
-%0D
 %0A%09%09List%3C
@@ -1780,17 +1780,16 @@
 ROD_A%22);
-%0D
 %0A%09%09asser
@@ -1816,15 +1816,11 @@
  1);
-%0D%0A%0D
+%0A
 %0A%09%7D
-%0D
 %0A%7D
-%0D
 %0A

update test