b118811bf2020b5fa5a8816650e69e46d10d14a7
[portal/sdk.git] /
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal SDK
4  * ===================================================================
5  * Copyright (C) 2018 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (C) 2018 IBM.
8  * ===================================================================
9  * Unless otherwise specified, all software contained herein is licensed
10  * under the Apache License, Version 2.0 (the "License");
11  * you may not use this software except in compliance with the License.
12  * You may obtain a copy of the License at
13  *
14  *             http://www.apache.org/licenses/LICENSE-2.0
15  *
16  * Unless required by applicable law or agreed to in writing, software
17  * distributed under the License is distributed on an "AS IS" BASIS,
18  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
19  * See the License for the specific language governing permissions and
20  * limitations under the License.
21  *
22  * Unless otherwise specified, all documentation contained herein is licensed
23  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
24  * you may not use this documentation except in compliance with the License.
25  * You may obtain a copy of the License at
26  *
27  *             https://creativecommons.org/licenses/by/4.0/
28  *
29  * Unless required by applicable law or agreed to in writing, documentation
30  * distributed under the License is distributed on an "AS IS" BASIS,
31  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
32  * See the License for the specific language governing permissions and
33  * limitations under the License.
34  *
35  * ============LICENSE_END============================================
36  *
37  * 
38  */
39 package org.onap.portalsdk.external.authorization.domain;
40
41 import static org.junit.Assert.assertEquals;
42 import static org.junit.Assert.assertTrue;
43
44 import java.util.ArrayList;
45 import java.util.List;
46
47 import org.junit.Test;
48
49 public class ExternalAccessPermsTest {
50
51     public ExternalAccessPerms mockExternalAccessPermsTest() {
52         ExternalAccessPerms mockExtPermsTest = new ExternalAccessPerms();
53         mockExtPermsTest.setAction("*");
54         mockExtPermsTest.setDescription("test_name");
55         mockExtPermsTest.setType("test_type");
56         mockExtPermsTest.setInstance("test_instance");
57         return mockExtPermsTest;
58     }
59
60     @Test
61     public void externalAccessPermsTest() {
62         List<String> roles = new ArrayList<>();
63         roles.add("test_role");
64         roles.add("test_role2");
65         ExternalAccessPerms extPermsDetailTest = new ExternalAccessPerms();
66         ExternalAccessPerms extPermsDetailTest2 = new ExternalAccessPerms("test_type", "test_instance", "*");
67         ExternalAccessPerms extPermsDetailTest3 = new ExternalAccessPerms("test_type", "test_instance", "*",
68                 "test_name");
69         extPermsDetailTest.setAction("*");
70         extPermsDetailTest.setDescription("test_name");
71         extPermsDetailTest.setType("test_type");
72         extPermsDetailTest.setInstance("test_instance");
73         assertEquals(extPermsDetailTest.getAction(), mockExternalAccessPermsTest().getAction());
74         assertEquals(extPermsDetailTest.getType(), mockExternalAccessPermsTest().getType());
75         assertEquals(extPermsDetailTest.getInstance(), mockExternalAccessPermsTest().getInstance());
76         assertEquals(extPermsDetailTest.getDescription(), mockExternalAccessPermsTest().getDescription());
77         assertEquals(extPermsDetailTest2.getAction(), mockExternalAccessPermsTest().getAction());
78         assertEquals(extPermsDetailTest2.getType(), mockExternalAccessPermsTest().getType());
79         assertEquals(extPermsDetailTest2.getInstance(), mockExternalAccessPermsTest().getInstance());
80         assertEquals(null, extPermsDetailTest2.getDescription());
81         assertEquals(extPermsDetailTest3.getAction(), mockExternalAccessPermsTest().getAction());
82         assertEquals(extPermsDetailTest3.getType(), mockExternalAccessPermsTest().getType());
83         assertEquals(extPermsDetailTest3.getInstance(), mockExternalAccessPermsTest().getInstance());
84         assertEquals(extPermsDetailTest3.getDescription(), mockExternalAccessPermsTest().getDescription());
85         assertEquals(true, new ExternalAccessPerms("test_type", "test_instance", "*", "test_name")
86                 .equals(new ExternalAccessPerms("test_type", "test_instance", "*", "test_name")));
87     }
88     
89     @Test
90     public void testCompareTo()
91     {
92         ExternalAccessPerms extPermsDetailTest1 = new ExternalAccessPerms("test_type", "test_instance", "*");
93         ExternalAccessPerms extPermsDetailTest2 = new ExternalAccessPerms("test_type", "test_instance", "*",
94                 "test_name");
95         extPermsDetailTest1.setInstance("test_instance");
96         extPermsDetailTest2.setInstance("test_instance");
97         int result= extPermsDetailTest1.compareTo(extPermsDetailTest2);
98         assertEquals(0, result);
99     }
100     
101     @Test
102     public void testHashCode()
103     {
104         ExternalAccessPerms extPermsDetailTest = new ExternalAccessPerms();
105         extPermsDetailTest.setAction("*");
106         extPermsDetailTest.setDescription("test_name");
107         extPermsDetailTest.setType("test_type");
108         extPermsDetailTest.setInstance("test_instance");
109         assertTrue((Integer)extPermsDetailTest.hashCode() instanceof Integer);
110     }
111 }