package com.nirima.jenkins.plugins.docker;

import org.junit.Test;
import static org.junit.Assert.*;
import hudson.model.Node;

public class DockerTemplateTest {

    private DockerTemplate getDockerTemplateInstanceWithDNSHost(String dnsString) {
        DockerTemplate instance = new DockerTemplate("image", null, "remoteFs", "remoteFsMapping", "credentialsId", "idleTerminationMinutes", "sshLaunchTimeoutMinutes", " jvmOptions", " javaPath", 1024, 1000, "prefixStartSlaveCmd", " suffixStartSlaveCmd", "", dnsString, "dockerCommand", "volumes", "volumesFrom", "environmentsString", "lxcConf", "hostname", "0.0.0.0:22", true, false);
        return instance;
    }

    @Test
    public void testDnsHosts() {
        DockerTemplate instance;
        String[] expected;

        instance = getDockerTemplateInstanceWithDNSHost("");
        assertEquals(0, instance.dnsHosts.length);

        instance = getDockerTemplateInstanceWithDNSHost("8.8.8.8");
        expected = new String[]{"8.8.8.8"};

        assertEquals(1, instance.dnsHosts.length);
        assertArrayEquals(expected, instance.dnsHosts);

        instance = getDockerTemplateInstanceWithDNSHost("8.8.8.8 8.8.4.4");
        expected = new String[]{"8.8.8.8", "8.8.4.4"};

        assertEquals(2, instance.dnsHosts.length);
        assertArrayEquals(expected, instance.dnsHosts);
        
        assertTrue("Error, wrong memoryLimit", 1024 == instance.memoryLimit);

        assertTrue("Error, wrong cpuShares", 1000 == instance.cpuShares);
    }

}

@@ -156,16 +156,979 @@
 Test %7B%0A%0A
+%0A    String image = %22image%22;%0A    String labelString;%0A    String remoteFs = %22remoteFs%22;%0A    String remoteFsMapping = %22remoteFsMapping%22;%0A    String credentialsId = %22credentialsId%22;%0A    String idleTerminationMinutes = %22idleTerminationMinutes%22;%0A    String sshLaunchTimeoutMinutes = %22sshLaunchTimeoutMinutes%22;%0A    String jvmOptions = %22 jvmOptions%22;%0A    String javaPath = %22 javaPath%22;%0A    Integer memoryLimit = 1024;%0A    Integer cpuShares = 1000;%0A    String prefixStartSlaveCmd = %22prefixStartSlaveCmd%22;%0A    String suffixStartSlaveCmd = %22 suffixStartSlaveCmd%22;%0A    String instanceCapStr = %22%22;%0A%0A    String dockerCommand = %22dockerCommand%22;%0A    String volumesString = %22volumes%22;%0A    String volumesFrom = %22volumesFrom%22;%0A    String environmentsString = %22environmentString%22;%0A    String lxcConfString = %22lxcConf%22;%0A    String hostname = %22hostname%22;%0A    String bindPorts = %220.0.0.0:22%22;%0A    boolean bindAllPorts = true;%0A    boolean privileged = false;%0A    boolean tty = false;%0A%0A%0A
     priv
@@ -1260,55 +1260,103 @@
 ate(
-%22
 image
-%22
 , 
-null, %22remoteFs%22, %22remoteFsMapping%22, %22
+labelString,%0A                remoteFs,%0A                remoteFsMapping,%0A                
 cred
@@ -1364,20 +1364,18 @@
 ntialsId
-%22
 , 
-%22
 idleTerm
@@ -1388,20 +1388,34 @@
 nMinutes
-%22, %22
+,%0A                
 sshLaunc
@@ -1429,20 +1429,33 @@
 tMinutes
-%22, %22
+,%0A               
  jvmOpti
@@ -1457,20 +1457,17 @@
 mOptions
-%22, %22
+,
  javaPat
@@ -1471,24 +1471,66 @@
 Path
-%22, 1024, 1000, %22
+,%0A                memoryLimit, cpuShares,%0A                
 pref
@@ -1544,20 +1544,17 @@
 SlaveCmd
-%22
 ,
- %22
  suffixS
@@ -1569,55 +1569,115 @@
 eCmd
-%22, %22%22, dnsString, %22dockerCommand%22, %22
+,%0A                instanceCapStr, dnsString,%0A                dockerCommand,%0A                
 volumes
-%22
+String
 , 
-%22
 volu
@@ -1687,83 +1687,225 @@
 From
-%22, %22environmentsString%22, %22lxcConf%22, %22hostname%22, %220.0.0.0:22%22, true, false);
+,%0A                environmentsString,%0A                lxcConfString,%0A                hostname,%0A                bindPorts,%0A                bindAllPorts,%0A                privileged,%0A                tty);%0A%0A              
 %0A   

Fix the test and make it more parseable than a huge list of params.