From f00ba833fda73666da4aedcaa5b0236e2fa8e0c0 Mon Sep 17 00:00:00 2001 From: Artem Stasiuk Date: Fri, 21 Jun 2019 14:24:54 -0700 Subject: [PATCH] Fix tests --- .../ec2fleet/ProvisionIntegrationTest.java | 62 ++----------------- 1 file changed, 5 insertions(+), 57 deletions(-) diff --git a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java index ed8ba67d..e99b33dc 100644 --- a/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java +++ b/src/test/java/com/amazon/jenkins/ec2fleet/ProvisionIntegrationTest.java @@ -10,7 +10,6 @@ import com.amazonaws.services.ec2.model.DescribeSpotFleetRequestsResult; import com.amazonaws.services.ec2.model.Instance; import com.amazonaws.services.ec2.model.ModifySpotFleetRequestRequest; -import com.amazonaws.services.ec2.model.ModifySpotFleetRequestResult; import com.amazonaws.services.ec2.model.Reservation; import com.amazonaws.services.ec2.model.SpotFleetRequestConfig; import com.amazonaws.services.ec2.model.SpotFleetRequestConfigData; @@ -32,6 +31,7 @@ import org.junit.Test; import org.jvnet.hudson.test.BuildWatcher; import org.jvnet.hudson.test.JenkinsRule; +import org.mockito.Mockito; import org.mockito.invocation.InvocationOnMock; import org.mockito.stubbing.Answer; @@ -43,7 +43,6 @@ import java.util.Set; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; -import java.util.logging.Logger; import static org.mockito.ArgumentMatchers.any; import static org.mockito.ArgumentMatchers.anyString; @@ -58,57 +57,6 @@ public class ProvisionIntegrationTest { @ClassRule public static BuildWatcher bw = new BuildWatcher(); - private static class MockAmazonEC2 extends EmptyAmazonEC2 { - - private static final Logger LOGGER = Logger.getLogger(MockAmazonEC2.class.getName()); - - private volatile int targetCapacity = 0; - - @Override - public DescribeInstancesResult describeInstances(DescribeInstancesRequest request) { - Reservation reservation = new Reservation(); - if (request.getInstanceIds().size() > 0) { - reservation.setInstances(Arrays.asList(new Instance() - .withInstanceId(request.getInstanceIds().get(0)) - .withPublicIpAddress("public-ip") - )); - } - List reservations = new ArrayList<>(); - reservations.add(reservation); - return new DescribeInstancesResult().withReservations(reservations); - } - - @Override - public DescribeSpotFleetInstancesResult describeSpotFleetInstances(DescribeSpotFleetInstancesRequest request) { - LOGGER.info("Describe spot fleet instances with target capacity " + targetCapacity); - DescribeSpotFleetInstancesResult result = new DescribeSpotFleetInstancesResult(); - List activeInstances = new ArrayList<>(); - for (int i = 0; i < targetCapacity; i++) { - activeInstances.add(new ActiveInstance().withInstanceId("i-" + i)); - } - result.setActiveInstances(activeInstances); - return result; - } - - @Override - public DescribeSpotFleetRequestsResult describeSpotFleetRequests(DescribeSpotFleetRequestsRequest request) { - LOGGER.info("Describe spot fleet requests"); - return new DescribeSpotFleetRequestsResult().withSpotFleetRequestConfigs(Arrays.asList( - new SpotFleetRequestConfig() - .withSpotFleetRequestState("active") - .withSpotFleetRequestConfig( - new SpotFleetRequestConfigData().withTargetCapacity(0)))); - } - - @Override - public ModifySpotFleetRequestResult modifySpotFleetRequest(ModifySpotFleetRequestRequest request) { - LOGGER.info("Set target capacity to " + request.getTargetCapacity()); - targetCapacity = request.getTargetCapacity(); - return null; - } - - } - @After public void after() { // restore @@ -130,7 +78,7 @@ public void should_not_do_anything_if_fleet_is_empty_and_max_size_isreached() th Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2); + when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeSpotFleetInstances(any(DescribeSpotFleetInstancesRequest.class))) .thenReturn(new DescribeSpotFleetInstancesResult()); @@ -170,7 +118,7 @@ public void should_add_planned_if_capacity_required_but_not_described_yet() thro Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2); + when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))) .thenReturn(new DescribeInstancesResult()); @@ -239,7 +187,7 @@ public void should_convert_planed_to_node_if_describe_instance() throws Exceptio Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2); + when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))) .then(new Answer() { @@ -321,7 +269,7 @@ public void should_not_convert_planned_to_node_if_state_is_not_running_and_check Registry.setEc2Api(ec2Api); AmazonEC2 amazonEC2 = mock(AmazonEC2.class); - when(ec2Api.connect(anyString(), anyString(), anyString())).thenReturn(amazonEC2); + when(ec2Api.connect(anyString(), anyString(), Mockito.nullable(String.class))).thenReturn(amazonEC2); when(amazonEC2.describeInstances(any(DescribeInstancesRequest.class))) .then(new Answer() {