package org.jenkins.ci.plugins.jenkinslint.check;

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

import static org.junit.Assert.assertTrue;

/**
 * SlaveDescriptionChecker Test Case.
 *
 * @author Victor Martinez
 */
public class SlaveLabelCheckerTestCase {
    private SlaveDescriptionChecker checker = new SlaveDescriptionChecker();

    @Rule public JenkinsRule j = new JenkinsRule();
    @Test public void testDefaultSlave() throws Exception {
        DumbSlave slave = j.createSlave();
        assertTrue(checker.executeCheck(slave));
    }
    @Test public void testEmptySlaveName() throws Exception {
        DumbSlave slave = j.createSlave();
        slave.setNodeName("");
        assertTrue(checker.executeCheck(slave));
    }
    @Test public void testSlaveDescription() throws Exception {
        DumbSlave slave = j.createSlave();
        slave.setNodeName("blablabla");
        assertTrue(checker.executeCheck(slave));
    }
    /**
    @Test public void testControlComment() throws Exception {
        DumbSlave slave = j.createSlave();
        assertFalse(checker.isIgnored(project.getDescription()));
        project.setDescription("#lint:ignore:" + checker.getClass().getSimpleName());
        assertTrue(checker.isIgnored(project.getDescription()));
    }*/
}

@@ -62,24 +62,187 @@
 son.
-slaves.DumbSlave
+model.Node;%0Aimport hudson.model.Slave;%0Aimport hudson.slaves.DumbSlave;%0Aimport hudson.slaves.JNLPLauncher;%0Aimport hudson.slaves.NodeProperty;%0Aimport hudson.slaves.RetentionStrategy
 ;%0Aim
@@ -328,16 +328,91 @@
 sRule;%0A%0A
+import java.util.Collections;%0A%0Aimport static org.junit.Assert.assertFalse;%0A
 import s
@@ -459,34 +459,36 @@
  * Slave
-DescriptionChecker
+LabelCheckerTestCase
  Test Ca
@@ -579,35 +579,29 @@
 rivate Slave
-Description
+Label
 Checker chec
@@ -615,27 +615,21 @@
 ew Slave
-Description
+Label
 Checker(
@@ -744,36 +744,32 @@
 ption %7B%0A        
-Dumb
 Slave slave = j.
@@ -758,34 +758,32 @@
   Slave slave = 
-j.
 createSlave();%0A 
@@ -770,32 +770,49 @@
 e = createSlave(
+%22default%22, %22%22, %22%22
 );%0A        asser
@@ -883,22 +883,18 @@
 test
-EmptySlaveName
+SlaveLabel
 () t
@@ -911,36 +911,32 @@
 ption %7B%0A        
-Dumb
 Slave slave = j.
@@ -925,34 +925,32 @@
   Slave slave = 
-j.
 createSlave();%0A 
@@ -949,38 +949,33 @@
 ave(
-);%0A        slave.setNodeName(%22
+%22default%22, %22%22, %22somelabel
 %22);%0A
@@ -980,35 +980,36 @@
 ;%0A        assert
-Tru
+Fals
 e(checker.execut
@@ -1022,32 +1022,33 @@
 (slave));%0A    %7D%0A
+%0A
     @Test public
@@ -1061,24 +1061,22 @@
 test
-SlaveDescription
+ControlComment
 () t
@@ -1093,36 +1093,32 @@
 ption %7B%0A        
-Dumb
 Slave slave = j.
@@ -1107,34 +1107,32 @@
   Slave slave = 
-j.
 createSlave();%0A 
@@ -1131,47 +1131,24 @@
 ave(
-);%0A        slave.setNodeName(%22blablabla
+%22default%22, %22%22, %22
 %22);%0A
@@ -1153,35 +1153,36 @@
 ;%0A        assert
-Tru
+Fals
 e(checker.execut
@@ -1179,146 +1179,143 @@
 ker.
-executeCheck(slave));%0A    %7D%0A    /**%0A    @Test public void testControlComment() throws Exception %7B%0A        DumbSlave slave = j.createSlave(
+isIgnored(slave.getNodeDescription()));%0A        slave = createSlave(%22default%22, %22#lint:ignore:%22 + checker.getClass().getSimpleName(), %22%22
 );%0A 
@@ -1319,36 +1319,35 @@
 ;%0A        assert
-Fals
+Tru
 e(checker.isIgno
@@ -1346,35 +1346,37 @@
 r.isIgnored(
-project.get
+slave.getNode
 Description(
@@ -1388,151 +1388,281 @@
     
+%7D%0A%0A
     pr
-oject.setDescription(%22#lint:ignore:%22 + checker.getClass().getSimpleName());%0A        assertTrue(checker.isIgnored(project.getDescription()
+ivate Slave createSlave(String name, String description, String label) throws Exception %7B%0A        return new DumbSlave(name, description, %22/wherever%22, %221%22, Node.Mode.NORMAL, label, new JNLPLauncher(), RetentionStrategy.NOOP, Collections.%3CNodeProperty%3C?%3E%3EemptyList(
 ));%0A
@@ -1666,13 +1666,11 @@
 );%0A    %7D
-*/
 %0A%7D%0A

Test cases for slavelabel check