2 * ============LICENSE_START==========================================
4 * ===================================================================
5 * Copyright (C) 2019 AT&T Intellectual Property. All rights reserved.
6 * ===================================================================
7 * Modifications Copyright (c) 2019 Samsung
8 * ===================================================================
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
15 * http://www.apache.org/licenses/LICENSE-2.0
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.
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
28 * https://creativecommons.org/licenses/by/4.0/
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.
36 * ============LICENSE_END============================================
41 package org.onap.portal.service.fn;
43 import static org.junit.jupiter.api.Assertions.*;
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.springframework.beans.factory.annotation.Autowired;
55 import org.springframework.boot.test.context.SpringBootTest;
56 import org.springframework.security.authentication.UsernamePasswordAuthenticationToken;
57 import org.springframework.test.context.TestPropertySource;
58 import org.springframework.test.context.junit4.SpringRunner;
59 import org.springframework.transaction.annotation.Transactional;
61 @RunWith(SpringRunner.class)
63 @TestPropertySource(locations="classpath:test.properties")
65 class FnUserServiceTest {
66 private UsernamePasswordAuthenticationToken principal = new UsernamePasswordAuthenticationToken("demo", "XZa6pS1vC0qKXWtn9wcZWdLx61L0=");
68 private FnUserService fnUserService;
70 private FnLuTimezoneService fnLuTimezoneService;
72 private FnLanguageService fnLanguageService;
77 //FnLuTimezone fnLuTimezone = fnLuTimezoneService.getById(10L).get();
78 FnLanguage language = fnLanguageService.findById(1L).get();
80 FnUser expected = FnUser.builder().build();
81 expected.setFirstName("Demo");
82 expected.setLastName("User");
83 expected.setEmail("demo@openecomp.org");
84 expected.setOrgUserId("demo");
85 //expected.setTimezone(fnLuTimezone);
86 expected.setLoginId("demoTest");
87 expected.setLoginPwd("demo123");
88 expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
89 expected.setActiveYn(true);
90 expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
91 expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
92 expected.setIsInternalYn(false);
93 expected.setStateCd("NJ");
94 expected.setCountryCd("US");
95 expected.setLanguageId(language);
96 expected.setGuest(false);
98 //fnLuTimezone.getFnUsers().add(expected);
99 language.getFnUsers().add(expected);
102 fnUserService.saveFnUser(principal, expected);
103 FnUser actual = fnUserService.getUser(expected.getUserId()).get();
105 assertEquals(expected.getUserId(), actual.getUserId());
106 assertEquals(expected.getLoginPwd(), actual.getLoginPwd());
108 fnUserService.deleteUser(expected);
113 FnUser actual = fnUserService.getUser(1L).get();
116 FnUser expected = FnUser.builder().build();
117 expected.setUserId(1L);
118 expected.setFirstName("Demo");
119 expected.setLastName("User");
120 expected.setEmail("demo@openecomp.org");
121 expected.setOrgUserId("demo");
122 expected.setLoginId("demo");
123 expected.setLoginPwd("demo123");
124 expected.setLastLoginDate(LocalDateTime.parse("2019-08-08T12:18:17"));
125 expected.setActiveYn(true);
126 expected.setCreatedDate(LocalDateTime.parse("2016-10-14T21:00"));
127 expected.setModifiedId(actual);
128 expected.setModifiedDate(LocalDateTime.parse("2019-08-08T12:18:17"));
129 expected.setIsInternalYn(false);
130 expected.setStateCd("NJ");
131 expected.setCountryCd("US");
132 expected.setTimezone(fnLuTimezoneService.getById(10L).orElse(new FnLuTimezone()));
133 expected.setLanguageId(fnLanguageService.findById(1L).orElse(new FnLanguage()));
136 assertEquals(expected.getUserId(), actual.getUserId());
137 assertEquals(expected.getOrgId(), actual.getOrgId());
138 assertEquals(expected.getManagerId(), actual.getManagerId());
139 assertEquals(expected.getFirstName(), actual.getFirstName());
140 assertEquals(expected.getMiddleName(), actual.getMiddleName());
141 assertEquals(expected.getLastName(), actual.getLastName());
142 assertEquals(expected.getPhone(), actual.getPhone());
143 assertEquals(expected.getFax(), actual.getFax());
144 assertEquals(expected.getCellular(), actual.getCellular());
145 assertEquals(expected.getEmail(), actual.getEmail());
146 assertEquals(expected.getAddressId(), actual.getAddressId());
147 assertEquals(expected.getAlertMethodCd(), actual.getAlertMethodCd());
148 assertEquals(expected.getHrid(), actual.getHrid());
149 assertEquals(expected.getOrgUserId(), actual.getOrgUserId());
150 assertEquals(expected.getOrg_code(), actual.getOrg_code());
151 assertEquals(expected.getLoginId(), actual.getLoginId());
152 assertEquals(expected.getLoginPwd(), actual.getLoginPwd());
153 assertEquals(expected.getLastLoginDate(), actual.getLastLoginDate());
154 assertEquals(expected.getActiveYn(), actual.getActiveYn());
155 assertEquals(expected.getCreatedId(), actual.getCreatedId());
156 assertEquals(expected.getCreatedDate(), actual.getCreatedDate());
157 assertEquals(expected.getModifiedDate(), actual.getModifiedDate());
158 assertEquals(expected.getIsInternalYn(), actual.getIsInternalYn());
159 assertEquals(expected.getAddressLine1(), actual.getAddressLine1());
160 assertEquals(expected.getAddressLine2(), actual.getAddressLine2());
161 assertEquals(expected.getCity(), actual.getCity());
162 assertEquals(expected.getStateCd(), actual.getStateCd());
163 assertEquals(expected.getZipCode(), actual.getZipCode());
164 assertEquals(expected.getCountryCd(), actual.getCountryCd());
165 assertEquals(expected.getLocationClli(), actual.getLocationClli());
166 assertEquals(expected.getOrgManagerUserId(), actual.getOrgManagerUserId());
167 assertEquals(expected.getCompany(), actual.getCompany());
168 assertEquals(expected.getDepartmentName(), actual.getDepartmentName());
169 assertEquals(expected.getJobTitle(), actual.getJobTitle());
170 assertEquals(expected.getTimezone().getTimezoneId(), actual.getTimezone().getTimezoneId());
171 assertEquals(expected.getDepartment(), actual.getDepartment());
172 assertEquals(expected.getBusinessUnit(), actual.getBusinessUnit());
173 assertEquals(expected.getBusinessUnitName(), actual.getBusinessUnitName());
174 assertEquals(expected.getCost_center(), actual.getCost_center());
175 assertEquals(expected.getFinLocCode(), actual.getFinLocCode());
176 assertEquals(expected.getSiloStatus(), actual.getSiloStatus());
177 assertEquals(expected.getLanguageId(), actual.getLanguageId());
181 void getActiveUsers() {
182 assertEquals(12, fnUserService.getActiveUsers().size());
186 void getUserWithOrgUserId() {
187 assertEquals(1, fnUserService.getUserWithOrgUserId("cs0008").size());
191 void getUserWithOrgUserIds() {
192 List<String> ids = new ArrayList<>(Arrays.asList("cs0008", "op0001"));
193 assertEquals(2, fnUserService.getUsersByOrgIds(ids).size());