Moti Asayag has uploaded a new change for review.

Change subject: engine: Add test for ValidName annotation
......................................................................

engine: Add test for ValidName annotation

Change-Id: Ica4ef1fd43a1c6144bb722b57a036a160d713c57
Signed-off-by: Moti Asayag <masa...@redhat.com>
---
A 
backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidNameValidatorTest.java
1 file changed, 67 insertions(+), 0 deletions(-)


  git pull ssh://gerrit.ovirt.org:29418/ovirt-engine refs/changes/77/22877/1

diff --git 
a/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidNameValidatorTest.java
 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidNameValidatorTest.java
new file mode 100644
index 0000000..d8b82b5
--- /dev/null
+++ 
b/backend/manager/modules/common/src/test/java/org/ovirt/engine/core/common/utils/ValidNameValidatorTest.java
@@ -0,0 +1,67 @@
+package org.ovirt.engine.core.common.utils;
+
+import static org.junit.Assert.assertEquals;
+
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Set;
+
+import javax.validation.ConstraintViolation;
+import javax.validation.Validator;
+
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+import org.ovirt.engine.core.common.validation.annotation.ValidName;
+
+@RunWith(Parameterized.class)
+public class ValidNameValidatorTest {
+
+    private Validator validator;
+    private String name;
+    private boolean expectedResult;
+
+    public ValidNameValidatorTest(String name, boolean expectedResult) {
+        this.name = name;
+        this.expectedResult = expectedResult;
+    }
+
+    @Before
+    public void setup() throws Exception {
+        validator = ValidationUtils.getValidator();
+    }
+
+    @Test
+    public void checkName() {
+        Set<ConstraintViolation<ValidNameContainer>> result = 
validator.validate(new ValidNameContainer(name));
+        assertEquals(expectedResult, result.isEmpty());
+    }
+
+    @Parameterized.Parameters
+    public static Collection<Object[]> namesParams() {
+        return Arrays.asList(new Object[][] {
+                { "abc", true },
+                { "123", true },
+                { "abc123", true },
+                { "123abc", true },
+                { null, true },
+                { " ", false },
+                { "", false },
+                { "abc ", false },
+                { " abc", false },
+                { "abc cde", false },
+                { "abc*", false }
+        });
+    }
+
+    private class ValidNameContainer {
+
+        @ValidName
+        private String name;
+
+        public ValidNameContainer(String name) {
+            this.name = name;
+        }
+    }
+}


-- 
To view, visit http://gerrit.ovirt.org/22877
To unsubscribe, visit http://gerrit.ovirt.org/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ica4ef1fd43a1c6144bb722b57a036a160d713c57
Gerrit-PatchSet: 1
Gerrit-Project: ovirt-engine
Gerrit-Branch: master
Gerrit-Owner: Moti Asayag <masa...@redhat.com>
_______________________________________________
Engine-patches mailing list
Engine-patches@ovirt.org
http://lists.ovirt.org/mailman/listinfo/engine-patches

Reply via email to