CertmanValidator junits 00/74900/1
authorpkaras <piotr.karas@nokia.com>
Wed, 19 Dec 2018 13:03:16 +0000 (14:03 +0100)
committerpkaras <piotr.karas@nokia.com>
Wed, 19 Dec 2018 13:03:16 +0000 (14:03 +0100)
Change-Id: I915bc10f29578751816a58f64bfa0db5e838480b
Issue-ID: AAF-679
Signed-off-by: piotr.karas <piotr.karas@nokia.com>
auth/auth-certman/src/main/java/org/onap/aaf/auth/cm/validation/CertmanValidator.java
auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/validation/JU_CertmanValidator.java [new file with mode: 0644]

index 1a27b41..bb157a2 100644 (file)
@@ -78,22 +78,6 @@ public class CertmanValidator extends Validator{
         return this;
     }
 
-    public CertmanValidator artisKeys(List<ArtiDAO.Data> list, int min) {
-        if (list==null) {
-            msg(ARTIFACT_LIST_IS_NULL);
-        } else {
-            if (list.size()<min) {
-                msg(ARTIFACTS_MUST_HAVE_AT_LEAST + min + ENTR + (min==1?Y:IES));
-            } else {
-                for (ArtiDAO.Data a : list) {
-                    keys(a);
-                }
-            }
-        }
-        return this;
-    }
-
-
     public CertmanValidator keys(ArtiDAO.Data add) {
         if (add==null) {
             msg("Artifact is null.");
diff --git a/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/validation/JU_CertmanValidator.java b/auth/auth-certman/src/test/java/org/onap/aaf/auth/cm/validation/JU_CertmanValidator.java
new file mode 100644 (file)
index 0000000..4aa3d6d
--- /dev/null
@@ -0,0 +1,114 @@
+/**
+ * ============LICENSE_START====================================================
+ * org.onap.aaf
+ * ===========================================================================
+ * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ */
+package org.onap.aaf.auth.cm.validation;
+
+import org.junit.Test;
+import org.onap.aaf.auth.dao.cass.ArtiDAO;
+
+import static com.google.common.collect.Lists.newArrayList;
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertFalse;
+
+public class JU_CertmanValidator {
+
+    private static final String COLLECTION_NAME = "collection_name";
+    private static final int MIN_SIZE = 3;
+    private CertmanValidator certmanValidator = new CertmanValidator();
+
+
+    @Test
+    public void nullBlankMin_shouldReportErrorWhenListIsNull() {
+
+        certmanValidator.nullBlankMin(COLLECTION_NAME, null, MIN_SIZE);
+        assertEquals(COLLECTION_NAME + " is null.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void nullBlankMin_shouldReportErrorWhenListHasNotEnoughElements() {
+
+        certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "two"), MIN_SIZE);
+        assertEquals(COLLECTION_NAME + " must have at least " + MIN_SIZE + " entries.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void nullBlankMin_shouldReportErrorWhenListContainsNullOrEmptyElements() {
+
+        certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "", "three"), MIN_SIZE);
+        assertEquals("List Item is blank.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void nullBlankMin_shouldPassValidation() {
+
+        certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "two", "three"), MIN_SIZE);
+        assertFalse(certmanValidator.err());
+    }
+
+    @Test
+    public void artisRequired_shouldReportErrorWhenListIsNull() {
+
+        certmanValidator.artisRequired(null, MIN_SIZE);
+        assertEquals("Artifact List is null.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void artisRequired_shouldReportErrorWhenListHasNotEnoughElements() {
+
+        certmanValidator.artisRequired(newArrayList(newArtifactData(), newArtifactData()), MIN_SIZE);
+        assertEquals("Artifacts must have at least " + MIN_SIZE + " entries.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void artisRequired_shouldReportErrorWhenArtifactDoesNotHaveAllRequiredFields() {
+
+        certmanValidator.artisRequired(newArrayList(newArtifactData("id", "", "ca", "dir", "user")), 1);
+        assertEquals("machine is blank.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void keys_shouldReportErrorWhenArtifactIsNull() {
+
+        certmanValidator.keys(null);
+        assertEquals("Artifact is null.\n", certmanValidator.errs());
+    }
+
+    @Test
+    public void keys_shouldReportErrorWhenArtifactDoesNotHaveAllRequiredFields() {
+
+        certmanValidator.keys(newArtifactData("", "", "ca", "dir", "user"));
+        assertEquals("mechid is blank.\n" + "machine is blank.\n", certmanValidator.errs());
+    }
+
+    private ArtiDAO.Data newArtifactData() {
+        return new ArtiDAO.Data();
+    }
+
+    private ArtiDAO.Data newArtifactData(String mechId, String machine, String ca, String dir, String user) {
+        ArtiDAO.Data artifact = new ArtiDAO.Data();
+        artifact.mechid = mechId;
+        artifact.machine = machine;
+        artifact.ca = ca;
+        artifact.dir = dir;
+        artifact.os_user = user;
+        return artifact;
+
+    }
+}
\ No newline at end of file