a0e5bfa6e7062eb09ef86db7f2af49a4ad5742af
[aaf/authz.git] / auth / auth-service / src / test / java / org / onap / aaf / auth / service / validation / test / JU_ServiceValidator.java
1 /*******************************************************************************
2  * ============LICENSE_START====================================================
3  * * org.onap.aaf
4  * * ===========================================================================
5  * * Copyright © 2017 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
10  * * 
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * * 
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====================================================
19  * *
20  * *
21  ******************************************************************************/
22 package org.onap.aaf.auth.service.validation.test;
23
24 import static org.junit.Assert.assertFalse;
25 import static org.junit.Assert.assertTrue;
26
27 import java.util.HashSet;
28 import java.util.Set;
29
30 import org.junit.Before;
31 import org.junit.Test;
32 import org.onap.aaf.auth.dao.cass.PermDAO;
33 import org.onap.aaf.auth.dao.cass.RoleDAO;
34 import org.onap.aaf.auth.layer.Result;
35 import org.onap.aaf.auth.service.validation.ServiceValidator;
36 import org.onap.aaf.auth.validation.Validator;
37
38 public class JU_ServiceValidator {
39
40         ServiceValidator validator;
41
42         @Before
43         public void setUp() {
44                 validator = new ServiceValidator();
45         }
46
47         @Test
48         public void permNotOk() {
49
50                 Result<PermDAO.Data> rpd = Result.err(1, "ERR_Security");
51
52                 validator.perm(rpd);
53                 assertTrue(validator.errs().equals("ERR_Security\n"));
54
55         }
56
57         @Test
58         public void permOkNull() {
59
60                 Result rpd = Result.ok();
61
62                 validator.perm(rpd);
63                 assertTrue(validator.errs().equals("Perm Data is null.\n"));
64
65         }
66
67         @Test
68         public void roleOkNull() {
69
70                 Result rrd = Result.ok();
71
72                 validator.role(rrd);
73                 assertTrue(validator.errs().equals("Role Data is null.\n"));
74         }
75
76         @Test
77         public void roleOk() {
78                 RoleDAO.Data to = new RoleDAO.Data();
79                 to.ns = "namespace";
80                 to.name = "name";
81                 to.description = "description";
82                 Set<String> permissions = new HashSet<String>();
83                 permissions.add("perm1");
84                 to.perms = permissions;
85
86                 Result<RoleDAO.Data> rrd = Result.ok(to);
87
88                 validator.role(rrd);
89                 assertTrue(
90                                 validator.errs().equals("Perm [perm1] in Role [namespace.name] is not correctly separated with '|'\n"));
91         }
92
93         @Test
94         public void roleNotOk() {
95
96                 Result rrd = Result.err(1, "ERR_Security");
97
98                 validator.role(rrd);
99                 assertTrue(validator.errs().equals("ERR_Security\n"));
100         }
101
102 }