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