package org.ovirt.engine.core.common.utils;

import static org.junit.Assert.assertEquals;

import java.util.Arrays;
import java.util.Collection;
import java.util.HashSet;
import java.util.Set;

import javax.validation.ConstraintViolation;
import javax.validation.Validator;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.Parameterized;
import org.ovirt.engine.core.common.validation.annotation.ValidNetworkLabelFormat;

@RunWith(Parameterized.class)
public class NetworkLabelFormatValidatorTest {

    private Validator validator;
    private boolean expectedResult;
    private Set<String> labels;

    public NetworkLabelFormatValidatorTest(Set<String> labels, boolean expectedResult) {
        this.labels = labels;
        this.expectedResult = expectedResult;
        validator = ValidationUtils.getValidator();
    }

    @Test
    public void checkNetworkLabelFormat() {
        Set<ConstraintViolation<NetworkLabelContainer>> validate =
                validator.validate(new NetworkLabelContainer(labels));
        assertEquals(expectedResult, validate.isEmpty());
    }

    @Parameterized.Parameters
    public static Collection<Object[]> ipAddressParams() {
        return Arrays.asList(new Object[][] {
                { new HashSet<String>(), true },
                { null, true },
                { new HashSet<String>(Arrays.asList("abc")), true },
                { new HashSet<String>(Arrays.asList("abc", "xyz")), true },
                { new HashSet<String>(Arrays.asList("abc-_sc")), true },
                { new HashSet<String>(Arrays.asList("")), false },
                { new HashSet<String>(Arrays.asList(" ")), false },
                { new HashSet<String>(Arrays.asList("abc*")), false },
                { new HashSet<String>(Arrays.asList("aaa", "abc*")), false }
        });
    }

    private class NetworkLabelContainer {
        @ValidNetworkLabelFormat
        private Set<String> labels;

        public NetworkLabelContainer(Set<String> labels) {
            this.labels = labels;
        }
    }
}

@@ -902,24 +902,106 @@
 lFormat() %7B%0A
+        NetworkLabelContainer labelContainer = new NetworkLabelContainer(labels);%0A
         Set%3C
@@ -1054,32 +1054,16 @@
 lidate =
-%0A               
  validat
@@ -1074,28 +1074,17 @@
 alidate(
-new NetworkL
+l
 abelCont
@@ -1088,24 +1088,16 @@
 ontainer
-(labels)
 );%0A     
@@ -1112,16 +1112,68 @@
 tEquals(
+%22Failed to validate %22 + labelContainer.getLabels(), 
 expected
@@ -1956,16 +1956,23 @@
 private 
+static 
 class Ne
@@ -2165,16 +2165,95 @@
        %7D
+%0A%0A        public Set%3CString%3E getLabels() %7B%0A            return labels;%0A        %7D
 %0A    %7D%0A%7D

Fix coverity warnings