package hudson.plugins.ec2;

import hudson.slaves.NodeProperty;
import org.junit.Rule;
import org.junit.Test;
import org.jvnet.hudson.test.JenkinsRule;

import java.util.ArrayList;

import static org.junit.Assert.assertEquals;

public class EC2AbstractSlaveTest {

    @Rule
    public JenkinsRule r = new JenkinsRule();

    int timeoutInSecs = Integer.MAX_VALUE;

    @Test
    public void testGetLaunchTimeoutInMillisShouldNotOverflow() throws Exception {
        EC2AbstractSlave slave = new EC2AbstractSlave("name", "id", "description", "fs", 1, null, "label", null, null, "init", "tmpDir", new ArrayList<NodeProperty<?>>(), "root", "jvm", false, "idle", null, "cloud", false, Integer.MAX_VALUE, new UnixData("remote", null, null, "22"), ConnectionStrategy.PRIVATE_IP, -1) {
            @Override
            public void terminate() {
                // To change body of implemented methods use File | Settings |
                // File Templates.
            }

            @Override
            public String getEc2Type() {
                return null; // To change body of implemented methods use File |
                             // Settings | File Templates.
            }
        };

        assertEquals((long) timeoutInSecs * 1000, slave.getLaunchTimeoutInMillis());
    }
}

@@ -68,88 +68,269 @@
 ort 
-org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.jvnet.hudson.test.JenkinsRule;
+hudson.model.Node;%0Aimport java.util.ArrayList;%0Aimport java.util.List;%0Aimport org.junit.Rule;%0Aimport org.junit.Test;%0Aimport org.junit.Before;%0Aimport org.junit.After;%0Aimport org.jvnet.hudson.test.JenkinsRule;%0Aimport com.amazonaws.services.ec2.model.InstanceType;%0A
 %0A%0Aim
@@ -540,16 +540,227 @@
 VALUE;%0A%0A
+    @Before%0A    public void setUp() throws Exception %7B%0A        AmazonEC2Cloud.setTestMode(true);%0A    %7D%0A%0A    @After%0A    public void tearDown() throws Exception %7B%0A        AmazonEC2Cloud.setTestMode(false);%0A    %7D%0A%0A
     @Tes
@@ -836,32 +836,33 @@
 ows Exception %7B%0A
+%0A
         EC2Abstr
@@ -1674,11 +1674,1310 @@
 );%0A    %7D
+%0A%0A    @Test%0A    public void testMaxUsesBackwardCompat() throws Exception %7B%0A        final String description = %22description%22;%0A        SlaveTemplate orig = new SlaveTemplate(%22ami-123%22, EC2AbstractSlave.TEST_ZONE, null, %22default%22, %22foo%22, InstanceType.M1Large, false, %22ttt%22, Node.Mode.NORMAL, description, %22bar%22, %22bbb%22, %22aaa%22, %2210%22, %22fff%22, null, %22-Xmx1g%22, false, %22subnet 456%22, null, null, null, %22%22, true, false, false, %22%22, false, %22%22, false, false, false, ConnectionStrategy.PUBLIC_IP, -1);%0A        List%3CSlaveTemplate%3E templates = new ArrayList%3C%3E();%0A        templates.add(orig);%0A        AmazonEC2Cloud ac = new AmazonEC2Cloud(%22us-east-1%22, false, %22abc%22, %22us-east-1%22, %22ghi%22, %223%22, templates, null, null);%0A        r.jenkins.clouds.add(ac);%0A        EC2AbstractSlave slave = new EC2AbstractSlave(%22name%22, %22%22, description, %22fs%22, 1, null, %22label%22, null, null, %22init%22, %22tmpDir%22, new ArrayList%3CNodeProperty%3C?%3E%3E(), %22root%22, %22jvm%22, false, %22idle%22, null, %22ec2-us-east-1%22, false, Integer.MAX_VALUE, new UnixData(%22remote%22, null, null, %2222%22), ConnectionStrategy.PRIVATE_IP, 0)  %7B%0A            @Override%0A            public void terminate() %7B%0A            %7D%0A%0A            @Override%0A            public String getEc2Type() %7B%0A                return null;%0A            %7D%0A        %7D;%0A        assertEquals(-1, slave.maxTotalUses);%0A    %7D
 %0A%7D%0A

Add test