2 * ============LICENSE_START====================================================
4 * ===========================================================================
5 * Copyright (c) 2018 AT&T Intellectual Property. All rights reserved.
6 * ===========================================================================
7 * Licensed under the Apache License, Version 2.0 (the "License");
8 * you may not use this file except in compliance with the License.
9 * You may obtain a copy of the License at
11 * http://www.apache.org/licenses/LICENSE-2.0
13 * Unless required by applicable law or agreed to in writing, software
14 * distributed under the License is distributed on an "AS IS" BASIS,
15 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16 * See the License for the specific language governing permissions and
17 * limitations under the License.
18 * ============LICENSE_END====================================================
21 package org.onap.aaf.auth.cm.validation;
23 import org.junit.Test;
24 import org.onap.aaf.auth.dao.cass.ArtiDAO;
26 import static com.google.common.collect.Lists.newArrayList;
27 import static org.junit.Assert.assertEquals;
28 import static org.junit.Assert.assertFalse;
30 public class JU_CertmanValidator {
32 private static final String COLLECTION_NAME = "collection_name";
33 private static final int MIN_SIZE = 3;
34 private CertmanValidator certmanValidator = new CertmanValidator();
38 public void nullBlankMin_shouldReportErrorWhenListIsNull() {
40 certmanValidator.nullBlankMin(COLLECTION_NAME, null, MIN_SIZE);
41 assertEquals(COLLECTION_NAME + " is null.\n", certmanValidator.errs());
45 public void nullBlankMin_shouldReportErrorWhenListHasNotEnoughElements() {
47 certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "two"), MIN_SIZE);
48 assertEquals(COLLECTION_NAME + " must have at least " + MIN_SIZE + " entries.\n", certmanValidator.errs());
52 public void nullBlankMin_shouldReportErrorWhenListContainsNullOrEmptyElements() {
54 certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "", "three"), MIN_SIZE);
55 assertEquals("List Item is blank.\n", certmanValidator.errs());
59 public void nullBlankMin_shouldPassValidation() {
61 certmanValidator.nullBlankMin(COLLECTION_NAME, newArrayList("one", "two", "three"), MIN_SIZE);
62 assertFalse(certmanValidator.err());
66 public void artisRequired_shouldReportErrorWhenListIsNull() {
68 certmanValidator.artisRequired(null, MIN_SIZE);
69 assertEquals("Artifact List is null.\n", certmanValidator.errs());
73 public void artisRequired_shouldReportErrorWhenListHasNotEnoughElements() {
75 certmanValidator.artisRequired(newArrayList(newArtifactData(), newArtifactData()), MIN_SIZE);
76 assertEquals("Artifacts must have at least " + MIN_SIZE + " entries.\n", certmanValidator.errs());
80 public void artisRequired_shouldReportErrorWhenArtifactDoesNotHaveAllRequiredFields() {
82 certmanValidator.artisRequired(newArrayList(newArtifactData("id", "", "ca", "dir", "user")), 1);
83 assertEquals("machine is blank.\n", certmanValidator.errs());
87 public void keys_shouldReportErrorWhenArtifactIsNull() {
89 certmanValidator.keys(null);
90 assertEquals("Artifact is null.\n", certmanValidator.errs());
94 public void keys_shouldReportErrorWhenArtifactDoesNotHaveAllRequiredFields() {
96 certmanValidator.keys(newArtifactData("", "", "ca", "dir", "user"));
97 assertEquals("mechid is blank.\n" + "machine is blank.\n", certmanValidator.errs());
100 private ArtiDAO.Data newArtifactData() {
101 return new ArtiDAO.Data();
104 private ArtiDAO.Data newArtifactData(String mechId, String machine, String ca, String dir, String user) {
105 ArtiDAO.Data artifact = new ArtiDAO.Data();
106 artifact.mechid = mechId;
107 artifact.machine = machine;
110 artifact.os_user = user;