d081b801fdcd266ce0f60981da5ded4200f60d73
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / domain / EPRoleTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *
8  * Unless otherwise specified, all software contained herein is licensed
9  * under the Apache License, Version 2.0 (the "License");
10  * you may not use this software except in compliance with the License.
11  * You may obtain a copy of the License at
12  *
13  *             http://www.apache.org/licenses/LICENSE-2.0
14  *
15  * Unless required by applicable law or agreed to in writing, software
16  * distributed under the License is distributed on an "AS IS" BASIS,
17  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18  * See the License for the specific language governing permissions and
19  * limitations under the License.
20  *
21  * Unless otherwise specified, all documentation contained herein is licensed
22  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
23  * you may not use this documentation except in compliance with the License.
24  * You may obtain a copy of the License at
25  *
26  *             https://creativecommons.org/licenses/by/4.0/
27  *
28  * Unless required by applicable law or agreed to in writing, documentation
29  * distributed under the License is distributed on an "AS IS" BASIS,
30  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
31  * See the License for the specific language governing permissions and
32  * limitations under the License.
33  *
34  * ============LICENSE_END============================================
35  *
36  * 
37  */
38
39 package org.onap.portalapp.portal.domain;
40
41 import static org.junit.Assert.assertEquals;
42 import static org.junit.Assert.assertNotNull;
43
44 import java.util.SortedSet;
45 import java.util.TreeSet;
46
47 import org.junit.Test;
48 import org.onap.portalapp.portal.domain.EPRole;
49 import org.onap.portalsdk.core.domain.RoleFunction;
50 import org.onap.portalsdk.core.restful.domain.EcompRoleFunction;
51
52 public class EPRoleTest {
53
54         
55         @Test
56         public void testEpRole() {
57                 EPRole role=new EPRole();
58                 role.setActive(true);
59                 role.setAppId(1l);
60                 role.setAppRoleId(2l);
61                 role.setId(3l);
62                 role.setName("TEST_ADMIN");
63                 SortedSet<EPRole> childRoles = new TreeSet<EPRole>();
64                 EPRole child=new EPRole();
65                 child.setActive(true);
66                 child.setAppId(1l);
67                 child.setAppRoleId(3l);
68                 child.setId(6l);
69                 child.setName("TEST_USER");
70                 childRoles.add(child);
71                 role.setChildRoles(childRoles);
72                 SortedSet<EPRole> parentRoles = new TreeSet<EPRole>();
73                 EPRole parent=new EPRole();
74                 parent.setActive(true);
75                 parent.setAppId(1l);
76                 parent.setAppRoleId(3l);
77                 parent.setId(6l);
78                 parent.setName("TEST_USER");
79                 parentRoles.add(parent);
80                 role.setParentRoles(parentRoles);
81                 
82                 SortedSet<RoleFunction> rolefunction = new TreeSet<RoleFunction>();
83                 RoleFunction function=new RoleFunction();
84                 function.setAction("Test");;
85                 function.setCode("code");
86                 rolefunction.add(function);
87                 role.setRoleFunctions(rolefunction);
88                 role.setPriority(5);
89                 role.setAppRoleId(3l);
90                 assertEquals(3l, role.getAppRoleId().longValue());
91                 assertNotNull(role.getChildRoles());
92                 assertNotNull(role.getParentRoles());
93                 assertNotNull(role.getRoleFunctions());
94                 role.compareTo(role);
95                 assertEquals(1l, role.getAppId().longValue());
96                 assertEquals("TEST_ADMIN",role.getName());
97                 role.removeChildRole(6l);
98                 role.removeParentRole(6l);
99                 assertEquals(role.toString(), "[Id = 3, name = TEST_ADMIN]");
100                 role.removeRoleFunction("code");
101                 role.addChildRole(child);
102                 role.addParentRole(parent);
103                 role.addRoleFunction(function);
104                 
105         }
106         
107 }
108