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