CADI AAF Integration and merging the code
[portal.git] / ecomp-portal-BE-common / src / test / java / org / onap / portalapp / portal / domain / EPUserAppTest.java
1 /*-
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2017 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  *  Modifications Copyright © 2018 IBM.
8  * ================================================================================
9  *
10  * Unless otherwise specified, all software contained herein is licensed
11  * under the Apache License, Version 2.0 (the "License");
12  * you may not use this software except in compliance with the License.
13  * You may obtain a copy of the License at
14  *
15  *             http://www.apache.org/licenses/LICENSE-2.0
16  *
17  * Unless required by applicable law or agreed to in writing, software
18  * distributed under the License is distributed on an "AS IS" BASIS,
19  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
20  * See the License for the specific language governing permissions and
21  * limitations under the License.
22  *
23  * Unless otherwise specified, all documentation contained herein is licensed
24  * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
25  * you may not use this documentation except in compliance with the License.
26  * You may obtain a copy of the License at
27  *
28  *             https://creativecommons.org/licenses/by/4.0/
29  *
30  * Unless required by applicable law or agreed to in writing, documentation
31  * distributed under the License is distributed on an "AS IS" BASIS,
32  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
33  * See the License for the specific language governing permissions and
34  * limitations under the License.
35  *
36  * ============LICENSE_END============================================
37  *
38  * 
39  */
40 package org.onap.portalapp.portal.domain;
41
42 import static org.junit.Assert.*;
43
44 import org.junit.Test;
45 import org.onap.portalapp.portal.domain.EPApp;
46 import org.onap.portalapp.portal.domain.EPRole;
47 import org.onap.portalapp.portal.domain.EPUserApp;
48
49 public class EPUserAppTest {
50
51     public EPUserApp mockEPUserApp(){
52         
53         EPApp epApp = new EPApp();
54         epApp.setName("test");
55         epApp.setImageUrl("test");
56         epApp.setDescription("test");
57         epApp.setNotes("test");
58         epApp.setUrl("test");
59         epApp.setAlternateUrl("test");
60         epApp.setAppRestEndpoint("test");
61         epApp.setMlAppName("test");
62         epApp.setMlAppAdminId("test");
63         epApp.setMotsId((long)1);
64         epApp.setUsername("test");
65         epApp.setAppPassword("test");
66             
67         
68         //Role
69         EPRole epRole = new EPRole();
70         epRole.setName("test");
71         epRole.setActive(false);
72         epRole.setPriority(1);
73         epRole.setAppId((long)1);
74         epRole.setAppRoleId((long)1);
75         
76         EPUserApp user = new EPUserApp();
77         user.setUserId((long)1);
78         user.setApp(epApp);
79         user.setRole(epRole);
80         user.setPriority((Integer)32767);
81         
82         
83         return user;
84     }
85     
86     @Test
87     public void userTest(){
88         EPUserApp user = mockEPUserApp();
89         
90         EPApp epApp = new EPApp();
91         epApp.setName("test");
92         epApp.setImageUrl("test");
93         epApp.setDescription("test");
94         epApp.setNotes("test");
95         epApp.setUrl("test");
96         epApp.setAlternateUrl("test");
97         epApp.setAppRestEndpoint("test");
98         epApp.setMlAppName("test");
99         epApp.setMlAppAdminId("test");
100         epApp.setMotsId((long)1);
101         epApp.setUsername("test");
102         epApp.setAppPassword("test");
103         user.setApp(epApp);
104         
105         //Role
106         EPRole epRole = new EPRole();
107         epRole.setName("test");
108         epRole.setActive(false);
109         epRole.setPriority(1);
110         epRole.setAppId((long)1);
111         epRole.setAppRoleId((long)1);
112         
113         
114         assertEquals(user.getUserId(),Long.valueOf(1));
115         assertEquals(user.getApp(), epApp); 
116         assertEquals(user.getPriority().getClass(), Integer.class);
117     
118         assertEquals(user.toString(), "[u: 1; a: null, r: null; appRoleId: 1]");
119         
120         assertEquals(user.hashCode(), user.hashCode());
121         
122         
123         }
124     
125     @Test
126     public void testEquals(){
127         
128         EPRole epRole = new EPRole();
129         epRole.setId((long) 12345);
130         epRole.setName("test");
131         epRole.setActive(false);
132         epRole.setPriority(1);
133         epRole.setAppId((long)1);
134         epRole.setAppRoleId((long)1);
135         
136         EPUserApp user1 = mockEPUserApp();
137         user1.setApp(mockEPApp());
138         user1.setRole(epRole);
139         
140         EPUserApp user2 = mockEPUserApp();
141         user2.setApp(mockEPApp());
142         user2.setRole(epRole);
143         
144         assertTrue(user1.equals(user2));
145         
146         }
147     
148     private EPApp mockEPApp() {
149         EPApp epApp = new EPApp();
150         epApp.setId((long) 12345);
151         epApp.setName("test");
152         epApp.setImageUrl("test");
153         epApp.setDescription("test");
154         epApp.setNotes("test");
155         epApp.setUrl("test");
156         epApp.setAlternateUrl("test");
157         epApp.setAppRestEndpoint("test");
158         epApp.setMlAppName("test");
159         epApp.setMlAppAdminId("test");
160         epApp.setMotsId((long)1);
161         epApp.setUsername("test");
162         epApp.setAppPassword("test");
163         return epApp;
164     }
165
166 }