Tests Coverage up
[portal.git] / portal-BE / src / test / java / org / onap / portal / service / fn / FnUserServiceTest.java
1 /*
2  * ============LICENSE_START==========================================
3  * ONAP Portal
4  * ===================================================================
5  * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6  * ===================================================================
7  * Modifications Copyright (c) 2019 Samsung
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
41 package org.onap.portal.service.fn;
42
43 import static org.junit.jupiter.api.Assertions.*;
44
45 import java.time.LocalDateTime;
46 import java.util.ArrayList;
47 import java.util.Arrays;
48 import java.util.Collections;
49 import java.util.List;
50 import org.junit.jupiter.api.Test;
51 import org.junit.runner.RunWith;
52 import org.onap.portal.domain.db.fn.FnLanguage;
53 import org.onap.portal.domain.db.fn.FnLuTimezone;
54 import org.onap.portal.domain.db.fn.FnUser;
55 import org.onap.portal.domain.builder.FnUserBuilder;
56 import org.springframework.beans.factory.annotation.Autowired;
57 import org.springframework.boot.test.context.SpringBootTest;
58 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
59 import org.springframework.test.context.TestPropertySource;
60 import org.springframework.test.context.junit4.SpringRunner;
61 import org.springframework.transaction.annotation.Transactional;
62
63 @RunWith(SpringRunner.class)
64 @SpringBootTest
65 @TestPropertySource(locations="classpath:test.properties")
66 @Transactional
67 class FnUserServiceTest {
68        private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
69        @Autowired
70        private FnUserService fnUserService;
71        @Autowired
72        private FnLuTimezoneService fnLuTimezoneService;
73        @Autowired
74        private FnLanguageService fnLanguageService;
75
76        @Test
77        void saveUser(){
78               FnUser actual = fnUserService.getUser(1L).get();
79
80               FnUser expected = new FnUserBuilder().createFnUser();
81               expected.setUserId(123L);
82               expected.setFirstName("Demo");
83               expected.setLastName("User");
84               expected.setEmail("demo@openecomp.org");
85               expected.setOrgUserId("demo");
86               expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
87               expected.setLoginId("demo");
88               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
89               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
90               expected.setActiveYn("Y");
91               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
92               expected.setModifiedId(actual);
93               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
94               expected.setIsInternalYn("N");
95               expected.setStateCd("NJ");
96               expected.setCountryCd("US");
97               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
98
99               fnUserService.saveFnUser(principal, expected);
100
101               //Clean up
102               fnUserService.deleteUser(expected);
103        }
104
105        @Test
106        void getUser() {
107               FnUser actual = fnUserService.getUser(1L).get();
108
109
110               FnUser expected = new FnUserBuilder().createFnUser();
111               expected.setUserId(1L);
112               expected.setFirstName("Demo");
113               expected.setLastName("User");
114               expected.setEmail("demo@openecomp.org");
115               expected.setOrgUserId("demo");
116               expected.setLoginId("demo");
117               expected.setLoginPwd("4Gl6WL1bmwviYm+XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
118               expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
119               expected.setActiveYn("Y");
120               expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
121               expected.setModifiedId(actual);
122               expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
123               expected.setIsInternalYn("N");
124               expected.setStateCd("NJ");
125               expected.setCountryCd("US");
126               expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
127               expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
128
129
130               assertEquals(expected.getUserId(), actual.getUserId());
131               assertEquals(expected.getOrgId(), actual.getOrgId());
132               assertEquals(expected.getManagerId(), actual.getManagerId());
133               assertEquals(expected.getFirstName(), actual.getFirstName());
134               assertEquals(expected.getMiddleName(), actual.getMiddleName());
135               assertEquals(expected.getLastName(), actual.getLastName());
136               assertEquals(expected.getPhone(), actual.getPhone());
137               assertEquals(expected.getFax(), actual.getFax());
138               assertEquals(expected.getCellular(), actual.getCellular());
139               assertEquals(expected.getEmail(), actual.getEmail());
140               assertEquals(expected.getAddressId(), actual.getAddressId());
141               assertEquals(expected.getAlertMethodCd(), actual.getAlertMethodCd());
142               assertEquals(expected.getHrid(), actual.getHrid());
143               assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
144               assertEquals(expected.getOrg_code(), actual.getOrg_code());
145               assertEquals(expected.getLoginId(), actual.getLoginId());
146               assertEquals(expected.getLoginPwd(), actual.getLoginPwd());
147               assertEquals(expected.getLastLoginDate(), actual.getLastLoginDate());
148               assertEquals(expected.getActiveYn(), actual.getActiveYn());
149               assertEquals(expected.getCreatedId(), actual.getCreatedId());
150               assertEquals(expected.getCreatedDate(), actual.getCreatedDate());
151               assertEquals(expected.getModifiedId(), actual.getModifiedId());
152               assertEquals(expected.getModifiedDate(), actual.getModifiedDate());
153               assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn());
154               assertEquals(expected.getAddressLine1(), actual.getAddressLine1());
155               assertEquals(expected.getAddressLine2(), actual.getAddressLine2());
156               assertEquals(expected.getCity(), actual.getCity());
157               assertEquals(expected.getStateCd(), actual.getStateCd());
158               assertEquals(expected.getZipCode(), actual.getZipCode());
159               assertEquals(expected.getCountryCd(), actual.getCountryCd());
160               assertEquals(expected.getLocationClli(), actual.getLocationClli());
161               assertEquals(expected.getOrgManagerUserId(), actual.getOrgManagerUserId());
162               assertEquals(expected.getCompany(), actual.getCompany());
163               assertEquals(expected.getDepartmentName(), actual.getDepartmentName());
164               assertEquals(expected.getJobTitle(), actual.getJobTitle());
165               assertEquals(expected.getTimezone().getTimezoneId(), actual.getTimezone().getTimezoneId());
166               assertEquals(expected.getDepartment(), actual.getDepartment());
167               assertEquals(expected.getBusinessUnit(), actual.getBusinessUnit());
168               assertEquals(expected.getBusinessUnitName(), actual.getBusinessUnitName());
169               assertEquals(expected.getCost_center(), actual.getCost_center());
170               assertEquals(expected.getFinLocCode(), actual.getFinLocCode());
171               assertEquals(expected.getSiloStatus(), actual.getSiloStatus());
172               assertEquals(expected.getLanguageId(), actual.getLanguageId());
173        }
174
175        @Test
176        void getActiveUsers() {
177               assertEquals(12, fnUserService.getActiveUsers().size());
178        }
179
180        @Test
181        void getUserWithOrgUserId() {
182               assertEquals(1, fnUserService.getUserWithOrgUserId("cs0008").size());
183        }
184
185        @Test
186        void getUserWithOrgUserIds() {
187               List<String> ids = new ArrayList<>(Arrays.asList("cs0008", "op0001"));
188               assertEquals(2, fnUserService.getUsersByOrgIds(ids).size());
189        }
190
191 }